diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index bdffb985f70..4aa33486533 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1412,6 +1412,15 @@ void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::Cl QGuiApplication::sendSpontaneousEvent(e->window.data(), &event); } +void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e) +{ + if (e->fileName.isEmpty()) + return; + + QFileOpenEvent event(e->fileName); + QGuiApplication::sendSpontaneousEvent(qApp, &event); +} + Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k) { return qHash(k.device) + k.touchPointId; diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index b7b8afc7ad4..ff1a88051c8 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -121,6 +121,8 @@ public: static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e); + static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e); + static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions); static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index c3136b0b0aa..c011fa4e134 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -520,4 +520,10 @@ bool QWindowSystemInterface::handleNativeEvent(QWindow *window, const QByteArray return QGuiApplicationPrivate::processNativeEvent(window, eventType, message, result); } +void QWindowSystemInterface::handleFileOpenEvent(const QString& fileName) +{ + QWindowSystemInterfacePrivate::FileOpenEvent e(fileName); + QGuiApplicationPrivate::processWindowSystemEvent(&e); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h index 7e0ebf0efcc..60db085c4da 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa.h @@ -148,6 +148,8 @@ public: static void handleThemeChange(QWindow *tlw); + static void handleFileOpenEvent(const QString& fileName); + // For event dispatcher implementations static bool sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags); static int windowSystemEventsQueued(); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa_p.h b/src/gui/kernel/qwindowsysteminterface_qpa_p.h index c7ad197b3c8..f026f1ca331 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa_p.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa_p.h @@ -68,7 +68,8 @@ public: ScreenLogicalDotsPerInch, ScreenRefreshRate, ThemeChange, - Expose + Expose, + FileOpen }; class WindowSystemEvent { @@ -257,6 +258,14 @@ public: QRegion region; }; + class FileOpenEvent : public WindowSystemEvent { + public: + FileOpenEvent(const QString& fileName) + : WindowSystemEvent(FileOpen), fileName(fileName) + { } + QString fileName; + }; + static QList windowSystemEventQueue; static QMutex queueMutex; diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 947d91005d1..ec086fe62cb 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -80,6 +80,8 @@ #include #include #include +#include "qt_mac_p.h" +#include QT_USE_NAMESPACE @@ -217,7 +219,7 @@ static void cleanupCocoaApplicationDelegate() { Q_UNUSED(filenames); Q_UNUSED(sender); -/* + for (NSString *fileName in filenames) { QString qtFileName = QCFString::toQString(fileName); if (inLaunch) { @@ -228,14 +230,13 @@ static void cleanupCocoaApplicationDelegate() if (qApp->arguments().contains(qtFileName)) continue; } - QFileOpenEvent foe(qtFileName); - qt_sendSpontaneousEvent(qAppInstance(), &foe); + QWindowSystemInterface::handleFileOpenEvent(qtFileName); } if (reflectionDelegate && [reflectionDelegate respondsToSelector:@selector(application:openFiles:)]) [reflectionDelegate application:sender openFiles:filenames]; -*/ + } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender