Ejemplo n.º 1
0
        public EditorWindow() : base(Gtk.WindowType.Toplevel)
        {
            this.Build();

            GLib.LogFunc logfunc = new GLib.LogFunc(GLib.Log.PrintTraceLogFunction);
            GLib.Log.SetLogHandler("Gtk", GLib.LogLevelFlags.All, logfunc);

            nb_tabs            = new Notebook();
            nb_tabs.CanFocus   = true;
            nb_tabs.Scrollable = true;

            edit_container.Add(nb_tabs);
            AddTab();

            status_bar.Push(id, "Welcome");
        }
Ejemplo n.º 2
0
	public EditorWindow () : base (Gtk.WindowType.Toplevel)
	{
		this.Build ();
		
		GLib.LogFunc logfunc = new GLib.LogFunc (GLib.Log.PrintTraceLogFunction);
		GLib.Log.SetLogHandler ("Gtk", GLib.LogLevelFlags.All, logfunc);
		
		nb_tabs = new Notebook ();
		nb_tabs.CanFocus = true;
		nb_tabs.Scrollable = true;
		
		edit_container.Add (nb_tabs);
		AddTab ();
		
		status_bar.Push (id, "Welcome");
	}
Ejemplo n.º 3
0
        static void Main(string [] args)
        {
            try {

                GLib.GType.Init ();

                GLib.LogFunc logFunc = new GLib.LogFunc (GLib.Log.PrintTraceLogFunction);
                GLib.Log.SetLogHandler ("GLib", GLib.LogLevelFlags.Critical, logFunc);
                GLib.Log.SetLogHandler ("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc);
                GLib.Log.SetLogHandler ("GLib-GObject", GLib.LogLevelFlags.Warning, logFunc);
                if (args.Length != 1) {
                    Console.WriteLine ("Usage: ExifPrint.exe file");
                    System.Environment.Exit (1);
                }
                Exiv2.Image image = Exiv2.ImageFactory.Open (args [0]);
                image.ReadMetadata ();

                Console.WriteLine (image.Good);

                ExifData exif_data = image.ExifData;
                if (exif_data.IsEmpty) {
                    Console.WriteLine ("No Exif data found in file");
                    return;
                }

                Console.WriteLine ("Exif count: {0}", exif_data.Count);

                foreach (ExifDatum datum in exif_data)
                    Console.WriteLine ("{0} {1} {2} {3} {4}",
                            datum.Key,
                            datum.Tag,
                            datum.Typename,
                            datum.Count,
                            datum.ToString ());

            } catch (GLib.GException e) {
                Console.WriteLine ("Exiv2.Exception caught {0}", e);
            }
        }
Ejemplo n.º 4
0
        static void Main(string [] args)
        {
            try {

                GLib.GType.Init ();

                GLib.LogFunc logFunc = new GLib.LogFunc (GLib.Log.PrintTraceLogFunction);
                GLib.Log.SetLogHandler ("GLib", GLib.LogLevelFlags.Critical, logFunc);
                GLib.Log.SetLogHandler ("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc);
                GLib.Log.SetLogHandler ("GLib-GObject", GLib.LogLevelFlags.Warning, logFunc);
                if (args.Length == 0) {
                    Console.WriteLine ("Usage: XmpSample.exe [file list]");
                    System.Environment.Exit (1);
                }

                foreach (string file in args) {
                    Console.WriteLine ("File {0}", file);
                    Exiv2.Image image = Exiv2.ImageFactory.Open (file);
                    image.ReadMetadata ();

                    Console.WriteLine (image.Good);

                    XmpData xmp_data = image.XmpData;
                    if (xmp_data.IsEmpty)
                        Console.WriteLine ("No XMP data found in file");

                    Console.WriteLine ("Xmp count: {0}", xmp_data.Count);

                    foreach (XmpDatum datum in xmp_data)
                        Console.WriteLine ("{0} {1} {2} {3}", datum.Key, datum.Typename, datum.Count, datum.ToString ());

                }

            } catch (GLib.GException e) {
                Console.WriteLine ("Exiv2.Exception caught {0}", e);
            }
        }
Ejemplo n.º 5
0
	static int Main (string [] args)
	{
		bool empty = false;
		Program program = null;
		ICore control = null;
		List<string> uris = new List<string> ();
		Unix.SetProcessName (Defines.PACKAGE);

		// Options and Option parsing
		bool shutdown = false;
		bool view = false;
		bool slideshow = false;
		string import_uri = null;
		
		program = new Program (Defines.PACKAGE, 
				       Defines.VERSION, 
				       Modules.UI, args);		
		
		FSpot.Global.PhotoDirectory = Preferences.Get<string> (Preferences.STORAGE_PATH);

		for (int i = 0; i < args.Length && !shutdown; i++) {
			switch (args [i]) {
			case "-h": case "-?": case "-help": case "--help": case "-usage":
				Help ();
				return 0;
			
			case "-shutdown": case "--shutdown":
				Log.Information ("Shutting down existing F-Spot server...");
				shutdown = true;
				break;

			case "-b": case "-basedir": case "--basedir":
				if (i+1 == args.Length || args[i+1].StartsWith ("-")) {
					Log.Error ("f-spot: -basedir option takes one argument");
					return 1;
				}
				FSpot.Global.BaseDirectory = args [++i];
				Log.InformationFormat ("BaseDirectory is now {0}", FSpot.Global.BaseDirectory);
				break;

			case "-p": case "-photodir": case "--photodir":
				if (i+1 == args.Length || args[i+1].StartsWith ("-")) {
					Log.Error ("f-spot: -photodir option takes one argument");
					return 1;
				}
				FSpot.Global.PhotoDirectory = System.IO.Path.GetFullPath (args [++i]);
				Log.InformationFormat ("PhotoDirectory is now {0}", FSpot.Global.PhotoDirectory);
				break;

			case "-i": case "-import": case "--import":
				if (i+1 == args.Length) {
					Log.Error ("f-spot: -import option takes one argument");
					return 1;
				}
				import_uri = args [++i];
				break;
			
			case "-slideshow": case "--slideshow":
				slideshow = true;
				break;

			case "-v": case "-view": case "--view":
				if (i+1 == args.Length || args[i+1].StartsWith ("-")) {
					Log.Error ("f-spot: -view option takes (at least) one argument");
					return 1;
				}
				view = true;
				while (!(i+1 == args.Length) && !args[i+1].StartsWith ("-"))
					uris.Add (args [++i]);
//				if (!System.IO.Directory.Exists (args[i+1]) && !System.IO.File.Exists (args[i+1])) {
//					Log.Error ("f-spot: -view argument must be an existing file or directory");
//					return 1;
//				}
				break;

			case "-versions": case "--versions":
				Versions ();
				return 0;
			
			case "-V": case "-version": case "--version":
				Version ();
				return 0;
			
			case "--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);

				break;
			case "--uninstalled": case "--gdb":
				break;
			default:
				if (args [i].StartsWith ("--profile"))
					break;
				if (args [i].StartsWith ("--trace"))
					break;
				Log.DebugFormat ("Unparsed argument >>{0}<<", args [i]);
				Help ();
				return 1;
			}
		}

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

		if (slideshow == true) {
			Catalog.Init ("f-spot", Defines.LOCALE_DIR);
				
			Core core = new Core ();
			core.ShowSlides (null);
			program.Run ();
			Log.Debug ("done");
			return 0;
		}
		
		try {

			uint timer = Log.InformationTimerStart ("Initializing DBus");
			try {
				NDesk.DBus.BusG.Init();
			} catch (Exception e) {
				throw new ApplicationException ("F-Spot cannot find the Dbus session bus.  Make sure dbus is configured properly or start a new session for f-spot using \"dbus-launch f-spot\"", e);
			}
			Log.DebugTimerPrint (timer, "DBusInitialization took {0}");
			uint ma_timer = Log.InformationTimerStart ("Initializing Mono.Addins");
			AddinManager.Initialize (FSpot.Global.BaseDirectory);
			AddinManager.Registry.Update (null);
			SetupService setupService = new SetupService (AddinManager.Registry);
			string maj_version = String.Join (".", Defines.VERSION.Split ('.'), 0, 3);
			foreach (AddinRepository repo in setupService.Repositories.GetRepositories ())
				if (repo.Url.StartsWith ("http://addins.f-spot.org/") && !repo.Url.StartsWith ("http://addins.f-spot.org/" + maj_version)) {
					Log.InformationFormat ("Unregistering {0}", repo.Url);
					setupService.Repositories.RemoveRepository (repo.Url);
				}
			setupService.Repositories.RegisterRepository (null, "http://addins.f-spot.org/" + maj_version, false);
			Log.DebugTimerPrint (ma_timer, "Mono.Addins Initialization took {0}");
			
		

			bool create = true;
			int retry_count = 0;
			while (control == null) {
				try {
					control = Core.FindInstance ();
					Log.InformationFormat ("Found active FSpot server: {0}", control);
					program = null;
				} catch (System.Exception) { 
					if (!shutdown)
						Log.Information ("Starting new FSpot server");
				}
				
				Core core = null;
				try {
					if (control == null && create) {
						create = false;
						Gnome.Vfs.Vfs.Initialize ();

						if (File.Exists (Preferences.Get<string> (Preferences.GTK_RC))) {
#if GTK_2_12_2
							if (!File.Exists (Path.Combine (Global.BaseDirectory, "gtkrc")))
								(File.Create (Path.Combine (Global.BaseDirectory, "gtkrc"))).Dispose ();
							Gtk.Rc.AddDefaultFile (Path.Combine (Global.BaseDirectory, "gtkrc"));
							Global.DefaultRcFiles = Gtk.Rc.DefaultFiles;
#endif
							Gtk.Rc.AddDefaultFile (Preferences.Get<string> (Preferences.GTK_RC));
						}
						
						Catalog.Init ("f-spot", Defines.LOCALE_DIR);
						try {
							Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] {
								GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 16, (Gtk.IconLookupFlags)0),
								GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 22, (Gtk.IconLookupFlags)0),
								GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 32, (Gtk.IconLookupFlags)0),
								GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 48, (Gtk.IconLookupFlags)0)
							};
						} catch {}

						core = new Core (view);
						core.RegisterServer ();

						empty = view || Core.Database.Empty;
						control = core;
					}
				} catch (System.Exception e) {
					System.Console.WriteLine ("XXXXX{1}{0}{1}XXXXX", e, Environment.NewLine);
					control = null;

					if (core != null)
						core.UnregisterServer ();

					// if there is a problem with the DB, so is no way we can survive
					if (e is DbException) {
						throw;
					}
				}
				if (control == null) {
					Log.Warning ("Can't get a connection to the dbus. Trying again...");
					if (++ retry_count > 5) {
						Log.Error ("Sorry, couldn't start F-Spot");
						return 1;
					}
				}
			}
			
			
			UriList list = new UriList ();

			if (shutdown) {
				try {
					control.Shutdown ();
				} catch (System.Exception) {
					// trap errors
				}
				System.Environment.Exit (0);
			}

			if (import_uri != null) {
				control.Import (import_uri);
			}

			if (view) {
				foreach (string s in uris)
					list.AddUnknown (s);
				if (list.Count == 0) {
					Help ();
					return 1;
				}
				control.View (list.ToString ());
			}
			
			if (empty && import_uri == null && !view)
				control.Import (null);
			
			if (import_uri != null || !view) {
				control.Organize ();
				Gdk.Global.NotifyStartupComplete ();
				foreach (ServiceNode service in AddinManager.GetExtensionNodes ("/FSpot/Services")) {
					service.Initialize ();
					service.Start ();
				}
			}			

