diff --git a/.gitee/Dockerfile b/.gitee/Dockerfile
new file mode 100644
index 0000000000000000000000000000000000000000..88afd34cedef7d3f4fa54b6f2ff866a753e0c89e
--- /dev/null
+++ b/.gitee/Dockerfile
@@ -0,0 +1,2 @@
+FROM python:3
+RUN pip3 install requests
\ No newline at end of file
diff --git a/.gitee/callback.py b/.gitee/callback.py
new file mode 100644
index 0000000000000000000000000000000000000000..b52d702032fff3384f76594113a833e9644e3d7e
--- /dev/null
+++ b/.gitee/callback.py
@@ -0,0 +1,31 @@
+import os
+import requests
+import json
+
+
+# sha=os.system("git rev-parse HEAD")
+sha = os.getenv("GIT_COMMIT")
+# sha = '48fed26c51a8c42554e45f72f43e49703e04c97f'
+#get sha from environment
+url = "https://gitee.com/api/v5/repos/deepin-community-store/spark-store/commits/{}/comments".format(sha)
+
+token = os.getenv("gitee_token")
+
+# process = os.popen("git symbolic-ref --short -q HEAD")
+
+body = "构建详情请见" + os.getenv("JENKINS_URL") + "blue/organizations/jenkins/" + os.getenv("JOB_NAME").replace("/", "/detail/") + "/" + str(os.getenv("BUILD_ID"))
+
+# process.close()
+
+d = {
+ 'access_token': token,
+ "body": body
+}
+
+h = {
+ "Content-Type": "application/json;charset=UTF-8"
+}
+
+res = requests.post(url,headers=h, data=json.dumps(d))
+# print(res.status_code)
+# print(res.content)
\ No newline at end of file
diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000000000000000000000000000000000000..dab36e40b3d8404f9e1cafd01ec39cf8c9df6283
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,33 @@
+pipeline {
+ agent any
+ stages {
+ stage('build') {
+ agent {
+ docker {
+ image 'jerry979/dtke:5.11'
+ }
+
+ }
+ steps {
+ sh 'mkdir build && cd build && qmake .. && make '
+ archiveArtifacts(artifacts: 'build/src/spark-store', allowEmptyArchive: true, defaultExcludes: true)
+ }
+ }
+
+ stage('send') {
+ agent {
+ dockerfile {
+ filename '.gitee/Dockerfile'
+ }
+
+ }
+ environment {
+ gitee_token = credentials('1')
+ }
+ steps {
+ sh "python3 .gitee/callback.py"
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git "a/assets/fonts/\345\215\216\345\272\267\345\260\221\345\245\263\345\255\227\344\275\223.ttf" b/assets/fonts/hksnzt.ttf
similarity index 100%
rename from "assets/fonts/\345\215\216\345\272\267\345\260\221\345\245\263\345\255\227\344\275\223.ttf"
rename to assets/fonts/hksnzt.ttf
diff --git a/assets/icons.qrc b/assets/icons.qrc
index 6c797cbe9b57c80e6cd2b89cd303dde850c82416..9c8ed0197d29da0265346d76decf241ade534355 100644
--- a/assets/icons.qrc
+++ b/assets/icons.qrc
@@ -64,6 +64,6 @@
tags/dwine2-small.png
- fonts/华康少女字体.ttf
+ fonts/hksnzt.ttf
diff --git a/spark-store-project.pro b/spark-store-project.pro
index 254ea6c9775edcc10a800f961f57ff062cdc1ab7..19a741e805e62b9d1a50b40818146468cc35f0d2 100644
--- a/spark-store-project.pro
+++ b/spark-store-project.pro
@@ -1,7 +1,9 @@
TEMPLATE = subdirs
+
CONFIG += ordered
-SUBDIRS = third-party/QtNetworkService \
+SUBDIRS += \
+ third-party/QtNetworkService \
src/spark-store.pro
spark-store.depends = third-party/QtNetworkService
diff --git a/src/appitem.cpp b/src/appitem.cpp
index ec44ba4f7af2c1cd0d3d0d07c5265b21ad2d340b..ed18e0a98bc6eba2de8db9a3ce87d5d6a78e92d0 100644
--- a/src/appitem.cpp
+++ b/src/appitem.cpp
@@ -14,12 +14,12 @@ AppItem::AppItem(QWidget *parent) :
{
ui->setupUi(this);
-// auto shadow = new QGraphicsDropShadowEffect();
-// shadow->setXOffset(0);
-// shadow->setYOffset(1);
-// shadow->setBlurRadius(2);
-// shadow->setColor(QColor::fromRgba(qRgba(0, 0, 0, 180)));
-// ui->container->setGraphicsEffect(shadow);
+ // auto shadow = new QGraphicsDropShadowEffect();
+ // shadow->setXOffset(0);
+ // shadow->setYOffset(1);
+ // shadow->setBlurRadius(2);
+ // shadow->setColor(QColor::fromRgba(qRgba(0, 0, 0, 180)));
+ // ui->container->setGraphicsEffect(shadow);
}
AppItem::~AppItem()
@@ -46,7 +46,8 @@ void AppItem::setDescription(QString description)
void AppItem::setIcon(QString icon)
{
m_icon = icon;
- if (!icon.isEmpty()) {
+ if(!icon.isEmpty())
+ {
downloadIcon(icon);
}
}
@@ -58,7 +59,8 @@ void AppItem::setUrl(QString url)
void AppItem::mousePressEvent(QMouseEvent *event)
{
- Q_UNUSED(event);
+ Q_UNUSED(event)
+
emit clicked(QUrl(m_url));
}
@@ -68,8 +70,10 @@ void AppItem::mousePressEvent(QMouseEvent *event)
*/
void AppItem::downloadIcon(QString icon)
{
- QtConcurrent::run([=](){
+ QtConcurrent::run([=]()
+ {
auto reqManager = new QNetworkAccessManager();
+
QUrl url(icon);
QNetworkReply *reply = reqManager->get(QNetworkRequest(url));
QEventLoop loop;
@@ -77,14 +81,17 @@ void AppItem::downloadIcon(QString icon)
connect(reply, &QNetworkReply::finished, this, [=] () { emit finished(); });
loop.exec();
reqManager->deleteLater();
+
QPixmap pixmap;
pixmap.loadFromData(reply->readAll());
pixmap = pixmap.scaled(78, 78, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- if (reply->error() == QNetworkReply::NoError) {
- QMetaObject::invokeMethod(this, "loadIcon", Qt::QueuedConnection,
- Q_ARG(QPixmap, pixmap));
- } else {
- qDebug() << reply->errorString();
+ if (reply->error() == QNetworkReply::NoError)
+ {
+ QMetaObject::invokeMethod(this, "loadIcon", Qt::QueuedConnection, Q_ARG(QPixmap, pixmap));
+ }
+ else
+ {
+ qDebug() << reply->errorString();
}
});
}
@@ -93,5 +100,3 @@ void AppItem::loadIcon(QPixmap pic)
{
ui->lbl_icon->setPixmap(pic);
}
-
-
diff --git a/src/appitem.h b/src/appitem.h
index b2f675062c4407b1b52c52768e0efdbdd5a3ca55..3d30c66aa8886e3f02fd358c04d5006613918596 100644
--- a/src/appitem.h
+++ b/src/appitem.h
@@ -14,7 +14,7 @@ class AppItem : public QWidget
public:
explicit AppItem(QWidget *parent = nullptr);
- ~AppItem();
+ ~AppItem() override;
void setTitle(QString title);
void setDescription(QString description);
@@ -24,14 +24,6 @@ public:
protected:
void mousePressEvent(QMouseEvent *event) override;
-signals:
- void clicked(QUrl url);
- void finished();
-
-public slots:
- void downloadIcon(QString icon);
- void loadIcon(QPixmap pic);
-
private:
Ui::AppItem *ui;
@@ -39,6 +31,15 @@ private:
QString m_description;
QString m_icon;
QString m_url;
+
+public slots:
+ void downloadIcon(QString icon);
+ void loadIcon(QPixmap pic);
+
+signals:
+ void clicked(QUrl url);
+ void finished();
+
};
#endif // APPITEM_H
diff --git a/src/big_image.cpp b/src/big_image.cpp
index abfbefd71fb5fee1d9c7246942fa4d9b6d5cb63d..9ae6f561e1f08ea34b780299deb49a85387e8ecb 100644
--- a/src/big_image.cpp
+++ b/src/big_image.cpp
@@ -1,22 +1,30 @@
#include "big_image.h"
+
#include
#include
-big_image::big_image(DBlurEffectWidget *parent) : DBlurEffectWidget(parent)
+
+big_image::big_image(DBlurEffectWidget *parent) :
+ DBlurEffectWidget(parent),
+ m_image(new QLabel)
{
-// m_image->setParent(this);
- QHBoxLayout *layout=new QHBoxLayout;
- setLayout(layout);
- layout->addWidget(m_image);
- layout->setMargin(0);
- m_image->setAlignment(Qt::AlignCenter);
-// m_image->setMaximumSize(1360,768);
- setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);//设置图片对话框总在最前
+ setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); // 设置图片对话框总在最前
setRadius(0);
setMaskAlpha(60);
setMaskColor(QColor("#000000"));
+ QHBoxLayout *layout = new QHBoxLayout;
+ setLayout(layout);
+ layout->addWidget(m_image);
+ layout->setMargin(0);
+ // m_image->setParent(this);
+ // m_image->setMaximumSize(1360,768);
+ m_image->setAlignment(Qt::AlignCenter);
+}
+void big_image::setimage(QPixmap image)
+{
+ m_image->setPixmap(image);
}
void big_image::mousePressEvent(QMouseEvent *)
@@ -25,11 +33,6 @@ void big_image::mousePressEvent(QMouseEvent *)
m_image->clear();
}
-void big_image::setimage(QPixmap image)
-{
- m_image->setPixmap(image);
-}
-
void big_image::focusOutEvent(QFocusEvent *)
{
hide();
diff --git a/src/big_image.h b/src/big_image.h
index 4a22430021f675f60fa61a6c7172361ef7007c9c..c35306284a34eddcce436b9604eb3aa2cd7501f0 100644
--- a/src/big_image.h
+++ b/src/big_image.h
@@ -1,25 +1,27 @@
#ifndef BIG_IMAGE_H
#define BIG_IMAGE_H
-#include
-#include
#include
#include
+
+#include
+
DWIDGET_USE_NAMESPACE
class big_image : public DBlurEffectWidget
{
Q_OBJECT
+
public:
explicit big_image(DBlurEffectWidget *parent = nullptr);
- void mousePressEvent(QMouseEvent *event);
- QLabel *m_image=new QLabel;
- void setimage(QPixmap);
- void focusOutEvent(QFocusEvent *event);
-signals:
+ QLabel *m_image;
+
+ void setimage(QPixmap);
-public slots:
+protected:
+ void mousePressEvent(QMouseEvent *event) override;
+ void focusOutEvent(QFocusEvent *event) override;
};
#endif // BIG_IMAGE_H
diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp
index 437938348103ab32dfa9ce68e10c544a2ad2ba18..1a1b46a6343c6fb539af68c162560381289feb55 100644
--- a/src/downloadlist.cpp
+++ b/src/downloadlist.cpp
@@ -1,19 +1,27 @@
#include "downloadlist.h"
#include "ui_downloadlist.h"
-#include "widget.h"
-#include
-#include
-#include
+
#include
#include
-#include
-bool downloadlist::isInstall=false;
+
+#include "widget.h"
+
+bool downloadlist::isInstall = false;
downloadlist::downloadlist(QWidget *parent) :
QWidget(parent),
- ui(new Ui::downloadlist)
+ reinstall(false),
+ close(false),
+ ui(new Ui::downloadlist),
+ menu_install(new QMenu),
+ action_dpkg(new QAction),
+ action_deepin(new QAction),
+ action_gdebi(new QAction),
+ output_w(new DDialog),
+ textbrowser(new QTextBrowser)
{
ui->setupUi(this);
+
ui->pushButton_install->setEnabled(false);
ui->progressBar->setValue(0);
ui->label_filename->hide();
@@ -22,22 +30,25 @@ downloadlist::downloadlist(QWidget *parent) :
ui->widget_spinner->start();
ui->widget_spinner->hide();
action_dpkg->setText(tr("Spark Store App Installer"));
- action_gdebi->setText(tr("gdebi"));
action_deepin->setText(tr("deepin deb installer"));
+ action_gdebi->setText(tr("gdebi"));
+
connect(action_dpkg,&QAction::triggered,[=](){downloadlist::install(0);});
connect(action_deepin,&QAction::triggered,[=](){downloadlist::install(1);});
connect(action_gdebi,&QAction::triggered,[=](){downloadlist::install(2);});
- //ssinstall命令存在时再加入该选项
+ // ssinstall 命令存在时再加入该选项
QFile ssinstall("/usr/local/bin/ssinstall");
ssinstall.open(QIODevice::ReadOnly);
- if(ssinstall.isOpen()){
+ if(ssinstall.isOpen())
+ {
menu_install->addAction(action_dpkg);
}
QFile deepin("/usr/bin/deepin-deb-installer");
deepin.open(QIODevice::ReadOnly);
- if(deepin.isOpen()){
+ if(deepin.isOpen())
+ {
menu_install->addAction(action_deepin);
}
@@ -49,18 +60,19 @@ downloadlist::~downloadlist()
delete ui;
}
-void downloadlist::setValue(long long value)
+void downloadlist::setValue(qint64 value)
{
- ui->progressBar->setValue(int(value));
- ui->label_2->setText(QString::number(double(value)/100)+"% ("+speed+")");
- if(ui->label_2->text().left(4)=="100%"){
+ ui->progressBar->setValue(qint32(value));
+ ui->label_2->setText(QString::number(double(value) / 100) + "% (" + speed + ")");
+ if(ui->label_2->text().left(4) == "100%")
+ {
ui->label_2->setText(tr("Downloaded, waiting to install"));
}
}
-void downloadlist::setMax(long long max)
+void downloadlist::setMax(qint64 max)
{
- ui->progressBar->setMaximum(int(max));
+ ui->progressBar->setMaximum(qint32(max));
}
void downloadlist::setName(QString name)
@@ -75,26 +87,28 @@ QString downloadlist::getName()
void downloadlist::readyInstall()
{
- if(ui->progressBar->value()!= ui->progressBar->maximum() && !close){
+ if(ui->progressBar->value() != ui->progressBar->maximum() && !close)
+ {
ui->progressBar->hide();
ui->pushButton_install->show();
ui->pushButton_2->hide();
Widget::sendNotification(tr("Failed to download %1").arg(ui->label->text()), 5000,
- "/tmp/spark-store/icon_"+QString::number(num).toUtf8()+".png");
+ "/tmp/spark-store/icon_" + QString::number(num).toUtf8() + ".png");
ui->label_2->setText(tr("Download Failed,Check Your Connection"));
ui->pushButton_install->setEnabled(false);
- return;
+ return;
}
- if(!close){
+
+ if(!close)
+ {
ui->progressBar->hide();
ui->pushButton_install->setEnabled(true);
ui->pushButton_install->show();
ui->pushButton_2->hide();
Widget::sendNotification(tr("Finished downloading %1, awaiting to install").arg(ui->label->text()), 5000,
- "/tmp/spark-store/icon_"+QString::number(num).toUtf8()+".png");
+ "/tmp/spark-store/icon_" + QString::number(num).toUtf8() + ".png");
}
-
}
void downloadlist::setFileName(QString fileName)
@@ -114,79 +128,98 @@ void downloadlist::closeDownload()
void downloadlist::setSpeed(QString s)
{
- speed=s;
+ speed = s;
}
void downloadlist::install(int t)
{
- if(!isInstall){
- isInstall=true;
+ if(!isInstall)
+ {
+ isInstall = true;
ui->pushButton_install->hide();
ui->widget_spinner->show();
- qDebug()<<"/tmp/spark-store/"+ui->label_filename->text().toUtf8();
+ qDebug() << "/tmp/spark-store/" + ui->label_filename->text().toUtf8();
ui->label_2->setText(tr("Installing"));
- QtConcurrent::run([=](){
+
+ QtConcurrent::run([=]()
+ {
QProcess installer;
- if(!reinstall){
- switch (t) {
+ if(!reinstall)
+ {
+ switch(t)
+ {
case 0:
- installer.start("pkexec ssinstall /tmp/spark-store/"+ui->label_filename->text().toUtf8());
+ installer.start("pkexec ssinstall /tmp/spark-store/" + ui->label_filename->text().toUtf8());
break;
case 1:
- installer.start("deepin-deb-installer /tmp/spark-store/"+ui->label_filename->text().toUtf8());
+ installer.start("deepin-deb-installer /tmp/spark-store/" + ui->label_filename->text().toUtf8());
break;
case 2:
- installer.start("pkexec gdebi -n /tmp/spark-store/"+ui->label_filename->text().toUtf8());
+ installer.start("pkexec gdebi -n /tmp/spark-store/" + ui->label_filename->text().toUtf8());
break;
}
- }else {
- switch (t) {
+ }
+ else
+ {
+ switch(t)
+ {
case 0:
- installer.start("pkexec ssinstall /tmp/spark-store/"+ui->label_filename->text().toUtf8());
+ installer.start("pkexec ssinstall /tmp/spark-store/" + ui->label_filename->text().toUtf8());
break;
case 1:
- installer.start("deepin-deb-installer /tmp/spark-store/"+ui->label_filename->text().toUtf8());
+ installer.start("deepin-deb-installer /tmp/spark-store/" + ui->label_filename->text().toUtf8());
break;
case 2:
- installer.start("pkexec gdebi -n /tmp/spark-store/"+ui->label_filename->text().toUtf8());
+ installer.start("pkexec gdebi -n /tmp/spark-store/" + ui->label_filename->text().toUtf8());
break;
}
}
- bool haveError=false;
- bool notRoot=false;
+
+ bool haveError = false;
+ bool notRoot = false;
installer.waitForFinished();
- out=installer.readAllStandardOutput();
- QStringList everyOut=out.split("\n");
- for (int i=0;ipushButton_install->hide();
ui->label_2->setText(tr("Finish"));
ui->pushButton_3->show();
- }else {
+ }
+ else
+ {
ui->pushButton_install->show();
ui->pushButton_install->setText(tr("Retry"));
ui->label_2->setText(tr("Error happened in dpkg progress , you can try it again"));
ui->pushButton_3->show();
}
- if(notRoot){
+
+ if(notRoot)
+ {
ui->label_2->setText(tr("dpkg progress had been aborted,you can retry installation"));
ui->pushButton_install->show();
ui->pushButton_3->hide();
}
- ui->widget_spinner->hide();
- downloadlist::isInstall=false;
+ ui->widget_spinner->hide();
+ downloadlist::isInstall = false;
});
qDebug()<label_filename->text().toUtf8();
@@ -196,7 +229,7 @@ void downloadlist::install(int t)
void downloadlist::on_pushButton_install_clicked()
{
- //弹出菜单
+ // 弹出菜单
menu_install->exec(cursor().pos());
}
@@ -205,17 +238,18 @@ void downloadlist::on_pushButton_2_clicked()
ui->label_2->setText(tr("Download canceled"));
ui->pushButton_2->setEnabled(false);
ui->progressBar->hide();
- close=true;
+ close = true;
}
void downloadlist::on_pushButton_3_clicked()
{
- output_w.layout()->addWidget(textbrowser);
textbrowser->setLineWidth(0);
textbrowser->setText(out);
- output_w.layout()->setMargin(20);
- output_w.setTitle(ui->label->text());
- output_w.setMinimumHeight(600);
- output_w.setAttribute(Qt::WA_TranslucentBackground);
- output_w.show();
+
+ output_w->setMinimumHeight(600);
+ output_w->setAttribute(Qt::WA_TranslucentBackground);
+ output_w->setTitle(ui->label->text());
+ output_w->layout()->setMargin(20);
+ output_w->layout()->addWidget(textbrowser);
+ output_w->show();
}
diff --git a/src/downloadlist.h b/src/downloadlist.h
index db11116a4f40aeac2be1a9636d6efaa29e24a9c8..e9a8b8aba108b8e572ae64d72665e5a2e627b4b0 100644
--- a/src/downloadlist.h
+++ b/src/downloadlist.h
@@ -2,11 +2,14 @@
#define DOWNLOADLIST_H
#include
-#include
#include
#include
#include
+
+#include
+
DWIDGET_USE_NAMESPACE
+
namespace Ui {
class downloadlist;
}
@@ -18,40 +21,45 @@ class downloadlist : public QWidget
public:
explicit downloadlist(QWidget *parent = nullptr);
~downloadlist();
- void setValue(long long);
- void setMax(long long);
+
+ int num;
+ bool free;
+ static bool isInstall;
+ bool reinstall;
+ QString speed;
+ QString out;
+ QString pkgName;
+ bool close;
+
+ void setValue(qint64);
+ void setMax(qint64);
void setName(QString);
QString getName();
void readyInstall();
- bool free;
+
void setFileName(QString);
void seticon(const QPixmap);
void closeDownload();
void setSpeed(QString);
- int num;
- bool close=false;
- QString out;
- DDialog output_w;
- QTextBrowser *textbrowser=new QTextBrowser;
- bool reinstall=false;
- QString pkgName;
- QMenu *menu_install=new QMenu;
- QAction *action_gdebi=new QAction;
- QAction *action_dpkg=new QAction;
- QAction *action_deepin=new QAction;
+
void install(int);
-private slots:
- void on_pushButton_install_clicked();
-// void on_pushButton_maninst_clicked();
- void on_pushButton_2_clicked();
- void on_pushButton_3_clicked();
private:
Ui::downloadlist *ui;
- static bool isInstall;
- QString speed;
+ QMenu *menu_install;
+ QAction *action_dpkg;
+ QAction *action_deepin;
+ QAction *action_gdebi;
+
+ DDialog *output_w;
+ QTextBrowser *textbrowser;
+
+private slots:
+ void on_pushButton_install_clicked();
+ void on_pushButton_2_clicked();
+ void on_pushButton_3_clicked();
};
-//bool downloadlist::isInstall=false;
+
#endif // DOWNLOADLIST_H
diff --git a/src/downloadworker.cpp b/src/downloadworker.cpp
index fbece6e78891301779e295970593e42fa88fb351..7a54e759c91432902fb6f61f13d9fb0b3f97fca7 100644
--- a/src/downloadworker.cpp
+++ b/src/downloadworker.cpp
@@ -1,10 +1,9 @@
#include "downloadworker.h"
-#include
+
#include
#include
#include
#include
-#include
#include
#include
#include
@@ -12,7 +11,7 @@
DownloadWorker::DownloadWorker(QObject *parent)
{
-
+ Q_UNUSED(parent)
}
void DownloadWorker::setIdentifier(int identifier)
@@ -35,28 +34,28 @@ qint64 DownloadWorker::getReceivedPos()
void DownloadWorker::doWork()
{
- mgr = new QNetworkAccessManager(this);
- QNetworkRequest request;
- request.setUrl(url);
- request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
- request.setRawHeader("Range", QString("bytes=%1-%2").arg(startPos)
- .arg(endPos).toLocal8Bit());
- reply = mgr->get(request);
- qDebug() << "开始下载数据:" << QString(" %1~%2 -> writePos Start %3")
- .arg(startPos).arg(endPos).arg(receivedPos);
- connect(reply, static_cast(&QNetworkReply::error),
- [this](QNetworkReply::NetworkError error){
- if (error != QNetworkReply::NoError) {
- qDebug() << "出错了:" << reply->errorString();
- }
- });
- connect(reply, &QNetworkReply::finished, mgr, &QNetworkAccessManager::deleteLater);
- connect(reply, &QNetworkReply::readyRead, this, &DownloadWorker::dataReady);
- connect(reply, &QNetworkReply::finished, this, &DownloadWorker::slotFinish);
- connect(reply, &QNetworkReply::downloadProgress, this, &DownloadWorker::handleProcess);
-// connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
- connect(reply, &QNetworkReply::finished, this, &DownloadWorker::doStop);
+ mgr = new QNetworkAccessManager(this);
+ QNetworkRequest request;
+ request.setUrl(url);
+ request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
+ request.setRawHeader("Range", QString("bytes=%1-%2").arg(startPos).arg(endPos).toLocal8Bit());
+ reply = mgr->get(request);
+ qDebug() << "开始下载数据:" << QString(" %1~%2 -> writePos Start %3").arg(startPos).arg(endPos).arg(receivedPos);
+ connect(reply, static_cast (&QNetworkReply::error),
+ [this](QNetworkReply::NetworkError error)
+ {
+ if(error != QNetworkReply::NoError)
+ {
+ qDebug() << "出错了:" << reply->errorString();
+ }
+ });
+ connect(reply, &QNetworkReply::finished, mgr, &QNetworkAccessManager::deleteLater);
+ connect(reply, &QNetworkReply::readyRead, this, &DownloadWorker::dataReady);
+ connect(reply, &QNetworkReply::finished, this, &DownloadWorker::slotFinish);
+ connect(reply, &QNetworkReply::downloadProgress, this, &DownloadWorker::handleProcess);
+ // connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
+ connect(reply, &QNetworkReply::finished, this, &DownloadWorker::doStop);
}
void DownloadWorker::doStop()
@@ -80,8 +79,7 @@ void DownloadWorker::dataReady()
void DownloadWorker::slotFinish()
{
file->flush();
- qDebug() << "数据块下载完毕:" << QString(" %1~%2 -> writePos Start %3")
- .arg(startPos).arg(endPos).arg(receivedPos);
+ qDebug() << "数据块下载完毕:" << QString(" %1~%2 -> writePos Start %3").arg(startPos).arg(endPos).arg(receivedPos);
emit workFinished();
}
@@ -93,6 +91,8 @@ void DownloadWorker::handleProcess(qint64, qint64)
DownloadController::DownloadController(QObject *parent)
{
+ Q_UNUSED(parent)
+
domains = {
"d1.store.deepinos.org.cn",
"d2.store.deepinos.org.cn",
@@ -100,13 +100,15 @@ DownloadController::DownloadController(QObject *parent)
"d4.store.deepinos.org.cn",
"d5.store.deepinos.org.cn"
};
- this->threadNum = domains.size() > 4 ? 4 : domains.size();
+ this->threadNum = domains.size() > 5 ? 5 : domains.size();
}
DownloadController::~DownloadController()
{
- if (workers.size() > 0) {
- for(int i = 0; i < workers.size(); i++) {
+ if(workers.size() > 0)
+ {
+ for(int i = 0; i < workers.size(); i++)
+ {
workers.at(i)->doStop();
workers.at(i)->disconnect();
workers.at(i)->deleteLater();
@@ -130,45 +132,52 @@ void DownloadController::setThreadNum(int threadNum)
*/
void DownloadController::startDownload(const QString &url)
{
-
-
finish = 0;
// 下载任务等分,计算每个线程的下载数据
fileSize = getFileSize(url);
- if (fileSize == 0) {
+ if(fileSize == 0)
+ {
emit errorOccur("文件大小获取失败");
return;
}
+
qint64 segmentSize = fileSize / threadNum;
ranges.resize(threadNum);
QVector receivedBytes;
receivedBytes.resize(threadNum);
- for (int i = 0; i < threadNum; i++) {
+ for(int i = 0; i < threadNum; i++)
+ {
ranges[i].first = i * segmentSize;
ranges[i].second = i * segmentSize + segmentSize - 1;
receivedBytes[i] = 0;
}
- ranges[threadNum-1].second = fileSize; // 余数部分加入最后一个
+ ranges[threadNum - 1].second = fileSize; // 余数部分加入最后一个
// 打开文件
QDir tmpdir("/tmp/spark-store");
file = new QFile;
file->setFileName(tmpdir.absoluteFilePath(filename));
- if (file->exists())
+ if(file->exists())
+ {
file->remove();
- if (!file->open(QIODevice::WriteOnly)) {
+ }
+
+ if(!file->open(QIODevice::WriteOnly))
+ {
delete file;
file = nullptr;
emit errorOccur(file->errorString());
return;
}
+
file->resize(fileSize);
// 创建下载线程
workers.clear();
- for(int i = 0; i < ranges.size(); i++) {
+ for(int i = 0; i < ranges.size(); i++)
+ {
qDebug() << QString("第%1个下载请求:%2-%3").arg(i).arg(ranges.at(i).first).arg(ranges.at(i).second);
auto worker = new DownloadWorker(this);
auto range = ranges.at(i);
@@ -176,8 +185,10 @@ void DownloadController::startDownload(const QString &url)
worker->setIdentifier(i);
worker->setParamter(chunkUrl, range, file);
workers.append(worker);
+
connect(worker, &DownloadWorker::downloadProcess, this, &DownloadController::handleProcess);
connect(worker, &DownloadWorker::workFinished, this, &DownloadController::chunkDownloadFinish);
+
worker->doWork();
}
}
@@ -187,14 +198,15 @@ void DownloadController::startDownload(const QString &url)
*/
void DownloadController::stopDownload()
{
- for(int i = 0; i < workers.size(); i++) {
+ for(int i = 0; i < workers.size(); i++)
+ {
workers.at(i)->doStop();
workers.at(i)->disconnect();
workers.at(i)->deleteLater();
}
workers.clear();
-
qDebug() << "文件下载路径:" << QFileInfo(file->fileName()).absoluteFilePath();
+
file->flush();
file->close();
delete file;
@@ -205,7 +217,8 @@ void DownloadController::stopDownload()
void DownloadController::handleProcess()
{
qint64 bytesReceived = 0;
- for(int i = 0; i < workers.size(); i++) {
+ for(int i = 0; i < workers.size(); i++)
+ {
bytesReceived += workers.at(i)->getReceivedPos();
}
qDebug() << QString("下载进度 %1-%2").arg(bytesReceived).arg(fileSize);
@@ -216,7 +229,8 @@ void DownloadController::chunkDownloadFinish()
{
finish++;
qDebug() << QString("已下载了%1块,共%2块!!!").arg(finish).arg(threadNum);
- if (finish == threadNum) {
+ if(finish == threadNum)
+ {
stopDownload();
emit downloadFinished();
}
@@ -230,17 +244,21 @@ qint64 DownloadController::getFileSize(const QString& url)
request.setUrl(QUrl(url));
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = requestManager.head(request);
- connect(reply, static_cast(&QNetworkReply::error),
- [this, reply](QNetworkReply::NetworkError error){
- if (error != QNetworkReply::NoError) {
+ connect(reply, static_cast (&QNetworkReply::error),
+ [this, reply](QNetworkReply::NetworkError error)
+ {
+ if(error != QNetworkReply::NoError)
+ {
emit errorOccur(reply->errorString());
}
});
connect(reply, &QNetworkReply::finished, &event, &QEventLoop::quit);
event.exec();
+
qint64 fileSize = 0;
- if (reply->rawHeader("Accept-Ranges") == QByteArrayLiteral("bytes")
- && reply->hasRawHeader(QString("Content-Length").toLocal8Bit())) {
+ if(reply->rawHeader("Accept-Ranges") == QByteArrayLiteral("bytes")
+ && reply->hasRawHeader(QString("Content-Length").toLocal8Bit()))
+ {
fileSize = reply->header(QNetworkRequest::ContentLengthHeader).toUInt();
}
qDebug() << "文件大小为:" << fileSize;
@@ -251,9 +269,9 @@ qint64 DownloadController::getFileSize(const QString& url)
QString DownloadController::replaceDomain(const QString& url, const QString domain)
{
QRegularExpression regex(R"((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])");
- if (regex.match(url).hasMatch()) {
+ if(regex.match(url).hasMatch())
+ {
return QString(url).replace(regex.match(url).captured(), domain);
}
return url;
}
-
diff --git a/src/downloadworker.h b/src/downloadworker.h
index 72f558bbbb69d7aa586ad1c4427d1326f01f6f55..5ea0acaf7bf0c980984d4e6735b527f5ec1e4c00 100644
--- a/src/downloadworker.h
+++ b/src/downloadworker.h
@@ -9,8 +9,10 @@
class DownloadWorker : public QObject
{
Q_OBJECT
+
public:
explicit DownloadWorker(QObject *parent = nullptr);
+
void setIdentifier(int identifier);
void setParamter(const QString &url, QPair range, QFile *flle);
qint64 getReceivedPos();
@@ -22,12 +24,6 @@ public slots:
void slotFinish();
void handleProcess(qint64, qint64);
-signals:
- void resultReady(int identifier, QByteArray data);
- void testSignals();
- void workFinished();
- void downloadProcess();
-
private:
int identifier;
QString url;
@@ -37,14 +33,23 @@ private:
QNetworkReply *reply;
QNetworkAccessManager *mgr;
QFile *file;
+
+signals:
+ void resultReady(int identifier, QByteArray data);
+ void testSignals();
+ void workFinished();
+ void downloadProcess();
+
};
class DownloadController : public QObject
{
Q_OBJECT
+
public:
explicit DownloadController(QObject *parent = nullptr);
~DownloadController();
+
void setFilename(QString filename);
void setThreadNum(int threadNum);
void startDownload(const QString &url);
@@ -52,15 +57,6 @@ public:
qint64 getFileSize(const QString& url);
QString replaceDomain(const QString& url, const QString domain);
-public slots:
- void handleProcess();
- void chunkDownloadFinish();
-
-signals:
- void errorOccur(const QString& msg);
- void downloadProcess(qint64, qint64);
- void downloadFinished();
-
private:
int threadNum;
QString filename;
@@ -70,6 +66,16 @@ private:
QList workers;
int finish = 0;
QVector domains;
+
+public slots:
+ void handleProcess();
+ void chunkDownloadFinish();
+
+signals:
+ void errorOccur(const QString& msg);
+ void downloadProcess(qint64, qint64);
+ void downloadFinished();
+
};
#endif // FILEDOWNLOADWORKER_H
diff --git a/src/flowlayout.cpp b/src/flowlayout.cpp
index 9203da0ba18fc6c78acd8c369c7bae5a698912ec..b60335c7430acd298c51c0732f2d333c0e9e1f43 100644
--- a/src/flowlayout.cpp
+++ b/src/flowlayout.cpp
@@ -117,14 +117,14 @@ QLayoutItem *FlowLayout::takeAt(int index)
if (index >= 0 && index < itemList.size())
return itemList.takeAt(index);
else
- return 0;
+ return nullptr;
}
//! [5]
//! [6]
Qt::Orientations FlowLayout::expandingDirections() const
{
- return 0;
+ return nullptr;
}
//! [6]
@@ -215,7 +215,7 @@ int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
return -1;
} else if (parent->isWidgetType()) {
QWidget *pw = static_cast(parent);
- return pw->style()->pixelMetric(pm, 0, pw);
+ return pw->style()->pixelMetric(pm, nullptr, pw);
} else {
return static_cast(parent)->spacing();
}
diff --git a/src/flowlayout.h b/src/flowlayout.h
index 920f4e63da203eaca62285026b5b688a9dbba938..8aa460359944b177bec8ca4fa2c6a7fb913ac547 100644
--- a/src/flowlayout.h
+++ b/src/flowlayout.h
@@ -60,7 +60,7 @@ class FlowLayout : public QLayout
public:
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
- ~FlowLayout();
+ ~FlowLayout() override;
void addItem(QLayoutItem *item) override;
int horizontalSpacing() const;
@@ -85,4 +85,4 @@ private:
};
//! [0]
-#endif // FLOWLAYOUT_H
\ No newline at end of file
+#endif // FLOWLAYOUT_H
diff --git a/src/image_show.cpp b/src/image_show.cpp
index 4dcc77341a8c179bdc9c9cf7a1c3dedbea3092cc..54ebf70c2b5eb93be51568b26ffaab6c4cc79a4f 100644
--- a/src/image_show.cpp
+++ b/src/image_show.cpp
@@ -1,17 +1,13 @@
#include "image_show.h"
-#include // Qt5 不再建议使用 QDesktopWidget
#include
-#include
-
-#include
-#include
-#include
-#include
-
-DWIDGET_USE_NAMESPACE
+#include // Qt5 不再建议使用 QDesktopWidget
+#include
-image_show::image_show(QWidget *parent) : QWidget(parent)
+image_show::image_show(QWidget *parent) :
+ QWidget(parent),
+ m_dialog(new big_image),
+ m_label(new QLabel)
{
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(m_label);
@@ -23,13 +19,12 @@ void image_show::setImage(QPixmap image)
{
QImage screen0;
screen0 = image.toImage();
- // QPainter painter(&screen0);
QImage re_screen1;
QImage re_screen0 = screen0.scaled(QSize(400, 300), Qt::KeepAspectRatio, Qt::SmoothTransformation);
// 获取主屏幕尺寸
- desktop_w = DApplication::primaryScreen()->geometry().width();
- desktop_h = DApplication::primaryScreen()->geometry().height();
+ desktop_w = QGuiApplication::primaryScreen()->geometry().width();
+ desktop_h = QGuiApplication::primaryScreen()->geometry().height();
if(screen0.width() > (desktop_w - 20) || screen0.height() > (desktop_h - 20))
{
@@ -53,5 +48,4 @@ void image_show::mousePressEvent(QMouseEvent *)
m_dialog->setFixedSize(desktop_w, desktop_h);
m_dialog->move(0,0);
- // moveToCenter(m_dialog);
}
diff --git a/src/image_show.h b/src/image_show.h
index 8854068cf6fc8c4ed60b7f5bb46d8759bb94886a..a851dd791c6ad9631372191c5448d35cc04b95ec 100644
--- a/src/image_show.h
+++ b/src/image_show.h
@@ -3,30 +3,30 @@
#include
#include
-#include
-#include
-#include
-#include
-#include
-DWIDGET_USE_NAMESPACE
+
+#include "big_image.h"
+
class image_show : public QWidget
{
Q_OBJECT
+
public:
explicit image_show(QWidget *parent = nullptr);
- void setImage(QPixmap);
int desktop_w;
int desktop_h;
+
+ void setImage(QPixmap);
+
+protected:
+ void mousePressEvent(QMouseEvent *event) override;
+
private:
- QLabel *m_label=new QLabel;
- QPixmap m_image;
+ big_image *m_dialog;
+ QLabel *m_label;
QLabel image;
- big_image *m_dialog=new big_image;
- void mousePressEvent(QMouseEvent *event);
-signals:
+ QPixmap m_image;
-public slots:
};
#endif // IMAGE_SHOW_H
diff --git a/src/main.cpp b/src/main.cpp
index b059f425a291718112bc2561a8dbcbb7ca988d0d..d2138612b2dd1197c8ff9f6665766b66ecc672a9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,19 +1,19 @@
#include
-#include //Dtk::Widget::moveToCenter(&w); 要调用它,就得引用DWidgetUtil
-#include
-#include
-#include
-#include
-#include "appitem.h"
+#include
+#include // Dtk::Widget::moveToCenter(&w); 要调用它,就得引用 DWidgetUtil
+
+#include
+
+#include "widget.h"
DWIDGET_USE_NAMESPACE
int main(int argc, char *argv[])
{
- DApplication::loadDXcbPlugin(); //让bar处在标题栏中
+ // DApplication::loadDXcbPlugin(); // 让 bar 处在标题栏中
DApplication a(argc, argv);
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
- a.loadTranslator();//载入翻译
+ a.loadTranslator(); // 载入翻译
/* Customized DAboutDialog (Can't work on other distro like Ubuntu...)
*
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
* a.setAboutDialog(&dialog);
* dialog.setLicense(QObject::tr("We publish this program under GPL V3"));
* dialog.setVersion(DApplication::buildVersion("Version 2.0.2.5"));
- * dialog.setProductIcon(QIcon::fromTheme("spark-store")); //设置Logo
+ * dialog.setProductIcon(QIcon::fromTheme("spark-store")); // 设置Logo
* dialog.setProductName(QLabel::tr("Spark Store"));
* dialog.setDescription(
* QObject::tr(
@@ -52,36 +52,49 @@ int main(int argc, char *argv[])
)
);
+ // 限制单实例运行
+ if(!a.setSingleInstance("spark-store"))
+ {
+ return -1;
+ }
+
+ // 保存窗口主题设置
+ DApplicationSettings settings;
+
Widget w;
- QDesktopWidget *s=DApplication::desktop();
- int d_w=s->width();
- int d_h=s->height();
- if(d_w<=1366){
+ QScreen *s = DApplication::primaryScreen();
+ int d_w = s->geometry().width();
+ int d_h = s->geometry().height();
+
+ if(d_w <= 1366)
+ {
w.setMinimumWidth(925);
w.resize(925,650);
- }else if(d_w<=1920){
- w.setMinimumWidth(1180);
- w.resize(1180,760);
- }else {
+ }
+ else
+ {
w.setMinimumWidth(1180);
w.resize(1180,760);
}
- if(d_h<=768){
+
+ if(d_h <= 768)
+ {
w.setMinimumHeight(650);
w.resize(925,650);
- }else if(d_h<=1080){
- w.setMinimumHeight(760);
- w.resize(1180,760);
- }else {
+ }
+ else
+ {
w.setMinimumHeight(760);
w.resize(1180,760);
}
- QString arg1=argv[1];
- if(arg1.left(6)=="spk://"){
+ QString arg1 = argv[1];
+ if(arg1.left(6)=="spk://")
+ {
w.openUrl(QUrl(argv[1]));
}
- //让打开时界面显示在正中
+
+ // 让打开时界面显示在正中
Dtk::Widget::moveToCenter(&w);
w.show();
diff --git a/src/progressload.cpp b/src/progressload.cpp
index 3e07fb33975e9deb27605702b60031be7cc2fdd6..c2fac28b3e37bf23b25ecfb4bfd13a405aa4f23f 100644
--- a/src/progressload.cpp
+++ b/src/progressload.cpp
@@ -1,37 +1,44 @@
#include "progressload.h"
-ProgressLoad::ProgressLoad(QWidget *parent) : QWidget(parent)
+#include
+
+ProgressLoad::ProgressLoad(QWidget *parent) :
+ QWidget(parent),
+ m_progess(new QWidget(this)),
+ timer(new QTimer),
+ value(0)
{
- m_progess=new QWidget(this);
m_progess->move(0,0);
m_progess->show();
- timer=new QTimer;
- value=0;
+
timer->setInterval(10);
timer->start();
- connect(timer,&QTimer::timeout,[=](){
- m_progess->setFixedWidth(width()/100*value);
+ connect(timer, &QTimer::timeout, [=]()
+ {
+ m_progess->setFixedWidth(width() / 100 * value);
m_progess->setFixedHeight(height());
});
}
void ProgressLoad::setValue(int v)
{
- value=v;
- m_progess->setFixedWidth(width()/100*value);
+ value = v;
+ m_progess->setFixedWidth(width() / 100 * value);
}
void ProgressLoad::setTheme(bool dark, QColor color)
{
- if(dark){
- plt.setColor(QPalette::Background,QColor(28,28,28));
+ if(dark)
+ {
+ plt.setColor(QPalette::Background, QColor(40, 40, 40));
setAutoFillBackground(true);
setPalette(plt);
-
- }else {
- plt.setColor(QPalette::Background,QColor(255,255,255));
+ }
+ else
+ {
+ plt.setColor(QPalette::Background, QColor(255, 255, 255));
setAutoFillBackground(true);
setPalette(plt);
}
- m_progess->setStyleSheet("background-color:"+color.name());
+ m_progess->setStyleSheet("background-color: " + color.name() + ";");
}
diff --git a/src/progressload.h b/src/progressload.h
index ffa3c7e0febb17d17d28e8c4a18d749ec6866a37..b1bb0ff8054e26116d013078c05204422108894e 100644
--- a/src/progressload.h
+++ b/src/progressload.h
@@ -4,21 +4,23 @@
#include
#include
#include
+
class ProgressLoad : public QWidget
{
Q_OBJECT
+
public:
explicit ProgressLoad(QWidget *parent = nullptr);
+
void setValue(int v);
- void setTheme(bool dark,QColor color);
-signals:
+ void setTheme(bool dark, QColor color);
-public slots:
private:
QWidget *m_progess;
- int value;
QTimer *timer;
+ int value;
QPalette plt;
+
};
#endif // PROGRESSLOAD_H
diff --git a/src/spark-store.pro b/src/spark-store.pro
index fcf5be5815b941e2b1e90c58f383e08fb856f284..c1737fdab163c0a7347f39e66940b834bbbdf8b7 100644
--- a/src/spark-store.pro
+++ b/src/spark-store.pro
@@ -8,9 +8,6 @@ QT += core gui network concurrent webenginewidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-CONFIG += c++11 link_pkgconfig
-PKGCONFIG += dtkwidget glib-2.0 gdk-pixbuf-2.0 libnotify
-
TARGET = spark-store
TEMPLATE = app
@@ -25,35 +22,42 @@ 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
+include(../third-party/QtNetworkService/QtNetworkService.pri)
+
+CONFIG += c++11 link_pkgconfig
+PKGCONFIG += dtkwidget glib-2.0 gdk-pixbuf-2.0 libnotify
+
# 禁止输出 qWarning / qDebug 信息
CONFIG(release, debug|release): DEFINES += QT_NO_WARNING_OUTPUT QT_NO_DEBUG_OUTPUT
-SOURCES += main.cpp\
+SOURCES += \
appitem.cpp \
- downloadworker.cpp \
- widget.cpp \
+ big_image.cpp \
downloadlist.cpp \
+ downloadworker.cpp \
+ flowlayout.cpp \
image_show.cpp \
- big_image.cpp \
+ main.cpp \
progressload.cpp \
- flowlayout.cpp \
+ widget.cpp \
workerthreads.cpp
-HEADERS += \
+HEADERS += \
appitem.h \
- downloadworker.h \
- widget.h \
+ big_image.h \
downloadlist.h \
+ downloadworker.h \
+ flowlayout.h \
image_show.h \
- big_image.h \
progressload.h \
- flowlayout.h \
+ widget.h \
workerthreads.h
FORMS += \
appitem.ui \
- widget.ui \
- downloadlist.ui
+ downloadlist.ui \
+ widget.ui
RESOURCES += \
../assets/icons.qrc
@@ -73,10 +77,7 @@ DISTFILES += \
../assets/tags/logo_icon.svg \
../assets/tags/uos.svg
-TRANSLATIONS = ../translations/spark-store_en.ts \
- ../translations/spark-store_zh_CN.ts
- ../translations/spark-store_fr.ts\
-
-DEFINES += QT_APP_DEBUG
-include(../third-party/QtNetworkService/QtNetworkService.pri)
-
+TRANSLATIONS += \
+ ../translations/spark-store_en.ts \
+ ../translations/spark-store_fr.ts \
+ ../translations/spark-store_zh_CN.ts
diff --git a/src/widget.cpp b/src/widget.cpp
index b67cc188c97abc20f42a1f514d505285cd4f211a..cb9eb05b46a3a2393e810e0d9e79ca08de29fe4c 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -1,38 +1,35 @@
+#include
#include
+
#include "widget.h"
#include "ui_widget.h"
-#include
+
+#include
+#include
+#include
+#include
+#include
#include
+#include
+#include
#include
#include
-#include
-#include
-#include
#include
-#include
-#include
-#include
-#include
-#include
-#include // 并发
#include
-#include
#include
-#include
-#include
-#include
-#include
-#include
-#include "image_show.h"
-#include
-#include
+#include // 并发
+
#include
#include
+#include
+#include
+#include
#include
-#include
-#include "HttpClient.h"
+
#include "appitem.h"
#include "flowlayout.h"
+
+#include "HttpClient.h"
#include "downloadworker.h"
DWIDGET_USE_NAMESPACE
@@ -42,31 +39,49 @@ Widget::Widget(DBlurEffectWidget *parent) :
ui(new Ui::Widget)
{
ui->setupUi(this);
+
initUI();
initConfig();
- manager = new QNetworkAccessManager(this);//下载管理
- m_loadweb=ui->progressload;
- m_loadweb->show();
+
+ manager = new QNetworkAccessManager(this); // 下载管理
httpClient = new AeaQt::HttpClient;
- // 并发下载
- downloadController = new DownloadController(this);
-
- connect(ui->menu_main,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(0);});
- connect(ui->menu_network,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(1);});
- connect(ui->menu_chat,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(2);});
- connect(ui->menu_music,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(3);});
- connect(ui->menu_video,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(4);});
- connect(ui->menu_photo,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(5);});
- connect(ui->menu_game,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(6);});
- connect(ui->menu_office,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(7);});
- connect(ui->menu_read,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(8);});
- connect(ui->menu_dev,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(9);});
- connect(ui->menu_system,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(10);});
- connect(ui->menu_theme,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(11);});
- connect(ui->menu_other,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(12);});
- connect(ui->menu_download,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(13);});
- // connect((ui->titlebar))
+ downloadController = new DownloadController(this); // 并发下载
+
+ connect(ui->menu_main, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(0);});
+ connect(ui->menu_network, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(1);});
+ connect(ui->menu_chat, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(2);});
+ connect(ui->menu_music, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(3);});
+ connect(ui->menu_video, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(4);});
+ connect(ui->menu_photo, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(5);});
+ connect(ui->menu_game, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(6);});
+ connect(ui->menu_office, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(7);});
+ connect(ui->menu_read, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(8);});
+ connect(ui->menu_dev, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(9);});
+ connect(ui->menu_system, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(10);});
+ connect(ui->menu_theme, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(11);});
+ connect(ui->menu_other, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(12);});
+ connect(ui->menu_download, &QPushButton::clicked, this, [=](){Widget::chooseLeftMenu(13);});
+
+ connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [=](DGuiApplicationHelper::ColorType themeType)
+ {
+ // 获取系统活动色
+ main_color = DGuiApplicationHelper::instance()->applicationPalette().highlight().color();
+
+ if(themeType == DGuiApplicationHelper::DarkType)
+ {
+ qDebug() << "Dark";
+ themeIsDark = true;
+ }
+ else if(themeType == DGuiApplicationHelper::LightType)
+ {
+ qDebug() << "Light";
+ themeIsDark = false;
+ }
+
+ // 设置 UI 主题
+ setTheme(themeIsDark, main_color);
+ });
connect(&appinfoLoadThread, SIGNAL(requestResetUi()), this, SLOT(sltAppinfoResetUi()), Qt::ConnectionType::BlockingQueuedConnection);
connect(&appinfoLoadThread, &SpkAppInfoLoaderThread::requestSetTags, this, &Widget::sltAppinfoTags, Qt::ConnectionType::BlockingQueuedConnection);
@@ -75,13 +90,12 @@ Widget::Widget(DBlurEffectWidget *parent) :
connect(&appinfoLoadThread, &SpkAppInfoLoaderThread::finishedScreenshotLoad, this, &Widget::sltAppinfoScreenshot, Qt::ConnectionType::BlockingQueuedConnection);
connect(&appinfoLoadThread, &SpkAppInfoLoaderThread::finishAllLoading, this, &Widget::sltAppinfoFinish, Qt::ConnectionType::BlockingQueuedConnection);
-
// 搜索事件
connect(searchEdit, &DSearchEdit::returnPressed, this, [=]()
{
qDebug() << "触发了搜索,呜啦啦啦!";
QString searchtext = searchEdit->text();
- if(searchtext != "")
+ if(!searchtext.isEmpty())
{
qDebug() << searchEdit->text();
searchApp(searchtext);
@@ -89,38 +103,35 @@ Widget::Widget(DBlurEffectWidget *parent) :
this->setFocus();
});
- connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [=](DGuiApplicationHelper::ColorType themeType) {
- QColor main_color;
- main_color=DGuiApplicationHelper::instance()->applicationPalette().highlight().color();
- if(themeType==DGuiApplicationHelper::DarkType){
- qDebug()<<"Dark";
- setTheme(true,main_color);
- }else {
- qDebug()<<"Light";
- setTheme(false,main_color);
- }
- });
-
// 计算显示下载速度
download_speed.setInterval(1000);
download_speed.start();
- connect(&download_speed,&QTimer::timeout,[=](){
- if(isdownload){
- size1=download_size;
+ connect(&download_speed,&QTimer::timeout,[=]()
+ {
+ if(isdownload)
+ {
+ size1 = download_size;
QString theSpeed;
double bspeed;
- bspeed=size1-size2;
- if(bspeed<1024){
- theSpeed=QString::number(bspeed)+"B/s";
- }else if (bspeed<(1024*1024)) {
- theSpeed=QString::number(0.01*int(100*(bspeed/1024)))+"KB/s";
- }else if (bspeed<(1024*1024*1024)) {
- theSpeed=QString::number(0.01*int(100*(bspeed/(1024*1024))))+"MB/s";
- }else {
- theSpeed=QString::number(0.01*int(100*(bspeed/(1024*1024*1024))))+"GB/s";
+ bspeed = size1 - size2;
+ if(bspeed < 1024)
+ {
+ theSpeed = QString::number(bspeed) + "B/s";
}
- download_list[nowDownload-1].setSpeed(theSpeed);
- size2=download_size;
+ else if(bspeed < 1024 * 1024)
+ {
+ theSpeed = QString::number(0.01 * int(100 * (bspeed / 1024))) + "KB/s";
+ }
+ else if(bspeed < 1024 * 1024 * 1024)
+ {
+ theSpeed = QString::number(0.01 * int(100 * (bspeed / (1024 * 1024)))) + "MB/s";
+ }
+ else
+ {
+ theSpeed = QString::number(0.01 * int(100 * (bspeed / (1024 * 1024 * 1024)))) + "GB/s";
+ }
+ download_list[nowDownload - 1].setSpeed(theSpeed);
+ size2 = download_size;
}
});
@@ -131,16 +142,17 @@ Widget::~Widget()
{
notify_uninit();
-// delete httpFinished;
+ // delete httpFinished;
delete ui;
- qDebug()<<"exit";
+
+ qDebug() << "exit";
DApplication::quit();
}
void Widget::initUI()
{
// ui初始化
- setMaskAlpha(220);
+ setMaskAlpha(200);
ui->webfoot->setFixedHeight(0);
ui->stackedWidget->setCurrentIndex(0);
ui->listWidget->hide();
@@ -148,25 +160,27 @@ void Widget::initUI()
ui->pushButton_uninstall->hide();
ui->line1_widget->setStyleSheet("background-color:#808080");
ui->icon->setPixmap(QIcon::fromTheme("spark-store").pixmap(36,36));
- ui->titlebar->setFixedHeight(50);
+ ui->titlebar->setFixedHeight(48);
+
+ m_loadweb = ui->progressload;
label_screen << ui->screen_0 << ui->screen_1 << ui->screen_2 << ui->screen_3 << ui->screen_4;
// 初始化分界线
- QGraphicsOpacityEffect *opacityEffect_1=new QGraphicsOpacityEffect;
+ QGraphicsOpacityEffect *opacityEffect_1 = new QGraphicsOpacityEffect;
opacityEffect_1->setOpacity(0.1);
ui->line1_widget->setGraphicsEffect(opacityEffect_1);
// 搜索框
- QWidget *w_titlebar=new QWidget;
- QHBoxLayout *ly_titlebar=new QHBoxLayout;
+ QWidget *w_titlebar = new QWidget;
+ QHBoxLayout *ly_titlebar = new QHBoxLayout;
w_titlebar->setLayout(ly_titlebar);
// ly_titlebar->addWidget(ui->pushButton_return);
ly_titlebar->addStretch();
ly_titlebar->addSpacing(50);
ly_titlebar->addWidget(searchEdit);
ly_titlebar->addStretch();
- titlebar=ui->titlebar;
+ titlebar = ui->titlebar;
titlebar->setCustomWidget(w_titlebar);
// titlebar->setIcon(QIcon::fromTheme("spark-store"));
titlebar->setTitle(tr("Spark Store"));
@@ -177,42 +191,42 @@ void Widget::initUI()
// 添加菜单项
QAction *actionSubmission = new QAction(tr("Submit App"), this);
- QAction *setting=new QAction(tr("Settings"));
-
- QMenu *menu=new QMenu;
+ QAction *setting = new QAction(tr("Settings"));
+ QMenu *menu = new QMenu;
menu->addAction(setting);
menu->addAction(actionSubmission);
titlebar->setMenu(menu);
- connect(actionSubmission, &QAction::triggered, this, [ = ] () {
- QDesktopServices::openUrl(QUrl("https://upload.spark-app.store/"));
- });
+
+ connect(actionSubmission, &QAction::triggered, this, [=]{QDesktopServices::openUrl(QUrl("https://upload.spark-app.store/"));});
connect(setting, &QAction::triggered, this, &Widget::opensetting);
// 载入自定义字体
- int loadedFontID = QFontDatabase::addApplicationFont(":/fonts/fonts/华康少女字体.ttf");
+ int loadedFontID = QFontDatabase::addApplicationFont(":/fonts/fonts/hksnzt.ttf");
QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(loadedFontID);
if(!loadedFontFamilies.isEmpty())
+ {
font = loadedFontFamilies.at(0);
+ }
/* 全局字体设置
* DApplication::setFont(font);
*/
// 初始化菜单数组
- left_list[0]=ui->menu_main;
- left_list[1]=ui->menu_network;
- left_list[2]=ui->menu_chat;
- left_list[3]=ui->menu_music;
- left_list[4]=ui->menu_video;
- left_list[5]=ui->menu_photo;
- left_list[6]=ui->menu_game;
- left_list[7]=ui->menu_office;
- left_list[8]=ui->menu_read;
- left_list[9]=ui->menu_dev;
- left_list[10]=ui->menu_system;
- left_list[11]=ui->menu_theme;
- left_list[12]=ui->menu_other;
- left_list[13]=ui->menu_download;
+ left_list[0] = ui->menu_main;
+ left_list[1] = ui->menu_network;
+ left_list[2] = ui->menu_chat;
+ left_list[3] = ui->menu_music;
+ left_list[4] = ui->menu_video;
+ left_list[5] = ui->menu_photo;
+ left_list[6] = ui->menu_game;
+ left_list[7] = ui->menu_office;
+ left_list[8] = ui->menu_read;
+ left_list[9] = ui->menu_dev;
+ left_list[10] = ui->menu_system;
+ left_list[11] = ui->menu_theme;
+ left_list[12] = ui->menu_other;
+ left_list[13] = ui->menu_download;
ui->label_show->hide();
@@ -224,16 +238,30 @@ void Widget::initUI()
main->addWidget(spinner);
ui->applist_scrollAreaWidget->setLayout(main);
spinner->setFixedSize(80, 80);
+
+ // 初始化系统活动色和主题颜色
+ main_color = DGuiApplicationHelper::instance()->applicationPalette().highlight().color();
+ if(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType)
+ {
+ themeIsDark = true;
+ }
+ else
+ {
+ themeIsDark = false;
+ }
+ setTheme(themeIsDark, main_color);
}
void Widget::initConfig()
{
// 读取服务器列表并初始化
std::fstream serverList;
- serverList.open(QDir::homePath().toUtf8()+"/.config/spark-store/server.list",std::ios::in);
+ serverList.open(QDir::homePath().toUtf8() + "/.config/spark-store/server.list", std::ios::in);
std::string lineTmp;
- if(serverList){
- while (getline(serverList,lineTmp)) {
+ if(serverList)
+ {
+ while(getline(serverList, lineTmp))
+ {
ui->comboBox_server->addItem(QString::fromStdString(lineTmp));
}
for(int i = 0; i < ui->comboBox_server->count(); i++)
@@ -243,55 +271,64 @@ void Widget::initConfig()
ui->comboBox_server->model()->setData(ui->comboBox_server->model()->index(i, 0), QVariant(0), Qt::UserRole - 1);
}
}
- }else {
+ }
+ else
+ {
ui->comboBox_server->addItem("https://d.store.deepinos.org.cn/");
}
// 读取服务器URL并初始化菜单项的链接
- QSettings readConfig(QDir::homePath()+"/.config/spark-store/config.ini",QSettings::IniFormat);
- if(readConfig.value("server/choose").toString()!=""){
+ QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
+ if(!readConfig.value("server/choose").toString().isEmpty())
+ {
ui->comboBox_server->setCurrentText(readConfig.value("server/choose").toString());
- appinfoLoadThread.setServer(serverUrl=readConfig.value("server/choose").toString());
- }else {
- appinfoLoadThread.setServer(serverUrl="https://d.store.deenos.org.cn/"); // 默认URL
+ appinfoLoadThread.setServer(serverUrl = readConfig.value("server/choose").toString());
}
- configCanSave=true; // 防止触发保存配置信号
- menuUrl[0]=serverUrl + "store/#/";
- // menuUrl[0]="http://127.0.0.1:8000/#/darkprogramming";
- menuUrl[1]=serverUrl + "store/#/network";
- menuUrl[2]=serverUrl + "store/#/relations";
- menuUrl[3]=serverUrl + "store/#/musicandsound";
- menuUrl[4]=serverUrl + "store/#/videos";
- menuUrl[5]=serverUrl + "store/#/photos";
- menuUrl[6]=serverUrl + "store/#/games";
- menuUrl[7]=serverUrl + "store/#/office";
- menuUrl[8]=serverUrl + "store/#/reading";
- menuUrl[9]=serverUrl + "store/#/programming";
- menuUrl[10]=serverUrl + "store/#/tools";
- menuUrl[11]=serverUrl + "store/#/themes";
- menuUrl[12]=serverUrl + "store/#/others";
-
-
- //web控件初始化
- // ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); //用来激活接受linkClicked信号
- // ui->webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled,true);
+ else
+ {
+ appinfoLoadThread.setServer(serverUrl = "https://d.store.deenos.org.cn/"); // 默认URL
+ }
+ configCanSave = true; // 防止触发保存配置信号
+
+ // menuUrl[0] = "http://127.0.0.1:8000/#/darkprogramming";
+ menuUrl[0] = serverUrl + "store/#/";
+ menuUrl[1] = serverUrl + "store/#/network";
+ menuUrl[2] = serverUrl + "store/#/relations";
+ menuUrl[3] = serverUrl + "store/#/musicandsound";
+ menuUrl[4] = serverUrl + "store/#/videos";
+ menuUrl[5] = serverUrl + "store/#/photos";
+ menuUrl[6] = serverUrl + "store/#/games";
+ menuUrl[7] = serverUrl + "store/#/office";
+ menuUrl[8] = serverUrl + "store/#/reading";
+ menuUrl[9] = serverUrl + "store/#/programming";
+ menuUrl[10] = serverUrl + "store/#/tools";
+ menuUrl[11] = serverUrl + "store/#/themes";
+ menuUrl[12] = serverUrl + "store/#/others";
+
+ // web控件初始化
+ // ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); // 用来激活接受 linkClicked 信号
+ // ui->webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
ui->webfoot->hide();
- //初始化首页
- chooseLeftMenu(0);
+ // 初始化首页
// ui->webEngineView->setUrl(menuUrl[0]);
+ chooseLeftMenu(0);
- //给下载列表赋值到数组,方便调用
- for (int i =0; ilabel_aptserver->setText(aptserver.readAll());
- }else {
+ }
+ else
+ {
ui->label_aptserver->setText(tr("Not Exist"));
}
aptserver.close();
@@ -301,36 +338,44 @@ void Widget::initConfig()
dir.mkdir("spark-store");
}
-void Widget::setTheme(bool isDark,QColor color)
+void Widget::setTheme(bool isDark, QColor color)
{
// 菜单图标
- if(isDark){
+ if(isDark)
+ {
// 黑色模式
- themeIsDark=true;
- ui->webEngineView->setStyleSheet("background-color:#282828");
- ui->btn_openDir->setStyleSheet("color:#8B91A1;background-color:#2E2F30;border:0px");
- ui->webfoot->setStyleSheet("background-color:#252525");
- ui->label->setStyleSheet("background-color:#252525");
- // ui->scrollArea->setStyleSheet("background-color:#252525");
- ui->label_show->setStyleSheet("background-color:#252525");
+ themeIsDark = true;
+ ui->webEngineView->setStyleSheet("background-color: #252525;");
+ ui->webfoot->setStyleSheet("background-color: #252525;");
+ ui->btn_openDir->setStyleSheet("color: #AFAFAF; background-color: #2C2C2C; border: 0px;");
+ ui->label->setStyleSheet("background-color: #252525;");
+ // ui->scrollArea->setStyleSheet("background-color: #2C2C2C;");
+ ui->label_show->setStyleSheet("background-color: #2C2C2C;");
ui->pushButton_return->setIcon(DStyle().standardIcon(DStyle::SP_ArrowLeft));
ui->pushButton_refresh->setIcon(QIcon(":/icons/icons/refresh-page-dark.svg"));
- }else {
+ }
+ else
+ {
// 亮色模式
- themeIsDark=false;
- ui->webEngineView->setStyleSheet("background-color:#FFFFFF");
- ui->webfoot->setStyleSheet("background-color:#FFFFFF");
- ui->btn_openDir->setStyleSheet("color:#505050;background-color:#FBFBFB;border:0px");
- ui->label->setStyleSheet("background-color:#FFFFFF");
- // ui->scrollArea->setStyleSheet("background-color:#F8F8F8");
- ui->label_show->setStyleSheet("background-color:#F8F8F8");
+ themeIsDark = false;
+ ui->webEngineView->setStyleSheet("background-color: #FFFFFF;");
+ ui->webfoot->setStyleSheet("background-color: #FFFFFF;");
+ ui->btn_openDir->setStyleSheet("color: #505050; background-color: #F8F8F8; border: 0px;");
+ ui->label->setStyleSheet("background-color: #FFFFFF;");
+ // ui->scrollArea->setStyleSheet("background-color: #F8F8F8;");
+ ui->label_show->setStyleSheet("background-color: #F8F8F8;");
ui->pushButton_return->setIcon(DStyle().standardIcon(DStyle::SP_ArrowLeft));
ui->pushButton_refresh->setIcon(QIcon(":/icons/icons/refresh-page.svg"));
}
- main_color=color;
- m_loadweb->setTheme(themeIsDark,color);
+
+ // 刷新系统活动色
+ main_color = color;
+ m_loadweb->setTheme(themeIsDark, color);
updateUI();
- if(ui->stackedWidget->currentIndex()==0){
+
+ // 刷新网页主题颜色
+ if(ui->stackedWidget->currentIndex() == 0)
+ {
chooseLeftMenu(nowMenu);
}
}
@@ -350,7 +395,9 @@ void Widget::sendNotification(const QString &message, const int msTimeout, const
notify_notification_set_timeout(_notify, msTimeout);
}
else
+ {
notify_notification_update(_notify, tr("Spark\\ Store").toLocal8Bit(), message.toLocal8Bit(), icon.toLocal8Bit());
+ }
notify_notification_show(_notify, nullptr);
}
@@ -363,14 +410,17 @@ void Widget::sendNotification(const char *message, const int msTimeout, const QS
notify_notification_set_timeout(_notify, msTimeout);
}
else
+ {
notify_notification_update(_notify, tr("Spark\\ Store").toLocal8Bit(), message, icon.toLocal8Bit());
+ }
notify_notification_show(_notify, nullptr);
}
void Widget::updateUI()
{
- if(themeIsDark){
+ if(themeIsDark)
+ {
left_list[0]->setIcon(QIcon(":/icons/icons/homepage_dark.svg"));
left_list[1]->setIcon(QIcon(":/icons/icons/category_network_dark.svg"));
left_list[2]->setIcon(QIcon(":/icons/icons/category_chat_dark.svg"));
@@ -385,7 +435,9 @@ void Widget::updateUI()
left_list[11]->setIcon(QIcon(":/icons/icons/theme-symbolic_dark.svg"));
left_list[12]->setIcon(QIcon(":/icons/icons/category_others_dark.svg"));
left_list[13]->setIcon(QIcon(":/icons/icons/downloads-symbolic_dark.svg"));
- }else {
+ }
+ else
+ {
left_list[0]->setIcon(QIcon(":/icons/icons/homepage.svg"));
left_list[1]->setIcon(QIcon(":/icons/icons/category_network.svg"));
left_list[2]->setIcon(QIcon(":/icons/icons/category_chat.svg"));
@@ -401,8 +453,9 @@ void Widget::updateUI()
left_list[12]->setIcon(QIcon(":/icons/icons/category_others.svg"));
left_list[13]->setIcon(QIcon(":/icons/icons/downloads-symbolic.svg"));
}
- for (int i=0;i<14;i++) {
+ for(int i = 0; i < 14; i++)
+ {
/* 设置左侧菜单字体
* QFont temp = font;
* temp.setPixelSize(15);
@@ -410,25 +463,42 @@ void Widget::updateUI()
*/
left_list[i]->setFixedHeight(38);
- if(themeIsDark){
+ if(themeIsDark)
+ {
// 中文环境菜单文字居中,其他则左对齐
if(QLocale::system().name() == "zh_CN")
- left_list[i]->setStyleSheet("color:#FFFFFF;border:0px;");
+ {
+ left_list[i]->setStyleSheet("color: #FFFFFF; border: 0px;");
+ }
else
- left_list[i]->setStyleSheet("color:#FFFFFF;border:0px;text-align:left;padding-left:15px;");
- }else {
+ {
+ left_list[i]->setStyleSheet("color: #FFFFFF; border: 0px; text-align: left; padding-left: 15px;");
+ }
+ }
+ else
+ {
if(QLocale::system().name() == "zh_CN")
- left_list[i]->setStyleSheet("color:#252525;border:0px;");
+ {
+ left_list[i]->setStyleSheet("color: #252525; border: 0px;");
+ }
else
- left_list[i]->setStyleSheet("color:#252525;border:0px;text-align:left;padding-left:15px;");
+ {
+ left_list[i]->setStyleSheet("color: #252525; border: 0px; text-align: left; padding-left: 15px;");
+ }
}
}
if(QLocale::system().name() == "zh_CN")
- left_list[nowMenu]->setStyleSheet("color:#FFFFFF;background-color:"+main_color.name()+";border-radius:8;border:0px;");
+ {
+ left_list[nowMenu]->setStyleSheet("color: #FFFFFF; background-color: " + main_color.name() + "; border-radius: 8; border: 0px;");
+ }
else
- left_list[nowMenu]->setStyleSheet("color:#FFFFFF;background-color:"+main_color.name()+";border-radius:8;border:0px;text-align:left;padding-left:15px;");
- switch (nowMenu) {
+ {
+ left_list[nowMenu]->setStyleSheet("color: #FFFFFF; background-color: " + main_color.name() + "; border-radius: 8; border: 0px; text-align: left; padding-left: 15px;");
+ }
+
+ switch (nowMenu)
+ {
case 0:
left_list[0]->setIcon(QIcon(":/icons/icons/homepage_dark.svg"));
break;
@@ -477,91 +547,103 @@ void Widget::updateUI()
// 菜单切换逻辑
void Widget::chooseLeftMenu(int index)
{
- nowMenu=index;
+ nowMenu = index;
// 菜单切换时,清除搜索栏的内容
- if (!searchEdit->text().isEmpty()) {
+ if(!searchEdit->text().isEmpty())
+ {
searchEdit->clear();
}
updateUI();
- if(QLocale::system().name() == "zh_CN")
- left_list[index]->setStyleSheet("color:#FFFFFF;background-color:"+main_color.name()+";border-radius:8;border:0px;");
- else
- left_list[index]->setStyleSheet("color:#FFFFFF;background-color:"+main_color.name()+";border-radius:8;border:0px;text-align:left;padding-left:15px;");
- if(index<=12){
- if(themeIsDark){
- QString darkurl=menuUrl[index].toString();
- QStringList tmp=darkurl.split("/");
+
+ if(index <= 12)
+ {
+ if(themeIsDark)
+ {
+ QString darkurl = menuUrl[index].toString();
+ QStringList list = darkurl.split("/");
darkurl.clear();
- for (int i=0;iwebEngineView->setUrl(darkurl);
- qDebug()<webEngineView->setUrl(menuUrl[index]);
-
}
ui->stackedWidget->setCurrentIndex(0);
- }else if (index==13) {
+ }
+ else
+ {
ui->stackedWidget->setCurrentIndex(1);
}
-
}
void Widget::setfoot(int h)
{
- foot=h;
+ foot = h;
}
void Widget::updatefoot()
{
- int allh=ui->stackedWidget->height();
- ui->webfoot->setFixedHeight(allh-foot);
+ int allh = ui->stackedWidget->height();
+ ui->webfoot->setFixedHeight(allh - foot);
}
void Widget::on_pushButton_download_clicked()
{
chooseLeftMenu(13);
- allDownload+=1;
+
+ allDownload += 1;
+
QFileInfo info(url.path());
QString fileName(info.fileName()); // 获取文件名
- download_list[allDownload-1].pkgName=pkgName;
+ download_list[allDownload - 1].pkgName = pkgName;
if(fileName.isEmpty())
{
sendNotification(tr("Failed to get the name to the file to be downloaded."));
return;
}
- download_list[allDownload-1].setParent(ui->listWidget);
- QListWidgetItem *item=new QListWidgetItem(ui->listWidget);
- item->setSizeHint(download_list[allDownload-1].size());
+
+ download_list[allDownload - 1].setParent(ui->listWidget);
+ QListWidgetItem *item = new QListWidgetItem(ui->listWidget);
+ item->setSizeHint(download_list[allDownload - 1].size());
item->setFlags(item->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);
- ui->listWidget->setItemWidget(item,&download_list[allDownload-1]);
+ ui->listWidget->setItemWidget(item, &download_list[allDownload - 1]);
urList.append(url);
- download_list[allDownload-1].setName(appName);
- download_list[allDownload-1].setFileName(fileName);
+ download_list[allDownload - 1].setName(appName);
+ download_list[allDownload - 1].setFileName(fileName);
+
QPixmap icon;
icon.load("icon.png");
- system("cp icon.png icon_"+QString::number(allDownload-1).toUtf8()+".png");
- download_list[allDownload-1].seticon(icon);
- if(!isBusy){
-// file = new QFile(fileName);
-// if(!file->open(QIODevice::WriteOnly)){
-// delete file;
-// file = nullptr;
-// return ;
-// }
-
- nowDownload+=1;
-
- startRequest(urList.at(nowDownload-1), fileName); // 进行链接请求
+ system("cp icon.png icon_" + QString::number(allDownload - 1).toUtf8() + ".png");
+ download_list[allDownload - 1].seticon(icon);
+
+ if(!isBusy)
+ {
+ /*
+ file = new QFile(fileName);
+ if(!file->open(QIODevice::WriteOnly))
+ {
+ delete file;
+ file = nullptr;
+ return;
+ }
+ */
+
+ nowDownload += 1;
+ startRequest(urList.at(nowDownload - 1), fileName); // 进行链接请求
}
- if(ui->pushButton_download->text()==tr("Reinstall")){
- download_list[allDownload-1].reinstall=true;
+
+ if(ui->pushButton_download->text() == tr("Reinstall"))
+ {
+ download_list[allDownload - 1].reinstall = true;
}
}
@@ -569,55 +651,61 @@ void Widget::startRequest(QUrl url, QString fileName)
{
ui->listWidget->show();
ui->label->hide();
- isBusy=true;
- isdownload=true;
- download_list[allDownload-1].free=false;
+ isBusy = true;
+ isdownload = true;
+ download_list[allDownload - 1].free = false;
connect(downloadController, &DownloadController::downloadProcess, this, &Widget::updateDataReadProgress);
connect(downloadController, &DownloadController::downloadFinished, this, &Widget::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->startDownload(url.toString());
}
void Widget::searchApp(QString text)
{
- if(text.left(6)=="spk://"){
+ if(text.left(6) == "spk://")
+ {
openUrl(text);
searchEdit->clearEdit();
- } else {
+ }
+ else
+ {
// sendNotification(tr("Spark store could only process spk:// links for now. The search feature is coming soon!"));
- // ui->webView->setUrl(QUrl("http://www.baidu.com/s?wd="+text));//这东西对接百度
+ // ui->webView->setUrl(QUrl("http://www.baidu.com/s?wd="+text)); // 这东西对接百度
// ui->stackedWidget->setCurrentIndex(0);
// 禁止同时进行多次搜索
if(!mutex.tryLock())
+ {
return;
+ }
// 关键字搜索处理
httpClient->get("https://search.deepinos.org.cn/appinfo/search")
- .header("content-type", "application/json")
- .queryParam("keyword", text)
- .onResponse([this](QByteArray result) {
- auto json = QJsonDocument::fromJson(result).array();
- if (json.empty()) {
- qDebug() << "相关应用未找到!";
- sendNotification(tr("Relative apps Not Found!"));
- mutex.unlock();
- return;
- }
- displaySearchApp(json);
- })
- .onError([this](QString errorStr) {
- qDebug() << "请求出错:" << errorStr;
- sendNotification(QString(tr("Request Error: %1")).arg(errorStr));
+ .header("content-type", "application/json")
+ .queryParam("keyword", text)
+ .onResponse([this](QByteArray result)
+ {
+ auto json = QJsonDocument::fromJson(result).array();
+ if (json.empty())
+ {
+ qDebug() << "相关应用未找到!";
+ sendNotification(tr("Relative apps Not Found!"));
mutex.unlock();
return;
- })
- .timeout(10 * 1000)
- .exec();
+ }
+ displaySearchApp(json);
+ })
+ .onError([this](QString errorStr)
+ {
+ qDebug() << "请求出错:" << errorStr;
+ sendNotification(QString(tr("Request Error: %1")).arg(errorStr));
+ mutex.unlock();
+ return;
+ })
+ .timeout(10 * 1000)
+ .exec();
}
}
@@ -630,7 +718,8 @@ void Widget::displaySearchApp(QJsonArray array)
// 清除原有的搜索结果
QLayoutItem *item = nullptr;
- while ((item = applist_grid->takeAt(0)) != nullptr) {
+ while((item = applist_grid->takeAt(0)) != nullptr)
+ {
applist_grid->removeWidget(item->widget());
item->widget()->disconnect();
item->widget()->setParent(nullptr);
@@ -654,14 +743,11 @@ void Widget::displaySearchApp(QJsonArray array)
appItem->setUrl(url);
applist_grid->addWidget(appItem);
qDebug() << "应用链接为:" << url;
- connect(appItem, &AppItem::clicked, this, &Widget::openUrl);
- connect(appItem, &AppItem::clicked, this, [=]()
+ connect(appItem, &AppItem::clicked, this, &Widget::openUrl);
+ connect(appItem, &AppItem::clicked, this, [=](){prePage = ui->stackedWidget->currentIndex();});
+ connect(appItem, &AppItem::finished, this, [=]()
{
- prePage = ui->stackedWidget->currentIndex();
- });
-
- connect(appItem, &AppItem::finished, this, [=](){
count++;
downloadIconsFinished(array.size());
});
@@ -691,21 +777,27 @@ void Widget::httpReadyRead()
void Widget::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes)
{
- if(totalBytes <= 0) return;
- download_list[nowDownload-1].setMax(10000); // 最大值
- download_list[nowDownload-1].setValue((bytesRead*10000)/totalBytes); // 当前值
- download_size=bytesRead;
- if(download_list[nowDownload-1].close){ // 随时检测下载是否被取消
+ if(totalBytes <= 0)
+ {
+ return;
+ }
+
+ download_list[nowDownload - 1].setMax(10000); // 最大值
+ download_list[nowDownload - 1].setValue((bytesRead * 10000) / totalBytes); // 当前值
+ download_size = bytesRead;
+ if(download_list[nowDownload - 1].close)
+ {
+ // 随时检测下载是否被取消
downloadController->disconnect();
downloadController->stopDownload();
- download_list[nowDownload-1].closeDownload();
+ download_list[nowDownload - 1].closeDownload();
httpFinished();
}
}
void Widget::sltAppinfoResetUi()
{
- // 先隐藏详情页负责显示截图的label
+ // 先隐藏详情页负责显示截图的 label
ui->screen_0->hide();
ui->screen_1->hide();
ui->screen_2->hide();
@@ -721,7 +813,7 @@ void Widget::sltAppinfoResetUi()
ui->tag_dwine5->hide();
ui->tag_a2d->hide();
- // 重置UI状态
+ // 重置 UI 状态
ui->pushButton_uninstall->hide();
ui->pushButton_website->setEnabled(false);
ui->pushButton->setEnabled(false);
@@ -732,23 +824,40 @@ void Widget::sltAppinfoResetUi()
void Widget::sltAppinfoTags(QStringList *tagList)
{
- foreach (const QString &tag, *tagList) {
+ foreach(const QString &tag, *tagList)
+ {
if(tag=="community")
+ {
ui->tag_community->show();
+ }
else if(tag=="ubuntu")
+ {
ui->tag_ubuntu->show();
+ }
else if(tag=="deepin")
+ {
ui->tag_deepin->show();
+ }
else if(tag=="uos")
+ {
ui->tag_uos->show();
+ }
else if(tag=="dtk5")
+ {
ui->tag_dtk5->show();
+ }
else if(tag=="dwine2")
+ {
ui->tag_dwine2->show();
+ }
else if(tag=="dwine5")
+ {
ui->tag_dwine5->show();
+ }
else if(tag=="a2d")
+ {
ui->tag_a2d->show();
+ }
}
}
@@ -762,13 +871,18 @@ void Widget::sltAppinfoDetails(QString *name, QString *details, QString *info,
ui->label_info->show();
ui->label_more->setText(*info);
ui->label_more->show();
+
pkgName = *packageName;
url = *fileUrl;
appweb = *website;
- if(isInstalled){
+
+ if(isInstalled)
+ {
ui->pushButton_download->setText(tr("Reinstall"));
ui->pushButton_uninstall->show();
- }else {
+ }
+ else
+ {
ui->pushButton_download->setText(tr("Install"));
}
}
@@ -785,11 +899,15 @@ void Widget::sltAppinfoIcon(QPixmap *icon)
void Widget::sltAppinfoScreenshot(QPixmap *picture, int index)
{
- if(picture != nullptr) {
+ if(picture != nullptr)
+ {
screen[index] = *picture;
label_screen[index]->setImage(*picture);
label_screen[index]->show();
- switch(index) { // 故意为之,为了清除多余截图
+
+ switch(index)
+ {
+ // 故意为之,为了清除多余截图
case 0:
label_screen[1]->hide();
case 1:
@@ -804,22 +922,25 @@ void Widget::sltAppinfoScreenshot(QPixmap *picture, int index)
void Widget::sltAppinfoFinish()
{
- ui->label_show->setText("");
+ ui->label_show->clear();
ui->label_show->hide();
}
void Widget::httpFinished() // 完成下载
{
- isdownload=false;
- isBusy=false;
- download_list[nowDownload-1].readyInstall();
- download_list[nowDownload-1].free=true;
- if(nowDownloadstackedWidget->currentIndex() == 2) //如果在详情页面要重新触发UrlChanged
+ // 如果在详情页面要重新触发 UrlChanged
+ if(ui->stackedWidget->currentIndex() == 2)
+ {
emit ui->webEngineView->urlChanged(ui->webEngineView->url());
+ }
else
+ {
ui->webEngineView->reload();
+ }
}
void Widget::on_comboBox_server_currentIndexChanged(const QString &arg1)
{
- appinfoLoadThread.setServer(arg1); // 服务器信息更新
- if(configCanSave){
+ appinfoLoadThread.setServer(arg1); // 服务器信息更新
+
+ if(configCanSave)
+ {
ui->label_setting1->show();
- QSettings *setConfig=new QSettings(QDir::homePath()+"/.config/spark-store/config.ini",QSettings::IniFormat);
- setConfig->setValue("server/choose",arg1);
+ QSettings *setConfig = new QSettings(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
+ setConfig->setValue("server/choose", arg1);
}
}
void Widget::on_pushButton_updateServer_clicked()
{
- QtConcurrent::run([=](){
+ QtConcurrent::run([=]()
+ {
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.list");
+
+ 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.list");
std::fstream server;
- server.open(QDir::homePath().toUtf8()+"/.config/spark-store/server.list",std::ios::in);
+ server.open(QDir::homePath().toUtf8() + "/.config/spark-store/server.list", std::ios::in);
std::string lineTmp;
- if(server){
- while (getline(server,lineTmp)) {
+ if(server)
+ {
+ while(getline(server, lineTmp))
+ {
ui->comboBox_server->addItem(QString::fromStdString(lineTmp));
}
- }else {
+ }
+ else
+ {
ui->comboBox_server->addItem("https://d.store.deepinos.org.cn/");
}
+
ui->pushButton_updateServer->setEnabled(true);
ui->comboBox_server->setCurrentIndex(0);
@@ -914,7 +1049,8 @@ void Widget::on_pushButton_updateServer_clicked()
void Widget::on_pushButton_updateApt_clicked()
{
- QtConcurrent::run([=](){
+ QtConcurrent::run([=]()
+ {
ui->pushButton_updateApt->setEnabled(false);
ui->label_aptserver->setText(tr("Updating, please wait..."));
@@ -925,10 +1061,11 @@ void Widget::on_pushButton_updateApt_clicked()
tmpdir.mkpath("spark-store");
sourcesList.open(tmpPath + "/sparkstore.list", std::ios::out);
- //policy.open(tmpPath + "/sparkstore", std::ios::out);
- // 商店已经下架会替换系统库的包,优先级policy弃用
+ // 商店已经下架会替换系统库的包,优先级 policy 弃用
+ // policy.open(tmpPath + "/sparkstore", std::ios::out);
- if(sourcesList /*&& policy*/) {
+ if(sourcesList /*&& policy*/)
+ {
auto serverAddr = ui->comboBox_server->currentText();
sourcesList << "deb [by-hash=force] ";
@@ -937,22 +1074,24 @@ void Widget::on_pushButton_updateApt_clicked()
sourcesList.close();
/*
- policy << "Package: *\n"
- "Pin: origin *" << serverAddr.mid(serverAddr.indexOf('.')).toUtf8().toStdString() << "\n"
- "Pin-Priority: 90"; // 降低星火源的优先级,防止从星火安装已存在的系统包,破坏依赖
- policy.close();
+ * policy << "Package: *\n" << "Pin: origin *" <<
+ * serverAddr.mid(serverAddr.indexOf('.')).toUtf8().toStdString() << "\n" <<
+ * "Pin-Priority: 90"; // 降低星火源的优先级,防止从星火安装已存在的系统包,破坏依赖
+ * policy.close();
*/
- update.open(tmpPath + "/update.sh",std::ios::out);
- if(update) {
+ update.open(tmpPath + "/update.sh", std::ios::out);
+ if(update)
+ {
unknownError = false;
- update << "#!/bin/sh\n"
- "mv " + tmpPath + "/sparkstore.list /etc/apt/sources.list.d/sparkstore.list && "
- // "mv " + tmpPath + "/sparkstore /etc/apt/preferences.d/sparkstore && "
+ update << "#!/bin/sh\n" <<
+ "mv " + tmpPath + "/sparkstore.list /etc/apt/sources.list.d/sparkstore.list && " <<
+ // "mv " + tmpPath + "/sparkstore /etc/apt/preferences.d/sparkstore && " <<
"apt update";
update.close();
system(("chmod +x " + tmpPath + "/update.sh").c_str());
+
QProcess runupdate;
runupdate.start(QString::fromStdString("pkexec " + tmpPath + "/update.sh"));
runupdate.waitForFinished();
@@ -960,21 +1099,27 @@ void Widget::on_pushButton_updateApt_clicked()
QStringList everyError = error.split("\n");
bool haveError = false;
- for (int i=0; i < everyError.size(); i++) {
- if(everyError[i].left(2) == "E:") {
+ for(int i = 0; i < everyError.size(); i++)
+ {
+ if(everyError[i].left(2) == "E:")
+ {
haveError = true;
}
}
- if(!haveError) {
+ if(!haveError)
+ {
ui->label_aptserver->setText("deb [by-hash=force] " + ui->comboBox_server->currentText().toUtf8() + " /");
- } else {
+ }
+ else
+ {
ui->label_aptserver->setText(tr("Apt has reported an error. Please use apt update in terminal to locate the problem."));
}
}
}
- if(unknownError) {
+ if(unknownError)
+ {
ui->label_aptserver->setText(tr("Unknown error!"));
}
@@ -984,16 +1129,20 @@ void Widget::on_pushButton_updateApt_clicked()
void Widget::on_pushButton_uninstall_clicked()
{
- QtConcurrent::run([=](){
+ QtConcurrent::run([=]()
+ {
ui->pushButton_download->setEnabled(false);
ui->pushButton_uninstall->setEnabled(false);
+
QProcess uninstall;
- uninstall.start("pkexec apt purge -y "+pkgName.toLower());
+ uninstall.start("pkexec apt purge -y " + pkgName.toLower());
uninstall.waitForFinished();
+
ui->pushButton_download->setEnabled(true);
ui->pushButton_download->setText("Install");
ui->pushButton_uninstall->hide();
ui->pushButton_uninstall->setEnabled(true);
+
updatesEnabled();
sendNotification(tr("Uninstall succeeded"));
});
@@ -1001,14 +1150,18 @@ void Widget::on_pushButton_uninstall_clicked()
void Widget::on_pushButton_clear_clicked() // 清空临时缓存目录
{
- QtConcurrent::run([=](){
+ QtConcurrent::run([=]()
+ {
ui->pushButton_clear->setEnabled(false);
+
QDir tmpdir("/tmp/spark-store");
tmpdir.setFilter(QDir::Files);
- int quantity=int(tmpdir.count());
- for (int i=0;ipushButton_clear->setEnabled(true);
Widget::opensetting();
@@ -1019,16 +1172,16 @@ quint64 Widget::dirFileSize(const QString &path)
{
QDir dir(path);
quint64 size = 0;
- // dir.entryInfoList(QDir::Files)返回文件信息
+ // dir.entryInfoList(QDir::Files); // 返回文件信息
foreach(QFileInfo fileInfo, dir.entryInfoList(QDir::Files))
{
// 计算文件大小
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))
{
- // 若存在子目录,则递归调用dirFileSize()函数
+ // 若存在子目录,则递归调用 dirFileSize() 函数
size += dirFileSize(path + QDir::separator() + subDir);
}
return size;
@@ -1037,32 +1190,44 @@ quint64 Widget::dirFileSize(const QString &path)
void Widget::opensetting()
{
// 防止下载时文件被删除
- if(isdownload){
+ if(isdownload)
+ {
ui->pushButton_clear->setEnabled(false);
- }else {
+ }
+ else
+ {
ui->pushButton_clear->setEnabled(true);
}
+
// 显示缓存占用空间
- quint64 tmp_size=dirFileSize(QString::fromUtf8(TMP_PATH));
+ quint64 tmp_size = dirFileSize(QString::fromUtf8(TMP_PATH));
QString tmp_size_str;
- if(tmp_size<1024){
- tmp_size_str=QString::number(tmp_size)+"B";
- }else if (tmp_size<(1024*1024)) {
- tmp_size_str=QString::number(0.01*int(100*(tmp_size/1024)))+"KB";
- }else if (tmp_size<(1024*1024*1024)) {
- tmp_size_str=QString::number(0.01*int(100*(tmp_size/(1024*1024))))+"MB";
- }else {
- tmp_size_str=QString::number(0.01*int(100*(tmp_size/(1024*1024*1024))))+"GB";
+ if(tmp_size < 1024)
+ {
+ tmp_size_str = QString::number(tmp_size) + "B";
+ }
+ else if(tmp_size < (1024 * 1024))
+ {
+ tmp_size_str = QString::number(0.01 * int(100 * (tmp_size / 1024))) + "KB";
+ }
+ else if(tmp_size<(1024*1024*1024))
+ {
+ tmp_size_str = QString::number(0.01 * int(100 * (tmp_size / (1024 * 1024)))) + "MB";
}
+ else
+ {
+ tmp_size_str = QString::number(0.01 * int(100 * (tmp_size / (1024 * 1024 * 1024)))) + "GB";
+ }
+
ui->tmp_size_ui->setText(tmp_size_str);
prePage = ui->stackedWidget->currentIndex();
ui->stackedWidget->setCurrentIndex(3);
}
-void Widget::openUrl(QUrl u)
+void Widget::openUrl(QUrl url)
{
- QString app=serverUrl + "store"+u.path()+"/app.json";
-// ui->webEngineView->setUrl(app);
+ QString app = serverUrl + "store" + url.path() + "/app.json";
+ // ui->webEngineView->setUrl(app);
emit ui->webEngineView->urlChanged(app);
}
@@ -1074,9 +1239,10 @@ void Widget::on_pushButton_website_clicked()
void Widget::on_pushButton_clicked()
{
QString share_url;
- share_url="spk://store/"+type_name+"/"+pkgName;
- qDebug()<<"Share"<setText(share_url);
sendNotification(tr("The URL has been copied to the clipboard"));
}
@@ -1088,10 +1254,13 @@ void Widget::on_btn_openDir_clicked()
void Widget::on_stackedWidget_currentChanged(int arg1)
{
- qDebug()<pushButton_return->setEnabled(false);
- }else {
+ }
+ else
+ {
ui->pushButton_return->setEnabled(true);
}
}
@@ -1099,27 +1268,33 @@ void Widget::on_stackedWidget_currentChanged(int arg1)
void Widget::on_webEngineView_urlChanged(const QUrl &arg1)
{
//分析出服务器中的分类名称
- QStringList url_=arg1.path().split("/");
+ QStringList url_ = arg1.path().split("/");
QString pname;
- if(url_.size()>3){
- type_name=url_[2];
- pname=url_[3];
+ if(url_.size() > 3)
+ {
+ type_name = url_[2];
+ pname = url_[3];
}
//如果是app.json就打开详情页
- if(arg1.path().right(8)=="app.json"){
+ if(arg1.path().right(8) == "app.json")
+ {
prePage = ui->stackedWidget->currentIndex();
- load.cancel();//打开并发加载线程前关闭正在执行的线程
+
+ load.cancel(); // 打开并发加载线程前关闭正在执行的线程
m_loadweb->setValue(0);
- ui->label_more->setText("");//清空详情介绍
- ui->label_info->setText("");
- ui->label_appname->setText("");
+
+ ui->label_more->clear(); // 清空详情介绍
+ ui->label_info->clear();
+ ui->label_appname->clear();
ui->pushButton_download->setEnabled(false);
ui->stackedWidget->setCurrentIndex(2);
- qDebug()<<"https://demo-one-vert.vercel.app/"+type_name+"/"+pname;
- qDebug()<< "链接地址:" << arg1;
+ qDebug() << "https://demo-one-vert.vercel.app/" + type_name + "/" + pname;
+ qDebug() << "链接地址:" << arg1;
+
/*
- load.cancel();//打开并发加载线程前关闭正在执行的线程
- load = QtConcurrent::run([=](){
+ load.cancel(); // 打开并发加载线程前关闭正在执行的线程
+ load = QtConcurrent::run([=]()
+ {
int loadresult = loadappinfo(arg1);
});
*/
@@ -1141,20 +1316,23 @@ void Widget::on_webEngineView_loadStarted()
void Widget::on_webEngineView_loadProgress(int progress)
{
m_loadweb->setValue(progress);
- if(progress>=90){
+ if(progress >= 90)
+ {
m_loadweb->setValue(0);
}
}
void Widget::on_webEngineView_loadFinished(bool arg1)
{
- if(arg1){
+ if(arg1)
+ {
m_loadweb->setValue(0);
- }else {
+ }
+ else
+ {
m_loadweb->setValue(0);
m_loaderror->show();
}
-
}
void Widget::on_pushButton_translate_clicked()
@@ -1170,7 +1348,9 @@ void Widget::on_pushButton_translate_clicked()
"Tips:You can simply click the file to edit to create a flat pull request without create a full pull request\n"
"Tips:You can use github account to login to Gitee"
"\nClick yes to continue."));
+
if(!tipDialog.exec())
- QDesktopServices::openUrl("https://gitee.com/deepin-community-store/json/tree/master/store/" +
- type_name + '/' + pkgName);
+ {
+ QDesktopServices::openUrl("https://gitee.com/deepin-community-store/json/tree/master/store/" + type_name + '/' + pkgName);
+ }
}
diff --git a/src/widget.h b/src/widget.h
index c44355c03dd975b9b3793003d191b9fa1aeea341..42d8c3d0e8ac1a67ff5fc0e13f735d3ed7956b56 100644
--- a/src/widget.h
+++ b/src/widget.h
@@ -2,12 +2,10 @@
#define WIDGET_H
#include
-#include
-#include
#include
#include
#include
-#include
+
#include
#include
#include
@@ -18,45 +16,47 @@
#include
#include
-#include
#include
-#include
-#include
-#include
#include
#include
-#include
-#include "workerthreads.h"
+#include
+#include
+#include
+
#include "image_show.h"
+#include "downloadlist.h"
+#include "progressload.h"
+#include "workerthreads.h"
-#define LIST_MAX 99 //一次最多下载数量
+#define LIST_MAX 99 // 一次最多下载数量
#define TMP_PATH "/tmp/spark-store"
DWIDGET_USE_NAMESPACE
+
namespace Ui {
class Widget;
}
-
class FlowLayout;
class DownloadController;
namespace AeaQt {
- class HttpClient;
+class HttpClient;
}
class Widget : public DBlurEffectWidget
{
-
Q_OBJECT
+
public:
explicit Widget(DBlurEffectWidget *parent = nullptr);
~Widget();
+
void startRequest(QUrl url, QString fileName);
void searchApp(QString);
- int nowDownload=0;
- int allDownload=0;
- int isdownload=false;
+ int nowDownload = 0;
+ int allDownload = 0;
+ int isdownload = false;
void opensetting(); //打开设置页面
void openUrl(QUrl);
void setTheme(bool,QColor);
@@ -103,7 +103,6 @@ private slots:
void on_pushButton_translate_clicked();
public:
-
QUrl url;
downloadlist download_list[LIST_MAX];
@@ -134,15 +133,15 @@ private:
QPushButton * left_list[15];
QUrl menuUrl[13];
ProgressLoad *m_loadweb;
- QLabel *m_loaderror=new QLabel;
+ QLabel *m_loaderror = new QLabel;
QString serverUrl;
- bool configCanSave=false;
- bool isBusy=false;
- int nowMenu=0; //定位当前菜单
- int prePage=0; //定位前一个页面
- long download_size=0;
- long size1=0;
- long size2=0;
+ bool configCanSave = false;
+ bool isBusy = false;
+ int nowMenu = 0; // 定位当前菜单
+ int prePage = 0; // 定位前一个页面
+ long download_size = 0;
+ long size1 = 0;
+ long size2 = 0;
QPixmap screen[5];
QFuture load;
QFutureWatcher watchScreenshotLoad;
diff --git a/src/widget.ui b/src/widget.ui
index eecd7518d1a1ebf827aeaa77d1b8367226a0d903..a7004afb0b861129eccff3cc9a1079b300081fba 100644
--- a/src/widget.ui
+++ b/src/widget.ui
@@ -489,8 +489,8 @@
0
0
- 606
- 854
+ 582
+ 849
@@ -984,8 +984,8 @@
0
0
- 568
- 323
+ 98
+ 28
@@ -1114,8 +1114,8 @@
0
0
- 743
- 902
+ 738
+ 886
diff --git a/src/workerthreads.cpp b/src/workerthreads.cpp
index 5241363912c42913c50ca771cbcf129e8255a327..35299f7d2b0beba02a0f5f446fcbf5cae84843da 100644
--- a/src/workerthreads.cpp
+++ b/src/workerthreads.cpp
@@ -1,9 +1,10 @@
+#include "workerthreads.h"
#include
#include
#include
#include
-#include "workerthreads.h"
+
#include "widget.h"
#include "HttpClient.h"
@@ -14,112 +15,136 @@ void SpkAppInfoLoaderThread::run()
httpClient = new AeaQt::HttpClient;
httpClient->get(targetUrl.toString())
- .header("content-type", "application/json")
- .onResponse([this](QByteArray json_array) {
- qDebug() << "请求应用信息 " << json_array;
- QString urladdress, deatils, more, packagename, appweb;
- bool isInstalled;
-
- // 将路径转化为相应源的下载路径
- urladdress = targetUrl.toString().left(targetUrl.toString().length()-8);
- QStringList downloadurl=urladdress.split("/");
-
- QString deburl = serverUrl;
- deburl = deburl.left(urladdress.length()-1);
- urladdress = "https://img.jerrywang.top/"; // 使用图片专用服务器请保留这行,删除后将使用源服务器
- urladdress = urladdress.left(urladdress.length()-1);
-
- for (int i=3;ipushButton_website->show(); move to setinfo slot
- appweb=json["Website"].toString();
- }
- details+=tr("Contributor: ")+json["Contributor"].toString()+"\n";
- details+=tr("Update Time: ")+json["Update"].toString()+"\n";
- details+=tr("Installed Size: ")+json["Size"].toString()+"\n";
- more = json["More"].toString();
-
- QProcess isInstall;
- packagename = json["Pkgname"].toString();
- isInstall.start("dpkg -s "+json["Pkgname"].toString());
- isInstall.waitForFinished();
- int error=QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
- if(error==0)
- isInstalled = true;
- else
- isInstalled = false;
-
- emit requestSetAppInformation(&appName, &details, &more, &appweb, &packagename, &fileUrl, isInstalled);
-
- //tag加载
- QString tags=json["Tags"].toString();
- QStringList tagList=tags.split(";");
- emit requestSetTags(&tagList);
-
- // 图标加载
- httpClient->get(urladdress+"icon.png")
- .onResponse([this](QByteArray imgData){
- QPixmap appicon;
- appicon.loadFromData(imgData);
- emit finishedIconLoad(&appicon);
- })
- .onError([this](QString errorStr) {
- Widget::sendNotification(tr("Failed to load application icon."));
- })
- .block()
- .timeout(5 * 100)
- .exec();
-
-
- // 截图展示加载
- QPixmap screenshotCache[5];
- for (int i = 0; i < 5; i++) {
- httpClient->get(urladdress+"screen_"+QString::number(i+1)+".png")
- .onResponse([this, i, &screenshotCache](QByteArray imgData){
- bool s = screenshotCache[i].loadFromData(imgData);
- if(s){
- emit finishedScreenshotLoad(&screenshotCache[i], i);
- }else{
- emit finishedScreenshotLoad(nullptr, i);
- }
- })
- .onError([this](QString errorStr) {
- qDebug() << "截图下载失败";
-// Widget::sendNotification(tr("Failed to load application screenshot."));
- })
- .block()
- .timeout(4 * 100)
- .exec();
- }
- emit finishAllLoading();
+ .header("content-type", "application/json")
+ .onResponse([this](QByteArray json_array)
+ {
+ qDebug() << "请求应用信息 " << json_array;
+ QString urladdress, deatils, more, packagename, appweb;
+ bool isInstalled;
+
+ // 将路径转化为相应源的下载路径
+ urladdress = targetUrl.toString().left(targetUrl.toString().length() - 8);
+ QStringList downloadurl = urladdress.split("/");
+
+ QString deburl = serverUrl;
+ deburl = deburl.left(urladdress.length() - 1);
+ urladdress = "https://img.jerrywang.top/"; // 使用图片专用服务器请保留这行,删除后将使用源服务器
+ urladdress = urladdress.left(urladdress.length() - 1);
+
+ for(int i = 3; i < downloadurl.size(); i++)
+ {
+ urladdress += "/" + downloadurl[i];
+ deburl += "/" + downloadurl[i];
+ }
+
+ // 路径转化完成
+ QJsonObject json = QJsonDocument::fromJson(json_array).object();
+ QString appName = json["Name"].toString();
+ QUrl fileUrl = deburl + json["Filename"].toString();
+
+ // 软件信息加载
+ QString details;
+ details = tr("PkgName: ") + json["Pkgname"].toString() + "\n";
+ details += tr("Version: ") + json["Version"].toString() + "\n";
+ if(!json["Author"].toString().trimmed().isEmpty())
+ {
+ details += tr("Author: ") + json["Author"].toString() + "\n";
+ }
- httpClient->deleteLater();
+ if(!json["Website"].toString().trimmed().isEmpty())
+ {
+ details += tr("Official Site: ") + json["Website"].toString() + "\n";
+ // ui->pushButton_website->show(); // move to setinfo slot
+ appweb = json["Website"].toString();
+ }
+ details += tr("Contributor: ") + json["Contributor"].toString() + "\n";
+ details += tr("Update Time: ") + json["Update"].toString() + "\n";
+ details += tr("Installed Size: ") + json["Size"].toString() + "\n";
+ more = json["More"].toString();
+
+ QProcess isInstall;
+ packagename = json["Pkgname"].toString();
+ isInstall.start("dpkg -s " + json["Pkgname"].toString());
+ isInstall.waitForFinished();
+ int error = QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
+ if(error == 0)
+ {
+ isInstalled = true;
+ }
+ else
+ {
+ isInstalled = false;
+ }
+
+ emit requestSetAppInformation(&appName, &details, &more, &appweb, &packagename, &fileUrl, isInstalled);
+
+ // tag 加载
+ QString tags = json["Tags"].toString();
+ QStringList tagList = tags.split(";");
+ emit requestSetTags(&tagList);
+
+ // 图标加载
+ httpClient->get(urladdress+"icon.png")
+ .onResponse([this](QByteArray imgData)
+ {
+ QPixmap appicon;
+ appicon.loadFromData(imgData);
+ emit finishedIconLoad(&appicon);
})
- .onError([](QString errorStr) {
- Widget::sendNotification(tr("Failed to download app info. Please check internet connection."));
+ .onError([this](QString errorStr)
+ {
+ Q_UNUSED(this)
+ Q_UNUSED(errorStr)
+
+ Widget::sendNotification(tr("Failed to load application icon."));
})
- .timeout(5 * 100)
.block()
- .exec();
+ .timeout(5 * 100)
+ .exec();
+
+ // 截图展示加载
+ QPixmap screenshotCache[5];
+ for(int i = 0; i < 5; i++)
+ {
+ httpClient->get(urladdress + "screen_" + QString::number(i + 1) + ".png")
+ .onResponse([this, i, &screenshotCache](QByteArray imgData)
+ {
+ bool s = screenshotCache[i].loadFromData(imgData);
+ if(s)
+ {
+ emit finishedScreenshotLoad(&screenshotCache[i], i);
+ }
+ else
+ {
+ emit finishedScreenshotLoad(nullptr, i);
+ }
+ })
+ .onError([this](QString errorStr)
+ {
+ Q_UNUSED(this)
+ Q_UNUSED(errorStr)
+
+ qDebug() << "截图下载失败";
+ // Widget::sendNotification(tr("Failed to load application screenshot."));
+ })
+ .block()
+ .timeout(4 * 100)
+ .exec();
+ }
+ emit finishAllLoading();
+
+ httpClient->deleteLater();
+ })
+ .onError([](QString errorStr)
+ {
+ Q_UNUSED(errorStr)
+
+ Widget::sendNotification(tr("Failed to download app info. Please check internet connection."));
+ })
+ .timeout(5 * 100)
+ .block()
+ .exec();
}
@@ -135,8 +160,9 @@ void SpkAppInfoLoaderThread::setServer(const QString &server)
void SpkAppInfoLoaderThread::downloadFinished(int exitcode, QProcess::ExitStatus status)
{
- Q_UNUSED(exitcode);
- Q_UNUSED(status);
+ Q_UNUSED(exitcode)
+ Q_UNUSED(status)
+
qDebug() << "Finish one download";
finishedDownload = true;
}
@@ -146,7 +172,10 @@ int SpkAppInfoLoaderThread::waitDownload(QProcess& downloader)
while(!downloader.waitForFinished(100))
{
if(downloader.state() == QProcess::NotRunning)
+ {
return -1;
+ }
+
if(this->isInterruptionRequested())
{
downloader.terminate();
diff --git a/src/workerthreads.h b/src/workerthreads.h
index dc3535fa1cf3a6bc625240548a6e235529d29fba..d66d7485e3952752358a4e0772054bf2c18155c0 100644
--- a/src/workerthreads.h
+++ b/src/workerthreads.h
@@ -6,21 +6,35 @@
#include
#include
-
namespace AeaQt {
- class HttpClient;
+class HttpClient;
}
class SpkAppInfoLoaderThread Q_DECL_FINAL : public QThread
{
Q_OBJECT
+
public:
- //explicit SpkAppInfoLoaderThread() = default;
+ // explicit SpkAppInfoLoaderThread() = default;
+
+protected:
void run() Q_DECL_OVERRIDE;
+
+private:
+ QUrl targetUrl;
+ QString serverUrl;
+ bool finishedDownload = false;
+ int downloaderRetval = 0;
+
+ AeaQt::HttpClient *httpClient;
+
+ int waitDownload(QProcess& downloader);
+
public slots:
void setUrl(const QUrl &url);
void setServer(const QString &server);
void downloadFinished(int exitcode, QProcess::ExitStatus status);
+
signals:
void requestResetUi();
void requestSetTags(QStringList *tagList);
@@ -28,16 +42,9 @@ signals:
QString *website, QString *packageName,
QUrl *fileUrl, bool isInstalled);
void finishedIconLoad(QPixmap *icon);
- void finishedScreenshotLoad(QPixmap *icon, int index); // 该信号必须以BlockingQueued方式连接
- void finishAllLoading(); // 该信号必须以BlockingQueued方式连接
-private:
- int waitDownload(QProcess& downloader);
- QUrl targetUrl;
- QString serverUrl;
- bool finishedDownload = false;
- int downloaderRetval = 0;
+ void finishedScreenshotLoad(QPixmap *icon, int index); // 该信号必须以 BlockingQueued 方式连接
+ void finishAllLoading(); // 该信号必须以 BlockingQueued 方式连接
- AeaQt::HttpClient *httpClient;
};
#endif // WORKERTHREADS_H