2
A small wrapper utility for connecting to GSettings.
4
Copyright 2009 Canonical Ltd.
7
Christoph Korn <c_korn@gmx.de>
9
This program is free software: you can redistribute it and/or modify it
10
under the terms of the GNU General Public License version 3, as published
11
by the Free Software Foundation.
13
This program is distributed in the hope that it will be useful, but
14
WITHOUT ANY WARRANTY; without even the implied warranties of
15
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16
PURPOSE. See the GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License along
19
with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include <glib/gi18n.h>
25
#include <dbus/dbus-glib.h>
26
#include <dbus/dbus-glib-bindings.h>
28
#include <libdbusmenu-glib/server.h>
29
#include <libdbusmenu-glib/menuitem.h>
31
#include "dbus-shared-names.h"
32
#include "settings-helper.h"
34
static GSettings* settings = NULL;
36
static guint confirmation_notify = 0;
37
static guint logout_notify = 0;
38
static guint restart_notify = 0;
39
static guint shutdown_notify = 0;
42
build_settings (void) {
44
settings = g_settings_new (SESSION_SCHEMA);
50
supress_confirmations (void) {
52
return g_settings_get_boolean (settings, SUPPRESS_KEY) ;
58
return !g_settings_get_boolean (settings, LOGOUT_KEY) ;
64
return !g_settings_get_boolean (settings, RESTART_KEY) ;
68
show_shutdown (void) {
70
return !g_settings_get_boolean (settings, SHUTDOWN_KEY) ;
73
static void update_menu_entries_callback (GSettings * settings, const gchar * key, gpointer data) {
74
RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = (RestartShutdownLogoutMenuItems*) data;
76
if(g_strcmp0 (key, SUPPRESS_KEY) == 0) {
77
if (g_settings_get_boolean (settings, key)) {
78
dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out"));
79
dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->restart_mi, RESTART_ITEM_LABEL, _("Restart"));
80
dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shut Down"));
82
dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out…"));
83
dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->restart_mi, RESTART_ITEM_LABEL, _("Restart…"));
84
dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shut Down…"));
90
update_logout_callback (GSettings * settings, const gchar * key, gpointer data) {
91
DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
93
if(g_strcmp0 (key, LOGOUT_KEY) == 0) {
94
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !g_settings_get_boolean(settings, key));
99
update_restart_callback (GSettings * settings, const gchar * key, gpointer data) {
100
DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
102
if(g_strcmp0 (key, RESTART_KEY) == 0) {
103
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !g_settings_get_boolean(settings, key));
108
update_shutdown_callback (GSettings * settings, const gchar * key, gpointer data) {
109
DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
111
if(g_strcmp0 (key, SHUTDOWN_KEY) == 0) {
112
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !g_settings_get_boolean(settings, key));
117
update_menu_entries(RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi) {
118
/* If we don't have a client, build one. */
121
if (confirmation_notify != 0) {
122
g_signal_handler_disconnect (settings, confirmation_notify);
123
confirmation_notify = 0;
126
if (logout_notify != 0) {
127
g_signal_handler_disconnect (settings, logout_notify);
131
if (restart_notify != 0) {
132
g_signal_handler_disconnect (settings, restart_notify);
136
if (shutdown_notify != 0) {
137
g_signal_handler_disconnect (settings, shutdown_notify);
141
confirmation_notify = g_signal_connect (settings, "changed::" SUPPRESS_KEY,
142
G_CALLBACK(update_menu_entries_callback), restart_shutdown_logout_mi);
143
logout_notify = g_signal_connect (settings, "changed::" LOGOUT_KEY,
144
G_CALLBACK(update_logout_callback), restart_shutdown_logout_mi->logout_mi);
145
restart_notify = g_signal_connect (settings, "changed::" RESTART_KEY,
146
G_CALLBACK(update_restart_callback), restart_shutdown_logout_mi->restart_mi);
147
shutdown_notify = g_signal_connect (settings, "changed::" SHUTDOWN_KEY,
148
G_CALLBACK(update_shutdown_callback), restart_shutdown_logout_mi->shutdown_mi);