Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate IBusConfig to GSettings #56

Merged
merged 1 commit into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions data/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
51 changes: 51 additions & 0 deletions data/org.freedesktop.ibus.engine.hangul.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema path="/org/freedesktop/ibus/engine/hangul/"
id="org.freedesktop.ibus.engine.hangul">
<key name="hangul-keyboard" type="s">
<default>'2'</default>
<summary>Hangul keyboard</summary>
<description></description>
</key>
<key name="initial-input-mode" type="s">
<default>'latin'</default>
<summary>Initial input mode</summary>
<description></description>
</key>
<key name="word-commit" type="b">
<default>false</default>
<summary>Word commit</summary>
<description></description>
</key>
<key name="auto-reorder" type="b">
<default>true</default>
<summary>Auto reorder</summary>
<description></description>
</key>
<key name="switch-keys" type="s">
<default>'Hangul,Shift+space'</default>
<summary>Switch keys</summary>
<description></description>
</key>
<key name="hanja-keys" type="s">
<default>'Hangul_Hanja,F9'</default>
<summary>Hanja keys</summary>
<description></description>
</key>
<key name="on-keys" type="s">
<default>''</default>
<summary>On keys</summary>
<description></description>
</key>
<key name="off-keys" type="s">
<default>''</default>
<summary>Off keys</summary>
<description></description>
</key>
<key name="disable-latin-mode" type="b">
<default>false</default>
<summary>Disable Latin mode</summary>
<description></description>
</key>
</schema>
</schemalist>
62 changes: 27 additions & 35 deletions setup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -76,26 +77,22 @@ def __init__ (self, bus):
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")
Expand All @@ -106,8 +103,7 @@ def __init__ (self, bus):

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])
Expand All @@ -130,8 +126,7 @@ def __init__ (self, bus):

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])
Expand Down Expand Up @@ -270,27 +265,24 @@ def on_hanja_key_remove(self, widget, data = None):
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)
Expand Down
Loading