2003-11-12 22:00:55 +00:00
|
|
|
/* -*- 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>
|
2004-01-12 01:49:46 +00:00
|
|
|
#include <gdk/gdkx.h>
|
2003-11-12 22:00:55 +00:00
|
|
|
#include <gconf/gconf-client.h>
|
|
|
|
#include <glade/glade.h>
|
|
|
|
|
2004-12-18 04:38:49 +00:00
|
|
|
#include "libgswitchit/gswitchit_config.h"
|
2003-11-12 22:00:55 +00:00
|
|
|
|
|
|
|
#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"
|
|
|
|
|
2004-07-25 23:28:35 +00:00
|
|
|
#define CWID(s) glade_xml_get_widget (chooserDialog, s)
|
|
|
|
|
2004-12-18 04:38:49 +00:00
|
|
|
static GSwitchItKbdConfig initialConfig;
|
2004-01-12 13:08:34 +00:00
|
|
|
|
2003-11-12 22:00:55 +00:00
|
|
|
char *
|
|
|
|
xci_desc_to_utf8 (XklConfigItem * ci)
|
|
|
|
{
|
2004-01-09 20:43:59 +00:00
|
|
|
char *sd = g_strstrip (ci->description);
|
|
|
|
return sd[0] == 0 ? g_strdup (ci->name) :
|
|
|
|
g_locale_to_utf8 (sd, -1, NULL, NULL, NULL);
|
2003-11-12 22:00:55 +00:00
|
|
|
}
|
|
|
|
|
2004-07-26 00:48:24 +00:00
|
|
|
static GConfValue *
|
|
|
|
model_from_widget (GConfPropertyEditor * peditor, GConfValue * value)
|
|
|
|
{
|
|
|
|
GConfValue *new_value;
|
|
|
|
|
|
|
|
new_value = gconf_value_new (GCONF_VALUE_STRING);
|
|
|
|
|
|
|
|
if (value->type == GCONF_VALUE_STRING)
|
|
|
|
{
|
|
|
|
GObject* widget = gconf_property_editor_get_ui_control(peditor);
|
|
|
|
gchar* n = g_object_get_data (widget, "xkbModelName");
|
|
|
|
gconf_value_set_string (new_value, n);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gconf_value_set_string (new_value, _("Unknown"));
|
|
|
|
|
|
|
|
return new_value;
|
|
|
|
}
|
|
|
|
|
2003-11-12 22:00:55 +00:00
|
|
|
static GConfValue *
|
|
|
|
model_to_widget (GConfPropertyEditor * peditor, GConfValue * value)
|
|
|
|
{
|
2004-01-09 20:43:59 +00:00
|
|
|
GConfValue *new_value;
|
|
|
|
|
2004-07-25 23:28:35 +00:00
|
|
|
new_value = gconf_value_new (GCONF_VALUE_STRING);
|
2004-01-09 20:43:59 +00:00
|
|
|
|
|
|
|
if (value->type == GCONF_VALUE_STRING)
|
|
|
|
{
|
2004-07-25 23:28:35 +00:00
|
|
|
XklConfigItem ci;
|
|
|
|
g_snprintf( ci.name, sizeof (ci.name), "%s", gconf_value_get_string( value ) );
|
|
|
|
if ( XklConfigFindModel( &ci ) )
|
2004-07-26 00:48:24 +00:00
|
|
|
{
|
|
|
|
GObject* widget = gconf_property_editor_get_ui_control(peditor);
|
|
|
|
gchar* d = xci_desc_to_utf8 (&ci);
|
|
|
|
|
|
|
|
g_object_set_data_full (widget, "xkbModelName", g_strdup (ci.name), g_free);
|
|
|
|
gconf_value_set_string (new_value, d);
|
|
|
|
g_free (d);
|
|
|
|
}
|
2004-07-25 23:28:35 +00:00
|
|
|
else
|
2004-07-26 00:48:24 +00:00
|
|
|
gconf_value_set_string (new_value, _("Unknown"));
|
2004-01-09 20:43:59 +00:00
|
|
|
}
|
2003-11-12 22:00:55 +00:00
|
|
|
|
2004-01-09 20:43:59 +00:00
|
|
|
return new_value;
|
2003-11-12 22:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-17 01:46:57 +00:00
|
|
|
cleanup_xkb_tabs (GladeXML * dialog)
|
2003-11-12 22:00:55 +00:00
|
|
|
{
|
2004-12-18 04:38:49 +00:00
|
|
|
GSwitchItKbdConfigTerm (&initialConfig);
|
2004-01-09 20:43:59 +00:00
|
|
|
XklConfigFreeRegistry ();
|
|
|
|
XklConfigTerm ();
|
2004-01-12 01:49:46 +00:00
|
|
|
XklTerm ();
|
2003-11-12 22:00:55 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 20:43:59 +00:00
|
|
|
static void
|
|
|
|
reset_to_defaults (GtkWidget * button, GladeXML * dialog)
|
|
|
|
{
|
|
|
|
gconf_client_set_bool (gconf_client_get_default (),
|
2004-12-18 04:38:49 +00:00
|
|
|
GSWITCHIT_KBD_CONFIG_KEY_OVERRIDE_SETTINGS,
|
2004-01-09 20:43:59 +00:00
|
|
|
TRUE, NULL);
|
|
|
|
/* all the rest is g-s-d's business */
|
2003-11-12 22:00:55 +00:00
|
|
|
}
|
|
|
|
|
2004-01-12 01:49:46 +00:00
|
|
|
static void
|
|
|
|
update_model (GConfClient * client,
|
|
|
|
guint cnxn_id, GConfEntry * entry, GladeXML * dialog)
|
|
|
|
{
|
|
|
|
enable_disable_restoring (dialog);
|
|
|
|
}
|
|
|
|
|
2004-07-26 23:19:03 +00:00
|
|
|
static void
|
|
|
|
notebook_page_changed (GtkNotebook * notebook,
|
|
|
|
GtkNotebookPage * page,
|
|
|
|
guint pageNum,
|
|
|
|
GladeXML * dialog)
|
|
|
|
{
|
|
|
|
switch (pageNum)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("enable_preview")), FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-12 22:00:55 +00:00
|
|
|
void
|
|
|
|
setup_xkb_tabs (GladeXML * dialog, GConfChangeSet * changeset)
|
|
|
|
{
|
2004-01-12 13:08:34 +00:00
|
|
|
GConfClient *confClient = gconf_client_get_default ();
|
2004-11-29 20:33:19 +00:00
|
|
|
gboolean isXkb;
|
2004-01-12 13:08:34 +00:00
|
|
|
|
2004-01-12 01:49:46 +00:00
|
|
|
XklInit (GDK_DISPLAY ());
|
2004-01-09 20:43:59 +00:00
|
|
|
XklConfigInit ();
|
|
|
|
XklConfigLoadRegistry ();
|
|
|
|
|
2004-07-25 23:28:35 +00:00
|
|
|
// fill_models_option_menu (dialog);
|
2004-01-09 20:43:59 +00:00
|
|
|
|
2004-07-25 23:28:35 +00:00
|
|
|
gconf_peditor_new_string
|
2004-12-18 04:38:49 +00:00
|
|
|
(changeset, (gchar *) GSWITCHIT_KBD_CONFIG_KEY_MODEL,
|
2004-07-25 23:28:35 +00:00
|
|
|
WID ("xkb_model"),
|
2004-07-26 00:48:24 +00:00
|
|
|
"conv-to-widget-cb", model_to_widget,
|
|
|
|
"conv-from-widget-cb", model_from_widget, NULL);
|
2004-01-09 20:43:59 +00:00
|
|
|
|
|
|
|
fill_available_layouts_tree (dialog);
|
|
|
|
fill_available_options_tree (dialog);
|
|
|
|
prepare_selected_layouts_tree (dialog);
|
|
|
|
prepare_selected_options_tree (dialog);
|
|
|
|
fill_selected_layouts_tree (dialog);
|
|
|
|
fill_selected_options_tree (dialog);
|
|
|
|
|
|
|
|
register_layouts_buttons_handlers (dialog);
|
|
|
|
register_options_buttons_handlers (dialog);
|
|
|
|
g_signal_connect (G_OBJECT (WID ("xkb_reset_to_defaults")), "clicked",
|
|
|
|
G_CALLBACK (reset_to_defaults), dialog);
|
2004-07-25 23:28:35 +00:00
|
|
|
|
|
|
|
g_signal_connect_swapped (G_OBJECT (WID ("xkb_model_pick")), "clicked",
|
|
|
|
G_CALLBACK (choose_model), dialog);
|
2004-01-09 20:43:59 +00:00
|
|
|
|
|
|
|
register_layouts_gconf_listener (dialog);
|
|
|
|
register_options_gconf_listener (dialog);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (WID ("keyboard_dialog")),
|
|
|
|
"destroy", G_CALLBACK (cleanup_xkb_tabs), dialog);
|
2004-01-12 01:49:46 +00:00
|
|
|
|
|
|
|
gconf_client_notify_add (gconf_client_get_default (),
|
2004-12-18 04:38:49 +00:00
|
|
|
GSWITCHIT_KBD_CONFIG_KEY_MODEL,
|
2004-01-12 01:49:46 +00:00
|
|
|
(GConfClientNotifyFunc)
|
|
|
|
update_model, dialog, NULL, NULL);
|
|
|
|
|
2004-12-18 04:38:49 +00:00
|
|
|
GSwitchItKbdConfigInit (&initialConfig, confClient);
|
2004-01-12 13:08:34 +00:00
|
|
|
g_object_unref (confClient);
|
2004-12-18 04:38:49 +00:00
|
|
|
GSwitchItKbdConfigLoadInitial (&initialConfig);
|
2004-01-12 13:08:34 +00:00
|
|
|
|
2004-01-12 01:49:46 +00:00
|
|
|
enable_disable_restoring (dialog);
|
2004-07-13 23:11:34 +00:00
|
|
|
|
2004-11-29 20:33:19 +00:00
|
|
|
isXkb = !strcmp (XklGetBackendName(), "XKB");
|
|
|
|
if (!isXkb)
|
|
|
|
gtk_widget_hide (WID ("enable_preview"));
|
|
|
|
|
2004-07-26 23:07:03 +00:00
|
|
|
g_signal_connect_swapped (G_OBJECT (WID ("enable_preview")), "toggled",
|
|
|
|
G_CALLBACK (preview_toggled), dialog);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("enable_preview")), FALSE);
|
2004-07-26 23:19:03 +00:00
|
|
|
g_signal_connect (G_OBJECT (WID ("keyboard_notebook")), "switch-page",
|
|
|
|
G_CALLBACK (notebook_page_changed), dialog);
|
2004-01-12 01:49:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
enable_disable_restoring (GladeXML * dialog)
|
|
|
|
{
|
2004-12-18 04:38:49 +00:00
|
|
|
GSwitchItKbdConfig gswic;
|
2004-01-12 01:49:46 +00:00
|
|
|
GConfClient *confClient = gconf_client_get_default ();
|
|
|
|
gboolean enable;
|
|
|
|
|
2004-12-18 04:38:49 +00:00
|
|
|
GSwitchItKbdConfigInit (&gswic, confClient);
|
2004-01-12 01:49:46 +00:00
|
|
|
g_object_unref (confClient);
|
2004-12-18 04:38:49 +00:00
|
|
|
GSwitchItKbdConfigLoad (&gswic);
|
2004-01-12 01:49:46 +00:00
|
|
|
|
2004-12-18 04:38:49 +00:00
|
|
|
enable = !GSwitchItKbdConfigEquals (&gswic, &initialConfig);
|
2004-01-12 01:49:46 +00:00
|
|
|
|
2004-12-18 04:38:49 +00:00
|
|
|
GSwitchItKbdConfigTerm (&gswic);
|
2004-01-12 01:49:46 +00:00
|
|
|
gtk_widget_set_sensitive (WID ("xkb_reset_to_defaults"), enable);
|
2003-11-12 22:00:55 +00:00
|
|
|
}
|