This commit is contained in:
Kovid Goyal 2007-12-06 00:04:22 +00:00
parent 27bcf6071e
commit 8a6f967645
2 changed files with 102 additions and 73 deletions

View File

@ -12,9 +12,10 @@
## You should have received a copy of the GNU General Public License along
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import cPickle
import os, cPickle
from PyQt4.QtCore import QObject, SIGNAL, Qt
from PyQt4.QtCore import QObject, SIGNAL, Qt, QSettings, QVariant, QByteArray
from PyQt4.QtGui import QAbstractSpinBox, QLineEdit, QCheckBox, QDialog, \
QPixmap, QTextEdit
@ -63,7 +64,6 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
self.initialize_options()
self.db = db
self.row = row
self.id = self.db.id(self.row)
self.cover_changed = False
self.cpixmap = None
self.changed = False
@ -75,6 +75,10 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
self.gui_sans_family.setModel(self.font_family_model)
self.gui_mono_family.setModel(self.font_family_model)
self.load_saved_global_defaults()
if db:
self.id = self.db.id(self.row)
self.read_saved_options()
self.initialize_metadata()
formats = self.db.formats(self.row)
@ -84,8 +88,8 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
except ValueError:
pass
if not formats:
d = error_dialog(window, 'No available formats',
'Cannot convert %s as this book has no supported formats'%(self.gui_title.text()))
d = error_dialog(window, _('No available formats'),
_('Cannot convert %s as this book has no supported formats')%(self.gui_title.text()))
d.exec_()
if len(formats) > 1:
@ -97,25 +101,35 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
self.selected_format = formats[0]
if self.selected_format:
self.setWindowTitle('Convert %s to LRF'%(self.selected_format,))
self.setWindowTitle(_('Convert %s to LRF')%(self.selected_format,))
else:
self.setWindowTitle(_('Set conversion defaults'))
def read_saved_options(self):
cmdline = self.db.conversion_options(self.id, self.output_format.lower())
def load_saved_global_defaults(self):
cmdline = QSettings().value('LRF conversion defaults', QVariant(QByteArray(''))).toByteArray().data()
if cmdline:
cmdline = cPickle.loads(cmdline)
self.set_options_from_cmdline(cmdline)
def set_options_from_cmdline(self, cmdline):
for opt in self.options():
try:
i = cmdline.index(opt.get_opt_string())
except ValueError:
continue
guiname = self.option_to_name(opt)
try:
obj = getattr(self, guiname)
except AttributeError:
continue
if isinstance(obj, QCheckBox):
if opt.get_opt_string() in cmdline:
obj.setCheckState(Qt.Checked)
elif isinstance(obj, QAbstractSpinBox):
else:
obj.setCheckState(Qt.Unchecked)
try:
i = cmdline.index(opt.get_opt_string())
except ValueError:
continue
if isinstance(obj, QAbstractSpinBox):
obj.setValue(cmdline[i+1])
elif isinstance(obj, QLineEdit):
obj.setText(cmdline[i+1])
@ -139,6 +153,11 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
except:
continue
def read_saved_options(self):
cmdline = self.db.conversion_options(self.id, self.output_format.lower())
if cmdline:
self.set_options_from_cmdline(cmdline)
def select_cover(self, checked):
files = choose_images(self, 'change cover dialog',
u'Choose cover for ' + qstring_to_unicode(self.gui_title.text()))
@ -342,6 +361,7 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
def accept(self):
cmdline = self.build_commandline()
if self.db:
self.cover_file = None
self.write_metadata()
cover = self.db.cover(self.row)
@ -354,5 +374,7 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
if self.cover_file:
cmdline.extend([u'--cover', self.cover_file.name])
self.cmdline = [unicode(i) for i in cmdline]
else:
QSettings().setValue('LRF conversion defaults', QVariant(QByteArray(cPickle.dumps(cmdline))))
QDialog.accept(self)

View File

@ -144,9 +144,12 @@ class Main(MainWindow, Ui_MainWindow):
cm = QMenu()
cm.addAction(_('Convert individually'))
cm.addAction(_('Bulk convert'))
cm.addSeparator()
cm.addAction(_('Set conversion defaults'))
self.action_convert.setMenu(cm)
QObject.connect(cm.actions()[0], SIGNAL('triggered(bool)'), self.convert_single)
QObject.connect(cm.actions()[1], SIGNAL('triggered(bool)'), self.convert_bulk)
QObject.connect(cm.actions()[3], SIGNAL('triggered(bool)'), self.set_conversion_defaults)
QObject.connect(self.action_convert, SIGNAL('triggered(bool)'), self.convert_single)
self.convert_menu = cm
self.tool_bar.widgetForAction(self.action_news).setPopupMode(QToolButton.InstantPopup)
@ -587,6 +590,10 @@ class Main(MainWindow, Ui_MainWindow):
d = error_dialog(self, 'Cannot convert', 'Not yet implemented.')
d.exec_()
def set_conversion_defaults(self, checked):
d = LRFSingleDialog(self, None, None)
d.exec_()
def convert_single(self, checked):
rows = self.library_view.selectionModel().selectedRows()
if not rows or len(rows) == 0: