Received: from eggs.gnu.org ([2001:4830:134:3::10]:49754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdhLA-0002m2-Br for qemu-devel@nongnu.org; Sun, 20 Sep 2015 12:19:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZdhL7-000236-8i for qemu-devel@nongnu.org; Sun, 20 Sep 2015 12:19:48 -0400 Received: from mail-qk0-x22b.google.com ([2607:f8b0:400d:c09::22b]:33408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdhL7-00022U-2O for qemu-devel@nongnu.org; Sun, 20 Sep 2015 12:19:45 -0400 Received: by qkdw123 with SMTP id w123so36846924qkd.0 for ; Sun, 20 Sep 2015 09:19:44 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: Date: Sun, 20 Sep 2015 12:19:42 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <78E3B4AF-5129-4073-88DF-FE498B5CDEF3@gmail.com> References: <71B9096B-B9D6-4929-9212-0D55A5C35CC8@gmail.com> Subject: Re: [Qemu-devel] PATCH] ui/cocoa.m: verify with user before quitting QEMU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel qemu-devel On Sep 20, 2015, at 8:21 AM, Peter Maydell wrote: > On 19 September 2015 at 00:20, Programmingkid = wrote: >> 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 >> wants to quit QEMU. >=20 > "if they want to" -- our users are not exclusively male :-) I'm thinking "if he or she wants to" would be more grammatically = correct.=20 >=20 >> Signed-off-by: John Arbuckle >>=20 >> --- >> ui/cocoa.m | 22 +++++++++++++++++++++- >> 1 files changed, 21 insertions(+), 1 deletions(-) >>=20 >> diff --git a/ui/cocoa.m b/ui/cocoa.m >> index 334e6f6..ff1a72b 100644 >> --- a/ui/cocoa.m >> +++ b/ui/cocoa.m >> @@ -829,6 +829,7 @@ QemuCocoaView *cocoaView; >> - (void)powerDownQEMU:(id)sender; >> - (void)ejectDeviceMedia:(id)sender; >> - (void)changeDeviceMedia:(id)sender; >> +- (void)verifyQuit; >> @end >>=20 >>=20 >>=20 >> @implementation QemuCocoaAppController >> @@ -862,6 +863,7 @@ QemuCocoaView *cocoaView; >> #endif >> [normalWindow makeKeyAndOrderFront:self]; >> [normalWindow center]; >> + [normalWindow setDelegate: self]; >> stretch_video =3D false; >>=20 >>=20 >>=20 >> /* Used for displaying pause on the screen */ >> @@ -933,6 +935,13 @@ QemuCocoaView *cocoaView; >> return YES; >> } >>=20 >>=20 >>=20 >> +/* Called when the user clicks on a window's close button */ >> +- (BOOL)windowShouldClose:(id)sender >> +{ >> + [self verifyQuit]; >> + return NO; >> +} >> + >> - (void)startEmulationWithArgc:(int)argc argv:(char**)argv >> { >> COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n"); >> @@ -1125,6 +1134,16 @@ QemuCocoaView *cocoaView; >> } >> } >>=20 >>=20 >>=20 >> +/* Verifies if the user really wants to quit */ >> +- (void)verifyQuit >> +{ >> + NSInteger response; >> + response =3D NSRunAlertPanel(@"Quit?", @"Are you sure you want = to quit?", >> + @"Cancel", = @"Quit", >> nil); >> + if(response =3D=3D NSAlertAlternateReturn) >> + exit(EXIT_SUCCESS); >=20 > Missing braces. Checkpatch will warn you about this kind of thing. Surprisingly it didn't work. I have noticed that checkpatch also doesn't = detect lines over 80 characters in length. I did use checkpatch on this patch. It said = there were no errors or warnings. Maybe it doesn't know objective-c very well? > Calling exit() here doesn't really seem right to me -- I think we > should return the "OK to terminate app/close this window" > response to the OSX framework and let it cause us to exit in > the normal way. Ok. >=20 >> +} >> + >> @end >>=20 >>=20 >>=20 >>=20 >>=20 >> @@ -1178,7 +1197,8 @@ int main (int argc, const char * argv[]) { >> [menuItem >> setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; >> [menu addItemWithTitle:@"Show All" >> action:@selector(unhideAllApplications:) keyEquivalent:@""]; // Show = All >> [menu addItem:[NSMenuItem separatorItem]]; //Separator >> - [menu addItemWithTitle:@"Quit QEMU" action:@selector(terminate:) >> keyEquivalent:@"q"]; >> + [menu addItemWithTitle:@"Quit QEMU" action:@selector(verifyQuit) >=20 > Should we be doing this by implementing > NSApplication:applicationShouldTerminate? > That seems to be where the OSX framework expects us to handle > "do you really want to do this" as part of the standard terminate: > flow. Ok. I can do that if you wish.=20 >=20 >> + >> keyEquivalent:@"q"]; >> menuItem =3D [[NSMenuItem alloc] initWithTitle:@"Apple" = action:nil >> keyEquivalent:@""]; >> [menuItem setSubmenu:menu]; >> [[NSApp mainMenu] addItem:menuItem]; >=20 > thanks > -- PMM