format: 代码格式化

This commit is contained in:
uniartisan 2022-12-23 12:13:48 +08:00
parent 89a3ab0b4c
commit fd4fdbe970
20 changed files with 473 additions and 469 deletions

@ -30,7 +30,6 @@ void DownloadController::setFilename(QString filename)
this->filename = filename; this->filename = filename;
} }
bool checkMeatlink(QString metaUrl) bool checkMeatlink(QString metaUrl)
{ {
QFile metaStatus("/tmp/spark-store/metaStatus.txt"); QFile metaStatus("/tmp/spark-store/metaStatus.txt");

@ -1,13 +1,12 @@
#include "image_show.h" #include "image_show.h"
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QScreen> // Qt5 不再建议使用 QDesktopWidget #include <QScreen> // Qt5 不再建议使用 QDesktopWidget
#include <QGuiApplication> #include <QGuiApplication>
image_show::image_show(QWidget *parent) : image_show::image_show(QWidget *parent) : QWidget(parent),
QWidget(parent), m_dialog(new big_image),
m_dialog(new big_image), m_label(new QLabel)
m_label(new QLabel)
{ {
QHBoxLayout *layout = new QHBoxLayout; QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(m_label); layout->addWidget(m_label);
@ -27,7 +26,7 @@ void image_show::setImage(QPixmap image)
desktop_w = QGuiApplication::primaryScreen()->geometry().width(); desktop_w = QGuiApplication::primaryScreen()->geometry().width();
desktop_h = QGuiApplication::primaryScreen()->geometry().height(); desktop_h = QGuiApplication::primaryScreen()->geometry().height();
if(screen0.width() > (desktop_w - 20) || screen0.height() > (desktop_h - 20)) if (screen0.width() > (desktop_w - 20) || screen0.height() > (desktop_h - 20))
{ {
re_screen1 = screen0.scaled(QSize(desktop_w - 20, desktop_h - 20), Qt::KeepAspectRatio, Qt::SmoothTransformation); re_screen1 = screen0.scaled(QSize(desktop_w - 20, desktop_h - 20), Qt::KeepAspectRatio, Qt::SmoothTransformation);
m_image = QPixmap::fromImage(re_screen1); m_image = QPixmap::fromImage(re_screen1);
@ -48,7 +47,7 @@ void image_show::mousePressEvent(QMouseEvent *)
// 识别主屏幕尺寸并设置 widget 大小 // 识别主屏幕尺寸并设置 widget 大小
m_dialog->setFixedSize(desktop_w, desktop_h); m_dialog->setFixedSize(desktop_w, desktop_h);
m_dialog->move(0,0); m_dialog->move(0, 0);
} }
image_show::~image_show() image_show::~image_show()
{ {

@ -7,7 +7,7 @@ QString SparkAPI::serverUrl = "";
SparkAPI::SparkAPI(QObject *parent) : QObject(parent) SparkAPI::SparkAPI(QObject *parent) : QObject(parent)
{ {
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat); QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
if(!readConfig.value("server/choose").toString().isEmpty() && readConfig.value("server/updated").toString() == "TRUE") if (!readConfig.value("server/choose").toString().isEmpty() && readConfig.value("server/updated").toString() == "TRUE")
{ {
SparkAPI::setServerUrl(readConfig.value("server/choose").toString()); SparkAPI::setServerUrl(readConfig.value("server/choose").toString());
} }
@ -15,9 +15,10 @@ SparkAPI::SparkAPI(QObject *parent) : QObject(parent)
void SparkAPI::get(QUrl url) void SparkAPI::get(QUrl url)
{ {
QNetworkRequest request; QNetworkRequest request;
HttpRequest *httprequest=new HttpRequest; HttpRequest *httprequest = new HttpRequest;
request.setUrl(QUrl(url.toString().replace("+","%2B"))); request.setUrl(QUrl(url.toString().replace("+", "%2B")));
connect(httprequest,&HttpRequest::finished,[=](QString data){ connect(httprequest, &HttpRequest::finished, [=](QString data)
{
QByteArray arr = data.toUtf8(); QByteArray arr = data.toUtf8();
//解析Json //解析Json
QJsonParseError error; QJsonParseError error;
@ -30,36 +31,35 @@ void SparkAPI::get(QUrl url)
emit finishedObject(doc); emit finishedObject(doc);
} }
httprequest->deleteLater(); httprequest->deleteLater(); });
});
httprequest->getRequest(request); httprequest->getRequest(request);
} }
void SparkAPI::getRAW(QUrl url) void SparkAPI::getRAW(QUrl url)
{ {
QNetworkRequest request; QNetworkRequest request;
HttpRequest *httprequest=new HttpRequest; HttpRequest *httprequest = new HttpRequest;
request.setUrl(QUrl(url.toString().replace("+","%2B"))); request.setUrl(QUrl(url.toString().replace("+", "%2B")));
connect(httprequest,&HttpRequest::finished,[=](QString data){ connect(httprequest, &HttpRequest::finished, [=](QString data)
{
emit finishedRAW(data); emit finishedRAW(data);
httprequest->deleteLater(); httprequest->deleteLater(); });
});
httprequest->getRequest(request); httprequest->getRequest(request);
} }
void SparkAPI::getAppList(QString type) void SparkAPI::getAppList(QString type)
{ {
get(QUrl(getServerUrl()+"store/"+type+"/applist.json")); get(QUrl(getServerUrl() + "store/" + type + "/applist.json"));
} }
void SparkAPI::getSearchList(QString keyword) void SparkAPI::getSearchList(QString keyword)
{ {
get(QUrl("https://search.deepinos.org.cn/appinfo/search?keyword="+keyword)); get(QUrl("https://search.deepinos.org.cn/appinfo/search?keyword=" + keyword));
} }
void SparkAPI::getAppInfo(QUrl spk) void SparkAPI::getAppInfo(QUrl spk)
{ {
get(QUrl(getServerUrl()+"store"+spk.path().replace("+","%2B") + "/app.json")); get(QUrl(getServerUrl() + "store" + spk.path().replace("+", "%2B") + "/app.json"));
} }
void SparkAPI::getAppDownloadTimes(QUrl spk) void SparkAPI::getAppDownloadTimes(QUrl spk)
{ {
getRAW(QUrl(getServerUrl()+"store"+spk.path().replace("+","%2B") + "/download-times.txt")); getRAW(QUrl(getServerUrl() + "store" + spk.path().replace("+", "%2B") + "/download-times.txt"));
} }
QString SparkAPI::getServerUrl() QString SparkAPI::getServerUrl()
{ {

@ -3,10 +3,9 @@
DBusSparkStoreService::DBusSparkStoreService(QObject *parent) DBusSparkStoreService::DBusSparkStoreService(QObject *parent)
: QDBusAbstractAdaptor(parent) : QDBusAbstractAdaptor(parent)
{ {
} }
void DBusSparkStoreService::activeWindow(const QString & arg) void DBusSparkStoreService::activeWindow(const QString &arg)
{ {
emit sigOpenUrl(arg); emit sigOpenUrl(arg);
} }

@ -16,55 +16,57 @@ int main(int argc, char *argv[])
{ {
// Get build time // Get build time
static const QString version = "Version 4.1.1"; static const QString version = "Version 4.1.1";
static const QDate buildDate = QLocale( QLocale::English ).toDate( QString(__DATE__).replace(" ", " 0"), "MMM dd yyyy"); 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 QTime buildTime = QTime::fromString(__TIME__, "hh:mm:ss");
//设置桌面环境环境变量 // 设置桌面环境环境变量
if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin")) { if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin"))
{
setenv("XDG_CURRENT_DESKTOP", "Deepin", 1); setenv("XDG_CURRENT_DESKTOP", "Deepin", 1);
} }
bool isWayland = false; bool isWayland = false;
auto e = QProcessEnvironment::systemEnvironment(); auto e = QProcessEnvironment::systemEnvironment();
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE")); QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY")); QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));
if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive)){ if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive))
{
isWayland = true; isWayland = true;
} }
qDebug() << "Wayland enabled:" << isWayland; qDebug() << "Wayland enabled:" << isWayland;
if(isWayland && !Dtk::Core::DSysInfo::isDDE()){ if (isWayland && !Dtk::Core::DSysInfo::isDDE())
{
qputenv("QT_QPA_PLATFORM", "wayland"); qputenv("QT_QPA_PLATFORM", "wayland");
} }
else if (isWayland && Dtk::Core::DSysInfo::isDDE()){ else if (isWayland && Dtk::Core::DSysInfo::isDDE())
{
qputenv("QT_QPA_PLATFORM", "dwayland"); qputenv("QT_QPA_PLATFORM", "dwayland");
} }
else { else
{
qputenv("QT_QPA_PLATFORM", "dxcb"); qputenv("QT_QPA_PLATFORM", "dxcb");
} }
DApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 开启 Hidpi 支持 DApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 开启 Hidpi 支持
// 浏览器开启 GPU 支持 // 浏览器开启 GPU 支持
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode"); qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode");
QVector<char*> fakeArgs(argc + 2); QVector<char *> fakeArgs(argc + 2);
fakeArgs[0] = argv[0]; fakeArgs[0] = argv[0];
fakeArgs[1] = "-platformtheme"; fakeArgs[1] = "-platformtheme";
fakeArgs[2] = "deepin"; fakeArgs[2] = "deepin";
for(int i = 1; i < argc; i++) fakeArgs[i + 2] = argv[i]; for (int i = 1; i < argc; i++)
int fakeArgc = argc + 2; // 为啥DApplication的argc要用引用啊 fakeArgs[i + 2] = argv[i];
int fakeArgc = argc + 2; // DApplication的argc要用引用避免c++编译器优化
DApplication a(fakeArgc, fakeArgs.data()); DApplication a(fakeArgc, fakeArgs.data());
// 初始化日志模块 (默认日志位置 ~/.cache/deepin/spark-store)
//初始化日志模块 (默认日志位置 ~/.cache/deepin/spark-store)
DLogManager::registerConsoleAppender(); DLogManager::registerConsoleAppender();
DLogManager::registerFileAppender(); DLogManager::registerFileAppender();
// Wayland 环境下使用,防止子控件 Native 化
//Wayland 环境下使用,防止子控件 Native 化 if (!DPlatformWindowHandle::pluginVersion().isEmpty())
if (!DPlatformWindowHandle::pluginVersion().isEmpty()) { {
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
} }
a.setAttribute(Qt::AA_UseHighDpiPixmaps); a.setAttribute(Qt::AA_UseHighDpiPixmaps);
@ -74,50 +76,47 @@ int main(int argc, char *argv[])
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat); QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
if (readConfig.value("build/version").toString() != version){ if (readConfig.value("build/version").toString() != version)
{
qDebug() << "Spark Store has been updated!"; qDebug() << "Spark Store has been updated!";
QSettings *setConfig = new QSettings(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat); QSettings *setConfig = new QSettings(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
setConfig->setValue("build/version", version); setConfig->setValue("build/version", version);
setConfig->setValue("build/time", buildDate.toString("yyyy.MM.dd")+"-"+buildTime.toString()); setConfig->setValue("build/time", buildDate.toString("yyyy.MM.dd") + "-" + buildTime.toString());
setConfig->deleteLater(); setConfig->deleteLater();
} }
//Customized DAboutDialog // Customized DAboutDialog
DAboutDialog dialog; DAboutDialog dialog;
a.setAboutDialog(&dialog); a.setAboutDialog(&dialog);
dialog.setLicense(QObject::tr("We publish this program under GPL V3")); 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.setVersion(DApplication::buildVersion(readConfig.value("build/version").toString() + "-" + "Flamescion" + "-" + readConfig.value("build/time").toString()));
dialog.setProductIcon(QIcon::fromTheme("spark-store")); // 设置Logo dialog.setProductIcon(QIcon::fromTheme("spark-store")); // 设置Logo
dialog.setProductName(QLabel::tr("Spark Store")); dialog.setProductName(QLabel::tr("Spark Store"));
dialog.setDescription( dialog.setDescription(
QObject::tr( QObject::tr(
"<span style=' font-size:10pt;font-weight:60;'>An appstore powered by community</span><br/>" "<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/>" "<a href='https://www.spark-app.store/'>https://www.spark-app.store</a><br/>"
"<span style=' font-size:12pt;'>Spark developers</span>" "<span style=' font-size:12pt;'>Spark developers</span>"));
)
);
dialog.setProductName(QLabel::tr("Spark Store")); dialog.setProductName(QLabel::tr("Spark Store"));
dialog.setCompanyLogo(QPixmap(":/spark-store.png")); dialog.setCompanyLogo(QPixmap(":/spark-store.png"));
dialog.setWebsiteName(QObject::tr("The Spark Project")); dialog.setWebsiteName(QObject::tr("The Spark Project"));
dialog.setWebsiteLink("https://gitee.com/deepin-community-store"); dialog.setWebsiteLink("https://gitee.com/deepin-community-store");
a.setOrganizationName("spark-union"); a.setOrganizationName("spark-union");
a.setProductName(QObject::tr("Spark Store")); a.setProductName(QObject::tr("Spark Store"));
a.setApplicationName("Spark Store"); // 不用翻译,影响 ~/.local/share/spark-union 下文件夹名称 a.setApplicationName("Spark Store"); // 不用翻译,影响 ~/.local/share/spark-union 下文件夹名称
a.setApplicationDisplayName(QObject::tr("Spark Store")); // 设置窗口显示标题 (Wayland 下会显示 Qt 原生标题栏) a.setApplicationDisplayName(QObject::tr("Spark Store")); // 设置窗口显示标题 (Wayland 下会显示 Qt 原生标题栏)
a.setWindowIcon(QIcon::fromTheme("spark-store")); a.setWindowIcon(QIcon::fromTheme("spark-store"));
a.setApplicationDescription( a.setApplicationDescription(
QObject::tr( QObject::tr(
"<span style='font-size:10pt;font-weight:60;'>An appstore powered by deepin community</span><br/>" "<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/>" "<a href='https://www.spark-app.store/'>https://www.spark-app.store</a><br/>"
"<span style='font-size:12pt;'>Spark developers</span><br/><br/>" "<span style='font-size:12pt;'>Spark developers</span><br/><br/>"
"Published under GPL V3" "Published under GPL V3"));
)
);
// 限制单实例运行 // 限制单实例运行
if(!a.setSingleInstance("spark-store")) if (!a.setSingleInstance("spark-store"))
{ {
qDebug() << "The application is already running!"; qDebug() << "The application is already running!";
QDBusInterface iface("com.gitee.spark.store", QDBusInterface iface("com.gitee.spark.store",
@ -127,21 +126,21 @@ int main(int argc, char *argv[])
QString arg1 = argv[1]; QString arg1 = argv[1];
iface.asyncCall("activeWindow",arg1); iface.asyncCall("activeWindow", arg1);
return -1; return -1;
} }
DGuiApplicationHelper::instance()->setPaletteType(DGuiApplicationHelper::LightType); //固定主题为浅色主题 DGuiApplicationHelper::instance()->setPaletteType(DGuiApplicationHelper::LightType); // 固定主题为浅色主题
DApplicationSettings settings; // 定义 DApplicationSettings自动保存主题设置 DApplicationSettings settings; // 定义 DApplicationSettings自动保存主题设置
MainWindow w; MainWindow w;
// 让打开时界面显示在正中 // 让打开时界面显示在正中
Dtk::Widget::moveToCenter(&w); Dtk::Widget::moveToCenter(&w);
QString arg1 = argv[1]; QString arg1 = argv[1];
if (arg1.startsWith("spk://")) { if (arg1.startsWith("spk://"))
{
w.openUrl(QUrl(argv[1])); w.openUrl(QUrl(argv[1]));
} }
w.show(); w.show();

@ -11,14 +11,13 @@
#define AppPageSettings 3 #define AppPageSettings 3
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: BaseWidgetOpacity(parent) : BaseWidgetOpacity(parent), ui(new Ui::MainWindow)
, ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
initConfig(); initConfig();
moveToCenter(this); //让窗口居中显示 moveToCenter(this); // 让窗口居中显示
WidgetAnimation::widgetOpacity(this,true); WidgetAnimation::widgetOpacity(this, true);
downloadlistwidget = new DownloadListWidget; downloadlistwidget = new DownloadListWidget;
downloadButton = new ProgressButton(ui->titlebar); downloadButton = new ProgressButton(ui->titlebar);
@ -26,7 +25,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->appintopage->setDownloadWidget(downloadlistwidget); ui->appintopage->setDownloadWidget(downloadlistwidget);
ui->stackedWidget->setCurrentIndex(0); ui->stackedWidget->setCurrentIndex(0);
ui->titlebar->setBackgroundTransparent(true); ui->titlebar->setBackgroundTransparent(true);
//ui->titlebar->setSwitchThemeMenuVisible(false); // 去除 dtk 标题栏主题切换菜单 // ui->titlebar->setSwitchThemeMenuVisible(false); // 去除 dtk 标题栏主题切换菜单
setMaskAlpha(250); setMaskAlpha(250);
updateUi(0); updateUi(0);
@ -42,32 +41,34 @@ MainWindow::MainWindow(QWidget *parent)
menu->addAction(actionSubmissionWithClient); menu->addAction(actionSubmissionWithClient);
ui->titlebar->setMenu(menu); ui->titlebar->setMenu(menu);
connect(actionSubmission, &QAction::triggered, this, [=]{QDesktopServices::openUrl(QUrl("https://upload.deepinos.org/"));}); connect(actionSubmission, &QAction::triggered, this, [=]
connect(setting, &QAction::triggered, this, [=]{ { QDesktopServices::openUrl(QUrl("https://upload.deepinos.org/")); });
connect(setting, &QAction::triggered, this, [=]
{
switchPage(AppPageSettings); switchPage(AppPageSettings);
ui->settingspage->updateUI(); ui->settingspage->updateUI(); });
}); connect(upgrade, &QAction::triggered, this, [=]
connect(upgrade, &QAction::triggered, this, [=]{QProcess::startDetached("/opt/durapps/spark-store/bin/update-upgrade/ss-update-controler.sh");}); { QProcess::startDetached("/opt/durapps/spark-store/bin/update-upgrade/ss-update-controler.sh"); });
// 投稿器 // 投稿器
connect(actionSubmissionWithClient, &QAction::triggered, this, [=] connect(actionSubmissionWithClient, &QAction::triggered, this, [=]
{
QString submitterSpk = "spk://store/tools/spark-store-submitter";
QFile actionSubmissionClientStatus("/opt/spark-store-submitter/bin/spark-store-submitter");
if (actionSubmissionClientStatus.exists())
{ {
qDebug() << "投稿器存在"; QString submitterSpk = "spk://store/tools/spark-store-submitter";
QProcess::startDetached("/opt/spark-store-submitter/bin/spark-store-submitter"); QFile actionSubmissionClientStatus("/opt/spark-store-submitter/bin/spark-store-submitter");
} if (actionSubmissionClientStatus.exists())
else{ {
qDebug() << "投稿器不存在,跳转页面"; qDebug() << "投稿器存在";
openUrl(submitterSpk); QProcess::startDetached("/opt/spark-store-submitter/bin/spark-store-submitter");
} }
else
{
qDebug() << "投稿器不存在,跳转页面";
openUrl(submitterSpk);
}
});
}); // 主题切换
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [=](DGuiApplicationHelper::ColorType themeType)
{
//主题切换
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [=](DGuiApplicationHelper::ColorType themeType) {
if (themeType == DGuiApplicationHelper::DarkType) { if (themeType == DGuiApplicationHelper::DarkType) {
//深色模式 //深色模式
setMaskColor(QColor("#2a2b2b")); setMaskColor(QColor("#2a2b2b"));
@ -123,32 +124,32 @@ MainWindow::MainWindow(QWidget *parent)
ui->applistpage->setTheme(themeType == DGuiApplicationHelper::DarkType); ui->applistpage->setTheme(themeType == DGuiApplicationHelper::DarkType);
ui->applistpage_1->setTheme(themeType == DGuiApplicationHelper::DarkType); ui->applistpage_1->setTheme(themeType == DGuiApplicationHelper::DarkType);
ui->appintopage->setTheme(themeType == DGuiApplicationHelper::DarkType); ui->appintopage->setTheme(themeType == DGuiApplicationHelper::DarkType);
ui->settingspage->setTheme(themeType == DGuiApplicationHelper::DarkType); ui->settingspage->setTheme(themeType == DGuiApplicationHelper::DarkType); });
});
//初始化标题栏控件 // 初始化标题栏控件
connect(downloadButton, &ProgressButton::clicked, [=]() { connect(downloadButton, &ProgressButton::clicked, [=]()
{
QPoint pos; QPoint pos;
pos.setX(downloadButton->mapToGlobal(QPoint(0, 0)).x() + downloadButton->width() / 2 - downloadlistwidget->width() / 2); pos.setX(downloadButton->mapToGlobal(QPoint(0, 0)).x() + downloadButton->width() / 2 - downloadlistwidget->width() / 2);
pos.setY(downloadButton->mapToGlobal(QPoint(0, 0)).y() + downloadButton->height() + 5); pos.setY(downloadButton->mapToGlobal(QPoint(0, 0)).y() + downloadButton->height() + 5);
downloadlistwidget->m_move(pos.x(), pos.y()); downloadlistwidget->m_move(pos.x(), pos.y());
downloadlistwidget->show(); downloadlistwidget->show(); });
});
//appintopage按下下载按钮时标题栏下载列表按钮抖动 // appintopage按下下载按钮时标题栏下载列表按钮抖动
connect(ui->appintopage, &AppIntoPage::clickedDownloadBtn, [=]() { connect(ui->appintopage, &AppIntoPage::clickedDownloadBtn, [=]()
WidgetAnimation::widgetShake(downloadButton,6);//第一个参数是抖动的控件,第二个参数是抖动范围(像素) {
}); WidgetAnimation::widgetShake(downloadButton, 6); // 第一个参数是抖动的控件,第二个参数是抖动范围(像素)
});
connect(backButtom, &QPushButton::clicked, [=]() { connect(backButtom, &QPushButton::clicked, [=]()
{
ui->stackedWidget->setCurrentIndex(pageHistory.at(pageHistory.count() - 2)); ui->stackedWidget->setCurrentIndex(pageHistory.at(pageHistory.count() - 2));
pageHistory.removeLast(); pageHistory.removeLast();
if (pageHistory.count() > 1) { if (pageHistory.count() > 1) {
backButtom->show(); backButtom->show();
} else { } else {
backButtom->hide(); backButtom->hide();
} } });
});
downloadlistwidget->hide(); downloadlistwidget->hide();
backButtom->hide(); backButtom->hide();
ui->titlebar->setIcon(QIcon::fromTheme(":/icon/logo.svg")); ui->titlebar->setIcon(QIcon::fromTheme(":/icon/logo.svg"));
@ -164,21 +165,23 @@ MainWindow::MainWindow(QWidget *parent)
ly_titlebar->addWidget(downloadButton); ly_titlebar->addWidget(downloadButton);
ly_titlebar->addStretch(1); ly_titlebar->addStretch(1);
ui->titlebar->setCustomWidget(w_titlebar); ui->titlebar->setCustomWidget(w_titlebar);
//侧边栏按钮 // 侧边栏按钮
int i = 0; int i = 0;
while (i < ui->buttonGroup->buttons().size()) { while (i < ui->buttonGroup->buttons().size())
{
ui->buttonGroup->buttons()[i]->setStyleSheet("QPushButton{qproperty-icon: url(data/images/userMangaer/teacher.png);}"); ui->buttonGroup->buttons()[i]->setStyleSheet("QPushButton{qproperty-icon: url(data/images/userMangaer/teacher.png);}");
connect(ui->buttonGroup->buttons()[i], &QPushButton::toggled, [=](bool checked) { connect(ui->buttonGroup->buttons()[i], &QPushButton::toggled, [=](bool checked)
{
if (checked == true) { if (checked == true) {
searchEdit->clearEdit(); searchEdit->clearEdit();
updateUi(i); updateUi(i);
} } });
});
i++; i++;
} }
// 搜索事件 // 搜索事件
connect(searchEdit, &DSearchEdit::returnPressed, this, [=]() { connect(searchEdit, &DSearchEdit::returnPressed, this, [=]()
{
QString searchtext = searchEdit->text(); QString searchtext = searchEdit->text();
if (!searchtext.isEmpty()) { if (!searchtext.isEmpty()) {
if (searchtext.startsWith("spk://")) { if (searchtext.startsWith("spk://")) {
@ -189,22 +192,17 @@ MainWindow::MainWindow(QWidget *parent)
switchPage(AppPageSearchlist); switchPage(AppPageSearchlist);
} }
} }
this->setFocus(); this->setFocus(); });
});
connect(downloadlistwidget, &DownloadListWidget::downloadProgress, this, [=](int i) { connect(downloadlistwidget, &DownloadListWidget::downloadProgress, this, [=](int i)
downloadButton->setProgress(i); { downloadButton->setProgress(i); });
});
// 列表点击事件 // 列表点击事件
connect(ui->applistpage, &AppListPage::clicked, this, [=](QUrl spk) { connect(ui->applistpage, &AppListPage::clicked, this, [=](QUrl spk)
openUrl(spk); { openUrl(spk); });
}); connect(ui->applistpage_1, &AppListPage::clicked, this, [=](QUrl spk)
connect(ui->applistpage_1, &AppListPage::clicked, this, [=](QUrl spk) { { openUrl(spk); });
openUrl(spk); connect(ui->settingspage, &SettingsPage::openUrl, this, [=](QUrl spk)
}); { openUrl(spk); });
connect(ui->settingspage, &SettingsPage::openUrl, this, [=](QUrl spk) {
openUrl(spk);
});
emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::instance()->themeType()); emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::instance()->themeType());
initDbus(); initDbus();
@ -223,12 +221,12 @@ void MainWindow::initDbus()
QDBusConnection::sessionBus().registerService("com.gitee.spark.store"); QDBusConnection::sessionBus().registerService("com.gitee.spark.store");
QDBusConnection::sessionBus().registerObject("/com/gitee/spark/store", "com.gitee.spark.store", this); QDBusConnection::sessionBus().registerObject("/com/gitee/spark/store", "com.gitee.spark.store", this);
connect(dbusInter,&DBusSparkStoreService::sigOpenUrl,this,&MainWindow::onGetUrl); connect(dbusInter, &DBusSparkStoreService::sigOpenUrl, this, &MainWindow::onGetUrl);
} }
void MainWindow::onGetUrl(const QString &url) void MainWindow::onGetUrl(const QString &url)
{ {
if(url.left(6)=="spk://") if (url.left(6) == "spk://")
{ {
openUrl(QUrl(url)); openUrl(QUrl(url));
} }
@ -237,11 +235,14 @@ void MainWindow::onGetUrl(const QString &url)
void MainWindow::openUrl(QUrl url) void MainWindow::openUrl(QUrl url)
{ {
if (url.toString().startsWith("spk://")) { if (url.toString().startsWith("spk://"))
ui->appintopage->openUrl(QUrl(url.toString().replace("+","%2B"))); {
ui->appintopage->openUrl(QUrl(url.toString().replace("+", "%2B")));
switchPage(AppPageAppdetail); switchPage(AppPageAppdetail);
} else { }
QDesktopServices::openUrl(QUrl(url.toString().replace("+","%2B"))); else
{
QDesktopServices::openUrl(QUrl(url.toString().replace("+", "%2B")));
} }
} }
@ -252,50 +253,54 @@ void MainWindow::initConfig()
dir.mkpath("/tmp/spark-store"); dir.mkpath("/tmp/spark-store");
} }
void MainWindow::switchPage(int now) //临时方案,回家后修改 void MainWindow::switchPage(int now) // 临时方案,回家后修改
{ {
qDebug() << pageHistory.count(); qDebug() << pageHistory.count();
if (pageHistory.count() >= 1) { if (pageHistory.count() >= 1)
{
backButtom->show(); backButtom->show();
} else { }
else
{
backButtom->hide(); backButtom->hide();
} }
ui->stackedWidget->setCurrentIndex(now); ui->stackedWidget->setCurrentIndex(now);
pageHistory << now; pageHistory << now;
} }
//刷新界面 // 刷新界面
void MainWindow::updateUi(int now) void MainWindow::updateUi(int now)
{ {
pageHistory.clear(); pageHistory.clear();
QStringList itemlist; QStringList itemlist;
itemlist << "" itemlist << ""
<< "network" << "network"
<< "chat" << "chat"
<< "music" << "music"
<< "video" << "video"
<< "image_graphics" << "image_graphics"
<< "games" << "games"
<< "office" << "office"
<< "reading" << "reading"
<< "development" << "development"
<< "tools" << "tools"
<< "themes" << "themes"
<< "others"; << "others";
ui->applistpage->getAppList(itemlist[now]); ui->applistpage->getAppList(itemlist[now]);
qDebug() << itemlist[now]; qDebug() << itemlist[now];
switchPage(AppPageApplist); switchPage(AppPageApplist);
} }
void MainWindow::on_pushButton_14_clicked() void MainWindow::on_pushButton_14_clicked()
{ {
QFile upgradeStatus("/tmp/spark-store/upgradeStatus.txt"); QFile upgradeStatus("/tmp/spark-store/upgradeStatus.txt");
if (!upgradeStatus.exists()){ if (!upgradeStatus.exists())
QtConcurrent::run([=]{ {
QtConcurrent::run([=]
{
auto upgradeP = new QProcess(); auto upgradeP = new QProcess();
upgradeP->startDetached("/opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade.sh"); upgradeP->startDetached("/opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade.sh");
upgradeP->waitForStarted(); upgradeP->waitForStarted();
upgradeP->waitForFinished(-1); upgradeP->waitForFinished(-1); });
});
} }
} }

