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
@ -151,7 +151,9 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
|||||||
QObject.connect(self.fetch_cover_button, SIGNAL('clicked()'),
|
QObject.connect(self.fetch_cover_button, SIGNAL('clicked()'),
|
||||||
self.fetch_cover)
|
self.fetch_cover)
|
||||||
QObject.connect(self.tag_editor_button, SIGNAL('clicked()'),
|
QObject.connect(self.tag_editor_button, SIGNAL('clicked()'),
|
||||||
self.edit_tags)
|
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.timeout = float(QSettings().value('network timeout', QVariant(5)).toInt()[0])
|
||||||
self.title.setText(db.title(row))
|
self.title.setText(db.title(row))
|
||||||
isbn = db.isbn(self.id)
|
isbn = db.isbn(self.id)
|
||||||
@ -186,9 +188,19 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
|||||||
size = self.db.sizeof_format(row, ext)
|
size = self.db.sizeof_format(row, ext)
|
||||||
Format(self.formats, ext, size)
|
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 = self.db.all_series()
|
||||||
all_series.sort(cmp=lambda x, y : cmp(x[1], y[1]))
|
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
|
idx, c = None, 0
|
||||||
for i in all_series:
|
for i in all_series:
|
||||||
id, name = i
|
id, name = i
|
||||||
@ -201,14 +213,15 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
|||||||
if idx is not None:
|
if idx is not None:
|
||||||
self.series.setCurrentIndex(idx)
|
self.series.setCurrentIndex(idx)
|
||||||
self.enable_series_index()
|
self.enable_series_index()
|
||||||
|
|
||||||
self.series_index.setValue(self.db.series_index(row))
|
pl = self.series.parentWidget().layout()
|
||||||
QObject.connect(self.series, SIGNAL('currentIndexChanged(int)'), self.enable_series_index)
|
for i in range(pl.count()):
|
||||||
QObject.connect(self.series, SIGNAL('editTextChanged(QString)'), self.enable_series_index)
|
l = pl.itemAt(i).layout()
|
||||||
QObject.connect(self.password_button, SIGNAL('clicked()'), self.change_password)
|
if l:
|
||||||
|
l.invalidate()
|
||||||
self.exec_()
|
l.activate()
|
||||||
|
|
||||||
|
self.layout().activate()
|
||||||
|
|
||||||
def edit_tags(self):
|
def edit_tags(self):
|
||||||
d = TagEditor(self, self.db, self.row)
|
d = TagEditor(self, self.db, self.row)
|
||||||
@ -280,6 +293,18 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
|||||||
def enable_series_index(self, *args):
|
def enable_series_index(self, *args):
|
||||||
self.series_index.setEnabled(True)
|
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):
|
def accept(self):
|
||||||
if self.formats_changed:
|
if self.formats_changed:
|
||||||
self.sync_formats()
|
self.sync_formats()
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
<widget class="QWidget" name="layoutWidget" >
|
<widget class="QWidget" name="layoutWidget" >
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout" >
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox" >
|
<widget class="QGroupBox" name="meta_box" >
|
||||||
<property name="title" >
|
<property name="title" >
|
||||||
<string>Meta information</string>
|
<string>Meta information</string>
|
||||||
</property>
|
</property>
|
||||||
@ -195,23 +195,49 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="1" >
|
<item row="6" column="1" >
|
||||||
<widget class="QComboBox" name="series" >
|
<layout class="QHBoxLayout" >
|
||||||
<property name="toolTip" >
|
<property name="spacing" >
|
||||||
<string>List of known series. You can add new series.</string>
|
<number>5</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="whatsThis" >
|
<item>
|
||||||
<string>List of known series. You can add new series.</string>
|
<widget class="QComboBox" name="series" >
|
||||||
</property>
|
<property name="sizePolicy" >
|
||||||
<property name="editable" >
|
<sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
|
||||||
<bool>true</bool>
|
<horstretch>0</horstretch>
|
||||||
</property>
|
<verstretch>0</verstretch>
|
||||||
<property name="insertPolicy" >
|
</sizepolicy>
|
||||||
<enum>QComboBox::InsertAlphabetically</enum>
|
</property>
|
||||||
</property>
|
<property name="toolTip" >
|
||||||
<property name="sizeAdjustPolicy" >
|
<string>List of known series. You can add new series.</string>
|
||||||
<enum>QComboBox::AdjustToContents</enum>
|
</property>
|
||||||
</property>
|
<property name="whatsThis" >
|
||||||
</widget>
|
<string>List of known series. You can add new series.</string>
|
||||||
|
</property>
|
||||||
|
<property name="editable" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="insertPolicy" >
|
||||||
|
<enum>QComboBox::InsertAlphabetically</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeAdjustPolicy" >
|
||||||
|
<enum>QComboBox::AdjustToContents</enum>
|
||||||
|
</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>
|
||||||
<item row="7" column="1" >
|
<item row="7" column="1" >
|
||||||
<widget class="QSpinBox" name="series_index" >
|
<widget class="QSpinBox" name="series_index" >
|
||||||
|
@ -751,6 +751,33 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
conn.execute('pragma user_version=7')
|
conn.execute('pragma user_version=7')
|
||||||
conn.commit()
|
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):
|
def __del__(self):
|
||||||
global _lock_file
|
global _lock_file
|
||||||
import os
|
import os
|
||||||
@ -778,6 +805,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
LibraryDatabase.upgrade_version5(self.conn)
|
LibraryDatabase.upgrade_version5(self.conn)
|
||||||
if self.user_version == 6: # Upgrade to 7
|
if self.user_version == 6: # Upgrade to 7
|
||||||
LibraryDatabase.upgrade_version6(self.conn)
|
LibraryDatabase.upgrade_version6(self.conn)
|
||||||
|
if self.user_version == 7: # Upgrade to 8
|
||||||
|
LibraryDatabase.upgrade_version7(self.conn)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
global _lock_file
|
global _lock_file
|
||||||
@ -1158,6 +1187,12 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
aid = self.conn.execute('INSERT INTO series(name) VALUES (?)', (series,)).lastrowid
|
aid = self.conn.execute('INSERT INTO series(name) VALUES (?)', (series,)).lastrowid
|
||||||
self.conn.execute('INSERT INTO books_series_link(book, series) VALUES (?,?)', (id, aid))
|
self.conn.execute('INSERT INTO books_series_link(book, series) VALUES (?,?)', (id, aid))
|
||||||
self.conn.commit()
|
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):
|
def set_series_index(self, id, idx):
|
||||||
self.conn.execute('UPDATE books SET series_index=? WHERE id=?', (int(idx), id))
|
self.conn.execute('UPDATE books SET series_index=? WHERE id=?', (int(idx), id))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user