Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-09-02 08:54:34 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-09-02 08:54:34 (GMT)
commit58a79eb1234f1681af033ff8711c3dbc6baa00b0 (patch)
tree97c3bdabc8ddc97ba885d17883410ba0914c1cb6
parent8ffff18bc330540d38a8188a79e53467dcf19874 (diff)
Get rid of default type from the activity definition.
Modify code to use activity type id instead, except from mapping service to activity.
-rw-r--r--activities/browser/BrowserActivity.py3
-rw-r--r--activities/browser/browser.activity1
-rw-r--r--shell/ActivityHost.py8
-rwxr-xr-xshell/Shell.py22
-rw-r--r--shell/frame/BottomPanel.py2
-rw-r--r--shell/home/MeshGroup.py4
-rw-r--r--sugar/activity/Activity.py29
-rw-r--r--sugar/activity/ActivityFactory.py7
-rw-r--r--sugar/conf/ActivityRegistry.py24
-rw-r--r--sugar/conf/__init__.py4
10 files changed, 48 insertions, 56 deletions
diff --git a/activities/browser/BrowserActivity.py b/activities/browser/BrowserActivity.py
index f702570..a8c795a 100644
--- a/activities/browser/BrowserActivity.py
+++ b/activities/browser/BrowserActivity.py
@@ -51,8 +51,7 @@ class BrowserActivity(Activity):
activity_ps.connect('service-appeared', self._service_appeared_cb)
- default_type = self.get_default_type()
- services = activity_ps.get_services_of_type(default_type)
+ services = activity_ps.get_services_of_type(self._default_type)
if len(services) > 0:
self._notif_service = services[0]
diff --git a/activities/browser/browser.activity b/activities/browser/browser.activity
index 47eea7f..8b4ed24 100644
--- a/activities/browser/browser.activity
+++ b/activities/browser/browser.activity
@@ -3,5 +3,4 @@ name = Web
id = com.redhat.Sugar.BrowserActivity
icon = activity-web
python_module = browser.BrowserActivity.BrowserActivity
-default_type = _web_olpc._udp
show_launcher = yes
diff --git a/shell/ActivityHost.py b/shell/ActivityHost.py
index 710da8f..49e23d8 100644
--- a/shell/ActivityHost.py
+++ b/shell/ActivityHost.py
@@ -18,11 +18,11 @@ class ActivityHost:
self._activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE)
self._id = self._activity.get_id()
- self._default_type = self._activity.get_default_type()
+ self._type = self._activity.get_type()
self._gdk_window = gtk.gdk.window_foreign_new(self._xid)
registry = conf.get_activity_registry()
- info = registry.get_activity(self._default_type)
+ info = registry.get_activity(self._type)
self._icon_name = info.get_icon()
def get_id(self):
@@ -45,8 +45,8 @@ class ActivityHost:
def get_shared(self):
return self._activity.get_shared()
- def get_default_type(self):
- return self._default_type
+ def get_type(self):
+ return self._type
def present(self):
self._window.activate(gtk.get_current_event_time())
diff --git a/shell/Shell.py b/shell/Shell.py
index e5de4c8..204ab67 100755
--- a/shell/Shell.py
+++ b/shell/Shell.py
@@ -155,12 +155,12 @@ class Shell(gobject.GObject):
activity = self.get_current_activity()
if activity:
registry = conf.get_activity_registry()
- module = registry.get_activity(activity.get_default_type())
+ module = registry.get_activity(activity.get_type())
self._console.set_page(module.get_id())
def join_activity(self, service):
registry = conf.get_activity_registry()
- info = registry.get_activity(service.get_type())
+ info = registry.get_activity_from_type(service.get_type())
activity_id = service.get_activity_id()
@@ -172,24 +172,14 @@ class Shell(gobject.GObject):
if activity_ps:
activity = ActivityFactory.create(info.get_id())
- activity.set_default_type(service.get_type())
activity.join(activity_ps.object_path())
else:
logging.error('Cannot start activity.')
- def start_activity(self, activity_name):
- activity = ActivityFactory.create(activity_name)
- registry = conf.get_activity_registry()
- info = registry.get_activity_from_id(activity_name)
- if info:
- default_type = info.get_default_type()
- if default_type != None:
- activity.set_default_type(default_type)
- activity.execute('test', [])
- return activity
- else:
- logging.error('No such activity in the directory')
- return None
+ def start_activity(self, activity_type):
+ activity = ActivityFactory.create(activity_type)
+ activity.execute('test', [])
+ return activity
def get_chat_controller(self):
return self._chat_controller
diff --git a/shell/frame/BottomPanel.py b/shell/frame/BottomPanel.py
index 29e7ef1..e3e1fa6 100644
--- a/shell/frame/BottomPanel.py
+++ b/shell/frame/BottomPanel.py
@@ -11,7 +11,7 @@ class ActivityItem(IconItem):
def __init__(self, activity, size):
icon_name = activity.get_icon()
if not icon_name:
- act_type = activity.get_default_type()
+ act_type = activity.get_type()
raise RuntimeError("Activity %s did not have an icon!" % act_type)
IconItem.__init__(self, icon_name=icon_name,
color=IconColor('white'), size=size)
diff --git a/shell/home/MeshGroup.py b/shell/home/MeshGroup.py
index ddf46cf..96cb779 100644
--- a/shell/home/MeshGroup.py
+++ b/shell/home/MeshGroup.py
@@ -21,7 +21,7 @@ class ActivityItem(IconItem):
def get_icon_name(self):
registry = conf.get_activity_registry()
- info = registry.get_activity(self._service.get_type())
+ info = registry.get_activity_from_type(self._service.get_type())
return info.get_icon()
@@ -62,7 +62,7 @@ class MeshGroup(goocanvas.Group):
def __check_service(self, service):
registry = conf.get_activity_registry()
- if registry.get_activity(service.get_type()) != None:
+ if registry.get_activity_from_type(service.get_type()) != None:
if not self.has_activity(service.get_activity_id()):
self.add_activity(service)
diff --git a/sugar/activity/Activity.py b/sugar/activity/Activity.py
index de6218a..62fbed6 100644
--- a/sugar/activity/Activity.py
+++ b/sugar/activity/Activity.py
@@ -7,6 +7,7 @@ import gtk
import gobject
from sugar.presence.PresenceService import PresenceService
+from sugar.conf import ActivityRegistry
import sugar.util
ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
@@ -47,14 +48,14 @@ class ActivityDbusService(dbus.service.Object):
return self._activity.get_id()
@dbus.service.method(ACTIVITY_INTERFACE)
- def get_default_type(self):
- """Get the activity default type"""
- return self._activity.get_default_type()
+ def get_type(self):
+ """Get the activity type"""
+ return self._activity.get_type()
@dbus.service.method(ACTIVITY_INTERFACE)
- def set_default_type(self, default_type):
- """Set the activity default type"""
- self._activity.set_default_type(default_type)
+ def set_type(self, activity_type):
+ """Set the activity type"""
+ self._activity.set_type(activity_type)
@dbus.service.method(ACTIVITY_INTERFACE)
def get_shared(self):
@@ -92,16 +93,14 @@ class Activity(gtk.Window):
self._bus = ActivityDbusService(bus_name, get_object_path(xid))
self._bus.start(self._pservice, self)
- def set_default_type(self, default_type):
- """Set the activity default type.
+ def set_type(self, activity_type):
+ """Sets the activity type."""
+ self._activity_type = activity_type
+ self._default_type = ActivityRegistry.get_default_type(activity_type)
- It's the type of the main network service which tracks presence
- and provides info about the activity, for example the title."""
- self._default_type = default_type
-
- def get_default_type(self):
- """Get the activity default type."""
- return self._default_type
+ def get_type(self):
+ """Gets the activity type."""
+ return self._activity_type
def get_shared(self):
"""Returns TRUE if the activity is shared on the mesh."""
diff --git a/sugar/activity/ActivityFactory.py b/sugar/activity/ActivityFactory.py
index 3d47def..e7a991b 100644
--- a/sugar/activity/ActivityFactory.py
+++ b/sugar/activity/ActivityFactory.py
@@ -19,7 +19,9 @@ def _get_factory(activity_name):
class ActivityFactory(dbus.service.Object):
"""Dbus service that takes care of creating new instances of an activity"""
- def __init__(self, name, activity_class):
+ def __init__(self, activity_type, activity_class):
+ self._activity_type = activity_type
+
splitted_module = activity_class.rsplit('.', 1)
module_name = splitted_module[0]
class_name = splitted_module[1]
@@ -31,13 +33,14 @@ class ActivityFactory(dbus.service.Object):
self._class = getattr(module, class_name)
bus = dbus.SessionBus()
- factory = _get_factory(name)
+ factory = _get_factory(activity_type)
bus_name = dbus.service.BusName(factory, bus = bus)
dbus.service.Object.__init__(self, bus_name, get_path(factory))
@dbus.service.method("com.redhat.Sugar.ActivityFactory")
def create(self):
activity = self._class()
+ activity.set_type(self._activity_type)
return activity.window.xid
def create(activity_name):
diff --git a/sugar/conf/ActivityRegistry.py b/sugar/conf/ActivityRegistry.py
index 189d3d9..c9b4e2e 100644
--- a/sugar/conf/ActivityRegistry.py
+++ b/sugar/conf/ActivityRegistry.py
@@ -5,6 +5,15 @@ from ConfigParser import NoOptionError
from sugar import env
+def get_default_type(activity_type):
+ """Get the activity default type.
+
+ It's the type of the main network service which tracks presence
+ and provides info about the activity, for example the title."""
+ splitted_id = activity_type.split('.')
+ splitted_id.reverse()
+ return '_' + '_'.join(splitted_id) + '._udp'
+
class ActivityModule:
"""Info about an activity module. Wraps a .activity file."""
@@ -37,7 +46,7 @@ class ActivityModule:
def get_default_type(self):
"""Get the the type of the default activity service."""
- return self._default_type
+ return get_default_type(self._id)
def set_default_type(self, default_type):
"""Set the the type of the default activity service."""
@@ -51,21 +60,21 @@ class ActivityModule:
"""Set whether there should be a visible launcher for the activity"""
self._show_launcher = show_launcher
-class ActivityRegistry:
+class _ActivityRegistry:
"""Service that tracks the available activities"""
def __init__(self):
self._activities = []
self.scan_directory(env.get_activities_dir())
- def get_activity_from_id(self, activity_id):
+ def get_activity(self, activity_id):
"""Returns an activity given his identifier"""
for activity in self._activities:
if activity.get_id() == activity_id:
return activity
return None
- def get_activity(self, default_type):
+ def get_activity_from_type(self, default_type):
"""Returns an activity given his default type"""
for activity in self._activities:
if activity.get_default_type() == default_type:
@@ -98,11 +107,6 @@ class ActivityRegistry:
logging.error('%s miss the required name option' % (path))
return False
- if cp.has_option('Activity', 'default_type'):
- default_type = cp.get('Activity', 'default_type')
- else:
- default_type = None
-
module = ActivityModule(name, activity_id, directory)
self._activities.append(module)
@@ -112,8 +116,6 @@ class ActivityRegistry:
if cp.has_option('Activity', 'icon'):
module.set_icon(cp.get('Activity', 'icon'))
- module.set_default_type(default_type)
-
return True
def list_activities(self):
diff --git a/sugar/conf/__init__.py b/sugar/conf/__init__.py
index 08532b2..d8406fa 100644
--- a/sugar/conf/__init__.py
+++ b/sugar/conf/__init__.py
@@ -1,7 +1,7 @@
-from sugar.conf.ActivityRegistry import ActivityRegistry
+from sugar.conf.ActivityRegistry import _ActivityRegistry
from sugar.conf.Profile import Profile
-__registry = ActivityRegistry()
+__registry = _ActivityRegistry()
__profile = Profile()
def get_activity_registry():