Exemple #1
0
 def do_map(self, book_ids, selected):
     from calibre.ebooks.metadata.tag_mapper import map_tags
     from calibre.gui2.tag_mapper import RulesDialog
     from calibre.gui2.device import BusyCursor
     d = RulesDialog(self.gui)
     d.setWindowTitle(ngettext(
         'Map tags for one book in the library',
         'Map tags for {} books in the library', len(book_ids)).format(len(book_ids)))
     d.rules = gprefs.get('library-tag-mapper-ruleset', ())
     txt = ngettext(
         'The changes will be applied to the <b>selected book</b>',
         'The changes will be applied to the <b>{} selected books</b>', len(book_ids)) if selected else ngettext(
         'The changes will be applied to <b>one book in the library</b>',
         'The changes will be applied to <b>{} books in the library</b>', len(book_ids))
     d.edit_widget.msg_label.setText(d.edit_widget.msg_label.text() + '<p>' + txt.format(len(book_ids)))
     if d.exec_() != d.Accepted:
         return
     with BusyCursor():
         rules = d.rules
         gprefs.set('library-tag-mapper-ruleset', rules)
         db = self.gui.current_db.new_api
         tag_map = db.all_field_for('tags', book_ids)
         changed_tag_map = {}
         for book_id, tags in iteritems(tag_map):
             tags = list(tags)
             new_tags = map_tags(tags, rules)
             if tags != new_tags:
                 changed_tag_map[book_id] = new_tags
         if changed_tag_map:
             db.set_field('tags', changed_tag_map)
             self.gui.library_view.model().refresh_ids(tuple(changed_tag_map), current_row=self.gui.library_view.currentIndex().row())
Exemple #2
0
 def change_add_filter_rules(self):
     from calibre.gui2.add_filters import RulesDialog
     d = RulesDialog(self)
     if gprefs.get('add_filter_rules'):
         d.rules = gprefs['add_filter_rules']
     if d.exec_() == d.Accepted:
         self.add_filter_rules = d.rules
         self.changed_signal.emit()
Exemple #3
0
 def change_tag_map_rules(self):
     from calibre.gui2.tag_mapper import RulesDialog
     d = RulesDialog(self)
     if gprefs.get('tag_map_on_add_rules'):
         d.rules = gprefs['tag_map_on_add_rules']
     if d.exec_() == d.Accepted:
         self.tag_map_rules = d.rules
         self.changed_signal.emit()
Exemple #4
0
 def change_author_map_rules(self):
     from calibre.gui2.author_mapper import RulesDialog
     d = RulesDialog(self)
     if msprefs.get('author_map_rules'):
         d.rules = msprefs['author_map_rules']
     if d.exec_() == d.Accepted:
         self.author_map_rules = d.rules
         self.changed_signal.emit()
Exemple #5
0
 def change_add_filter_rules(self):
     from calibre.gui2.add_filters import RulesDialog
     d = RulesDialog(self)
     if gprefs.get('add_filter_rules'):
         d.rules = gprefs['add_filter_rules']
     if d.exec_() == d.Accepted:
         self.add_filter_rules = d.rules
         self.changed_signal.emit()
Exemple #6
0
 def change_tag_map_rules(self):
     from calibre.gui2.tag_mapper import RulesDialog
     d = RulesDialog(self)
     if gprefs.get('tag_map_on_add_rules'):
         d.rules = gprefs['tag_map_on_add_rules']
     if d.exec_() == d.Accepted:
         self.tag_map_rules = d.rules
         self.changed_signal.emit()
Exemple #7
0
 def change_author_map_rules(self):
     from calibre.gui2.author_mapper import RulesDialog
     d = RulesDialog(self)
     if gprefs.get('author_map_on_add_rules'):
         d.rules = gprefs['author_map_on_add_rules']
     if d.exec() == QDialog.DialogCode.Accepted:
         self.author_map_rules = d.rules
         self.changed_signal.emit()
Exemple #8
0
 def change_author_map_rules(self):
     from calibre.gui2.author_mapper import RulesDialog
     d = RulesDialog(self)
     if msprefs.get('author_map_rules'):
         d.rules = msprefs['author_map_rules']
     if d.exec_() == d.Accepted:
         self.author_map_rules = d.rules
         self.changed_signal.emit()
 def change_tag_map_rules(self):
     from calibre.gui2.tag_mapper import RulesDialog
     d = RulesDialog(self)
     if msprefs.get('tag_map_rules'):
         d.rules = msprefs['tag_map_rules']
     if d.exec() == QDialog.DialogCode.Accepted:
         self.tag_map_rules = d.rules
         self.changed_signal.emit()
Exemple #10
0
 def do_map(self, book_ids, selected):
     from calibre.ebooks.metadata.tag_mapper import map_tags
     from calibre.gui2.tag_mapper import RulesDialog
     from calibre.gui2.device import BusyCursor
     d = RulesDialog(self.gui)
     d.setWindowTitle(_('Map tags for %d books in the library') % len(book_ids))
     d.rules = gprefs.get('library-tag-mapper-ruleset', ())
     txt = _('The changes will be applied to the <b>%d selected books</b>') if selected else _(
         'The changes will be applied to <b>%d books in the library</b>')
     d.edit_widget.msg_label.setText(d.edit_widget.msg_label.text() + '<p>' + txt % len(book_ids))
     if d.exec_() != d.Accepted:
         return
     with BusyCursor():
         rules = d.rules
         gprefs.set('library-tag-mapper-ruleset', rules)
         db = self.gui.current_db.new_api
         tag_map = db.all_field_for('tags', book_ids)
         changed_tag_map = {}
         for book_id, tags in tag_map.iteritems():
             tags = list(tags)
             new_tags = map_tags(tags, rules)
             if tags != new_tags:
                 changed_tag_map[book_id] = new_tags
         if changed_tag_map:
             db.set_field('tags', changed_tag_map)
             self.gui.library_view.model().refresh_ids(tuple(changed_tag_map), current_row=self.gui.library_view.currentIndex().row())
Exemple #11
0
 def __init__(self, *args, **kw):
     # This has to be loaded on instantiation as it can be shared by
     # multiple processes
     self.PREFS_OBJECT = JSONConfig('style-transform-rules')
     RulesDialogBase.__init__(self, *args, **kw)
 def __init__(self, *args, **kw):
     # This has to be loaded on instantiation as it can be shared by
     # multiple processes
     self.PREFS_OBJECT = JSONConfig('style-transform-rules')
     RulesDialogBase.__init__(self, *args, **kw)