From patchwork Thu Jul 28 14:42:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 9251401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7AA866075F for ; Thu, 28 Jul 2016 15:26:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A1E927D16 for ; Thu, 28 Jul 2016 15:26:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EDF927D4A; Thu, 28 Jul 2016 15:26:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD8C327D16 for ; Thu, 28 Jul 2016 15:26:28 +0000 (UTC) Received: from localhost ([::1]:53949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSnCc-0003Lw-JH for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Jul 2016 11:26:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSmVq-0002pm-8Q for qemu-devel@nongnu.org; Thu, 28 Jul 2016 10:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSmVm-0001br-1w for qemu-devel@nongnu.org; Thu, 28 Jul 2016 10:42:13 -0400 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]:36140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSmVl-0001bj-Ra for qemu-devel@nongnu.org; Thu, 28 Jul 2016 10:42:09 -0400 Received: by mail-io0-x241.google.com with SMTP id y34so7670332ioi.3 for ; Thu, 28 Jul 2016 07:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-transfer-encoding:subject:date:message-id:cc:to :mime-version; bh=KgdMRUAn2CvetbynrPLOfgMjBmBGZRj38sBlfn3iHqU=; b=zJqw68GDR8A+vJsRrRURrlilTUqeho4pULEyLWTIGB/ciISEf3yKDbOSrFd0xesE7b VVYTAWDk4OAoR0XlNK+GYieFUvC7KpYl4o6o/mWS4UKKuJLcy3rJS//Rd2LZcmv+r2Im bVSjhUgu0tIZ21Pdq9RPYhOA6SVUQubgOskfLFtJI+ZcdOC2xop4m9aAi8WfcLYF3Jxz AM2oWa/Q4jtsMBkqiSfW9ZA2SiuqFbewoWfE22YFE4O5V2fkrxFhV6OblGflSuaA0UtZ cIlP6JWbum0aF2mOlx7eNXfkBSMEENZWr2Hj7mLFOUcip4DWFw3y/rJCMTTt32Rb2woQ cFVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:content-transfer-encoding:subject:date :message-id:cc:to:mime-version; bh=KgdMRUAn2CvetbynrPLOfgMjBmBGZRj38sBlfn3iHqU=; b=Zx8lHIbu1a9P6heAgvs5y72nnFpgMlQwmjmOkYcCGULBckgln8+pFSvOg8xQGnPVz6 0tz1fgDcEEXJ8rV0MT/jhOyMSta9N2vM0GT9eak4aln51QuYLJMSzMXHpjMLYZEyEKdd 62F0PFWeAzDhvrZ+DIzLBYaBf0ucCYT9K/w66rG53U3lqqnmoc09QBZkYLi2hH66q0WE 9zdLFoPRE9EPTReSv/NSLjIQmMnxdlrYPvNA+LQNXRprO+pMeJbqqI/ziOWWQbG1mjzr MfxzO+/kpDuNTWpQbjykeVV7o31sOSD55DdUIpg/ab6mwef3uNm+B0m5VmskaVlTAP94 Nxbg== X-Gm-Message-State: AEkoout3g7Iy8SGE+uzrw+bTZylSbEOGlEBMarhK70YHRvDI6zOWTOY/2pXjx+DtvKY/WA== X-Received: by 10.107.33.66 with SMTP id h63mr38347194ioh.10.1469716928862; Thu, 28 Jul 2016 07:42:08 -0700 (PDT) Received: from [192.168.0.6] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by smtp.gmail.com with ESMTPSA id z25sm15971739ita.7.2016.07.28.07.42.07 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jul 2016 07:42:07 -0700 (PDT) From: Programmingkid Date: Thu, 28 Jul 2016 10:42:06 -0400 Message-Id: <48D5339B-75BD-4053-8C19-B38621A8A838@gmail.com> To: Peter Maydell Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c06::241 Subject: [Qemu-devel] ui/cocoa.m: Make a better about dialog X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel qemu-devel Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From 0c803fd07ddf05904d283628f8277b14fb8cbf35 Mon Sep 17 00:00:00 2001 From: John Arbuckle Date: Thu, 28 Jul 2016 10:34:33 -0400 Subject: [PATCH] Make a better about dialog The about dialog in QEMU on Mac OS X is very plain and unhelpful. This patch makes the about dialog look a lot better and have some descriptive information on what version of QEMU the user is running. Signed-off-by: John Arbuckle --- ui/cocoa.m | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 3 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 36c6bf0..b934eaa 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -34,6 +34,7 @@ #include "qmp-commands.h" #include "sysemu/blockdev.h" #include +#include "qemu-version.h" #ifndef MAC_OS_X_VERSION_10_5 #define MAC_OS_X_VERSION_10_5 1050 @@ -63,7 +64,7 @@ typedef struct { int bitsPerPixel; } QEMUScreen; -NSWindow *normalWindow; +NSWindow *normalWindow, *about_window; static DisplayChangeListener *dcl; static int last_buttons; @@ -670,7 +671,9 @@ QemuCocoaView *cocoaView; case NSLeftMouseUp: mouse_event = true; if (!isMouseGrabbed && [self screenContainsPoint:p]) { - [self grabMouse]; + if([[self window] isKeyWindow]) { + [self grabMouse]; + } } break; case NSRightMouseUp: @@ -824,6 +827,8 @@ QemuCocoaView *cocoaView; - (void)changeDeviceMedia:(id)sender; - (BOOL)verifyQuit; - (void)openDocumentation:(NSString *)filename; +- (IBAction) do_about_menu_item: (id) sender; +- (void)make_about_window; @end @implementation QemuCocoaAppController @@ -876,6 +881,7 @@ QemuCocoaView *cocoaView; supportedImageFileTypes = [NSArray arrayWithObjects: @"img", @"iso", @"dmg", @"qcow", @"qcow2", @"cloop", @"vmdk", @"cdr", nil]; + [self make_about_window]; } return self; } @@ -1138,6 +1144,106 @@ QemuCocoaView *cocoaView; } } +/* The action method for the About menu item */ +- (IBAction) do_about_menu_item: (id) sender +{ + [about_window makeKeyAndOrderFront: nil]; +} + +/* Create and display the about dialog */ +- (void)make_about_window +{ + /* Make the window */ + int x = 0, y = 0, about_width = 400, about_height = 200; + NSRect window_rect = NSMakeRect(x, y, about_width, about_height); + about_window = [[NSWindow alloc] initWithContentRect:window_rect + styleMask:NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask + backing:NSBackingStoreBuffered + defer:NO]; + [about_window setTitle: @"About"]; + [about_window setReleasedWhenClosed: NO]; + [about_window center]; + NSView *superView = [about_window contentView]; + + /* Create the dimensions of the picture */ + int picture_width = 80, picture_height = 80; + x = (about_width - picture_width)/2; + y = about_height - picture_height - 10; + NSRect picture_rect = NSMakeRect(x, y, picture_width, picture_height); + + /* Get the path to the QEMU binary */ + NSString *binary_name = [NSString stringWithCString: gArgv[0] + encoding: NSASCIIStringEncoding]; + binary_name = [binary_name lastPathComponent]; + NSString *program_path = [[NSString alloc] initWithFormat: @"%@/%@", + [[NSBundle mainBundle] bundlePath], binary_name]; + + /* Make the picture of QEMU */ + NSImageView *picture_view = [[NSImageView alloc] initWithFrame: + picture_rect]; + NSImage *qemu_image = [[NSWorkspace sharedWorkspace] iconForFile: + program_path]; + [picture_view setImage: qemu_image]; + [picture_view setImageScaling: NSScaleToFit]; + [superView addSubview: picture_view]; + + /* Make the name label */ + x = 0; + y = y - 25; + int name_width = about_width, name_height = 20; + NSRect name_rect = NSMakeRect(x, y, name_width, name_height); + NSTextField *name_label = [[NSTextField alloc] initWithFrame: name_rect]; + [name_label setEditable: NO]; + [name_label setBezeled: NO]; + [name_label setDrawsBackground: NO]; + [name_label setAlignment: NSCenterTextAlignment]; + NSString *qemu_name = [[NSString alloc] initWithCString: gArgv[0] + encoding: NSASCIIStringEncoding]; + qemu_name = [qemu_name lastPathComponent]; + [name_label setStringValue: qemu_name]; + [superView addSubview: name_label]; + + /* Set the version label's attributes */ + x = 0; + y = 50; + int version_width = about_width, version_height = 20; + NSRect version_rect = NSMakeRect(x, y, version_width, version_height); + NSTextField *version_label = [[NSTextField alloc] initWithFrame: + version_rect]; + [version_label setEditable: NO]; + [version_label setBezeled: NO]; + [version_label setAlignment: NSCenterTextAlignment]; + [version_label setDrawsBackground: NO]; + + /* Remove the parenthese and first 'v' character */ + char buffer[100]; + sprintf(buffer, "%s", QEMU_PKGVERSION); + snprintf(buffer, strlen(buffer) - 3, "%s", (buffer+3)); + + /* Create the version string*/ + NSString *version_string; + version_string = [[NSString alloc] initWithFormat: + @"QEMU emulator version %s", buffer]; + [version_label setStringValue: version_string]; + [superView addSubview: version_label]; + + /* Make copyright label */ + x = 0; + y = 35; + int copyright_width = about_width, copyright_height = 20; + NSRect copyright_rect = NSMakeRect(x, y, copyright_width, copyright_height); + NSTextField *copyright_label = [[NSTextField alloc] initWithFrame: + copyright_rect]; + [copyright_label setEditable: NO]; + [copyright_label setBezeled: NO]; + [copyright_label setDrawsBackground: NO]; + [copyright_label setAlignment: NSCenterTextAlignment]; + [copyright_label setStringValue: + @"Copyright (c) 2003-2008 Fabrice Bellard"]; + [superView addSubview: copyright_label]; +} + @end @@ -1185,7 +1291,7 @@ int main (int argc, const char * argv[]) { // Application menu menu = [[NSMenu alloc] initWithTitle:@""]; - [menu addItemWithTitle:@"About QEMU" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; // About QEMU + [menu addItemWithTitle:@"About QEMU" action:@selector(do_about_menu_item:) keyEquivalent:@""]; // About QEMU [menu addItem:[NSMenuItem separatorItem]]; //Separator [menu addItemWithTitle:@"Hide QEMU" action:@selector(hide:) keyEquivalent:@"h"]; //Hide QEMU menuItem = (NSMenuItem *)[menu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; // Hide Others