From ee942b95061d709f544f74dc1e2fc08127f72d15 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sat, 16 Apr 2016 13:38:53 +0200 Subject: [PATCH 1/3] Pass the new ID URL patterns to devices while maintaining compatibility with the old interface. --- src/calibre/devices/interface.py | 10 ++++++++++ src/calibre/devices/smart_device_app/driver.py | 5 +++-- src/calibre/gui2/device.py | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/interface.py b/src/calibre/devices/interface.py index 1336e3c782..7229fc3329 100644 --- a/src/calibre/devices/interface.py +++ b/src/calibre/devices/interface.py @@ -597,6 +597,7 @@ class DevicePlugin(Plugin): ''' device_prefs.set_overrides() + # A driver should implement at most one of the set_library_info methods def set_library_info(self, library_name, library_uuid, field_metadata): ''' Implement this method if you want information about the current calibre @@ -605,6 +606,15 @@ class DevicePlugin(Plugin): ''' pass + def set_library_info_extended(self, library_name, library_uuid, field_metadata, other_info): + ''' + Implement this method if you want information about the current calibre + library. This method is called at startup and when the calibre library + changes while connected. The fourth parameter of this method is a dict + of other information, currently containing only the identifier patterns + ''' + pass + # Dynamic control interface. # The following methods are probably called on the GUI thread. Any driver # that implements these methods must take pains to be thread safe, because diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 6bf0504d64..6b8ddd45b8 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -1563,13 +1563,14 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): self.plugboard_func = pb_func @synchronous('sync_lock') - def set_library_info(self, library_name, library_uuid, field_metadata): + def set_library_info_extended(self, library_name, library_uuid, field_metadata, other_info): self._debug(library_name, library_uuid) if self.can_accept_library_info: self._call_client('SET_LIBRARY_INFO', {'libraryName' : library_name, 'libraryUuid': library_uuid, - 'fieldMetadata': field_metadata.all_metadata()}, + 'fieldMetadata': field_metadata.all_metadata(), + 'otherInfo': other_info}, print_debug_info=True) @synchronous('sync_lock') diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 6de4622126..59172554b9 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -477,8 +477,15 @@ class DeviceManager(Thread): # {{{ def _set_library_information(self, library_name, library_uuid, field_metadata): '''Give the device the current library information''' + # Try both the new and the old API. This helps with device drivers that + # are user-installed plugins built around the old Interface class self.device.set_library_info(library_name, library_uuid, field_metadata) + other_info = {} + from calibre.ebooks.metadata.sources.prefs import msprefs + other_info['id_link_rules'] = msprefs.get('id_link_rules', {}) + self.device.set_library_info_extended(library_name, library_uuid, field_metadata, other_info) + def set_library_information(self, done, library_name, library_uuid, field_metadata, add_as_step_to_job=None): '''Give the device the current library information''' From 90e6218e5a8f9c9a24c81eb25cc3b874ff0a1ec6 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 17 Apr 2016 13:13:48 +0200 Subject: [PATCH 2/3] Revert "Pass the new ID URL patterns to devices while maintaining compatibility with the old interface." This reverts commit ee942b95061d709f544f74dc1e2fc08127f72d15. --- src/calibre/devices/interface.py | 10 ---------- src/calibre/devices/smart_device_app/driver.py | 5 ++--- src/calibre/gui2/device.py | 7 ------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/calibre/devices/interface.py b/src/calibre/devices/interface.py index 7229fc3329..1336e3c782 100644 --- a/src/calibre/devices/interface.py +++ b/src/calibre/devices/interface.py @@ -597,7 +597,6 @@ class DevicePlugin(Plugin): ''' device_prefs.set_overrides() - # A driver should implement at most one of the set_library_info methods def set_library_info(self, library_name, library_uuid, field_metadata): ''' Implement this method if you want information about the current calibre @@ -606,15 +605,6 @@ class DevicePlugin(Plugin): ''' pass - def set_library_info_extended(self, library_name, library_uuid, field_metadata, other_info): - ''' - Implement this method if you want information about the current calibre - library. This method is called at startup and when the calibre library - changes while connected. The fourth parameter of this method is a dict - of other information, currently containing only the identifier patterns - ''' - pass - # Dynamic control interface. # The following methods are probably called on the GUI thread. Any driver # that implements these methods must take pains to be thread safe, because diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 6b8ddd45b8..6bf0504d64 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -1563,14 +1563,13 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): self.plugboard_func = pb_func @synchronous('sync_lock') - def set_library_info_extended(self, library_name, library_uuid, field_metadata, other_info): + def set_library_info(self, library_name, library_uuid, field_metadata): self._debug(library_name, library_uuid) if self.can_accept_library_info: self._call_client('SET_LIBRARY_INFO', {'libraryName' : library_name, 'libraryUuid': library_uuid, - 'fieldMetadata': field_metadata.all_metadata(), - 'otherInfo': other_info}, + 'fieldMetadata': field_metadata.all_metadata()}, print_debug_info=True) @synchronous('sync_lock') diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 59172554b9..6de4622126 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -477,15 +477,8 @@ class DeviceManager(Thread): # {{{ def _set_library_information(self, library_name, library_uuid, field_metadata): '''Give the device the current library information''' - # Try both the new and the old API. This helps with device drivers that - # are user-installed plugins built around the old Interface class self.device.set_library_info(library_name, library_uuid, field_metadata) - other_info = {} - from calibre.ebooks.metadata.sources.prefs import msprefs - other_info['id_link_rules'] = msprefs.get('id_link_rules', {}) - self.device.set_library_info_extended(library_name, library_uuid, field_metadata, other_info) - def set_library_information(self, done, library_name, library_uuid, field_metadata, add_as_step_to_job=None): '''Give the device the current library information''' From ae0f52d7c9a1ad9d12c8c8a21e5c97e52a169ac9 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 17 Apr 2016 13:21:30 +0200 Subject: [PATCH 3/3] Don't change the API. Instead do the work in the wireless driver --- src/calibre/devices/smart_device_app/driver.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 6bf0504d64..b8025c6bfe 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -1566,10 +1566,15 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): def set_library_info(self, library_name, library_uuid, field_metadata): self._debug(library_name, library_uuid) if self.can_accept_library_info: + other_info = {} + from calibre.ebooks.metadata.sources.prefs import msprefs + other_info['id_link_rules'] = msprefs.get('id_link_rules', {}) + self._call_client('SET_LIBRARY_INFO', {'libraryName' : library_name, 'libraryUuid': library_uuid, - 'fieldMetadata': field_metadata.all_metadata()}, + 'fieldMetadata': field_metadata.all_metadata(), + 'otherInfo': other_info}, print_debug_info=True) @synchronous('sync_lock')