~charlesk/gnome-control-center/make-new-panel

« back to all changes in this revision

Viewing changes to capplets/keyboard/gnome-keyboard-properties.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
 
/* -*- mode: c; style: linux -*- */
2
 
 
3
 
/* keyboard-properties.c
4
 
 * Copyright (C) 2000-2001 Ximian, Inc.
5
 
 * Copyright (C) 2001 Jonathan Blandford
6
 
 *
7
 
 * Written by: Bradford Hovinen <hovinen@ximian.com>
8
 
 *             Rachel Hestilow <hestilow@ximian.com>
9
 
 *             Jonathan Blandford <jrb@redhat.com>
10
 
 *
11
 
 * This program is free software; you can redistribute it and/or modify
12
 
 * it under the terms of the GNU General Public License as published by
13
 
 * the Free Software Foundation; either version 2, or (at your option)
14
 
 * any later version.
15
 
 *
16
 
 * This program is distributed in the hope that it will be useful,
17
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
 * GNU General Public License for more details.
20
 
 *
21
 
 * You should have received a copy of the GNU General Public License
22
 
 * along with this program; if not, write to the Free Software
23
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24
 
 * 02111-1307, USA.
25
 
 */
26
 
 
27
 
#ifdef HAVE_CONFIG_H
28
 
#  include <config.h>
29
 
#endif
30
 
 
31
 
#include <gconf/gconf-client.h>
32
 
 
33
 
#include "capplet-util.h"
34
 
#include "gconf-property-editor.h"
35
 
#include "activate-settings-daemon.h"
36
 
#include "capplet-stock-icons.h"
37
 
 
38
 
#include "gnome-keyboard-properties-a11y.h"
39
 
#include "gnome-keyboard-properties-xkb.h"
40
 
 
41
 
enum {
42
 
        RESPONSE_APPLY = 1,
43
 
        RESPONSE_CLOSE
44
 
};
45
 
 
46
 
static GtkBuilder *
47
 
create_dialog (void)
48
 
{
49
 
        GtkBuilder *dialog;
50
 
        GtkSizeGroup *size_group;
51
 
        GtkWidget *image;
52
 
 
53
 
        dialog = gtk_builder_new ();
54
 
    gtk_builder_add_from_file (dialog, GNOMECC_UI_DIR
55
 
                               "/gnome-keyboard-properties-dialog.ui",
56
 
                               NULL);
57
 
 
58
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
59
 
        gtk_size_group_add_widget (size_group, WID ("repeat_slow_label"));
60
 
        gtk_size_group_add_widget (size_group, WID ("delay_short_label"));
61
 
        gtk_size_group_add_widget (size_group, WID ("blink_slow_label"));
62
 
        g_object_unref (G_OBJECT (size_group));
63
 
 
64
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
65
 
        gtk_size_group_add_widget (size_group, WID ("repeat_fast_label"));
66
 
        gtk_size_group_add_widget (size_group, WID ("delay_long_label"));
67
 
        gtk_size_group_add_widget (size_group, WID ("blink_fast_label"));
68
 
        g_object_unref (G_OBJECT (size_group));
69
 
 
70
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
71
 
        gtk_size_group_add_widget (size_group, WID ("repeat_delay_scale"));
72
 
        gtk_size_group_add_widget (size_group, WID ("repeat_speed_scale"));
73
 
        gtk_size_group_add_widget (size_group, WID ("cursor_blink_time_scale"));
74
 
        g_object_unref (G_OBJECT (size_group));
75
 
 
76
 
        image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
77
 
        gtk_button_set_image (GTK_BUTTON (WID ("xkb_layouts_add")), image);
78
 
 
79
 
        image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
80
 
        gtk_button_set_image (GTK_BUTTON (WID ("xkb_reset_to_defaults")), image);
81
 
 
82
 
        return dialog;
83
 
}
84
 
 
85
 
static GConfValue *
86
 
blink_from_widget (GConfPropertyEditor * peditor, const GConfValue * value)
87
 
