Received: from eggs.gnu.org ([2001:4830:134:3::10]:51689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afuFA-0003Lz-Mw for qemu-devel@nongnu.org; Tue, 15 Mar 2016 15:03:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afuF7-0001G9-Gw for qemu-devel@nongnu.org; Tue, 15 Mar 2016 15:03:00 -0400 Received: from mail-io0-x235.google.com ([2607:f8b0:4001:c06::235]:34739) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afuF7-0001F1-Bh for qemu-devel@nongnu.org; Tue, 15 Mar 2016 15:02:57 -0400 Received: by mail-io0-x235.google.com with SMTP id m184so35995193iof.1 for ; Tue, 15 Mar 2016 12:02:57 -0700 (PDT) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Tue, 15 Mar 2016 15:02:54 -0400 Message-Id: Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH v3] ui/cocoa.m: fix help menus List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel qemu-devel Make the help menus actually work. The code will search thru three = different locations for the help file. If it can't be found a dialog will tell the = user=20 the file can't be found. Signed-off-by: John Arbuckle --- *v3 changes Removed code that opens a web page.=20 Removed number_of_paths and added ARRAY_SIZE() macro. *v2 changes Moved opening code to one method.=20 Searches three different locations on the user's computer first. Attempts to open file on web if file can't be found on user's computer. ui/cocoa.m | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 7063a02..9295233 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -858,6 +858,7 @@ QemuCocoaView *cocoaView; - (void)ejectDeviceMedia:(id)sender; - (void)changeDeviceMedia:(id)sender; - (BOOL)verifyQuit; +- (void)openDocumentation:(NSString *)filename; @end =20 @implementation QemuCocoaAppController @@ -994,20 +995,42 @@ QemuCocoaView *cocoaView; [cocoaView toggleFullScreen:sender]; } =20 +/* Tries to find then open the specified filename */ +- (void) openDocumentation: (NSString *) filename +{ + /* Where to look for local files */ + NSString *path_array[] =3D {@"../share/doc/qemu/", @"../doc/qemu/", = @"../"}; + NSString *full_file_path; + + /* iterate thru the possible paths until the file is found */ + int index; + for (index =3D 0; index < ARRAY_SIZE(path_array); index++) { + full_file_path =3D [[NSBundle mainBundle] executablePath]; + full_file_path =3D [full_file_path = stringByDeletingLastPathComponent]; + full_file_path =3D [NSString stringWithFormat: @"%@/%@%@", = full_file_path, + path_array[index], filename]; + if ([[NSWorkspace sharedWorkspace] openFile: full_file_path] =3D=3D= YES) { + return; + } + } + + /* If none of the paths opened a file */ + NSBeep(); + QEMU_Alert(@"Failed to open file"); +} + - (void)showQEMUDoc:(id)sender { COCOA_DEBUG("QemuCocoaAppController: showQEMUDoc\n"); =20 - [[NSWorkspace sharedWorkspace] openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-doc.html", - [[NSBundle mainBundle] resourcePath]] withApplication:@"Help = Viewer"]; + [self openDocumentation: @"qemu-doc.html"]; } =20 - (void)showQEMUTec:(id)sender { COCOA_DEBUG("QemuCocoaAppController: showQEMUTec\n"); =20 - [[NSWorkspace sharedWorkspace] openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", - [[NSBundle mainBundle] resourcePath]] withApplication:@"Help = Viewer"]; + [self openDocumentation: @"qemu-tech.html"]; } =20 /* Stretches video to fit host monitor size */ --=20 2.7.2