qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] PATCH] ui/cocoa.m: verify with user before quitting QEMU


From: Programmingkid
Subject: [Qemu-devel] PATCH] ui/cocoa.m: verify with user before quitting QEMU
Date: Fri, 18 Sep 2015 19:20:41 -0400

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.

Signed-off-by: John Arbuckle <address@hidden>

---
 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);
+}
+
 @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)
+                                                            keyEquivalent:@"q"];
     menuItem = [[NSMenuItem alloc] initWithTitle:@"Apple" action:nil keyEquivalent:@""];
     [menuItem setSubmenu:menu];
     [[NSApp mainMenu] addItem:menuItem];
-- 
1.7.5.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]