{
88
 
        GConfValue *new_value;
89
 
 
90
 
        new_value = gconf_value_new (GCONF_VALUE_INT);
91
 
        gconf_value_set_int (new_value,
92
 
                             2600 - gconf_value_get_int (value));
93
 
 
94
 
        return new_value;
95
 
}
96
 
 
97
 
static GConfValue *
98
 
blink_to_widget (GConfPropertyEditor * peditor, const GConfValue * value)
99
 
{
100
 
        GConfValue *new_value;
101
 
        gint current_rate;
102
 
 
103
 
        current_rate = gconf_value_get_int (value);
104
 
        new_value = gconf_value_new (GCONF_VALUE_INT);
105
 
        gconf_value_set_int (new_value,
106
 
                             CLAMP (2600 - current_rate, 100, 2500));
107
 
 
108
 
        return new_value;
109
 
}
110
 
 
111
 
static void
112
 
dialog_response (GtkWidget * widget,
113
 
                 gint response_id, GConfChangeSet * changeset)
114
 
{
115
 
        if (response_id == GTK_RESPONSE_HELP)
116
 
                capplet_help (GTK_WINDOW (widget), "goscustperiph-2");
117
 
        else
118
 
                gtk_main_quit ();
119
 
}
120
 
 
121
 
static void
122
 
setup_dialog (GtkBuilder * dialog, GConfChangeSet * changeset)
123
 
{
124
 
        GObject *peditor;
125
 
        gchar *monitor;
126
 
 
127
 
        peditor = gconf_peditor_new_boolean
128
 
            (changeset, "/desktop/gnome/peripherals/keyboard/repeat",
129
 
             WID ("repeat_toggle"), NULL);
130
 
        gconf_peditor_widget_set_guard (GCONF_PROPERTY_EDITOR (peditor),
131
 
                                        WID ("repeat_table"));
132
 
 
133
 
        gconf_peditor_new_numeric_range
134
 
            (changeset, "/desktop/gnome/peripherals/keyboard/delay",
135
 
             WID ("repeat_delay_scale"), NULL);
136
 
 
137
 
        gconf_peditor_new_numeric_range
138
 
            (changeset, "/desktop/gnome/peripherals/keyboard/rate",
139
 
             WID ("repeat_speed_scale"), NULL);
140
 
 
141
 
        peditor = gconf_peditor_new_boolean
142
 
            (changeset, "/desktop/gnome/interface/cursor_blink",
143
 
             WID ("cursor_toggle"), NULL);
144
 
        gconf_peditor_widget_set_guard (GCONF_PROPERTY_EDITOR (peditor),
145
 
                                        WID ("cursor_hbox"));
146
 
        gconf_peditor_new_numeric_range (changeset,
147
 
                                         "/desktop/gnome/interface/cursor_blink_time",
148
 
                                         WID ("cursor_blink_time_scale"),
149
 
                                         "conv-to-widget-cb",
150
 
                                         blink_to_widget,
151
 
                                         "conv-from-widget-cb",
152
 
                                         blink_from_widget, NULL);
153
 
 
154
 
        /* Ergonomics */
155
 
        monitor = g_find_program_in_path ("gnome-typing-monitor");
156
 
        if (monitor != NULL) {
157
 
                g_free (monitor);
158
 
 
159
 
                peditor = gconf_peditor_new_boolean
160
 
                        (changeset, "/desktop/gnome/typing_break/enabled",
161
 
                        WID ("break_enabled_toggle"), NULL);
162
 
                gconf_peditor_widget_set_guard (GCONF_PROPERTY_EDITOR (peditor),
163
 
                                                WID ("break_details_table"));
164
 
                gconf_peditor_new_numeric_range (changeset,
165
 
                                                 "/desktop/gnome/typing_break/type_time",
166
 
                                                 WID ("break_enabled_spin"), NULL);
167
 
                gconf_peditor_new_numeric_range (changeset,
168
 
                                                 "/desktop/gnome/typing_break/break_time",
169
 
                                                 WID ("break_interval_spin"),
170
 
                                                 NULL);
171
 
                gconf_peditor_new_boolean (changeset,
172
 
                                           "/desktop/gnome/typing_break/allow_postpone",
173
 
                                           WID ("break_postponement_toggle"),
174
 
                                           NULL);
175
 
 
176
 
        } else {
177
 
                /* don't show the typing break tab if the daemon is not available */
178
 
                GtkNotebook *nb = GTK_NOTEBOOK (WID ("keyboard_notebook"));
179
 
                gint tb_page = gtk_notebook_page_num (nb, WID ("break_enabled_toggle"));
180
 
                gtk_notebook_remove_page (nb, tb_page);
181
 
        }
182
 
 
183
 
        g_signal_connect (WID ("keyboard_dialog"), "response",
184
 
                          (GCallback) dialog_response, changeset);
185
 
 
186
 
        setup_xkb_tabs (dialog, changeset);
187
 
        setup_a11y_tabs (dialog, changeset);
188
 
}
189
 
 
190
 
