mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 12:52:04 +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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user