~ubuntu-branches/ubuntu/oneiric/indicator-session/oneiric-proposed

« back to all changes in this revision

Viewing changes to src/settings-helper.c

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2011-08-25 08:58:56 UTC
  • mfrom: (1.1.34 upstream)
  • Revision ID: james.westby@ubuntu.com-20110825085856-qtuta6vqal1iw7mt
Tags: 0.3.3-0ubuntu1
* New upstream release.
  - User menu should still show even if there is only 1 user (LP: #831758)
  - Bluetooth item in menu not needed (LP: #825111)
  - Newly created users are not added to the menu until next 
    login (LP: #552048)
  - Users list in shutdown menu is not updated on user 
    deletion (LP: #557608)
  - should use gsettings rather than gconf (LP: #656323)
* debian/control
  - Bump dbusmenu build dep to >= 0.4.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
A small wrapper utility for connecting to GSettings.
 
3
 
 
4
Copyright 2009 Canonical Ltd.
 
5
 
 
6
Authors:
 
7
    Christoph Korn <c_korn@gmx.de>
 
8
 
 
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.
 
12
 
 
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.
 
17
 
 
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/>.
 
20
*/
 
21
 
 
22
#include <gio/gio.h>
 
23
#include <glib/gi18n.h>
 
24
 
 
25
#include <dbus/dbus-glib.h>
 
26
#include <dbus/dbus-glib-bindings.h>
 
27
 
 
28
#include <libdbusmenu-glib/server.h>
 
29
#include <libdbusmenu-glib/menuitem.h>
 
30
 
 
31
#include "dbus-shared-names.h"
 
32
#include "settings-helper.h"
 
33
 
 
34
static GSettings* settings = NULL;
 
35
 
 
36
static guint confirmation_notify = 0;
 
37
static guint logout_notify = 0;
 
38
static guint restart_notify = 0;
 
39
static guint shutdown_notify = 0;
 
40
 
 
41
static void
 
42
build_settings (void) {
 
43
        if(!settings) {
 
44
                settings = g_settings_new (SESSION_SCHEMA);
 
45
        }
 
46
        return;
 
47
}
 
48
 
 
49
gboolean
 
50
supress_confirmations (void) {
 
51
        build_settings();
 
52
        return g_settings_get_boolean (settings, SUPPRESS_KEY) ;
 
53
}
 
54
 
 
55
gboolean
 
56
show_logout (void) {
 
57
        build_settings();
 
58
        return !g_settings_get_boolean (settings, LOGOUT_KEY) ;
 
59
}
 
60
 
 
61
gboolean
 
62
show_restart (void) {
 
63
        build_settings();
 
64
        return !g_settings_get_boolean (settings, RESTART_KEY) ;
 
65
}
 
66
 
 
67
gboolean
 
68
show_shutdown (void) {
 
69
        build_settings();
 
70
        return !g_settings_get_boolean (settings, SHUTDOWN_KEY) ;
 
71
}
 
72
 
 
73
static void update_menu_entries_callback (GSettings * settings, const gchar * key, gpointer data) {
 
74
        RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = (RestartShutdownLogoutMenuItems*) data;
 
75
 
 
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"));
 
81
                } else {
 
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…"));
 
85
                }
 
86
        }
 
87
}
 
88
 
 
89
static void
 
90
update_logout_callback (GSettings * settings, const gchar * key, gpointer data) {
 
91
        DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
 
92
 
 
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));
 
95
        }
 
96
}
 
97
 
 
98
static void
 
99
update_restart_callback (GSettings * settings, const gchar * key, gpointer data) {
 
100
        DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
 
101
 
 
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));
 
104
        }
 
105
}
 
106
 
 
107
static void
 
108
update_shutdown_callback (GSettings * settings, const gchar * key, gpointer data) {
 
109
        DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data;
 
110
 
 
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));
 
113
        }
 
114
}
 
115
 
 
116
void
 
117
update_menu_entries(RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi) {
 
118
        /* If we don't have a client, build one. */
 
119
        build_settings();
 
120
 
 
121
        if (confirmation_notify != 0) {
 
122
                g_signal_handler_disconnect (settings, confirmation_notify);
 
123
                confirmation_notify = 0;
 
124
        }
 
125
 
 
126
        if (logout_notify != 0) {
 
127
                g_signal_handler_disconnect (settings, logout_notify);
 
128
                logout_notify = 0;
 
129
        }
 
130
 
 
131
        if (restart_notify != 0) {
 
132
                g_signal_handler_disconnect (settings, restart_notify);
 
133
                restart_notify = 0;
 
134
        }
 
135
 
 
136
        if (shutdown_notify != 0) {
 
137
                g_signal_handler_disconnect (settings, shutdown_notify);
 
138
                shutdown_notify = 0;
 
139
        }
 
140
 
 
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);
 
149
 
 
150
        return;
 
151
}
 
152