diff --git a/src/calibre/devices/interface.py b/src/calibre/devices/interface.py index 2d82bf4563..da8a2cb978 100644 --- a/src/calibre/devices/interface.py +++ b/src/calibre/devices/interface.py @@ -289,7 +289,10 @@ class DevicePlugin(Plugin): word "card" if C{on_card} is not None otherwise it must contain the word "memory". :files: A list of paths and/or file-like objects. If they are paths and the paths point to temporary files, they may have an additional - attribute, original_file_path pointing to the originals. + attribute, original_file_path pointing to the originals. They may have + another optional attribute, deleted_after_upload which if True means + that the file pointed to by original_file_path will be deleted after + being uploaded to the device. :names: A list of file names that the books should have once uploaded to the device. len(names) == len(files) :return: A list of 3-element tuples. The list is meant to be passed diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 378c585efb..1445b0f36e 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -599,7 +599,10 @@ class Emailer(Thread): # {{{ # }}} -class DeviceGUI(object): +class DeviceMixin(object): + + def __init__(self): + self.db_book_uuid_cache = set() def dispatch_sync_event(self, dest, delete, specific): rows = self.library_view.selectionModel().selectedRows() @@ -851,6 +854,7 @@ class DeviceGUI(object): def sync_news(self, send_ids=None, do_auto_convert=True): if self.device_connected: + del_on_upload = config['delete_news_from_library_on_upload'] settings = self.device_manager.device.settings() ids = list(dynamic.get('news_to_be_synced', set([]))) if send_ids is None else send_ids ids = [id for id in ids if self.library_view.model().db.has_id(id)] @@ -880,6 +884,8 @@ class DeviceGUI(object): 'the device?'), det_msg=autos): self.auto_convert_news(auto, format) files = [f for f in files if f is not None] + for f in files: + f.deleted_after_upload = del_on_upload if not files: dynamic.set('news_to_be_synced', set([])) return @@ -897,8 +903,7 @@ class DeviceGUI(object): 'rb').read()) dynamic.set('news_to_be_synced', set([])) if config['upload_news_to_device'] and files: - remove = ids if \ - config['delete_news_from_library_on_upload'] else [] + remove = ids if del_on_upload else [] space = { self.location_view.model().free[0] : None, self.location_view.model().free[1] : 'carda', self.location_view.model().free[2] : 'cardb' } diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 99516ce677..293a522a9e 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -39,6 +39,7 @@ class FormatPath(unicode): def __new__(cls, path, orig_file_path): ans = unicode.__new__(cls, path) ans.orig_file_path = orig_file_path + ans.deleted_after_upload = False return ans class BooksModel(QAbstractTableModel): # {{{ diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 54ef0f9f60..b342728ff4 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -44,7 +44,7 @@ from calibre.gui2.dialogs.scheduler import Scheduler from calibre.gui2.update import CheckForUpdates from calibre.gui2.main_window import MainWindow from calibre.gui2.main_ui import Ui_MainWindow -from calibre.gui2.device import DeviceManager, DeviceMenu, DeviceGUI, Emailer +from calibre.gui2.device import DeviceManager, DeviceMenu, DeviceMixin, Emailer from calibre.gui2.jobs import JobManager, JobsDialog, JobsButton from calibre.gui2.dialogs.metadata_single import MetadataSingleDialog from calibre.gui2.dialogs.metadata_bulk import MetadataBulkDialog @@ -105,7 +105,7 @@ class SystemTrayIcon(QSystemTrayIcon): # {{{ # }}} -class Main(MainWindow, Ui_MainWindow, DeviceGUI, ToolbarMixin, +class Main(MainWindow, Ui_MainWindow, DeviceMixin, ToolbarMixin, TagBrowserMixin, CoverFlowMixin, LibraryViewMixin): 'The main GUI' @@ -228,6 +228,8 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI, ToolbarMixin, QObject.connect(self.advanced_search_button, SIGNAL('clicked(bool)'), self.do_advanced_search) + DeviceMixin.__init__(self) + ####################### Start spare job server ######################## QTimer.singleShot(1000, self.add_spare_server) diff --git a/src/calibre/linux.py b/src/calibre/linux.py index 26bbe0837b..51711b5b0f 100644 --- a/src/calibre/linux.py +++ b/src/calibre/linux.py @@ -411,7 +411,8 @@ def options(option_parser): def opts_and_words(name, op, words): opts = '|'.join(options(op)) words = '|'.join([w.replace("'", "\\'") for w in words]) - return ('_'+name+'()'+\ + fname = name.replace('-', '_') + return ('_'+fname+'()'+\ ''' { local cur opts @@ -435,7 +436,7 @@ def opts_and_words(name, op, words): esac } -complete -F _'''%(opts, words) + name + ' ' + name +"\n\n").encode('utf-8') +complete -F _'''%(opts, words) + fname + ' ' + name +"\n\n").encode('utf-8') def opts_and_exts(name, op, exts):