summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@edeltech.ch>2014-07-02 16:46:24 +0200
committerDavid Faure <david.faure@kdab.com>2014-07-10 21:54:19 +0200
commit50c04d631858639c630e85456e7e003a80e33493 (patch)
tree21dd2c6cb9026395bfdf10056dfe35eca0f641b9 /src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
parent53ed4de02278b17708199891f9b56c6e6e04103b (diff)
Session management for OS X
This patch aims to implement the session management available on OS X. Currently applicationShouldTerminate is just a go through that closes everything and ends the application. The new implementation calls first appCommitData and cancels the termination properly if required. This means that if a user wishes to logout, Qt applications can now cancel that like e.g. answering to Safari asking whether it is ok to close because of a number of opened tab/window. Task-number: QTBUG-33034 Change-Id: Icedc8590a1c0934d9bc87d3a43d6702a9903bfb8 Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
index efe3269d42..6c39f1eb5a 100644
--- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
+++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
@@ -1,5 +1,6 @@
/****************************************************************************
**
+** Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch>
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
@@ -78,11 +79,13 @@
#import "qnswindowdelegate.h"
#import "qcocoamenuloader.h"
#include "qcocoaintegration.h"
+#include "qcocoasessionmanager.h"
#include <qevent.h>
#include <qurl.h>
#include <qdebug.h>
#include <qguiapplication.h>
#include <private/qguiapplication_p.h>
+#include <private/qsessionmanager_p.h>
#include "qt_mac_p.h"
#include <qpa/qwindowsysteminterface.h>
@@ -216,6 +219,17 @@ static void cleanupCocoaApplicationDelegate()
return NSTerminateNow;
}
+ QGuiApplicationPrivate *qGuiAppPriv = QGuiApplicationPrivate::instance();
+
+#ifndef QT_NO_SESSIONMANAGER
+ QSessionManagerPrivate *managerPrivate = static_cast<QSessionManagerPrivate*>(QObjectPrivate::get(qGuiAppPriv->session_manager));
+ QCocoaSessionManager *cocoaSessionManager = static_cast<QCocoaSessionManager *>(managerPrivate->platformSessionManager);
+ cocoaSessionManager->appCommitData();
+
+ if (cocoaSessionManager->wasCanceled())
+ return NSTerminateCancel;
+#endif
+
if ([self canQuit]) {
if (!startedQuit) {
startedQuit = true;
@@ -239,7 +253,7 @@ static void cleanupCocoaApplicationDelegate()
}
}
- if (QGuiApplicationPrivate::instance()->threadData->eventLoops.isEmpty()) {
+ if (qGuiAppPriv->threadData->eventLoops.isEmpty()) {
// INVARIANT: No event loop is executing. This probably
// means that Qt is used as a plugin, or as a part of a native
// Cocoa application. In any case it should be fine to
@@ -270,10 +284,6 @@ static void cleanupCocoaApplicationDelegate()
*/
NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
[eventManager setEventHandler:self
- andSelector:@selector(appleEventQuit:withReplyEvent:)
- forEventClass:kCoreEventClass
- andEventID:kAEQuitApplication];
- [eventManager setEventHandler:self
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
@@ -283,7 +293,6 @@ static void cleanupCocoaApplicationDelegate()
- (void) removeAppleEventHandlers
{
NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
- [eventManager removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEQuitApplication];
[eventManager removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL];
}
@@ -330,7 +339,8 @@ static void cleanupCocoaApplicationDelegate()
&& [reflectionDelegate respondsToSelector:
@selector(applicationShouldTerminateAfterLastWindowClosed:)])
return [reflectionDelegate applicationShouldTerminateAfterLastWindowClosed:sender];
- return NO; // Someday qApp->quitOnLastWindowClosed(); when QApp and NSApp work closer together.
+
+ return qApp->quitOnLastWindowClosed();
}
@@ -436,13 +446,6 @@ static void cleanupCocoaApplicationDelegate()
QWindowSystemInterface::handleFileOpenEvent(QUrl(QCFString::toQString(urlString)));
}
-- (void)appleEventQuit:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
-{
- Q_UNUSED(event);
- Q_UNUSED(replyEvent);
- [NSApp terminate:self];
-}
-
- (void)qtDispatcherToQAction:(id)sender
{
Q_UNUSED(sender);