All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ui/cocoa: Show QEMU icon in the about window
@ 2021-03-09 12:22 Akihiko Odaki
  2021-03-09 12:22 ` [PATCH 2/2] ui/cocoa: Do not rely on the first argument Akihiko Odaki
  2021-03-10 12:23 ` [PATCH 1/2] ui/cocoa: Show QEMU icon in the about window Gerd Hoffmann
  0 siblings, 2 replies; 8+ messages in thread
From: Akihiko Odaki @ 2021-03-09 12:22 UTC (permalink / raw)
  Cc: Peter Maydell, qemu-devel, Akihiko Odaki, Gerd Hoffmann

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 ui/cocoa.m | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 0ef5fdf3b7a..d8eacea6d22 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -39,6 +39,7 @@
 #include "qapi/qapi-commands-misc.h"
 #include "sysemu/blockdev.h"
 #include "qemu-version.h"
+#include "qemu/cutils.h"
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
 #include <Carbon/Carbon.h>
@@ -1401,18 +1402,13 @@ - (void)make_about_window
     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];
+    char *qemu_image_path_c = get_relocated_path(CONFIG_QEMU_ICONDIR "/hicolor/512x512/apps/qemu.png");
+    NSString *qemu_image_path = [NSString stringWithUTF8String:qemu_image_path_c];
+    g_free(qemu_image_path_c);
+    NSImage *qemu_image = [[NSImage alloc] initWithContentsOfFile:qemu_image_path];
     [picture_view setImage: qemu_image];
     [picture_view setImageScaling: NSImageScaleProportionallyUpOrDown];
     [superView addSubview: picture_view];
-- 
2.24.3 (Apple Git-128)



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

* [PATCH 2/2] ui/cocoa: Do not rely on the first argument
  2021-03-09 12:22 [PATCH 1/2] ui/cocoa: Show QEMU icon in the about window Akihiko Odaki
@ 2021-03-09 12:22 ` Akihiko Odaki
  2021-03-09 13:10   ` BALATON Zoltan
  2021-03-10 12:23 ` [PATCH 1/2] ui/cocoa: Show QEMU icon in the about window Gerd Hoffmann
  1 sibling, 1 reply; 8+ messages in thread
From: Akihiko Odaki @ 2021-03-09 12:22 UTC (permalink / raw)
  Cc: Peter Maydell, qemu-devel, Akihiko Odaki, Gerd Hoffmann

The first argument of the executable was used to get its path, but it is
not reliable because the executer can specify any arbitrary string. Use the
interfaces provided by QEMU and the platform to get those paths.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 ui/cocoa.m | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index d8eacea6d22..6e94301c0d6 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1414,20 +1414,21 @@ - (void)make_about_window
     [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: NSTextAlignmentCenter];
-    NSString *qemu_name = [[NSString alloc] initWithCString: gArgv[0]
-                                            encoding: NSASCIIStringEncoding];
-    qemu_name = [qemu_name lastPathComponent];
-    [name_label setStringValue: qemu_name];
-    [superView addSubview: name_label];
+    NSBundle *bundle = [NSBundle mainBundle];
+    if (bundle) {
+        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: NSTextAlignmentCenter];
+        NSString *qemu_name = [[bundle executablePath] lastPathComponent];
+        [name_label setStringValue: qemu_name];
+        [superView addSubview: name_label];
+    }
 
     /* Set the version label's attributes */
     x = 0;
-- 
2.24.3 (Apple Git-128)



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

* Re: [PATCH 2/2] ui/cocoa: Do not rely on the first argument
  2021-03-09 12:22 ` [PATCH 2/2] ui/cocoa: Do not rely on the first argument Akihiko Odaki
@ 2021-03-09 13:10   ` BALATON Zoltan
  2021-03-10  3:31     ` Akihiko Odaki
  0 siblings, 1 reply; 8+ messages in thread
From: BALATON Zoltan @ 2021-03-09 13:10 UTC (permalink / raw)
  To: Akihiko Odaki; +Cc: Peter Maydell, qemu-devel, Gerd Hoffmann

