aboutsummaryrefslogtreecommitdiff
path: root/src/gtk-dialog
diff options
context:
space:
mode:
Diffstat (limited to 'src/gtk-dialog')
-rw-r--r--src/gtk-dialog/Makefile.am4
-rw-r--r--src/gtk-dialog/ck-pk-helper.c98
-rw-r--r--src/gtk-dialog/ck-pk-helper.h4
-rw-r--r--src/gtk-dialog/gconf-helper.c49
-rw-r--r--src/gtk-dialog/gconf-helper.h21
-rw-r--r--src/gtk-dialog/gtk-logout-helper.c12
-rw-r--r--src/gtk-dialog/logout-dialog.c3
7 files changed, 123 insertions, 68 deletions
diff --git a/src/gtk-dialog/Makefile.am b/src/gtk-dialog/Makefile.am
index 90a6209..3f14d78 100644
--- a/src/gtk-dialog/Makefile.am
+++ b/src/gtk-dialog/Makefile.am
@@ -10,6 +10,6 @@ gtk_logout_helper_SOURCES = \
logout-dialog.c \
logout-dialog.h
-gtk_logout_helper_CFLAGS = $(GTKLOGOUTHELPER_CFLAGS) $(GCONF_CFLAGS) -Wall -Werror
-gtk_logout_helper_LDADD = $(GTKLOGOUTHELPER_LIBS) $(GCONF_LIBS)
+gtk_logout_helper_CFLAGS = $(SESSIONSERVICE_CFLAGS) $(GTKLOGOUTHELPER_CFLAGS) $(GCONF_CFLAGS) -Wall -Werror -DINDICATOR_ICONS_DIR="\"$(INDICATORICONSDIR)\""
+gtk_logout_helper_LDADD = $(SESSIONSERVICE_LIBS) $(GTKLOGOUTHELPER_LIBS) $(GCONF_LIBS)
diff --git a/src/gtk-dialog/ck-pk-helper.c b/src/gtk-dialog/ck-pk-helper.c
index 466ccbc..dc7d900 100644
--- a/src/gtk-dialog/ck-pk-helper.c
+++ b/src/gtk-dialog/ck-pk-helper.c
@@ -24,7 +24,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <unistd.h>
#include <glib.h>
#include <dbus/dbus-glib.h>
-#include <polkit-gnome/polkit-gnome.h>
+#include <polkit/polkit.h>
#include "logout-dialog.h"
#include "ck-pk-helper.h"
@@ -170,67 +170,53 @@ pk_require_auth (LogoutDialogAction action) {
}
}
- PolKitResult polres;
+ PolkitAuthorizationResult *polres = NULL;
+ gboolean ret = FALSE;
if (pk_can_do_action(pk_action, &polres)) {
- if (polres == POLKIT_RESULT_YES) {
- return FALSE;
+ if (polkit_authorization_result_get_is_challenge (polres)) {
+ ret = TRUE;
}
- return TRUE;
+ g_debug ("pk_require_auth(%s): authorized, is_challenge: %i", pk_action, ret);
+ } else {
+ g_debug ("pk_require_auth(%s): not authorized", pk_action);
+ }
+ if (polres) {
+ g_object_unref (polres);
}
- return FALSE;
+ return ret;
}
gboolean
-pk_can_do_action (const gchar *action_id, PolKitResult * pol_result)
+pk_can_do_action (const gchar *action_id, PolkitAuthorizationResult ** pol_result)
{
- PolKitGnomeContext *gnome_context;
- PolKitAction *action;
- PolKitCaller *caller;
- DBusError dbus_error;
- PolKitError *error;
- PolKitResult result;
-
- gnome_context = polkit_gnome_context_get (NULL);
-
- if (gnome_context == NULL) {
- return FALSE;
- }
-
- if (gnome_context->pk_tracker == NULL) {
- return FALSE;
- }
-
- dbus_error_init (&dbus_error);
- caller = polkit_tracker_get_caller_from_pid (gnome_context->pk_tracker,
- getpid (),
- &dbus_error);
- dbus_error_free (&dbus_error);
-
- if (caller == NULL) {
- return FALSE;
- }
-
- action = polkit_action_new ();
- if (!polkit_action_set_action_id (action, action_id)) {
- polkit_action_unref (action);
- polkit_caller_unref (caller);
- return FALSE;
- }
-
- result = POLKIT_RESULT_UNKNOWN;
- error = NULL;
- result = polkit_context_is_caller_authorized (gnome_context->pk_context,
- action, caller, FALSE,
- &error);
- if (polkit_error_is_set (error)) {
- polkit_error_free (error);
- }
- polkit_action_unref (action);
- polkit_caller_unref (caller);
-
- if (pol_result != NULL) {
- *pol_result = result;
- }
+ PolkitAuthority *authority;
+ PolkitSubject *subject;
+ PolkitAuthorizationResult *result;
+ gboolean ret;
+
+ authority = polkit_authority_get();
+ if (!authority) {
+ g_warning ("Could not get PolicyKit authority instance");
+ return FALSE;
+ }
+ subject = polkit_unix_process_new (getpid());
- return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN;
+ result = polkit_authority_check_authorization_sync (authority, subject, action_id, NULL, 0, NULL, NULL);
+ g_object_unref (authority);
+
+ ret = FALSE;
+ if (result) {
+ ret = polkit_authorization_result_get_is_authorized (result) ||
+ polkit_authorization_result_get_is_challenge (result);
+ g_debug ("pk_can_do_action(%s): %i", action_id, ret);
+ } else {
+ g_warning ("pk_can_do_action(%s): check_authorization returned NULL", action_id);
+ }
+ if (pol_result) {
+ *pol_result = result;
+ } else {
+ g_object_unref (result);
+ }
+ return ret;
+
}
diff --git a/src/gtk-dialog/ck-pk-helper.h b/src/gtk-dialog/ck-pk-helper.h
index 98bce56..501a8c8 100644
--- a/src/gtk-dialog/ck-pk-helper.h
+++ b/src/gtk-dialog/ck-pk-helper.h
@@ -24,9 +24,9 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef __CK_PK_HELPER_H__
#define __CK_PK_HELPER_H__ 1
-#include <polkit-gnome/polkit-gnome.h>
+#include <polkit/polkit.h>
gboolean pk_require_auth (LogoutDialogAction action);
-gboolean pk_can_do_action (const gchar *action_id, PolKitResult * pol_result);
+gboolean pk_can_do_action (const gchar *action_id, PolkitAuthorizationResult ** pol_result);
#endif /* __CK_PK_HELPER__ */
diff --git a/src/gtk-dialog/gconf-helper.c b/src/gtk-dialog/gconf-helper.c
index 0bd21ad..213592e 100644
--- a/src/gtk-dialog/gconf-helper.c
+++ b/src/gtk-dialog/gconf-helper.c
@@ -1,6 +1,5 @@
/*
-A small wrapper utility to load indicators and put them as menu items
-into the gnome-panel using it's applet interface.
+A small wrapper utility for connecting to gconf.
Copyright 2009 Canonical Ltd.
@@ -23,10 +22,52 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <gconf/gconf-client.h>
+#include <glib/gi18n.h>
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+
+#include <libdbusmenu-glib/server.h>
+#include <libdbusmenu-glib/menuitem.h>
+
#include "gconf-helper.h"
+static GConfClient * gconf_client = NULL;
+
gboolean
supress_confirmations (void) {
- GConfClient *client = gconf_client_get_default ();
- return gconf_client_get_bool (client, SUPPRESS_KEY, NULL) ;
+ if(!gconf_client) {
+ gconf_client = gconf_client_get_default ();
+ }
+ return gconf_client_get_bool (gconf_client, SUPPRESS_KEY, NULL) ;
+}
+
+static void update_menu_entries_callback (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data) {
+ RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = (RestartShutdownLogoutMenuItems*) data;
+ GConfValue * value = gconf_entry_get_value (entry);
+ const gchar * key = gconf_entry_get_key (entry);
+
+ if(g_strcmp0 (key, SUPPRESS_KEY) == 0) {
+ if (gconf_value_get_bool (value)) {
+ dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out"));
+ dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart"));
+ dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shutdown"));
+ } else {
+ dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out..."));
+ dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart..."));
+ dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shutdown..."));
+ }
+ }
}
+
+void
+update_menu_entries(RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi) {
+ if(!gconf_client) {
+ gconf_client = gconf_client_get_default ();
+ }
+ gconf_client_add_dir (gconf_client, GLOBAL_DIR,
+ GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ gconf_client_notify_add (gconf_client, SUPPRESS_KEY,
+ update_menu_entries_callback, restart_shutdown_logout_mi, NULL, NULL);
+}
+
diff --git a/src/gtk-dialog/gconf-helper.h b/src/gtk-dialog/gconf-helper.h
index 1d78fd8..951bb0f 100644
--- a/src/gtk-dialog/gconf-helper.h
+++ b/src/gtk-dialog/gconf-helper.h
@@ -1,6 +1,5 @@
/*
-A small wrapper utility to load indicators and put them as menu items
-into the gnome-panel using it's applet interface.
+A small wrapper utility for connecting to gconf.
Copyright 2009 Canonical Ltd.
@@ -26,8 +25,26 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <gconf/gconf-client.h>
+#include <glib/gi18n.h>
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+
+#include <libdbusmenu-glib/server.h>
+#include <libdbusmenu-glib/menuitem.h>
+
#define SUPPRESS_KEY "/apps/indicator-session/suppress_logout_restart_shutdown"
+#define GLOBAL_DIR "/apps/indicator-session"
+
+typedef struct _RestartShutdownLogoutMenuItems
+{
+ DbusmenuMenuitem * logout_mi;
+ DbusmenuMenuitem * restart_mi;
+ DbusmenuMenuitem * shutdown_mi;
+}
+RestartShutdownLogoutMenuItems;
+void update_menu_entries(RestartShutdownLogoutMenuItems*);
gboolean supress_confirmations (void);
#endif /* __GCONF_HELPER__ */
diff --git a/src/gtk-dialog/gtk-logout-helper.c b/src/gtk-dialog/gtk-logout-helper.c
index 13991ca..0c03e86 100644
--- a/src/gtk-dialog/gtk-logout-helper.c
+++ b/src/gtk-dialog/gtk-logout-helper.c
@@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
+#include <config.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <dbus/dbus-glib.h>
@@ -121,6 +121,12 @@ main (int argc, char * argv[])
{
gtk_init(&argc, &argv);
+ /* Setting up i18n and gettext. Apparently, we need
+ all of these. */
+ setlocale (LC_ALL, "");
+ bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+ textdomain (GETTEXT_PACKAGE);
+
GError * error = NULL;
GOptionContext * context = g_option_context_new(" - logout of the current session");
g_option_context_add_main_entries(context, options, "gtk-logout-helper");
@@ -133,6 +139,10 @@ main (int argc, char * argv[])
return 1;
}
+ /* Init some theme/icon stuff */
+ gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
+ INDICATOR_ICONS_DIR);
+
GtkWidget * dialog = NULL;
if (!pk_require_auth(type) && !supress_confirmations()) {
dialog = logout_dialog_new(type);
diff --git a/src/gtk-dialog/logout-dialog.c b/src/gtk-dialog/logout-dialog.c
index a80dbef..a94c649 100644
--- a/src/gtk-dialog/logout-dialog.c
+++ b/src/gtk-dialog/logout-dialog.c
@@ -298,8 +298,9 @@ logout_dialog_init (LogoutDialog *logout_dialog)
GTK_RESPONSE_OK);
gtk_widget_grab_default (logout_dialog->ok_button);
- /* Title */
+ /* Window Title and Icon */
gtk_window_set_title (GTK_WINDOW(logout_dialog), _(title_strings[logout_dialog->action]));
+ gtk_window_set_icon_name (GTK_WINDOW(logout_dialog), icon_strings[logout_dialog->action]);
/* hbox */
logout_dialog->hbox = gtk_hbox_new (FALSE, 12);