summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis-Francis Ratté-Boulianne <louis-francis.ratte-boulianne@collabora.co.uk>2011-08-14 09:23:01 -0400
committerLouis-Francis Ratté-Boulianne <louis-francis.ratte-boulianne@collabora.co.uk>2011-08-14 09:23:01 -0400
commitcaef223f1eef0cb2dbfca401062956bc7d290c6d (patch)
treec8971fda904601a96f8789e7fc4751055d20f1aa
parentbc35bded5abdb32290ed142b5f47cff9113f9ce4 (diff)
bugfix: properly handle content roaming errors when profile is broken (fdo #32941)
Added event interface for ContentRoaming as well for consistency.
-rw-r--r--papyon/client.py18
-rw-r--r--papyon/event/__init__.py1
-rw-r--r--papyon/event/content_roaming.py37
-rw-r--r--papyon/service/ContentRoaming/content_roaming.py6
-rw-r--r--papyon/service/ContentRoaming/storage.py2
-rw-r--r--tests/test_content_roaming.py24
6 files changed, 73 insertions, 15 deletions
diff --git a/papyon/client.py b/papyon/client.py
index 55ff508..4ccf409 100644
--- a/papyon/client.py
+++ b/papyon/client.py
@@ -403,15 +403,17 @@ class Client(EventsDispatcher):
self.profile.password,
self._proxies)
self._address_book = AB.AddressBook(self._sso, self, self._proxies)
- self.__connect_addressbook_signals()
self._mailbox = msnp.Mailbox(self._protocol)
- self.__connect_mailbox_signals()
self._oim_box = OIM.OfflineMessagesBox(self._sso, self, self._proxies)
- self.__connect_oim_box_signals()
self._spaces = Spaces.Spaces(self._sso, self._proxies)
self._roaming = CR.ContentRoaming(self._sso, self._address_book, self._proxies)
self._turn_client = TURNClient(self._sso, self.profile.account)
+ self.__connect_addressbook_signals()
+ self.__connect_mailbox_signals()
+ self.__connect_oim_box_signals()
+ self.__connect_roaming_signals()
+
self._state = ClientState.CONNECTED
def connect_failure(transp, reason):
@@ -530,6 +532,16 @@ class Client(EventsDispatcher):
connect_signal("message-sent")
connect_signal("messages-deleted")
+ def __connect_roaming_signals(self):
+ """Connect Content Roaming signals"""
+ def state_changed(roaming, pspec):
+ self._dispatch("on_roaming_state_changed", roaming.state)
+ def error(roaming, error_code):
+ self._dispatch("on_client_error", ClientErrorType.CONTENT_ROAMING, error_code)
+
+ self._roaming.connect("notify::state", state_changed)
+ self._roaming.connect("error", error)
+
def __connect_webcam_handler_signals(self):
"""Connect Webcam Handler signals"""
def session_created(webcam_handler, session, producer):
diff --git a/papyon/event/__init__.py b/papyon/event/__init__.py
index e916603..cb3d85c 100644
--- a/papyon/event/__init__.py
+++ b/papyon/event/__init__.py
@@ -70,6 +70,7 @@ from conversation import *
from profile import *
from contact import *
from address_book import *
+from content_roaming import *
from offline_messages import *
from invite import *
from mailbox import *
diff --git a/papyon/event/content_roaming.py b/papyon/event/content_roaming.py
new file mode 100644
index 0000000..3810fba
--- /dev/null
+++ b/papyon/event/content_roaming.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2007 Johann Prieur <johann.prieur@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+"""Content Roaming event interfaces
+
+The interfaces defined in this module allow receiving notification events about
+content roaming."""
+
+from papyon.event import BaseEventInterface
+
+__all__ = ["ContentRoamingEventInterface"]
+
+class ContentRoamingEventInterface(BaseEventInterface):
+ """interfaces allowing the user to get notified about events from the
+ content roaming object."""
+
+ def __init__(self, client):
+ BaseEventInterface.__init__(self, client)
+
+ def on_roaming_state_changed(self, state):
+ pass
diff --git a/papyon/service/ContentRoaming/content_roaming.py b/papyon/service/ContentRoaming/content_roaming.py
index ac70896..5bb2d35 100644
--- a/papyon/service/ContentRoaming/content_roaming.py
+++ b/papyon/service/ContentRoaming/content_roaming.py
@@ -103,6 +103,8 @@ class ContentRoaming(gobject.GObject):
def display_picture(self):
return self.__display_picture
+ ### Public API -----------------------------------------------------------
+
def sync(self):
if self._state != ContentRoamingState.NOT_SYNCHRONIZED:
return
@@ -116,9 +118,7 @@ class ContentRoaming(gobject.GObject):
gp.cid = self._ab.profile.cid
gp()
- ### Public API -----------------------------------------------------------
-
- def store(self, display_name=None, personal_message=None,
+ def store(self, display_name=None, personal_message=None,
display_picture=None, callback=None, errback=None):
if display_name is None:
display_name = self.__display_name
diff --git a/papyon/service/ContentRoaming/storage.py b/papyon/service/ContentRoaming/storage.py
index 6c79cba..822cbd0 100644
--- a/papyon/service/ContentRoaming/storage.py
+++ b/papyon/service/ContentRoaming/storage.py
@@ -147,6 +147,8 @@ class Storage(SOAPService):
scheme, host, port, resource = url_split(user_tile_url)
if host:
self.get_resource(scheme, host, resource, callback, errback)
+ else:
+ run(errback, error, None)
scheme, host, port, resource = url_split(pre_auth_url)
resource += '?t=' + urllib.quote(token.split('&')[0][2:], '')
diff --git a/tests/test_content_roaming.py b/tests/test_content_roaming.py
index 43d9eb1..3e411d4 100644
--- a/tests/test_content_roaming.py
+++ b/tests/test_content_roaming.py
@@ -34,24 +34,30 @@ class ContentRoamingClient(TestClient):
args = [("nickname", "string"),
("message", "string"),
("path", "string")]
- TestClient.__init__(self, "Content Roaming", opts, args)
+ TestClient.__init__(self, "Content Roaming", opts, args, ContentRoamingClientEvents)
def connected(self):
- self._roaming.connect("notify::state",
- self.on_content_roaming_state_changed)
- self._roaming.sync()
+ self.content_roaming.sync()
- def on_content_roaming_state_changed(self, cr, pspec):
- if cr.state == ContentRoamingState.SYNCHRONIZED:
+
+class ContentRoamingClientEvents(TestClientEvents,
+ papyon.event.ContentRoamingEventInterface):
+
+ def __init__(self, client):
+ TestClientEvents.__init__(self, client)
+ papyon.event.ContentRoamingEventInterface.__init__(self, client)
+
+ def on_content_roaming_state_changed(self, state):
+ if state == ContentRoamingState.SYNCHRONIZED:
path = self.arguments['path']
if self.options.action == 'get':
- type, data = cr.display_picture
+ type, data = self._client.content_roaming.display_picture
f = open(path, 'w')
f.write(data)
elif self.options.action == 'put':
f = open(path, 'r')
- cr.store(self.arguments['nickname'], self.arguments['message'],
- f.read())
+ self._client.content_roaming.store(self.arguments['nickname'],
+ self.arguments['message'], f.read())
if __name__ == "__main__":