int
191
 
main (int argc, char **argv)
192
 
{
193
 
        GConfClient *client;
194
 
        GConfChangeSet *changeset;
195
 
        GtkBuilder *dialog;
196
 
        GOptionContext *context;
197
 
 
198
 
        static gboolean apply_only = FALSE;
199
 
        static gboolean switch_to_typing_break_page = FALSE;
200
 
        static gboolean switch_to_a11y_page = FALSE;
201
 
 
202
 
        static GOptionEntry cap_options[] = {
203
 
                {"apply", 0, 0, G_OPTION_ARG_NONE, &apply_only,
204
 
                 N_
205
 
                 ("Just apply settings and quit (compatibility only; now handled by daemon)"),
206
 
                 NULL},
207
 
                {"init-session-settings", 0, 0, G_OPTION_ARG_NONE,
208
 
                 &apply_only,
209
 
                 N_
210
 
                 ("Just apply settings and quit (compatibility only; now handled by daemon)"),
211
 
                 NULL},
212
 
                {"typing-break", 0, 0, G_OPTION_ARG_NONE,
213
 
                 &switch_to_typing_break_page,
214
 
                 N_
215
 
                 ("Start the page with the typing break settings showing"),
216
 
                 NULL},
217
 
                {"a11y", 0, 0, G_OPTION_ARG_NONE,
218
 
                 &switch_to_a11y_page,
219
 
                 N_
220
 
                 ("Start the page with the accessibility settings showing"),
221
 
                 NULL},
222
 
                {NULL}
223
 
        };
224
 
 
225
 
 
226
 
        context = g_option_context_new (_("- GNOME Keyboard Preferences"));
227
 
        g_option_context_add_main_entries (context, cap_options,
228
 
                                           GETTEXT_PACKAGE);
229
 
 
230
 
        capplet_init (context, &argc, &argv);
231
 
 
232
 
        activate_settings_daemon ();
233
 
 
234
 
        client = gconf_client_get_default ();
235
 
        gconf_client_add_dir (client,
236
 
                              "/desktop/gnome/peripherals/keyboard",
237
 
                              GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
238
 
        gconf_client_add_dir (client, "/desktop/gnome/interface",
239
 
                              GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
240
 
        g_object_unref (client);
241
 
 
242
 
        changeset = NULL;
243
 
        dialog = create_dialog ();
244
 
        setup_dialog (dialog, changeset);
245
 
        if (switch_to_typing_break_page) {
246
 
                gtk_notebook_set_current_page (GTK_NOTEBOOK
247
 
                                               (WID
248
 
                                                ("keyboard_notebook")),
249
 
                                               4);
250
 
        }
251
 
        else if (switch_to_a11y_page) {
252
 
                gtk_notebook_set_current_page (GTK_NOTEBOOK
253
 
                                               (WID
254
 
                                                ("keyboard_notebook")),
255
 
                                               2);
256
 
 
257
 
        }
258
 
 
259
 
        capplet_set_icon (WID ("keyboard_dialog"),
260
 
                          "preferences-desktop-keyboard");
261
 
        gtk_widget_show (WID ("keyboard_dialog"));
262
 
        gtk_main ();
263
 
 
264
 
        return 0;
265
 
}