From: Programmingkid <programmingkidx@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] PATCH] ui/cocoa.m: verify with user before quitting QEMU
Date: Sun, 20 Sep 2015 12:19:42 -0400 [thread overview]
Message-ID: <78E3B4AF-5129-4073-88DF-FE498B5CDEF3@gmail.com> (raw)
In-Reply-To: <CAFEAcA_S9EaYt8pxcU8m+bWu7Gc9oWTHZJ0LTJHwTjMAPcbU9A@mail.gmail.com>
On Sep 20, 2015, at 8:21 AM, Peter Maydell wrote:
> On 19 September 2015 at 00:20, Programmingkid <programmingkidx@gmail.com> 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.
>
> "if they want to" -- our users are not exclusively male :-)
I'm thinking "if he or she wants to" would be more grammatically correct.
>
>> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
>>
>> ---
>> ui/cocoa.m | 22 +++++++++++++++++++++-
>> 1 files changed, 21 insertions(+), 1 deletions(-)
>>
>> 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
>>
>>
>>
>> @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,13 @@ QemuCocoaView *cocoaView;
>> return YES;
>> }
>>
>>
>>
>> +/* 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;
>> }
>> }
>>
>>
>>
>> +/* Verifies if the user really wants to quit */
>> +- (void)verifyQuit
>> +{
>> + NSInteger response;
>> + response = NSRunAlertPanel(@"Quit?", @"Are you sure you want to quit?",
>> + @"Cancel", @"Quit",
>> nil);
>> + if(response == NSAlertAlternateReturn)
>> + exit(EXIT_SUCCESS);
>
> 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.
>
>> +}
>> +
>> @end
>>
>>
>>
>>
>>
>> @@ -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)
>
> 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.
>
>> +
>> keyEquivalent:@"q"];
>> menuItem = [[NSMenuItem alloc] initWithTitle:@"Apple" action:nil
>> keyEquivalent:@""];
>> [menuItem setSubmenu:menu];
>> [[NSApp mainMenu] addItem:menuItem];
>
> thanks
> -- PMM
next prev parent reply other threads:[~2015-09-20 16:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-18 23:20 [Qemu-devel] PATCH] ui/cocoa.m: verify with user before quitting QEMU Programmingkid
2015-09-20 12:21 ` Peter Maydell
2015-09-20 16:19 ` Programmingkid [this message]
2015-09-21 2:32 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78E3B4AF-5129-4073-88DF-FE498B5CDEF3@gmail.com \
--to=programmingkidx@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).