9
9
from calibre.gui2 import qstring_to_unicode
10
10
from calibre.gui2.dialogs.metadata_bulk_ui import Ui_MetadataBulkDialog
11
11
from calibre.gui2.dialogs.tag_editor import TagEditor
12
from calibre.ebooks.metadata import string_to_authors, authors_to_sort_string
12
from calibre.ebooks.metadata import string_to_authors, authors_to_sort_string, \
14
15
class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
16
17
def __init__(self, window, rows, db):
17
18
QDialog.__init__(self, window)
18
19
Ui_MetadataBulkDialog.__init__(self)
22
23
self.write_series = False
23
24
self.write_rating = False
24
25
self.changed = False
25
QObject.connect(self.button_box, SIGNAL("accepted()"), self.sync)
26
QObject.connect(self.button_box, SIGNAL("accepted()"), self.sync)
26
27
QObject.connect(self.rating, SIGNAL('valueChanged(int)'), self.rating_changed)
28
all_series = self.db.all_series()
32
self.series.addItem(name)
29
self.tags.update_tags_cache(self.db.all_tags())
30
self.remove_tags.update_tags_cache(self.db.all_tags())
32
self.initialize_combos()
34
34
for f in self.db.all_formats():
35
35
self.remove_format.addItem(f)
37
37
self.remove_format.setCurrentIndex(-1)
39
self.series.lineEdit().setText('')
40
39
QObject.connect(self.series, SIGNAL('currentIndexChanged(int)'), self.series_changed)
41
40
QObject.connect(self.series, SIGNAL('editTextChanged(QString)'), self.series_changed)
42
41
QObject.connect(self.tag_editor_button, SIGNAL('clicked()'), self.tag_editor)
45
def initialize_combos(self):
46
self.initalize_authors()
47
self.initialize_series()
48
self.initialize_publisher()
50
def initalize_authors(self):
51
all_authors = self.db.all_authors()
52
all_authors.sort(cmp=lambda x, y : cmp(x[1], y[1]))
56
name = authors_to_string([name.strip().replace('|', ',') for n in name.split(',')])
57
self.authors.addItem(name)
58
self.authors.setEditText('')
60
def initialize_series(self):
61
all_series = self.db.all_series()
62
all_series.sort(cmp=lambda x, y : cmp(x[1], y[1]))
66
self.series.addItem(name)
67
self.series.setEditText('')
69
def initialize_publisher(self):
70
all_publishers = self.db.all_publishers()
71
all_publishers.sort(cmp=lambda x, y : cmp(x[1], y[1]))
73
for i in all_publishers:
75
self.publisher.addItem(name)
76
self.publisher.setEditText('')
45
78
def tag_editor(self):
46
79
d = TagEditor(self, self.db, None)
48
81
if d.result() == QDialog.Accepted:
49
82
tag_string = ', '.join(d.tags)
50
83
self.tags.setText(tag_string)
84
self.tags.update_tags_cache(self.db.all_tags())
85
self.remove_tags.update_tags_cache(self.db.all_tags())
53
88
for id in self.ids:
54
89
au = qstring_to_unicode(self.authors.text())
80
115
self.db.set_tags(id, tags, append=True, notify=False)
81
116
if self.write_series:
82
117
self.db.set_series(id, qstring_to_unicode(self.series.currentText()), notify=False)
84
119
if self.remove_format.currentIndex() > -1:
85
120
self.db.remove_format(id, unicode(self.remove_format.currentText()), index_is_id=True, notify=False)
87
122
self.changed = True
89
124
def series_changed(self):
90
125
self.write_series = True
92
127
def rating_changed(self):
93
self.write_rating = True
b'\\ No newline at end of file'
128
self.write_rating = True