mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-13 20:32:05 +08:00
enhance: 微小的改进
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <QFile>
|
||||
|
||||
#include <DSysInfo>
|
||||
#include <QAtomicInt>
|
||||
|
||||
AppIntoPage::AppIntoPage(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
@@ -21,11 +22,15 @@ AppIntoPage::AppIntoPage(QWidget *parent)
|
||||
{
|
||||
initUI();
|
||||
initConnections();
|
||||
QString headers = "Mozilla/5.0 Spark-Store/"+ QString(APP_VERSION)+" (Linux; "+QSysInfo::prettyProductName().toUtf8()+";)";
|
||||
QByteArray ba = headers.toLatin1(); // must
|
||||
rawHeaders=ba.data();
|
||||
}
|
||||
|
||||
AppIntoPage::~AppIntoPage()
|
||||
{
|
||||
delete ui;
|
||||
free(rawHeaders);
|
||||
}
|
||||
|
||||
void AppIntoPage::openUrl(const QUrl &url)
|
||||
@@ -53,36 +58,41 @@ void AppIntoPage::openUrl(const QUrl &url)
|
||||
ui->label_2->setText(info["More"].toString());
|
||||
|
||||
// 显示 tags
|
||||
QStringList taglist = info["Tags"].toString().split(";", QString::SkipEmptyParts);
|
||||
QStringList taglist = info["Tags"].toString().split(";", Qt::SkipEmptyParts);
|
||||
setAppinfoTags(taglist);
|
||||
|
||||
// 获取图标
|
||||
QNetworkRequest request;
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||
// 获取图标和截图
|
||||
QString pkgUrlBase = api->getImgServerUrl() + SparkAPI::getArchDir() + url.path();
|
||||
qDebug() << "Icon URL: " << pkgUrlBase + "/icon.png";
|
||||
request.setUrl(QUrl(pkgUrlBase + "/icon.png"));
|
||||
request.setRawHeader("User-Agent", "Mozilla/5.0");
|
||||
request.setRawHeader("Content-Type", "charset='utf-8'");
|
||||
manager->get(request);
|
||||
QObject::connect(manager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply)
|
||||
{
|
||||
QByteArray jpegData = reply->readAll();
|
||||
iconpixmap.loadFromData(jpegData);
|
||||
iconpixmap.scaled(210, 200, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
ui->icon->setPixmap(iconpixmap);
|
||||
ui->icon->setScaledContents(true);
|
||||
// 创建网络请求管理器
|
||||
QNetworkAccessManager *iconManager = new QNetworkAccessManager(this);
|
||||
|
||||
// 获取图标
|
||||
QNetworkRequest iconRequest;
|
||||
iconRequest.setUrl(QUrl(pkgUrlBase + "/icon.png"));
|
||||
iconRequest.setRawHeader("User-Agent", rawHeaders);
|
||||
iconRequest.setRawHeader("Content-Type", "charset='utf-8'");
|
||||
|
||||
iconManager->get(iconRequest);
|
||||
QObject::connect(iconManager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply)
|
||||
{
|
||||
QByteArray jpegData = reply->readAll();
|
||||
iconpixmap.loadFromData(jpegData);
|
||||
iconpixmap = iconpixmap.scaled(210, 200, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
ui->icon->setPixmap(iconpixmap);
|
||||
ui->icon->setScaledContents(true);
|
||||
|
||||
iconManager->deleteLater();
|
||||
reply->deleteLater();
|
||||
});
|
||||
|
||||
manager->deleteLater(); });
|
||||
|
||||
// 获取截图
|
||||
for (int i = 0; i < 5 /* 魔法数字,最多五个截图 */; i++)
|
||||
{
|
||||
QString imgUrl = pkgUrlBase + "/screen_" + QString::number(i + 1) + ".png";
|
||||
QNetworkRequest request;
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||
request.setUrl(QUrl(imgUrl));
|
||||
request.setRawHeader("User-Agent", "Mozilla/5.0");
|
||||
request.setRawHeader("User-Agent", rawHeaders);
|
||||
request.setRawHeader("Content-Type", "charset='utf-8'");
|
||||
manager->get(request);
|
||||
QObject::connect(manager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply)
|
||||
@@ -105,6 +115,7 @@ void AppIntoPage::openUrl(const QUrl &url)
|
||||
manager->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Check UOS
|
||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||
|
||||
@@ -30,6 +30,8 @@ private:
|
||||
void isDownloading(const QUrl &url);
|
||||
void setAppinfoTags(const QStringList &tagList);
|
||||
void notifyUserUnsupportedTags(bool ubuntuSupport, bool deepinSupport, bool uosSupport);
|
||||
char* rawHeaders;
|
||||
QMap<int, QPixmap> imageMap;
|
||||
|
||||
signals:
|
||||
void clickedDownloadBtn();
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
#include "httprequest.h"
|
||||
|
||||
HttpRequest::HttpRequest()
|
||||
HttpRequest::HttpRequest(QObject *parent):QObject(parent)
|
||||
{
|
||||
QString headers = "Mozilla/5.0 Spark-Store/"+ QString(APP_VERSION)+" (Linux; "+QSysInfo::prettyProductName().toUtf8()+");";
|
||||
QByteArray ba = headers.toLatin1();
|
||||
rawHeaders = strdup(ba.data());
|
||||
}
|
||||
// 在析构函数中释放 rawHeaders 的内存
|
||||
HttpRequest::~HttpRequest()
|
||||
{
|
||||
free(rawHeaders);
|
||||
}
|
||||
|
||||
void HttpRequest::getRequest(QNetworkRequest request)
|
||||
{
|
||||
QNetworkAccessManager *naManager = new QNetworkAccessManager(this);
|
||||
|
||||
request.setRawHeader("User-Agent", "Mozilla/5.0");
|
||||
request.setRawHeader("User-Agent", rawHeaders);
|
||||
request.setRawHeader("Content-Type", "charset='utf-8'");
|
||||
request.setRawHeader("Content-Type", "application/json");
|
||||
|
||||
@@ -26,6 +33,7 @@ QString HttpRequest::postRequest(QString url, QString jsondata)
|
||||
QNetworkAccessManager *naManager = new QNetworkAccessManager(this);
|
||||
QUrl strUrl = url.replace("+", "%2B");
|
||||
request.setUrl(strUrl);
|
||||
request.setRawHeader("User-Agent", rawHeaders);
|
||||
request.setRawHeader("Content-Type", "charset='utf-8'");
|
||||
request.setRawHeader("Content-Type", "application/json");
|
||||
|
||||
|
||||
@@ -10,8 +10,11 @@
|
||||
class HttpRequest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
char* rawHeaders;
|
||||
public:
|
||||
HttpRequest();
|
||||
HttpRequest(QObject *parent = nullptr);
|
||||
~HttpRequest();
|
||||
|
||||
void getRequest(QNetworkRequest request);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user