Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu.vizoso@collabora.co.uk>2010-07-02 11:06:39 (GMT)
committer Tomeu Vizoso <tomeu.vizoso@collabora.co.uk>2010-08-20 13:02:26 (GMT)
commit72f44fa8e7a61ca60052789cc8372b07b2fdd73c (patch)
treee8b381a58f7f1ed4f8613ff42ae6bc1c33425fb3
parentbadc739f713ffdaf7ef3d4d4e7139d69d1dbed47 (diff)
Make ConnectionWatcher a singleton
-rw-r--r--src/jarabe/model/filetransfer.py14
-rw-r--r--src/jarabe/util/telepathy/connection_watcher.py8
2 files changed, 14 insertions, 8 deletions
diff --git a/src/jarabe/model/filetransfer.py b/src/jarabe/model/filetransfer.py
index 46b246d..e59e389 100644
--- a/src/jarabe/model/filetransfer.py
+++ b/src/jarabe/model/filetransfer.py
@@ -325,15 +325,12 @@ def _connection_addded_cb(conn_watcher, connection):
def _connection_removed_cb(conn_watcher, connection):
logging.debug('connection removed %r', connection)
-_conn_watcher = None
-
def init():
- global _conn_watcher
- _conn_watcher = connection_watcher.ConnectionWatcher()
- _conn_watcher.connect('connection-added', _connection_addded_cb)
- _conn_watcher.connect('connection-removed', _connection_removed_cb)
+ conn_watcher = connection_watcher.get_instance()
+ conn_watcher.connect('connection-added', _connection_addded_cb)
+ conn_watcher.connect('connection-removed', _connection_removed_cb)
- for connection in _conn_watcher.get_connections():
+ for connection in conn_watcher.get_connections():
_monitor_connection(connection)
def start_transfer(buddy, file_name, title, description, mime_type):
@@ -342,7 +339,8 @@ def start_transfer(buddy, file_name, title, description, mime_type):
new_file_transfer.send(None, file_transfer=outgoing_file_transfer)
def file_transfer_available():
- for connection in _conn_watcher.get_connections():
+ conn_watcher = connection_watcher.get_instance()
+ for connection in conn_watcher.get_connections():
properties_iface = connection[dbus.PROPERTIES_IFACE]
properties = properties_iface.GetAll(CONNECTION_INTERFACE_REQUESTS)
diff --git a/src/jarabe/util/telepathy/connection_watcher.py b/src/jarabe/util/telepathy/connection_watcher.py
index 4a4c6e0..391bdd5 100644
--- a/src/jarabe/util/telepathy/connection_watcher.py
+++ b/src/jarabe/util/telepathy/connection_watcher.py
@@ -93,6 +93,14 @@ class ConnectionWatcher(gobject.GObject):
def get_connections(self):
return self._connections.values()
+_instance = None
+
+def get_instance():
+ global _instance
+ if _instance is None:
+ _instance = ConnectionWatcher()
+ return _instance
+
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)