kov changed gksu/trunk/ChangeLog, gksu/trunk/gksu/gksu.c,
gksu/trunk/man/gksu.1
Gustavo Noronha
kov at costa.debian.org
Tue Sep 13 17:22:36 UTC 2005
Mensagem de log:
* gksu/gksu.c, man/gksu.1:
- add a --desktop option so that gksu is now able to
read some of the information it uses to fill the dialog
from a desktop file
-----
Modified: gksu/trunk/ChangeLog
===================================================================
--- gksu/trunk/ChangeLog 2005-09-13 02:34:25 UTC (rev 436)
+++ gksu/trunk/ChangeLog 2005-09-13 17:22:35 UTC (rev 437)
@@ -1,3 +1,10 @@
+2005-09-13 Gustavo Noronha Silva <kov at debian.org>
+
+ * gksu/gksu.c, man/gksu.1:
+ - add a --desktop option so that gksu is now able to
+ read some of the information it uses to fill the dialog
+ from a desktop file
+
2005-09-12 Gustavo Noronha Silva <kov at debian.org>
* gksu/gksu.c:
Modified: gksu/trunk/gksu/gksu.c
===================================================================
--- gksu/trunk/gksu/gksu.c 2005-09-13 02:34:25 UTC (rev 436)
+++ gksu/trunk/gksu/gksu.c 2005-09-13 17:22:35 UTC (rev 437)
@@ -9,6 +9,8 @@
#include <string.h>
#include <getopt.h>
+#include <glib/gkeyfile.h>
+
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
@@ -56,6 +58,7 @@
{"sudo-mode", optional_argument, NULL, 'S'},
{"prompt", optional_argument, NULL, 'P'},
{"always-ask-password", optional_argument, NULL, 'a'},
+ {"desktop", required_argument, NULL, 'D'},
{0, 0, 0, 0}
};
@@ -371,6 +374,9 @@
" Replace the default title with the argument.\n"
" --user <user>, -u <user>\n"
" Call <command> as the specified user.\n"
+" --desktop <file>, -D <file>\n"
+" Use a .desktop file to get the name of the application"
+" and the icon from.\n"
"\n"
" --preserve-env, -k\n"
" Preserve the current environments, does not set $HOME\n"
@@ -799,6 +805,96 @@
gtk_widget_destroy (GTK_WIDGET(dialog));
}
+void
+set_dialog_from_desktop (GksuuiDialog *dialog, 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);
+ return;
+ }
+
+ buffer = g_key_file_get_locale_string (desktop, "Desktop Entry",
+ "Name", NULL, NULL);
+ if (buffer)
+ {
+ gchar *msg;
+
+ if (sudo_mode)
+ msg = g_strdup_printf (_("<b>Authentication required</b>\n\n"
+ "You need your password to run:\n\"%s\"."),
+ buffer);
+ else
+ msg = g_strdup_printf (_("<b>Authentication required</b>\n\n"
+ "You need to type %s's password to run:\n\"%s\"."),
+ gksu_context_get_user (context), buffer);
+
+ gksuui_dialog_set_message (dialog, msg);
+
+ g_free (buffer);
+ g_free (msg);
+ message_changed = TRUE;
+ }
+
+ buffer = g_key_file_get_locale_string (desktop, "Desktop Entry",
+ "Icon", NULL, NULL);
+ if (buffer)
+ {
+ GdkPixbuf *pixbuf = NULL;
+ gboolean is_absolute = FALSE;
+ gchar *icon_path;
+
+ is_absolute = !(buffer[0] != '/');
+
+ if (is_absolute)
+ {
+ icon_path = buffer;
+ buffer = NULL;
+ }
+ else
+ {
+ icon_path = g_strdup_printf (DATA_DIR"/pixmaps/%s", buffer);
+ g_free (buffer);
+ }
+
+ pixbuf = gdk_pixbuf_new_from_file (icon_path, &error);
+ if (error)
+ {
+ gchar *error_msg;
+
+ error_msg = g_strdup_printf ("Could not load icon file: %s",
+ error->message);
+ g_warning (error_msg);
+ g_free (error_msg);
+ g_error_free (error);
+
+ if (!is_absolute)
+ g_free (icon_path);
+
+ return;
+ }
+
+ gksuui_dialog_set_icon (dialog, pixbuf);
+
+ if (!is_absolute)
+ g_free (icon_path);
+ }
+}
+
int
main (int argc, char **argv)
{
@@ -812,6 +908,7 @@
gchar **newargv = NULL;
gchar *title = NULL, *message = NULL;
+ gchar *desktop_file_name = NULL;
GdkPixbuf *icon = NULL;
int retvalue = 0;
@@ -856,7 +953,7 @@
context = gksu_context_new ();
gconf_client = gconf_client_get_default ();
get_configuration_options (context);
- while ((c = getopt_long(newargc, newargv, "?hu:lpm:kt:i:gdsS::P::a", long_opts, NULL))
+ while ((c = getopt_long(newargc, newargv, "?hu:lpm:kt:i:gdsS::P::aD:", long_opts, NULL))
!= EOF)
{
switch (c)
@@ -953,6 +1050,10 @@
break;
case 'a':
always_ask_pass = TRUE;
+ break;
+ case 'D':
+ desktop_file_name = g_strdup (optarg);
+ break;
}
}
@@ -994,6 +1095,10 @@
else
dialog = gksuui_dialog_new ();
+ if (desktop_file_name)
+ set_dialog_from_desktop (GKSUUI_DIALOG(dialog), context,
+ desktop_file_name);
+
if (title)
gtk_window_set_title (GTK_WINDOW(dialog), title);
if (message)
Modified: gksu/trunk/man/gksu.1
===================================================================
--- gksu/trunk/man/gksu.1 2005-09-13 02:34:25 UTC (rev 436)
+++ gksu/trunk/man/gksu.1 2005-09-13 17:22:35 UTC (rev 437)
@@ -62,6 +62,10 @@
.IP
Replaces the default window icon with the argument
.HP
+\fB\-\-desktop\R <file>, \fB\-D\fR <file>
+Use a .desktop file to get the name of the application
+and the icon from.
+.HP
\fB\-\-print\-pass\fR, \fB\-p\fR
.IP
Asks gksu to print the password to stdout, just
More information about the gksu-commits
mailing list