[virt-tools-list] [PATCH virt-viewer] fix character encoding on Windows platform

Qiu Wenbo qiuwenbo at kylinos.com.cn
Mon Oct 15 11:26:12 UTC 2018


Thank you. We can't use the same code path here. The code path of 
GApplication on Windows is different compared to Linux. To handle 
different file name encodings on Windows, GApplication will get its 
command line arguments through g_win32_get_command_line() which will 
return an arrary of UTF-8 encoded strings. But on Linux, GApplication 
simply get its command line  arguments through argv of the program's 
main() which is in encoded by current system locale. The only difference 
between g_option_context_parse() and g_option_context_parse_strv() is 
how they interpret their arguments. We need use 
g_option_context_parse_strv on Windows since it accept UTF-8 encoded 
strings. And we should use the original code path to handle system 
locale encoded strings on Linux.

On 2018/10/15 18:13, Christophe Fergeau wrote:
> Hey,
>
> For some reason, the patch did not get through so well (html maybe),
> blank space was missing. I'm attaching a version which should be more
> readable to this email. g_option_context_parse_strv documentation has
> more details regarding the different with g_option_context_parse, I'd
> add this to the commit log:
>
> « On Windows, the strings are expected to be in UTF-8. This is in
> contrast to g_option_context_parse() which expects them to be in the
> system codepage, which is how they are passed as argv to main(). See
> g_win32_get_command_line() for a solution. »
>
> I'm not sure we need separate win32 and linux code paths here, have you
> tried using g_option_context_parse_strv on linux, or did you keep code
> this way just to be safe?
>
> Thanks for the patch,
>
> Christophe
>
>
> On Mon, Oct 15, 2018 at 03:36:10PM +0800, 邱文博 wrote:
>> virt-viewer can't handle encoding of its command line arguments correctly on Windows. As a simple test case, simply run
>>
>>
>>
>>      remote-viewer -t "你好" spice://<target-host>:5900
>>
>>
>> on Windows and the titlebar will not display characters as we expect.
>>
>>
>>  From 5e52e3a2a292e9a663fc9ba6560603df5aca66b7 Mon Sep 17 00:00:00 2001 From: root <root at localhost.localdomain> Date: Mon, 15 Oct 2018 10:30:01 +0800 Subject: [PATCH] win32: fix command line encoding on windows platform ---  configure.ac          | 4 ++--  src/virt-viewer-app.c | 4 ++++  2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index d5eb258..08fc75e 100644 --- a/configure.ac +++ b/configure.ac @@ -13,8 +13,8 @@ m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])  AM_SILENT_RULES([yes])    # Keep these two definitions in agreement. -GLIB2_REQUIRED="2.38" -GLIB2_ENCODED_VERSION="GLIB_VERSION_2_38" +GLIB2_REQUIRED="2.40" +GLIB2_ENCODED_VERSION="GLIB_VERSION_2_40"    # Keep these two definitions in agreement.  GTK_REQUIRED="3.12" diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c index 2a88882..08fb234 100644 --- a/src/virt-viewer-app.c +++ b/src/virt-viewer-app.c @@ -1882,7 +1882,11 @@ virt_viewer_app_local_command_line (GApplication   *gapp,      g_option_context_add_group(context, spice_get_option_group());  #endif   +#ifndef G_OS_WIN32      if (!g_option_context_parse(context, &argc, args, &error)) { +#else +    if (!g_option_context_parse_strv(context, args, &error)) { +#endif          if (error != NULL) {              g_printerr(_("%s\n"), error->message);              g_error_free(error); --  2.17.2
>> _______________________________________________
>> virt-tools-list mailing list
>> virt-tools-list at redhat.com
>> https://www.redhat.com/mailman/listinfo/virt-tools-list







More information about the virt-tools-list mailing list