[cheese] Use new GApplicationCommandline handling



commit 9697f05e2c0ce03b96791ec2fa9b993c4c505164
Author: David King <amigadave amigadave com>
Date:   Mon Mar 10 20:19:20 2014 +0000

    Use new GApplicationCommandline handling
    
    Additionally, avoid a non-literal format warning.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725994

 configure.ac                |    4 +-
 src/cheese-application.vala |  105 ++++++++++++-------------------------------
 2 files changed, 31 insertions(+), 78 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3bc1d9d..0d32e64 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@ AM_SILENT_RULES([yes])
 # Check for programs
 AC_PROG_CC
 AM_PROG_CC_C_O
-AM_PROG_VALAC([0.22.0])
+AM_PROG_VALAC([0.23.3])
 
 # Initialize libtool
 LT_PREREQ([2.2])
@@ -56,7 +56,7 @@ IT_PROG_INTLTOOL([0.50.0])
 #*******************************************************************************
 
 
-GLIB_REQUIRED="glib-2.0 >= 2.38.0"
+GLIB_REQUIRED="glib-2.0 >= 2.39.90"
 GTK_REQUIRED="gtk+-3.0 >= 3.10.0"
 GDK_PIXBUF_REQUIRED="gdk-pixbuf-2.0"
 LIBGNOMEDESKTOP_REQUIRED="gnome-desktop-3.0 >= 2.91.6"
diff --git a/src/cheese-application.vala b/src/cheese-application.vala
index 4c30afd..7c20821 100644
--- a/src/cheese-application.vala
+++ b/src/cheese-application.vala
@@ -28,10 +28,7 @@ public class Cheese.Application : Gtk.Application
 {
     private GLib.Settings settings;
 
-    static bool wide;
     static string device;
-    static bool version;
-    static bool fullscreen;
 
     static MainWindow main_window;
 
@@ -52,20 +49,23 @@ public class Cheese.Application : Gtk.Application
     };
 
     const OptionEntry[] options = {
-        { "wide", 'w', 0, OptionArg.NONE, ref wide, N_("Start in wide mode"),
+        { "wide", 'w', 0, OptionArg.NONE, null, N_("Start in wide mode"),
           null  },
-        { "device", 'd', 0, OptionArg.FILENAME, ref device,
+        { "device", 'd', 0, OptionArg.FILENAME, null,
           N_("Device to use as a camera"), N_("DEVICE") },
-        { "version", 'v', 0, OptionArg.NONE, ref version,
+        { "version", 'v', 0, OptionArg.NONE, null,
           N_("Output version information and exit"), null },
-        { "fullscreen", 'f', 0, OptionArg.NONE, ref fullscreen,
+        { "fullscreen", 'f', 0, OptionArg.NONE, null,
           N_("Start in fullscreen mode"), null },
         { null }
     };
 
     public Application ()
     {
-        GLib.Object (application_id: "org.gnome.Cheese");
+        GLib.Object (application_id: "org.gnome.Cheese",
+                     flags: ApplicationFlags.HANDLES_COMMAND_LINE);
+
+        this.add_main_option_entries (options);
     }
 
     /**
@@ -152,87 +152,40 @@ public class Cheese.Application : Gtk.Application
         }
     }
 
-    /**
-     * Overridden method of GApplication, to handle the arguments locally.
-     *
-     * @param arguments the command-line arguments
-     * @param exit_status the exit status to return to the OS
-     * @return true if the arguments were successfully processed, false
-     * otherwise
-     */
-    protected override bool local_command_line ([CCode (array_null_terminated = true, array_length = false)]
-                                                ref unowned string[] argv,
-                                                out int exit_status)
+    protected override int command_line (ApplicationCommandLine cl)
     {
-        // Try to register.
-        try
+        var opts = cl.get_options_dict ();
+
+        if (opts.lookup ("device", "^ay", out device, null))
         {
-            register ();
+            settings.set_string ("camera", device);
         }
-        catch (Error e)
+
+        if (opts.contains ("fullscreen"))
         {
-            warning ("Unable to register application: %s", e.message);
-            exit_status = 1;
-            return true;
+            activate_action ("fullscreen", null);
         }
 
-        // Workaround until bug 642885 is solved.
-        unowned string[] arguments = argv;
-        var n_args = arguments.length;
-
-        if (n_args <= 1)
+        if (opts.contains ("wide"))
         {
-            activate ();
-            exit_status = 0;
+            activate_action ("wide-mode", null);
         }
-        else
-        {
-            try
-            {
-                var context = new OptionContext (_("- Take photos and videos from your webcam"));
-                context.set_translation_domain (Config.GETTEXT_PACKAGE);
-                context.set_help_enabled (true);
-                context.add_main_entries (options, null);
-                context.parse (ref arguments);
-            }
-            catch (OptionError e)
-            {
-                warning ("%s", e.message);
-                stdout.printf (_("Run '%s --help' to see a full list of available command line options."),
-                               arguments[0]);
-                stdout.printf ("\n");
-                exit_status = 1;
-                return true;
-            }
 
-            if (version)
-            {
-                stdout.printf ("%s %s\n", Config.PACKAGE_NAME,
-                               Config.PACKAGE_VERSION);
-                exit_status = 1;
-                return true;
-            }
-
-            if (device != null)
-            {
-                settings.set_string ("camera", device);
-            }
-
-            if (fullscreen)
-            {
-                activate_action ("fullscreen", null);
-            }
+        this.activate ();
 
-            if (wide)
-            {
-                activate_action ("wide-mode", null);
-            }
+        return 0;
+    }
 
-            activate ();
-            exit_status = 0;
+    protected override int handle_local_options (VariantDict opts)
+    {
+        if (opts.contains ("version"))
+        {
+            stdout.printf ("%s %s\n", Config.PACKAGE_NAME,
+                           Config.PACKAGE_VERSION);
+            return 0;
         }
 
-        return base.local_command_line (ref arguments, out exit_status);
+        return -1;
     }
 
     /**


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