On Tue, 9 Mar 2021, Akihiko Odaki wrote:
> The first argument of the executable was used to get its path, but it is
> not reliable because the executer can specify any arbitrary string. Use the
> interfaces provided by QEMU and the platform to get those paths.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
> ---
> ui/cocoa.m | 29 +++++++++++++++--------------
> 1 file changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index d8eacea6d22..6e94301c0d6 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -1414,20 +1414,21 @@ - (void)make_about_window
>     [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: NSTextAlignmentCenter];
> -    NSString *qemu_name = [[NSString alloc] initWithCString: gArgv[0]
> -                                            encoding: NSASCIIStringEncoding];
> -    qemu_name = [qemu_name lastPathComponent];
> -    [name_label setStringValue: qemu_name];
> -    [superView addSubview: name_label];
> +    NSBundle *bundle = [NSBundle mainBundle];
> +    if (bundle) {

Does this break about window if the executable is not in a bundle (like 
when run from the command line after compiling)? Shouldn't you only put 
the qemu_name in this if and have some default name if bundle is not 
available (or fall back to argv[0] in that case?

Regards,
BALATON Zoltan

> +        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: NSTextAlignmentCenter];
> +        NSString *qemu_name = [[bundle executablePath] lastPathComponent];
> +        [name_label setStringValue: qemu_name];
> +        [superView addSubview: name_label];
> +    }
>
>     /* Set the version label's attributes */
>     x = 0;
>


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

* Re: [PATCH 2/2] ui/cocoa: Do not rely on the first argument
  2021-03-09 13:10   ` BALATON Zoltan
@ 2021-03-10  3:31     ` Akihiko Odaki
  2021-03-10 12:22       ` Gerd Hoffmann
  0 siblings, 1 reply; 8+ messages in thread
From: Akihiko Odaki @ 2021-03-10  3:31 UTC (permalink / raw)
  To: BALATON Zoltan; +Cc: Peter Maydell, qemu Developers, Gerd Hoffmann

2021年3月9日(火) 22:10 BALATON Zoltan <balaton@eik.bme.hu>:
>
> On Tue, 9 Mar 2021, Akihiko Odaki wrote:
> > The first argument of the executable was used to get its path, but it is
> > not reliable because the executer can specify any arbitrary string. Use the
> > interfaces provided by QEMU and the platform to get those paths.
> >
> > Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
> > ---
> > ui/cocoa.m | 29 +++++++++++++++--------------
> > 1 file changed, 15 insertions(+), 14 deletions(-)
> >
> > diff --git a/ui/cocoa.m b/ui/cocoa.m
> > index d8eacea6d22..6e94301c0d6 100644
> > --- a/ui/cocoa.m
> > +++ b/ui/cocoa.m
> > @@ -1414,20 +1414,21 @@ - (void)make_about_window
> >     [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: NSTextAlignmentCenter];
> > -    NSString *qemu_name = [[NSString alloc] initWithCString: gArgv[0]
> > -                                            encoding: NSASCIIStringEncoding];
> > -    qemu_name = [qemu_name lastPathComponent];
> > -    [name_label setStringValue: qemu_name];
> > -    [superView addSubview: name_label];
> > +    NSBundle *bundle = [NSBundle mainBundle];
> > +    if (bundle) {
>
> Does this break about window if the executable is not in a bundle (like
> when run from the command line after compiling)? Shouldn't you only put
> the qemu_name in this if and have some default name if bundle is not
> available (or fall back to argv[0] in that case?
>
> Regards,
> BALATON Zoltan
>

No, it just doesn't show the application name. Everything else is fine.

Regards,
Akihiko Odaki


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

* Re: [PATCH 2/2] ui/cocoa: Do not rely on the first argument
  2021-03-10  3:31     ` Akihiko Odaki
@ 2021-03-10 12:22       ` Gerd Hoffmann
  2021-03-10 15:49         ` Akihiko Odaki
  0 siblings, 1 reply; 8+ messages in thread
From: Gerd Hoffmann @ 2021-03-10 12:22 UTC (permalink / raw)
  To: Akihiko Odaki; +Cc: Peter Maydell, qemu Developers

