Add default mime type handlers

This commit is contained in:
Marco Pesenti Gritti 2007-09-11 21:53:26 +02:00
parent d74f966f6d
commit 8b784a6223
5 changed files with 42 additions and 1 deletions

1
NEWS
View File

@ -1,3 +1,4 @@
* #3339 Add default mime types handler to the shell. (marco)
* #3143 Finish up the invite-only mode implementation. (marco) * #3143 Finish up the invite-only mode implementation. (marco)
Snapshot 79237f3114 Snapshot 79237f3114

View File

@ -8,6 +8,7 @@ sugar-xo.gtkrc: gtkrc.em
sugardir = $(pkgdatadir)/data sugardir = $(pkgdatadir)/data
sugar_DATA = \ sugar_DATA = \
mime.defaults \
$(GTKRC_FILES) $(GTKRC_FILES)
GTKRC_FILES = \ GTKRC_FILES = \

20
data/mime.defaults Normal file
View File

@ -0,0 +1,20 @@
# MIME Activity service name
application/pdf org.laptop.sugar.ReadActivity
text/rtf org.laptop.AbiWordActivity
text/plain org.laptop.AbiWordActivity
application/x-abiword org.laptop.AbiWordActivity
text/x-xml-abiword org.laptop.AbiWordActivity
application/msword org.laptop.AbiWordActivity
application/rtf org.laptop.AbiWordActivity
image/png org.laptop.WebActivity
image/gif org.laptop.WebActivity
image/jpeg org.laptop.WebActivity
text/html org.laptop.WebActivity
application/xhtml+xml org.laptop.WebActivity
application/xml org.laptop.WebActivity
application/rss+xml org.laptop.WebActivity
application/ogg org.osl.MediaPlayerActivity

View File

@ -29,6 +29,20 @@ def _get_data_dirs():
else: else:
return [ '/usr/local/share/', '/usr/share/' ] return [ '/usr/local/share/', '/usr/share/' ]
def _load_mime_defaults():
defaults = {}
f = open(env.get_data_path('mime.defaults'), 'r')
for line in f.readlines():
line = line.strip()
if line and not line.startswith('#'):
mime = line[:line.find(' ')]
handler = line[line.rfind(' ') + 1:]
defaults[mime] = handler
f.close()
return defaults
class _ServiceManager(object): class _ServiceManager(object):
"""Internal class responsible for creating dbus service files """Internal class responsible for creating dbus service files
@ -72,6 +86,7 @@ class BundleRegistry(gobject.GObject):
self._bundles = [] self._bundles = []
self._search_path = [] self._search_path = []
self._service_manager = _ServiceManager() self._service_manager = _ServiceManager()
self._mime_defaults = _load_mime_defaults()
def get_bundle(self, service_name): def get_bundle(self, service_name):
"""Returns an bundle given his service name""" """Returns an bundle given his service name"""
@ -120,6 +135,9 @@ class BundleRegistry(gobject.GObject):
result = [] result = []
for bundle in self._bundles: for bundle in self._bundles:
if bundle.get_mime_types() and mime_type in bundle.get_mime_types(): if bundle.get_mime_types() and mime_type in bundle.get_mime_types():
if self._mime_defaults[mime_type] == bundle.get_service_name():
result.insert(0, bundle)
else:
result.append(bundle) result.append(bundle)
return result return result

View File

@ -112,6 +112,7 @@ class DSObject(object):
activities.append(activity_info) activities.append(activity_info)
mime_type = self.metadata['mime_type'] mime_type = self.metadata['mime_type']
print mime_type
if mime_type: if mime_type:
activities_info = activity.get_registry().get_activities_for_type(mime_type) activities_info = activity.get_registry().get_activities_for_type(mime_type)
for activity_info in activities_info: for activity_info in activities_info: