~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to capplets/accessibility/at-properties/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <config.h>
2
 
#include <gtk/gtk.h>
3
 
#include <gconf/gconf-client.h>
4
 
 
5
 
#include <dbus/dbus-glib.h>
6
 
#include <dbus/dbus-glib-lowlevel.h>
7
 
 
8
 
#define GSM_SERVICE_DBUS   "org.gnome.SessionManager"
9
 
#define GSM_PATH_DBUS      "/org/gnome/SessionManager"
10
 
#define GSM_INTERFACE_DBUS "org.gnome.SessionManager"
11
 
 
12
 
enum {
13
 
        GSM_LOGOUT_MODE_NORMAL = 0,
14
 
        GSM_LOGOUT_MODE_NO_CONFIRMATION,
15
 
        GSM_LOGOUT_MODE_FORCE
16
 
};
17
 
 
18
 
#include "capplet-util.h"
19
 
#include "gconf-property-editor.h"
20
 
#include "activate-settings-daemon.h"
21
 
 
22
 
#define ACCESSIBILITY_KEY       "/desktop/gnome/interface/accessibility"
23
 
#define ACCESSIBILITY_KEY_DIR   "/desktop/gnome/interface"
24
 
 
25
 
static gboolean initial_state;
26
 
 
27
 
static GtkBuilder *
28
 
create_builder (void)
29
 
{
30
 
        GtkBuilder *builder;
31
 
        GError *error = NULL;
32
 
        static const gchar *uifile = UIDIR "/at-enable-dialog.ui";
33
 
 
34
 
        builder = gtk_builder_new ();
35
 
 
36
 
        if (gtk_builder_add_from_file (builder, uifile, &error)) {
37
 
                GObject *object;
38
 
                gchar *prog;
39
 
 
40
 
                object = gtk_builder_get_object (builder, "at_enable_image");
41
 
                gtk_image_set_from_file (GTK_IMAGE (object),
42
 
                                         PIXMAPDIR "/at-startup.png");
43
 
 
44
 
                object = gtk_builder_get_object (builder,
45
 
                                                 "at_applications_image");
46
 
                gtk_image_set_from_file (GTK_IMAGE (object),
47
 
                                         PIXMAPDIR "/at-support.png");
48
 
 
49
 
                prog = g_find_program_in_path ("gdmsetup");
50
 
                if (prog == NULL) {
51
 
                        object = gtk_builder_get_object (builder,
52
 
                                                         "login_button");
53
 
                        gtk_widget_hide (GTK_WIDGET (object));
54
 
                }
55
 
 
56
 
                g_free (prog);
57
 
        } else {
58
 
                g_warning ("Could not load UI: %s", error->message);
59
 
                g_error_free (error);
60
 
                g_object_unref (builder);
61
 
                builder = NULL;
62
 
        }
63
 
 
64
 
        return builder;
65
 
}
66
 
 
67
 
static void
68
 
cb_at_preferences (GtkDialog *dialog, gint response_id)
69
 
{
70
 
        g_spawn_command_line_async ("gnome-default-applications-properties --show-page=a11y", NULL);
71
 
}
72
 
 
73
 
static void
74
 
cb_keyboard_preferences (GtkDialog *dialog, gint response_id)
75
 
{
76
 
        g_spawn_command_line_async ("gnome-keyboard-properties --a11y", NULL);
77
 
}
78
 
 
79
 
static void
80
 
cb_mouse_preferences (GtkDialog *dialog, gint response_id)
81
 
{
82
 
        g_spawn_command_line_async ("gnome-mouse-properties --show-page=accessibility", NULL);
83
 
}
84
 
 
85
 
static void
86
 
cb_login_preferences (GtkDialog *dialog, gint response_id)
87
 
{
88
 
        g_spawn_command_line_async ("gdmsetup", NULL);
89
 
}
90
 
 
91
 
/* get_session_bus(), get_sm_proxy(), and do_logout() are all
92
 
 * based on code from gnome-session-save.c from gnome-session.
93
 
 */
