diff --git a/CMake/xToolsCommon.cmake b/CMake/xToolsCommon.cmake index a726187d..83f87948 100644 --- a/CMake/xToolsCommon.cmake +++ b/CMake/xToolsCommon.cmake @@ -1,9 +1,8 @@ add_compile_definitions(X_TOOLS_AUTHOR="x-tools-author") -add_compile_definitions(SAK_EDITION="beta1") -add_compile_definitions(SAK_VERSION="5.1.0") -add_compile_definitions(SAK_STYLE_DEFAULT="Fusion") -add_compile_definitions(SAK_HOST_ADDRESS_ANY="Any") -add_compile_definitions(SAK_CLEAR_MESSAGE_INTERVAL=8000) +add_compile_definitions(X_TOOL_EDITION="beta1") +add_compile_definitions(X_TOOLS_VERSION="5.1.0") +add_compile_definitions(X_TOOLS_DEFAULT_APP_STYLE="Fusion") +add_compile_definitions(X_TOOLS_CLEAR_MESSAGE_INTERVAL=8000) add_compile_definitions(X_TOOLS_AUTHOR_EMAIL="x-tools@outlook.com") add_compile_definitions(X_TOOLS_GITEE_REPOSITORY_URL="https://gitee.com/x-tools-author/x-tools") add_compile_definitions(X_TOOLS_GITHUB_REPOSITORY_URL="https://github.com/x-tools-author/x-tools") diff --git a/Source/Assistants/FileCheck/Source/xToolsFileCheckAssistant.cpp b/Source/Assistants/FileCheck/Source/xToolsFileCheckAssistant.cpp index d4869225..6d8099a2 100644 --- a/Source/Assistants/FileCheck/Source/xToolsFileCheckAssistant.cpp +++ b/Source/Assistants/FileCheck/Source/xToolsFileCheckAssistant.cpp @@ -57,7 +57,7 @@ xToolsFileCheckAssistant::xToolsFileCheckAssistant(QWidget* parent) // It will clean the message which was showed on the info label when the timer // is timeout - m_clearMessageTimer.setInterval(SAK_CLEAR_MESSAGE_INTERVAL); + m_clearMessageTimer.setInterval(X_TOOLS_CLEAR_MESSAGE_INTERVAL); connect(&m_clearMessageTimer, &QTimer::timeout, this, &xToolsFileCheckAssistant::clearMessage); m_upperCheckBox->setChecked(true); diff --git a/Source/Common/Common/xTools.h b/Source/Common/Common/xTools.h index 31b39709..16123eff 100644 --- a/Source/Common/Common/xTools.h +++ b/Source/Common/Common/xTools.h @@ -21,11 +21,10 @@ #include "xToolsInterface.h" #endif #include "xToolsSettings.h" -#include "xToolsTranslator.h" #ifdef X_TOOLS_USING_GLOG -static void sakInitGoogleLogging(char *argv0) +static void xToolsInitGoogleLogging(char *argv0) { QString logPath = SAKSettings::instance()->settingsPath(); logPath += "/log"; @@ -52,7 +51,7 @@ static void sakInitGoogleLogging(char *argv0) qInfo() << "The logging path is:" << qPrintable(logPath); } -static void sakShutdownGoogleLogging() +static void xToolsShutdownGoogleLogging() { #ifndef QT_DEBUG google::ShutdownGoogleLogging(); @@ -85,7 +84,7 @@ static void qtLogToGoogleLog(QtMsgType type, const QMessageLogContext &context, } #endif -static void sakInitApp(const QString &appName) +static void xToolsInitApp(const QString &appName) { // Initialize some information about application. QString cookedAppName = appName; @@ -94,21 +93,21 @@ static void sakInitApp(const QString &appName) QCoreApplication::setOrganizationDomain(QString("IT")); QCoreApplication::setApplicationName(cookedAppName); -#ifdef SAK_VERSION - QCoreApplication::setApplicationVersion(SAK_VERSION); +#ifdef X_TOOLS_VERSION + QCoreApplication::setApplicationVersion(X_TOOLS_VERSION); #else QCoreApplication::setApplicationVersion("0.0.0"); #endif } -static void sakInstallMessageHandler() +static void xToolsInstallMessageHandler() { #ifndef QT_DEBUG qInstallMessageHandler(qtLogToGoogleLog); #endif } -static void sakTryToClearSettings() +static void xToolsTryToClearSettings() { // Remove settings file and database if (xToolsSettings::instance()->clearSettings()) { @@ -121,13 +120,7 @@ static void sakTryToClearSettings() } } -static void sakInitLanguage() -{ - QString language = xToolsSettings::instance()->language(); - xToolsTranslator::instance()->setupLanguage(language); -} - -static void sakInitHdpi() +static void xToolsInitHdpi() { #if 0 qputenv("QT_SCALE_FACTOR", "1.5"); @@ -141,7 +134,7 @@ static void sakInitHdpi() #endif } -static void sakInitAppStyle() +static void xToolsInitAppStyle() { qInfo() << "The supported application styles are:" << qPrintable(QStyleFactory::keys().join(QChar(','))); @@ -154,24 +147,21 @@ static void sakInitAppStyle() static void sakDoSomethingBeforeAppCreated(char *argv[], const QString &appName) { - sakInitApp(appName); + xToolsInitApp(appName); #ifdef X_TOOLS_USING_GLOG - sakInitGoogleLogging(argv[0]); - sakInstallMessageHandler(); + xToolsInitGoogleLogging(argv[0]); + xToolsInstallMessageHandler(); #else Q_UNUSED(argv) #endif - sakTryToClearSettings(); -#if 0 - sakInitLanguage(); -#endif - sakInitHdpi(); - sakInitAppStyle(); + xToolsTryToClearSettings(); + xToolsInitHdpi(); + xToolsInitAppStyle(); } static void sakDoSomethingAfterAppExited() { #ifdef X_TOOLS_USING_GLOG - sakShutdownGoogleLogging(); + xToolsShutdownGoogleLogging(); #endif } diff --git a/Source/Common/Common/xToolsSettings.cpp b/Source/Common/Common/xToolsSettings.cpp index c814adbc..0d9e64c5 100644 --- a/Source/Common/Common/xToolsSettings.cpp +++ b/Source/Common/Common/xToolsSettings.cpp @@ -78,7 +78,7 @@ void xToolsSettings::setHdpiPolicy(int policy) QString xToolsSettings::appStyle() { - return value(mSettingsKey.appStyle, SAK_STYLE_DEFAULT).toString(); + return value(mSettingsKey.appStyle, X_TOOLS_DEFAULT_APP_STYLE).toString(); } void xToolsSettings::setAppStyle(const QString& style) diff --git a/Source/Common/CommonUI/xToolsApplication.cpp b/Source/Common/CommonUI/xToolsApplication.cpp index 747ded98..91daa66b 100644 --- a/Source/Common/CommonUI/xToolsApplication.cpp +++ b/Source/Common/CommonUI/xToolsApplication.cpp @@ -103,6 +103,11 @@ QSplashScreen &xToolsApplication::splashScreen() return m_splashScreen; } +QStringList xToolsApplication::supportedLanguages() +{ + return m_languageFlagNameMap.values(); +} + void xToolsApplication::setupLanguage(const QString &language) { setupLanguage(language, m_translatorPrefix); diff --git a/Source/Common/CommonUI/xToolsApplication.h b/Source/Common/CommonUI/xToolsApplication.h index 12c07335..d1a7d480 100644 --- a/Source/Common/CommonUI/xToolsApplication.h +++ b/Source/Common/CommonUI/xToolsApplication.h @@ -15,6 +15,7 @@ class xToolsApplication : public QApplication { Q_OBJECT + Q_PROPERTY(QStringList supportedLanguages READ supportedLanguages CONSTANT FINAL) public: enum xToolsAppPalette { DefaultPalette, DarkPalette, LightPalette, CustomPalette = -1 }; @@ -25,6 +26,7 @@ public: void setupPalette(int palette); void setupPalette(const QString &fileName); QSplashScreen &splashScreen(); + QStringList supportedLanguages(); virtual void setupLanguage(const QString &language); diff --git a/Source/Common/CommonUI/xToolsMainWindow.cpp b/Source/Common/CommonUI/xToolsMainWindow.cpp index 829a57be..2348441f 100644 --- a/Source/Common/CommonUI/xToolsMainWindow.cpp +++ b/Source/Common/CommonUI/xToolsMainWindow.cpp @@ -29,17 +29,15 @@ #include "xToolsDataStructure.h" #endif +#include "xToolsApplication.h" #include "xToolsInterface.h" #include "xToolsSettings.h" -#include "xToolsTranslator.h" xToolsMainWindow::xToolsMainWindow(QWidget* parent) : QMainWindow(parent) { m_appStyleActionGroup = new QActionGroup(this); m_languageActionGroup = new QActionGroup(this); - QString language = xToolsSettings::instance()->language(); - xToolsTranslator::instance()->setupLanguage(language); init(); } @@ -98,7 +96,7 @@ void xToolsMainWindow::initMenuLanguage() m_languageMenu = new QMenu(tr("&Languages"), this); menuBar()->addMenu(m_languageMenu); - QStringList languages = xToolsTranslator::instance()->languanges(); + QStringList languages = qobject_cast(qApp)->supportedLanguages(); for (auto& language : languages) { QAction* action = new QAction(language, this); action->setCheckable(true); diff --git a/Source/MainWindow.cpp b/Source/MainWindow.cpp index 82aff438..1ef59eb5 100644 --- a/Source/MainWindow.cpp +++ b/Source/MainWindow.cpp @@ -451,7 +451,7 @@ void MainWindow::aboutSoftware() QList infoList; infoList << Info{tr("Version"), QString(qApp->applicationVersion()), false} #ifndef SAK_RELEASE_FOR_APP_STORE - << Info{tr("Edition"), SAK_EDITION, false} + << Info{tr("Edition"), X_TOOL_EDITION, false} #endif << Info{tr("Author"), QString(X_TOOLS_AUTHOR), false} << Info{tr("Email"), QString(X_TOOLS_AUTHOR_EMAIL), false}