From 50b929ea48d22ae257ba95dd0f71a4ca620afd70 Mon Sep 17 00:00:00 2001
From: Roman Telezhynskyi <kroluku@gmail.com>
Date: Thu, 28 Nov 2019 16:42:06 +0200
Subject: [PATCH] u_setDataDirectory to define path to ICU data.

--HG--
branch : develop
---
 src/app/tape/main.cpp                          |  8 +++-----
 src/app/tape/tape.pro                          |  4 ++++
 src/app/valentina/main.cpp                     |  8 +++-----
 src/app/valentina/valentina.pro                |  4 ++++
 src/libs/vmisc/vabstractapplication.cpp        | 12 ++++++++++--
 src/libs/vmisc/vabstractapplication.h          |  2 ++
 src/test/CollectionTest/CollectionTest.pro     |  4 ++++
 src/test/TranslationsTest/TranslationsTest.pro |  4 ++++
 src/test/ValentinaTest/ValentinaTest.pro       |  4 ++++
 9 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/src/app/tape/main.cpp b/src/app/tape/main.cpp
index 829cfa91c..044abbbd5 100644
--- a/src/app/tape/main.cpp
+++ b/src/app/tape/main.cpp
@@ -43,9 +43,7 @@ int main(int argc, char *argv[])
     Q_INIT_RESOURCE(flags);
     Q_INIT_RESOURCE(style);
 
-    QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations
-
-#if defined(APPIMAGE)
+#if defined(APPIMAGE) && defined(Q_OS_LINUX)
     /* When deploying with AppImage based on OpenSuse, the ICU library has a hardcoded path to the icudt*.dat file.
      * This prevents the library from using shared in memory data. There are few ways to resolve this issue. According
      * to documentation we can either use ICU_DATA environment variable or the function u_setDataDirectory().
@@ -53,6 +51,8 @@ int main(int argc, char *argv[])
     VAbstractApplication::SetICUData(argc, argv);
 #endif
 
+    QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations
+
 #if defined(Q_OS_WIN)
     VAbstractApplication::WinAttachConsole();
 #endif
@@ -64,8 +64,6 @@ int main(int argc, char *argv[])
     MApplication app(argc, argv);
     app.InitOptions();
 
-    qDebug() << "ICU_DATA: " << qgetenv("ICU_DATA");
-
     if (FvUpdater::IsStaledTestBuild())
     {
         qWarning() << QApplication::translate("Tape",
diff --git a/src/app/tape/tape.pro b/src/app/tape/tape.pro
index 7fa078bfe..afd214e9f 100644
--- a/src/app/tape/tape.pro
+++ b/src/app/tape/tape.pro
@@ -430,6 +430,10 @@ else:unix: LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpro
 INCLUDEPATH += $${PWD}/../../libs/vpropertyexplorer
 DEPENDPATH += $${PWD}/../../libs/vpropertyexplorer
 
+contains(DEFINES, APPIMAGE) {
+    unix:!macx: LIBS += -licudata -licui18n -licuuc
+}
+
 noDebugSymbols{ # For enable run qmake with CONFIG+=noDebugSymbols
     # do nothing
 } else {
diff --git a/src/app/valentina/main.cpp b/src/app/valentina/main.cpp
index c856a3110..fe53daa82 100644
--- a/src/app/valentina/main.cpp
+++ b/src/app/valentina/main.cpp
@@ -47,9 +47,7 @@ int main(int argc, char *argv[])
     Q_INIT_RESOURCE(toolicon);
     Q_INIT_RESOURCE(style);
 
-    QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations
-
-#if defined(APPIMAGE)
+#if defined(APPIMAGE) && defined(Q_OS_LINUX)
     /* When deploying with AppImage based on OpenSuse, the ICU library has a hardcoded path to the icudt*.dat file.
      * This prevents the library from using shared in memory data. There are few ways to resolve this issue. According
      * to documentation we can either use ICU_DATA environment variable or the function u_setDataDirectory().
@@ -57,6 +55,8 @@ int main(int argc, char *argv[])
     VAbstractApplication::SetICUData(argc, argv);
 #endif
 
+    QT_REQUIRE_VERSION(argc, argv, "5.4.0")// clazy:exclude=qstring-arg,qstring-allocations
+
 #if defined(Q_OS_WIN)
     VAbstractApplication::WinAttachConsole();
 #endif
@@ -73,8 +73,6 @@ int main(int argc, char *argv[])
     VApplication app(argc, argv);
     app.InitOptions();
 
-    qDebug() << "ICU_DATA: " << qgetenv("ICU_DATA");
-
     if (FvUpdater::IsStaledTestBuild())
     {
         qWarning() << QApplication::translate("Valentina",
diff --git a/src/app/valentina/valentina.pro b/src/app/valentina/valentina.pro
index 222b885d7..0d888987b 100644
--- a/src/app/valentina/valentina.pro
+++ b/src/app/valentina/valentina.pro
@@ -682,6 +682,10 @@ else:unix: LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpro
 INCLUDEPATH += $${PWD}/../../libs/vpropertyexplorer
 DEPENDPATH += $${PWD}/../../libs/vpropertyexplorer
 
+contains(DEFINES, APPIMAGE) {
+    unix:!macx: LIBS += -licudata -licui18n -licuuc
+}
+
 noDebugSymbols{ # For enable run qmake with CONFIG+=noDebugSymbols
     # do nothing
 } else {
diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp
index 5d1a6bf62..0838a048d 100644
--- a/src/libs/vmisc/vabstractapplication.cpp
+++ b/src/libs/vmisc/vabstractapplication.cpp
@@ -49,9 +49,14 @@
 #  include <unistd.h>
 #endif
 
+#if defined(APPIMAGE) && defined(Q_OS_LINUX)
+#   include "unicode/putil.h"
+#endif
+
 namespace
 {
-QString ApplicationFilePath(int &argc, char **argv)
+#if defined(APPIMAGE) && defined(Q_OS_LINUX)
+QString ApplicationFilePath(const int &argc, char **argv)
 {
     if (argc)
     {
@@ -109,6 +114,7 @@ QString ApplicationFilePath(int &argc, char **argv)
 #endif
     return QString();
 }
+#endif // defined(APPIMAGE) && defined(Q_OS_LINUX)
 }
 
 const QString VAbstractApplication::patternMessageSignature = QStringLiteral("[PATTERN MESSAGE]");
@@ -340,6 +346,7 @@ bool VAbstractApplication::IsPatternMessage(const QString &message) const
     return VAbstractApplication::ClearMessage(message).startsWith(patternMessageSignature);
 }
 
+#if defined(APPIMAGE) && defined(Q_OS_LINUX)
 //---------------------------------------------------------------------------------------------------------------------
 void VAbstractApplication::SetICUData(int &argc, char **argv)
 {
@@ -348,8 +355,9 @@ void VAbstractApplication::SetICUData(int &argc, char **argv)
      * to documentation we can either use ICU_DATA environment variable or the function u_setDataDirectory().
      */
     const QString appDirPath = QFileInfo(ApplicationFilePath(argc, argv)).path();
