[gnome-commander/gcmd-1-4] Added support for user choosen terminal, which fixes #bgo737088



commit 6a2773c226b1f0c1d408b8e6f3d776e89152b34a
Author: Uwe Scholz <uwescholz src gnome org>
Date:   Sun Oct 5 19:19:08 2014 +0200

    Added support for user choosen terminal, which fixes #bgo737088
    
    With this commit the "terminal" entry in the configuration file got
    obsolete. Instead of the last one, two new variables are available now:
    "terminal_open" and "terminal_exec". Their default values are set in
    src/gnome-cmd-data.cc. They can be adjusted at runrime in
    "Settings->Options->Programs".

 src/dialogs/gnome-cmd-options-dialog.cc |   14 ++++++++++----
 src/gnome-cmd-data.cc                   |   12 ++++++++----
 src/gnome-cmd-data.h                    |   21 +++++++++++++++------
 src/gnome-cmd-user-actions.cc           |   25 ++++++++++++++++++++-----
 src/utils.cc                            |    2 +-
 5 files changed, 54 insertions(+), 20 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-options-dialog.cc b/src/dialogs/gnome-cmd-options-dialog.cc
index 9596713..bd0c987 100644
--- a/src/dialogs/gnome-cmd-options-dialog.cc
+++ b/src/dialogs/gnome-cmd-options-dialog.cc
@@ -1524,7 +1524,7 @@ inline GtkWidget *create_programs_tab (GtkWidget *parent, GnomeCmdData::Options
     cat = create_category (parent, check, _("MIME applications"));
     gtk_box_pack_start (GTK_BOX (vbox), cat, FALSE, FALSE, 0);
 
-    table = create_table (parent, 5, 2);
+    table = create_table (parent, 6, 2);
     cat = create_category (parent, table, _("Standard programs"));
     gtk_box_pack_start (GTK_BOX (vbox), cat, FALSE, FALSE, 0);
 
@@ -1536,6 +1536,8 @@ inline GtkWidget *create_programs_tab (GtkWidget *parent, GnomeCmdData::Options
     table_add (table, label, 0, 3, GTK_FILL);
     label = create_label (parent, _("Terminal:"));
     table_add (table, label, 0, 4, GTK_FILL);
+    label = create_label (parent, _("Terminal for executing a program:"));
+    table_add (table, label, 0, 5, GTK_FILL);
 
     entry = create_entry (parent, "viewer", cfg.viewer);
     table_add (table, entry, 1, 0, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
@@ -1547,8 +1549,10 @@ inline GtkWidget *create_programs_tab (GtkWidget *parent, GnomeCmdData::Options
     table_add (table, entry, 1, 2, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
     entry = create_entry (parent, "differ", cfg.differ);
     table_add (table, entry, 1, 3, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
-    entry = create_entry (parent, "term", cfg.term);
+    entry = create_entry (parent, "termopen", cfg.termopen);
     table_add (table, entry, 1, 4, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
+    entry = create_entry (parent, "termexec", cfg.termexec);
+    table_add (table, entry, 1, 5, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
 
 
     //Other favorite apps frame
@@ -1605,14 +1609,16 @@ inline void store_programs_options (GtkWidget *dialog, GnomeCmdData::Options &cf
     GtkWidget *entry1 = lookup_widget (dialog, "viewer");
     GtkWidget *entry2 = lookup_widget (dialog, "editor");
     GtkWidget *entry3 = lookup_widget (dialog, "differ");
-    GtkWidget *entry5 = lookup_widget (dialog, "term");
+    GtkWidget *entry5 = lookup_widget (dialog, "termopen");
+    GtkWidget *entry6 = lookup_widget (dialog, "termexec");
     GtkWidget *check_uris = lookup_widget (dialog, "honor_expect_uris");
     GtkWidget *check_iv = lookup_widget (dialog, "use_internal_viewer");
 
     cfg.set_viewer(gtk_entry_get_text (GTK_ENTRY (entry1)));
     cfg.set_editor(gtk_entry_get_text (GTK_ENTRY (entry2)));
     cfg.set_differ(gtk_entry_get_text (GTK_ENTRY (entry3)));
-    cfg.set_term(gtk_entry_get_text (GTK_ENTRY (entry5)));
+    cfg.set_termopen(gtk_entry_get_text (GTK_ENTRY (entry5)));
+    cfg.set_termexec(gtk_entry_get_text (GTK_ENTRY (entry6)));
 
     cfg.honor_expect_uris = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_uris));
     cfg.use_internal_viewer = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_iv));
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index c6d9bd6..e901b68 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -109,7 +109,8 @@ GnomeCmdData::Options::Options(const Options &cfg)
     use_internal_viewer = cfg.use_internal_viewer;
     editor = g_strdup (cfg.editor);
     differ = g_strdup (cfg.differ);
-    term = g_strdup (cfg.term);
+    termopen = g_strdup (cfg.termopen);
+    termexec = g_strdup (cfg.termexec);
     fav_apps = cfg.fav_apps;
     device_only_icon = cfg.device_only_icon;
     skip_mounting = cfg.skip_mounting;
@@ -164,7 +165,8 @@ GnomeCmdData::Options &GnomeCmdData::Options::operator = (const Options &cfg)
         use_internal_viewer = cfg.use_internal_viewer;
         editor = g_strdup (cfg.editor);
         differ = g_strdup (cfg.differ);
-        term = g_strdup (cfg.term);
+        termopen = g_strdup (cfg.termopen);
+        termexec = g_strdup (cfg.termexec);
         fav_apps = cfg.fav_apps;
         device_only_icon = cfg.device_only_icon;
         skip_mounting = cfg.skip_mounting;
@@ -1204,7 +1206,8 @@ void GnomeCmdData::load()
     options.viewer = gnome_cmd_data_get_string ("/programs/viewer", "gedit %s");
     options.editor = gnome_cmd_data_get_string ("/programs/editor", "gedit %s");
     options.differ = gnome_cmd_data_get_string ("/programs/differ", "meld %s");
-    options.term   = gnome_cmd_data_get_string ("/programs/terminal", "xterm -hold -e %s");
+    options.termopen = gnome_cmd_data_get_string ("/programs/terminal_open", "xterm -hold");
+    options.termexec = gnome_cmd_data_get_string ("/programs/terminal_exec", "xterm -hold -e %s");
 
     use_gcmd_block = gnome_cmd_data_get_bool ("/programs/use_gcmd_block", FALSE);
 
@@ -1624,7 +1627,8 @@ void GnomeCmdData::save()
     gnome_cmd_data_set_string ("/programs/viewer", options.viewer);
     gnome_cmd_data_set_string ("/programs/editor", options.editor);
     gnome_cmd_data_set_string ("/programs/differ", options.differ);
-    gnome_cmd_data_set_string ("/programs/terminal", options.term);
+    gnome_cmd_data_set_string ("/programs/terminal_open", options.termopen);
+    gnome_cmd_data_set_string ("/programs/terminal_exec", options.termexec);
 
     gnome_cmd_data_set_bool   ("/programs/use_gcmd_block", use_gcmd_block);
 
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 75ae429..0fb4b3f 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -136,7 +136,8 @@ struct GnomeCmdData
         gboolean                     use_internal_viewer;
         gchar                       *editor;
         gchar                       *differ;
-        gchar                       *term;
+        gchar                       *termopen;
+        gchar                       *termexec;
         GList                       *fav_apps;
         //  Devices
         gboolean                     device_only_icon;
@@ -182,7 +183,8 @@ struct GnomeCmdData
                    use_internal_viewer(TRUE),
                    editor(NULL),
                    differ(NULL),
-                   term(NULL),
+                   termopen(NULL),
+                   termexec(NULL),
                    fav_apps(NULL),
                    device_only_icon(FALSE),
                    skip_mounting(FALSE)
@@ -204,7 +206,8 @@ struct GnomeCmdData
             g_free (viewer);
             g_free (editor);
             g_free (differ);
-            g_free (term);
+            g_free (termopen);
+            g_free (termexec);
         }
 
         Options &operator = (const Options &cfg);
@@ -270,10 +273,16 @@ struct GnomeCmdData
             differ = g_strdup (command);
         }
 
-        void set_term(const gchar *command)
+        void set_termexec(const gchar *command)
         {
-            g_free (term);
-            term = g_strdup (command);
+            g_free (termexec);
+            termexec = g_strdup (command);
+        }
+
+        void set_termopen(const gchar *command)
+        {
+            g_free (termopen);
+            termopen = g_strdup (command);
         }
 
         void add_fav_app(GnomeCmdApp *app)
diff --git a/src/gnome-cmd-user-actions.cc b/src/gnome-cmd-user-actions.cc
index e98ed29..2633f22 100644
--- a/src/gnome-cmd-user-actions.cc
+++ b/src/gnome-cmd-user-actions.cc
@@ -1186,8 +1186,9 @@ void command_execute (GtkMenuItem *menuitem, gpointer command)
     g_shell_parse_argv (cmd.c_str(), &argc, &argv, NULL);
     if (!g_spawn_async (gnome_cmd_dir_is_local (dir) ? dir_path.c_str() : NULL, argv, NULL, 
G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error))
         gnome_cmd_error_message (_("Unable to execute command."), error);
-    g_strfreev (argv);
 
+    g_strfreev (argv);
+    g_free (error);
     g_list_free (sfl);
 }
 
@@ -1204,17 +1205,31 @@ void command_open_terminal__internal (GtkMenuItem *menuitem, gpointer not_used)
         command_open_terminal (menuitem, NULL);
 }
 
-
+/** 
+ * Executes the command stored in gnome_cmd_data.options.termopen in the
+ * active directory.
+ */
 void command_open_terminal (GtkMenuItem *menuitem, gpointer not_used)
 {
+    gint argc;
+    gchar **argv;
+    gchar *command;
     gchar *dpath = GNOME_CMD_FILE (get_fs (ACTIVE)->get_directory())->get_real_path();
+    GError *error = NULL;
 
-    if (gnome_execute_terminal_shell (dpath, NULL) == -1)
-        gnome_cmd_show_message (NULL, _("Unable to open terminal"), g_strerror (errno));
+    command = g_strdup (gnome_cmd_data.options.termopen);
+
+    DEBUG ('g', "running: %s\n", command);
+
+    g_shell_parse_argv (command, &argc, &argv, NULL);
+    if (!g_spawn_async (dpath, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error))
+        gnome_cmd_error_message (_("Unable to execute command."), error);
+
+    g_strfreev (argv);
+    g_free (command);
     g_free (dpath);
 }
 
-
 void command_open_terminal_as_root (GtkMenuItem *menuitem, gpointer not_used)
 {
     int argc = 1;
diff --git a/src/utils.cc b/src/utils.cc
index e4307a5..926b939 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -112,7 +112,7 @@ void run_command_indir (const gchar *in_command, const gchar *dir, gboolean term
         else
             arg = g_shell_quote (in_command);
 
-        command = g_strdup_printf (gnome_cmd_data.options.term, arg);
+        command = g_strdup_printf (gnome_cmd_data.options.termexec, arg);
 
         g_free (arg);
     }


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