From d06cb74d2594c60ded1f7be052d0d8a8262eeaf5 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 11 Sep 2006 19:25:16 +0200 Subject: [PATCH 1/5] Cast size to int --- configure.ac | 2 +- sugar/canvas/IconItem.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 072ebd85..25710ab4 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([Sugar],[0.27],[],[sugar]) +AC_INIT([Sugar],[0.28],[],[sugar]) AC_PREREQ([2.59]) diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index b9e1fb3a..e0c3b839 100644 --- a/sugar/canvas/IconItem.py +++ b/sugar/canvas/IconItem.py @@ -124,7 +124,7 @@ class IconView(goocanvas.ItemViewSimple, goocanvas.ItemView): self._buffer = None if self._buffer == None: - size = _ICON_SIZE * scale + size = int(_ICON_SIZE * scale) surface = cr.get_target().create_similar( cairo.CONTENT_COLOR_ALPHA, size, size) From d65e8b88e70350b24fd482946a47d6d418995f75 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 12 Sep 2006 12:19:20 +0200 Subject: [PATCH 2/5] Handle activity removal and cleanup a bit --- shell/home/MeshGroup.py | 48 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/shell/home/MeshGroup.py b/shell/home/MeshGroup.py index e0a61441..bae483e6 100644 --- a/shell/home/MeshGroup.py +++ b/shell/home/MeshGroup.py @@ -9,14 +9,15 @@ from sugar.presence import PresenceService from home.IconLayout import IconLayout class ActivityItem(IconItem): - def __init__(self, service): + def __init__(self, activity, service): self._service = service + self._activity = activity IconItem.__init__(self, icon_name=self.get_icon_name(), color=self.get_color(), size=96) def get_id(self): - return self._service.get_activity_id() + return self._activity.get_id() def get_icon_name(self): registry = conf.get_activity_registry() @@ -25,9 +26,7 @@ class ActivityItem(IconItem): return info.get_icon() def get_color(self): - pservice = PresenceService.get_instance() - activity = pservice.get_activity(self.get_id()) - return IconColor(activity.get_color()) + return IconColor(self._activity.get_color()) def get_service(self): return self._service @@ -39,38 +38,47 @@ class MeshGroup(goocanvas.Group): self._icon_layout = IconLayout(1200, 900) self._activities = {} - pservice = PresenceService.get_instance() - pservice.connect("service-appeared", self.__service_appeared_cb) + self._pservice = PresenceService.get_instance() + self._pservice.connect("service-appeared", self._service_appeared_cb) + self._pservice.connect('activity-disappeared', self._activity_disappeared_cb) - for service in pservice.get_services(): - self.__check_service(service) + for service in self._pservice.get_services(): + self._check_service(service) - def __service_appeared_cb(self, pservice, service): - self.__check_service(service) + def _service_appeared_cb(self, pservice, service): + self._check_service(service) - def __check_service(self, service): + def _check_service(self, service): registry = conf.get_activity_registry() if registry.get_activity_from_type(service.get_type()) != None: - if not self.has_activity(service.get_activity_id()): - self.add_activity(service) + activity_id = service.get_activity_id() + if not self.has_activity(activity_id): + activity = self._pservice.get_activity(activity_id) + if activity != None: + self.add_activity(activity, service) def has_activity(self, activity_id): return self._activities.has_key(activity_id) - def add_activity(self, service): - item = ActivityItem(service) - item.connect('clicked', self.__activity_clicked_cb) - + def add_activity(self, activity, service): + item = ActivityItem(activity, service) + item.connect('clicked', self._activity_clicked_cb) self._icon_layout.add_icon(item) self.add_child(item) self._activities[item.get_id()] = item - def __activity_clicked_cb(self, item): + def _activity_disappeared_cb(self, activity): + print 'remove' + if self._activities.has_key(activity.get_id()): + self.remove_child(self._activities[activity.get_id()]) + del self._activities[activity.get_id()] + + def _activity_clicked_cb(self, item): default_type = item.get_service().get_type() registry = conf.get_activity_registry() bundle_id = registry.get_activity_from_type(default_type).get_id() - activity_id = item.get_service().get_activity_id() + activity_id = item.get_id() self._shell.join_activity(bundle_id, activity_id) From 53f7cc1f343e9f54bd61f92d434a9e700e7aa160 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 12 Sep 2006 13:21:18 +0200 Subject: [PATCH 3/5] Cleanup browser model service on destroy. Remove the activity service even if the owner is gone. --- activities/browser/BrowserActivity.py | 5 +++++ shell/PresenceService/PresenceService.py | 7 ++++--- shell/home/MeshGroup.py | 3 +-- sugar/p2p/model/LocalModel.py | 11 +++++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/activities/browser/BrowserActivity.py b/activities/browser/BrowserActivity.py index a8c795a2..6d452c5f 100644 --- a/activities/browser/BrowserActivity.py +++ b/activities/browser/BrowserActivity.py @@ -25,6 +25,7 @@ class BrowserActivity(Activity): self._model = None self.set_title("Web Page") + self.connect('destroy', self._destroy_cb) vbox = gtk.VBox() @@ -123,3 +124,7 @@ class BrowserActivity(Activity): self._notif_bar.set_action('goto_shared_location', 'Go There') self._notif_bar.set_icon('stock_right') self._notif_bar.show() + + def _destroy_cb(self, window): + if self._model: + self._model.shutdown() diff --git a/shell/PresenceService/PresenceService.py b/shell/PresenceService/PresenceService.py index 56b54a32..ae7f7e05 100644 --- a/shell/PresenceService/PresenceService.py +++ b/shell/PresenceService/PresenceService.py @@ -536,6 +536,9 @@ class PresenceService(object): if not service: return False + self._dbus_helper.ServiceDisappeared(service.object_path()) + self._handle_remove_activity_service(service) + # Decompose service name if we can (actid, buddy_name) = Service.decompose_service_name(full_name) @@ -545,10 +548,8 @@ class PresenceService(object): except KeyError: pass else: - buddy.remove_service(service) - self._dbus_helper.ServiceDisappeared(service.object_path()) - self._handle_remove_activity_service(service) if not buddy.is_valid(): + buddy.remove_service(service) self._dbus_helper.BuddyDisappeared(buddy.object_path()) del self._buddies[buddy_name] key = (service.get_full_name(), service.get_type()) diff --git a/shell/home/MeshGroup.py b/shell/home/MeshGroup.py index bae483e6..f7bc1c99 100644 --- a/shell/home/MeshGroup.py +++ b/shell/home/MeshGroup.py @@ -68,8 +68,7 @@ class MeshGroup(goocanvas.Group): self._activities[item.get_id()] = item - def _activity_disappeared_cb(self, activity): - print 'remove' + def _activity_disappeared_cb(self, pservice, activity): if self._activities.has_key(activity.get_id()): self.remove_child(self._activities[activity.get_id()]) del self._activities[activity.get_id()] diff --git a/sugar/p2p/model/LocalModel.py b/sugar/p2p/model/LocalModel.py index b19e07e4..0053aeef 100644 --- a/sugar/p2p/model/LocalModel.py +++ b/sugar/p2p/model/LocalModel.py @@ -37,13 +37,16 @@ class LocalModel(AbstractModel): self._notifier.notify(key) def _setup_service(self): - service = self._pservice.share_activity(self._activity, - stype = LocalModel.SERVICE_TYPE) - self._setup_server(service) - + self._service = self._pservice.share_activity( + self._activity, stype = LocalModel.SERVICE_TYPE) + self._setup_server(self._service) + # FIXME this is duplicated with StreamReader def _setup_server(self, service): port = service.get_port() logging.debug('Start model server on port %d' % (port)) p2p_server = network.GlibXMLRPCServer(("", port)) p2p_server.register_instance(ModelRequestHandler(self)) + + def shutdown(self): + self._pservice.unregister_service(self._service) From 8ebb57d98555f34624ee2bbbf19fb52fe225d5d1 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 12 Sep 2006 13:26:51 +0200 Subject: [PATCH 4/5] I messed up... back to actually remove the service --- shell/PresenceService/PresenceService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/PresenceService/PresenceService.py b/shell/PresenceService/PresenceService.py index ae7f7e05..c37dc2aa 100644 --- a/shell/PresenceService/PresenceService.py +++ b/shell/PresenceService/PresenceService.py @@ -548,8 +548,8 @@ class PresenceService(object): except KeyError: pass else: + buddy.remove_service(service) if not buddy.is_valid(): - buddy.remove_service(service) self._dbus_helper.BuddyDisappeared(buddy.object_path()) del self._buddies[buddy_name] key = (service.get_full_name(), service.get_type()) From 2956a3ab8cb37ad61379fe61ead6eb5719bbc67d Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 12 Sep 2006 13:39:48 +0200 Subject: [PATCH 5/5] Adapt to LocalModel interface --- sugar/p2p/model/RemoteModel.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sugar/p2p/model/RemoteModel.py b/sugar/p2p/model/RemoteModel.py index 28de2ae3..0fb32845 100644 --- a/sugar/p2p/model/RemoteModel.py +++ b/sugar/p2p/model/RemoteModel.py @@ -26,3 +26,6 @@ class RemoteModel(AbstractModel): def _setup_notification_listener(self): self._notification = NotificationListener(self._notification_service) self._notification.add_listener(self._notify_model_change) + + def shutdown(self): + pass