mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-09-23 03:22:20 +08:00
将图片下载由 curl 转为 QtNetworkService
This commit is contained in:
parent
9cc68fac86
commit
815036e28f
169
src/widget.cpp
169
src/widget.cpp
@ -131,6 +131,7 @@ Widget::~Widget()
|
|||||||
{
|
{
|
||||||
notify_uninit();
|
notify_uninit();
|
||||||
|
|
||||||
|
// delete httpFinished;
|
||||||
delete ui;
|
delete ui;
|
||||||
qDebug()<<"exit";
|
qDebug()<<"exit";
|
||||||
DApplication::quit();
|
DApplication::quit();
|
||||||
@ -516,174 +517,6 @@ void Widget::updatefoot()
|
|||||||
ui->webfoot->setFixedHeight(allh-foot);
|
ui->webfoot->setFixedHeight(allh-foot);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Widget::loadappinfo(QUrl arg1)
|
|
||||||
{
|
|
||||||
if(arg1.isEmpty()){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 先隐藏详情页负责显示截图的label
|
|
||||||
ui->screen_0->hide();
|
|
||||||
ui->screen_1->hide();
|
|
||||||
ui->screen_2->hide();
|
|
||||||
ui->screen_3->hide();
|
|
||||||
ui->screen_4->hide();
|
|
||||||
ui->label_appicon->clear();
|
|
||||||
ui->tag_community->hide();
|
|
||||||
ui->tag_ubuntu->hide();
|
|
||||||
ui->tag_deepin->hide();
|
|
||||||
ui->tag_uos->hide();
|
|
||||||
ui->tag_dtk5->hide();
|
|
||||||
ui->tag_dwine2->hide();
|
|
||||||
ui->tag_dwine5->hide();
|
|
||||||
ui->tag_a2d->hide();
|
|
||||||
|
|
||||||
// 重置UI状态
|
|
||||||
ui->pushButton_uninstall->hide();
|
|
||||||
ui->pushButton_website->setEnabled(false);
|
|
||||||
ui->pushButton->setEnabled(false);
|
|
||||||
ui->pushButton_translate->setEnabled(false);
|
|
||||||
ui->label_show->setText("Loading...");
|
|
||||||
ui->label_show->show();
|
|
||||||
|
|
||||||
QProcess get_json;
|
|
||||||
QDir dir("/tmp");
|
|
||||||
dir.mkdir("spark-store");
|
|
||||||
QDir::setCurrent("/tmp/spark-store");
|
|
||||||
|
|
||||||
get_json.start("curl -o app.json "+arg1.toString());
|
|
||||||
get_json.waitForFinished();
|
|
||||||
if(get_json.exitCode())
|
|
||||||
{
|
|
||||||
sendNotification(tr("Failed to download app info. Please check internet connection."));
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile app_json("app.json");
|
|
||||||
if(app_json.open(QIODevice::ReadOnly)){
|
|
||||||
// 成功得到json文件
|
|
||||||
QByteArray json_array=app_json.readAll();
|
|
||||||
// 将路径转化为相应源的下载路径
|
|
||||||
urladdress=arg1.toString().left(arg1.toString().length()-8);
|
|
||||||
QStringList downloadurl=urladdress.split("/");
|
|
||||||
urladdress=ui->comboBox_server->currentText();
|
|
||||||
QString deburl=urladdress;
|
|
||||||
deburl=deburl.left(urladdress.length()-1);
|
|
||||||
urladdress="https://cdn.jsdelivr.net/gh/Jerrywang959/jsonpng@master/"; // 使用图片专用服务器请保留这行,删除后将使用源服务器
|
|
||||||
urladdress=urladdress.left(urladdress.length()-1);
|
|
||||||
|
|
||||||
for (int i=3;i<downloadurl.size();i++) {
|
|
||||||
urladdress+="/"+downloadurl[i];
|
|
||||||
deburl+="/"+downloadurl[i];
|
|
||||||
}
|
|
||||||
// 路径转化完成
|
|
||||||
QJsonObject json= QJsonDocument::fromJson(json_array).object();
|
|
||||||
appName = json["Name"].toString();
|
|
||||||
url=deburl + json["Filename"].toString();
|
|
||||||
qDebug()<<url;
|
|
||||||
ui->label_appname->setText(appName);
|
|
||||||
system("rm -r *.png");
|
|
||||||
ui->label_show->show();
|
|
||||||
// 软件信息加载
|
|
||||||
QString info;
|
|
||||||
info= tr("PkgName: ")+json["Pkgname"].toString()+"\n";
|
|
||||||
info+=tr("Version: ")+json["Version"].toString()+"\n";
|
|
||||||
if(json["Author"].toString()!="" && json["Author"].toString()!=" "){
|
|
||||||
info+=tr("Author: ")+json["Author"].toString()+"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(json["Website"].toString()!="" && json["Website"].toString()!=" "){
|
|
||||||
info+=tr("Official Site: ")+json["Website"].toString()+"\n";
|
|
||||||
ui->pushButton_website->show();
|
|
||||||
appweb=json["Website"].toString();
|
|
||||||
}
|
|
||||||
info+=tr("Contributor: ")+json["Contributor"].toString()+"\n";
|
|
||||||
info+=tr("Update Time: ")+json["Update"].toString()+"\n";
|
|
||||||
info+=tr("Installed Size: ")+json["Size"].toString()+"\n";
|
|
||||||
ui->label_info->setText(info);
|
|
||||||
ui->label_more->setText(json["More"].toString());
|
|
||||||
QProcess isInstall;
|
|
||||||
pkgName=json["Pkgname"].toString();
|
|
||||||
isInstall.start("dpkg -s "+json["Pkgname"].toString());
|
|
||||||
isInstall.waitForFinished();
|
|
||||||
int error=QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
|
|
||||||
if(error==0){
|
|
||||||
ui->pushButton_download->setText(tr("Reinstall"));
|
|
||||||
ui->pushButton_uninstall->show();
|
|
||||||
|
|
||||||
}else {
|
|
||||||
ui->pushButton_download->setText(tr("Install"));
|
|
||||||
}
|
|
||||||
//tag加载
|
|
||||||
QString tags=json["Tags"].toString();
|
|
||||||
QStringList tagList=tags.split(";");
|
|
||||||
for (int i=0;i<tagList.size();i++) {
|
|
||||||
if(tagList[i]=="community")
|
|
||||||
ui->tag_community->show();
|
|
||||||
if(tagList[i]=="ubuntu")
|
|
||||||
ui->tag_ubuntu->show();
|
|
||||||
if(tagList[i]=="deepin")
|
|
||||||
ui->tag_deepin->show();
|
|
||||||
if(tagList[i]=="uos")
|
|
||||||
ui->tag_uos->show();
|
|
||||||
if(tagList[i]=="dtk5")
|
|
||||||
ui->tag_dtk5->show();
|
|
||||||
if(tagList[i]=="dwine2")
|
|
||||||
ui->tag_dwine2->show();
|
|
||||||
if(tagList[i]=="dwine5")
|
|
||||||
ui->tag_dwine5->show();
|
|
||||||
if(tagList[i]=="a2d")
|
|
||||||
ui->tag_a2d->show();
|
|
||||||
}
|
|
||||||
// 图标加载
|
|
||||||
get_json.start("curl -o icon.png "+urladdress+"icon.png");
|
|
||||||
get_json.waitForFinished();
|
|
||||||
if(!get_json.exitCode()) {
|
|
||||||
QPixmap appicon(QString::fromUtf8(TMP_PATH)+"/icon.png");
|
|
||||||
ui->label_appicon->setPixmap(appicon);
|
|
||||||
ui->pushButton_download->setEnabled(true);
|
|
||||||
ui->pushButton->setEnabled(true);
|
|
||||||
ui->pushButton_translate->setEnabled(true);
|
|
||||||
ui->pushButton_website->setEnabled(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sendNotification(tr("Failed to load application icon."));
|
|
||||||
|
|
||||||
|
|
||||||
// 截图展示加载
|
|
||||||
QList<image_show*> label_screen;
|
|
||||||
label_screen << ui->screen_0 << ui->screen_1 << ui->screen_2 << ui->screen_3 << ui->screen_4;
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
QString cmd = "curl -o screen_"+QString::number(i+1)+".png "+urladdress+"screen_"+QString::number(i+1)+".png";
|
|
||||||
get_json.terminate();
|
|
||||||
get_json.start(cmd);
|
|
||||||
get_json.waitForFinished();
|
|
||||||
bool s = screen[i].load("screen_"+QString::number(i+1)+".png");
|
|
||||||
if(s){
|
|
||||||
label_screen[i]->setImage(screen[i]);
|
|
||||||
label_screen[i]->show();
|
|
||||||
/*
|
|
||||||
switch(i){ // 故意为之,为了清除多余截图
|
|
||||||
case 0:
|
|
||||||
label_screen[1]->hide();
|
|
||||||
case 1:
|
|
||||||
label_screen[2]->hide();
|
|
||||||
case 2:
|
|
||||||
label_screen[3]->hide();
|
|
||||||
case 3:
|
|
||||||
label_screen[4]->hide();
|
|
||||||
|
|
||||||
}*/
|
|
||||||
}else{
|
|
||||||
QFile::remove("screen_"+QString::number(i+1)+".png");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ui->label_show->setText("");
|
|
||||||
ui->label_show->hide();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Widget::on_pushButton_download_clicked()
|
void Widget::on_pushButton_download_clicked()
|
||||||
{
|
{
|
||||||
chooseLeftMenu(13);
|
chooseLeftMenu(13);
|
||||||
|
@ -123,7 +123,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
void initUI();
|
void initUI();
|
||||||
void initConfig();
|
void initConfig();
|
||||||
int loadappinfo(QUrl);
|
|
||||||
void chooseLeftMenu(int index);
|
void chooseLeftMenu(int index);
|
||||||
void setfoot(int);
|
void setfoot(int);
|
||||||
void updatefoot();
|
void updatefoot();
|
||||||
|
@ -5,115 +5,124 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include "workerthreads.h"
|
#include "workerthreads.h"
|
||||||
#include "widget.h"
|
#include "widget.h"
|
||||||
|
#include "HttpClient.h"
|
||||||
|
|
||||||
void SpkAppInfoLoaderThread::run()
|
void SpkAppInfoLoaderThread::run()
|
||||||
{
|
{
|
||||||
emit requestResetUi();
|
emit requestResetUi();
|
||||||
|
|
||||||
QProcess get_json;
|
httpClient = new AeaQt::HttpClient;
|
||||||
QString urladdress, deatils, more, packagename, appweb;
|
|
||||||
QDir dir("/tmp");
|
|
||||||
bool isInstalled;
|
|
||||||
dir.mkdir("spark-store");
|
|
||||||
QDir::setCurrent("/tmp/spark-store");
|
|
||||||
|
|
||||||
get_json.start("curl -o app.json " + targetUrl.toString());
|
httpClient->get(targetUrl.toString())
|
||||||
if(waitDownload(get_json) == -1)
|
.header("content-type", "application/json")
|
||||||
return;
|
.onResponse([this](QByteArray json_array) {
|
||||||
if(get_json.exitCode())
|
QString urladdress, deatils, more, packagename, appweb;
|
||||||
{
|
bool isInstalled;
|
||||||
Widget::sendNotification(tr("Failed to download app info. Please check internet connection."));
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile app_json("app.json");
|
// 将路径转化为相应源的下载路径
|
||||||
if(app_json.open(QIODevice::ReadOnly)){
|
urladdress = targetUrl.toString().left(targetUrl.toString().length()-8);
|
||||||
// 成功得到json文件
|
QStringList downloadurl=urladdress.split("/");
|
||||||
QByteArray json_array = app_json.readAll();
|
|
||||||
// 将路径转化为相应源的下载路径
|
|
||||||
urladdress = targetUrl.toString().left(targetUrl.toString().length()-8);
|
|
||||||
QStringList downloadurl=urladdress.split("/");
|
|
||||||
|
|
||||||
QString deburl = serverUrl;
|
QString deburl = serverUrl;
|
||||||
deburl = deburl.left(urladdress.length()-1);
|
deburl = deburl.left(urladdress.length()-1);
|
||||||
urladdress = "https://cdn.jsdelivr.net/gh/Jerrywang959/jsonpng@master/"; // 使用图片专用服务器请保留这行,删除后将使用源服务器
|
urladdress = "https://cdn.jsdelivr.net/gh/Jerrywang959/jsonpng@master/"; // 使用图片专用服务器请保留这行,删除后将使用源服务器
|
||||||
urladdress = urladdress.left(urladdress.length()-1);
|
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];
|
urladdress+="/"+downloadurl[i];
|
||||||
deburl+="/"+downloadurl[i];
|
deburl+="/"+downloadurl[i];
|
||||||
}
|
|
||||||
|
|
||||||
// 路径转化完成
|
|
||||||
QJsonObject json= QJsonDocument::fromJson(json_array).object();
|
|
||||||
QString appName = json["Name"].toString();
|
|
||||||
QUrl fileUrl = deburl + json["Filename"].toString();
|
|
||||||
|
|
||||||
// 软件信息加载
|
|
||||||
QString details;
|
|
||||||
details = tr("PkgName: ") + json["Pkgname"].toString()+"\n";
|
|
||||||
details += tr("Version: ") + json["Version"].toString()+"\n";
|
|
||||||
if(json["Author"].toString() != "" && json["Author"].toString() != " "){
|
|
||||||
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();
|
|
||||||
|
|
||||||
QProcess isInstall;
|
|
||||||
packagename = json["Pkgname"].toString();
|
|
||||||
isInstall.start("dpkg -s "+json["Pkgname"].toString());
|
|
||||||
isInstall.waitForFinished();
|
|
||||||
int error=QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
|
|
||||||
if(error==0)
|
|
||||||
isInstalled = true;
|
|
||||||
else
|
|
||||||
isInstalled = false;
|
|
||||||
|
|
||||||
emit requestSetAppInformation(&appName, &details, &more, &appweb, &packagename, &fileUrl, isInstalled);
|
|
||||||
|
|
||||||
//tag加载
|
|
||||||
QString tags=json["Tags"].toString();
|
|
||||||
QStringList tagList=tags.split(";");
|
|
||||||
emit requestSetTags(&tagList);
|
|
||||||
|
|
||||||
// 图标加载
|
|
||||||
get_json.start("curl -o icon.png "+urladdress+"icon.png");
|
|
||||||
if(waitDownload(get_json) == -1)
|
|
||||||
return;
|
|
||||||
if(!get_json.exitCode()) {
|
|
||||||
QPixmap appicon("icon.png");
|
|
||||||
emit finishedIconLoad(&appicon);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Widget::sendNotification(tr("Failed to load application icon."));
|
|
||||||
|
|
||||||
|
|
||||||
// 截图展示加载
|
|
||||||
QPixmap screenshotCache[5];
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
QString cmd = "curl -o screen_"+QString::number(i+1)+".png "+urladdress+"screen_"+QString::number(i+1)+".png";
|
|
||||||
get_json.start(cmd);
|
|
||||||
if(waitDownload(get_json) == -1)
|
|
||||||
return;
|
|
||||||
bool s = screenshotCache[i].load(QString(TMP_PATH) + "/screen_"+QString::number(i+1)+".png");
|
|
||||||
if(s){
|
|
||||||
emit finishedScreenshotLoad(&screenshotCache[i], i);
|
|
||||||
}else{
|
|
||||||
emit finishedScreenshotLoad(nullptr, i);
|
|
||||||
QFile::remove("screen_"+QString::number(i+1)+".png");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
emit finishAllLoading();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 路径转化完成
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
QProcess isInstall;
|
||||||
|
packagename = json["Pkgname"].toString();
|
||||||
|
isInstall.start("dpkg -s "+json["Pkgname"].toString());
|
||||||
|
isInstall.waitForFinished();
|
||||||
|
int error=QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
|
||||||
|
if(error==0)
|
||||||
|
isInstalled = true;
|
||||||
|
else
|
||||||
|
isInstalled = false;
|
||||||
|
|
||||||
|
emit requestSetAppInformation(&appName, &details, &more, &appweb, &packagename, &fileUrl, isInstalled);
|
||||||
|
|
||||||
|
//tag加载
|
||||||
|
QString tags=json["Tags"].toString();
|
||||||
|
QStringList tagList=tags.split(";");
|
||||||
|
emit requestSetTags(&tagList);
|
||||||
|
|
||||||
|
// 图标加载
|
||||||
|
httpClient->get(urladdress+"icon.png")
|
||||||
|
.onResponse([this](QByteArray imgData){
|
||||||
|
QPixmap appicon;
|
||||||
|
appicon.loadFromData(imgData);
|
||||||
|
emit finishedIconLoad(&appicon);
|
||||||
|
})
|
||||||
|
.onError([this](QString errorStr) {
|
||||||
|
Widget::sendNotification(tr("Failed to load application icon."));
|
||||||
|
})
|
||||||
|
.timeout(10 * 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."));
|
||||||
|
})
|
||||||
|
.timeout(10 * 100)
|
||||||
|
.exec();
|
||||||
|
}
|
||||||
|
emit finishAllLoading();
|
||||||
|
|
||||||
|
})
|
||||||
|
.onError([](QString errorStr) {
|
||||||
|
Widget::sendNotification(tr("Failed to download app info. Please check internet connection."));
|
||||||
|
})
|
||||||
|
.timeout(10 * 100)
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SpkAppInfoLoaderThread::~SpkAppInfoLoaderThread()
|
||||||
|
{
|
||||||
|
if (httpClient) {
|
||||||
|
httpClient->deleteLater();
|
||||||
|
httpClient = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpkAppInfoLoaderThread::setUrl(const QUrl &url)
|
void SpkAppInfoLoaderThread::setUrl(const QUrl &url)
|
||||||
|
@ -6,12 +6,18 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
|
|
||||||
|
namespace AeaQt {
|
||||||
|
class HttpClient;
|
||||||
|
}
|
||||||
|
|
||||||
class SpkAppInfoLoaderThread Q_DECL_FINAL : public QThread
|
class SpkAppInfoLoaderThread Q_DECL_FINAL : public QThread
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
//explicit SpkAppInfoLoaderThread() = default;
|
//explicit SpkAppInfoLoaderThread() = default;
|
||||||
void run() Q_DECL_OVERRIDE;
|
void run() Q_DECL_OVERRIDE;
|
||||||
|
~SpkAppInfoLoaderThread();
|
||||||
public slots:
|
public slots:
|
||||||
void setUrl(const QUrl &url);
|
void setUrl(const QUrl &url);
|
||||||
void setServer(const QString &server);
|
void setServer(const QString &server);
|
||||||
@ -31,6 +37,8 @@ private:
|
|||||||
QString serverUrl;
|
QString serverUrl;
|
||||||
bool finishedDownload = false;
|
bool finishedDownload = false;
|
||||||
int downloaderRetval = 0;
|
int downloaderRetval = 0;
|
||||||
|
|
||||||
|
AeaQt::HttpClient *httpClient;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WORKERTHREADS_H
|
#endif // WORKERTHREADS_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user