Changing library dependency from virtual libgswitchit/libkbdraw to normal libgnomekbd

This commit is contained in:
Sergey V. Udaltsov 2006-10-18 22:37:40 +00:00
parent 0caebda160
commit ada87a95f2
15 changed files with 1091 additions and 1150 deletions

View file

@ -9,9 +9,7 @@ gnome_keyboard_properties_SOURCES = gnome-keyboard-properties.c \
gnome-keyboard-properties-xkb.h
gnome_keyboard_properties_LDADD = \
../accessibility/keyboard/libaccessibility-keyboard.a \
$(GNOMECC_CAPPLETS_LIBS) $(LIBXKLAVIER_LIBS) \
../../libgswitchit/libgswitchit.a \
../../libkbdraw/libkbdraw.a
$(GNOMECC_CAPPLETS_LIBS) $(LIBGNOMEKBDUI_LIBS)
@INTLTOOL_DESKTOP_RULE@
@ -29,6 +27,6 @@ desktopdir = $(datadir)/applications
Desktop_in_files = keyboard.desktop.in
desktop_DATA = $(Desktop_in_files:.desktop.in=.desktop)
INCLUDES = $(GNOMECC_CAPPLETS_CFLAGS) $(LIBXKLAVIER_CFLAGS)
INCLUDES = $(GNOMECC_CAPPLETS_CFLAGS) $(LIBGNOMEKBDUI_CFLAGS)
CLEANFILES = $(GNOMECC_CAPPLETS_CLEANFILES) $(Desktop_in_files) $(desktop_DATA)
EXTRA_DIST = $(Glade_DATA) $(pixmaps_DATA)

View file

