Example #1
0
    def do_tags_list_edit(self, tag, category):
        '''
        Open the 'manage_X' dialog where X == category. If tag is not None, the
        dialog will position the editor on that item.
        '''

        tags_model = self.tags_view.model()
        result = tags_model.get_category_editor_data(category)
        if result is None:
            return

        if category == 'series':
            key = lambda x: sort_key(title_sort(x))
        else:
            key = sort_key

        db = self.library_view.model().db
        d = TagListEditor(self,
                          cat_name=db.field_metadata[category]['name'],
                          tag_to_match=tag,
                          data=result,
                          sorter=key)
        d.exec_()
        if d.result() == d.Accepted:
            to_rename = d.to_rename  # dict of old id to new name
            to_delete = d.to_delete  # list of ids
            orig_name = d.original_names  # dict of id: name

            rename_func = None
            if category == 'tags':
                rename_func = db.rename_tag
                delete_func = db.delete_tag_using_id
            elif category == 'series':
                rename_func = db.rename_series
                delete_func = db.delete_series_using_id
            elif category == 'publisher':
                rename_func = db.rename_publisher
                delete_func = db.delete_publisher_using_id
            else:  # must be custom
                cc_label = db.field_metadata[category]['label']
                rename_func = partial(db.rename_custom_item, label=cc_label)
                delete_func = partial(db.delete_custom_item_using_id,
                                      label=cc_label)
            m = self.tags_view.model()
            if rename_func:
                for item in to_delete:
                    delete_func(item)
                    m.delete_item_from_all_user_categories(
                        orig_name[item], category)
                for old_id in to_rename:
                    rename_func(old_id, new_name=unicode(to_rename[old_id]))
                    m.rename_item_in_all_user_categories(
                        orig_name[old_id], category,
                        unicode(to_rename[old_id]))

            # Clean up the library view
            self.do_tag_item_renamed()
            self.tags_view.recount()
Example #2
0
    def do_tags_list_edit(self, tag, category):
        '''
        Open the 'manage_X' dialog where X == category. If tag is not None, the
        dialog will position the editor on that item.
        '''

        db = self.current_db

        def get_book_ids(use_virtual_library):
            book_ids = None if not use_virtual_library else self.tags_view.model(
            ).get_book_ids_to_use()
            data = db.new_api.get_categories(book_ids=book_ids)
            if category in data:
                result = [(t.id, t.original_name, t.count)
                          for t in data[category] if t.count > 0]
            else:
                result = None
            return result

        if category == 'series':
            key = lambda x: sort_key(title_sort(x))
        else:
            key = sort_key

        d = TagListEditor(self,
                          cat_name=db.field_metadata[category]['name'],
                          tag_to_match=tag,
                          get_book_ids=get_book_ids,
                          sorter=key)
        d.exec_()
        if d.result() == d.Accepted:
            to_rename = d.to_rename  # dict of old id to new name
            to_delete = d.to_delete  # list of ids
            orig_name = d.original_names  # dict of id: name

            if (category in ['tags', 'series', 'publisher']
                    or db.new_api.field_metadata.is_custom_field(category)):
                m = self.tags_view.model()
                for item in to_delete:
                    m.delete_item_from_all_user_categories(
                        orig_name[item], category)
                for old_id in to_rename:
                    m.rename_item_in_all_user_categories(
                        orig_name[old_id], category,
                        unicode_type(to_rename[old_id]))

                db.new_api.remove_items(category, to_delete)
                db.new_api.rename_items(category,
                                        to_rename,
                                        change_index=False)

                # Clean up the library view
                self.do_tag_item_renamed()
                self.tags_view.recount()
Example #3
0
    def do_tags_list_edit(self, tag, category):
        '''
        Open the 'manage_X' dialog where X == category. If tag is not None, the
        dialog will position the editor on that item.
        '''

        tags_model = self.tags_view.model()
        result = tags_model.get_category_editor_data(category)
        if result is None:
            return

        if category == 'series':
            key = lambda x:sort_key(title_sort(x))
        else:
            key = sort_key

        db=self.library_view.model().db
        d = TagListEditor(self, cat_name=db.field_metadata[category]['name'],
                          tag_to_match=tag, data=result, sorter=key)
        d.exec_()
        if d.result() == d.Accepted:
            to_rename = d.to_rename  # dict of old id to new name
            to_delete = d.to_delete  # list of ids
            orig_name = d.original_names  # dict of id: name

            rename_func = None
            if category == 'tags':
                rename_func = db.rename_tag
                delete_func = db.delete_tag_using_id
            elif category == 'series':
                rename_func = db.rename_series
                delete_func = db.delete_series_using_id
            elif category == 'publisher':
                rename_func = db.rename_publisher
                delete_func = db.delete_publisher_using_id
            else:  # must be custom
                cc_label = db.field_metadata[category]['label']
                rename_func = partial(db.rename_custom_item, label=cc_label)
                delete_func = partial(db.delete_custom_item_using_id, label=cc_label)
            m = self.tags_view.model()
            if rename_func:
                for item in to_delete:
                    delete_func(item)
                    m.delete_item_from_all_user_categories(orig_name[item], category)
                for old_id in to_rename:
                    rename_func(old_id, new_name=unicode(to_rename[old_id]))
                    m.rename_item_in_all_user_categories(orig_name[old_id],
                                            category, unicode(to_rename[old_id]))

            # Clean up the library view
            self.do_tag_item_renamed()
            self.tags_view.recount()
