[gnome-commander] Open terminal with administrator privileges



commit 21046956519a5c0a3b0d89683328b237c9dc9f32
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Thu Dec 16 23:21:15 2010 +0100

    Open terminal with administrator privileges

 NEWS                          |    1 +
 doc/C/gnome-commander.xml     |    3 +++
 src/gnome-cmd-user-actions.cc |   29 +++++++++++++++++++++++++++++
 src/gnome-cmd-user-actions.h  |    1 +
 4 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index ec7085f..033f94f 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ New features:
  * One instance mode
  * User defined LS_COLORS colours
  * Enhanced file name matching in quick search
+ * Open terminal with administrator privileges
  * --config-dir command line option for customized location of config files
  * New or updated docs: de, en, es, fr, sl
  * New or updated translations: cs, da, es, eu, fr, hu, ko, nb, pl, ro, ru, sl, uk, zh_CN
diff --git a/doc/C/gnome-commander.xml b/doc/C/gnome-commander.xml
index 0d75404..93be97d 100644
--- a/doc/C/gnome-commander.xml
+++ b/doc/C/gnome-commander.xml
@@ -7556,6 +7556,9 @@
                             <para>Enhanced file name matching in quick search</para>
                         </listitem>
                         <listitem>
+                            <para>Open terminal with administrator privileges</para>
+                        </listitem>
+                        <listitem>
                             <para>--config-dir command line option for customized location of config files</para>
                         </listitem>
                         <listitem>
diff --git a/src/gnome-cmd-user-actions.cc b/src/gnome-cmd-user-actions.cc
index 0e18e67..61b9589 100644
--- a/src/gnome-cmd-user-actions.cc
+++ b/src/gnome-cmd-user-actions.cc
@@ -20,6 +20,7 @@
 
 #include <config.h>
 #include <gtk/gtkclipboard.h>
+#include <libgnome/gnome-util.h>
 #include <libgnomeui/gnome-url.h>
 #include <set>
 #include <algorithm>
@@ -143,6 +144,7 @@ static UserActionData user_actions_data[] = {
                                              {command_execute, "command.execute", N_("Execute command")},
                                              {command_open_nautilus, "command.open_folder", N_("Open folder")},
                                              {command_open_terminal, "command.open_terminal", N_("Open terminal")},
+                                             {command_open_terminal_as_root, "command.open_terminal_as_root", N_("Open terminal as root")},
                                              {command_root_mode, "command.root_mode", N_("Start GNOME Commander as root")},
                                              {connections_close_current, "connections.close", N_("Close connection")},
                                              {connections_new, "connections.new", N_("New connection")},
@@ -1177,6 +1179,33 @@ void command_open_terminal (GtkMenuItem *menuitem, gpointer not_used)
 }
 
 
+void command_open_terminal_as_root (GtkMenuItem *menuitem, gpointer not_used)
+{
+    int argc = 1;
+    char **argv = g_new (char *, argc+1);
+
+    argv[0] = gnome_util_user_shell ();
+    argv[1] = NULL;
+
+    gnome_prepend_terminal_to_vector (&argc, &argv);
+
+    if (gnome_cmd_prepend_su_to_vector (argc, argv))
+    {
+        gchar *dpath = GNOME_CMD_FILE (get_fs (ACTIVE)->get_directory())->get_real_path();
+        GError *error = NULL;
+
+        if (!g_spawn_async (dpath, argv, NULL, GSpawnFlags (G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL), NULL, NULL, NULL, &error))
+            gnome_cmd_error_message (_("Unable to open terminal in root mode"), error);
+
+        g_free (dpath);
+    }
+    else
+        gnome_cmd_show_message (NULL, _("xdg-su, gksu, gnomesu, kdesu or beesu is not found"));
+
+    g_strfreev (argv);
+}
+
+
 inline void open_uri_in_nautilus (gchar *uri)
 {
     if (!uri)
diff --git a/src/gnome-cmd-user-actions.h b/src/gnome-cmd-user-actions.h
index db7932b..029bdeb 100644
--- a/src/gnome-cmd-user-actions.h
+++ b/src/gnome-cmd-user-actions.h
@@ -269,6 +269,7 @@ GNOME_CMD_USER_ACTION(edit_copy_fnames);
 /************** Command Menu **************/
 GNOME_CMD_USER_ACTION(command_execute);
 GNOME_CMD_USER_ACTION(command_open_terminal);
+GNOME_CMD_USER_ACTION(command_open_terminal_as_root);
 GNOME_CMD_USER_ACTION(command_open_nautilus);
 GNOME_CMD_USER_ACTION(command_open_nautilus_in_cwd);
 GNOME_CMD_USER_ACTION(command_root_mode);



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