[gnome-boxes] Add options parsing



commit e22a1fbcc2c3ad3c66cdb14df28378fd577055e0
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Wed Oct 5 22:29:54 2011 +0200

    Add options parsing
    
    Split boxes.vala in app.vala and main.vala

 Makefile.am                  |   40 ++++++++++++++++----------
 configure.ac                 |    1 +
 src/Makefile.am              |    7 +++-
 src/{boxes.vala => app.vala} |   25 ----------------
 src/main.vala                |   63 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 93 insertions(+), 43 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index f771f2f..51ba3c5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,22 +3,25 @@ NULL =
 
 SUBDIRS = data src po
 
-INTLTOOL_FILES = intltool-extract.in		\
-		 intltool-merge.in		\
-		 intltool-update.in		\
-		 $(NULL)
-
-DISTCLEANFILES = intltool-extract		\
-		 intltool-merge			\
-		 intltool-update		\
-		 gnome-doc-utils.make		\
-		 po/.intltool-merge-cache	\
-		 $(NULL)
-
-EXTRA_DIST = build-aux/git-version-gen		\
-	     .version				\
-	     $(INTLTOOL_FILES)			\
-	     $(NULL)
+INTLTOOL_FILES =				\
+	intltool-extract.in			\
+	intltool-merge.in			\
+	intltool-update.in			\
+	$(NULL)
+
+DISTCLEANFILES =				\
+	intltool-extract			\
+	intltool-merge				\
+	intltool-update				\
+	gnome-doc-utils.make			\
+	po/.intltool-merge-cache		\
+	$(NULL)
+
+EXTRA_DIST =					\
+	build-aux/git-version-gen		\
+	.version				\
+	$(INTLTOOL_FILES)			\
+	$(NULL)
 
 MAINTAINERCLEANFILES =				\
 	ABOUT-NLS				\
@@ -45,4 +48,9 @@ BUILT_SOURCES = $(top_srcdir)/.version
 $(top_srcdir)/.version:
 	echo $(VERSION) > $ -t && mv $ -t $@
 
+all: version.h
+
+version.h: $(top_srcdir)/.version
+	echo '#define BUILD_VERSION "'`cat $(top_srcdir)/.version`'"' > $ -t && mv $ -t $@
+
 -include $(top_srcdir)/git.mk
diff --git a/configure.ac b/configure.ac
index da6db7a..b1d6fdc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -60,6 +60,7 @@ VALA_CHECK_PACKAGES([
   gdk-pixbuf-2.0
   glib-2.0
   libxml-2.0
+  cogl-1.0
 ])
 
 AC_CONFIG_FILES([
diff --git a/src/Makefile.am b/src/Makefile.am
index f73c535..3c63eba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,7 +9,9 @@ AM_VALAFLAGS =						\
 	--vapidir=$(srcdir)/				\
 	--vapidir=$(top_srcdir)/vapi                    \
 	--pkg clutter-gtk-1.0				\
+	--pkg cogl-1.0					\
 	--pkg config					\
+	--pkg posix					\
 	--pkg gdk-pixbuf-2.0				\
 	--pkg glib-2.0					\
 	--pkg libvirt-gobject-1.0			\
@@ -19,11 +21,12 @@ AM_VALAFLAGS =						\
 
 bin_PROGRAMS = gnome-boxes
 
-gnome_boxes_SOURCES =					\
+gnome_boxes_SOURCES =				\
+	app.vala				\
 	box.vala				\
-	boxes.vala				\
 	collection-view.vala			\
 	collection.vala				\
+	main.vala				\
 	sidebar.vala				\
 	spice-display.vala			\
 	topbar.vala				\
diff --git a/src/boxes.vala b/src/app.vala
similarity index 86%
rename from src/boxes.vala
rename to src/app.vala
index c5acabc..ed7db6f 100644
--- a/src/boxes.vala
+++ b/src/app.vala
@@ -41,31 +41,6 @@ private class Boxes.App: Boxes.UI {
     private Topbar topbar;
     private CollectionView view;
 
-    public static void main (string[] args) {
-        Intl.bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
-        Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-        Intl.textdomain (GETTEXT_PACKAGE);
-        GLib.Environment.set_application_name (_("GNOME Boxes"));
-
-        GtkClutter.init (ref args);
-
-        Gtk.Window.set_default_icon_name ("gnome-boxes");
-        Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
-        var provider = new Gtk.CssProvider ();
-        try {
-            var sheet = get_style ("gtk-style.css");
-            provider.load_from_path (sheet);
-            Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
-                                                      provider,
-                                                      600);
-        } catch (GLib.Error e) {
-            warning (e.message);
-        }
-
-        new App ();
-        Gtk.main ();
-    }
-
     public App () {
         setup_ui ();
         collection = new Collection ();
diff --git a/src/main.vala b/src/main.vala
new file mode 100644
index 0000000..0f0ea22
--- /dev/null
+++ b/src/main.vala
@@ -0,0 +1,63 @@
+// This file is part of GNOME Boxes. License: LGPLv2
+using Config;
+using Posix;
+
+private static bool version;
+
+private const OptionEntry[] options = {
+    { "version", 0, 0, OptionArg.NONE, ref version, "Display version number", null },
+    { null }
+};
+
+private static void parse_args (ref unowned string[] args) {
+    var parameter_string = "- " + PACKAGE_TARNAME;
+    var opt_context = new OptionContext (parameter_string);
+    opt_context.set_help_enabled (true);
+    opt_context.set_ignore_unknown_options (true);
+    opt_context.add_main_entries (options, null);
+    opt_context.add_group (Gtk.get_option_group (true));
+    opt_context.add_group (Cogl.get_option_group ());
+    opt_context.add_group (Clutter.get_option_group_without_init ());
+    opt_context.add_group (GtkClutter.get_option_group ());
+
+    try {
+        opt_context.parse (ref args);
+    } catch (OptionError.BAD_VALUE err) {
+        GLib.stdout.printf (opt_context.get_help (true, null));
+        exit (1);
+    } catch (OptionError e) {
+        warning (e.message);
+    }
+
+    if (version) {
+        GLib.stdout.printf ("%s\n", Config.BUILD_VERSION);
+        exit (0);
+    }
+}
+
+public void main (string[] args) {
+    Intl.bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+    Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    Intl.textdomain (GETTEXT_PACKAGE);
+    GLib.Environment.set_application_name (_("GNOME Boxes"));
+
+    GtkClutter.init (ref args);
+    parse_args (ref args);
+
+    Gtk.Window.set_default_icon_name ("gnome-boxes");
+    Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
+    var provider = new Gtk.CssProvider ();
+    try {
+        var sheet = Boxes.get_style ("gtk-style.css");
+        provider.load_from_path (sheet);
+        Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
+                                                  provider,
+                                                  600);
+    } catch (GLib.Error e) {
+        warning (e.message);
+    }
+
+    new Boxes.App ();
+    Gtk.main ();
+}
+



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