Example #1
0
        static int Main(string [] args)
        {
            args = FixArgs(args);

            ApplicationContext.ApplicationName = "F-Spot";
            ApplicationContext.TrySetProcessName(Defines.PACKAGE);

            Paths.ApplicationName = "f-spot";
            SynchronizationContext.SetSynchronizationContext(new GtkSynchronizationContext());
            ThreadAssist.InitializeMainThread();
            ThreadAssist.ProxyToMainHandler = RunIdle;

            // Options and Option parsing
            bool shutdown  = false;
            bool view      = false;
            bool slideshow = false;
            bool import    = false;

            GLib.GType.Init();
            Catalog.Init("f-spot", Defines.LOCALE_DIR);

            Global.PhotoUri = new SafeUri(Preferences.Get <string> (Preferences.STORAGE_PATH));

            ApplicationContext.CommandLine = new CommandLineParser(args, 0);

            if (ApplicationContext.CommandLine.ContainsStart("help"))
            {
                ShowHelp();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("version"))
            {
                ShowVersion();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("versions"))
            {
                ShowAssemblyVersions();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("shutdown"))
            {
                Log.Information("Shutting down existing F-Spot server...");
                shutdown = true;
            }

            if (ApplicationContext.CommandLine.Contains("slideshow"))
            {
                Log.Information("Running F-Spot in slideshow mode.");
                slideshow = true;
            }

            if (ApplicationContext.CommandLine.Contains("basedir"))
            {
                string dir = ApplicationContext.CommandLine ["basedir"];

                if (!string.IsNullOrEmpty(dir))
                {
                    Global.BaseDirectory = dir;
                    Log.InformationFormat("BaseDirectory is now {0}", dir);
                }
                else
                {
                    Log.Error("f-spot: -basedir option takes one argument");
                    return(1);
                }
            }

            if (ApplicationContext.CommandLine.Contains("photodir"))
            {
                string dir = ApplicationContext.CommandLine ["photodir"];

                if (!string.IsNullOrEmpty(dir))
                {
                    Global.PhotoUri = new SafeUri(dir);
                    Log.InformationFormat("PhotoDirectory is now {0}", dir);
                }
                else
                {
                    Log.Error("f-spot: -photodir option takes one argument");
                    return(1);
                }
            }

            if (ApplicationContext.CommandLine.Contains("import"))
            {
                import = true;
            }

            if (ApplicationContext.CommandLine.Contains("view"))
            {
                view = true;
            }

            if (ApplicationContext.CommandLine.Contains("debug"))
            {
                Log.Debugging = true;
                // Debug GdkPixbuf critical warnings
                var logFunc = new GLib.LogFunc(GLib.Log.PrintTraceLogFunction);
                GLib.Log.SetLogHandler("GdkPixbuf", GLib.LogLevelFlags.Critical, logFunc);

                // Debug Gtk critical warnings
                GLib.Log.SetLogHandler("Gtk", GLib.LogLevelFlags.Critical, logFunc);

                // Debug GLib critical warnings
                GLib.Log.SetLogHandler("GLib", GLib.LogLevelFlags.Critical, logFunc);

                //Debug GLib-GObject critical warnings
                GLib.Log.SetLogHandler("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc);

                GLib.Log.SetLogHandler("GLib-GIO", GLib.LogLevelFlags.Critical, logFunc);
            }

            // Validate command line options
            if ((import && (view || shutdown || slideshow)) ||
                (view && (shutdown || slideshow)) ||
                (shutdown && slideshow))
            {
                Log.Error("Can't mix -import, -view, -shutdown or -slideshow");
                return(1);
            }

            InitializeAddins();

            // Gtk initialization
            Gtk.Application.Init(Defines.PACKAGE, ref args);
            // Maybe we'll add this at a future date
            //Xwt.Application.InitializeAsGuest (Xwt.ToolkitType.Gtk);

            // init web proxy globally
            Platform.WebProxy.Init();

            if (File.Exists(Preferences.Get <string> (Preferences.GTK_RC)))
            {
                if (File.Exists(Path.Combine(Global.BaseDirectory, "gtkrc")))
                {
                    Gtk.Rc.AddDefaultFile(Path.Combine(Global.BaseDirectory, "gtkrc"));
                }

                Global.DefaultRcFiles = Gtk.Rc.DefaultFiles;
                Gtk.Rc.AddDefaultFile(Preferences.Get <string> (Preferences.GTK_RC));
                Gtk.Rc.ReparseAllForSettings(Gtk.Settings.Default, true);
            }

            try {
                Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] {
                    GtkUtil.TryLoadIcon(Global.IconTheme, "f-spot", 16, 0),
                    GtkUtil.TryLoadIcon(Global.IconTheme, "f-spot", 22, 0),
                    GtkUtil.TryLoadIcon(Global.IconTheme, "f-spot", 32, 0),
                    GtkUtil.TryLoadIcon(Global.IconTheme, "f-spot", 48, 0)
                };
            } catch (Exception ex) {
                Log.Exception("Loading default f-spot icons", ex);
            }

            GLib.ExceptionManager.UnhandledException += exceptionArgs =>
            {
                Console.WriteLine("Unhandeled exception handler:");
                var exception = exceptionArgs.ExceptionObject as Exception;
                if (exception != null)
                {
                    Console.WriteLine("Message: " + exception.Message);
                    Console.WriteLine("Stack trace: " + exception.StackTrace);
                }
                else
                {
                    Console.WriteLine("Unknown exception type: " + exceptionArgs.ExceptionObject.GetType().ToString());
                }
            };

            CleanRoomStartup.Startup(Startup);

            // Running threads are preventing the application from quitting
            // we force it for now until this is fixed
            Environment.Exit(0);
            return(0);
        }
