From 13682dd1b4458899e7044e1e917e5bc7a905fee4 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Tue, 16 Sep 2008 11:13:36 +0200 Subject: [PATCH 1/3] Move DSObject.resume() from sugar-toolkit to the shell --- src/sugar/datastore/datastore.py | 81 -------------------------------- 1 file changed, 81 deletions(-) diff --git a/src/sugar/datastore/datastore.py b/src/sugar/datastore/datastore.py index 81c00e40..9cd22bfd 100644 --- a/src/sugar/datastore/datastore.py +++ b/src/sugar/datastore/datastore.py @@ -23,8 +23,6 @@ import os import gobject from sugar.datastore import dbus_helpers -from sugar import activity -from sugar.activity.activityhandle import ActivityHandle from sugar.bundle.contentbundle import ContentBundle from sugar.bundle.activitybundle import ActivityBundle from sugar import mime @@ -116,32 +114,6 @@ class DSObject(object): file_path = property(get_file_path, set_file_path) - def _get_activities_for_mime(self, mime_type): - registry = activity.get_registry() - result = registry.get_activities_for_type(mime_type) - if not result: - for parent_mime in mime.get_mime_parents(mime_type): - result.extend(registry.get_activities_for_type(parent_mime)) - return result - - def get_activities(self): - activities = [] - - bundle_id = self.metadata.get('activity', '') - if bundle_id: - activity_info = activity.get_registry().get_activity(bundle_id) - if activity_info: - activities.append(activity_info) - - mime_type = self.metadata.get('mime_type', '') - if mime_type: - activities_info = self._get_activities_for_mime(mime_type) - for activity_info in activities_info: - if activity_info.bundle_id != bundle_id: - activities.append(activity_info) - - return activities - def is_activity_bundle(self): return self.metadata['mime_type'] in \ [ActivityBundle.MIME_TYPE, ActivityBundle.DEPRECATED_MIME_TYPE] @@ -152,59 +124,6 @@ class DSObject(object): def is_bundle(self): return self.is_activity_bundle() or self.is_content_bundle() - def resume(self, bundle_id=None): - from sugar.activity import activityfactory - - if self.is_activity_bundle() and not bundle_id: - - logging.debug('Creating activity bundle') - bundle = ActivityBundle(self.file_path) - if not bundle.is_installed(): - logging.debug('Installing activity bundle') - bundle.install() - elif bundle.need_upgrade(): - logging.debug('Upgrading activity bundle') - bundle.upgrade() - - logging.debug('activityfactory.creating bundle with id %r', - bundle.get_bundle_id()) - activityfactory.create(bundle.get_bundle_id()) - - elif self.is_content_bundle() and not bundle_id: - - logging.debug('Creating content bundle') - bundle = ContentBundle(self.file_path) - if not bundle.is_installed(): - logging.debug('Installing content bundle') - bundle.install() - - activities = self._get_activities_for_mime('text/html') - if len(activities) == 0: - logging.warning('No activity can open HTML content bundles') - return - - uri = bundle.get_start_uri() - logging.debug('activityfactory.creating with uri %s', uri) - activityfactory.create_with_uri(activities[0].bundle_id, - bundle.get_start_uri()) - else: - if not self.get_activities() and bundle_id is None: - logging.warning('No activity can open this object, %s.' % - self.metadata.get('mime_type', None)) - return - if bundle_id is None: - bundle_id = self.get_activities()[0].bundle_id - - activity_id = self.metadata['activity_id'] - object_id = self.object_id - - if activity_id: - handle = ActivityHandle(object_id=object_id, - activity_id=activity_id) - activityfactory.create(bundle_id, handle) - else: - activityfactory.create_with_object_id(bundle_id, object_id) - def destroy(self): if self._destroyed: logging.warning('This DSObject has already been destroyed!.') From be32d3fb6705ad238adbe5629a5c267e851e3e36 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Tue, 16 Sep 2008 15:34:26 +0200 Subject: [PATCH 2/3] Remove the clipboard service wrapper --- configure.ac | 1 - src/sugar/Makefile.am | 2 +- src/sugar/clipboard/Makefile.am | 5 - src/sugar/clipboard/__init__.py | 22 --- src/sugar/clipboard/clipboardservice.py | 230 ------------------------ 5 files changed, 1 insertion(+), 259 deletions(-) delete mode 100644 src/sugar/clipboard/Makefile.am delete mode 100644 src/sugar/clipboard/__init__.py delete mode 100644 src/sugar/clipboard/clipboardservice.py diff --git a/configure.ac b/configure.ac index 23605ae4..271bc4ad 100644 --- a/configure.ac +++ b/configure.ac @@ -39,7 +39,6 @@ src/Makefile src/sugar/Makefile src/sugar/activity/Makefile src/sugar/bundle/Makefile -src/sugar/clipboard/Makefile src/sugar/graphics/Makefile src/sugar/presence/Makefile src/sugar/datastore/Makefile diff --git a/src/sugar/Makefile.am b/src/sugar/Makefile.am index ef7e634c..dabb35dd 100644 --- a/src/sugar/Makefile.am +++ b/src/sugar/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = activity bundle clipboard graphics presence datastore +SUBDIRS = activity bundle graphics presence datastore sugardir = $(pythondir)/sugar sugar_PYTHON = \ diff --git a/src/sugar/clipboard/Makefile.am b/src/sugar/clipboard/Makefile.am deleted file mode 100644 index 0d61c29e..00000000 --- a/src/sugar/clipboard/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -sugardir = $(pythondir)/sugar/clipboard -sugar_PYTHON = \ - __init__.py \ - clipboardservice.py - diff --git a/src/sugar/clipboard/__init__.py b/src/sugar/clipboard/__init__.py deleted file mode 100644 index deee8dd0..00000000 --- a/src/sugar/clipboard/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Client-code's interface to the ClipboardService - -Provides a simplified API for accessing the dbus service -which coordinates clipboard operations within Sugar. -""" -# Copyright (C) 2007, One Laptop Per Child -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - diff --git a/src/sugar/clipboard/clipboardservice.py b/src/sugar/clipboard/clipboardservice.py deleted file mode 100644 index 59ef0fba..00000000 --- a/src/sugar/clipboard/clipboardservice.py +++ /dev/null @@ -1,230 +0,0 @@ -"""UI class to access system-level clipboard object""" -# Copyright (C) 2007, One Laptop Per Child -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. -import logging -import dbus -import gobject - -NAME_KEY = 'NAME' -PERCENT_KEY = 'PERCENT' -ICON_KEY = 'ICON' -PREVIEW_KEY = 'PREVIEW' -ACTIVITIES_KEY = 'ACTIVITIES' -FORMATS_KEY = 'FORMATS' - -TYPE_KEY = 'TYPE' -DATA_KEY = 'DATA' -ON_DISK_KEY = 'ON_DISK' - -DBUS_SERVICE = "org.laptop.Clipboard" -DBUS_INTERFACE = "org.laptop.Clipboard" -DBUS_PATH = "/org/laptop/Clipboard" - -class ClipboardService(gobject.GObject): - """GUI interfaces for the system clipboard dbus service - - This object is used to provide convenient access to the clipboard - service (see source/services/clipboard/clipboardservice.py). It - provides utility methods for adding/getting/removing objects from - the clipboard as well as generating events when such events occur. - - Meaning is source/services/clipboard/clipboardobject.py - objects when describing "objects" on the clipboard. - """ - __gsignals__ = { - 'object-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([str, str])), - 'object-deleted': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([str])), - 'object-state-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([str, str, int, str, str, object])), - } - - def __init__(self): - """Initialise the ClipboardService instance - - If the service is not yet active in the background uses - a signal watcher to connect when the service appears. - """ - gobject.GObject.__init__(self) - - self._dbus_service = None - - bus = dbus.SessionBus() - self._nameOwnerChangedHandler = bus.add_signal_receiver( - self._name_owner_changed_cb, - signal_name="NameOwnerChanged", - dbus_interface="org.freedesktop.DBus", - arg0=DBUS_SERVICE) - - self._connected = False - # Try to register to ClipboardService, if we fail, we'll try later. - try: - self._connect_clipboard_signals() - except dbus.DBusException, exception: - logging.debug(exception) - - def _connect_clipboard_signals(self): - """Connect dbus signals to our GObject signal generating callbacks""" - bus = dbus.SessionBus() - if not self._connected: - # NOTE: We need to follow_name_owner_changes here - # because we can not connect to a signal unless - # we follow the changes or we start the service - # before we connect. Starting the service here - # causes a major bottleneck during startup - proxy_obj = bus.get_object(DBUS_SERVICE, - DBUS_PATH, - follow_name_owner_changes=True) - self._dbus_service = dbus.Interface(proxy_obj, DBUS_SERVICE) - self._dbus_service.connect_to_signal('object_added', - self._object_added_cb) - self._dbus_service.connect_to_signal('object_deleted', - self._object_deleted_cb) - self._dbus_service.connect_to_signal('object_state_changed', - self._object_state_changed_cb) - self._connected = True - - bus.remove_signal_receiver(self._nameOwnerChangedHandler) - - def _name_owner_changed_cb(self, name, old, new): - """On backend service creation, connect to the server""" - if not old and new: - # ClipboardService started up - self._connect_clipboard_signals() - - def _object_added_cb(self, object_id, name): - """Emit an object-added GObject event when dbus event arrives""" - self.emit('object-added', str(object_id), name) - - def _object_deleted_cb(self, object_id): - """Emit an object-deleted GObject event when dbus event arrives""" - self.emit('object-deleted', str(object_id)) - - def _object_state_changed_cb(self, object_id, values): - """Emit an object-state-changed GObject event when dbus event arrives - - GObject event has: - - object_id - name - percent - icon - preview - activities - - From the ClipboardObject instance which is being described. - """ - self.emit('object-state-changed', str(object_id), values[NAME_KEY], - values[PERCENT_KEY], values[ICON_KEY], values[PREVIEW_KEY], - values[ACTIVITIES_KEY]) - - def add_object(self, name): - """Add a new object to the path - - returns dbus path-name for the new object's cliboard service, - this is used for all future references to the cliboard object. - - Note: - That service is actually provided by the clipboard - service object, not the ClipboardObject - """ - return str(self._dbus_service.add_object(name)) - - def add_object_format(self, object_id, formatType, data, on_disk): - """Annotate given object on the clipboard with new information - - object_id -- dbus path as returned from add_object - formatType -- XXX what should this be? mime type? - data -- storage format for the clipped object? - on_disk -- whether the data is on-disk (non-volatile) or in - memory (volatile) - - Last three arguments are just passed directly to the - clipboardobject.Format instance on the server side. - - returns None - """ - self._dbus_service.add_object_format(dbus.ObjectPath(object_id), - formatType, - data, - on_disk) - - def delete_object(self, object_id): - """Remove the given object from the clipboard - - object_id -- dbus path as returned from add_object - """ - self._dbus_service.delete_object(dbus.ObjectPath(object_id)) - - def set_object_percent(self, object_id, percent): - """Set the "percentage" for the given clipboard object - - object_id -- dbus path as returned from add_object - percentage -- numeric value from 0 to 100 inclusive - - Object percentages which are set to 100% trigger "file-completed" - operations, see the backend ClipboardService's - _handle_file_completed method for details. - - returns None - """ - self._dbus_service.set_object_percent( - dbus.ObjectPath(object_id), percent) - - def get_object(self, object_id): - """Retrieve the clipboard object structure for given object - - object_id -- dbus path as returned from add_object - - Retrieves the metadata description of a given object, but - *not* the data for the object. Use get_object_data passing - one of the values in the FORMATS_KEY value in order to - retrieve the data. - - returns dictionary with - NAME_KEY: str, - PERCENT_KEY: number, - ICON_KEY: str, - PREVIEW_KEY: XXX what is it?, - ACTIVITIES_KEY: activities that can open this object, - FORMATS_KEY: list of XXX what is it? - """ - return self._dbus_service.get_object(dbus.ObjectPath(object_id),) - - def get_object_data(self, object_id, formatType): - """Retrieve object's data in the given formatType - - object_id -- dbus path as returned from add_object - formatType -- format specifier XXX of what description - - returns dictionary with - TYPE_KEY: str, - DATA_KEY: str, - ON_DISK_KEY: bool - """ - return self._dbus_service.get_object_data(dbus.ObjectPath(object_id), - formatType, - byte_arrays=True) - -_clipboard_service = None -def get_instance(): - """Retrieve this process's interface to the clipboard service""" - global _clipboard_service - if not _clipboard_service: - _clipboard_service = ClipboardService() - return _clipboard_service From a93992eedc32d43b5d1bfd5bef04f87170729f5a Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Tue, 16 Sep 2008 16:03:49 +0200 Subject: [PATCH 3/3] Revert "Move DSObject.resume() from sugar-toolkit to the shell" This reverts commit 13682dd1b4458899e7044e1e917e5bc7a905fee4. --- src/sugar/datastore/datastore.py | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/sugar/datastore/datastore.py b/src/sugar/datastore/datastore.py index 9cd22bfd..81c00e40 100644 --- a/src/sugar/datastore/datastore.py +++ b/src/sugar/datastore/datastore.py @@ -23,6 +23,8 @@ import os import gobject from sugar.datastore import dbus_helpers +from sugar import activity +from sugar.activity.activityhandle import ActivityHandle from sugar.bundle.contentbundle import ContentBundle from sugar.bundle.activitybundle import ActivityBundle from sugar import mime @@ -114,6 +116,32 @@ class DSObject(object): file_path = property(get_file_path, set_file_path) + def _get_activities_for_mime(self, mime_type): + registry = activity.get_registry() + result = registry.get_activities_for_type(mime_type) + if not result: + for parent_mime in mime.get_mime_parents(mime_type): + result.extend(registry.get_activities_for_type(parent_mime)) + return result + + def get_activities(self): + activities = [] + + bundle_id = self.metadata.get('activity', '') + if bundle_id: + activity_info = activity.get_registry().get_activity(bundle_id) + if activity_info: + activities.append(activity_info) + + mime_type = self.metadata.get('mime_type', '') + if mime_type: + activities_info = self._get_activities_for_mime(mime_type) + for activity_info in activities_info: + if activity_info.bundle_id != bundle_id: + activities.append(activity_info) + + return activities + def is_activity_bundle(self): return self.metadata['mime_type'] in \ [ActivityBundle.MIME_TYPE, ActivityBundle.DEPRECATED_MIME_TYPE] @@ -124,6 +152,59 @@ class DSObject(object): def is_bundle(self): return self.is_activity_bundle() or self.is_content_bundle() + def resume(self, bundle_id=None): + from sugar.activity import activityfactory + + if self.is_activity_bundle() and not bundle_id: + + logging.debug('Creating activity bundle') + bundle = ActivityBundle(self.file_path) + if not bundle.is_installed(): + logging.debug('Installing activity bundle') + bundle.install() + elif bundle.need_upgrade(): + logging.debug('Upgrading activity bundle') + bundle.upgrade() + + logging.debug('activityfactory.creating bundle with id %r', + bundle.get_bundle_id()) + activityfactory.create(bundle.get_bundle_id()) + + elif self.is_content_bundle() and not bundle_id: + + logging.debug('Creating content bundle') + bundle = ContentBundle(self.file_path) + if not bundle.is_installed(): + logging.debug('Installing content bundle') + bundle.install() + + activities = self._get_activities_for_mime('text/html') + if len(activities) == 0: + logging.warning('No activity can open HTML content bundles') + return + + uri = bundle.get_start_uri() + logging.debug('activityfactory.creating with uri %s', uri) + activityfactory.create_with_uri(activities[0].bundle_id, + bundle.get_start_uri()) + else: + if not self.get_activities() and bundle_id is None: + logging.warning('No activity can open this object, %s.' % + self.metadata.get('mime_type', None)) + return + if bundle_id is None: + bundle_id = self.get_activities()[0].bundle_id + + activity_id = self.metadata['activity_id'] + object_id = self.object_id + + if activity_id: + handle = ActivityHandle(object_id=object_id, + activity_id=activity_id) + activityfactory.create(bundle_id, handle) + else: + activityfactory.create_with_object_id(bundle_id, object_id) + def destroy(self): if self._destroyed: logging.warning('This DSObject has already been destroyed!.')