mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Added possibility to sort fetched metadata using the column headers.
This commit is contained in:
parent
3d30edcc83
commit
fc5934436c
@ -16,6 +16,8 @@ from calibre.gui2 import error_dialog, NONE, info_dialog, config
|
|||||||
from calibre.gui2.widgets import ProgressIndicator
|
from calibre.gui2.widgets import ProgressIndicator
|
||||||
from calibre import strftime, force_unicode
|
from calibre import strftime, force_unicode
|
||||||
from calibre.customize.ui import get_isbndb_key, set_isbndb_key
|
from calibre.customize.ui import get_isbndb_key, set_isbndb_key
|
||||||
|
from calibre.utils.icu import sort_key
|
||||||
|
from calibre import force_unicode
|
||||||
|
|
||||||
_hung_fetchers = set([])
|
_hung_fetchers = set([])
|
||||||
|
|
||||||
@ -72,25 +74,32 @@ class Matches(QAbstractTableModel):
|
|||||||
def summary(self, row):
|
def summary(self, row):
|
||||||
return self.matches[row].comments
|
return self.matches[row].comments
|
||||||
|
|
||||||
|
def data_as_text(self, book, col):
|
||||||
|
if col == 0 and book.title is not None:
|
||||||
|
return book.title
|
||||||
|
elif col == 1:
|
||||||
|
return ', '.join(book.authors)
|
||||||
|
elif col == 2 and book.author_sort is not None:
|
||||||
|
return book.author_sort
|
||||||
|
elif col == 3 and book.publisher is not None:
|
||||||
|
return book.publisher
|
||||||
|
elif col == 4 and book.isbn is not None:
|
||||||
|
return book.isbn
|
||||||
|
elif col == 5 and hasattr(book.pubdate, 'timetuple'):
|
||||||
|
return strftime('%b %Y', book.pubdate.timetuple())
|
||||||
|
elif col == 6 and book.has_cover:
|
||||||
|
return 'has_cover'
|
||||||
|
elif col == 7 and book.comments is not None:
|
||||||
|
return book.comments
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
row, col = index.row(), index.column()
|
row, col = index.row(), index.column()
|
||||||
book = self.matches[row]
|
book = self.matches[row]
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
res = None
|
res = self.data_as_text(book, col)
|
||||||
if col == 0:
|
if not (col <= 5 and res):
|
||||||
res = book.title
|
|
||||||
elif col == 1:
|
|
||||||
res = ', '.join(book.authors)
|
|
||||||
elif col == 2:
|
|
||||||
res = book.author_sort
|
|
||||||
elif col == 3:
|
|
||||||
res = book.publisher
|
|
||||||
elif col == 4:
|
|
||||||
res = book.isbn
|
|
||||||
elif col == 5:
|
|
||||||
if hasattr(book.pubdate, 'timetuple'):
|
|
||||||
res = strftime('%b %Y', book.pubdate.timetuple())
|
|
||||||
if not res:
|
|
||||||
return NONE
|
return NONE
|
||||||
return QVariant(res)
|
return QVariant(res)
|
||||||
elif role == Qt.DecorationRole:
|
elif role == Qt.DecorationRole:
|
||||||
@ -100,6 +109,16 @@ class Matches(QAbstractTableModel):
|
|||||||
return self.yes_icon
|
return self.yes_icon
|
||||||
return NONE
|
return NONE
|
||||||
|
|
||||||
|
def sort(self, col, order, reset=True):
|
||||||
|
if not self.matches:
|
||||||
|
return
|
||||||
|
descending = order == Qt.DescendingOrder
|
||||||
|
self.matches.sort(None,
|
||||||
|
lambda x: sort_key(unicode(force_unicode(self.data_as_text(x, col)))),
|
||||||
|
descending)
|
||||||
|
if reset:
|
||||||
|
self.reset()
|
||||||
|
|
||||||
class FetchMetadata(QDialog, Ui_FetchMetadata):
|
class FetchMetadata(QDialog, Ui_FetchMetadata):
|
||||||
|
|
||||||
HANG_TIME = 75 #seconds
|
HANG_TIME = 75 #seconds
|
||||||
@ -136,6 +155,11 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
self.connect(self.matches, SIGNAL('entered(QModelIndex)'),
|
self.connect(self.matches, SIGNAL('entered(QModelIndex)'),
|
||||||
self.show_summary)
|
self.show_summary)
|
||||||
self.matches.setMouseTracking(True)
|
self.matches.setMouseTracking(True)
|
||||||
|
# Enabling sorting and setting a sort column will not change the initial
|
||||||
|
# order of the results, as they are filled in later
|
||||||
|
self.matches.setSortingEnabled(True)
|
||||||
|
QObject.connect(self.matches.horizontalHeader(), SIGNAL('sectionClicked(int)'), self.show_sort_indicator)
|
||||||
|
self.matches.horizontalHeader().setSortIndicatorShown(False)
|
||||||
self.fetch_metadata()
|
self.fetch_metadata()
|
||||||
self.opt_get_social_metadata.setChecked(config['get_social_metadata'])
|
self.opt_get_social_metadata.setChecked(config['get_social_metadata'])
|
||||||
self.opt_overwrite_author_title_metadata.setChecked(config['overwrite_author_title_metadata'])
|
self.opt_overwrite_author_title_metadata.setChecked(config['overwrite_author_title_metadata'])
|
||||||
@ -243,3 +267,6 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
def chosen(self, index):
|
def chosen(self, index):
|
||||||
self.matches.setCurrentIndex(index)
|
self.matches.setCurrentIndex(index)
|
||||||
self.accept()
|
self.accept()
|
||||||
|
|
||||||
|
def show_sort_indicator(self):
|
||||||
|
self.matches.horizontalHeader().setSortIndicatorShown(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user