kov changed gksu/branches/gksu2/ChangeLog, gksu/branches/gksu2/gksu/gksu.c

Gustavo Noronha kov at costa.debian.org
Sun Apr 30 19:17:55 UTC 2006


Mensagem de log: 
reimplemented the --desktop functionality by using
the new set_description API


-----


Modified: gksu/branches/gksu2/ChangeLog
===================================================================
--- gksu/branches/gksu2/ChangeLog	2006-04-30 18:56:21 UTC (rev 578)
+++ gksu/branches/gksu2/ChangeLog	2006-04-30 19:17:54 UTC (rev 579)
@@ -1,3 +1,9 @@
+2006-04-30  Gustavo Noronha Silva  <kov at debian.org>
+
+	* gksu/gksu.c:
+	- reimplemented the --desktop functionality by using
+	  the new set_description API
+
 2006-04-25  Gustavo Noronha Silva  <kov at debian.org>
 
 	* gksu/gksu.c:

Modified: gksu/branches/gksu2/gksu/gksu.c
===================================================================
--- gksu/branches/gksu2/gksu/gksu.c	2006-04-30 18:56:21 UTC (rev 578)
+++ gksu/branches/gksu2/gksu/gksu.c	2006-04-30 19:17:54 UTC (rev 579)
@@ -9,6 +9,9 @@
 #include <string.h>
 #include <getopt.h>
 
+#include <glib.h>
+#include <glib/gstdio.h>
+
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #include <X11/Xlib.h>
@@ -55,6 +58,7 @@
     {"su-mode", no_argument, NULL, 'w'},
     {"prompt", optional_argument, NULL, 'P'},
     {"desktop", required_argument, NULL, 'D'},
+    {"description", required_argument, NULL, 'D'},
     {0, 0, 0, 0}
 };
 
@@ -72,44 +76,53 @@
   gchar *help_trans;
   const gchar* help_text[] = {
     N_("GKsu version %s\n\n"),
-    N_("Usage: %s [-u <user>] [-k] [-l] <command>\n\n"),
+    N_("Usage: %s [-u <user>] [options] <command>\n\n"),
     N_("  --debug, -d\n"
        "    Print information on the screen that might be\n"
        "    useful for diagnosing and/or solving problems.\n"),
+    N_("\n"),
+    N_("  --user <user>, -u <user>\n"
+       "    Call <command> as the specified user.\n"),
+    N_("\n"),
     N_("  --disable-grab, -g\n"
        "    Disable the \"locking\" of the keyboard, mouse,\n"
        "    and focus done by the program when asking for\n"
        "    password.\n"),
+    N_("  --prompt, -P\n"
+       "    Ask the user if they want to have their keyboard\n"
+       "    and mouse grabbed before doing so.\n"),
+    N_("  --preserve-env, -k\n"
+       "    Preserve the current environments, does not set $HOME\n"
+       "    nor $PATH, for example.\n"),
+    N_("  --login, -l\n"
+       "    Make this a login shell. Beware this may cause\n"
+       "    problems with the Xauthority magic. Run xhost\n"
+       "    to allow the target user to open windows on your\n"
+       "    display!\n"),
+    N_("\n"),
+    N_("  --description <description|file>, -D <description|file>\n"
+       "    Provide a descriptional name for the command to\n"
+       "    be used in the default message, making it nicer.\n"
+       "    You can also provide the absolute path for a\n"
+       "    .desktop file. The Name key for will be used in\n"
+       "    this case.\n"),
     N_("  --message <message>, -m <message>\n"
        "    Replace the standard message shown to ask for\n"
-       "    password for the argument passed to the option.\n"),
+       "    password for the argument passed to the option.\n"
+       "    Only use this if --description does not suffice.\n"),
+    N_("\n"),
     N_("  --print-pass, -p\n"
        "    Ask gksu to print the password to stdout, just\n"
        "    like ssh-askpass. Useful to use in scripts with\n"
        "    programs that accept receiving the password on\n"
        "    stdin.\n"),
-    N_("  --prompt, -P\n"
-       "    Ask the user if they want to have their keyboard\n"
-       "    and mouse grabbed before doing so.\n"),
+    N_("\n"),
     N_("  --sudo-mode, -S\n"
        "    Make GKSu use sudo instead of su, as if it had been\n"
        "    run as \"gksudo\".\n"),
     N_("  --su-mode, -w\n"
        "    Make GKSu use su, even if instead of using libgksu's\n"
        "    default.\n"),
-    N_("  --user <user>, -u <user>\n"
-       "    Call <command> as the specified user.\n"),
-    N_("\n"),
-    N_("  --preserve-env, -k\n"
-       "    Preserve the current environments, does not set $HOME\n"
-       "    nor $PATH, for example.\n"),
-    N_("  --login, -l\n"
-       "    Make this a login shell. Beware this may cause\n"
-       "    problems with the Xauthority magic. Run xhost\n"
-       "    to allow the target user to open windows on your\n"
-       "    display!\n"
-       "\n"
-       "\n")
   };
 
   help_trans = g_strconcat(_(help_text[0]), _(help_text[1]),
@@ -155,6 +168,40 @@
   gtk_widget_destroy (diag_win);
 }
 
+void
+set_description_from_desktop (GksuContext *context, gchar *file_name)
+{
+  GKeyFile *desktop;
+  GError *error = NULL;
+  gchar *buffer = NULL;
+
+  desktop = g_key_file_new ();
+
+  g_key_file_load_from_file (desktop, file_name, G_KEY_FILE_NONE, &error);
+  if (error)
+    {
+      gchar *error_msg;
+
+      error_msg = g_strdup_printf ("Could not load desktop file: %s",
+				   error->message);
+      g_warning (error_msg);
+      g_free (error_msg);
+      g_error_free (error);
+      g_key_file_free (desktop);
+      return;
+    }
+
+  buffer = g_key_file_get_locale_string (desktop, "Desktop Entry",
+					 "Name", NULL, NULL);
+  if (buffer)
+    {
+      gksu_context_set_description (context, buffer);
+      g_free (buffer);
+    }
+
+  g_key_file_free (desktop);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -259,6 +306,12 @@
 	case 'd':
 	  gksu_context_set_debug (context, TRUE);
 	  break;
+	case 'D':
+	  if (!g_access (optarg, R_OK))
+	    set_description_from_desktop (context, optarg);
+	  else
+	    gksu_context_set_description (context, optarg);
+	  break;
 	case 'S':
 	  run_mode = SUDO_MODE;
 	  break;
@@ -355,7 +408,7 @@
   sn_display = sn_display_new (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
 			       NULL, NULL);
   context->sn_context = sn_launcher_context_new (sn_display, gdk_screen_get_number (gdk_display_get_default_screen (gdk_display_get_default ())));
-  sn_launcher_context_set_description (context->sn_context, _("Grant Rights"));
+  sn_launcher_context_set_description (context->sn_context, _("Granting Rights"));
   sn_launcher_context_set_name (context->sn_context, g_get_prgname ());
   sn_launcher_context_set_binary_name (context->sn_context,
 				       gksu_context_get_command (context));




More information about the gksu-commits mailing list