From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgyJT-0007wN-0L for qemu-devel@nongnu.org; Tue, 29 Sep 2015 13:03:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZgyJP-00008I-F1 for qemu-devel@nongnu.org; Tue, 29 Sep 2015 13:03:34 -0400 Received: from mail-qg0-x22f.google.com ([2607:f8b0:400d:c04::22f]:34846) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgyJP-00007y-96 for qemu-devel@nongnu.org; Tue, 29 Sep 2015 13:03:31 -0400 Received: by qgt47 with SMTP id 47so11771883qgt.2 for ; Tue, 29 Sep 2015 10:03:31 -0700 (PDT) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Tue, 29 Sep 2015 13:03:27 -0400 Message-Id: <358BAD94-9E5B-4E19-AC9F-C6DC90200774@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH] ui/cocoa.m: run custom script menu item List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , "Dr. David Alan Gilbert" , Markus Armbruster Cc: qemu-devel qemu-devel Allow the user the ability to run a custom script file. This patch adds a menu item called "Run Custom Script". When the user selects it, a open-file dialog has the user select a text file with the custom scripts to run. This allows for virtually unlimited expandability. All monitor commands should work with this feature. Signed-off-by: John Arbuckle --- To test this patch, save this text "sendkey ctrl-alt-delete" in a text file. Then run a Windows guest to try out this feature. That is only a sample of what this patch could do. Mounting image files, debugging, and saving states are just a few of the things this patch can help the user to accomplish. ui/cocoa.m | 75 = ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 75 insertions(+), 0 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 334e6f6..15a28f0 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -263,6 +263,44 @@ static void handleAnyDeviceErrors(Error * err) } } =20 +/* Sends a command to the monitor console */ +static void sendMonitorCommand(const char *command_string) +{ + int index; + char *console_name; + static QemuConsole *monitor =3D NULL; + + /* If the monitor console hasn't been found yet */ + if(!monitor) { + index =3D 0; + /* Find the monitor console */ + while (qemu_console_lookup_by_index(index) !=3D NULL) { + console_name =3D qemu_console_get_label( + = qemu_console_lookup_by_index(index)); + if(strstr(console_name, "monitor")) { + monitor =3D qemu_console_lookup_by_index(index); + break; + } + index++; + } + } + + /* If the monitor console was not found */ + if(!monitor) { + NSBeep(); + QEMU_Alert(@"Sorry but the monitor isn't available."); + return; + } + + /* send each letter in the commandString to the monitor */ + for (index =3D 0; index < strlen(command_string); index++) { + kbd_put_keysym_console(monitor, command_string[index]); + } + + /* simulate the user pushing the return key */ + kbd_put_keysym_console(monitor, '\n'); +} + /* ------------------------------------------------------ QemuCocoaView @@ -829,6 +867,7 @@ QemuCocoaView *cocoaView; - (void)powerDownQEMU:(id)sender; - (void)ejectDeviceMedia:(id)sender; - (void)changeDeviceMedia:(id)sender; +- (void)runScript:(id)sender; @end =20 @implementation QemuCocoaAppController @@ -1125,6 +1164,31 @@ QemuCocoaView *cocoaView; } } =20 +/* Runs a user's custom script */ +- (void)runScript:(id)sender +{ + NSOpenPanel *openPanel =3D [NSOpenPanel openPanel]; + [openPanel setTitle: @"Select a script file"]; + if([openPanel runModal] =3D=3D NSFileHandlingPanelOKButton) { + NSString *file_buffer, *file_path; + NSError *err =3D nil; + file_path =3D [[openPanel URL] path]; + file_buffer =3D [NSString stringWithContentsOfFile:file_path + = encoding:NSASCIIStringEncoding + error:&err]; + + if(err) { + NSString *message =3D [NSString stringWithFormat: @"Error: = %@", + [err = localizedFailureReason]]; + NSBeep(); + QEMU_Alert(message); + return; + } + sendMonitorCommand([file_buffer cStringUsingEncoding: + = NSASCIIStringEncoding]); + } +} + @end =20 =20 @@ -1184,6 +1248,17 @@ int main (int argc, const char * argv[]) { [[NSApp mainMenu] addItem:menuItem]; [NSApp performSelector:@selector(setAppleMenu:) withObject:menu]; = // Workaround (this method is private since 10.4+) =20 + // File menu + menu =3D [[NSMenu alloc] initWithTitle:@"File"]; + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Run custom = script..." + action:@selector(runScript:) + keyEquivalent:@""] autorelease]]; + menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"File" + action:nil = keyEquivalent:@""] + = autorelease]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] addItem:menuItem]; + // Machine menu menu =3D [[NSMenu alloc] initWithTitle: @"Machine"]; [menu setAutoenablesItems: NO]; --=20 1.7.5.4