diff options
-rw-r--r-- | daemon/bus.py | 24 | ||||
-rw-r--r-- | daemon/config.py | 24 | ||||
-rw-r--r-- | daemon/ibusdaemon.py | 2 | ||||
-rw-r--r-- | gconf/config.py | 32 | ||||
-rw-r--r-- | ibus/bus.py | 20 | ||||
-rw-r--r-- | ibus/interface/iconfig.py | 12 | ||||
-rw-r--r-- | panel/panel.py | 23 | ||||
-rw-r--r-- | setup/main.py | 46 |
8 files changed, 86 insertions, 97 deletions
diff --git a/daemon/bus.py b/daemon/bus.py index b5b0363..9e7df96 100644 --- a/daemon/bus.py +++ b/daemon/bus.py @@ -60,13 +60,13 @@ class IBus(ibus.Object): self.__prev_key = None self.__shortcut_trigger = self.__load_config_shortcut( - ibus.CONFIG_GENERAL_SHORTCUT_TRIGGER, + "general", "keyboard_shortcut_trigger", ibus.CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT) self.__shortcut_next_engine = self.__load_config_shortcut( - ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, + "general", "keyboard_shortcut_next_engine", ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT) self.__shortcut_prev_engine = self.__load_config_shortcut( - ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, + "general", "keyboard_shortcut_next_engine", ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT) self.__default_factory = None @@ -79,14 +79,14 @@ class IBus(ibus.Object): self.__default_factory = factory if factory == None: return - self.__config.set_value("/general/default_engine", factory.get_object_path()) + self.__config.set_value("general", "default_engine", factory.get_object_path()) - def __load_config_shortcut(self, config_key, default_value): + def __load_config_shortcut(self, section, name, default_value): # load trigger shortcut_strings = default_value try: - shortcut_strings = self.__config.get_value(config_key) + shortcut_strings = self.__config.get_value(section, name) except: pass shortcuts = [] @@ -113,7 +113,7 @@ class IBus(ibus.Object): if self.__default_factory != None: return try: - factory_path = self.__config.get_value("/general/default_engine") + factory_path = self.__config.get_value("general", "default_engine") self.__default_factory = self.__factory_manager.get_factory(factory_path) except: pass @@ -476,11 +476,11 @@ class IBus(ibus.Object): map(lambda id:self.__config.disconnect(id), self.__config_handlers) self.__config_handlers = list() - def config_set_value(self, key, value, conn, **kargs): - return self.__config.set_value(key, value, **kargs) + def config_set_value(self, section, name, value, conn, **kargs): + return self.__config.set_value(section, name, value, **kargs) - def config_get_value(self, key, conn, **kargs): - return self.__config.get_value(key, **kargs) + def config_get_value(self, section, name, conn, **kargs): + return self.__config.get_value(section, name, **kargs) def config_add_watch(self, key, conn): if not key.endswith("/"): @@ -512,7 +512,7 @@ class IBus(ibus.Object): return keyval, keymask - def __config_value_changed_cb(self, config, key, value): + def __config_value_changed_cb(self, config, section, name, value): for _dir in self.__config_watch.keys(): if key.startswith(_dir): for conn in self.__config_watch[_dir]: diff --git a/daemon/config.py b/daemon/config.py index 4c719fe..7695fde 100644 --- a/daemon/config.py +++ b/daemon/config.py @@ -33,7 +33,7 @@ class Config(ibus.Object): "value-changed" : ( gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)), + (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)), } def __init__(self, ibusconn, object_path): @@ -45,11 +45,11 @@ class Config(ibus.Object): self.__ibusconn.connect("destroy", self.__ibusconn_destroy_cb) self.__ibusconn.connect("dbus-signal", self.__dbus_signal_cb) - def get_value(self, key, **kargs): - return self.__config.GetValue(key, **kargs) + def get_value(self, section, name, **kargs): + return self.__config.GetValue(section, name, **kargs) def set_value(self, key, value, **kargs): - return self.__config.GetValue(key, value, **kargs) + return self.__config.GetValue(section, name, **kargs) def destroy(self): if self.__ibusconn != None: @@ -67,7 +67,7 @@ class Config(ibus.Object): def __dbus_signal_cb(self, ibusconn, message): if message.is_signal(ibus.IBUS_CONFIG_IFACE, "ValueChanged"): args = message.get_args_list() - self.emit("value-changed", args[0], args[1]) + self.emit("value-changed", args[0], args[1], args[2]) else: return False ibusconn.stop_emission("dbus-signal") @@ -80,7 +80,7 @@ class DefaultConfig(ibus.Object): "value-changed" : ( gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)), + (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)), } def __init__(self): @@ -88,11 +88,11 @@ class DefaultConfig(ibus.Object): self.__config = defaultconfig.Config() self.__handler_id = self.__config.connect("value-changed", self.__value_changed_cb) - def get_value(self, key, **kargs): + def get_value(self, section, name, **kargs): reply_handler = kargs.get("reply_handler", None) error_handler = kargs.get("error_handler", None) try: - value = self.__config.get_value(key) + value = self.__config.get_value(section, name) if reply_handler: reply_handler(value) else: @@ -103,11 +103,11 @@ class DefaultConfig(ibus.Object): else: raise e - def set_value(self, key, value, **kargs): + def set_value(self, section, name, value, **kargs): reply_handler = kargs.get("reply_handler", None) error_handler = kargs.get("error_handler", None) try: - self.__config.set_value(key, value) + self.__config.set_value(section, name, value) if reply_handler: reply_handler() else: @@ -118,8 +118,8 @@ class DefaultConfig(ibus.Object): else: raise e - def __value_changed_cb(self, config, key, value): - self.emit("value-changed", key, value) + def __value_changed_cb(self, config, section, name, value): + self.emit("value-changed", section, name, value) def do_destroy(self): if self.__config: diff --git a/daemon/ibusdaemon.py b/daemon/ibusdaemon.py index 421cca3..8171a9a 100644 --- a/daemon/ibusdaemon.py +++ b/daemon/ibusdaemon.py @@ -42,7 +42,7 @@ class IBusServer(dbus.server.Server): def __launch_auto_load_engines(self): engines = [] try: - engines = self.__ibus.config_get_value("general/preload_engines", None) + engines = self.__ibus.config_get_value("general", "preload_engines", None) if not engines: engines = [] except: diff --git a/gconf/config.py b/gconf/config.py index ac46e0a..52f3dbf 100644 --- a/gconf/config.py +++ b/gconf/config.py @@ -50,19 +50,15 @@ class Config(ibus.Object): self.__handler_id = self.__client.connect("value-changed", self.__value_changed_cb) self.__client.add_dir(GCONF_IBUS_PATH, gconf.CLIENT_PRELOAD_NONE) - def get_value(self, key): - if not key.startswith("/"): - key = "/" + key - key = GCONF_IBUS_PATH + key + def get_value(self, section, name): + key = "/".join([GCONF_IBUS_PATH, section, name]) value = self.__client.get(key) if value == None: raise ibus.IBusException("key = \"%s\" does not exist" % key) return self.__to_py_value(value) - def set_value(self, key, value): - if not key.startswith("/"): - key = "/" + key - key = GCONF_IBUS_PATH + key + def set_value(self, section, name, value): + key = "/".join([GCONF_IBUS_PATH, section, name]) value = self.__to_gconf_value(value) self.__client.set(key, value) @@ -140,7 +136,14 @@ class Config(ibus.Object): value = self.__to_py_value(value) if value == None: value = 0 - self.emit("value-changed", key.replace(GCONF_IBUS_PATH, ""), value) + section_name = key.replace(GCONF_IBUS_PATH + "/", "") + section_name = section_name.split("/", 1) + if len(section_name) == 1: + self.emit("value-changed", "", section_name[0], value) + elif len(section_name) == 2: + self.emit("value-changed", section_name[0], section_name[1], value) + else: + print "Can not process %s" % key gobject.type_register(Config) @@ -148,12 +151,13 @@ class ConfigProxy(interface.IConfig): def __init__ (self, config, conn, object_path): super(ConfigProxy, self).__init__(conn, object_path) self.__config = config - self.__config.connect("value-changed", lambda c, k, v: self.ValueChanged(k, v)) + self.__config.connect("value-changed", lambda c, s, n, v: self.ValueChanged(s, n, v)) + + def GetValue(self, section, name): + return self.__config.get_value(section, name) - def GetValue(self, key): - return self.__config.get_value(key) - def SetValue(self, key, value): - self.__config.set_value(key, value) + def SetValue(self, section, name, value): + self.__config.set_value(section, name, value) def Destroy(self): self.remove_from_connection() diff --git a/ibus/bus.py b/ibus/bus.py index 5c78c00..4f70c8a 100644 --- a/ibus/bus.py +++ b/ibus/bus.py @@ -194,22 +194,22 @@ class Bus(ibus.Object): def get_input_context_states(self, ic): return self.__ibus.GetInputContextStates(ic) - def config_add_watch(self, key): - return self.__ibus.ConfigAddWatch(key) + def config_add_watch(self, section): + return self.__ibus.ConfigAddWatch(section) - def config_remove_watch(self, key): - return self.__ibus.ConfigRemoveWatch(key) + def config_remove_watch(self, section): + return self.__ibus.ConfigRemoveWatch(section) - def config_set_value(self, key, value): - return self.__ibus.ConfigSetValue(key, value) + def config_set_value(self, section, name, value): + return self.__ibus.ConfigSetValue(section, name, value) - def config_set_list(self, key, value, list_type): + def config_set_list(self, section, name, value, list_type): value = dbus.Array(value, signature = list_type) - return self.__ibus.ConfigSetValue(key, value) + return self.__ibus.ConfigSetValue(section, name, value) - def config_get_value(self, key, default_value = None): + def config_get_value(self, section, name, default_value = None): try: - return self.__ibus.ConfigGetValue(key) + return self.__ibus.ConfigGetValue(section, name) except Exception, e: return default_value diff --git a/ibus/interface/iconfig.py b/ibus/interface/iconfig.py index 42268b3..02b694a 100644 --- a/ibus/interface/iconfig.py +++ b/ibus/interface/iconfig.py @@ -42,15 +42,15 @@ class IConfig(dbus.service.Object): async_callbacks = ("reply_cb", "error_cb"), \ **args) - @method(in_signature = "s", out_signature = "v") - def GetValue(self, key): pass + @method(in_signature = "ss", out_signature = "v") + def GetValue(self, section, name): pass - @method(in_signature = "sv") - def SetValue(self, key, value): pass + @method(in_signature = "ssv") + def SetValue(self, section, name, value): pass @method() def Destroy(self): pass - @signal(signature = "sv") - def ValueChanged(self, key, value): pass + @signal(signature = "ssv") + def ValueChanged(self, section, name, value): pass diff --git a/panel/panel.py b/panel/panel.py index f745cdc..de54464 100644 --- a/panel/panel.py +++ b/panel/panel.py @@ -35,11 +35,6 @@ from gettext import dgettext _ = lambda a : dgettext("ibus", a) N_ = lambda a : a -CONFIG_PANEL_LOOKUP_TABLE_ORIENTATION = "/panel/lookup_table_orientation" -CONFIG_PANEL_AUTO_HIDE = "/panel/auto_hide" -CONFIG_PANEL_USE_CUSTOM_FONT = "/panel/use_custom_font" -CONFIG_PANEL_CUSTOM_FONT = "/panel/custom_font" - def show_uri(screen, link): try: gtk.show_uri(screen, link, 0) @@ -70,7 +65,7 @@ class Panel(ibus.PanelBase): # connect bus signal self.__bus.connect("config-value-changed", self.__config_value_changed_cb) self.__bus.connect("config-reloaded", self.__config_reloaded_cb) - self.__bus.config_add_watch("/panel") + self.__bus.config_add_watch("panel") # add icon search path icon_theme = gtk.icon_theme_get_default() @@ -211,7 +206,7 @@ class Panel(ibus.PanelBase): gtk.main_quit() def __config_load_lookup_table_orientation(self): - value = self.__bus.config_get_value(CONFIG_PANEL_LOOKUP_TABLE_ORIENTATION, 0) + value = self.__bus.config_get_value("panel", "lookup_table_orientation", 0) if value != 0 and value != 1: value = 0 if value == 0: @@ -220,14 +215,14 @@ class Panel(ibus.PanelBase): self.__candidate_panel.set_orientation(gtk.ORIENTATION_VERTICAL) def __config_load_auto_hide(self): - auto_hide = self.__bus.config_get_value(CONFIG_PANEL_AUTO_HIDE, False) + auto_hide = self.__bus.config_get_value("panel", "auto_hide", False) self.__language_bar.set_auto_hide(auto_hide) def __config_load_custom_font(self): - use_custom_font = self.__bus.config_get_value(CONFIG_PANEL_USE_CUSTOM_FONT, False) + use_custom_font = self.__bus.config_get_value("panel", "use_custom_font", False) font_name = gtk.settings_get_default().get_property("gtk-font-name") font_name = unicode(font_name, "utf-8") - custom_font = self.__bus.config_get_value(CONFIG_PANEL_CUSTOM_FONT, font_name) + custom_font = self.__bus.config_get_value("panel", "custom_font", font_name) style_string = 'style "custom-font" { font_name="%s" }\n' \ 'class "IBusPanelLabel" style "custom-font"\n' if use_custom_font: @@ -240,12 +235,12 @@ class Panel(ibus.PanelBase): settings = gtk.settings_get_default() gtk.rc_reset_styles(settings) - def __config_value_changed_cb(self, bus, key, value): - if key == CONFIG_PANEL_LOOKUP_TABLE_ORIENTATION: + def __config_value_changed_cb(self, bus, section, name, value): + if name == "lookup_table_orientation": self.__config_load_lookup_table_orientation() - elif key == CONFIG_PANEL_AUTO_HIDE: + elif name == "auto_hide": self.__config_load_auto_hide() - elif key == CONFIG_PANEL_USE_CUSTOM_FONT or key == CONFIG_PANEL_CUSTOM_FONT: + elif name == "use_custom_font" or name == "custom_font": self.__config_load_custom_font() def __config_reloaded_cb(self, bus): diff --git a/setup/main.py b/setup/main.py index f2d1d4c..2a518d7 100644 --- a/setup/main.py +++ b/setup/main.py @@ -57,12 +57,6 @@ N_ = lambda a : a DATA_PRELOAD ) = range(9) -CONFIG_PRELOAD_ENGINES = "/general/preload_engines" -CONFIG_PANEL_LOOKUP_TABLE_ORIENTATION = "/panel/lookup_table_orientation" -CONFIG_PANEL_AUTO_HIDE = "/panel/auto_hide" -CONFIG_PANEL_USE_CUSTOM_FONT = "/panel/use_custom_font" -CONFIG_PANEL_CUSTOM_FONT = "/panel/custom_font" - class Setup(object): def __flush_gtk_events(self): while gtk.events_pending(): @@ -113,6 +107,7 @@ class Setup(object): entry.set_text("; ".join(shortcuts)) button.connect("clicked", self.__shortcut_button_clicked_cb, N_("next engine"), ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, entry) + # prev engine shortcuts = self.__bus.config_get_value( ibus.CONFIG_GENERAL_SHORTCUT_PREV_ENGINE, @@ -128,30 +123,30 @@ class Setup(object): # lookup table orientation self.__combobox_lookup_table_orientation = self.__xml.get_widget("combobox_lookup_table_orientation") self.__combobox_lookup_table_orientation.set_active( - self.__bus.config_get_value(CONFIG_PANEL_LOOKUP_TABLE_ORIENTATION, 0)) + self.__bus.config_get_value("panel", "lookup_table_orientation", 0)) self.__combobox_lookup_table_orientation.connect("changed", self.__combobox_lookup_table_orientation_changed_cb) # auto hide self.__checkbutton_auto_hide = self.__xml.get_widget("checkbutton_auto_hide") self.__checkbutton_auto_hide.set_active( - self.__bus.config_get_value(CONFIG_PANEL_AUTO_HIDE, False)) + self.__bus.config_get_value("panel", "auto_hide", False)) self.__checkbutton_auto_hide.connect("toggled", self.__checkbutton_auto_hide_toggled_cb) # custom font self.__checkbutton_custom_font = self.__xml.get_widget("checkbutton_custom_font") self.__checkbutton_custom_font.set_active( - self.__bus.config_get_value(CONFIG_PANEL_USE_CUSTOM_FONT, False)) + self.__bus.config_get_value("panel", "use_custom_font", False)) self.__checkbutton_custom_font.connect("toggled", self.__checkbutton_custom_font_toggled_cb) self.__fontbutton_custom_font = self.__xml.get_widget("fontbutton_custom_font") - if self.__bus.config_get_value(CONFIG_PANEL_USE_CUSTOM_FONT, False): + if self.__bus.config_get_value("panel", "use_custom_font", False): self.__fontbutton_custom_font.set_sensitive(True) else: self.__fontbutton_custom_font.set_sensitive(False) font_name = gtk.settings_get_default().get_property("gtk-font-name") font_name = unicode(font_name, "utf-8") - font_name = self.__bus.config_get_value(CONFIG_PANEL_CUSTOM_FONT, font_name) + font_name = self.__bus.config_get_value("panel", "custom_font", font_name) self.__fontbutton_custom_font.connect("notify::font-name", self.__fontbutton_custom_font_notify_cb) self.__fontbutton_custom_font.set_font_name(font_name) @@ -160,7 +155,7 @@ class Setup(object): def __init_bus(self): try: self.__bus = ibus.Bus() - self.__bus.connect("config-value-changed", self.__config_value_changed_cb) + # self.__bus.connect("config-value-changed", self.__config_value_changed_cb) self.__bus.connect("config-reloaded", self.__config_reloaded_cb) self.__bus.config_add_watch("/general") self.__bus.config_add_watch("/panel") @@ -197,7 +192,7 @@ class Setup(object): def __init_engine_view(self): # engines tree self.__tree = self.__xml.get_widget("treeview_engines") - self.__preload_engines = set(self.__bus.config_get_value(CONFIG_PRELOAD_ENGINES, [])) + self.__preload_engines = set(self.__bus.config_get_value("general", "preload_engines", [])) model = self.__create_model() self.__tree.set_model(model) @@ -308,12 +303,11 @@ class Setup(object): if data[DATA_PRELOAD]: if engine not in self.__preload_engines: self.__preload_engines.add(engine) - self.__bus.config_set_list(CONFIG_PRELOAD_ENGINES, list(self.__preload_engines), "s") + self.__bus.config_set_list("general", "preload_engines", list(self.__preload_engines), "s") else: if engine in self.__preload_engines: self.__preload_engines.remove(engine) - self.__bus.config_set_list(CONFIG_PRELOAD_ENGINES, list(self.__preload_engines), "s") - + self.__bus.config_set_list("general", "preload_engines", list(self.__preload_engines), "s") # set new value model.set(iter, COLUMN_PRELOAD, data[DATA_PRELOAD]) @@ -426,33 +420,29 @@ class Setup(object): def __combobox_lookup_table_orientation_changed_cb(self, combobox): self.__bus.config_set_value( - CONFIG_PANEL_LOOKUP_TABLE_ORIENTATION, + "panel", "lookup_table_orientation", self.__combobox_lookup_table_orientation.get_active()) def __checkbutton_auto_hide_toggled_cb(self, button): self.__bus.config_set_value( - CONFIG_PANEL_AUTO_HIDE, + "panel", "auto_hide", self.__checkbutton_auto_hide.get_active()) def __checkbutton_custom_font_toggled_cb(self, button): if self.__checkbutton_custom_font.get_active(): self.__fontbutton_custom_font.set_sensitive(True) - self.__bus.config_set_value(CONFIG_PANEL_USE_CUSTOM_FONT, True) + self.__bus.config_set_value("panel", "use_custom_font", True) else: self.__fontbutton_custom_font.set_sensitive(False) - self.__bus.config_set_value(CONFIG_PANEL_USE_CUSTOM_FONT, False) + self.__bus.config_set_value("panel", "use_custom_font", False) def __fontbutton_custom_font_notify_cb(self, button, arg): font_name = self.__fontbutton_custom_font.get_font_name() font_name = unicode(font_name, "utf-8") - self.__bus.config_set_value(CONFIG_PANEL_CUSTOM_FONT, font_name) - - def __config_value_changed_cb(self, bus, key, value): - if key == CONFIG_PANEL_LOOKUP_TABLE_ORIENTATION: - item = self.__bus.config_get_value(CONFIG_PANEL_LOOKUP_TABLE_ORIENTATION, 0) - if item != 0 and item != 1: - item = 0 - self.__combobox_lookup_table_orientation.set_active(item) + self.__bus.config_set_value("panel", "custom_font", font_name) + + def __config_value_changed_cb(self, bus, section, name, value): + pass def __config_reloaded_cb(self, bus): pass |