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

« back to all changes in this revision

Viewing changes to panels/region/gnome-region-panel-xkb.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
/* gnome-region-panel-xkb.c
 
2
 * Copyright (C) 2003-2007 Sergey V. Udaltsov
 
3
 *
 
4
 * Written by: Sergey V. Udaltsov <svu@gnome.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2, or (at your option)
 
9
 * any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
 * 02111-1307, USA.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#  include <config.h>
 
24
#endif
 
25
 
 
26
#include <string.h>
 
27
#include <gdk/gdkx.h>
 
28
#include <glib/gi18n.h>
 
29
 
 
30
#include "gnome-region-panel-xkb.h"
 
31
 
 
32
#include <libgnomekbd/gkbd-desktop-config.h>
 
33
 
 
34
XklEngine *engine;
 
35
XklConfigRegistry *config_registry;
 
36
 
 
37
GkbdKeyboardConfig initial_config;
 
38
GkbdDesktopConfig desktop_config;
 
39
 
 
40
GSettings *xkb_keyboard_settings;
 
41
GSettings *xkb_desktop_settings;
 
42
 
 
43
char *
 
44
xci_desc_to_utf8 (const XklConfigItem * ci)
 
45
{
 
46
        gchar *dd = g_strdup (ci->description);
 
47
        gchar *sd = g_strstrip (dd);
 
48
        gchar *rv = g_strdup (sd[0] == 0 ? ci->name : sd);
 
49
        g_free (dd);
 
50
        return rv;
 
51
}
 
52
 
 
53
static void
 
54
cleanup_xkb_tabs (GtkBuilder * dialog,
 
55
                  GObject *where_the_object_wa)
 
56
{
 
57
        gkbd_desktop_config_term (&desktop_config);
 
58
        gkbd_keyboard_config_term (&initial_config);
 
59
        g_object_unref (G_OBJECT (config_registry));
 
60
        config_registry = NULL;
 
61
        /* Don't unref it here, or we'll crash if open the panel again */
 
62
        engine = NULL;
 
63
        g_object_unref (G_OBJECT (xkb_keyboard_settings));
 
64
        g_object_unref (G_OBJECT (xkb_desktop_settings));
 
65
        xkb_keyboard_settings = NULL;
 
66
        xkb_desktop_settings = NULL;
 
67
}
 
68
 
 
69
static void
 
70
reset_to_defaults (GtkWidget * button, GtkBuilder * dialog)
 
71
{
 
72
        GkbdKeyboardConfig empty_kbd_config;
 
73
 
 
74
        gkbd_keyboard_config_init (&empty_kbd_config, engine);
 
75
        gkbd_keyboard_config_save (&empty_kbd_config);
 
76
        gkbd_keyboard_config_term (&empty_kbd_config);
 
77
 
 
78
        g_settings_reset (xkb_desktop_settings,
 
79
                          GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP);
 
80
 
 
81
        /* all the rest is g-s-d's business */
 
82
}
 
83
 
 
84
static void
 
85
chk_new_windows_inherit_layout_toggled (GtkWidget *
 
86
                                        chk_new_windows_inherit_layout,
 
87
                                        GtkBuilder * dialog)
 
88
{
 
89
        xkb_save_default_group (gtk_toggle_button_get_active
 
90
                                (GTK_TOGGLE_BUTTON
 
91
                                 (chk_new_windows_inherit_layout)) ? -1 :
 
92
                                0);
 
93
}
 
94
 
 
95
void
 
96
setup_xkb_tabs (GtkBuilder * dialog)
 
97
{
 
98
        GtkWidget *widget;
 
99
        GtkStyleContext *context;
 
100
        GtkWidget *chk_new_windows_inherit_layout;
 
101
 
 
102
        chk_new_windows_inherit_layout = WID ("chk_new_windows_inherit_layout");
 
103
 
 
104
        xkb_desktop_settings = g_settings_new (GKBD_DESKTOP_SCHEMA);
 
105
        xkb_keyboard_settings = g_settings_new (GKBD_KEYBOARD_SCHEMA);
 
106
 
 
107
        engine =
 
108
            xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY
 
109
                                     (gdk_display_get_default ()));
 
110
        config_registry = xkl_config_registry_get_instance (engine);
 
