From 68d13604c069937cdb1e6cab3ecd54cfb45fc593 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Mar 2010 15:49:41 -0600 Subject: Flattening the build tree. --- src/Makefile.am | 31 +++++- src/dialog.c | 153 ++++++++++++++++++++++++++ src/dialog.h | 42 ++++++++ src/gconf-helper.c | 73 +++++++++++++ src/gconf-helper.h | 50 +++++++++ src/gtk-dialog/Makefile.am | 13 --- src/gtk-dialog/dialog.c | 153 -------------------------- src/gtk-dialog/dialog.h | 42 -------- src/gtk-dialog/gconf-helper.c | 73 ------------- src/gtk-dialog/gconf-helper.h | 50 --------- src/gtk-dialog/gtk-logout-helper.c | 216 ------------------------------------- src/gtk-logout-helper.c | 216 +++++++++++++++++++++++++++++++++++++ src/session-service.c | 2 +- 13 files changed, 563 insertions(+), 551 deletions(-) create mode 100644 src/dialog.c create mode 100644 src/dialog.h create mode 100644 src/gconf-helper.c create mode 100644 src/gconf-helper.h delete mode 100644 src/gtk-dialog/Makefile.am delete mode 100644 src/gtk-dialog/dialog.c delete mode 100644 src/gtk-dialog/dialog.h delete mode 100644 src/gtk-dialog/gconf-helper.c delete mode 100644 src/gtk-dialog/gconf-helper.h delete mode 100644 src/gtk-dialog/gtk-logout-helper.c create mode 100644 src/gtk-logout-helper.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index a07c782..cd525bd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,7 @@ -SUBDIRS = gtk-dialog -libexec_PROGRAMS = indicator-session-service +libexec_PROGRAMS = \ + indicator-session-service \ + gtk-logout-helper ################### # Indicator Stuff @@ -50,13 +51,37 @@ indicator_session_service_SOURCES = \ lock-helper.h \ session-service.c \ dbusmenu-shared.h \ - gtk-dialog/gconf-helper.c \ + gconf-helper.c \ users-service-dbus.h \ users-service-dbus.c \ users-service-marshal.c indicator_session_service_CFLAGS = $(SESSIONSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) $(GCONF_LIBS) +################# +# GTK Logout Stuff +################# + +gtk_logout_helper_SOURCES = \ + gtk-logout-helper.c \ + gconf-helper.c \ + gconf-helper.h \ + dialog.c \ + dialog.h + +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) + + ############### # Other Stuff ############### diff --git a/src/dialog.c b/src/dialog.c new file mode 100644 index 0000000..7e2347e --- /dev/null +++ b/src/dialog.c @@ -0,0 +1,153 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "dialog.h" + +/* Strings */ + +static const gchar * title_strings[LOGOUT_DIALOG_TYPE_CNT] = { + /* LOGOUT_DIALOG_LOGOUT, */ NC_("title", "Log Out"), + /* LOGOUT_DIALOG_RESTART, */ NC_("title", "Restart"), + /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("title", "Switch Off") +}; + +static const gchar * body_strings[LOGOUT_DIALOG_TYPE_CNT] = { + /* LOGOUT_DIALOG_LOGOUT, */ N_("Are you sure you want to close all programs and log out?"), + /* LOGOUT_DIALOG_RESTART, */ N_("Are you sure you want to close all programs and restart the computer?"), + /* LOGOUT_DIALOG_SHUTDOWN, */ N_("Are you sure you want to close all programs and shut down the computer?") +}; + +static const gchar * button_strings[LOGOUT_DIALOG_TYPE_CNT] = { + /* LOGOUT_DIALOG_LOGOUT, */ NC_("button", "Log Out"), + /* LOGOUT_DIALOG_RESTART, */ NC_("button", "Restart"), + /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("button", "Switch Off") +}; + +/* +static const gchar * restart_updates = N_("Restart Instead"); +static const gchar * restart_auth = N_("Restart..."); +static const gchar * body_logout_update = N_("Some software updates won't apply until the computer next restarts."); +*/ + +static const gchar * icon_strings[LOGOUT_DIALOG_TYPE_CNT] = { + /* LOGOUT_DIALOG_LOGOUT, */ "system-log-out", + /* LOGOUT_DIALOG_RESTART, */ "system-restart", + /* LOGOUT_DIALOG_SHUTDOWN, */ "system-shutdown" +}; + + + +typedef struct _LogoutDialogPrivate LogoutDialogPrivate; +struct _LogoutDialogPrivate { + guint type; +}; + +#define LOGOUT_DIALOG_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), LOGOUT_DIALOG_TYPE, LogoutDialogPrivate)) + +static void logout_dialog_class_init (LogoutDialogClass *klass); +static void logout_dialog_init (LogoutDialog *self); +static void logout_dialog_dispose (GObject *object); +static void logout_dialog_finalize (GObject *object); + +G_DEFINE_TYPE (LogoutDialog, logout_dialog, GTK_TYPE_MESSAGE_DIALOG); + +static void +logout_dialog_class_init (LogoutDialogClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (LogoutDialogPrivate)); + + object_class->dispose = logout_dialog_dispose; + object_class->finalize = logout_dialog_finalize; + + return; +} + +static void +logout_dialog_init (LogoutDialog *self) +{ + + return; +} + +static void +logout_dialog_dispose (GObject *object) +{ + + + G_OBJECT_CLASS (logout_dialog_parent_class)->dispose (object); + return; +} + +static void +logout_dialog_finalize (GObject *object) +{ + + + G_OBJECT_CLASS (logout_dialog_parent_class)->finalize (object); + return; +} + +/* Checks for updates that would signal that a restart is + required for them to apply */ +static gboolean +check_restart_required (void) +{ + + return FALSE; +} + +/* Checks with console kit to see if we can do what we want */ +static gboolean +ck_check_allowed (LogoutDialogType type) +{ + + + + return TRUE; +} + +LogoutDialog * +logout_dialog_new (LogoutDialogType type) +{ + GtkWidget * image = gtk_image_new_from_icon_name(icon_strings[type], GTK_ICON_SIZE_DIALOG); + gtk_widget_show(image); + + LogoutDialog * dialog = LOGOUT_DIALOG(g_object_new(LOGOUT_DIALOG_TYPE, + /* Window */ + "icon-name", icon_strings[type], + "modal", TRUE, + "resizable", FALSE, + "title", _(title_strings[type]), + "window-position", GTK_WIN_POS_CENTER_ALWAYS, + /* Message Dialog */ + "buttons", GTK_BUTTONS_NONE, + "image", image, + "message-type", GTK_MESSAGE_OTHER, + "text", _(body_strings[type]), + NULL)); + + gboolean allowed = FALSE; + if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) { + allowed = ck_check_allowed(LOGOUT_DIALOG_TYPE_RESTART); + } else { + allowed = ck_check_allowed(type); + } + + gboolean restart_required = FALSE; + if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) { + restart_required = check_restart_required(); + } + + gtk_dialog_add_buttons(GTK_DIALOG(dialog), + _("Cancel"), GTK_RESPONSE_CANCEL, + _(button_strings[type]), GTK_RESPONSE_OK, + NULL); + + return dialog; +} diff --git a/src/dialog.h b/src/dialog.h new file mode 100644 index 0000000..3240a8e --- /dev/null +++ b/src/dialog.h @@ -0,0 +1,42 @@ +#ifndef __LOGOUT_DIALOG_H__ +#define __LOGOUT_DIALOG_H__ + +#include +#include + +#include + +G_BEGIN_DECLS + +#define LOGOUT_DIALOG_TYPE (logout_dialog_get_type ()) +#define LOGOUT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOGOUT_DIALOG_TYPE, LogoutDialog)) +#define LOGOUT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOGOUT_DIALOG_TYPE, LogoutDialogClass)) +#define IS_LOGOUT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOGOUT_DIALOG_TYPE)) +#define IS_LOGOUT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOGOUT_DIALOG_TYPE)) +#define LOGOUT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOGOUT_DIALOG_TYPE, LogoutDialogClass)) + +typedef enum _LogoutDialogType LogoutDialogType; +enum _LogoutDialogType { + LOGOUT_DIALOG_TYPE_LOG_OUT, + LOGOUT_DIALOG_TYPE_RESTART, + LOGOUT_DIALOG_TYPE_SHUTDOWN, + LOGOUT_DIALOG_TYPE_CNT +}; + +typedef struct _LogoutDialog LogoutDialog; +typedef struct _LogoutDialogClass LogoutDialogClass; + +struct _LogoutDialogClass { + GtkMessageDialogClass parent_class; +}; + +struct _LogoutDialog { + GtkMessageDialog parent; +}; + +GType logout_dialog_get_type (void); +LogoutDialog * logout_dialog_new (LogoutDialogType type); + +G_END_DECLS + +#endif diff --git a/src/gconf-helper.c b/src/gconf-helper.c new file mode 100644 index 0000000..213592e --- /dev/null +++ b/src/gconf-helper.c @@ -0,0 +1,73 @@ +/* +A small wrapper utility for connecting to gconf. + +Copyright 2009 Canonical Ltd. + +Authors: + Christoph Korn + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + + +#include + +#include + +#include +#include + +#include +#include + +#include "gconf-helper.h" + +static GConfClient * gconf_client = NULL; + +gboolean +supress_confirmations (void) { + 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/gconf-helper.h b/src/gconf-helper.h new file mode 100644 index 0000000..951bb0f --- /dev/null +++ b/src/gconf-helper.h @@ -0,0 +1,50 @@ +/* +A small wrapper utility for connecting to gconf. + +Copyright 2009 Canonical Ltd. + +Authors: + Christoph Korn + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + + +#ifndef __GCONF_HELPER_H__ +#define __GCONF_HELPER_H__ 1 + +#include + +#include + +#include +#include + +#include +#include + +#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/Makefile.am b/src/gtk-dialog/Makefile.am deleted file mode 100644 index 508beb2..0000000 --- a/src/gtk-dialog/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ - -libexec_PROGRAMS = gtk-logout-helper - -gtk_logout_helper_SOURCES = \ - gtk-logout-helper.c \ - gconf-helper.c \ - gconf-helper.h \ - dialog.c \ - dialog.h - -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/dialog.c b/src/gtk-dialog/dialog.c deleted file mode 100644 index 7e2347e..0000000 --- a/src/gtk-dialog/dialog.c +++ /dev/null @@ -1,153 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "dialog.h" - -/* Strings */ - -static const gchar * title_strings[LOGOUT_DIALOG_TYPE_CNT] = { - /* LOGOUT_DIALOG_LOGOUT, */ NC_("title", "Log Out"), - /* LOGOUT_DIALOG_RESTART, */ NC_("title", "Restart"), - /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("title", "Switch Off") -}; - -static const gchar * body_strings[LOGOUT_DIALOG_TYPE_CNT] = { - /* LOGOUT_DIALOG_LOGOUT, */ N_("Are you sure you want to close all programs and log out?"), - /* LOGOUT_DIALOG_RESTART, */ N_("Are you sure you want to close all programs and restart the computer?"), - /* LOGOUT_DIALOG_SHUTDOWN, */ N_("Are you sure you want to close all programs and shut down the computer?") -}; - -static const gchar * button_strings[LOGOUT_DIALOG_TYPE_CNT] = { - /* LOGOUT_DIALOG_LOGOUT, */ NC_("button", "Log Out"), - /* LOGOUT_DIALOG_RESTART, */ NC_("button", "Restart"), - /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("button", "Switch Off") -}; - -/* -static const gchar * restart_updates = N_("Restart Instead"); -static const gchar * restart_auth = N_("Restart..."); -static const gchar * body_logout_update = N_("Some software updates won't apply until the computer next restarts."); -*/ - -static const gchar * icon_strings[LOGOUT_DIALOG_TYPE_CNT] = { - /* LOGOUT_DIALOG_LOGOUT, */ "system-log-out", - /* LOGOUT_DIALOG_RESTART, */ "system-restart", - /* LOGOUT_DIALOG_SHUTDOWN, */ "system-shutdown" -}; - - - -typedef struct _LogoutDialogPrivate LogoutDialogPrivate; -struct _LogoutDialogPrivate { - guint type; -}; - -#define LOGOUT_DIALOG_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), LOGOUT_DIALOG_TYPE, LogoutDialogPrivate)) - -static void logout_dialog_class_init (LogoutDialogClass *klass); -static void logout_dialog_init (LogoutDialog *self); -static void logout_dialog_dispose (GObject *object); -static void logout_dialog_finalize (GObject *object); - -G_DEFINE_TYPE (LogoutDialog, logout_dialog, GTK_TYPE_MESSAGE_DIALOG); - -static void -logout_dialog_class_init (LogoutDialogClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (LogoutDialogPrivate)); - - object_class->dispose = logout_dialog_dispose; - object_class->finalize = logout_dialog_finalize; - - return; -} - -static void -logout_dialog_init (LogoutDialog *self) -{ - - return; -} - -static void -logout_dialog_dispose (GObject *object) -{ - - - G_OBJECT_CLASS (logout_dialog_parent_class)->dispose (object); - return; -} - -static void -logout_dialog_finalize (GObject *object) -{ - - - G_OBJECT_CLASS (logout_dialog_parent_class)->finalize (object); - return; -} - -/* Checks for updates that would signal that a restart is - required for them to apply */ -static gboolean -check_restart_required (void) -{ - - return FALSE; -} - -/* Checks with console kit to see if we can do what we want */ -static gboolean -ck_check_allowed (LogoutDialogType type) -{ - - - - return TRUE; -} - -LogoutDialog * -logout_dialog_new (LogoutDialogType type) -{ - GtkWidget * image = gtk_image_new_from_icon_name(icon_strings[type], GTK_ICON_SIZE_DIALOG); - gtk_widget_show(image); - - LogoutDialog * dialog = LOGOUT_DIALOG(g_object_new(LOGOUT_DIALOG_TYPE, - /* Window */ - "icon-name", icon_strings[type], - "modal", TRUE, - "resizable", FALSE, - "title", _(title_strings[type]), - "window-position", GTK_WIN_POS_CENTER_ALWAYS, - /* Message Dialog */ - "buttons", GTK_BUTTONS_NONE, - "image", image, - "message-type", GTK_MESSAGE_OTHER, - "text", _(body_strings[type]), - NULL)); - - gboolean allowed = FALSE; - if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) { - allowed = ck_check_allowed(LOGOUT_DIALOG_TYPE_RESTART); - } else { - allowed = ck_check_allowed(type); - } - - gboolean restart_required = FALSE; - if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) { - restart_required = check_restart_required(); - } - - gtk_dialog_add_buttons(GTK_DIALOG(dialog), - _("Cancel"), GTK_RESPONSE_CANCEL, - _(button_strings[type]), GTK_RESPONSE_OK, - NULL); - - return dialog; -} diff --git a/src/gtk-dialog/dialog.h b/src/gtk-dialog/dialog.h deleted file mode 100644 index 3240a8e..0000000 --- a/src/gtk-dialog/dialog.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __LOGOUT_DIALOG_H__ -#define __LOGOUT_DIALOG_H__ - -#include -#include - -#include - -G_BEGIN_DECLS - -#define LOGOUT_DIALOG_TYPE (logout_dialog_get_type ()) -#define LOGOUT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOGOUT_DIALOG_TYPE, LogoutDialog)) -#define LOGOUT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOGOUT_DIALOG_TYPE, LogoutDialogClass)) -#define IS_LOGOUT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOGOUT_DIALOG_TYPE)) -#define IS_LOGOUT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOGOUT_DIALOG_TYPE)) -#define LOGOUT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOGOUT_DIALOG_TYPE, LogoutDialogClass)) - -typedef enum _LogoutDialogType LogoutDialogType; -enum _LogoutDialogType { - LOGOUT_DIALOG_TYPE_LOG_OUT, - LOGOUT_DIALOG_TYPE_RESTART, - LOGOUT_DIALOG_TYPE_SHUTDOWN, - LOGOUT_DIALOG_TYPE_CNT -}; - -typedef struct _LogoutDialog LogoutDialog; -typedef struct _LogoutDialogClass LogoutDialogClass; - -struct _LogoutDialogClass { - GtkMessageDialogClass parent_class; -}; - -struct _LogoutDialog { - GtkMessageDialog parent; -}; - -GType logout_dialog_get_type (void); -LogoutDialog * logout_dialog_new (LogoutDialogType type); - -G_END_DECLS - -#endif diff --git a/src/gtk-dialog/gconf-helper.c b/src/gtk-dialog/gconf-helper.c deleted file mode 100644 index 213592e..0000000 --- a/src/gtk-dialog/gconf-helper.c +++ /dev/null @@ -1,73 +0,0 @@ -/* -A small wrapper utility for connecting to gconf. - -Copyright 2009 Canonical Ltd. - -Authors: - Christoph Korn - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ - - -#include - -#include - -#include -#include - -#include -#include - -#include "gconf-helper.h" - -static GConfClient * gconf_client = NULL; - -gboolean -supress_confirmations (void) { - 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 deleted file mode 100644 index 951bb0f..0000000 --- a/src/gtk-dialog/gconf-helper.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -A small wrapper utility for connecting to gconf. - -Copyright 2009 Canonical Ltd. - -Authors: - Christoph Korn - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ - - -#ifndef __GCONF_HELPER_H__ -#define __GCONF_HELPER_H__ 1 - -#include - -#include - -#include -#include - -#include -#include - -#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 deleted file mode 100644 index bf37ca7..0000000 --- a/src/gtk-dialog/gtk-logout-helper.c +++ /dev/null @@ -1,216 +0,0 @@ -/* -A small wrapper utility to load indicators and put them as menu items -into the gnome-panel using it's applet interface. - -Copyright 2009 Canonical Ltd. - -Authors: - Ted Gould - Christoph Korn - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ - -#include -#include -#include -#include -#include "dialog.h" -#include "gconf-helper.h" - -static void -consolekit_fallback (LogoutDialogType action) -{ - DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - g_return_if_fail(sbus != NULL); /* worst case */ - DBusGProxy * proxy = dbus_g_proxy_new_for_name(sbus, "org.freedesktop.ConsoleKit", - "/org/freedesktop/ConsoleKit/Manager", - "org.freedesktop.ConsoleKit.Manager"); - - if (proxy == NULL) { - g_warning("Unable to get consolekit proxy"); - return; - } - - GError * error = NULL; - - switch (action) { - case LOGOUT_DIALOG_TYPE_LOG_OUT: - g_warning("Unable to fallback to ConsoleKit for logout as it's a session issue. We need some sort of session handler."); - break; - case LOGOUT_DIALOG_TYPE_SHUTDOWN: - dbus_g_proxy_call(proxy, - "Stop", - &error, - G_TYPE_INVALID); - break; - case LOGOUT_DIALOG_TYPE_RESTART: - dbus_g_proxy_call(proxy, - "Restart", - &error, - G_TYPE_INVALID); - break; - default: - g_warning("Unknown action"); - break; - } - - g_object_unref(proxy); - - if (error != NULL) { - g_error("Unable to signal ConsoleKit: %s", error->message); - g_error_free(error); - } - - return; -} - -static void -session_action (LogoutDialogType action) -{ - DBusGConnection * sbus; - DBusGProxy * sm_proxy; - GError * error = NULL; - gboolean res = FALSE; - - sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - if (sbus == NULL) { - g_warning("Unable to get DBus session bus."); - return; - } - sm_proxy = dbus_g_proxy_new_for_name_owner (sbus, - "org.gnome.SessionManager", - "/org/gnome/SessionManager", - "org.gnome.SessionManager", - &error); - if (sm_proxy == NULL) { - g_warning("Unable to get DBus proxy to SessionManager interface: %s", error->message); - g_error_free(error); - - consolekit_fallback(action); - return; - } - - g_clear_error (&error); - - if (action == LOGOUT_DIALOG_TYPE_LOG_OUT) { - res = dbus_g_proxy_call_with_timeout (sm_proxy, "Logout", INT_MAX, &error, - G_TYPE_UINT, 1, G_TYPE_INVALID, G_TYPE_INVALID); - } else if (action == LOGOUT_DIALOG_TYPE_SHUTDOWN) { - res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestShutdown", INT_MAX, &error, - G_TYPE_INVALID, G_TYPE_INVALID); - } else if (action == LOGOUT_DIALOG_TYPE_RESTART) { - res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestReboot", INT_MAX, &error, - G_TYPE_INVALID, G_TYPE_INVALID); - } else { - g_warning ("Unknown session action"); - } - - if (!res) { - if (error != NULL) { - g_warning ("SessionManager action failed: %s", error->message); - } else { - g_warning ("SessionManager action failed: unknown error"); - } - } - - g_object_unref(sm_proxy); - - if (error != NULL) { - g_error_free(error); - } - - return; -} - -static LogoutDialogType type = LOGOUT_DIALOG_TYPE_LOG_OUT; - -static gboolean -option_logout (const gchar * arg, const gchar * value, gpointer data, GError * error) -{ - type = LOGOUT_DIALOG_TYPE_LOG_OUT; - return TRUE; -} - -static gboolean -option_shutdown (const gchar * arg, const gchar * value, gpointer data, GError * error) -{ - type = LOGOUT_DIALOG_TYPE_SHUTDOWN; - return TRUE; -} - -static gboolean -option_restart (const gchar * arg, const gchar * value, gpointer data, GError * error) -{ - type = LOGOUT_DIALOG_TYPE_RESTART; - return TRUE; -} - -static GOptionEntry options[] = { - {"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_logout, "Log out of the current session", NULL}, - {"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_shutdown, "Shutdown the entire system", NULL}, - {"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restart, "Restart the system", NULL}, - - {NULL} -}; - -int -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"); - g_option_context_add_group(context, gtk_get_option_group(TRUE)); - g_option_context_set_help_enabled(context, TRUE); - - if (!g_option_context_parse(context, &argc, &argv, &error)) { - g_debug("Option parsing failed: %s", error->message); - g_error_free(error); - 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 (!supress_confirmations()) { - dialog = GTK_WIDGET(logout_dialog_new(type)); - } - - if (dialog != NULL) { - GtkResponseType response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_hide(dialog); - - if (response == GTK_RESPONSE_HELP) { - type = LOGOUT_DIALOG_TYPE_RESTART; - response = GTK_RESPONSE_OK; - } - - if (response != GTK_RESPONSE_OK) { - return 0; - } - } - - session_action(type); - - return 0; -} diff --git a/src/gtk-logout-helper.c b/src/gtk-logout-helper.c new file mode 100644 index 0000000..bf37ca7 --- /dev/null +++ b/src/gtk-logout-helper.c @@ -0,0 +1,216 @@ +/* +A small wrapper utility to load indicators and put them as menu items +into the gnome-panel using it's applet interface. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + Christoph Korn + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include +#include +#include +#include +#include "dialog.h" +#include "gconf-helper.h" + +static void +consolekit_fallback (LogoutDialogType action) +{ + DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); + g_return_if_fail(sbus != NULL); /* worst case */ + DBusGProxy * proxy = dbus_g_proxy_new_for_name(sbus, "org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager"); + + if (proxy == NULL) { + g_warning("Unable to get consolekit proxy"); + return; + } + + GError * error = NULL; + + switch (action) { + case LOGOUT_DIALOG_TYPE_LOG_OUT: + g_warning("Unable to fallback to ConsoleKit for logout as it's a session issue. We need some sort of session handler."); + break; + case LOGOUT_DIALOG_TYPE_SHUTDOWN: + dbus_g_proxy_call(proxy, + "Stop", + &error, + G_TYPE_INVALID); + break; + case LOGOUT_DIALOG_TYPE_RESTART: + dbus_g_proxy_call(proxy, + "Restart", + &error, + G_TYPE_INVALID); + break; + default: + g_warning("Unknown action"); + break; + } + + g_object_unref(proxy); + + if (error != NULL) { + g_error("Unable to signal ConsoleKit: %s", error->message); + g_error_free(error); + } + + return; +} + +static void +session_action (LogoutDialogType action) +{ + DBusGConnection * sbus; + DBusGProxy * sm_proxy; + GError * error = NULL; + gboolean res = FALSE; + + sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + if (sbus == NULL) { + g_warning("Unable to get DBus session bus."); + return; + } + sm_proxy = dbus_g_proxy_new_for_name_owner (sbus, + "org.gnome.SessionManager", + "/org/gnome/SessionManager", + "org.gnome.SessionManager", + &error); + if (sm_proxy == NULL) { + g_warning("Unable to get DBus proxy to SessionManager interface: %s", error->message); + g_error_free(error); + + consolekit_fallback(action); + return; + } + + g_clear_error (&error); + + if (action == LOGOUT_DIALOG_TYPE_LOG_OUT) { + res = dbus_g_proxy_call_with_timeout (sm_proxy, "Logout", INT_MAX, &error, + G_TYPE_UINT, 1, G_TYPE_INVALID, G_TYPE_INVALID); + } else if (action == LOGOUT_DIALOG_TYPE_SHUTDOWN) { + res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestShutdown", INT_MAX, &error, + G_TYPE_INVALID, G_TYPE_INVALID); + } else if (action == LOGOUT_DIALOG_TYPE_RESTART) { + res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestReboot", INT_MAX, &error, + G_TYPE_INVALID, G_TYPE_INVALID); + } else { + g_warning ("Unknown session action"); + } + + if (!res) { + if (error != NULL) { + g_warning ("SessionManager action failed: %s", error->message); + } else { + g_warning ("SessionManager action failed: unknown error"); + } + } + + g_object_unref(sm_proxy); + + if (error != NULL) { + g_error_free(error); + } + + return; +} + +static LogoutDialogType type = LOGOUT_DIALOG_TYPE_LOG_OUT; + +static gboolean +option_logout (const gchar * arg, const gchar * value, gpointer data, GError * error) +{ + type = LOGOUT_DIALOG_TYPE_LOG_OUT; + return TRUE; +} + +static gboolean +option_shutdown (const gchar * arg, const gchar * value, gpointer data, GError * error) +{ + type = LOGOUT_DIALOG_TYPE_SHUTDOWN; + return TRUE; +} + +static gboolean +option_restart (const gchar * arg, const gchar * value, gpointer data, GError * error) +{ + type = LOGOUT_DIALOG_TYPE_RESTART; + return TRUE; +} + +static GOptionEntry options[] = { + {"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_logout, "Log out of the current session", NULL}, + {"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_shutdown, "Shutdown the entire system", NULL}, + {"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restart, "Restart the system", NULL}, + + {NULL} +}; + +int +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"); + g_option_context_add_group(context, gtk_get_option_group(TRUE)); + g_option_context_set_help_enabled(context, TRUE); + + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_debug("Option parsing failed: %s", error->message); + g_error_free(error); + 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 (!supress_confirmations()) { + dialog = GTK_WIDGET(logout_dialog_new(type)); + } + + if (dialog != NULL) { + GtkResponseType response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_hide(dialog); + + if (response == GTK_RESPONSE_HELP) { + type = LOGOUT_DIALOG_TYPE_RESTART; + response = GTK_RESPONSE_OK; + } + + if (response != GTK_RESPONSE_OK) { + return 0; + } + } + + session_action(type); + + return 0; +} diff --git a/src/session-service.c b/src/session-service.c index 289bff8..af3c3e5 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -40,7 +40,7 @@ with this program. If not, see . #include "dbus-shared-names.h" #include "dbusmenu-shared.h" -#include "gtk-dialog/gconf-helper.h" +#include "gconf-helper.h" #include "users-service-dbus.h" #include "lock-helper.h" -- cgit v1.2.3