> > > +    if (bundle) {
> >
> > Does this break about window if the executable is not in a bundle (like
> > when run from the command line after compiling)? Shouldn't you only put
> > the qemu_name in this if and have some default name if bundle is not
> > available (or fall back to argv[0] in that case?
> >
> > Regards,
> > BALATON Zoltan
> >
> 
> No, it just doesn't show the application name. Everything else is fine.

Having a fallback would still be nice, even if it is just the fixed
string "qemu".  Starting a fresh build without installing it first is
common while developing.

take care,
  Gerd



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

* Re: [PATCH 1/2] ui/cocoa: Show QEMU icon in the about window
  2021-03-09 12:22 [PATCH 1/2] ui/cocoa: Show QEMU icon in the about window Akihiko Odaki
  2021-03-09 12:22 ` [PATCH 2/2] ui/cocoa: Do not rely on the first argument Akihiko Odaki
@ 2021-03-10 12:23 ` Gerd Hoffmann
  1 sibling, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2021-03-10 12:23 UTC (permalink / raw)
  To: Akihiko Odaki; +Cc: Peter Maydell, qemu-devel

On Tue, Mar 09, 2021 at 09:22:25PM +0900, Akihiko Odaki wrote:
> Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>

Patch added to ui queue.

thanks,
  Gerd



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

* Re: [PATCH 2/2] ui/cocoa: Do not rely on the first argument
  2021-03-10 12:22       ` Gerd Hoffmann
@ 2021-03-10 15:49         ` Akihiko Odaki
  2021-03-11  8:31           ` Gerd Hoffmann
  0 siblings, 1 reply; 8+ messages in thread
From: Akihiko Odaki @ 2021-03-10 15:49 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Peter Maydell, qemu Developers

2021年3月10日(水) 21:22 Gerd Hoffmann <kraxel@redhat.com>:
>
> > > > +    if (bundle) {
> > >
> > > Does this break about window if the executable is not in a bundle (like
> > > when run from the command line after compiling)? Shouldn't you only put
> > > the qemu_name in this if and have some default name if bundle is not
> > > available (or fall back to argv[0] in that case?
> > >
> > > Regards,
> > > BALATON Zoltan
> > >
> >
> > No, it just doesn't show the application name. Everything else is fine.
>
> Having a fallback would still be nice, even if it is just the fixed
> string "qemu".  Starting a fresh build without installing it first is
> common while developing.
>
> take care,
>   Gerd
>

It shows "QEMU emulator version %s" just below. Also, it can show the
name even in a build tree without installing so it should be ok.

Regards,
Akihiko Odaki


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

* Re: [PATCH 2/2] ui/cocoa: Do not rely on the first argument
  2021-03-10 15:49         ` Akihiko Odaki
@ 2021-03-11  8:31           ` Gerd Hoffmann
  0 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2021-03-11  8:31 UTC (permalink / raw)
  To: Akihiko Odaki; +Cc: Peter Maydell, qemu Developers

  Hi,

> > Having a fallback would still be nice, even if it is just the fixed
> > string "qemu".  Starting a fresh build without installing it first is
> > common while developing.
> >
> > take care,
> >   Gerd
> >
> 
> It shows "QEMU emulator version %s" just below. Also, it can show the
> name even in a build tree without installing so it should be ok.

Fair enough.  Added to UI queue.

thanks,
  Gerd



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

end of thread, other threads:[~2021-03-11  8:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-09 12:22 [PATCH 1/2] ui/cocoa: Show QEMU icon in the about window Akihiko Odaki
2021-03-09 12:22 ` [PATCH 2/2] ui/cocoa: Do not rely on the first argument Akihiko Odaki
2021-03-09 13:10   ` BALATON Zoltan
2021-03-10  3:31     ` Akihiko Odaki
2021-03-10 12:22       ` Gerd Hoffmann
2021-03-10 15:49         ` Akihiko Odaki
2021-03-11  8:31           ` Gerd Hoffmann
2021-03-10 12:23 ` [PATCH 1/2] ui/cocoa: Show QEMU icon in the about window Gerd Hoffmann

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.