[nautilus] desktop: add command line options for override gsettings



commit a93e1a5014e2be9dcc30bb034471a94c7b6c328a
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Apr 19 17:48:15 2016 +0200

    desktop: add command line options for override gsettings
    
    Sometimes we want to override the show-desktop-icons gsettings, as we
    were doing before splitting the desktop.
    
    Wrongly I assumed that since it's a different binary, once can simply
    run it or not, but of course that was an oversimplification, and forgot
    all what I needed to do in order to support all the cases for the
    desktop handling.
    
    This patch adds the missing command line options we had, --force-desktop
    and --no-desktop, and also adds the --force-desktop to the classic
    desktop file, since we needed to enable the classic mode.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765159

 data/nautilus-classic.desktop.in                |    2 +-
 nautilus-desktop/nautilus-desktop-application.c |   46 ++++++++++++++++++++--
 2 files changed, 42 insertions(+), 6 deletions(-)
---
diff --git a/data/nautilus-classic.desktop.in b/data/nautilus-classic.desktop.in
index 252534a..32564da 100644
--- a/data/nautilus-classic.desktop.in
+++ b/data/nautilus-classic.desktop.in
@@ -2,7 +2,7 @@
 Type=Application
 Name=Desktop Icons
 Comment=Classic session desktop file for desktop icons
-Exec=nautilus-desktop
+Exec=nautilus-desktop --force
 OnlyShowIn=GNOME;
 NoDisplay=true
 X-GNOME-Bugzilla-Bugzilla=GNOME
diff --git a/nautilus-desktop/nautilus-desktop-application.c b/nautilus-desktop/nautilus-desktop-application.c
index abf1ea8..7622cda 100644
--- a/nautilus-desktop/nautilus-desktop-application.c
+++ b/nautilus-desktop/nautilus-desktop-application.c
@@ -28,6 +28,8 @@
 #include <libnautilus-private/nautilus-global-preferences.h>
 #include <eel/eel.h>
 #include <gdk/gdkx.h>
+#include <stdlib.h>
+#include <glib/gi18n.h>
 
 static NautilusFreedesktopFileManager1 *freedesktop_proxy = NULL;
 
@@ -35,6 +37,7 @@ struct _NautilusDesktopApplication
 {
   NautilusApplication parent_instance;
 
+  gboolean force;
   GCancellable *freedesktop_cancellable;
 };
 
@@ -134,6 +137,8 @@ update_desktop_from_gsettings (NautilusDesktopApplication *self)
   display = gdk_display_get_default ();
   visible = g_settings_get_boolean (gnome_background_preferences,
                                     NAUTILUS_PREFERENCES_SHOW_DESKTOP);
+  visible = visible || self->force;
+
   if (!GDK_IS_X11_DISPLAY (display))
     {
       if (visible)
@@ -155,9 +160,12 @@ update_desktop_from_gsettings (NautilusDesktopApplication *self)
 static void
 init_desktop (NautilusDesktopApplication *self)
 {
-  g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
-                            G_CALLBACK (update_desktop_from_gsettings),
-                            self);
+  if (!self->force)
+    {
+      g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
+                                G_CALLBACK (update_desktop_from_gsettings),
+                                self);
+    }
   update_desktop_from_gsettings (self);
 }
 
@@ -167,6 +175,25 @@ nautilus_desktop_application_activate (GApplication *app)
   /* Do nothing */
 }
 
+static gint
+nautilus_desktop_application_command_line (GApplication            *application,
+                                           GApplicationCommandLine *command_line)
+{
+  NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (application);
+  GVariantDict *options;
+
+  options = g_application_command_line_get_options_dict (command_line);
+
+  if (g_variant_dict_contains (options, "force"))
+    {
+      self->force = TRUE;
+    }
+
+  init_desktop (self);
+
+  return EXIT_SUCCESS;
+}
+
 static void
 nautilus_desktop_application_startup (GApplication *app)
 {
@@ -188,8 +215,6 @@ nautilus_desktop_application_startup (GApplication *app)
     }
 
   g_clear_error (&error);
-
-  init_desktop (self);
 }
 
 static void
@@ -214,6 +239,7 @@ nautilus_desktop_application_class_init (NautilusDesktopApplicationClass *klass)
 
   application_class->startup = nautilus_desktop_application_startup;
   application_class->activate = nautilus_desktop_application_activate;
+  application_class->command_line = nautilus_desktop_application_command_line;
 
   gobject_class->dispose = nautilus_desktop_application_dispose;
 }
@@ -225,9 +251,18 @@ nautilus_desktop_ensure_builtins (void)
   g_type_ensure (NAUTILUS_TYPE_DESKTOP_DIRECTORY);
 }
 
+const GOptionEntry desktop_options[] = {
+  { "force", '\0', 0, G_OPTION_ARG_NONE, NULL,
+    N_("Always manage the desktop (ignore the GSettings preference)."), NULL },
+  { NULL }
+};
+
 static void
 nautilus_desktop_application_init (NautilusDesktopApplication *self)
 {
+  self->force = FALSE;
+
+  g_application_add_main_option_entries (G_APPLICATION (self), desktop_options);
   nautilus_ensure_extension_points ();
   nautilus_ensure_extension_builtins ();
   nautilus_desktop_ensure_builtins ();
@@ -239,6 +274,7 @@ nautilus_desktop_application_new (void)
   return g_object_new (NAUTILUS_TYPE_DESKTOP_APPLICATION,
                        "application-id", "org.gnome.NautilusDesktop",
                        "register-session", TRUE,
+                       "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
                         NULL);
 }
 


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