Several fixes for the object type registry and the activity registry.
This commit is contained in:
@@ -4,18 +4,23 @@ service_in_files = \
|
||||
org.laptop.Clipboard.service.in \
|
||||
org.laptop.ObjectTypeRegistry.service.in
|
||||
|
||||
service_DATA = $(service_in_files:.service.in=.service)
|
||||
service_DATA = \
|
||||
org.laptop.Clipboard.service \
|
||||
org.laptop.ObjectTypeRegistry.service
|
||||
|
||||
$(service_DATA): $(service_in_files) Makefile
|
||||
org.laptop.Clipboard.service: org.laptop.Clipboard.service.in Makefile
|
||||
@sed -e "s|\@bindir\@|$(bindir)|" $< > $@
|
||||
|
||||
org.laptop.ObjectTypeRegistry.service: org.laptop.ObjectTypeRegistry.service.in Makefile
|
||||
@sed -e "s|\@bindir\@|$(bindir)|" $< > $@
|
||||
|
||||
sugardir = $(pkgdatadir)/services/clipboard
|
||||
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
clipboardobject.py \
|
||||
clipboardservice.py \
|
||||
objecttypeservice.py \
|
||||
objecttypeservice.py \
|
||||
typeregistry.py
|
||||
|
||||
bin_SCRIPTS = sugar-clipboard
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import logging
|
||||
import gobject
|
||||
import os
|
||||
import shutil
|
||||
import dbus
|
||||
@@ -32,14 +31,13 @@ PREVIEW_KEY = 'PREVIEW'
|
||||
ACTIVITY_KEY = 'ACTIVITY'
|
||||
FORMATS_KEY = 'FORMATS'
|
||||
|
||||
class ClipboardDBusServiceHelper(dbus.service.Object):
|
||||
class ClipboardService(dbus.service.Object):
|
||||
|
||||
_CLIPBOARD_DBUS_INTERFACE = "org.laptop.Clipboard"
|
||||
_CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard"
|
||||
_CLIPBOARD_OBJECTS_PATH = _CLIPBOARD_OBJECT_PATH + "/Objects/"
|
||||
|
||||
def __init__(self, parent):
|
||||
self._parent = parent
|
||||
def __init__(self):
|
||||
self._objects = {}
|
||||
self._next_id = 0
|
||||
|
||||
@@ -175,13 +173,3 @@ class ClipboardDBusServiceHelper(dbus.service.Object):
|
||||
def object_state_changed(self, object_path, values):
|
||||
pass
|
||||
|
||||
class ClipboardService(object):
|
||||
def __init__(self):
|
||||
self._dbus_helper = ClipboardDBusServiceHelper(self)
|
||||
|
||||
def run(self):
|
||||
loop = gobject.MainLoop()
|
||||
try:
|
||||
loop.run()
|
||||
except KeyboardInterrupt:
|
||||
print 'Ctrl+C pressed, exiting...'
|
||||
|
||||
@@ -17,46 +17,49 @@
|
||||
import dbus
|
||||
import dbus.service
|
||||
|
||||
from sugar.objects.objecttype import ObjectType
|
||||
|
||||
_REGISTRY_IFACE = "org.laptop.ObjectTypeRegistry"
|
||||
_REGISTRY_PATH = "/org/laptop/ObjectTypeRegistry"
|
||||
|
||||
class ObjectTypeRegistry(dbus.service.Object):
|
||||
def __init__(self):
|
||||
bus = dbus.SessionBus()
|
||||
bus_name = dbus.service.BusName(self._REGISTRY_IFACE, bus=bus)
|
||||
dbus.service.Object.__init__(self, bus_name, self._REGISTRY_PATH)
|
||||
bus_name = dbus.service.BusName(_REGISTRY_IFACE, bus=bus)
|
||||
dbus.service.Object.__init__(self, bus_name, _REGISTRY_PATH)
|
||||
|
||||
self._types = {}
|
||||
|
||||
self._add_primitive('Text', _('Text'), 'object-text',
|
||||
[ 'text/rtf' ])
|
||||
self._add_primitive('Image', _('Image'), 'object-image',
|
||||
from gettext import gettext as _
|
||||
self._add_primitive('Text', _('Text'), 'theme:object-text',
|
||||
[ 'text/plain', 'text/rtf', 'application/pdf',
|
||||
'application/x-pdf' ])
|
||||
self._add_primitive('Image', _('Image'), 'theme:object-image',
|
||||
[ 'image/png' ])
|
||||
|
||||
def _add_primitive(self, type_id, name, icon, mime_types):
|
||||
object_type = ObjectType(type_id, name, icon, mime_types)
|
||||
self._types.add(object_type)
|
||||
object_type = {'type_id': type_id,
|
||||
'name': name,
|
||||
'icon': icon,
|
||||
'mime_types': mime_types}
|
||||
self._types[type_id] = 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:
|
||||
if mime_type in object_type['mime_types']:
|
||||
return object_type
|
||||
|
||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
||||
@dbus.service.method(_REGISTRY_IFACE,
|
||||
in_signature="s", out_signature="a{sv}")
|
||||
def GetType(self, type_id):
|
||||
if self._types.has_key(type_id):
|
||||
return self._types[type_id].to_dict()
|
||||
return self._types[type_id]
|
||||
else:
|
||||
return []
|
||||
return {}
|
||||
|
||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
||||
@dbus.service.method(_REGISTRY_IFACE,
|
||||
in_signature="s", out_signature="a{sv}")
|
||||
def GetTypeForMIME(self, mime_type):
|
||||
object_type = self._get_type_for_mime(mime_type)
|
||||
if object_type:
|
||||
return object_type.to_dict()
|
||||
return object_type
|
||||
else:
|
||||
return []
|
||||
return {}
|
||||
|
||||
@@ -35,11 +35,18 @@ from sugar import env
|
||||
sys.path.append(env.get_service_path('clipboard'))
|
||||
|
||||
from clipboardservice import ClipboardService
|
||||
from objecttypeservice import ObjectTypeRegistry
|
||||
|
||||
logging.info('Starting clipboard service.')
|
||||
|
||||
gobject.threads_init()
|
||||
dbus.glib.threads_init()
|
||||
|
||||
app = ClipboardService()
|
||||
app.run()
|
||||
clipboard_service = ClipboardService()
|
||||
object_type_registry = ObjectTypeRegistry()
|
||||
|
||||
loop = gobject.MainLoop()
|
||||
try:
|
||||
loop.run()
|
||||
except KeyboardInterrupt:
|
||||
print 'Ctrl+C pressed, exiting...'
|
||||
|
||||
Reference in New Issue
Block a user