mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Implement #537
This commit is contained in:
parent
b45bcc9ea3
commit
1ddcfb5844
@ -152,6 +152,8 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
self.fetch_cover)
|
||||
QObject.connect(self.tag_editor_button, SIGNAL('clicked()'),
|
||||
self.edit_tags)
|
||||
QObject.connect(self.remove_series_button, SIGNAL('clicked()'),
|
||||
self.remove_unused_series)
|
||||
self.timeout = float(QSettings().value('network timeout', QVariant(5)).toInt()[0])
|
||||
self.title.setText(db.title(row))
|
||||
isbn = db.isbn(self.id)
|
||||
@ -186,9 +188,19 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
size = self.db.sizeof_format(row, ext)
|
||||
Format(self.formats, ext, size)
|
||||
|
||||
self.initialize_series()
|
||||
|
||||
self.series_index.setValue(self.db.series_index(row))
|
||||
QObject.connect(self.series, SIGNAL('currentIndexChanged(int)'), self.enable_series_index)
|
||||
QObject.connect(self.series, SIGNAL('editTextChanged(QString)'), self.enable_series_index)
|
||||
QObject.connect(self.password_button, SIGNAL('clicked()'), self.change_password)
|
||||
|
||||
self.exec_()
|
||||
|
||||
def initialize_series(self):
|
||||
all_series = self.db.all_series()
|
||||
all_series.sort(cmp=lambda x, y : cmp(x[1], y[1]))
|
||||
series_id = self.db.series_id(row)
|
||||
series_id = self.db.series_id(self.row)
|
||||
idx, c = None, 0
|
||||
for i in all_series:
|
||||
id, name = i
|
||||
@ -202,13 +214,14 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
self.series.setCurrentIndex(idx)
|
||||
self.enable_series_index()
|
||||
|
||||
self.series_index.setValue(self.db.series_index(row))
|
||||
QObject.connect(self.series, SIGNAL('currentIndexChanged(int)'), self.enable_series_index)
|
||||
QObject.connect(self.series, SIGNAL('editTextChanged(QString)'), self.enable_series_index)
|
||||
QObject.connect(self.password_button, SIGNAL('clicked()'), self.change_password)
|
||||
|
||||
self.exec_()
|
||||
pl = self.series.parentWidget().layout()
|
||||
for i in range(pl.count()):
|
||||
l = pl.itemAt(i).layout()
|
||||
if l:
|
||||
l.invalidate()
|
||||
l.activate()
|
||||
|
||||
self.layout().activate()
|
||||
|
||||
def edit_tags(self):
|
||||
d = TagEditor(self, self.db, self.row)
|
||||
@ -280,6 +293,18 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
def enable_series_index(self, *args):
|
||||
self.series_index.setEnabled(True)
|
||||
|
||||
def remove_unused_series(self):
|
||||
self.db.remove_unused_series()
|
||||
idx = qstring_to_unicode(self.series.currentText())
|
||||
self.series.clear()
|
||||
self.initialize_series()
|
||||
if idx:
|
||||
for i in range(self.series.count()):
|
||||
if qstring_to_unicode(self.series.itemText(i)) == idx:
|
||||
self.series.setCurrentIndex(i)
|
||||
break
|
||||
|
||||
|
||||
def accept(self):
|
||||
if self.formats_changed:
|
||||
self.sync_formats()
|
||||
|
@ -24,7 +24,7 @@
|
||||
<widget class="QWidget" name="layoutWidget" >
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<widget class="QGroupBox" name="meta_box" >
|
||||
<property name="title" >
|
||||
<string>Meta information</string>
|
||||
</property>
|
||||
@ -195,7 +195,18 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="series" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>List of known series. You can add new series.</string>
|
||||
</property>
|
||||
@ -213,6 +224,21 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="remove_series_button" >
|
||||
<property name="toolTip" >
|
||||
<string>Remove unused series (Series that have no books)</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="../images.qrc" >:/images/trash.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="7" column="1" >
|
||||
<widget class="QSpinBox" name="series_index" >
|
||||
<property name="enabled" >
|
||||
|
@ -751,6 +751,33 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
conn.execute('pragma user_version=7')
|
||||
conn.commit()
|
||||
|
||||
@staticmethod
|
||||
def upgrade_version7(conn):
|
||||
conn.executescript('''\
|
||||
DROP TRIGGER fkc_update_books_series_link_b;
|
||||
CREATE TRIGGER fkc_update_books_series_link_b
|
||||
BEFORE UPDATE OF series ON books_series_link
|
||||
BEGIN
|
||||
SELECT CASE
|
||||
WHEN (SELECT id from series WHERE id=NEW.series) IS NULL
|
||||
THEN RAISE(ABORT, 'Foreign key violation: series not in series')
|
||||
END;
|
||||
END;
|
||||
|
||||
DROP TRIGGER fkc_delete_books_series_link;
|
||||
CREATE TRIGGER fkc_delete_books_series_link
|
||||
BEFORE DELETE ON series
|
||||
BEGIN
|
||||
SELECT CASE
|
||||
WHEN (SELECT COUNT(id) FROM books_series_link WHERE series=OLD.id) > 0
|
||||
THEN RAISE(ABORT, 'Foreign key violation: series is still referenced')
|
||||
END;
|
||||
END;
|
||||
'''
|
||||
)
|
||||
conn.execute('pragma user_version=8')
|
||||
conn.commit()
|
||||
|
||||
def __del__(self):
|
||||
global _lock_file
|
||||
import os
|
||||
@ -778,6 +805,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
LibraryDatabase.upgrade_version5(self.conn)
|
||||
if self.user_version == 6: # Upgrade to 7
|
||||
LibraryDatabase.upgrade_version6(self.conn)
|
||||
if self.user_version == 7: # Upgrade to 8
|
||||
LibraryDatabase.upgrade_version7(self.conn)
|
||||
|
||||
def close(self):
|
||||
global _lock_file
|
||||
@ -1159,6 +1188,12 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
self.conn.execute('INSERT INTO books_series_link(book, series) VALUES (?,?)', (id, aid))
|
||||
self.conn.commit()
|
||||
|
||||
def remove_unused_series(self):
|
||||
for id, in self.conn.execute('SELECT id FROM series').fetchall():
|
||||
if not self.conn.execute('SELECT id from books_series_link WHERE series=?', (id,)).fetchone():
|
||||
self.conn.execute('DELETE FROM series WHERE id=?', (id,))
|
||||
self.conn.commit()
|
||||
|
||||
def set_series_index(self, id, idx):
|
||||
self.conn.execute('UPDATE books SET series_index=? WHERE id=?', (int(idx), id))
|
||||
self.conn.commit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user