def resume(metadata, bundle_id=None): registry = bundleregistry.get_registry() if is_activity_bundle(metadata) and bundle_id is None: logging.debug("Creating activity bundle") file_path = model.get_file(metadata["uid"]) bundle = ActivityBundle(file_path) if not registry.is_installed(bundle): logging.debug("Installing activity bundle") try: registry.install(bundle) except AlreadyInstalledException: _downgrade_option_alert(bundle) return else: logging.debug("Upgrading activity bundle") registry.upgrade(bundle) _launch_bundle(bundle) elif is_content_bundle(metadata) and bundle_id is None: logging.debug("Creating content bundle") file_path = model.get_file(metadata["uid"]) bundle = ContentBundle(file_path) if not bundle.is_installed(): logging.debug("Installing content bundle") bundle.install() activities = _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) activity_bundle = registry.get_bundle(activities[0].get_bundle_id()) launch(activity_bundle, uri=uri) else: activity_id = metadata.get("activity_id", "") if bundle_id is None: activities = get_activities(metadata) if not activities: logging.warning("No activity can open this object, %s.", metadata.get("mime_type", None)) return bundle_id = activities[0].get_bundle_id() bundle = registry.get_bundle(bundle_id) if metadata.get("mountpoint", "/") == "/": object_id = metadata["uid"] else: object_id = model.copy(metadata, "/") launch(bundle, activity_id=activity_id, object_id=object_id, color=get_icon_color(metadata))
def get_bundle(metadata): try: if is_activity_bundle(metadata): file_path = model.get_file(metadata['uid']) if not os.path.exists(file_path): logging.warning('Invalid path: %r', file_path) return None return ActivityBundle(file_path) elif is_content_bundle(metadata): file_path = model.get_file(metadata['uid']) if not os.path.exists(file_path): logging.warning('Invalid path: %r', file_path) return None return ContentBundle(file_path) elif is_journal_bundle(metadata): file_path = model.get_file(metadata['uid']) if not os.path.exists(file_path): logging.warning('Invalid path: %r', file_path) return None return JournalEntryBundle(file_path, metadata['uid']) else: return None except Exception: logging.exception('Incorrect bundle') return None
def get_bundle(metadata): try: if is_activity_bundle(metadata): file_path = model.get_file(metadata['uid']) if not os.path.exists(file_path): logging.warning('Invalid path: %r', file_path) return None return get_bundle_instance(file_path) elif is_content_bundle(metadata): file_path = model.get_file(metadata['uid']) if not os.path.exists(file_path): logging.warning('Invalid path: %r', file_path) return None return ContentBundle(file_path) elif is_journal_bundle(metadata): file_path = model.get_file(metadata['uid']) if not os.path.exists(file_path): logging.warning('Invalid path: %r', file_path) return None return JournalEntryBundle(file_path, metadata['uid']) else: return None except Exception: logging.exception('Incorrect bundle') return None
def __copy_to_volume_cb(self, menu_item): uid_list = self._get_uid_list_cb() if len(uid_list) == 1: uid = uid_list[0] file_path = model.get_file(uid) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return try: metadata = model.get(uid) model.copy(metadata, self._mount_point) except IOError as e: logging.exception('Error while copying the entry. %s', e.strerror) self.emit('volume-error', _('Error while copying the entry. %s') % e.strerror, _('Error')) else: BatchOperator(self._journalactivity, uid_list, _('Copy'), self._get_confirmation_alert_message(len(uid_list)), self._perform_copy)
def __copy_to_clipboard_cb(self, menu_item): clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) uid_list = self._get_uid_list_cb() if len(uid_list) == 1: uid = uid_list[0] file_path = model.get_file(uid) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return # XXX SL#4307 - until set_with_data bindings are fixed upstream if hasattr(clipboard, 'set_with_data'): clipboard.set_with_data( [Gtk.TargetEntry.new('text/uri-list', 0, 0)], self.__clipboard_get_func_cb, self.__clipboard_clear_func_cb, None) else: SugarExt.clipboard_set_with_data( clipboard, [Gtk.TargetEntry.new('text/uri-list', 0, 0)], self.__clipboard_get_func_cb, self.__clipboard_clear_func_cb, None)
def get_icon_name(metadata): file_name = None bundle_id = metadata.get('activity', '') if not bundle_id: bundle_id = metadata.get('bundle_id', '') if bundle_id: activity_info = bundleregistry.get_registry().get_bundle(bundle_id) if activity_info: file_name = activity_info.get_icon() if file_name is None and is_activity_bundle(metadata): file_path = model.get_file(metadata['uid']) if file_path is not None and os.path.exists(file_path): try: bundle = ActivityBundle(file_path) file_name = bundle.get_icon() except Exception: logging.exception('Could not read bundle') if file_name is None: file_name = _get_icon_for_mime(metadata.get('mime_type', '')) if file_name is None: file_name = get_icon_file_name('application-octet-stream') return file_name
def get_icon_name(metadata): file_name = None bundle_id = metadata.get('activity', '') if not bundle_id: bundle_id = metadata.get('bundle_id', '') if bundle_id: if bundle_id == PROJECT_BUNDLE_ID: file_name = \ '/home/broot/sugar-build/build' + \ '/out/install/share/icons/sugar/' + \ 'scalable/mimetypes/project-box.svg' return file_name activity_info = bundleregistry.get_registry().get_bundle(bundle_id) if activity_info: file_name = activity_info.get_icon() if file_name is None and is_activity_bundle(metadata): file_path = model.get_file(metadata['uid']) if file_path is not None and os.path.exists(file_path): try: bundle = get_bundle_instance(file_path) file_name = bundle.get_icon() except Exception: logging.exception('Could not read bundle') if file_name is None: file_name = _get_icon_for_mime(metadata.get('mime_type', '')) if file_name is None: file_name = get_icon_file_name('application-octet-stream') return file_name
def get_icon_name(metadata): file_name = None bundle_id = metadata.get('activity', '') if not bundle_id: bundle_id = metadata.get('bundle_id', '') if bundle_id: activity_info = bundleregistry.get_registry().get_bundle(bundle_id) if activity_info: file_name = activity_info.get_icon() if file_name is None and is_activity_bundle(metadata): file_path = model.get_file(metadata['uid']) if file_path is not None and os.path.exists(file_path): try: bundle = get_bundle_instance(file_path) file_name = bundle.get_icon() except Exception: logging.exception('Could not read bundle') if file_name is None: file_name = _get_icon_for_mime(metadata.get('mime_type', '')) if file_name is None: file_name = get_icon_file_name('application-octet-stream') return file_name
def get_icon_name(metadata): file_name = None bundle_id = metadata.get("activity", "") if not bundle_id: bundle_id = metadata.get("bundle_id", "") if bundle_id: activity_info = bundleregistry.get_registry().get_bundle(bundle_id) if activity_info: file_name = activity_info.get_icon() if file_name is None and is_activity_bundle(metadata): file_path = model.get_file(metadata["uid"]) if file_path is not None and os.path.exists(file_path): try: bundle = ActivityBundle(file_path) file_name = bundle.get_icon() except Exception: logging.exception("Could not read bundle") if file_name is None: file_name = _get_icon_for_mime(metadata.get("mime_type", "")) if file_name is None: file_name = get_icon_file_name("application-octet-stream") return file_name
def __copy_to_volume_cb(self, menu_item): uid_list = self._get_uid_list_cb() if len(uid_list) == 1: uid = uid_list[0] file_path = model.get_file(uid) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return try: metadata = model.get(uid) model.copy(metadata, self._mount_point) except IOError as e: logging.exception('Error while copying the entry. %s', e.strerror) self.emit('volume-error', _('Error while copying the entry. %s') % e.strerror, _('Error')) else: BatchOperator( self._journalactivity, uid_list, _('Copy'), self._get_confirmation_alert_message(len(uid_list)), self._perform_copy)
def __duplicate_activate_cb(self, menu_item): file_path = model.get_file(self._metadata['uid']) try: model.copy(self._metadata, '/') except IOError, e: logging.exception('Error while copying the entry. %s', e.strerror) self.emit('volume-error', _('Error while copying the entry. %s') % e.strerror, _('Error'))
def _duplicate_clicked_cb(self, button): file_path = model.get_file(self._metadata['uid']) try: model.copy(self._metadata, '/') except IOError, e: logging.exception('Error while copying the entry.') self.emit('volume-error', _('Error while copying the entry. %s') % (e.strerror, ), _('Error'))
def _perform_copy(self, metadata): file_path = model.get_file(metadata["uid"]) if not file_path or not os.path.exists(file_path): logging.warn("Entries without a file cannot be copied.") return try: model.copy(metadata, self._mount_point) except IOError, e: logging.exception("Error while copying the entry. %s", e.strerror)
def _perform_copy(self, metadata): file_path = model.get_file(metadata['uid']) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') return try: model.copy(metadata, self._mount_point) except IOError, e: logging.exception('Error while copying the entry. %s', e.strerror)
def __copy_to_clipboard_cb(self, menu_item): file_path = model.get_file(self._metadata['uid']) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return clipboard = gtk.Clipboard() clipboard.set_with_data([('text/uri-list', 0, 0)], self.__clipboard_get_func_cb, self.__clipboard_clear_func_cb)
def do_drag_data_get(self, path, selection): uid = self[path][ListModel.COLUMN_UID] if selection.target == 'text/uri-list': # Get hold of a reference so the temp file doesn't get deleted self._temp_drag_file_path = model.get_file(uid) logging.debug('putting %r in selection', self._temp_drag_file_path) selection.set(selection.target, 8, self._temp_drag_file_path) return True elif selection.target == 'journal-object-id': selection.set(selection.target, 8, uid) return True return False
def __copy_to_clipboard_cb(self, menu_item): file_path = model.get_file(self._metadata['uid']) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.set_with_data([Gtk.TargetEntry.new('text/uri-list', 0, 0)], self.__clipboard_get_func_cb, self.__clipboard_clear_func_cb, None)
def _drag_data_received_cb(self, widget, drag_context, x, y, selection_data, info, timestamp): object_id = selection_data.get_data() metadata = model.get(object_id) file_path = model.get_file(metadata["uid"]) if not file_path or not os.path.exists(file_path): logging.warn("Entries without a file cannot be copied.") self.emit("volume-error", _("Entries without a file cannot be copied."), _("Warning")) return try: model.copy(metadata, self.mount_point) except IOError, e: logging.exception("Error while copying the entry. %s", e.strerror) self.emit("volume-error", _("Error while copying the entry. %s") % e.strerror, _("Error"))
def do_drag_data_get(self, path, selection): uid = self[path][ListModel.COLUMN_UID] target_atom = selection.get_target() target_name = target_atom.name() if target_name == 'text/uri-list': # Get hold of a reference so the temp file doesn't get deleted self._temp_drag_file_path = model.get_file(uid) logging.debug('putting %r in selection', self._temp_drag_file_path) selection.set(target_atom, 8, self._temp_drag_file_path) return True elif target_name == 'journal-object-id': # uid is unicode but Gtk.SelectionData.set() needs str selection.set(target_atom, 8, str(uid)) return True return False
def __copy_to_volume_cb(self, menu_item, mount_point): file_path = model.get_file(self._metadata['uid']) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return try: model.copy(self._metadata, mount_point) except IOError, e: logging.exception('Error while copying the entry. %s', e.strerror) self.emit('volume-error', _('Error while copying the entry. %s') % e.strerror, _('Error'))
def __friend_selected_cb(self, menu_item, buddy): logging.debug("__friend_selected_cb") file_name = model.get_file(self._metadata["uid"]) if not file_name or not os.path.exists(file_name): logging.warn("Entries without a file cannot be sent.") self.emit("volume-error", _("Entries without a file cannot be sent."), _("Warning")) return title = str(self._metadata["title"]) description = str(self._metadata.get("description", "")) mime_type = str(self._metadata["mime_type"]) if not mime_type: mime_type = mime.get_for_file(file_name) filetransfer.start_transfer(buddy, file_name, title, description, mime_type)
def __copy_to_clipboard_cb(self, menu_item): clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) uid_list = self._get_uid_list_cb() if len(uid_list) == 1: uid = uid_list[0] file_path = model.get_file(uid) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return clipboard.set_with_data( [Gtk.TargetEntry.new('text/uri-list', 0, 0)], self.__clipboard_get_func_cb, self.__clipboard_clear_func_cb, None)
def __copy_to_volume_cb(self, menu_item): uid_list = self._get_uid_list_cb() if len(uid_list) == 1: uid = uid_list[0] file_path = model.get_file(uid) if not file_path or not os.path.exists(file_path): logging.warn("Entries without a file cannot be copied.") self.emit("volume-error", _("Entries without a file cannot be copied."), _("Warning")) return try: metadata = model.get(uid) model.copy(metadata, self._mount_point) except IOError, e: logging.exception("Error while copying the entry. %s", e.strerror) self.emit("volume-error", _("Error while copying the entry. %s") % e.strerror, _("Error"))
def __copy_to_clipboard_cb(self, menu_item): clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) uid_list = self._get_uid_list_cb() if len(uid_list) == 1: uid = uid_list[0] file_path = model.get_file(uid) if not file_path or not os.path.exists(file_path): logging.warn("Entries without a file cannot be copied.") self.emit("volume-error", _("Entries without a file cannot be copied."), _("Warning")) return clipboard.set_with_data( [Gtk.TargetEntry.new("text/uri-list", 0, 0)], self.__clipboard_get_func_cb, self.__clipboard_clear_func_cb, None, )
def _drag_data_received_cb(self, widget, drag_context, x, y, selection_data, info, timestamp): object_id = selection_data.data metadata = model.get(object_id) file_path = model.get_file(metadata['uid']) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return try: model.copy(metadata, self.mount_point) except IOError, e: logging.exception('Error while copying the entry. %s', e.strerror) self.emit('volume-error', _('Error while copying the entry. %s') % e.strerror, _('Error'))
def _drag_data_received_cb(self, widget, drag_context, x, y, selection_data, info, timestamp): object_id = selection_data.get_data() metadata = model.get(object_id) file_path = model.get_file(metadata['uid']) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return try: model.copy(metadata, self.mount_point) except IOError as e: logging.exception('Error while copying the entry. %s', e.strerror) self.emit('volume-error', _('Error while copying the entry. %s') % e.strerror, _('Error'))
def __friend_selected_cb(self, menu_item, buddy): logging.debug('__friend_selected_cb') file_name = model.get_file(self._metadata['uid']) if not file_name or not os.path.exists(file_name): logging.warn('Entries without a file cannot be sent.') self.emit('volume-error', _('Entries without a file cannot be sent.'), _('Warning')) return title = str(self._metadata['title']) description = str(self._metadata.get('description', '')) mime_type = str(self._metadata['mime_type']) if not mime_type: mime_type = mime.get_for_file(file_name) filetransfer.start_transfer(buddy, file_name, title, description, mime_type)
def do_drag_data_get(self, path, selection): uid = self[path][ListModel.COLUMN_UID] target_atom = selection.get_target() target_name = target_atom.name() if target_name == 'text/uri-list': # Only get a new temp path if we have a new file, the frame # requests a path many times and if we give it a new path it # ends up with a broken path if uid != self._temp_drag_file_uid: # Get hold of a reference so the temp file doesn't get deleted self._temp_drag_file_path = model.get_file(uid) self._temp_drag_file_uid = uid logging.debug('putting %r in selection', self._temp_drag_file_path) selection.set(target_atom, 8, self._temp_drag_file_path) return True elif target_name == 'journal-object-id': # uid is unicode but Gtk.SelectionData.set() needs str selection.set(target_atom, 8, str(uid)) return True return False
def __copy_to_volume_cb(self, menu_item): uid_list = self._get_uid_list_cb() if len(uid_list) == 1: uid = uid_list[0] file_path = model.get_file(uid) if not file_path or not os.path.exists(file_path): logging.warn('Entries without a file cannot be copied.') self.emit('volume-error', _('Entries without a file cannot be copied.'), _('Warning')) return try: metadata = model.get(uid) model.copy(metadata, self._mount_point) except IOError, e: logging.exception('Error while copying the entry. %s', e.strerror) self.emit('volume-error', _('Error while copying the entry. %s') % e.strerror, _('Error'))
def resume(metadata, bundle_id=None): registry = bundleregistry.get_registry() if is_activity_bundle(metadata) and bundle_id is None: logging.debug('Creating activity bundle') file_path = model.get_file(metadata['uid']) bundle = ActivityBundle(file_path) if not registry.is_installed(bundle): logging.debug('Installing activity bundle') try: registry.install(bundle) except AlreadyInstalledException: _downgrade_option_alert(bundle) return else: logging.debug('Upgrading activity bundle') registry.upgrade(bundle) _launch_bundle(bundle) elif is_content_bundle(metadata) and bundle_id is None: logging.debug('Creating content bundle') file_path = model.get_file(metadata['uid']) bundle = ContentBundle(file_path) if not bundle.is_installed(): logging.debug('Installing content bundle') bundle.install() activities = _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) activity_bundle = registry.get_bundle(activities[0].get_bundle_id()) launch(activity_bundle, uri=uri) else: activity_id = metadata.get('activity_id', '') if bundle_id is None: activities = get_activities(metadata) if not activities: logging.warning('No activity can open this object, %s.', metadata.get('mime_type', None)) return bundle_id = activities[0].get_bundle_id() bundle = registry.get_bundle(bundle_id) if metadata.get('mountpoint', '/') == '/': object_id = metadata['uid'] else: object_id = model.copy(metadata, '/') launch(bundle, activity_id=activity_id, object_id=object_id, color=get_icon_color(metadata))
def __clipboard_get_func_cb(self, clipboard, selection_data, info, data): # Get hold of a reference so the temp file doesn't get deleted self._temp_file_path = model.get_file(self._metadata['uid']) logging.debug('__clipboard_get_func_cb %r', self._temp_file_path) selection_data.set_uris(['file://' + self._temp_file_path])
def __clipboard_get_func_cb(self, clipboard, selection_data, info, data): # Get hold of a reference so the temp file doesn't get deleted for uid in self._uid_list: self._temp_file_path = model.get_file(uid) logging.debug('__clipboard_get_func_cb %r', self._temp_file_path) selection_data.set_uris(['file://' + self._temp_file_path])
def __clipboard_get_func_cb(self, clipboard, selection_data, info, data): # Get hold of a reference so the temp file doesn't get deleted for uid in self._get_uid_list_cb(): self._temp_file_path = model.get_file(uid) logging.debug('__clipboard_get_func_cb %r', self._temp_file_path) selection_data.set_uris(['file://' + self._temp_file_path])