From patchwork Thu Sep 24 00:57:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 521992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7EF9514029E for ; Thu, 24 Sep 2015 10:58:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=lwKftb6/; dkim-atps=neutral Received: from localhost ([::1]:51776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeurS-0002q5-HX for incoming@patchwork.ozlabs.org; Wed, 23 Sep 2015 20:58:10 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:date:message-id :to:mime-version; bh=qzm3TQfOF4vlXbtUuT+1L8WjsUPO+/HFycwDd4fwY+c=; b=lwKftb6/Qw4CG5BOWcxHpxLWCv1i0DmydWtadsf8il5M9am1HSB3J+kuxLFvkhtHl5 GX5sFFqnNFOTL6HnGTa28iwB8NSEAd2eDuR0qavlYkqZiz5Fip3yHhqhJK9VsyRnE+GZ +VaTBcDiKbF/+q6ll/5OZ8ncgrDKuwEQ4KvzKvea+FTkO5nIJ1J3FNFc1MLqUVX0aU9O a2vJ65a4IuFSWxgUMLXAfBE/BziMA1Gydf9ZN6/6HjmAEud2izl0qI7W1wv7NU48q5NF XQxXyPDEly1gyOVoE1XNJ0AeHv0VjgI0466gAdLqeRkb/vepllDTKWX/FXwfV5IZHZsl orEQ== X-Received: by 10.140.145.80 with SMTP id 77mr43349386qhr.36.1443056271146; Wed, 23 Sep 2015 17:57:51 -0700 (PDT) Received: from [192.168.0.3] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by smtp.gmail.com with ESMTPSA id j193sm3555986qhc.17.2015.09.23.17.57.49 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 23 Sep 2015 17:57:50 -0700 (PDT) From: Programmingkid Date: Wed, 23 Sep 2015 20:57:48 -0400 Message-Id: <29169A74-0347-47F5-934F-A5AD24C225CA@gmail.com> To: Peter Maydell , qemu-devel qemu-devel Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c04::234 Subject: [Qemu-devel] [PATCH v3] ui/cocoa.m: verify with user before quitting QEMU X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 >= 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 @implementation QemuCocoaAppController @@ -862,6 +863,7 @@ QemuCocoaView *cocoaView; #endif [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; + [normalWindow setDelegate: self]; stretch_video = false; /* Used for displaying pause on the screen */ @@ -933,6 +935,26 @@ 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]; + /* 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; } } +/* Verifies if the user really wants to quit */ +- (BOOL)verifyQuit +{ + NSAlert *alert = [NSAlert new]; + [alert autorelease]; + [alert setMessageText: @"Are you sure you want to quit QEMU?"]; + [alert addButtonWithTitle: @"Cancel"]; + [alert addButtonWithTitle: @"Quit"]; + if([alert runModal] == NSAlertSecondButtonReturn) { + return YES; + } else { + return NO; + } +} + @end