fix: 修复配置文件写入位置异常问题

main.cpp 中通过 QStandardPaths 获取配置文件路径,此时未设置组织名称和程序名称,导致路径异常

Log:
1. main.cpp 中提前设置组织名称和程序名称,再读写配置文件
2. main.cpp 中提前检查配置文件所在文件夹是否存在,不存在则创建,再读写配置文件
3. 修复 main.cpp 中修改配置文件后没有写入的问题
4. 去除版本号中重复的 Version 字样(由关于窗口提供)
5. 修复关于窗口中组织图标显示为 deepin 的问题(已去除)
6. 修复 wayland 下窗口设置透明度相关警告(wayland 下禁用透明度动画)
7. 下载列表 wayland 下窗口标题添加翻译
This commit is contained in:
zty199 2022-12-25 17:55:04 +08:00
parent f99c0839dd
commit dca80a3fbb
10 changed files with 91 additions and 53 deletions

@ -22,7 +22,7 @@ Application::Application(int &argc, char **argv)
loadTranslator(); // 载入翻译
setOrganizationName("spark-union");
setApplicationName("spark-store"); // 影响 ~/.local/share/spark-union 下文件夹名称
setApplicationName("spark-store"); // 影响 ~/.config/spark-union ~/.local/share/spark-union 下文件夹名称
setApplicationDisplayName(QObject::tr("Spark Store")); // 设置窗口显示标题 (Wayland 下会显示 Qt 原生标题栏)
setProductName(QObject::tr("Spark Store"));
setProductIcon(QIcon::fromTheme("spark-store"));
@ -53,6 +53,15 @@ void Application::handleAboutAction()
DApplication::handleAboutAction();
}
void Application::checkAppConfigLocation()
{
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
if (!dir.exists()) {
qWarning() << "AppConfigLocation not existed, creating...";
dir.mkpath(dir.absolutePath());
}
}
void Application::setVersionAndBuildDateTime(const QString &version, const QString &buildDateTime)
{
m_version = version;
@ -70,23 +79,16 @@ void Application::setVersionAndBuildDateTime(const QString &version, const QStri
setApplicationVersion(DApplication::buildVersion(config.value("build/version").toString() + "-" + "Flamescion" + "-" + config.value("build/time").toString()));
}
void Application::checkAppConfigLocation()
{
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
if (!dir.exists()) {
qWarning() << "AppConfigLocation not existed, creating...";
dir.mkpath(dir.absolutePath());
}
}
void Application::initAboutDialog()
{
// Customized DAboutDialog
// 自定义 DAboutDialog
DAboutDialog *dialog = new DAboutDialog(activeWindow());
dialog->setProductName(productName());
dialog->setProductIcon(productIcon());
dialog->setVersion(translate("DAboutDialog", "Version: %1").arg(applicationVersion()));
// dialog->setCompanyLogo(QPixmap(":/icon/Logo-Spark.png")); // 根据 shenmo 要求,不显示组织 Logo
// 根据 shenmo 要求,不显示组织 Logo
// dialog->setCompanyLogo(QPixmap(":/icon/Logo-Spark.png"));
dialog->setCompanyLogo(QPixmap());
dialog->setWebsiteName(QObject::tr("Spark Project"));
dialog->setWebsiteLink(applicationHomePage());
dialog->setDescription(applicationDescription());

@ -13,10 +13,11 @@ public:
Application(int &argc, char **argv);
void handleAboutAction() override;
static void checkAppConfigLocation();
void setVersionAndBuildDateTime(const QString &version, const QString &buildDateTime);
private:
void checkAppConfigLocation();
void initAboutDialog();
private:

@ -13,7 +13,7 @@ DWIDGET_USE_NAMESPACE
int main(int argc, char *argv[])
{
// Get build time
static const QString version = "Version 4.1.2";
static const QString version = "4.1.2";
static const QDate buildDate = QLocale(QLocale::English).toDate(QString(__DATE__).replace(" ", " 0"), "MMM dd yyyy");
static const QTime buildTime = QTime::fromString(__TIME__, "hh:mm:ss");
static const QString buildDateTime = buildDate.toString("yyyy.MM.dd") + "-" + buildTime.toString("hh:mm:ss");
@ -35,15 +35,20 @@ int main(int argc, char *argv[])
isWayland = true;
}
// NOTE: 提前设置组织名称和应用名称,避免配置文件位置错误
DApplication::setOrganizationName("spark-union");
DApplication::setApplicationName("spark-store");
Application::checkAppConfigLocation(); // 检查 ~/.config/spark-union/spark-store 文件夹是否存在
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
config.setValue("build/isWayland", isWayland);
config.setValue("build/isDeepinOS", isDeepinOS);
// Check config file, if there is no wayland config, then set it to default, which means use wayland if possible.
if (!config.contains("build/useWayland"))
{
config.setValue("build/useWayland", true);
}
config.sync(); // 写入更改至 config.ini并同步最新内容
bool useWayland = config.value("build/useWayland").toBool();
qDebug() << "System Wayland enabled:" << isWayland << ". Spark Wayland enabled:" << useWayland;
@ -112,7 +117,6 @@ int main(int argc, char *argv[])
}
}
w.show();
w.setWindowTitle("Spark Store");
return a.exec();
}

