From 06f6f8cbebf9dddea51f8377bac079a033f2dc67 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 May 2010 15:20:51 -0600 Subject: [PATCH 1/2] Add icon to In Device column and fix a couple of minor typos --- src/calibre/devices/usbms/books.py | 2 +- src/calibre/gui2/library.py | 12 +++++++++++- src/calibre/gui2/ui.py | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index 1ddc00729f..50756ef3ee 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -49,7 +49,7 @@ class Book(object): @property def db_id(self): '''The database id in the application database that this file corresponds to''' - match = re.search(r'_(\d+)$', self.rpath.rpartition('.')[0]) + match = re.search(r'_(\d+)$', self.path.rpartition('.')[0]) if match: return int(match.group(1)) diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py index 90dc3eb1ea..0ee5f36a59 100644 --- a/src/calibre/gui2/library.py +++ b/src/calibre/gui2/library.py @@ -778,6 +778,12 @@ class BooksModel(QAbstractTableModel): return self.bool_blank_icon return self.bool_no_icon + def ondevice_decorator(r, idx=-1): + text = self.db.data[r][idx] + if text: + return self.bool_yes_icon + return self.bool_blank_icon + def text_type(r, mult=False, idx=-1): text = self.db.data[r][idx] if text and mult: @@ -810,7 +816,11 @@ class BooksModel(QAbstractTableModel): 'ondevice' : functools.partial(text_type, idx=self.db.FIELD_MAP['ondevice'], mult=False), } - self.dc_decorator = {} + + self.dc_decorator = { + 'ondevice':functools.partial(ondevice_decorator, + idx=self.db.FIELD_MAP['ondevice']), + } # Add the custom columns to the data converters for col in self.custom_columns: diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 4f5e71174c..e97665909f 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -959,7 +959,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.status_bar.reset_info() self.location_view.setCurrentIndex(self.location_view.model().index(0)) self.eject_action.setEnabled(False) - self.refresh_ondevice_info (clear_info = True) + self.refresh_ondevice_info(clear_flags=True) def info_read(self, job): ''' @@ -1019,7 +1019,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): ############################################################################ ### Force the library view to refresh, taking into consideration books information - def refresh_ondevice_info(self, clear_flags = False): + def refresh_ondevice_info(self, clear_flags=False): self.book_on_device(None, reset=True) self.library_view.model().refresh() ############################################################################ From a2bf9e3696c33d7c26ec89551ed41f85b79f8710 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 May 2010 15:30:25 -0600 Subject: [PATCH 2/2] Use icons for the In Library column --- src/calibre/gui2/library.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py index 0ee5f36a59..75b1d672cd 100644 --- a/src/calibre/gui2/library.py +++ b/src/calibre/gui2/library.py @@ -1420,11 +1420,11 @@ class DeviceBooksModel(BooksModel): ''' Return indices into underlying database from rows ''' - return [ self.map[r.row()] for r in rows] + return [self.map[r.row()] for r in rows] def data(self, index, role): + row, col = index.row(), index.column() if role == Qt.DisplayRole or role == Qt.EditRole: - row, col = index.row(), index.column() if col == 0: text = self.db[self.map[row]].title if not text: @@ -1449,9 +1449,6 @@ class DeviceBooksModel(BooksModel): tags = self.db[self.map[row]].tags if tags: return QVariant(', '.join(tags)) - elif col == 5: - return QVariant(_('Yes')) \ - if self.db[self.map[row]].in_library else QVariant(_('No')) elif role == Qt.TextAlignmentRole and index.column() in [2, 3]: return QVariant(Qt.AlignRight | Qt.AlignVCenter) elif role == Qt.ToolTipRole and index.isValid(): @@ -1460,6 +1457,10 @@ class DeviceBooksModel(BooksModel): col = index.column() if col in [0, 1] or (col == 4 and self.db.supports_tags()): return QVariant(_("Double click to edit me

")) + elif role == Qt.DecorationRole and col == 5: + if self.db[self.map[row]].in_library: + return QVariant(self.bool_yes_icon) + return NONE def headerData(self, section, orientation, role):