@ -1,20 +1,19 @@
#include "appintopage.h" #include "appintopage.h"
#include "ui_appintopage.h" #include "ui_appintopage.h"
AppIntoPage::AppIntoPage(QWidget *parent) : AppIntoPage::AppIntoPage(QWidget *parent) : QWidget(parent),
QWidget(parent), ui(new Ui::AppIntoPage)
ui(new Ui::AppIntoPage)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->listWidget->setViewMode(QListView::IconMode); ui->listWidget->setViewMode(QListView::IconMode);
ui->listWidget->setMovement(QListView::Static); ui->listWidget->setMovement(QListView::Static);
ui->listWidget->setMaximumHeight(200); ui->listWidget->setMaximumHeight(200);
ui->listWidget->setFlow(QListView::TopToBottom); ui->listWidget->setFlow(QListView::TopToBottom);
api1=new SparkAPI(this); api1 = new SparkAPI(this);
connect(api1,&SparkAPI::finishedRAW,[=](QString download_times){ connect(api1, &SparkAPI::finishedRAW, [=](QString download_times)
{
download_times.remove(QRegExp("\\n")); download_times.remove(QRegExp("\\n"));
ui->download_times->setText(download_times); ui->download_times->setText(download_times);
qDebug()<<"Download Times:"+download_times; qDebug()<<"Download Times:"+download_times; });
});
clear(); clear();
} }
@ -35,31 +34,31 @@ void AppIntoPage::clear()
ui->downloadButton->hide(); ui->downloadButton->hide();
ui->downloadButton->setEnabled(true); ui->downloadButton->setEnabled(true);
ui->pushButton_3->hide(); ui->pushButton_3->hide();
int n=ui->listWidget->count(); int n = ui->listWidget->count();
for(int i=0;i<n;i++) for (int i = 0; i < n; i++)
{ {
QListWidgetItem *item = ui->listWidget->takeItem(0); QListWidgetItem *item = ui->listWidget->takeItem(0);
QWidget *card = ui->listWidget->itemWidget(item); QWidget *card = ui->listWidget->itemWidget(item);
delete card; delete card;
card = NULL; card = NULL;
delete item; delete item;
item = NULL; item = NULL;
} }
ui->listWidget->clear(); ui->listWidget->clear();
} }
void AppIntoPage::setDownloadWidget(DownloadListWidget *w) void AppIntoPage::setDownloadWidget(DownloadListWidget *w)
{ {
dw=w; dw = w;
connect(w, &DownloadListWidget::downloadFinished, [=]() { connect(w, &DownloadListWidget::downloadFinished, [=]()
isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString()); { isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); });
});
} }
void AppIntoPage::openUrl(QUrl url) void AppIntoPage::openUrl(QUrl url)
{ {
spk=url; spk = url;
SparkAPI *api=new SparkAPI(this); SparkAPI *api = new SparkAPI(this);
clear(); clear();
connect(api,&SparkAPI::finishedObject,[=](QJsonObject appinfo){ connect(api, &SparkAPI::finishedObject, [=](QJsonObject appinfo)
{
info = appinfo; info = appinfo;
// qDebug()<<url; // qDebug()<<url;
@ -188,36 +187,42 @@ void AppIntoPage::openUrl(QUrl url)
} }
this->sltAppinfoTags(&taglist); this->sltAppinfoTags(&taglist);
disconnect(api,&SparkAPI::finished,nullptr,nullptr); disconnect(api,&SparkAPI::finished,nullptr,nullptr);
api->deleteLater(); api->deleteLater(); });
});
api->getAppInfo(url); api->getAppInfo(url);
api1->getAppDownloadTimes(url); api1->getAppDownloadTimes(url);
} }
void AppIntoPage::isDownloading(QUrl url) void AppIntoPage::isDownloading(QUrl url)
{ {
if (dw->getUrlList().lastIndexOf(url) == -1) { if (dw->getUrlList().lastIndexOf(url) == -1)
{
ui->downloadButton->setEnabled(true); ui->downloadButton->setEnabled(true);
return; return;
} else { }
else
{
ui->downloadButton->setEnabled(false); ui->downloadButton->setEnabled(false);
} }
ui->pushButton_3->hide(); ui->pushButton_3->hide();
if (dw->getDIList()[dw->getUrlList().lastIndexOf(url)]->download == 2) { if (dw->getDIList()[dw->getUrlList().lastIndexOf(url)]->download == 2)
{
ui->downloadButton->setEnabled(true); ui->downloadButton->setEnabled(true);
ui->downloadButton->setText(tr("Download")); ui->downloadButton->setText(tr("Download"));
} }
if (dw->getDIList()[dw->getUrlList().lastIndexOf(url)]->download == 1) { if (dw->getDIList()[dw->getUrlList().lastIndexOf(url)]->download == 1)
{
ui->downloadButton->setEnabled(true); ui->downloadButton->setEnabled(true);
ui->downloadButton->setText(tr("Install")); ui->downloadButton->setText(tr("Install"));
} }
if (dw->getDIList()[dw->getUrlList().lastIndexOf(url)]->isInstall) { if (dw->getDIList()[dw->getUrlList().lastIndexOf(url)]->isInstall)
{
ui->downloadButton->setEnabled(false); ui->downloadButton->setEnabled(false);
ui->downloadButton->setText(tr("Installing")); ui->downloadButton->setText(tr("Installing"));
return; return;
} }
if (dw->getDIList()[dw->getUrlList().lastIndexOf(url)]->download == 3) { if (dw->getDIList()[dw->getUrlList().lastIndexOf(url)]->download == 3)
{
ui->downloadButton->setEnabled(true); ui->downloadButton->setEnabled(true);
ui->downloadButton->setText(tr("Reinstall")); ui->downloadButton->setText(tr("Reinstall"));
ui->downloadButton->show(); ui->downloadButton->show();
@ -227,37 +232,37 @@ void AppIntoPage::isDownloading(QUrl url)
void AppIntoPage::sltAppinfoTags(QStringList *tagList) void AppIntoPage::sltAppinfoTags(QStringList *tagList)
{ {
foreach(const QString &tag, *tagList) foreach (const QString &tag, *tagList)
{ {
if(tag=="community") if (tag == "community")
{ {
ui->tag_community->show(); ui->tag_community->show();
} }
else if(tag=="ubuntu") else if (tag == "ubuntu")
{ {
ui->tag_ubuntu->show(); ui->tag_ubuntu->show();
} }
else if(tag=="deepin") else if (tag == "deepin")
{ {
ui->tag_deepin->show(); ui->tag_deepin->show();
} }
else if(tag=="uos") else if (tag == "uos")
{ {
ui->tag_uos->show(); ui->tag_uos->show();
} }
else if(tag=="dtk5") else if (tag == "dtk5")
{ {
ui->tag_dtk5->show(); ui->tag_dtk5->show();
} }
else if(tag=="dwine2") else if (tag == "dwine2")
{ {
ui->tag_dwine2->show(); ui->tag_dwine2->show();
} }
else if(tag=="dwine5") else if (tag == "dwine5")
{ {
ui->tag_dwine5->show(); ui->tag_dwine5->show();
} }
else if(tag=="a2d") else if (tag == "a2d")
{ {
ui->tag_a2d->show(); ui->tag_a2d->show();
} }
@ -265,9 +270,9 @@ void AppIntoPage::sltAppinfoTags(QStringList *tagList)
} }
void AppIntoPage::setTheme(bool dark) void AppIntoPage::setTheme(bool dark)
{ {
if(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);}";
ui->frame->setStyleSheet(frameStyleSheet); ui->frame->setStyleSheet(frameStyleSheet);
ui->frame_2->setStyleSheet(frameStyleSheet); ui->frame_2->setStyleSheet(frameStyleSheet);
ui->frame_3->setStyleSheet(frameStyleSheet); ui->frame_3->setStyleSheet(frameStyleSheet);
@ -279,9 +284,11 @@ void AppIntoPage::setTheme(bool dark)
ui->icon_4->setPixmap(QPixmap(":/icon/dark/text.svg")); ui->icon_4->setPixmap(QPixmap(":/icon/dark/text.svg"));
ui->icon_5->setPixmap(QPixmap(":/icon/dark/folder.svg")); ui->icon_5->setPixmap(QPixmap(":/icon/dark/folder.svg"));
ui->icon_6->setPixmap(QPixmap(":/icon/dark/globe.svg")); ui->icon_6->setPixmap(QPixmap(":/icon/dark/globe.svg"));
}else { }
//亮色模式 else
QString frameStyleSheet ="#frame,#frame_2,#frame_3,#frame_4{background-color: #fbfbfb;border-radius:14px;border:1px solid rgb(229,229,229);}"; {
// 亮色模式
QString frameStyleSheet = "#frame,#frame_2,#frame_3,#frame_4{background-color: #fbfbfb;border-radius:14px;border:1px solid rgb(229,229,229);}";
ui->frame->setStyleSheet(frameStyleSheet); ui->frame->setStyleSheet(frameStyleSheet);
ui->frame_2->setStyleSheet(frameStyleSheet); ui->frame_2->setStyleSheet(frameStyleSheet);
ui->frame_3->setStyleSheet(frameStyleSheet); ui->frame_3->setStyleSheet(frameStyleSheet);
@ -293,7 +300,6 @@ void AppIntoPage::setTheme(bool dark)
ui->icon_4->setPixmap(QPixmap(":/icon/light/text.svg")); ui->icon_4->setPixmap(QPixmap(":/icon/light/text.svg"));
ui->icon_5->setPixmap(QPixmap(":/icon/light/folder.svg")); ui->icon_5->setPixmap(QPixmap(":/icon/light/folder.svg"));
ui->icon_6->setPixmap(QPixmap(":/icon/light/globe.svg")); ui->icon_6->setPixmap(QPixmap(":/icon/light/globe.svg"));
} }
} }
AppIntoPage::~AppIntoPage() AppIntoPage::~AppIntoPage()
@ -303,34 +309,34 @@ AppIntoPage::~AppIntoPage()
void AppIntoPage::on_downloadButton_clicked() void AppIntoPage::on_downloadButton_clicked()
{ {
if(ui->downloadButton->text() == tr("Install")) if (ui->downloadButton->text() == tr("Install"))
{ {
dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())]->install(0); dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())]->install(0);
isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString()); isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString());
QObject::connect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())],&DownloadItem::finished,[=](){ QObject::connect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())], &DownloadItem::finished, [=]()
{
isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString()); isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString());
disconnect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())],&DownloadItem::finished,nullptr,nullptr); disconnect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())],&DownloadItem::finished,nullptr,nullptr); });
});
return; return;
} }
emit clickedDownloadBtn(); emit clickedDownloadBtn();
dw->addItem(info["Name"].toString(),info["Filename"].toString(),info["Pkgname"].toString(),iconpixmap,SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString()); dw->addItem(info["Name"].toString(), info["Filename"].toString(), info["Pkgname"].toString(), iconpixmap, SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString());
if(ui->downloadButton->text() == tr("Reinstall")) if (ui->downloadButton->text() == tr("Reinstall"))
{ {
dw->getDIList()[dw->allDownload - 1]->reinstall = true; dw->getDIList()[dw->allDownload - 1]->reinstall = true;
} }
ui->downloadButton->setEnabled(false); ui->downloadButton->setEnabled(false);
QObject::connect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())],&DownloadItem::finished,[=](){ QObject::connect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())], &DownloadItem::finished, [=]()
{
isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString()); isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString());
disconnect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())],&DownloadItem::finished,nullptr,nullptr); disconnect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())],&DownloadItem::finished,nullptr,nullptr); });
}); isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString());
isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString());
} }
void AppIntoPage::on_pushButton_3_clicked() void AppIntoPage::on_pushButton_3_clicked()
{ {
QtConcurrent::run([=]() QtConcurrent::run([=]()
{ {
ui->downloadButton->setEnabled(false); ui->downloadButton->setEnabled(false);
ui->pushButton_3->setEnabled(false); ui->pushButton_3->setEnabled(false);
@ -352,19 +358,17 @@ void AppIntoPage::on_pushButton_3_clicked()
} }
ui->downloadButton->setEnabled(true); ui->downloadButton->setEnabled(true);
ui->pushButton_3->setEnabled(true); ui->pushButton_3->setEnabled(true); });
});
} }
void AppIntoPage::on_shareButton_clicked() void AppIntoPage::on_shareButton_clicked()
{ {
qDebug() << "Share" << spk; qDebug() << "Share" << spk;
Utils::sendNotification("spark-store",tr("Spark Store"),tr("The URL has been copied to the clipboard")); Utils::sendNotification("spark-store", tr("Spark Store"), tr("The URL has been copied to the clipboard"));
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(spk.toString()); clipboard->setText(spk.toString());
} }
void AppIntoPage::on_updateButton_clicked() void AppIntoPage::on_updateButton_clicked()
{ {
QString feedbackSpk = "spk://store/chat/store.spark-app.feedback"; QString feedbackSpk = "spk://store/chat/store.spark-app.feedback";
@ -374,9 +378,9 @@ void AppIntoPage::on_updateButton_clicked()
qDebug() << "反馈器存在"; qDebug() << "反馈器存在";
QProcess::startDetached("sh /opt/durapps/store.spark-app.feedback/launch.sh"); QProcess::startDetached("sh /opt/durapps/store.spark-app.feedback/launch.sh");
} }
else{ else
{
qDebug() << "反馈器不存在,跳转页面"; qDebug() << "反馈器不存在,跳转页面";
openUrl(feedbackSpk); openUrl(feedbackSpk);
} }
} }

