From 2508202262b832f221b967ad2fa6e88c624b08ab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 21 Dec 2009 21:12:04 -0700 Subject: [PATCH] When adding books via the add books button to the device, restrict to formats supported by device --- src/calibre/gui2/ui.py | 12 ++++++++---- src/calibre/library/database2.py | 2 +- src/calibre/utils/config.py | 24 +----------------------- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 013b37e98f..ad1e3938c4 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -926,8 +926,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): ''' Add books from the local filesystem to either the library or the device. ''' - books = choose_files(self, 'add books dialog dir', 'Select books', - filters=[ + filters = [ (_('Books'), BOOK_EXTENSIONS), (_('EPUB Books'), ['epub']), (_('LRF Books'), ['lrf']), @@ -938,10 +937,15 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): (_('PDF Books'), ['pdf']), (_('Comics'), ['cbz', 'cbr', 'cbc']), (_('Archives'), ['zip', 'rar']), - ]) + ] + to_device = self.stack.currentIndex() != 0 + if to_device: + filters = [(_('Supported books'), self.device_manager.device.FORMATS)] + + books = choose_files(self, 'add books dialog dir', 'Select books', + filters=filters) if not books: return - to_device = self.stack.currentIndex() != 0 self._add_books(books, to_device) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index dce8d73499..411e5ee98b 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -473,7 +473,7 @@ class LibraryDatabase2(LibraryDatabase): def upgrade_version_2(self): ''' Fix Foreign key constraints for deleting from link tables. ''' script = textwrap.dedent('''\ - DROP TRIGGER fkc_delete_books_%(ltable)s_link; + DROP TRIGGER IF EXISTS fkc_delete_books_%(ltable)s_link; CREATE TRIGGER fkc_delete_on_%(table)s BEFORE DELETE ON %(table)s BEGIN diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py index 3bfba86cb2..9281165d5f 100644 --- a/src/calibre/utils/config.py +++ b/src/calibre/utils/config.py @@ -11,7 +11,6 @@ from copy import deepcopy from functools import partial from optparse import OptionParser as _OptionParser from optparse import IndentedHelpFormatter -from PyQt4.QtCore import QString from calibre.constants import terminal_controller, iswindows, isosx, \ __appname__, __version__, __author__, plugins from calibre.utils.lock import LockError, ExclusiveFile @@ -365,6 +364,7 @@ class OptionSet(object): if val is val is True or val is False or val is None or \ isinstance(val, (int, float, long, basestring)): return repr(val) + from PyQt4.QtCore import QString if isinstance(val, QString): return repr(unicode(val)) pickle = cPickle.dumps(val, -1) @@ -722,26 +722,4 @@ def migrate(): p.set('migrated', True) -if __name__ == '__main__': - import subprocess - from PyQt4.Qt import QByteArray - c = Config('test', 'test config') - - c.add_opt('one', ['-1', '--one'], help="This is option #1") - c.set('one', u'345') - - c.add_opt('two', help="This is option #2") - c.set('two', 345) - - c.add_opt('three', help="This is option #3") - c.set('three', QString(u'aflatoon')) - - c.add_opt('four', help="This is option #4") - c.set('four', QByteArray('binary aflatoon')) - - subprocess.call(['pygmentize', os.path.expanduser('~/.config/calibre/test.py')]) - - opts = c.parse() - for i in ('one', 'two', 'three', 'four'): - print i, repr(getattr(opts, i))