Index: ChangeLog =================================================================== RCS file: /cvs/gnome/f-spot/ChangeLog,v retrieving revision 1.1723 diff -u -p -r1.1723 ChangeLog --- ChangeLog 20 Nov 2006 15:13:18 -0000 1.1723 +++ ChangeLog 21 Nov 2006 15:01:14 -0000 @@ -1,3 +1,10 @@ +2006-11-21 Stephane Delcroix + + * configure.in: check for Mono.GetOptions.dll + * src/Makefile.am: compile with -r:Mono.GetOptions + * src/AssemblyInfo.cs.in: add some attributes for Mono.GetOptions + * src/main.cs: use Mono.GetOptions to parse commandline arguments + 2006-11-20 Stephane Delcroix * google-sharp/PicasaWeb.cs: quick fix for picasa (new|broken) Index: configure.in =================================================================== RCS file: /cvs/gnome/f-spot/configure.in,v retrieving revision 1.120 diff -u -p -r1.120 configure.in --- configure.in 18 Nov 2006 19:51:55 -0000 1.120 +++ configure.in 21 Nov 2006 15:01:14 -0000 @@ -37,7 +37,7 @@ fi dnl -- check for various mono DLLs that we need. -needed_dlls="Mono.Data.SqliteClient Mono.Posix System.Runtime.Remoting System.Web System.Web.Services" +needed_dlls="Mono.Data.SqliteClient Mono.Posix System.Runtime.Remoting System.Web System.Web.Services Mono.GetOptions" for i in $needed_dlls; do AC_MSG_CHECKING([for $i.dll]) if test ! -e `$PKG_CONFIG --variable=prefix mono`/lib/mono/2.0/$i.dll; then Index: src/AssemblyInfo.cs.in =================================================================== RCS file: /cvs/gnome/f-spot/src/AssemblyInfo.cs.in,v retrieving revision 1.1 diff -u -p -r1.1 AssemblyInfo.cs.in --- src/AssemblyInfo.cs.in 29 Aug 2006 01:58:59 -0000 1.1 +++ src/AssemblyInfo.cs.in 21 Nov 2006 15:01:15 -0000 @@ -10,4 +10,9 @@ using System.Reflection; using System.Runtime.CompilerServices; [assembly: AssemblyVersion("@VERSION@")] - +[assembly: AssemblyTitle ("F-Spot")] +[assembly: AssemblyCopyright ("(c)2003-2006, Novell Inc")] +[assembly: AssemblyDescription ("Personal photo management for the GNOME Desktop")] +[assembly: Mono.UsageComplement ("")] +[assembly: Mono.About ("F-Spot is a full-featured personal photo management application for the GNOME desktop (http://www.gnome.org/). \nF-Spot simplifies digital photography by providing intuitive tools to help you share, touch-up, find and organize your images.")] +[assembly: Mono.Author ("Larry Ewing and others")] Index: src/Makefile.am =================================================================== RCS file: /cvs/gnome/f-spot/src/Makefile.am,v retrieving revision 1.85 diff -u -p -r1.85 Makefile.am --- src/Makefile.am 16 Nov 2006 23:49:23 -0000 1.85 +++ src/Makefile.am 21 Nov 2006 15:01:15 -0000 @@ -186,6 +186,7 @@ ASSEMBLIES = \ -r:System.Data \ -r:System.Web \ -r:Mono.Data.SqliteClient \ + -r:Mono.GetOptions \ -r:Mono.Posix \ -r:Mono.Security \ -r:ICSharpCode.SharpZipLib \ Index: src/main.cs =================================================================== RCS file: /cvs/gnome/f-spot/src/main.cs,v retrieving revision 1.46 diff -u -p -r1.46 main.cs --- src/main.cs 16 Nov 2006 22:58:56 -0000 1.46 +++ src/main.cs 21 Nov 2006 15:01:15 -0000 @@ -6,72 +6,70 @@ using System.Runtime.InteropServices; using System.Text; using System.Collections; using Mono.Unix; +using Mono.GetOptions; namespace FSpot { - -public class Driver { - - private static void HelpMsg(string [] args) + public class FSpotOptions : Options { - Catalog.Init ("f-spot", Defines.LOCALE_DIR); + //--import, -i + [Option ("import from the given uri", 'i', "import")] + public string import; + + //--view, -v + [Option ("view file(s) or directory(ies)", 'v', "view")] + public bool view; + + //--basedir, -b + [Option ("path to the photo database folder", 'b', "basedir")] + public string basedir; + + //--photodir, -p + [Option ("default import folder", 'p', "photodir")] + public string photodir; + + //--shutdown + [Option ("shutdown a running f-spot instance", "shutdown")] + public bool shutdown; + + //--slideshow + [Option ("display a slideshow", "slideshow")] + public bool slideshow; + + //--debug, -g + [Option ("run f-spot with mono on debug mode", 'g', "debug")] + public bool debug; + + public FSpotOptions () + { + base.ParsingMode = OptionsParsingMode.Both; + } - System.Console.WriteLine ("Usage: f-spot [--basedir ] | [--photodir ] | [--debug]"); - System.Console.WriteLine ("\t\t [ --import | --view |"); - System.Console.WriteLine ("\t\t\t--shutdown | --slideshow | --help ]"); - System.Console.WriteLine (""); - - System.Console.WriteLine (" --import [uri]\t\t\timport from the given uri"); - System.Console.WriteLine (" --view \t\tview some files or directories (one or more)"); - System.Console.WriteLine (" --basedir \t\t\t where the photo database is located "); - System.Console.WriteLine (" --photodir \t\timport (copy) photos to "); - System.Console.WriteLine (" --shutdown\t\t\t\tshutdown a running f-spot server"); - System.Console.WriteLine (" --slideshow\t\t\t\tdisplay a slideshow"); - System.Console.WriteLine (" --debug\t\t\t\trun f-spot with mono in debug mode"); - System.Console.WriteLine (" --help\t\t\t\tview this message"); - } - - private static bool ValidateCmds(string [] args) - { - string [] restricted_cmds = new string [] {"--slideshow", "--import", "--shutdown", "--view"}; - string [] valid_cmds = new string [] {"--import", "--view", "--basedir", "--photodir", - "--shutdown", "--slideshow", "--debug", "--help", "--uninstalled"}; - string [] single_cmds = new string [] {"--shutdown", "--help"}; - string [] parameter_cmds = new string [] {"--import", "--view", "--basedir", "--photodir"}; - - - bool valid_cmd = true; - int number_of_restricted_cmds = 0; - for (int k=0; k< args.Length; k++) { - string arg = args[k]; - // Only check commands - if (!arg.StartsWith("--")) - continue; - // Only one restricted cmd is allowed - if (System.Array.IndexOf (restricted_cmds, arg) > 0) - number_of_restricted_cmds++; - // These commands has to be by itself - if ( (System.Array.IndexOf (single_cmds, arg) > 0) && (args.Length != 1) ) - valid_cmd = false; - // Unknow command is not allowed - if (System.Array.IndexOf (valid_cmds, arg) < 0) - valid_cmd = false; - // Command with a parameter has to have a parameter - if (System.Array.IndexOf (parameter_cmds, arg) > 0) { - if ( (k+1 == args.Length) || (args[k+1].StartsWith ("--")) ) - valid_cmd = false; + public bool Validate () + { + if ( (import != null && (view || shutdown || slideshow)) || + (view && (shutdown || slideshow)) || + (shutdown && slideshow) ) { + Console.WriteLine ("Can't mix --import, --view, --shutdown or --slideshow"); + return false; + } + if (view && RemainingArguments.Length == 0) { + Console.WriteLine ("Need to specify at least one uri for --view"); + return false; } + foreach (string s in RemainingArguments) + if (s.StartsWith("-")) { + Console.WriteLine ("Unknown option {0}", s); + return false; + } + return true; } - valid_cmd = valid_cmd && (number_of_restricted_cmds < 2); - - return valid_cmd; } - + +public class Driver { public static void Main (string [] args) { - bool view_only = false; - bool import = false; bool empty = false; Program program = null; ICore control = null; @@ -80,31 +78,37 @@ public class Driver { NDesk.DBus.BusG.Init(); try { - if (!ValidateCmds(args)) { - System.Console.WriteLine ("Invalid argument list. Please review the arguments and try again."); - System.Console.WriteLine (""); - HelpMsg(args); + FSpotOptions options = new FSpotOptions (); + options.ProcessArgs (args); + + if (!options.Validate ()) { + options.DoHelp (); return; } - - foreach (string arg in args) { - if (arg == "--help") { - HelpMsg(args); - return; - } else if (arg == "--slideshow") { - Catalog.Init ("f-spot", Defines.LOCALE_DIR); - - program = new Program (Defines.PACKAGE, - Defines.VERSION, - Modules.UI, args); - Core core = new Core (); - core.ShowSlides (null); - program.Run (); - System.Console.WriteLine ("done"); - return; - } + + if (options.basedir != null) { + FSpot.Global.BaseDirectory = options.basedir; + System.Console.WriteLine("BaseDirectory is now {0}", FSpot.Global.BaseDirectory); + } + + if (options.photodir != null) { + FSpot.Global.PhotoDirectory = System.IO.Path.GetFullPath(options.photodir); + System.Console.WriteLine("PhotoDirectory is now {0}", FSpot.Global.PhotoDirectory); } - + + if (options.slideshow) { + Catalog.Init ("f-spot", Defines.LOCALE_DIR); + + program = new Program (Defines.PACKAGE, + Defines.VERSION, + Modules.UI, args); + Core core = new Core (); + core.ShowSlides (null); + program.Run (); + System.Console.WriteLine ("done"); + return; + } + /* * FIXME we need to inialize gobject before making the dbus calls, we'll go * ahead and do it like this for now. @@ -120,28 +124,10 @@ public class Driver { System.Console.WriteLine ("Found active FSpot server: {0}", control); program = null; } catch (System.Exception) { - if (System.Array.IndexOf (args, "--shutdown") == 0) + if (!options.shutdown) System.Console.WriteLine ("Starting new FSpot server"); } - // Process this before creating the Core - for (int i = 0; i < args.Length; i++) { - switch (args[i]) { - case "--basedir": - if (++i < args.Length) { - FSpot.Global.BaseDirectory = args [i]; - System.Console.WriteLine("BaseDirectory is now {0}", args[i]); - } - break; - case "--photodir": - if (++i < args.Length) { - FSpot.Global.PhotoDirectory = System.IO.Path.GetFullPath(args [i]); - System.Console.WriteLine("PhotoDirectory is now {0}", System.IO.Path.GetFullPath(args[i])); - } - break; - } - } - Core core = null; try { if (control == null && create) { @@ -173,41 +159,31 @@ public class Driver { UriList list = new UriList (); - for (int i = 0; i < args.Length; i++) { - switch (args [i]) { - case "--shutdown": - try { - control.Shutdown (); - } catch (System.Exception) { - // trap errors - } - System.Environment.Exit (0); - break; - case "--import": - if (++i < args.Length) - control.Import (args [i]); - - import = true; - break; - case "--view": - while (++i < args.Length) { - if (args[i].StartsWith ("--")) - break; - list.AddUnknown (args [i]); - } - - if (list.Count > 0) - control.View (list.ToString ()); - view_only = true; - break; + if (options.shutdown) { + try { + control.Shutdown (); + } catch (System.Exception) { + // trap errors } + System.Environment.Exit (0); + } + + if (options.import != null) { + control.Import (options.import); + } + + if (options.view) { + foreach (string s in options.RemainingArguments) + list.AddUnknown (s); + if (list.Count > 0) + control.View (list.ToString ()); } - if (empty && !import) + if (empty && options.import == null) control.Import (null); - if (import || !view_only) { + if (options.import != null || !options.view) { control.Organize (); Gdk.Global.NotifyStartupComplete (); }