All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item
@ 2015-09-26  3:01 Programmingkid
  2015-10-13 20:44 ` Peter Maydell
  0 siblings, 1 reply; 7+ messages in thread
From: Programmingkid @ 2015-09-26  3:01 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel qemu-devel

Add a menu item to the Machine menu called "Use Real CDROM". It gives the user
the ability to use a real CDROM disc with QEMU by simply selecting a menu item.

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>

---
 ui/cocoa.m |   87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 334e6f6..7586ba3 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)useRealCDROM:(id)sender;
 @end
 
 @implementation QemuCocoaAppController
@@ -1125,6 +1126,16 @@ QemuCocoaView *cocoaView;
     }
 }
 
+/* Has QEMU use the real CDROM drive */
+- (void)useRealCDROM:(id)sender
+{
+    Error *err = NULL;
+    const char *device = [[sender representedObject] cStringUsingEncoding:
+                                                         NSASCIIStringEncoding];
+    qmp_change_blockdev(device, "/dev/cdrom", "raw", &err);
+    handleAnyDeviceErrors(err);
+}
+
 @end
 
 
@@ -1338,6 +1349,79 @@ static void add_console_menu_entries(void)
     }
 }
 
+/*
+ * Determines if the emulator has a CDROM drive.
+ * Can only be called after the addRemovableDevicesMenuItems() function has been
+ * called.
+ */
+static bool emulatorHasCDROM(void)
+{
+    int index;
+    NSString *title;
+    NSArray *menu_item_array;
+    NSMenu *menu;
+    menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
+    menu_item_array = [menu itemArray];
+    if (!menu_item_array) {
+        NSBeep();
+        QEMU_Alert(@"Failed to obtain Machine menu items!");
+        return false;
+    }
+    /* Start at the first removable device menu item */
+    for (index = 7; index < [menu_item_array count]; index++) {
+        title = [[menu_item_array objectAtIndex: index] title];
+        if ([title rangeOfString: @"cd"].location != NSNotFound) {
+            return true;
+        }
+    }
+    return false;
+}
+
+/* Find the CDROM's name */
+static NSString *getCDName(void)
+{
+    int index, end_of_string_index;
+    NSString *title, *return_value;
+    NSArray *menu_item_array;
+    NSMenu *menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
+    menu_item_array = [menu itemArray];
+    if (!menu_item_array) {
+        NSBeep();
+        QEMU_Alert(@"Failed to obtain Machine menu items!");
+        return nil;
+    }
+    /* Start at the first removable device menu item */
+    for (index = 7; index < [menu_item_array count]; index++) {
+        title = [[menu_item_array objectAtIndex: index] title];
+        if ([title rangeOfString: @"cd"].location != NSNotFound) {
+            return_value = [[title componentsSeparatedByString: @" "]
+                                                              objectAtIndex: 1];
+            end_of_string_index = [return_value rangeOfString: @"."].location;
+            return_value = [return_value substringToIndex: end_of_string_index];
+            return return_value;
+        }
+    }
+    return nil;
+}
+
+/* Add the "Use Real CDROM" menu item */
+static void addRealCDMenuItem(void)
+{
+    NSMenu *machine_menu;
+    NSMenuItem *menu_item;
+    machine_menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu];
+    if (!machine_menu) {
+        NSBeep();
+        QEMU_Alert(@"Could not find Machine Menu!");
+        return;
+    }
+    menu_item = [[NSMenuItem alloc] initWithTitle: @"Use Real CDROM"
+                                          action: @selector(useRealCDROM:)
+                                   keyEquivalent: @""];
+    [menu_item setRepresentedObject: getCDName()];
+    [machine_menu insertItem: menu_item atIndex: 7];
+}
+
 /* Make menu items for all removable devices.
  * Each device is given an 'Eject' and 'Change' menu item.
  */
@@ -1433,4 +1517,7 @@ void cocoa_display_init(DisplayState *ds, int full_screen)
      * find out what removable devices it has.
      */
     addRemovableDevicesMenuItems();
+    if(emulatorHasCDROM()) {
+        addRealCDMenuItem();
+    }
 }
-- 
1.7.5.4

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

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item
@ 2015-09-26  5:45 Namsun Ch'o
  2015-09-26 12:26 ` Programmingkid
  0 siblings, 1 reply; 7+ messages in thread
From: Namsun Ch'o @ 2015-09-26  5:45 UTC (permalink / raw)
  To: programmingkidx; +Cc: qemu-devel

> Add a menu item to the Machine menu called "Use Real CDROM". It gives the
> user the ability to use a real CDROM with QEMU by simply selecting a menu
> item.

> NSASCIIStringEncoding];
> +    qmp_change_blockdev(device, "/dev/cdrom", "raw", &err);
> +    handleAnyDeviceErrors(err);

Not all systems put their CDROM in /dev/cdrom. And you can already select the
machine's real CDROM hardware by doing -cdrom /dev/cdrom (or /dev/sr0, etc).
Examples of device files for CDROMs on other systems:

/dev/sr0
/dev/cd0
/dev/sdc0
/dev/acd0c
/dev/cdrom0
/dev/disk1s0
/dev/scsi/sc0d
/dev/dsk/c1t0d0s0
/dev/rdsk/dks0d1vh

