diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py
index 42d0f3c863..6394626a9f 100644
--- a/src/calibre/devices/usbms/books.py
+++ b/src/calibre/devices/usbms/books.py
@@ -132,6 +132,8 @@ class CollectionsBookList(BookList):
return True
def get_collections(self, collection_attributes):
+ from calibre.devices.usbms.driver import debug_print
+ debug_print('Starting get_collections:', prefs['manage_device_metadata'])
collections = {}
series_categories = set([])
# This map of sets is used to avoid linear searches when testing for
@@ -146,14 +148,19 @@ class CollectionsBookList(BookList):
# book in all existing collections. Do not add any new ones.
attrs = ['device_collections']
if getattr(book, '_new_book', False):
- if prefs['preserve_user_collections']:
+ if prefs['manage_device_metadata'] == 'manual':
# Ensure that the book is in all the book's existing
# collections plus all metadata collections
attrs += collection_attributes
else:
- # The book's existing collections are ignored. Put the book
- # in collections defined by its metadata.
+ # For new books, both 'on_send' and 'on_connect' do the same
+ # thing. The book's existing collections are ignored. Put
+ # the book in collections defined by its metadata.
attrs = collection_attributes
+ elif prefs['manage_device_metadata'] == 'on_connect':
+ # For existing books, modify the collections only if the user
+ # specified 'on_connect'
+ attrs = collection_attributes
for attr in attrs:
attr = attr.strip()
val = getattr(book, attr, None)
diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py
index 377ec36c16..1a088cc77c 100644
--- a/src/calibre/devices/usbms/driver.py
+++ b/src/calibre/devices/usbms/driver.py
@@ -58,7 +58,7 @@ class USBMS(CLI, Device):
debug_print ('USBMS: Fetching list of books from device. oncard=', oncard)
- dummy_bl = BookList(None, None, None)
+ dummy_bl = booklist_class(None, None, None)
if oncard == 'carda' and not self._card_a_prefix:
self.report_progress(1.0, _('Getting list of books on device...'))
diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py
index 4acde6089b..d976fad128 100644
--- a/src/calibre/gui2/device.py
+++ b/src/calibre/gui2/device.py
@@ -33,6 +33,7 @@ from calibre.devices.apple.driver import ITUNES_ASYNC
from calibre.devices.folder_device.driver import FOLDER_DEVICE
from calibre.ebooks.metadata.meta import set_metadata
from calibre.constants import DEBUG
+from calibre.utils.config import prefs
# }}}
@@ -1425,19 +1426,24 @@ class DeviceMixin(object): # {{{
aus = re.sub('(?u)\W|[_]', '', aus)
self.db_book_title_cache[title]['author_sort'][aus] = mi
self.db_book_title_cache[title]['db_ids'][mi.application_id] = mi
- self.db_book_uuid_cache[mi.uuid] = mi.application_id
+ self.db_book_uuid_cache[mi.uuid] = mi
# Now iterate through all the books on the device, setting the
# in_library field Fastest and most accurate key is the uuid. Second is
# the application_id, which is really the db key, but as this can
# accidentally match across libraries we also verify the title. The
# db_id exists on Sony devices. Fallback is title and author match
+
+ update_metadata = prefs['manage_device_metadata'] == 'on_connect'
for booklist in booklists:
for book in booklist:
if getattr(book, 'uuid', None) in self.db_book_uuid_cache:
+ if update_metadata:
+ book.smart_update(self.db_book_uuid_cache[book.uuid])
book.in_library = True
# ensure that the correct application_id is set
- book.application_id = self.db_book_uuid_cache[book.uuid]
+ book.application_id = \
+ self.db_book_uuid_cache[book.uuid].application_id
continue
book_title = book.title.lower() if book.title else ''
@@ -1447,11 +1453,13 @@ class DeviceMixin(object): # {{{
if d is not None:
if getattr(book, 'application_id', None) in d['db_ids']:
book.in_library = True
- book.smart_update(d['db_ids'][book.application_id])
+ if update_metadata:
+ book.smart_update(d['db_ids'][book.application_id])
continue
if book.db_id in d['db_ids']:
book.in_library = True
- book.smart_update(d['db_ids'][book.db_id])
+ if update_metadata:
+ book.smart_update(d['db_ids'][book.db_id])
continue
if book.authors:
# Compare against both author and author sort, because
@@ -1460,14 +1468,19 @@ class DeviceMixin(object): # {{{
book_authors = re.sub('(?u)\W|[_]', '', book_authors)
if book_authors in d['authors']:
book.in_library = True
- book.smart_update(d['authors'][book_authors])
+ if update_metadata:
+ book.smart_update(d['authors'][book_authors])
elif book_authors in d['author_sort']:
book.in_library = True
- book.smart_update(d['author_sort'][book_authors])
+ if update_metadata:
+ book.smart_update(d['author_sort'][book_authors])
# Set author_sort if it isn't already
asort = getattr(book, 'author_sort', None)
if not asort and book.authors:
book.author_sort = self.library_view.model().db.author_sort_from_authors(book.authors)
+ if update_metadata:
+ if self.device_manager.is_device_connected:
+ self.device_manager.sync_booklists(None, booklists)
# }}}
diff --git a/src/calibre/gui2/dialogs/config/add_save.py b/src/calibre/gui2/dialogs/config/add_save.py
index b1f5621f44..8eb6cf7bd0 100644
--- a/src/calibre/gui2/dialogs/config/add_save.py
+++ b/src/calibre/gui2/dialogs/config/add_save.py
@@ -45,7 +45,12 @@ class AddSave(QTabWidget, Ui_TabWidget):
self.metadata_box.layout().insertWidget(0, self.filename_pattern)
self.opt_swap_author_names.setChecked(prefs['swap_author_names'])
self.opt_add_formats_to_existing.setChecked(prefs['add_formats_to_existing'])
- self.preserve_user_collections.setChecked(prefs['preserve_user_collections'])
+ if prefs['manage_device_metadata'] == 'manual':
+ self.manage_device_metadata.setCurrentIndex(0)
+ elif prefs['manage_device_metadata'] == 'on_send':
+ self.manage_device_metadata.setCurrentIndex(1)
+ else:
+ self.manage_device_metadata.setCurrentIndex(2)
help = '\n'.join(textwrap.wrap(c.get_option('template').help, 75))
self.save_template.initialize('save_to_disk', opts.template, help)
self.send_template.initialize('send_to_device', opts.send_template, help)
@@ -72,12 +77,14 @@ class AddSave(QTabWidget, Ui_TabWidget):
prefs['filename_pattern'] = pattern
prefs['swap_author_names'] = bool(self.opt_swap_author_names.isChecked())
prefs['add_formats_to_existing'] = bool(self.opt_add_formats_to_existing.isChecked())
- prefs['preserve_user_collections'] = bool(self.preserve_user_collections.isChecked())
-
+ if self.manage_device_metadata.currentIndex() == 0:
+ prefs['manage_device_metadata'] = 'manual'
+ elif self.manage_device_metadata.currentIndex() == 1:
+ prefs['manage_device_metadata'] = 'on_send'
+ else:
+ prefs['manage_device_metadata'] = 'on_connect'
return True
-
-
if __name__ == '__main__':
from PyQt4.Qt import QApplication
app=QApplication([])
diff --git a/src/calibre/gui2/dialogs/config/add_save.ui b/src/calibre/gui2/dialogs/config/add_save.ui
index 64a8137aa1..35824ef847 100644
--- a/src/calibre/gui2/dialogs/config/add_save.ui
+++ b/src/calibre/gui2/dialogs/config/add_save.ui
@@ -14,7 +14,7 @@
TabWidget
- 0
+ 2
@@ -179,16 +179,34 @@ Title match ignores leading indefinite articles ("the", "a",
-
-
-
- Preserve device collections.
-
+
+
-
+
+ Manual management. Calibre updates cached metadata and adds collections, but never removes them
+
+
+ -
+
+ Calibre manages metadata when sending books. Calibre updates cached metadata, and adds/remove collections
+
+
+ -
+
+ Calibre manages metadata at device connection. Calibre updates cached metadata, and adds/removes collections
+
+
-
- If checked, collections will not be deleted even if a book with changed metadata is resent and the collection is not in the book's metadata. In addition, editing collections in the device view will be enabled. If unchecked, collections will be always reflect only the metadata in the calibre library.
+ Choose 'Manual Management', to have Calibre update the metadata cache (not the book) and add collections when a book is sent. With this option, calibre will never remove a collection. Choose 'Calibre manages metadata when sending books' to have Calibre update the metadata cache and add/remove collections when you send a book to the device. Choose 'Calibre manages metadata when device is connected' to have Calibre update the metadata cache and add/remove collections when you connect the device.
+
+
+ Qt::PlainText
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
true
@@ -198,7 +216,7 @@ Title match ignores leading indefinite articles ("the", "a",
-
-
+
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index 7ffbc42f02..147aa1188d 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -939,7 +939,7 @@ class DeviceBooksModel(BooksModel): # {{{
(cname == 'collections' and \
callable(getattr(self.db, 'supports_collections', None)) and \
self.db.supports_collections() and \
- prefs['preserve_user_collections']):
+ prefs['manage_device_metadata']=='manual'):
flags |= Qt.ItemIsEditable
return flags
diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py
index 9d85dce075..c6c32f86f7 100644
--- a/src/calibre/gui2/library/views.py
+++ b/src/calibre/gui2/library/views.py
@@ -503,7 +503,7 @@ class DeviceBooksView(BooksView): # {{{
self.edit_collections_menu.setVisible(
callable(getattr(self._model.db, 'supports_collections', None)) and \
self._model.db.supports_collections() and \
- prefs['preserve_user_collections'])
+ prefs['manage_device_metadata'] == 'manual')
self.context_menu.popup(event.globalPos())
event.accept()
diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py
index f24a6d2e30..5c4bd55644 100644
--- a/src/calibre/utils/config.py
+++ b/src/calibre/utils/config.py
@@ -698,8 +698,8 @@ def _prefs():
# calibre server can execute searches
c.add_opt('saved_searches', default={}, help=_('List of named saved searches'))
c.add_opt('user_categories', default={}, help=_('User-created tag browser categories'))
- c.add_opt('preserve_user_collections', default=True,
- help=_('Preserve all collections even if not in library metadata.'))
+ c.add_opt('manage_device_metadata', default='manual',
+ help=_('How and when calibre updates metadata on the device.'))
c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.')
return c