From 885acff46a85399adc9170016d1b0789f633d2ce Mon Sep 17 00:00:00 2001 From: "Sergey V. Udaltsov" Date: Sun, 25 Jul 2004 23:28:35 +0000 Subject: [PATCH] first round of working model chooser - not complete yet --- capplets/keyboard/Makefile.am | 1 + .../keyboard/gnome-keyboard-properties-xkb.c | 121 ++--------- .../keyboard/gnome-keyboard-properties-xkb.h | 2 + .../gnome-keyboard-properties-xkbmc.c | 127 ++++++++++++ .../keyboard/gnome-keyboard-properties.glade | 191 +++++++++++++++++- 5 files changed, 331 insertions(+), 111 deletions(-) create mode 100644 capplets/keyboard/gnome-keyboard-properties-xkbmc.c diff --git a/capplets/keyboard/Makefile.am b/capplets/keyboard/Makefile.am index f7647fc29..917e56c4b 100644 --- a/capplets/keyboard/Makefile.am +++ b/capplets/keyboard/Makefile.am @@ -2,6 +2,7 @@ bin_PROGRAMS = gnome-keyboard-properties gnome_keyboard_properties_SOURCES = gnome-keyboard-properties.c \ gnome-keyboard-properties-xkb.c \ + gnome-keyboard-properties-xkbmc.c \ gnome-keyboard-properties-xkblt.c \ gnome-keyboard-properties-xkbot.c \ gnome-keyboard-properties-xkbpv.c \ diff --git a/capplets/keyboard/gnome-keyboard-properties-xkb.c b/capplets/keyboard/gnome-keyboard-properties-xkb.c index 792cdf0cc..401a70686 100644 --- a/capplets/keyboard/gnome-keyboard-properties-xkb.c +++ b/capplets/keyboard/gnome-keyboard-properties-xkb.c @@ -40,6 +40,8 @@ #include "gnome-keyboard-properties-xkb.h" +#define CWID(s) glade_xml_get_widget (chooserDialog, s) + static GSwitchItXkbConfig initialConfig; char * @@ -50,67 +52,22 @@ xci_desc_to_utf8 (XklConfigItem * ci) g_locale_to_utf8 (sd, -1, NULL, NULL, NULL); } -static GConfValue * -model_from_widget (GConfPropertyEditor * peditor, GConfValue * value) -{ - GConfValue *new_value = gconf_value_new (GCONF_VALUE_STRING); - const char *rvs = ""; - if (value->type == GCONF_VALUE_INT) - { - GtkWidget *omenu = - GTK_WIDGET (gconf_property_editor_get_ui_control (peditor)); - const int ivalue = gconf_value_get_int (value); - GtkWidget *menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (omenu)); - GList *items = GTK_MENU_SHELL (menu)->children; - while (items != NULL) - { - GtkWidget *item = GTK_WIDGET (items->data); - const int itemNo = - GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "itemNo")); - if (itemNo == ivalue) - { - rvs = (const char *) - g_object_get_data (G_OBJECT (item), "itemId"); - break; - } - items = items->next; - } - } - gconf_value_set_string (new_value, rvs); - return new_value; -} - static GConfValue * model_to_widget (GConfPropertyEditor * peditor, GConfValue * value) { GConfValue *new_value; - int rvi = -1; - new_value = gconf_value_new (GCONF_VALUE_INT); + new_value = gconf_value_new (GCONF_VALUE_STRING); if (value->type == GCONF_VALUE_STRING) { - GtkWidget *omenu = - GTK_WIDGET (gconf_property_editor_get_ui_control (peditor)); - const char *svalue = gconf_value_get_string (value); - GtkWidget *menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (omenu)); - GList *items = GTK_MENU_SHELL (menu)->children; - while (items != NULL) - { - GtkWidget *item = GTK_WIDGET (items->data); - const char *itemId = (const char *) - g_object_get_data (G_OBJECT (item), "itemId"); - if (!g_strcasecmp (itemId, svalue)) - { - rvi = - GPOINTER_TO_INT (g_object_get_data - (G_OBJECT (item), "itemNo")); - break; - } - items = items->next; - } + XklConfigItem ci; + g_snprintf( ci.name, sizeof (ci.name), "%s", gconf_value_get_string( value ) ); + if ( XklConfigFindModel( &ci ) ) + gconf_value_set_string( new_value, ci.description ); + else + gconf_value_set_string( new_value, _("Unknown") ); } - gconf_value_set_int (new_value, rvi); return new_value; } @@ -124,54 +81,6 @@ cleanup_xkb_tabs (GladeXML * dialog) XklTerm (); } -static void -add_model_to_option_menu (const XklConfigItemPtr configItem, GtkWidget * menu) -{ - GList *existingItemNode = GTK_MENU_SHELL (menu)->children; - char *utfModelName = xci_desc_to_utf8 (configItem); - GtkWidget *menuItem = gtk_menu_item_new_with_label (utfModelName); - int position = 0; - g_object_set_data_full (G_OBJECT (menuItem), "itemId", - g_strdup (configItem->name), - (GDestroyNotify) g_free); - for (; existingItemNode != NULL; - position++, existingItemNode = existingItemNode->next) - { - GtkWidget *menuItem = GTK_WIDGET (existingItemNode->data); - GtkWidget *lbl = GTK_BIN (menuItem)->child; - const char *txt = gtk_label_get_text (GTK_LABEL (lbl)); - if (g_utf8_collate (txt, utfModelName) > 0) - break; - } - g_free (utfModelName); - gtk_menu_shell_insert (GTK_MENU_SHELL (menu), - GTK_WIDGET (menuItem), position); -} - -static void -fill_models_option_menu (GladeXML * dialog) -{ - GtkWidget *menu = gtk_menu_new (); - int itemCounter = 0; - GList *items; - XklConfigEnumModels ((ConfigItemProcessFunc) - add_model_to_option_menu, menu); - - items = GTK_MENU_SHELL (menu)->children; - while (items != NULL) - { - GtkWidget *menuItem = GTK_WIDGET (items->data); - g_object_set_data (G_OBJECT (menuItem), "itemNo", - GINT_TO_POINTER (itemCounter++)); - items = items->next; - } - - gtk_option_menu_set_menu (GTK_OPTION_MENU (WID ("xkb_models")), - GTK_WIDGET (menu)); - gtk_widget_show_all (menu); -} - - static void reset_to_defaults (GtkWidget * button, GladeXML * dialog) { @@ -197,13 +106,12 @@ setup_xkb_tabs (GladeXML * dialog, GConfChangeSet * changeset) XklConfigInit (); XklConfigLoadRegistry (); - fill_models_option_menu (dialog); +// fill_models_option_menu (dialog); - gconf_peditor_new_select_menu + gconf_peditor_new_string (changeset, (gchar *) GSWITCHIT_CONFIG_XKB_KEY_MODEL, - WID ("xkb_models"), - "conv-to-widget-cb", model_to_widget, - "conv-from-widget-cb", model_from_widget, NULL); + WID ("xkb_model"), + "conv-to-widget-cb", model_to_widget, NULL); fill_available_layouts_tree (dialog); fill_available_options_tree (dialog); @@ -217,6 +125,9 @@ setup_xkb_tabs (GladeXML * dialog, GConfChangeSet * changeset) 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); + register_layouts_gconf_listener (dialog); register_options_gconf_listener (dialog); diff --git a/capplets/keyboard/gnome-keyboard-properties-xkb.h b/capplets/keyboard/gnome-keyboard-properties-xkb.h index b6230309f..e1368b096 100644 --- a/capplets/keyboard/gnome-keyboard-properties-xkb.h +++ b/capplets/keyboard/gnome-keyboard-properties-xkb.h @@ -60,5 +60,7 @@ extern void enable_disable_restoring(GladeXML * dialog); extern void init_preview(GladeXML * dialog); +extern void choose_model(GladeXML * dialog); + G_END_DECLS #endif /* __GNOME_KEYBOARD_PROPERTY_XKB_H */ diff --git a/capplets/keyboard/gnome-keyboard-properties-xkbmc.c b/capplets/keyboard/gnome-keyboard-properties-xkbmc.c new file mode 100644 index 000000000..8cfb70c4e --- /dev/null +++ b/capplets/keyboard/gnome-keyboard-properties-xkbmc.c @@ -0,0 +1,127 @@ +/* -*- mode: c; style: linux -*- */ + +/* gnome-keyboard-properties-xkb.c + * Copyright (C) 2003 Sergey V. Oudaltsov + * + * Written by: Sergey V. Oudaltsov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include + +#include "libgswitchit/gswitchit_xkb_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 "gnome-keyboard-properties-xkb.h" + +#define CWID(s) glade_xml_get_widget (chooserDialog, s) + +static void +add_model_to_list (const XklConfigItemPtr configItem, GtkListStore * listStore) +{ + GtkTreeIter iter; + char *utfModelName = xci_desc_to_utf8 (configItem); + gtk_list_store_append( listStore, &iter ); + gtk_list_store_set( listStore, &iter, + 0, utfModelName, + 1, configItem->name, -1 ); + g_free (utfModelName); +} + +static void +xkb_model_chooser_change_sel (GtkTreeSelection* selection, + GladeXML* chooserDialog) +{ + 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 * chooserDialog) +{ + GtkWidget* modelsList = CWID( "models_list" ); + GtkCellRenderer* renderer = gtk_cell_renderer_text_new (); + GtkTreeViewColumn* descriptionCol = gtk_tree_view_column_new_with_attributes ( _("Model"), + renderer, + "text", 0, + NULL); + GtkListStore *listStore = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); + + gtk_tree_view_column_set_visible (descriptionCol, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (modelsList), descriptionCol); + + XklConfigEnumModels ((ConfigItemProcessFunc) + add_model_to_list, listStore); + + gtk_tree_view_set_model (GTK_TREE_VIEW (modelsList), GTK_TREE_MODEL (listStore) ); + + g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (modelsList))), + "changed", + G_CALLBACK (xkb_model_chooser_change_sel), + chooserDialog); +} + +static void +xkb_model_chooser_response (GtkDialog *dialog, + gint response, + GladeXML *chooserDialog) +{ + if (response == GTK_RESPONSE_OK) + { + GtkWidget* modelsList = CWID( "models_list" ); + GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (modelsList)); + GtkTreeIter iter; + GtkTreeModel* listStore = NULL; + if (gtk_tree_selection_get_selected (selection, &listStore, &iter)) + { + gchar* modelName = NULL; + gtk_tree_model_get (listStore, &iter, + 1, &modelName, -1); + + gconf_client_set_string (gconf_client_get_default (), + GSWITCHIT_CONFIG_XKB_KEY_MODEL, + modelName, NULL); + g_free(modelName); + } + } +} + +void +choose_model(GladeXML * dialog) +{ + GladeXML* chooserDialog = 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"))); + fill_models_list (chooserDialog); + g_signal_connect (G_OBJECT (chooser), + "response", G_CALLBACK (xkb_model_chooser_response), chooserDialog); + gtk_dialog_run (GTK_DIALOG (chooser)); + gtk_widget_destroy (chooser); +} diff --git a/capplets/keyboard/gnome-keyboard-properties.glade b/capplets/keyboard/gnome-keyboard-properties.glade index bf432a720..a821e2722 100644 --- a/capplets/keyboard/gnome-keyboard-properties.glade +++ b/capplets/keyboard/gnome-keyboard-properties.glade @@ -12,6 +12,11 @@ False True False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST False @@ -33,6 +38,7 @@ gtk-help True GTK_RELIEF_NORMAL + True -11 @@ -43,6 +49,7 @@ True True GTK_RELIEF_NORMAL + True 0 @@ -53,6 +60,10 @@ 0.5 0 0 + 0 + 0 + 0 + 0 @@ -114,6 +125,7 @@ gtk-close True GTK_RELIEF_NORMAL + True -7 @@ -211,6 +223,7 @@ Key presses _repeat when key is held down True GTK_RELIEF_NORMAL + True False False True @@ -539,6 +552,7 @@ Cursor _blinks in text boxes and fields True GTK_RELIEF_NORMAL + True False False True @@ -790,7 +804,7 @@ 0.5 0 0 - xkb_models + xkb_model 0 @@ -800,15 +814,20 @@ - + True - True - -1 + False + True + 0 + Microsoft Natural Keyboard + True + * + False 0 - False - False + True + True @@ -817,6 +836,7 @@ True True GTK_RELIEF_NORMAL + True @@ -825,6 +845,10 @@ 0.5 0 0 + 0 + 0 + 0 + 0 @@ -881,6 +905,45 @@ GTK_PACK_END + + + + True + True + ... + True + GTK_RELIEF_NORMAL + True + + + 0 + False + False + + + + + + True + 0 + 0.5 + 1 + 1 + 0 + 0 + 6 + 6 + + + + + + + 0 + True + True + + 0 @@ -991,6 +1054,7 @@ gtk-add True GTK_RELIEF_NORMAL + True 0 @@ -1006,6 +1070,7 @@ gtk-remove True GTK_RELIEF_NORMAL + True 0 @@ -1021,6 +1086,7 @@ gtk-go-up True GTK_RELIEF_NORMAL + True 0 @@ -1036,6 +1102,7 @@ gtk-go-down True GTK_RELIEF_NORMAL + True 0 @@ -1258,6 +1325,7 @@ gtk-add True GTK_RELIEF_NORMAL + True 0 @@ -1273,6 +1341,7 @@ gtk-remove True GTK_RELIEF_NORMAL + True 0 @@ -1405,6 +1474,7 @@ <b>_Lock screen to enforce typing break</b> True GTK_RELIEF_NORMAL + True False False True @@ -1648,6 +1718,7 @@ All_ow postponing of breaks True GTK_RELIEF_NORMAL + True False False True @@ -1720,6 +1791,10 @@ 0.5 1 1 + 0 + 0 + 0 + 0 @@ -1760,4 +1835,108 @@ + + True + Choose a keyboard model + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + False + 6 + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + + + + + 0 + True + True + + + + + 0 + True + True + + + + + +