[gnome-control-center] New search-based layout addition
- From: Sergey V. Udaltsov <svu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] New search-based layout addition
- Date: Fri, 4 Feb 2011 19:57:21 +0000 (UTC)
commit fe04b358a420d8e03951473c98ac0740613eb8d4
Author: Sergey V. Udaltsov <svu gnome org>
Date: Fri Feb 4 19:55:38 2011 +0000
New search-based layout addition
Bug #640772, see mockup
Requires new version of libgnomekbd and libxklavier
panels/region/gnome-region-panel-layout-chooser.ui | 260 ++-------
panels/region/gnome-region-panel-xkb.c | 9 +-
panels/region/gnome-region-panel-xkb.h | 2 +-
panels/region/gnome-region-panel-xkblt.c | 9 +-
panels/region/gnome-region-panel-xkbltadd.c | 587 ++++++--------------
5 files changed, 221 insertions(+), 646 deletions(-)
---
diff --git a/panels/region/gnome-region-panel-layout-chooser.ui b/panels/region/gnome-region-panel-layout-chooser.ui
index 1516364..656386b 100644
--- a/panels/region/gnome-region-panel-layout-chooser.ui
+++ b/panels/region/gnome-region-panel-layout-chooser.ui
@@ -2,6 +2,18 @@
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
+ <object class="GtkListStore" id="filtered_layout_list_model">
+ <columns>
+ <!-- column-name sort_order -->
+ <column type="gchararray"/>
+ <!-- column-name visible -->
+ <column type="gchararray"/>
+ <!-- column-name xkb_id -->
+ <column type="gchararray"/>
+ <!-- column-name real_id -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkDialog" id="xkb_layout_chooser">
<property name="visible">True</property>
<property name="border_width">5</property>
@@ -19,159 +31,35 @@
<property name="border_width">5</property>
<property name="spacing">6</property>
<child>
- <object class="GtkNotebook" id="choosers_nb">
+ <object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="spacing">6</property>
<child>
- <object class="GtkAlignment" id="alignment1">
+ <object class="GtkLabel" id="label1">
<property name="visible">True</property>
- <property name="top_padding">3</property>
- <property name="bottom_padding">3</property>
- <property name="left_padding">3</property>
- <property name="right_padding">6</property>
- <child>
- <object class="GtkTable" id="table1">
- <property name="visible">True</property>
- <property name="n_rows">2</property>
- <property name="n_columns">2</property>
- <property name="column_spacing">12</property>
- <property name="row_spacing">6</property>
- <child>
- <object class="GtkComboBox" id="xkb_country_variants_available">
- <property name="visible">True</property>
- <property name="model">countryVariants</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <object class="GtkComboBox" id="xkb_countries_available">
- <property name="visible">True</property>
- <property name="model">countries</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label4">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Variants:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">xkb_country_variants_available</property>
- </object>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label3">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Country:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">xkb_countries_available</property>
- </object>
- <packing>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child type="tab">
- <object class="GtkLabel" id="label22">
- <property name="visible">True</property>
- <property name="label" translatable="yes">By _country</property>
- <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Select an input source to add</property>
</object>
<packing>
- <property name="tab_fill">False</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkAlignment" id="alignment2">
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
- <property name="top_padding">3</property>
- <property name="bottom_padding">3</property>
- <property name="left_padding">3</property>
- <property name="right_padding">3</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">never</property>
+ <property name="vscrollbar_policy">automatic</property>
<child>
- <object class="GtkTable" id="table3">
+ <object class="GtkTreeView" id="xkb_filtered_layouts_list">
<property name="visible">True</property>
- <property name="n_rows">2</property>
- <property name="n_columns">2</property>
- <property name="column_spacing">12</property>
- <property name="row_spacing">6</property>
- <child>
- <object class="GtkComboBox" id="xkb_language_variants_available">
- <property name="visible">True</property>
- <property name="model">languageVariants</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <object class="GtkComboBox" id="xkb_languages_available">
- <property name="visible">True</property>
- <property name="model">languages</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label13">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Variants:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">xkb_country_variants_available</property>
- </object>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label12">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Language:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">xkb_countries_available</property>
- </object>
- <packing>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
+ <property name="can_focus">True</property>
+ <property name="model">filtered_layout_list_model</property>
+ <property name="headers_visible">False</property>
+ <property name="search_column">0</property>
+ <property name="tooltip_column">0</property>
</object>
</child>
</object>
@@ -179,66 +67,20 @@
<property name="position">1</property>
</packing>
</child>
- <child type="tab">
- <object class="GtkLabel" id="label9">
- <property name="visible">True</property>
- <property name="label" translatable="yes">By _language</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="position">1</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
</object>
<packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkVBox" id="vboxPreview">
+ <object class="GtkEntry" id="xkb_layout_filter">
<property name="visible">True</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkHBox" id="hbox1">
- <property name="visible">True</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkLabel" id="label10">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Preview:</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkFrame" id="previewFrame">
- <property name="visible">True</property>
- <property name="label_xalign">0</property>
- <property name="shadow_type">in</property>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">â?¢</property>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
@@ -252,13 +94,11 @@
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="btnPrint">
- <property name="label">gtk-print</property>
+ <object class="GtkButton" id="btnPreview">
+ <property name="label" translatable="yes">Preview</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">False</property>
- <property name="use_stock">True</property>
+ <property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
@@ -268,8 +108,8 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="cancelbutton2">
- <property name="label">gtk-cancel</property>
+ <object class="GtkButton" id="btnOk">
+ <property name="label">gtk-add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
@@ -279,12 +119,13 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">1</property>
+ <property name="pack_type">end</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
- <object class="GtkButton" id="btnOk1">
- <property name="label">gtk-add</property>
+ <object class="GtkButton" id="btnCancel">
+ <property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
@@ -294,7 +135,8 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">2</property>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -307,13 +149,9 @@
</object>
</child>
<action-widgets>
- <action-widget response="1">btnPrint</action-widget>
- <action-widget response="-6">cancelbutton2</action-widget>
- <action-widget response="-5">btnOk1</action-widget>
+ <action-widget response="1">btnPreview</action-widget>
+ <action-widget response="-5">btnOk</action-widget>
+ <action-widget response="-6">btnCancel</action-widget>
</action-widgets>
</object>
- <object class="GtkListStore" id="countries"/>
- <object class="GtkListStore" id="countryVariants"/>
- <object class="GtkListStore" id="languages"/>
- <object class="GtkListStore" id="languageVariants"/>
</interface>
diff --git a/panels/region/gnome-region-panel-xkb.c b/panels/region/gnome-region-panel-xkb.c
index 7ddb7a8..352e05f 100644
--- a/panels/region/gnome-region-panel-xkb.c
+++ b/panels/region/gnome-region-panel-xkb.c
@@ -41,10 +41,13 @@ GSettings *xkb_keyboard_settings;
GSettings *xkb_desktop_settings;
char *
-xci_desc_to_utf8 (XklConfigItem * ci)
+xci_desc_to_utf8 (const XklConfigItem * ci)
{
- char *sd = g_strstrip (ci->description);
- return sd[0] == 0 ? g_strdup (ci->name) : g_strdup (sd);
+ gchar *dd = g_strdup (ci->description);
+ gchar *sd = g_strstrip (dd);
+ gchar *rv = g_strdup (sd[0] == 0 ? ci->name : sd);
+ g_free (dd);
+ return rv;
}
static void
diff --git a/panels/region/gnome-region-panel-xkb.h b/panels/region/gnome-region-panel-xkb.h
index e4201a0..11f0be5 100644
--- a/panels/region/gnome-region-panel-xkb.h
+++ b/panels/region/gnome-region-panel-xkb.h
@@ -52,7 +52,7 @@ extern void xkb_options_load_options (GtkBuilder * dialog);
extern void xkb_options_popup_dialog (GtkBuilder * dialog);
-extern char *xci_desc_to_utf8 (XklConfigItem * ci);
+extern char *xci_desc_to_utf8 (const XklConfigItem * ci);
extern gchar *xkb_layout_description_utf8 (const gchar * visible);
diff --git a/panels/region/gnome-region-panel-xkblt.c b/panels/region/gnome-region-panel-xkblt.c
index 49fac8b..a58fafc 100644
--- a/panels/region/gnome-region-panel-xkblt.c
+++ b/panels/region/gnome-region-panel-xkblt.c
@@ -335,16 +335,11 @@ show_selected_layout (GtkWidget * button, GtkBuilder * dialog)
gint idx = find_selected_layout_idx (dialog);
if (idx != -1) {
- gchar **layouts_list = xkb_layouts_get_selected_list ();
- const gchar *id = layouts_list[idx];
- char *descr = xkb_layout_description_utf8 (id);
GtkWidget *parent = WID ("region_notebook");
- GtkWidget *popup =
- gkbd_keyboard_drawing_new_dialog (idx, descr);
+ GtkWidget *popup = gkbd_keyboard_drawing_dialog_new ();
+ gkbd_keyboard_drawing_dialog_set_group (popup, idx);
gtk_window_set_transient_for (GTK_WINDOW (popup),
GTK_WINDOW (gtk_widget_get_toplevel (parent)));
- g_strfreev (layouts_list);
- g_free (descr);
}
}
diff --git a/panels/region/gnome-region-panel-xkbltadd.c b/panels/region/gnome-region-panel-xkbltadd.c
index 07d6ad5..cc0417e 100644
--- a/panels/region/gnome-region-panel-xkbltadd.c
+++ b/panels/region/gnome-region-panel-xkbltadd.c
@@ -33,58 +33,105 @@
enum {
COMBO_BOX_MODEL_COL_SORT,
COMBO_BOX_MODEL_COL_VISIBLE,
- COMBO_BOX_MODEL_COL_XKB_ID,
- COMBO_BOX_MODEL_COL_REAL_ID
+ COMBO_BOX_MODEL_COL_XKB_ID
};
-typedef void (*LayoutIterFunc) (XklConfigRegistry * config,
- ConfigItemProcessFunc func, gpointer data);
-
-typedef struct {
- GtkListStore *list_store;
- const gchar *lang_id;
-} AddVariantData;
+#define RESPONSE_PREVIEW 1
static void
-xkb_layout_chooser_available_layouts_fill (GtkBuilder * chooser_dialog,
- const gchar cblid[],
- const gchar cbvid[],
- LayoutIterFunc layout_iterator,
- ConfigItemProcessFunc
- layout_handler,
- GCallback combo_changed_notify);
+xkl_layout_chooser_add_default_switcher_if_necessary (gchar **
+ layouts_list)
+{
+ gchar **options_list = xkb_options_get_selected_list ();
+ gboolean was_appended;
-static void
-xkb_layout_chooser_available_language_variants_fill (GtkBuilder *
- chooser_dialog);
+ options_list =
+ gkbd_keyboard_config_add_default_switch_option_if_necessary
+ (layouts_list, options_list, &was_appended);
+ if (was_appended)
+ xkb_options_set_selected_list (options_list);
+ g_strfreev (options_list);
+}
static void
-xkb_layout_chooser_available_country_variants_fill (GtkBuilder *
- chooser_dialog);
+xkb_layout_chooser_response (GtkDialog * dialog,
+ gint response, GtkBuilder * chooser_dialog)
+{
+ switch (response)
+ case GTK_RESPONSE_OK:{
+ gchar *selected_id = (gchar *)
+ xkb_layout_chooser_get_selected_id
+ (chooser_dialog);
+
+ if (selected_id != NULL) {
+ gchar **layouts_list =
+ xkb_layouts_get_selected_list ();
+
+ layouts_list =
+ gkbd_strv_append (layouts_list,
+ g_strdup
+ (selected_id));
+
+ xkb_layouts_set_selected_list
+ (layouts_list);
+
+ xkl_layout_chooser_add_default_switcher_if_necessary
+ (layouts_list);
+
+ g_strfreev (layouts_list);
+ }
+ break;
+ case RESPONSE_PREVIEW:{
+ gchar *selected_id = (gchar *)
+ xkb_layout_chooser_get_selected_id
+ (chooser_dialog);
+
+ if (selected_id != NULL) {
+ GtkWidget *dlg =
+ gkbd_keyboard_drawing_dialog_new
+ ();
+ gkbd_keyboard_drawing_dialog_set_layout
+ (dlg, config_registry, selected_id);
+ gtk_window_set_transient_for
+ (GTK_WINDOW (dlg),
+ GTK_WINDOW (CWID
+ ("xkb_layout_chooser")));
+ gtk_widget_show_all (dlg);
+ }
+ }
+
+ return;
+ }
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
static void
- xkb_layout_chooser_add_variant_to_available_country_variants
- (XklConfigRegistry * config_registry,
- XklConfigItem * parent_config_item, XklConfigItem * config_item,
- AddVariantData * data) {
- gchar *utf_variant_name = config_item ?
- xkb_layout_description_utf8 (gkbd_keyboard_config_merge_items
- (parent_config_item->name,
- config_item->name)) :
- xci_desc_to_utf8 (parent_config_item);
+xkl_layout_add_to_filtered_list (XklConfigRegistry * config,
+ const XklConfigItem * item,
+ const XklConfigItem * subitem,
+ GtkBuilder * chooser_dialog)
+{
+ GtkListStore *list_store =
+ GTK_LIST_STORE (gtk_builder_get_object (chooser_dialog,
+ "filtered_layout_list_model"));
GtkTreeIter iter;
+ gchar *utf_variant_name =
+ subitem ?
+ xkb_layout_description_utf8 (gkbd_keyboard_config_merge_items
+ (item->name,
+ subitem->name)) :
+ xci_desc_to_utf8 (item);
const gchar *xkb_id =
- config_item ?
- gkbd_keyboard_config_merge_items (parent_config_item->name,
- config_item->name) :
- parent_config_item->name;
+ subitem ? gkbd_keyboard_config_merge_items (item->name,
+ subitem->name) :
+ item->name;
- if (config_item && g_object_get_data
- (G_OBJECT (config_item), XCI_PROP_EXTRA_ITEM)) {
+ if (subitem
+ && g_object_get_data (G_OBJECT (subitem),
+ XCI_PROP_EXTRA_ITEM)) {
gchar *buf =
g_strdup_printf ("<i>%s</i>", utf_variant_name);
- gtk_list_store_insert_with_values (data->list_store, &iter,
- -1,
+ gtk_list_store_insert_with_values (list_store, &iter, -1,
COMBO_BOX_MODEL_COL_SORT,
utf_variant_name,
COMBO_BOX_MODEL_COL_VISIBLE,
@@ -93,7 +140,7 @@ static void
xkb_id, -1);
g_free (buf);
} else
- gtk_list_store_insert_with_values (data->list_store, &iter,
+ gtk_list_store_insert_with_values (list_store, &iter,
-1,
COMBO_BOX_MODEL_COL_SORT,
utf_variant_name,
@@ -105,425 +152,117 @@ static void
}
static void
- xkb_layout_chooser_add_variant_to_available_language_variants
- (XklConfigRegistry * config_registry,
- XklConfigItem * parent_config_item, XklConfigItem * config_item,
- AddVariantData * data) {
- xkb_layout_chooser_add_variant_to_available_country_variants
- (config_registry, parent_config_item, config_item, data);
-}
-
-static void
-xkb_layout_chooser_add_language_to_available_languages (XklConfigRegistry *
- config_registry,
- XklConfigItem *
- config_item,
- GtkListStore *
- list_store)
-{
- gtk_list_store_insert_with_values (list_store, NULL, -1,
- COMBO_BOX_MODEL_COL_SORT,
- config_item->description,
- COMBO_BOX_MODEL_COL_VISIBLE,
- config_item->description,
- COMBO_BOX_MODEL_COL_REAL_ID,
- config_item->name, -1);
-}
-
-static void
-xkb_layout_chooser_add_country_to_available_countries (XklConfigRegistry *
- config_registry,
- XklConfigItem *
- config_item,
- GtkListStore *
- list_store)
-{
- gtk_list_store_insert_with_values (list_store, NULL, -1,
- COMBO_BOX_MODEL_COL_SORT,
- config_item->description,
- COMBO_BOX_MODEL_COL_VISIBLE,
- config_item->description,
- COMBO_BOX_MODEL_COL_REAL_ID,
- config_item->name, -1);
-}
-
-static void
-xkb_layout_chooser_enable_disable_buttons (GtkBuilder * chooser_dialog)
-{
- GtkWidget *cbv =
- CWID (gtk_notebook_get_current_page
- (GTK_NOTEBOOK (CWID ("choosers_nb"))) ?
- "xkb_language_variants_available" :
- "xkb_country_variants_available");
- GtkTreeIter viter;
- gboolean enable_ok =
- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (cbv),
- &viter);
-
- gtk_dialog_set_response_sensitive (GTK_DIALOG
- (CWID
- ("xkb_layout_chooser")),
- GTK_RESPONSE_OK, enable_ok);
- gtk_widget_set_sensitive (CWID ("btnPrint"), enable_ok);
-}
-
-static void
-xkb_layout_chooser_available_variant_changed (GtkBuilder * chooser_dialog)
-{
- xkb_layout_preview_update (chooser_dialog);
- xkb_layout_chooser_enable_disable_buttons (chooser_dialog);
-}
-
-static void
-xkb_layout_chooser_available_language_changed (GtkBuilder * chooser_dialog)
-{
- xkb_layout_chooser_available_language_variants_fill
- (chooser_dialog);
- xkb_layout_chooser_available_variant_changed (chooser_dialog);
-}
-
-static void
-xkb_layout_chooser_available_country_changed (GtkBuilder * chooser_dialog)
-{
- xkb_layout_chooser_available_country_variants_fill
- (chooser_dialog);
- xkb_layout_chooser_available_variant_changed (chooser_dialog);
-}
-
-static void
-xkb_layout_chooser_page_changed (GtkWidget * notebook, GtkWidget * page,
- gint page_num,
- GtkBuilder * chooser_dialog)
-{
- xkb_layout_chooser_available_variant_changed (chooser_dialog);
-}
-
-static void
-xkb_layout_chooser_available_language_variants_fill (GtkBuilder *
- chooser_dialog)
-{
- GtkWidget *cbl = CWID ("xkb_languages_available");
- GtkWidget *cbv = CWID ("xkb_language_variants_available");
- GtkListStore *list_store;
- GtkTreeIter liter;
-
- list_store = gtk_list_store_new
- (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_STRING);
-
- /* Turn on sorting after filling the store, since that's faster */
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE
- (list_store),
- COMBO_BOX_MODEL_COL_SORT,
- GTK_SORT_ASCENDING);
-
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (cbl), &liter)) {
- GtkTreeModel *lm =
- gtk_combo_box_get_model (GTK_COMBO_BOX (cbl));
- gchar *lang_id;
- AddVariantData data = { list_store, 0 };
-
- /* Now the variants of the selected layout */
- gtk_tree_model_get (lm, &liter,
- COMBO_BOX_MODEL_COL_REAL_ID,
- &lang_id, -1);
- data.lang_id = lang_id;
-
- xkl_config_registry_foreach_language_variant
- (config_registry, lang_id, (TwoConfigItemsProcessFunc)
- xkb_layout_chooser_add_variant_to_available_language_variants,
- &data);
- g_free (lang_id);
- }
-
- gtk_combo_box_set_model (GTK_COMBO_BOX (cbv),
- GTK_TREE_MODEL (list_store));
- gtk_combo_box_set_active (GTK_COMBO_BOX (cbv), 0);
-}
-
-static void
-xkb_layout_chooser_available_country_variants_fill (GtkBuilder *
- chooser_dialog)
+xkb_layout_filter_changed (GtkBuilder * chooser_dialog)
{
- GtkWidget *cbl = CWID ("xkb_countries_available");
- GtkWidget *cbv = CWID ("xkb_country_variants_available");
- GtkListStore *list_store;
- GtkTreeIter liter;
-
- list_store = gtk_list_store_new
- (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_STRING);
-
- /* Turn on sorting after filling the store, since that's faster */
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE
- (list_store),
- COMBO_BOX_MODEL_COL_SORT,
- GTK_SORT_ASCENDING);
-
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (cbl), &liter)) {
- GtkTreeModel *lm =
- gtk_combo_box_get_model (GTK_COMBO_BOX (cbl));
- gchar *country_id;
- AddVariantData data = { list_store, 0 };
-
- /* Now the variants of the selected layout */
- gtk_tree_model_get (lm, &liter,
- COMBO_BOX_MODEL_COL_REAL_ID,
- &country_id, -1);
- xkl_config_registry_foreach_country_variant
- (config_registry, country_id,
- (TwoConfigItemsProcessFunc)
- xkb_layout_chooser_add_variant_to_available_country_variants,
- &data);
- g_free (country_id);
- }
-
- gtk_combo_box_set_model (GTK_COMBO_BOX (cbv),
- GTK_TREE_MODEL (list_store));
- gtk_combo_box_set_active (GTK_COMBO_BOX (cbv), 0);
+ GtkWidget *xkb_layout_filter = CWID ("xkb_layout_filter");
+ const gchar *pattern =
+ gtk_entry_get_text (GTK_ENTRY (xkb_layout_filter));
+ GtkListStore *model =
+ GTK_LIST_STORE (gtk_builder_get_object (chooser_dialog,
+ "filtered_layout_list_model"));
+
+ gtk_list_store_clear (model);
+ xkl_config_registry_search_by_pattern (config_registry, pattern,
+ (TwoConfigItemsProcessFunc)
+ (xkl_layout_add_to_filtered_list), chooser_dialog);
}
static void
-xkb_layout_chooser_available_layouts_fill (GtkBuilder *
- chooser_dialog,
- const gchar cblid[],
- const gchar cbvid[],
- LayoutIterFunc layout_iterator,
- ConfigItemProcessFunc
- layout_handler,
- GCallback combo_changed_notify)
+xkb_layout_chooser_selection_changed (GtkTreeSelection * selection,
+ GtkBuilder * chooser_dialog)
{
- GtkWidget *cbl = CWID (cblid);
- GtkWidget *cbev = CWID (cbvid);
- GtkCellRenderer *renderer;
- GtkListStore *list_store;
-
- list_store = gtk_list_store_new
- (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_STRING);
-
- gtk_combo_box_set_model (GTK_COMBO_BOX (cbl),
- GTK_TREE_MODEL (list_store));
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbl), renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbl),
- renderer, "markup",
- COMBO_BOX_MODEL_COL_VISIBLE, NULL);
-
- /* Turn on sorting after filling the model since that's faster */
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE
- (list_store),
- COMBO_BOX_MODEL_COL_SORT,
- GTK_SORT_ASCENDING);
-
- layout_iterator (config_registry, layout_handler, list_store);
-
- g_signal_connect_swapped (G_OBJECT (cbl), "changed",
- combo_changed_notify, chooser_dialog);
-
- /* Setup the variants combo */
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbev),
- renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbev),
- renderer, "markup",
- COMBO_BOX_MODEL_COL_VISIBLE, NULL);
-
- g_signal_connect_swapped (G_OBJECT (cbev), "changed",
- G_CALLBACK
- (xkb_layout_chooser_available_variant_changed),
- chooser_dialog);
-}
-
-static void
-xkl_layout_chooser_add_default_switcher_if_necessary (gchar **
- layouts_list)
-{
- gchar **options_list = xkb_options_get_selected_list ();
- gboolean was_appended;
-
- options_list =
- gkbd_keyboard_config_add_default_switch_option_if_necessary
- (layouts_list, options_list, &was_appended);
- if (was_appended)
- xkb_options_set_selected_list (options_list);
- g_strfreev (options_list);
-}
-
-static void
-xkb_layout_chooser_print (GtkBuilder * chooser_dialog)
-{
- GtkWidget *chooser = CWID ("xkb_layout_chooser");
- GtkWidget *kbdraw =
- GTK_WIDGET (g_object_get_data (G_OBJECT (chooser), "kbdraw"));
- const char *id =
- xkb_layout_chooser_get_selected_id (chooser_dialog);
- char *descr = xkb_layout_description_utf8 (id);
- gkbd_keyboard_drawing_print (GKBD_KEYBOARD_DRAWING
- (kbdraw),
- GTK_WINDOW (CWID
- ("xkb_layout_chooser")),
- descr);
- g_free (descr);
-}
-
-static void
-xkb_layout_chooser_response (GtkDialog * dialog,
- gint response, GtkBuilder * chooser_dialog)
-{
- GdkRectangle rect;
-
- if (response == GTK_RESPONSE_OK) {
- gchar *selected_id = (gchar *)
- xkb_layout_chooser_get_selected_id (chooser_dialog);
-
- if (selected_id != NULL) {
- gchar **layouts_list =
- xkb_layouts_get_selected_list ();
-
- layouts_list =
- gkbd_strv_append (layouts_list,
- g_strdup (selected_id));
-
- xkb_layouts_set_selected_list (layouts_list);
-
- xkl_layout_chooser_add_default_switcher_if_necessary
- (layouts_list);
-
- g_strfreev (layouts_list);
- }
- } else if (response == gtk_dialog_get_response_for_widget
- (dialog, CWID ("btnPrint"))) {
- xkb_layout_chooser_print (chooser_dialog);
- g_signal_stop_emission_by_name (dialog, "response");
- return;
- }
-
- gtk_window_get_position (GTK_WINDOW (dialog), &rect.x, &rect.y);
- gtk_window_get_size (GTK_WINDOW (dialog), &rect.width,
- &rect.height);
- gkbd_preview_save_position (&rect);
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ GList *selected_layouts =
+ gtk_tree_selection_get_selected_rows (selection, NULL);
+ GtkWidget *add_button = CWID ("btnOk");
+ GtkWidget *preview_button = CWID ("btnPreview");
+ gboolean anything_selected = g_list_length (selected_layouts) == 1;
+ gtk_widget_set_sensitive (add_button, anything_selected);
+ gtk_widget_set_sensitive (preview_button, anything_selected);
}
void
xkb_layout_choose (GtkBuilder * dialog)
{
- GtkBuilder *chooser_dialog;
+ GtkBuilder *chooser_dialog = gtk_builder_new ();
+ GtkWidget *chooser, *xkb_filtered_layouts_list, *xkb_layout_filter;
+ GtkTreeViewColumn *visible_column;
+ GtkTreeSelection *selection;
- chooser_dialog = gtk_builder_new ();
gtk_builder_add_from_file (chooser_dialog, GNOMECC_UI_DIR
"/gnome-region-panel-layout-chooser.ui",
NULL);
- GtkWidget *chooser = CWID ("xkb_layout_chooser");
- GtkWidget *lang_chooser = CWID ("xkb_languages_available");
- GtkWidget *notebook = CWID ("choosers_nb");
- GtkWidget *kbdraw = NULL;
- GtkWidget *toplevel = NULL;
+ chooser = CWID ("xkb_layout_chooser");
+ xkb_filtered_layouts_list = CWID ("xkb_filtered_layouts_list");
+ xkb_layout_filter = CWID ("xkb_layout_filter");
+
+ visible_column =
+ gtk_tree_view_column_new_with_attributes ("Layout",
+ gtk_cell_renderer_text_new
+ (), "text",
+ COMBO_BOX_MODEL_COL_VISIBLE,
+ NULL);
gtk_window_set_transient_for (GTK_WINDOW (chooser),
- GTK_WINDOW (gtk_widget_get_toplevel (WID ("region_notebook"))));
-
- xkb_layout_chooser_available_layouts_fill (chooser_dialog,
- "xkb_countries_available",
- "xkb_country_variants_available",
- xkl_config_registry_foreach_country,
- (ConfigItemProcessFunc)
- xkb_layout_chooser_add_country_to_available_countries,
- G_CALLBACK
- (xkb_layout_chooser_available_country_changed));
- xkb_layout_chooser_available_layouts_fill (chooser_dialog,
- "xkb_languages_available",
- "xkb_language_variants_available",
- xkl_config_registry_foreach_language,
- (ConfigItemProcessFunc)
- xkb_layout_chooser_add_language_to_available_languages,
- G_CALLBACK
- (xkb_layout_chooser_available_language_changed));
-
- g_signal_connect_after (G_OBJECT (notebook), "switch_page",
- G_CALLBACK
- (xkb_layout_chooser_page_changed),
- chooser_dialog);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX
- (CWID ("xkb_countries_available")),
- FALSE);
-
- if (gtk_tree_model_iter_n_children
- (gtk_combo_box_get_model (GTK_COMBO_BOX (lang_chooser)),
- NULL)) {
- gtk_combo_box_set_active (GTK_COMBO_BOX
- (CWID
- ("xkb_languages_available")),
- FALSE);
- } else {
- /* If language info is not available - remove the corresponding tab,
- pretend there is no notebook at all */
- gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), 1);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook),
- FALSE);
- gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook),
- FALSE);
- }
-
-#ifdef HAVE_X11_EXTENSIONS_XKB_H
- if (!strcmp (xkl_engine_get_backend_name (engine), "XKB")) {
- kbdraw = xkb_layout_preview_create_widget (chooser_dialog);
- g_object_set_data (G_OBJECT (chooser), "kbdraw", kbdraw);
- gtk_container_add (GTK_CONTAINER
- (CWID ("previewFrame")), kbdraw);
- gtk_widget_show_all (kbdraw);
- gtk_button_box_set_child_secondary (GTK_BUTTON_BOX
- (CWID
- ("hbtnBox")),
- CWID
- ("btnPrint"), TRUE);
- } else
-#endif
- {
- gtk_widget_hide (CWID ("vboxPreview"));
- gtk_widget_hide (CWID ("btnPrint"));
- }
+ GTK_WINDOW (gtk_widget_get_toplevel
+ (WID
+ ("region_notebook"))));
+
+ gtk_tree_view_append_column (GTK_TREE_VIEW
+ (xkb_filtered_layouts_list),
+ visible_column);
+ g_signal_connect_swapped (G_OBJECT (xkb_layout_filter),
+ "notify::text",
+ G_CALLBACK (xkb_layout_filter_changed),
+ chooser_dialog);
g_signal_connect (G_OBJECT (chooser),
"response",
G_CALLBACK (xkb_layout_chooser_response),
chooser_dialog);
- toplevel = gtk_widget_get_toplevel (chooser);
- if (gtk_widget_is_toplevel (toplevel)) {
- GdkRectangle *rect = gkbd_preview_load_position ();
- if (rect != NULL) {
- gtk_window_move (GTK_WINDOW (toplevel),
- rect->x, rect->y);
- gtk_window_resize (GTK_WINDOW (toplevel),
- rect->width, rect->height);
- g_free (rect);
- }
- }
+ selection =
+ gtk_tree_view_get_selection (GTK_TREE_VIEW
+ (xkb_filtered_layouts_list));
+
+ g_signal_connect (G_OBJECT (selection),
+ "changed",
+ G_CALLBACK
+ (xkb_layout_chooser_selection_changed),
+ chooser_dialog);
+
+ xkb_layout_chooser_selection_changed (selection, chooser_dialog);
+
+ xkb_layout_filter_changed (chooser_dialog);
- xkb_layout_preview_update (chooser_dialog);
gtk_widget_show (chooser);
}
gchar *
xkb_layout_chooser_get_selected_id (GtkBuilder * chooser_dialog)
{
- GtkWidget *cbv =
- CWID (gtk_notebook_get_current_page
- (GTK_NOTEBOOK (CWID ("choosers_nb"))) ?
- "xkb_language_variants_available" :
- "xkb_country_variants_available");
- GtkTreeModel *vm = gtk_combo_box_get_model (GTK_COMBO_BOX (cbv));
+ GtkListStore *list_store =
+ GTK_LIST_STORE (gtk_builder_get_object (chooser_dialog,
+ "filtered_layout_list_model"));
+ GtkWidget *xkb_filtered_layouts_list =
+ CWID ("xkb_filtered_layouts_list");
GtkTreeIter viter;
gchar *v_id;
+ GtkTreeSelection *selection =
+ gtk_tree_view_get_selection (GTK_TREE_VIEW
+ (xkb_filtered_layouts_list));
+ GList *selected_layouts =
+ gtk_tree_selection_get_selected_rows (selection, NULL);
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (cbv), &viter))
+ if (g_list_length (selected_layouts) != 1)
return NULL;
- gtk_tree_model_get (vm, &viter,
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store), &viter,
+ (GtkTreePath *) (selected_layouts->data));
+ g_list_foreach (selected_layouts, (GFunc) gtk_tree_path_free,
+ NULL);
+ g_list_free (selected_layouts);
+
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &viter,
COMBO_BOX_MODEL_COL_XKB_ID, &v_id, -1);
return v_id;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]