From 2ae6e8078572d05378ab2f6b6c05b0c33b2f27b4 Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Sun, 8 Nov 2020 20:41:18 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20QtNetworkService?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- spark-store.pro | 4 + third-party/QtNetworkService/HttpClient.cpp | 42 +++ third-party/QtNetworkService/HttpClient.h | 36 ++ third-party/QtNetworkService/HttpRequest.cpp | 268 ++++++++++++++ third-party/QtNetworkService/HttpRequest.h | 115 ++++++ third-party/QtNetworkService/HttpResponse.cpp | 331 ++++++++++++++++++ third-party/QtNetworkService/HttpResponse.h | 107 ++++++ third-party/QtNetworkService/LICENSE | 21 ++ .../QtNetworkService/QtNetworkService.pri | 15 + .../QtNetworkService/QtNetworkService.pro | 35 ++ third-party/QtNetworkService/README.md | 83 +++++ widget.cpp | 21 +- widget.h | 4 + 14 files changed, 1083 insertions(+), 2 deletions(-) create mode 100644 third-party/QtNetworkService/HttpClient.cpp create mode 100644 third-party/QtNetworkService/HttpClient.h create mode 100644 third-party/QtNetworkService/HttpRequest.cpp create mode 100644 third-party/QtNetworkService/HttpRequest.h create mode 100644 third-party/QtNetworkService/HttpResponse.cpp create mode 100644 third-party/QtNetworkService/HttpResponse.h create mode 100644 third-party/QtNetworkService/LICENSE create mode 100644 third-party/QtNetworkService/QtNetworkService.pri create mode 100644 third-party/QtNetworkService/QtNetworkService.pro create mode 100644 third-party/QtNetworkService/README.md diff --git a/.gitignore b/.gitignore index 18b01f03..6a5b5520 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ spark-store.pro.user* build/ -.vscode/ \ No newline at end of file +.vscode/ +Lib/ \ No newline at end of file diff --git a/spark-store.pro b/spark-store.pro index ebac092f..221fbfb3 100644 --- a/spark-store.pro +++ b/spark-store.pro @@ -66,3 +66,7 @@ DISTFILES += \ TRANSLATIONS = ./trans/spark-store_en.ts \ ./trans/spark-store_zh_CN.ts ./trans/spark-store_fr.ts\ + +DEFINES += QT_APP_DEBUG +include(./third-party/QtNetworkService/QtNetworkService.pri) + diff --git a/third-party/QtNetworkService/HttpClient.cpp b/third-party/QtNetworkService/HttpClient.cpp new file mode 100644 index 00000000..1a70b890 --- /dev/null +++ b/third-party/QtNetworkService/HttpClient.cpp @@ -0,0 +1,42 @@ +/********************************************************** +Author: Qt君 +微信公众号: Qt君(文章首发) +Website: qtbig.com(后续更新) +Email: 2088201923@qq.com +QQ交流群: 732271126 +LISCENSE: MIT +**********************************************************/ +#include "HttpClient.h" +#include +#include +#include + +using namespace AeaQt; + +HttpClient::HttpClient() +{ +} + +HttpClient::~HttpClient() +{ +} + +HttpRequest HttpClient::get(const QString &url) +{ + return HttpRequest(QNetworkAccessManager::GetOperation, this).url(url); +} + +HttpRequest HttpClient::post(const QString &url) +{ + return HttpRequest(QNetworkAccessManager::PostOperation, this).url(url); +} + +HttpRequest HttpClient::put(const QString &url) +{ + return HttpRequest(QNetworkAccessManager::PutOperation, this).url(url); +} + +HttpRequest HttpClient::send(const QString &url, QNetworkAccessManager::Operation op) +{ + return HttpRequest(op, this).url(url); +} diff --git a/third-party/QtNetworkService/HttpClient.h b/third-party/QtNetworkService/HttpClient.h new file mode 100644 index 00000000..1102a234 --- /dev/null +++ b/third-party/QtNetworkService/HttpClient.h @@ -0,0 +1,36 @@ +/********************************************************** +Author: Qt君 +微信公众号: Qt君(文章首发) +Website: qtbig.com(后续更新) +Email: 2088201923@qq.com +QQ交流群: 732271126 +LISCENSE: MIT +**********************************************************/ +#ifndef HTTP_CLIENT_H +#define HTTP_CLIENT_H + +#include "HttpRequest.h" +#include "HttpResponse.h" +#include +#include + +namespace AeaQt { + +class HttpClient : public QNetworkAccessManager +{ + Q_OBJECT +public: + friend class HttpRequest; + + HttpClient(); + ~HttpClient(); + + HttpRequest get(const QString &url); + HttpRequest post(const QString &url); + HttpRequest put(const QString &url); + + HttpRequest send(const QString &url, Operation op = GetOperation); +}; + +} +#endif diff --git a/third-party/QtNetworkService/HttpRequest.cpp b/third-party/QtNetworkService/HttpRequest.cpp new file mode 100644 index 00000000..8d44c118 --- /dev/null +++ b/third-party/QtNetworkService/HttpRequest.cpp @@ -0,0 +1,268 @@ +/********************************************************** +Author: Qt君 +微信公众号: Qt君(文章首发) +Website: qtbig.com(后续更新) +Email: 2088201923@qq.com +QQ交流群: 732271126 +LISCENSE: MIT +**********************************************************/ +#include "HttpRequest.h" +#include "HttpClient.h" + +#include +#include +#include +#include + +using namespace AeaQt; + +static const char *s_httpOperation[] = { + "UnknownOperation", + "HeadOperation", + "GetOperation", + "PutOperation", + "PostOperation", + "DeleteOperation", + "CustomOperation" +}; + +HttpRequest::HttpRequest() +{ + +} + +HttpRequest::~HttpRequest() +{ +} + +HttpRequest::HttpRequest(QNetworkAccessManager::Operation op, HttpClient *jsonHttpClient) : + m_body(QByteArray()), + m_op(op), + m_httpService(jsonHttpClient), + m_timeout(-1) +{ +} + +HttpRequest &HttpRequest::url(const QString &url) +{ + m_networkRequest.setUrl(QUrl(url)); + return *this; +} + +HttpRequest &HttpRequest::header(const QString &key, const QVariant &value) +{ + m_networkRequest.setRawHeader(QByteArray(key.toStdString().data()), QByteArray(value.toString().toStdString().data())); + + return *this; +} + +HttpRequest &HttpRequest::headers(const QMap &headers) +{ + QMapIterator iter(headers); + while (iter.hasNext()) { + iter.next(); + header(iter.key(), iter.value()); + } + + return *this; +} + +HttpRequest &HttpRequest::body(const QVariantMap &content) +{ + m_body = QJsonDocument(QJsonObject::fromVariantMap(content)).toJson(); + return *this; +} + +HttpRequest &HttpRequest::body(const QJsonObject &content) +{ + m_body = QJsonDocument(QJsonObject::fromVariantMap(content.toVariantMap())).toJson(); + return *this; +} + +HttpRequest &HttpRequest::body(const QByteArray &content) +{ + m_body = content; + return *this; +} + +#if 0 +HttpRequest &HttpRequest::body(const QVariant &body) +{ + /// clear m_jsonBody + m_jsonBody = QJsonObject(); + + if (type == X_Www_Form_Urlencoded) { + QUrl url; + QUrlQuery urlQuery(url); + + if (body.type() == QVariant::Map + || body.typeName() == QMetaType::typeName(QMetaType::QJsonObject)) { + + QMapIterator i(body.toMap()); + while (i.hasNext()) { + i.next(); + urlQuery.addQueryItem(i.key(), i.value().toString()); + } + + url.setQuery(urlQuery); + m_body = url.toString(QUrl::FullyEncoded).toUtf8().remove(0, 1); + } + else { + m_body = body.toByteArray(); + } + } + else if (type == Raw_Text_Json) { + if (body.type() == QVariant::Map + || body.typeName() == QMetaType::typeName(QMetaType::QJsonObject)) { + + m_body = QJsonDocument(QJsonObject::fromVariantMap(body.toMap())).toJson(); + } + else { + warning << "This is not data in JSON format(QVariantMap or QJsonObject)."; + m_body = QByteArray(); + // warning output + } + } + else { + m_body = QByteArray(); + warning << "Disable body."; + } + + debugger << "Body Content:" << m_body; + return *this; +} +#endif + +HttpRequest &HttpRequest::onResponse(const QObject *receiver, const char *slot, HttpResponse::SupportMethod type) +{ + m_slotsMap.insert(type, {slot, QVariant::fromValue((QObject *)receiver)}); + return *this; +} + +HttpRequest &HttpRequest::onResponse(std::function lambda) +{ + return onResponse(QVariant::fromValue(lambda)); +} + +HttpRequest &HttpRequest::onResponse(std::function lambda) +{ + return onResponse(QVariant::fromValue(lambda)); +} + +HttpRequest &HttpRequest::onResponse(std::function lambda) +{ + return onResponse(QVariant::fromValue(lambda)); +} + +HttpRequest &HttpRequest::onResponse(std::function lambda) +{ + return onResponse(QVariant::fromValue(lambda)); +} + +HttpRequest &HttpRequest::onError(const QObject *receiver, const char *slot) +{ + return onResponse(receiver, slot, HttpResponse::AutoInfer); +} + +HttpRequest &HttpRequest::onError(std::function lambda) +{ + return onResponse(QVariant::fromValue(lambda)); +} + +HttpRequest &HttpRequest::onError(std::function lambda) +{ + return onResponse(QVariant::fromValue(lambda)); +} + +HttpRequest &HttpRequest::onError(std::function lambda) +{ + return onResponse(QVariant::fromValue(lambda)); +} + +HttpRequest &HttpRequest::onError(std::function lambda) +{ + return onResponse(QVariant::fromValue(lambda)); +} + +HttpRequest &HttpRequest::timeout(const int &msec) +{ + m_timeout = msec; + return *this; +} + +HttpRequest &HttpRequest::block() +{ + m_isBlock = true; + return *this; +} + +HttpRequest &HttpRequest::onResponse(QVariant lambda) +{ + m_slotsMap.insert(HttpResponse::AutoInfer, {lambda.typeName(), lambda}); + + return *this; +} + +HttpResponse *HttpRequest::exec() +{ + QNetworkReply* reply = NULL; + QBuffer* sendBuffer = new QBuffer(); + if (! m_body.isEmpty()) { + sendBuffer->setData(m_body); + } + + debugger << "Http Client info: "; + debugger << "Type: " << s_httpOperation[m_op]; + debugger << "Url: " << m_networkRequest.url().toString(); + QString headers; + for (int i = 0; i < m_networkRequest.rawHeaderList().count(); i++) { + QString each = m_networkRequest.rawHeaderList().at(i); + QString header = m_networkRequest.rawHeader(each.toUtf8()); + headers += QString("%1: %2;").arg(each) + .arg(header); + } + debugger << "Header: " << headers; + debugger << "Send buffer(Body):\r\n" << m_body; + + reply = m_httpService->createRequest(m_op, m_networkRequest, sendBuffer); + + if (reply == NULL) { + sendBuffer->deleteLater(); + return NULL; + } + else { + sendBuffer->setParent(reply); + } + + return new HttpResponse(reply, m_slotsMap, m_timeout, m_isBlock); +} + +HttpRequest &HttpRequest::queryParam(const QString &key, const QVariant &value) +{ + QUrl url(m_networkRequest.url()); + QUrlQuery urlQuery(url); + + urlQuery.addQueryItem(key, value.toString()); + url.setQuery(urlQuery); + + m_networkRequest.setUrl(url); + + return *this; +} + +HttpRequest &HttpRequest::queryParams(const QMap ¶ms) +{ + QMapIterator iter(params); + while (iter.hasNext()) { + iter.next(); + queryParam(iter.key(), iter.value()); + } + + return *this; +} + +HttpRequest &HttpRequest::userAttribute(const QVariant &value) +{ + m_networkRequest.setAttribute(QNetworkRequest::User, value); + return *this; +} diff --git a/third-party/QtNetworkService/HttpRequest.h b/third-party/QtNetworkService/HttpRequest.h new file mode 100644 index 00000000..44672a17 --- /dev/null +++ b/third-party/QtNetworkService/HttpRequest.h @@ -0,0 +1,115 @@ +/********************************************************** +Author: Qt君 +微信公众号: Qt君(文章首发) +Website: qtbig.com(后续更新) +Email: 2088201923@qq.com +QQ交流群: 732271126 +LISCENSE: MIT +**********************************************************/ +#ifndef HTTP_REQUEST_H +#define HTTP_REQUEST_H + +#include "HttpResponse.h" + +#include +#include +#include +#include + +namespace AeaQt { + +#ifdef QT_APP_DEBUG +#define debugger qDebug().noquote().nospace() \ + << "[AeaQt::Network] Debug: -> " \ + << "function: " << __func__ << "; " \ + << "line: " << __LINE__ << "; " +#else +#define debug QString() +#endif + +#define warning qWarning().noquote().nospace() \ + << "[AeaQt::Network] Warning: -> " \ + << "function: " << __func__ << "; " \ + << "line: " << __LINE__ << "; " + +class HttpClient; + +class HttpRequest +{ +public: + enum BodyType { + None = 0, // This request does not have a body. + X_Www_Form_Urlencoded, // x-www-form-urlencoded + Raw_Text_Json, // application/json + }; + + explicit HttpRequest(QNetworkAccessManager::Operation op, HttpClient *jsonHttpClient); + virtual ~HttpRequest(); + + HttpRequest &url(const QString &url); + HttpRequest &header(const QString &key, const QVariant &value); + HttpRequest &headers(const QMap &headers); + + HttpRequest &queryParam(const QString &key, const QVariant &value); + HttpRequest &queryParams(const QMap ¶ms); + + /* Mainly used for identification */ + HttpRequest &userAttribute(const QVariant &value); + + HttpRequest &body(const QVariantMap &content); + HttpRequest &body(const QJsonObject &content); + HttpRequest &body(const QByteArray &content); + + /* + * @onRespone slot support type: void function(QVariantMap resultMap) OR + * void function(QByteArray resultData) OR + * void function(QNetworkReply* reply) + * note: The same type is only triggered once + */ + HttpRequest &onResponse(const QObject *receiver, const char *slot, HttpResponse::SupportMethod type = HttpResponse::AutoInfer); + HttpRequest &onResponse(std::function lambda); + HttpRequest &onResponse(std::function lambda); + HttpRequest &onResponse(std::function lambda); + HttpRequest &onResponse(std::function lambda); + /* + * @onError slot support type: void function(QNetworkReply::NetworkError error) + * void function(QString errorString); + * void function(QNetworkReply::NetworkError error, QNetworkReply* reply); + * void function(QString errorString, QNetworkReply* reply); + * note: The same type is only triggered once + */ + HttpRequest &onError(const QObject *receiver, const char *slot); + HttpRequest &onError(std::function lambda); + HttpRequest &onError(std::function lambda); + HttpRequest &onError(std::function lambda); + HttpRequest &onError(std::function lambda); + + /** + * @brief msec <= 0, disable timeout + * msec > 0, enable timeout + */ + HttpRequest &timeout(const int &msec = -1); + + /** + * @brief Block current thread, entering an event loop. + */ + HttpRequest &block(); + + HttpResponse *exec(); + +private: + HttpRequest(); + HttpRequest &onResponse(QVariant lambda); + +private: + QNetworkRequest m_networkRequest; + QByteArray m_body; + QNetworkAccessManager::Operation m_op; + HttpClient *m_httpService; + int m_timeout; + bool m_isBlock; + QMultiMap> m_slotsMap; +}; + +} +#endif // HTTP_REQUEST_H diff --git a/third-party/QtNetworkService/HttpResponse.cpp b/third-party/QtNetworkService/HttpResponse.cpp new file mode 100644 index 00000000..7c54915b --- /dev/null +++ b/third-party/QtNetworkService/HttpResponse.cpp @@ -0,0 +1,331 @@ +/********************************************************** +Author: Qt君 +微信公众号: Qt君(文章首发) +Website: qtbig.com(后续更新) +Email: 2088201923@qq.com +QQ交流群: 732271126 +LISCENSE: MIT +**********************************************************/ +#include "HttpResponse.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#define T2S(t) (QString(#t).remove(QRegExp("\\s"))) //type to string + +#define _exec(target, type, arg) \ + if (target.canConvert >()) { \ + std::function func = target.value >(); func(arg); \ + } \ + else + +#define _exec2(target, type1, type2, arg1, arg2) \ + if (target.canConvert >()) { \ + std::function func = target.value >(); func(arg1, arg2); \ + } else + +using namespace AeaQt; + +static const QMap> methodParams = +{ + { + HttpResponse::onResponse_QNetworkReply_A_Pointer, + { + {"types", QStringList({T2S(QNetworkReply*)})}, + {"lambda", T2S(std::function)}, + {"signal", SIGNAL(finished(QNetworkReply*))}, + {"isAutoInfer", true} + } + }, + { + HttpResponse::onResponse_QByteArray, + { + {"types", QStringList({T2S(QByteArray)})}, + {"lambda", T2S(std::function)}, + {"signal", SIGNAL(finished(QByteArray))}, + {"isAutoInfer", true} + } + }, + { + HttpResponse::onResponse_QVariantMap, + { + {"types", QStringList({T2S(QVariantMap)})}, + {"lambda", T2S(std::function)}, + {"signal", SIGNAL(finished(QVariantMap))}, + {"isAutoInfer", true} + } + }, + { + HttpResponse::onDownloadProgress_qint64_qint64, + { + {"types", QStringList({T2S(qint64), T2S(qint64)})}, + {"lambda", T2S(std::function)}, + {"signal", SIGNAL(downloadProgress(qint64, qint64))}, + {"isAutoInfer", true} + } + }, + { + HttpResponse::onError_QNetworkReply_To_NetworkError, + { + {"types", QStringList({T2S(QNetworkReply::NetworkError)})}, + {"lambda", T2S(std::function)}, + {"signal", SIGNAL(error(QNetworkReply::NetworkError))}, + {"isAutoInfer", true} + } + }, + { + HttpResponse::onError_QString, + { + {"types", QStringList({T2S(QString)})}, + {"lambda", T2S(std::function)}, + {"signal", SIGNAL(error(QString))}, + {"isAutoInfer", true} + } + }, + { + HttpResponse::onError_QNetworkReply_To_NetworkError_QNetworkReply_A_Pointer, + { + {"types", QStringList({T2S(QNetworkReply::NetworkError), T2S(QNetworkReply*)})}, + {"lambda", T2S(std::function)}, + {"signal", SIGNAL(error(QNetworkReply::NetworkError, QNetworkReply*))}, + {"isAutoInfer", true} + } + }, + { + HttpResponse::onError_QString_QNetworkReply_A_Poniter, + { + {"types", QStringList({T2S(QString), T2S(QNetworkReply*)})}, + {"lambda", T2S(std::function)}, + {"signal", SIGNAL(error(QString, QNetworkReply*))}, + {"isAutoInfer", true} + } + }, +}; + +static int extractCode(const char *member) +{ + /* extract code, ensure QMETHOD_CODE <= code <= QSIGNAL_CODE */ + return (((int)(*member) - '0') & 0x3); +} + +HttpResponse::HttpResponse(QNetworkReply *networkReply, + const QMultiMap > &slotsMap, + const int &timeout, + bool isBlock) + : m_networkReply(networkReply), + m_slotsMap(slotsMap), + QObject(networkReply) +{ + slotsMapOperation(m_slotsMap); + new HttpResponseTimeout(networkReply, timeout); + + connect(m_networkReply, SIGNAL(finished()), this, SLOT(onFinished())); + connect(m_networkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError))); + connect(m_networkReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(onDownloadProgress(qint64, qint64))); + + if (isBlock) { + QEventLoop loop; + QObject::connect(m_networkReply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); + } +} + +HttpResponse::~HttpResponse() +{ +} + +QNetworkReply *HttpResponse::networkReply() +{ + return m_networkReply; +} + +void HttpResponse::onFinished() +{ + QNetworkReply *reply = m_networkReply; + if (reply->error() != QNetworkReply::NoError) + return; + + if (m_slotsMap.contains(onResponse_QNetworkReply_A_Pointer)) { + _exec(m_slotsMap.value(onResponse_QNetworkReply_A_Pointer).second, QNetworkReply*, reply) { + emit finished(reply); + } + } + else if (m_slotsMap.contains((onResponse_QByteArray))) { + QByteArray result = reply->readAll(); + + _exec(m_slotsMap.value((onResponse_QByteArray)).second, QByteArray, result) { + emit finished(result); + } + + reply->deleteLater(); + } + else if (m_slotsMap.contains((onResponse_QVariantMap))) { + QByteArray result = reply->readAll(); + QVariantMap resultMap = QJsonDocument::fromJson(result).object().toVariantMap(); + + _exec(m_slotsMap.value((onResponse_QVariantMap)).second, QVariantMap, resultMap){ + emit finished(resultMap); + } + + reply->deleteLater(); + } +} + +void HttpResponse::onError(QNetworkReply::NetworkError error) +{ + QNetworkReply *reply = m_networkReply; + const QMetaObject & metaObject = QNetworkReply::staticMetaObject; + QMetaEnum metaEnum = metaObject.enumerator(metaObject.indexOfEnumerator("NetworkError")); + QString errorString = reply->errorString().isEmpty() ? metaEnum.valueToKey(error) : reply->errorString(); + + if (m_slotsMap.contains((onError_QString_QNetworkReply_A_Poniter))) { + _exec2(m_slotsMap.value((onError_QString_QNetworkReply_A_Poniter)).second, QString, QNetworkReply*, errorString, reply) { + emit this->error(errorString, reply); + } + } + else if (m_slotsMap.contains((onError_QNetworkReply_To_NetworkError_QNetworkReply_A_Pointer))) { + _exec2(m_slotsMap.value((onError_QNetworkReply_To_NetworkError_QNetworkReply_A_Pointer)).second, + QNetworkReply::NetworkError, QNetworkReply*, + error, reply) { + emit this->error(error, reply); + } + } + else if (m_slotsMap.contains((onError_QString))) { + _exec(m_slotsMap.value((onError_QString)).second, QString, errorString) { + emit this->error(errorString); + } + + reply->deleteLater(); + } + else if (m_slotsMap.contains((onError_QNetworkReply_To_NetworkError))) { + _exec(m_slotsMap.value((onError_QNetworkReply_To_NetworkError)).second, QNetworkReply::NetworkError, error) { + emit this->error(error); + } + + reply->deleteLater(); + } +} + +void HttpResponse::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) +{ + if (m_slotsMap.contains((onDownloadProgress_qint64_qint64))) { + _exec2(m_slotsMap.value((onDownloadProgress_qint64_qint64)).second, qint64, qint64, bytesReceived, bytesTotal) { + emit downloadProgress(bytesReceived, bytesTotal); + } + } +} + +static void extractSlot(const QString &respReceiverSlot, QString &extractSlot, QStringList &extractSlotTypes) +{ + QString slot(respReceiverSlot); + if (extractCode(respReceiverSlot.toStdString().data()) == QSLOT_CODE && !slot.isEmpty()) { + slot.remove(0, 1); + + QString unconvertedSlotType = slot; + int startIndex = slot.indexOf('('); + int endIndex = slot.indexOf(')'); + Q_ASSERT(startIndex != -1 && endIndex != -1); + + extractSlot = slot.remove(startIndex, endIndex-startIndex+1); + + extractSlotTypes = unconvertedSlotType.mid(startIndex+1, endIndex-startIndex-1) + .remove(QRegExp("\\s")) + .split(','); + } +} + +/* from slotMap get [SupportMethod] */ +static HttpResponse::SupportMethod getSupportMethod(const QPair &slotMap) { + + QMapIterator> iter(methodParams); + + QString receiverSlot = slotMap.first; + QString slot; + QStringList slotTypes; + extractSlot(receiverSlot, slot, slotTypes); + + while (iter.hasNext()) { + iter.next(); + HttpResponse::SupportMethod supportMethod = iter.key(); + QMap value = iter.value(); + if (slotTypes == value.value("types").toStringList()) { + return supportMethod; + } + else if (receiverSlot == value.value("lambda").toString()) { + return supportMethod; + } + } + + return HttpResponse::Invalid; +} + +static void autoInfterConvertedSupportMethod(QMultiMap > &unconvertedSlotsMap) +{ + QMultiMap > convertedSlotsMap; + QMapIterator > iter(unconvertedSlotsMap); + + while (iter.hasNext()) { + iter.next(); + const HttpResponse::SupportMethod supportMethod = iter.key(); + const QPair slotMap = iter.value(); + + if (supportMethod == HttpResponse::AutoInfer) { + HttpResponse::SupportMethod supportMethod = getSupportMethod(slotMap); + if (supportMethod == HttpResponse::Invalid) { + qDebug()<<"Not find support Method!"< > &slotsMap) +{ + autoInfterConvertedSupportMethod(slotsMap); + + QMapIterator > iter(slotsMap); + while (iter.hasNext()) { + iter.next(); + SupportMethod supportMethod = iter.key(); + const QPair &slotMap = iter.value(); + + const QString &receiverSlot = slotMap.first; + QVariant target = slotMap.second; + const QObject *receiver = target.value(); + + if (receiver) { + if (methodParams.contains(supportMethod)) { + connect(this, + methodParams[supportMethod].value("signal").toString().toStdString().data(), + receiver, + receiverSlot.toStdString().data(), + Qt::QueuedConnection); + } + } + } +} + +HttpResponse::HttpResponse() +{ + +} diff --git a/third-party/QtNetworkService/HttpResponse.h b/third-party/QtNetworkService/HttpResponse.h new file mode 100644 index 00000000..c6ed2254 --- /dev/null +++ b/third-party/QtNetworkService/HttpResponse.h @@ -0,0 +1,107 @@ +/********************************************************** +Author: Qt君 +微信公众号: Qt君(文章首发) +Website: qtbig.com(后续更新) +Email: 2088201923@qq.com +QQ交流群: 732271126 +LISCENSE: MIT +**********************************************************/ +#ifndef HTTP_RESPONSE_H +#define HTTP_RESPONSE_H + +#include +#include +#include +#include + +namespace AeaQt { + +class HttpResponseTimeout : public QObject { + Q_OBJECT +public: + HttpResponseTimeout(QNetworkReply *parent = NULL, const int timeout = -1) : QObject(parent) { + if (timeout > 0) + QTimer::singleShot(timeout, this, SLOT(onTimeout())); + } + +private slots: + void onTimeout() { + QNetworkReply *reply = static_cast(parent()); + if (reply->isRunning()) { + reply->abort(); + reply->deleteLater(); + } + } +}; + +class HttpResponse : public QObject +{ + Q_OBJECT +public: + /* + * Support Reflex Method + * default: AutoInfer + * AutoInfer: Automatic derivation based on type + */ + enum SupportMethod { + Invalid = 0, + AutoInfer, + onResponse_QNetworkReply_A_Pointer, /* method: void function(QNetworkReply* reply); Is_AutoInfer: true */ + onResponse_QByteArray, /* method: void function(QByteArray data); Is_AutoInfer: true */ + onResponse_QVariantMap, /* method: void function(QVariantMap map); Is_AutoInfer: true */ + onDownloadProgress_qint64_qint64, /* method: void function(qint64 bytesReceived, qint64 bytesTotal); Is_AutoInfer: true */ + onError_QNetworkReply_To_NetworkError, /* method: void function(QNetworkReply::NetworkError error); Is_AutoInfer: true */ + onError_QString, /* method: void function(QString errorString); Is_AutoInfer: true */ + onError_QNetworkReply_To_NetworkError_QNetworkReply_A_Pointer, /* method: void function(QNetworkReply::NetworkError error, QNetworkReply* reply); Is_AutoInfer: true */ + onError_QString_QNetworkReply_A_Poniter/* method: void function(QString errorString, QNetworkReply* reply); Is_AutoInfer: true */ + }; + + explicit HttpResponse(QNetworkReply *networkReply, + const QMultiMap > &slotsMap, + const int &timeout, + bool isBlock); + + virtual ~HttpResponse(); + + QNetworkReply *networkReply(); + +protected: + void slotsMapOperation(QMultiMap > &slotsMap); + +signals: + void finished(QNetworkReply *reply); + void finished(QByteArray data); + void finished(QVariantMap map); + void error(QString errorString); + void error(QNetworkReply::NetworkError error); + void error(QString errorString, QNetworkReply *reply); + void error(QNetworkReply::NetworkError error, QNetworkReply *reply); + void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); + +private slots: + void onFinished(); + void onError(QNetworkReply::NetworkError error); + void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal); + +private: + HttpResponse(); + +private: + QMultiMap > m_slotsMap; + QNetworkReply *m_networkReply; +}; + +} + +Q_DECLARE_METATYPE(std::function) +Q_DECLARE_METATYPE(std::function) +Q_DECLARE_METATYPE(std::function) + +Q_DECLARE_METATYPE(std::function) +Q_DECLARE_METATYPE(std::function) +Q_DECLARE_METATYPE(std::function) +Q_DECLARE_METATYPE(std::function) + +Q_DECLARE_METATYPE(std::function) + +#endif // HTTP_RESPONSE_H diff --git a/third-party/QtNetworkService/LICENSE b/third-party/QtNetworkService/LICENSE new file mode 100644 index 00000000..26b4c3dd --- /dev/null +++ b/third-party/QtNetworkService/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Qt君 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/third-party/QtNetworkService/QtNetworkService.pri b/third-party/QtNetworkService/QtNetworkService.pri new file mode 100644 index 00000000..891bcb2c --- /dev/null +++ b/third-party/QtNetworkService/QtNetworkService.pri @@ -0,0 +1,15 @@ +#********************************************************** +#Author: Qt君 +#微信公众号: Qt君(文章首发) +#Website: qtbig.com(后续更新) +#Email: 2088201923@qq.com +#QQ交流群: 732271126 +#LISCENSE: MIT +#********************************************************** +INCLUDEPATH += $$PWD/ + +QT += network + +!CONFIG(QT_APP_MODE) { + LIBS += -L$$OUT_PWD/Lib -lQtNetworkService +} diff --git a/third-party/QtNetworkService/QtNetworkService.pro b/third-party/QtNetworkService/QtNetworkService.pro new file mode 100644 index 00000000..49e18191 --- /dev/null +++ b/third-party/QtNetworkService/QtNetworkService.pro @@ -0,0 +1,35 @@ +#********************************************************** +#Author: Qt君 +#微信公众号: Qt君(文章首发) +#Website: qtbig.com(后续更新) +#Email: 2088201923@qq.com +#QQ交流群: 732271126 +#LISCENSE: MIT +#********************************************************** +CONFIG += c++11 + +#CONFIG += QT_APP_MODE +DEFINES += QT_APP_DEBUG + +CONFIG += staticlib +TEMPLATE = lib +unix:TARGET = $$OUT_PWD/Lib/QtNetworkService + +win32: { +DESTDIR = $$OUT_PWD/Lib/ +TARGET = QtNetworkService +} + +message(" ================ QtNetworkService Library ================ ") + +SOURCES += \ + $$PWD/HttpResponse.cpp \ + $$PWD/HttpRequest.cpp \ + $$PWD/HttpClient.cpp + +HEADERS += \ + $$PWD/HttpResponse.h \ + $$PWD/HttpRequest.h \ + $$PWD/HttpClient.h + +include(QtNetworkService.pri) diff --git a/third-party/QtNetworkService/README.md b/third-party/QtNetworkService/README.md new file mode 100644 index 00000000..db8aa0a7 --- /dev/null +++ b/third-party/QtNetworkService/README.md @@ -0,0 +1,83 @@ +# 示例 +(1) 简单示例 +* 使用lambda特性 +```cpp +static HttpClient http; +http.post("https://example.com") + .header("content-type", "application/json") + .queryParam("key", "Hello world!") + .body(R"({"user": "test"})") + .onResponse([](QByteArray result) { /* 接收数据 */ + qDebug() << "Result: " << result; + }) + .onResponse([](qint64 recv, qint64 total) { /* 接收进度 */ + qDebug() << "Total: " << total << "; Received: " << recv; + }) + .onError([](QString errorStr) { /* 错误处理 */ + qDebug()<<"Error: "< infos; + if (!result.isEmpty()) + data = result.value("data").toMap(); + + if (!data.isEmpty()) + infos = data.value("info").toList(); + + static HttpService http; + foreach (QVariant each, infos) { + http.get("http://m.kugou.com/app/i/getSongInfo.php") + .queryParam("cmd", "playInfo") + .queryParam("hash", each.toMap()["hash"]) + .onResopnse([](QVariantMap result){ + qDebug()<<"mp3: "< + 微信公众号:Qt君 +

