[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2] ui/cocoa.m: verify with user before quitting QEM
From: |
Programmingkid |
Subject: |
[Qemu-devel] [PATCH v2] ui/cocoa.m: verify with user before quitting QEMU |
Date: |
Sun, 20 Sep 2015 15:20:49 -0400 |
This patch prevents the user from accidentally quitting QEMU by pushing
Command-Q or by pushing the close button on the main window. When the user does
one of these two things, a dialog box appears verifying with the user if he or
she wants to quit QEMU.
Signed-off-by: John Arbuckle <address@hidden>
---
ui/cocoa.m | 35 +++++++++++++++++++++++++++++++++--
1 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 334e6f6..3c5172c 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -807,10 +807,11 @@ QemuCocoaView *cocoaView;
QemuCocoaAppController
------------------------------------------------------
*/
address@hidden QemuCocoaAppController : NSObject
address@hidden QemuCocoaAppController : NSObject <NSWindowDelegate
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
- <NSApplicationDelegate>
+ , NSApplicationDelegate
#endif
+>
{
}
- (void)startEmulationWithArgc:(int)argc argv:(char**)argv;
@@ -829,6 +830,7 @@ QemuCocoaView *cocoaView;
- (void)powerDownQEMU:(id)sender;
- (void)ejectDeviceMedia:(id)sender;
- (void)changeDeviceMedia:(id)sender;
+- (BOOL)verifyQuit;
@end
@implementation QemuCocoaAppController
@@ -862,6 +864,7 @@ QemuCocoaView *cocoaView;
#endif
[normalWindow makeKeyAndOrderFront:self];
[normalWindow center];
+ [normalWindow setDelegate: self];
stretch_video = false;
/* Used for displaying pause on the screen */
@@ -933,6 +936,21 @@ QemuCocoaView *cocoaView;
return YES;
}
+- (NSApplicationTerminateReply)applicationShouldTerminate:
+ (NSApplication
*)sender
+{
+ COCOA_DEBUG("QemuCocoaAppController: applicationShouldTerminate\n");
+ return [self verifyQuit];
+}
+
+/* Called when the user clicks on a window's close button */
+- (BOOL)windowShouldClose:(id)sender
+{
+ COCOA_DEBUG("QemuCocoaAppController: windowShouldClose\n");
+ [NSApp terminate: sender];
+ return NO; /* The main window should always be available */
+}
+
- (void)startEmulationWithArgc:(int)argc argv:(char**)argv
{
COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n");
@@ -1125,6 +1143,19 @@ QemuCocoaView *cocoaView;
}
}
+/* Verifies if the user really wants to quit */
+- (BOOL)verifyQuit
+{
+ NSInteger response;
+ response = NSRunAlertPanel(@"Quit?", @"Are you sure you want to quit?",
+ @"Cancel", @"Quit",
nil);
+ if(response == NSAlertAlternateReturn) {
+ return YES; /* Yes, I want to quit */
+ } else {
+ return NO; /* No, I don't want to quit */
+ }
+}
+
@end
--
1.7.5.4
- [Qemu-devel] [PATCH v2] ui/cocoa.m: verify with user before quitting QEMU,
Programmingkid <=