#!/usr/bin/python

###
### Copyright 2002 Ximian, Inc.
###
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License, version 2,
### as published by the Free Software Foundation.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
###

try:
    import sys
    import os

    red_carpet_prefix = "/opt/gnome"
    red_carpet_datadir = "/opt/gnome/share/red-carpet"
    red_carpet_libdir = "/opt/gnome/lib64/red-carpet"
    red_carpet_localedir = "/opt/gnome/share/locale"

    red_carpet_version = "2.4.4"
    red_carpet_pixbuf_path = "/opt/gnome/share/pixmaps/red-carpet"
    red_carpet_help_path = "/opt/gnome/share/gnome/help/red-carpet"

    # Magic that allows us to use red_extra and the unmarshaller w/o
    # having it installed and a pygtk installed into a different prefix.

    additional_paths = ["..", "../red_extra/.libs", "/usr/lib/python2.4/site-packages",
                        "../ximian_unmarshaller", "../sgmlop",
                        "../sgmlop/build/lib.linux-i686-2.2",
                        red_carpet_libdir]

    sys.path = additional_paths + sys.path

    import pygtk

    if not hasattr(sys, "frozen") or sys.frozen == 0:
        pygtk.require("2.0")

        # FIXME: This has a special check to allow us to run rc in-place
        # without having done a "make install".  We might want to take this
        # out at some point.

        if not (os.path.isfile("./red_icon_main.py") \
                or (os.path.isdir(red_carpet_datadir) \
                    and os.path.isfile(red_carpet_datadir + "/red_icon_main.py"))):
            print "ERROR: The Red Carpet Graphical Client doesn't appear to be"
            print "ERROR: installed properly.  Please check your installation."
            sys.exit(1)

    sys.path.append(red_carpet_datadir)

    ###
    ### Make sure we can import gtk.  This keeps us from getting
    ### an error w/ an ugly backtrace if we can't open the DISPLAY.
    ###
    try:
        import gtk
    except RuntimeError, r:
        sys.stderr.write("Error importing gtk: %s\n" % r)
        sys.exit(1)
    except:
        sys.stderr.write("Error: Couldn't import gtk.\n")
        sys.exit(1)

    # Set up paths
    import red_pixbuf
    red_pixbuf.pixbuf_path.append(red_carpet_pixbuf_path)

    import red_gettext
    red_gettext.init(red_carpet_localedir)

    import red_icon_main

    red_icon_main.help_path = red_carpet_help_path

    if "--rc-profile" in sys.argv:
        import profile
        sys.stderr.write("*** Profiling Enabled ***\n")
        sys.argv = filter(lambda x:x != "--rc-profile", sys.argv)
        profile.run("red_icon_main.main(red_carpet_version)")
    else:
        red_icon_main.main(red_carpet_version)
except KeyboardInterrupt:
    # Just quietly exit if we got a ^C
    import sys
    
    sys.exit(0)
