mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add compact database button to config dialog
This commit is contained in:
parent
885cfdeb95
commit
e7a465ce6e
@ -53,6 +53,12 @@ def question_dialog(parent, title, msg):
|
||||
d.setIconPixmap(QPixmap(':/images/dialog_information.svg'))
|
||||
return d
|
||||
|
||||
def info_dialog(parent, title, msg):
|
||||
d = QMessageBox(QMessageBox.Information, title, msg, QMessageBox.NoButton,
|
||||
parent)
|
||||
d.setIconPixmap(QPixmap(':/images/dialog_information.svg'))
|
||||
return d
|
||||
|
||||
def qstring_to_unicode(q):
|
||||
return unicode(q)
|
||||
|
||||
|
@ -14,8 +14,8 @@
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
import os
|
||||
|
||||
from PyQt4.QtGui import QDialog
|
||||
from PyQt4.QtCore import QSettings, QVariant, SIGNAL, QStringList
|
||||
from PyQt4.QtGui import QDialog, QMessageBox
|
||||
from PyQt4.QtCore import QSettings, QVariant, SIGNAL, QStringList, QTimer
|
||||
|
||||
from libprs500 import islinux
|
||||
from libprs500.gui2.dialogs.config_ui import Ui_Dialog
|
||||
@ -23,11 +23,12 @@ from libprs500.gui2 import qstring_to_unicode, choose_dir, error_dialog
|
||||
|
||||
class ConfigDialog(QDialog, Ui_Dialog):
|
||||
|
||||
def __init__(self, window):
|
||||
def __init__(self, window, db):
|
||||
QDialog.__init__(self, window)
|
||||
Ui_Dialog.__init__(self)
|
||||
self.setupUi(self)
|
||||
|
||||
self.db = db
|
||||
settings = QSettings()
|
||||
path = qstring_to_unicode(\
|
||||
settings.value("database path",
|
||||
@ -35,6 +36,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
|
||||
self.location.setText(os.path.dirname(path))
|
||||
self.connect(self.browse_button, SIGNAL('clicked(bool)'), self.browse)
|
||||
self.connect(self.compact_button, SIGNAL('clicked(bool)'), self.compact)
|
||||
|
||||
dirs = settings.value('frequently used directories', QVariant(QStringList())).toStringList()
|
||||
rn = bool(settings.value('use roman numerals for series number',
|
||||
@ -51,6 +53,10 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
if not islinux:
|
||||
self.dirs_box.setVisible(False)
|
||||
|
||||
def compact(self, toggled):
|
||||
d = Vacuum(self, self.db)
|
||||
d.exec_()
|
||||
|
||||
def browse(self):
|
||||
dir = choose_dir(self, 'database location dialog', 'Select database location')
|
||||
if dir:
|
||||
@ -82,3 +88,16 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
self.directories = [qstring_to_unicode(self.directory_list.item(i).text()) for i in range(self.directory_list.count())]
|
||||
settings.setValue('frequently used directories', QVariant(self.directories))
|
||||
QDialog.accept(self)
|
||||
|
||||
class Vacuum(QMessageBox):
|
||||
|
||||
def __init__(self, parent, db):
|
||||
self.db = db
|
||||
QMessageBox.__init__(self, QMessageBox.Information, 'Compacting...', 'Compacting database. This may take a while.',
|
||||
QMessageBox.NoButton, parent)
|
||||
QTimer.singleShot(200, self.vacuum)
|
||||
|
||||
def vacuum(self):
|
||||
self.db.vacuum()
|
||||
self.accept()
|
||||
|
@ -19,8 +19,8 @@
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackedWidget" >
|
||||
<widget class="QWidget" name="page" >
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<widget class="QLabel" name="label" >
|
||||
@ -54,7 +54,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QCheckBox" name="roman_numerals" >
|
||||
<property name="text" >
|
||||
<string>Use &Roman numerals for series number</string>
|
||||
@ -64,7 +64,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="2" column="0" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2" >
|
||||
@ -97,13 +97,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<item row="3" column="0" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3" >
|
||||
<property name="text" >
|
||||
<string>&Priority for conversion jobs:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>priority</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -111,7 +114,47 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="compact_button" >
|
||||
<property name="toolTip" >
|
||||
<string>Free unused diskspace from the database</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Compact database</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0" >
|
||||
<widget class="QGroupBox" name="dirs_box" >
|
||||
<property name="title" >
|
||||
<string>Frequently used directories</string>
|
||||
@ -206,7 +249,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="6" column="0" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
@ -676,7 +676,7 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
d = error_dialog(self, _('Cannot configure'), _('Cannot configure while there are running jobs.'))
|
||||
d.exec_()
|
||||
return
|
||||
d = ConfigDialog(self)
|
||||
d = ConfigDialog(self, self.library_view.model().db)
|
||||
d.exec_()
|
||||
if d.result() == d.Accepted:
|
||||
if os.path.dirname(self.database_path) != d.database_location:
|
||||
|
@ -1277,6 +1277,10 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
mi.libprs_id = id
|
||||
return mi
|
||||
|
||||
def vacuum(self):
|
||||
self.conn.execute('VACUUM;')
|
||||
self.conn.commit()
|
||||
|
||||
def export_to_dir(self, dir, indices, byauthor=False):
|
||||
if not os.path.exists(dir):
|
||||
raise IOError('Target directory does not exist: '+dir)
|
||||
@ -1329,6 +1333,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
|
||||
class SearchToken(object):
|
||||
|
||||
FIELD_MAP = { 'title' : 1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user