mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement add to library in the device context menu
This commit is contained in:
parent
871e34fb63
commit
d472d64b31
@ -411,6 +411,30 @@ class AddAction(object): # {{{
|
|||||||
if hasattr(self._adder, 'cleanup'):
|
if hasattr(self._adder, 'cleanup'):
|
||||||
self._adder.cleanup()
|
self._adder.cleanup()
|
||||||
self._adder = None
|
self._adder = None
|
||||||
|
|
||||||
|
def _add_from_device_adder(self, paths=[], names=[], infos=[],
|
||||||
|
on_card=None, model=None):
|
||||||
|
self._files_added(paths, names, infos, on_card=on_card)
|
||||||
|
# set the in-library flags, and as a consequence send the library's
|
||||||
|
# metadata for this book to the device. This sets the uuid to the
|
||||||
|
# correct value.
|
||||||
|
self.set_books_in_library(booklists=[model.db], reset=True)
|
||||||
|
model.reset()
|
||||||
|
|
||||||
|
def add_books_from_device(self, view):
|
||||||
|
rows = view.selectionModel().selectedRows()
|
||||||
|
if not rows or len(rows) == 0:
|
||||||
|
d = error_dialog(self, _('Add to library'), _('No book selected'))
|
||||||
|
d.exec_()
|
||||||
|
return
|
||||||
|
paths = view._model.paths(rows)
|
||||||
|
from calibre.gui2.add import Adder
|
||||||
|
self.__adder_func = partial(self._add_from_device_adder, on_card=None,
|
||||||
|
model=view._model)
|
||||||
|
self._adder = Adder(self, self.library_view.model().db,
|
||||||
|
Dispatcher(self.__adder_func), spare_server=self.spare_server)
|
||||||
|
self._adder.add(paths)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class DeleteAction(object): # {{{
|
class DeleteAction(object): # {{{
|
||||||
|
@ -218,20 +218,25 @@ class LibraryViewMixin(object): # {{{
|
|||||||
partial(self.show_similar_books, 'tag'))
|
partial(self.show_similar_books, 'tag'))
|
||||||
self.action_books_by_this_publisher.triggered.connect(
|
self.action_books_by_this_publisher.triggered.connect(
|
||||||
partial(self.show_similar_books, 'publisher'))
|
partial(self.show_similar_books, 'publisher'))
|
||||||
|
|
||||||
self.library_view.set_context_menu(self.action_edit, self.action_sync,
|
self.library_view.set_context_menu(self.action_edit, self.action_sync,
|
||||||
self.action_convert, self.action_view,
|
self.action_convert, self.action_view,
|
||||||
self.action_save,
|
self.action_save,
|
||||||
self.action_open_containing_folder,
|
self.action_open_containing_folder,
|
||||||
self.action_show_book_details,
|
self.action_show_book_details,
|
||||||
self.action_del,
|
self.action_del,
|
||||||
|
add_to_library = None,
|
||||||
similar_menu=similar_menu)
|
similar_menu=similar_menu)
|
||||||
|
add_to_library = (_('Add books to library'), self.add_books_from_device)
|
||||||
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)
|
||||||
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)
|
||||||
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)
|
||||||
|
|
||||||
self.library_view.files_dropped.connect(self.files_dropped, type=Qt.QueuedConnection)
|
self.library_view.files_dropped.connect(self.files_dropped, type=Qt.QueuedConnection)
|
||||||
for func, args in [
|
for func, args in [
|
||||||
|
@ -370,7 +370,8 @@ class BooksView(QTableView): # {{{
|
|||||||
|
|
||||||
# Context Menu {{{
|
# Context Menu {{{
|
||||||
def set_context_menu(self, edit_metadata, send_to_device, convert, view,
|
def set_context_menu(self, edit_metadata, send_to_device, convert, view,
|
||||||
save, open_folder, book_details, delete, similar_menu=None):
|
save, open_folder, book_details, delete,
|
||||||
|
add_to_library, similar_menu=None):
|
||||||
self.setContextMenuPolicy(Qt.DefaultContextMenu)
|
self.setContextMenuPolicy(Qt.DefaultContextMenu)
|
||||||
self.context_menu = QMenu(self)
|
self.context_menu = QMenu(self)
|
||||||
if edit_metadata is not None:
|
if edit_metadata is not None:
|
||||||
@ -389,6 +390,9 @@ class BooksView(QTableView): # {{{
|
|||||||
self.context_menu.addAction(book_details)
|
self.context_menu.addAction(book_details)
|
||||||
if similar_menu is not None:
|
if similar_menu is not None:
|
||||||
self.context_menu.addMenu(similar_menu)
|
self.context_menu.addMenu(similar_menu)
|
||||||
|
if add_to_library is not None:
|
||||||
|
func = partial(add_to_library[1], view=self)
|
||||||
|
self.context_menu.addAction(add_to_library[0], func)
|
||||||
|
|
||||||
def contextMenuEvent(self, event):
|
def contextMenuEvent(self, event):
|
||||||
self.context_menu.popup(event.globalPos())
|
self.context_menu.popup(event.globalPos())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user