Implement add to library in the device context menu

This commit is contained in:
Charles Haley 2010-06-18 12:06:43 +01:00
parent 871e34fb63
commit d472d64b31
3 changed files with 38 additions and 5 deletions

View File

@ -411,6 +411,30 @@ class AddAction(object): # {{{
if hasattr(self._adder, 'cleanup'):
self._adder.cleanup()
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): # {{{

View File

@ -218,20 +218,25 @@ class LibraryViewMixin(object): # {{{
partial(self.show_similar_books, 'tag'))
self.action_books_by_this_publisher.triggered.connect(
partial(self.show_similar_books, 'publisher'))
self.library_view.set_context_menu(self.action_edit, self.action_sync,
self.action_convert, self.action_view,
self.action_save,
self.action_open_containing_folder,
self.action_show_book_details,
self.action_del,
add_to_library = None,
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.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.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.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)
for func, args in [

View File

@ -370,7 +370,8 @@ class BooksView(QTableView): # {{{
# Context Menu {{{
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.context_menu = QMenu(self)
if edit_metadata is not None:
@ -389,6 +390,9 @@ class BooksView(QTableView): # {{{
self.context_menu.addAction(book_details)
if similar_menu is not None:
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):
self.context_menu.popup(event.globalPos())