예제 #1
0
파일: misc.py 프로젝트: erikos/sugar
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))
예제 #2
0
파일: misc.py 프로젝트: edudev/sugar
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
예제 #3
0
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
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
파일: misc.py 프로젝트: edudev/sugar
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
예제 #7
0
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
예제 #8
0
파일: misc.py 프로젝트: vish-321/sugar
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
예제 #9
0
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
예제 #10
0
파일: misc.py 프로젝트: erikos/sugar
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
예제 #11
0
파일: palettes.py 프로젝트: sugarlabs/sugar
    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)
예제 #12
0
파일: palettes.py 프로젝트: sugarlabs/sugar
    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)
예제 #13
0
 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'))
예제 #14
0
 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'))
예제 #15
0
 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'))
예제 #16
0
 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)
예제 #17
0
 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)
예제 #18
0
    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)
예제 #19
0
    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
예제 #20
0
    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
예제 #21
0
파일: palettes.py 프로젝트: gambogi/sugar-1
    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)
예제 #22
0
    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"))
예제 #23
0
    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
예제 #24
0
파일: listmodel.py 프로젝트: i5o/sugar
    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
예제 #25
0
    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'))
예제 #26
0
    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)
예제 #27
0
    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)
예제 #28
0
    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"))
예제 #29
0
    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,
            )
예제 #30
0
파일: palettes.py 프로젝트: gambogi/sugar-1
    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'))
예제 #31
0
    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'))
예제 #32
0
    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'))
예제 #33
0
파일: palettes.py 프로젝트: sugarlabs/sugar
    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)
예제 #34
0
    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)
예제 #35
0
    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
예제 #36
0
    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
예제 #37
0
    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'))
예제 #38
0
파일: misc.py 프로젝트: ceibal-tatu/sugar
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))
예제 #39
0
파일: palettes.py 프로젝트: gambogi/sugar-1
 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])
예제 #40
0
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))
예제 #41
0
 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])
예제 #42
0
파일: palettes.py 프로젝트: sugarlabs/sugar
 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])