Qt君

+

diff --git a/widget.cpp b/widget.cpp index bcd204fd..f221cfcb 100644 --- a/widget.cpp +++ b/widget.cpp @@ -29,8 +29,11 @@ #include #include #include +#include "HttpClient.h" + DWIDGET_USE_NAMESPACE + Widget::Widget(DBlurEffectWidget *parent) : DBlurEffectWidget(parent), ui(new Ui::Widget) @@ -42,6 +45,8 @@ Widget::Widget(DBlurEffectWidget *parent) : m_loadweb=ui->progressload; m_loadweb->show(); + httpClient = new AeaQt::HttpClient; + connect(ui->menu_main,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(0);}); connect(ui->menu_network,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(1);}); connect(ui->menu_chat,&QPushButton::clicked,[=](){Widget::chooseLeftMenu(2);}); @@ -710,12 +715,26 @@ void Widget::startRequest(QUrl url) void Widget::searchApp(QString text) { + qDebug() << "测试,我的输出是否被调用了,啊啊啊啊"; if(text.left(6)=="spk://"){ openUrl(text); }else { - sendNotification(tr("Spark store could only process spk:// links for now. The search feature is coming soon!")); + // sendNotification(tr("Spark store could only process spk:// links for now. The search feature is coming soon!")); // ui->webView->setUrl(QUrl("http://www.baidu.com/s?wd="+text));//这东西对接百度 // ui->stackedWidget->setCurrentIndex(0); + // 关键字搜索处理 + httpClient->get("http://192.168.0.102:8000/appinfo/search") + .header("content-type", "application/json") + .queryParam("keyword", text) + .onResponse([](QByteArray result) { + qDebug() << "请求结果" << result; + }) + .onError([](QString errorStr) { + qDebug() << "请求出错:" << errorStr; + }) + .timeout(10 * 1000) + .exec(); + } } diff --git a/widget.h b/widget.h index ea4a4cda..8097c530 100644 --- a/widget.h +++ b/widget.h @@ -36,6 +36,9 @@ class Widget; } +namespace AeaQt { + class HttpClient; +} class Widget : public DBlurEffectWidget { @@ -145,6 +148,7 @@ private: QList label_screen; SpkAppInfoLoaderThread appinfoLoadThread; + AeaQt::HttpClient *httpClient; }; #endif // WIDGET_H -- Gitee From 8972425c7c3e280e6feb33d8d6821c2bf5138a92 Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Sun, 8 Nov 2020 22:35:31 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=88=97=E8=A1=A8UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QtNetworkService/QtNetworkService.pro | 2 + widget.cpp | 8 +- widget.ui | 625 ++++++++++-------- 3 files changed, 348 insertions(+), 287 deletions(-) diff --git a/third-party/QtNetworkService/QtNetworkService.pro b/third-party/QtNetworkService/QtNetworkService.pro index 49e18191..446ccfb4 100644 --- a/third-party/QtNetworkService/QtNetworkService.pro +++ b/third-party/QtNetworkService/QtNetworkService.pro @@ -11,6 +11,8 @@ CONFIG += c++11 #CONFIG += QT_APP_MODE DEFINES += QT_APP_DEBUG +QT += network + CONFIG += staticlib TEMPLATE = lib unix:TARGET = $$OUT_PWD/Lib/QtNetworkService diff --git a/widget.cpp b/widget.cpp index f221cfcb..bcbbab3f 100644 --- a/widget.cpp +++ b/widget.cpp @@ -715,7 +715,6 @@ void Widget::startRequest(QUrl url) void Widget::searchApp(QString text) { - qDebug() << "测试,我的输出是否被调用了,啊啊啊啊"; if(text.left(6)=="spk://"){ openUrl(text); }else { @@ -727,7 +726,12 @@ void Widget::searchApp(QString text) .header("content-type", "application/json") .queryParam("keyword", text) .onResponse([](QByteArray result) { - qDebug() << "请求结果" << result; + auto json = QJsonDocument::fromJson(result).array(); + if (json.empty()) { + qDebug() << "搜索不到相关应用!"; + return; + } + // TODO 展示应用 }) .onError([](QString errorStr) { qDebug() << "请求出错:" << errorStr; diff --git a/widget.ui b/widget.ui index 98f4f5c0..0d372cb3 100644 --- a/widget.ui +++ b/widget.ui @@ -7,7 +7,7 @@ 0 0 1053 - 674 + 697 @@ -29,283 +29,30 @@ 0 - - + + - 150 - 0 + 0 + 3 - 150 - 16777215 + 16777215 + 3 - - - 11 - + + -1 - - background-color:#FFFFFF + + - - - - - - 5 - - - 5 - - - - - Video - - - - - - - Download - - - - - - - Tools - - - - - - - Beautify - - - - - - - Music - - - - - - - - 0 - 36 - - - - - 16777215 - 36 - - - - icon - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 3 - 20 - - - - - - - - Development - - - - - - - Office - - - - - - - - 40 - 16777215 - - - - Back to category - - - - - - - :/icons/icons/category_active.svg:/icons/icons/category_active.svg - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Reading - - - - - - - Others - - - - - - - font: 11pt "Zeniq"; - - - Home - - - false - - - - - - - Graphics - - - - - - - Games - - - - - - - Chat - - - - - - - Network - - - - - - - - 0 - 1 - - - - - 16777215 - 4 - - - - background-color:#808080 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 40 - 16777215 - - - - Reload - - - - - - - :/icons/icons/refresh-page.svg:/icons/icons/refresh-page.svg - - - - - - - - + + + + @@ -313,7 +60,7 @@ 0 - 3 + 4 @@ -333,11 +80,11 @@ 0 - + Qt::DefaultContextMenu - + about:blank @@ -457,8 +204,8 @@ 0 0 - 889 - 849 + 886 + 865 @@ -952,8 +699,8 @@ 0 0 - 851 - 326 + 840 + 318 @@ -1082,8 +829,8 @@ 0 0 - 889 - 812 + 886 + 921 @@ -1354,6 +1101,61 @@ + + + + + 0 + 0 + 903 + 667 + + + + 1 + + + + + + 250 + 210 + 231 + 121 + + + + Not found applist info! + + + + + + + + 0 + 0 + 903 + 667 + + + + true + + + + + 0 + 0 + 901 + 665 + + + + + + + @@ -1366,26 +1168,279 @@ - - + + - 0 - 3 + 150 + 0 - 16777215 - 3 + 150 + 16777215 - - -1 + + + 11 + + + + background-color:#FFFFFF + + + 5 + + + 5 + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Music + + + + + + + Graphics + + + + + + + Development + + + + + + + + 0 + 36 + + + + + 16777215 + 36 + + + + icon + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 3 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Tools + + + + + + + Reading + + + + + + + Office + + + + + + + + 40 + 16777215 + + + + Reload + + + + + + + :/icons/icons/refresh-page.svg:/icons/icons/refresh-page.svg + + + + + + + Chat + + + + + + + + 40 + 16777215 + + + + Back to category + + + + + + + :/icons/icons/category_active.svg:/icons/icons/category_active.svg + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Beautify + + + + + + + Network + + + + + + + Games + + + + + + + Others + + + + + + + font: 11pt "Zeniq"; + + + Home + + + false + + + + + + + Download + + + + + + + Video + + + + + + + + 0 + 1 + + + + + 16777215 + 4 + + + + background-color:#808080 + + + + -- Gitee From 66ef37c1ca5ed555e09dbda8acbc8480b7e2e738 Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Fri, 13 Nov 2020 22:57:37 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\345\245\263\345\255\227\344\275\223.ttf" | Bin icons.qrc => assets/icons.qrc | 24 +- {icons => assets/icons}/category_active.svg | 0 .../icons}/category_active_dark.svg | 0 {icons => assets/icons}/category_chat.svg | 0 .../icons}/category_chat_dark.svg | 0 {icons => assets/icons}/category_develop.svg | 0 .../icons}/category_develop_dark.svg | 0 {icons => assets/icons}/category_game.svg | 0 .../icons}/category_game_dark.svg | 0 {icons => assets/icons}/category_graphic.svg | 0 .../icons}/category_graphic_dark.svg | 0 {icons => assets/icons}/category_music.svg | 0 .../icons}/category_music_dark.svg | 0 {icons => assets/icons}/category_network.svg | 0 .../icons}/category_network_dark.svg | 0 {icons => assets/icons}/category_office.svg | 0 .../icons}/category_office_dark.svg | 0 {icons => assets/icons}/category_others.svg | 0 .../icons}/category_others_dark.svg | 0 {icons => assets/icons}/category_reading.svg | 0 .../icons}/category_reading_dark.svg | 0 {icons => assets/icons}/category_system.svg | 0 .../icons}/category_system_dark.svg | 0 {icons => assets/icons}/category_video.svg | 0 .../icons}/category_video_dark.svg | 0 .../icons}/downloads-symbolic.svg | 0 .../icons}/downloads-symbolic_dark.svg | 0 {icons => assets/icons}/homepage.svg | 0 {icons => assets/icons}/homepage_dark.svg | 0 {icons => assets/icons}/refresh-page-dark.svg | 0 {icons => assets/icons}/refresh-page.svg | 0 {icons => assets/icons}/theme-symbolic.svg | 0 .../icons}/theme-symbolic_dark.svg | 0 {tags => assets/tags}/a2d-small.png | Bin {tags => assets/tags}/a2d.png | Bin {tags => assets/tags}/community-small.png | Bin {tags => assets/tags}/community.png | Bin {tags => assets/tags}/community.svg | 0 {tags => assets/tags}/deepin-small.png | Bin {tags => assets/tags}/deepin.svg | 0 {tags => assets/tags}/dtk-small.png | Bin {tags => assets/tags}/dwine2-small.png | Bin {tags => assets/tags}/dwine5-small.png | Bin {tags => assets/tags}/dwine5.svg | 0 {tags => assets/tags}/logo_icon.svg | 0 {tags => assets/tags}/ubuntu-small.png | Bin {tags => assets/tags}/ubuntu.png | Bin {tags => assets/tags}/uos-small.png | Bin {tags => assets/tags}/uos.svg | 0 spark-store-project.pro | 7 + spark-store-project.pro.user | 355 ++++++++++++++++++ src/appitem.cpp | 14 + src/appitem.h | 22 ++ src/appitem.ui | 21 ++ big_image.cpp => src/big_image.cpp | 0 big_image.h => src/big_image.h | 0 downloadlist.cpp => src/downloadlist.cpp | 0 downloadlist.h => src/downloadlist.h | 0 downloadlist.ui => src/downloadlist.ui | 0 image_show.cpp => src/image_show.cpp | 0 image_show.h => src/image_show.h | 0 main.cpp => src/main.cpp | 0 progressload.cpp => src/progressload.cpp | 0 progressload.h => src/progressload.h | 0 spark-store.pro => src/spark-store.pro | 39 +- widget.cpp => src/widget.cpp | 0 widget.h => src/widget.h | 0 widget.ui => src/widget.ui | 0 workerthreads.cpp => src/workerthreads.cpp | 0 workerthreads.h => src/workerthreads.h | 0 third-party/QtNetworkService/HttpRequest.cpp | 16 +- third-party/QtNetworkService/HttpRequest.h | 6 +- .../QtNetworkService/QtNetworkService.pri | 2 +- .../QtNetworkService/QtNetworkService.pro | 2 +- 75 files changed, 465 insertions(+), 43 deletions(-) rename "fonts/\345\215\216\345\272\267\345\260\221\345\245\263\345\255\227\344\275\223.ttf" => "assets/fonts/\345\215\216\345\272\267\345\260\221\345\245\263\345\255\227\344\275\223.ttf" (100%) rename icons.qrc => assets/icons.qrc (82%) rename {icons => assets/icons}/category_active.svg (100%) rename {icons => assets/icons}/category_active_dark.svg (100%) rename {icons => assets/icons}/category_chat.svg (100%) rename {icons => assets/icons}/category_chat_dark.svg (100%) rename {icons => assets/icons}/category_develop.svg (100%) rename {icons => assets/icons}/category_develop_dark.svg (100%) rename {icons => assets/icons}/category_game.svg (100%) rename {icons => assets/icons}/category_game_dark.svg (100%) rename {icons => assets/icons}/category_graphic.svg (100%) rename {icons => assets/icons}/category_graphic_dark.svg (100%) rename {icons => assets/icons}/category_music.svg (100%) rename {icons => assets/icons}/category_music_dark.svg (100%) rename {icons => assets/icons}/category_network.svg (100%) rename {icons => assets/icons}/category_network_dark.svg (100%) rename {icons => assets/icons}/category_office.svg (100%) rename {icons => assets/icons}/category_office_dark.svg (100%) rename {icons => assets/icons}/category_others.svg (100%) rename {icons => assets/icons}/category_others_dark.svg (100%) rename {icons => assets/icons}/category_reading.svg (100%) rename {icons => assets/icons}/category_reading_dark.svg (100%) rename {icons => assets/icons}/category_system.svg (100%) rename {icons => assets/icons}/category_system_dark.svg (100%) rename {icons => assets/icons}/category_video.svg (100%) rename {icons => assets/icons}/category_video_dark.svg (100%) rename {icons => assets/icons}/downloads-symbolic.svg (100%) rename {icons => assets/icons}/downloads-symbolic_dark.svg (100%) rename {icons => assets/icons}/homepage.svg (100%) rename {icons => assets/icons}/homepage_dark.svg (100%) rename {icons => assets/icons}/refresh-page-dark.svg (100%) rename {icons => assets/icons}/refresh-page.svg (100%) rename {icons => assets/icons}/theme-symbolic.svg (100%) rename {icons => assets/icons}/theme-symbolic_dark.svg (100%) rename {tags => assets/tags}/a2d-small.png (100%) rename {tags => assets/tags}/a2d.png (100%) rename {tags => assets/tags}/community-small.png (100%) rename {tags => assets/tags}/community.png (100%) rename {tags => assets/tags}/community.svg (100%) rename {tags => assets/tags}/deepin-small.png (100%) rename {tags => assets/tags}/deepin.svg (100%) rename {tags => assets/tags}/dtk-small.png (100%) rename {tags => assets/tags}/dwine2-small.png (100%) rename {tags => assets/tags}/dwine5-small.png (100%) rename {tags => assets/tags}/dwine5.svg (100%) rename {tags => assets/tags}/logo_icon.svg (100%) rename {tags => assets/tags}/ubuntu-small.png (100%) rename {tags => assets/tags}/ubuntu.png (100%) rename {tags => assets/tags}/uos-small.png (100%) rename {tags => assets/tags}/uos.svg (100%) create mode 100644 spark-store-project.pro create mode 100644 spark-store-project.pro.user create mode 100644 src/appitem.cpp create mode 100644 src/appitem.h create mode 100644 src/appitem.ui rename big_image.cpp => src/big_image.cpp (100%) rename big_image.h => src/big_image.h (100%) rename downloadlist.cpp => src/downloadlist.cpp (100%) rename downloadlist.h => src/downloadlist.h (100%) rename downloadlist.ui => src/downloadlist.ui (100%) rename image_show.cpp => src/image_show.cpp (100%) rename image_show.h => src/image_show.h (100%) rename main.cpp => src/main.cpp (100%) rename progressload.cpp => src/progressload.cpp (100%) rename progressload.h => src/progressload.h (100%) rename spark-store.pro => src/spark-store.pro (66%) rename widget.cpp => src/widget.cpp (100%) rename widget.h => src/widget.h (100%) rename widget.ui => src/widget.ui (100%) rename workerthreads.cpp => src/workerthreads.cpp (100%) rename workerthreads.h => src/workerthreads.h (100%) diff --git "a/fonts/\345\215\216\345\272\267\345\260\221\345\245\263\345\255\227\344\275\223.ttf" "b/assets/fonts/\345\215\216\345\272\267\345\260\221\345\245\263\345\255\227\344\275\223.ttf" similarity index 100% rename from "fonts/\345\215\216\345\272\267\345\260\221\345\245\263\345\255\227\344\275\223.ttf" rename to "assets/fonts/\345\215\216\345\272\267\345\260\221\345\245\263\345\255\227\344\275\223.ttf" diff --git a/icons.qrc b/assets/icons.qrc similarity index 82% rename from icons.qrc rename to assets/icons.qrc index 08145308..bdfa1bee 100644 --- a/icons.qrc +++ b/assets/icons.qrc @@ -34,18 +34,18 @@ icons/refresh-page.svg - Logo-Spark.png - big_image.cpp - big_image.h - downloadlist.cpp - downloadlist.h - image_show.cpp - image_show.h - main.cpp - progressload.cpp - progressload.h - widget.cpp - widget.h + ../Logo-Spark.png + ../src/big_image.cpp + ../src/big_image.h + ../src/downloadlist.cpp + ../src/downloadlist.h + ../src/image_show.cpp + ../src/image_show.h + ../src/main.cpp + ../src/progressload.cpp + ../src/progressload.h + ../src/widget.cpp + ../src/widget.h tags/a2d.png tags/community.svg tags/deepin.svg diff --git a/icons/category_active.svg b/assets/icons/category_active.svg similarity index 100% rename from icons/category_active.svg rename to assets/icons/category_active.svg diff --git a/icons/category_active_dark.svg b/assets/icons/category_active_dark.svg similarity index 100% rename from icons/category_active_dark.svg rename to assets/icons/category_active_dark.svg diff --git a/icons/category_chat.svg b/assets/icons/category_chat.svg similarity index 100% rename from icons/category_chat.svg rename to assets/icons/category_chat.svg diff --git a/icons/category_chat_dark.svg b/assets/icons/category_chat_dark.svg similarity index 100% rename from icons/category_chat_dark.svg rename to assets/icons/category_chat_dark.svg diff --git a/icons/category_develop.svg b/assets/icons/category_develop.svg similarity index 100% rename from icons/category_develop.svg rename to assets/icons/category_develop.svg diff --git a/icons/category_develop_dark.svg b/assets/icons/category_develop_dark.svg similarity index 100% rename from icons/category_develop_dark.svg rename to assets/icons/category_develop_dark.svg diff --git a/icons/category_game.svg b/assets/icons/category_game.svg similarity index 100% rename from icons/category_game.svg rename to assets/icons/category_game.svg diff --git a/icons/category_game_dark.svg b/assets/icons/category_game_dark.svg similarity index 100% rename from icons/category_game_dark.svg rename to assets/icons/category_game_dark.svg diff --git a/icons/category_graphic.svg b/assets/icons/category_graphic.svg similarity index 100% rename from icons/category_graphic.svg rename to assets/icons/category_graphic.svg diff --git a/icons/category_graphic_dark.svg b/assets/icons/category_graphic_dark.svg similarity index 100% rename from icons/category_graphic_dark.svg rename to assets/icons/category_graphic_dark.svg diff --git a/icons/category_music.svg b/assets/icons/category_music.svg similarity index 100% rename from icons/category_music.svg rename to assets/icons/category_music.svg diff --git a/icons/category_music_dark.svg b/assets/icons/category_music_dark.svg similarity index 100% rename from icons/category_music_dark.svg rename to assets/icons/category_music_dark.svg diff --git a/icons/category_network.svg b/assets/icons/category_network.svg similarity index 100% rename from icons/category_network.svg rename to assets/icons/category_network.svg diff --git a/icons/category_network_dark.svg b/assets/icons/category_network_dark.svg similarity index 100% rename from icons/category_network_dark.svg rename to assets/icons/category_network_dark.svg diff --git a/icons/category_office.svg b/assets/icons/category_office.svg similarity index 100% rename from icons/category_office.svg rename to assets/icons/category_office.svg diff --git a/icons/category_office_dark.svg b/assets/icons/category_office_dark.svg similarity index 100% rename from icons/category_office_dark.svg rename to assets/icons/category_office_dark.svg diff --git a/icons/category_others.svg b/assets/icons/category_others.svg similarity index 100% rename from icons/category_others.svg rename to assets/icons/category_others.svg diff --git a/icons/category_others_dark.svg b/assets/icons/category_others_dark.svg similarity index 100% rename from icons/category_others_dark.svg rename to assets/icons/category_others_dark.svg diff --git a/icons/category_reading.svg b/assets/icons/category_reading.svg similarity index 100% rename from icons/category_reading.svg rename to assets/icons/category_reading.svg diff --git a/icons/category_reading_dark.svg b/assets/icons/category_reading_dark.svg similarity index 100% rename from icons/category_reading_dark.svg rename to assets/icons/category_reading_dark.svg diff --git a/icons/category_system.svg b/assets/icons/category_system.svg similarity index 100% rename from icons/category_system.svg rename to assets/icons/category_system.svg diff --git a/icons/category_system_dark.svg b/assets/icons/category_system_dark.svg similarity index 100% rename from icons/category_system_dark.svg rename to assets/icons/category_system_dark.svg diff --git a/icons/category_video.svg b/assets/icons/category_video.svg similarity index 100% rename from icons/category_video.svg rename to assets/icons/category_video.svg diff --git a/icons/category_video_dark.svg b/assets/icons/category_video_dark.svg similarity index 100% rename from icons/category_video_dark.svg rename to assets/icons/category_video_dark.svg diff --git a/icons/downloads-symbolic.svg b/assets/icons/downloads-symbolic.svg similarity index 100% rename from icons/downloads-symbolic.svg rename to assets/icons/downloads-symbolic.svg diff --git a/icons/downloads-symbolic_dark.svg b/assets/icons/downloads-symbolic_dark.svg similarity index 100% rename from icons/downloads-symbolic_dark.svg rename to assets/icons/downloads-symbolic_dark.svg diff --git a/icons/homepage.svg b/assets/icons/homepage.svg similarity index 100% rename from icons/homepage.svg rename to assets/icons/homepage.svg diff --git a/icons/homepage_dark.svg b/assets/icons/homepage_dark.svg similarity index 100% rename from icons/homepage_dark.svg rename to assets/icons/homepage_dark.svg diff --git a/icons/refresh-page-dark.svg b/assets/icons/refresh-page-dark.svg similarity index 100% rename from icons/refresh-page-dark.svg rename to assets/icons/refresh-page-dark.svg diff --git a/icons/refresh-page.svg b/assets/icons/refresh-page.svg similarity index 100% rename from icons/refresh-page.svg rename to assets/icons/refresh-page.svg diff --git a/icons/theme-symbolic.svg b/assets/icons/theme-symbolic.svg similarity index 100% rename from icons/theme-symbolic.svg rename to assets/icons/theme-symbolic.svg diff --git a/icons/theme-symbolic_dark.svg b/assets/icons/theme-symbolic_dark.svg similarity index 100% rename from icons/theme-symbolic_dark.svg rename to assets/icons/theme-symbolic_dark.svg diff --git a/tags/a2d-small.png b/assets/tags/a2d-small.png similarity index 100% rename from tags/a2d-small.png rename to assets/tags/a2d-small.png diff --git a/tags/a2d.png b/assets/tags/a2d.png similarity index 100% rename from tags/a2d.png rename to assets/tags/a2d.png diff --git a/tags/community-small.png b/assets/tags/community-small.png similarity index 100% rename from tags/community-small.png rename to assets/tags/community-small.png diff --git a/tags/community.png b/assets/tags/community.png similarity index 100% rename from tags/community.png rename to assets/tags/community.png diff --git a/tags/community.svg b/assets/tags/community.svg similarity index 100% rename from tags/community.svg rename to assets/tags/community.svg diff --git a/tags/deepin-small.png b/assets/tags/deepin-small.png similarity index 100% rename from tags/deepin-small.png rename to assets/tags/deepin-small.png diff --git a/tags/deepin.svg b/assets/tags/deepin.svg similarity index 100% rename from tags/deepin.svg rename to assets/tags/deepin.svg diff --git a/tags/dtk-small.png b/assets/tags/dtk-small.png similarity index 100% rename from tags/dtk-small.png rename to assets/tags/dtk-small.png diff --git a/tags/dwine2-small.png b/assets/tags/dwine2-small.png similarity index 100% rename from tags/dwine2-small.png rename to assets/tags/dwine2-small.png diff --git a/tags/dwine5-small.png b/assets/tags/dwine5-small.png similarity index 100% rename from tags/dwine5-small.png rename to assets/tags/dwine5-small.png diff --git a/tags/dwine5.svg b/assets/tags/dwine5.svg similarity index 100% rename from tags/dwine5.svg rename to assets/tags/dwine5.svg diff --git a/tags/logo_icon.svg b/assets/tags/logo_icon.svg similarity index 100% rename from tags/logo_icon.svg rename to assets/tags/logo_icon.svg diff --git a/tags/ubuntu-small.png b/assets/tags/ubuntu-small.png similarity index 100% rename from tags/ubuntu-small.png rename to assets/tags/ubuntu-small.png diff --git a/tags/ubuntu.png b/assets/tags/ubuntu.png similarity index 100% rename from tags/ubuntu.png rename to assets/tags/ubuntu.png diff --git a/tags/uos-small.png b/assets/tags/uos-small.png similarity index 100% rename from tags/uos-small.png rename to assets/tags/uos-small.png diff --git a/tags/uos.svg b/assets/tags/uos.svg similarity index 100% rename from tags/uos.svg rename to assets/tags/uos.svg diff --git a/spark-store-project.pro b/spark-store-project.pro new file mode 100644 index 00000000..329b0969 --- /dev/null +++ b/spark-store-project.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs +CONFIG += ordered + +SUBDIRS = third-party/QtNetworkService \ + src/spark-store.pro + +spark-store.depends = third-party/QtNetworkService \ No newline at end of file diff --git a/spark-store-project.pro.user b/spark-store-project.pro.user new file mode 100644 index 00000000..4c6991ae --- /dev/null +++ b/spark-store-project.pro.user @@ -0,0 +1,355 @@ + + + + + + EnvironmentId + {00b3f4d7-8db0-4253-a398-d3de963c3817} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + true + true + true + true + + + 0 + true + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 2 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + qt5.11.3 + qt5.11.3 + {138a9e55-4e7e-4c77-90d9-30ea9975c6ad} + 0 + 0 + 0 + + true + 0 + /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Debug + /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 2 + 2 + + + true + 2 + /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Release + /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 2 + + + true + 0 + /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Profile + /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Profile + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/src/appitem.cpp b/src/appitem.cpp new file mode 100644 index 00000000..2e845f9c --- /dev/null +++ b/src/appitem.cpp @@ -0,0 +1,14 @@ +#include "appitem.h" +#include "ui_appitem.h" + +AppItem::AppItem(QWidget *parent) : + QWidget(parent), + ui(new Ui::AppItem) +{ + ui->setupUi(this); +} + +AppItem::~AppItem() +{ + delete ui; +} diff --git a/src/appitem.h b/src/appitem.h new file mode 100644 index 00000000..93f4da37 --- /dev/null +++ b/src/appitem.h @@ -0,0 +1,22 @@ +#ifndef APPITEM_H +#define APPITEM_H + +#include + +namespace Ui { +class AppItem; +} + +class AppItem : public QWidget +{ + Q_OBJECT + +public: + explicit AppItem(QWidget *parent = nullptr); + ~AppItem(); + +private: + Ui::AppItem *ui; +}; + +#endif // APPITEM_H diff --git a/src/appitem.ui b/src/appitem.ui new file mode 100644 index 00000000..9d5d09c5 --- /dev/null +++ b/src/appitem.ui @@ -0,0 +1,21 @@ + + + + + AppItem + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/big_image.cpp b/src/big_image.cpp similarity index 100% rename from big_image.cpp rename to src/big_image.cpp diff --git a/big_image.h b/src/big_image.h similarity index 100% rename from big_image.h rename to src/big_image.h diff --git a/downloadlist.cpp b/src/downloadlist.cpp similarity index 100% rename from downloadlist.cpp rename to src/downloadlist.cpp diff --git a/downloadlist.h b/src/downloadlist.h similarity index 100% rename from downloadlist.h rename to src/downloadlist.h diff --git a/downloadlist.ui b/src/downloadlist.ui similarity index 100% rename from downloadlist.ui rename to src/downloadlist.ui diff --git a/image_show.cpp b/src/image_show.cpp similarity index 100% rename from image_show.cpp rename to src/image_show.cpp diff --git a/image_show.h b/src/image_show.h similarity index 100% rename from image_show.h rename to src/image_show.h diff --git a/main.cpp b/src/main.cpp similarity index 100% rename from main.cpp rename to src/main.cpp diff --git a/progressload.cpp b/src/progressload.cpp similarity index 100% rename from progressload.cpp rename to src/progressload.cpp diff --git a/progressload.h b/src/progressload.h similarity index 100% rename from progressload.h rename to src/progressload.h diff --git a/spark-store.pro b/src/spark-store.pro similarity index 66% rename from spark-store.pro rename to src/spark-store.pro index 221fbfb3..61089ea7 100644 --- a/spark-store.pro +++ b/src/spark-store.pro @@ -26,6 +26,7 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += main.cpp\ + appitem.cpp \ widget.cpp \ downloadlist.cpp \ image_show.cpp \ @@ -34,6 +35,7 @@ SOURCES += main.cpp\ workerthreads.cpp HEADERS += \ + appitem.h \ widget.h \ downloadlist.h \ image_show.h \ @@ -42,31 +44,32 @@ HEADERS += \ workerthreads.h FORMS += \ + appitem.ui \ widget.ui \ downloadlist.ui RESOURCES += \ - icons.qrc + ../assets/icons.qrc DISTFILES += \ - tags/a2d-small.png \ - tags/a2d.png \ - tags/community-small.png \ - tags/community.png \ - tags/deepin-small.png \ - tags/dtk-small.png \ - tags/ubuntu-small.png \ - tags/ubuntu.png \ - tags/uos-small.png \ - tags/community.svg \ - tags/deepin.svg \ - tags/logo_icon.svg \ - tags/uos.svg + ../assets/tags/a2d-small.png \ + ../assets/tags/a2d.png \ + ../assets/tags/community-small.png \ + ../assets/tags/community.png \ + ../assets/tags/deepin-small.png \ + ../assets/tags/dtk-small.png \ + ../assets/tags/ubuntu-small.png \ + ../assets/tags/ubuntu.png \ + ../assets/tags/uos-small.png \ + ../assets/tags/community.svg \ + ../assets/tags/deepin.svg \ + ../assets/tags/logo_icon.svg \ + ../assets/tags/uos.svg -TRANSLATIONS = ./trans/spark-store_en.ts \ - ./trans/spark-store_zh_CN.ts - ./trans/spark-store_fr.ts\ +TRANSLATIONS = ../trans/spark-store_en.ts \ + ../trans/spark-store_zh_CN.ts + ../trans/spark-store_fr.ts\ DEFINES += QT_APP_DEBUG -include(./third-party/QtNetworkService/QtNetworkService.pri) +include(../third-party/QtNetworkService/QtNetworkService.pri) diff --git a/widget.cpp b/src/widget.cpp similarity index 100% rename from widget.cpp rename to src/widget.cpp diff --git a/widget.h b/src/widget.h similarity index 100% rename from widget.h rename to src/widget.h diff --git a/widget.ui b/src/widget.ui similarity index 100% rename from widget.ui rename to src/widget.ui diff --git a/workerthreads.cpp b/src/workerthreads.cpp similarity index 100% rename from workerthreads.cpp rename to src/workerthreads.cpp diff --git a/workerthreads.h b/src/workerthreads.h similarity index 100% rename from workerthreads.h rename to src/workerthreads.h diff --git a/third-party/QtNetworkService/HttpRequest.cpp b/third-party/QtNetworkService/HttpRequest.cpp index 8d44c118..f34b1476 100644 --- a/third-party/QtNetworkService/HttpRequest.cpp +++ b/third-party/QtNetworkService/HttpRequest.cpp @@ -118,17 +118,17 @@ HttpRequest &HttpRequest::body(const QVariant &body) m_body = QJsonDocument(QJsonObject::fromVariantMap(body.toMap())).toJson(); } else { - warning << "This is not data in JSON format(QVariantMap or QJsonObject)."; + log_warning << "This is not data in JSON format(QVariantMap or QJsonObject)."; m_body = QByteArray(); // warning output } } else { m_body = QByteArray(); - warning << "Disable body."; + log_warning << "Disable body."; } - debugger << "Body Content:" << m_body; + log_debugger << "Body Content:" << m_body; return *this; } #endif @@ -211,9 +211,9 @@ HttpResponse *HttpRequest::exec() sendBuffer->setData(m_body); } - debugger << "Http Client info: "; - debugger << "Type: " << s_httpOperation[m_op]; - debugger << "Url: " << m_networkRequest.url().toString(); + log_debugger << "Http Client info: "; + log_debugger << "Type: " << s_httpOperation[m_op]; + log_debugger << "Url: " << m_networkRequest.url().toString(); QString headers; for (int i = 0; i < m_networkRequest.rawHeaderList().count(); i++) { QString each = m_networkRequest.rawHeaderList().at(i); @@ -221,8 +221,8 @@ HttpResponse *HttpRequest::exec() headers += QString("%1: %2;").arg(each) .arg(header); } - debugger << "Header: " << headers; - debugger << "Send buffer(Body):\r\n" << m_body; + log_debugger << "Header: " << headers; + log_debugger << "Send buffer(Body):\r\n" << m_body; reply = m_httpService->createRequest(m_op, m_networkRequest, sendBuffer); diff --git a/third-party/QtNetworkService/HttpRequest.h b/third-party/QtNetworkService/HttpRequest.h index 44672a17..b7358c3c 100644 --- a/third-party/QtNetworkService/HttpRequest.h +++ b/third-party/QtNetworkService/HttpRequest.h @@ -19,15 +19,15 @@ LISCENSE: MIT namespace AeaQt { #ifdef QT_APP_DEBUG -#define debugger qDebug().noquote().nospace() \ +#define log_debugger qDebug().noquote().nospace() \ << "[AeaQt::Network] Debug: -> " \ << "function: " << __func__ << "; " \ << "line: " << __LINE__ << "; " #else -#define debug QString() +#define log_debugger QString() #endif -#define warning qWarning().noquote().nospace() \ +#define log_warning qWarning().noquote().nospace() \ << "[AeaQt::Network] Warning: -> " \ << "function: " << __func__ << "; " \ << "line: " << __LINE__ << "; " diff --git a/third-party/QtNetworkService/QtNetworkService.pri b/third-party/QtNetworkService/QtNetworkService.pri index 891bcb2c..1d01eb27 100644 --- a/third-party/QtNetworkService/QtNetworkService.pri +++ b/third-party/QtNetworkService/QtNetworkService.pri @@ -11,5 +11,5 @@ INCLUDEPATH += $$PWD/ QT += network !CONFIG(QT_APP_MODE) { - LIBS += -L$$OUT_PWD/Lib -lQtNetworkService + LIBS += -L$$OUT_PWD/../third-party/QtNetworkService/Lib -lQtNetworkService } diff --git a/third-party/QtNetworkService/QtNetworkService.pro b/third-party/QtNetworkService/QtNetworkService.pro index 446ccfb4..47bbcf9e 100644 --- a/third-party/QtNetworkService/QtNetworkService.pro +++ b/third-party/QtNetworkService/QtNetworkService.pro @@ -13,8 +13,8 @@ DEFINES += QT_APP_DEBUG QT += network -CONFIG += staticlib TEMPLATE = lib +CONFIG += staticlib unix:TARGET = $$OUT_PWD/Lib/QtNetworkService win32: { -- Gitee From 3cca0d87fe09a0d00c8081f08e46d986041c114a Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Sat, 21 Nov 2020 11:18:20 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=88=B0=E5=BF=BD=E7=95=A5=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- spark-store-project.pro.user | 355 ----------------------------------- 2 files changed, 2 insertions(+), 357 deletions(-) delete mode 100644 spark-store-project.pro.user diff --git a/.gitignore b/.gitignore index 6a5b5520..e8f73651 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -spark-store.pro.user* +*.pro.user* build/ .vscode/ -Lib/ \ No newline at end of file +Lib/ diff --git a/spark-store-project.pro.user b/spark-store-project.pro.user deleted file mode 100644 index 4c6991ae..00000000 --- a/spark-store-project.pro.user +++ /dev/null @@ -1,355 +0,0 @@ - - - - - - EnvironmentId - {00b3f4d7-8db0-4253-a398-d3de963c3817} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - true - true - true - true - - - 0 - true - - true - Builtin.Questionable - - true - Builtin.DefaultTidyAndClazy - 2 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - qt5.11.3 - qt5.11.3 - {138a9e55-4e7e-4c77-90d9-30ea9975c6ad} - 0 - 0 - 0 - - true - 0 - /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Debug - /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Debug - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - 2 - 2 - - - true - 2 - /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Release - /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Release - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 2 - - - true - 0 - /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Profile - /home/metanoia1989/WorkSpace/build-spark-store-project-qt5_11_3-Profile - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - - 2 - - - ProjectExplorer.CustomExecutableRunConfiguration - - - false - - false - true - false - false - true - - - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - -- Gitee From a73a4416fc13b833c883838957054c26f52a5943 Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Sun, 29 Nov 2020 20:28:59 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=88=97=E8=A1=A8=E7=9A=84=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appitem.cpp | 62 ++ src/appitem.h | 22 + src/appitem.ui | 35 +- src/flowlayout.cpp | 223 +++++ src/flowlayout.h | 88 ++ src/main.cpp | 2 + src/spark-store.pro | 2 + src/widget.cpp | 50 +- src/widget.h | 6 + src/widget.ui | 2230 +++++++++++++++++++++---------------------- 10 files changed, 1580 insertions(+), 1140 deletions(-) create mode 100644 src/flowlayout.cpp create mode 100644 src/flowlayout.h diff --git a/src/appitem.cpp b/src/appitem.cpp index 2e845f9c..384cbd12 100644 --- a/src/appitem.cpp +++ b/src/appitem.cpp @@ -1,5 +1,10 @@ #include "appitem.h" #include "ui_appitem.h" +#include +#include +#include +#include +#include AppItem::AppItem(QWidget *parent) : QWidget(parent), @@ -12,3 +17,60 @@ AppItem::~AppItem() { delete ui; } + +void AppItem::setTitle(QString title) +{ + m_title = title; + ui->lbl_title->setText(title); +} + +void AppItem::setDescription(QString description) +{ + m_description = description; + ui->lbl_desc->setText(description); +} + +void AppItem::setIcon(QString icon) +{ + m_icon = icon; + downloadIcon(icon); +} + +void AppItem::setUrl(QString url) +{ + m_url = url; +} + +void AppItem::mousePressEvent(QMouseEvent *event) +{ + emit clicked(QUrl(m_url)); +} + +/** + * @brief 下载图标 + * @param icon + */ +void AppItem::downloadIcon(QString icon) +{ + QtConcurrent::run([=](){ + auto reqManager = new QNetworkAccessManager(); + QUrl url(icon); + QNetworkReply *reply = reqManager->get(QNetworkRequest(url)); + QEventLoop loop; + connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); + loop.exec(); + reqManager->deleteLater(); + QPixmap pixmap; + pixmap.loadFromData(reply->readAll()); + if (reply->error() == QNetworkReply::NoError) { + QMetaObject::invokeMethod(this, "loadIcon", Qt::QueuedConnection, + Q_ARG(QPixmap, pixmap)); + } + }); +} + +void AppItem::loadIcon(QPixmap pic) +{ + qDebug() << pic; + ui->lbl_icon->setPixmap(pic); +} diff --git a/src/appitem.h b/src/appitem.h index 93f4da37..f7b2e564 100644 --- a/src/appitem.h +++ b/src/appitem.h @@ -2,6 +2,7 @@ #define APPITEM_H #include +#include namespace Ui { class AppItem; @@ -15,8 +16,29 @@ public: explicit AppItem(QWidget *parent = nullptr); ~AppItem(); + void setTitle(QString title); + void setDescription(QString description); + void setIcon(QString icon); + void setUrl(QString url); + +protected: + void mousePressEvent(QMouseEvent *event) override; + +signals: + void clicked(QUrl url); + +public slots: + void downloadIcon(QString icon); + void loadIcon(QPixmap pic); + private: Ui::AppItem *ui; + + QString m_title; + QString m_description; + QString m_icon; + QString m_pkgname; + QString m_url; }; #endif // APPITEM_H diff --git a/src/appitem.ui b/src/appitem.ui index 9d5d09c5..decbdba3 100644 --- a/src/appitem.ui +++ b/src/appitem.ui @@ -1,9 +1,7 @@ + - - - AppItem - + 0 @@ -15,7 +13,34 @@ Form + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/src/flowlayout.cpp b/src/flowlayout.cpp new file mode 100644 index 00000000..9c6b87a8 --- /dev/null +++ b/src/flowlayout.cpp @@ -0,0 +1,223 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "flowlayout.h" +//! [1] +FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing) + : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) +{ + setContentsMargins(margin, margin, margin, margin); +} + +FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing) + : m_hSpace(hSpacing), m_vSpace(vSpacing) +{ + setContentsMargins(margin, margin, margin, margin); +} +//! [1] + +//! [2] +FlowLayout::~FlowLayout() +{ + QLayoutItem *item; + while ((item = takeAt(0))) + delete item; +} +//! [2] + +//! [3] +void FlowLayout::addItem(QLayoutItem *item) +{ + itemList.append(item); +} +//! [3] + +//! [4] +int FlowLayout::horizontalSpacing() const +{ + if (m_hSpace >= 0) { + return m_hSpace; + } else { + return smartSpacing(QStyle::PM_LayoutHorizontalSpacing); + } +} + +int FlowLayout::verticalSpacing() const +{ + if (m_vSpace >= 0) { + return m_vSpace; + } else { + return smartSpacing(QStyle::PM_LayoutVerticalSpacing); + } +} +//! [4] + +//! [5] +int FlowLayout::count() const +{ + return itemList.size(); +} + +QLayoutItem *FlowLayout::itemAt(int index) const +{ + return itemList.value(index); +} + +QLayoutItem *FlowLayout::takeAt(int index) +{ + if (index >= 0 && index < itemList.size()) + return itemList.takeAt(index); + else + return 0; +} +//! [5] + +//! [6] +Qt::Orientations FlowLayout::expandingDirections() const +{ + return 0; +} +//! [6] + +//! [7] +bool FlowLayout::hasHeightForWidth() const +{ + return true; +} + +int FlowLayout::heightForWidth(int width) const +{ + int height = doLayout(QRect(0, 0, width, 0), true); + return height; +} +//! [7] + +//! [8] +void FlowLayout::setGeometry(const QRect &rect) +{ + QLayout::setGeometry(rect); + doLayout(rect, false); +} + +QSize FlowLayout::sizeHint() const +{ + return minimumSize(); +} + +QSize FlowLayout::minimumSize() const +{ + QSize size; + QLayoutItem *item; + foreach (item, itemList) + size = size.expandedTo(item->minimumSize()); + + size += QSize(2*margin(), 2*margin()); + return size; +} +//! [8] + +//! [9] +int FlowLayout::doLayout(const QRect &rect, bool testOnly) const +{ + int left, top, right, bottom; + getContentsMargins(&left, &top, &right, &bottom); + QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom); + int x = effectiveRect.x(); + int y = effectiveRect.y(); + int lineHeight = 0; +//! [9] + +//! [10] + QLayoutItem *item; + foreach (item, itemList) { + QWidget *wid = item->widget(); + int spaceX = horizontalSpacing(); + if (spaceX == -1) + spaceX = wid->style()->layoutSpacing( + QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal); + int spaceY = verticalSpacing(); + if (spaceY == -1) + spaceY = wid->style()->layoutSpacing( + QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical); +//! [10] +//! [11] + int nextX = x + item->sizeHint().width() + spaceX; + if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) { + x = effectiveRect.x(); + y = y + lineHeight + spaceY; + nextX = x + item->sizeHint().width() + spaceX; + lineHeight = 0; + } + + if (!testOnly) + item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); + + x = nextX; + lineHeight = qMax(lineHeight, item->sizeHint().height()); + } + return y + lineHeight - rect.y() + bottom; +} +//! [11] +//! [12] +int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const +{ + QObject *parent = this->parent(); + if (!parent) { + return -1; + } else if (parent->isWidgetType()) { + QWidget *pw = static_cast(parent); + return pw->style()->pixelMetric(pm, 0, pw); + } else { + return static_cast(parent)->spacing(); + } +} +//! [12] \ No newline at end of file diff --git a/src/flowlayout.h b/src/flowlayout.h new file mode 100644 index 00000000..920f4e63 --- /dev/null +++ b/src/flowlayout.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FLOWLAYOUT_H +#define FLOWLAYOUT_H + +#include +#include +#include +//! [0] +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(); + + void addItem(QLayoutItem *item) override; + int horizontalSpacing() const; + int verticalSpacing() const; + Qt::Orientations expandingDirections() const override; + bool hasHeightForWidth() const override; + int heightForWidth(int) const override; + int count() const override; + QLayoutItem *itemAt(int index) const override; + QSize minimumSize() const override; + void setGeometry(const QRect &rect) override; + QSize sizeHint() const override; + QLayoutItem *takeAt(int index) override; + +private: + int doLayout(const QRect &rect, bool testOnly) const; + int smartSpacing(QStyle::PixelMetric pm) const; + + QList itemList; + int m_hSpace; + int m_vSpace; +}; +//! [0] + +#endif // FLOWLAYOUT_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0f228bfc..51009e52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,8 @@ #include #include #include +#include "appitem.h" + DWIDGET_USE_NAMESPACE int main(int argc, char *argv[]) { diff --git a/src/spark-store.pro b/src/spark-store.pro index 61089ea7..e55cbab5 100644 --- a/src/spark-store.pro +++ b/src/spark-store.pro @@ -32,6 +32,7 @@ SOURCES += main.cpp\ image_show.cpp \ big_image.cpp \ progressload.cpp \ + flowlayout.cpp \ workerthreads.cpp HEADERS += \ @@ -41,6 +42,7 @@ HEADERS += \ image_show.h \ big_image.h \ progressload.h \ + flowlayout.h \ workerthreads.h FORMS += \ diff --git a/src/widget.cpp b/src/widget.cpp index bcbbab3f..e6cec2fe 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -9,8 +9,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -30,6 +30,8 @@ #include #include #include "HttpClient.h" +#include "appitem.h" +#include "flowlayout.h" DWIDGET_USE_NAMESPACE @@ -205,6 +207,9 @@ void Widget::initUI() left_list[13]=ui->menu_download; ui->label_show->hide(); + + // 搜索列表页 + applist_grid = new FlowLayout; } void Widget::initConfig() @@ -722,24 +727,63 @@ void Widget::searchApp(QString text) // ui->webView->setUrl(QUrl("http://www.baidu.com/s?wd="+text));//这东西对接百度 // ui->stackedWidget->setCurrentIndex(0); // 关键字搜索处理 - httpClient->get("http://192.168.0.102:8000/appinfo/search") + httpClient->get("http://192.168.0.103:8000/appinfo/search") .header("content-type", "application/json") .queryParam("keyword", text) - .onResponse([](QByteArray result) { + .onResponse([this](QByteArray result) { auto json = QJsonDocument::fromJson(result).array(); if (json.empty()) { qDebug() << "搜索不到相关应用!"; + sendNotification(tr("Not found relative App!")); return; } // TODO 展示应用 + qDebug() << json; + displaySearchApp(json); + }) .onError([](QString errorStr) { qDebug() << "请求出错:" << errorStr; }) .timeout(10 * 1000) .exec(); + } +} + +/** + * @brief 展示搜索的APP信息 + */ +void Widget::displaySearchApp(QJsonArray array) +{ + ui->stackedWidget->setCurrentIndex(4); + + // 清除原有的搜索结果 + QLayoutItem *item; + while ((item = applist_grid->takeAt(0)) != nullptr) { + item->widget()->disconnect(); + delete item->widget(); + delete item; + } + item = nullptr; + + for(int i = 0; i < array.size(); i++) + { + QJsonObject appInfo = array.at(i).toObject(); + AppItem *appItem = new AppItem(this); + QString url = QString("spk://store/%1/%2") + .arg(appInfo["category_slug"].toString()) + .arg(appInfo["pkgname"].toString()); + appItem->setTitle(appInfo["name"].toString()); + appItem->setDescription(appInfo["more"].toString()); + appItem->setIcon(appInfo["icon"].toString()); + appItem->setUrl(url); + applist_grid->addWidget(appItem); + qDebug() << "应用链接为:" << url; + connect(appItem, &AppItem::clicked, this, &Widget::openUrl); } + ui->applist_scrollarea->widget()->setLayout(applist_grid); + qDebug() << "显示结果了吗????喵喵喵"; } void Widget::httpReadyRead() diff --git a/src/widget.h b/src/widget.h index 8097c530..8cabbb47 100644 --- a/src/widget.h +++ b/src/widget.h @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -36,6 +37,8 @@ class Widget; } +class FlowLayout; + namespace AeaQt { class HttpClient; } @@ -76,6 +79,8 @@ private slots: void sltAppinfoScreenshot(QPixmap *picture, int index); void sltAppinfoFinish(); + void displaySearchApp(QJsonArray array); // 展示搜索的APP信息 + void on_pushButton_download_clicked(); void on_pushButton_return_clicked(); void on_comboBox_server_currentIndexChanged(const QString &arg1); @@ -149,6 +154,7 @@ private: SpkAppInfoLoaderThread appinfoLoadThread; AeaQt::HttpClient *httpClient; + FlowLayout *applist_grid; }; #endif // WIDGET_H diff --git a/src/widget.ui b/src/widget.ui index 0d372cb3..b6479460 100644 --- a/src/widget.ui +++ b/src/widget.ui @@ -7,7 +7,7 @@ 0 0 1053 - 697 + 711 @@ -51,1136 +51,29 @@ - - - - + + + + + 0 + 20 + - - 0 + + + + + + + 150 + 0 + - - 4 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::DefaultContextMenu - - - - about:blank - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 14 - - - - - - - 0 - - - The list is currently empty. Go and download some softwares! - - - Qt::AlignCenter - - - - - - - QFrame::NoFrame - - - QFrame::Sunken - - - 0 - - - - - - - - 16777215 - 30 - - - - Qt::NoFocus - - - Open download directory - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - 0 - - - true - - - - - 0 - 0 - 886 - 865 - - - - - 0 - - - - - - 16777215 - 350 - - - - true - - - - - - Qt::Horizontal - - - QSizePolicy::Maximum - - - - 70 - 20 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Maximum - - - - 60 - 20 - - - - - - - - Install - - - - - - - - Bitstream Charter - 22 - - - - Name - - - - - - - - true - - - - <html><head/><body><p><br/></p></body></html> - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - 128 - 128 - - - - - 128 - 128 - - - - border-radius:10px; - - - ICON - - - true - - - Qt::AlignCenter - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - Uninstall - - - - - - - - 70 - 16777215 - - - - - - - Site - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - Share - - - - - - - - 0 - 30 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 30 - 16777215 - - - - <html><head/><body><p>This app is developed by community user,we give this tag to honor those who contribute to the Linux Ecology</p></body></html> - - - <html><head/><body><p>This app is developed by community user,we give this tag to honor those who contribute to the Linux Ecology</p></body></html> - - - <html><head/><body><p><img src=":/tags/community-small.png"/></p></body></html> - - - - - - - - 30 - 16777215 - - - - <html><head/><body><p>Capable to Ubuntu 20.04</p></body></html> - - - <html><head/><body><p>Capable to Ubuntu 20.04</p></body></html> - - - <html><head/><body><p><img src=":/tags/ubuntu-small.png"/></p></body></html> - - - - - - - - 30 - 16777215 - - - - <html><head/><body><p>Capable to deepin 20</p></body></html> - - - <html><head/><body><p>Capable to deepin 20</p></body></html> - - - <html><head/><body><p><img src=":/tags/deepin-small.png"/></p></body></html> - - - - - - - - 30 - 16777215 - - - - <html><head/><body><p>Capable to UOS home 20</p></body></html> - - - <html><head/><body><p>Capable to UOS home 20</p></body></html> - - - <html><head/><body><p><img src=":/tags/uos-small.png"/></p></body></html> - - - - - - - - 30 - 16777215 - - - - <html><head/><body><p>This is a DTK5 app,which means it would have better effect on Deepin Desktop Environment</p></body></html> - - - <html><head/><body><p>This is a DTK5 app,which means it would have better effect on Deepin Desktop Environment</p></body></html> - - - <html><head/><body><p><img src=":/tags/dtk-small.png"/></p></body></html> - - - - - - - - 30 - 16777215 - - - - <html><head/><body><p>A deepin-wine2 app.If you are using ubuntu or other non-deepin distro,you should deploy deepin-wine2 by your self.</p></body></html> - - - <html><head/><body><p>A deepin-wine2 app.If you are using ubuntu or other non-deepin distro,you should deploy deepin-wine2 by your self.</p></body></html> - - - <html><head/><body><p><img src=":/tags/dwine2-small.png"/></p></body></html> - - - - - - - - 30 - 16777215 - - - - <html><head/><body><p>A deepin-wine5 app.If you are using ubuntu or other non-deepin distro,you should deploy deepin-wine5 by your self.</p></body></html> - - - <html><head/><body><p>A deepin-wine5 app.If you are using ubuntu or other non-deepin distro,you should deploy deepin-wine5 by your self.</p></body></html> - - - <html><head/><body><p><img src=":/tags/dwine5-small.png"/></p></body></html> - - - - - - - - 30 - 16777215 - - - - <html><head/><body><p>An Appimage to deb app.</p></body></html> - - - <html><head/><body><p>An Appimage to deb app.</p></body></html> - - - <html><head/><body><p><img src=":/tags/a2d-small.png"/></p></body></html> - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Contribute translation - - - - - - - - - - - - - - 14 - - - - Info - - - - - - - <html><head/><body><p>An app store developed by community enthusiasts</p></body></html> - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - - - - 0 - 370 - - - - - 16777215 - 370 - - - - - 0 - - - - - - 14 - - - - Screenshots - - - - - - - 0 - - - true - - - - - 0 - 0 - 840 - 318 - - - - - - - - 0 - 0 - - - - - 400 - 16777215 - - - - - - - - - 400 - 16777215 - - - - - - - - - 400 - 16777215 - - - - - - - - - 400 - 16777215 - - - - - - - - - 400 - 16777215 - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - Qt::AlignCenter - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - QFrame::NoFrame - - - 0 - - - true - - - - - 0 - 0 - 886 - 921 - - - - - - - - - - - 18 - - - - Line Settings - - - - - - - - - - - 100 - 16777215 - - - - Choose Line: - - - - - - - - 300 - 0 - - - - - 300 - 16777215 - - - - - - - - Refresh - - - - - - - - 160 - 16777215 - - - - Take effect when restart - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - color:#808080 - - - <html><head/><body><p>The role of the source server is to ensure that the software is updated, and supports the use of the apt tool to get the software. We usually prefer that you use the first line as the update source, which is generally the most stable. </p></body></html> - - - true - - - - - - - Update - - - - - - - Source Server - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Server - - - - - - - - - - - - - - - - - 18 - - - - Temp - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Clean - - - - - - - color:#808080 - - - Since the dictionary is at /tmp,It would be cleaned automatically when system reboot. - - - - - - - - 80 - 16777215 - - - - Size: - - - - - - - 0B - - - - - - - Location:/tmp/spark-store - - - - - - - - - - - - - - - - - 18 - - - - About us - - - - - - - <html><head/><body><p>We are <span style=" font-weight:600;">NOT</span> the official team, just like you, we are just one of the many Linux/deepin system enthusiasts and users, we develop and run the &quot;Spark Store&quot;! &quot;, is to bring the community together to share useful software, or to participate in development together, so that we all use the latest and greatest software. </p><p>We don't make a profit from this, all developers and maintainers don't get paid, and we rely on the community's donations to us for most of our expenses, which we are grateful for and which allow us not to spend too much energy worrying about funding. </p><p>Our service and software are free for everyone to use, communicate, and learn, but you must comply with local laws and regulations in the process of your use, otherwise any problems have nothing to do with us. </p><p>If any part of the store infringes your rights, please tell us &lt;jifengshenmo@outlook.com&gt; we will remove the infringing content as soon as possible. </p><p>If you'd like to get involved with us too, whether you're involved in development, design, pitching or submitting work, we welcome you to join us. </p><p>QQ group:872690351<br/></p></body></html> - - - true - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - 0 - 0 - 903 - 667 - - - - 1 - - - - - - 250 - 210 - 231 - 121 - - - - Not found applist info! - - - - - - - - 0 - 0 - 903 - 667 - - - - true - - - - - 0 - 0 - 901 - 665 - - - - - - - - - - - - - - 0 - 20 - - - - - - - - - 150 - 0 - - - - - 150 - 16777215 - + + + 150 + 16777215 + @@ -1321,7 +214,7 @@ - + :/icons/icons/refresh-page.svg:/icons/icons/refresh-page.svg @@ -1348,7 +241,7 @@ - + :/icons/icons/category_active.svg:/icons/icons/category_active.svg @@ -1443,6 +336,1079 @@ + + + + + + + 0 + + + 4 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::DefaultContextMenu + + + + about:blank + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 14 + + + + + + + 0 + + + The list is currently empty. Go and download some softwares! + + + Qt::AlignCenter + + + + + + + QFrame::NoFrame + + + QFrame::Sunken + + + 0 + + + + + + + + 16777215 + 30 + + + + Qt::NoFocus + + + Open download directory + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + true + + + + + 0 + 0 + 655 + 865 + + + + + 0 + + + + + + 16777215 + 350 + + + + true + + + + + + Qt::Horizontal + + + QSizePolicy::Maximum + + + + 70 + 20 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Maximum + + + + 60 + 20 + + + + + + + + Install + + + + + + + + Bitstream Charter + 22 + + + + Name + + + + + + + + true + + + + <html><head/><body><p><br/></p></body></html> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + 128 + 128 + + + + + 128 + 128 + + + + border-radius:10px; + + + ICON + + + true + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Uninstall + + + + + + + + 70 + 16777215 + + + + + + + Site + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + Share + + + + + + + + 0 + 30 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 30 + 16777215 + + + + <html><head/><body><p>This app is developed by community user,we give this tag to honor those who contribute to the Linux Ecology</p></body></html> + + + <html><head/><body><p>This app is developed by community user,we give this tag to honor those who contribute to the Linux Ecology</p></body></html> + + + <html><head/><body><p><img src=":/tags/community-small.png"/></p></body></html> + + + + + + + + 30 + 16777215 + + + + <html><head/><body><p>Capable to Ubuntu 20.04</p></body></html> + + + <html><head/><body><p>Capable to Ubuntu 20.04</p></body></html> + + + <html><head/><body><p><img src=":/tags/ubuntu-small.png"/></p></body></html> + + + + + + + + 30 + 16777215 + + + + <html><head/><body><p>Capable to deepin 20</p></body></html> + + + <html><head/><body><p>Capable to deepin 20</p></body></html> + + + <html><head/><body><p><img src=":/tags/deepin-small.png"/></p></body></html> + + + + + + + + 30 + 16777215 + + + + <html><head/><body><p>Capable to UOS home 20</p></body></html> + + + <html><head/><body><p>Capable to UOS home 20</p></body></html> + + + <html><head/><body><p><img src=":/tags/uos-small.png"/></p></body></html> + + + + + + + + 30 + 16777215 + + + + <html><head/><body><p>This is a DTK5 app,which means it would have better effect on Deepin Desktop Environment</p></body></html> + + + <html><head/><body><p>This is a DTK5 app,which means it would have better effect on Deepin Desktop Environment</p></body></html> + + + <html><head/><body><p><img src=":/tags/dtk-small.png"/></p></body></html> + + + + + + + + 30 + 16777215 + + + + <html><head/><body><p>A deepin-wine2 app.If you are using ubuntu or other non-deepin distro,you should deploy deepin-wine2 by your self.</p></body></html> + + + <html><head/><body><p>A deepin-wine2 app.If you are using ubuntu or other non-deepin distro,you should deploy deepin-wine2 by your self.</p></body></html> + + + <html><head/><body><p><img src=":/tags/dwine2-small.png"/></p></body></html> + + + + + + + + 30 + 16777215 + + + + <html><head/><body><p>A deepin-wine5 app.If you are using ubuntu or other non-deepin distro,you should deploy deepin-wine5 by your self.</p></body></html> + + + <html><head/><body><p>A deepin-wine5 app.If you are using ubuntu or other non-deepin distro,you should deploy deepin-wine5 by your self.</p></body></html> + + + <html><head/><body><p><img src=":/tags/dwine5-small.png"/></p></body></html> + + + + + + + + 30 + 16777215 + + + + <html><head/><body><p>An Appimage to deb app.</p></body></html> + + + <html><head/><body><p>An Appimage to deb app.</p></body></html> + + + <html><head/><body><p><img src=":/tags/a2d-small.png"/></p></body></html> + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Contribute translation + + + + + + + + + + + + + + 14 + + + + Info + + + + + + + <html><head/><body><p>An app store developed by community enthusiasts</p></body></html> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + + + + 0 + 370 + + + + + 16777215 + 370 + + + + + 0 + + + + + + 14 + + + + Screenshots + + + + + + + 0 + + + true + + + + + 0 + 0 + 609 + 318 + + + + + + + + 0 + 0 + + + + + 400 + 16777215 + + + + + + + + + 400 + 16777215 + + + + + + + + + 400 + 16777215 + + + + + + + + + 400 + 16777215 + + + + + + + + + 400 + 16777215 + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + Qt::AlignCenter + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + QFrame::NoFrame + + + 0 + + + true + + + + + 0 + 0 + 808 + 941 + + + + + + + + + + + 18 + + + + Line Settings + + + + + + + + + + + 100 + 16777215 + + + + Choose Line: + + + + + + + + 300 + 0 + + + + + 300 + 16777215 + + + + + + + + Refresh + + + + + + + + 160 + 16777215 + + + + Take effect when restart + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + color:#808080 + + + <html><head/><body><p>The role of the source server is to ensure that the software is updated, and supports the use of the apt tool to get the software. We usually prefer that you use the first line as the update source, which is generally the most stable. </p></body></html> + + + true + + + + + + + Update + + + + + + + Source Server + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Server + + + + + + + + + + + + + + + + + 18 + + + + Temp + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Clean + + + + + + + color:#808080 + + + Since the dictionary is at /tmp,It would be cleaned automatically when system reboot. + + + + + + + + 80 + 16777215 + + + + Size: + + + + + + + 0B + + + + + + + Location:/tmp/spark-store + + + + + + + + + + + + + + + + + 18 + + + + About us + + + + + + + <html><head/><body><p>We are <span style=" font-weight:600;">NOT</span> the official team, just like you, we are just one of the many Linux/deepin system enthusiasts and users, we develop and run the &quot;Spark Store&quot;! &quot;, is to bring the community together to share useful software, or to participate in development together, so that we all use the latest and greatest software. </p><p>We don't make a profit from this, all developers and maintainers don't get paid, and we rely on the community's donations to us for most of our expenses, which we are grateful for and which allow us not to spend too much energy worrying about funding. </p><p>Our service and software are free for everyone to use, communicate, and learn, but you must comply with local laws and regulations in the process of your use, otherwise any problems have nothing to do with us. </p><p>If any part of the store infringes your rights, please tell us &lt;jifengshenmo@outlook.com&gt; we will remove the infringing content as soon as possible. </p><p>If you'd like to get involved with us too, whether you're involved in development, design, pitching or submitting work, we welcome you to join us. </p><p>QQ group:872690351<br/></p></body></html> + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + true + + + + + 0 + 0 + 879 + 657 + + + + + + + + + @@ -1471,7 +1437,7 @@ - + -- Gitee From 736ede0742ea535893b714c27afa5a9e73081ecd Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Sun, 29 Nov 2020 22:25:20 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E6=9B=B4=E6=96=B0appitem=E7=9A=84?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appitem.cpp | 2 ++ src/appitem.ui | 27 +++++++++++++++++++++++++-- src/widget.ui | 10 +++++----- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/appitem.cpp b/src/appitem.cpp index 384cbd12..d3698c5f 100644 --- a/src/appitem.cpp +++ b/src/appitem.cpp @@ -43,6 +43,7 @@ void AppItem::setUrl(QString url) void AppItem::mousePressEvent(QMouseEvent *event) { + Q_UNUSED(event); emit clicked(QUrl(m_url)); } @@ -62,6 +63,7 @@ void AppItem::downloadIcon(QString icon) 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)); diff --git a/src/appitem.ui b/src/appitem.ui index decbdba3..99629224 100644 --- a/src/appitem.ui +++ b/src/appitem.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 300 + 100 @@ -16,6 +16,17 @@ + + + 100 + 100 + + + + width: 78px; +height: 70px; +padding: 10px; + @@ -25,6 +36,12 @@ + + + 200 + 50 + + @@ -32,6 +49,12 @@ + + + 200 + 50 + + diff --git a/src/widget.ui b/src/widget.ui index b6479460..fe7edd5a 100644 --- a/src/widget.ui +++ b/src/widget.ui @@ -345,7 +345,7 @@ 0 - 4 + 3 @@ -489,7 +489,7 @@ 0 0 - 655 + 886 865 @@ -984,7 +984,7 @@ 0 0 - 609 + 840 318 @@ -1114,8 +1114,8 @@ 0 0 - 808 - 941 + 886 + 921 -- Gitee From 4315f040234fa1c51a5471513b777b4e70b677dc Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Mon, 30 Nov 2020 22:44:25 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E5=9B=BE=E6=A0=87=E9=94=AF=E9=BD=BF=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appitem.cpp | 5 ++++- src/appitem.ui | 50 +++++++++++++++++++++++++++++++++++++++++++++++-- src/widget.cpp | 1 - src/widget.ui | 6 +++--- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/appitem.cpp b/src/appitem.cpp index d3698c5f..6a3a09d9 100644 --- a/src/appitem.cpp +++ b/src/appitem.cpp @@ -5,6 +5,7 @@ #include #include #include +#include AppItem::AppItem(QWidget *parent) : QWidget(parent), @@ -63,6 +64,7 @@ void AppItem::downloadIcon(QString icon) reqManager->deleteLater(); QPixmap pixmap; pixmap.loadFromData(reply->readAll()); + qDebug() << "图标下载完毕:" << pixmap; pixmap = pixmap.scaled(78, 78, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); if (reply->error() == QNetworkReply::NoError) { QMetaObject::invokeMethod(this, "loadIcon", Qt::QueuedConnection, @@ -73,6 +75,7 @@ void AppItem::downloadIcon(QString icon) void AppItem::loadIcon(QPixmap pic) { - qDebug() << pic; ui->lbl_icon->setPixmap(pic); } + + diff --git a/src/appitem.ui b/src/appitem.ui index 99629224..c65088cb 100644 --- a/src/appitem.ui +++ b/src/appitem.ui @@ -6,13 +6,44 @@ 0 0 - 300 - 100 + 331 + 131 Form + + QWidget#AppItem { + width: 300px; + height: 100px; + margin: 15px; + color: #6d6d6d; + border-radius: 18px; + background-color: #F4F4F6; +} + +QLabel#lbl_icon { + background: transparent; + border-radius: 10px; +} + +QLabel#lbl_title { + text-align: left; + font-weight: lighter; + white-space: nowrap; + padding-right: 10px; + font-size: 19px; +} + +QLabel#lbl_desc { + text-align: left; + font-weight: lighter; + white-space: nowrap; + font-size: 12px; + color: grey; +} + @@ -30,6 +61,9 @@ padding: 10px; + + true + @@ -42,6 +76,12 @@ padding: 10px; 50 + + + 200 + 50 + + @@ -55,6 +95,12 @@ padding: 10px; 50 + + + 200 + 50 + + diff --git a/src/widget.cpp b/src/widget.cpp index e6cec2fe..d6354132 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -312,7 +312,6 @@ void Widget::setTheme(bool isDark,QColor color) if(ui->stackedWidget->currentIndex()==0){ chooseLeftMenu(nowMenu); } - } DTitlebar* Widget::getTitlebar() diff --git a/src/widget.ui b/src/widget.ui index fe7edd5a..89fe46b4 100644 --- a/src/widget.ui +++ b/src/widget.ui @@ -345,7 +345,7 @@ 0 - 3 + 2 @@ -1398,8 +1398,8 @@ 0 0 - 879 - 657 + 98 + 28 -- Gitee From 91fcab56df16d6509574e16752f07a260db83577 Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Tue, 1 Dec 2020 22:10:52 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appitem.cpp | 19 +++++- src/appitem.ui | 169 ++++++++++++++++++++++++++++++------------------ src/widget.cpp | 2 + src/widget.ui | 9 ++- 4 files changed, 132 insertions(+), 67 deletions(-) diff --git a/src/appitem.cpp b/src/appitem.cpp index 6a3a09d9..a004fedf 100644 --- a/src/appitem.cpp +++ b/src/appitem.cpp @@ -6,12 +6,20 @@ #include #include #include +#include AppItem::AppItem(QWidget *parent) : QWidget(parent), ui(new Ui::AppItem) { 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); } AppItem::~AppItem() @@ -28,13 +36,19 @@ void AppItem::setTitle(QString title) void AppItem::setDescription(QString description) { m_description = description; - ui->lbl_desc->setText(description); + QString elidedText = ui->lbl_desc->fontMetrics().elidedText( + description, Qt::ElideRight, + ui->lbl_desc->width(), Qt::TextShowMnemonic); + ui->lbl_desc->setText(elidedText); + ui->lbl_desc->setAlignment(Qt::AlignTop); } void AppItem::setIcon(QString icon) { m_icon = icon; - downloadIcon(icon); + if (!icon.isEmpty()) { + downloadIcon(icon); + } } void AppItem::setUrl(QString url) @@ -65,6 +79,7 @@ void AppItem::downloadIcon(QString icon) QPixmap pixmap; pixmap.loadFromData(reply->readAll()); qDebug() << "图标下载完毕:" << pixmap; + qDebug() << icon << "响应有报错吗?" << reply->errorString(); pixmap = pixmap.scaled(78, 78, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); if (reply->error() == QNetworkReply::NoError) { QMetaObject::invokeMethod(this, "loadIcon", Qt::QueuedConnection, diff --git a/src/appitem.ui b/src/appitem.ui index c65088cb..718e1e74 100644 --- a/src/appitem.ui +++ b/src/appitem.ui @@ -6,8 +6,8 @@ 0 0 - 331 - 131 + 333 + 133 @@ -20,6 +20,15 @@ margin: 15px; color: #6d6d6d; border-radius: 18px; + background-color: width: 300px; + height: 100px; + margin: 15px; + color: #6d6d6d; + border-radius: 18px; + background-color: #F4F4F6; +} + +QWidget#container { background-color: #F4F4F6; } @@ -30,10 +39,10 @@ QLabel#lbl_icon { QLabel#lbl_title { text-align: left; - font-weight: lighter; white-space: nowrap; padding-right: 10px; font-size: 19px; + } QLabel#lbl_desc { @@ -44,70 +53,106 @@ QLabel#lbl_desc { color: grey; } - + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + - - - - 100 - 100 - - - - width: 78px; + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 100 + 100 + + + + width: 78px; height: 70px; padding: 10px; - - - - - - true - + + + + + + true + + + + + + + + + + 200 + 50 + + + + + 200 + 50 + + + + + + + + + + + + 200 + 50 + + + + + 200 + 50 + + + + + + + + + + - - - - - - - 200 - 50 - - - - - 200 - 50 - - - - - - - - - - - - 200 - 50 - - - - - 200 - 50 - - - - - - - - - diff --git a/src/widget.cpp b/src/widget.cpp index d6354132..5bad22f1 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -725,6 +725,7 @@ void Widget::searchApp(QString text) // sendNotification(tr("Spark store could only process spk:// links for now. The search feature is coming soon!")); // ui->webView->setUrl(QUrl("http://www.baidu.com/s?wd="+text));//这东西对接百度 // ui->stackedWidget->setCurrentIndex(0); + // 关键字搜索处理 httpClient->get("http://192.168.0.103:8000/appinfo/search") .header("content-type", "application/json") @@ -743,6 +744,7 @@ void Widget::searchApp(QString text) }) .onError([](QString errorStr) { qDebug() << "请求出错:" << errorStr; + sendNotification(QString("请求出错:%1").arg(errorStr)); }) .timeout(10 * 1000) .exec(); diff --git a/src/widget.ui b/src/widget.ui index 89fe46b4..81667d3f 100644 --- a/src/widget.ui +++ b/src/widget.ui @@ -345,7 +345,7 @@ 0 - 2 + 3 @@ -1390,6 +1390,9 @@ + + QFrame::NoFrame + true @@ -1398,8 +1401,8 @@ 0 0 - 98 - 28 + 881 + 659 -- Gitee From 7a5b982deaf25bc3ae165aaaf6b85cf9810023f8 Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Wed, 2 Dec 2020 22:22:59 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=B8=BA=E7=BA=BF=E4=B8=8A=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/widget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget.cpp b/src/widget.cpp index 5bad22f1..6057a53f 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -727,7 +727,7 @@ void Widget::searchApp(QString text) // ui->stackedWidget->setCurrentIndex(0); // 关键字搜索处理 - httpClient->get("http://192.168.0.103:8000/appinfo/search") + httpClient->get("http://spark-store-api.metanoia1989.com/appinfo/search") .header("content-type", "application/json") .queryParam("keyword", text) .onResponse([this](QByteArray result) { -- Gitee From 1d0e0cc65ca5dfd66c10d9e8363c5a55e75875f9 Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Sat, 5 Dec 2020 13:53:13 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=9F=9F=E5=90=8D=E4=B8=BA=E6=98=9F?= =?UTF-8?q?=E7=81=AB=E7=9A=84=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appitem.cpp | 4 ++-- src/appitem.h | 1 - src/widget.cpp | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/appitem.cpp b/src/appitem.cpp index a004fedf..85afa3ae 100644 --- a/src/appitem.cpp +++ b/src/appitem.cpp @@ -78,12 +78,12 @@ void AppItem::downloadIcon(QString icon) reqManager->deleteLater(); QPixmap pixmap; pixmap.loadFromData(reply->readAll()); - qDebug() << "图标下载完毕:" << pixmap; - qDebug() << icon << "响应有报错吗?" << reply->errorString(); 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(); } }); } diff --git a/src/appitem.h b/src/appitem.h index f7b2e564..3aa0f823 100644 --- a/src/appitem.h +++ b/src/appitem.h @@ -37,7 +37,6 @@ private: QString m_title; QString m_description; QString m_icon; - QString m_pkgname; QString m_url; }; diff --git a/src/widget.cpp b/src/widget.cpp index 6057a53f..2a771818 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -727,7 +727,7 @@ void Widget::searchApp(QString text) // ui->stackedWidget->setCurrentIndex(0); // 关键字搜索处理 - httpClient->get("http://spark-store-api.metanoia1989.com/appinfo/search") + httpClient->get("http://search.deepinos.org.cn/appinfo/search") .header("content-type", "application/json") .queryParam("keyword", text) .onResponse([this](QByteArray result) { @@ -737,8 +737,6 @@ void Widget::searchApp(QString text) sendNotification(tr("Not found relative App!")); return; } - // TODO 展示应用 - qDebug() << json; displaySearchApp(json); }) -- Gitee From e28d1c39ac8d709dadc5f29fe0eb0bc832d1b9cd Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Tue, 8 Dec 2020 23:31:40 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E4=B8=8D=E9=87=8D=E6=96=B0=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/widget.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/widget.cpp b/src/widget.cpp index b7de290f..c2022e51 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -484,6 +484,11 @@ void Widget::chooseLeftMenu(int index) }else if (index==13) { ui->stackedWidget->setCurrentIndex(1); } + + // 菜单切换时,清除搜索栏的内容 + if (!searchEdit->text().isEmpty()) { + searchEdit->clear(); + } } void Widget::setfoot(int h) @@ -732,7 +737,7 @@ void Widget::searchApp(QString text) return; // 关键字搜索处理 - httpClient->get("http://search.deepinos.org.cn/appinfo/search") + httpClient->get("https://search.deepinos.org.cn/appinfo/search") .header("content-type", "application/json") .queryParam("keyword", text) .onResponse([this](QByteArray result) { @@ -803,7 +808,6 @@ void Widget::downloadIconsFinished(int arraysize) mutex.unlock(); } ui->applist_scrollarea->widget()->setLayout(applist_grid); - qDebug() << "显示结果了吗????喵喵喵"; } void Widget::httpReadyRead() @@ -968,7 +972,10 @@ void Widget::on_pushButton_return_clicked() // return; // } appinfoLoadThread.requestInterruption(); - chooseLeftMenu(nowMenu); + ui->stackedWidget->setCurrentIndex(0); + // TODO 添加 QWebEngineViewHistory 实现上一页功能 + + // chooseLeftMenu(nowMenu); // if(themeIsDark){ // QString darkurl=menuUrl[nowMenu].toString(); // QStringList tmp=darkurl.split("/"); -- Gitee From 3e473c091abf102120a29c918e7a1a9ae6deb387 Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Thu, 10 Dec 2020 21:31:53 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BB=8E=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E8=BF=94=E5=9B=9E=E5=88=97=E8=A1=A8=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E8=BF=9B=E5=BA=A6=E6=81=A2=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/widget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget.cpp b/src/widget.cpp index c2022e51..02b8e2fa 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -972,8 +972,8 @@ void Widget::on_pushButton_return_clicked() // return; // } appinfoLoadThread.requestInterruption(); + ui->webEngineView->back(); ui->stackedWidget->setCurrentIndex(0); - // TODO 添加 QWebEngineViewHistory 实现上一页功能 // chooseLeftMenu(nowMenu); // if(themeIsDark){ -- Gitee From ab88af006b107c97d32d8e6c8ae33410dc320ed2 Mon Sep 17 00:00:00 2001 From: metanoia1989 Date: Thu, 10 Dec 2020 22:46:55 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=BA=94=E7=94=A8=E9=87=8D=E5=A4=8D=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E8=BF=9B=E5=85=A5=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/widget.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/widget.cpp b/src/widget.cpp index 02b8e2fa..55006b82 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -73,7 +73,8 @@ Widget::Widget(DBlurEffectWidget *parent) : connect(&appinfoLoadThread, &SpkAppInfoLoaderThread::finishAllLoading, this, &Widget::sltAppinfoFinish, Qt::ConnectionType::BlockingQueuedConnection); // 搜索事件 - connect(searchEdit,&DSearchEdit::editingFinished,this,[=](){ + connect(searchEdit,&DSearchEdit::returnPressed ,this,[=](){ + qDebug() << "触发了搜索,呜啦啦啦!"; QString searchtext=searchEdit->text(); if(searchtext!=""){ qDebug()<text(); @@ -458,6 +459,11 @@ void Widget::chooseLeftMenu(int index) { nowMenu=index; + // 菜单切换时,清除搜索栏的内容 + if (!searchEdit->text().isEmpty()) { + searchEdit->clear(); + } + updateUI(); if(QLocale::system().name() == "zh_CN") left_list[index]->setStyleSheet("color:#FFFFFF;background-color:"+main_color.name()+";border-radius:8;border:0px;"); @@ -485,10 +491,6 @@ void Widget::chooseLeftMenu(int index) ui->stackedWidget->setCurrentIndex(1); } - // 菜单切换时,清除搜索栏的内容 - if (!searchEdit->text().isEmpty()) { - searchEdit->clear(); - } } void Widget::setfoot(int h) @@ -972,8 +974,15 @@ void Widget::on_pushButton_return_clicked() // return; // } appinfoLoadThread.requestInterruption(); - ui->webEngineView->back(); - ui->stackedWidget->setCurrentIndex(0); + + // 检测是否是从搜索页面进入到应用详情页的,根据搜索栏是否有关键词判断 + if (searchEdit->text().isEmpty()) { + ui->webEngineView->back(); + ui->stackedWidget->setCurrentIndex(0); + } else { + ui->stackedWidget->setCurrentIndex(4); + } + // chooseLeftMenu(nowMenu); // if(themeIsDark){ @@ -1180,7 +1189,8 @@ void Widget::opensetting() void Widget::openUrl(QUrl u) { QString app=serverUrl + "store"+u.path()+"/app.json"; - ui->webEngineView->setUrl(app); +// ui->webEngineView->setUrl(app); + emit ui->webEngineView->urlChanged(app); } void Widget::on_pushButton_website_clicked() -- Gitee