Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2007-09-26 08:09:55 (GMT)
committer Marco Pesenti Gritti <mpg@redhat.com>2007-09-26 08:09:55 (GMT)
commit2a197bb8b863a0f2a71e40a501fe5f2e8e07f371 (patch)
treec7f2f088b5c628aaa61ec31284121fb790d18f97
parent55baffea32b3754ca120a75ce1b1ebd76ba613f8 (diff)
parent8ff6cbab1ea5f2b45064c278fbf77e4a1931f5c2 (diff)
Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
-rw-r--r--services/shell/objecttypeservice.py33
-rw-r--r--sugar/bundle/activitybundle.py50
-rw-r--r--sugar/bundle/bundle.py4
3 files changed, 76 insertions, 11 deletions
diff --git a/services/shell/objecttypeservice.py b/services/shell/objecttypeservice.py
index 4e806d4..c4910f7 100644
--- a/services/shell/objecttypeservice.py
+++ b/services/shell/objecttypeservice.py
@@ -16,9 +16,13 @@
import dbus
import dbus.service
+import gnomevfs
+import gtk
from gettext import gettext as _
+import bundleregistry
+
_REGISTRY_IFACE = "org.laptop.ObjectTypeRegistry"
_REGISTRY_PATH = "/org/laptop/ObjectTypeRegistry"
@@ -53,6 +57,11 @@ class ObjectTypeRegistry(dbus.service.Object):
'text-uri-list',
['text/x-moz-url', 'text/uri-list'])
+ self._activity_registry = bundleregistry.get_registry()
+ for bundle in self._activity_registry:
+ self._add_activity(self._activity_registry, bundle)
+ self._activity_registry.connect('bundle-added', self._add_activity)
+
def _add_primitive(self, type_id, name, icon, mime_types):
object_type = {'type_id': type_id,
'name': name,
@@ -60,6 +69,30 @@ class ObjectTypeRegistry(dbus.service.Object):
'mime_types': mime_types}
self._types[type_id] = object_type
+ def _add_activity(self, activity_registry, bundle):
+ mime_types = bundle.get_mime_types()
+ if mime_types is None:
+ return
+
+ icon_theme = gtk.icon_theme_get_default()
+ for mime_type in mime_types:
+ if self._get_type_for_mime(mime_type) is not None:
+ continue
+
+ name = gnomevfs.mime_get_description(mime_type)
+ if name is None:
+ continue
+
+ icon = mime_type.replace('/', '-')
+ if icon_theme.lookup_icon(icon, gtk.ICON_SIZE_BUTTON, 0) is None:
+ continue
+
+ object_type = {'type_id': mime_type,
+ 'name': name,
+ 'icon': icon,
+ 'mime_types': [mime_type]}
+ self._types[mime_type] = object_type
+
def _get_type_for_mime(self, mime_type):
for object_type in self._types.values():
if mime_type in object_type['mime_types']:
diff --git a/sugar/bundle/activitybundle.py b/sugar/bundle/activitybundle.py
index 07a5255..f77bdb7 100644
--- a/sugar/bundle/activitybundle.py
+++ b/sugar/bundle/activitybundle.py
@@ -213,8 +213,6 @@ class ActivityBundle(Bundle):
self._unzip(install_dir)
install_path = os.path.join(install_dir, self._zip_root_dir)
- if not activity.get_registry().add_bundle(install_path):
- raise RegistrationException
xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share'))
@@ -229,20 +227,54 @@ class ActivityBundle(Bundle):
os.spawnlp(os.P_WAIT, 'update-mime-database',
'update-mime-database', mime_dir)
- icons_dir = os.path.join(install_path, 'activity', 'mime-icons')
- if os.path.isdir(icons_dir):
- installed_icons_dir = os.path.join(xdg_data_home, 'icons/sugar/scalable/mimetypes')
+ mime_types = self.get_mime_types()
+ if mime_types is not None:
+ installed_icons_dir = os.path.join(xdg_data_home,
+ 'icons/sugar/scalable/mimetypes')
if not os.path.isdir(installed_icons_dir):
os.makedirs(installed_icons_dir)
- for file in os.listdir(icons_dir):
- if file.endswith('.svg') or file.endswith('.icon'):
- os.symlink(os.path.join(icons_dir, file),
- os.path.join(installed_icons_dir, file))
+
+ for mime_type in mime_types:
+ mime_icon_base = os.path.join(install_path, 'activity',
+ mime_type.replace('/', '-'))
+ svg_file = mime_icon_base + '.svg'
+ info_file = mime_icon_base + '.icon'
+ if os.path.isfile(svg_file):
+ os.symlink(svg_file,
+ os.path.join(installed_icons_dir,
+ os.path.basename(svg_file)))
+ if os.path.isfile(info_file):
+ os.symlink(info_file,
+ os.path.join(installed_icons_dir,
+ os.path.basename(info_file)))
+
+ if not activity.get_registry().add_bundle(install_path):
+ raise RegistrationException
def uninstall(self):
if not self.is_installed():
raise NotInstalledException
+ xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share'))
+
+ mime_dir = os.path.join(xdg_data_home, 'mime')
+ installed_mime_path = os.path.join(mime_dir, 'packages', '%s.xml' % self._service_name)
+ if os.path.exists(installed_mime_path):
+ os.remove(installed_mime_path)
+ os.spawnlp(os.P_WAIT, 'update-mime-database',
+ 'update-mime-database', mime_dir)
+
+ mime_types = self.get_mime_types()
+ if mime_types is not None:
+ installed_icons_dir = os.path.join(xdg_data_home,
+ 'icons/sugar/scalable/mimetypes')
+ for file in os.listdir(installed_icons_dir):
+ path = os.path.join(installed_icons_dir, file)
+ if os.path.islink(path) and \
+ os.readlink(path).startswith(self._path):
+ os.remove(path)
+
self._uninstall()
+
# FIXME: notify shell
diff --git a/sugar/bundle/bundle.py b/sugar/bundle/bundle.py
index a2e9076..75b4b38 100644
--- a/sugar/bundle/bundle.py
+++ b/sugar/bundle/bundle.py
@@ -127,7 +127,7 @@ class Bundle:
zip.write(filename, os.path.join(base_dir, filename))
zip.close()
- def remove(self):
+ def _uninstall(self):
ext = os.path.splitext(self._path)[1]
if self._unpacked:
if not os.path.isdir(self._path) or ext != self._unzipped_extension:
@@ -137,7 +137,7 @@ class Bundle:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
- os.rmdir(root)
+ os.rmdir(self._path)
else:
if not os.path.isfile(self._path) or ext != self._zipped_extension:
raise InvalidPathException