And of course many of the numbers here increment on systems with multiple
drives. There is seriously an insane amount of variation of the names of CDROM
drives. Don't assume that it will only be /dev/cdrom and hardcode it that way.

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

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item
  2015-09-26  5:45 [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item Namsun Ch'o
@ 2015-09-26 12:26 ` Programmingkid
  0 siblings, 0 replies; 7+ messages in thread
From: Programmingkid @ 2015-09-26 12:26 UTC (permalink / raw)
  To: Namsun Ch'o; +Cc: qemu-devel


On Sep 26, 2015, at 1:45 AM, Namsun Ch'o wrote:

>> Add a menu item to the Machine menu called "Use Real CDROM". It gives the
>> user the ability to use a real CDROM with QEMU by simply selecting a menu
>> item.
> 
>> NSASCIIStringEncoding];
>> +    qmp_change_blockdev(device, "/dev/cdrom", "raw", &err);
>> +    handleAnyDeviceErrors(err);
> 
> Not all systems put their CDROM in /dev/cdrom. And you can already select the
> machine's real CDROM hardware by doing -cdrom /dev/cdrom (or /dev/sr0, etc).
> Examples of device files for CDROMs on other systems:
> 
> /dev/sr0
> /dev/cd0
> /dev/sdc0
> /dev/acd0c
> /dev/cdrom0
> /dev/disk1s0
> /dev/scsi/sc0d
> /dev/dsk/c1t0d0s0
> /dev/rdsk/dks0d1vh
> 
> And of course many of the numbers here increment on systems with multiple
> drives. There is seriously an insane amount of variation of the names of CDROM
> drives. Don't assume that it will only be /dev/cdrom and hardcode it that way.


Actually on Mac OS X, /dev/cdrom always points to the optical drive. It is how QEMU is programmed.

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

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item
@ 2015-09-26 22:49 Namsun Ch'o
  2015-09-26 22:51 ` Programmingkid
  0 siblings, 1 reply; 7+ messages in thread
From: Namsun Ch'o @ 2015-09-26 22:49 UTC (permalink / raw)
  To: programmingkidx; +Cc: qemu-devel

> Actually on Mac OS X, /dev/cdrom always points to the optical drive.
> It is how QEMU is programmed.

Is this only for Mac? I must have missed that.

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

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item
  2015-09-26 22:49 Namsun Ch'o
@ 2015-09-26 22:51 ` Programmingkid
  0 siblings, 0 replies; 7+ messages in thread
From: Programmingkid @ 2015-09-26 22:51 UTC (permalink / raw)
  To: Namsun Ch'o; +Cc: qemu-devel


On Sep 26, 2015, at 6:49 PM, Namsun Ch'o wrote:

>> Actually on Mac OS X, /dev/cdrom always points to the optical drive.
>> It is how QEMU is programmed.
> 
> Is this only for Mac? I must have missed that.

Yes, it is for the Macintosh's cocoa interface.

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

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item
  2015-09-26  3:01 Programmingkid
@ 2015-10-13 20:44 ` Peter Maydell
  2015-10-13 22:16   ` Programmingkid
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Maydell @ 2015-10-13 20:44 UTC (permalink / raw)
  To: Programmingkid; +Cc: qemu-devel qemu-devel

On 26 September 2015 at 04:01, Programmingkid <programmingkidx@gmail.com> wrote:
> Add a menu item to the Machine menu called "Use Real CDROM". It gives the user
> the ability to use a real CDROM disc with QEMU by simply selecting a menu item.
>
> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>

This feature is not present in any of our other UI frontends,
and the implementation makes assumptions about the names of
block devices in the models (ie that if it has "cd" in the name
anywhere it's a CD). I also don't have a mac with a CD drive
so I have no way of testing it.

I'm afraid that I think that this comes under the heading of
"features that should be in the VM management layer, not QEMU
itself", so I would prefer not to take it into QEMU.

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item
  2015-10-13 20:44 ` Peter Maydell
@ 2015-10-13 22:16   ` Programmingkid
  0 siblings, 0 replies; 7+ messages in thread
From: Programmingkid @ 2015-10-13 22:16 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel qemu-devel


On Oct 13, 2015, at 4:44 PM, Peter Maydell wrote:

> On 26 September 2015 at 04:01, Programmingkid <programmingkidx@gmail.com> wrote:
>> Add a menu item to the Machine menu called "Use Real CDROM". It gives the user
>> the ability to use a real CDROM disc with QEMU by simply selecting a menu item.
>> 
>> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
> 
> This feature is not present in any of our other UI frontends,
> and the implementation makes assumptions about the names of
> block devices in the models (ie that if it has "cd" in the name
> anywhere it's a CD). I also don't have a mac with a CD drive
> so I have no way of testing it.
> 
> I'm afraid that I think that this comes under the heading of
> "features that should be in the VM management layer, not QEMU
> itself", so I would prefer not to take it into QEMU.

Mac OS X users don't have any VM management layer. That is pretty much
a Linux-only feature. What we do have is the cocoa interface. 

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

end of thread, other threads:[~2015-10-13 22:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-26  5:45 [Qemu-devel] [PATCH] ui/cocoa.m: Add real CDROM menu item Namsun Ch'o
2015-09-26 12:26 ` Programmingkid
  -- strict thread matches above, loose matches on Subject: below --
2015-09-26 22:49 Namsun Ch'o
2015-09-26 22:51 ` Programmingkid
2015-09-26  3:01 Programmingkid
2015-10-13 20:44 ` Peter Maydell
2015-10-13 22:16   ` Programmingkid

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.