1
/* gnome-region-panel-xkb.c
2
* Copyright (C) 2003-2007 Sergey V. Udaltsov
4
* Written by: Sergey V. Udaltsov <svu@gnome.org>
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)
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.
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
28
#include <glib/gi18n.h>
30
#include "gnome-region-panel-xkb.h"
32
#include <libgnomekbd/gkbd-desktop-config.h>
35
XklConfigRegistry *config_registry;
37
GkbdKeyboardConfig initial_config;
38
GkbdDesktopConfig desktop_config;
40
GSettings *xkb_keyboard_settings;
41
GSettings *xkb_desktop_settings;
44
xci_desc_to_utf8 (const XklConfigItem * ci)
46
gchar *dd = g_strdup (ci->description);
47
gchar *sd = g_strstrip (dd);
48
gchar *rv = g_strdup (sd[0] == 0 ? ci->name : sd);
54
cleanup_xkb_tabs (GtkBuilder * dialog,
55
GObject *where_the_object_wa)
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 */
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;
70
reset_to_defaults (GtkWidget * button, GtkBuilder * dialog)
72
GkbdKeyboardConfig empty_kbd_config;
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);
78
g_settings_reset (xkb_desktop_settings,
79
GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP);
81
/* all the rest is g-s-d's business */
85
chk_new_windows_inherit_layout_toggled (GtkWidget *
86
chk_new_windows_inherit_layout,
89
xkb_save_default_group (gtk_toggle_button_get_active
91
(chk_new_windows_inherit_layout)) ? -1 :
96
setup_xkb_tabs (GtkBuilder * dialog)
99
GtkStyleContext *context;
100
GtkWidget *chk_new_windows_inherit_layout;
102
chk_new_windows_inherit_layout = WID ("chk_new_windows_inherit_layout");
104
xkb_desktop_settings = g_settings_new (GKBD_DESKTOP_SCHEMA);
105
xkb_keyboard_settings = g_settings_new (GKBD_KEYBOARD_SCHEMA);
108
xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY
109
(gdk_display_get_default ()));
110
config_registry = xkl_config_registry_get_instance (engine);
112
gkbd_desktop_config_init (&desktop_config, engine);
113
gkbd_desktop_config_load (&desktop_config);
115
xkl_config_registry_load (config_registry,
116
desktop_config.load_extra_items);
118
gkbd_keyboard_config_init (&initial_config, engine);
119
gkbd_keyboard_config_load_from_x_initial (&initial_config, NULL);
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);
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);
141
xkb_layouts_prepare_selected_tree (dialog);
142
xkb_layouts_fill_selected_tree (dialog);
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),
149
g_signal_connect (G_OBJECT (chk_new_windows_inherit_layout),
152
(chk_new_windows_inherit_layout_toggled),
155
g_signal_connect_swapped (G_OBJECT (WID ("xkb_layout_options")),
157
G_CALLBACK (xkb_options_popup_dialog),
160
xkb_layouts_register_conf_listener (dialog);
161
xkb_options_register_conf_listener (dialog);
163
g_object_weak_ref (G_OBJECT (WID ("region_notebook")),
164
(GWeakNotify) cleanup_xkb_tabs, dialog);
166
enable_disable_restoring (dialog);
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);
178
enable_disable_restoring (GtkBuilder * dialog)
180
GkbdKeyboardConfig gswic;
183
gkbd_keyboard_config_init (&gswic, engine);
184
gkbd_keyboard_config_load (&gswic, NULL);
186
enable = !gkbd_keyboard_config_equals (&gswic, &initial_config);
188
gkbd_keyboard_config_term (&gswic);
189
gtk_widget_set_sensitive (WID ("xkb_reset_to_defaults"), enable);