Adding optional vendor combo
svn path=/trunk/; revision=7634
This commit is contained in:
parent
eb516cd218
commit
a0b8e6e3e2
3 changed files with 251 additions and 47 deletions
|
@ -1,3 +1,9 @@
|
|||
2007-05-17 Sergey Udaltsov <svu@gnome.org>
|
||||
|
||||
* gnome-keyboard-properties-xkbmc.c, gnome-keyboard-properties.glade:
|
||||
adding vendor list to the box (option, if there are vendors in
|
||||
base.xml)
|
||||
|
||||
2007-05-05 Jens Granseuer <jensgr@gmx.net>
|
||||
|
||||
* gnome-keyboard-properties.c: (create_dialog):
|
||||
|
|
|
@ -35,6 +35,70 @@
|
|||
#include "gnome-keyboard-properties-xkb.h"
|
||||
|
||||
static gchar *current_model_name = NULL;
|
||||
static gchar *current_vendor_name = NULL;
|
||||
|
||||
static void fill_models_list (GladeXML * chooser_dialog);
|
||||
|
||||
static gboolean fill_vendors_list (GladeXML * chooser_dialog);
|
||||
|
||||
static GtkTreePath *
|
||||
gtk_list_store_find_entry (GtkListStore * list_store,
|
||||
GtkTreeIter * iter, gchar * name, int column_id)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
char *current_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, column_id,
|
||||
¤t_name, -1);
|
||||
if (!g_ascii_strcasecmp (name, current_name)) {
|
||||
path =
|
||||
gtk_tree_model_get_path
|
||||
(GTK_TREE_MODEL (list_store), iter);
|
||||
return path;
|
||||
}
|
||||
g_free (current_name);
|
||||
} while (gtk_tree_model_iter_next
|
||||
(GTK_TREE_MODEL (list_store), iter));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
add_vendor_to_list (XklConfigRegistry * config_registry,
|
||||
XklConfigItem * config_item,
|
||||
GtkTreeView * vendors_list)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *found_existing;
|
||||
GtkListStore *list_store;
|
||||
|
||||
gchar *vendor_name =
|
||||
(gchar *) g_object_get_data (G_OBJECT (config_item),
|
||||
XCI_PROP_VENDOR);
|
||||
if (vendor_name == NULL)
|
||||
return;
|
||||
|
||||
list_store =
|
||||
GTK_LIST_STORE (gtk_tree_view_get_model (vendors_list));
|
||||
|
||||
if (!g_ascii_strcasecmp (config_item->name, current_model_name)) {
|
||||
current_vendor_name = g_strdup (vendor_name);
|
||||
}
|
||||
|
||||
found_existing =
|
||||
gtk_list_store_find_entry (list_store, &iter, vendor_name, 0);
|
||||
/* This vendor is already there */
|
||||
if (found_existing != NULL) {
|
||||
gtk_tree_path_free (found_existing);
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_list_store_append (list_store, &iter);
|
||||
gtk_list_store_set (list_store, &iter, 0, vendor_name, -1);
|
||||
}
|
||||
|
||||
static void
|
||||
add_model_to_list (XklConfigRegistry * config_registry,
|
||||
|
@ -43,7 +107,18 @@ add_model_to_list (XklConfigRegistry * config_registry,
|
|||
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);
|
||||
char *utf_model_name;
|
||||
if (current_vendor_name != NULL) {
|
||||
gchar *vendor_name =
|
||||
(gchar *) g_object_get_data (G_OBJECT (config_item),
|
||||
XCI_PROP_VENDOR);
|
||||
if (vendor_name == NULL)
|
||||
return;
|
||||
|
||||
if (g_ascii_strcasecmp (vendor_name, current_vendor_name))
|
||||
return;
|
||||
}
|
||||
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);
|
||||
|
@ -52,8 +127,30 @@ add_model_to_list (XklConfigRegistry * config_registry,
|
|||
}
|
||||
|
||||
static void
|
||||
xkb_model_chooser_change_sel (GtkTreeSelection * selection,
|
||||
GladeXML * chooser_dialog)
|
||||
xkb_model_chooser_change_vendor_sel (GtkTreeSelection * selection,
|
||||
GladeXML * chooser_dialog)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *list_store = NULL;
|
||||
if (gtk_tree_selection_get_selected
|
||||
(selection, &list_store, &iter)) {
|
||||
gchar *vendor_name = NULL;
|
||||
gtk_tree_model_get (list_store, &iter,
|
||||
0, &vendor_name, -1);
|
||||
|
||||
current_vendor_name = vendor_name;
|
||||
fill_models_list (chooser_dialog);
|
||||
g_free (vendor_name);
|
||||
} else {
|
||||
current_vendor_name = NULL;
|
||||
fill_models_list (chooser_dialog);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
xkb_model_chooser_change_model_sel (GtkTreeSelection * selection,
|
||||
GladeXML * chooser_dialog)
|
||||
{
|
||||
gboolean anysel =
|
||||
gtk_tree_selection_get_selected (selection, NULL, NULL);
|
||||
|
@ -63,68 +160,126 @@ xkb_model_chooser_change_sel (GtkTreeSelection * selection,
|
|||
}
|
||||
|
||||
static void
|
||||
fill_models_list (GladeXML * chooser_dialog)
|
||||
prepare_vendors_list (GladeXML * chooser_dialog)
|
||||
{
|
||||
GtkWidget *models_list = CWID ("models_list");
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path;
|
||||
GtkWidget *vendors_list = CWID ("vendors_list");
|
||||
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
|
||||
GtkTreeViewColumn *description_col =
|
||||
gtk_tree_view_column_new_with_attributes (_("Models"),
|
||||
GtkTreeViewColumn *vendor_col =
|
||||
gtk_tree_view_column_new_with_attributes (_("Vendors"),
|
||||
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 (vendor_col, TRUE);
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (vendors_list),
|
||||
vendor_col);
|
||||
}
|
||||
|
||||
gtk_tree_view_column_set_visible (description_col, TRUE);
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (models_list),
|
||||
description_col);
|
||||
static gboolean
|
||||
fill_vendors_list (GladeXML * chooser_dialog)
|
||||
{
|
||||
GtkWidget *vendors_list = CWID ("vendors_list");
|
||||
GtkListStore *list_store = gtk_list_store_new (1, G_TYPE_STRING);
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path;
|
||||
|
||||
gtk_tree_view_set_model (GTK_TREE_VIEW (models_list),
|
||||
gtk_tree_view_set_model (GTK_TREE_VIEW (vendors_list),
|
||||
GTK_TREE_MODEL (list_store));
|
||||
|
||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE
|
||||
(list_store), 0,
|
||||
GTK_SORT_ASCENDING);
|
||||
|
||||
current_vendor_name = NULL;
|
||||
|
||||
xkl_config_registry_foreach_model (config_registry,
|
||||
(ConfigItemProcessFunc)
|
||||
add_vendor_to_list,
|
||||
vendors_list);
|
||||
|
||||
if (current_vendor_name != NULL) {
|
||||
path = gtk_list_store_find_entry (list_store,
|
||||
&iter,
|
||||
current_vendor_name, 0);
|
||||
if (path != NULL) {
|
||||
gtk_tree_selection_select_iter
|
||||
(gtk_tree_view_get_selection
|
||||
(GTK_TREE_VIEW (vendors_list)), &iter);
|
||||
gtk_tree_view_scroll_to_cell
|
||||
(GTK_TREE_VIEW (vendors_list),
|
||||
path, NULL, TRUE, 0.5, 0);
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
fill_models_list (chooser_dialog);
|
||||
g_free (current_vendor_name);
|
||||
} else {
|
||||
fill_models_list (chooser_dialog);
|
||||
}
|
||||
|
||||
g_signal_connect (G_OBJECT
|
||||
(gtk_tree_view_get_selection
|
||||
(GTK_TREE_VIEW (vendors_list))), "changed",
|
||||
G_CALLBACK (xkb_model_chooser_change_vendor_sel),
|
||||
chooser_dialog);
|
||||
|
||||
return gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store),
|
||||
&iter);
|
||||
}
|
||||
|
||||
static void
|
||||
prepare_models_list (GladeXML * chooser_dialog)
|
||||
{
|
||||
GtkWidget *models_list = CWID ("models_list");
|
||||
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
|
||||
GtkTreeViewColumn *description_col =
|
||||
gtk_tree_view_column_new_with_attributes (_("Models"),
|
||||
renderer,
|
||||
"text", 0,
|
||||
NULL);
|
||||
gtk_tree_view_column_set_visible (description_col, TRUE);
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (models_list),
|
||||
description_col);
|
||||
}
|
||||
|
||||
static void
|
||||
fill_models_list (GladeXML * chooser_dialog)
|
||||
{
|
||||
GtkWidget *models_list = CWID ("models_list");
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path;
|
||||
|
||||
GtkListStore *list_store =
|
||||
gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
|
||||
|
||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE
|
||||
(list_store), 0,
|
||||
GTK_SORT_ASCENDING);
|
||||
|
||||
gtk_tree_view_set_model (GTK_TREE_VIEW (models_list),
|
||||
GTK_TREE_MODEL (list_store));
|
||||
|
||||
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));
|
||||
path = gtk_list_store_find_entry (list_store,
|
||||
&iter,
|
||||
current_model_name, 1);
|
||||
if (path != NULL) {
|
||||
gtk_tree_selection_select_iter
|
||||
(gtk_tree_view_get_selection
|
||||
(GTK_TREE_VIEW (models_list)), &iter);
|
||||
gtk_tree_view_scroll_to_cell
|
||||
(GTK_TREE_VIEW (models_list),
|
||||
path, NULL, TRUE, 0.5, 0);
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
}
|
||||
|
||||
g_signal_connect (G_OBJECT
|
||||
(gtk_tree_view_get_selection
|
||||
(GTK_TREE_VIEW (models_list))), "changed",
|
||||
G_CALLBACK (xkb_model_chooser_change_sel),
|
||||
G_CALLBACK (xkb_model_chooser_change_model_sel),
|
||||
chooser_dialog);
|
||||
}
|
||||
|
||||
|
@ -167,7 +322,18 @@ choose_model (GladeXML * dialog)
|
|||
current_model_name =
|
||||
gconf_client_get_string (xkb_gconf_client,
|
||||
GKBD_KEYBOARD_CONFIG_KEY_MODEL, NULL);
|
||||
fill_models_list (chooser_dialog);
|
||||
|
||||
|
||||
prepare_vendors_list (chooser_dialog);
|
||||
prepare_models_list (chooser_dialog);
|
||||
|
||||
if (!fill_vendors_list (chooser_dialog)) {
|
||||
gtk_widget_hide_all (CWID ("vendors_label"));
|
||||
gtk_widget_hide_all (CWID ("vendors_scrolledwindow"));
|
||||
current_vendor_name = NULL;
|
||||
fill_models_list (chooser_dialog);
|
||||
}
|
||||
|
||||
g_signal_connect (G_OBJECT (chooser),
|
||||
"response",
|
||||
G_CALLBACK (xkb_model_chooser_response),
|
||||
|
|
|
@ -935,7 +935,7 @@
|
|||
<property name="title" translatable="yes">Choose a Keyboard Model</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="default_width">450</property>
|
||||
<property name="default_height">300</property>
|
||||
<property name="default_height">400</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
|
||||
<property name="has_separator">False</property>
|
||||
<child internal-child="vbox">
|
||||
|
@ -948,10 +948,10 @@
|
|||
<property name="border_width">5</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label58">
|
||||
<widget class="GtkLabel" id="vendors_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">_Models:</property>
|
||||
<property name="label" translatable="yes">_Vendors:</property>
|
||||
<property name="use_underline">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
|
@ -960,7 +960,39 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow5">
|
||||
<widget class="GtkScrolledWindow" id="vendors_scrolledwindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="shadow_type">GTK_SHADOW_IN</property>
|
||||
<child>
|
||||
<widget class="GtkTreeView" id="vendors_list">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="headers_visible">False</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label7">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">_Models:</property>
|
||||
<property name="use_underline">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
|
@ -975,7 +1007,7 @@
|
|||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue