mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2688 (duplicate tag entries in tag database) and add PDB, RB to internally viewed formats
This commit is contained in:
parent
f8f4a0fbe3
commit
998d7647a3
@ -48,7 +48,8 @@ def _config():
|
||||
help=_('Defaults for conversion to LRF'))
|
||||
c.add_opt('LRF_ebook_viewer_options', default=None,
|
||||
help=_('Options for the LRF ebook viewer'))
|
||||
c.add_opt('internally_viewed_formats', default=['LRF', 'EPUB', 'LIT', 'MOBI', 'PRC', 'HTML', 'FB2'],
|
||||
c.add_opt('internally_viewed_formats', default=['LRF', 'EPUB', 'LIT',
|
||||
'MOBI', 'PRC', 'HTML', 'FB2', 'PDB', 'RB'],
|
||||
help=_('Formats that are viewed using the internal viewer'))
|
||||
c.add_opt('column_map', default=ALL_COLUMNS,
|
||||
help=_('Columns to be displayed in the book list'))
|
||||
|
@ -12,7 +12,7 @@ from calibre.gui2.dialogs.tag_editor import TagEditor
|
||||
from calibre.ebooks.metadata import string_to_authors, authors_to_sort_string
|
||||
|
||||
class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
|
||||
|
||||
def __init__(self, window, rows, db):
|
||||
QDialog.__init__(self, window)
|
||||
Ui_MetadataBulkDialog.__init__(self)
|
||||
@ -22,33 +22,33 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
self.write_series = False
|
||||
self.write_rating = False
|
||||
self.changed = False
|
||||
QObject.connect(self.button_box, SIGNAL("accepted()"), self.sync)
|
||||
QObject.connect(self.button_box, SIGNAL("accepted()"), self.sync)
|
||||
QObject.connect(self.rating, SIGNAL('valueChanged(int)'), self.rating_changed)
|
||||
|
||||
|
||||
all_series = self.db.all_series()
|
||||
|
||||
|
||||
for i in all_series:
|
||||
id, name = i
|
||||
self.series.addItem(name)
|
||||
|
||||
|
||||
for f in self.db.all_formats():
|
||||
self.remove_format.addItem(f)
|
||||
|
||||
|
||||
self.remove_format.setCurrentIndex(-1)
|
||||
|
||||
|
||||
self.series.lineEdit().setText('')
|
||||
QObject.connect(self.series, SIGNAL('currentIndexChanged(int)'), self.series_changed)
|
||||
QObject.connect(self.series, SIGNAL('editTextChanged(QString)'), self.series_changed)
|
||||
QObject.connect(self.tag_editor_button, SIGNAL('clicked()'), self.tag_editor)
|
||||
self.exec_()
|
||||
|
||||
|
||||
def tag_editor(self):
|
||||
d = TagEditor(self, self.db, None)
|
||||
d.exec_()
|
||||
if d.result() == QDialog.Accepted:
|
||||
tag_string = ', '.join(d.tags)
|
||||
self.tags.setText(tag_string)
|
||||
|
||||
|
||||
def sync(self):
|
||||
for id in self.ids:
|
||||
au = qstring_to_unicode(self.authors.text())
|
||||
@ -80,14 +80,14 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
self.db.set_tags(id, tags, append=True, notify=False)
|
||||
if self.write_series:
|
||||
self.db.set_series(id, qstring_to_unicode(self.series.currentText()), notify=False)
|
||||
|
||||
|
||||
if self.remove_format.currentIndex() > -1:
|
||||
self.db.remove_format(id, unicode(self.remove_format.currentText()), index_is_id=True, notify=False)
|
||||
|
||||
|
||||
self.changed = True
|
||||
|
||||
|
||||
def series_changed(self):
|
||||
self.write_series = True
|
||||
|
||||
|
||||
def rating_changed(self):
|
||||
self.write_rating = True
|
||||
self.write_rating = True
|
||||
|
@ -224,6 +224,10 @@ class ResultCache(SearchQueryParser):
|
||||
id = row if row_is_id else self._map_filtered[row]
|
||||
self._data[id][col] = val
|
||||
|
||||
def get(self, row, col, row_is_id=False):
|
||||
id = row if row_is_id else self._map_filtered[row]
|
||||
return self._data[id][col]
|
||||
|
||||
def index(self, id, cache=False):
|
||||
x = self._map if cache else self._map_filtered
|
||||
return x.index(id)
|
||||
@ -1105,6 +1109,14 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
if notify:
|
||||
self.notify('metadata', [id])
|
||||
|
||||
def get_tags(self, id):
|
||||
result = self.conn.get(
|
||||
'SELECT name FROM tags WHERE id IN (SELECT tag FROM books_tags_link WHERE book=?)',
|
||||
(id,), all=True)
|
||||
if not result:
|
||||
return set([])
|
||||
return set([r[0] for r in result])
|
||||
|
||||
def set_tags(self, id, tags, append=False, notify=True):
|
||||
'''
|
||||
@param tags: list of strings
|
||||
@ -1113,7 +1125,8 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
if not append:
|
||||
self.conn.execute('DELETE FROM books_tags_link WHERE book=?', (id,))
|
||||
self.conn.execute('DELETE FROM tags WHERE (SELECT COUNT(id) FROM books_tags_link WHERE tag=tags.id) < 1')
|
||||
for tag in set(tags):
|
||||
otags = self.get_tags(id)
|
||||
for tag in (set(tags)-otags):
|
||||
tag = tag.strip()
|
||||
if not tag:
|
||||
continue
|
||||
@ -1138,13 +1151,7 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
self.conn.execute('INSERT INTO books_tags_link(book, tag) VALUES (?,?)',
|
||||
(id, tid))
|
||||
self.conn.commit()
|
||||
try:
|
||||
otags = [t.strip() for t in self.data[self.data.row(id)][FIELD_MAP['tags']].split(',')]
|
||||
except AttributeError:
|
||||
otags = []
|
||||
if not append:
|
||||
otags = []
|
||||
tags = ','.join(otags+tags)
|
||||
tags = ','.join(self.get_tags(id))
|
||||
self.data.set(id, FIELD_MAP['tags'], tags, row_is_id=True)
|
||||
if notify:
|
||||
self.notify('metadata', [id])
|
||||
|
Loading…
x
Reference in New Issue
Block a user