From patchwork Fri Sep 25 22:18:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 54183 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id CDC2D218DB for ; Fri, 25 Sep 2015 22:20:17 +0000 (UTC) Received: by laka1 with SMTP id a1sf25855076lak.0 for ; Fri, 25 Sep 2015 15:20:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=S5hCy2jO72V5XJqdFDajx6qtU3CclI1Ofkwbg6jXNbs=; b=RzBdFlEQfDAAwpS0qPJNHAl11bsrnyFlCC/E395Kiu2xRKtxkWQmJG7RP7dr6bKaMZ QV+5HoCtybZF4WVASPR2Xh3GyYQmHkw3ENfwGpgRmTKkV7YGSmBM0lIpT/vZg4EHkwJB T5PgHBcmvin14kEz5ZZQamwUJOWR7aq2pgbzHihjMc39dsifGU1XNQOZ8btdLUIqACsV RiMnT5zX1fDIm2jH9SEXB5AB69A0MBF5NESyR2HluCzeTmzHvxdbY0ZMMjgVb0VOxJoK t4c+FHlmEpaKrCej6wahA+Tm07eVijb8NhTfrd628Z13ni036+w+1UaF/FCTE1CWPLZQ vOsA== X-Gm-Message-State: ALoCoQkZ1UtxqQtIH9oSuxOjgh0SjkFgqr8mvVTJpnsZiTSqAsvc7f8aBD41/xDkUhPeoWcPun/U X-Received: by 10.195.18.100 with SMTP id gl4mr1327663wjd.4.1443219616711; Fri, 25 Sep 2015 15:20:16 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.232 with SMTP id v8ls182155lav.22.gmail; Fri, 25 Sep 2015 15:20:16 -0700 (PDT) X-Received: by 10.112.52.168 with SMTP id u8mr2324544lbo.48.1443219616547; Fri, 25 Sep 2015 15:20:16 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id e3si2578485lbc.171.2015.09.25.15.20.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Sep 2015 15:20:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by laclj5 with SMTP id lj5so17395809lac.3 for ; Fri, 25 Sep 2015 15:20:16 -0700 (PDT) X-Received: by 10.152.23.170 with SMTP id n10mr338082laf.32.1443219616080; Fri, 25 Sep 2015 15:20:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp291364lbq; Fri, 25 Sep 2015 15:20:15 -0700 (PDT) X-Received: by 10.50.43.202 with SMTP id y10mr4825340igl.86.1443219610065; Fri, 25 Sep 2015 15:20:10 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h67si4253100ioi.120.2015.09.25.15.20.09 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 25 Sep 2015 15:20:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:50744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfbLd-0000wo-Dv for patch@linaro.org; Fri, 25 Sep 2015 18:20:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfbKY-0008I5-6Q for qemu-devel@nongnu.org; Fri, 25 Sep 2015 18:19:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfbKX-0007RV-BQ for qemu-devel@nongnu.org; Fri, 25 Sep 2015 18:19:02 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:35102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfbKX-0007Mt-4t for qemu-devel@nongnu.org; Fri, 25 Sep 2015 18:19:01 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZfbKO-0003zS-WD for qemu-devel@nongnu.org; Fri, 25 Sep 2015 23:18:53 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 25 Sep 2015 23:18:50 +0100 Message-Id: <1443219532-15309-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1443219532-15309-1-git-send-email-peter.maydell@linaro.org> References: <1443219532-15309-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 1/3] 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: John Arbuckle 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 Message-id: 29169A74-0347-47F5-934F-A5AD24C225CA@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- ui/cocoa.m | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index c24d9f9..7c64e1a 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