Received: from eggs.gnu.org ([2001:4830:134:3::10]:59000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeurD-0002Xm-Oe for qemu-devel@nongnu.org; Wed, 23 Sep 2015 20:57:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zeur9-0003VJ-NG for qemu-devel@nongnu.org; Wed, 23 Sep 2015 20:57:55 -0400 Received: from mail-qg0-x234.google.com ([2607:f8b0:400d:c04::234]:33478) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zeur9-0003VD-HY for qemu-devel@nongnu.org; Wed, 23 Sep 2015 20:57:51 -0400 Received: by qgev79 with SMTP id v79so33548631qge.0 for ; Wed, 23 Sep 2015 17:57:51 -0700 (PDT) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Wed, 23 Sep 2015 20:57:48 -0400 Message-Id: <29169A74-0347-47F5-934F-A5AD24C225CA@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH v3] ui/cocoa.m: verify with user before quitting QEMU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel qemu-devel This patch prevents the user from accidentally quitting QEMU by pushing=20= 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 --- Replaced NSRunAlertPanel() with NSAlert. Added more informative comment to windowShouldClose: method. ui/cocoa.m | 39 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 38 insertions(+), 1 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 334e6f6..a46014c 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -809,7 +809,7 @@ QemuCocoaView *cocoaView; */ @interface QemuCocoaAppController : NSObject #if (MAC_OS_X_VERSION_MAX_ALLOWED >=3D MAC_OS_X_VERSION_10_6) - + #endif { } @@ -829,6 +829,7 @@ QemuCocoaView *cocoaView; - (void)powerDownQEMU:(id)sender; - (void)ejectDeviceMedia:(id)sender; - (void)changeDeviceMedia:(id)sender; +- (BOOL)verifyQuit; @end =20 @implementation QemuCocoaAppController @@ -862,6 +863,7 @@ QemuCocoaView *cocoaView; #endif [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; + [normalWindow setDelegate: self]; stretch_video =3D false; =20 /* Used for displaying pause on the screen */ @@ -933,6 +935,26 @@ QemuCocoaView *cocoaView; return YES; } =20 +- (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]; + /* If the user allows the application to quit then the call to + * NSApp terminate will never return. If we get here then the user + * cancelled the quit, so we should return NO to not permit the + * closing of this window. + */ + return NO; +} + - (void)startEmulationWithArgc:(int)argc argv:(char**)argv { COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n"); @@ -1125,6 +1147,21 @@ QemuCocoaView *cocoaView; } } =20 +/* Verifies if the user really wants to quit */ +- (BOOL)verifyQuit +{ + NSAlert *alert =3D [NSAlert new]; + [alert autorelease]; + [alert setMessageText: @"Are you sure you want to quit QEMU?"]; + [alert addButtonWithTitle: @"Cancel"]; + [alert addButtonWithTitle: @"Quit"]; + if([alert runModal] =3D=3D NSAlertSecondButtonReturn) { + return YES; + } else { + return NO; + } +} + @end =20 =20 --=20 1.7.5.4