2007-05-29 14:16:49 +02:00
|
|
|
# Copyright (C) 2007, Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
import dbus
|
|
|
|
import dbus.service
|
|
|
|
|
2007-08-16 13:06:39 +02:00
|
|
|
from gettext import gettext as _
|
|
|
|
|
2007-05-29 14:16:49 +02:00
|
|
|
_REGISTRY_IFACE = "org.laptop.ObjectTypeRegistry"
|
|
|
|
_REGISTRY_PATH = "/org/laptop/ObjectTypeRegistry"
|
|
|
|
|
|
|
|
class ObjectTypeRegistry(dbus.service.Object):
|
|
|
|
def __init__(self):
|
|
|
|
bus = dbus.SessionBus()
|
2007-06-12 21:57:49 +02:00
|
|
|
bus_name = dbus.service.BusName(_REGISTRY_IFACE, bus=bus)
|
|
|
|
dbus.service.Object.__init__(self, bus_name, _REGISTRY_PATH)
|
2007-05-29 14:16:49 +02:00
|
|
|
|
|
|
|
self._types = {}
|
|
|
|
|
2007-08-26 20:44:51 +02:00
|
|
|
self._add_primitive('Text', _('Text'), 'text-x-generic',
|
2007-08-21 16:53:42 +02:00
|
|
|
['text/plain', 'text/rtf', 'application/pdf',
|
2007-07-05 11:36:04 +02:00
|
|
|
'application/x-pdf', 'text/html',
|
2007-08-18 19:04:08 +02:00
|
|
|
'application/vnd.oasis.opendocument.text',
|
2007-08-21 16:53:42 +02:00
|
|
|
'application/rtf', 'text/rtf'])
|
|
|
|
|
2007-08-26 20:44:51 +02:00
|
|
|
self._add_primitive('Image', _('Image'), 'image-x-generic',
|
2007-08-21 16:53:42 +02:00
|
|
|
['image/png', 'image/gif', 'image/jpeg'])
|
|
|
|
|
2007-08-26 20:44:51 +02:00
|
|
|
self._add_primitive('Audio', _('Audio'), 'audio-x-generic',
|
2007-08-21 16:53:42 +02:00
|
|
|
['audio/ogg'])
|
|
|
|
|
2007-08-26 20:44:51 +02:00
|
|
|
self._add_primitive('Video', _('Video'), 'video-x-generic',
|
2007-08-21 17:29:41 +02:00
|
|
|
['video/ogg', 'application/ogg'])
|
2007-08-21 16:53:42 +02:00
|
|
|
|
|
|
|
self._add_primitive('Etoys project', _('Etoys project'),
|
2007-08-26 20:44:51 +02:00
|
|
|
'application-x-squeak-project',
|
2007-08-21 16:53:42 +02:00
|
|
|
['application/x-squeak-project'])
|
|
|
|
|
|
|
|
self._add_primitive('Link', _('Link'),
|
2007-08-26 20:44:51 +02:00
|
|
|
'text-uri-list',
|
2007-08-21 16:53:42 +02:00
|
|
|
['text/x-moz-url', 'text/uri-list'])
|
2007-05-29 14:16:49 +02:00
|
|
|
|
|
|
|
def _add_primitive(self, type_id, name, icon, mime_types):
|
2007-06-12 21:57:49 +02:00
|
|
|
object_type = {'type_id': type_id,
|
|
|
|
'name': name,
|
|
|
|
'icon': icon,
|
|
|
|
'mime_types': mime_types}
|
|
|
|
self._types[type_id] = object_type
|
2007-05-29 14:16:49 +02:00
|
|
|
|
|
|
|
def _get_type_for_mime(self, mime_type):
|
|
|
|
for object_type in self._types.values():
|
2007-06-12 21:57:49 +02:00
|
|
|
if mime_type in object_type['mime_types']:
|
2007-05-29 14:16:49 +02:00
|
|
|
return object_type
|
2007-08-21 16:53:42 +02:00
|
|
|
return None
|
2007-05-29 14:16:49 +02:00
|
|
|
|
2007-06-12 21:57:49 +02:00
|
|
|
@dbus.service.method(_REGISTRY_IFACE,
|
2007-05-29 14:16:49 +02:00
|
|
|
in_signature="s", out_signature="a{sv}")
|
|
|
|
def GetType(self, type_id):
|
|
|
|
if self._types.has_key(type_id):
|
2007-06-12 21:57:49 +02:00
|
|
|
return self._types[type_id]
|
2007-05-29 14:16:49 +02:00
|
|
|
else:
|
2007-06-12 21:57:49 +02:00
|
|
|
return {}
|
2007-05-29 14:16:49 +02:00
|
|
|
|
2007-06-12 21:57:49 +02:00
|
|
|
@dbus.service.method(_REGISTRY_IFACE,
|
2007-05-29 14:16:49 +02:00
|
|
|
in_signature="s", out_signature="a{sv}")
|
|
|
|
def GetTypeForMIME(self, mime_type):
|
|
|
|
object_type = self._get_type_for_mime(mime_type)
|
|
|
|
if object_type:
|
2007-06-12 21:57:49 +02:00
|
|
|
return object_type
|
2007-05-29 14:16:49 +02:00
|
|
|
else:
|
2007-06-12 21:57:49 +02:00
|
|
|
return {}
|
2007-06-20 21:28:00 +02:00
|
|
|
|
|
|
|
_instance = None
|
|
|
|
|
|
|
|
def get_instance():
|
|
|
|
global _instance
|
|
|
|
if not _instance:
|
|
|
|
_instance = ObjectTypeRegistry()
|
|
|
|
return _instance
|