@ -1,48 +1,55 @@
#include "applistpage.h" #include "applistpage.h"
#include "ui_applistpage.h" #include "ui_applistpage.h"
AppListPage::AppListPage(QWidget *parent) : AppListPage::AppListPage(QWidget *parent) : QWidget(parent),
QWidget(parent), ui(new Ui::AppListPage)
ui(new Ui::AppListPage)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->webEngineView->page()->setBackgroundColor(Qt::transparent); ui->webEngineView->page()->setBackgroundColor(Qt::transparent);
} }
void AppListPage::setTheme(bool dark) void AppListPage::setTheme(bool dark)
{ {
isDark=dark; isDark = dark;
if(dark) if (dark)
{ {
this->setStyleSheet("#frame{background-color: #252525;border-radius:14px;border:1px solid rgb(64, 64, 64);}"); this->setStyleSheet("#frame{background-color: #252525;border-radius:14px;border:1px solid rgb(64, 64, 64);}");
}else { }
//亮色模式 else
{
// 亮色模式
this->setStyleSheet("#frame{background-color: #ffffff;border-radius:14px;border:1px solid rgb(229,229,229);}"); this->setStyleSheet("#frame{background-color: #ffffff;border-radius:14px;border:1px solid rgb(229,229,229);}");
} }
if(isSearch) if (isSearch)
{ {
getSearchList(nowType); getSearchList(nowType);
}else{ }
else
{
getAppList(nowType); getAppList(nowType);
} }
} }
void AppListPage::getAppList(QString type) void AppListPage::getAppList(QString type)
{ {
isSearch=false; isSearch = false;
nowType=type; nowType = type;
SparkAPI *api=new SparkAPI(this); SparkAPI *api = new SparkAPI(this);
QString url; QString url;
QString theme; QString theme;
if(isDark) if (isDark)
{ {
theme="theme=dark"; theme = "theme=dark";
}else{
theme="theme=light";
} }
if(type=="") else
{ {
url=api->getServerUrl()+"store/#/flamescion/?"+theme; theme = "theme=light";
}else{ }
url=api->getServerUrl()+"store/#/flamescion/applist?type="+type+"&"+theme; if (type == "")
{
url = api->getServerUrl() + "store/#/flamescion/?" + theme;
}
else
{
url = api->getServerUrl() + "store/#/flamescion/applist?type=" + type + "&" + theme;
} }
ui->webEngineView->setUrl(url); ui->webEngineView->setUrl(url);
@ -50,18 +57,20 @@ void AppListPage::getAppList(QString type)
void AppListPage::getSearchList(QString keyword) void AppListPage::getSearchList(QString keyword)
{ {
isSearch=true; isSearch = true;
nowType=keyword; nowType = keyword;
SparkAPI *api=new SparkAPI(this); SparkAPI *api = new SparkAPI(this);
QString url; QString url;
QString theme; QString theme;
if(isDark) if (isDark)
{ {
theme="theme=dark"; theme = "theme=dark";
}else{
theme="theme=light";
} }
url=api->getServerUrl()+"store/#/flamescion/search?keywords="+keyword+"&"+theme; else
{
theme = "theme=light";
}
url = api->getServerUrl() + "store/#/flamescion/search?keywords=" + keyword + "&" + theme;
ui->webEngineView->setUrl(url); ui->webEngineView->setUrl(url);
} }
@ -72,15 +81,14 @@ AppListPage::~AppListPage()
void AppListPage::on_webEngineView_urlChanged(const QUrl &arg1) void AppListPage::on_webEngineView_urlChanged(const QUrl &arg1)
{ {
if(arg1.path().right(8) == "app.json") if (arg1.path().right(8) == "app.json")
{ {
QString url = arg1.toString(); QString url = arg1.toString();
url = url.mid(url.indexOf("/store/")); url = url.mid(url.indexOf("/store/"));
url = "spk:/"+url; url = "spk:/" + url;
url = url.mid(0,url.indexOf("/app.json")); url = url.mid(0, url.indexOf("/app.json"));
qDebug() << "程序跳转链接地址:" << url; qDebug() << "程序跳转链接地址:" << url;
ui->webEngineView->back(); ui->webEngineView->back();
emit clicked(url); emit clicked(url);
} }
} }

@ -1,9 +1,8 @@
#include "settingspage.h" #include "settingspage.h"
#include "ui_settingspage.h" #include "ui_settingspage.h"
bool SettingsPage::isdownload = false; bool SettingsPage::isdownload = false;
SettingsPage::SettingsPage(QWidget *parent) : SettingsPage::SettingsPage(QWidget *parent) : QWidget(parent),
QWidget(parent), ui(new Ui::SettingsPage)
ui(new Ui::SettingsPage)
{ {
ui->setupUi(this); ui->setupUi(this);
configCanSave = false; configCanSave = false;
@ -12,11 +11,13 @@ SettingsPage::SettingsPage(QWidget *parent) :
void SettingsPage::setTheme(bool dark) void SettingsPage::setTheme(bool dark)
{ {
if(dark) if (dark)
{ {
this->setStyleSheet("#frame{background-color: #252525;border-radius:14px;border:1px solid rgb(64, 64, 64);}"); this->setStyleSheet("#frame{background-color: #252525;border-radius:14px;border:1px solid rgb(64, 64, 64);}");
}else { }
//亮色模式 else
{
// 亮色模式
this->setStyleSheet("#frame{background-color: #ffffff;border-radius:14px;border:1px solid rgb(229,229,229);}"); this->setStyleSheet("#frame{background-color: #ffffff;border-radius:14px;border:1px solid rgb(229,229,229);}");
} }
} }
@ -26,7 +27,7 @@ void SettingsPage::readServerList()
// 读取服务器列表并初始化 // 读取服务器列表并初始化
QFile file(QDir::homePath().toUtf8() + "/.config/spark-store/server.list"); QFile file(QDir::homePath().toUtf8() + "/.config/spark-store/server.list");
//判断文件是否存在 // 判断文件是否存在
if (!file.exists()) if (!file.exists())
{ {
ui->comboBox_server->addItem("https://d.store.deepinos.org.cn/"); ui->comboBox_server->addItem("https://d.store.deepinos.org.cn/");
@ -34,28 +35,28 @@ void SettingsPage::readServerList()
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
qDebug()<<"无法读取server.list"; qDebug() << "无法读取server.list";
} }
//创建QTextStream对象 // 创建QTextStream对象
QTextStream textStream(&file); QTextStream textStream(&file);
QString lineData = textStream.readLine();//读取文件的第一行 QString lineData = textStream.readLine(); // 读取文件的第一行
ui->comboBox_server->addItem(lineData); ui->comboBox_server->addItem(lineData);
while(!lineData.isNull()) while (!lineData.isNull())
{ {
lineData = textStream.readLine(); lineData = textStream.readLine();
ui->comboBox_server->addItem(lineData); ui->comboBox_server->addItem(lineData);
} }
for(int i = 0; i < ui->comboBox_server->count(); i++) for (int i = 0; i < ui->comboBox_server->count(); i++)
{ {
if(ui->comboBox_server->itemText(i) == "开发者模式 Dev only") if (ui->comboBox_server->itemText(i) == "开发者模式 Dev only")
{ {
ui->comboBox_server->model()->setData(ui->comboBox_server->model()->index(i, 0), QVariant(0), Qt::UserRole - 1); ui->comboBox_server->model()->setData(ui->comboBox_server->model()->index(i, 0), QVariant(0), Qt::UserRole - 1);
} }
if(ui->comboBox_server->itemText(i) == "镜像源 Download only") if (ui->comboBox_server->itemText(i) == "镜像源 Download only")
{ {
for(int j = i; j < ui->comboBox_server->count(); j++) for (int j = i; j < ui->comboBox_server->count(); j++)
{ {
ui->comboBox_server->model()->setData(ui->comboBox_server->model()->index(j, 0), QVariant(0), Qt::UserRole - 1); ui->comboBox_server->model()->setData(ui->comboBox_server->model()->index(j, 0), QVariant(0), Qt::UserRole - 1);
} }
@ -71,13 +72,13 @@ void SettingsPage::initConfig()
// 读取服务器URL并初始化菜单项的链接 // 读取服务器URL并初始化菜单项的链接
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat); QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
if(!readConfig.value("server/choose").toString().isEmpty() && readConfig.value("server/updated").toString() == "TRUE") if (!readConfig.value("server/choose").toString().isEmpty() && readConfig.value("server/updated").toString() == "TRUE")
{ {
qDebug()<<readConfig.value("server/choose").toString(); qDebug() << readConfig.value("server/choose").toString();
ui->comboBox_server->setCurrentText(readConfig.value("server/choose").toString()); ui->comboBox_server->setCurrentText(readConfig.value("server/choose").toString());
SparkAPI::setServerUrl(readConfig.value("server/choose").toString()); SparkAPI::setServerUrl(readConfig.value("server/choose").toString());
} }
configCanSave = true; // 防止触发保存配置信号 configCanSave = true; //  防止触发保存配置信号
} }
SettingsPage::~SettingsPage() SettingsPage::~SettingsPage()
@ -88,7 +89,7 @@ SettingsPage::~SettingsPage()
void SettingsPage::on_pushButton_updateServer_clicked() void SettingsPage::on_pushButton_updateServer_clicked()
{ {
QtConcurrent::run([=]() QtConcurrent::run([=]()
{ {
ui->pushButton_updateServer->setEnabled(false); ui->pushButton_updateServer->setEnabled(false);
ui->comboBox_server->clear(); ui->comboBox_server->clear();
@ -97,17 +98,15 @@ void SettingsPage::on_pushButton_updateServer_clicked()
ui->pushButton_updateServer->setEnabled(true); ui->pushButton_updateServer->setEnabled(true);
readServerList(); readServerList();
ui->comboBox_server->setCurrentIndex(0); ui->comboBox_server->setCurrentIndex(0); });
});
} }
void SettingsPage::on_comboBox_server_currentIndexChanged(const QString &arg1) void SettingsPage::on_comboBox_server_currentIndexChanged(const QString &arg1)
{ {
SparkAPI::setServerUrl(arg1); // 服务器信息更新 SparkAPI::setServerUrl(arg1); // 服务器信息更新
qDebug()<<arg1; qDebug() << arg1;
const QString updatedInfo = "TRUE"; const QString updatedInfo = "TRUE";
if(configCanSave) if (configCanSave)
{ {
// ui->label_setting1->show(); // ui->label_setting1->show();
QSettings *setConfig = new QSettings(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat); QSettings *setConfig = new QSettings(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
@ -124,7 +123,7 @@ void SettingsPage::setIsDownload(bool isdownload)
void SettingsPage::updateUI() void SettingsPage::updateUI()
{ {
if(isdownload) if (isdownload)
{ {
ui->pushButton_clear->setEnabled(false); ui->pushButton_clear->setEnabled(false);
} }
@ -135,15 +134,15 @@ void SettingsPage::updateUI()
// 显示缓存占用空间 // 显示缓存占用空间
quint64 tmp_size = dirFileSize(QString::fromUtf8(TMP_PATH)); quint64 tmp_size = dirFileSize(QString::fromUtf8(TMP_PATH));
QString tmp_size_str; QString tmp_size_str;
if(tmp_size < 1024) if (tmp_size < 1024)
{ {
tmp_size_str = QString::number(tmp_size) + "B"; tmp_size_str = QString::number(tmp_size) + "B";
} }
else if(tmp_size < (1024 * 1024)) else if (tmp_size < (1024 * 1024))
{ {
tmp_size_str = QString::number(0.01 * int(100 * (tmp_size / 1024))) + "KB"; tmp_size_str = QString::number(0.01 * int(100 * (tmp_size / 1024))) + "KB";
} }
else if(tmp_size<(1024*1024*1024)) else if (tmp_size < (1024 * 1024 * 1024))
{ {
tmp_size_str = QString::number(0.01 * int(100 * (tmp_size / (1024 * 1024)))) + "MB"; tmp_size_str = QString::number(0.01 * int(100 * (tmp_size / (1024 * 1024)))) + "MB";
} }
@ -160,13 +159,13 @@ quint64 SettingsPage::dirFileSize(const QString &path)
QDir dir(path); QDir dir(path);
quint64 size = 0; quint64 size = 0;
// dir.entryInfoList(QDir::Files); // 返回文件信息 // dir.entryInfoList(QDir::Files); // 返回文件信息
foreach(QFileInfo fileInfo, dir.entryInfoList(QDir::Files)) foreach (QFileInfo fileInfo, dir.entryInfoList(QDir::Files))
{ {
// 计算文件大小 // 计算文件大小
size += quint64(fileInfo.size()); size += quint64(fileInfo.size());
} }
// dir.entryList(QDir::Dirs|QDir::NoDotAndDotDot); // 返回所有子目录,并进行过滤 // dir.entryList(QDir::Dirs|QDir::NoDotAndDotDot); // 返回所有子目录,并进行过滤
foreach(QString subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) foreach (QString subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{ {
// 若存在子目录,则递归调用 dirFileSize() 函数 // 若存在子目录,则递归调用 dirFileSize() 函数
size += dirFileSize(path + QDir::separator() + subDir); size += dirFileSize(path + QDir::separator() + subDir);
@ -177,22 +176,20 @@ quint64 SettingsPage::dirFileSize(const QString &path)
void SettingsPage::on_pushButton_updateApt_clicked() void SettingsPage::on_pushButton_updateApt_clicked()
{ {
QtConcurrent::run([=]() QtConcurrent::run([=]()
{ {
ui->pushButton_updateApt->setEnabled(false); ui->pushButton_updateApt->setEnabled(false);
ui->label_aptserver->setText(tr("Updating, please wait...")); ui->label_aptserver->setText(tr("Updating, please wait..."));
emit openUrl(QUrl("spk://store/tools/spark-store")); emit openUrl(QUrl("spk://store/tools/spark-store"));
ui->label_aptserver->setText(tr("")); ui->label_aptserver->setText(tr(""));
ui->pushButton_updateApt->setEnabled(true); ui->pushButton_updateApt->setEnabled(true); });
});
} }
void SettingsPage::on_pushButton_clear_clicked() void SettingsPage::on_pushButton_clear_clicked()
{ {
QtConcurrent::run([=]() QtConcurrent::run([=]()
{ {
ui->pushButton_clear->setEnabled(false); ui->pushButton_clear->setEnabled(false);
QDir tmpdir("/tmp/spark-store"); QDir tmpdir("/tmp/spark-store");
@ -204,15 +201,13 @@ void SettingsPage::on_pushButton_clear_clicked()
} }
Utils::sendNotification("spark-store",tr("Spark Store"),tr("Temporary cache was cleaned")); Utils::sendNotification("spark-store",tr("Spark Store"),tr("Temporary cache was cleaned"));
ui->pushButton_clear->setEnabled(true); ui->pushButton_clear->setEnabled(true);
updateUI(); updateUI(); });
});
} }
void SettingsPage::on_pushButton_clearWebCache_clicked() void SettingsPage::on_pushButton_clearWebCache_clicked()
{ {
QtConcurrent::run([=]() QtConcurrent::run([=]()
{ {
QString dataLocal = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); QString dataLocal = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
qDebug() << dataLocal; qDebug() << dataLocal;
QDir dataDir(dataLocal); QDir dataDir(dataLocal);
@ -220,7 +215,5 @@ void SettingsPage::on_pushButton_clearWebCache_clicked()
dataLocal = QStandardPaths::writableLocation(QStandardPaths::TempLocation); dataLocal = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
qDebug() << dataLocal; qDebug() << dataLocal;
QDir cacheDir(dataLocal); QDir cacheDir(dataLocal);
cacheDir.removeRecursively(); cacheDir.removeRecursively(); });
});
} }

@ -1,22 +1,19 @@
#include "httprequest.h" #include "httprequest.h"
HttpRequest::HttpRequest() HttpRequest::HttpRequest()
{ {
} }
void HttpRequest::getRequest(QNetworkRequest request) void HttpRequest::getRequest(QNetworkRequest request)
{ {
QNetworkAccessManager *naManager=new QNetworkAccessManager(this); QNetworkAccessManager *naManager = new QNetworkAccessManager(this);
request.setRawHeader("User-Agent", "Mozilla/5.0"); request.setRawHeader("User-Agent", "Mozilla/5.0");
request.setRawHeader("Content-Type", "charset='utf-8'"); request.setRawHeader("Content-Type", "charset='utf-8'");
request.setRawHeader("Content-Type", "application/json"); request.setRawHeader("Content-Type", "application/json");
naManager->get(request); naManager->get(request);
QObject::connect(naManager,&QNetworkAccessManager::finished,this,&HttpRequest::readdata_slot); QObject::connect(naManager, &QNetworkAccessManager::finished, this, &HttpRequest::readdata_slot);
} }
void HttpRequest::readdata_slot(QNetworkReply *reply) void HttpRequest::readdata_slot(QNetworkReply *reply)
{ {
@ -24,19 +21,19 @@ void HttpRequest::readdata_slot(QNetworkReply *reply)
} }
QString HttpRequest::postRequest(QString url, QString jsondata) QString HttpRequest::postRequest(QString url, QString jsondata)
{ {
QByteArray array= jsondata.toLatin1(); QByteArray array = jsondata.toLatin1();
QNetworkRequest request; QNetworkRequest request;
QNetworkAccessManager *naManager=new QNetworkAccessManager(this); QNetworkAccessManager *naManager = new QNetworkAccessManager(this);
QUrl strUrl = url.replace("+","%2B"); QUrl strUrl = url.replace("+", "%2B");
request.setUrl(strUrl); request.setUrl(strUrl);
request.setRawHeader("Content-Type", "charset='utf-8'"); request.setRawHeader("Content-Type", "charset='utf-8'");
request.setRawHeader("Content-Type", "application/json"); request.setRawHeader("Content-Type", "application/json");
QNetworkReply* reply = naManager->post(request, array); QNetworkReply *reply = naManager->post(request, array);
QEventLoop eventLoop; QEventLoop eventLoop;
connect(naManager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); connect(naManager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
eventLoop.exec(); eventLoop.exec();
QTextCodec* codec = QTextCodec::codecForName("utf8"); QTextCodec *codec = QTextCodec::codecForName("utf8");
QString strReply = codec->toUnicode(reply->readAll()); QString strReply = codec->toUnicode(reply->readAll());
reply->deleteLater(); reply->deleteLater();
return strReply; return strReply;

@ -2,18 +2,17 @@
Utils::Utils() Utils::Utils()
{ {
} }
//这个函数是chatGPT写的 // Author: chatGPT
void Utils::sendNotification(QString icon,QString title,QString body) void Utils::sendNotification(QString icon, QString title, QString body)
{ {
QDBusInterface iface("org.freedesktop.Notifications", QDBusInterface iface("org.freedesktop.Notifications",
"/org/freedesktop/Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications"); "org.freedesktop.Notifications");
QVariantList args; QVariantList args;
args << QCoreApplication::applicationName() // the name of the application args << QCoreApplication::applicationName() // the name of the application
<< (uint)0 // replaces the previous notification with the same ID << (uint)0 // replaces the previous notification with the same ID
<< icon // the application icon of the notification << icon // the application icon of the notification
<< title // the title of the notification << title // the title of the notification

@ -2,43 +2,45 @@
WidgetAnimation::WidgetAnimation() WidgetAnimation::WidgetAnimation()
{ {
} }
void WidgetAnimation::widgetShake(QWidget *pWidget, int nRange) void WidgetAnimation::widgetShake(QWidget *pWidget, int nRange)
{ {
int nX = pWidget->x(); int nX = pWidget->x();
int nY = pWidget->y(); int nY = pWidget->y();
QPropertyAnimation *pAnimation = new QPropertyAnimation(pWidget,"geometry"); QPropertyAnimation *pAnimation = new QPropertyAnimation(pWidget, "geometry");
pAnimation->setEasingCurve(QEasingCurve::InOutSine); pAnimation->setEasingCurve(QEasingCurve::InOutSine);
pAnimation->setDuration(400); pAnimation->setDuration(400);
pAnimation->setStartValue(QRect(QPoint(nX,nY),pWidget->size())); pAnimation->setStartValue(QRect(QPoint(nX, nY), pWidget->size()));
int nShakeCount = 8; int nShakeCount = 8;
double nStep = 1.0/nShakeCount; double nStep = 1.0 / nShakeCount;
for(int i = 1; i < nShakeCount; i++){ for (int i = 1; i < nShakeCount; i++)
nRange = i&1 ? -nRange : nRange; {
pAnimation->setKeyValueAt(nStep*i,QRect(QPoint(nX + nRange,nY),pWidget->size())); nRange = i & 1 ? -nRange : nRange;
pAnimation->setKeyValueAt(nStep * i, QRect(QPoint(nX + nRange, nY), pWidget->size()));
} }
pAnimation->setEndValue(QRect(QPoint(nX,nY),pWidget->size())); pAnimation->setEndValue(QRect(QPoint(nX, nY), pWidget->size()));
pAnimation->start(QAbstractAnimation::DeleteWhenStopped); pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
} }
QPropertyAnimation* WidgetAnimation::createWidgetOpacity(QWidget *pWidget, bool isAppear) QPropertyAnimation *WidgetAnimation::createWidgetOpacity(QWidget *pWidget, bool isAppear)
{ {
QPropertyAnimation *animation = new QPropertyAnimation(pWidget, "windowOpacity", pWidget); QPropertyAnimation *animation = new QPropertyAnimation(pWidget, "windowOpacity", pWidget);
//设置动画效果 // 设置动画效果
animation->setEasingCurve(QEasingCurve::Linear); animation->setEasingCurve(QEasingCurve::Linear);
//设置动画时间(单位:毫秒) // 设置动画时间(单位:毫秒)
animation->setDuration(500); animation->setDuration(500);
// 设置动画步长值,以及在该位置时显示的透明度 // 设置动画步长值,以及在该位置时显示的透明度
if(isAppear) if (isAppear)
{ {
animation->setKeyValueAt(0, 0); animation->setKeyValueAt(0, 0);
// m_animation->setKeyValueAt(0.5, 0); // m_animation->setKeyValueAt(0.5, 0);
animation->setKeyValueAt(1, 1); animation->setKeyValueAt(1, 1);
}else{ }
else
{
animation->setKeyValueAt(0, 1); animation->setKeyValueAt(0, 1);
animation->setKeyValueAt(1, 0); animation->setKeyValueAt(1, 0);
} }
@ -46,7 +48,7 @@ QPropertyAnimation* WidgetAnimation::createWidgetOpacity(QWidget *pWidget, bool
} }
void WidgetAnimation::widgetOpacity(QWidget *pWidget, bool isAppear) void WidgetAnimation::widgetOpacity(QWidget *pWidget, bool isAppear)
{ {
// 开始动画 // 开始动画
createWidgetOpacity(pWidget, isAppear)->start(); createWidgetOpacity(pWidget, isAppear)->start();
} }

@ -5,14 +5,15 @@
BaseWidgetOpacity::BaseWidgetOpacity(QWidget *parent) : DBlurEffectWidget(parent) BaseWidgetOpacity::BaseWidgetOpacity(QWidget *parent) : DBlurEffectWidget(parent)
{ {
// WidgetAnimation::widgetOpacity(this,true); // WidgetAnimation::widgetOpacity(this,true);
} }
/// @brief 窗口关闭事件 /// @brief 窗口关闭事件
/// @param event /// @param event
void BaseWidgetOpacity::closeEvent(QCloseEvent *event) void BaseWidgetOpacity::closeEvent(QCloseEvent *event)
{ {
if (!closeWindowAnimation) { if (!closeWindowAnimation)
{
closeWindowAnimation = true; closeWindowAnimation = true;
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity"); QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
@ -21,18 +22,20 @@ void BaseWidgetOpacity::closeEvent(QCloseEvent *event)
animation->setStartValue(1.0); animation->setStartValue(1.0);
animation->setEndValue(0.0); animation->setEndValue(0.0);
QObject::connect(animation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value){ QObject::connect(animation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value)
this->update(); {
// setWindowTitle(QString("ヾ(⌒∇⌒*)See You♪ - %1%").arg(int(value.toFloat() * 100))); this->update();
}); // setWindowTitle(QString("ヾ(⌒∇⌒*)See You♪ - %1%").arg(int(value.toFloat() * 100)));
});
QObject::connect(animation, &QPropertyAnimation::finished, this, [=](){ QObject::connect(animation, &QPropertyAnimation::finished, this, [=]()
this->close(); { this->close(); });
});
animation->start(); animation->start();
event->ignore(); event->ignore();
} else { }
else
{
event->accept(); event->accept();
} }
} }

@ -3,11 +3,10 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QtConcurrent> #include <QtConcurrent>
big_image::big_image(DBlurEffectWidget *parent) : big_image::big_image(DBlurEffectWidget *parent) : DBlurEffectWidget(parent),
DBlurEffectWidget(parent), m_image(new QLabel)
m_image(new QLabel)
{ {
// setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); // 设置图片对话框总在最前 // setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); // 设置图片对话框总在最前
setWindowModality(Qt::ApplicationModal); // 以上无效不如直接使用 模态化对话框 setWindowModality(Qt::ApplicationModal); // 以上无效不如直接使用 模态化对话框
setRadius(0); setRadius(0);
setMaskAlpha(60); setMaskAlpha(60);

@ -6,13 +6,12 @@
bool DownloadItem::isInstall = false; bool DownloadItem::isInstall = false;
DownloadItem::DownloadItem(QWidget *parent) : DownloadItem::DownloadItem(QWidget *parent) : QWidget(parent),
QWidget(parent), reinstall(false),
reinstall(false), close(false),
close(false), ui(new Ui::DownloadItem),
ui(new Ui::DownloadItem), output_w(new DDialog),
output_w(new DDialog), textbrowser(new QTextBrowser)
textbrowser(new QTextBrowser)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -34,7 +33,7 @@ void DownloadItem::setValue(qint64 value)
{ {
ui->progressBar->setValue(qint32(value)); ui->progressBar->setValue(qint32(value));
ui->label_2->setText(QString::number(double(value) / 100) + "% (" + speed + ")"); ui->label_2->setText(QString::number(double(value) / 100) + "% (" + speed + ")");
if(ui->label_2->text().left(4) == "100%") if (ui->label_2->text().left(4) == "100%")
{ {
download = 1; download = 1;
ui->label_2->setText(tr("Download Complete.")); ui->label_2->setText(tr("Download Complete."));
@ -58,7 +57,7 @@ QString DownloadItem::getName()
void DownloadItem::readyInstall() void DownloadItem::readyInstall()
{ {
if(!close) if (!close)
{ {
ui->progressBar->hide(); ui->progressBar->hide();
ui->pushButton_install->setEnabled(true); ui->pushButton_install->setEnabled(true);
@ -90,7 +89,7 @@ void DownloadItem::setSpeed(QString s)
void DownloadItem::install(int t) void DownloadItem::install(int t)
{ {
if(!isInstall) if (!isInstall)
{ {
isInstall = true; isInstall = true;
ui->pushButton_install->hide(); ui->pushButton_install->hide();
@ -99,7 +98,7 @@ void DownloadItem::install(int t)
ui->label_2->setText(tr("Installing")); ui->label_2->setText(tr("Installing"));
QtConcurrent::run([=]() QtConcurrent::run([=]()
{ {
QProcess installer; QProcess installer;
switch(t) switch(t)
{ {
@ -164,10 +163,9 @@ void DownloadItem::install(int t)
ui->widget_spinner->hide(); ui->widget_spinner->hide();
DownloadItem::isInstall = false; DownloadItem::isInstall = false;
emit finished(); emit finished(); });
});
// emit finished(); // emit finished();
qDebug()<<ui->label_filename->text().toUtf8(); qDebug() << ui->label_filename->text().toUtf8();
} }
} }

@ -8,15 +8,15 @@
ProgressButton::ProgressButton(QWidget *parent) ProgressButton::ProgressButton(QWidget *parent)
: QWidget{parent} : QWidget{parent}
{ {
//this->setWindowFlags(Qt::FramelessWindowHint); // this->setWindowFlags(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAttribute(Qt::WA_TranslucentBackground, true);
setMinimumWidth(36); setMinimumWidth(36);
setMinimumHeight(36); setMinimumHeight(36);
svgPath=""; svgPath = "";
backColor=Qt::transparent; backColor = Qt::transparent;
setMouseTracking(true); setMouseTracking(true);
connect(this,&ProgressButton::startProcessing,this,&ProgressButton::operationProcessing,Qt::QueuedConnection); connect(this, &ProgressButton::startProcessing, this, &ProgressButton::operationProcessing, Qt::QueuedConnection);
} }
ProgressButton::~ProgressButton() ProgressButton::~ProgressButton()
@ -26,63 +26,63 @@ ProgressButton::~ProgressButton()
void ProgressButton::paintEvent(QPaintEvent *event) void ProgressButton::paintEvent(QPaintEvent *event)
{ {
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing,true); painter.setRenderHint(QPainter::Antialiasing, true);
auto rect = event->rect(); auto rect = event->rect();
if(buttonState == state::normal || buttonState == state::hover) if (buttonState == state::normal || buttonState == state::hover)
{ {
auto radiu = (rect.height() - 6) / 2; auto radiu = (rect.height() - 6) / 2;
painter.translate(rect.center()); painter.translate(rect.center());
painter.setPen(Qt::transparent); painter.setPen(Qt::transparent);
painter.setBrush(QColor(buttonState == state::normal ? color : color.darker())); painter.setBrush(QColor(buttonState == state::normal ? color : color.darker()));
//painter.drawEllipse(QPoint(0,0),radiu,radiu); // painter.drawEllipse(QPoint(0,0),radiu,radiu);
//radiu -= 3; // radiu -= 3;
painter.setBrush(backColor); painter.setBrush(backColor);
painter.drawEllipse(QPoint(0,0),radiu,radiu); painter.drawEllipse(QPoint(0, 0), radiu, radiu);
QSvgRenderer m_svgRender; QSvgRenderer m_svgRender;
m_svgRender.load(svgPath); m_svgRender.load(svgPath);
m_svgRender.render(&painter ,QRectF(-radiu / 2,-radiu / 2,radiu,radiu)); m_svgRender.render(&painter, QRectF(-radiu / 2, -radiu / 2, radiu, radiu));
} }
else if(buttonState == state::openProgress) else if (buttonState == state::openProgress)
{ {
painter.translate(rect.center()); painter.translate(rect.center());
auto radiu = (rect.height() - 6) / 2 -3; auto radiu = (rect.height() - 6) / 2 - 3;
painter.setBrush(backColor); painter.setBrush(backColor);
painter.setPen(QPen(backColor,3)); painter.setPen(QPen(backColor, 3));
painter.drawEllipse(QPoint(0,0),radiu,radiu); painter.drawEllipse(QPoint(0, 0), radiu, radiu);
painter.setPen(QPen(backColor,3)); painter.setPen(QPen(backColor, 3));
QSvgRenderer m_svgRender; QSvgRenderer m_svgRender;
m_svgRender.load(svgPath); m_svgRender.load(svgPath);
m_svgRender.render(&painter ,QRectF(-radiu / 2,-radiu / 2,radiu,radiu)); m_svgRender.render(&painter, QRectF(-radiu / 2, -radiu / 2, radiu, radiu));
QRect rect = QRect(-radiu, -radiu, QRect rect = QRect(-radiu, -radiu,
radiu*2, radiu*2); radiu * 2, radiu * 2);
painter.setPen(QPen(color.darker(100),3)); painter.setPen(QPen(color.darker(100), 3));
auto angle = progress * 360 / 100; auto angle = progress * 360 / 100;
painter.drawArc(rect.adjusted(-3,-3,3,3),90 * 16,-static_cast<int>(angle * 16)); painter.drawArc(rect.adjusted(-3, -3, 3, 3), 90 * 16, -static_cast<int>(angle * 16));
} }
else if(buttonState == state::closeProgress) else if (buttonState == state::closeProgress)
{ {
auto radiu = (rect.height() - 6) / 2; auto radiu = (rect.height() - 6) / 2;
painter.translate(rect.center()); painter.translate(rect.center());
painter.setPen(Qt::transparent); painter.setPen(Qt::transparent);
painter.setBrush(QColor(0, 0, 0, 63)); painter.setBrush(QColor(0, 0, 0, 63));
painter.drawEllipse(QPoint(0,0),radiu,radiu); painter.drawEllipse(QPoint(0, 0), radiu, radiu);
radiu -= 3; radiu -= 3;
painter.setBrush(backColor); painter.setBrush(backColor);
painter.drawEllipse(QPoint(0,0),radiu,radiu); painter.drawEllipse(QPoint(0, 0), radiu, radiu);
painter.setPen(QPen(color,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin)); painter.setPen(QPen(color, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.drawLine(QPoint(-radiu / 3,0), painter.drawLine(QPoint(-radiu / 3, 0),
QPoint(-radiu / 5,radiu / 3)); QPoint(-radiu / 5, radiu / 3));
painter.drawLine(QPoint(-radiu / 5,radiu / 3), painter.drawLine(QPoint(-radiu / 5, radiu / 3),
QPoint(radiu / 4,-radiu / 4)); QPoint(radiu / 4, -radiu / 4));
} }
} }
@ -90,12 +90,12 @@ void ProgressButton::setProgress(int progress)
{ {
buttonState = state::openProgress; buttonState = state::openProgress;
ProgressButton::progress = progress; ProgressButton::progress = progress;
if(progress == 0) if (progress == 0)
{ {
buttonState = state::normal; buttonState = state::normal;
update(); update();
} }
if(progress == 100) if (progress == 100)
{ {
buttonState = state::closeProgress; buttonState = state::closeProgress;
update(); update();
@ -127,7 +127,7 @@ void ProgressButton::setColor(QColor color)
void ProgressButton::leaveEvent(QEvent *event) void ProgressButton::leaveEvent(QEvent *event)
{ {
if(buttonState == state::hover) if (buttonState == state::hover)
{ {
buttonState = state::normal; buttonState = state::normal;
update(); update();
@ -137,12 +137,12 @@ void ProgressButton::leaveEvent(QEvent *event)
void ProgressButton::mousePressEvent(QMouseEvent *event) void ProgressButton::mousePressEvent(QMouseEvent *event)
{ {
if(buttonState == state::hover || buttonState == state::normal) if (buttonState == state::hover || buttonState == state::normal)
{ {
widthChangeValue = (this->width() - 6) / 2; widthChangeValue = (this->width() - 6) / 2;
update(); update();
} }
else if(buttonState == state::closeProgress) else if (buttonState == state::closeProgress)
{ {
update(); update();
} }
@ -152,24 +152,21 @@ void ProgressButton::mousePressEvent(QMouseEvent *event)
void ProgressButton::operationProcessing() void ProgressButton::operationProcessing()
{ {
} }
const int RADIUS = 60; const int RADIUS = 60;
WaterDrop::WaterDrop(QWidget *parent) WaterDrop::WaterDrop(QWidget *parent)
: QWidget(parent) : QWidget(parent), m_waterDropAnimation(nullptr), m_animationRadius(0)
, m_waterDropAnimation(nullptr)
, m_animationRadius(0)
{ {
this->setFixedSize(QSize(RADIUS * 2, RADIUS * 2)); this->setFixedSize(QSize(RADIUS * 2, RADIUS * 2));
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool); this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
this->setAttribute(Qt::WA_TranslucentBackground); this->setAttribute(Qt::WA_TranslucentBackground);
this->setAttribute(Qt::WA_DeleteOnClose); this->setAttribute(Qt::WA_DeleteOnClose);
m_waterDropAnimation = new QVariantAnimation(this); m_waterDropAnimation = new QVariantAnimation(this);
// m_waterDropAnimation->setEasingCurve(QEasingCurve(static_cast<QEasingCurve::Type>(QRandomGenerator::global()->bounded(40)))); // m_waterDropAnimation->setEasingCurve(QEasingCurve(static_cast<QEasingCurve::Type>(QRandomGenerator::global()->bounded(40))));
} }
//把鼠标点击的点转换为圆心点坐标 // 把鼠标点击的点转换为圆心点坐标
void WaterDrop::move(const QPoint &point) void WaterDrop::move(const QPoint &point)
{ {
QPoint translatePoint = point - QPoint(RADIUS, RADIUS); QPoint translatePoint = point - QPoint(RADIUS, RADIUS);
@ -196,7 +193,7 @@ void WaterDrop::paintEvent(QPaintEvent *event)
pen.setColor(QColor(0xffffff80)); pen.setColor(QColor(0xffffff80));
pen.setWidth(5); pen.setWidth(5);
painter.setPen(pen); painter.setPen(pen);
painter.drawEllipse(event->rect().center(),m_animationRadius, m_animationRadius); painter.drawEllipse(event->rect().center(), m_animationRadius, m_animationRadius);
} }
void WaterDrop::onRaduisChanged(QVariant value) void WaterDrop::onRaduisChanged(QVariant value)

@ -5,13 +5,13 @@
#include <QDebug> #include <QDebug>
SmoothListWidget::SmoothListWidget(QWidget *parent) : QListWidget(parent) SmoothListWidget::SmoothListWidget(QWidget *parent) : QListWidget(parent)
{ {
vScrollBar->setOrientation(Qt::Orientation::Vertical); //将滚动条设置为纵向 vScrollBar->setOrientation(Qt::Orientation::Vertical); // 将滚动条设置为纵向
setVerticalScrollBar(vScrollBar); //设置纵向滚动条 setVerticalScrollBar(vScrollBar); // 设置纵向滚动条
connect(vScrollBar, SIGNAL(valueChanged(int)), this, SLOT(onSliderChanged(int))); connect(vScrollBar, SIGNAL(valueChanged(int)), this, SLOT(onSliderChanged(int)));
} }
void SmoothListWidget::wheelEvent(QWheelEvent *e) void SmoothListWidget::wheelEvent(QWheelEvent *e)
{ {
//当捕获到事件后,调用相对滚动的槽函数 // 当捕获到事件后,调用相对滚动的槽函数
vScrollBar->scroll(e->angleDelta().y()); vScrollBar->scroll(e->angleDelta().y());
} }
void SmoothListWidget::onSliderChanged(int p) void SmoothListWidget::onSliderChanged(int p)
@ -21,5 +21,5 @@ void SmoothListWidget::onSliderChanged(int p)
{ {
emit reachedBottom(); // 1 emit reachedBottom(); // 1
} }
emit msliderChanged(p); // 2 emit msliderChanged(p); // 2
} }

@ -1,56 +1,56 @@
#include "smoothscrollbar.h" #include "smoothscrollbar.h"
#include <QWheelEvent> #include <QWheelEvent>
#include <QDebug> #include <QDebug>
SmoothScrollBar::SmoothScrollBar(QWidget* parent):QScrollBar(parent) SmoothScrollBar::SmoothScrollBar(QWidget *parent) : QScrollBar(parent)
{ {
m_scrollAni=new QPropertyAnimation(this); m_scrollAni = new QPropertyAnimation(this);
m_scrollAni->setTargetObject(this); m_scrollAni->setTargetObject(this);
m_scrollAni->setPropertyName("value"); m_scrollAni->setPropertyName("value");
m_scrollAni->setEasingCurve(QEasingCurve::OutQuint); //设置动画曲线在Qt文档中有详细的介绍 m_scrollAni->setEasingCurve(QEasingCurve::OutQuint); // 设置动画曲线在Qt文档中有详细的介绍
m_scrollAni->setDuration(500); //设置动画时间,数值越小播放越快 m_scrollAni->setDuration(500); // 设置动画时间,数值越小播放越快
m_targetValue_v=value(); //将m_targetValue_v初始化 m_targetValue_v = value(); // 将m_targetValue_v初始化
} }
void SmoothScrollBar::setValue(int value) void SmoothScrollBar::setValue(int value)
{ {
m_scrollAni->stop();//停止现在的动画,防止出现冲突 m_scrollAni->stop(); // 停止现在的动画,防止出现冲突
m_scrollAni->setStartValue(this->value()); //设置动画滚动的初始值为当前位置 m_scrollAni->setStartValue(this->value()); // 设置动画滚动的初始值为当前位置
m_scrollAni->setEndValue(value); //设置动画的结束位置为目标值 m_scrollAni->setEndValue(value); // 设置动画的结束位置为目标值
m_scrollAni->start(); //开始动画 m_scrollAni->start(); // 开始动画
} }
void SmoothScrollBar::scrollTop() void SmoothScrollBar::scrollTop()
{ {
setValue(-m_targetValue_v); //开始动画 setValue(-m_targetValue_v); // 开始动画
m_targetValue_v=0; m_targetValue_v = 0;
} }
void SmoothScrollBar::scroll(int value) void SmoothScrollBar::scroll(int value)
{ {
//这里推荐评论区中大佬优化的写法 // 这里推荐评论区中大佬优化的写法
if(m_targetValue_v-value>=0) if (m_targetValue_v - value >= 0)
{ {
m_targetValue_v-=value; //将目标值和相对位置进行运算 m_targetValue_v -= value; // 将目标值和相对位置进行运算
setValue(m_targetValue_v); //开始动画 setValue(m_targetValue_v); // 开始动画
} }
} }
void SmoothScrollBar::mousePressEvent(QMouseEvent *e) void SmoothScrollBar::mousePressEvent(QMouseEvent *e)
{ {
//当使用鼠标操作滚动条时不会刷新m_targetValue_v的值因而需要重写事件对其进行刷新。 // 当使用鼠标操作滚动条时不会刷新m_targetValue_v的值因而需要重写事件对其进行刷新。
m_scrollAni->stop(); m_scrollAni->stop();
QScrollBar::mousePressEvent(e); QScrollBar::mousePressEvent(e);
m_targetValue_v=value(); m_targetValue_v = value();
} }
void SmoothScrollBar::mouseReleaseEvent(QMouseEvent *e) void SmoothScrollBar::mouseReleaseEvent(QMouseEvent *e)
{ {
m_scrollAni->stop(); m_scrollAni->stop();
QScrollBar::mouseReleaseEvent(e); QScrollBar::mouseReleaseEvent(e);
m_targetValue_v=value(); m_targetValue_v = value();
} }
void SmoothScrollBar::mouseMoveEvent(QMouseEvent *e) void SmoothScrollBar::mouseMoveEvent(QMouseEvent *e)
{ {
m_scrollAni->stop(); m_scrollAni->stop();
QScrollBar::mouseMoveEvent(e); QScrollBar::mouseMoveEvent(e);
m_targetValue_v=value(); m_targetValue_v = value();
} }

@ -13,7 +13,8 @@ WebEnginePage::~WebEnginePage()
void WebEnginePage::setUrl(const QUrl &url) void WebEnginePage::setUrl(const QUrl &url)
{ {
if (m_currentUrl == url) { if (m_currentUrl == url)
{
return; return;
} }
@ -32,7 +33,8 @@ QWebEnginePage *WebEnginePage::createWindow(QWebEnginePage::WebWindowType type)
void WebEnginePage::slotUrlChanged(const QUrl &url) void WebEnginePage::slotUrlChanged(const QUrl &url)
{ {
if (m_currentUrl == url) { if (m_currentUrl == url)
{
sender()->deleteLater(); sender()->deleteLater();
return; return;
} }

@ -3,23 +3,22 @@
#include <QGraphicsOpacityEffect> #include <QGraphicsOpacityEffect>
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QDebug> #include <QDebug>
DownloadListWidget::DownloadListWidget(QWidget *parent) : DownloadListWidget::DownloadListWidget(QWidget *parent) : DBlurEffectWidget(parent),
DBlurEffectWidget(parent), ui(new Ui::DownloadListWidget)
ui(new Ui::DownloadListWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
installEventFilter(this); installEventFilter(this);
this->setAttribute(Qt::WA_Hover,true); this->setAttribute(Qt::WA_Hover, true);
setFocus(); setFocus();
setFixedSize(500,400); setFixedSize(500, 400);
setMaskAlpha(250); setMaskAlpha(250);
ui->listWidget->hide(); ui->listWidget->hide();
ui->widget->show(); ui->widget->show();
// 计算显示下载速度 // 计算显示下载速度
download_speed.setInterval(1000); download_speed.setInterval(1000);
download_speed.start(); download_speed.start();
connect(&download_speed,&QTimer::timeout,[=]() connect(&download_speed, &QTimer::timeout, [=]()
{ {
if(isdownload && theSpeed == "") if(isdownload && theSpeed == "")
{ {
size1 = download_size; size1 = download_size;
@ -47,13 +46,13 @@ DownloadListWidget::DownloadListWidget(QWidget *parent) :
downloaditemlist[nowDownload - 1]->setSpeed(theSpeed); downloaditemlist[nowDownload - 1]->setSpeed(theSpeed);
}else{ }else{
emit downloadProgress(0); emit downloadProgress(0);
} } });
});
} }
DownloadListWidget::~DownloadListWidget() DownloadListWidget::~DownloadListWidget()
{ {
if (downloadController) { if (downloadController)
{
downloadController->stopDownload(); downloadController->stopDownload();
downloadController->deleteLater(); downloadController->deleteLater();
} }
@ -64,41 +63,41 @@ DownloadListWidget::~DownloadListWidget()
void DownloadListWidget::clearItem() void DownloadListWidget::clearItem()
{ {
ui->listWidget->vScrollBar->scrollTop(); ui->listWidget->vScrollBar->scrollTop();
int n=ui->listWidget->count(); int n = ui->listWidget->count();
for(int i=0;i<n;i++) for (int i = 0; i < n; i++)
{ {
QListWidgetItem *item = ui->listWidget->takeItem(0); QListWidgetItem *item = ui->listWidget->takeItem(0);
QWidget *card = ui->listWidget->itemWidget(item); QWidget *card = ui->listWidget->itemWidget(item);
delete card; delete card;
card = NULL; card = NULL;
delete item; delete item;
item = NULL; item = NULL;
} }
ui->listWidget->clear(); ui->listWidget->clear();
} }
void DownloadListWidget::addItem(QString name,QString fileName,QString pkgName,const QPixmap icon,QString downloadurl) void DownloadListWidget::addItem(QString name, QString fileName, QString pkgName, const QPixmap icon, QString downloadurl)
{ {
if(fileName.isEmpty()) if (fileName.isEmpty())
{ {
return; return;
} }
urList.append(downloadurl); urList.append(downloadurl);
allDownload += 1; allDownload += 1;
DownloadItem *di=new DownloadItem(this); DownloadItem *di = new DownloadItem(this);
dlist<<downloadurl; dlist << downloadurl;
downloaditemlist<<di; downloaditemlist << di;
di->setName(name); di->setName(name);
di->setFileName(fileName); di->setFileName(fileName);
di->pkgName=pkgName; di->pkgName = pkgName;
di->seticon(icon); di->seticon(icon);
QListWidgetItem* pItem = new QListWidgetItem(); QListWidgetItem *pItem = new QListWidgetItem();
pItem->setSizeHint(QSize(240, 50)); pItem->setSizeHint(QSize(240, 50));
ui->listWidget->addItem(pItem); ui->listWidget->addItem(pItem);
ui->listWidget->setItemWidget(pItem, di); ui->listWidget->setItemWidget(pItem, di);
if(!isBusy) if (!isBusy)
{ {
nowDownload += 1; nowDownload += 1;
startRequest(urList.at(nowDownload - 1), fileName); // 进行链接请求 startRequest(urList.at(nowDownload - 1), fileName); // 进行链接请求
} }
} }
@ -120,10 +119,10 @@ void DownloadListWidget::startRequest(QUrl url, QString fileName)
isdownload = true; isdownload = true;
downloaditemlist[allDownload - 1]->free = false; downloaditemlist[allDownload - 1]->free = false;
downloadController = new DownloadController(this); // 并发下载,在点击下载按钮的时候才会初始化 downloadController = new DownloadController(this); // 并发下载,在点击下载按钮的时候才会初始化
connect(downloadController, &DownloadController::downloadProcess, this, &DownloadListWidget::updateDataReadProgress); connect(downloadController, &DownloadController::downloadProcess, this, &DownloadListWidget::updateDataReadProgress);
connect(downloadController, &DownloadController::downloadFinished, this, &DownloadListWidget::httpFinished); connect(downloadController, &DownloadController::downloadFinished, this, &DownloadListWidget::httpFinished);
//connect(downloadController, &DownloadController::errorOccur, this, [=](QString msg){this->sendNotification(msg);}); // connect(downloadController, &DownloadController::errorOccur, this, [=](QString msg){this->sendNotification(msg);});
downloadController->setFilename(fileName); downloadController->setFilename(fileName);
downloadController->startDownload(url.toString()); downloadController->startDownload(url.toString());
} }
@ -135,37 +134,37 @@ void DownloadListWidget::httpFinished() // 完成下载
downloaditemlist[nowDownload - 1]->readyInstall(); downloaditemlist[nowDownload - 1]->readyInstall();
downloaditemlist[nowDownload - 1]->free = true; downloaditemlist[nowDownload - 1]->free = true;
emit downloadFinished(); emit downloadFinished();
if(nowDownload < allDownload) if (nowDownload < allDownload)
{ {
// 如果有排队则下载下一个 // 如果有排队则下载下一个
qDebug() << "切换下一个下载..."; qDebug() << "切换下一个下载...";
nowDownload += 1; nowDownload += 1;
while(downloaditemlist[nowDownload - 1]->close) while (downloaditemlist[nowDownload - 1]->close)
{ {
nowDownload += 1; nowDownload += 1;
if(nowDownload >= allDownload) if (nowDownload >= allDownload)
{ {
nowDownload = allDownload; nowDownload = allDownload;
return; return;
} }
} }
QString fileName = downloaditemlist[nowDownload - 1]->getName(); QString fileName = downloaditemlist[nowDownload - 1]->getName();
startRequest(urList.at(nowDownload-1), fileName); startRequest(urList.at(nowDownload - 1), fileName);
} }
} }
void DownloadListWidget::updateDataReadProgress(QString speedInfo, qint64 bytesRead, qint64 totalBytes) void DownloadListWidget::updateDataReadProgress(QString speedInfo, qint64 bytesRead, qint64 totalBytes)
{ {
if(totalBytes <= 0) if (totalBytes <= 0)
{ {
return; return;
} }
theSpeed = speedInfo; theSpeed = speedInfo;
downloaditemlist[nowDownload - 1]->setMax(10000); // 最大值 downloaditemlist[nowDownload - 1]->setMax(10000); // 最大值
downloaditemlist[nowDownload - 1]->setValue(int(bytesRead * 100 / totalBytes) * 100); // 当前值 downloaditemlist[nowDownload - 1]->setValue(int(bytesRead * 100 / totalBytes) * 100); // 当前值
emit downloadProgress(int(bytesRead * 100 / totalBytes)); emit downloadProgress(int(bytesRead * 100 / totalBytes));
download_size = bytesRead; download_size = bytesRead;
if(downloaditemlist[nowDownload - 1]->close) if (downloaditemlist[nowDownload - 1]->close)
{ {
// 随时检测下载是否被取消 // 随时检测下载是否被取消
downloadController->disconnect(); downloadController->disconnect();
@ -175,21 +174,23 @@ void DownloadListWidget::updateDataReadProgress(QString speedInfo, qint64 bytesR
} }
} }
void DownloadListWidget::m_move(int x, int y)
void DownloadListWidget::m_move(int x,int y)
{ {
m_rect.setX(x); m_rect.setX(x);
m_rect.setY(y); m_rect.setY(y);
move(x,y); move(x, y);
return; return;
} }
bool DownloadListWidget::eventFilter(QObject *watched, QEvent *event) bool DownloadListWidget::eventFilter(QObject *watched, QEvent *event)
{ {
if (Q_NULLPTR == watched) { if (Q_NULLPTR == watched)
{
return false; return false;
} }
if (QEvent::ActivationChange == event->type()) { if (QEvent::ActivationChange == event->type())
if(QApplication::activeWindow() != this){ {
if (QApplication::activeWindow() != this)
{
this->close(); this->close();
} }
} }