mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle multiple file drops onto dock icon in OS X correctly
This commit is contained in:
parent
0d90ff04d3
commit
c1e7185590
@ -2,9 +2,11 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
""" The GUI """
|
""" The GUI """
|
||||||
import os
|
import os
|
||||||
|
from threading import RLock
|
||||||
|
|
||||||
from PyQt4.QtCore import QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, QSize, \
|
from PyQt4.QtCore import QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, QSize, \
|
||||||
QByteArray, QTranslator, QCoreApplication, QThread, \
|
QByteArray, QTranslator, QCoreApplication, QThread, \
|
||||||
QEvent
|
QEvent, QTimer
|
||||||
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
||||||
QIcon, QTableView, QApplication, QDialog, QPushButton
|
QIcon, QTableView, QApplication, QDialog, QPushButton
|
||||||
|
|
||||||
@ -533,6 +535,8 @@ class Application(QApplication):
|
|||||||
self._translator = None
|
self._translator = None
|
||||||
self.load_translations()
|
self.load_translations()
|
||||||
qt_app = self
|
qt_app = self
|
||||||
|
self._file_open_paths = []
|
||||||
|
self._file_open_lock = RLock()
|
||||||
|
|
||||||
if islinux:
|
if islinux:
|
||||||
self.setStyleSheet('''
|
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):
|
def load_translations(self):
|
||||||
if self._translator is not None:
|
if self._translator is not None:
|
||||||
@ -557,7 +566,9 @@ class Application(QApplication):
|
|||||||
if callable(self.file_event_hook) and e.type() == QEvent.FileOpen:
|
if callable(self.file_event_hook) and e.type() == QEvent.FileOpen:
|
||||||
path = unicode(e.file())
|
path = unicode(e.file())
|
||||||
if os.access(path, os.R_OK):
|
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
|
return True
|
||||||
else:
|
else:
|
||||||
return QApplication.event(self, e)
|
return QApplication.event(self, e)
|
||||||
|
@ -988,15 +988,23 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
self.cover_cache.refresh([cid])
|
self.cover_cache.refresh([cid])
|
||||||
self.library_view.model().current_changed(current_idx, current_idx)
|
self.library_view.model().current_changed(current_idx, current_idx)
|
||||||
|
|
||||||
def add_filesystem_book(self, path, allow_device=True):
|
def _add_filesystem_book(self, paths, allow_device=True):
|
||||||
if os.access(path, os.R_OK):
|
if isinstance(paths, basestring):
|
||||||
books = [os.path.abspath(path)]
|
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
|
to_device = allow_device and self.stack.currentIndex() != 0
|
||||||
self._add_books(books, to_device)
|
self._add_books(books, to_device)
|
||||||
if to_device:
|
if to_device:
|
||||||
self.status_bar.showMessage(\
|
self.status_bar.showMessage(\
|
||||||
_('Uploading books to device.'), 2000)
|
_('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):
|
def add_books(self, checked):
|
||||||
'''
|
'''
|
||||||
Add books from the local filesystem to either the library or the device.
|
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)
|
infos, on_card=on_card)
|
||||||
self.status_bar.showMessage(
|
self.status_bar.showMessage(
|
||||||
_('Uploading books to device.'), 2000)
|
_('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)
|
self.library_view.model().books_added(self._adder.number_of_books_added)
|
||||||
if hasattr(self, 'db_images'):
|
if hasattr(self, 'db_images'):
|
||||||
self.db_images.reset()
|
self.db_images.reset()
|
||||||
if self._adder.critical:
|
if getattr(self._adder, 'critical', None) is not None:
|
||||||
det_msg = []
|
det_msg = []
|
||||||
for name, log in self._adder.critical.items():
|
for name, log in self._adder.critical.items():
|
||||||
if isinstance(name, str):
|
if isinstance(name, str):
|
||||||
@ -1056,7 +1064,8 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
_('Failed to read metadata from the following')+':',
|
_('Failed to read metadata from the following')+':',
|
||||||
det_msg='\n\n'.join(det_msg), show=True)
|
det_msg='\n\n'.join(det_msg), show=True)
|
||||||
|
|
||||||
self._adder.cleanup()
|
if hasattr(self._adder, 'cleanup'):
|
||||||
|
self._adder.cleanup()
|
||||||
self._adder = None
|
self._adder = None
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user