31
29
#include <libdbusmenu-glib/menuitem.h>
33
31
#include "dbus-shared-names.h"
34
#include "gconf-helper.h"
36
static GConfClient * gconf_client = NULL;
32
#include "settings-helper.h"
34
static GSettings* settings = NULL;
37
36
static guint confirmation_notify = 0;
38
37
static guint logout_notify = 0;
39
38
static guint restart_notify = 0;
40
39
static guint shutdown_notify = 0;
42
build_settings (void) {
44
settings = g_settings_new (SESSION_SCHEMA);
43
50
supress_confirmations (void) {
45
gconf_client = gconf_client_get_default ();
47
return gconf_client_get_bool (gconf_client, SUPPRESS_KEY, NULL) ;
52
return g_settings_get_boolean (settings, SUPPRESS_KEY) ;
51
56
show_logout (void) {
53
gconf_client = gconf_client_get_default ();
55
return !gconf_client_get_bool (gconf_client, LOGOUT_KEY, NULL) ;
58
return !g_settings_get_boolean (settings, LOGOUT_KEY) ;
59
62
show_restart (void) {
61
gconf_client = gconf_client_get_default ();
63
return !gconf_client_get_bool (gconf_client, RESTART_KEY, NULL) ;
64
return !g_settings_get_boolean (settings, RESTART_KEY) ;
67
68
show_shutdown (void) {
69
gconf_client = gconf_client_get_default ();
71
return !gconf_client_get_bool (gconf_client, SHUTDOWN_KEY, NULL) ;
70
return !g_settings_get_boolean (settings, SHUTDOWN_KEY) ;
74
static void update_menu_entries_callback (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data) {
73
static void update_menu_entries_callback (GSettings * settings, const gchar * key, gpointer data) {
75
74
RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = (RestartShutdownLogoutMenuItems*) data;
76
GConfValue * value = gconf_entry_get_value (entry);
77
const gchar * key = gconf_entry_get_key (entry);
79
76
if(g_strcmp0 (key, SUPPRESS_KEY) == 0) {
80
if (gconf_value_get_bool (value)) {
77
if (g_settings_get_boolean (settings, key)) {
81
78
dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out"));
82
79
dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->restart_mi, RESTART_ITEM_LABEL, _("Restart"));
83
80
dbusmenu_menuitem_property_set(restart_shutdown_logout_mi->shutdown_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Shut Down"));
93
update_logout_callback (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data) {
90
update_logout_callback (GSettings * settings, const gchar * key, gpointer data) {
94
91
DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
95
GConfValue * value = gconf_entry_get_value (entry);
96
const gchar * key = gconf_entry_get_key (entry);
98
93
if(g_strcmp0 (key, LOGOUT_KEY) == 0) {
99
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !gconf_value_get_bool(value));
94
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !g_settings_get_boolean(settings, key));
104
update_restart_callback (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data) {
99
update_restart_callback (GSettings * settings, const gchar * key, gpointer data) {
105
100
DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
106
GConfValue * value = gconf_entry_get_value (entry);
107
const gchar * key = gconf_entry_get_key (entry);
109
102
if(g_strcmp0 (key, RESTART_KEY) == 0) {
110
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !gconf_value_get_bool(value));
103
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !g_settings_get_boolean(settings, key));
115
update_shutdown_callback (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data) {
108
update_shutdown_callback (GSettings * settings, const gchar * key, gpointer data) {
116
109
DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
117
GConfValue * value = gconf_entry_get_value (entry);
118
const gchar * key = gconf_entry_get_key (entry);
120
111
if(g_strcmp0 (key, SHUTDOWN_KEY) == 0) {
121
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !gconf_value_get_bool(value));
112
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_VISIBLE, !g_settings_get_boolean(settings, key));
126
117
update_menu_entries(RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi) {
127
118
/* If we don't have a client, build one. */
129
gconf_client = gconf_client_get_default ();
132
/* If we've not gotten any notifications, then we need
133
to add the directory for notifications to come from. */
134
if (confirmation_notify == 0 || logout_notify == 0) {
135
gconf_client_add_dir (gconf_client, GLOBAL_DIR,
136
GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
139
121
if (confirmation_notify != 0) {
140
gconf_client_notify_remove (gconf_client, confirmation_notify);
122
g_signal_handler_disconnect (settings, confirmation_notify);
141
123
confirmation_notify = 0;
144
126
if (logout_notify != 0) {
145
gconf_client_notify_remove (gconf_client, logout_notify);
127
g_signal_handler_disconnect (settings, logout_notify);
146
128
logout_notify = 0;
149
131
if (restart_notify != 0) {
150
gconf_client_notify_remove (gconf_client, restart_notify);
132
g_signal_handler_disconnect (settings, restart_notify);
151
133
restart_notify = 0;
154
136
if (shutdown_notify != 0) {
155
gconf_client_notify_remove (gconf_client, shutdown_notify);
137
g_signal_handler_disconnect (settings, shutdown_notify);
156
138
shutdown_notify = 0;
159
confirmation_notify = gconf_client_notify_add (gconf_client, SUPPRESS_KEY,
160
update_menu_entries_callback, restart_shutdown_logout_mi, NULL, NULL);
161
logout_notify = gconf_client_notify_add (gconf_client, LOGOUT_KEY,
162
update_logout_callback, restart_shutdown_logout_mi->logout_mi, NULL, NULL);
163
restart_notify = gconf_client_notify_add (gconf_client, RESTART_KEY,
164
update_restart_callback, restart_shutdown_logout_mi->restart_mi, NULL, NULL);
165
shutdown_notify = gconf_client_notify_add (gconf_client, SHUTDOWN_KEY,
166
update_shutdown_callback, restart_shutdown_logout_mi->shutdown_mi, NULL, NULL);
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);