[Xfce4-commits] [apps/xfce4-screenshooter] 01/01: Use g_app_info_launch() for command launching (Bug #13886)

noreply at xfce.org noreply at xfce.org
Thu Oct 12 19:22:42 CEST 2017


This is an automated email from the git hooks/post-receive script.

a   n   d   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-screenshooter.

commit e86731e3373538f64c0ac71bb2562e7fb3ec2c69
Author: Eduard Wirch <wirch.eduard at gmail.com>
Date:   Thu Oct 12 14:20:32 2017 -0300

    Use g_app_info_launch() for command launching (Bug #13886)
---
 lib/screenshooter-actions.c         |  2 +-
 lib/screenshooter-dialogs.c         | 12 +++++++++++-
 lib/screenshooter-global.h          |  1 +
 lib/screenshooter-utils.c           | 22 +++++++++++++---------
 lib/screenshooter-utils.h           |  3 ++-
 panel-plugin/screenshooter-plugin.c |  1 +
 src/main.c                          |  1 +
 7 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/lib/screenshooter-actions.c b/lib/screenshooter-actions.c
index 43ee4e2..ad288fb 100644
--- a/lib/screenshooter-actions.c
+++ b/lib/screenshooter-actions.c
@@ -123,7 +123,7 @@ gboolean screenshooter_action_idle (ScreenshotData *sd)
       if (screenshot_path != NULL)
         {
           if (sd->action == OPEN)
-            screenshooter_open_screenshot (screenshot_path, sd->app);
+            screenshooter_open_screenshot (screenshot_path, sd->app, sd->app_info);
           else if (sd->action == UPLOAD_IMGUR) {
               screenshooter_upload_to_imgur   (screenshot_path,
                                                sd->title);
diff --git a/lib/screenshooter-dialogs.c b/lib/screenshooter-dialogs.c
index a309719..5123ebf 100644
--- a/lib/screenshooter-dialogs.c
+++ b/lib/screenshooter-dialogs.c
@@ -298,12 +298,15 @@ static void cb_combo_active_item_changed (GtkWidget *box, ScreenshotData *sd)
   GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (box));
   GtkTreeIter iter;
   gchar *active_command = NULL;
+  GAppInfo *app_info = NULL;
 
   gtk_combo_box_get_active_iter (GTK_COMBO_BOX (box), &iter);
   gtk_tree_model_get (model, &iter, 2, &active_command, -1);
+  gtk_tree_model_get (model, &iter, 3, &app_info, -1);
 
   g_free (sd->app);
   sd->app = active_command;
+  sd->app_info = app_info;
 }
 
 
@@ -342,6 +345,7 @@ static void add_item (GAppInfo *app_info, GtkWidget *liststore)
                       0, pixbuf,
                       1, name,
                       2, command,
+                      3, g_app_info_dup (app_info),
                       -1);
 
   /* Free the stuff */
@@ -385,16 +389,19 @@ static void set_default_item (GtkWidget *combobox, ScreenshotData *sd)
     {
       gchar *command = NULL;
       gboolean found = FALSE;
+      GAppInfo *app_info;
 
       /* Loop until finding the appropirate item, if any */
       do
         {
           gtk_tree_model_get (model, &iter, 2, &command, -1);
+          gtk_tree_model_get (model, &iter, 3, &app_info, -1);
 
           if (g_str_equal (command, sd->app))
             {
               gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox),
                                              &iter);
+              sd->app_info = app_info;
 
               found = TRUE;
             }
@@ -409,12 +416,14 @@ static void set_default_item (GtkWidget *combobox, ScreenshotData *sd)
         {
           gtk_tree_model_get_iter_first (model , &iter);
           gtk_tree_model_get (model, &iter, 2, &command, -1);
+          gtk_tree_model_get (model, &iter, 3, &app_info, -1);
 
           gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
 
           g_free (sd->app);
 
           sd->app = command;
+          sd->app_info = app_info;
         }
     }
   else
@@ -422,6 +431,7 @@ static void set_default_item (GtkWidget *combobox, ScreenshotData *sd)
       g_free (sd->app);
 
       sd->app = g_strdup ("none");
+      sd->app_info = NULL;
     }
 }
 
@@ -1041,7 +1051,7 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
   gtk_grid_attach (GTK_GRID (actions_grid), open_with_radio_button, 0, 2, 1, 1);
 
   /* Open with combobox */
-  liststore = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
+  liststore = gtk_list_store_new (4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_APP_INFO);
   combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (liststore));
   renderer = gtk_cell_renderer_text_new ();
   renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
