From 1687467cd782077a9b9aa1a0549f6b465efab8c6 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Fri, 20 Apr 2018 13:44:43 +0900 Subject: Migrate IBusConfig to GSettings IBus plans to deprecate IBusConfig and suggests to migrate to GSettings. https://groups.google.com/forum/#!topic/ibus-devel/Mu1IoFX-bKE https://github.com/choehwanjin/ibus-hangul/issues/51 --- data/Makefile.am | 19 ++++ .../org.freedesktop.ibus.engine.hangul.gschema.xml | 51 +++++++++ setup/main.py | 62 +++++----- src/engine.c | 125 +++++++++++---------- 4 files changed, 161 insertions(+), 96 deletions(-) create mode 100644 data/org.freedesktop.ibus.engine.hangul.gschema.xml diff --git a/data/Makefile.am b/data/Makefile.am index 1900137..96a6b6b 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -19,12 +19,31 @@ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA +schemas_DATA = \ + org.freedesktop.ibus.engine.hangul.gschema.xml + $(NULL) + +schemasdir = $(datadir)/glib-2.0/schemas + symboltable_DATA = \ symbol.txt \ $(NULL) symboltabledir = $(datadir)/ibus-hangul/data +install-data-hook: + if test -z "$(DESTDIR)"; then \ + glib-compile-schemas $(schemasdir); \ + fi + +uninstall-hook: + SCHEMAS_FILES=`ls $(schemasdir)/*.gschema.xml` || true; \ + if test -z "$$SCHEMAS_FILES" && \ + test -f $(schemasdir)/gschemas.compiled; then \ + rm $(schemasdir)/gschemas.compiled; \ + fi + EXTRA_DIST = \ + $(schemas_DATA) \ $(symboltable_DATA) \ $(NULL) diff --git a/data/org.freedesktop.ibus.engine.hangul.gschema.xml b/data/org.freedesktop.ibus.engine.hangul.gschema.xml new file mode 100644 index 0000000..9f65a74 --- /dev/null +++ b/data/org.freedesktop.ibus.engine.hangul.gschema.xml @@ -0,0 +1,51 @@ + + + + + '2' + Hangul keyboard + + + + 'latin' + Initial input mode + + + + false + Word commit + + + + true + Auto reorder + + + + 'Hangul,Shift+space' + Switch keys + + + + 'Hangul_Hanja,F9' + Hanja keys + + + + '' + On keys + + + + '' + Off keys + + + + false + Disable Latin mode + + + + diff --git a/setup/main.py b/setup/main.py index 90573e3..dae7234 100644 --- a/setup/main.py +++ b/setup/main.py @@ -20,6 +20,7 @@ import sys import os +from gi.repository import Gio from gi.repository import GLib from gi.repository import Gtk from gi.repository import IBus @@ -53,8 +54,8 @@ def get_hangul_keyboard_list(): class Setup (): def __init__ (self, bus): self.__bus = bus - self.__config = self.__bus.get_config() - self.__config.connect("value-changed", self.on_value_changed, None) + self.__settings = Gio.Settings(schema="org.freedesktop.ibus.engine.hangul") + self.__settings.connect("changed", self.on_value_changed) ui_file = os.path.join(os.path.dirname(__file__), "setup.ui") self.__builder = Gtk.Builder() @@ -76,26 +77,22 @@ class Setup (): self.__hangul_keyboard.pack_start(renderer, True) self.__hangul_keyboard.add_attribute(renderer, "text", 0) - default = GLib.Variant.new_string("2") - current = self.__read("hangul-keyboard", default).get_string() + current = self.__read("hangul-keyboard").get_string() for i in model: if i[1] == current: self.__hangul_keyboard.set_active(i[2]) break self.__start_in_hangul_mode = self.__builder.get_object("StartInHangulMode") - default = GLib.Variant.new_string("latin") - initial_input_mode = self.__read("initial-input-mode", default).get_string() + initial_input_mode = self.__read("initial-input-mode").get_string() self.__start_in_hangul_mode.set_active(initial_input_mode == "hangul") self.__word_commit = self.__builder.get_object("WordCommit") - default = GLib.Variant.new_boolean(False) - word_commit = self.__read("word-commit", default).get_boolean() + word_commit = self.__read("word-commit").get_boolean() self.__word_commit.set_active(word_commit) self.__auto_reorder = self.__builder.get_object("AutoReorder") - default = GLib.Variant.new_boolean(True) - auto_reorder = self.__read("auto-reorder", default).get_boolean() + auto_reorder = self.__read("auto-reorder").get_boolean() self.__auto_reorder.set_active(auto_reorder) button = self.__builder.get_object("HangulKeyListAddButton") @@ -106,8 +103,7 @@ class Setup (): model = Gtk.ListStore(str) - default = GLib.Variant.new_string("Hangul,Shift+space") - keylist_str = self.__read("switch-keys", default).get_string() + keylist_str = self.__read("switch-keys").get_string() self.__hangul_key_list_str = keylist_str.split(',') for i in self.__hangul_key_list_str: model.append([i]) @@ -130,8 +126,7 @@ class Setup (): model = Gtk.ListStore(str) - default = GLib.Variant.new_string("Hangul_Hanja,F9") - keylist_str = self.__read("hanja-keys", default).get_string() + keylist_str = self.__read("hanja-keys").get_string() self.__hanja_key_list_str = keylist_str.split(',') for i in self.__hanja_key_list_str: model.append([i]) @@ -270,27 +265,24 @@ class Setup (): if model and iter: model.remove(iter) - def on_value_changed(self, config, section, name, value, data): - if section == "engine/Hangul": - if name == "hangul-keyboard": - model = self.__hangul_keyboard.get_model() - for i in model: - if i[1] == value: - self.__hangul_keyboard.set_active(i[2]) - break - elif name == "switch-keys": - self.__hangul_key_list_str = value.split(',') - elif name == "hanja-keys": - self.__hanja_key_list_str = value.split(',') - - def __read(self, name, v): - value = self.__config.get_value("engine/hangul", name) - if value is None: - return v - return value - - def __write(self, name, v): - return self.__config.set_value("engine/Hangul", name, v) + def on_value_changed(self, settings, key): + value = settings.get_value(key) + if key == "hangul-keyboard": + model = self.__hangul_keyboard.get_model() + for i in model: + if i[1] == value.get_string(): + self.__hangul_keyboard.set_active(i[2]) + break + elif key == "switch-keys": + self.__hangul_key_list_str = value.get_string().split(',') + elif key == "hanja-keys": + self.__hanja_key_list_str = value.get_string().split(',') + + def __read(self, key): + return self.__settings.get_value(key) + + def __write(self, key, v): + self.__settings.set_value(key, v) if __name__ == "__main__": locale.bindtextdomain(config.gettext_package, config.localedir) diff --git a/src/engine.c b/src/engine.c index 04bcc1b..640b407 100644 --- a/src/engine.c +++ b/src/engine.c @@ -23,6 +23,7 @@ #endif #include +#include #include #include #include @@ -163,10 +164,8 @@ static bool ibus_hangul_engine_on_transition const ucschar *preedit, void *data); -static void ibus_config_value_changed (IBusConfig *config, - const gchar *section, - const gchar *name, - GVariant *value, +static void settings_changed (GSettings *settings, + const gchar *key, gpointer user_data); static void lookup_table_set_visible (IBusLookupTable *table, @@ -196,7 +195,8 @@ static glong ucschar_strlen (const ucschar* str); static IBusEngineClass *parent_class = NULL; static HanjaTable *hanja_table = NULL; static HanjaTable *symbol_table = NULL; -static IBusConfig *config = NULL; +static GSettings *settings_hangul = NULL; +static GSettings *settings_panel = NULL; static GString *hangul_keyboard = NULL; static HotkeyList hanja_keys; static HotkeyList switch_keys; @@ -248,90 +248,82 @@ ibus_hangul_engine_get_type (void) void ibus_hangul_init (IBusBus *bus) { - GVariant* value; + GVariant* value = NULL; hanja_table = hanja_table_load (NULL); symbol_table = hanja_table_load (IBUSHANGUL_DATADIR "/data/symbol.txt"); - config = ibus_bus_get_config (bus); - if (config) - g_object_ref_sink (config); + settings_hangul = g_settings_new ("org.freedesktop.ibus.engine.hangul"); + settings_panel = g_settings_new ("org.freedesktop.ibus.panel"); - hangul_keyboard = g_string_new_len ("2", 8); - value = ibus_config_get_value (config, "engine/hangul", - "hangul-keyboard"); + hangul_keyboard = g_string_new_len (NULL, 8); + value = g_settings_get_value (settings_hangul, "hangul-keyboard"); if (value != NULL) { const gchar* str = g_variant_get_string (value, NULL); g_string_assign (hangul_keyboard, str); - g_variant_unref(value); + g_clear_pointer (&value, g_variant_unref); } hotkey_list_init(&switch_keys); - value = ibus_config_get_value (config, "engine/hangul", - "switch-keys"); + value = g_settings_get_value (settings_hangul, "switch-keys"); if (value != NULL) { const gchar* str = g_variant_get_string (value, NULL); hotkey_list_set_from_string(&switch_keys, str); - g_variant_unref(value); + g_clear_pointer (&value, g_variant_unref); } else { - hotkey_list_append(&switch_keys, IBUS_Hangul, 0); - hotkey_list_append(&switch_keys, IBUS_space, IBUS_SHIFT_MASK); + hotkey_list_append(&switch_keys, IBUS_Hangul, 0); + hotkey_list_append(&switch_keys, IBUS_space, IBUS_SHIFT_MASK); } hotkey_list_init(&hanja_keys); - value = ibus_config_get_value (config, "engine/hangul", - "hanja-keys"); + value = g_settings_get_value (settings_hangul, "hanja-keys"); if (value != NULL) { const gchar* str = g_variant_get_string (value, NULL); hotkey_list_set_from_string(&hanja_keys, str); - g_variant_unref(value); + g_clear_pointer (&value, g_variant_unref); } else { - hotkey_list_append(&hanja_keys, IBUS_Hangul_Hanja, 0); - hotkey_list_append(&hanja_keys, IBUS_F9, 0); + hotkey_list_append(&hanja_keys, IBUS_Hangul_Hanja, 0); + hotkey_list_append(&hanja_keys, IBUS_F9, 0); } hotkey_list_init (&on_keys); - value = ibus_config_get_value (config, "engine/hangul", "on-keys"); + value = g_settings_get_value (settings_hangul, "on-keys"); if (value != NULL) { const gchar* str = g_variant_get_string (value, NULL); hotkey_list_set_from_string (&on_keys, str); - g_variant_unref (value); - } else { + g_clear_pointer (&value, g_variant_unref); } hotkey_list_init (&off_keys); - value = ibus_config_get_value (config, "engine/hangul", "off-keys"); + value = g_settings_get_value (settings_hangul, "off-keys"); if (value != NULL) { const gchar* str = g_variant_get_string (value, NULL); hotkey_list_set_from_string (&off_keys, str); - g_variant_unref (value); - } else { - hotkey_list_append (&off_keys, IBUS_KEY_Escape, 0); + g_clear_pointer (&value, g_variant_unref); } - value = ibus_config_get_value (config, "engine/hangul", - "word-commit"); + value = g_settings_get_value (settings_hangul, "word-commit"); if (value != NULL) { word_commit = g_variant_get_boolean (value); - g_variant_unref(value); + g_clear_pointer (&value, g_variant_unref); } - value = ibus_config_get_value (config, "engine/hangul", "auto-reorder"); + value = g_settings_get_value (settings_hangul, "auto-reorder"); if (value != NULL) { auto_reorder = g_variant_get_boolean (value); - g_variant_unref (value); + g_clear_pointer (&value, g_variant_unref); } - value = ibus_config_get_value (config, "engine/hangul", "disable-latin-mode"); + value = g_settings_get_value (settings_hangul, "disable-latin-mode"); if (value != NULL) { disable_latin_mode = g_variant_get_boolean (value); - g_variant_unref (value); + g_clear_pointer (&value, g_variant_unref); } - value = ibus_config_get_value (config, "engine/hangul", "initial-input-mode"); + value = g_settings_get_value (settings_hangul, "initial-input-mode"); if (value != NULL) { const gchar* str = g_variant_get_string (value, NULL); if (strcmp(str, "latin") == 0) { @@ -339,13 +331,13 @@ ibus_hangul_init (IBusBus *bus) } else if (strcmp(str, "hangul") == 0) { initial_input_mode = INPUT_MODE_HANGUL; } - g_variant_unref (value); + g_clear_pointer (&value, g_variant_unref); } - value = ibus_config_get_value (config, "panel", "lookup-table-orientation"); + value = g_settings_get_value (settings_panel, "lookup-table-orientation"); if (value != NULL) { lookup_table_orientation = g_variant_get_int32(value); - g_variant_unref (value); + g_clear_pointer (&value, g_variant_unref); } keymap = ibus_keymap_get("us"); @@ -370,8 +362,8 @@ ibus_hangul_exit (void) hanja_table_delete (symbol_table); symbol_table = NULL; - g_object_unref (config); - config = NULL; + g_clear_object (&settings_hangul); + g_clear_object (&settings_panel); g_string_free (hangul_keyboard, TRUE); hangul_keyboard = NULL; @@ -474,8 +466,10 @@ ibus_hangul_engine_init (IBusHangulEngine *hangul) hangul->table = ibus_lookup_table_new (9, 0, TRUE, FALSE); g_object_ref_sink (hangul->table); - g_signal_connect (config, "value-changed", - G_CALLBACK(ibus_config_value_changed), hangul); + g_signal_connect (settings_hangul, "changed", + G_CALLBACK (settings_changed), hangul); + g_signal_connect (settings_panel, "changed", + G_CALLBACK (settings_changed), hangul); } static GObject* @@ -1519,41 +1513,50 @@ ibus_hangul_engine_on_transition (HangulInputContext *hic, } static void -ibus_config_value_changed (IBusConfig *config, - const gchar *section, - const gchar *name, - GVariant *value, - gpointer user_data) +settings_changed (GSettings *settings, + const gchar *key, + gpointer user_data) { IBusHangulEngine *hangul = (IBusHangulEngine *) user_data; - - if (strcmp(section, "engine/hangul") == 0) { - if (strcmp(name, "hangul-keyboard") == 0) { + GValue schema_value = G_VALUE_INIT; + const gchar *schema_id; + GVariant *value; + + g_return_if_fail (G_IS_SETTINGS (settings)); + + g_value_init (&schema_value, G_TYPE_STRING); + g_object_get_property (G_OBJECT (settings), "schema-id", &schema_value); + schema_id = g_value_get_string (&schema_value); + value = g_settings_get_value (settings, key); + if (strcmp (schema_id, "org.freedesktop.ibus.engine.hangul") == 0) { + if (strcmp(key, "hangul-keyboard") == 0) { const gchar *str = g_variant_get_string(value, NULL); g_string_assign (hangul_keyboard, str); hangul_ic_select_keyboard (hangul->context, hangul_keyboard->str); - } else if (strcmp(name, "hanja-keys") == 0) { + } else if (strcmp (key, "hanja-keys") == 0) { const gchar* str = g_variant_get_string(value, NULL); hotkey_list_set_from_string(&hanja_keys, str); - } else if (strcmp(name, "word-commit") == 0) { + } else if (strcmp (key, "word-commit") == 0) { word_commit = g_variant_get_boolean (value); - } else if (strcmp (name, "auto-reorder") == 0) { + } else if (strcmp (key, "auto-reorder") == 0) { auto_reorder = g_variant_get_boolean (value); - } else if (strcmp (name, "switch-keys") == 0) { + } else if (strcmp (key, "switch-keys") == 0) { const gchar* str = g_variant_get_string(value, NULL); hotkey_list_set_from_string(&switch_keys, str); - } else if (strcmp (name, "on-keys") == 0) { + } else if (strcmp (key, "on-keys") == 0) { const gchar* str = g_variant_get_string(value, NULL); hotkey_list_set_from_string(&on_keys, str); - } else if (strcmp (name, "off-keys") == 0) { + } else if (strcmp (key, "off-keys") == 0) { const gchar* str = g_variant_get_string(value, NULL); hotkey_list_set_from_string(&off_keys, str); } - } else if (strcmp(section, "panel") == 0) { - if (strcmp(name, "lookup-table-orientation") == 0) { + } else if (strcmp (schema_id, "org.freedesktop.ibus.panel") == 0) { + if (strcmp (key, "lookup-table-orientation") == 0) { lookup_table_orientation = g_variant_get_int32(value); } } + g_variant_unref (value); + g_value_unset (&schema_value); } static void -- cgit v1.2.1