[gnome-screenshot] Fix launching from gnome-shell



commit dbc20998a10ae065e4e5a56161f5e301eb744a05
Author: Kalev Lember <kalevlember gmail com>
Date:   Mon Sep 1 16:16:18 2014 +0200

    Fix launching from gnome-shell
    
    Instead of starting in headless mode, start in the interactive mode and
    bring up the UI when we're being DBus activated.
    
    To make this possible, this patch separates the GSettings loading and
    command line parsing, so we would only have to parse the command line
    when started on the command line, and skip this in the DBus activation
    case.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=735375

 src/screenshot-application.c |   41 +++++----
 src/screenshot-config.c      |  187 +++++++++++++++++++++---------------------
 src/screenshot-config.h      |   23 +++---
 3 files changed, 127 insertions(+), 124 deletions(-)
---
diff --git a/src/screenshot-application.c b/src/screenshot-application.c
index 3c75126..452ffb9 100644
--- a/src/screenshot-application.c
+++ b/src/screenshot-application.c
@@ -686,17 +686,16 @@ screenshot_application_command_line (GApplication            *app,
   g_variant_dict_lookup (options, "delay", "i", &delay_arg);
   g_variant_dict_lookup (options, "file", "^&ay", &file_arg);
 
-  res = screenshot_load_config (clipboard_arg,
-                                window_arg,
-                                area_arg,
-                                include_border_arg,
-                                disable_border_arg,
-                                include_pointer_arg,
-                                border_effect_arg,
-                                delay_arg,
-                                interactive_arg,
-                                file_arg);
-
+  res = screenshot_config_parse_command_line (clipboard_arg,
+                                              window_arg,
+                                              area_arg,
+                                              include_border_arg,
+                                              disable_border_arg,
+                                              include_pointer_arg,
+                                              border_effect_arg,
+                                              delay_arg,
+                                              interactive_arg,
+                                              file_arg);
   if (!res)
     {
       exit_status = EXIT_FAILURE;
@@ -705,7 +704,7 @@ screenshot_application_command_line (GApplication            *app,
 
   /* interactive mode: trigger the dialog and wait for the response */
   if (screenshot_config->interactive)
-    screenshot_show_interactive_dialog (self);
+    g_application_activate (app);
   else
     screenshot_start (self);
 
@@ -771,21 +770,18 @@ static GActionEntry action_entries[] = {
 static void
 screenshot_application_startup (GApplication *app)
 {
+  GMenuModel *menu;
+  GtkBuilder *builder;
   ScreenshotApplication *self = SCREENSHOT_APPLICATION (app);
 
   G_APPLICATION_CLASS (screenshot_application_parent_class)->startup (app);
 
+  screenshot_load_config ();
+
   gtk_window_set_default_icon_name (SCREENSHOOTER_ICON);
 
   g_action_map_add_action_entries (G_ACTION_MAP (self), action_entries,
                                    G_N_ELEMENTS (action_entries), self);
-}
-
-static void
-screenshot_application_activate (GApplication *app)
-{
-  GtkBuilder *builder;
-  GMenuModel *menu;
 
   builder = gtk_builder_new ();
   gtk_builder_add_from_resource (builder, "/org/gnome/screenshot/screenshot-app-menu.ui", NULL);
@@ -797,6 +793,13 @@ screenshot_application_activate (GApplication *app)
 }
 
 static void
+screenshot_application_activate (GApplication *app)
+{
+  screenshot_config->interactive = TRUE;
+  screenshot_show_interactive_dialog (SCREENSHOT_APPLICATION (app));
+}
+
+static void
 screenshot_application_finalize (GObject *object)
 {
   ScreenshotApplication *self = SCREENSHOT_APPLICATION (object);
diff --git a/src/screenshot-config.c b/src/screenshot-config.c
index ae00eb4..8e57264 100644
--- a/src/screenshot-config.c
+++ b/src/screenshot-config.c
@@ -36,24 +36,81 @@
 
 ScreenshotConfig *screenshot_config;
 
-gboolean
-screenshot_load_config (gboolean clipboard_arg,
-                        gboolean window_arg,
-                        gboolean area_arg,
-                        gboolean include_border_arg,
-                        gboolean disable_border_arg,
-                        gboolean include_pointer_arg,
-                        const gchar *border_effect_arg,
-                        guint delay_arg,
-                        gboolean interactive_arg,
-                        const gchar *file_arg)
+void
+screenshot_load_config (void)
 {
-  static gboolean initialized = FALSE;
   ScreenshotConfig *config;
 
-  if (initialized)
-    return FALSE;
+  config = g_slice_new0 (ScreenshotConfig);
+
+  config->settings = g_settings_new ("org.gnome.gnome-screenshot");
+  config->save_dir =
+    g_settings_get_string (config->settings,
+                           LAST_SAVE_DIRECTORY_KEY);
+  config->delay =
+    g_settings_get_int (config->settings,
+                        DELAY_KEY);
+  config->include_border =
+    g_settings_get_boolean (config->settings,
+                            INCLUDE_BORDER_KEY);
+  config->include_pointer =
+    g_settings_get_boolean (config->settings,
+                            INCLUDE_POINTER_KEY);
+  config->border_effect =
+    g_settings_get_string (config->settings,
+                           BORDER_EFFECT_KEY);
+  config->file_type =
+    g_settings_get_string (config->settings,
+                           DEFAULT_FILE_TYPE_KEY);
+  config->include_icc_profile =
+    g_settings_get_boolean (config->settings,
+                            INCLUDE_ICC_PROFILE);
+
+  if (config->border_effect == NULL)
+    config->border_effect = g_strdup ("none");
+
+  config->take_window_shot = FALSE;
+  config->take_area_shot = FALSE;
+
+  screenshot_config = config;
+}
+
+void
+screenshot_save_config (void)
+{
+  ScreenshotConfig *c = screenshot_config;
+
+  g_assert (c != NULL);
+
+  /* if we were not started up in interactive mode, avoid
+   * overwriting these settings.
+   */
+  if (!c->interactive)
+    return;
+
+  g_settings_set_boolean (c->settings,
+                          INCLUDE_BORDER_KEY, c->include_border);
+  g_settings_set_boolean (c->settings,
+                          INCLUDE_POINTER_KEY, c->include_pointer);
+  g_settings_set_string (c->settings,
+                         BORDER_EFFECT_KEY, c->border_effect);
+
+  if (!c->take_area_shot)
+    g_settings_set_int (c->settings, DELAY_KEY, c->delay);
+}
 
+gboolean
+screenshot_config_parse_command_line (gboolean clipboard_arg,
+                                      gboolean window_arg,
+                                      gboolean area_arg,
+                                      gboolean include_border_arg,
+                                      gboolean disable_border_arg,
+                                      gboolean include_pointer_arg,
+                                      const gchar *border_effect_arg,
+                                      guint delay_arg,
+                                      gboolean interactive_arg,
+                                      const gchar *file_arg)
+{
   if (window_arg && area_arg)
     {
       g_printerr (_("Conflicting options: --window and --area should not be "
@@ -68,13 +125,9 @@ screenshot_load_config (gboolean clipboard_arg,
       return FALSE;
     }
 
-  config = g_slice_new0 (ScreenshotConfig);
-  initialized = TRUE;
-
-  config->interactive = interactive_arg;
+  screenshot_config->interactive = interactive_arg;
 
-  config->settings = g_settings_new ("org.gnome.gnome-screenshot");
-  if (config->interactive)
+  if (screenshot_config->interactive)
     {
       if (clipboard_arg)
         g_warning ("Option --clipboard is ignored in interactive mode.");
@@ -83,91 +136,37 @@ screenshot_load_config (gboolean clipboard_arg,
       if (file_arg)
         g_warning ("Option --file is ignored in interactive mode.");
 
-      config->save_dir =
-        g_settings_get_string (config->settings,
-                               LAST_SAVE_DIRECTORY_KEY);
-      config->delay =
-        g_settings_get_int (config->settings, DELAY_KEY);
       if (delay_arg > 0)
-        config->delay = delay_arg;
-
-      config->include_border =
-        g_settings_get_boolean (config->settings,
-                                INCLUDE_BORDER_KEY);
+        screenshot_config->delay = delay_arg;
       if (include_border_arg)
-        config->include_border = TRUE;
+        screenshot_config->include_border = TRUE;
       if (disable_border_arg)
-        config->include_border = FALSE;
-
-      config->include_pointer =
-        g_settings_get_boolean (config->settings,
-                                INCLUDE_POINTER_KEY);
-
-      if (border_effect_arg != NULL)
-        config->border_effect = g_strdup (border_effect_arg);
-      else
-        config->border_effect =
-          g_settings_get_string (config->settings,
-                                 BORDER_EFFECT_KEY);
-      config->file_type =
-        g_settings_get_string (config->settings,
-                               DEFAULT_FILE_TYPE_KEY);
+        screenshot_config->include_border = FALSE;
     }
   else
     {
-      config->save_dir =
-        g_settings_get_string (config->settings,
+      g_free (screenshot_config->save_dir);
+      screenshot_config->save_dir =
+        g_settings_get_string (screenshot_config->settings,
                                AUTO_SAVE_DIRECTORY_KEY);
-      config->delay = delay_arg;
-      config->include_border = include_border_arg;
-      config->include_border = !disable_border_arg;
-      config->include_pointer = include_pointer_arg;
-      if (border_effect_arg != NULL)
-        config->border_effect = g_strdup (border_effect_arg);
-
-      config->copy_to_clipboard = clipboard_arg;
+
+      screenshot_config->delay = delay_arg;
+      screenshot_config->include_border = include_border_arg;
+      screenshot_config->include_border = !disable_border_arg;
+      screenshot_config->include_pointer = include_pointer_arg;
+      screenshot_config->copy_to_clipboard = clipboard_arg;
       if (file_arg != NULL)
-        config->file = g_file_new_for_commandline_arg (file_arg);
-      config->file_type =
-        g_settings_get_string (config->settings,
-                               DEFAULT_FILE_TYPE_KEY);
+        screenshot_config->file = g_file_new_for_commandline_arg (file_arg);
     }
 
-  config->include_icc_profile =
-    g_settings_get_boolean (config->settings,
-                            INCLUDE_ICC_PROFILE);
-
-  if (config->border_effect == NULL)
-    config->border_effect = g_strdup ("none");
-
-  config->take_window_shot = window_arg;
-  config->take_area_shot = area_arg;
+  if (border_effect_arg != NULL)
+    {
+      g_free (screenshot_config->border_effect);
+      screenshot_config->border_effect = g_strdup (border_effect_arg);
+    }
 
-  screenshot_config = config;
+  screenshot_config->take_window_shot = window_arg;
+  screenshot_config->take_area_shot = area_arg;
 
   return TRUE;
 }
-
-void
-screenshot_save_config (void)
-{
-  ScreenshotConfig *c = screenshot_config;
-
-  g_assert (c != NULL);
-
-  /* if we were not started up in interactive mode, avoid
-   * overwriting these settings.
-   */
-  if (!c->interactive)
-    return;
-
-  g_settings_set_boolean (c->settings,
-                          INCLUDE_BORDER_KEY, c->include_border);
-  g_settings_set_boolean (c->settings,
-                          INCLUDE_POINTER_KEY, c->include_pointer);
-  g_settings_set_string (c->settings,
-                         BORDER_EFFECT_KEY, c->border_effect);
-
-  if (!c->take_area_shot)
-    g_settings_set_int (c->settings, DELAY_KEY, c->delay);
-}
diff --git a/src/screenshot-config.h b/src/screenshot-config.h
index 1a4ce9e..7b606d8 100644
--- a/src/screenshot-config.h
+++ b/src/screenshot-config.h
@@ -50,17 +50,18 @@ typedef struct {
 
 extern ScreenshotConfig *screenshot_config;
 
-gboolean screenshot_load_config (gboolean clipboard_arg,
-                                 gboolean window_arg,
-                                 gboolean area_arg,
-                                 gboolean include_border_arg,
-                                 gboolean disable_border_arg,
-                                 gboolean include_pointer_arg,
-                                 const gchar *border_effect_arg,
-                                 guint delay_arg,
-                                 gboolean interactive_arg,
-                                 const gchar *file_arg);
-void screenshot_save_config      (void);
+void           screenshot_load_config                  (void);
+void           screenshot_save_config                  (void);
+gboolean       screenshot_config_parse_command_line    (gboolean clipboard_arg,
+                                                        gboolean window_arg,
+                                                        gboolean area_arg,
+                                                        gboolean include_border_arg,
+                                                        gboolean disable_border_arg,
+                                                        gboolean include_pointer_arg,
+                                                        const gchar *border_effect_arg,
+                                                        guint delay_arg,
+                                                        gboolean interactive_arg,
+                                                        const gchar *file_arg);
 
 G_END_DECLS
 


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