diff --git a/shell/ChatController.py b/shell/ChatController.py index 00bab802..0b4068d2 100644 --- a/shell/ChatController.py +++ b/shell/ChatController.py @@ -1,7 +1,7 @@ from sugar import env from sugar.chat.BuddyChat import BuddyChat from sugar.activity import ActivityFactory -from sugar.presence.PresenceService import PresenceService +from sugar.presence import PresenceService from sugar.p2p.Stream import Stream from sugar.chat.Chat import Chat @@ -21,7 +21,7 @@ class ChatController: del self._id_to_name[activity_id] def listen(self): - self._pservice = PresenceService() + self._pservice = PresenceService.get_instance() self._pservice.register_service_type(BuddyChat.SERVICE_TYPE) self._service = self._pservice.register_service(env.get_nick_name(), diff --git a/shell/Owner.py b/shell/Owner.py index 90f60240..14cd6361 100644 --- a/shell/Owner.py +++ b/shell/Owner.py @@ -25,7 +25,7 @@ class ShellOwner(object): fd.close() break - self._pservice = PresenceService.PresenceService() + self._pservice = PresenceService.get_instance() def announce(self): # Create and announce our presence diff --git a/shell/PresenceView.py b/shell/PresenceView.py index ec632881..4eef96bc 100644 --- a/shell/PresenceView.py +++ b/shell/PresenceView.py @@ -2,7 +2,7 @@ import gtk import gobject import dbus -from sugar.presence.PresenceService import PresenceService +from sugar.presence import PresenceService from sugar.presence.Service import Service from sugar.chat.BuddyChat import BuddyChat @@ -20,7 +20,7 @@ class PresenceView(gtk.VBox): self._activity_ps = None self._shell = shell - self._pservice = PresenceService() + self._pservice = PresenceService.get_instance() self._pservice.connect("activity-appeared", self._activity_appeared_cb) self._setup_ui() diff --git a/shell/Shell.py b/shell/Shell.py index bb91bf3e..d3f7703e 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -173,7 +173,7 @@ class Shell(gobject.GObject): if activity: activity.present() else: - pservice = PresenceService.PresenceService() + pservice = PresenceService.get_instance() activity_ps = pservice.get_activity(activity_id) if activity_ps: diff --git a/shell/home/FriendsModel.py b/shell/home/FriendsModel.py index 6f18083a..0988b8af 100644 --- a/shell/home/FriendsModel.py +++ b/shell/home/FriendsModel.py @@ -1,6 +1,6 @@ import gobject -from sugar.presence.PresenceService import PresenceService +from sugar.presence import PresenceService class Friend: def __init__(self, buddy): @@ -22,7 +22,7 @@ class FriendsModel(gobject.GObject): self._friends = [] - self._pservice = PresenceService() + self._pservice = PresenceService.get_instance() self._pservice.connect("buddy-appeared", self.__buddy_appeared_cb) for buddy in self._pservice.get_buddies(): diff --git a/shell/home/MeshModel.py b/shell/home/MeshModel.py index 2225cc67..68ed4a9d 100644 --- a/shell/home/MeshModel.py +++ b/shell/home/MeshModel.py @@ -1,6 +1,6 @@ import gobject -from sugar.presence.PresenceService import PresenceService +from sugar.presence import PresenceService from sugar import conf class ActivityInfo: @@ -32,7 +32,7 @@ class MeshModel(gobject.GObject): self._activities = {} - self._pservice = PresenceService() + self._pservice = PresenceService.get_instance() self._pservice.connect("service-appeared", self.__service_appeared_cb) for service in self._pservice.get_services(): diff --git a/sugar/presence/PresenceService.py b/sugar/presence/PresenceService.py index 9fbbc0d1..9cd94d4e 100644 --- a/sugar/presence/PresenceService.py +++ b/sugar/presence/PresenceService.py @@ -206,6 +206,14 @@ class PresenceService(gobject.GObject): def unregister_service_type(self, stype): self._ps.unregisterServiceType(stype) +_ps = None +def get_instance(): + global _ps + if not _ps: + _ps = PresenceService() + return _ps + + def start(): bus = dbus.SessionBus() ps = dbus.Interface(bus.get_object(DBUS_SERVICE, DBUS_PATH), DBUS_INTERFACE)