qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ui/cocoa.m: run custom script menu item
@ 2015-09-29 17:03 Programmingkid
  2015-09-29 17:18 ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Programmingkid @ 2015-09-29 17:03 UTC (permalink / raw)
  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 <programmingkidx@gmail.com>

---
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)
     }
 }
 
+/* Sends a command to the monitor console */
+static void sendMonitorCommand(const char *command_string)
+{
+    int index;
+    char *console_name;
+    static QemuConsole *monitor = NULL;
+
+    /* If the monitor console hasn't been found yet */
+    if(!monitor) {
+        index = 0;
+        /* Find the monitor console */
+        while (qemu_console_lookup_by_index(index) != NULL) {
+            console_name = qemu_console_get_label(
+                                           qemu_console_lookup_by_index(index));
+            if(strstr(console_name, "monitor")) {
+                monitor = 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 = 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
 
 @implementation QemuCocoaAppController
@@ -1125,6 +1164,31 @@ QemuCocoaView *cocoaView;
     }
 }
 
+/* Runs a user's custom script */
+- (void)runScript:(id)sender
+{
+    NSOpenPanel *openPanel = [NSOpenPanel openPanel];
+    [openPanel setTitle: @"Select a script file"];
+    if([openPanel runModal] == NSFileHandlingPanelOKButton) {
+        NSString *file_buffer, *file_path;
+        NSError *err = nil;
+        file_path = [[openPanel URL] path];
+        file_buffer = [NSString stringWithContentsOfFile:file_path
+                                                encoding:NSASCIIStringEncoding
+                                                   error:&err];
+
+        if(err) {
+            NSString *message = [NSString stringWithFormat: @"Error: %@",
+                                                  [err localizedFailureReason]];
+            NSBeep();
+            QEMU_Alert(message);
+            return;
+        }
+        sendMonitorCommand([file_buffer cStringUsingEncoding:
+                                                      NSASCIIStringEncoding]);
+    }
+}
+
 @end
 
 
@@ -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+)
 
+    // File menu
+    menu = [[NSMenu alloc] initWithTitle:@"File"];
+    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Run custom script..."
+                                    action:@selector(runScript:)
+                             keyEquivalent:@""] autorelease]];
+    menuItem = [[[NSMenuItem alloc] initWithTitle:@"File"
+                                           action:nil keyEquivalent:@""]
+                                                                   autorelease];
+    [menuItem setSubmenu:menu];
+    [[NSApp mainMenu] addItem:menuItem];
+
     // Machine menu
     menu = [[NSMenu alloc] initWithTitle: @"Machine"];
     [menu setAutoenablesItems: NO];
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: run custom script menu item
  2015-09-29 17:03 [Qemu-devel] [PATCH] ui/cocoa.m: run custom script menu item Programmingkid
@ 2015-09-29 17:18 ` Peter Maydell
  2015-09-29 17:53   ` Programmingkid
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2015-09-29 17:18 UTC (permalink / raw)
  To: Programmingkid
  Cc: qemu-devel qemu-devel, Dr. David Alan Gilbert, Markus Armbruster

On 29 September 2015 at 18:03, Programmingkid <programmingkidx@gmail.com> wrote:
> 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 <programmingkidx@gmail.com>
>
> ---
> 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.

Not a feature I want in the cocoa UI, please.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: run custom script menu item
  2015-09-29 17:18 ` Peter Maydell
@ 2015-09-29 17:53   ` Programmingkid
  2015-09-29 18:00     ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Programmingkid @ 2015-09-29 17:53 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-devel qemu-devel, Dr. David Alan Gilbert, Markus Armbruster


On Sep 29, 2015, at 1:18 PM, Peter Maydell wrote:

> On 29 September 2015 at 18:03, Programmingkid <programmingkidx@gmail.com> wrote:
>> 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 <programmingkidx@gmail.com>
>> 
>> ---
>> 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.
> 
> Not a feature I want in the cocoa UI, please.