Example #4
0
    def do_tags_list_edit(self, tag, category, is_first_letter=False):
        '''
        Open the 'manage_X' dialog where X == category. If tag is not None, the
        dialog will position the editor on that item.
        '''

        db = self.current_db
        if category == 'series':
            key = lambda x: sort_key(title_sort(x))
        else:
            key = sort_key

        d = TagListEditor(self,
                          category=category,
                          cat_name=db.field_metadata[category]['name'],
                          tag_to_match=tag,
                          get_book_ids=partial(self.get_book_ids,
                                               db=db,
                                               category=category),
                          sorter=key,
                          ttm_is_first_letter=is_first_letter,
                          fm=db.field_metadata[category])
        d.exec_()
        if d.result() == QDialog.DialogCode.Accepted:
            to_rename = d.to_rename  # dict of old id to new name
            to_delete = d.to_delete  # list of ids
            orig_name = d.original_names  # dict of id: name

            if (category in ['tags', 'series', 'publisher']
                    or db.new_api.field_metadata.is_custom_field(category)):
                m = self.tags_view.model()
                for item in to_delete:
                    m.delete_item_from_all_user_categories(
                        orig_name[item], category)
                for old_id in to_rename:
                    m.rename_item_in_all_user_categories(
                        orig_name[old_id], category,
                        unicode_type(to_rename[old_id]))

                db.new_api.remove_items(category, to_delete)
                db.new_api.rename_items(category,
                                        to_rename,
                                        change_index=False)

                # Clean up the library view
                self.do_tag_item_renamed()
                self.tags_view.recount()
Example #5
0
    def do_tags_list_edit(self, tag, category):
        '''
        Open the 'manage_X' dialog where X == category. If tag is not None, the
        dialog will position the editor on that item.
        '''

        tags_model = self.tags_view.model()
        result = tags_model.get_category_editor_data(category)
        if result is None:
            return

        if category == 'series':
            key = lambda x: sort_key(title_sort(x))
        else:
            key = sort_key

        db = self.library_view.model().db
        d = TagListEditor(self,
                          cat_name=db.field_metadata[category]['name'],
                          tag_to_match=tag,
                          data=result,
                          sorter=key)
        d.exec_()
        if d.result() == d.Accepted:
            to_rename = d.to_rename  # dict of old id to new name
            to_delete = d.to_delete  # list of ids
            orig_name = d.original_names  # dict of id: name

            if (category in ['tags', 'series', 'publisher']
                    or db.new_api.field_metadata.is_custom_field(category)):
                m = self.tags_view.model()
                for item in to_delete:
                    m.delete_item_from_all_user_categories(
                        orig_name[item], category)
                for old_id in to_rename:
                    m.rename_item_in_all_user_categories(
                        orig_name[old_id], category,
                        unicode(to_rename[old_id]))

                db.new_api.remove_items(category, to_delete)
                db.new_api.rename_items(category,
                                        to_rename,
                                        change_index=False)

                # Clean up the library view
                self.do_tag_item_renamed()
                self.tags_view.recount()
Example #6
0
    def do_tags_list_edit(self, tag, category):
        '''
        Open the 'manage_X' dialog where X == category. If tag is not None, the
        dialog will position the editor on that item.
        '''

        db = self.current_db

        def get_book_ids(use_virtual_library):
            book_ids = None if not use_virtual_library else self.tags_view.model().get_book_ids_to_use()
            data = db.new_api.get_categories(book_ids=book_ids)
            if category in data:
                result = [(t.id, t.original_name, t.count) for t in data[category] if t.count > 0]
            else:
                result = None
            return result

        if category == 'series':
            key = lambda x:sort_key(title_sort(x))
        else:
            key = sort_key

        d = TagListEditor(self, cat_name=db.field_metadata[category]['name'],
                          tag_to_match=tag, get_book_ids=get_book_ids, sorter=key)
        d.exec_()
        if d.result() == d.Accepted:
            to_rename = d.to_rename  # dict of old id to new name
            to_delete = d.to_delete  # list of ids
            orig_name = d.original_names  # dict of id: name

            if (category in ['tags', 'series', 'publisher'] or
                    db.new_api.field_metadata.is_custom_field(category)):
                m = self.tags_view.model()
                for item in to_delete:
                    m.delete_item_from_all_user_categories(orig_name[item], category)
                for old_id in to_rename:
                    m.rename_item_in_all_user_categories(orig_name[old_id],
                                            category, unicode_type(to_rename[old_id]))

                db.new_api.remove_items(category, to_delete)
                db.new_api.rename_items(category, to_rename, change_index=False)

                # Clean up the library view
                self.do_tag_item_renamed()
                self.tags_view.recount()
Example #7
0
    def do_tags_list_edit(self, tag, category):
        '''
        Open the 'manage_X' dialog where X == category. If tag is not None, the
        dialog will position the editor on that item.
        '''

        tags_model = self.tags_view.model()
        result = tags_model.get_category_editor_data(category)
        if result is None:
            return

        if category == 'series':
            key = lambda x:sort_key(title_sort(x))
        else:
            key = sort_key

        db=self.library_view.model().db
        d = TagListEditor(self, cat_name=db.field_metadata[category]['name'],
                          tag_to_match=tag, data=result, sorter=key)
        d.exec_()
        if d.result() == d.Accepted:
            to_rename = d.to_rename  # dict of old id to new name
            to_delete = d.to_delete  # list of ids
            orig_name = d.original_names  # dict of id: name

            if (category in ['tags', 'series', 'publisher'] or
                    db.new_api.field_metadata.is_custom_field(category)):
                m = self.tags_view.model()
                for item in to_delete:
                    m.delete_item_from_all_user_categories(orig_name[item], category)
                for old_id in to_rename:
                    m.rename_item_in_all_user_categories(orig_name[old_id],
                                            category, unicode(to_rename[old_id]))

                db.new_api.remove_items(category, to_delete)
                db.new_api.rename_items(category, to_rename, change_index=False)

                # Clean up the library view
                self.do_tag_item_renamed()
                self.tags_view.recount()