@ -21,7 +21,13 @@ MainWindow::MainWindow(QWidget *parent)
setWindowTitle(QObject::tr("Spark Store"));
initConfig();
WidgetAnimation::widgetOpacity(this, true);
// FIXME: wayland 不支持直接设置窗口透明度,需要调用 wayland 相关库(考虑抄控制中心“窗口移动时启用透明特效”代码?)
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
bool isWayland = config.value("build/isWayland").toBool();
if(!isWayland)
{
WidgetAnimation::widgetOpacity(this, true);
}
searchEdit = new DSearchEdit(ui->titlebar);
downloadlistwidget = new DownloadListWidget;
@ -157,7 +163,7 @@ MainWindow::MainWindow(QWidget *parent)
ly_titlebar->addWidget(backButtom);
// Check wayland configs
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
// QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
if (!config.value("build/isDeepinOS").toBool() && config.value("build/useWayland").toBool())
{
// Wayland 搜索栏居中

@ -207,7 +207,7 @@ void SettingsPage::on_pushButton_clear_clicked()
{
ui->pushButton_clear->setEnabled(false);
QDir tmpdir("/tmp/spark-store");
QDir tmpdir(QString::fromUtf8(TMP_PATH));
tmpdir.setFilter(QDir::Files);
int quantity = int(tmpdir.count());
for(int i = 0; i < quantity; i++)

@ -1,6 +1,8 @@
#include "basewidgetopacity.h"
#include <QCloseEvent>
#include <QSettings>
#include <QStandardPaths>
#include <QPropertyAnimation>
BaseWidgetOpacity::BaseWidgetOpacity(QWidget *parent) : DBlurEffectWidget(parent)
@ -12,6 +14,14 @@ BaseWidgetOpacity::BaseWidgetOpacity(QWidget *parent) : DBlurEffectWidget(parent
/// @param event
void BaseWidgetOpacity::closeEvent(QCloseEvent *event)
{
// FIXME: wayland 不支持直接设置窗口透明度,需要调用 wayland 相关库(考虑抄控制中心“窗口移动时启用透明特效”代码?)
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
bool isWayland = config.value("build/isWayland").toBool();
if(isWayland)
{
return DBlurEffectWidget::closeEvent(event);
}
if (!closeWindowAnimation)
{
closeWindowAnimation = true;

@ -7,7 +7,7 @@ DownloadListWidget::DownloadListWidget(QWidget *parent) : DBlurEffectWidget(pare
ui(new Ui::DownloadListWidget)
{
ui->setupUi(this);
setWindowTitle("Download list");
setWindowTitle(QObject::tr("Download list"));
installEventFilter(this);
this->setAttribute(Qt::WA_Hover, true);
setFocus();

@ -240,7 +240,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/application.cpp" line="93"/>
<location filename="../src/application.cpp" line="95"/>
<source>%1 is released under %2</source>
<translation type="unfinished"></translation>
</message>
@ -441,32 +441,32 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="38"/>
<location filename="../src/mainwindow-dtk.cpp" line="44"/>
<source>Submit App</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="39"/>
<location filename="../src/mainwindow-dtk.cpp" line="45"/>
<source>Submit App with client(Recommanded)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="40"/>
<location filename="../src/mainwindow-dtk.cpp" line="46"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="41"/>
<location filename="../src/mainwindow-dtk.cpp" line="47"/>
<source>APP Upgrade and Install Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="154"/>
<location filename="../src/mainwindow-dtk.cpp" line="160"/>
<source>Spark Store</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="155"/>
<location filename="../src/mainwindow-dtk.cpp" line="161"/>
<source>Search or enter spk://</source>
<translation type="unfinished"></translation>
</message>
@ -486,10 +486,15 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/application.cpp" line="90"/>
<location filename="../src/application.cpp" line="92"/>
<source>Spark Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/widgets/downloadlistwidget.cpp" line="10"/>
<source>Download list</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SettingsPage</name>
@ -579,17 +584,17 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/pages/settingspage.cpp" line="196"/>
<location filename="../src/pages/settingspage.cpp" line="195"/>
<source>Updating, please wait...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/pages/settingspage.cpp" line="218"/>
<location filename="../src/pages/settingspage.cpp" line="217"/>
<source>Spark Store</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/pages/settingspage.cpp" line="218"/>
<location filename="../src/pages/settingspage.cpp" line="217"/>
<source>Temporary cache was cleaned</source>
<translation type="unfinished"></translation>
</message>

@ -240,7 +240,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/application.cpp" line="93"/>
<location filename="../src/application.cpp" line="95"/>
<source>%1 is released under %2</source>
<translation type="unfinished"></translation>
</message>
@ -441,32 +441,32 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="38"/>
<location filename="../src/mainwindow-dtk.cpp" line="44"/>
<source>Submit App</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="39"/>
<location filename="../src/mainwindow-dtk.cpp" line="45"/>
<source>Submit App with client(Recommanded)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="40"/>
<location filename="../src/mainwindow-dtk.cpp" line="46"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="41"/>
<location filename="../src/mainwindow-dtk.cpp" line="47"/>
<source>APP Upgrade and Install Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="154"/>
<location filename="../src/mainwindow-dtk.cpp" line="160"/>
<source>Spark Store</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="155"/>
<location filename="../src/mainwindow-dtk.cpp" line="161"/>
<source>Search or enter spk://</source>
<translation type="unfinished"></translation>
</message>
@ -486,10 +486,15 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/application.cpp" line="90"/>
<location filename="../src/application.cpp" line="92"/>
<source>Spark Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/widgets/downloadlistwidget.cpp" line="10"/>
<source>Download list</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SettingsPage</name>
@ -579,17 +584,17 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/pages/settingspage.cpp" line="196"/>
<location filename="../src/pages/settingspage.cpp" line="195"/>
<source>Updating, please wait...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/pages/settingspage.cpp" line="218"/>
<location filename="../src/pages/settingspage.cpp" line="217"/>
<source>Spark Store</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/pages/settingspage.cpp" line="218"/>
<location filename="../src/pages/settingspage.cpp" line="217"/>
<source>Temporary cache was cleaned</source>
<translation type="unfinished"></translation>
</message>

@ -240,7 +240,7 @@
<translation>%1</translation>
</message>
<message>
<location filename="../src/application.cpp" line="93"/>
<location filename="../src/application.cpp" line="95"/>
<source>%1 is released under %2</source>
<translation>%1%2</translation>
</message>
@ -441,32 +441,32 @@
<translation></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="38"/>
<location filename="../src/mainwindow-dtk.cpp" line="44"/>
<source>Submit App</source>
<translation></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="39"/>
<location filename="../src/mainwindow-dtk.cpp" line="45"/>
<source>Submit App with client(Recommanded)</source>
<translation>使稿</translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="40"/>
<location filename="../src/mainwindow-dtk.cpp" line="46"/>
<source>Settings</source>
<translation></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="41"/>
<location filename="../src/mainwindow-dtk.cpp" line="47"/>
<source>APP Upgrade and Install Settings</source>
<translation></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="154"/>
<location filename="../src/mainwindow-dtk.cpp" line="160"/>
<source>Spark Store</source>
<translation></translation>
</message>
<message>
<location filename="../src/mainwindow-dtk.cpp" line="155"/>
<location filename="../src/mainwindow-dtk.cpp" line="161"/>
<source>Search or enter spk://</source>
<translation></translation>
</message>
@ -486,10 +486,15 @@
<translation>&lt;span style=&apos; font-size:10pt;font-weight:60;&apos;&gt;&lt;/span&gt;&lt;br/&gt;&quot;&quot;&lt;a href=&apos;https://www.spark-app.store/&apos;&gt;https://www.spark-app.store&lt;/a&gt;&lt;br/&gt;&quot;&quot;&lt;span style=&apos; font-size:12pt;&apos;&gt;星火开发者联盟&lt;/span&gt;</translation>
</message>
<message>
<location filename="../src/application.cpp" line="90"/>
<location filename="../src/application.cpp" line="92"/>
<source>Spark Project</source>
<translation></translation>
</message>
<message>
<location filename="../src/widgets/downloadlistwidget.cpp" line="10"/>
<source>Download list</source>
<translation></translation>
</message>
</context>
<context>
<name>SettingsPage</name>
@ -579,17 +584,17 @@
<translation>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;&lt;/span&gt;Linux/deepinSpark&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;使使&lt;/p&gt;&lt;p&gt; &amp;lt;jifengshenmo@outlook.com&amp;gt; &lt;/p&gt;&lt;p&gt;稿&lt;/p&gt;&lt;p&gt; Spark IM :&lt;a href=&quot;https://chat.shenmo.tech&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;https://chat.shenmo.tech&lt;br/&gt;&lt;/span&gt;&lt;/a&gt;QQ 872690351&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
</message>
<message>
<location filename="../src/pages/settingspage.cpp" line="196"/>
<location filename="../src/pages/settingspage.cpp" line="195"/>
<source>Updating, please wait...</source>
<translation></translation>
</message>
<message>
<location filename="../src/pages/settingspage.cpp" line="218"/>
<location filename="../src/pages/settingspage.cpp" line="217"/>
<source>Spark Store</source>
<translation></translation>
</message>
<message>
<location filename="../src/pages/settingspage.cpp" line="218"/>
<location filename="../src/pages/settingspage.cpp" line="217"/>
<source>Temporary cache was cleaned</source>
<translation></translation>
</message>