Example #2
0
        static int Main(string [] args)
        {
            args = FixArgs(args);

            ApplicationContext.ApplicationName = "F-Spot";
            ApplicationContext.TrySetProcessName(Defines.PACKAGE);

            Paths.ApplicationName = "f-spot";
            ThreadAssist.InitializeMainThread();
            ThreadAssist.ProxyToMainHandler = RunIdle;
            XdgThumbnailSpec.DefaultLoader  = (uri) => {
                using (var file = ImageFile.Create(uri))
                    return(file.Load());
            };

            // Options and Option parsing
            bool shutdown  = false;
            bool view      = false;
            bool slideshow = false;
            bool import    = false;

            GLib.GType.Init();
            Catalog.Init("f-spot", Defines.LOCALE_DIR);

            FSpot.Core.Global.PhotoUri = new SafeUri(Preferences.Get <string> (Preferences.STORAGE_PATH));

            ApplicationContext.CommandLine = new CommandLineParser(args, 0);

            if (ApplicationContext.CommandLine.ContainsStart("help"))
            {
                ShowHelp();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("version"))
            {
                ShowVersion();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("versions"))
            {
                ShowAssemblyVersions();
                return(0);
            }

            if (ApplicationContext.CommandLine.Contains("shutdown"))
            {
                Log.Information("Shutting down existing F-Spot server...");
                shutdown = true;
            }

            if (ApplicationContext.CommandLine.Contains("slideshow"))
            {
                Log.Information("Running F-Spot in slideshow mode.");
                slideshow = true;
            }

            if (ApplicationContext.CommandLine.Contains("basedir"))
            {
                string dir = ApplicationContext.CommandLine ["basedir"];

                if (!string.IsNullOrEmpty(dir))
                {
                    FSpot.Core.Global.BaseDirectory = dir;
                    Log.InformationFormat("BaseDirectory is now {0}", dir);
                }
                else
                {
                    Log.Error("f-spot: -basedir option takes one argument");
                    return(1);
                }
            }

            if (ApplicationContext.CommandLine.Contains("photodir"))
            {
                string dir = ApplicationContext.CommandLine ["photodir"];

                if (!string.IsNullOrEmpty(dir))
                {
                    FSpot.Core.Global.PhotoUri = new SafeUri(dir);
                    Log.InformationFormat("PhotoDirectory is now {0}", dir);
                }
                else
                {
                    Log.Error("f-spot: -photodir option takes one argument");
                    return(1);
                }
            }

            if (ApplicationContext.CommandLine.Contains("import"))
            {
                import = true;
            }

            if (ApplicationContext.CommandLine.Contains("view"))
            {
                view = true;
            }

            if (ApplicationContext.CommandLine.Contains("debug"))
            {
                Log.Debugging = true;
                // Debug GdkPixbuf critical warnings
                GLib.LogFunc logFunc = new GLib.LogFunc(GLib.Log.PrintTraceLogFunction);
                GLib.Log.SetLogHandler("GdkPixbuf", GLib.LogLevelFlags.Critical, logFunc);

                // Debug Gtk critical warnings
                GLib.Log.SetLogHandler("Gtk", GLib.LogLevelFlags.Critical, logFunc);

                // Debug GLib critical warnings
                GLib.Log.SetLogHandler("GLib", GLib.LogLevelFlags.Critical, logFunc);

                //Debug GLib-GObject critical warnings
                GLib.Log.SetLogHandler("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc);

                GLib.Log.SetLogHandler("GLib-GIO", GLib.LogLevelFlags.Critical, logFunc);
            }

            // Validate command line options
            if ((import && (view || shutdown || slideshow)) ||
                (view && (shutdown || slideshow)) ||
                (shutdown && slideshow))
            {
                Log.Error("Can't mix -import, -view, -shutdown or -slideshow");
                return(1);
            }

            InitializeAddins();

            // Gtk initialization
            Gtk.Application.Init(Defines.PACKAGE, ref args);

            // init web proxy globally
            Platform.WebProxy.Init();

            if (File.Exists(Preferences.Get <string> (Preferences.GTK_RC)))
            {
                if (File.Exists(Path.Combine(FSpot.Core.Global.BaseDirectory, "gtkrc")))
                {
                    Gtk.Rc.AddDefaultFile(Path.Combine(FSpot.Core.Global.BaseDirectory, "gtkrc"));
                }

                FSpot.Core.Global.DefaultRcFiles = Gtk.Rc.DefaultFiles;
                Gtk.Rc.AddDefaultFile(Preferences.Get <string> (Preferences.GTK_RC));
                Gtk.Rc.ReparseAllForSettings(Gtk.Settings.Default, true);
            }

            try {
                Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] {
                    GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 16, (Gtk.IconLookupFlags) 0),
                    GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 22, (Gtk.IconLookupFlags) 0),
                    GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 32, (Gtk.IconLookupFlags) 0),
                    GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 48, (Gtk.IconLookupFlags) 0)
                };
            } catch {}

            CleanRoomStartup.Startup(Startup);

            return(0);
        }