2011-06-21 08:49:07 +00:00
|
|
|
From 7f81445b3e6613d14f64253506a309095a37c8d7 Mon Sep 17 00:00:00 2001
|
2010-11-12 09:51:00 +00:00
|
|
|
From: fujiwarat <takao.fujiwara1@gmail.com>
|
2011-06-21 08:49:07 +00:00
|
|
|
Date: Mon, 20 Jun 2011 19:04:42 +0900
|
2010-11-12 09:51:00 +00:00
|
|
|
Subject: [PATCH] Reload preload engines until users customize the list.
|
|
|
|
|
|
|
|
The idea is, if users don't customize the preload_engines with ibus-setup,
|
|
|
|
users would prefer to load the system default engines again by login.
|
|
|
|
The gconf value 'preload_engine_mode' is
|
2011-06-21 08:49:07 +00:00
|
|
|
IBUS_PRELOAD_ENGINE_MODE_USER by default but set
|
|
|
|
IBUS_PRELOAD_ENGINE_MODE_LANG_RELATIVE for the initial login.
|
2010-11-12 09:51:00 +00:00
|
|
|
If preload_engine_mode is IBUS_PRELOAD_ENGINE_MODE_LANG_RELATIVE,
|
|
|
|
ibus-daemon loads the system preload engines by langs.
|
|
|
|
If preload_engine_mode is IBUS_PRELOAD_ENGINE_MODE_USER,
|
|
|
|
ibus-daemon do not update the gconf value preload_engines.
|
|
|
|
On the other hand, if users enable the customized engine checkbutton
|
|
|
|
on ibus-setup, ibus-setup sets 'preload_engine_mode' as
|
|
|
|
IBUS_PRELOAD_ENGINE_MODE_USER and users can customize the value
|
|
|
|
'preload_engines'.
|
|
|
|
---
|
2011-06-21 08:49:07 +00:00
|
|
|
bus/ibusimpl.c | 402 +++++++++++++++++++++++++++++++++++++++-----------
|
|
|
|
data/ibus.schemas.in | 13 ++
|
2011-03-10 09:07:52 +00:00
|
|
|
ibus/common.py | 6 +
|
2011-06-21 08:49:07 +00:00
|
|
|
setup/main.py | 70 ++++++++-
|
2011-03-10 09:07:52 +00:00
|
|
|
setup/setup.ui | 21 +++-
|
2010-11-26 05:38:39 +00:00
|
|
|
src/ibustypes.h | 10 ++
|
2011-06-21 08:49:07 +00:00
|
|
|
6 files changed, 427 insertions(+), 95 deletions(-)
|
2010-11-12 09:51:00 +00:00
|
|
|
|
|
|
|
diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c
|
2011-06-21 08:49:07 +00:00
|
|
|
index a7ae52b..bb4b8ae 100644
|
2010-11-12 09:51:00 +00:00
|
|
|
--- a/bus/ibusimpl.c
|
|
|
|
+++ b/bus/ibusimpl.c
|
2011-06-21 08:49:07 +00:00
|
|
|
@@ -144,6 +144,9 @@ static void bus_ibus_impl_set_previous_engine
|
2010-11-12 09:51:00 +00:00
|
|
|
static void bus_ibus_impl_set_preload_engines
|
|
|
|
(BusIBusImpl *ibus,
|
|
|
|
GVariant *value);
|
|
|
|
+static void bus_ibus_impl_set_preload_engine_mode
|
|
|
|
+ (BusIBusImpl *ibus,
|
|
|
|
+ GVariant *value);
|
|
|
|
static void bus_ibus_impl_set_use_sys_layout
|
|
|
|
(BusIBusImpl *ibus,
|
|
|
|
GVariant *value);
|
2011-06-21 08:49:07 +00:00
|
|
|
@@ -285,6 +288,259 @@ _panel_destroy_cb (BusPanelProxy *panel,
|
2010-11-12 09:51:00 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 08:49:07 +00:00
|
|
|
static void
|
|
|
|
+_config_set_value_done (GObject *object,
|
|
|
|
+ GAsyncResult *res,
|
|
|
|
+ gpointer user_data)
|
|
|
|
+{
|
|
|
|
+ IBusConfig *config = (IBusConfig *) object;
|
|
|
|
+ GVariant *value = (GVariant *) user_data;
|
|
|
|
+ GError *error = NULL;
|
|
|
|
+
|
|
|
|
+ g_assert (IBUS_IS_CONFIG (config));
|
|
|
|
+
|
|
|
|
+ if (!ibus_config_set_value_async_finish (config, res, &error)) {
|
|
|
|
+ if (error) {
|
|
|
|
+ g_error_free (error);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ g_variant_unref (value);
|
|
|
|
+}
|
|
|
|
+
|
2011-03-10 09:07:52 +00:00
|
|
|
+#ifndef OS_CHROMEOS
|
2010-11-26 05:38:39 +00:00
|
|
|
+static gint
|
|
|
|
+_engine_desc_cmp (IBusEngineDesc *desc1,
|
|
|
|
+ IBusEngineDesc *desc2)
|
2010-11-12 09:51:00 +00:00
|
|
|
+{
|
2010-11-26 05:38:39 +00:00
|
|
|
+ return - ((gint) ibus_engine_desc_get_rank (desc1)) +
|
|
|
|
+ ((gint) ibus_engine_desc_get_rank (desc2));
|
|
|
|
+}
|
2011-03-10 09:07:52 +00:00
|
|
|
+#endif
|
2010-11-12 09:51:00 +00:00
|
|
|
+
|
2011-03-10 09:07:52 +00:00
|
|
|
+#ifndef OS_CHROMEOS
|
2010-11-26 05:38:39 +00:00
|
|
|
+static gint
|
|
|
|
+_get_config_preload_engine_mode (BusIBusImpl *ibus)
|
|
|
|
+{
|
|
|
|
+ GVariant *variant = NULL;
|
2011-06-21 08:49:07 +00:00
|
|
|
+ gint preload_engine_mode = IBUS_PRELOAD_ENGINE_MODE_USER;
|
2010-11-26 05:38:39 +00:00
|
|
|
+
|
|
|
|
+ g_assert (BUS_IS_IBUS_IMPL (ibus));
|
|
|
|
+
|
|
|
|
+ if (ibus->config == NULL) {
|
|
|
|
+ return preload_engine_mode;
|
2010-11-12 09:51:00 +00:00
|
|
|
+ }
|
|
|
|
+
|
2010-11-26 05:38:39 +00:00
|
|
|
+ variant = ibus_config_get_value (ibus->config, "general",
|
2011-06-21 08:49:07 +00:00
|
|
|
+ "preload_engines");
|
|
|
|
+ if (variant == NULL) {
|
|
|
|
+ /* Set LANG_RELATIVE mode for the initial login */
|
|
|
|
+ preload_engine_mode = IBUS_PRELOAD_ENGINE_MODE_LANG_RELATIVE;
|
|
|
|
+ variant = g_variant_ref_sink (g_variant_new ("i", preload_engine_mode));
|
|
|
|
+ ibus_config_set_value_async (ibus->config, "general",
|
|
|
|
+ "preload_engine_mode", variant,
|
|
|
|
+ -1,
|
|
|
|
+ NULL,
|
|
|
|
+ _config_set_value_done,
|
|
|
|
+ variant);
|
|
|
|
+ return preload_engine_mode;
|
|
|
|
+ } else {
|
|
|
|
+ g_variant_unref (variant);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ variant = ibus_config_get_value (ibus->config, "general",
|
2010-11-26 05:38:39 +00:00
|
|
|
+ "preload_engine_mode");
|
|
|
|
+ if (variant != NULL) {
|
|
|
|
+ if (g_variant_classify (variant) == G_VARIANT_CLASS_INT32) {
|
|
|
|
+ preload_engine_mode = g_variant_get_int32 (variant);
|
|
|
|
+ }
|
|
|
|
+ g_variant_unref (variant);
|
2010-11-12 09:51:00 +00:00
|
|
|
+ }
|
|
|
|
+
|
2010-11-26 05:38:39 +00:00
|
|
|
+ return preload_engine_mode;
|
2010-11-12 09:51:00 +00:00
|
|
|
+}
|
2011-03-10 09:07:52 +00:00
|
|
|
+#endif
|
2010-11-12 09:51:00 +00:00
|
|
|
+
|
2011-06-21 08:49:07 +00:00
|
|
|
+static int
|
|
|
|
+_compare_engine_list_value (GVariant *value_a, GVariant *value_b)
|
|
|
|
+{
|
|
|
|
+ GVariant *value;
|
|
|
|
+ GVariantIter iter;
|
|
|
|
+ const gchar *engine_name = NULL;
|
|
|
|
+ gchar *concat_engine_names;
|
|
|
|
+ gchar *concat_engine_names_a = NULL;
|
|
|
|
+ gchar *concat_engine_names_b = NULL;
|
|
|
|
+ int retval = 0;
|
|
|
|
+
|
|
|
|
+ value = value_a;
|
|
|
|
+ concat_engine_names = NULL;
|
|
|
|
+ if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_ARRAY) {
|
|
|
|
+ g_variant_iter_init (&iter, value);
|
|
|
|
+ while (g_variant_iter_loop (&iter, "&s", &engine_name)) {
|
|
|
|
+ gchar *tmp = g_strdup_printf ("%s::%s",
|
|
|
|
+ concat_engine_names ? concat_engine_names : "",
|
|
|
|
+ engine_name ? engine_name : "");
|
|
|
|
+ g_free (concat_engine_names);
|
|
|
|
+ concat_engine_names = tmp;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ concat_engine_names_a = concat_engine_names;
|
|
|
|
+
|
|
|
|
+ value = value_b;
|
|
|
|
+ concat_engine_names = NULL;
|
|
|
|
+ if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_ARRAY) {
|
|
|
|
+ g_variant_iter_init (&iter, value);
|
|
|
|
+ while (g_variant_iter_loop (&iter, "&s", &engine_name)) {
|
|
|
|
+ gchar *tmp = g_strdup_printf ("%s::%s",
|
|
|
|
+ concat_engine_names ? concat_engine_names : "",
|
|
|
|
+ engine_name ? engine_name : "");
|
|
|
|
+ g_free (concat_engine_names);
|
|
|
|
+ concat_engine_names = tmp;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ concat_engine_names_b = concat_engine_names;
|
|
|
|
+
|
|
|
|
+ retval = g_strcmp0 (concat_engine_names_a, concat_engine_names_b);
|
|
|
|
+ g_free (concat_engine_names_a);
|
|
|
|
+ g_free (concat_engine_names_b);
|
|
|
|
+ return retval;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void
|
|
|
|
+_preload_engines_config_get_value_done (GObject *object,
|
|
|
|
+ GAsyncResult *res,
|
|
|
|
+ gpointer user_data)
|
|
|
|
+{
|
|
|
|
+ IBusConfig *config = (IBusConfig *) object;
|
|
|
|
+ GVariant *new_value = (GVariant *) user_data;
|
|
|
|
+ GVariant *value = NULL;
|
|
|
|
+ GError *error = NULL;
|
|
|
|
+
|
|
|
|
+ g_assert (IBUS_IS_CONFIG (config));
|
|
|
|
+
|
|
|
|
+ value = ibus_config_get_value_async_finish (config, res, &error);
|
|
|
|
+ if (error) {
|
|
|
|
+ g_error_free (error);
|
|
|
|
+ }
|
|
|
|
+ if (_compare_engine_list_value (value, new_value) != 0) {
|
|
|
|
+ ibus_config_set_value_async (config, "general",
|
|
|
|
+ "preload_engines", new_value,
|
|
|
|
+ -1,
|
|
|
|
+ NULL,
|
|
|
|
+ _config_set_value_done,
|
|
|
|
+ new_value);
|
|
|
|
+ } else if (new_value) {
|
|
|
|
+ g_variant_unref (new_value);
|
|
|
|
+ }
|
|
|
|
+ if (value) {
|
|
|
|
+ g_variant_unref (value);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
2010-11-12 09:51:00 +00:00
|
|
|
+static void
|
2010-11-26 05:38:39 +00:00
|
|
|
+_set_preload_engines (BusIBusImpl *ibus,
|
|
|
|
+ GVariant *value)
|
|
|
|
+{
|
|
|
|
+ GList *engine_list = NULL;
|
|
|
|
+
|
|
|
|
+ g_assert (BUS_IS_IBUS_IMPL (ibus));
|
|
|
|
+
|
|
|
|
+ g_list_foreach (ibus->engine_list, (GFunc) g_object_unref, NULL);
|
|
|
|
+ g_list_free (ibus->engine_list);
|
|
|
|
+
|
|
|
|
+ if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_ARRAY) {
|
|
|
|
+ GVariantIter iter;
|
|
|
|
+ g_variant_iter_init (&iter, value);
|
|
|
|
+ const gchar *engine_name = NULL;
|
|
|
|
+ while (g_variant_iter_loop (&iter, "&s", &engine_name)) {
|
|
|
|
+ IBusEngineDesc *engine = bus_registry_find_engine_by_name (ibus->registry, engine_name);
|
|
|
|
+ if (engine == NULL || g_list_find (engine_list, engine) != NULL)
|
|
|
|
+ continue;
|
|
|
|
+ engine_list = g_list_append (engine_list, engine);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (engine_list != NULL &&
|
2011-06-21 08:49:07 +00:00
|
|
|
+ ibus->config != NULL) {
|
|
|
|
+ /* sync function will effects the startup performance.
|
|
|
|
+ * We'd always like to save the value so that ibus-setup
|
|
|
|
+ * get the updated engine list. */
|
|
|
|
+ ibus_config_get_value_async (ibus->config, "general",
|
|
|
|
+ "preload_engines",
|
|
|
|
+ -1,
|
|
|
|
+ NULL,
|
|
|
|
+ _preload_engines_config_get_value_done,
|
|
|
|
+ g_variant_ref_sink (value));
|
2011-03-10 09:07:52 +00:00
|
|
|
+ } else {
|
|
|
|
+ /* We don't update preload_engines with an empty string for safety.
|
|
|
|
+ * Just unref the floating value. */
|
|
|
|
+ g_variant_unref (value);
|
2010-11-26 05:38:39 +00:00
|
|
|
+ }
|
2011-03-10 09:07:52 +00:00
|
|
|
+ } else if (value != NULL) {
|
|
|
|
+ g_variant_unref (value);
|
2010-11-26 05:38:39 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ g_list_foreach (engine_list, (GFunc) g_object_ref, NULL);
|
|
|
|
+ ibus->engine_list = engine_list;
|
|
|
|
+
|
|
|
|
+ if (ibus->engine_list) {
|
|
|
|
+ BusComponent *component = bus_component_from_engine_desc ((IBusEngineDesc *) ibus->engine_list->data);
|
|
|
|
+ if (component && !bus_component_is_running (component)) {
|
|
|
|
+ bus_component_start (component, g_verbose);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2011-04-19 03:14:20 +00:00
|
|
|
+ bus_ibus_impl_check_global_engine (ibus);
|
2010-11-26 05:38:39 +00:00
|
|
|
+ bus_ibus_impl_update_engines_hotkey_profile (ibus);
|
|
|
|
+}
|
|
|
|
+
|
2011-03-10 09:07:52 +00:00
|
|
|
+#ifndef OS_CHROMEOS
|
2010-11-26 05:38:39 +00:00
|
|
|
+static void
|
|
|
|
+_set_language_relative_preload_engines (BusIBusImpl *ibus)
|
|
|
|
+{
|
|
|
|
+ gchar *lang = NULL;
|
|
|
|
+ gchar *p = NULL;
|
|
|
|
+ GList *engines = NULL;
|
|
|
|
+ GList *list;
|
|
|
|
+ GVariantBuilder builder;
|
|
|
|
+
|
|
|
|
+ g_assert (BUS_IS_IBUS_IMPL (ibus));
|
|
|
|
+
|
2011-03-10 09:07:52 +00:00
|
|
|
+ /* The setlocale call first checks LC_ALL. If it's not available, checks
|
|
|
|
+ * LC_CTYPE. If it's also not available, checks LANG. */
|
2011-02-17 07:30:49 +00:00
|
|
|
+ lang = g_strdup (setlocale (LC_CTYPE, NULL));
|
|
|
|
+ if (lang == NULL) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
2011-03-10 09:07:52 +00:00
|
|
|
+
|
2010-11-26 05:38:39 +00:00
|
|
|
+ p = index (lang, '.');
|
|
|
|
+ if (p) {
|
|
|
|
+ *p = '\0';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ engines = bus_registry_get_engines_by_language (ibus->registry, lang);
|
|
|
|
+ if (engines == NULL) {
|
|
|
|
+ p = index (lang, '_');
|
|
|
|
+ if (p) {
|
|
|
|
+ *p = '\0';
|
|
|
|
+ engines = bus_registry_get_engines_by_language (ibus->registry, lang);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ g_free (lang);
|
|
|
|
+
|
|
|
|
+ /* sort engines by rank */
|
|
|
|
+ engines = g_list_sort (engines, (GCompareFunc) _engine_desc_cmp);
|
|
|
|
+
|
|
|
|
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
|
|
|
|
+ for (list = engines; list != NULL; list = list->next) {
|
|
|
|
+ IBusEngineDesc *desc = (IBusEngineDesc *)list->data;
|
|
|
|
+ /* ignore engines with rank <== 0 */
|
|
|
|
+ if (ibus_engine_desc_get_rank (desc) > 0)
|
|
|
|
+ g_variant_builder_add (&builder, "s", ibus_engine_desc_get_name (desc));
|
|
|
|
+ }
|
|
|
|
+ _set_preload_engines (ibus, g_variant_builder_end (&builder));
|
|
|
|
+ g_list_free (engines);
|
|
|
|
+}
|
2011-03-10 09:07:52 +00:00
|
|
|
+#endif
|
2010-11-26 05:38:39 +00:00
|
|
|
+
|
2011-06-21 08:49:07 +00:00
|
|
|
+static void
|
2010-11-26 05:38:39 +00:00
|
|
|
bus_ibus_impl_set_hotkey (BusIBusImpl *ibus,
|
|
|
|
GQuark hotkey,
|
2011-06-21 08:49:07 +00:00
|
|
|
GVariant *value)
|
|
|
|
@@ -394,35 +650,50 @@ static void
|
2010-11-26 05:38:39 +00:00
|
|
|
bus_ibus_impl_set_preload_engines (BusIBusImpl *ibus,
|
|
|
|
GVariant *value)
|
2010-11-12 09:51:00 +00:00
|
|
|
{
|
2010-11-26 05:38:39 +00:00
|
|
|
- GList *engine_list = NULL;
|
2011-03-10 09:07:52 +00:00
|
|
|
-
|
2011-01-26 08:27:03 +00:00
|
|
|
- g_list_foreach (ibus->engine_list, (GFunc) g_object_unref, NULL);
|
|
|
|
- g_list_free (ibus->engine_list);
|
2011-03-10 09:07:52 +00:00
|
|
|
+#ifndef OS_CHROMEOS
|
|
|
|
+ gint preload_engine_mode = _get_config_preload_engine_mode (ibus);
|
|
|
|
|
2010-11-26 05:38:39 +00:00
|
|
|
- if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_ARRAY) {
|
|
|
|
- GVariantIter iter;
|
|
|
|
- g_variant_iter_init (&iter, value);
|
|
|
|
- const gchar *engine_name = NULL;
|
|
|
|
- while (g_variant_iter_loop (&iter, "&s", &engine_name)) {
|
|
|
|
- IBusEngineDesc *engine = bus_registry_find_engine_by_name (ibus->registry, engine_name);
|
|
|
|
- if (engine == NULL || g_list_find (engine_list, engine) != NULL)
|
|
|
|
- continue;
|
|
|
|
- engine_list = g_list_append (engine_list, engine);
|
|
|
|
+ if (preload_engine_mode == IBUS_PRELOAD_ENGINE_MODE_USER) {
|
|
|
|
+ if (value == NULL) {
|
|
|
|
+ _set_language_relative_preload_engines (ibus);
|
|
|
|
+ } else {
|
|
|
|
+ _set_preload_engines (ibus, value);
|
|
|
|
}
|
|
|
|
}
|
2011-03-10 09:07:52 +00:00
|
|
|
+#else
|
|
|
|
+ _set_preload_engines (ibus, value);
|
|
|
|
+#endif
|
2010-11-26 05:38:39 +00:00
|
|
|
+}
|
|
|
|
|
|
|
|
- g_list_foreach (engine_list, (GFunc) g_object_ref, NULL);
|
|
|
|
- ibus->engine_list = engine_list;
|
2011-03-10 09:07:52 +00:00
|
|
|
+/**
|
|
|
|
+ * bus_ibus_impl_set_preload_engine_mode:
|
|
|
|
+ *
|
2011-06-21 08:49:07 +00:00
|
|
|
+ * A function to be called when "preload_engine_mode" config is updated.
|
2011-03-10 09:07:52 +00:00
|
|
|
+ */
|
2010-11-26 05:38:39 +00:00
|
|
|
+static void
|
|
|
|
+bus_ibus_impl_set_preload_engine_mode (BusIBusImpl *ibus,
|
|
|
|
+ GVariant *value)
|
|
|
|
+{
|
2011-03-10 09:07:52 +00:00
|
|
|
+#ifndef OS_CHROMEOS
|
2011-06-21 08:49:07 +00:00
|
|
|
+ gint preload_engine_mode = IBUS_PRELOAD_ENGINE_MODE_USER;
|
2010-11-26 05:38:39 +00:00
|
|
|
|
|
|
|
- if (ibus->engine_list) {
|
|
|
|
- BusComponent *component = bus_component_from_engine_desc ((IBusEngineDesc *) ibus->engine_list->data);
|
|
|
|
- if (component && !bus_component_is_running (component)) {
|
|
|
|
- bus_component_start (component, g_verbose);
|
|
|
|
- }
|
2011-03-11 09:23:28 +00:00
|
|
|
+ /* bus_ibus_impl_reload_config() sets value = NULL.
|
|
|
|
+ * bus_ibus_impl_reload_config() is always called when
|
|
|
|
+ * RequestName signal is sent so it is good to get the gconf value
|
|
|
|
+ * again when value == NULL.
|
|
|
|
+ */
|
2010-11-26 05:38:39 +00:00
|
|
|
+ if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_INT32) {
|
|
|
|
+ preload_engine_mode = g_variant_get_int32 (value);
|
2011-03-11 09:23:28 +00:00
|
|
|
+ } else {
|
|
|
|
+ preload_engine_mode = _get_config_preload_engine_mode (ibus);
|
2010-11-26 05:38:39 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 03:14:20 +00:00
|
|
|
- bus_ibus_impl_check_global_engine (ibus);
|
2010-11-26 05:38:39 +00:00
|
|
|
- bus_ibus_impl_update_engines_hotkey_profile (ibus);
|
|
|
|
+ if (preload_engine_mode == IBUS_PRELOAD_ENGINE_MODE_USER) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _set_language_relative_preload_engines (ibus);
|
2011-03-10 09:07:52 +00:00
|
|
|
+#endif
|
2010-11-12 09:51:00 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 05:38:39 +00:00
|
|
|
/**
|
2011-06-21 08:49:07 +00:00
|
|
|
@@ -503,89 +774,47 @@ bus_ibus_impl_set_use_global_engine (BusIBusImpl *ibus,
|
2010-11-26 05:38:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-04 18:06:02 +00:00
|
|
|
-#ifndef OS_CHROMEOS
|
2010-11-26 05:38:39 +00:00
|
|
|
-static gint
|
|
|
|
-_engine_desc_cmp (IBusEngineDesc *desc1,
|
|
|
|
- IBusEngineDesc *desc2)
|
|
|
|
-{
|
|
|
|
- return - ((gint) ibus_engine_desc_get_rank (desc1)) +
|
|
|
|
- ((gint) ibus_engine_desc_get_rank (desc2));
|
|
|
|
-}
|
2011-02-04 18:06:02 +00:00
|
|
|
-#endif
|
2010-11-26 05:38:39 +00:00
|
|
|
-
|
|
|
|
/**
|
|
|
|
* bus_ibus_impl_set_default_preload_engines:
|
|
|
|
*
|
2011-03-10 09:07:52 +00:00
|
|
|
- * If the "preload_engines" config variable is not set yet, set the default value which is determined based on a current locale.
|
2010-11-26 05:38:39 +00:00
|
|
|
+ * bus_ibus_impl_set_default_preload_engines handles the gconf value
|
2010-11-12 09:51:00 +00:00
|
|
|
+ * /desktop/ibus/general/preload_engines and preload_engine_mode.
|
|
|
|
+ * The idea is, if users don't customize the preload_engines with ibus-setup,
|
|
|
|
+ * users would prefer to load the system default engines again by login.
|
|
|
|
+ * The gconf value 'preload_engine_mode' is
|
2011-06-21 08:49:07 +00:00
|
|
|
+ * IBUS_PRELOAD_ENGINE_MODE_USER by default but set
|
|
|
|
+ * IBUS_PRELOAD_ENGINE_MODE_LANG_RELATIVE for the initial login.
|
2010-11-12 09:51:00 +00:00
|
|
|
+ * If preload_engine_mode is IBUS_PRELOAD_ENGINE_MODE_LANG_RELATIVE,
|
|
|
|
+ * ibus-daemon loads the system preload engines by langs.
|
|
|
|
+ * If preload_engine_mode is IBUS_PRELOAD_ENGINE_MODE_USER,
|
|
|
|
+ * ibus-daemon do not update the gconf value preload_engines.
|
|
|
|
+ * On the other hand, if users enable the customized engine checkbutton
|
|
|
|
+ * on ibus-setup, ibus-setup sets 'preload_engine_mode' as
|
|
|
|
+ * IBUS_PRELOAD_ENGINE_MODE_USER and users can customize the value
|
|
|
|
+ * 'preload_engines'.
|
2010-11-26 05:38:39 +00:00
|
|
|
*/
|
2010-11-12 09:51:00 +00:00
|
|
|
static void
|
2010-11-26 05:38:39 +00:00
|
|
|
bus_ibus_impl_set_default_preload_engines (BusIBusImpl *ibus)
|
2010-11-12 09:51:00 +00:00
|
|
|
{
|
2011-02-04 18:06:02 +00:00
|
|
|
#ifndef OS_CHROMEOS
|
2010-11-26 05:38:39 +00:00
|
|
|
- g_assert (BUS_IS_IBUS_IMPL (ibus));
|
|
|
|
-
|
2010-11-12 09:51:00 +00:00
|
|
|
static gboolean done = FALSE;
|
2011-06-21 08:49:07 +00:00
|
|
|
+ gint preload_engine_mode = IBUS_PRELOAD_ENGINE_MODE_USER;
|
2010-11-26 05:38:39 +00:00
|
|
|
+
|
|
|
|
+ g_assert (BUS_IS_IBUS_IMPL (ibus));
|
2010-11-12 09:51:00 +00:00
|
|
|
|
2010-11-26 05:38:39 +00:00
|
|
|
if (done || ibus->config == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-12 09:51:00 +00:00
|
|
|
|
|
|
|
- GVariant *variant = ibus_config_get_value (ibus->config, "general", "preload_engines");
|
|
|
|
- if (variant != NULL) {
|
2010-11-26 05:38:39 +00:00
|
|
|
+ preload_engine_mode = _get_config_preload_engine_mode (ibus);
|
2010-11-12 09:51:00 +00:00
|
|
|
+
|
2010-11-26 05:38:39 +00:00
|
|
|
+ if (preload_engine_mode == IBUS_PRELOAD_ENGINE_MODE_USER) {
|
|
|
|
done = TRUE;
|
|
|
|
- g_variant_unref (variant);
|
|
|
|
return;
|
2010-11-12 09:51:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done = TRUE;
|
2011-03-10 09:07:52 +00:00
|
|
|
-
|
|
|
|
- /* The setlocale call first checks LC_ALL. If it's not available, checks
|
|
|
|
- * LC_CTYPE. If it's also not available, checks LANG. */
|
|
|
|
- gchar *lang = g_strdup (setlocale (LC_CTYPE, NULL));
|
|
|
|
- if (lang == NULL) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
2010-11-26 05:38:39 +00:00
|
|
|
- gchar *p = index (lang, '.');
|
|
|
|
- if (p) {
|
|
|
|
- *p = '\0';
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- GList *engines = bus_registry_get_engines_by_language (ibus->registry, lang);
|
|
|
|
- if (engines == NULL) {
|
|
|
|
- p = index (lang, '_');
|
|
|
|
- if (p) {
|
|
|
|
- *p = '\0';
|
|
|
|
- engines = bus_registry_get_engines_by_language (ibus->registry, lang);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- g_free (lang);
|
|
|
|
-
|
|
|
|
- /* sort engines by rank */
|
|
|
|
- engines = g_list_sort (engines, (GCompareFunc) _engine_desc_cmp);
|
|
|
|
-
|
|
|
|
- GVariantBuilder builder;
|
|
|
|
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
|
|
|
|
- GList *list;
|
|
|
|
- for (list = engines; list != NULL; list = list->next) {
|
|
|
|
- IBusEngineDesc *desc = (IBusEngineDesc *) list->data;
|
|
|
|
- /* ignore engines with rank <= 0 */
|
|
|
|
- if (ibus_engine_desc_get_rank (desc) > 0)
|
|
|
|
- g_variant_builder_add (&builder, "s", ibus_engine_desc_get_name (desc));
|
|
|
|
- }
|
2011-01-26 08:27:03 +00:00
|
|
|
-
|
|
|
|
- GVariant *value = g_variant_builder_end (&builder);
|
|
|
|
- if (value != NULL) {
|
|
|
|
- if (g_variant_n_children (value) > 0) {
|
|
|
|
- ibus_config_set_value (ibus->config,
|
|
|
|
- "general", "preload_engines", value);
|
|
|
|
- } else {
|
|
|
|
- /* We don't update preload_engines with an empty string for safety.
|
|
|
|
- * Just unref the floating value. */
|
|
|
|
- g_variant_unref (value);
|
|
|
|
- }
|
|
|
|
- }
|
2010-11-26 05:38:39 +00:00
|
|
|
- g_list_free (engines);
|
|
|
|
+ _set_language_relative_preload_engines (ibus);
|
2011-02-04 18:06:02 +00:00
|
|
|
#endif
|
2010-11-26 05:38:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 08:49:07 +00:00
|
|
|
@@ -601,6 +830,7 @@ const static struct {
|
2011-03-10 09:07:52 +00:00
|
|
|
{ "general/hotkey", "next_engine_in_menu", bus_ibus_impl_set_next_engine_in_menu },
|
|
|
|
{ "general/hotkey", "previous_engine", bus_ibus_impl_set_previous_engine },
|
|
|
|
{ "general", "preload_engines", bus_ibus_impl_set_preload_engines },
|
2011-06-21 08:49:07 +00:00
|
|
|
+ { "general", "preload_engine_mode", bus_ibus_impl_set_preload_engine_mode },
|
2011-03-10 09:07:52 +00:00
|
|
|
{ "general", "use_system_keyboard_layout", bus_ibus_impl_set_use_sys_layout },
|
|
|
|
{ "general", "use_global_engine", bus_ibus_impl_set_use_global_engine },
|
|
|
|
{ "general", "embed_preedit_text", bus_ibus_impl_set_embed_preedit_text },
|
2010-11-12 09:51:00 +00:00
|
|
|
diff --git a/data/ibus.schemas.in b/data/ibus.schemas.in
|
2011-06-21 08:49:07 +00:00
|
|
|
index 7ca4899..d4334e1 100644
|
2010-11-12 09:51:00 +00:00
|
|
|
--- a/data/ibus.schemas.in
|
|
|
|
+++ b/data/ibus.schemas.in
|
|
|
|
@@ -13,6 +13,19 @@
|
|
|
|
</locale>
|
|
|
|
</schema>
|
|
|
|
<schema>
|
|
|
|
+ <key>/schemas/desktop/ibus/general/preload_engine_mode</key>
|
|
|
|
+ <applyto>/desktop/ibus/general/preload_engine_mode</applyto>
|
|
|
|
+ <owner>ibus</owner>
|
|
|
|
+ <type>int</type>
|
2011-06-21 08:49:07 +00:00
|
|
|
+ <default>0</default>
|
2010-11-12 09:51:00 +00:00
|
|
|
+ <locale name="C">
|
|
|
|
+ <short>Preload engine mode</short>
|
|
|
|
+ <long>Preload engines are loaded with this mode.
|
2010-11-26 05:38:39 +00:00
|
|
|
+ 0 = user customized engines.
|
|
|
|
+ 1 = language related engines.</long>
|
2010-11-12 09:51:00 +00:00
|
|
|
+ </locale>
|
|
|
|
+ </schema>
|
|
|
|
+ <schema>
|
|
|
|
<key>/schemas/desktop/ibus/general/hotkey/trigger</key>
|
|
|
|
<applyto>/desktop/ibus/general/hotkey/trigger</applyto>
|
|
|
|
<owner>ibus</owner>
|
|
|
|
diff --git a/ibus/common.py b/ibus/common.py
|
2011-06-21 08:49:07 +00:00
|
|
|
index 6483aae..127ed93 100644
|
2010-11-12 09:51:00 +00:00
|
|
|
--- a/ibus/common.py
|
|
|
|
+++ b/ibus/common.py
|
2011-04-19 03:14:20 +00:00
|
|
|
@@ -40,6 +40,8 @@ __all__ = (
|
|
|
|
"BUS_REQUEST_NAME_REPLY_IN_QUEUE",
|
|
|
|
"BUS_REQUEST_NAME_REPLY_EXISTS",
|
|
|
|
"BUS_REQUEST_NAME_REPLY_ALREADY_OWNER",
|
2010-11-26 05:38:39 +00:00
|
|
|
+ "PRELOAD_ENGINE_MODE_USER",
|
|
|
|
+ "PRELOAD_ENGINE_MODE_LANG_RELATIVE",
|
|
|
|
"default_reply_handler",
|
|
|
|
"default_error_handler",
|
|
|
|
"DEFAULT_ASYNC_HANDLERS",
|
2011-04-19 03:14:20 +00:00
|
|
|
@@ -150,6 +152,10 @@ BUS_REQUEST_NAME_REPLY_IN_QUEUE = 2
|
|
|
|
BUS_REQUEST_NAME_REPLY_EXISTS = 3
|
|
|
|
BUS_REQUEST_NAME_REPLY_ALREADY_OWNER = 4
|
2010-11-12 09:51:00 +00:00
|
|
|
|
|
|
|
+# define preload engine mode
|
2010-11-26 05:38:39 +00:00
|
|
|
+PRELOAD_ENGINE_MODE_USER = 0
|
|
|
|
+PRELOAD_ENGINE_MODE_LANG_RELATIVE = 1
|
2010-11-12 09:51:00 +00:00
|
|
|
+
|
|
|
|
def default_reply_handler( *args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
diff --git a/setup/main.py b/setup/main.py
|
2011-06-21 08:49:07 +00:00
|
|
|
index 7f4a040..192fb88 100644
|
2010-11-12 09:51:00 +00:00
|
|
|
--- a/setup/main.py
|
|
|
|
+++ b/setup/main.py
|
2011-06-21 08:49:07 +00:00
|
|
|
@@ -92,6 +92,7 @@ class Setup(object):
|
|
|
|
# keyboard shortcut
|
|
|
|
# trigger
|
|
|
|
self.__config = self.__bus.get_config()
|
|
|
|
+ self.__config.connect("value-changed", self.__config_value_changed_cb)
|
|
|
|
shortcuts = self.__config.get_value(
|
|
|
|
"general/hotkey", "trigger",
|
|
|
|
ibus.CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT)
|
|
|
|
@@ -213,15 +214,22 @@ class Setup(object):
|
2010-11-12 09:51:00 +00:00
|
|
|
self.__checkbutton_use_global_engine.connect("toggled", self.__checkbutton_use_global_engine_toggled_cb)
|
|
|
|
|
|
|
|
# init engine page
|
|
|
|
+ preload_engine_mode = self.__config.get_value("general",
|
|
|
|
+ "preload_engine_mode",
|
2010-11-26 05:38:39 +00:00
|
|
|
+ ibus.common.PRELOAD_ENGINE_MODE_USER)
|
2010-11-12 09:51:00 +00:00
|
|
|
+ button = self.__builder.get_object("checkbutton_preload_engine_mode")
|
|
|
|
+ if preload_engine_mode == ibus.common.PRELOAD_ENGINE_MODE_USER:
|
|
|
|
+ button.set_active(True)
|
|
|
|
+ self.__builder.get_object("hbox_customize_active_input_methods").set_sensitive(True)
|
|
|
|
+ else:
|
|
|
|
+ button.set_active(False)
|
|
|
|
+ self.__builder.get_object("hbox_customize_active_input_methods").set_sensitive(False)
|
|
|
|
+ button.connect("toggled", self.__checkbutton_preload_engine_mode_toggled_cb)
|
|
|
|
self.__engines = self.__bus.list_engines()
|
|
|
|
self.__combobox = self.__builder.get_object("combobox_engines")
|
|
|
|
self.__combobox.set_engines(self.__engines)
|
|
|
|
|
|
|
|
- tmp_dict = {}
|
|
|
|
- for e in self.__engines:
|
|
|
|
- tmp_dict[e.name] = e
|
2010-11-26 05:38:39 +00:00
|
|
|
- engine_names = self.__config.get_value("general", "preload_engines", [])
|
2010-11-12 09:51:00 +00:00
|
|
|
- engines = [tmp_dict[name] for name in engine_names if name in tmp_dict]
|
2010-11-26 05:38:39 +00:00
|
|
|
+ engines = self.__bus.list_active_engines()
|
2010-11-12 09:51:00 +00:00
|
|
|
|
|
|
|
self.__treeview = self.__builder.get_object("treeview_engines")
|
|
|
|
self.__treeview.set_engines(engines)
|
2011-06-21 08:49:07 +00:00
|
|
|
@@ -265,6 +273,26 @@ class Setup(object):
|
2010-11-12 09:51:00 +00:00
|
|
|
engine_names = map(lambda e: e.name, engines)
|
|
|
|
self.__config.set_list("general", "preload_engines", engine_names, "s")
|
|
|
|
|
|
|
|
+ def __get_engine_descs_from_names(self, engine_names):
|
|
|
|
+ tmp_dict = {}
|
|
|
|
+ for e in self.__engines:
|
|
|
|
+ tmp_dict[e.name] = e
|
|
|
|
+ engines = [tmp_dict[name] for name in engine_names if name in tmp_dict]
|
|
|
|
+ return engines
|
2011-06-21 08:49:07 +00:00
|
|
|
+
|
|
|
|
+ def __compare_descs(self, engines_a, engines_b):
|
|
|
|
+ engines = engines_a
|
|
|
|
+ concat_engine_names = ""
|
|
|
|
+ for engine in engines:
|
|
|
|
+ concat_engine_names = "%s::%s" % (concat_engine_names, engine.name)
|
|
|
|
+ concat_engine_names_a = concat_engine_names
|
|
|
|
+ engines = engines_b
|
|
|
|
+ concat_engine_names = ""
|
|
|
|
+ for engine in engines:
|
|
|
|
+ concat_engine_names = "%s::%s" % (concat_engine_names, engine.name)
|
|
|
|
+ concat_engine_names_b = concat_engine_names
|
|
|
|
+ return concat_engine_names_a == concat_engine_names_b
|
2010-11-12 09:51:00 +00:00
|
|
|
+
|
|
|
|
def __button_engine_add_cb(self, button):
|
|
|
|
engine = self.__combobox.get_active_engine()
|
|
|
|
self.__treeview.append_engine(engine)
|
2011-06-21 08:49:07 +00:00
|
|
|
@@ -276,6 +304,32 @@ class Setup(object):
|
2010-11-12 09:51:00 +00:00
|
|
|
about.run()
|
|
|
|
about.destroy()
|
|
|
|
|
|
|
|
+ def __checkbutton_preload_engine_mode_toggled_cb(self, button):
|
|
|
|
+ if button.get_active():
|
|
|
|
+ self.__config.set_value("general",
|
|
|
|
+ "preload_engine_mode",
|
|
|
|
+ ibus.common.PRELOAD_ENGINE_MODE_USER)
|
|
|
|
+ self.__builder.get_object("hbox_customize_active_input_methods").set_sensitive(True)
|
2010-11-26 05:38:39 +00:00
|
|
|
+ self.__treeview.notify("engines")
|
2010-11-12 09:51:00 +00:00
|
|
|
+ else:
|
2011-06-21 08:49:07 +00:00
|
|
|
+ message = _("The list of your saved input methods will be " \
|
|
|
|
+ "cleared immediately and the list will be " \
|
|
|
|
+ "configured by the login language every time. " \
|
|
|
|
+ "Do you agree with this?")
|
|
|
|
+ dlg = gtk.MessageDialog(type = gtk.MESSAGE_QUESTION,
|
|
|
|
+ buttons = gtk.BUTTONS_YES_NO,
|
|
|
|
+ message_format = message)
|
|
|
|
+ id = dlg.run()
|
|
|
|
+ dlg.destroy()
|
|
|
|
+ self.__flush_gtk_events()
|
|
|
|
+ if id != gtk.RESPONSE_YES:
|
|
|
|
+ button.set_active(True)
|
|
|
|
+ return
|
2010-11-12 09:51:00 +00:00
|
|
|
+ self.__config.set_value("general",
|
|
|
|
+ "preload_engine_mode",
|
|
|
|
+ ibus.common.PRELOAD_ENGINE_MODE_LANG_RELATIVE)
|
|
|
|
+ self.__builder.get_object("hbox_customize_active_input_methods").set_sensitive(False)
|
|
|
|
+
|
|
|
|
def __init_bus(self):
|
|
|
|
try:
|
|
|
|
self.__bus = ibus.Bus()
|
2011-06-21 08:49:07 +00:00
|
|
|
@@ -466,7 +520,11 @@ class Setup(object):
|
|
|
|
self.__config.set_value("general", "use_global_engine", value)
|
|
|
|
|
|
|
|
def __config_value_changed_cb(self, bus, section, name, value):
|
|
|
|
- pass
|
|
|
|
+ if section == 'general' and name == 'preload_engines':
|
|
|
|
+ engines = self.__get_engine_descs_from_names(value)
|
|
|
|
+ current_engines = self.__treeview.get_engines()
|
|
|
|
+ if self.__compare_descs(engines, current_engines) == False:
|
|
|
|
+ self.__treeview.set_engines(engines)
|
|
|
|
|
|
|
|
def __config_reloaded_cb(self, bus):
|
|
|
|
pass
|
2010-11-12 09:51:00 +00:00
|
|
|
diff --git a/setup/setup.ui b/setup/setup.ui
|
2011-03-11 09:23:28 +00:00
|
|
|
index f1e6d0b..562c091 100644
|
2010-11-12 09:51:00 +00:00
|
|
|
--- a/setup/setup.ui
|
|
|
|
+++ b/setup/setup.ui
|
2011-03-10 09:07:52 +00:00
|
|
|
@@ -582,7 +582,22 @@
|
2010-11-12 09:51:00 +00:00
|
|
|
<property name="visible">True</property>
|
|
|
|
<property name="orientation">vertical</property>
|
|
|
|
<child>
|
|
|
|
- <object class="GtkHBox" id="hbox1">
|
|
|
|
+ <object class="GtkCheckButton" id="checkbutton_preload_engine_mode">
|
|
|
|
+ <property name="visible">True</property>
|
|
|
|
+ <property name="label" translatable="yes">Customize active input _methods</property>
|
|
|
|
+ <property name="use_underline">True</property>
|
|
|
|
+ <property name="can_focus">True</property>
|
|
|
|
+ <property name="receives_default">False</property>
|
|
|
|
+ <property name="tooltip_text" translatable="yes">Customize active input methods</property>
|
|
|
|
+ <property name="draw_indicator">True</property>
|
|
|
|
+ </object>
|
|
|
|
+ <packing>
|
|
|
|
+ <property name="expand">False</property>
|
|
|
|
+ <property name="position">0</property>
|
|
|
|
+ </packing>
|
|
|
|
+ </child>
|
|
|
|
+ <child>
|
|
|
|
+ <object class="GtkHBox" id="hbox_customize_active_input_methods">
|
|
|
|
<property name="visible">True</property>
|
|
|
|
<child>
|
|
|
|
<object class="GtkAlignment" id="alignment6">
|
2011-03-10 09:07:52 +00:00
|
|
|
@@ -733,7 +748,7 @@
|
2010-11-12 09:51:00 +00:00
|
|
|
</child>
|
|
|
|
</object>
|
|
|
|
<packing>
|
|
|
|
- <property name="position">0</property>
|
|
|
|
+ <property name="position">1</property>
|
|
|
|
</packing>
|
|
|
|
</child>
|
|
|
|
<child>
|
2011-03-10 09:07:52 +00:00
|
|
|
@@ -772,7 +787,7 @@ You may use up/down buttons to change it.</i></small></property>
|
2010-11-12 09:51:00 +00:00
|
|
|
</object>
|
|
|
|
<packing>
|
|
|
|
<property name="expand">False</property>
|
|
|
|
- <property name="position">1</property>
|
|
|
|
+ <property name="position">2</property>
|
|
|
|
</packing>
|
|
|
|
</child>
|
|
|
|
</object>
|
|
|
|
diff --git a/src/ibustypes.h b/src/ibustypes.h
|
2011-06-21 08:49:07 +00:00
|
|
|
index 6a31847..14b44fc 100644
|
2010-11-12 09:51:00 +00:00
|
|
|
--- a/src/ibustypes.h
|
|
|
|
+++ b/src/ibustypes.h
|
2011-06-21 08:49:07 +00:00
|
|
|
@@ -186,6 +186,16 @@ typedef enum {
|
|
|
|
} IBusError;
|
2010-11-12 09:51:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
+ * IBusPreloadEngineMode:
|
|
|
|
+ * @IBUS_PRELOAD_ENGINE_MODE_USER: user custimized engines
|
2010-11-26 05:38:39 +00:00
|
|
|
+ * @IBUS_PRELOAD_ENGINE_MODE_LANG_RELATIVE: language related engines.
|
2010-11-12 09:51:00 +00:00
|
|
|
+ */
|
|
|
|
+typedef enum {
|
2010-11-26 05:38:39 +00:00
|
|
|
+ IBUS_PRELOAD_ENGINE_MODE_USER = 0,
|
|
|
|
+ IBUS_PRELOAD_ENGINE_MODE_LANG_RELATIVE = 1,
|
2010-11-12 09:51:00 +00:00
|
|
|
+} IBusPreloadEngineMode;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
* IBusRectangle:
|
|
|
|
* @x: x coordinate.
|
|
|
|
* @y: y coordinate.
|
|
|
|
--
|
2011-06-21 08:49:07 +00:00
|
|
|
1.7.4.4
|
2010-11-12 09:51:00 +00:00
|
|
|
|