From 7de925ef4a48c77370ca73105c8dbde7f8567d5d Mon Sep 17 00:00:00 2001 From: hama Date: Fri, 19 Feb 2016 00:22:59 +0100 Subject: [PATCH] rebackgui speaks German --- appl/rebackgui/main.cpp | 2 +- appl/rebackgui/mainwindow.cpp | 5 +- appl/rebackgui/mainwindow.hpp | 3 +- appl/rebackgui/rebackgui.de.qm | Bin 0 -> 21328 bytes .../{rebackgui_de.ts => rebackgui.de.ts} | 0 gui/ReGuiApplication.cpp | 119 +++++++++++++++--- gui/ReGuiApplication.hpp | 17 ++- gui/regui.hpp | 1 + 8 files changed, 121 insertions(+), 26 deletions(-) create mode 100644 appl/rebackgui/rebackgui.de.qm rename appl/rebackgui/{rebackgui_de.ts => rebackgui.de.ts} (100%) diff --git a/appl/rebackgui/main.cpp b/appl/rebackgui/main.cpp index 0d45da3..bfa513e 100644 --- a/appl/rebackgui/main.cpp +++ b/appl/rebackgui/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char *argv[]){ g_argv = argv; QString homeDir = argc > 1 ? argv[1] : ""; QApplication a(argc, argv); - MainWindow w(homeDir); + MainWindow w(a, homeDir); w.show(); return a.exec(); } diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index 2ab0460..00c035d 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -21,8 +21,9 @@ const QString VERSION("2016.02.17"); * @param homeDir the home directory. If "": usage of the user's homedir * @param parent QT parent or NULL */ -MainWindow::MainWindow(const QString& homeDir, QWidget *parent) : - ReGuiApplication("rebackupgui", homeDir, 2, 100100100, parent), +MainWindow::MainWindow(QApplication& application, const QString& homeDir, + QWidget *parent) : + ReGuiApplication(application, "rebackupgui", homeDir, 2, 100100100, "de", parent), ReGuiValidator(), ui(new Ui::MainWindow), m_configuration(this), diff --git a/appl/rebackgui/mainwindow.hpp b/appl/rebackgui/mainwindow.hpp index b043ff4..4560a55 100644 --- a/appl/rebackgui/mainwindow.hpp +++ b/appl/rebackgui/mainwindow.hpp @@ -23,7 +23,8 @@ class MainWindow : public ReGuiApplication, public ReGuiValidator Q_OBJECT public: - explicit MainWindow(const QString& homeDir, QWidget *parent = 0); + explicit MainWindow(QApplication& application, const QString& homeDir, + QWidget *parent = 0); ~MainWindow(); public: void addToFileList(const QString info); diff --git a/appl/rebackgui/rebackgui.de.qm b/appl/rebackgui/rebackgui.de.qm new file mode 100644 index 0000000000000000000000000000000000000000..278cbd6ddff36469e29f310bf3b0393dba6ce6f7 GIT binary patch literal 21328 zcmeHPdvIJ=c|W!#*Ds&Z zZtmW-BvWXC>6AyHEp3xw+G(3~XhRri+72y+0YXC`WXM2hnEp}di%|NYl$lcKbTZK2 z@0|PE-Mg}*IHsP)vi5QBIp6tS=R4o)YT}cnS3mt9zy7Pw?0DVh?tkPn-L{n7h{*tbD!OnpX( zLsyFarJu*R4~m-~`hpNclj7DrZxiTCs|36q~d_&ih9~0u{(uVAw-@^BQ*l^RAK970#Y&i7BF(C@M4bOiYaNjh! z;k$#ttMEYA*(dG;U8nH=XL$d$u6N#aP>9S!UBB_ZKM^ALc-L<}Xb5rBO4k=3`em%Q zuIsN~`>+t#cXxf`N$}+jXS#R({uM%`zurCiL%dHg(=Qajhfnt0ZGRK^e5vRD&w{?$7kb|RwZ8|Srh6X# zIebrV?fKdO=otTWk6!QTp6?hx0^i@)^W86hP>3Dx*f{#puYw=n-}s?VOCfGOweitE z_%9){S8jab{uJ=|)W&b09l^TUO^bW>3Ly{a_v@b9^s$FOi}9b>^xcR5REWu;&F}ao z=$n3a^WXjy=pHswmw)JAgt#G{8hj3VvG2pF{eSs3tov+gq3;>+>FLzFzrGuEiPRTv z_#*C)r+)ND|B7|*-}2x_&^5kg%cI}?ZSe0~TRwI7Ph*_3<*B~sz_*iIzV`(9wCjeg z*B#j)#Ll;G-Cce}h$Gi-E&TX4wJz2Mh@_xE0V*9U|c z{CMvTub;*`pXi-<9CDt0Yj0^i_&fZX-lg{d{=_GGfBfE)(5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-0T)0y*^%P4p;V4J7V*DyVS{|4NCq$+q5r-LRX#{S(`D1D zA5TyFt^r0-4Mwqf*as4+L0;`c2!`cnxKt(S*p(HeVOe=Uw=2W@+FoFPf1#g=@CLkVSwhX8UbbToNi(;Qll`ahD9P|} ze}bAEN1{u&NH9F8DEDI&%O68Xr4c-fPt2LY&Hk zTZ8~cWzAVax*aD7N;YT%3@{tLZ|uJD{x(&4HMS&qL|e?%grWEur@T*Vo873+n{EPO z>?VmI+^ih-v*2nwq{|c}8|?GUg+y38k&ufz4;ewkyF6Mw)Lz0hCM6JSdLy^>x9b%3}2I9O*~9PX!WZV`ZCsuR^9!C5lyDDaiKh2uavGKeHOrhohfUk(YSS+Jc?4D`b>@Rc zxxPsL!hy&0S!`of$B#~fj56L=52)$zh+2k`o>9T4aanK7s~jp@y<2*`FVjoSHTRT0 z(Zp~%P{DDtHWmkMa2m>sXP%yMKCHXLXWcm&rkZ--e4Ib4QUR;b4*zcG>iTu-{ukSf B|H1$O literal 0 HcmV?d00001 diff --git a/appl/rebackgui/rebackgui_de.ts b/appl/rebackgui/rebackgui.de.ts similarity index 100% rename from appl/rebackgui/rebackgui_de.ts rename to appl/rebackgui/rebackgui.de.ts diff --git a/gui/ReGuiApplication.cpp b/gui/ReGuiApplication.cpp index 131bd68..ebe26ec 100644 --- a/gui/ReGuiApplication.cpp +++ b/gui/ReGuiApplication.cpp @@ -27,11 +27,13 @@ enum { * directory * @param maxLogFiles max. count of (rotating) log files * @param maxLogSize max. size of the (rotating) log files + * @param languages a comma separated list of supported languages, + * e.g. "de,fr" */ -ReGuiApplication::ReGuiApplication(const char* applicationName, - const QString& homeDirBase, - int maxLogFiles, int maxLogSize, - QWidget *parent = NULL) : +ReGuiApplication::ReGuiApplication(QApplication& application, + const char* applicationName,const QString& homeDirBase, + int maxLogFiles, int maxLogSize, const QString& languages = "de", + QWidget *parent = NULL) : QMainWindow(parent), m_applicationName(applicationName), m_homeDir(buildHomeDir(homeDirBase, ".reappl")), @@ -40,12 +42,21 @@ ReGuiApplication::ReGuiApplication(const char* applicationName, m_guiQueue(), m_guiTimer(new QTimer(this)), m_statusMessage(new QLabel(tr("Welcome!"))), - m_mutexGuiQueue() + m_mutexGuiQueue(), + m_application(application), + m_currentTranslator(NULL), + m_translators(), + m_languages(languages), + m_installPath() + { + m_installPath = QDir(ReFileUtils::parentOf(m_application.arguments().at(0))) + .absolutePath(); m_logger.buildStandardAppender(I18N::s2b(m_homeDir) + applicationName, maxLogSize, maxLogFiles); m_storageFile = m_homeDir + applicationName + ".state.conf"; m_logger.log(LOG_INFO, LOC_CONSTRUCTOR_1, "start"); + initializeLanguage(""); } /** @@ -107,19 +118,6 @@ void ReGuiApplication::externalTaskFinished(const QString& message){ m_mutexGuiQueue.unlock(); } -/** - * Initializes the GUI elements of this class. - * - * Should be called after initializing the formular (ui->setupUi()). - */ -void ReGuiApplication::initializeGuiElements(){ - QCoreApplication* app = QCoreApplication::instance(); - QObject::connect(app, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit())); - connect(m_guiTimer, SIGNAL(timeout()), this, SLOT(onGuiTimerUpdate())); - m_guiTimer->start(100); - statusBar()->addWidget(m_statusMessage); -} - /** * Returns the application's name. * @@ -187,6 +185,63 @@ void ReGuiApplication::externalLog(const QString& message){ m_mutexGuiQueue.unlock(); } +/** + * Initializes the GUI elements of this class. + * + * Should be called after initializing the formular (ui->setupUi()). + */ +void ReGuiApplication::initializeGuiElements(){ + QCoreApplication* app = QCoreApplication::instance(); + QObject::connect(app, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit())); + connect(m_guiTimer, SIGNAL(timeout()), this, SLOT(onGuiTimerUpdate())); + m_guiTimer->start(100); + statusBar()->addWidget(m_statusMessage); +} + +/** + * Initializes the possibility to switch the GUI language. + */ +void ReGuiApplication::initializeLanguage(const QString& language) +{ + if (language.isEmpty()){ + QStringList languages = m_languages.split(','); + for (int ix = 0; ix < languages.count(); ix++){ + QString lang = languages.at(ix); + if (lang != "en") + initializeLanguage(lang); + } + QLocale locale; + QString lang = locale.name(); + if (lang.length() == 5) + switchLanguage(lang.mid(0, 2)); + if (m_currentTranslator == NULL) + switchLanguage(lang); + } else { + QTranslator* translator = new QTranslator(); + QString fn = QString(m_applicationName) + "." + language; + if (translator->load(fn, m_installPath)){ + // found, nothing to do + } else if (translator->load(fn, m_homeDir)){ + // found, nothing to do + } else { + // forget it: + delete translator; + translator = NULL; + } + if (translator != NULL) + m_translators.insert(language, translator); + } +} + +/** + * Returns the path of the program file. + * @return the path of the program file + */ +const QString& ReGuiApplication::installPath() const +{ + return m_installPath; +} + /** * Writes a text to the status line. * @@ -207,3 +262,31 @@ void ReGuiApplication::setStatusMessage(ReLoggerLevel level, const QString& mess } } +/** + * Switch the GUI language. + * + * @param language + */ +void ReGuiApplication::switchLanguage(const QString& language){ + if (language == "en"){ + if (m_currentTranslator != NULL){ + m_application.removeTranslator(m_currentTranslator); + m_currentTranslator = NULL; + } + } else { + QString lang = language; + QTranslator* translator = NULL; + if (m_translators.contains(lang)){ + translator = m_translators.value(lang); + } else if (lang.length() == 5 && lang.at(2) == '_'){ + lang = lang.mid(0, 2); + if (m_translators.contains(lang)){ + translator = m_translators.value(lang); + } + } + if (translator != NULL){ + m_currentTranslator = translator; + m_application.installTranslator(translator); + } + } +} diff --git a/gui/ReGuiApplication.hpp b/gui/ReGuiApplication.hpp index 0d6c7bf..449c400 100644 --- a/gui/ReGuiApplication.hpp +++ b/gui/ReGuiApplication.hpp @@ -19,9 +19,9 @@ */ class ReGuiApplication : public QMainWindow{ public: - ReGuiApplication(const char* applicationName, + ReGuiApplication(QApplication& application, const char* applicationName, const QString& homeDir, int maxLogFiles, int maxLogSize, - QWidget *parent); + const QString& languages, QWidget *parent); public: const QByteArray& applicationName() const; QString fileOfHome(const QString& node); @@ -29,12 +29,16 @@ public: void externalError(const QString& message); void externalLog(const QString& message); void externalTaskFinished(const QString& message); + const QString& installPath() const; ReLogger* logger(); + void setStatusMessage(ReLoggerLevel level, const QString& message); + void switchLanguage(const QString& language); public: static QString buildHomeDir(QString homeDirBase, const QString& node); - void setStatusMessage(ReLoggerLevel level, const QString& message); + protected: void initializeGuiElements(); + void initializeLanguage(const QString& language); protected slots: /** * Reads the m_guiQueue. @@ -52,7 +56,12 @@ protected: QTimer* m_guiTimer; QLabel* m_statusMessage; QMutex m_mutexGuiQueue; - + QApplication& m_application; + QTranslator* m_currentTranslator; + QHash m_translators; + QString m_languages; + // Path of the program file + QString m_installPath; }; #endif /* REGUIAPPLICATION_HPP_ */ diff --git a/gui/regui.hpp b/gui/regui.hpp index 8e8f9e7..b65228f 100644 --- a/gui/regui.hpp +++ b/gui/regui.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "gui/ReGuiUtils.hpp" #include "gui/ReGuiQueue.hpp" #include "gui/ReStateStorage.hpp" -- 2.39.5