94
 
static DBusGConnection *
95
 
get_session_bus (void)
96
 
{
97
 
        DBusGConnection *bus;
98
 
        GError *error = NULL;
99
 
 
100
 
        bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
101
 
 
102
 
        if (bus == NULL) {
103
 
                g_warning ("Couldn't connect to session bus: %s", error->message);
104
 
                g_error_free (error);
105
 
        }
106
 
 
107
 
        return bus;
108
 
}
109
 
 
110
 
static DBusGProxy *
111
 
get_sm_proxy (void)
112
 
{
113
 
        DBusGConnection *connection;
114
 
        DBusGProxy      *sm_proxy;
115
 
 
116
 
        if (!(connection = get_session_bus ()))
117
 
                return NULL;
118
 
 
119
 
        sm_proxy = dbus_g_proxy_new_for_name (connection,
120
 
                                              GSM_SERVICE_DBUS,
121
 
                                              GSM_PATH_DBUS,
122
 
                                              GSM_INTERFACE_DBUS);
123
 
 
124
 
        return sm_proxy;
125
 
}
126
 
 
127
 
static gboolean
128
 
do_logout (GError **err)
129
 
{
130
 
        DBusGProxy *sm_proxy;
131
 
        GError     *error;
132
 
        gboolean    res;
133
 
 
134
 
        sm_proxy = get_sm_proxy ();
135
 
        if (sm_proxy == NULL)
136
 
                return FALSE;
137
 
 
138
 
        res = dbus_g_proxy_call (sm_proxy,
139
 
                                 "Logout",
140
 
                                 &error,
141
 
                                 G_TYPE_UINT, 0,   /* '0' means 'log out normally' */
142
 
                                 G_TYPE_INVALID,
143
 
                                 G_TYPE_INVALID);
144
 
 
145
 
        if (sm_proxy)
146
 
                g_object_unref (sm_proxy);
147
 
 
148
 
        return res;
149
 
}
150
 
 
151
 
static void
152
 
cb_dialog_response (GtkDialog *dialog, gint response_id)
153
 
{
154
 
        if (response_id == GTK_RESPONSE_HELP)
155
 
                capplet_help (GTK_WINDOW (dialog),
156
 
                              "goscustaccess-11");
157
 
        else if (response_id == GTK_RESPONSE_CLOSE || response_id == GTK_RESPONSE_DELETE_EVENT)
158
 
                gtk_main_quit ();
159
 
        else {
160
 
                g_message ("CLOSE AND LOGOUT!");
161
 
 
162
 
                if (!do_logout (NULL))
163
 
                        gtk_main_quit ();
164
 
        }
165
 
}
166
 
 
167
 
static void
168
 
close_logout_update (GtkBuilder *builder)
169
 
{
170
 
        GConfClient *client = gconf_client_get_default ();
171
 
        gboolean curr_state = gconf_client_get_bool (client, ACCESSIBILITY_KEY, NULL);
172
 
        GObject *btn = gtk_builder_get_object (builder,
173
 
                                               "at_close_logout_button");
174
 
 
175
 
        gtk_widget_set_sensitive (GTK_WIDGET (btn), initial_state != curr_state);
176
 
        g_object_unref (client);
177
 
}
178
 
 
179
 
static void
180
 
at_enable_toggled (GtkToggleButton *toggle_button,
181
 
                   GtkBuilder      *builder)
182
 
{
183
 
        GConfClient *client = gconf_client_get_default ();
184
 
        gboolean is_enabled = gtk_toggle_button_get_active (toggle_button);
185
 
 
186
 
        gconf_client_set_bool (client, ACCESSIBILITY_KEY,
187
 
                               is_enabled,
188
 
                               NULL);
189
 
        g_object_unref (client);
190
 
}
191
 
 
192
 
static void
193
 
at_enable_update (GConfClient *client,
194
 
                  GtkBuilder  *builder)
