!22 合并 multiple 分支修复的 BUG

Merge pull request !22 from zty199/multiple
This commit is contained in:
忘记、过去 2021-06-13 14:36:48 +08:00 committed by Gitee
commit 0ab9f4dda6
21 changed files with 610 additions and 476 deletions

View File

@ -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

View File

@ -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,13 +81,16 @@ 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 {
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);
}

View File

@ -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

View File

@ -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); // 设置图片对话框总在最前
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();

View File

@ -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

View File

@ -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>
#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,8 +30,9 @@ 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);});
@ -31,13 +40,15 @@ downloadlist::downloadlist(QWidget *parent) :
// 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->progressBar->setValue(qint32(value));
ui->label_2->setText(QString::number(double(value) / 100) + "% (" + speed + ")");
if(ui->label_2->text().left(4)=="100%"){
if(ui->label_2->text().left(4) == "100%")
{
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,7 +87,8 @@ 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();
@ -83,10 +96,12 @@ void downloadlist::readyInstall()
"/tmp/spark-store/icon_" + QString::number(num).toUtf8() + ".png");
ui->label_2->setText(tr("Download FailedCheck 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();
@ -94,7 +109,6 @@ void downloadlist::readyInstall()
Widget::sendNotification(tr("Finished downloading %1, awaiting to install").arg(ui->label->text()), 5000,
"/tmp/spark-store/icon_" + QString::number(num).toUtf8() + ".png");
}
}
void downloadlist::setFileName(QString fileName)
@ -119,28 +133,21 @@ void downloadlist::setSpeed(QString s)
void downloadlist::install(int t)
{
if(!isInstall){
if(!isInstall)
{
isInstall = true;
ui->pushButton_install->hide();
ui->widget_spinner->show();
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) {
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;
}
}else {
switch (t) {
if(!reinstall)
{
switch(t)
{
case 0:
installer.start("pkexec ssinstall /tmp/spark-store/" + ui->label_filename->text().toUtf8());
break;
@ -152,41 +159,67 @@ void downloadlist::install(int t)
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());
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:"){
for(int i=0;i<everyOut.size();i++)
{
if(everyOut[i].left(2) == "E:")
{
haveError = true;
}
if(everyOut[i].right(14)=="Not authorized"){
if(everyOut[i].right(14) == "Not authorized")
{
notRoot = true;
}
}
QProcess isInstall;
isInstall.start("dpkg -s " + pkgName);
isInstall.waitForFinished();
int error = QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
if(error==0){
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 abortedyou can retry installation"));
ui->pushButton_install->show();
ui->pushButton_3->hide();
}
ui->widget_spinner->hide();
downloadlist::isInstall = false;
});
qDebug()<<ui->label_filename->text().toUtf8();
@ -210,12 +243,13 @@ void downloadlist::on_pushButton_2_clicked()
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();
}

View File

@ -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

View File

@ -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)
@ -39,14 +38,15 @@ void DownloadWorker::doWork()
QNetworkRequest request;
request.setUrl(url);
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
request.setRawHeader("Range", QString("bytes=%1-%2").arg(startPos)
.arg(endPos).toLocal8Bit());
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);
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) {
[this](QNetworkReply::NetworkError error)
{
if(error != QNetworkReply::NoError)
{
qDebug() << "出错了:" << reply->errorString();
}
});
@ -56,7 +56,6 @@ void DownloadWorker::doWork()
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",
@ -105,8 +105,10 @@ DownloadController::DownloadController(QObject *parent)
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,21 +132,22 @@ 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;
@ -157,18 +160,24 @@ void DownloadController::startDownload(const QString &url)
file->setFileName(tmpdir.absoluteFilePath(filename));
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();
}
@ -231,16 +245,20 @@ qint64 DownloadController::getFileSize(const QString& 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) {
[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())) {
&& 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;
}

View File

@ -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

View File

@ -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();
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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

View File

@ -1,10 +1,10 @@
#include <DApplication>
#include <DApplicationSettings>
#include <DWidgetUtil> // Dtk::Widget::moveToCenter(&w); 要调用它,就得引用 DWidgetUtil
#include <QDesktopWidget>
#include <widget.h>
#include <QTranslator>
#include <DAboutDialog>
#include "appitem.h"
#include <QScreen>
#include "widget.h"
DWIDGET_USE_NAMESPACE
int main(int argc, char *argv[])
@ -52,35 +52,48 @@ 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://"){
if(arg1.left(6)=="spk://")
{
w.openUrl(QUrl(argv[1]));
}
// 让打开时界面显示在正中
Dtk::Widget::moveToCenter(&w);

View File

@ -1,15 +1,20 @@
#include "progressload.h"
ProgressLoad::ProgressLoad(QWidget *parent) : QWidget(parent)
#include <DApplicationHelper>
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,[=](){
connect(timer, &QTimer::timeout, [=]()
{
m_progess->setFixedWidth(width() / 100 * value);
m_progess->setFixedHeight(height());
});
@ -23,15 +28,17 @@ void ProgressLoad::setValue(int v)
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 {
}
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() + ";");
}

View File

@ -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

View File

