first round of working model chooser - not complete yet

This commit is contained in:
Sergey V. Udaltsov 2004-07-25 23:28:35 +00:00
parent 85cb682efc
commit 885acff46a
5 changed files with 331 additions and 111 deletions

View file

@ -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 \

View file

@ -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;
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") );
}
items = items->next;
}
}
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);

View file

@ -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 */

View file

@ -0,0 +1,127 @@
/* -*- mode: c; style: linux -*- */
/* gnome-keyboard-properties-xkb.c
* Copyright (C) 2003 Sergey V. Oudaltsov
*
* Written by: Sergey V. Oudaltsov <svu@users.sourceforge.net>
*
* 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 <config.h>
#endif
#include <gnome.h>
#include <gdk/gdkx.h>
#include <gconf/gconf-client.h>
#include <glade/glade.h>
#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);
}

View file

@ -12,6 +12,11 @@
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
@ -33,6 +38,7 @@
<property name="label">gtk-help</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-11</property>
</widget>
</child>
@ -43,6 +49,7 @@
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="accessibility_button_clicked" last_modification_time="Tue, 02 Jul 2002 06:58:29 GMT"/>
@ -53,6 +60,10 @@
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox7">
@ -114,6 +125,7 @@
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-7</property>
</widget>
</child>
@ -211,6 +223,7 @@
<property name="label" translatable="yes">Key presses _repeat when key is held down</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
@ -539,6 +552,7 @@
<property name="label" translatable="yes">Cursor _blinks in text boxes and fields</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
@ -790,7 +804,7 @@
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="mnemonic_widget">xkb_models</property>
<property name="mnemonic_widget">xkb_model</property>
</widget>
<packing>
<property name="padding">0</property>
@ -800,15 +814,20 @@
</child>
<child>
<widget class="GtkOptionMenu" id="xkb_models">
<widget class="GtkEntry" id="xkb_model">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="history">-1</property>
<property name="editable">False</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes">Microsoft Natural Keyboard</property>
<property name="has_frame">True</property>
<property name="invisible_char" translatable="yes">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
@ -817,6 +836,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<child>
<widget class="GtkAlignment" id="alignment2">
@ -825,6 +845,10 @@
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox29">
@ -881,6 +905,45 @@
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="xkb_model_pick">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">...</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xscale">1</property>
<property name="yscale">1</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">6</property>
<property name="right_padding">6</property>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
@ -991,6 +1054,7 @@
<property name="label">gtk-add</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="padding">0</property>
@ -1006,6 +1070,7 @@
<property name="label">gtk-remove</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="padding">0</property>
@ -1021,6 +1086,7 @@
<property name="label">gtk-go-up</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="padding">0</property>
@ -1036,6 +1102,7 @@
<property name="label">gtk-go-down</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="padding">0</property>
@ -1258,6 +1325,7 @@
<property name="label">gtk-add</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="padding">0</property>
@ -1273,6 +1341,7 @@
<property name="label">gtk-remove</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="padding">0</property>
@ -1405,6 +1474,7 @@
<property name="label" translatable="yes">&lt;b&gt;_Lock screen to enforce typing break&lt;/b&gt;</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
@ -1648,6 +1718,7 @@
<property name="label" translatable="yes">All_ow postponing of breaks</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
@ -1720,6 +1791,10 @@
<property name="yalign">0.5</property>
<property name="xscale">1</property>
<property name="yscale">1</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<placeholder/>
@ -1760,4 +1835,108 @@
</child>
</widget>
<widget class="GtkDialog" id="xkb_model_chooser">
<property name="visible">True</property>
<property name="title" translatable="yes">Choose a keyboard model</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">True</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">True</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="cancelbutton1">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="okbutton1">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="xkb_model_chooser_pane">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow5">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="models_list">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>