mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-15 05:12:04 +08:00
feat: 支持 DTK 5.6.4 关于对话框“版本特性”显示功能
将版本特性信息写入 json,运行时解析文件信息并初始化版本特性对话框 Log: 添加版本特性 json 文件以及解析文件相关函数,用于构造版本特性对话框;版本号维护放入 src/assets/json/features.json 中统一管理,不再修改 main 函数,运行时从 json 文件读取并显示 * 该提交需要在低版本 DTK 验证能否正常编译运行
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
#include "application.h"
|
||||
#include "mainwindow-dtk.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#include <DPlatformWindowHandle>
|
||||
#include <DLog>
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DAboutDialog>
|
||||
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
||||
#include <DFeatureDisplayDialog>
|
||||
#endif
|
||||
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
@@ -43,6 +47,13 @@ Application::Application(int &argc, char **argv)
|
||||
// 初始化日志模块 (默认日志位置 ~/.cache/spark-union/spark-store)
|
||||
DLogManager::registerConsoleAppender();
|
||||
DLogManager::registerFileAppender();
|
||||
|
||||
// 获取版本特性信息
|
||||
m_featuresJsonObj = Utils::parseFeatureJsonFile();
|
||||
m_version = m_featuresJsonObj.value("version").toString(); // 获取版本号
|
||||
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
||||
initFeatureDisplayDialog(); // 初始化版本特性对话框
|
||||
#endif
|
||||
}
|
||||
|
||||
void Application::handleAboutAction()
|
||||
@@ -65,9 +76,8 @@ void Application::checkAppConfigLocation()
|
||||
}
|
||||
}
|
||||
|
||||
void Application::setVersionAndBuildDateTime(const QString &version, const QString &buildDateTime)
|
||||
void Application::setBuildDateTime(const QString &buildDateTime)
|
||||
{
|
||||
m_version = version;
|
||||
m_buildDateTime = buildDateTime;
|
||||
|
||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||
@@ -109,6 +119,9 @@ void Application::initAboutDialog()
|
||||
dialog->setProductName(productName());
|
||||
dialog->setProductIcon(productIcon());
|
||||
dialog->setVersion(translate("DAboutDialog", "Version: %1").arg(applicationVersion()));
|
||||
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
||||
dialog->setVersion(applicationVersion());
|
||||
#endif
|
||||
// 根据 shenmo 要求,不显示组织 Logo
|
||||
// dialog->setCompanyLogo(QPixmap(":/icon/Logo-Spark.png"));
|
||||
dialog->setCompanyLogo(QPixmap());
|
||||
@@ -118,9 +131,70 @@ void Application::initAboutDialog()
|
||||
dialog->setLicense(translate("DAboutDialog", "%1 is released under %2").arg(productName()).arg(applicationLicense()));
|
||||
|
||||
setAboutDialog(dialog);
|
||||
connect(aboutDialog(), &DAboutDialog::destroyed, this, [=] {
|
||||
connect(aboutDialog(), &DAboutDialog::destroyed, this, [=]() {
|
||||
setAboutDialog(nullptr);
|
||||
});
|
||||
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
||||
connect(aboutDialog(), &DAboutDialog::featureActivated, this, [=]() {
|
||||
featureDisplayDialog()->show();
|
||||
});
|
||||
#endif
|
||||
|
||||
dialog->hide();
|
||||
}
|
||||
|
||||
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
||||
/**
|
||||
* @brief Application::initFeatureDisplayDialog 初始化版本特性对话框
|
||||
*/
|
||||
void Application::initFeatureDisplayDialog()
|
||||
{
|
||||
if (featureDisplayDialog())
|
||||
{
|
||||
featureDisplayDialog()->deleteLater();
|
||||
setFeatureDisplayDialog(nullptr);
|
||||
}
|
||||
|
||||
// 自定义 DFeatureDisplayDialog
|
||||
DFeatureDisplayDialog *dialog = new DFeatureDisplayDialog(m_mainWindow);
|
||||
// 标题
|
||||
dialog->setTitle(m_featuresJsonObj.value("title").toString());
|
||||
// NOTE: json 文件中支持多语言;考虑到维护性,不放入翻译文件处理
|
||||
if (m_featuresJsonObj.contains(QString("title[%1]").arg(QLocale::system().name())))
|
||||
{
|
||||
dialog->setTitle(m_featuresJsonObj.value(QString("title[%1]").arg(QLocale::system().name())).toString());
|
||||
}
|
||||
|
||||
// 特性项
|
||||
QList<DFeatureItem *> items;
|
||||
foreach (const QJsonValue &jsonValue, m_featuresJsonObj.value("items").toArray())
|
||||
{
|
||||
QJsonObject jsonObj = jsonValue.toObject();
|
||||
QString name = jsonObj.value("name").toString();
|
||||
if (jsonObj.contains(QString("name[%1]").arg(QLocale::system().name())))
|
||||
{
|
||||
name = jsonObj.value(QString("name[%1]").arg(QLocale::system().name())).toString();
|
||||
}
|
||||
QString description = jsonObj.value("description").toString();
|
||||
if (jsonObj.contains(QString("description[%1]").arg(QLocale::system().name())))
|
||||
{
|
||||
description = jsonObj.value(QString("description[%1]").arg(QLocale::system().name())).toString();
|
||||
}
|
||||
|
||||
DFeatureItem *item = new DFeatureItem(QIcon::fromTheme("spark-store"), name, description, dialog);
|
||||
items.append(item);
|
||||
}
|
||||
dialog->addItems(items); // NOTE: 也支持 addItem 依次添加单个 item
|
||||
|
||||
// “了解更多”链接按钮
|
||||
dialog->setLinkUrl(m_featuresJsonObj.value("linkUrl").toString());
|
||||
dialog->setLinkButtonVisible(m_featuresJsonObj.value("linkButtonVisible").toBool());
|
||||
|
||||
setFeatureDisplayDialog(dialog);
|
||||
connect(featureDisplayDialog(), &DFeatureDisplayDialog::destroyed, this, [=]() {
|
||||
setFeatureDisplayDialog(nullptr);
|
||||
});
|
||||
|
||||
dialog->hide();
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user