@ -30,192 +30,192 @@
#include <gconf/gconf-client.h>
#include <glade/glade.h>
#include "libgswitchit/gswitchit-config.h"
#include "capplet-util.h"
#include "gconf-property-editor.h"
#include "activate-settings-daemon.h"
#include "capplet-stock-icons.h"
#include <../accessibility/keyboard/accessibility-keyboard.h>
#include <libgnomekbd/gkbd-desktop-config.h>
#include "gnome-keyboard-properties-xkb.h"
XklEngine *engine;
XklConfigRegistry *config_registry;
GSwitchItKbdConfig initial_config;
GkbdKeyboardConfig initial_config;
GConfClient *xkb_gconf_client;
char *
xci_desc_to_utf8 (XklConfigItem * ci)
{
char *sd = g_strstrip (ci->description);
return sd[0] == 0 ? g_strdup (ci->name) :
g_locale_to_utf8 (sd, -1, NULL, NULL, NULL);
char *sd = g_strstrip (ci->description);
return sd[0] == 0 ? g_strdup (ci->name) :
g_locale_to_utf8 (sd, -1, NULL, NULL, NULL);
}
static void
set_model_text (GtkWidget * entry,
GConfValue * value)
set_model_text (GtkWidget * entry, GConfValue * value)
{
XklConfigItem ci;
const char * model = NULL;
XklConfigItem ci;
const char *model = NULL;
if (value != NULL && value->type == GCONF_VALUE_STRING)
{
model = gconf_value_get_string (value);
if (model != NULL && model[0] == '\0')
model = NULL;
}
if (value != NULL && value->type == GCONF_VALUE_STRING) {
model = gconf_value_get_string (value);
if (model != NULL && model[0] == '\0')
model = NULL;
}
if (model == NULL)
{
model = initial_config.model;
if (model == NULL)
model = "";
}
if (model == NULL) {
model = initial_config.model;
if (model == NULL)
model = "";
}
g_snprintf (ci.name, sizeof (ci.name), "%s", model);
g_snprintf (ci.name, sizeof (ci.name), "%s", model);
if (xkl_config_registry_find_model (config_registry, &ci))
{
char * d;
if (xkl_config_registry_find_model (config_registry, &ci)) {
char *d;
d = xci_desc_to_utf8 (&ci);
gtk_entry_set_text (GTK_ENTRY (entry), d);
g_free (d);
}
else
{
gtk_entry_set_text (GTK_ENTRY (entry), _("Unknown"));
}
d = xci_desc_to_utf8 (&ci);
gtk_entry_set_text (GTK_ENTRY (entry), d);
g_free (d);
} else {
gtk_entry_set_text (GTK_ENTRY (entry), _("Unknown"));
}
}
static void
model_key_changed (GConfClient * client,
guint cnxn_id,
GConfEntry * entry,
GladeXML * dialog)
guint cnxn_id, GConfEntry * entry, GladeXML * dialog)
{
set_model_text (WID ("xkb_model"),
gconf_entry_get_value (entry));
set_model_text (WID ("xkb_model"), gconf_entry_get_value (entry));
enable_disable_restoring (dialog);
enable_disable_restoring (dialog);
}
static void
setup_model_entry (GladeXML * dialog)
{
GConfValue * value;
GConfValue *value;
value = gconf_client_get (xkb_gconf_client,
GSWITCHIT_KBD_CONFIG_KEY_MODEL,
NULL);
set_model_text (WID ("xkb_model"), value);
if (value != NULL)
gconf_value_free (value);
value = gconf_client_get (xkb_gconf_client,
GKBD_KEYBOARD_CONFIG_KEY_MODEL, NULL);
set_model_text (WID ("xkb_model"), value);
if (value != NULL)
gconf_value_free (value);
gconf_client_notify_add (xkb_gconf_client,
GSWITCHIT_KBD_CONFIG_KEY_MODEL,
(GConfClientNotifyFunc) model_key_changed,
dialog, NULL, NULL);
gconf_client_notify_add (xkb_gconf_client,
GKBD_KEYBOARD_CONFIG_KEY_MODEL,
(GConfClientNotifyFunc) model_key_changed,
dialog, NULL, NULL);
}
static void
cleanup_xkb_tabs (GladeXML * dialog)
{
gswitchit_kbd_config_term (&initial_config);
g_object_unref (G_OBJECT (config_registry));
config_registry = NULL;
g_object_unref (G_OBJECT (engine));
engine = NULL;
g_object_unref (G_OBJECT (xkb_gconf_client));
xkb_gconf_client = NULL;
gkbd_keyboard_config_term (&initial_config);
g_object_unref (G_OBJECT (config_registry));
config_registry = NULL;
g_object_unref (G_OBJECT (engine));
engine = NULL;
g_object_unref (G_OBJECT (xkb_gconf_client));
xkb_gconf_client = NULL;
}
static void
reset_to_defaults (GtkWidget * button, GladeXML * dialog)
{
GSwitchItKbdConfig empty_kbd_config;
GkbdKeyboardConfig empty_kbd_config;
gswitchit_kbd_config_init (&empty_kbd_config, xkb_gconf_client, engine);
gswitchit_kbd_config_save_to_gconf_backup (&empty_kbd_config);
gswitchit_kbd_config_save_to_gconf (&empty_kbd_config);
gswitchit_kbd_config_term (&empty_kbd_config);
gkbd_keyboard_config_init (&empty_kbd_config, xkb_gconf_client,
engine);
gkbd_keyboard_config_save_to_gconf_backup (&empty_kbd_config);
gkbd_keyboard_config_save_to_gconf (&empty_kbd_config);
gkbd_keyboard_config_term (&empty_kbd_config);
/* all the rest is g-s-d's business */
/* all the rest is g-s-d's business */
}
static void
chk_separate_group_per_window_toggled (GConfPropertyEditor *peditor,
const gchar *key,
const GConfValue *value,
GladeXML* dialog)
chk_separate_group_per_window_toggled (GConfPropertyEditor * peditor,
const gchar * key,
const GConfValue * value,
GladeXML * dialog)
{
xkb_layouts_enable_disable_default (dialog, value && gconf_value_get_bool (value));
xkb_layouts_enable_disable_default (dialog, value
&&
gconf_value_get_bool (value));
}
void
setup_xkb_tabs (GladeXML * dialog, GConfChangeSet * changeset)
{
GObject * peditor;
xkb_gconf_client = gconf_client_get_default ();
GObject *peditor;
xkb_gconf_client = gconf_client_get_default ();
engine = xkl_engine_get_instance (GDK_DISPLAY ());
config_registry = xkl_config_registry_get_instance (engine);
xkl_config_registry_load (config_registry);
engine = xkl_engine_get_instance (GDK_DISPLAY ());
config_registry = xkl_config_registry_get_instance (engine);
xkl_config_registry_load (config_registry);
gswitchit_kbd_config_init (&initial_config, xkb_gconf_client, engine);
gswitchit_kbd_config_load_from_x_initial (&initial_config);
gkbd_keyboard_config_init (&initial_config, xkb_gconf_client,
engine);
gkbd_keyboard_config_load_from_x_initial (&initial_config, NULL);
setup_model_entry (dialog);
setup_model_entry (dialog);
peditor = gconf_peditor_new_boolean
(changeset, (gchar *) GSWITCHIT_CONFIG_KEY_GROUP_PER_WINDOW,
WID ("chk_separate_group_per_window"), NULL);
peditor = gconf_peditor_new_boolean
(changeset, (gchar *) GKBD_DESKTOP_CONFIG_KEY_GROUP_PER_WINDOW,
WID ("chk_separate_group_per_window"), NULL);
g_signal_connect (peditor, "value-changed", (GCallback)chk_separate_group_per_window_toggled , dialog);
g_signal_connect (peditor, "value-changed",
(GCallback)
chk_separate_group_per_window_toggled, dialog);
/* tab 2 */
/*fill_available_layouts_tree (dialog);*/
xkb_layouts_prepare_selected_tree (dialog, changeset);
xkb_layouts_fill_selected_tree (dialog);
/*fill_available_layouts_tree (dialog); */
xkb_layouts_prepare_selected_tree (dialog, changeset);
xkb_layouts_fill_selected_tree (dialog);
/* tab 3 */
xkb_options_load_options (dialog);
xkb_options_load_options (dialog);
xkb_layouts_register_buttons_handlers (dialog);
g_signal_connect (G_OBJECT (WID ("xkb_reset_to_defaults")), "clicked",
G_CALLBACK (reset_to_defaults), dialog);
xkb_layouts_register_buttons_handlers (dialog);
g_signal_connect (G_OBJECT (WID ("xkb_reset_to_defaults")),
"clicked", G_CALLBACK (reset_to_defaults),
dialog);
g_signal_connect_swapped (G_OBJECT (WID ("xkb_model_pick")), "clicked",
G_CALLBACK (choose_model), dialog);
g_signal_connect_swapped (G_OBJECT (WID ("xkb_model_pick")),
"clicked", G_CALLBACK (choose_model),
dialog);
xkb_layouts_register_gconf_listener (dialog);
xkb_options_register_gconf_listener (dialog);
xkb_layouts_register_gconf_listener (dialog);
xkb_options_register_gconf_listener (dialog);
g_signal_connect (G_OBJECT (WID ("keyboard_dialog")),
"destroy", G_CALLBACK (cleanup_xkb_tabs), dialog);
g_signal_connect (G_OBJECT (WID ("keyboard_dialog")),
"destroy", G_CALLBACK (cleanup_xkb_tabs),
dialog);
enable_disable_restoring (dialog);
xkb_layouts_enable_disable_default (dialog,
gconf_client_get_bool (xkb_gconf_client,
GSWITCHIT_CONFIG_KEY_GROUP_PER_WINDOW,
NULL));
enable_disable_restoring (dialog);
xkb_layouts_enable_disable_default (dialog,
gconf_client_get_bool
(xkb_gconf_client,
GKBD_DESKTOP_CONFIG_KEY_GROUP_PER_WINDOW,
NULL));
}
void
enable_disable_restoring (GladeXML * dialog)
{
GSwitchItKbdConfig gswic;
gboolean enable;
GkbdKeyboardConfig gswic;
gboolean enable;
gswitchit_kbd_config_init (&gswic, xkb_gconf_client, engine);
gswitchit_kbd_config_load_from_gconf (&gswic, NULL);
gkbd_keyboard_config_init (&gswic, xkb_gconf_client, engine);
gkbd_keyboard_config_load_from_gconf (&gswic, NULL);
enable = !gswitchit_kbd_config_equals (&gswic, &initial_config);
enable = !gkbd_keyboard_config_equals (&gswic, &initial_config);
gswitchit_kbd_config_term (&gswic);
gtk_widget_set_sensitive (WID ("xkb_reset_to_defaults"), enable);
gkbd_keyboard_config_term (&gswic);
gtk_widget_set_sensitive (WID ("xkb_reset_to_defaults"), enable);
}

View file

