[ease] Add GOption command line parsing.



commit 482c3a33e15bdd1947635fead9c0c1ddb7ca1b73
Author: Nate Stedman <natesm gmail com>
Date:   Fri May 28 22:25:55 2010 -0400

    Add GOption command line parsing.

 src/Main.vala |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 60 insertions(+), 6 deletions(-)
---
diff --git a/src/Main.vala b/src/Main.vala
index b873e67..29e9ea7 100644
--- a/src/Main.vala
+++ b/src/Main.vala
@@ -29,7 +29,19 @@ public static class Ease.Main : GLib.Object
 {
 	private static Gee.ArrayList<EditorWindow> windows;
 	private static WelcomeWindow welcome;
-
+	
+	// options
+	static string play_filename;
+	static string[] filenames;
+	
+	private const OptionEntry[] options = {
+		{ "play", 'p', 0, OptionArg.FILENAME, ref play_filename,
+		   "Play the specified file", "FILE" },
+		{ "", 0, 0, OptionArg.FILENAME_ARRAY, ref filenames, null, "FILE..." },
+		{ null } };
+	
+	private static Player player;
+	
 	/**
 	 * Start Ease to edit files.
 	 * 
@@ -41,7 +53,29 @@ public static class Ease.Main : GLib.Object
 	 */
 	public static int main(string[] args)
 	{
-		GtkClutter.init(ref args);
+		// parse command line options
+		var context = new OptionContext(_(" - a presentation editor"));
+		
+		// TODO: set translation
+		context.add_main_entries(options, null);
+
+		// add library option groups
+		context.add_group(Gtk.get_option_group(true));
+		context.add_group(Clutter.get_option_group());
+		
+		try
+		{
+			if (!context.parse(ref args))
+			{
+				return 1;
+			}
+		}
+		catch (OptionError e)
+		{
+			stdout.printf(_("error parsing options: %s\n"), e.message);
+			return 1;
+		}
+	
 		ClutterGst.init(ref args);
 
 		// initalize static classes
@@ -49,12 +83,32 @@ public static class Ease.Main : GLib.Object
 		OpenDialog.init();
 		windows = new Gee.ArrayList<EditorWindow>();
 	
-		// TODO: non-awful args handling
-		if (args.length == 2)
+		// open editor windows for each argument specified
+		if (filenames != null)
 		{
-			test_editor(args[1]);
+			for (int i = 0; filenames[i] != null; i++)
+			{
+				test_editor(filenames[i]);
+			}
 		}
-		else
+		
+		// if --play is specified, play the presentation
+		if (play_filename != null)
+		{
+			var doc = new Document.from_file(play_filename);
+			player = new Player(doc);
+			
+			// if no editor windows are specified, quit when done
+			if (filenames == null)
+			{
+				player.stage.hide.connect(() => {
+					Gtk.main_quit();
+				});
+			}
+		}
+		
+		// if no files are given, show the new presentation window
+		if (filenames == null && play_filename == null)
 		{
 			show_welcome();
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]