From patchwork Mon Feb 25 10:24:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 159165 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp1859810jad; Mon, 25 Feb 2019 02:24:43 -0800 (PST) X-Received: by 2002:adf:9dc4:: with SMTP id q4mr12559642wre.330.1551090282990; Mon, 25 Feb 2019 02:24:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551090282; cv=none; d=google.com; s=arc-20160816; b=M44vjQRD+pHrNCocdVGX9OOC7mXOewpXDpivD5KycK+av3aFwCXvbaSuRolNjz/p6q WWcimdoODMkXM0BHBGRGMgUXg8lfb7Sgd+8umne8uvgBEiHHGMEPObcdwdoczkBIRVWZ V/y/ddGMo2StOYy6F51cIjr2i1CKQr1Zp2omd/9R2brdPFd6jcQjmc4RqjoXU5yFXY/r 46qj61hIs0+qzbDyL4oP1sSyEb/wGDxxbeWuad6rfs2lj1kA8tYWKvdLXP/17eHbjhnw j6kjmvImliHMPdwvxDANDnyNLiofWB5+CT6V6o1HQOWkmUXA0Q4coSKbqJmd1Pxm1U6X NOtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=qKHYmK4Qjd/L8Bxby+U0AcrdM9zpOx8LLP3umMgo5pY=; b=Ul/tNNK8rF4RrdUX1hEWZS7HjHcu6KN0735pePgtEmBEp6T6VhEewMy3yt0gOmnVIN lBszMjUIGuIRHnRWjSEHM9CFC4YRfIRuzIELX6/PswIWSCQlrvnaKgUsHO3BPoXLcAZt Ixb7iHuznkBPqmFWbs3ArWQk6b+HEsu0yWwos1DrQY8fsyNL7kNrB4v2vhVLikSxdfgS NYqb2xuh1VWji/uealNgCTgVpfKs4Cop7vW4VeypeVuqZcxUB3HiqvMPZ9/HQNipp4Uq BEeGlMOLr92PDcN7oyNunDXi6DgwLMlyu6xnJFSch94B19Wjj/bhFnHLRVvsL0sGHeXV Gr3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="v/u0vHn9"; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h5sor4936377wml.3.2019.02.25.02.24.42 for (Google Transport Security); Mon, 25 Feb 2019 02:24:42 -0800 (PST) Received-SPF: pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="v/u0vHn9"; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qKHYmK4Qjd/L8Bxby+U0AcrdM9zpOx8LLP3umMgo5pY=; b=v/u0vHn9KwcBYMfLhyQQm3KF4O/JStEDEgcg5HhwD6BX4sX82HvKXrCzcAC8xkzLf+ QGk9ZWjij1sVIBB08UkSGEIHs+mqlz7YyBQZwuVPVNBfXhM92JTkMs8tTZ8YkfUzHDey TEmMOPiIwK0fw1KXYOETlYKuGxJ3pcypG/nvNzbyRqcuxoSyxaT7FjMVdgl1WyZJLj0c bXtIJpTSO83ws+NaWClIlRDWikI0jxKsGqvfkrmMeaN+ZxmdlSUcL1SZSmh/VQbVoejs UC3UWd6hOcsog5TFuqN7UBIAXFM72avUuA3V77/hDkKEg4xyg4iwXb8qmL0wH9C2uBx/ DnQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qKHYmK4Qjd/L8Bxby+U0AcrdM9zpOx8LLP3umMgo5pY=; b=aadgPkuKVT0tX6bUNfS85bkBHUjKyCuuZBTkjkyFFMu0eQN2WIOjg2SgbFHFzcIY/Y OO98+YSvheeb1XsmclmUGkxN/PYVmOZwVNts0D1HZEcN3Owk1DenemBzsY3v6caQ2Z+Z w1sVOe5BNFOJ5XO9L6cxYgsYZeaFa6mpGeHobGl4l8HmkzmshoUqFYTHrhY3KwJ7AoDq 3Coe999AyYb0Hc+hzD7W2uMycaAjgTF1SI0tVmJ/+uKy9r7rWzftCSAVHC1/8q41/JgH x6JlbWSIuop5X3D+P26khWlkiD1XWSRpqioj5xIFZ039HxEoqGxyLnt3HtXBd9hh/f1g yhog== X-Gm-Message-State: AHQUAuZlSbmy/PQfOWa0q+neE9Ih5POj+AyRWi0ReNLjTEibT5Vm8TqE qjOogC61ImsU34xA04Y5wVumOM5E X-Google-Smtp-Source: AHgI3IaG9i0vQrA6L2HJT6rbuYYcTmyFUkielQ0yg2ZvqxbgLuZjzZ0C2mhfz/8AZPD3zy8DIfnQsA== X-Received: by 2002:a1c:5fc5:: with SMTP id t188mr9784494wmb.86.1551090282499; Mon, 25 Feb 2019 02:24:42 -0800 (PST) Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id v10sm1764692wrn.26.2019.02.25.02.24.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 02:24:41 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Roman Bolshakov , BALATON Zoltan , John Arbuckle , Berkus Decker , Gerd Hoffmann , Ben Hekster Subject: [PATCH v3 4/7] ui/cocoa: Move console/device menu creation code up in file Date: Mon, 25 Feb 2019 10:24:30 +0000 Message-Id: <20190225102433.22401-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225102433.22401-1-peter.maydell@linaro.org> References: <20190225102433.22401-1-peter.maydell@linaro.org> MIME-Version: 1.0 Move the console/device menu creation code functions further up in the source file, next to the code which creates the initial menus. We're going to want to change the location we call these functions from in the next patch. This commit is a pure code move with no other changes. Signed-off-by: Peter Maydell Reviewed-by: BALATON Zoltan Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov Message-id: 20190214102816.3393-5-peter.maydell@linaro.org --- ui/cocoa.m | 184 ++++++++++++++++++++++++++--------------------------- 1 file changed, 92 insertions(+), 92 deletions(-) -- 2.17.2 (Apple Git-113) diff --git a/ui/cocoa.m b/ui/cocoa.m index 4baec0b2ff..d1fc1a6aff 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -1552,6 +1552,98 @@ static void create_initial_menus(void) [[NSApp mainMenu] addItem:menuItem]; } +/* Returns a name for a given console */ +static NSString * getConsoleName(QemuConsole * console) +{ + return [NSString stringWithFormat: @"%s", qemu_console_get_label(console)]; +} + +/* Add an entry to the View menu for each console */ +static void add_console_menu_entries(void) +{ + NSMenu *menu; + NSMenuItem *menuItem; + int index = 0; + + menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu]; + + [menu addItem:[NSMenuItem separatorItem]]; + + while (qemu_console_lookup_by_index(index) != NULL) { + menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index)) + action: @selector(displayConsole:) keyEquivalent: @""] autorelease]; + [menuItem setTag: index]; + [menu addItem: menuItem]; + index++; + } +} + +/* Make menu items for all removable devices. + * Each device is given an 'Eject' and 'Change' menu item. + */ +static void addRemovableDevicesMenuItems(void) +{ + NSMenu *menu; + NSMenuItem *menuItem; + BlockInfoList *currentDevice, *pointerToFree; + NSString *deviceName; + + currentDevice = qmp_query_block(NULL); + pointerToFree = currentDevice; + if(currentDevice == NULL) { + NSBeep(); + QEMU_Alert(@"Failed to query for block devices!"); + return; + } + + menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu]; + + // Add a separator between related groups of menu items + [menu addItem:[NSMenuItem separatorItem]]; + + // Set the attributes to the "Removable Media" menu item + NSString *titleString = @"Removable Media"; + NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:titleString]; + NSColor *newColor = [NSColor blackColor]; + NSFontManager *fontManager = [NSFontManager sharedFontManager]; + NSFont *font = [fontManager fontWithFamily:@"Helvetica" + traits:NSBoldFontMask|NSItalicFontMask + weight:0 + size:14]; + [attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [titleString length])]; + [attString addAttribute:NSForegroundColorAttributeName value:newColor range:NSMakeRange(0, [titleString length])]; + [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt: 1] range:NSMakeRange(0, [titleString length])]; + + // Add the "Removable Media" menu item + menuItem = [NSMenuItem new]; + [menuItem setAttributedTitle: attString]; + [menuItem setEnabled: NO]; + [menu addItem: menuItem]; + + /* Loop through all the block devices in the emulator */ + while (currentDevice) { + deviceName = [[NSString stringWithFormat: @"%s", currentDevice->value->device] retain]; + + if(currentDevice->value->removable) { + menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Change %s...", currentDevice->value->device] + action: @selector(changeDeviceMedia:) + keyEquivalent: @""]; + [menu addItem: menuItem]; + [menuItem setRepresentedObject: deviceName]; + [menuItem autorelease]; + + menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Eject %s", currentDevice->value->device] + action: @selector(ejectDeviceMedia:) + keyEquivalent: @""]; + [menu addItem: menuItem]; + [menuItem setRepresentedObject: deviceName]; + [menuItem autorelease]; + } + currentDevice = currentDevice->next; + } + qapi_free_BlockInfoList(pointerToFree); +} + int main (int argc, const char * argv[]) { gArgc = argc; @@ -1680,98 +1772,6 @@ static void cocoa_cleanup(void) .dpy_refresh = cocoa_refresh, }; -/* Returns a name for a given console */ -static NSString * getConsoleName(QemuConsole * console) -{ - return [NSString stringWithFormat: @"%s", qemu_console_get_label(console)]; -} - -/* Add an entry to the View menu for each console */ -static void add_console_menu_entries(void) -{ - NSMenu *menu; - NSMenuItem *menuItem; - int index = 0; - - menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu]; - - [menu addItem:[NSMenuItem separatorItem]]; - - while (qemu_console_lookup_by_index(index) != NULL) { - menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index)) - action: @selector(displayConsole:) keyEquivalent: @""] autorelease]; - [menuItem setTag: index]; - [menu addItem: menuItem]; - index++; - } -} - -/* Make menu items for all removable devices. - * Each device is given an 'Eject' and 'Change' menu item. - */ -static void addRemovableDevicesMenuItems(void) -{ - NSMenu *menu; - NSMenuItem *menuItem; - BlockInfoList *currentDevice, *pointerToFree; - NSString *deviceName; - - currentDevice = qmp_query_block(NULL); - pointerToFree = currentDevice; - if(currentDevice == NULL) { - NSBeep(); - QEMU_Alert(@"Failed to query for block devices!"); - return; - } - - menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu]; - - // Add a separator between related groups of menu items - [menu addItem:[NSMenuItem separatorItem]]; - - // Set the attributes to the "Removable Media" menu item - NSString *titleString = @"Removable Media"; - NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:titleString]; - NSColor *newColor = [NSColor blackColor]; - NSFontManager *fontManager = [NSFontManager sharedFontManager]; - NSFont *font = [fontManager fontWithFamily:@"Helvetica" - traits:NSBoldFontMask|NSItalicFontMask - weight:0 - size:14]; - [attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [titleString length])]; - [attString addAttribute:NSForegroundColorAttributeName value:newColor range:NSMakeRange(0, [titleString length])]; - [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt: 1] range:NSMakeRange(0, [titleString length])]; - - // Add the "Removable Media" menu item - menuItem = [NSMenuItem new]; - [menuItem setAttributedTitle: attString]; - [menuItem setEnabled: NO]; - [menu addItem: menuItem]; - - /* Loop through all the block devices in the emulator */ - while (currentDevice) { - deviceName = [[NSString stringWithFormat: @"%s", currentDevice->value->device] retain]; - - if(currentDevice->value->removable) { - menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Change %s...", currentDevice->value->device] - action: @selector(changeDeviceMedia:) - keyEquivalent: @""]; - [menu addItem: menuItem]; - [menuItem setRepresentedObject: deviceName]; - [menuItem autorelease]; - - menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Eject %s", currentDevice->value->device] - action: @selector(ejectDeviceMedia:) - keyEquivalent: @""]; - [menu addItem: menuItem]; - [menuItem setRepresentedObject: deviceName]; - [menuItem autorelease]; - } - currentDevice = currentDevice->next; - } - qapi_free_BlockInfoList(pointerToFree); -} - static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) { COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");