-    qputenv("ICU_DATA", QString(appDirPath + QStringLiteral("/../share/icu")).toUtf8());
+    u_setDataDirectory(QString(appDirPath + QStringLiteral("/../share/icu")).toUtf8());
 }
+#endif // defined(Q_OS_LINUX)
 
 //---------------------------------------------------------------------------------------------------------------------
 #if defined(Q_OS_WIN)
diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h
index 7784dbc17..a77492a60 100644
--- a/src/libs/vmisc/vabstractapplication.h
+++ b/src/libs/vmisc/vabstractapplication.h
@@ -129,7 +129,9 @@ public:
     static const QString patternMessageSignature;
     bool IsPatternMessage(const QString &message) const;
 
+#if defined(APPIMAGE) && defined(Q_OS_LINUX)
     static void SetICUData(int &argc, char ** argv);
+#endif
 
 protected:
     QUndoStack         *undoStack;
diff --git a/src/test/CollectionTest/CollectionTest.pro b/src/test/CollectionTest/CollectionTest.pro
index 691c665cf..96891b7f3 100644
--- a/src/test/CollectionTest/CollectionTest.pro
+++ b/src/test/CollectionTest/CollectionTest.pro
@@ -188,6 +188,10 @@ else:unix: LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpro
 INCLUDEPATH += $${PWD}/../../libs/vpropertyexplorer
 DEPENDPATH += $${PWD}/../../libs/vpropertyexplorer
 
+contains(DEFINES, APPIMAGE) {
+    unix:!macx: LIBS += -licudata -licui18n -licuuc
+}
+
 TAPE_TEST_FILES += \
     tst_tape/keiko.vit \
     tst_tape/empty.vit \
diff --git a/src/test/TranslationsTest/TranslationsTest.pro b/src/test/TranslationsTest/TranslationsTest.pro
index 952b38671..8727ea9ac 100644
--- a/src/test/TranslationsTest/TranslationsTest.pro
+++ b/src/test/TranslationsTest/TranslationsTest.pro
@@ -163,3 +163,7 @@ else:unix: LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser
 
 INCLUDEPATH += $${PWD}/../../libs/qmuparser
 DEPENDPATH += $${PWD}/../../libs/qmuparser
+
+contains(DEFINES, APPIMAGE) {
+    unix:!macx: LIBS += -licudata -licui18n -licuuc
+}
diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro
index 64ad14e1f..b09fd98ad 100644
--- a/src/test/ValentinaTest/ValentinaTest.pro
+++ b/src/test/ValentinaTest/ValentinaTest.pro
@@ -226,6 +226,10 @@ else:unix: LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpro
 INCLUDEPATH += $${PWD}/../../libs/vpropertyexplorer
 DEPENDPATH += $${PWD}/../../libs/vpropertyexplorer
 
+contains(DEFINES, APPIMAGE) {
+    unix:!macx: LIBS += -licudata -licui18n -licuuc
+}
+
 DATA_RESOURCE = share/test_data.qrc # External Binary Resource
 
 !exists($${OUT_PWD}/$${DESTDIR}/test_data.rcc) {