111
 
 
112
        gkbd_desktop_config_init (&desktop_config, engine);
 
113
        gkbd_desktop_config_load (&desktop_config);
 
114
 
 
115
        xkl_config_registry_load (config_registry,
 
116
                                  desktop_config.load_extra_items);
 
117
 
 
118
        gkbd_keyboard_config_init (&initial_config, engine);
 
119
        gkbd_keyboard_config_load_from_x_initial (&initial_config, NULL);
 
120
 
 
121
        /* Set initial state */
 
122
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("chk_separate_group_per_window")),
 
123
                                      g_settings_get_boolean (xkb_desktop_settings,
 
124
                                                              GKBD_DESKTOP_CONFIG_KEY_GROUP_PER_WINDOW));
 
125
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chk_new_windows_inherit_layout),
 
126
                                      xkb_get_default_group () < 0);
 
127
 
 
128
        g_settings_bind (xkb_desktop_settings,
 
129
                         GKBD_DESKTOP_CONFIG_KEY_GROUP_PER_WINDOW,
 
130
                         WID ("chk_separate_group_per_window"), "active",
 
131
                         G_SETTINGS_BIND_DEFAULT);
 
132
        g_settings_bind (xkb_desktop_settings,
 
133
                         GKBD_DESKTOP_CONFIG_KEY_GROUP_PER_WINDOW,
 
134
                         WID ("chk_new_windows_inherit_layout"), "sensitive",
 
135
                         G_SETTINGS_BIND_DEFAULT);
 
136
        g_settings_bind (xkb_desktop_settings,
 
137
                         GKBD_DESKTOP_CONFIG_KEY_GROUP_PER_WINDOW,
 
138
                         WID ("chk_new_windows_default_layout"), "sensitive",
 
139
                         G_SETTINGS_BIND_DEFAULT);
 
140
 
 
141
        xkb_layouts_prepare_selected_tree (dialog);
 
142
        xkb_layouts_fill_selected_tree (dialog);
 
143
 
 
144
        xkb_layouts_register_buttons_handlers (dialog);
 
145
        g_signal_connect (G_OBJECT (WID ("xkb_reset_to_defaults")),
 
146
                          "clicked", G_CALLBACK (reset_to_defaults),
 
147
                          dialog);
 
148
 
 
149
        g_signal_connect (G_OBJECT (chk_new_windows_inherit_layout),
 
150
                          "toggled",
 
151
                          G_CALLBACK
 
152
                          (chk_new_windows_inherit_layout_toggled),
 
153
                          dialog);
 
154
 
 
155
        g_signal_connect_swapped (G_OBJECT (WID ("xkb_layout_options")),
 
156
                                  "clicked",
 
157
                                  G_CALLBACK (xkb_options_popup_dialog),
 
158
                                  dialog);
 
159
 
 
160
        xkb_layouts_register_conf_listener (dialog);
 
161
        xkb_options_register_conf_listener (dialog);
 
162
 
 
163
        g_object_weak_ref (G_OBJECT (WID ("region_notebook")),
 
164
                           (GWeakNotify) cleanup_xkb_tabs, dialog);
 
165
 
 
166
        enable_disable_restoring (dialog);
 
167
 
 
168
        /* Setup junction between toolbar and treeview */
 
169
        widget = WID ("xkb_layouts_swindow");
 
170
        context = gtk_widget_get_style_context (widget);
 
171
        gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
 
172
        widget = WID("layouts-toolbar");
 
173
        context = gtk_widget_get_style_context (widget);
 
174
        gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
 
175
}
 
176
 
 
177
void
 
178
enable_disable_restoring (GtkBuilder * dialog)
 
179
{
 
180
        GkbdKeyboardConfig gswic;
 
181
        gboolean enable;
 
182
 
 
183
        gkbd_keyboard_config_init (&gswic, engine);
 
184
        gkbd_keyboard_config_load (&gswic, NULL);
 
185
 
 
186
        enable = !gkbd_keyboard_config_equals (&gswic, &initial_config);
 
187
 
 
188
        gkbd_keyboard_config_term (&gswic);
 
189
        gtk_widget_set_sensitive (WID ("xkb_reset_to_defaults"), enable);
 
190
}