From c87508d20e22bc37a74f2b248eaf59d4f7add49c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 24 Sep 2012 10:25:55 +0530 Subject: [PATCH] MTP: Add a way to get device info in the GUI easily --- src/calibre/devices/mtp/unix/driver.py | 13 +++++++ src/calibre/devices/mtp/windows/driver.py | 6 ++++ src/calibre/gui2/device_drivers/mtp_config.py | 35 ++++++++++++++++--- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/calibre/devices/mtp/unix/driver.py b/src/calibre/devices/mtp/unix/driver.py index 599304e851..760113c366 100644 --- a/src/calibre/devices/mtp/unix/driver.py +++ b/src/calibre/devices/mtp/unix/driver.py @@ -196,6 +196,19 @@ class MTP_DEVICE(MTPDeviceBase): self.current_serial_num = snum self.currently_connected_dev = connected_device + @synchronous + def device_debug_info(self): + ans = self.get_gui_name() + ans += '\nSerial number: %s'%self.current_serial_num + ans += '\nManufacturer: %s'%self.dev.manufacturer_name + ans += '\nModel: %s'%self.dev.model_name + ans += '\nids: %s'%(self.dev.ids,) + ans += '\nDevice version: %s'%self.dev.device_version + ans += '\nStorage:\n' + storage = sorted(self.dev.storage_info, key=operator.itemgetter('id')) + ans += pprint.pformat(storage) + return ans + @property def filesystem_cache(self): if self._filesystem_cache is None: diff --git a/src/calibre/devices/mtp/windows/driver.py b/src/calibre/devices/mtp/windows/driver.py index e349ddf5e0..202c8dfd6e 100644 --- a/src/calibre/devices/mtp/windows/driver.py +++ b/src/calibre/devices/mtp/windows/driver.py @@ -52,6 +52,7 @@ class MTP_DEVICE(MTPDeviceBase): self.start_thread = None self._filesystem_cache = None self.eject_dev_on_next_scan = False + self.current_device_data = {} def startup(self): self.start_thread = threading.current_thread() @@ -303,6 +304,11 @@ class MTP_DEVICE(MTPDeviceBase): _('Unknown MTP device')) self.currently_connected_pnp_id = connected_device self.current_serial_num = snum + self.current_device_data = devdata.copy() + + def device_debug_info(self): + import pprint + return pprint.pformat(self.current_device_data) @same_thread def get_basic_device_information(self): diff --git a/src/calibre/gui2/device_drivers/mtp_config.py b/src/calibre/gui2/device_drivers/mtp_config.py index 9fd59ab124..dbb31a3e3d 100644 --- a/src/calibre/gui2/device_drivers/mtp_config.py +++ b/src/calibre/gui2/device_drivers/mtp_config.py @@ -12,7 +12,8 @@ import weakref from PyQt4.Qt import (QWidget, QListWidgetItem, Qt, QToolButton, QLabel, QTabWidget, QGridLayout, QListWidget, QIcon, QLineEdit, QVBoxLayout, QPushButton, QGroupBox, QScrollArea, QHBoxLayout, QComboBox, - pyqtSignal, QSizePolicy, QDialog, QDialogButtonBox) + pyqtSignal, QSizePolicy, QDialog, QDialogButtonBox, QPlainTextEdit, + QApplication) from calibre.ebooks import BOOK_EXTENSIONS from calibre.gui2 import error_dialog @@ -372,15 +373,19 @@ class MTPConfig(QTabWidget): _('&Ignore the %s in calibre')%device.current_friendly_name, self.base) b.clicked.connect(self.ignore_device) + self.show_debug_button = bd = QPushButton(QIcon(I('debug.png')), + _('Show device information')) + bd.clicked.connect(self.show_debug_info) l.addWidget(b, 0, 0, 1, 2) l.addWidget(la, 1, 0, 1, 1) - l.addWidget(self.formats, 2, 0, 3, 1) + l.addWidget(self.formats, 2, 0, 4, 1) l.addWidget(self.send_to, 2, 1, 1, 1) l.addWidget(self.template, 3, 1, 1, 1) - l.setRowStretch(4, 10) - l.addWidget(r, 5, 0, 1, 2) - l.setRowStretch(5, 100) + l.addWidget(self.show_debug_button, 4, 1, 1, 1) + l.setRowStretch(5, 10) + l.addWidget(r, 6, 0, 1, 2) + l.setRowStretch(6, 100) self.igntab = IgnoredDevices(self.device.prefs['history'], self.device.prefs['blacklist']) @@ -388,6 +393,26 @@ class MTPConfig(QTabWidget): self.setCurrentIndex(1 if msg else 0) + def show_debug_info(self): + info = self.device.device_debug_info() + d = QDialog(self) + d.l = l = QVBoxLayout() + d.setLayout(l) + d.v = v = QPlainTextEdit() + d.setWindowTitle(self.device.get_gui_name()) + v.setPlainText(info) + v.setMinimumWidth(400) + v.setMinimumHeight(350) + l.addWidget(v) + bb = d.bb = QDialogButtonBox(QDialogButtonBox.Close) + bb.accepted.connect(d.accept) + bb.rejected.connect(d.reject) + l.addWidget(bb) + bb.addButton(_('Copy to clipboard'), bb.ActionRole) + bb.clicked.connect(lambda : + QApplication.clipboard().setText(v.toPlainText())) + d.exec_() + def ignore_device(self): self.igntab.ignore_device(self.device.current_serial_num) self.base.b.setEnabled(False)