mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Changes to device plugboard architecture
This commit is contained in:
parent
ddcde43f2c
commit
6f8197ecfa
@ -21,6 +21,7 @@ class FOLDER_DEVICE_FOR_CONFIG(USBMS):
|
|||||||
VENDOR_ID = 0xffff
|
VENDOR_ID = 0xffff
|
||||||
PRODUCT_ID = 0xffff
|
PRODUCT_ID = 0xffff
|
||||||
BCD = 0xffff
|
BCD = 0xffff
|
||||||
|
DEVICE_PLUGBOARD_NAME = 'FOLDER_DEVICE'
|
||||||
|
|
||||||
|
|
||||||
class FOLDER_DEVICE(USBMS):
|
class FOLDER_DEVICE(USBMS):
|
||||||
@ -36,6 +37,7 @@ class FOLDER_DEVICE(USBMS):
|
|||||||
VENDOR_ID = 0xffff
|
VENDOR_ID = 0xffff
|
||||||
PRODUCT_ID = 0xffff
|
PRODUCT_ID = 0xffff
|
||||||
BCD = 0xffff
|
BCD = 0xffff
|
||||||
|
DEVICE_PLUGBOARD_NAME = 'FOLDER_DEVICE'
|
||||||
|
|
||||||
THUMBNAIL_HEIGHT = 68 # Height for thumbnails on device
|
THUMBNAIL_HEIGHT = 68 # Height for thumbnails on device
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ class PRS505(USBMS):
|
|||||||
EXTRA_CUSTOMIZATION_DEFAULT = ', '.join(['series', 'tags'])
|
EXTRA_CUSTOMIZATION_DEFAULT = ', '.join(['series', 'tags'])
|
||||||
|
|
||||||
plugboard = None
|
plugboard = None
|
||||||
|
plugboard_func = None
|
||||||
|
|
||||||
def windows_filter_pnp_id(self, pnp_id):
|
def windows_filter_pnp_id(self, pnp_id):
|
||||||
return '_LAUNCHER' in pnp_id
|
return '_LAUNCHER' in pnp_id
|
||||||
@ -152,7 +153,12 @@ class PRS505(USBMS):
|
|||||||
else:
|
else:
|
||||||
collections = []
|
collections = []
|
||||||
debug_print('PRS505: collection fields:', collections)
|
debug_print('PRS505: collection fields:', collections)
|
||||||
c.update(blists, collections, self.plugboard)
|
pb = None
|
||||||
|
if self.plugboard_func:
|
||||||
|
pb = self.plugboard_func(self.__class__.__name__,
|
||||||
|
'device_db', self.plugboards)
|
||||||
|
debug_print('PRS505: use plugboards', pb)
|
||||||
|
c.update(blists, collections, pb)
|
||||||
c.write()
|
c.write()
|
||||||
|
|
||||||
USBMS.sync_booklists(self, booklists, end_session=end_session)
|
USBMS.sync_booklists(self, booklists, end_session=end_session)
|
||||||
@ -165,9 +171,6 @@ class PRS505(USBMS):
|
|||||||
c.write()
|
c.write()
|
||||||
debug_print('PRS505: finished rebuild_collections')
|
debug_print('PRS505: finished rebuild_collections')
|
||||||
|
|
||||||
def use_plugboard_ext(self):
|
def set_plugboards(self, plugboards, pb_func):
|
||||||
return 'device_db'
|
self.plugboards = plugboards
|
||||||
|
self.plugboard_func = pb_func
|
||||||
def set_plugboard(self, pb):
|
|
||||||
debug_print('PRS505: use plugboard', pb)
|
|
||||||
self.plugboard = pb
|
|
||||||
|
@ -104,6 +104,28 @@ class DeviceJob(BaseJob): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
def find_plugboard(device_name, format, plugboards):
|
||||||
|
cpb = None
|
||||||
|
if format in plugboards:
|
||||||
|
cpb = plugboards[format]
|
||||||
|
elif plugboard_any_format_value in plugboards:
|
||||||
|
cpb = plugboards[plugboard_any_format_value]
|
||||||
|
if cpb is not None:
|
||||||
|
if device_name in cpb:
|
||||||
|
cpb = cpb[device_name]
|
||||||
|
elif plugboard_any_device_value in cpb:
|
||||||
|
cpb = cpb[plugboard_any_device_value]
|
||||||
|
else:
|
||||||
|
cpb = None
|
||||||
|
if DEBUG:
|
||||||
|
prints('Device using plugboard', format, device_name, cpb)
|
||||||
|
return cpb
|
||||||
|
|
||||||
|
def device_name_for_plugboards(device_class):
|
||||||
|
if hasattr(device_class, 'DEVICE_PLUGBOARD_NAME'):
|
||||||
|
return device_class.DEVICE_PLUGBOARD_NAME
|
||||||
|
return device_class.__class__.__name__
|
||||||
|
|
||||||
class DeviceManager(Thread): # {{{
|
class DeviceManager(Thread): # {{{
|
||||||
|
|
||||||
def __init__(self, connected_slot, job_manager, open_feedback_slot, sleep_time=2):
|
def __init__(self, connected_slot, job_manager, open_feedback_slot, sleep_time=2):
|
||||||
@ -311,12 +333,9 @@ class DeviceManager(Thread): # {{{
|
|||||||
return self.device.card_prefix(end_session=False), self.device.free_space()
|
return self.device.card_prefix(end_session=False), self.device.free_space()
|
||||||
|
|
||||||
def sync_booklists(self, done, booklists, plugboards):
|
def sync_booklists(self, done, booklists, plugboards):
|
||||||
if hasattr(self.connected_device, 'use_plugboard_ext') and \
|
if hasattr(self.connected_device, 'set_plugboards') and \
|
||||||
callable(self.connected_device.use_plugboard_ext):
|
callable(self.connected_device.set_plugboards):
|
||||||
ext = self.connected_device.use_plugboard_ext()
|
self.connected_device.set_plugboards(plugboards, find_plugboard)
|
||||||
if ext is not None:
|
|
||||||
self.connected_device.set_plugboard(
|
|
||||||
self.find_plugboard(ext, plugboards))
|
|
||||||
return self.create_job(self._sync_booklists, done, args=[booklists],
|
return self.create_job(self._sync_booklists, done, args=[booklists],
|
||||||
description=_('Send metadata to device'))
|
description=_('Send metadata to device'))
|
||||||
|
|
||||||
@ -325,37 +344,18 @@ class DeviceManager(Thread): # {{{
|
|||||||
args=[booklist, on_card],
|
args=[booklist, on_card],
|
||||||
description=_('Send collections to device'))
|
description=_('Send collections to device'))
|
||||||
|
|
||||||
def find_plugboard(self, ext, plugboards):
|
|
||||||
dev_name = self.connected_device.__class__.__name__
|
|
||||||
cpb = None
|
|
||||||
if ext in plugboards:
|
|
||||||
cpb = plugboards[ext]
|
|
||||||
elif plugboard_any_format_value in plugboards:
|
|
||||||
cpb = plugboards[plugboard_any_format_value]
|
|
||||||
if cpb is not None:
|
|
||||||
if dev_name in cpb:
|
|
||||||
cpb = cpb[dev_name]
|
|
||||||
elif plugboard_any_device_value in cpb:
|
|
||||||
cpb = cpb[plugboard_any_device_value]
|
|
||||||
else:
|
|
||||||
cpb = None
|
|
||||||
if DEBUG:
|
|
||||||
prints('Device using plugboard', ext, dev_name, cpb)
|
|
||||||
return cpb
|
|
||||||
|
|
||||||
def _upload_books(self, files, names, on_card=None, metadata=None, plugboards=None):
|
def _upload_books(self, files, names, on_card=None, metadata=None, plugboards=None):
|
||||||
'''Upload books to device: '''
|
'''Upload books to device: '''
|
||||||
if hasattr(self.connected_device, 'use_plugboard_ext') and \
|
if hasattr(self.connected_device, 'set_plugboards') and \
|
||||||
callable(self.connected_device.use_plugboard_ext):
|
callable(self.connected_device.set_plugboards):
|
||||||
ext = self.connected_device.use_plugboard_ext()
|
self.connected_device.set_plugboards(plugboards, find_plugboard)
|
||||||
if ext is not None:
|
|
||||||
self.connected_device.set_plugboard(
|
|
||||||
self.find_plugboard(ext, plugboards))
|
|
||||||
if metadata and files and len(metadata) == len(files):
|
if metadata and files and len(metadata) == len(files):
|
||||||
for f, mi in zip(files, metadata):
|
for f, mi in zip(files, metadata):
|
||||||
if isinstance(f, unicode):
|
if isinstance(f, unicode):
|
||||||
ext = f.rpartition('.')[-1].lower()
|
ext = f.rpartition('.')[-1].lower()
|
||||||
cpb = self.find_plugboard(ext, plugboards)
|
cpb = find_plugboard(
|
||||||
|
device_name_for_plugboards(self.connected_device),
|
||||||
|
ext, plugboards)
|
||||||
if ext:
|
if ext:
|
||||||
try:
|
try:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
@ -9,6 +9,7 @@ from PyQt4 import QtGui
|
|||||||
from PyQt4.Qt import Qt
|
from PyQt4.Qt import Qt
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
|
from calibre.gui2.device import device_name_for_plugboards
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||||
from calibre.gui2.preferences.plugboard_ui import Ui_Form
|
from calibre.gui2.preferences.plugboard_ui import Ui_Form
|
||||||
from calibre.customize.ui import metadata_writers, device_plugins
|
from calibre.customize.ui import metadata_writers, device_plugins
|
||||||
@ -47,10 +48,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
|
|
||||||
self.devices = ['']
|
self.devices = ['']
|
||||||
for device in device_plugins():
|
for device in device_plugins():
|
||||||
n = device.__class__.__name__
|
n = device_name_for_plugboards(device)
|
||||||
if n.startswith('FOLDER_DEVICE'):
|
if n not in self.devices:
|
||||||
n = 'FOLDER_DEVICE'
|
self.devices.append(n)
|
||||||
self.devices.append(n)
|
|
||||||
self.devices.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
|
self.devices.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
|
||||||
self.devices.insert(1, plugboard_save_to_disk_value)
|
self.devices.insert(1, plugboard_save_to_disk_value)
|
||||||
self.devices.insert(2, plugboard_any_device_value)
|
self.devices.insert(2, plugboard_any_device_value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user