Received: from eggs.gnu.org ([2001:4830:134:3::10]:51726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YBSmU-0006IW-Av for qemu-devel@nongnu.org; Wed, 14 Jan 2015 13:35:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YBSmQ-0001hc-TT for qemu-devel@nongnu.org; Wed, 14 Jan 2015 13:35:02 -0500 Received: from mail-qg0-x230.google.com ([2607:f8b0:400d:c04::230]:63782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YBSmQ-0001hU-Nk for qemu-devel@nongnu.org; Wed, 14 Jan 2015 13:34:58 -0500 Received: by mail-qg0-f48.google.com with SMTP id j5so8307904qga.7 for ; Wed, 14 Jan 2015 10:34:58 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: Date: Wed, 14 Jan 2015 13:34:55 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: <0FFE82CE-80F6-41BD-8AFF-F63500FFF8AD@gmail.com> References: <1B8AA8D9-61F0-4FE2-A0DF-A3321FBD72AB@gmail.com> Subject: Re: [Qemu-devel] [PATCH] Machine menu patch for Mac OS X List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel qemu-devel On Jan 14, 2015, at 12:42 PM, Peter Maydell wrote: > On 13 January 2015 at 01:49, Programmingkid = wrote: >> This patch adds a Machine menu to QEMU. This menu gives the user the = ability to easily work with floppy and CD image files. >>=20 >> Features: >> Menu items to switch floppy and CD image files. >> Menu items to eject floppy and CD image files. >> Menu item to use /dev/cdrom. >> Verifies with the user before quitting QEMU by displaying a dialog = box. >>=20 >> Signed-off-by: John Arbuckle >=20 > Hi. I'm afraid I couldn't get this patch to apply -- is it dependent > on one of your other patches? I have been making a lot of changes to cocoa.m. Can you suggest a way to = make these changes not interfere with each other? >=20 > Some comments below, anyway. >=20 >> +/* Pause the guest */ >> +- (void)pauseQemu:(id)sender >> +{ >> + qmp_stop(NULL); >> + [sender setEnabled: NO]; >> + [[[sender menu] itemWithTitle: @"Resume"] setEnabled: YES]; >> + [normalWindow setTitle: @"*** Paused ***"]; >> +} >> + >> +/* Resume running the guest operating system */ >> +- (void)resumeQemu: (id) sender >> +{ >> + qmp_cont(NULL); >> + [sender setEnabled: NO]; >> + [[[sender menu] itemWithTitle: @"Pause"] setEnabled: YES]; >> + [normalWindow setTitle: @"QEMU"]; >=20 > Isn't this changing of the title string going to conflict with the > changes that we make for mouse grab/ungrab? Unfortunately yes, but I still need a way to alert the user that QEMU is = paused. I guess I could find a way to make both messages show up in the = titlebar. Or I could display a message in the main window that says = "Paused". Will come up with something soon. >=20 >> +} >> + >> +/* Eject the floppy0 disk */ >> +- (void)ejectFloppy:(id)sender >> +{ >> + Error *err =3D NULL; >> + qmp_eject("floppy0", false, false, &err); >> + handleAnyDeviceErrors(err); >> +} >> + >> +/* Displays a dialog box asking the user to select a floppy image to = load */ >> +- (void)changeFloppy:(id)sender >> +{ >> + NSOpenPanel * open_panel; >> + open_panel =3D [NSOpenPanel openPanel]; >> + [open_panel setCanChooseFiles: YES]; >> + [open_panel setAllowsMultipleSelection: NO]; >> + if([open_panel runModalForDirectory: nil file: nil] =3D=3D = NSOKButton) { >> + Error *err =3D NULL; >> + NSString * file =3D [[open_panel filenames] objectAtIndex: = 0]; >> + qmp_change_blockdev("floppy0", [file cString], "raw", &err); >> + handleAnyDeviceErrors(err); >> + } >> +} >=20 > You don't know that the machine being emulated has a floppy drive > at all, or that it's called "floppy0"... I did only use the PC and Mac targets. I know there are others. It looks = like conditionally adding some of these menu items will have to do. I = guess detecting if the guest machine has a floppy and/or cdrom drive can = be done - hopefully... >=20 >> + >> +// Ejects the cdrom >> +- (void)ejectCdrom:(id)sender >> +{ >> + Error *err =3D NULL; >> + qmp_eject("ide1-cd0", false, false, &err); >> + handleAnyDeviceErrors(err); >> +} >> + >> +/* Displays a dialog box asking the user to select a CD image to = load */ >> +- (void)changeCdrom:(id)sender >> +{ >> + NSOpenPanel * open_panel; >> + open_panel =3D [NSOpenPanel openPanel]; >> + [open_panel setCanChooseFiles: YES]; >> + [open_panel setAllowsMultipleSelection: NO]; >> + if([open_panel runModalForDirectory: nil file: nil] =3D=3D = NSOKButton) { >> + NSString * file =3D [[open_panel filenames] objectAtIndex: = 0]; >> + Error *err =3D NULL; >> + qmp_change_blockdev("ide1-cd0", [file cString], "raw", = &err); >> + handleAnyDeviceErrors(err); >> + } >> +} >=20 > Similarly, the CD may not exist in the guest machine or may > not be called "ide1-cd0". Ok, will find some way to determine what the CDROM drive is called - if = that is possible... >=20 >> + >> +/* Restarts QEMU */ >> +- (void)restartQemu: (id) sender >> +{ >> + qemu_system_reset_request(); >> +} >> + >> +/* Switches QEMU to use the real cdrom drive */ >> +- (void)useRealCdrom: (id) sender >> +{ >> + Error *err =3D NULL; >> + qmp_change_blockdev("ide1-cd0", "/dev/cdrom", "raw", &err); >> + handleAnyDeviceErrors(err); >> +} >> + >> +/* Verifies if the user really wants to quit */ >> +- (void)verifyQuit: (id) sender >> +{ >> + NSInteger response; >> + response =3D NSRunAlertPanel(@"Quit?", @"Are you sure you want = to quit?", @"Cancel", @"Quit", nil); >=20 > We don't have an are-you-sure prompt for closing the QEMU window via > the red button, and we don't for the Quit menu option in the GTK UI = either... A prompt can be added to the close "red" button. As for GTK, we are = allowed to be better than them. It really stinks when I'm working on = something in the guest and I push Command-Q thinking it will only quit = the one application I am working on, but instead takes out the entire = emulator. I'm hoping that prompt will save someone from having a really = bad day.=20 >=20 >> + if(response =3D=3D NSAlertAlternateReturn) >> + exit(EXIT_SUCCESS); >=20 > You should use qmp_quit(NULL) rather than just exit(). Not a problem. >=20 >> +} >> + >> @end >>=20 >>=20 >> @@ -1046,7 +1153,7 @@ 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 =3D [[NSMenuItem alloc] initWithTitle:@"Apple" = action:nil keyEquivalent:@""]; >> [menuItem setSubmenu:menu]; >> [[NSApp mainMenu] addItem:menuItem]; >> @@ -1059,6 +1166,24 @@ int main (int argc, const char * argv[]) { >> [menuItem setSubmenu:menu]; >> [[NSApp mainMenu] addItem:menuItem]; >>=20 >> + /* Machine menu */ >> + menu =3D [[NSMenu alloc] initWithTitle: @"Machine"]; >> + [menu setAutoenablesItems: NO]; >> + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Pause" = action: @selector(pauseQemu:) keyEquivalent: @""] autorelease]]; >> + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Resume" = action: @selector(resumeQemu:) keyEquivalent: @""] autorelease]]; >> + [menu addItem: [NSMenuItem separatorItem]]; >> + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Eject = Floppy" action: @selector(ejectFloppy:) keyEquivalent: @""] = autorelease]]; >> + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Change = Floppy..." action: @selector(changeFloppy:) keyEquivalent: @""] = autorelease]]; >> + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Eject = cdrom" action: @selector(ejectCdrom:) keyEquivalent: @""] autorelease]]; >> + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Use cdrom = image..." action: @selector(changeCdrom:) keyEquivalent: @""] = autorelease]]; >> + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Use real = cdrom drive" action: @selector(useRealCdrom:) keyEquivalent: @""] = autorelease]]; >> + [menu addItem: [NSMenuItem separatorItem]]; >> + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Restart" = action: @selector(restartQemu:) keyEquivalent: @""] autorelease]]; >=20 > In the GTK UI we call this "Reset". We also have a "Power Down" which = would > probably be nice for consistency. Changing Restart to Reset will be done. I don't know how to implement = "Power Down", so I'm not sure about that one. >=20 >> + menuItem =3D [[[NSMenuItem alloc] initWithTitle: @"Machine" = action:nil keyEquivalent:@""] autorelease]; >> + [menuItem setSubmenu:menu]; >> + [[NSApp mainMenu] addItem:menuItem]; >> + [[menu itemWithTitle: @"Resume"] setEnabled: NO]; >> + >> // Window menu >> menu =3D [[NSMenu alloc] initWithTitle:@"Window"]; >> [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" = action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; = // Miniaturize >> @@ -1168,7 +1293,7 @@ void cocoa_display_init(DisplayState *ds, int = full_screen) >> [NSApp activateIgnoringOtherApps: YES]; >> [[[NSApplication sharedApplication] delegate] = toggleFullScreen: nil]; >> } >> - >> + >> dcl =3D g_malloc0(sizeof(DisplayChangeListener)); >>=20 >> // register vga output callbacks >=20 > Stray whitespace change. Sorry for that.=20 Do you think anyone will ever make SDL or GTK UIs for QEMU work on Mac = OS X?=