!178 fix: 修复主窗口关闭后,关于窗口没有自动关闭的问题

* 添加 Application 类,继承 DApplication,将 main 函数中设置属性、关于信息等操作移至 Application 构造函数中进行
* 1.1. 添加 setOrganizationName 操作,设置组织名称为 spark-union,与 SWRT 保持一致
* 1.2. 设置组织名称后,QStandardPaths::AppConfigLocation 等路径相应改变,修改所有配置文件和缓存文件路径(server.list/config.ini 等)
* 1.3. 关于对话框设置父对象后,对话框背景色受主窗口样式表影响,移动部分控件样式表设置方式与位置
* 修复关于窗口不显示组织 Logo 的问题,补充丢失的资源文件,整理资源文件
* 去除 .pro 文件中无效的更新翻译文件脚本调用,整理 .pro 文件,添加编译时更新 ts 文件脚本调用
* 继续修复偶现关闭客户端时崩溃问题(疑似 aria2c 进程未启动,pid 未初始化为随机值,执行 kill 操作时未判断导致)
* 修复进入详情页时焦点默认在分享链接按钮上的问题
* 暂时去除没有意义的 DBus 接口,使用 DGuiApplicationHelper::newProcessInstance 获取新进程的启动参数
* 更新翻译文件,去除已经不存在的翻译
This commit is contained in:
2022-12-25 08:28:05 +00:00
committed by Pluto
parent 1b9c925183
commit f99c0839dd
24 changed files with 752 additions and 1427 deletions

101
src/application.cpp Normal file
View File

@@ -0,0 +1,101 @@
#include "application.h"
#include <DPlatformWindowHandle>
#include <DLog>
#include <DGuiApplicationHelper>
#include <DAboutDialog>
#include <QSettings>
#include <QStandardPaths>
DCORE_USE_NAMESPACE
Application::Application(int &argc, char **argv)
: DApplication(argc, argv)
{
// Wayland 环境下使用,防止子控件 Native 化
if (!DPlatformWindowHandle::pluginVersion().isEmpty()) {
setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
}
setAttribute(Qt::AA_UseHighDpiPixmaps);
loadTranslator(); // 载入翻译
setOrganizationName("spark-union");
setApplicationName("spark-store"); // 影响 ~/.local/share/spark-union 下文件夹名称
setApplicationDisplayName(QObject::tr("Spark Store")); // 设置窗口显示标题 (Wayland 下会显示 Qt 原生标题栏)
setProductName(QObject::tr("Spark Store"));
setProductIcon(QIcon::fromTheme("spark-store"));
setApplicationHomePage("https://gitee.com/deepin-community-store");
setApplicationDescription(
QObject::tr(
"<span style=' font-size:10pt;font-weight:60;'>An appstore powered by community</span><br/>"
"<a href='https://www.spark-app.store/'>https://www.spark-app.store</a><br/>"
"<span style=' font-size:12pt;'>Spark developers</span>"));
setApplicationLicense(" <a href='https://www.gnu.org/licenses/gpl-3.0.html'>GPLv3</a> ");
// 检查 ~/.config/spark-union/spark-store 文件夹是否存在
checkAppConfigLocation();
// 初始化日志模块 (默认日志位置 ~/.cache/spark-union/spark-store)
DLogManager::registerConsoleAppender();
DLogManager::registerFileAppender();
}
void Application::handleAboutAction()
{
if (aboutDialog()) {
DApplication::handleAboutAction();
return;
}
initAboutDialog();
DApplication::handleAboutAction();
}
void Application::setVersionAndBuildDateTime(const QString &version, const QString &buildDateTime)
{
m_version = version;
m_buildDateTime = buildDateTime;
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
if (config.value("build/version").toString() != m_version) {
qDebug() << "Spark Store has been updated!";
config.setValue("build/version", m_version);
config.setValue("build/time", m_buildDateTime);
config.sync();
}
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 *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
dialog->setWebsiteName(QObject::tr("Spark Project"));
dialog->setWebsiteLink(applicationHomePage());
dialog->setDescription(applicationDescription());
dialog->setLicense(translate("DAboutDialog", "%1 is released under %2").arg(productName()).arg(applicationLicense()));
setAboutDialog(dialog);
connect(aboutDialog(), &DAboutDialog::destroyed, this, [=] {
setAboutDialog(nullptr);
});
dialog->hide();
}

27
src/application.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef APPLICATION_H
#define APPLICATION_H
#include <DApplication>
DWIDGET_USE_NAMESPACE
class Application : public DApplication
{
Q_OBJECT
public:
Application(int &argc, char **argv);
void handleAboutAction() override;
void setVersionAndBuildDateTime(const QString &version, const QString &buildDateTime);
private:
void checkAppConfigLocation();
void initAboutDialog();
private:
QString m_version;
QString m_buildDateTime;
};
#endif // APPLICATION_H

View File