195
 
{
196
 
        gboolean is_enabled = gconf_client_get_bool (client, ACCESSIBILITY_KEY, NULL);
197
 
        GObject *btn = gtk_builder_get_object (builder, "at_enable_toggle");
198
 
 
199
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (btn),
200
 
                                      is_enabled);
201
 
}
202
 
 
203
 
static void
204
 
at_enable_changed (GConfClient *client,
205
 
                   guint        cnxn_id,
206
 
                   GConfEntry  *entry,
207
 
                   gpointer     user_data)
208
 
{
209
 
        at_enable_update (client, user_data);
210
 
        close_logout_update (user_data);
211
 
}
212
 
 
213
 
static void
214
 
setup_dialog (GtkBuilder *builder)
215
 
{
216
 
        GConfClient *client;
217
 
        GtkWidget *widget;
218
 
        GObject *object;
219
 
        GObject *peditor;
220
 
 
221
 
        client = gconf_client_get_default ();
222
 
 
223
 
        gconf_client_add_dir (client, ACCESSIBILITY_KEY_DIR,
224
 
                              GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
225
 
 
226
 
        object = gtk_builder_get_object (builder, "at_enable_toggle");
227
 
        g_signal_connect (object, "toggled",
228
 
                          G_CALLBACK (at_enable_toggled),
229
 
                          builder);
230
 
 
231
 
        peditor = gconf_peditor_new_boolean (NULL, ACCESSIBILITY_KEY,
232
 
                                             GTK_WIDGET (object),
233
 
                                             NULL);
234
 
 
235
 
        initial_state = gconf_client_get_bool (client, ACCESSIBILITY_KEY, NULL);
236
 
 
237
 
        at_enable_update (client, builder);
238
 
 
239
 
        gconf_client_notify_add (client, ACCESSIBILITY_KEY_DIR,
240
 
                                 at_enable_changed,
241
 
                                 builder, NULL, NULL);
242
 
 
243
 
        object = gtk_builder_get_object (builder, "at_pref_button");
244
 
        g_signal_connect (object, "clicked",
245
 
                          G_CALLBACK (cb_at_preferences), NULL);
246
 
 
247
 
        object = gtk_builder_get_object (builder, "keyboard_button");
248
 
        g_signal_connect (object, "clicked",
249
 
                          G_CALLBACK (cb_keyboard_preferences), NULL);
250
 
 
251
 
        object = gtk_builder_get_object (builder, "mouse_button");
252
 
        g_signal_connect (object, "clicked",
253
 
                          G_CALLBACK (cb_mouse_preferences), NULL);
254
 
 
255
 
        object = gtk_builder_get_object (builder, "login_button");
256
 
        g_signal_connect (object, "clicked",
257
 
                          G_CALLBACK (cb_login_preferences), NULL);
258
 
 
259
 
        widget = GTK_WIDGET (gtk_builder_get_object (builder,
260
 
                                                     "at_properties_dialog"));
261
 
        capplet_set_icon (widget, "preferences-desktop-accessibility");
262
 
 
263
 
        g_signal_connect (G_OBJECT (widget),
264
 
                          "response",
265
 
                          G_CALLBACK (cb_dialog_response), NULL);
266
 
 
267
 
        gtk_widget_show (widget);
268
 
 
269
 
        g_object_unref (client);
270
 
}
271
 
 
272
 
int
273
 
main (int argc, char *argv[])
274
 
{
275
 
        GtkBuilder *builder;
276
 
 
277
 
        capplet_init (NULL, &argc, &argv);
278
 
 
279
 
        activate_settings_daemon ();
280
 
 
281
 
        builder = create_builder ();
282
 
 
283
 
        if (builder) {
284
 
 
285
 
                setup_dialog (builder);
286
 
 
287
 
                gtk_main ();
288
 
 
289
 
                g_object_unref (builder);
290
 
        }
291
 
 
292
 
        return 0;
293
 
}