Clean up FileOpen event handling

This commit is contained in:
Kovid Goyal 2024-07-27 10:57:34 +05:30
parent 28fded9122
commit 4c0df1ba17
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1394,16 +1394,21 @@ class Application(QApplication):
def event(self, e): def event(self, e):
etype = e.type() etype = e.type()
if etype == QEvent.Type.FileOpen: if etype == QEvent.Type.FileOpen:
url = e.url().toString(QUrl.ComponentFormattingOption.FullyEncoded) added_event = False
if url and url.startswith('calibre://'): qurl = e.url()
if qurl.isLocalFile():
with self._file_open_lock: with self._file_open_lock:
self._file_open_paths.append(url) path = qurl.toLocalFile()
QTimer.singleShot(1000, self._send_file_open_events) if os.access(path, os.R_OK):
return True self._file_open_paths.append(path)
path = str(e.file()) added_event = True
if path and os.access(path, os.R_OK): elif qurl.isValid():
with self._file_open_lock: if qurl.scheme() == 'calibre':
self._file_open_paths.append(path) url = qurl.toString(QUrl.ComponentFormattingOption.FullyEncoded)
with self._file_open_lock:
self._file_open_paths.append(url)
added_event = True
if added_event:
QTimer.singleShot(1000, self._send_file_open_events) QTimer.singleShot(1000, self._send_file_open_events)
return True return True
else: else: