[gnome-commander] Code refactoring in command_root_mode()
- From: Piotr Eljasiak <epiotr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Code refactoring in command_root_mode()
- Date: Thu, 16 Dec 2010 23:02:06 +0000 (UTC)
commit 2f058b41ea947061efe35a84a51d9ae902b312e9
Author: Piotr Eljasiak <epiotr src gnome org>
Date: Thu Dec 16 23:40:37 2010 +0100
Code refactoring in command_root_mode()
src/gnome-cmd-user-actions.cc | 47 +++++++++++-----------------------------
1 files changed, 13 insertions(+), 34 deletions(-)
---
diff --git a/src/gnome-cmd-user-actions.cc b/src/gnome-cmd-user-actions.cc
index a17b443..30d641e 100644
--- a/src/gnome-cmd-user-actions.cc
+++ b/src/gnome-cmd-user-actions.cc
@@ -1243,43 +1243,22 @@ void command_open_nautilus_in_cwd (GtkMenuItem *menuitem, gpointer not_used)
void command_root_mode (GtkMenuItem *menuitem, gpointer not_used)
{
- char *su = NULL;
- gboolean need_c = FALSE;
-
- if ((su = g_find_program_in_path ("xdg-su")))
- goto with_c_param;
- if ((su = g_find_program_in_path ("gksu")))
- goto without_c_param;
- if ((su = g_find_program_in_path ("gnomesu")))
- goto with_c_param;
- if ((su = g_find_program_in_path ("beesu")))
- goto without_c_param;
- if ((su = g_find_program_in_path ("kdesu")))
- goto without_c_param;
-
- gnome_cmd_show_message (NULL, _("xdg-su, gksu, gnomesu, kdesu or beesu is not found"));
- return;
-
- with_c_param:
- need_c = TRUE;
-
- without_c_param:
-
- char *argv[4];
- int i = 0;
-
- argv[i++] = su;
- argv[i++] = g_get_prgname ();
- if (need_c)
- argv[i++] = "-c";
- argv[i++] = NULL;
+ int argc = 1;
+ char **argv = g_new0 (char *, argc+1);
- GError *error = NULL;
+ argv[0] = g_strdup (g_get_prgname ());
+
+ if (gnome_cmd_prepend_su_to_vector (argc, argv))
+ {
+ GError *error = NULL;
- if (!g_spawn_async (NULL, 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 start GNOME Commander in root mode."), error);
+ if (!g_spawn_async (NULL, argv, NULL, G_SPAWN_STDOUT_TO_DEV_NULL, NULL, NULL, NULL, &error))
+ gnome_cmd_error_message (_("Unable to start GNOME Commander in root mode."), error);
+ }
+ else
+ gnome_cmd_show_message (NULL, _("xdg-su, gksu, gnomesu, kdesu or beesu is not found"));
- g_free (su);
+ g_strfreev (argv);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]