mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Small corrections to collection editing & collections sorting on display
This commit is contained in:
parent
bb6cacd205
commit
46a9d48b1d
@ -157,7 +157,7 @@ class PRS505(USBMS):
|
|||||||
debug_print('PRS505: finished sync_booklists')
|
debug_print('PRS505: finished sync_booklists')
|
||||||
|
|
||||||
def rebuild_collections(self, booklist, oncard):
|
def rebuild_collections(self, booklist, oncard):
|
||||||
debug_print('PRS505: started rebuild_collections')
|
debug_print('PRS505: started rebuild_collections on card', oncard)
|
||||||
c = self.initialize_XML_cache()
|
c = self.initialize_XML_cache()
|
||||||
c.rebuild_collections(booklist, {'carda':1, 'cardb':2}.get(oncard, 0))
|
c.rebuild_collections(booklist, {'carda':1, 'cardb':2}.get(oncard, 0))
|
||||||
c.write()
|
c.write()
|
||||||
|
@ -351,9 +351,10 @@ class XMLCache(object):
|
|||||||
return
|
return
|
||||||
root = self.record_roots[bl_index]
|
root = self.record_roots[bl_index]
|
||||||
self.update_playlists(bl_index, root, booklist, [])
|
self.update_playlists(bl_index, root, booklist, [])
|
||||||
|
self.fix_ids()
|
||||||
|
|
||||||
def update_playlists(self, bl_index, root, booklist, collections_attributes):
|
def update_playlists(self, bl_index, root, booklist, collections_attributes):
|
||||||
debug_print('Starting update_playlists', collections_attributes)
|
debug_print('Starting update_playlists', collections_attributes, bl_index)
|
||||||
collections = booklist.get_collections(collections_attributes)
|
collections = booklist.get_collections(collections_attributes)
|
||||||
lpath_map = self.build_lpath_map(root)
|
lpath_map = self.build_lpath_map(root)
|
||||||
for category, books in collections.items():
|
for category, books in collections.items():
|
||||||
|
@ -832,7 +832,7 @@ class EditMetadataAction(object): # {{{
|
|||||||
db.set_metadata(dest_id, dest_mi, ignore_errors=False)
|
db.set_metadata(dest_id, dest_mi, ignore_errors=False)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def edit_device_collections(self, view):
|
def edit_device_collections(self, view, oncard=None):
|
||||||
model = view.model()
|
model = view.model()
|
||||||
result = model.get_collections_with_ids()
|
result = model.get_collections_with_ids()
|
||||||
compare = (lambda x,y:cmp(x.lower(), y.lower()))
|
compare = (lambda x,y:cmp(x.lower(), y.lower()))
|
||||||
@ -845,7 +845,8 @@ class EditMetadataAction(object): # {{{
|
|||||||
model.rename_collection(old_id=to_rename[text], new_name=unicode(text))
|
model.rename_collection(old_id=to_rename[text], new_name=unicode(text))
|
||||||
for item in to_delete:
|
for item in to_delete:
|
||||||
model.delete_collection_using_id(item)
|
model.delete_collection_using_id(item)
|
||||||
self.upload_collections(model.db, view=view)
|
self.upload_collections(model.db, view=view, oncard=oncard)
|
||||||
|
view.reset()
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -1239,17 +1239,13 @@ class DeviceMixin(object): # {{{
|
|||||||
self.card_a_view.reset()
|
self.card_a_view.reset()
|
||||||
self.card_b_view.reset()
|
self.card_b_view.reset()
|
||||||
|
|
||||||
def _upload_collections(self, job, view):
|
def _upload_collections(self, job):
|
||||||
if job.failed:
|
if job.failed:
|
||||||
self.device_job_exception(job)
|
self.device_job_exception(job)
|
||||||
view.reset()
|
|
||||||
|
|
||||||
def upload_collections(self, booklist, view):
|
def upload_collections(self, booklist, view=None, oncard=None):
|
||||||
on_card = 'carda' if self.stack.currentIndex() == 2 else \
|
return self.device_manager.upload_collections(self._upload_collections,
|
||||||
'cardb' if self.stack.currentIndex() == 3 else \
|
booklist, oncard)
|
||||||
None
|
|
||||||
done = partial(self._upload_collections, view=view)
|
|
||||||
return self.device_manager.upload_collections(done, booklist, on_card)
|
|
||||||
|
|
||||||
def upload_books(self, files, names, metadata, on_card=None, memory=None):
|
def upload_books(self, files, names, metadata, on_card=None, memory=None):
|
||||||
'''
|
'''
|
||||||
|
@ -229,15 +229,23 @@ class LibraryViewMixin(object): # {{{
|
|||||||
edit_device_collections=None,
|
edit_device_collections=None,
|
||||||
similar_menu=similar_menu)
|
similar_menu=similar_menu)
|
||||||
add_to_library = (_('Add books to library'), self.add_books_from_device)
|
add_to_library = (_('Add books to library'), self.add_books_from_device)
|
||||||
edit_device_collections = (_('Manage collections'), self.edit_device_collections)
|
|
||||||
|
edit_device_collections = (_('Manage collections'),
|
||||||
|
partial(self.edit_device_collections, oncard=None))
|
||||||
self.memory_view.set_context_menu(None, None, None,
|
self.memory_view.set_context_menu(None, None, None,
|
||||||
self.action_view, self.action_save, None, None, self.action_del,
|
self.action_view, self.action_save, None, None, self.action_del,
|
||||||
add_to_library=add_to_library,
|
add_to_library=add_to_library,
|
||||||
edit_device_collections=edit_device_collections)
|
edit_device_collections=edit_device_collections)
|
||||||
|
|
||||||
|
edit_device_collections = (_('Manage collections'),
|
||||||
|
partial(self.edit_device_collections, oncard='carda'))
|
||||||
self.card_a_view.set_context_menu(None, None, None,
|
self.card_a_view.set_context_menu(None, None, None,
|
||||||
self.action_view, self.action_save, None, None, self.action_del,
|
self.action_view, self.action_save, None, None, self.action_del,
|
||||||
add_to_library=add_to_library,
|
add_to_library=add_to_library,
|
||||||
edit_device_collections=edit_device_collections)
|
edit_device_collections=edit_device_collections)
|
||||||
|
|
||||||
|
edit_device_collections = (_('Manage collections'),
|
||||||
|
partial(self.edit_device_collections, oncard='cardb'))
|
||||||
self.card_b_view.set_context_menu(None, None, None,
|
self.card_b_view.set_context_menu(None, None, None,
|
||||||
self.action_view, self.action_save, None, None, self.action_del,
|
self.action_view, self.action_save, None, None, self.action_del,
|
||||||
add_to_library=add_to_library,
|
add_to_library=add_to_library,
|
||||||
@ -254,12 +262,14 @@ class LibraryViewMixin(object): # {{{
|
|||||||
getattr(view, func)(*args)
|
getattr(view, func)(*args)
|
||||||
|
|
||||||
self.memory_view.connect_dirtied_signal(self.upload_booklists)
|
self.memory_view.connect_dirtied_signal(self.upload_booklists)
|
||||||
self.memory_view.connect_upload_collections_signal(self.upload_collections)
|
self.memory_view.connect_upload_collections_signal(
|
||||||
|
func=self.upload_collections, oncard=None)
|
||||||
self.card_a_view.connect_dirtied_signal(self.upload_booklists)
|
self.card_a_view.connect_dirtied_signal(self.upload_booklists)
|
||||||
self.card_a_view.connect_upload_collections_signal(self.upload_collections)
|
self.card_a_view.connect_upload_collections_signal(
|
||||||
|
func=self.upload_collections, oncard='carda')
|
||||||
self.card_b_view.connect_dirtied_signal(self.upload_booklists)
|
self.card_b_view.connect_dirtied_signal(self.upload_booklists)
|
||||||
self.card_b_view.connect_upload_collections_signal(self.upload_collections)
|
self.card_b_view.connect_upload_collections_signal(
|
||||||
|
func=self.upload_collections, oncard='cardb')
|
||||||
self.book_on_device(None, reset=True)
|
self.book_on_device(None, reset=True)
|
||||||
db.set_book_on_device_func(self.book_on_device)
|
db.set_book_on_device_func(self.book_on_device)
|
||||||
self.library_view.set_database(db)
|
self.library_view.set_database(db)
|
||||||
|
@ -978,8 +978,8 @@ class DeviceBooksModel(BooksModel): # {{{
|
|||||||
x, y = int(self.db[x].size), int(self.db[y].size)
|
x, y = int(self.db[x].size), int(self.db[y].size)
|
||||||
return cmp(x, y)
|
return cmp(x, y)
|
||||||
def tagscmp(x, y):
|
def tagscmp(x, y):
|
||||||
x = ','.join(getattr(self.db[x], 'device_collections', [])).lower()
|
x = ','.join(sorted(getattr(self.db[x], 'device_collections', []))).lower()
|
||||||
y = ','.join(getattr(self.db[y], 'device_collections', [])).lower()
|
y = ','.join(sorted(getattr(self.db[y], 'device_collections', []))).lower()
|
||||||
return cmp(x, y)
|
return cmp(x, y)
|
||||||
def libcmp(x, y):
|
def libcmp(x, y):
|
||||||
x, y = self.db[x].in_library, self.db[y].in_library
|
x, y = self.db[x].in_library, self.db[y].in_library
|
||||||
@ -1027,9 +1027,6 @@ class DeviceBooksModel(BooksModel): # {{{
|
|||||||
def set_database(self, db):
|
def set_database(self, db):
|
||||||
self.custom_columns = {}
|
self.custom_columns = {}
|
||||||
self.db = db
|
self.db = db
|
||||||
for book in db:
|
|
||||||
if book.device_collections is not None:
|
|
||||||
book.device_collections.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
|
|
||||||
self.map = list(range(0, len(db)))
|
self.map = list(range(0, len(db)))
|
||||||
|
|
||||||
def current_changed(self, current, previous):
|
def current_changed(self, current, previous):
|
||||||
@ -1143,6 +1140,7 @@ class DeviceBooksModel(BooksModel): # {{{
|
|||||||
elif cname == 'collections':
|
elif cname == 'collections':
|
||||||
tags = self.db[self.map[row]].device_collections
|
tags = self.db[self.map[row]].device_collections
|
||||||
if tags:
|
if tags:
|
||||||
|
tags.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
|
||||||
return QVariant(', '.join(tags))
|
return QVariant(', '.join(tags))
|
||||||
elif role == Qt.ToolTipRole and index.isValid():
|
elif role == Qt.ToolTipRole and index.isValid():
|
||||||
if self.map[row] in self.indices_to_be_deleted():
|
if self.map[row] in self.indices_to_be_deleted():
|
||||||
@ -1189,6 +1187,7 @@ class DeviceBooksModel(BooksModel): # {{{
|
|||||||
tags = [i.strip() for i in val.split(',')]
|
tags = [i.strip() for i in val.split(',')]
|
||||||
tags = [t for t in tags if t]
|
tags = [t for t in tags if t]
|
||||||
self.db[idx].device_collections = tags
|
self.db[idx].device_collections = tags
|
||||||
|
self.dataChanged.emit(index, index)
|
||||||
self.upload_collections.emit(self.db)
|
self.upload_collections.emit(self.db)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -509,8 +509,8 @@ class DeviceBooksView(BooksView): # {{{
|
|||||||
def connect_dirtied_signal(self, slot):
|
def connect_dirtied_signal(self, slot):
|
||||||
self._model.booklist_dirtied.connect(slot)
|
self._model.booklist_dirtied.connect(slot)
|
||||||
|
|
||||||
def connect_upload_collections_signal(self, func):
|
def connect_upload_collections_signal(self, func=None, oncard=None):
|
||||||
self._model.upload_collections.connect(partial(func, view=self))
|
self._model.upload_collections.connect(partial(func, view=self, oncard=oncard))
|
||||||
|
|
||||||
def dropEvent(self, *args):
|
def dropEvent(self, *args):
|
||||||
error_dialog(self, _('Not allowed'),
|
error_dialog(self, _('Not allowed'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user