mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-07-14 17:42:21 +08:00
Reorganize codes
Reorganize all parts of codes; Fix a bug that index page color is not correct when initialized.
This commit is contained in:
parent
6fd3c40e97
commit
e64e7fcae2
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,22 +1,30 @@
|
||||
#include "big_image.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QtConcurrent>
|
||||
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();
|
||||
|
@ -1,25 +1,27 @@
|
||||
#ifndef BIG_IMAGE_H
|
||||
#define BIG_IMAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <DBlurEffectWidget>
|
||||
#include <QMouseEvent>
|
||||
#include <QLabel>
|
||||
|
||||
#include <DBlurEffectWidget>
|
||||
|
||||
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;
|
||||
|
||||
QLabel *m_image;
|
||||
|
||||
void setimage(QPixmap);
|
||||
void focusOutEvent(QFocusEvent *event);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void focusOutEvent(QFocusEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // BIG_IMAGE_H
|
||||
|
@ -1,19 +1,27 @@
|
||||
#include "downloadlist.h"
|
||||
#include "ui_downloadlist.h"
|
||||
#include "widget.h"
|
||||
#include <QDebug>
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
|
||||
#include <QtConcurrent>
|
||||
#include <QProcess>
|
||||
#include <QTextBrowser>
|
||||
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());
|
||||
break;
|
||||
}
|
||||
}else {
|
||||
switch (t) {
|
||||
case 0:
|
||||
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());
|
||||
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;
|
||||
else
|
||||
{
|
||||
switch(t)
|
||||
{
|
||||
case 0:
|
||||
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());
|
||||
break;
|
||||
case 2:
|
||||
installer.start("pkexec gdebi -n /tmp/spark-store/" + ui->label_filename->text().toUtf8());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool haveError = false;
|
||||
bool notRoot = false;
|
||||
installer.waitForFinished();
|
||||
out=installer.readAllStandardOutput();
|
||||
QStringList everyOut=out.split("\n");
|
||||
for (int i=0;i<everyOut.size();i++) {
|
||||
if(everyOut[i].left(2)=="E:"){
|
||||
haveError=true;
|
||||
out = installer.readAllStandardOutput();
|
||||
|
||||
QStringList everyOut = out.split("\n");
|
||||
for(int i=0;i<everyOut.size();i++)
|
||||
{
|
||||
if(everyOut[i].left(2) == "E:")
|
||||
{
|
||||
haveError = true;
|
||||
}
|
||||
if(everyOut[i].right(14)=="Not authorized"){
|
||||
notRoot=true;
|
||||
if(everyOut[i].right(14) == "Not authorized")
|
||||
{
|
||||
notRoot = true;
|
||||
}
|
||||
}
|
||||
|
||||
QProcess isInstall;
|
||||
isInstall.start("dpkg -s "+pkgName);
|
||||
isInstall.start("dpkg -s " + pkgName);
|
||||
isInstall.waitForFinished();
|
||||
int error=QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
|
||||
if(error==0){
|
||||
int error = QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
|
||||
if(error == 0)
|
||||
{
|
||||
ui->pushButton_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()<<ui->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();
|
||||
}
|
||||
|
@ -2,11 +2,14 @@
|
||||
#define DOWNLOADLIST_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <DDialog>
|
||||
#include <QTextBrowser>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
#include <DDialog>
|
||||
|
||||
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
|
||||
|
@ -1,10 +1,9 @@
|
||||
#include "downloadworker.h"
|
||||
#include <QIODevice>
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
#include <QRegularExpression>
|
||||
#include <QFileInfo>
|
||||
@ -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<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&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<void(QNetworkReply::*)(QNetworkReply::NetworkError) > (&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() > 5 ? 5 : 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<qint64> 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<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
|
||||
[this, reply](QNetworkReply::NetworkError error){
|
||||
if (error != QNetworkReply::NoError) {
|
||||
connect(reply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError) > (&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;
|
||||
}
|
||||
|
||||
|
@ -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<qint64, qint64> 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<DownloadWorker*> workers;
|
||||
int finish = 0;
|
||||
QVector<QString> domains;
|
||||
|
||||
public slots:
|
||||
void handleProcess();
|
||||
void chunkDownloadFinish();
|
||||
|
||||
signals:
|
||||
void errorOccur(const QString& msg);
|
||||
void downloadProcess(qint64, qint64);
|
||||
void downloadFinished();
|
||||
|
||||
};
|
||||
|
||||
#endif // FILEDOWNLOADWORKER_H
|
||||
|
@ -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<QWidget *>(parent);
|
||||
return pw->style()->pixelMetric(pm, 0, pw);
|
||||
return pw->style()->pixelMetric(pm, nullptr, pw);
|
||||
} else {
|
||||
return static_cast<QLayout *>(parent)->spacing();
|
||||
}
|
||||
|
@ -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
|
||||
#endif // FLOWLAYOUT_H
|
||||
|
@ -1,17 +1,13 @@
|
||||
#include "image_show.h"
|
||||
|
||||
#include <QScreen> // Qt5 不再建议使用 QDesktopWidget
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QScreen> // Qt5 不再建议使用 QDesktopWidget
|
||||
#include <QGuiApplication>
|
||||
|
||||
#include <DDialog>
|
||||
#include <DBlurEffectWidget>
|
||||
#include <DWidgetUtil>
|
||||
#include <DApplication>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -3,30 +3,30 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMouseEvent>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <DDialog>
|
||||
#include <DBlurEffectWidget>
|
||||
#include <big_image.h>
|
||||
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;
|
||||
private:
|
||||
QLabel *m_label=new QLabel;
|
||||
QPixmap m_image;
|
||||
QLabel image;
|
||||
big_image *m_dialog=new big_image;
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void setImage(QPixmap);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
big_image *m_dialog;
|
||||
QLabel *m_label;
|
||||
QLabel image;
|
||||
QPixmap m_image;
|
||||
|
||||
};
|
||||
|
||||
#endif // IMAGE_SHOW_H
|
||||
|
@ -1,37 +1,42 @@
|
||||
#include "progressload.h"
|
||||
|
||||
ProgressLoad::ProgressLoad(QWidget *parent) : QWidget(parent)
|
||||
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));
|
||||
setAutoFillBackground(true);
|
||||
setPalette(plt);
|
||||
|
||||
}else {
|
||||
plt.setColor(QPalette::Background,QColor(255,255,255));
|
||||
if(dark)
|
||||
{
|
||||
plt.setColor(QPalette::Background, QColor(28,28,28));
|
||||
setAutoFillBackground(true);
|
||||
setPalette(plt);
|
||||
}
|
||||
m_progess->setStyleSheet("background-color:"+color.name());
|
||||
else
|
||||
{
|
||||
plt.setColor(QPalette::Background, QColor(255,255,255));
|
||||
setAutoFillBackground(true);
|
||||
setPalette(plt);
|
||||
}
|
||||
m_progess->setStyleSheet("background-color: " + color.name() + ";");
|
||||
}
|
||||
|
@ -4,21 +4,23 @@
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QPalette>
|
||||
|
||||
class ProgressLoad : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProgressLoad(QWidget *parent = nullptr);
|
||||
|
||||
void setValue(int v);
|
||||
void setTheme(bool dark,QColor color);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
private:
|
||||
QWidget *m_progess;
|
||||
int value;
|
||||
QTimer *timer;
|
||||
int value;
|
||||
QPalette plt;
|
||||
|
||||
};
|
||||
|
||||
#endif // PROGRESSLOAD_H
|
||||
|
@ -65,6 +65,24 @@ Widget::Widget(DBlurEffectWidget *parent) :
|
||||
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)
|
||||
{
|
||||
// 获取系统活动色
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
connect(&appinfoLoadThread, SIGNAL(requestResetUi()), this, SLOT(sltAppinfoResetUi()), Qt::ConnectionType::BlockingQueuedConnection);
|
||||
connect(&appinfoLoadThread, &SpkAppInfoLoaderThread::requestSetTags, this, &Widget::sltAppinfoTags, Qt::ConnectionType::BlockingQueuedConnection);
|
||||
connect(&appinfoLoadThread, &SpkAppInfoLoaderThread::requestSetAppInformation, this, &Widget::sltAppinfoDetails, Qt::ConnectionType::BlockingQueuedConnection);
|
||||
@ -85,24 +103,6 @@ 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();
|
||||
@ -236,6 +236,16 @@ void Widget::initUI()
|
||||
main->addWidget(spinner);
|
||||
ui->applist_scrollAreaWidget->setLayout(main);
|
||||
spinner->setFixedSize(80, 80);
|
||||
|
||||
// 初始化主题颜色
|
||||
if(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType)
|
||||
{
|
||||
themeIsDark = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
themeIsDark = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::initConfig()
|
||||
@ -296,17 +306,17 @@ void Widget::initConfig()
|
||||
// ui->webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled,true);
|
||||
ui->webfoot->hide();
|
||||
|
||||
//初始化首页
|
||||
// 初始化首页
|
||||
// ui->webEngineView->setUrl(menuUrl[0]);
|
||||
chooseLeftMenu(0);
|
||||
|
||||
//给下载列表赋值到数组,方便调用
|
||||
// 给下载列表赋值到数组,方便调用
|
||||
for(int i = 0; i < LIST_MAX; i++)
|
||||
{
|
||||
download_list[i].num = i;
|
||||
}
|
||||
|
||||
// 初始化apt源显示
|
||||
// 初始化 apt 源显示
|
||||
QFile aptserver("/etc/apt/sources.list.d/sparkstore.list");
|
||||
aptserver.open(QIODevice::ReadOnly);
|
||||
if(aptserver.isOpen())
|
||||
@ -543,17 +553,6 @@ void Widget::chooseLeftMenu(int index)
|
||||
|
||||
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)
|
||||
@ -810,7 +809,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);
|
||||
@ -919,7 +918,7 @@ void Widget::sltAppinfoScreenshot(QPixmap *picture, int index)
|
||||
|
||||
void Widget::sltAppinfoFinish()
|
||||
{
|
||||
ui->label_show->setText("");
|
||||
ui->label_show->clear();
|
||||
ui->label_show->hide();
|
||||
}
|
||||
|
||||
@ -1090,7 +1089,7 @@ void Widget::on_pushButton_updateApt_clicked()
|
||||
system(("chmod +x " + tmpPath + "/update.sh").c_str());
|
||||
|
||||
QProcess runupdate;
|
||||
runupdate.start(QString::fromStdString("pkexec " + tmpPath + "/update.sh"), QStringList());
|
||||
runupdate.start(QString::fromStdString("pkexec " + tmpPath + "/update.sh"));
|
||||
runupdate.waitForFinished();
|
||||
QString error = runupdate.readAllStandardError();
|
||||
|
||||
@ -1132,7 +1131,7 @@ void Widget::on_pushButton_uninstall_clicked()
|
||||
ui->pushButton_uninstall->setEnabled(false);
|
||||
|
||||
QProcess uninstall;
|
||||
uninstall.start("pkexec apt purge -y " + pkgName.toLower(), QStringList());
|
||||
uninstall.start("pkexec apt purge -y " + pkgName.toLower());
|
||||
uninstall.waitForFinished();
|
||||
|
||||
ui->pushButton_download->setEnabled(true);
|
||||
|
22
src/widget.h
22
src/widget.h
@ -54,9 +54,9 @@ public:
|
||||
|
||||
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);
|
||||
@ -133,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<void> load;
|
||||
QFutureWatcher<void> watchScreenshotLoad;
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include "workerthreads.h"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#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;
|
||||
.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("/");
|
||||
// 将路径转化为相应源的下载路径
|
||||
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);
|
||||
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];
|
||||
}
|
||||
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();
|
||||
// 路径转化完成
|
||||
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() != "" && json["Author"].toString() != " "){
|
||||
details += tr("Author: ") + json["Author"].toString() + "\n";
|
||||
}
|
||||
// 软件信息加载
|
||||
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";
|
||||
}
|
||||
|
||||
if(json["Website"].toString() != "" && json["Website"].toString() != " "){
|
||||
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();
|
||||
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;
|
||||
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);
|
||||
emit requestSetAppInformation(&appName, &details, &more, &appweb, &packagename, &fileUrl, isInstalled);
|
||||
|
||||
//tag加载
|
||||
QString tags=json["Tags"].toString();
|
||||
QStringList tagList=tags.split(";");
|
||||
emit requestSetTags(&tagList);
|
||||
// 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();
|
||||
|
||||
httpClient->deleteLater();
|
||||
// 图标加载
|
||||
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();
|
||||
|
@ -6,21 +6,35 @@
|
||||
#include <QUrl>
|
||||
#include <QProcess>
|
||||
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user