#if GSD_2_24
			Log.Information ("Hack for gnome-settings-daemon engaged");
			int max_age, max_size;
			if (Preferences.TryGet<int> (Preferences.GSD_THUMBS_MAX_AGE, out max_age)) {
				if (max_age < 0)
					Log.Debug ("maximum_age check already disabled, good");
				else if (max_age == 0)
					Log.Warning ("maximum_age is 0 (tin-hat mode), not overriding");
				else if (max_age < 180) {
					Log.Debug ("Setting maximum_age to a saner value");
					Preferences.Set (Preferences.GSD_THUMBS_MAX_AGE, 180);
				}
			}

			if (Preferences.TryGet<int> (Preferences.GSD_THUMBS_MAX_SIZE, out max_size)) {
				int count = Core.Database.Photos.Count ("photos");
				// average thumbs are taking 70K, so this will push the threshold
				//if f-spot takes more than 70% of the thumbs space
				int size = count / 10;
				if (max_size < 0)
					Log.Debug ("maximum_size check already disabled, good");
				else if (max_size == 0)
					Log.Warning ("maximum_size is 0 (tin-hat mode), not overriding");
				else if (max_size < size) {
					Log.DebugFormat ("Setting maximum_size to a saner value ({0}MB), according to your db size", size);
					Preferences.Set (Preferences.GSD_THUMBS_MAX_SIZE, size);
				}
			}