@@ -1,64 +1,65 @@
<RCC>
<qresource prefix="/">
<file>icon/logo.svg</file>
<file>tags/a2d-small.png</file>
<file>tags/a2d.png</file>
<file>tags/community-small.png</file>
<file>tags/community.png</file>
<file>tags/community.svg</file>
<file>tags/deepin-small.png</file>
<file>tags/deepin.svg</file>
<file>tags/dtk-small.png</file>
<file>tags/dwine2-small.png</file>
<file>tags/dwine5-small.png</file>
<file>tags/dwine5.svg</file>
<file>tags/logo_icon.svg</file>
<file>tags/ubuntu-small.png</file>
<file>tags/ubuntu.png</file>
<file>tags/uos-authorize.svg</file>
<file>tags/uos-small.png</file>
<file>tags/uos.svg</file>
<file>icon/light/back.svg</file>
<file>icon/light/download.svg</file>
<file>icon/light/leftbutton_0.svg</file>
<file>icon/light/leftbutton_1.svg</file>
<file>icon/light/leftbutton_2.svg</file>
<file>icon/light/leftbutton_3.svg</file>
<file>icon/light/leftbutton_4.svg</file>
<file>icon/light/leftbutton_5.svg</file>
<file>icon/light/leftbutton_6.svg</file>
<file>icon/light/leftbutton_7.svg</file>
<file>icon/light/leftbutton_8.svg</file>
<file>icon/light/leftbutton_9.svg</file>
<file>icon/light/leftbutton_10.svg</file>
<file>icon/light/leftbutton_11.svg</file>
<file>icon/light/leftbutton_12.svg</file>
<file>icon/light/box.svg</file>
<file>icon/light/calendar.svg</file>
<file>icon/light/globe.svg</file>
<file>icon/light/folder.svg</file>
<file>icon/light/text.svg</file>
<file>icon/dark/back.svg</file>
<file>icon/dark/box.svg</file>
<file>icon/dark/calendar.svg</file>
<file>icon/dark/download.svg</file>
<file>icon/dark/folder.svg</file>
<file>icon/dark/globe.svg</file>
<file>icon/dark/leftbutton_0.svg</file>
<file>icon/dark/leftbutton_1.svg</file>
<file>icon/dark/leftbutton_2.svg</file>
<file>icon/dark/leftbutton_3.svg</file>
<file>icon/dark/leftbutton_4.svg</file>
<file>icon/dark/leftbutton_5.svg</file>
<file>icon/dark/leftbutton_6.svg</file>
<file>icon/dark/leftbutton_7.svg</file>
<file>icon/dark/leftbutton_8.svg</file>
<file>icon/dark/leftbutton_9.svg</file>
<file>icon/dark/leftbutton_10.svg</file>
<file>icon/dark/leftbutton_11.svg</file>
<file>icon/dark/leftbutton_12.svg</file>
<file>icon/dark/text.svg</file>
<file>icon/light/update.svg</file>
<file>icon/dark/update.svg</file>
</qresource>
</RCC>
<RCC>
<qresource prefix="/">
<file>icon/Logo-Spark.png</file>
<file>icon/dark/back.svg</file>
<file>icon/dark/box.svg</file>
<file>icon/dark/calendar.svg</file>
<file>icon/dark/download.svg</file>
<file>icon/dark/folder.svg</file>
<file>icon/dark/globe.svg</file>
<file>icon/dark/leftbutton_0.svg</file>
<file>icon/dark/leftbutton_1.svg</file>
<file>icon/dark/leftbutton_2.svg</file>
<file>icon/dark/leftbutton_3.svg</file>
<file>icon/dark/leftbutton_4.svg</file>
<file>icon/dark/leftbutton_5.svg</file>
<file>icon/dark/leftbutton_6.svg</file>
<file>icon/dark/leftbutton_7.svg</file>
<file>icon/dark/leftbutton_8.svg</file>
<file>icon/dark/leftbutton_9.svg</file>
<file>icon/dark/leftbutton_10.svg</file>
<file>icon/dark/leftbutton_11.svg</file>
<file>icon/dark/leftbutton_12.svg</file>
<file>icon/dark/text.svg</file>
<file>icon/dark/update.svg</file>
<file>icon/light/back.svg</file>
<file>icon/light/download.svg</file>
<file>icon/light/leftbutton_0.svg</file>
<file>icon/light/leftbutton_1.svg</file>
<file>icon/light/leftbutton_2.svg</file>
<file>icon/light/leftbutton_3.svg</file>
<file>icon/light/leftbutton_4.svg</file>
<file>icon/light/leftbutton_5.svg</file>
<file>icon/light/leftbutton_6.svg</file>
<file>icon/light/leftbutton_7.svg</file>
<file>icon/light/leftbutton_8.svg</file>
<file>icon/light/leftbutton_9.svg</file>
<file>icon/light/leftbutton_10.svg</file>
<file>icon/light/leftbutton_11.svg</file>
<file>icon/light/leftbutton_12.svg</file>
<file>icon/light/box.svg</file>
<file>icon/light/calendar.svg</file>
<file>icon/light/globe.svg</file>
<file>icon/light/folder.svg</file>
<file>icon/light/text.svg</file>
<file>icon/light/update.svg</file>
<file>icon/logo.svg</file>
<file>tags/a2d-small.png</file>
<file>tags/a2d.png</file>
<file>tags/community-small.png</file>
<file>tags/community.png</file>
<file>tags/community.svg</file>
<file>tags/deepin-small.png</file>
<file>tags/deepin.svg</file>
<file>tags/dtk-small.png</file>
<file>tags/dwine2-small.png</file>
<file>tags/dwine5-small.png</file>
<file>tags/dwine5.svg</file>
<file>tags/logo_icon.svg</file>
<file>tags/ubuntu-small.png</file>
<file>tags/ubuntu.png</file>
<file>tags/uos-authorize.svg</file>
<file>tags/uos-small.png</file>
<file>tags/uos.svg</file>
</qresource>
</RCC>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -1,9 +1,11 @@
#include "downloadworker.h"
#include <QEventLoop>
#include <QProcess>
#include <QRegularExpression>
#include <QDir>
#include <QtConcurrent>
#include <QStandardPaths>
DownloadController::DownloadController(QObject *parent)
{
@@ -48,7 +50,7 @@ bool checkMeatlink(QString metaUrl)
void gennerateDomain(QVector<QString> &domains)
{
QFile serverList(QDir::homePath().toUtf8() + "/.config/spark-store/server.list");
QFile serverList(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/server.list");
if (serverList.open(QFile::ReadOnly))
{
QStringList list = QString(serverList.readAll()).trimmed().split("\n");
@@ -87,14 +89,17 @@ void DownloadController::startDownload(const QString &url)
}
QtConcurrent::run([=]()
{
{
QString metaUrl = url + ".metalink";
qDebug() << "metalink" << metaUrl;
bool useMetalink = false;
if (checkMeatlink(metaUrl)){
if (checkMeatlink(metaUrl))
{
useMetalink = true;
qDebug() << "useMetalink:" << useMetalink;
}else{
}
else
{
gennerateDomain(domains);
// qDebug() << domains << domains.size();
}
@@ -111,10 +116,12 @@ void DownloadController::startDownload(const QString &url)
QString aria2ConnectionMax = "--max-concurrent-downloads=16";
QString aria2DNSCommand = "--async-dns-server=119.29.29.29,223.5.5.5";
if (useMetalink){
if (useMetalink)
{
command.append(metaUrl.toUtf8());
}
else{
else
{
for (int i = 0; i < domains.size(); i++)
{
command.append(replaceDomain(url, domains.at(i)).replace("+","%2B").toUtf8()); //对+进行转译避免oss出错
@@ -133,7 +140,8 @@ void DownloadController::startDownload(const QString &url)
command.append(aria2ConnectionPerServer.toUtf8());
command.append(aria2ConnectionMax.toUtf8());
command.append(aria2DNSCommand.toUtf8());
if (useMetalink){
if (useMetalink)
{
command.append(aria2NoSeeds.toUtf8());
}
qDebug() << command;
@@ -144,8 +152,7 @@ void DownloadController::startDownload(const QString &url)
cmd->start();
cmd->waitForStarted(); //等待启动完成
QObject::connect(cmd, &QProcess::readyReadStandardOutput,
[&]()
QObject::connect(cmd, &QProcess::readyReadStandardOutput, [&]()
{
//通过读取输出计算下载速度
QString message = cmd->readAllStandardOutput().data();
@@ -188,8 +195,7 @@ void DownloadController::startDownload(const QString &url)
emit downloadProcess(speedInfo, downloadSizeRecord, fileSize);
}
});
QObject::connect(cmd, &QProcess::readyReadStandardError,
[&]()
QObject::connect(cmd, &QProcess::readyReadStandardError, [&]()
{
emit errorOccur(cmd->readAllStandardError().data());
return;
@@ -222,10 +228,16 @@ void DownloadController::startDownload(const QString &url)
*/
void DownloadController::stopDownload()
{
if (pidNumber < 0)
{
return;
}
// 实现下载进程退出
QString killCmd = QString("kill -9 %1").arg(pidNumber);
system(killCmd.toUtf8());
qDebug() << "kill aria2!";
pidNumber = -1;
}
qint64 DownloadController::getFileSize(const QString &url)

View File

@@ -21,7 +21,7 @@ public:
private:
int threadNum;
int pidNumber;
int pidNumber = -1;
QString filename;
qint64 fileSize;
QVector<QPair<qint64, qint64>> ranges;

View File

@@ -1,39 +1,45 @@
#include "sparkapi.h"
#include <QSettings>
#include <QStandardPaths>
#include <QDebug>
QString SparkAPI::serverUrl = "";
SparkAPI::SparkAPI(QObject *parent) : QObject(parent)
{
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
if (!readConfig.value("server/choose").toString().isEmpty() && readConfig.value("server/updated").toString() == "TRUE")
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
if (!config.value("server/choose").toString().isEmpty() && config.value("server/updated").toBool())
{
SparkAPI::setServerUrl(readConfig.value("server/choose").toString());
SparkAPI::setServerUrl(config.value("server/choose").toString());
}
}
void SparkAPI::get(QUrl url)
{
QNetworkRequest request;
HttpRequest *httprequest = new HttpRequest;
request.setUrl(QUrl(url.toString().replace("+", "%2B")));
connect(httprequest, &HttpRequest::finished, [=](QString data)
{
{
QByteArray arr = data.toUtf8();
//解析Json
QJsonParseError error;
if(QJsonDocument::fromJson(arr,&error).isArray())
{
auto doc = QJsonDocument::fromJson(arr,&error).array();
emit finished(doc);
}else {
auto doc = QJsonDocument::fromJson(arr,&error).object();
emit finishedObject(doc);
}
// 解析 Json
QJsonParseError error;
if(QJsonDocument::fromJson(arr,&error).isArray())
{
auto doc = QJsonDocument::fromJson(arr,&error).array();
emit finished(doc);
} else {
auto doc = QJsonDocument::fromJson(arr,&error).object();
emit finishedObject(doc);
}
httprequest->deleteLater();
});
httprequest->deleteLater(); });
httprequest->getRequest(request);
}
void SparkAPI::getRAW(QUrl url)
{
QNetworkRequest request;
@@ -45,30 +51,37 @@ void SparkAPI::getRAW(QUrl url)
httprequest->deleteLater(); });
httprequest->getRequest(request);
}
void SparkAPI::getAppList(QString type)
{
get(QUrl(getServerUrl() + "store/" + type + "/applist.json"));
}
void SparkAPI::getSearchList(QString keyword)
{
get(QUrl("https://search.deepinos.org.cn/appinfo/search?keyword=" + keyword));
}
void SparkAPI::getAppInfo(QUrl spk)
{
get(QUrl(getServerUrl() + "store" + spk.path().replace("+", "%2B") + "/app.json"));
}
void SparkAPI::getAppDownloadTimes(QUrl spk)
{
getRAW(QUrl(getServerUrl() + "store" + spk.path().replace("+", "%2B") + "/download-times.txt"));
}
QString SparkAPI::getServerUrl()
{
return SparkAPI::serverUrl;
}
QString SparkAPI::getImgServerUrl()
{
return SparkAPI::serverUrl;
}
void SparkAPI::setServerUrl(QString url)
{
SparkAPI::serverUrl = url;

View File

@@ -1,16 +1,21 @@
#ifndef SPARKAPI_H
#define SPARKAPI_H
#include "utils/httprequest.h"
#include <QObject>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
#include "utils/httprequest.h"
#include <QSettings>
#include <QDir>
class SparkAPI : public QObject
{
Q_OBJECT
public:
explicit SparkAPI(QObject *parent = nullptr);
static QString getServerUrl();
static QString getImgServerUrl();
static void setServerUrl(QString url);
@@ -20,17 +25,14 @@ public:
void getRAW(QUrl url);
void getAppList(QString type);
void getAppInfo(QUrl spk);
explicit SparkAPI(QObject *parent = nullptr);
private:
static QString serverUrl;
signals:
void finished(QJsonArray);
void finishedRAW(QString);
void finishedObject(QJsonObject);
public slots:
private:
static QString serverUrl;
};
#endif // SPARKAPI_H

View File

@@ -1,13 +1,11 @@
#include "application.h"
#include "mainwindow-dtk.h"
#include <DApplication>
#include <DLog>
#include <DPlatformWindowHandle>
#include <DApplicationSettings>
#include <DAboutDialog>
#include <QLabel>
#include <DWidgetUtil>
#include <DSysInfo>
#include <DApplicationSettings>
#include <DWidgetUtil>
#include <QStandardPaths>
DCORE_USE_NAMESPACE
DWIDGET_USE_NAMESPACE
@@ -18,35 +16,36 @@ int main(int argc, char *argv[])
static const QString version = "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");
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
QSettings *setConfig = new QSettings(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
static const QString buildDateTime = buildDate.toString("yyyy.MM.dd") + "-" + buildTime.toString("hh:mm:ss");
// 设置桌面环境环境变量
bool isDeepinOS = true;
if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin"))
{
setenv("XDG_CURRENT_DESKTOP", "Deepin", 1);
qputenv("XDG_CURRENT_DESKTOP", "Deepin");
isDeepinOS = false;
}
bool isWayland = false;
auto e = QProcessEnvironment::systemEnvironment();
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));
if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive))
{
isWayland = true;
}
setConfig->setValue("build/isWayland", isWayland);
setConfig->setValue("build/isDeepinOS", isDeepinOS);
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 (!readConfig.contains("build/useWayland"))
if (!config.contains("build/useWayland"))
{
setConfig->setValue("build/useWayland", true);
config.setValue("build/useWayland", true);
}
bool useWayland = readConfig.value("build/useWayland").toBool();
bool useWayland = config.value("build/useWayland").toBool();
qDebug() << "System Wayland enabled:" << isWayland << ". Spark Wayland enabled:" << useWayland;
// Set display backend
@@ -62,104 +61,55 @@ int main(int argc, char *argv[])
{
qputenv("QT_QPA_PLATFORM", "dxcb");
}
// 龙芯机器配置,使得 DApplication 能正确加载 QTWEBENGINE
qputenv("DTK_FORCE_RASTER_WIDGETS", "FALSE");
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-features=UseModernMediaControls");
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-web-security");
// 浏览器开启 GPU 支持
#ifdef __sw_64__
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode --no-sandbox");
#else
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode");
#endif
DApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 开启 Hidpi 支持
// 浏览器开启 GPU 支持
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode");
// 强制使用 DTK 平台插件
QVector<char *> fakeArgs(argc + 2);
fakeArgs[0] = argv[0];
QString fakeArgs1 = "-platformtheme";
QByteArray fakeArgsTemp = fakeArgs1.toLatin1(); // must
fakeArgs[1] = fakeArgsTemp.data();
fakeArgs1 = "deepin";
fakeArgsTemp = fakeArgs1.toLatin1(); // must
fakeArgs[2] = fakeArgsTemp.data();
fakeArgs[1] = const_cast<char *>("-platformtheme");
fakeArgs[2] = const_cast<char *>("deepin");
for (int i = 1; i < argc; i++)
{
fakeArgs[i + 2] = argv[i];
int fakeArgc = argc + 2; // DApplication的argc要用引用避免c++编译器优化
DApplication a(fakeArgc, fakeArgs.data());
// 初始化日志模块 (默认日志位置 ~/.cache/deepin/spark-store)
DLogManager::registerConsoleAppender();
DLogManager::registerFileAppender();
// Wayland 环境下使用,防止子控件 Native 化
if (!DPlatformWindowHandle::pluginVersion().isEmpty())
{
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
}
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
a.setApplicationDisplayName("Spark Store");
int fakeArgc = argc + 2; // QCoreApplication 的 argc 要用引用,避免 c++ 编译器优化
Application a(fakeArgc, fakeArgs.data());
// 设置版本和构建时间
a.setVersionAndBuildDateTime(version, buildDateTime);
a.loadTranslator(); // 载入翻译
if (readConfig.value("build/version").toString() != version)
{
qDebug() << "Spark Store has been updated!";
setConfig->setValue("build/version", version);
setConfig->setValue("build/time", buildDate.toString("yyyy.MM.dd") + "-" + buildTime.toString());
}
setConfig->deleteLater();
// Customized DAboutDialog
DAboutDialog dialog;
a.setAboutDialog(&dialog);
dialog.setLicense(QObject::tr("We publish this program under GPL V3"));
dialog.setVersion(DApplication::buildVersion(readConfig.value("build/version").toString() + "-" + "Flamescion" + "-" + readConfig.value("build/time").toString()));
dialog.setProductIcon(QIcon::fromTheme("spark-store")); // 设置Logo
dialog.setProductName(QLabel::tr("Spark Store"));
dialog.setDescription(
QObject::tr(
"<span style=' font-size:10pt;font-weight:60;'>An appstore powered by community</span><br/>"
"<a href='https://www.spark-app.store/'>https://www.spark-app.store</a><br/>"
"<span style=' font-size:12pt;'>Spark developers</span>"));
dialog.setProductName(QLabel::tr("Spark Store"));
dialog.setCompanyLogo(QPixmap(":/spark-store.png"));
dialog.setWebsiteName(QObject::tr("The Spark Project"));
dialog.setWebsiteLink("https://gitee.com/deepin-community-store");
a.setOrganizationName("spark-union");
a.setProductName(QObject::tr("Spark Store"));
a.setApplicationName("Spark Store"); // 不用翻译,影响 ~/.local/share/spark-union 下文件夹名称
a.setApplicationDisplayName(QObject::tr("Spark Store")); // 设置窗口显示标题 (Wayland 下会显示 Qt 原生标题栏)
a.setWindowIcon(QIcon::fromTheme("spark-store"));
a.setApplicationDescription(
QObject::tr(
"<span style='font-size:10pt;font-weight:60;'>An appstore powered by deepin community</span><br/>"
"<a href='https://www.spark-app.store/'>https://www.spark-app.store</a><br/>"
"<span style='font-size:12pt;'>Spark developers</span><br/><br/>"
"Published under GPL V3"));
// 限制单实例运行
if (!a.setSingleInstance("spark-store"))
{
qDebug() << "The application is already running!";
QDBusInterface iface("com.gitee.spark.store",
"/com/gitee/spark/store",
"com.gitee.spark.store",
QDBusConnection::sessionBus());
QString arg1 = argv[1];
iface.asyncCall("activeWindow", arg1);
qWarning() << "Another instance has already started, activating...";
return -1;
}
DGuiApplicationHelper::instance()->setPaletteType(DGuiApplicationHelper::LightType); // 固定主题为浅色主题
DApplicationSettings settings; // 定义 DApplicationSettings自动保存主题设置
DApplicationSettings settings; // 定义 DApplicationSettings自动保存主题设置
MainWindow w;
// 让打开时界面显示在正中
Dtk::Widget::moveToCenter(&w);
QString arg1 = argv[1];
if (arg1.startsWith("spk://"))
if (argc > 1)
{
w.openUrl(QUrl(argv[1]));
QString arg1 = argv[1];
if (arg1.trimmed().startsWith("spk://"))
{
w.openUrl(QUrl(argv[1]));
}
}
w.show();
w.setWindowTitle("Spark Store");

View File

@@ -18,11 +18,12 @@ MainWindow::MainWindow(QWidget *parent)
: BaseWidgetOpacity(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle(QObject::tr("Spark Store"));
initConfig();
moveToCenter(this); // 让窗口居中显示
WidgetAnimation::widgetOpacity(this, true);
searchEdit = new DSearchEdit(ui->titlebar);
downloadlistwidget = new DownloadListWidget;
downloadButton = new ProgressButton(ui->titlebar);
backButtom = new QPushButton(ui->titlebar);
@@ -75,9 +76,6 @@ MainWindow::MainWindow(QWidget *parent)
if (themeType == DGuiApplicationHelper::DarkType) {
//深色模式
setMaskColor(QColor("#2a2b2b"));
this->setStyleSheet("#mainpage{background-color: transparent;border-radius:14px;}\
QLabel#cardtitle,QLabel#title,QLabel#title_1,QLabel#title_2,QLabel#title_3 {color:#FFFFFF}\
");
backButtom->setIcon(QIcon(":/icon/dark/back.svg"));
downloadButton->setIcon(":/icon/dark/download.svg");
downloadButton->setBackgroundColor(QColor("#444444"));
@@ -98,9 +96,6 @@ MainWindow::MainWindow(QWidget *parent)
} else {
//亮色模式
setMaskColor(QColor("#f3f7f8"));
this->setStyleSheet("#mainpage{background-color: transparent;border-radius:14px;}\
QLabel#cardtitle,QLabel#title,QLabel#title_1,QLabel#title_2,QLabel#title_3 {color:#000000}\
");
backButtom->setIcon(QIcon(":/icon/light/back.svg"));
downloadButton->setBackgroundColor(QColor("#e3e4e4"));
downloadButton->setColor(QColor("#66CCFF"));
@@ -153,18 +148,17 @@ MainWindow::MainWindow(QWidget *parent)
backButtom->hide();
ui->titlebar->setIcon(QIcon::fromTheme(":/icon/logo.svg"));
// Check wayland configs
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
QWidget *w_titlebar = new QWidget(ui->titlebar);
QHBoxLayout *ly_titlebar = new QHBoxLayout(w_titlebar);
QLabel *title = new QLabel(this);
QLabel *title = new QLabel(ui->titlebar);
title->setText(tr("Spark Store"));
searchEdit->setPlaceholderText(tr("Search or enter spk://"));
ly_titlebar->addWidget(title);
ly_titlebar->addWidget(backButtom);
if (!readConfig.value("build/isDeepinOS").toBool() && readConfig.value("build/useWayland").toBool())
// Check wayland configs
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
if (!config.value("build/isDeepinOS").toBool() && config.value("build/useWayland").toBool())
{
// Wayland 搜索栏居中
ly_titlebar->addStretch(WaylandSearchCenter);
@@ -219,14 +213,16 @@ MainWindow::MainWindow(QWidget *parent)
{ openUrl(spk); });
emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::instance()->themeType());
initDbus();
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::newProcessInstance, this, &MainWindow::onNewProcessInstance);
}
MainWindow::~MainWindow()
{
delete searchEdit;
delete downloadlistwidget;
delete ui;
if (downloadlistwidget) {
downloadlistwidget->deleteLater();
}
}
void MainWindow::initDbus()
@@ -240,13 +236,21 @@ void MainWindow::initDbus()
void MainWindow::onGetUrl(const QString &url)
{
if (url.left(6) == "spk://")
{
if (url.trimmed().startsWith("spk://")) {
openUrl(QUrl(url));
}
activateWindow();
}
void MainWindow::onNewProcessInstance(qint64 pid, const QStringList &arguments)
{
Q_UNUSED(pid)
if (arguments.size() > 1) {
onGetUrl(arguments.value(1));
}
}
void MainWindow::openUrl(QUrl url)
{
if (url.toString().startsWith("spk://"))
@@ -279,6 +283,7 @@ void MainWindow::switchPage(int now) // 临时方案,回家后修改
backButtom->hide();
}
ui->stackedWidget->setCurrentIndex(now);
ui->stackedWidget->currentWidget()->setFocus();
pageHistory << now;
}

View File

@@ -39,20 +39,20 @@ private:
void switchPage(int now);
void updateUi(int now);
private:
QList<int> pageHistory;
DownloadListWidget *downloadlistwidget;
ProgressButton *downloadButton;
QPushButton *backButtom;
DSearchEdit *searchEdit = new DSearchEdit;
Ui::MainWindow *ui;
private slots:
//接受来自dbus的url
void onGetUrl(const QString &url);
void onNewProcessInstance(qint64 pid, const QStringList &arguments);
void on_pushButton_14_clicked();
private:
QList<int> pageHistory;
Ui::MainWindow *ui;
DownloadListWidget *downloadlistwidget;
ProgressButton *downloadButton;
QPushButton *backButtom;
DSearchEdit *searchEdit;
};
#endif // MAINWINDOWDTK_H

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1190</width>
<height>651</height>
<height>656</height>
</rect>
</property>
<property name="windowTitle">
@@ -34,6 +34,12 @@
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="styleSheet">
<string notr="true">.QWidget#mainpage {
background: transparent;
border-radius: 14px;
}</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>

View File

@@ -272,7 +272,8 @@ void AppIntoPage::setTheme(bool dark)
{
if (dark)
{
QString frameStyleSheet = "#frame,#frame_2,#frame_3,#frame_4{background-color: #252525;border-radius:14px;border:1px solid rgb(64, 64, 64);}";
QString frameStyleSheet ="#frame,#frame_2,#frame_3,#frame_4 {background-color: #252525; border-radius: 14px; border: 1px solid rgb(64, 64, 64);}\
QLabel#cardtitle,QLabel#title,QLabel#title_1,QLabel#title_2,QLabel#title_3 {color: #FFFFFF}";
ui->frame->setStyleSheet(frameStyleSheet);
ui->frame_2->setStyleSheet(frameStyleSheet);
ui->frame_3->setStyleSheet(frameStyleSheet);
@@ -284,11 +285,10 @@ void AppIntoPage::setTheme(bool dark)
ui->icon_4->setPixmap(QPixmap(":/icon/dark/text.svg"));
ui->icon_5->setPixmap(QPixmap(":/icon/dark/folder.svg"));
ui->icon_6->setPixmap(QPixmap(":/icon/dark/globe.svg"));
}
else
{
// 亮色模式
QString frameStyleSheet = "#frame,#frame_2,#frame_3,#frame_4{background-color: #fbfbfb;border-radius:14px;border:1px solid rgb(229,229,229);}";
}else {
//亮色模式
QString frameStyleSheet ="#frame,#frame_2,#frame_3,#frame_4 {background-color: #fbfbfb; border-radius: 14px; border: 1px solid rgb(229,229,229);}\
QLabel#cardtitle,QLabel#title,QLabel#title_1,QLabel#title_2,QLabel#title_3 {color: #000000}";
ui->frame->setStyleSheet(frameStyleSheet);
ui->frame_2->setStyleSheet(frameStyleSheet);
ui->frame_3->setStyleSheet(frameStyleSheet);
@@ -336,29 +336,30 @@ void AppIntoPage::on_downloadButton_clicked()
void AppIntoPage::on_pushButton_3_clicked()
{
QtConcurrent::run([=]()
{
ui->downloadButton->setEnabled(false);
ui->pushButton_3->setEnabled(false);
{
ui->downloadButton->setEnabled(false);
ui->pushButton_3->setEnabled(false);
QProcess uninstall;
uninstall.start("pkexec", QStringList() << "apt" << "purge" << "-y" << info["Pkgname"].toString().toLower());
uninstall.waitForFinished(-1);
QProcess uninstall;
uninstall.start("pkexec", QStringList() << "apt" << "purge" << "-y" << info["Pkgname"].toString().toLower());
uninstall.waitForFinished(-1);
QProcess check;
check.start("dpkg", QStringList() << "-s" << info["Pkgname"].toString().toLower());
check.waitForFinished(10*1000);
QProcess check;
check.start("dpkg", QStringList() << "-s" << info["Pkgname"].toString().toLower());
check.waitForFinished(10*1000);
if (check.readAllStandardOutput().isEmpty())
{
ui->downloadButton->setText(tr("Install"));
ui->pushButton_3->hide();
if (check.readAllStandardOutput().isEmpty())
{
ui->downloadButton->setText(tr("Install"));
ui->pushButton_3->hide();
updatesEnabled();
Utils::sendNotification("spark-store",tr("Spark Store"),tr("Uninstall succeeded"));
}
updatesEnabled();
Utils::sendNotification("spark-store",tr("Spark Store"),tr("Uninstall succeeded"));
}
ui->downloadButton->setEnabled(true);
ui->pushButton_3->setEnabled(true); });
ui->downloadButton->setEnabled(true);
ui->pushButton_3->setEnabled(true);
});
}
void AppIntoPage::on_shareButton_clicked()

View File

@@ -1,10 +1,22 @@
#include "settingspage.h"
#include "ui_settingspage.h"
#include "../backend/sparkapi.h"
#include "utils/utils.h"
#include <QSettings>
#include <QtConcurrent>
#include <QDebug>
#define TMP_PATH "/tmp/spark-store"
bool SettingsPage::isdownload = false;
SettingsPage::SettingsPage(QWidget *parent) : QWidget(parent),
ui(new Ui::SettingsPage)
SettingsPage::SettingsPage(QWidget *parent)
: QWidget(parent)
, ui(new Ui::SettingsPage)
{
ui->setupUi(this);
configCanSave = false;
initConfig();
}
@@ -25,20 +37,22 @@ void SettingsPage::setTheme(bool dark)
void SettingsPage::readServerList()
{
// 读取服务器列表并初始化
QFile file(QDir::homePath().toUtf8() + "/.config/spark-store/server.list");
QFile file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/server.list");
// 判断文件是否存在
if (!file.exists())
{
ui->comboBox_server->addItem("https://d.store.deepinos.org.cn/");
return;
}
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "无法读取server.list";
qWarning() << "无法读取 server.list";
return;
}
// 创建QTextStream对象
// 创建 QTextStream 对象
QTextStream textStream(&file);
QString lineData = textStream.readLine(); // 读取文件的第一行
@@ -71,12 +85,12 @@ void SettingsPage::initConfig()
readServerList();
// 读取服务器URL并初始化菜单项的链接
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
if (!readConfig.value("server/choose").toString().isEmpty() && readConfig.value("server/updated").toString() == "TRUE")
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
if (!config.value("server/choose").toString().isEmpty() && config.value("server/updated").toBool())
{
qDebug() << readConfig.value("server/choose").toString();
ui->comboBox_server->setCurrentText(readConfig.value("server/choose").toString());
SparkAPI::setServerUrl(readConfig.value("server/choose").toString());
qDebug() << config.value("server/choose").toString();
ui->comboBox_server->setCurrentText(config.value("server/choose").toString());
SparkAPI::setServerUrl(config.value("server/choose").toString());
}
configCanSave = true; //  防止触发保存配置信号
}
@@ -93,8 +107,8 @@ void SettingsPage::on_pushButton_updateServer_clicked()
ui->pushButton_updateServer->setEnabled(false);
ui->comboBox_server->clear();
QFile::remove(QDir::homePath().toUtf8() + "/.config/spark-store/server.list");
system("curl -o " + QDir::homePath().toUtf8() + "/.config/spark-store/server.list https://d.store.deepinos.org.cn/store/server-and-mirror.list");
QFile::remove(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/server.list");
system("curl -o " + QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation).toUtf8() + "/server.list https://d.store.deepinos.org.cn/store/server-and-mirror.list");
ui->pushButton_updateServer->setEnabled(true);
readServerList();
@@ -105,14 +119,14 @@ void SettingsPage::on_comboBox_server_currentIndexChanged(const QString &arg1)
{
SparkAPI::setServerUrl(arg1); // 服务器信息更新
qDebug() << arg1;
const QString updatedInfo = "TRUE";
if (configCanSave)
bool updatedInfo = true;
if(configCanSave)
{
// ui->label_setting1->show();
QSettings *setConfig = new QSettings(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
setConfig->setValue("server/choose", arg1);
setConfig->setValue("server/updated", updatedInfo);
setConfig->deleteLater();
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
config.setValue("server/choose", arg1);
config.setValue("server/updated", updatedInfo);
config.sync();
}
}
@@ -183,7 +197,8 @@ void SettingsPage::on_pushButton_updateApt_clicked()
emit openUrl(QUrl("spk://store/tools/spark-store"));
ui->label_aptserver->setText(tr(""));
ui->pushButton_updateApt->setEnabled(true); });
ui->pushButton_updateApt->setEnabled(true);
});
}
void SettingsPage::on_pushButton_clear_clicked()
@@ -207,13 +222,15 @@ void SettingsPage::on_pushButton_clear_clicked()
void SettingsPage::on_pushButton_clearWebCache_clicked()
{
QtConcurrent::run([=]()
{
QString dataLocal = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
qDebug() << dataLocal;
QDir dataDir(dataLocal);
{
QString localDataLocation = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/QtWebEngine";
qDebug() << localDataLocation;
QDir dataDir(localDataLocation);
dataDir.removeRecursively();
dataLocal = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
qDebug() << dataLocal;
QDir cacheDir(dataLocal);
cacheDir.removeRecursively(); });
QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/QtWebEngine";
qDebug() << cacheLocation;
QDir cacheDir(cacheLocation);
cacheDir.removeRecursively();
});
}

View File

@@ -2,14 +2,7 @@
#define SETTINGSPAGE_H
#include <QWidget>
#include <QFile>
#include <QDir>
#include <QDebug>
#include <QSettings>
#include <QtConcurrent>
#include "../backend/sparkapi.h"
#include "utils/utils.h"
#define TMP_PATH "/tmp/spark-store"
#include <QUrl>
namespace Ui {
class SettingsPage;

View File

@@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += core gui network concurrent webenginewidgets dbus svg
QT += core gui concurrent dbus network svg webenginewidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@@ -22,78 +22,75 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
DEFINES += QT_APP_DEBUG
# Disable qWarning / qDebug output in Release
# CONFIG(release, debug|release): DEFINES += QT_NO_WARNING_OUTPUT QT_NO_DEBUG_OUTPUT
CONFIG += c++11 link_pkgconfig
PKGCONFIG += dtkcore dtkgui dtkwidget
# Disable qWarning / qDebug output in Release
CONFIG(release, debug|release): DEFINES += QT_NO_WARNING_OUTPUT QT_NO_DEBUG_OUTPUT
# Update translation files
CONFIG(release, debug|release): system(bash $${PWD}/translate_generation.sh)
TRANSLATIONS += \
../translations/spark-store_en.ts \
../translations/spark-store_fr.ts \
../translations/spark-store_zh_CN.ts
SOURCES += \
dbus/dbussparkstoreservice.cpp \
main.cpp \
mainwindow-dtk.cpp \
backend/downloadworker.cpp \
backend/image_show.cpp \
backend/sparkapi.cpp \
dbus/dbussparkstoreservice.cpp \
pages/appintopage.cpp \
pages/applistpage.cpp \
pages/settingspage.cpp \
utils/httprequest.cpp \
utils/utils.cpp \
utils/widgetanimation.cpp \
widgets/common/progressbutton.cpp \
widgets/common/webenginepage.cpp \
widgets/common/webengineview.cpp \
widgets/downloadlistwidget.cpp \
widgets/base/basewidgetopacity.cpp \
widgets/common/downloaditem.cpp \
widgets/common/progressbutton.cpp \
widgets/common/smoothlistwidget.cpp \
widgets/common/smoothscrollbar.cpp \
utils/httprequest.cpp \
pages/applistpage.cpp \
backend/downloadworker.cpp \
pages/appintopage.cpp \
widgets/common/webenginepage.cpp \
widgets/common/webengineview.cpp \
widgets/big_image.cpp \
backend/image_show.cpp \
widgets/base/basewidgetopacity.cpp
widgets/downloadlistwidget.cpp \
application.cpp \
main.cpp \
mainwindow-dtk.cpp
HEADERS += \
dbus/dbussparkstoreservice.h \
mainwindow-dtk.h \
backend/downloadworker.h \
backend/image_show.h \
backend/sparkapi.h \
dbus/dbussparkstoreservice.h \
pages/appintopage.h \
pages/applistpage.h \
pages/settingspage.h \
utils/httprequest.h \
utils/utils.h \
utils/widgetanimation.h \
widgets/common/progressbutton.h \
widgets/common/webenginepage.h \
widgets/common/webengineview.h \
widgets/downloadlistwidget.h \
widgets/base/basewidgetopacity.h \
widgets/common/downloaditem.h \
widgets/common/progressbutton.h \
widgets/common/smoothlistwidget.h \
widgets/common/smoothscrollbar.h \
utils/httprequest.h \
pages/applistpage.h \
backend/downloadworker.h \
pages/appintopage.h \
widgets/common/webenginepage.h \
widgets/common/webengineview.h \
widgets/big_image.h \
backend/image_show.h \
widgets/base/basewidgetopacity.h
widgets/downloadlistwidget.h \
application.h \
mainwindow-dtk.h
FORMS += \
mainwindow-dtk.ui \
pages/settingspage.ui \
widgets/downloadlistwidget.ui \
widgets/common/downloaditem.ui \
pages/appintopage.ui \
pages/applistpage.ui \
pages/appintopage.ui
pages/settingspage.ui \
widgets/common/downloaditem.ui \
widgets/downloadlistwidget.ui \
mainwindow-dtk.ui
RESOURCES += \
assets/assets.qrc
TRANSLATIONS += \
../translations/spark-store_en.ts \
../translations/spark-store_fr.ts \
../translations/spark-store_zh_CN.ts
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/durapps/$${TARGET}/bin

View File

@@ -55,7 +55,6 @@ DownloadListWidget::~DownloadListWidget()
if (downloadController)
{
downloadController->stopDownload();
downloadController->deleteLater();
}
delete ui;