diff --git a/src/calibre/devices/interface.py b/src/calibre/devices/interface.py index 90da55a9db..86d1664271 100644 --- a/src/calibre/devices/interface.py +++ b/src/calibre/devices/interface.py @@ -447,6 +447,15 @@ class DevicePlugin(Plugin): ''' pass + def set_driveinfo_name(self, location_code, name): + ''' + Set the device name in the driveinfo file to 'name'. This setting will + persist until the file is re-created or the name is changed again. + + Non-disk devices will ignore this request. + ''' + pass + class BookList(list): ''' A list of books. Each Book object must have the fields diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index 37785612b5..ef935e239a 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -55,29 +55,33 @@ class USBMS(CLI, Device): METADATA_CACHE = 'metadata.calibre' DRIVEINFO = 'driveinfo.calibre' - def _update_driveinfo_record(self, dinfo, prefix): + def _update_driveinfo_record(self, dinfo, prefix, name=None): if not isinstance(dinfo, dict): dinfo = {} if dinfo.get('device_store_uuid', None) is None: dinfo['device_store_uuid'] = unicode(uuid.uuid4()) + if dinfo.get('device_name') is None: + dinfo['device_name'] = self.get_gui_name() + if name is not None: + dinfo['device_name'] = name dinfo['last_library_uuid'] = getattr(self, 'current_library_uuid', None) dinfo['calibre_version'] = '.'.join([unicode(i) for i in numeric_version]) dinfo['date_last_connected'] = unicode(now()) dinfo['prefix'] = prefix.replace('\\', '/') return dinfo - def _update_driveinfo_file(self, prefix): + def _update_driveinfo_file(self, prefix, name=None): if os.path.exists(os.path.join(prefix, self.DRIVEINFO)): with open(os.path.join(prefix, self.DRIVEINFO), 'rb') as f: try: driveinfo = json.loads(f.read(), object_hook=from_json) except: driveinfo = None - driveinfo = self._update_driveinfo_record(driveinfo, prefix) + driveinfo = self._update_driveinfo_record(driveinfo, prefix, name) with open(os.path.join(prefix, self.DRIVEINFO), 'wb') as f: f.write(json.dumps(driveinfo, default=to_json)) else: - driveinfo = self._update_driveinfo_record({}, prefix) + driveinfo = self._update_driveinfo_record({}, prefix, name) with open(os.path.join(prefix, self.DRIVEINFO), 'wb') as f: f.write(json.dumps(driveinfo, default=to_json)) return driveinfo @@ -93,6 +97,14 @@ class USBMS(CLI, Device): self.driveinfo['B'] = self._update_driveinfo_file(self._card_b_prefix) return (self.get_gui_name(), '', '', '', self.driveinfo) + def set_driveinfo_name(self, location_code, name): + if location_code == 'main': + self._update_driveinfo_file(self._main_prefix, name) + elif location_code == 'A': + self._update_driveinfo_file(self._card_a_prefix, name) + elif location_code == 'B': + self._update_driveinfo_file(self._card_b_prefix, name) + def books(self, oncard=None, end_session=True): from calibre.ebooks.metadata.meta import path_to_ext diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 972e02a6ab..955e287522 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -430,6 +430,10 @@ class DeviceManager(Thread): # {{{ def set_current_library_uuid(self, uuid): self.current_library_uuid = uuid + def set_driveinfo_name(self, location_code, name): + if self.connected_device: + self.connected_device.set_driveinfo_name(location_code, name) + # }}} class DeviceAction(QAction): # {{{