mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
0f187dfed3
@ -648,6 +648,14 @@ class DevicePlugin(Plugin):
|
||||
'''
|
||||
device_prefs.set_overrides()
|
||||
|
||||
def set_library_info(self, library_name, library_uuid, field_metadata):
|
||||
'''
|
||||
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.
|
||||
'''
|
||||
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
|
||||
|
@ -244,6 +244,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
'OK' : 0,
|
||||
'BOOK_DONE' : 11,
|
||||
'CALIBRE_BUSY' : 18,
|
||||
'SET_LIBRARY_INFO' : 19,
|
||||
'DELETE_BOOK' : 13,
|
||||
'DISPLAY_MESSAGE' : 17,
|
||||
'FREE_SPACE' : 5,
|
||||
@ -1040,6 +1041,8 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
self._debug('Cache uses lpaths', self.client_cache_uses_lpaths)
|
||||
self.can_send_ok_to_sendbook = result.get('canSendOkToSendbook', False)
|
||||
self._debug('Can send OK to sendbook', self.can_send_ok_to_sendbook)
|
||||
self.can_accept_library_info = result.get('canAcceptLibraryInfo', False)
|
||||
self._debug('Can accept library info', self.can_accept_library_info)
|
||||
|
||||
if not self.settings().extra_customization[self.OPT_USE_METADATA_CACHE]:
|
||||
self.client_can_use_metadata_cache = False
|
||||
@ -1512,6 +1515,16 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
self.plugboards = plugboards
|
||||
self.plugboard_func = pb_func
|
||||
|
||||
@synchronous('sync_lock')
|
||||
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()},
|
||||
print_debug_info=True)
|
||||
|
||||
@synchronous('sync_lock')
|
||||
def specialize_global_preferences(self, device_prefs):
|
||||
device_prefs.set_overrides(manage_device_metadata='on_connect')
|
||||
|
@ -473,6 +473,17 @@ class DeviceManager(Thread): # {{{
|
||||
return self.create_job_step(self._get_device_information, done,
|
||||
description=_('Get device information'), to_job=add_as_step_to_job)
|
||||
|
||||
def _set_library_information(self, library_name, library_uuid, field_metadata):
|
||||
'''Give the device the current library information'''
|
||||
self.device.set_library_info(library_name, library_uuid, field_metadata)
|
||||
|
||||
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'''
|
||||
return self.create_job_step(self._set_library_information, done,
|
||||
args=[library_name, library_uuid, field_metadata],
|
||||
description=_('Set library information'), to_job=add_as_step_to_job)
|
||||
|
||||
def slow_driveinfo(self):
|
||||
''' Update the stored device information with the driveinfo if the
|
||||
device indicates that getting driveinfo is slow '''
|
||||
@ -1081,6 +1092,10 @@ class DeviceMixin(object): # {{{
|
||||
self.device_manager.device.icon)
|
||||
self.bars_manager.update_bars()
|
||||
self.status_bar.device_connected(info[0])
|
||||
db = self.current_db
|
||||
self.device_manager.set_library_information(None, os.path.basename(db.library_path),
|
||||
db.library_id, db.field_metadata,
|
||||
add_as_step_to_job=job)
|
||||
self.device_manager.books(FunctionDispatcher(self.metadata_downloaded),
|
||||
add_as_step_to_job=job)
|
||||
|
||||
@ -1638,6 +1653,12 @@ class DeviceMixin(object): # {{{
|
||||
self.set_books_in_library(self.booklists(), reset=True, force_send=True)
|
||||
self.refresh_ondevice()
|
||||
|
||||
def set_current_library_information(self, library_name, library_uuid, field_metadata):
|
||||
self.device_manager.set_current_library_uuid(library_uuid)
|
||||
if self.device_manager.is_device_connected:
|
||||
self.device_manager.set_library_information(None, library_name,
|
||||
library_uuid, field_metadata)
|
||||
|
||||
def book_on_device(self, id, reset=False):
|
||||
'''
|
||||
Return an indication of whether the given book represented by its db id
|
||||
@ -1815,9 +1836,8 @@ class DeviceMixin(object): # {{{
|
||||
# Why every tenth book? WAG balancing performance in the
|
||||
# loop with preventing App Not Responding errors
|
||||
if current_book_count % 10 == 0:
|
||||
QCoreApplication.processEvents(flags=
|
||||
QEventLoop.ExcludeUserInputEvents|
|
||||
QEventLoop.ExcludeSocketNotifiers)
|
||||
QCoreApplication.processEvents(
|
||||
flags=QEventLoop.ExcludeUserInputEvents|QEventLoop.ExcludeSocketNotifiers)
|
||||
current_book_count += 1
|
||||
book.in_library = None
|
||||
if getattr(book, 'uuid', None) in self.db_book_uuid_cache:
|
||||
|
@ -47,6 +47,7 @@ from calibre.gui2.auto_add import AutoAdder
|
||||
from calibre.gui2.proceed import ProceedQuestion
|
||||
from calibre.gui2.dialogs.message_box import JobError
|
||||
from calibre.gui2.job_indicator import Pointer
|
||||
from calibre.library import current_library_name
|
||||
|
||||
class Listener(Thread): # {{{
|
||||
|
||||
@ -419,7 +420,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
||||
traceback.print_exc()
|
||||
if ac.plugin_path is None:
|
||||
raise
|
||||
self.device_manager.set_current_library_uuid(db.library_id)
|
||||
self.set_current_library_information(current_library_name(), db.library_id,
|
||||
db.field_metadata)
|
||||
|
||||
self.keyboard.finalize()
|
||||
self.auto_adder = AutoAdder(gprefs['auto_add_path'], self)
|
||||
@ -693,7 +695,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
||||
self.memory_view.reset()
|
||||
self.card_a_view.reset()
|
||||
self.card_b_view.reset()
|
||||
self.device_manager.set_current_library_uuid(db.library_id)
|
||||
self.set_current_library_information(current_library_name(), db.library_id,
|
||||
db.field_metadata)
|
||||
self.library_view.set_current_row(0)
|
||||
# Run a garbage collection now so that it does not freeze the
|
||||
# interface later
|
||||
|
Loading…
x
Reference in New Issue
Block a user