mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge from trunk
This commit is contained in:
commit
3b4f46b115
@ -173,8 +173,8 @@ class EditMetadataAction(InterfaceAction):
|
||||
'''
|
||||
rows = [r.row() for r in \
|
||||
self.gui.library_view.selectionModel().selectedRows()]
|
||||
db = self.gui.library_view.model().db
|
||||
ids = [db.id(r) for r in rows]
|
||||
m = self.gui.library_view.model()
|
||||
ids = [m.id(r) for r in rows]
|
||||
if not rows or len(rows) == 0:
|
||||
d = error_dialog(self.gui, _('Cannot edit metadata'),
|
||||
_('No books selected'))
|
||||
@ -193,7 +193,7 @@ class EditMetadataAction(InterfaceAction):
|
||||
self.gui.tags_view.recount()
|
||||
if self.gui.cover_flow:
|
||||
self.gui.cover_flow.dataChanged()
|
||||
self.gui.library_view.select_rows_with_id(ids)
|
||||
self.gui.library_view.select_rows(ids)
|
||||
|
||||
# Merge books {{{
|
||||
def merge_books(self, safe_merge=False):
|
||||
|
@ -479,20 +479,35 @@ class BooksView(QTableView): # {{{
|
||||
sm = self.selectionModel()
|
||||
sm.select(index, sm.ClearAndSelect|sm.Rows)
|
||||
|
||||
def select_rows_with_id(self, ids):
|
||||
def select_rows(self, identifiers, using_ids=True, change_current=True,
|
||||
scroll=True):
|
||||
'''
|
||||
Loop through the visible rows, selecting any that have db_id in list ids
|
||||
Select rows identified by identifiers. identifiers can be a set of ids,
|
||||
row numbers or QModelIndexes.
|
||||
'''
|
||||
ids = set(ids)
|
||||
selmode = self.selectionMode()
|
||||
self.setSelectionMode(QAbstractItemView.MultiSelection)
|
||||
self.clearSelection()
|
||||
db = self.model().db
|
||||
loc = db.FIELD_MAP['id']
|
||||
for i in range(0, len(db.data)):
|
||||
if db.get_property(i, index_is_id=False, loc=loc) in ids:
|
||||
self.selectRow(i)
|
||||
self.setSelectionMode(selmode)
|
||||
try:
|
||||
rows = set([x.row() if hasattr(x, 'row') else x for x in
|
||||
identifiers])
|
||||
if using_ids:
|
||||
rows = set([])
|
||||
identifiers = set(identifiers)
|
||||
m = self.model()
|
||||
for row in range(m.rowCount(QModelIndex())):
|
||||
if m.id(row) in identifiers:
|
||||
rows.add(row)
|
||||
if rows:
|
||||
row = list(sorted(rows))[0]
|
||||
if change_current:
|
||||
self.set_current_row(row, select=False)
|
||||
if scroll:
|
||||
self.scroll_to_row(row)
|
||||
self.clearSelection()
|
||||
for r in rows:
|
||||
self.selectRow(r)
|
||||
finally:
|
||||
self.setSelectionMode(selmode)
|
||||
|
||||
def close(self):
|
||||
self._model.close()
|
||||
|
@ -56,7 +56,7 @@ class ContentServer(object):
|
||||
|
||||
def sort(self, items, field, order):
|
||||
field = self.db.data.sanitize_sort_field_name(field)
|
||||
if field not in ('title', 'authors', 'rating', 'timestamp', 'tags', 'size', 'series'):
|
||||
if field not in self.db.field_metadata.field_keys():
|
||||
raise cherrypy.HTTPError(400, '%s is not a valid sort field'%field)
|
||||
keyg = CSSortKeyGenerator([(field, order)], self.db.field_metadata)
|
||||
items.sort(key=keyg, reverse=not order)
|
||||
|
Loading…
x
Reference in New Issue
Block a user