diff --git a/src/calibre/gui2/actions/convert.py b/src/calibre/gui2/actions/convert.py index 4289158b78..3034c0de18 100644 --- a/src/calibre/gui2/actions/convert.py +++ b/src/calibre/gui2/actions/convert.py @@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en' import os from functools import partial -from PyQt4.Qt import QModelIndex +from PyQt4.Qt import QModelIndex, QTimer from calibre.gui2 import error_dialog, Dispatcher from calibre.gui2.tools import convert_single_ebook, convert_bulk_ebook @@ -24,6 +24,31 @@ class ConvertAction(InterfaceAction): action_type = 'current' action_add_menu = True + accepts_drops = True + + def accept_enter_event(self, event, mime_data): + if mime_data.hasFormat("application/calibre+from_library"): + return True + return False + + def accept_drag_move_event(self, event, mime_data): + if mime_data.hasFormat("application/calibre+from_library"): + return True + return False + + def drop_event(self, event, mime_data): + mime = 'application/calibre+from_library' + if mime_data.hasFormat(mime): + self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + QTimer.singleShot(1, self.do_drop) + return True + return False + + def do_drop(self): + book_ids = self.dropped_ids + del self.dropped_ids + self.do_convert(book_ids) + def genesis(self): m = self.convert_menu = self.qaction.menu() cm = partial(self.create_menu_action, self.convert_menu) @@ -112,6 +137,9 @@ class ConvertAction(InterfaceAction): def convert_ebook(self, checked, bulk=None): book_ids = self.get_books_for_conversion() if book_ids is None: return + self.do_convert(book_ids, bulk=bulk) + + def do_convert(self, book_ids, bulk=None): previous = self.gui.library_view.currentIndex() rows = [x.row() for x in \ self.gui.library_view.selectionModel().selectedRows()]