#endif
			if (program != null)
				program.Run ();
			
			Log.Information ("exiting");
		} catch (System.Exception e) {
			Log.Exception (e);
			ExceptionDialog dlg = new ExceptionDialog(e);
			dlg.Run();
			dlg.Destroy();
			System.Environment.Exit(1);
		}
		return 0;
	}
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        static int Main(string [] args)
        {
            bool          empty   = false;
            Program       program = null;
            ICore         control = null;
            List <string> uris    = new List <string> ();

            Unix.SetProcessName(Defines.PACKAGE);

            // Options and Option parsing
            bool   shutdown   = false;
            bool   view       = false;
            bool   slideshow  = false;
            string import_uri = null;

            program = new Program(Defines.PACKAGE,
                                  Defines.VERSION,
                                  Modules.UI, args);

            FSpot.Global.PhotoDirectory = Preferences.Get <string> (Preferences.STORAGE_PATH);

            for (int i = 0; i < args.Length && !shutdown; i++)
            {
                switch (args [i])
                {
                case "-h":
                case "-?":
                case "-help":
                case "--help":
                case "-usage":
                    Help();
                    return(0);

                case "-shutdown":
                case "--shutdown":
                    Log.Information("Shutting down existing F-Spot server...");
                    shutdown = true;
                    break;

                case "-b":
                case "-basedir":
                case "--basedir":
                    if (i + 1 == args.Length || args[i + 1].StartsWith("-"))
                    {
                        Log.Error("f-spot: -basedir option takes one argument");
                        return(1);
                    }
                    FSpot.Global.BaseDirectory = args [++i];
                    Log.InformationFormat("BaseDirectory is now {0}", FSpot.Global.BaseDirectory);
                    break;

                case "-p":
                case "-photodir":
                case "--photodir":
                    if (i + 1 == args.Length || args[i + 1].StartsWith("-"))
                    {
                        Log.Error("f-spot: -photodir option takes one argument");
                        return(1);
                    }
                    FSpot.Global.PhotoDirectory = System.IO.Path.GetFullPath(args [++i]);
                    Log.InformationFormat("PhotoDirectory is now {0}", FSpot.Global.PhotoDirectory);
                    break;

                case "-i":
                case "-import":
                case "--import":
                    if (i + 1 == args.Length)
                    {
                        Log.Error("f-spot: -import option takes one argument");
                        return(1);
                    }
                    import_uri = args [++i];
                    break;

                case "-slideshow":
                case "--slideshow":
                    slideshow = true;
                    break;

                case "-v":
                case "-view":
                case "--view":
                    if (i + 1 == args.Length || args[i + 1].StartsWith("-"))
                    {
                        Log.Error("f-spot: -view option takes (at least) one argument");
                        return(1);
                    }
                    view = true;
                    while (!(i + 1 == args.Length) && !args[i + 1].StartsWith("-"))
                    {
                        uris.Add(args [++i]);
                    }
//				if (!System.IO.Directory.Exists (args[i+1]) && !System.IO.File.Exists (args[i+1])) {
//					Log.Error ("f-spot: -view argument must be an existing file or directory");
//					return 1;
//				}
                    break;

                case "-versions":
                case "--versions":
                    Versions();
                    return(0);

                case "-V":
                case "-version":
                case "--version":
                    Version();
                    return(0);

                case "--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);

                    break;

                case "--uninstalled":
                case "--gdb":
                    break;

                default:
                    if (args [i].StartsWith("--profile"))
                    {
                        break;
                    }
                    if (args [i].StartsWith("--trace"))
                    {
                        break;
                    }
                    Log.DebugFormat("Unparsed argument >>{0}<<", args [i]);
                    Help();
                    return(1);
                }
            }

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

            if (slideshow == true)
            {
                Catalog.Init("f-spot", Defines.LOCALE_DIR);

                Core core = new Core();
                core.ShowSlides(null);
                program.Run();
                Log.Debug("done");
                return(0);
            }

            try {
                uint timer = Log.InformationTimerStart("Initializing DBus");
                try {
                    NDesk.DBus.BusG.Init();
                } catch (Exception e) {
                    throw new ApplicationException("F-Spot cannot find the Dbus session bus.  Make sure dbus is configured properly or start a new session for f-spot using \"dbus-launch f-spot\"", e);
                }
                Log.DebugTimerPrint(timer, "DBusInitialization took {0}");
                uint ma_timer = Log.InformationTimerStart("Initializing Mono.Addins");
                AddinManager.Initialize(FSpot.Global.BaseDirectory);
                AddinManager.Registry.Update(null);
                SetupService setupService = new SetupService(AddinManager.Registry);
                string       maj_version  = String.Join(".", Defines.VERSION.Split('.'), 0, 3);
                foreach (AddinRepository repo in setupService.Repositories.GetRepositories())
                {
                    if (repo.Url.StartsWith("http://addins.f-spot.org/") && !repo.Url.StartsWith("http://addins.f-spot.org/" + maj_version))
                    {
                        Log.InformationFormat("Unregistering {0}", repo.Url);
                        setupService.Repositories.RemoveRepository(repo.Url);
                    }
                }
                setupService.Repositories.RegisterRepository(null, "http://addins.f-spot.org/" + maj_version, false);
                Log.DebugTimerPrint(ma_timer, "Mono.Addins Initialization took {0}");



                bool create      = true;
                int  retry_count = 0;
                while (control == null)
                {
                    try {
                        control = Core.FindInstance();
                        Log.InformationFormat("Found active FSpot server: {0}", control);
                        program = null;
                    } catch (System.Exception) {
                        if (!shutdown)
                        {
                            Log.Information("Starting new FSpot server");
                        }
                    }

                    Core core = null;
                    try {
                        if (control == null && create)
                        {
                            create = false;
                            Gnome.Vfs.Vfs.Initialize();

                            if (File.Exists(Preferences.Get <string> (Preferences.GTK_RC)))
                            {
#if GTK_2_12_2
                                if (!File.Exists(Path.Combine(Global.BaseDirectory, "gtkrc")))
                                {
                                    (File.Create(Path.Combine(Global.BaseDirectory, "gtkrc"))).Dispose();
                                }
                                Gtk.Rc.AddDefaultFile(Path.Combine(Global.BaseDirectory, "gtkrc"));
                                Global.DefaultRcFiles = Gtk.Rc.DefaultFiles;
#endif
                                Gtk.Rc.AddDefaultFile(Preferences.Get <string> (Preferences.GTK_RC));
                            }

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

                            core = new Core(view);
                            core.RegisterServer();

                            empty   = view || Core.Database.Empty;
                            control = core;
                        }
                    } catch (System.Exception e) {
                        System.Console.WriteLine("XXXXX{1}{0}{1}XXXXX", e, Environment.NewLine);
                        control = null;

                        if (core != null)
                        {
                            core.UnregisterServer();
                        }

                        // if there is a problem with the DB, so is no way we can survive
                        if (e is DbException)
                        {
                            throw;
                        }
                    }
                    if (control == null)
                    {
                        Log.Warning("Can't get a connection to the dbus. Trying again...");
                        if (++retry_count > 5)
                        {
                            Log.Error("Sorry, couldn't start F-Spot");
                            return(1);
                        }
                    }
                }


                UriList list = new UriList();

                if (shutdown)
                {
                    try {
                        control.Shutdown();
                    } catch (System.Exception) {
                        // trap errors
                    }
                    System.Environment.Exit(0);
                }

                if (import_uri != null)
                {
                    control.Import(import_uri);
                }

                if (view)
                {
                    foreach (string s in uris)
                    {
                        list.AddUnknown(s);
                    }
                    if (list.Count == 0)
                    {
                        Help();
                        return(1);
                    }
                    control.View(list.ToString());
                }

                if (empty && import_uri == null && !view)
                {
                    control.Import(null);
                }

                if (import_uri != null || !view)
                {
                    control.Organize();
                    Gdk.Global.NotifyStartupComplete();
                    foreach (ServiceNode service in AddinManager.GetExtensionNodes("/FSpot/Services"))
                    {
                        service.Initialize();
                        service.Start();
                    }
                }

#if GSD_2_24
                Log.Information("Hack for gnome-settings-daemon engaged");
                int max_age, max_size;
                if (Preferences.TryGet <int> (Preferences.GSD_THUMBS_MAX_AGE, out max_age))
                {
                    if (max_age < 0)
                    {
                        Log.Debug("maximum_age check already disabled, good");
                    }
                    else if (max_age == 0)
                    {
                        Log.Warning("maximum_age is 0 (tin-hat mode), not overriding");
                    }
                    else if (max_age < 180)
                    {
                        Log.Debug("Setting maximum_age to a saner value");
                        Preferences.Set(Preferences.GSD_THUMBS_MAX_AGE, 180);
                    }
                }

                if (Preferences.TryGet <int> (Preferences.GSD_THUMBS_MAX_SIZE, out max_size))
                {
                    int count = Core.Database.Photos.Count("photos");
                    // average thumbs are taking 70K, so this will push the threshold
                    //if f-spot takes more than 70% of the thumbs space
                    int size = count / 10;
                    if (max_size < 0)
                    {
                        Log.Debug("maximum_size check already disabled, good");
                    }
                    else if (max_size == 0)
                    {
                        Log.Warning("maximum_size is 0 (tin-hat mode), not overriding");
                    }
                    else if (max_size < size)
                    {
                        Log.DebugFormat("Setting maximum_size to a saner value ({0}MB), according to your db size", size);
                        Preferences.Set(Preferences.GSD_THUMBS_MAX_SIZE, size);
                    }
                }
#endif
                if (program != null)
                {
                    program.Run();
                }

                Log.Information("exiting");
            } catch (System.Exception e) {
                Log.Exception(e);
                ExceptionDialog dlg = new ExceptionDialog(e);
                dlg.Run();
                dlg.Destroy();
                System.Environment.Exit(1);
            }
            return(0);
        }