@ -24,29 +24,23 @@
#ifndef __GNOME_KEYBOARD_PROPERTY_XKB_H
#define __GNOME_KEYBOARD_PROPERTY_XKB_H
#include <libxklavier/xklavier.h>
#include <gconf/gconf-client.h>
#include "libgswitchit/gswitchit-config.h"
#include "libgnomekbd/gkbd-keyboard-config.h"
G_BEGIN_DECLS
#define SEL_LAYOUT_TREE_COL_DESCRIPTION 0
#define SEL_LAYOUT_TREE_COL_DEFAULT 1
#define SEL_LAYOUT_TREE_COL_ID 2
#define AVAIL_LAYOUT_TREE_COL_DESCRIPTION 0
#define AVAIL_LAYOUT_TREE_COL_ID 1
#define CWID(s) glade_xml_get_widget (chooser_dialog, s)
extern XklEngine *engine;
extern XklConfigRegistry *config_registry;
extern GConfClient *xkb_gconf_client;
extern GSwitchItKbdConfig initial_config;
extern GkbdKeyboardConfig initial_config;
extern void setup_xkb_tabs (GladeXML * dialog,
GConfChangeSet * changeset);
extern void setup_xkb_tabs (GladeXML * dialog, GConfChangeSet * changeset);
extern void xkb_layouts_fill_available_tree (GladeXML * dialog);
@ -64,8 +58,8 @@ extern void xkb_layouts_register_gconf_listener (GladeXML * dialog);
extern void xkb_options_register_gconf_listener (GladeXML * dialog);
extern void xkb_layouts_prepare_selected_tree (GladeXML * dialog,
GConfChangeSet * changeset);
extern void xkb_layouts_prepare_selected_tree (GladeXML * dialog,
GConfChangeSet * changeset);
extern void xkb_options_prepare_selected_tree (GladeXML * dialog);
@ -85,23 +79,24 @@ extern void choose_model (GladeXML * dialog);
extern void xkb_layout_choose (GladeXML * dialog);
extern void xkb_layouts_enable_disable_default (GladeXML * dialog,
gboolean enable);
extern void xkb_layouts_enable_disable_default (GladeXML * dialog,
gboolean enable);
extern GSList *xkb_layouts_get_selected_list (void);
extern GSList *xkb_options_get_selected_list (void);
#define xkb_layouts_set_selected_list(list) \
gconf_client_set_list (gconf_client_get_default (), \
GSWITCHIT_KBD_CONFIG_KEY_LAYOUTS, \
GKBD_KEYBOARD_CONFIG_KEY_LAYOUTS, \
GCONF_VALUE_STRING, (list), NULL)
#define xkb_options_set_selected_list(list) \
gconf_client_set_list (gconf_client_get_default (), \
GSWITCHIT_KBD_CONFIG_KEY_OPTIONS, \
GKBD_KEYBOARD_CONFIG_KEY_OPTIONS, \
GCONF_VALUE_STRING, (list), NULL)
extern GtkWidget * xkb_layout_preview_create_widget (GladeXML * chooser_dialog);
extern GtkWidget *xkb_layout_preview_create_widget (GladeXML *
chooser_dialog);
extern void xkb_layout_preview_update (GladeXML * chooser_dialog);

File diff suppressed because it is too large Load diff

View file

