summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2008-10-03 20:19:03 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2008-10-03 20:19:03 +0800
commit6515cb122eea13c16d5f936a346acbc1369b2d64 (patch)
tree697ecf0303f04e7452364ce17fb44df79d01662b
parent09a7df4511f12e447d1f43ad485b375a3e5b26c6 (diff)
downloadibus-6515cb122eea13c16d5f936a346acbc1369b2d64.tar.gz
ibus-6515cb122eea13c16d5f936a346acbc1369b2d64.tar.xz
ibus-6515cb122eea13c16d5f936a346acbc1369b2d64.zip
WIP.
-rw-r--r--daemon/Makefile.am1
-rw-r--r--daemon/bus.py83
-rw-r--r--daemon/config.py57
-rw-r--r--daemon/connection.py16
l---------daemon/defaultconfig.py1
-rw-r--r--daemon/ibusdaemon.py32
-rw-r--r--gconf/config.py37
-rw-r--r--gconf/main.py5
-rw-r--r--ibus/bus.py38
-rw-r--r--ibus/interface/iibus.py16
10 files changed, 79 insertions, 207 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 1fabf8a..73abeff 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -21,7 +21,6 @@
ibusdaemon_PYTHON = \
bus.py \
_dbus.py \
- defaultconfig.py \
config.py \
connection.py \
contextmanager.py \
diff --git a/daemon/bus.py b/daemon/bus.py
index 6322332..56b75ef 100644
--- a/daemon/bus.py
+++ b/daemon/bus.py
@@ -26,7 +26,7 @@ from ibus import modifier
from contextmanager import ContextManager
from factorymanager import FactoryManager
from panel import Panel, DummyPanel
-from config import Config, DefaultConfig
+from config import Config, DummyConfig
from register import Register
import _dbus
@@ -43,14 +43,12 @@ class IBus(ibus.Object):
self.__panel_handlers = list()
self.__install_panel_handlers()
- self.__config = DefaultConfig()
+ self.__config = DummyConfig()
self.__config_handlers = list()
self.__install_config_handlers()
self.__register = Register()
- self.__config_watch = dict()
-
self.__focused_context = None
self.__last_focused_context = None
self.__context_handlers = list()
@@ -71,8 +69,10 @@ class IBus(ibus.Object):
self.__default_factory = None
def __dbus_name_owner_changed_cb(self, bus, name, old_name, new_name):
- if name == ibus.panel.IBUS_PANEL_NAME:
+ if name == ibus.IBUS_PANEL_NAME:
self.__panel_changed(new_name)
+ elif name == ibus.IBUS_CONFIG_NAME:
+ self.__config_changed(new_name)
def __factory_manager_default_factory_changed_cb(self, manager, factory):
if self.__default_factory != factory:
@@ -102,8 +102,6 @@ class IBus(ibus.Object):
self.__connections.append(conn)
def __conn_destroy_cb(self, conn):
- for key in conn.config_get_watch():
- self.config_remove_watch(key, conn)
self.__connections.remove(conn)
##########################################################
@@ -453,20 +451,16 @@ class IBus(ibus.Object):
##########################################################
# methods for panel
##########################################################
- def register_config(self, object_path, replace, conn):
- if not isinstance(self.__config, DefaultConfig) and replace == False:
- raise ibus.Exception("has have a config!")
+ def __config_changed(self, bus_name):
+ ibusconn = _dbus.bus.get_connection_by_name(bus_name)
self.__uninstall_config_handlers()
self.__config.destroy()
- self.__config = Config(conn, object_path)
+ self.__config = Config(ibusconn, ibus.IBUS_CONFIG_PATH)
self.__install_config_handlers()
- for conn in self.__connections:
- conn.emit_dbus_signal("ConfigReload")
def __install_config_handlers(self):
signals = (
- ("value-changed", self.__config_value_changed_cb),
- ("destroy", self.__config_destroy_cb)
+ ("destroy", self.__config_destroy_cb),
)
for signal, handler in signals:
id = self.__config.connect(signal, handler)
@@ -476,29 +470,6 @@ class IBus(ibus.Object):
map(lambda id:self.__config.disconnect(id), self.__config_handlers)
self.__config_handlers = list()
- def config_set_value(self, section, name, value, conn, **kargs):
- return self.__config.set_value(section, name, value, **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("/"):
- key += "/"
-
- if conn.config_add_watch(key):
- if key not in self.__config_watch:
- self.__config_watch[key] = set()
- self.__config_watch[key].add(conn)
-
- def config_remove_watch(self, key, conn):
- if not key.endswith("/"):
- key += "/"
-
- if conn.config_remove_watch(key):
- if key in self.__config_watch:
- self.__config_watch[key].remove(conn)
-
def __parse_shortcut_string(self, string):
keys = string.split("+")
keymask = 0
@@ -512,26 +483,6 @@ class IBus(ibus.Object):
return keyval, keymask
- 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]:
- conn.emit_dbus_signal("ConfigValueChanged", key, value)
-
- # check daemon configure
- if key == ibus.CONFIG_GENERAL_SHORTCUT_TRIGGER:
- self.__shortcut_trigger = self.__load_config_shortcut(
- ibus.CONFIG_GENERAL_SHORTCUT_TRIGGER,
- ibus.CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT)
- elif key == ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE:
- self.__shortcut_next_engine = self.__load_config_shortcut(
- ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE,
- ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT)
- elif key == ibus.CONFIG_GENERAL_SHORTCUT_PREV_ENGINE:
- self.__shortcut_prev_engine = self.__load_config_shortcut(
- ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE,
- ibus.CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT)
-
def __config_destroy_cb(self, config):
if config == self.__config:
self.__config = DefaultConfig()
@@ -657,22 +608,6 @@ class IBusProxy(ibus.IIBus):
def GetInputContextStates(self, ic, dbusconn):
return self.__ibus.get_input_context_states(ic, self.__conn)
- def ConfigAddWatch(self, section, dbusconn):
- return self.__ibus.config_add_watch(section, self.__conn)
-
- def ConfigRemoveWatch(self, section, dbusconn):
- return self.__ibus.config_remove_watch(section, self.__conn)
-
- def ConfigSetValue(self, section, name, value, dbusconn, reply_cb, error_cb):
- self.__ibus.config_set_value(section, name, value, self.__conn,
- reply_handler = reply_cb,
- error_handler = error_cb)
-
- def ConfigGetValue(self, section, name, dbusconn, reply_cb, error_cb):
- self.__ibus.config_get_value(section, name, self.__conn,
- reply_handler = reply_cb,
- error_handler = error_cb)
-
def RegisterListEngines(self, dbusconn):
return self.__ibus.register_list_engines(self.__conn)
diff --git a/daemon/config.py b/daemon/config.py
index 7695fde..319e533 100644
--- a/daemon/config.py
+++ b/daemon/config.py
@@ -26,7 +26,6 @@ __all__ = (
import gobject
import ibus
-import defaultconfig
class Config(ibus.Object):
__gsignals__ = {
@@ -48,7 +47,7 @@ class Config(ibus.Object):
def get_value(self, section, name, **kargs):
return self.__config.GetValue(section, name, **kargs)
- def set_value(self, key, value, **kargs):
+ def set_value(self, section, name, value, **kargs):
return self.__config.GetValue(section, name, **kargs)
def destroy(self):
@@ -75,7 +74,7 @@ class Config(ibus.Object):
gobject.type_register(Config)
-class DefaultConfig(ibus.Object):
+class DummyConfig(ibus.Object):
__gsignals__ = {
"value-changed" : (
gobject.SIGNAL_RUN_FIRST,
@@ -84,47 +83,23 @@ class DefaultConfig(ibus.Object):
}
def __init__(self):
- super(DefaultConfig, self).__init__()
- self.__config = defaultconfig.Config()
- self.__handler_id = self.__config.connect("value-changed", self.__value_changed_cb)
+ super(DummyConfig, self).__init__()
+ self.__values = dict()
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(section, name)
- if reply_handler:
- reply_handler(value)
- else:
- return value
- except Exception, e:
- if error_handler:
- error_handler(e)
- else:
- raise e
+ value = self.__values.get((section, name), None)
+ if value == None:
+ raise ibus.IBusException("Can not get config section=%s name=%s" % (section, name))
+ return value
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(section, name, value)
- if reply_handler:
- reply_handler()
- else:
- return
- except Exception, e:
- if error_handler:
- error_handler(e)
- else:
- raise e
-
- def __value_changed_cb(self, config, section, name, value):
+ old_value = self.__values.get((section, name), None)
+ if value == old_value:
+ return
+ if value == None:
+ del self.__values[(section, name)]
+ else:
+ self.__values[(section, name)] = value
self.emit("value-changed", section, name, value)
- def do_destroy(self):
- if self.__config:
- self.__config.disconnect(self.__handler_id)
- self.__config.destroy()
- self.__config = None
-
-gobject.type_register(DefaultConfig)
+gobject.type_register(DummyConfig)
diff --git a/daemon/connection.py b/daemon/connection.py
index 2974bd2..f897e08 100644
--- a/daemon/connection.py
+++ b/daemon/connection.py
@@ -41,7 +41,6 @@ class Connection(ibus.Object):
self.__dbusconn = dbusconn
self.__unique_name = ""
self.__names = set()
- self.__config_watch = set()
dbusconn.add_message_filter(self.message_filter_cb)
def message_filter_cb(self, dbusconn, message):
@@ -74,21 +73,6 @@ class Connection(ibus.Object):
def do_destroy(self):
self.__dbusconn = None
- def config_add_watch(self, key):
- if key in self.__config_watch:
- return False
- self.__config_watch.add(key)
- return True
-
- def config_remove_watch(self, key):
- if key not in self.__config_watch:
- return False
- self.__config_watch.remove(key)
- return True
-
- def config_get_watch(self):
- return self.__config_watch.copy()
-
def get_dbusconn(self):
return self.__dbusconn
diff --git a/daemon/defaultconfig.py b/daemon/defaultconfig.py
deleted file mode 120000
index 017ed90..0000000
--- a/daemon/defaultconfig.py
+++ /dev/null
@@ -1 +0,0 @@
-../gconf/config.py \ No newline at end of file
diff --git a/daemon/ibusdaemon.py b/daemon/ibusdaemon.py
index 8171a9a..b2f44c8 100644
--- a/daemon/ibusdaemon.py
+++ b/daemon/ibusdaemon.py
@@ -37,22 +37,22 @@ class IBusServer(dbus.server.Server):
super(IBusServer, self).__init__()
self.__ibus = IBus()
- self.__launch_auto_load_engines()
-
- def __launch_auto_load_engines(self):
- engines = []
- try:
- engines = self.__ibus.config_get_value("general", "preload_engines", None)
- if not engines:
- engines = []
- except:
- pass
- for e in engines:
- try:
- lang, name = e.split(":")
- self.__ibus.register_start_engine(lang, name, None)
- except:
- pass
+ # self.__launch_auto_load_engines()
+
+ # def __launch_auto_load_engines(self):
+ # engines = []
+ # try:
+ # engines = self.__ibus.config_get_value("general", "preload_engines", None)
+ # if not engines:
+ # engines = []
+ # except:
+ # pass
+ # for e in engines:
+ # try:
+ # lang, name = e.split(":")
+ # self.__ibus.register_start_engine(lang, name, None)
+ # except:
+ # pass
def connection_added(self, dbusconn):
conn = Connection(dbusconn)
diff --git a/gconf/config.py b/gconf/config.py
index 4b67106..8ec0d5f 100644
--- a/gconf/config.py
+++ b/gconf/config.py
@@ -30,11 +30,10 @@ except:
from ibus import gconf
import dbus
import ibus
-from ibus import interface
GCONF_IBUS_PATH = "/desktop/ibus"
-class Config(ibus.Object):
+class Config(ibus.ConfigBase):
__gsignals__ = {
"value-changed" : (
gobject.SIGNAL_RUN_FIRST,
@@ -42,10 +41,8 @@ class Config(ibus.Object):
(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)),
}
- def __init__ (self, bus = None, path = None):
- super(Config, self).__init__()
- conn = bus.get_dbusconn() if bus != None else None
- self.__proxy = ConfigProxy(self, conn, path)
+ def __init__ (self, bus):
+ super(Config, self).__init__(bus)
self.__client = gconf.Client()
self.__handler_id = self.__client.connect("value-changed", self.__value_changed_cb)
self.__client.add_dir(GCONF_IBUS_PATH, gconf.CLIENT_PRELOAD_NONE)
@@ -63,12 +60,10 @@ class Config(ibus.Object):
self.__client.set(key, value)
def do_destroy(self):
- if self.__proxy:
- self.__proxy.Destriy()
- self.__proxy = None
if self.__client:
self.__client.disconnect(self.__handler_id)
self.__client = None
+ super(Config, self).do_destroy()
def __to_py_value(self, value):
if value.type == gconf.VALUE_STRING:
@@ -139,28 +134,8 @@ class Config(ibus.Object):
section_name = key.replace(GCONF_IBUS_PATH + "/", "")
section_name = section_name.rsplit("/", 1)
if len(section_name) == 1:
- self.emit("value-changed", "", section_name[0], value)
+ self.value_changed("", section_name[0], value)
elif len(section_name) == 2:
- self.emit("value-changed", section_name[0], section_name[1], value)
+ self.value_changed(section_name[0], section_name[1], value)
else:
print "Can not process %s" % key
-
-gobject.type_register(Config)
-
-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, s, n, v: self.ValueChanged(s, n, v))
-
- def GetValue(self, section, name):
- return self.__config.get_value(section, name)
-
- def SetValue(self, section, name, value):
- self.__config.set_value(section, name, value)
-
- def Destroy(self):
- self.remove_from_connection()
- if self.__config:
- self.__config.destroy()
- self.__config = None
diff --git a/gconf/main.py b/gconf/main.py
index 3b915df..5410872 100644
--- a/gconf/main.py
+++ b/gconf/main.py
@@ -34,10 +34,9 @@ class GconfApplication:
self.__bus = ibus.Bus()
self.__bus.connect("destroy", self.__bus_destroy_cb)
- self.__config = config.Config(self.__bus, CONFIG_PATH)
+ self.__config = config.Config(self.__bus)
self.__config.connect("destroy", self.__config_destroy_cb)
-
- self.__bus.register_config(CONFIG_PATH, True)
+ self.__bus.request_name(ibus.IBUS_CONFIG_NAME, 0)
def run(self):
self.__mainloop.run()
diff --git a/ibus/bus.py b/ibus/bus.py
index 4f70c8a..4eb7b36 100644
--- a/ibus/bus.py
+++ b/ibus/bus.py
@@ -122,6 +122,11 @@ class Bus(ibus.Object):
self.__dbusconn = dbus.connection.Connection(ibus.IBUS_ADDR)
self.__ibus = self.__dbusconn.get_object(ibus.IBUS_NAME, ibus.IBUS_PATH)
self.__dbus = self.__dbusconn.get_object(dbus.BUS_DAEMON_NAME, dbus.BUS_DAEMON_PATH)
+ try:
+ unique_name = self.__dbus.get_name_owner(ibus.IBUS_CONFIG_NAME)
+ self.__config = self.__dbusconn.get_object(unique_name, ibus.IBUS_CONFIG_PATH)
+ except:
+ self.__config = None
self.__dbusconn.add_message_filter(self.__dbus_message_cb)
# define dbus methods
@@ -195,21 +200,31 @@ class Bus(ibus.Object):
return self.__ibus.GetInputContextStates(ic)
def config_add_watch(self, section):
- return self.__ibus.ConfigAddWatch(section)
+ return self.__dbus.AddMatch(
+ "type='signal',"
+ "interface='" + ibus.IBUS_CONFIG_NAME + "',"
+ "member='ValueChanged',"
+ "arg0='" + section + "'"
+ )
def config_remove_watch(self, section):
- return self.__ibus.ConfigRemoveWatch(section)
+ return self.__dbus.RemoveMatch(
+ "type='signal',"
+ "interface='" + ibus.IBUS_CONFIG_NAME + "',"
+ "member='ValueChanged',"
+ "arg0='" + section + "'"
+ )
def config_set_value(self, section, name, value):
- return self.__ibus.ConfigSetValue(section, name, value)
+ return self.__config.SetValue(section, name, value)
def config_set_list(self, section, name, value, list_type):
value = dbus.Array(value, signature = list_type)
- return self.__ibus.ConfigSetValue(section, name, value)
+ return self.__config.SetValue(section, name, value)
def config_get_value(self, section, name, default_value = None):
try:
- return self.__ibus.ConfigGetValue(section, name)
+ return self.__config.GetValue(section, name)
except Exception, e:
return default_value
@@ -232,8 +247,17 @@ class Bus(ibus.Object):
return self.__ibus.Kill()
def __dbus_message_cb(self, conn, message):
+ # name owner changed signal
+ if message.is_signal(dbus.BUS_DAEMON_IFACE, "NameOwnerChanged"):
+ args = message.get_args_list()
+ if args[0] == ibus.IBUS_CONFIG_NAME:
+ if args[2] != "":
+ self.__config = self.__dbusconn.get_object(ibus.IBUS_CONFIG_NAME, ibus.IBUS_CONFIG_PATH)
+ else:
+ self.__config = None
+
# commit string signal
- if message.is_signal(ibus.IBUS_IFACE, "CommitString"):
+ elif message.is_signal(ibus.IBUS_IFACE, "CommitString"):
args = message.get_args_list()
ic, string = args[0:2]
self.emit("commit-string", ic, string.encode("utf-8"))
@@ -331,6 +355,4 @@ class Bus(ibus.Object):
retval = dbus.lowlevel.HANDLER_RESULT_HANDLED
else:
retval = dbus.lowlevel.HANDLER_RESULT_NOT_YET_HANDLED
-
return retval
-
diff --git a/ibus/interface/iibus.py b/ibus/interface/iibus.py
index ab2ea36..0f299b0 100644
--- a/ibus/interface/iibus.py
+++ b/ibus/interface/iibus.py
@@ -77,10 +77,6 @@ class IIBus(dbus.service.Object):
@method(in_signature = "ao")
def UnregisterFactories(self, object_paths, dbusconn): pass
- # methods for ibus config
- @method(in_signature = "ob")
- def RegisterConfig(self, object_path, replace, dbusconn): pass
-
# general methods
@method(out_signature = "av")
def GetFactories(self, dbusconn): pass
@@ -94,18 +90,6 @@ class IIBus(dbus.service.Object):
@method(in_signature = "s", out_signature = "sb")
def GetInputContextStates(self, ic, dbusconn): pass
- @method(in_signature = "s")
- def ConfigAddWatch(self, section, dbusconn): pass
-
- @method(in_signature = "s")
- def ConfigRemoveWatch(self, section, dbusconn): pass
-
- @async_method(in_signature = "ssv")
- def ConfigSetValue(self, section, name, value, dbusconn, reply_cb, error_cb): pass
-
- @async_method(in_signature = "ss", out_signature = "v")
- def ConfigGetValue(self, section, name, dbusconn, reply_cb, error_cb): pass
-
@method(out_signature = "a(sssssssb)")
def RegisterListEngines(self, dbusconn): pass