diff --git a/lib/screenshooter-global.h b/lib/screenshooter-global.h
index 173f9d4..3ffcf2c 100644
--- a/lib/screenshooter-global.h
+++ b/lib/screenshooter-global.h
@@ -53,6 +53,7 @@ typedef struct
   gchar *screenshot_dir;
   gchar *title;
   gchar *app;
+  GAppInfo *app_info;
   gchar *last_user;
   GdkPixbuf *screenshot;
 }
diff --git a/lib/screenshooter-utils.c b/lib/screenshooter-utils.c
index f2c2edc..76080d4 100644
--- a/lib/screenshooter-utils.c
+++ b/lib/screenshooter-utils.c
@@ -112,6 +112,7 @@ screenshooter_read_rc_file (const gchar *file, ScreenshotData *sd)
   sd->screenshot_dir = screenshot_dir;
   sd->title = title;
   sd->app = app;
+  sd->app_info = NULL;
   sd->last_user = last_user;
 }
 
@@ -153,12 +154,14 @@ screenshooter_write_rc_file (const gchar *file, ScreenshotData *sd)
 /* Opens the screenshot using application.
 @screenshot_path: the path to the saved screenshot.
 @application: the command to run the application.
+ at app_info: GAppInfo object associated with application.
 */
 void
-screenshooter_open_screenshot (const gchar *screenshot_path, const gchar *application)
+screenshooter_open_screenshot (const gchar *screenshot_path, const gchar *application, GAppInfo *const app_info)
 {
-  gchar *command;
   GError *error = NULL;
+  gpointer screenshot_file = NULL;
+  GList *files = NULL;
 
   g_return_if_fail (screenshot_path != NULL);
 
@@ -169,14 +172,15 @@ screenshooter_open_screenshot (const gchar *screenshot_path, const gchar *applic
 
   TRACE ("Application was not none");
 
-  command = g_strconcat (application, " ",
-                         "\"", screenshot_path, "\"", NULL);
+  g_return_if_fail (app_info != NULL);
 
-  TRACE ("Launch the command");
+  TRACE ("app_info was != NULL");
+
+  screenshot_file = g_file_new_for_path (screenshot_path);
+  files = g_list_append (NULL, screenshot_file);
 
-  /* Execute the command and show an error dialog if there was
-  * an error. */
-  if (!g_spawn_command_line_async (command, &error))
+  TRACE ("Launch the command");
+  if (!g_app_info_launch (app_info, files, NULL, &error))
     {
       TRACE ("An error occured");
 
@@ -184,7 +188,7 @@ screenshooter_open_screenshot (const gchar *screenshot_path, const gchar *applic
       g_error_free (error);
     }
 
-  g_free (command);
+  g_list_free_full (files, g_object_unref);
 }
 
 
diff --git a/lib/screenshooter-utils.h b/lib/screenshooter-utils.h
index 4453706..b8059fb 100644
--- a/lib/screenshooter-utils.h
+++ b/lib/screenshooter-utils.h
@@ -42,7 +42,8 @@ void      screenshooter_read_rc_file          (const gchar    *file,
 void      screenshooter_write_rc_file         (const gchar    *file,
                                                ScreenshotData *sd);
 void      screenshooter_open_screenshot       (const gchar    *screenshot_path,
-                                               const gchar    *application);
+                                               const gchar    *application,
+                                                     GAppInfo *app_info);
 gchar    *screenshooter_get_home_uri          (void);
 gchar    *screenshooter_get_xdg_image_dir_uri (void);
 gboolean  screenshooter_is_remote_uri         (const gchar    *uri);
diff --git a/panel-plugin/screenshooter-plugin.c b/panel-plugin/screenshooter-plugin.c
index 209437d..22d9a25 100644
--- a/panel-plugin/screenshooter-plugin.c
+++ b/panel-plugin/screenshooter-plugin.c
@@ -353,6 +353,7 @@ screenshooter_plugin_construct (XfcePanelPlugin *plugin)
   /* Initialise the data structs */
   PluginData *pd = g_new0 (PluginData, 1);
   ScreenshotData *sd = g_new0 (ScreenshotData, 1);
+  sd->app_info = NULL;
   GFile *default_save_dir;
   gint icon_size;
 
diff --git a/src/main.c b/src/main.c
index 8267913..f7a0568 100644
--- a/src/main.c
+++ b/src/main.c
@@ -150,6 +150,7 @@ int main (int argc, char **argv)
 
   ScreenshotData *sd = g_new0 (ScreenshotData, 1);
   sd->plugin = FALSE;
+  sd->app_info = NULL;
 
   xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list