diff --git a/daemon/bus.py b/daemon/bus.py index 42ba7874..f4fb2480 100644 --- a/daemon/bus.py +++ b/daemon/bus.py @@ -61,6 +61,8 @@ 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) ########################################################## @@ -363,27 +365,27 @@ class IBus(ibus.Object): def config_get_value(self, key, conn, **kargs): return self.__config.get_value(key, **kargs) - def config_add_watch(self, dir, conn): - if not dir.endswith("/"): - dir += "/" + def config_add_watch(self, key, conn): + if not key.endswith("/"): + key += "/" - if conn.add_watch_dir(dir): - if dir not in self.__config_watch: - self.__config_watch[dir] = set() - self.__config_watch[dir].add(conn) + 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, dir, conn): - if not dir.endswith("/"): - dir += "/" + def config_remove_watch(self, key, conn): + if not key.endswith("/"): + key += "/" - if conn.remove_watch_dir(dir): - if dir in self.__config_watch: - self.__config_watch[dir].remove(conn) + if conn.config_remove_watch(key): + if key in self.__config_watch: + self.__config_watch[key].remove(conn) def __config_value_changed_cb(self, config, key, value): - for dir in self.__config_watch.keys(): - if key.startswith(dir): - for conn in self.__config_watch[dir]: + 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) def __config_destroy_cb(self, config): diff --git a/daemon/connection.py b/daemon/connection.py index f59ccd58..a618e127 100644 --- a/daemon/connection.py +++ b/daemon/connection.py @@ -34,7 +34,7 @@ class Connection(ibus.Object): def __init__(self, dbusconn): super(Connection, self).__init__() self.__dbusconn = dbusconn - self.__watch_dirs = set() + self.__config_watch = set() dbusconn.add_message_filter(self.message_filter_cb) def message_filter_cb(self, dbusconn, message): @@ -63,18 +63,21 @@ class Connection(ibus.Object): def dispatch_dbus_signal(self, message): self.emit("dbus-signal", message) - def add_watch_dir(self, dir): - if dir in self.__watch_dirs: + def config_add_watch(self, key): + if key in self.__config_watch: return False - self.__watch_dirs.add(dir) + self.__config_watch.add(key) return True - def remove_watch_dir(self, dir): - if dir not in self.__watch_dirs: + def config_remove_watch(self, key): + if key not in self.__config_watch: return False - self.__watch_dirs.remove(dir) + self.__config_watch.remove(key) return True + def config_get_watch(self): + return self.__config_watch.copy() + def get_dbusconn(self): return self.__dbusconn