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):
etype = e.type()
if etype == QEvent.Type.FileOpen:
url = e.url().toString(QUrl.ComponentFormattingOption.FullyEncoded)
if url and url.startswith('calibre://'):
added_event = False
qurl = e.url()
if qurl.isLocalFile():
with self._file_open_lock:
path = qurl.toLocalFile()
if os.access(path, os.R_OK):
self._file_open_paths.append(path)
added_event = True
elif qurl.isValid():
if qurl.scheme() == 'calibre':
url = qurl.toString(QUrl.ComponentFormattingOption.FullyEncoded)
with self._file_open_lock:
self._file_open_paths.append(url)
QTimer.singleShot(1000, self._send_file_open_events)
return True
path = str(e.file())
if path and os.access(path, os.R_OK):
with self._file_open_lock:
self._file_open_paths.append(path)
added_event = True
if added_event:
QTimer.singleShot(1000, self._send_file_open_events)
return True
else: