[Xfce4-commits] <xfce4-taskmanager:master> Add "Run Task Manager as root" item in "Execute" menu

Mike Massonnet noreply at xfce.org
Sat Jun 19 19:36:03 CEST 2010


Updating branch refs/heads/master
         to d70a49561878f49bb14c020fc2613191aefae486 (commit)
       from a8d0079795404ef1a7899940adcbea1b51f1a88d (commit)

commit d70a49561878f49bb14c020fc2613191aefae486
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Fri Jun 18 15:59:04 2010 +0200

    Add "Run Task Manager as root" item in "Execute" menu

 configure.ac.in      |    9 ++++++---
 src/Makefile.am      |    2 ++
 src/process-window.c |   30 ++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 2cddabe..3522a3b 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -66,11 +66,13 @@ dnl ***********************************
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.12.0])
 XDT_CHECK_PACKAGE([CAIRO], [cairo], [1.5.0])
 
-dnl ******************************************
-dnl *** Check for optional package libwnck ***
-dnl ******************************************
+dnl ***********************************
+dnl *** Check for optional packages ***
+dnl ***********************************
 XDT_CHECK_OPTIONAL_PACKAGE([WNCK], [libwnck-1.0], [2.0], [wnck], [building with libwnck for window icons/names], [yes])
 AM_CONDITIONAL([HAVE_WNCK], [test x"$WNCK_FOUND" = x"yes"])
+XDT_CHECK_OPTIONAL_PACKAGE([GKSU], [libgksu2], [2.0], [gksu], [building with libgksu to run as root], [yes])
+AM_CONDITIONAL([HAVE_GKSU], [test x"$GKSU_FOUND" = x"yes"])
 
 dnl ***********************************
 dnl ********** Check for skel *********
@@ -144,6 +146,7 @@ dnl ***************************
 echo
 echo "Build Configuration:"
 echo
+echo "* Gksu:          ${GKSU_FOUND:-no} "${GKSU_VERSION:+"(libgksu $GKSU_VERSION)"}
 echo "* Wnck:          ${WNCK_FOUND:-no} "${WNCK_VERSION:+"(libwnck $WNCK_VERSION)"}
 echo "* Target OS:     $target_os ($ac_os_implementation)"
 echo "* Debug Support: $enable_debug"
diff --git a/src/Makefile.am b/src/Makefile.am
index f8a1fc3..b9a3b5a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,12 +12,14 @@ xfce4_taskmanager_CFLAGS =						\
 	$(GTK_CFLAGS)							\
 	$(CAIRO_CFLAGS)							\
 	$(WNCK_CFLAGS)							\
+	$(GKSU_CFLAGS)							\
 	$(NULL)
 
 xfce4_taskmanager_LDADD = 						\
 	$(GTK_LIBS)							\
 	$(CAIRO_LIBS)							\
 	$(WNCK_LIBS)							\
+	$(GKSU_LIBS)							\
 	$(NULL)
 
 xfce4_taskmanager_SOURCES =						\
diff --git a/src/process-window.c b/src/process-window.c
index ecd56aa..3d7a258 100644
--- a/src/process-window.c
+++ b/src/process-window.c
@@ -19,6 +19,10 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+#ifdef HAVE_GKSU
+#include <libgksu/libgksu.h>
+#endif
+
 #include "settings.h"
 #include "process-window.h"
 #include "process-window_ui.h"
@@ -210,6 +214,16 @@ monitor_update_step_size (XtmProcessWindow *window)
 	g_object_set (window->priv->mem_monitor, "step-size", refresh_rate / 1000.0, NULL);
 }
 
+#ifdef HAVE_GKSU
+static void
+run_as_root (XtmProcessWindow *window)
+{
+	gtk_widget_hide (window->priv->window);
+	gksu_run (g_get_prgname (), NULL);
+	gtk_widget_show (window->priv->window);
+}
+#endif
+
 static void
 execute_command (const gchar *command)
 {
@@ -256,6 +270,22 @@ show_menu_execute_task (XtmProcessWindow *window)
 	if (menu == NULL)
 	{
 		menu = gtk_menu_new ();
+
+#ifdef HAVE_GKSU
+		/* Run task manager as root */
+		if (geteuid () != 0)
+		{
+			GtkWidget *image = gtk_image_new_from_icon_name ("utilities-system-monitor", GTK_ICON_SIZE_MENU);
+			GtkWidget *mi = gtk_image_menu_item_new_with_label ("Run Task Manager as root");
+			gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image);
+			gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+			g_signal_connect_swapped (mi, "activate", G_CALLBACK (run_as_root), window);
+
+			mi = gtk_separator_menu_item_new ();
+			gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+		}
+#endif
+
 		/* Find a runner program */
 		if (program_exists ("xfrun4"))
 			menu_execute_append_item (GTK_MENU (menu), _("Run Program..."), "xfrun4", "system-run");



More information about the Xfce4-commits mailing list