Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-08-22 12:01:53 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-08-22 12:01:53 (GMT)
commit3e51b086df1221a469bc98842fe779c47f4f2514 (patch)
treeb237039d9682bf7d6387c84c5ccc1f4a354089e1 /sugar
parent49073039e94685f697389712dbed35f5d39e4270 (diff)
Create a conf module. Move activity registry out of the shell
(should only be graphical) into it.
Diffstat (limited to 'sugar')
-rw-r--r--sugar/Makefile.am2
-rw-r--r--sugar/conf/ActivityRegistry.py118
-rw-r--r--sugar/conf/Makefile.am4
-rw-r--r--sugar/conf/__init__.py6
-rw-r--r--sugar/env.py4
5 files changed, 133 insertions, 1 deletions
diff --git a/sugar/Makefile.am b/sugar/Makefile.am
index d339fba..b13bb24 100644
--- a/sugar/Makefile.am
+++ b/sugar/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = activity canvas chat p2p presence
+SUBDIRS = activity canvas chat conf p2p presence
sugardir = $(pythondir)/sugar
sugar_PYTHON = \
diff --git a/sugar/conf/ActivityRegistry.py b/sugar/conf/ActivityRegistry.py
new file mode 100644
index 0000000..5ff0059
--- /dev/null
+++ b/sugar/conf/ActivityRegistry.py
@@ -0,0 +1,118 @@
+import logging
+import os
+from ConfigParser import ConfigParser
+from ConfigParser import NoOptionError
+
+class ActivityModule:
+ """Info about an activity module. Wraps a .activity file."""
+
+ def __init__(self, name, activity_id, directory):
+ self._name = name
+ self._icon = None
+ self._id = activity_id
+ self._directory = directory
+ self._show_launcher = False
+
+ def get_name(self):
+ """Get the activity user visible name."""
+ return self._name
+
+ def get_id(self):
+ """Get the activity identifier"""
+ return self._id
+
+ def get_icon(self):
+ """Get the activity icon name"""
+ return self._icon
+
+ def set_icon(self, icon):
+ """Set the activity icon name"""
+ self._icon = icon
+
+ def get_directory(self):
+ """Get the path to activity directory."""
+ return self._directory
+
+ def get_default_type(self):
+ """Get the the type of the default activity service."""
+ return self._default_type
+
+ def set_default_type(self, default_type):
+ """Set the the type of the default activity service."""
+ self._default_type = default_type
+
+ def get_show_launcher(self):
+ """Get whether there should be a visible launcher for the activity"""
+ return self._show_launcher
+
+ def set_show_launcher(self, show_launcher):
+ """Set whether there should be a visible launcher for the activity"""
+ self._show_launcher = show_launcher
+
+class ActivityRegistry:
+ """Service that tracks the available activities"""
+
+ def __init__(self):
+ self._activities = []
+
+ def get_activity_from_id(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):
+ """Returns an activity given his default type"""
+ for activity in self._activities:
+ if activity.get_default_type() == default_type:
+ return activity
+ return None
+
+ def scan_directory(self, path):
+ """Scan a directory for activities and add them to the registry."""
+ if os.path.isdir(path):
+ for f in os.listdir(path):
+ if f.endswith(".activity"):
+ self.add(os.path.join(path, f))
+
+ def add(self, path):
+ """Add an activity to the registry. The path points to a .activity file."""
+ cp = ConfigParser()
+ cp.read([path])
+
+ directory = os.path.dirname(path)
+
+ try:
+ activity_id = cp.get('Activity', 'id')
+ except NoOptionError:
+ logging.error('%s miss the required id option' % (path))
+ return False
+
+ try:
+ name = cp.get('Activity', 'name')
+ except NoOptionError:
+ 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)
+
+ if cp.has_option('Activity', 'show_launcher'):
+ module.set_show_launcher(True)
+
+ 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):
+ """Enumerate the registered activities as an ActivityModule list."""
+ return self._activities
diff --git a/sugar/conf/Makefile.am b/sugar/conf/Makefile.am
new file mode 100644
index 0000000..59d6562
--- /dev/null
+++ b/sugar/conf/Makefile.am
@@ -0,0 +1,4 @@
+sugardir = $(pythondir)/sugar/conf
+sugar_PYTHON = \
+ __init__.py \
+ ActivityRegistry.py
diff --git a/sugar/conf/__init__.py b/sugar/conf/__init__.py
new file mode 100644
index 0000000..6032837
--- /dev/null
+++ b/sugar/conf/__init__.py
@@ -0,0 +1,6 @@
+from sugar.conf.ActivityRegistry import ActivityRegistry
+
+__registry = ActivityRegistry()
+
+def get_activity_registry():
+ return __registry
diff --git a/sugar/env.py b/sugar/env.py
index 66299bf..0caf198 100644
--- a/sugar/env.py
+++ b/sugar/env.py
@@ -8,6 +8,7 @@ except ImportError:
from sugar.__installed__ import *
import sugar.setup
+import sugar.conf
def add_to_python_path(path):
sys.path.insert(0, path)
@@ -40,6 +41,9 @@ def setup():
sugar.setup.write_service('org.laptop.Presence', bin,
get_services_dir())
+ registry = sugar.conf.get_activity_registry()
+ registry.scan_directory(get_activities_dir())
+
def get_user_dir():
if os.environ.has_key('SUGAR_NICK_NAME'):
nick = get_nick_name()