@ -30,8 +30,6 @@
#include <gconf/gconf-client.h>
#include <glade/glade.h>
#include "libgswitchit/gswitchit-config.h"
#include "capplet-util.h"
#include "gconf-property-editor.h"
#include "activate-settings-daemon.h"
@ -40,123 +38,145 @@
#include "gnome-keyboard-properties-xkb.h"
static gchar* current_model_name = NULL;
static gchar *current_model_name = NULL;
static void
add_model_to_list (XklConfigRegistry * config_registry,
XklConfigItem * config_item,
GtkTreeView * models_list)
XklConfigItem * config_item, GtkTreeView * models_list)
{
GtkTreeIter iter;
GtkListStore * list_store = GTK_LIST_STORE (gtk_tree_view_get_model (models_list));
char *utf_model_name = xci_desc_to_utf8 (config_item);
gtk_list_store_append( list_store, &iter );
gtk_list_store_set( list_store, &iter,
0, utf_model_name,
1, config_item->name, -1 );
GtkTreeIter iter;
GtkListStore *list_store =
GTK_LIST_STORE (gtk_tree_view_get_model (models_list));
char *utf_model_name = xci_desc_to_utf8 (config_item);
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
0, utf_model_name, 1, config_item->name, -1);
g_free (utf_model_name);
g_free (utf_model_name);
}
static void
xkb_model_chooser_change_sel (GtkTreeSelection* selection,
GladeXML* chooser_dialog)
xkb_model_chooser_change_sel (GtkTreeSelection * selection,
GladeXML * chooser_dialog)
{
gboolean anysel = gtk_tree_selection_get_selected (selection, NULL, NULL);
gtk_dialog_set_response_sensitive (GTK_DIALOG (CWID ("xkb_model_chooser")),
GTK_RESPONSE_OK, anysel);
gboolean anysel =
gtk_tree_selection_get_selected (selection, NULL, NULL);
gtk_dialog_set_response_sensitive (GTK_DIALOG
(CWID ("xkb_model_chooser")),
GTK_RESPONSE_OK, anysel);
}
static void
fill_models_list (GladeXML * chooser_dialog)
{
GtkWidget* models_list = CWID( "models_list" );
GtkTreeIter iter;
GtkTreePath *path;
GtkCellRenderer* renderer = gtk_cell_renderer_text_new ();
GtkTreeViewColumn* description_col = gtk_tree_view_column_new_with_attributes ( _("Models"),
renderer,
"text", 0,
NULL);
GtkListStore *list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
char *model_name;
GtkWidget *models_list = CWID ("models_list");
GtkTreeIter iter;
GtkTreePath *path;
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
GtkTreeViewColumn *description_col =
gtk_tree_view_column_new_with_attributes (_("Models"),
renderer,
"text", 0,
NULL);
GtkListStore *list_store =
gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
char *model_name;
gtk_tree_view_column_set_visible (description_col, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (models_list), description_col);
gtk_tree_view_column_set_visible (description_col, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (models_list),
description_col);
gtk_tree_view_set_model (GTK_TREE_VIEW (models_list), GTK_TREE_MODEL (list_store) );
gtk_tree_view_set_model (GTK_TREE_VIEW (models_list),
GTK_TREE_MODEL (list_store));
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store),
0, GTK_SORT_ASCENDING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE
(list_store), 0,
GTK_SORT_ASCENDING);
xkl_config_registry_foreach_model (config_registry,
(ConfigItemProcessFunc) add_model_to_list,
models_list);
xkl_config_registry_foreach_model (config_registry,
(ConfigItemProcessFunc)
add_model_to_list, models_list);
if (current_model_name != NULL)
{
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
{
do
{
gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
1, &model_name, -1);
if (!g_ascii_strcasecmp(model_name, current_model_name))
{
gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (models_list)), &iter);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (list_store), &iter);
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (models_list),
path, NULL, TRUE, 0.5, 0);
gtk_tree_path_free (path);
}
g_free (model_name);
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter));
}
}
if (current_model_name != NULL) {
if (gtk_tree_model_get_iter_first
(GTK_TREE_MODEL (list_store), &iter)) {
do {
gtk_tree_model_get (GTK_TREE_MODEL
(list_store), &iter, 1,
&model_name, -1);
if (!g_ascii_strcasecmp
(model_name, current_model_name)) {
gtk_tree_selection_select_iter
(gtk_tree_view_get_selection
(GTK_TREE_VIEW (models_list)),
&iter);
path =
gtk_tree_model_get_path
(GTK_TREE_MODEL (list_store),
&iter);
gtk_tree_view_scroll_to_cell
(GTK_TREE_VIEW (models_list),
path, NULL, TRUE, 0.5, 0);
gtk_tree_path_free (path);
}
g_free (model_name);
} while (gtk_tree_model_iter_next
(GTK_TREE_MODEL (list_store), &iter));
}
}
g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (models_list))),
"changed",
G_CALLBACK (xkb_model_chooser_change_sel),
chooser_dialog);
g_signal_connect (G_OBJECT
(gtk_tree_view_get_selection
(GTK_TREE_VIEW (models_list))), "changed",
G_CALLBACK (xkb_model_chooser_change_sel),
chooser_dialog);
}
static void
xkb_model_chooser_response (GtkDialog *dialog,
gint response,
GladeXML *chooser_dialog)
xkb_model_chooser_response (GtkDialog * dialog,
gint response, GladeXML * chooser_dialog)
{
if (response == GTK_RESPONSE_OK)
{
GtkWidget* models_list = CWID( "models_list" );
GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (models_list));
GtkTreeIter iter;
GtkTreeModel* list_store = NULL;
if (gtk_tree_selection_get_selected (selection, &list_store, &iter))
{
gchar* model_name = NULL;
gtk_tree_model_get (list_store, &iter,
1, &model_name, -1);
if (response == GTK_RESPONSE_OK) {
GtkWidget *models_list = CWID ("models_list");
GtkTreeSelection *selection =
gtk_tree_view_get_selection (GTK_TREE_VIEW
(models_list));
GtkTreeIter iter;
GtkTreeModel *list_store = NULL;
if (gtk_tree_selection_get_selected
(selection, &list_store, &iter)) {
gchar *model_name = NULL;
gtk_tree_model_get (list_store, &iter,
1, &model_name, -1);
gconf_client_set_string (xkb_gconf_client,
GSWITCHIT_KBD_CONFIG_KEY_MODEL,
model_name, NULL);
g_free(model_name);
}
}
gconf_client_set_string (xkb_gconf_client,
GKBD_KEYBOARD_CONFIG_KEY_MODEL,
model_name, NULL);
g_free (model_name);
}
}
}
void
choose_model(GladeXML * dialog)
choose_model (GladeXML * dialog)
{
GladeXML* chooser_dialog = glade_xml_new (GNOMECC_DATA_DIR "/interfaces/gnome-keyboard-properties.glade", "xkb_model_chooser", NULL);
GtkWidget* chooser = CWID ( "xkb_model_chooser");
gtk_window_set_transient_for (GTK_WINDOW (chooser), GTK_WINDOW (WID ("keyboard_dialog")));
current_model_name = gconf_client_get_string (xkb_gconf_client,
GSWITCHIT_KBD_CONFIG_KEY_MODEL, NULL);
fill_models_list (chooser_dialog);
g_signal_connect (G_OBJECT (chooser),
"response", G_CALLBACK (xkb_model_chooser_response), chooser_dialog);
gtk_dialog_run (GTK_DIALOG (chooser));
gtk_widget_destroy (chooser);
g_free (current_model_name);
GladeXML *chooser_dialog =
glade_xml_new (GNOMECC_DATA_DIR
"/interfaces/gnome-keyboard-properties.glade",
"xkb_model_chooser", NULL);
GtkWidget *chooser = CWID ("xkb_model_chooser");
gtk_window_set_transient_for (GTK_WINDOW (chooser),
GTK_WINDOW (WID
("keyboard_dialog")));
current_model_name =
gconf_client_get_string (xkb_gconf_client,
GKBD_KEYBOARD_CONFIG_KEY_MODEL, NULL);
fill_models_list (chooser_dialog);
g_signal_connect (G_OBJECT (chooser),
"response",
G_CALLBACK (xkb_model_chooser_response),
chooser_dialog);
gtk_dialog_run (GTK_DIALOG (chooser));
gtk_widget_destroy (chooser);
g_free (current_model_name);
}

View file

