Re: [Qemu-devel] [PATCH] ui/cocoa.m: fix help menus

2015-10-13 Thread Peter Maydell
On 27 September 2015 at 15:31, Programmingkid  wrote:
> Make the help menus actually work.
>
> Signed-off-by: John Arbuckle 
>
> ---
>  ui/cocoa.m |   20 
>  1 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index 334e6f6..2c81785 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -992,16 +992,28 @@ QemuCocoaView *cocoaView;
>  {
>  COCOA_DEBUG("QemuCocoaAppController: showQEMUDoc\n");
>
> -[[NSWorkspace sharedWorkspace] openFile:[NSString 
> stringWithFormat:@"%@/../doc/qemu/qemu-doc.html",
> -[[NSBundle mainBundle] resourcePath]] withApplication:@"Help 
> Viewer"];
> +NSString *path;
> +path = [[NSBundle mainBundle] resourcePath];
> +path = [path stringByDeletingLastPathComponent];
> +path = [NSString stringWithFormat: @"%@/%s", path, "qemu-doc.html"];
> +if([[NSWorkspace sharedWorkspace] openFile: path] == NO) {
> +NSBeep();
> +QEMU_Alert(@"Failed to open file qemu-doc.html!");
> +}

This looks like it changes the place we look for the docs
from "../doc/qemu/" to "../".  The latter will work if you're
running QEMU directly from a build tree, but if you've installed
QEMU via 'make install' then we put docs into
 ${prefix}/share/doc/qemu
and binaries into
 ${prefix}/bin
so we need also to search "../share/doc/qemu/". (I think the
current code is attempting to do the latter but is buggy.
This also doesn't account for users manually passing --docdir
to configure, but I think that's pretty hard to do.)

If you want to add support for finding the docs when running
directly from a build tree then we need to check that search
path as well as the one for an installed setup.

>  }
>
>  - (void)showQEMUTec:(id)sender
>  {
>  COCOA_DEBUG("QemuCocoaAppController: showQEMUTec\n");
>
> -[[NSWorkspace sharedWorkspace] openFile:[NSString 
> stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
> -[[NSBundle mainBundle] resourcePath]] withApplication:@"Help 
> Viewer"];
> +NSString *path;
> +path = [[NSBundle mainBundle] resourcePath];
> +path = [path stringByDeletingLastPathComponent];
> +path = [NSString stringWithFormat: @"%@/%s", path, "qemu-tech.html"];
> +if([[NSWorkspace sharedWorkspace] openFile: path] == NO) {
> +NSBeep();
> +QEMU_Alert(@"Failed to open file qemu-tech.html!");
> +}
>  }
>
>  /* Stretches video to fit host monitor size */

You now have two lots of identical code which differ only by
what file they're looking for; this would be better refactored
out into a separate function (especially if you want to search
more than one path).

thanks
-- PMM



[Qemu-devel] [PATCH] ui/cocoa.m: fix help menus

2015-09-27 Thread Programmingkid
Make the help menus actually work. 

Signed-off-by: John Arbuckle 

---
 ui/cocoa.m |   20 
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 334e6f6..2c81785 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -992,16 +992,28 @@ QemuCocoaView *cocoaView;
 {
 COCOA_DEBUG("QemuCocoaAppController: showQEMUDoc\n");
 
-[[NSWorkspace sharedWorkspace] openFile:[NSString 
stringWithFormat:@"%@/../doc/qemu/qemu-doc.html",
-[[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"];
+NSString *path;
+path = [[NSBundle mainBundle] resourcePath];
+path = [path stringByDeletingLastPathComponent];
+path = [NSString stringWithFormat: @"%@/%s", path, "qemu-doc.html"];
+if([[NSWorkspace sharedWorkspace] openFile: path] == NO) {
+NSBeep();
+QEMU_Alert(@"Failed to open file qemu-doc.html!");
+}
 }
 
 - (void)showQEMUTec:(id)sender
 {
 COCOA_DEBUG("QemuCocoaAppController: showQEMUTec\n");
 
-[[NSWorkspace sharedWorkspace] openFile:[NSString 
stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
-[[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"];
+NSString *path;
+path = [[NSBundle mainBundle] resourcePath];
+path = [path stringByDeletingLastPathComponent];
+path = [NSString stringWithFormat: @"%@/%s", path, "qemu-tech.html"];
+if([[NSWorkspace sharedWorkspace] openFile: path] == NO) {
+NSBeep();
+QEMU_Alert(@"Failed to open file qemu-tech.html!");
+}
 }
 
 /* Stretches video to fit host monitor size */
-- 
1.7.5.4