Ejemplo n.º 8
0
Archivo: main.cs Proyecto: hbons/f-spot
        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);
            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 (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;
        }
Ejemplo n.º 9
0
        static int Main(string [] args)
        {
            bool empty = false;
            List<string> uris = new List<string> ();
            Unix.SetProcessName (Defines.PACKAGE);

            // Options and Option parsing
            bool shutdown = false;
            bool view = false;
            bool slideshow = false;
            string import_uri = null;

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

            FSpot.Global.PhotoDirectory = Preferences.Get<string> (Preferences.STORAGE_PATH);
            for (int i = 0; i < args.Length && !shutdown; i++) {
                switch (args [i]) {
                case "-h": case "-?": case "-help": case "--help": case "-usage":
                    Help ();
                    return 0;

                case "-shutdown": case "--shutdown":
                    Log.Information ("Shutting down existing F-Spot server...");
                    shutdown = true;
                    break;

                case "-b": case "-basedir": case "--basedir":
                    if (i+1 == args.Length || args[i+1].StartsWith ("-")) {
                        Log.Error ("f-spot: -basedir option takes one argument");
                        return 1;
                    }
                    FSpot.Global.BaseDirectory = args [++i];
                    Log.Information ("BaseDirectory is now {0}", FSpot.Global.BaseDirectory);
                    break;

                case "-p": case "-photodir": case "--photodir":
                    if (i+1 == args.Length || args[i+1].StartsWith ("-")) {
                        Log.Error ("f-spot: -photodir option takes one argument");
                        return 1;
                    }
                    FSpot.Global.PhotoDirectory = System.IO.Path.GetFullPath (args [++i]);
                    Log.Information ("PhotoDirectory is now {0}", FSpot.Global.PhotoDirectory);
                    break;

                case "-i": case "-import": case "--import":
                    if (i+1 == args.Length) {
                        Log.Error ("f-spot: -import option takes one argument");
                        return 1;
                    }
                    import_uri = args [++i];
                    break;

                case "-slideshow": case "--slideshow":
                    slideshow = true;
                    break;

                case "-v": case "-view": case "--view":
                    if (i+1 == args.Length || args[i+1].StartsWith ("-")) {
                        Log.Error ("f-spot: -view option takes (at least) one argument");
                        return 1;
                    }
                    view = true;
                    while (!(i+1 == args.Length) && !args[i+1].StartsWith ("-"))
                        uris.Add (args [++i]);
            //				if (!System.IO.Directory.Exists (args[i+1]) && !System.IO.File.Exists (args[i+1])) {
            //					Log.Error ("f-spot: -view argument must be an existing file or directory");
            //					return 1;
            //				}
                    break;

                case "-versions": case "--versions":
                    Versions ();
                    return 0;

                case "-V": case "-version": case "--version":
                    Version ();
                    return 0;

                case "--strace":
                    Log.Tracing = true;
                    break;

                case "--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);

                    break;
                case "--uninstalled": case "--gdb": case "--valgrind": case "--sync":
                    break;
                default:
                    if (args [i].StartsWith ("--profile"))
                        break;
                    if (args [i].StartsWith ("--trace"))
                        break;
                    Log.Debug ("Unparsed argument >>{0}<<", args [i]);
                    break;
                }
            }

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

            //Initialize Mono.Addins
            uint timer = Log.InformationTimerStart ("Initializing Mono.Addins");
            AddinManager.Initialize (FSpot.Global.BaseDirectory);
            AddinManager.Registry.Update (null);
            SetupService setupService = new SetupService (AddinManager.Registry);
            string maj_version = String.Join (".", Defines.VERSION.Split ('.'), 0, 3);
            foreach (AddinRepository repo in setupService.Repositories.GetRepositories ())
                if (repo.Url.StartsWith ("http://addins.f-spot.org/") && !repo.Url.StartsWith ("http://addins.f-spot.org/" + maj_version)) {
                    Log.Information ("Unregistering {0}", repo.Url);
                    setupService.Repositories.RemoveRepository (repo.Url);
                }
            setupService.Repositories.RegisterRepository (null, "http://addins.f-spot.org/" + maj_version, false);
            Log.DebugTimerPrint (timer, "Mono.Addins Initialization took {0}");

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

            // 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 (FSpot.Global.IconTheme, "f-spot", 16, (Gtk.IconLookupFlags)0),
                    GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 22, (Gtk.IconLookupFlags)0),
                    GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 32, (Gtk.IconLookupFlags)0),
                    GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 48, (Gtk.IconLookupFlags)0)
                };
            } catch {}

            try {
                if (slideshow == true) {
                    App.Instance.Slideshow (null);
                } else if (shutdown) {
                    try {
                        App.Instance.Shutdown ();
                    } catch (System.Exception) { // trap errors
                    }
                    System.Environment.Exit (0);
                } else if (view) {
                    UriList list = new UriList ();
                    foreach (string s in uris)
                        list.AddUnknown (s);
                    if (list.Count == 0) {
                        Help ();
                        return 1;
                    }
                    App.Instance.View (list);
                } else if (import_uri != null) {
                    App.Instance.Import (import_uri);
                } else {
                    App.Instance.Organize ();
                }

                if (App.Instance.IsRunning)
                    return 0;
                Gtk.Application.Run ();
            } catch (System.Exception e) {
                Log.Exception (e);
                ExceptionDialog dlg = new ExceptionDialog(e);
                dlg.Run();
                dlg.Destroy();
                System.Environment.Exit(1);
            }
            return 0;
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        static void Main(string [] args)
        {
            try {

                GLib.GType.Init ();

                GLib.LogFunc logFunc = new GLib.LogFunc (GLib.Log.PrintTraceLogFunction);
                GLib.Log.SetLogHandler ("GLib", GLib.LogLevelFlags.Critical, logFunc);
                GLib.Log.SetLogHandler ("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc);
                GLib.Log.SetLogHandler ("GLib-GObject", GLib.LogLevelFlags.Warning, logFunc);

                if (args.Length != 1) {
                    Console.WriteLine ("Usage: AddModel.exe file");
                    System.Environment.Exit (1);
                }

                // Container for exif metadata. This is an example of creating
                // exif metadata from scratch. If you want to add, modify, delete
                // metadata that exists in an image, start with ImageFactory.Open
                ExifData exifData = new ExifData ();

                //Add to the Exif data

                // This is the quickest way to add (simple) Exif data. If a metadatum for
                // a given key already exists, its value is overwritten. Otherwise a new
                // tag is added.
                exifData["Exif.Image.Model"] = "Test 1";				// AsciiValue
                exifData["Exif.Image.SamplesPerPixel"] = (UInt16)162;			// UShortValue
                exifData["Exif.Image.XResolution"] = (Int32)(-2);			// LongValue
                exifData["Exif.Image.YResolution"] = new Exiv2.Rational (-2, 3);	// RationalValue
                exifData["Exif.Photo.DateTimeOriginal"] = "1999:12:31 23:59:59";	// AsciiValue
                Console.WriteLine ("Added a few tags the quick way.");

                // Modify Exif data

                // Since we know that the metadatum exists (or we don't mind creating a new
                // tag if it doesn't), we can simply do this:
                ExifDatum tag = exifData["Exif.Photo.DateTimeOriginal"] as ExifDatum;
                string date = tag.ToString ();
                date = "2000" + ((date.Length > 4) ? date.Substring (4) : null);
                tag.Value = date;
                Console.WriteLine ("Modified key '{0}', new value '{1}'", tag.Key, tag.ToString ());

            //				tag.setValue(date);
            //				std::cout << "Modified key \"" << key
            //				          << "\", new value \"" << tag.value() << "\"\n";
            //
            //				// Alternatively, we can use findKey()
            //				key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities");
            //				Exiv2::ExifData::iterator pos = exifData.findKey(key);
            //				if (pos == exifData.end()) throw Exiv2::Error(1, "Key not found");
            //				// Get a pointer to a copy of the value
            //				v = pos->getValue();
            //				// Downcast the Value pointer to its actual type
            //				Exiv2::URationalValue* prv = dynamic_cast<Exiv2::URationalValue*>(v.release());
            //				if (prv == 0) throw Exiv2::Error(1, "Downcast failed");
            //				rv = Exiv2::URationalValue::AutoPtr(prv);
            //				// Modify the value directly through the interface of URationalValue
            //				rv->value_[2] = std::make_pair(88,77);
            //				// Copy the modified value back to the metadatum
            //				pos->setValue(rv.get());
            //				std::cout << "Modified key \"" << key
            //				          << "\", new value \"" << pos->value() << "\"\n";

                exifData.Erase (new ExifKey("Exif.Image.XResolution"));

                //Finally, write the remaining data to the image file
                Exiv2.Image image = ImageFactory.Open (args [0]);
                image.ExifData = exifData;
                image.WriteMetadata ();

            } catch (GLib.GException e) {
                Console.WriteLine ("caught a GException {0}", e);
            }
        }