@ -30,7 +30,7 @@
#include <gconf/gconf-client.h>
#include <glade/glade.h>
#include "libgswitchit/gswitchit-config.h"
#include "libgnomekbd/gkbd-keyboard-config.h"
#include "capplet-util.h"
#include "gconf-property-editor.h"
@ -54,153 +54,170 @@ static GSList *current_radio_group = NULL;
GSList *
xkb_options_get_selected_list (void)
{
GSList *retval;
GSList *retval;
retval = gconf_client_get_list (xkb_gconf_client,
GSWITCHIT_KBD_CONFIG_KEY_OPTIONS,
GCONF_VALUE_STRING,
NULL);
if (retval == NULL)
{
GSList *cur_option;
retval = gconf_client_get_list (xkb_gconf_client,
GKBD_KEYBOARD_CONFIG_KEY_OPTIONS,
GCONF_VALUE_STRING, NULL);
if (retval == NULL) {
GSList *cur_option;
for (cur_option = initial_config.options; cur_option != NULL; cur_option = cur_option->next)
retval = g_slist_prepend (retval, g_strdup (cur_option->data));
for (cur_option = initial_config.options;
cur_option != NULL; cur_option = cur_option->next)
retval =
g_slist_prepend (retval,
g_strdup (cur_option->data));
retval = g_slist_reverse (retval);
}
retval = g_slist_reverse (retval);
}
return retval;
return retval;
}
static GtkWidget *
xkb_options_get_expander (GtkWidget * option_button)
{
return gtk_widget_get_parent (
gtk_widget_get_parent (
gtk_widget_get_parent (option_button)));
return
gtk_widget_get_parent (gtk_widget_get_parent
(gtk_widget_get_parent
(option_button)));
}
static int
xkb_options_expander_selcounter_get (GtkWidget * expander)
{
return GPOINTER_TO_INT(g_object_get_data (G_OBJECT (expander), SELCOUNTER_PROP));
return
GPOINTER_TO_INT (g_object_get_data
(G_OBJECT (expander), SELCOUNTER_PROP));
}
static void
xkb_options_expander_selcounter_add (GtkWidget * expander, int value)
{
g_object_set_data (G_OBJECT (expander), SELCOUNTER_PROP,
GINT_TO_POINTER (xkb_options_expander_selcounter_get (expander) + value));
g_object_set_data (G_OBJECT (expander), SELCOUNTER_PROP,
GINT_TO_POINTER
(xkb_options_expander_selcounter_get (expander)
+ value));
}
static void
xkb_options_expander_highlight (GtkWidget * expander)
{
char * utf_group_name = g_object_get_data (G_OBJECT (expander), "utfGroupName");
int counter = xkb_options_expander_selcounter_get (expander);
if (utf_group_name != NULL) {
gchar *titlemarkup = g_strconcat (counter > 0 ? "<span weight=\"bold\">" : "<span>",
utf_group_name, "</span>", NULL);
gtk_expander_set_label (GTK_EXPANDER (expander), titlemarkup);
g_free (titlemarkup);
}
char *utf_group_name =
g_object_get_data (G_OBJECT (expander), "utfGroupName");
int counter = xkb_options_expander_selcounter_get (expander);
if (utf_group_name != NULL) {
gchar *titlemarkup =
g_strconcat (counter >
0 ? "<span weight=\"bold\">" : "<span>",
utf_group_name, "</span>", NULL);
gtk_expander_set_label (GTK_EXPANDER (expander),
titlemarkup);
g_free (titlemarkup);
}
}
/* Add optionname from the backend's selection list if it's not
already in there. */
static void
xkb_options_select (gchar *optionname)
xkb_options_select (gchar * optionname)
{
gboolean already_selected = FALSE;
GSList *options_list = xkb_options_get_selected_list ();
GSList *option;
for (option = options_list ; option != NULL ; option = option->next)
if (!strcmp ((gchar*)option->data, optionname))
already_selected = TRUE;
gboolean already_selected = FALSE;
GSList *options_list = xkb_options_get_selected_list ();
GSList *option;
for (option = options_list; option != NULL; option = option->next)
if (!strcmp ((gchar *) option->data, optionname))
already_selected = TRUE;
if (!already_selected)
options_list = g_slist_append (options_list, g_strdup (optionname));
xkb_options_set_selected_list (options_list);
if (!already_selected)
options_list =
g_slist_append (options_list, g_strdup (optionname));
xkb_options_set_selected_list (options_list);
clear_xkb_elements_list (options_list);
clear_xkb_elements_list (options_list);
}
/* Remove all occurences of optionname from the backend's selection list */
static void
xkb_options_deselect (gchar *optionname)
xkb_options_deselect (gchar * optionname)
{
GSList *options_list = xkb_options_get_selected_list ();
GSList *nodetmp;
GSList *option = options_list;
while (option != NULL)
{
gchar *id = (char *) option->data;
if (!strcmp(id, optionname))
{
nodetmp = option->next;
g_free (id);
options_list = g_slist_remove_link (options_list, option);
g_slist_free_1 (option);
option=nodetmp;
}
else
option = option->next;
}
xkb_options_set_selected_list (options_list);
clear_xkb_elements_list (options_list);
GSList *options_list = xkb_options_get_selected_list ();
GSList *nodetmp;
GSList *option = options_list;
while (option != NULL) {
gchar *id = (char *) option->data;
if (!strcmp (id, optionname)) {
nodetmp = option->next;
g_free (id);
options_list =
g_slist_remove_link (options_list, option);
g_slist_free_1 (option);
option = nodetmp;
} else
option = option->next;
}
xkb_options_set_selected_list (options_list);
clear_xkb_elements_list (options_list);
}
/* Return true if optionname describes a string already in the backend's
list of selected options */
static gboolean
xkb_options_is_selected (gchar *optionname)
xkb_options_is_selected (gchar * optionname)
{
gboolean retval = FALSE;
GSList *options_list = xkb_options_get_selected_list ();
GSList *option;
for (option = options_list ; option != NULL ; option = option->next)
{
if (!strcmp ((gchar*)option->data, optionname))
retval = TRUE;
}
clear_xkb_elements_list (options_list);
return retval;
gboolean retval = FALSE;
GSList *options_list = xkb_options_get_selected_list ();
GSList *option;
for (option = options_list; option != NULL; option = option->next) {
if (!strcmp ((gchar *) option->data, optionname))
retval = TRUE;
}
clear_xkb_elements_list (options_list);
return retval;
}
/* Update xkb backend to reflect the new UI state */
static void
option_toggled_cb (GtkWidget *checkbutton, gpointer data)
option_toggled_cb (GtkWidget * checkbutton, gpointer data)
{
gpointer optionID = g_object_get_data (G_OBJECT (checkbutton), OPTION_ID_PROP);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton)))
xkb_options_select (optionID);
else
xkb_options_deselect (optionID);
gpointer optionID =
g_object_get_data (G_OBJECT (checkbutton), OPTION_ID_PROP);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton)))
xkb_options_select (optionID);
else
xkb_options_deselect (optionID);
}
/* Update UI state from xkb backend */
static void
option_update_cb (GConfClient * client,
guint cnxn_id, GConfEntry * entry, gpointer data)
guint cnxn_id, GConfEntry * entry, gpointer data)
{
GtkToggleButton *toggle = GTK_TOGGLE_BUTTON (data);
GtkWidget *expander = xkb_options_get_expander (GTK_WIDGET (toggle));
gboolean old_state = gtk_toggle_button_get_active (toggle);
gboolean new_state = xkb_options_is_selected (
g_object_get_data (G_OBJECT (toggle), OPTION_ID_PROP));
int old_gstate = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (toggle), GCONFSTATE_PROP));
int state_diff = new_state - old_gstate;
GtkToggleButton *toggle = GTK_TOGGLE_BUTTON (data);
GtkWidget *expander =
xkb_options_get_expander (GTK_WIDGET (toggle));
gboolean old_state = gtk_toggle_button_get_active (toggle);
gboolean new_state =
xkb_options_is_selected (g_object_get_data
(G_OBJECT (toggle), OPTION_ID_PROP));
int old_gstate =
GPOINTER_TO_INT (g_object_get_data
(G_OBJECT (toggle), GCONFSTATE_PROP));
int state_diff = new_state - old_gstate;
if (GTK_WIDGET_TYPE (toggle) == GTK_TYPE_RADIO_BUTTON &&
old_state == TRUE && new_state == FALSE)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (g_object_get_data (G_OBJECT (toggle), "NoneRadio")), TRUE);
else
gtk_toggle_button_set_active (toggle, new_state);
if (GTK_WIDGET_TYPE (toggle) == GTK_TYPE_RADIO_BUTTON &&
old_state == TRUE && new_state == FALSE)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(g_object_get_data
(G_OBJECT (toggle),
"NoneRadio")), TRUE);
else
gtk_toggle_button_set_active (toggle, new_state);
g_object_set_data (G_OBJECT (toggle), GCONFSTATE_PROP, GINT_TO_POINTER (new_state));
xkb_options_expander_selcounter_add (expander, state_diff);
xkb_options_expander_highlight (expander);
g_object_set_data (G_OBJECT (toggle), GCONFSTATE_PROP,
GINT_TO_POINTER (new_state));
xkb_options_expander_selcounter_add (expander, state_diff);
xkb_options_expander_highlight (expander);
}
/* Add a check_button or radio_button to control a particular option
@ -208,153 +225,186 @@ option_update_cb (GConfClient * client,
the top of this file. */
static void
xkb_options_add_option (XklConfigRegistry * config_registry,
XklConfigItem * config_item,
GladeXML * dialog)
XklConfigItem * config_item, GladeXML * dialog)
{
GtkWidget *option_check;
gchar *utf_option_name = xci_desc_to_utf8 (config_item);
/* Copy this out because we'll load it into the widget with set_data */
gchar *full_option_name = g_strdup(
gswitchit_kbd_config_merge_items (current1st_level_id, config_item->name));
gboolean initial_state;
GtkWidget *option_check;
gchar *utf_option_name = xci_desc_to_utf8 (config_item);
/* Copy this out because we'll load it into the widget with set_data */
gchar *full_option_name =
g_strdup (gkbd_keyboard_config_merge_items
(current1st_level_id, config_item->name));
gboolean initial_state;
if (current_multi_select)
option_check = gtk_check_button_new_with_label (utf_option_name);
else
{
if (current_radio_group == NULL)
{
/* The first radio in a group is to be "Default", meaning none of
the below options are to be included in the selected list.
This is a HIG-compliant alternative to allowing no
selection in the group. */
option_check = gtk_radio_button_new_with_label (current_radio_group, _("Default"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (option_check), TRUE);
gtk_box_pack_start_defaults (GTK_BOX (current_vbox), option_check);
current_radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (option_check));
current_none_radio = option_check;
}
option_check = gtk_radio_button_new_with_label (current_radio_group, utf_option_name);
current_radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (option_check));
g_object_set_data (G_OBJECT (option_check), "NoneRadio", current_none_radio);
}
g_free (utf_option_name);
if (current_multi_select)
option_check =
gtk_check_button_new_with_label (utf_option_name);
else {
if (current_radio_group == NULL) {
/* The first radio in a group is to be "Default", meaning none of
the below options are to be included in the selected list.
This is a HIG-compliant alternative to allowing no
selection in the group. */
option_check =
gtk_radio_button_new_with_label
(current_radio_group, _("Default"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(option_check),
TRUE);
gtk_box_pack_start_defaults (GTK_BOX
(current_vbox),
option_check);
current_radio_group =
gtk_radio_button_get_group (GTK_RADIO_BUTTON
(option_check));
current_none_radio = option_check;
}
option_check =
gtk_radio_button_new_with_label (current_radio_group,
utf_option_name);
current_radio_group =
gtk_radio_button_get_group (GTK_RADIO_BUTTON
(option_check));
g_object_set_data (G_OBJECT (option_check), "NoneRadio",
current_none_radio);
}
g_free (utf_option_name);
initial_state = xkb_options_is_selected (full_option_name);
initial_state = xkb_options_is_selected (full_option_name);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (option_check), initial_state);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (option_check),
initial_state);
g_object_set_data_full (G_OBJECT (option_check), OPTION_ID_PROP, full_option_name, g_free);
g_object_set_data_full (G_OBJECT (option_check), OPTION_ID_PROP,
full_option_name, g_free);
g_signal_connect (G_OBJECT (option_check), "toggled", G_CALLBACK (option_toggled_cb), NULL);
g_signal_connect (G_OBJECT (option_check), "toggled",
G_CALLBACK (option_toggled_cb), NULL);
gconf_client_notify_add (xkb_gconf_client,
GSWITCHIT_KBD_CONFIG_KEY_OPTIONS,
(GConfClientNotifyFunc)
option_update_cb, option_check, NULL, NULL);
gconf_client_notify_add (xkb_gconf_client,
GKBD_KEYBOARD_CONFIG_KEY_OPTIONS,
(GConfClientNotifyFunc)
option_update_cb, option_check, NULL,
NULL);
gtk_box_pack_start_defaults (GTK_BOX (current_vbox), option_check);
gtk_box_pack_start_defaults (GTK_BOX (current_vbox), option_check);
xkb_options_expander_selcounter_add (xkb_options_get_expander (option_check), initial_state);
g_object_set_data (G_OBJECT (option_check), GCONFSTATE_PROP, GINT_TO_POINTER (initial_state));
xkb_options_expander_selcounter_add (xkb_options_get_expander
(option_check),
initial_state);
g_object_set_data (G_OBJECT (option_check), GCONFSTATE_PROP,
GINT_TO_POINTER (initial_state));
}
/* Add a group of options: create title and layout widgets and then
add widgets for all the options in the group. */
static void
xkb_options_add_group (XklConfigRegistry * config_registry,
XklConfigItem * config_item,
GladeXML * dialog)
XklConfigItem * config_item, GladeXML * dialog)
{
GtkWidget *expander, *align, *vbox;
gboolean allow_multiple_selection = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (config_item),
XCI_PROP_ALLOW_MULTIPLE_SELECTION));
GtkWidget *expander, *align, *vbox;
gboolean allow_multiple_selection =
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (config_item),
XCI_PROP_ALLOW_MULTIPLE_SELECTION));
GSList * expanders_list = g_object_get_data (G_OBJECT (dialog), EXPANDERS_PROP);
GSList *expanders_list =
g_object_get_data (G_OBJECT (dialog), EXPANDERS_PROP);
gchar *utf_group_name = xci_desc_to_utf8 (config_item);
gchar *titlemarkup = g_strconcat ("<span>", utf_group_name, "</span>", NULL);
gchar *utf_group_name = xci_desc_to_utf8 (config_item);
gchar *titlemarkup =
g_strconcat ("<span>", utf_group_name, "</span>", NULL);
expander = gtk_expander_new (titlemarkup);
gtk_expander_set_use_markup (GTK_EXPANDER (expander), TRUE);
g_object_set_data_full (G_OBJECT (expander), "utfGroupName", utf_group_name, g_free);
expander = gtk_expander_new (titlemarkup);
gtk_expander_set_use_markup (GTK_EXPANDER (expander), TRUE);
g_object_set_data_full (G_OBJECT (expander), "utfGroupName",
utf_group_name, g_free);
g_free (titlemarkup);
align = gtk_alignment_new (0, 0, 1, 1);
gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 12, 12, 0);
vbox = gtk_vbox_new (TRUE, 6);
gtk_container_add (GTK_CONTAINER (align), vbox);
gtk_container_add (GTK_CONTAINER (expander), align);
current_vbox = vbox;
g_free (titlemarkup);
align = gtk_alignment_new (0, 0, 1, 1);
gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 12, 12, 0);
vbox = gtk_vbox_new (TRUE, 6);
gtk_container_add (GTK_CONTAINER (align), vbox);
gtk_container_add (GTK_CONTAINER (expander), align);
current_vbox = vbox;
current_multi_select = (gboolean) allow_multiple_selection;
current_radio_group = NULL;
current_multi_select = (gboolean) allow_multiple_selection;
current_radio_group = NULL;
current1st_level_id = config_item->name;
xkl_config_registry_foreach_option (config_registry, config_item->name,
(ConfigItemProcessFunc)xkb_options_add_option,
dialog);
current1st_level_id = config_item->name;
xkl_config_registry_foreach_option (config_registry,
config_item->name,
(ConfigItemProcessFunc)
xkb_options_add_option,
dialog);
xkb_options_expander_highlight (expander);
xkb_options_expander_highlight (expander);
expanders_list = g_slist_append (expanders_list, expander);
g_object_set_data (G_OBJECT (dialog), EXPANDERS_PROP, expanders_list);
expanders_list = g_slist_append (expanders_list, expander);
g_object_set_data (G_OBJECT (dialog), EXPANDERS_PROP,
expanders_list);
}
static gint
xkb_options_expanders_compare (GtkWidget * expander1, GtkWidget * expander2)
xkb_options_expanders_compare (GtkWidget * expander1,
GtkWidget * expander2)
{
const gchar *t1 = gtk_expander_get_label (GTK_EXPANDER (expander1));
const gchar *t2 = gtk_expander_get_label (GTK_EXPANDER (expander2));
return g_utf8_collate (t1, t2);
const gchar *t1 =
gtk_expander_get_label (GTK_EXPANDER (expander1));
const gchar *t2 =
gtk_expander_get_label (GTK_EXPANDER (expander2));
return g_utf8_collate (t1, t2);
}
/* Create widgets to represent the options made available by the backend */
void
xkb_options_load_options (GladeXML * dialog)
{
GtkWidget *opts_vbox = WID ("options_vbox");
GSList * expanders_list;
GtkWidget * expander;
GtkWidget *opts_vbox = WID ("options_vbox");
GSList *expanders_list;
GtkWidget *expander;
/* fill the list */
xkl_config_registry_foreach_option_group (config_registry,
(ConfigItemProcessFunc)xkb_options_add_group,
dialog);
/* sort it */
expanders_list = g_object_get_data (G_OBJECT (dialog), EXPANDERS_PROP);
expanders_list = g_slist_sort (expanders_list, (GCompareFunc)xkb_options_expanders_compare);
while (expanders_list)
{
expander = GTK_WIDGET (expanders_list->data);
gtk_box_pack_start (GTK_BOX (opts_vbox), expander, FALSE, FALSE, 0);
expanders_list = expanders_list->next;
}
/* fill the list */
xkl_config_registry_foreach_option_group (config_registry,
(ConfigItemProcessFunc)
xkb_options_add_group,
dialog);
/* sort it */
expanders_list =
g_object_get_data (G_OBJECT (dialog), EXPANDERS_PROP);
expanders_list =
g_slist_sort (expanders_list,
(GCompareFunc) xkb_options_expanders_compare);
while (expanders_list) {
expander = GTK_WIDGET (expanders_list->data);
gtk_box_pack_start (GTK_BOX (opts_vbox), expander, FALSE,
FALSE, 0);
expanders_list = expanders_list->next;
}
/* just cleanup */
expanders_list = g_object_get_data (G_OBJECT (dialog), EXPANDERS_PROP);
g_object_set_data (G_OBJECT (dialog), EXPANDERS_PROP, NULL);
g_slist_free (expanders_list);
/* just cleanup */
expanders_list =
g_object_get_data (G_OBJECT (dialog), EXPANDERS_PROP);
g_object_set_data (G_OBJECT (dialog), EXPANDERS_PROP, NULL);
g_slist_free (expanders_list);
gtk_widget_show_all (opts_vbox);
gtk_widget_show_all (opts_vbox);
}
/* Respond to a change in the xkb gconf settings */
static void
xkb_options_update (GConfClient * client,
guint cnxn_id, GConfEntry * entry, GladeXML * dialog)
guint cnxn_id, GConfEntry * entry, GladeXML * dialog)
{
/* Updating options is handled by gconf notifies for each widget
This is here to avoid calling it N_OPTIONS times for each gconf
change.*/
enable_disable_restoring (dialog);
/* Updating options is handled by gconf notifies for each widget
This is here to avoid calling it N_OPTIONS times for each gconf
change. */
enable_disable_restoring (dialog);
}
void
xkb_options_register_gconf_listener (GladeXML * dialog)
{
gconf_client_notify_add (xkb_gconf_client,
GSWITCHIT_KBD_CONFIG_KEY_OPTIONS,
(GConfClientNotifyFunc)
xkb_options_update, dialog, NULL, NULL);
gconf_client_notify_add (xkb_gconf_client,
GKBD_KEYBOARD_CONFIG_KEY_OPTIONS,
(GConfClientNotifyFunc)
xkb_options_update, dialog, NULL, NULL);
}

