Make each activity have a default type for sharing

This commit is contained in:
Dan Williams 2006-06-16 23:10:30 -04:00
parent 358c548641
commit e060c07873
4 changed files with 25 additions and 13 deletions

View File

@ -8,9 +8,11 @@ import geckoembed
from sugar.shell import activity from sugar.shell import activity
import sugar.env import sugar.env
_GMAIL_ACTIVITY_TYPE = "_gmail_google._tcp"
class GMailActivity(activity.Activity): class GMailActivity(activity.Activity):
def __init__(self): def __init__(self):
activity.Activity.__init__(self) activity.Activity.__init__(self, _GMAIL_ACTIVITY_TYPE)
def on_connected_to_shell(self): def on_connected_to_shell(self):
profile_path = os.path.join(sugar.env.get_user_dir(), 'gmail') profile_path = os.path.join(sugar.env.get_user_dir(), 'gmail')

View File

@ -22,7 +22,7 @@ class BrowserActivity(activity.Activity):
LEADING = 3 LEADING = 3
def __init__(self, uri): def __init__(self, uri):
activity.Activity.__init__(self) activity.Activity.__init__(self, _BROWSER_ACTIVITY_TYPE)
self.uri = uri self.uri = uri
self._mode = BrowserActivity.SOLO self._mode = BrowserActivity.SOLO
self._pservice = PresenceService.get_instance() self._pservice = PresenceService.get_instance()

View File

@ -77,10 +77,10 @@ class ActivityDbusService(dbus.service.Object):
SHELL_SERVICE_NAME + ".ActivityContainer") SHELL_SERVICE_NAME + ".ActivityContainer")
if activity_id is None: if activity_id is None:
self._activity_id = self._activity_container.add_activity("") self._activity_id = self._activity_container.add_activity("", self._activity.default_type())
else: else:
self._activity_id = activity_id self._activity_id = activity_id
self._activity_container.add_activity_with_id("", activity_id) self._activity_container.add_activity_with_id("", self._activity.default_type(), activity_id)
self._object_path = SHELL_SERVICE_PATH + "/Activities/%s" % self._activity_id self._object_path = SHELL_SERVICE_PATH + "/Activities/%s" % self._activity_id
@ -144,7 +144,7 @@ class ActivityDbusService(dbus.service.Object):
class Activity(object): class Activity(object):
"""Base Activity class that all other Activities derive from.""" """Base Activity class that all other Activities derive from."""
def __init__(self): def __init__(self, default_type):
self._dbus_service = self._get_new_dbus_service() self._dbus_service = self._get_new_dbus_service()
self._dbus_service.register_callback(ON_CONNECTED_TO_SHELL_CB, self._internal_on_connected_to_shell_cb) self._dbus_service.register_callback(ON_CONNECTED_TO_SHELL_CB, self._internal_on_connected_to_shell_cb)
self._dbus_service.register_callback(ON_DISCONNECTED_FROM_SHELL_CB, self._internal_on_disconnected_from_shell_cb) self._dbus_service.register_callback(ON_DISCONNECTED_FROM_SHELL_CB, self._internal_on_disconnected_from_shell_cb)
@ -156,6 +156,9 @@ class Activity(object):
self._has_focus = False self._has_focus = False
self._plug = None self._plug = None
self._activity_object = None self._activity_object = None
if type(default_type) != type("") or not len(default_type):
raise ValueError("Default type must be a valid string.")
self._default_type = default_type
def _cleanup(self): def _cleanup(self):
if self._plug: if self._plug:
@ -173,6 +176,9 @@ class Activity(object):
Allows subclasses to use their own dbus service object if they choose.""" Allows subclasses to use their own dbus service object if they choose."""
return ActivityDbusService(self) return ActivityDbusService(self)
def default_type(self):
return self._default_type
def has_focus(self): def has_focus(self):
"""Return whether or not this Activity is visible to the user.""" """Return whether or not this Activity is visible to the user."""
return self._has_focus return self._has_focus

View File

@ -17,7 +17,7 @@ from sugar.chat.GroupChat import GroupChat
class ActivityHost(dbus.service.Object): class ActivityHost(dbus.service.Object):
def __init__(self, activity_container, activity_name, activity_id = None): def __init__(self, activity_container, activity_name, default_type, activity_id = None):
self.activity_name = activity_name self.activity_name = activity_name
self.ellipsize_tab = False self.ellipsize_tab = False
@ -27,7 +27,8 @@ class ActivityHost(dbus.service.Object):
self.activity_id = sugar.util.unique_id() self.activity_id = sugar.util.unique_id()
else: else:
self.activity_id = activity_id self.activity_id = activity_id
self._default_type = default_type
self.dbus_object_name = "/com/redhat/Sugar/Shell/Activities/%s" % self.activity_id self.dbus_object_name = "/com/redhat/Sugar/Shell/Activities/%s" % self.activity_id
dbus.service.Object.__init__(self, activity_container.service, self.dbus_object_name) dbus.service.Object.__init__(self, activity_container.service, self.dbus_object_name)
@ -83,6 +84,9 @@ class ActivityHost(dbus.service.Object):
def get_chat(self): def get_chat(self):
return self._group_chat return self._group_chat
def get_default_type(self):
return self._default_type
def __close_button_clicked_reply_cb(self): def __close_button_clicked_reply_cb(self):
pass pass
@ -364,12 +368,12 @@ class ActivityContainer(dbus.service.Object):
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \ @dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
in_signature="s", \ in_signature="ss", \
out_signature="s", \ out_signature="s", \
sender_keyword="sender") sender_keyword="sender")
def add_activity(self, activity_name, sender): def add_activity(self, activity_name, default_type, sender):
#print "hello world, activity_name = '%s', sender = '%s'"%(activity_name, sender) #print "hello world, activity_name = '%s', sender = '%s'"%(activity_name, sender)
activity = ActivityHost(self, activity_name) activity = ActivityHost(self, activity_name, default_type)
self.activities.append((sender, activity)) self.activities.append((sender, activity))
activity_id = activity.get_host_activity_id() activity_id = activity.get_host_activity_id()
@ -379,10 +383,10 @@ class ActivityContainer(dbus.service.Object):
return activity_id return activity_id
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \ @dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
in_signature="ss", \ in_signature="sss", \
sender_keyword="sender") sender_keyword="sender")
def add_activity_with_id(self, activity_name, activity_id, sender): def add_activity_with_id(self, activity_name, default_type, activity_id, sender):
activity = ActivityHost(self, activity_name, activity_id) activity = ActivityHost(self, activity_name, default_type, activity_id)
self.activities.append((sender, activity)) self.activities.append((sender, activity))
activity_id = activity.get_host_activity_id() activity_id = activity.get_host_activity_id()
self._signal_helper.activity_started(activity_id) self._signal_helper.activity_started(activity_id)