Qt: Make sure we have usable command line arguments.
authorGerald Combs <gerald@wireshark.org>
Tue, 16 Jun 2015 18:55:09 +0000 (11:55 -0700)
committerGerald Combs <gerald@wireshark.org>
Tue, 16 Jun 2015 18:58:54 +0000 (18:58 +0000)
Call arg_list_utf_16to8 in wireshark-qt.cpp on Windows. Set our default
codec in Qt4 to UTF-8 before doing so.

Bug: 11276
Change-Id: I8e0afb9523ddb5956d30424b7b7ad7f3ea0838c7
Reviewed-on: https://code.wireshark.org/review/8954
Reviewed-by: Gerald Combs <gerald@wireshark.org>
wireshark-qt.cpp
wsutil/unicode-utils.h

index aa2859bec4e28b8a40a795a1baa90005de45128a..4fdb22d15c615d0811f4c4e5a7f56358832c0662 100644 (file)
@@ -49,6 +49,7 @@
 #endif
 #include <wsutil/report_err.h>
 #include <wsutil/u3.h>
+#include <wsutil/unicode-utils.h>
 #include <wsutil/ws_diag_control.h>
 #include <wsutil/ws_version_info.h>
 
@@ -463,9 +464,23 @@ int main(int argc, char *argv[])
 
     cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont);
 
+    // In Qt 5, C strings are treated always as UTF-8 when converted to
+    // QStrings; in Qt 4, the codec must be set to make that happen
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
+    // Hopefully we won't have to use QString::fromUtf8() in as many places.
+    QTextCodec *utf8codec = QTextCodec::codecForName("UTF-8");
+    QTextCodec::setCodecForCStrings(utf8codec);
+    // XXX - QObject doesn't *have* a tr method in 5.0, as far as I can see...
+    QTextCodec::setCodecForTr(utf8codec);
+#endif
+
+    /* Set the C-language locale to the native environment. */
+    // The GTK+ UI calls this. Should we as well?
+    //setlocale(LC_ALL, "");
 #ifdef _WIN32
+    arg_list_utf_16to8(argc, argv);
     create_app_running_mutex();
-#endif
+#endif /* _WIN32 */
 
     /*
      * Get credential information for later use, and drop privileges
@@ -685,16 +700,6 @@ DIAG_ON(cast-qual)
     QString cf_name;
     unsigned int in_file_type = WTAP_TYPE_AUTO;
 
-    // In Qt 5, C strings are treated always as UTF-8 when converted to
-    // QStrings; in Qt 4, the codec must be set to make that happen
-#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
-    // Hopefully we won't have to use QString::fromUtf8() in as many places.
-    QTextCodec *utf8codec = QTextCodec::codecForName("UTF-8");
-    QTextCodec::setCodecForCStrings(utf8codec);
-    // XXX - QObject doesn't *have* a tr method in 5.0, as far as I can see...
-    QTextCodec::setCodecForTr(utf8codec);
-#endif
-
     /* Add it to the information to be reported on a crash. */
     ws_add_crash_info("Wireshark %s\n"
            "\n"
index 83fa2bda67000ae863432b72225544169007fdcf..865563e231bc9e66124c23d880beac99c7108405 100644 (file)
  * Unicode convenience routines.
  */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 WS_DLL_PUBLIC
 int ws_utf8_char_len(guint8 ch);
 
@@ -99,4 +103,8 @@ void arg_list_utf_16to8(int argc, char *argv[]);
 #define SURROGATE_VALUE(lead, trail) \
        (((((lead) - 0xd800) << 10) | ((trail) - 0xdc00)) + 0x100000)
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __UNICODEUTIL_H__ */