diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index fed22f87e2..870010b168 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -2,9 +2,11 @@ __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' """ The GUI """ import os +from threading import RLock + from PyQt4.QtCore import QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, QSize, \ QByteArray, QTranslator, QCoreApplication, QThread, \ - QEvent + QEvent, QTimer from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \ QIcon, QTableView, QApplication, QDialog, QPushButton @@ -533,6 +535,8 @@ class Application(QApplication): self._translator = None self.load_translations() qt_app = self + self._file_open_paths = [] + self._file_open_lock = RLock() if islinux: self.setStyleSheet(''' @@ -545,6 +549,11 @@ class Application(QApplication): } ''') + def _send_file_open_events(self): + with self._file_open_lock: + self.file_event_hook(self._file_open_paths) + self._file_open_paths = [] + def load_translations(self): if self._translator is not None: @@ -557,7 +566,9 @@ class Application(QApplication): if callable(self.file_event_hook) and e.type() == QEvent.FileOpen: path = unicode(e.file()) if os.access(path, os.R_OK): - self.file_event_hook(path) + with self._file_open_lock: + self._file_open_paths.append(path) + QTimer.singleShot(self._send_file_open_events, 1000) return True else: return QApplication.event(self, e) diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index c16b868b34..110224e4f2 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -988,15 +988,23 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.cover_cache.refresh([cid]) self.library_view.model().current_changed(current_idx, current_idx) - def add_filesystem_book(self, path, allow_device=True): - if os.access(path, os.R_OK): - books = [os.path.abspath(path)] + def _add_filesystem_book(self, paths, allow_device=True): + if isinstance(paths, basestring): + paths = [paths] + books = [os.path.abspath(path) for path in paths is os.access(path, + os.R_OK)] + + if books: to_device = allow_device and self.stack.currentIndex() != 0 self._add_books(books, to_device) if to_device: self.status_bar.showMessage(\ _('Uploading books to device.'), 2000) + + def add_filesystem_book(self, paths, allow_device=True): + Dispatcher(self._add_filesystem_book)(paths, allow_device=allow_device) + def add_books(self, checked): ''' Add books from the local filesystem to either the library or the device. @@ -1042,11 +1050,11 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): infos, on_card=on_card) self.status_bar.showMessage( _('Uploading books to device.'), 2000) - if self._adder.number_of_books_added > 0: + if getattr(self._adder, 'number_of_books_added', 0) > 0: self.library_view.model().books_added(self._adder.number_of_books_added) if hasattr(self, 'db_images'): self.db_images.reset() - if self._adder.critical: + if getattr(self._adder, 'critical', None) is not None: det_msg = [] for name, log in self._adder.critical.items(): if isinstance(name, str): @@ -1056,7 +1064,8 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): _('Failed to read metadata from the following')+':', det_msg='\n\n'.join(det_msg), show=True) - self._adder.cleanup() + if hasattr(self._adder, 'cleanup'): + self._adder.cleanup() self._adder = None