From a5b208eeda7537f47fc904180ce744360da5a22c Mon Sep 17 00:00:00 2001 From: SimplestStudio Date: Tue, 3 Oct 2023 06:46:52 +0300 Subject: [PATCH] [win-linux] fix language switching on the start page --- .../update-daemon/src/classes/csvcmanager.cpp | 13 +- .../src/cascapplicationmanagerwrapper.cpp | 4 + win-linux/src/cupdatemanager.cpp | 119 ++++++++++++------ win-linux/src/cupdatemanager.h | 17 ++- 4 files changed, 106 insertions(+), 47 deletions(-) diff --git a/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp b/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp index df77bb364..b6d751e54 100644 --- a/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp +++ b/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp @@ -278,8 +278,7 @@ void CSvcManager::onCompleteUnzip(const int error) } else if (error == UNZIP_ERROR) { - tstring error(_T("An error occured while unpacking the archive")); - if (!m_socket->sendMessage(MSG_OtherError, error)) + if (!m_socket->sendMessage(MSG_OtherError, _T("SVC_TXT_ERR_UNPACKING"))) NS_Logger::WriteLog(DEFAULT_ERROR_MESSAGE); } else @@ -307,18 +306,18 @@ void CSvcManager::onCompleteSlot(const int error, const tstring &filePath) // Pause or Stop } else if (error == -1) { - m_socket->sendMessage(MSG_OtherError, _T("Update download failed: out of memory!")); + m_socket->sendMessage(MSG_OtherError, _T("SVC_TXT_ERR_DNL_OUT_MEM")); } else if (error == -2) { - m_socket->sendMessage(MSG_OtherError, _T("Update download failed: server connection error!")); + m_socket->sendMessage(MSG_OtherError, _T("SVC_TXT_ERR_DNL_CONN")); } else if (error == -3) { - m_socket->sendMessage(MSG_OtherError, _T("Update download failed: wrong URL!")); + m_socket->sendMessage(MSG_OtherError, _T("SVC_TXT_ERR_DNL_URL")); } else if (error == -4) { - m_socket->sendMessage(MSG_OtherError, _T("Update download failed: unable to create file!")); + m_socket->sendMessage(MSG_OtherError, _T("SVC_TXT_ERR_DNL_CREAT")); } else { - m_socket->sendMessage(MSG_OtherError, _T("Update download failed: network error!")); + m_socket->sendMessage(MSG_OtherError, _T("SVC_TXT_ERR_DNL_INET")); } } diff --git a/win-linux/src/cascapplicationmanagerwrapper.cpp b/win-linux/src/cascapplicationmanagerwrapper.cpp index c7e68a906..23cf84d98 100644 --- a/win-linux/src/cascapplicationmanagerwrapper.cpp +++ b/win-linux/src/cascapplicationmanagerwrapper.cpp @@ -1610,6 +1610,10 @@ bool CAscApplicationManagerWrapper::applySettings(const wstring& wstrjson) _reg_user.setValue("locale", _lang_id); CLangater::reloadTranslations(_lang_id); +#ifdef _UPDMODULE + if (m_pUpdateManager) + m_pUpdateManager->refreshStartPage(); +#endif } } diff --git a/win-linux/src/cupdatemanager.cpp b/win-linux/src/cupdatemanager.cpp index d1219a0e5..0cd1f65c5 100644 --- a/win-linux/src/cupdatemanager.cpp +++ b/win-linux/src/cupdatemanager.cpp @@ -74,6 +74,35 @@ using std::vector; +const char *SVC_TXT_ERR_UNPACKING = QT_TRANSLATE_NOOP("CUpdateManager", "An error occured while unpacking the archive"), + *SVC_TXT_ERR_DNL_OUT_MEM = QT_TRANSLATE_NOOP("CUpdateManager", "Update download failed: out of memory!"), + *SVC_TXT_ERR_DNL_CONN = QT_TRANSLATE_NOOP("CUpdateManager", "Update download failed: server connection error!"), + *SVC_TXT_ERR_DNL_URL = QT_TRANSLATE_NOOP("CUpdateManager", "Update download failed: wrong URL!"), + *SVC_TXT_ERR_DNL_CREAT = QT_TRANSLATE_NOOP("CUpdateManager", "Update download failed: unable to create file!"), + *SVC_TXT_ERR_DNL_INET = QT_TRANSLATE_NOOP("CUpdateManager", "Update download failed: network error!"), + *SVC_TXT_ERR_OTHER = QT_TRANSLATE_NOOP("CUpdateManager", "A service error has occurred!"), + + *TXT_LAST_CHECK = QT_TRANSLATE_NOOP("CUpdateManager", "Last check performed %1"), + *TXT_UPDATED = QT_TRANSLATE_NOOP("CUpdateManager", "Current version is up to date"), + *TXT_CHECKING_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Checking for updates..."), + *TXT_AVAILABLE_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Update is available (version %1)"), + *TXT_DOWNLOADING_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Downloading new version %1 (%2%)"), + *TXT_PREPARING_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Preparing update..."), + *TXT_RESTART_TO_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "To finish updating, restart app"), + *TXT_ERR_NOT_ALLOWED = QT_TRANSLATE_NOOP("CUpdateManager", "Updates are not allowed!"), + *TXT_ERR_URL = QT_TRANSLATE_NOOP("CUpdateManager", "Unable to check update: URL not defined."), + *TXT_ERR_PACK_URL = QT_TRANSLATE_NOOP("CUpdateManager", "An error occurred while loading updates: package Url is empty!"), + *TXT_ERR_CHECK = QT_TRANSLATE_NOOP("CUpdateManager", "An error occurred while check updates: Update Service not found!"), + *TXT_ERR_LOAD = QT_TRANSLATE_NOOP("CUpdateManager", "An error occurred while loading updates: Update Service not found!"), + *TXT_ERR_UNZIP = QT_TRANSLATE_NOOP("CUpdateManager", "An error occurred while unzip updates: Update Service not found!"), + *TXT_ERR_JSON = QT_TRANSLATE_NOOP("CUpdateManager", "Error opening JSON file."), + *TXT_ERR_MD5 = QT_TRANSLATE_NOOP("CUpdateManager", "Update package error: md5 sum does not match the original."), + + *BTN_TXT_CHECK = QT_TRANSLATE_NOOP("CUpdateManager", "Check for updates"), + *BTN_TXT_DOWNLOAD = QT_TRANSLATE_NOOP("CUpdateManager", "Download update"), + *BTN_TXT_RESTART = QT_TRANSLATE_NOOP("CUpdateManager", "Restart"), + *BTN_TXT_CANCEL = QT_TRANSLATE_NOOP("CUpdateManager", "Cancel"); + class CUpdateManager::DialogSchedule : public QObject { Q_OBJECT @@ -111,7 +140,7 @@ CUpdateManager::DialogSchedule::DialogSchedule(QObject *owner) : m_shedule_vec.removeFirst(); if (m_shedule_vec.isEmpty()) { m_timer->stop(); - qobject_cast(owner)->refreshStartPage({"", "", "", "", "false"}); + qobject_cast(owner)->refreshStartPage({"", {}, nullptr, "", "false"}); } } }); @@ -122,7 +151,7 @@ void CUpdateManager::DialogSchedule::addToSchedule(const QString &method, const m_shedule_vec.push_back({method, text}); if (!m_timer->isActive()) { m_timer->start(); - qobject_cast(m_owner)->refreshStartPage({"", "", "", "", "true"}); + qobject_cast(m_owner)->refreshStartPage({"", {}, nullptr, "", "true"}); } } @@ -252,14 +281,14 @@ CUpdateManager::CUpdateManager(QObject *parent): m_pLastCheckMsgTimer->setSingleShot(true); m_pLastCheckMsgTimer->setInterval(RESET_MESSAGE_MS); connect(m_pLastCheckMsgTimer, &QTimer::timeout, this, [=]() { - refreshStartPage({"lastcheck", tr("Last check performed ") + formattedTime(m_lastCheck)}); + refreshStartPage({"lastcheck", {TXT_LAST_CHECK, formattedTime(m_lastCheck)}}); }); if (IsPackage(Portable)) runProcess(QStrToTStr(qApp->applicationDirPath()) + DAEMON_NAME, _T("--run-as-app")); init(); } else { CLogger::log("Updates is off, URL is empty."); - refreshStartPage({"error", tr("Unable to check update: URL not defined."), tr("Check for updates"), "", "true"}); + refreshStartPage({"error", {TXT_ERR_URL}, BTN_TXT_CHECK, "", "true"}); } } @@ -284,8 +313,7 @@ void CUpdateManager::init() m_savedPackageData->fileType = reg_user.value("type", QString()).toString(); m_savedPackageData->version = reg_user.value("version", QString()).toString(); m_lastCheck = time_t(reg_user.value("last_check", 0).toLongLong()); - refreshStartPage({"lastcheck", tr("Last check performed ") + formattedTime(m_lastCheck), - tr("Check for updates"), "check", "false"}); + refreshStartPage({"lastcheck", {TXT_LAST_CHECK, formattedTime(m_lastCheck)}, BTN_TXT_CHECK, "check", "false"}); m_interval = reg_user.value("interval", DAY_TO_SEC).toInt(); if (m_interval < MINIMUM_INTERVAL) m_interval = MINIMUM_INTERVAL; @@ -304,7 +332,7 @@ void CUpdateManager::init() break; case MSG_ShowStartInstallMessage: { - refreshStartPage({"success", tr("To finish updating, restart app"), tr("Restart"), "install", "false"}); + refreshStartPage({"success", {TXT_RESTART_TO_UPD}, BTN_TXT_RESTART, "install", "false"}); QMetaObject::invokeMethod(m_dialogSchedule, "addToSchedule", Qt::QueuedConnection, Q_ARG(QString, QString("showStartInstallMessage"))); break; } @@ -364,13 +392,13 @@ void CUpdateManager::checkUpdates(bool manualCheck) __GLOBAL_LOCK - refreshStartPage({"load", tr("Checking for updates..."), tr("Check for updates"), "check", "true"}); + refreshStartPage({"load", {TXT_CHECKING_UPD}, BTN_TXT_CHECK, "check", "true"}); m_manualCheck = manualCheck; m_packageData->clear(); #ifdef CHECK_DIRECTORY if (QFileInfo(qApp->applicationDirPath()).baseName() != QString(REG_APP_NAME)) { - refreshStartPage({"error", tr("Updates are not allowed!")}); + refreshStartPage({"error", {TXT_ERR_NOT_ALLOWED}}); m_dialogSchedule->addToSchedule("criticalMsg", tr("This folder configuration does not allow for " "updates! The folder name should be: ") + QString(REG_APP_NAME)); return; @@ -378,8 +406,7 @@ void CUpdateManager::checkUpdates(bool manualCheck) #endif if (!m_socket->sendMessage(MSG_CheckUpdates, WStrToTStr(m_checkUrl))) { - refreshStartPage({"error", tr("An error occurred while check updates: Update Service not found!"), - tr("Check for updates"), "check", "false"}); + refreshStartPage({"error", {TXT_ERR_CHECK}, BTN_TXT_CHECK, "check", "false"}); __UNLOCK // m_dialogSchedule->addToSchedule("criticalMsg", QObject::tr("An error occurred while check updates: Update Service not found!")); } @@ -402,12 +429,31 @@ void CUpdateManager::updateNeededCheking() void CUpdateManager::onProgressSlot(const int percent) { - refreshStartPage({"", tr("Downloading new version %1 (%2%)").arg(m_packageData->version, QString::number(percent))}); + refreshStartPage({"", {TXT_DOWNLOADING_UPD, m_packageData->version, QString::number(percent)}}); } void CUpdateManager::onError(const QString &error) { - refreshStartPage({"error", error, tr("Check for updates"), "check", "false"}); + const char *_error = SVC_TXT_ERR_OTHER; + if (error == "SVC_TXT_ERR_UNPACKING") + _error = SVC_TXT_ERR_UNPACKING; + else + if (error == "SVC_TXT_ERR_DNL_OUT_MEM") + _error = SVC_TXT_ERR_DNL_OUT_MEM; + else + if (error == "SVC_TXT_ERR_DNL_CONN") + _error = SVC_TXT_ERR_DNL_CONN; + else + if (error == "SVC_TXT_ERR_DNL_URL") + _error = SVC_TXT_ERR_DNL_URL; + else + if (error == "SVC_TXT_ERR_DNL_CREAT") + _error = SVC_TXT_ERR_DNL_CREAT; + else + if (error == "SVC_TXT_ERR_DNL_INET") + _error = SVC_TXT_ERR_DNL_INET; + + refreshStartPage({"error", {_error}, BTN_TXT_CHECK, "check", "false"}); __UNLOCK // m_dialogSchedule->addToSchedule("criticalMsg", error); } @@ -466,21 +512,21 @@ void CUpdateManager::loadUpdates() __UNLOCK unzipIfNeeded(); } else { - refreshStartPage({"success", tr("To finish updating, restart app"), tr("Restart"), "install", "false"}); + refreshStartPage({"success", {TXT_RESTART_TO_UPD}, BTN_TXT_RESTART, "install", "false"}); m_dialogSchedule->addToSchedule("showStartInstallMessage"); } } else if (!m_packageData->packageUrl.empty()) { if (!m_socket->sendMessage(MSG_LoadUpdates, WStrToTStr(m_packageData->packageUrl), QStrToTStr(m_packageData->fileType))) { - refreshStartPage({"error", tr("An error occurred while loading updates: Update Service not found!"), tr("Check for updates"), "check", "false"}); + refreshStartPage({"error", {TXT_ERR_LOAD}, BTN_TXT_CHECK, "check", "false"}); __UNLOCK // m_dialogSchedule->addToSchedule("criticalMsg", QObject::tr("An error occurred while loading updates: Update Service not found!")); } else { - refreshStartPage({"load", tr("Downloading new version %1 (0%)").arg(m_packageData->version), tr("Cancel"), "abort", "false"}); + refreshStartPage({"load", {TXT_DOWNLOADING_UPD, m_packageData->version, "0"}, BTN_TXT_CANCEL, "abort", "false"}); } } else { - refreshStartPage({"error", tr("An error occurred while loading updates: package Url is empty!"), tr("Check for updates"), "check", "false"}); + refreshStartPage({"error", {TXT_ERR_PACK_URL}, BTN_TXT_CHECK, "check", "false"}); __UNLOCK } } @@ -502,10 +548,10 @@ void CUpdateManager::refreshStartPage(const Command &cmd) lock = false; if (!m_lastCommand.icon.isEmpty()) jsn["icon"] = m_lastCommand.icon; - if (!m_lastCommand.text.isEmpty()) - jsn["text"] = m_lastCommand.text; - if (!m_lastCommand.btn_text.isEmpty()) - btn_jsn["text"] = m_lastCommand.btn_text; + if (m_lastCommand.text.text != nullptr) + jsn["text"] = tr(m_lastCommand.text.text, "CUpdateManager").arg(m_lastCommand.text.arg1, m_lastCommand.text.arg2); + if (m_lastCommand.btn_text != nullptr) + btn_jsn["text"] = tr(m_lastCommand.btn_text, "CUpdateManager"); if (!m_lastCommand.btn_action.isEmpty()) btn_jsn["action"] = m_lastCommand.btn_action; if (!m_lastCommand.btn_lock.isEmpty()) @@ -515,13 +561,13 @@ void CUpdateManager::refreshStartPage(const Command &cmd) m_lastCommand.icon = cmd.icon; jsn["icon"] = cmd.icon; } - if (!cmd.text.isEmpty()) { + if (cmd.text.text != nullptr) { m_lastCommand.text = cmd.text; - jsn["text"] = cmd.text; + jsn["text"] = tr(cmd.text.text, "CUpdateManager").arg(cmd.text.arg1, cmd.text.arg2); } - if (!cmd.btn_text.isEmpty()) { + if (cmd.btn_text != nullptr) { m_lastCommand.btn_text = cmd.btn_text; - btn_jsn["text"] = cmd.btn_text; + btn_jsn["text"] = tr(cmd.btn_text, "CUpdateManager"); } if (!cmd.btn_action.isEmpty()) { m_lastCommand.btn_action = cmd.btn_action; @@ -554,8 +600,7 @@ QString CUpdateManager::getVersion() const void CUpdateManager::onLoadUpdateFinished(const QString &filePath) { if (getFileHash(filePath) != m_packageData->hash) { - refreshStartPage({"error", tr("Update package error: md5 sum does not match the original."), - tr("Check for updates"), "check", "false"}); + refreshStartPage({"error", {TXT_ERR_MD5}, BTN_TXT_CHECK, "check", "false"}); __UNLOCK // m_dialogSchedule->addToSchedule("criticalMsg", "Update package error: md5 sum does not match the original."); return; @@ -566,7 +611,7 @@ void CUpdateManager::onLoadUpdateFinished(const QString &filePath) __UNLOCK unzipIfNeeded(); } else { - refreshStartPage({"success", tr("To finish updating, restart app"), tr("Restart"), "install", "false"}); + refreshStartPage({"success", {TXT_RESTART_TO_UPD}, BTN_TXT_RESTART, "install", "false"}); m_dialogSchedule->addToSchedule("showStartInstallMessage"); } } @@ -575,9 +620,9 @@ void CUpdateManager::unzipIfNeeded() { __GLOBAL_LOCK - refreshStartPage({"load", tr("Preparing update..."), tr("Cancel"), "abort", "true"}); + refreshStartPage({"load", {TXT_PREPARING_UPD}, BTN_TXT_CANCEL, "abort", "true"}); if (!m_socket->sendMessage(MSG_UnzipIfNeeded, QStrToTStr(m_packageData->fileName), QStrToTStr(m_packageData->version))) { - refreshStartPage({"error", tr("An error occurred while unzip updates: Update Service not found!"), tr("Check for updates"), "check", "false"}); + refreshStartPage({"error", {TXT_ERR_UNZIP}, BTN_TXT_CHECK, "check", "false"}); __UNLOCK // m_dialogSchedule->addToSchedule("criticalMsg", QObject::tr("An error occurred while unzip updates: Update Service not found!")); } @@ -631,8 +676,7 @@ void CUpdateManager::setNewUpdateSetting(const QString& _rate) void CUpdateManager::cancelLoading() { - refreshStartPage({"lastcheck", tr("Last check performed ") + formattedTime(m_lastCheck), - tr("Check for updates"), "check", "false"}); + refreshStartPage({"lastcheck", {TXT_LAST_CHECK, formattedTime(m_lastCheck)}, BTN_TXT_CHECK, "check", "false"}); m_socket->sendMessage(MSG_StopDownload); __UNLOCK } @@ -711,7 +755,7 @@ void CUpdateManager::onLoadCheckFinished(const QString &filePath) onCheckFinished(false, false, "", ""); } } else { - onCheckFinished(true, false, "", "Error opening JSON file."); + onCheckFinished(true, false, "", ""); } } @@ -730,19 +774,18 @@ void CUpdateManager::onCheckFinished(bool error, bool updateExist, const QString __UNLOCK loadUpdates(); } else { - refreshStartPage({"lastcheck", tr("Update is available (version %1)").arg(version), - tr("Download update"), "download", "false"}); + refreshStartPage({"lastcheck", {TXT_AVAILABLE_UPD, version}, BTN_TXT_DOWNLOAD, "download", "false"}); m_dialogSchedule->addToSchedule("showUpdateMessage"); } break; } } else { - refreshStartPage({"success", tr("Current version is up to date"), tr("Check for updates"), "check", "false"}); + refreshStartPage({"success", {TXT_UPDATED}, BTN_TXT_CHECK, "check", "false"}); m_pLastCheckMsgTimer->start(); __UNLOCK; } } else { - refreshStartPage({"error", changelog, tr("Check for updates"), "check", "false"}); + refreshStartPage({"error", {TXT_ERR_JSON}, BTN_TXT_CHECK, "check", "false"}); __UNLOCK // m_dialogSchedule->addToSchedule("criticalMsg", changelog); } @@ -761,7 +804,7 @@ void CUpdateManager::showUpdateMessage(QWidget *parent) { break; case WinDlg::DLG_RESULT_SKIP: { skipVersion(); - refreshStartPage({"success", tr("Current version is up to date"), tr("Check for updates"), "check", "false"}); + refreshStartPage({"success", {TXT_UPDATED}, BTN_TXT_CHECK, "check", "false"}); m_pLastCheckMsgTimer->start(); break; } diff --git a/win-linux/src/cupdatemanager.h b/win-linux/src/cupdatemanager.h index 574977db4..345e32d46 100644 --- a/win-linux/src/cupdatemanager.h +++ b/win-linux/src/cupdatemanager.h @@ -56,12 +56,25 @@ enum UpdateMode { DISABLE=0, SILENT=1, ASK=2 }; +struct ComplexText { + ComplexText(const char *_text = nullptr, const QString &_arg1 = "", const QString &_arg2 = "") : + text(_text), arg1(_arg1), arg2(_arg2) {} + const char *text = nullptr; + QString arg1, arg2; +}; + struct Command { + Command(const QString &_icon = "", const ComplexText &_text = ComplexText(), const char *_btn_text = nullptr, + const QString &_btn_action = "", const QString &_btn_lock = "") : + icon(_icon), text(_text), btn_text(_btn_text), btn_action(_btn_action), btn_lock(_btn_lock) {} bool isEmpty() const { - return (icon.isEmpty() && text.isEmpty() && btn_text.isEmpty() && + return (icon.isEmpty() && text.text == nullptr && btn_text == nullptr && btn_action.isEmpty() && btn_lock.isEmpty()); } - QString icon, text, btn_text, btn_action, btn_lock; + QString icon; + ComplexText text; + const char *btn_text = nullptr; + QString btn_action, btn_lock; }; class CUpdateManager: public QObject