From 6ba05b0e44f6fb2a52aaae3591b7a78f8bb599f0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 26 Oct 2010 10:52:42 -0600 Subject: [PATCH] Fix auto send of news to device with multiple calibre libraries. The fix means that if you have any pending news to be sent, it will be ignored after the update. Future news downloads will once again be automatically sent to the device. --- src/calibre/gui2/actions/fetch_news.py | 5 ++--- src/calibre/gui2/device.py | 29 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/actions/fetch_news.py b/src/calibre/gui2/actions/fetch_news.py index 98be7cdcb2..5c2a5e9663 100644 --- a/src/calibre/gui2/actions/fetch_news.py +++ b/src/calibre/gui2/actions/fetch_news.py @@ -9,7 +9,6 @@ from PyQt4.Qt import Qt from calibre.gui2 import Dispatcher from calibre.gui2.tools import fetch_scheduled_recipe -from calibre.utils.config import dynamic from calibre.gui2.actions import InterfaceAction class FetchNewsAction(InterfaceAction): @@ -60,9 +59,9 @@ class FetchNewsAction(InterfaceAction): return self.gui.job_exception(job) id = self.gui.library_view.model().add_news(pt.name, arg) self.gui.library_view.model().reset() - sync = dynamic.get('news_to_be_synced', set([])) + sync = self.gui.news_to_be_synced sync.add(id) - dynamic.set('news_to_be_synced', sync) + self.gui.news_to_be_synced = sync self.scheduler.recipe_downloaded(arg) self.gui.status_bar.show_message(arg['title'] + _(' fetched.'), 3000) self.gui.email_news(id) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index e662c6a5cc..663649c192 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -1102,12 +1102,35 @@ class DeviceMixin(object): # {{{ self.status_bar.show_message(_('Sending catalogs to device.'), 5000) + @dynamic_property + def news_to_be_synced(self): + doc = 'Set of ids to be sent to device' + def fget(self): + ans = [] + try: + ans = self.library_view.model().db.prefs.get('news_to_be_synced', + []) + except: + import traceback + traceback.print_exc() + return set(ans) + + def fset(self, ids): + try: + self.library_view.model().db.prefs.set('news_to_be_synced', + list(ids)) + except: + import traceback + traceback.print_exc() + + return property(fget=fget, fset=fset, doc=doc) + 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 = list(self.news_to_be_synced) if send_ids is None else send_ids ids = [id for id in ids if self.library_view.model().db.has_id(id)] files, _auto_ids = self.library_view.model().get_preferred_formats_from_ids( ids, settings.format_map, @@ -1139,7 +1162,7 @@ class DeviceMixin(object): # {{{ for f in files: f.deleted_after_upload = del_on_upload if not files: - dynamic.set('news_to_be_synced', set([])) + self.news_to_be_synced = set([]) return metadata = self.library_view.model().metadata_for(ids) names = [] @@ -1153,7 +1176,7 @@ class DeviceMixin(object): # {{{ if mi.cover and os.access(mi.cover, os.R_OK): mi.thumbnail = self.cover_to_thumbnail(open(mi.cover, 'rb').read()) - dynamic.set('news_to_be_synced', set([])) + self.news_to_be_synced = set([]) if config['upload_news_to_device'] and files: remove = ids if del_on_upload else [] space = { self.location_manager.free[0] : None,