summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2009-02-24 16:28:22 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2009-02-24 16:28:22 +0800
commitdb492c157773af0a932ca1fe6b9a6b8b977e6194 (patch)
treeeffc9574964a337e8b4e51b0fa78e2314807c422
parent0ea4adadcba4a81bfca597d6aa587d461c3c6644 (diff)
downloadibus-db492c157773af0a932ca1fe6b9a6b8b977e6194.tar.gz
ibus-db492c157773af0a932ca1fe6b9a6b8b977e6194.tar.xz
ibus-db492c157773af0a932ca1fe6b9a6b8b977e6194.zip
Enable default engines by locale name.
-rw-r--r--bus/ibusimpl.c57
-rw-r--r--bus/registry.c28
-rw-r--r--bus/registry.h3
3 files changed, 88 insertions, 0 deletions
diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c
index c52907e..91db048 100644
--- a/bus/ibusimpl.c
+++ b/bus/ibusimpl.c
@@ -23,6 +23,8 @@
#include <sys/wait.h>
#include <signal.h>
#include <stdlib.h>
+#include <locale.h>
+#include <strings.h>
#include "ibusimpl.h"
#include "dbusimpl.h"
#include "server.h"
@@ -228,6 +230,60 @@ bus_ibus_impl_set_preload_engines (BusIBusImpl *ibus,
}
static void
+bus_ibus_impl_set_default_preload_engines (BusIBusImpl *ibus)
+{
+ g_assert (BUS_IS_IBUS_IMPL (ibus));
+
+ static gboolean done = FALSE;
+ GValue value = { 0 };
+ GList *engines, *l;
+ gchar *lang, *p;
+ GValueArray *array;
+
+ if (done || ibus->config == NULL) {
+ return;
+ }
+
+ if (ibus_config_get_value (ibus->config, "general", "preload_engines", &value)) {
+ done = TRUE;
+ g_value_unset (&value);
+ return;
+ }
+
+ done = TRUE;
+ lang = g_strdup (setlocale (LC_ALL, NULL));
+ 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);
+
+ g_value_init (&value, G_TYPE_VALUE_ARRAY);
+ array = g_value_array_new (5);
+ for (l = engines; l != NULL; l = l->next) {
+ IBusEngineDesc *desc;
+ GValue name = { 0 };
+ desc = (IBusEngineDesc *)l->data;
+ g_value_init (&name, G_TYPE_STRING);
+ g_value_set_string (&name, desc->name);
+ g_value_array_append (array, &name);
+ }
+ g_value_take_boxed (&value, array);
+ ibus_config_set_value (ibus->config, "general", "preload_engines", &value);
+ g_value_unset (&value);
+ g_list_free (engines);
+}
+
+static void
bus_ibus_impl_reload_config (BusIBusImpl *ibus)
{
g_assert (BUS_IS_IBUS_IMPL (ibus));
@@ -378,6 +434,7 @@ _dbus_name_owner_changed_cb (BusDBusImpl *dbus,
G_CALLBACK (_config_destroy_cb),
ibus);
+ bus_ibus_impl_set_default_preload_engines (ibus);
bus_ibus_impl_reload_config (ibus);
}
}
diff --git a/bus/registry.c b/bus/registry.c
index 13e1cdf..65488da 100644
--- a/bus/registry.c
+++ b/bus/registry.c
@@ -20,6 +20,7 @@
#include <glib/gstdio.h>
#include <gio/gio.h>
#include <stdlib.h>
+#include <string.h>
#include "registry.h"
enum {
@@ -403,6 +404,33 @@ bus_registry_get_engines (BusRegistry *registry)
}
+GList *
+bus_registry_get_engines_by_language (BusRegistry *registry,
+ const gchar *language)
+{
+ g_assert (BUS_IS_REGISTRY (registry));
+ g_assert (language);
+
+ gint n;
+ GList *p1, *p2, *engines;
+
+ n = strlen (language);
+
+ p1 = bus_registry_get_engines (registry);
+
+ engines = NULL;
+
+ for (p2 = p1; p2 != NULL; p2 = p2->next) {
+ IBusEngineDesc *desc = (IBusEngineDesc *) p2->data;
+ if (strncmp (desc->language, language, n) == 0) {
+ engines = g_list_append (engines, desc);
+ }
+ }
+
+ g_list_free (p1);
+ return engines;
+}
+
IBusEngineDesc *
bus_registry_find_engine_by_name (BusRegistry *registry,
const gchar *name)
diff --git a/bus/registry.h b/bus/registry.h
index 377ac45..fb4078d 100644
--- a/bus/registry.h
+++ b/bus/registry.h
@@ -67,6 +67,9 @@ GType bus_registry_get_type (void);
BusRegistry *bus_registry_new (void);
GList *bus_registry_get_components (BusRegistry *registry);
GList *bus_registry_get_engines (BusRegistry *registry);
+GList *bus_registry_get_engines_by_language
+ (BusRegistry *registry,
+ const gchar *language);
void bus_registry_stop_all_components
(BusRegistry *registry);