diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 47bc4b3185..558f382dca 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -31,6 +31,7 @@ from calibre.ebooks.metadata import title_sort from calibre.ebooks.metadata.book.base import Metadata from calibre.ebooks.metadata.book.json_codec import JsonCodec from calibre.library import current_library_name +from calibre.library.server import server_config as content_server_config from calibre.ptempfile import PersistentTemporaryFile from calibre.utils.ipc import eintr_retry_call from calibre.utils.config import from_json, tweaks @@ -98,9 +99,16 @@ class ConnectionListener (Thread): try: packet = self.driver.broadcast_socket.recvfrom(100) remote = packet[1] + content_server_port = b''; + try : + content_server_port = \ + str(content_server_config().parse().port) + except: + pass message = str(self.driver.ZEROCONF_CLIENT_STRING + b' (on ' + str(socket.gethostname().partition('.')[0]) + - b'),' + str(self.driver.port)) + b');' + content_server_port + + b',' + str(self.driver.port)) self.driver._debug('received broadcast', packet, message) self.driver.broadcast_socket.sendto(message, remote) except: @@ -163,7 +171,9 @@ class SDBook(Book): class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): name = 'SmartDevice App Interface' - gui_name = _('SmartDevice') + gui_name = gui_name_base = _('Wireless Device') + gui_name_template = '%s: %s' + icon = I('devices/galaxy_s3.png') description = _('Communicate with Smart Device apps') supported_platforms = ['windows', 'osx', 'linux'] @@ -321,28 +331,30 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): self.client_can_stream_metadata = False def _debug(self, *args): - if not DEBUG: - return - total_elapsed = time.time() - self.debug_start_time - elapsed = time.time() - self.debug_time - print('SMART_DEV (%7.2f:%7.3f) %s'%(total_elapsed, elapsed, - inspect.stack()[1][3]), end='') - for a in args: - try: - if isinstance(a, dict): - printable = {} - for k,v in a.iteritems(): - if isinstance(v, (str, unicode)) and len(v) > 50: - printable[k] = 'too long' - else: - printable[k] = v - prints('', printable, end='') - else: - prints('', a, end='') - except: - prints('', 'value too long', end='') - print() - self.debug_time = time.time() + # manual synchronization so we don't lose the calling method name + with self.sync_lock: + if not DEBUG: + return + total_elapsed = time.time() - self.debug_start_time + elapsed = time.time() - self.debug_time + print('SMART_DEV (%7.2f:%7.3f) %s'%(total_elapsed, elapsed, + inspect.stack()[1][3]), end='') + for a in args: + try: + if isinstance(a, dict): + printable = {} + for k,v in a.iteritems(): + if isinstance(v, (str, unicode)) and len(v) > 50: + printable[k] = 'too long' + else: + printable[k] = v + prints('', printable, end='') + else: + prints('', a, end='') + except: + prints('', 'value too long', end='') + print() + self.debug_time = time.time() # local utilities @@ -825,6 +837,9 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): self.client_can_receive_book_binary = result.get('canReceiveBookBinary', False) self._debug('Device can receive book binary', self.client_can_stream_metadata) + self.client_device_kind = result.get('deviceKind', '') + self._debug('Client device kind', self.client_device_kind) + self.max_book_packet_len = result.get('maxBookContentPacketLen', self.BASE_PACKET_LEN) self._debug('max_book_packet_len', self.max_book_packet_len) @@ -886,6 +901,12 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): raise return False + def get_gui_name(self): + if self.client_device_kind: + return self.gui_name_template%(self.gui_name, self.client_device_kind) + return self.gui_name + + @synchronous('sync_lock') def get_device_information(self, end_session=True): self._debug() @@ -1035,10 +1056,12 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): def eject(self): self._debug() self._close_device_socket() + self.gui_name = self.gui_name_base @synchronous('sync_lock') def post_yank_cleanup(self): self._debug() + self.gui_name = self.gui_name_base @synchronous('sync_lock') def upload_books(self, files, names, on_card=None, end_session=True, diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index fae2d50f80..393ef876c9 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -608,6 +608,8 @@ class BuiltinApproximateFormats(BuiltinFormatterFunction): def evaluate(self, formatter, kwargs, mi, locals): fmt_data = mi.get('db_approx_formats', []) + if not fmt_data: + return '' data = sorted(fmt_data) return ','.join(v.upper() for v in data)