@ -44,8 +44,6 @@ Widget::Widget(DBlurEffectWidget *parent) :
initConfig();
manager = new QNetworkAccessManager(this); // 下载管理
m_loadweb=ui->progressload;
m_loadweb->show();
httpClient = new AeaQt::HttpClient;
downloadController = new DownloadController(this); // 并发下载
@ -65,6 +63,26 @@ 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)
{
// 获取系统活动色
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);
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();
@ -152,7 +152,7 @@ Widget::~Widget()
void Widget::initUI()
{
// ui初始化
setMaskAlpha(220);
setMaskAlpha(200);
ui->webfoot->setFixedHeight(0);
ui->stackedWidget->setCurrentIndex(0);
ui->listWidget->hide();
@ -160,7 +160,9 @@ 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;
@ -196,11 +198,11 @@ void Widget::initUI()
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())
{
@ -236,6 +238,18 @@ 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()
@ -331,12 +345,12 @@ void Widget::setTheme(bool isDark, QColor color)
{
// 黑色模式
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");
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"));
}
@ -344,12 +358,12 @@ void Widget::setTheme(bool isDark, QColor color)
{
// 亮色模式
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");
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"));
}
@ -359,7 +373,7 @@ void Widget::setTheme(bool isDark, QColor color)
m_loadweb->setTheme(themeIsDark, color);
updateUI();
// 刷新页主题颜色
// 刷新页主题颜色
if(ui->stackedWidget->currentIndex() == 0)
{
chooseLeftMenu(nowMenu);
@ -543,17 +557,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)
@ -919,7 +922,7 @@ void Widget::sltAppinfoScreenshot(QPixmap *picture, int index)
void Widget::sltAppinfoFinish()
{
ui->label_show->setText("");
ui->label_show->clear();
ui->label_show->hide();
}
@ -1132,7 +1135,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);

View File

@ -489,8 +489,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>606</width>
<height>854</height>
<width>582</width>
<height>849</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
@ -984,8 +984,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>568</width>
<height>323</height>
<width>98</width>
<height>28</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -1114,8 +1114,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>743</width>
<height>902</height>
<width>738</width>
<height>886</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">

View File

@ -1,9 +1,10 @@
#include "workerthreads.h"
#include <QProcess>
#include <QDir>
#include <QFile>
#include <QJsonDocument>
#include "workerthreads.h"
#include "widget.h"
#include "HttpClient.h"
@ -15,7 +16,8 @@ void SpkAppInfoLoaderThread::run()
httpClient->get(targetUrl.toString())
.header("content-type", "application/json")
.onResponse([this](QByteArray json_array) {
.onResponse([this](QByteArray json_array)
{
qDebug() << "请求应用信息 " << json_array;
QString urladdress, deatils, more, packagename, appweb;
bool isInstalled;
@ -29,7 +31,8 @@ void SpkAppInfoLoaderThread::run()
urladdress = "https://img.jerrywang.top/"; // 使用图片专用服务器请保留这行,删除后将使用源服务器
urladdress = urladdress.left(urladdress.length() - 1);
for (int i=3;i<downloadurl.size();i++) {
for(int i = 3; i < downloadurl.size(); i++)
{
urladdress += "/" + downloadurl[i];
deburl += "/" + downloadurl[i];
}
@ -43,13 +46,15 @@ void SpkAppInfoLoaderThread::run()
QString details;
details = tr("PkgName: ") + json["Pkgname"].toString() + "\n";
details += tr("Version: ") + json["Version"].toString() + "\n";
if(json["Author"].toString() != "" && json["Author"].toString() != " "){
if(!json["Author"].toString().trimmed().isEmpty())
{
details += tr("Author: ") + json["Author"].toString() + "\n";
}
if(json["Website"].toString() != "" && json["Website"].toString() != " "){
if(!json["Website"].toString().trimmed().isEmpty())
{
details += tr("Official Site: ") + json["Website"].toString() + "\n";
//ui->pushButton_website->show(); move to setinfo slot
// ui->pushButton_website->show(); // move to setinfo slot
appweb = json["Website"].toString();
}
details += tr("Contributor: ") + json["Contributor"].toString() + "\n";
@ -63,9 +68,13 @@ void SpkAppInfoLoaderThread::run()
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);
@ -76,12 +85,17 @@ void SpkAppInfoLoaderThread::run()
// 图标加载
httpClient->get(urladdress+"icon.png")
.onResponse([this](QByteArray imgData){
.onResponse([this](QByteArray imgData)
{
QPixmap appicon;
appicon.loadFromData(imgData);
emit finishedIconLoad(&appicon);
})
.onError([this](QString errorStr) {
.onError([this](QString errorStr)
{
Q_UNUSED(this)
Q_UNUSED(errorStr)
Widget::sendNotification(tr("Failed to load application icon."));
})
.block()
@ -91,17 +105,26 @@ void SpkAppInfoLoaderThread::run()
// 截图展示加载
QPixmap screenshotCache[5];
for (int i = 0; i < 5; i++) {
for(int i = 0; i < 5; i++)
{
httpClient->get(urladdress + "screen_" + QString::number(i + 1) + ".png")
.onResponse([this, i, &screenshotCache](QByteArray imgData){
.onResponse([this, i, &screenshotCache](QByteArray imgData)
{
bool s = screenshotCache[i].loadFromData(imgData);
if(s){
if(s)
{
emit finishedScreenshotLoad(&screenshotCache[i], i);
}else{
}
else
{
emit finishedScreenshotLoad(nullptr, i);
}
})
.onError([this](QString errorStr) {
.onError([this](QString errorStr)
{
Q_UNUSED(this)
Q_UNUSED(errorStr)
qDebug() << "截图下载失败";
// Widget::sendNotification(tr("Failed to load application screenshot."));
})
@ -113,13 +136,15 @@ void SpkAppInfoLoaderThread::run()
httpClient->deleteLater();
})
.onError([](QString errorStr) {
.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();

View File

@ -6,7 +6,6 @@
#include <QUrl>
#include <QProcess>
namespace AeaQt {
class HttpClient;
}
@ -14,13 +13,28 @@ namespace AeaQt {
class SpkAppInfoLoaderThread Q_DECL_FINAL : public QThread
{
Q_OBJECT
public:
// 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);
@ -30,14 +44,7 @@ signals:
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;
AeaQt::HttpClient *httpClient;
};
#endif // WORKERTHREADS_H