Пример #1
0
 def __cell_title_edited_cb(self, cell, path, new_text):
     row = self._model[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     metadata['title'] = new_text
     model.write(metadata, update_mtime=False)
     self.cell_title.props.editable = False
     self.emit('title-edit-finished')
Пример #2
0
    def _favorite_clicked_cb(self, cell, path):
        row = self._model[path]
        iterator = self._model.get_iter(path)
        metadata = model.get(row[ListModel.COLUMN_UID])
        if not model.is_editable(metadata):
            return
        if metadata.get('keep', 0) == '1':
            metadata['keep'] = '0'
            self._model[iterator][ListModel.COLUMN_FAVORITE] = '0'
        else:
            metadata['keep'] = '1'
            self._model[iterator][ListModel.COLUMN_FAVORITE] = '1'

        cell_rect = self.tree_view.get_cell_area(path, self._fav_column)
        self.tree_view.queue_draw_area(cell_rect.x, cell_rect.y,
                                       cell_rect.width, cell_rect.height)

        # HACK for https://bugs.sugarlabs.org/ticket/4904
        if rect.y == 0:
            GLib.idle_add(
                self.tree_view.queue_draw_area(cell_rect.x, cell_rect.y,
                                               cell_rect.width,
                                               cell_rect.height))

        # HACK for https://bugs.sugarlabs.org/ticket/4944
        # Icon does not update automatically if there is only one journal entry
        if len(self._model.get_all_ids()) == 1:
            self._do_refresh()
Пример #3
0
    def _check_for_bundle(self, object_id):
        registry = bundleregistry.get_registry()

        metadata = model.get(object_id)
        if metadata.get('progress', '').isdigit():
            if int(metadata['progress']) < 100:
                return

        bundle = misc.get_bundle(metadata)
        if bundle is None:
            return

        if registry.is_installed(bundle):
            logging.debug('_check_for_bundle bundle already installed')
            return

        if metadata['mime_type'] == JournalEntryBundle.MIME_TYPE:
            # JournalEntryBundle code takes over the datastore entry and
            # transforms it into the journal entry from the bundle -- we have
            # nothing more to do.
            try:
                registry.install(bundle, metadata['uid'])
            except (ZipExtractException, RegistrationException):
                logging.exception('Could not install bundle %s',
                                  bundle.get_path())
            return

        try:
            registry.install(bundle)
        except (ZipExtractException, RegistrationException):
            logging.exception('Could not install bundle %s', bundle.get_path())
            return

        metadata['bundle_id'] = bundle.get_bundle_id()
        model.write(metadata)
Пример #4
0
 def __detail_clicked_cb(self, list_view, object_id):
     metadata = model.get(object_id)
     activity = metadata.get('activity', None)
     if activity == PROJECT_BUNDLE_ID:
         self.project_view_activated_cb(list_view, metadata)
     else:
         self._show_secondary_view(object_id)
Пример #5
0
 def show_object(self, object_id):
     metadata = model.get(object_id)
     if metadata is None:
         return False
     else:
         self._show_secondary_view(object_id)
         return True
Пример #6
0
 def __icon_clicked_cb(self, cell, path):
     row = self.tree_view.get_model()[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     if metadata['activity'] == PROJECT_BUNDLE_ID:
         self.emit('project-view-activate', metadata)
         return
     misc.resume(metadata, alert_window=journalwindow.get_journal_window())
Пример #7
0
 def __icon_clicked_cb(self, cell, path):
     row = self.tree_view.get_model()[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     if metadata["activity"] == PROJECT_BUNDLE_ID:
         self.emit("project-view-activate", metadata)
         return
     misc.resume(metadata, alert_window=journalwindow.get_journal_window())
Пример #8
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)
Пример #9
0
 def __cell_title_edited_cb(self, cell, path, new_text):
     row = self._model[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     metadata['title'] = new_text
     model.write(metadata, update_mtime=False)
     self.cell_title.props.editable = False
     self.emit('title-edit-finished')
Пример #10
0
    def __button_release_event_cb(self, tree_view, event):
        try:
            if self._is_dragging:
                return
        finally:
            self._is_dragging = False

        pos = tree_view.get_path_at_pos(int(event.x), int(event.y))
        if pos is None:
            return

        path, column, x_, y_ = pos
        if column != self._title_column:
            return

        row = self.tree_view.get_model()[path]
        metadata = model.get(row[ListModel.COLUMN_UID])
        self.cell_title.props.editable = model.is_editable(metadata)
        if self.cell_title.props.editable:
            self.emit('title-edit-started')

        tree_view.set_cursor_on_cell(path,
                                     column,
                                     self.cell_title,
                                     start_editing=True)
Пример #11
0
 def show_object(self, object_id):
     metadata = model.get(object_id)
     if metadata is None:
         return False
     else:
         self._show_secondary_view(object_id)
         return True
Пример #12
0
    def __model_updated_cb(self, sender, **kwargs):
        misc.handle_bundle_installation(model.get(kwargs["object_id"]))

        if self.canvas == self._secondary_view and kwargs["object_id"] == self._detail_view.props.metadata["uid"]:
            self._detail_view.refresh()

        self._check_available_space()
Пример #13
0
 def __detail_clicked_cb(self, list_view, object_id):
     metadata = model.get(object_id)
     activity = metadata.get('activity', None)
     if activity == PROJECT_BUNDLE_ID:
         self.project_view_activated_cb(list_view, metadata)
     else:
         self._show_secondary_view(object_id)
Пример #14
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)
Пример #15
0
    def _check_for_bundle(self, object_id):
        registry = bundleregistry.get_registry()

        metadata = model.get(object_id)
        if metadata.get('progress', '').isdigit():
            if int(metadata['progress']) < 100:
                return

        bundle = misc.get_bundle(metadata)
        if bundle is None:
            return

        if registry.is_installed(bundle):
            logging.debug('_check_for_bundle bundle already installed')
            return

        if metadata['mime_type'] == JournalEntryBundle.MIME_TYPE:
            # JournalEntryBundle code takes over the datastore entry and
            # transforms it into the journal entry from the bundle -- we have
            # nothing more to do.
            try:
                registry.install(bundle, metadata['uid'])
            except (ZipExtractException, RegistrationException):
                logging.exception('Could not install bundle %s',
                        bundle.get_path())
            return

        try:
            registry.install(bundle)
        except (ZipExtractException, RegistrationException):
            logging.exception('Could not install bundle %s', bundle.get_path())
            return

        metadata['bundle_id'] = bundle.get_bundle_id()
        model.write(metadata)
Пример #16
0
    def __model_updated_cb(self, sender, **kwargs):
        misc.handle_bundle_installation(model.get(kwargs['object_id']))

        if self.canvas == self._secondary_view and \
                kwargs['object_id'] == self._detail_view.props.metadata['uid']:
            self._detail_view.refresh()

        self._check_available_space()
Пример #17
0
 def _favorite_clicked_cb(self, cell, path):
     row = self._model[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     if not model.is_editable(metadata):
         return
     if metadata.get('keep', 0) == '1':
         metadata['keep'] = '0'
     else:
         metadata['keep'] = '1'
     model.write(metadata, update_mtime=False)
Пример #18
0
 def __favorite_clicked_cb(self, cell, path):
     row = self._model[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     if not model.is_editable(metadata):
         return
     if metadata.get('keep', 0) == '1':
         metadata['keep'] = '0'
     else:
         metadata['keep'] = '1'
     model.write(metadata, update_mtime=False)
Пример #19
0
 def _do_finish(self):
     self._tarfile.close()
     # Add metadata to the file created
     metadata = model.get(self._checkpoint)
     metadata['description'] = _('Backup from user %s') % \
         profile.get_nick_name()
     metadata['icon_color'] = profile.get_color().to_string()
     metadata['uncompressed_size'] = self._uncompressed_size
     metadata['mime_type'] = 'application/vnd.olpc-journal-backup'
     model.write(metadata, self._checkpoint)
     self.emit('finished')
Пример #20
0
 def _do_finish(self):
     self._tarfile.close()
     # Add metadata to the file created
     metadata = model.get(self._checkpoint)
     metadata['description'] = _('Backup from user %s') % \
         profile.get_nick_name()
     metadata['icon_color'] = profile.get_color().to_string()
     metadata['uncompressed_size'] = self._uncompressed_size
     metadata['mime_type'] = 'application/vnd.olpc-journal-backup'
     model.write(metadata, self._checkpoint)
     self.emit('finished')
Пример #21
0
def _get_checkpoint_size(path):
    # read information in the metadata
    metadata = model.get(path)
    if 'uncompressed_size' in metadata:
        size = int(metadata['uncompressed_size'])
        logging.error('size from metadata = %d', size)
    else:
        size = 0
        with tarfile.open(path, 'r:gz') as file:
            for tarinfo in file:
                size += DIR_SIZE if tarinfo.isdir() else tarinfo.size
    return size
Пример #22
0
def _get_checkpoint_size(path):
    # read information in the metadata
    metadata = model.get(path)
    if 'uncompressed_size' in metadata:
        size = int(metadata['uncompressed_size'])
        logging.error('size from metadata = %d', size)
    else:
        size = 0
        with tarfile.open(path, 'r:gz') as file:
            for tarinfo in file:
                size += DIR_SIZE if tarinfo.isdir() else tarinfo.size
    return size
Пример #23
0
    def __project_chooser_response_cb(self, project_chooser, response_value,
                                      metadata_to_send):
        if response_value == Gtk.ResponseType.DELETE_EVENT:
            project_chooser.destroy()
            return

        object_id = project_chooser.get_selected_object_id()
        metadata = model.get(object_id)
        jobject_to_send = datastore.get(metadata_to_send['uid'])
        datastore.delete(metadata_to_send['uid'])
        jobject_to_send.metadata['project_id'] = metadata['uid']
        datastore.write(jobject_to_send)
        project_chooser.destroy()
Пример #24
0
    def __project_chooser_response_cb(self, project_chooser, response_value,
                                      metadata_to_send):
        if response_value == Gtk.ResponseType.DELETE_EVENT:
            project_chooser.destroy()
            return

        object_id = project_chooser.get_selected_object_id()
        metadata = model.get(object_id)
        jobject_to_send = datastore.get(metadata_to_send['uid'])
        datastore.delete(metadata_to_send['uid'])
        jobject_to_send.metadata['project_id'] = metadata['uid']
        datastore.write(jobject_to_send)
        project_chooser.destroy()
Пример #25
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"))
Пример #26
0
    def _favorite_clicked_cb(self, cell, path):
        row = self._model[path]
        iterator = self._model.get_iter(path)
        metadata = model.get(row[ListModel.COLUMN_UID])
        if not model.is_editable(metadata):
            return
        if metadata.get("keep", 0) == "1":
            metadata["keep"] = "0"
            self._model[iterator][ListModel.COLUMN_FAVORITE] = "0"
        else:
            metadata["keep"] = "1"
            self._model[iterator][ListModel.COLUMN_FAVORITE] = "1"

        cell_rect = self.tree_view.get_cell_area(path, self._fav_column)
        self.tree_view.queue_draw_area(cell_rect.x, cell_rect.y, cell_rect.width, cell_rect.height)
Пример #27
0
    def _favorite_clicked_cb(self, cell, path):
        row = self._model[path]
        iterator = self._model.get_iter(path)
        metadata = model.get(row[ListModel.COLUMN_UID])
        if not model.is_editable(metadata):
            return
        if metadata.get('keep', 0) == '1':
            metadata['keep'] = '0'
            self._model[iterator][ListModel.COLUMN_FAVORITE] = '0'
        else:
            metadata['keep'] = '1'
            self._model[iterator][ListModel.COLUMN_FAVORITE] = '1'

        cell_rect = self.tree_view.get_cell_area(path, self._fav_column)
        self.tree_view.queue_draw_area(cell_rect.x, cell_rect.y,
                                       cell_rect.width, cell_rect.height)
Пример #28
0
    def _show_secondary_view(self, object_id):
        metadata = model.get(object_id)
        try:
            self._detail_toolbox.set_metadata(metadata)
        except Exception:
            logging.exception("Exception while displaying entry:")

        self.set_toolbar_box(self._detail_toolbox)
        self._detail_toolbox.show()

        try:
            self._detail_view.props.metadata = metadata
        except Exception:
            logging.exception("Exception while displaying entry:")

        self.set_canvas(self._secondary_view)
        self._secondary_view.show()
Пример #29
0
    def _show_secondary_view(self, object_id):
        metadata = model.get(object_id)
        try:
            self._detail_toolbox.set_metadata(metadata)
        except Exception:
            logging.exception('Exception while displaying entry:')

        self.set_toolbar_box(self._detail_toolbox)
        self._detail_toolbox.show()

        try:
            self._detail_view.props.metadata = metadata
        except Exception:
            logging.exception('Exception while displaying entry:')

        self.set_canvas(self._secondary_view)
        self._secondary_view.show()
Пример #30
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"))
Пример #31
0
    def _show_secondary_view(self, object_id):
        self._active_view = JournalViews.DETAIL
        metadata = model.get(object_id)
        try:
            self._detail_toolbox.set_metadata(metadata)
        except Exception:
            logging.exception('Exception while displaying entry:')

        self.set_toolbar_box(self._detail_toolbox)
        self._detail_toolbox.show()

        try:
            self._detail_view.props.metadata = metadata
        except Exception:
            logging.exception('Exception while displaying entry:')

        self.set_canvas(self._secondary_view)
        self._secondary_view.show()
Пример #32
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'))
Пример #33
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'))
Пример #34
0
    def _operate_by_uid_internal(self):
        # If there is still some uid left, proceed with the operation.
        # Else, proceed to post-operations.
        if self._object_index < len(self._uid_list):
            uid = self._uid_list[self._object_index]
            metadata = model.get(uid)
            title = None
            if 'title' in metadata:
                title = metadata['title']
            if title is None or title == '':
                title = _('Untitled')
            alert_message = _('%(index)d of %(total)d : %(object_title)s') % {
                'index': self._object_index + 1,
                'total': len(self._uid_list),
                'object_title': title}

            self._confirmation_alert.props.msg = alert_message
            GLib.idle_add(self._operate_per_metadata, metadata)
        else:
            self._finish_batch_execution()
Пример #35
0
    def _operate_by_uid_internal(self):
        # If there is still some uid left, proceed with the operation.
        # Else, proceed to post-operations.
        if self._object_index < len(self._uid_list):
            uid = self._uid_list[self._object_index]
            metadata = model.get(uid)
            title = None
            if 'title' in metadata:
                title = metadata['title']
            if title is None or title == '':
                title = _('Untitled')
            alert_message = _('%(index)d of %(total)d : %(object_title)s') % {
                'index': self._object_index + 1,
                'total': len(self._uid_list),
                'object_title': title}

            self._confirmation_alert.props.msg = alert_message
            GObject.idle_add(self._operate_per_metadata, metadata)
        else:
            self._finish_batch_execution()
Пример #36
0
    def __button_release_event_cb(self, tree_view, event):
        try:
            if self._is_dragging:
                return
        finally:
            self._is_dragging = False

        pos = tree_view.get_path_at_pos(int(event.x), int(event.y))
        if pos is None:
            return

        path, column, x_, y_ = pos
        if column != self._title_column:
            return

        row = self.tree_view.get_model()[path]
        metadata = model.get(row[ListModel.COLUMN_UID])
        self.cell_title.props.editable = model.is_editable(metadata)

        tree_view.set_cursor_on_cell(path, column, start_editing=True)
Пример #37
0
    def _operate_by_uid_internal(self):
        # If there is still some uid left, proceed with the operation.
        # Else, proceed to post-operations.
        if self._object_index < len(self._uid_list):
            uid = self._uid_list[self._object_index]
            metadata = model.get(uid)
            title = None
            if "title" in metadata:
                title = metadata["title"]
            if title is None or title == "":
                title = _("Untitled")
            alert_message = _("%(index)d of %(total)d : %(object_title)s") % {
                "index": self._object_index,
                "total": len(self._uid_list),
                "object_title": title,
            }

            self._confirmation_alert.props.msg = alert_message
            GObject.idle_add(self._operate_per_metadata, metadata)
        else:
            self._finish_batch_execution()
Пример #38
0
    def _favorite_clicked_cb(self, cell, path):
        row = self._model[path]
        iterator = self._model.get_iter(path)
        metadata = model.get(row[ListModel.COLUMN_UID])
        if not model.is_editable(metadata):
            return
        if metadata.get('keep', 0) == '1':
            metadata['keep'] = '0'
            self._model[iterator][ListModel.COLUMN_FAVORITE] = '0'
        else:
            metadata['keep'] = '1'
            self._model[iterator][ListModel.COLUMN_FAVORITE] = '1'

        cell_rect = self.tree_view.get_cell_area(path, self._fav_column)
        self.tree_view.queue_draw_area(cell_rect.x, cell_rect.y,
                                       cell_rect.width, cell_rect.height)

        # HACK for https://bugs.sugarlabs.org/ticket/4944
        # Icon does not update automatically if there is only one journal entry
        if len(self._model.get_all_ids()) == 1:
            self._do_refresh()
Пример #39
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'))
Пример #40
0
 def get_metadata(self, path):
     return model.get(self[path][ListModel.COLUMN_UID])
Пример #41
0
 def __model_created_cb(self, sender, **kwargs):
     misc.handle_bundle_installation(model.get(kwargs["object_id"]))
     self._main_toolbox.refresh_filters()
     self._check_available_space()
Пример #42
0
 def refresh(self):
     logging.debug('DetailView.refresh')
     self._metadata = model.get(self._metadata['uid'])
     self._update_view()
Пример #43
0
 def refresh(self):
     logging.debug('DetailView.refresh')
     self._metadata = model.get(self._metadata['uid'])
     self._update_view()
Пример #44
0
 def _get_metadata(self):
     return model.get(self._get_uid_list()[0])
Пример #45
0
 def __model_created_cb(self, sender, **kwargs):
     misc.handle_bundle_installation(model.get(kwargs['object_id']))
     self._main_toolbox.refresh_filters()
     self._check_available_space()
Пример #46
0
 def _get_metadata(self):
     return model.get(self._get_uid_list()[0])
Пример #47
0
 def __icon_clicked_cb(self, cell, path):
     row = self.tree_view.get_model()[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     misc.resume(metadata,
                 alert_window=journalwindow.get_journal_window())
Пример #48
0
 def __icon_clicked_cb(self, cell, path):
     row = self.tree_view.get_model()[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     misc.resume(metadata)
Пример #49
0
 def refresh(self):
     logging.debug("DetailView.refresh")
     self._metadata = model.get(self._metadata["uid"])
     self._update_view()
Пример #50
0
 def __icon_clicked_cb(self, cell, path):
     row = self.tree_view.get_model()[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     misc.resume(metadata, alert_window=journalwindow.get_journal_window())
Пример #51
0
 def __icon_clicked_cb(self, cell, path):
     row = self.tree_view.get_model()[path]
     metadata = model.get(row[ListModel.COLUMN_UID])
     misc.resume(metadata)
Пример #52
0
 def get_metadata(self, path):
     return model.get(self[path][ListModel.COLUMN_UID])