[gnome-commander/gcmd-1-12] Add run error handling to file-roller plugin



commit e251b869e26c2d5c5dbfb8ab5357d658156e0a8c
Author: Andrey Sokolov <keremet altlinux org>
Date:   Tue Nov 16 17:55:29 2021 +0300

    Add run error handling to file-roller plugin
    
    Update NEWS and releases.xml

 NEWS                                     |  1 +
 doc/C/releases.xml                       |  3 +++
 plugins/fileroller/file-roller-plugin.cc | 34 ++++++++++++++++++++++----------
 po/ru.po                                 |  4 ++++
 4 files changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/NEWS b/NEWS
index 13226eea..773910fd 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ New features:
 
 Bug fixes:
  * Fixed issue #108 (Crash after right click on file)
+ * File-roller plugin: Add run error handling (Thanks to Andrey Sokolov)
 
 New or updated translations:
  * ...
diff --git a/doc/C/releases.xml b/doc/C/releases.xml
index a235d634..07502db8 100644
--- a/doc/C/releases.xml
+++ b/doc/C/releases.xml
@@ -32,6 +32,9 @@
                         <listitem>
                             <para>Fixed issue #108 (Crash after right click on file)</para>
                         </listitem>
+                        <listitem>
+                            <para>File-roller plugin: Add run error handling (Thanks to Andrey 
Sokolov)</para>
+                        </listitem>
                     </itemizedlist>
                 </para>
                 <para>New features:</para>
diff --git a/plugins/fileroller/file-roller-plugin.cc b/plugins/fileroller/file-roller-plugin.cc
index 3d16e45d..b6a41df9 100644
--- a/plugins/fileroller/file-roller-plugin.cc
+++ b/plugins/fileroller/file-roller-plugin.cc
@@ -184,6 +184,28 @@ static GnomeCmdPluginClass *parent_class = NULL;
 
 gchar *GetGfileAttributeString(GFile *gFile, const char *attribute);
 
+static void run_cmd (const gchar *work_dir, const gchar *cmd)
+{
+    gint argc;
+    gchar **argv;
+    GError *err = nullptr;
+
+    g_shell_parse_argv (cmd, &argc, &argv, NULL);
+    if (!g_spawn_async (work_dir, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &err))
+    {
+        GtkWidget* dialog = gtk_message_dialog_new (NULL,
+            (GtkDialogFlags) 0,
+            GTK_MESSAGE_ERROR,
+            GTK_BUTTONS_CLOSE,
+            _("Error running \"%s\"\n\n%s"), cmd, err->message);
+        gtk_dialog_run (GTK_DIALOG (dialog));
+        gtk_widget_destroy (dialog);
+        g_error_free (err);
+    }
+
+    g_strfreev (argv);
+}
+
 static void on_extract_cwd (GtkMenuItem *item, GFile *gFile)
 {
     gchar *target_arg, *archive_arg;
@@ -191,8 +213,6 @@ static void on_extract_cwd (GtkMenuItem *item, GFile *gFile)
     gchar *target_name = (gchar *) g_object_get_data (G_OBJECT (item), TARGET_NAME);
     gchar *target_dir = (gchar *) g_object_get_data (G_OBJECT (item), TARGET_DIR);
     gchar *cmd, *t;
-    gint argc;
-    gchar **argv;
 
     if (!target_dir)
     {
@@ -210,9 +230,7 @@ static void on_extract_cwd (GtkMenuItem *item, GFile *gFile)
     cmd = g_strdup_printf ("file-roller %s %s", target_arg, archive_arg);
 
     t = g_path_get_dirname (local_path);
-    g_shell_parse_argv (cmd, &argc, &argv, NULL);
-    g_spawn_async (t, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
-    g_strfreev (argv);
+    run_cmd (t, cmd);
     g_free (t);
 
     g_free (target_arg);
@@ -230,8 +248,6 @@ inline void do_add_to_archive (const gchar *name, GnomeCmdState *state)
     gchar *cmd = g_strdup_printf ("file-roller %s ", arg);
     gchar *active_dir_path;
     GList *files;
-    gint argc;
-    gchar **argv;
 
     for (files = state->active_dir_selected_files; files; files = files->next)
     {
@@ -247,9 +263,7 @@ inline void do_add_to_archive (const gchar *name, GnomeCmdState *state)
 
     g_printerr ("add: %s\n", cmd);
     active_dir_path = g_file_get_path (state->activeDirGfile);
-    g_shell_parse_argv (cmd, &argc, &argv, NULL);
-    g_spawn_async (active_dir_path, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
-    g_strfreev (argv);
+    run_cmd (active_dir_path, cmd);
 
     g_free (cmd);
     g_free (active_dir_path);
diff --git a/po/ru.po b/po/ru.po
index 2a02499a..99ff50f9 100644
--- a/po/ru.po
+++ b/po/ru.po
@@ -1364,6 +1364,10 @@ msgstr "Извлечь в текущую директорию"
 msgid "Extract to '%s'"
 msgstr "Извлечь в «%s»"
 
+#: ../plugins/fileroller/file-roller-plugin.cc:199
+msgid "Error running \"%s\"\n\n%s"
+msgstr "Ошибка запуска \"%s\"\n\n%s"
+
 #: ../plugins/fileroller/file-roller-plugin.cc:499
 #: ../src/gnome-cmd-advrename-profile-component.cc:918
 #: ../src/plugin_manager.cc:406 ../src/tags/gnome-cmd-tags.cc:686


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