View file

@ -28,12 +28,12 @@
#include <gnome.h>
#include <glade/glade.h>
#include "libgswitchit/gswitchit-config.h"
#include <libgnomekbd/gkbd-keyboard-config.h>
#include "capplet-util.h"
#include "gnome-keyboard-properties-xkb.h"
#include "libkbdraw/keyboard-drawing.h"
#include <libgnomekbd/gkbd-keyboard-drawing.h>
#ifdef HAVE_X11_EXTENSIONS_XKB_H
#include "X11/XKBlib.h"
@ -42,78 +42,92 @@
* Any ideas on architectural improvements are WELCOME
*/
extern gboolean xkl_xkb_config_native_prepare (XklEngine * engine,
const XklConfigRec * data,
XkbComponentNamesPtr component_names);
const XklConfigRec * data,
XkbComponentNamesPtr
component_names);
extern void xkl_xkb_config_native_cleanup (XklEngine * engine,
XkbComponentNamesPtr component_names);
XkbComponentNamesPtr
component_names);
/* */
#endif
static KeyboardDrawingGroupLevel groupsLevels[] = {{0,1},{0,3},{0,0},{0,2}};
static KeyboardDrawingGroupLevel * pGroupsLevels[] = {
groupsLevels, groupsLevels+1, groupsLevels+2, groupsLevels+3 };
static GkbdKeyboardDrawingGroupLevel groupsLevels[] =
{ {0, 1}, {0, 3}, {0, 0}, {0, 2} };
static GkbdKeyboardDrawingGroupLevel *pGroupsLevels[] = {
groupsLevels, groupsLevels + 1, groupsLevels + 2, groupsLevels + 3
};
GtkWidget*
GtkWidget *
xkb_layout_preview_create_widget (GladeXML * chooserDialog)
{
GtkWidget *kbdraw = keyboard_drawing_new ();
keyboard_drawing_set_groups_levels (KEYBOARD_DRAWING (kbdraw), pGroupsLevels);
return kbdraw;
GtkWidget *kbdraw = gkbd_keyboard_drawing_new ();
gkbd_keyboard_drawing_set_groups_levels (GKBD_KEYBOARD_DRAWING
(kbdraw), pGroupsLevels);
return kbdraw;
}
void
xkb_layout_preview_update (GladeXML * chooser_dialog)
{
#ifdef HAVE_X11_EXTENSIONS_XKB_H
GtkWidget *chooser = CWID ( "xkb_layout_chooser");
GtkWidget *available_layouts_tree = CWID ("xkb_layouts_available");
GtkTreeSelection *selection =
gtk_tree_view_get_selection (GTK_TREE_VIEW (available_layouts_tree));
GtkTreeIter selected_iter;
GtkTreeModel *model;
GtkWidget *kbdraw = GTK_WIDGET (g_object_get_data (G_OBJECT (chooser), "kbdraw"));
if (kbdraw != NULL &&
gtk_tree_selection_get_selected (selection, &model, &selected_iter))
{
gchar *id;
XklConfigRec *data;
char **p, *layout, *variant;
XkbComponentNamesRec component_names;
GtkWidget *chooser = CWID ("xkb_layout_chooser");
GtkWidget *available_layouts_tree = CWID ("xkb_layouts_available");
GtkTreeSelection *selection =
gtk_tree_view_get_selection (GTK_TREE_VIEW
(available_layouts_tree));
GtkTreeIter selected_iter;
GtkTreeModel *model;
GtkWidget *kbdraw =
GTK_WIDGET (g_object_get_data (G_OBJECT (chooser), "kbdraw"));
if (kbdraw != NULL
&& gtk_tree_selection_get_selected (selection, &model,
&selected_iter)) {
gchar *id;
XklConfigRec *data;
char **p, *layout, *variant;
XkbComponentNamesRec component_names;
gtk_tree_model_get (model, &selected_iter, AVAIL_LAYOUT_TREE_COL_ID, &id, -1);
data = xkl_config_rec_new ();
if (xkl_config_rec_get_from_server (data, engine))
{
if( ( p = data->layouts ) != NULL )
g_strfreev(data->layouts);
gtk_tree_model_get (model, &selected_iter,
AVAIL_LAYOUT_TREE_COL_ID, &id, -1);
data = xkl_config_rec_new ();
if (xkl_config_rec_get_from_server (data, engine)) {
if ((p = data->layouts) != NULL)
g_strfreev (data->layouts);
if( ( p = data->variants ) != NULL )
g_strfreev(data->variants);
data->layouts = g_new0 (char*, 2);
data->variants = g_new0 (char*, 2);
if (gswitchit_kbd_config_split_items (id, &layout, &variant)
&& variant != NULL)
{
data->layouts[0] = (layout == NULL) ? NULL : g_strdup (layout);
data->variants[0] = (variant == NULL) ? NULL : g_strdup (variant);
} else
{
data->layouts[0] = (id == NULL) ? NULL : g_strdup (id);
data->variants[0] = NULL;
}
if ((p = data->variants) != NULL)
g_strfreev (data->variants);
if (xkl_xkb_config_native_prepare (engine, data, &component_names))
{
keyboard_drawing_set_keyboard (KEYBOARD_DRAWING (kbdraw), &component_names);
data->layouts = g_new0 (char *, 2);
data->variants = g_new0 (char *, 2);
if (gkbd_keyboard_config_split_items
(id, &layout, &variant)
&& variant != NULL) {
data->layouts[0] =
(layout ==
NULL) ? NULL : g_strdup (layout);
data->variants[0] =
(variant ==
NULL) ? NULL : g_strdup (variant);
} else {
data->layouts[0] =
(id == NULL) ? NULL : g_strdup (id);
data->variants[0] = NULL;
}
xkl_xkb_config_native_cleanup (engine, &component_names);
}
}
g_object_unref (G_OBJECT (data));
}
if (xkl_xkb_config_native_prepare
(engine, data, &component_names)) {
gkbd_keyboard_drawing_set_keyboard
(GKBD_KEYBOARD_DRAWING (kbdraw),
&component_names);
xkl_xkb_config_native_cleanup (engine,
&component_names);
}
}
g_object_unref (G_OBJECT (data));
}
#endif
}