It can be consider it a poor man's Virt-manager. It is very small
and light. It can help a lot of people out. I really believe in this
feature. It can encompass a lot of the GUI features in most
front-ends. Think about it, the user might never have to enter
long file paths again with this feature. It makes life so much
easier for QEMU users.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: run custom script menu item
  2015-09-29 17:53   ` Programmingkid
@ 2015-09-29 18:00     ` Peter Maydell
  2015-09-29 18:04       ` Programmingkid
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2015-09-29 18:00 UTC (permalink / raw)
  To: Programmingkid
  Cc: qemu-devel qemu-devel, Dr. David Alan Gilbert, Markus Armbruster

On 29 September 2015 at 18:53, Programmingkid <programmingkidx@gmail.com> wrote:
>
> On Sep 29, 2015, at 1:18 PM, Peter Maydell wrote:
>
>> On 29 September 2015 at 18:03, Programmingkid <programmingkidx@gmail.com> wrote:
>>> 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.

>> Not a feature I want in the cocoa UI, please.
>
> It can be consider it a poor man's Virt-manager. It is very small
> and light. It can help a lot of people out. I really believe in this
> feature. It can encompass a lot of the GUI features in most
> front-ends. Think about it, the user might never have to enter
> long file paths again with this feature. It makes life so much
> easier for QEMU users.

I simply do not have the time or expertise to review
these patches for significant new OSX UI layer features.
(OSX host support is something I do as a sideline to the work I'm
paid to do on QEMU, and so my time for it is decidedly limited.)

This leaves you with three choices:
 * find another core developer who will review these for you
 * implement them for some other QEMU UI layer on a platform
   which has more people who care about it and thus gets more
   review (ie Linux+GTK or SDL), and then do the OSX UI updates
   second as a "bring in line with GTK" change
 * implement these features in a separate virt-manager for OSX

I can continue to review bugfix patches and similar.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: run custom script menu item
  2015-09-29 18:00     ` Peter Maydell
@ 2015-09-29 18:04       ` Programmingkid
  0 siblings, 0 replies; 5+ messages in thread
From: Programmingkid @ 2015-09-29 18:04 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel qemu-devel


On Sep 29, 2015, at 2:00 PM, Peter Maydell wrote:

> On 29 September 2015 at 18:53, Programmingkid <programmingkidx@gmail.com> wrote:
>> 
>> On Sep 29, 2015, at 1:18 PM, Peter Maydell wrote:
>> 
>>> On 29 September 2015 at 18:03, Programmingkid <programmingkidx@gmail.com> wrote:
>>>> 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.
> 
>>> Not a feature I want in the cocoa UI, please.
>> 
>> It can be consider it a poor man's Virt-manager. It is very small
>> and light. It can help a lot of people out. I really believe in this
>> feature. It can encompass a lot of the GUI features in most
>> front-ends. Think about it, the user might never have to enter
>> long file paths again with this feature. It makes life so much
>> easier for QEMU users.
> 
> I simply do not have the time or expertise to review
> these patches for significant new OSX UI layer features.
> (OSX host support is something I do as a sideline to the work I'm
> paid to do on QEMU, and so my time for it is decidedly limited.)
> 
> This leaves you with three choices:
> * find another core developer who will review these for you
> * implement them for some other QEMU UI layer on a platform
>   which has more people who care about it and thus gets more
>   review (ie Linux+GTK or SDL), and then do the OSX UI updates
>   second as a "bring in line with GTK" change
> * implement these features in a separate virt-manager for OSX
> 
> I can continue to review bugfix patches and similar.
> 
> thanks
> -- PMM

Adding more maintainers sounds like a great idea.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-29 18:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-29 17:03 [Qemu-devel] [PATCH] ui/cocoa.m: run custom script menu item Programmingkid
2015-09-29 17:18 ` Peter Maydell
2015-09-29 17:53   ` Programmingkid
2015-09-29 18:00     ` Peter Maydell
2015-09-29 18:04       ` Programmingkid

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).