debugging
This commit is contained in:
parent
6e16292f06
commit
27124380e4
33
API/api.cpp
33
API/api.cpp
@ -290,7 +290,8 @@ void API::addAsset(const QString& title, const QString& icon, const QJSValue &fi
|
|||||||
request.setRawHeader("Authorization", "Bearer " + accessToken.toUtf8());
|
request.setRawHeader("Authorization", "Bearer " + accessToken.toUtf8());
|
||||||
QNetworkReply* reply = network.post(request, params.toString(QUrl::FullyEncoded).toUtf8());
|
QNetworkReply* reply = network.post(request, params.toString(QUrl::FullyEncoded).toUtf8());
|
||||||
connect(reply, &QNetworkReply::finished,
|
connect(reply, &QNetworkReply::finished,
|
||||||
std::bind(&API::onAssetAdded, this, reply, finished)
|
this, std::bind(&API::onAssetAdded, this, reply, finished),
|
||||||
|
Qt::QueuedConnection
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,17 +314,15 @@ void API::sendPoll(bool clear) {
|
|||||||
if (clear)
|
if (clear)
|
||||||
url.setQuery(QUrlQuery({{"clearCache", "all"}}));
|
url.setQuery(QUrlQuery({{"clearCache", "all"}}));
|
||||||
|
|
||||||
QByteArray authorizationHeader = "Bearer " + accessToken.toUtf8();
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, json);
|
request.setHeader(QNetworkRequest::ContentTypeHeader, json);
|
||||||
request.setRawHeader("Authorization", authorizationHeader);
|
request.setRawHeader("Authorization", "Bearer " + accessToken.toUtf8());
|
||||||
request.setTransferTimeout(30000);
|
request.setTransferTimeout(30000);
|
||||||
|
|
||||||
pollReply = std::unique_ptr<QNetworkReply>(network.get(request));
|
pollReply = std::unique_ptr<QNetworkReply>(network.get(request));
|
||||||
connect(
|
connect(
|
||||||
pollReply.get(), &QNetworkReply::finished,
|
pollReply.get(), &QNetworkReply::finished,
|
||||||
this, &API::onPollFinished,
|
this, &API::onPollFinished, Qt::QueuedConnection
|
||||||
Qt::QueuedConnection
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,10 +370,8 @@ void API::onPollFinished() {
|
|||||||
|
|
||||||
bool API::handleChanges(const QVariantMap& changes) {
|
bool API::handleChanges(const QVariantMap& changes) {
|
||||||
QVariantMap::ConstIterator itr = changes.constFind("system");
|
QVariantMap::ConstIterator itr = changes.constFind("system");
|
||||||
if (itr != changes.constEnd()) {
|
if (itr != changes.constEnd() && itr.value().canConvert<QVariantMap>()) {
|
||||||
const QVariant& vsys = itr.value();
|
const QVariantMap& sys = qast<QVariantMap>(itr.value());
|
||||||
if (vsys.canConvert<QVariantMap>()) {
|
|
||||||
const QVariantMap& sys = qast<QVariantMap>(vsys);
|
|
||||||
QVariantMap::ConstIterator invItr = sys.constFind("invalidate");
|
QVariantMap::ConstIterator invItr = sys.constFind("invalidate");
|
||||||
if (invItr != sys.constEnd()) {
|
if (invItr != sys.constEnd()) {
|
||||||
const QVariant& vinv = invItr.value();
|
const QVariant& vinv = invItr.value();
|
||||||
@ -382,13 +379,10 @@ bool API::handleChanges(const QVariantMap& changes) {
|
|||||||
resetAllModels();
|
resetAllModels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
itr = changes.constFind("assets");
|
itr = changes.constFind("assets");
|
||||||
if (itr != changes.constEnd()) {
|
if (itr != changes.constEnd() && itr.value().canConvert<QVariantMap>()) {
|
||||||
const QVariant& vassets = itr.value();
|
const QVariantMap& assets = qast<QVariantMap>(itr.value());
|
||||||
if (vassets.canConvert<QVariantMap>()) {
|
|
||||||
const QVariantMap& assets = qast<QVariantMap>(vassets);
|
|
||||||
QVariantMap::ConstIterator aItr = assets.constFind("invalidate");
|
QVariantMap::ConstIterator aItr = assets.constFind("invalidate");
|
||||||
if (aItr != assets.constEnd()) {
|
if (aItr != assets.constEnd()) {
|
||||||
const QVariant& vinv = aItr.value();
|
const QVariant& vinv = aItr.value();
|
||||||
@ -397,16 +391,14 @@ bool API::handleChanges(const QVariantMap& changes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
aItr = assets.constFind("added");
|
aItr = assets.constFind("added");
|
||||||
if (aItr != assets.constEnd()) {
|
if (aItr != assets.constEnd() && aItr.value().canConvert<QVariantList>()) {
|
||||||
const QVariant& vadd = aItr.value();
|
|
||||||
std::deque<Models::Asset> added;
|
std::deque<Models::Asset> added;
|
||||||
if (!Models::Assets::deserialize(qast<QVariantList>(itr.value()), added))
|
if (!Models::Assets::deserialize(qast<QVariantList>(aItr.value()), added))
|
||||||
qDebug() << "Error deserializng added assets";
|
qDebug() << "Error deserializng added assets";
|
||||||
else
|
else
|
||||||
API::assets.addAssets(added);
|
API::assets.addAssets(added);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -428,14 +420,13 @@ void API::requestAssets() {
|
|||||||
qDebug() << "Requesting assets...";
|
qDebug() << "Requesting assets...";
|
||||||
|
|
||||||
QUrl url = createUrl("/listAssets");
|
QUrl url = createUrl("/listAssets");
|
||||||
QByteArray authorizationHeader = "Bearer " + accessToken.toUtf8();
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, json);
|
request.setHeader(QNetworkRequest::ContentTypeHeader, json);
|
||||||
request.setRawHeader("Authorization", authorizationHeader);
|
request.setRawHeader("Authorization", "Bearer " + accessToken.toUtf8());
|
||||||
|
|
||||||
QNetworkReply* reply = network.get(request);
|
QNetworkReply* reply = network.get(request);
|
||||||
connect(
|
connect(
|
||||||
pollReply.get(), &QNetworkReply::finished,
|
reply, &QNetworkReply::finished,
|
||||||
this, std::bind(&API::responseAssets, this, reply)
|
this, std::bind(&API::responseAssets, this, reply)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,7 @@ void Models::Assets::fetchMore (const QModelIndex& parent) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
state = State::requesting;
|
state = State::requesting;
|
||||||
|
emit requestAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Models::Assets::data (const QModelIndex& index, int role) const {
|
QVariant Models::Assets::data (const QModelIndex& index, int role) const {
|
||||||
@ -116,7 +117,7 @@ bool Models::Assets::deserialize (const QVariantList& from, std::deque<Asset>& o
|
|||||||
asset.title = ser.value("title").toString();
|
asset.title = ser.value("title").toString();
|
||||||
asset.icon = ser.value("icon").toString();
|
asset.icon = ser.value("icon").toString();
|
||||||
asset.archived = ser.value("archived").toBool();
|
asset.archived = ser.value("archived").toBool();
|
||||||
asset.id = ser.value("archived").toUInt();
|
asset.id = ser.value("id").toUInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -22,6 +22,7 @@ struct Asset {
|
|||||||
class Assets : public QAbstractListModel {
|
class Assets : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
QML_SINGLETON
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Assets (QObject* parent = nullptr);
|
explicit Assets (QObject* parent = nullptr);
|
||||||
|
@ -3,16 +3,20 @@
|
|||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Layouts
|
||||||
|
|
||||||
import magpie.API
|
import magpie.Models as Models
|
||||||
|
import magpie.Components as Components
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
signal add
|
signal add
|
||||||
|
|
||||||
Column {
|
ColumnLayout {
|
||||||
|
id: column
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
|
id: label
|
||||||
text: "This is Assets screen"
|
text: "This is Assets screen"
|
||||||
font {
|
font {
|
||||||
pixelSize: 24
|
pixelSize: 24
|
||||||
@ -21,12 +25,12 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
anchors.centerIn: parent
|
id: listView
|
||||||
model: API.assets
|
Layout.fillHeight: true
|
||||||
delegate: Rectangle {
|
Layout.fillWidth: true
|
||||||
Text {
|
model: Models.Assets
|
||||||
text: title
|
delegate: Components.AssetLine {
|
||||||
}
|
height: 20
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
qml/Components/AssetLine.qml
Normal file
26
qml/Components/AssetLine.qml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: line
|
||||||
|
required property string title
|
||||||
|
required property string icon
|
||||||
|
|
||||||
|
Row {
|
||||||
|
anchors.fill: parent
|
||||||
|
IconLabel {
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
icon.name: line.icon
|
||||||
|
width: parent.height
|
||||||
|
height: parent.height
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
text: title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ qt_add_qml_module(magpieComponents
|
|||||||
NO_PLUGIN
|
NO_PLUGIN
|
||||||
QML_FILES
|
QML_FILES
|
||||||
Modal.qml
|
Modal.qml
|
||||||
|
AssetLine.qml
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(magpie PRIVATE magpieComponents)
|
target_link_libraries(magpie PRIVATE magpieComponents)
|
||||||
|
@ -66,7 +66,7 @@ Item {
|
|||||||
|
|
||||||
Button {
|
Button {
|
||||||
text: qsTr("Create")
|
text: qsTr("Create")
|
||||||
onClicked: inner.send(titleField.text, titleField.text, colorField.text)
|
onClicked: inner.send(titleField.text, iconField.text, colorField.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ Item {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
titleField.text = title;
|
titleField.text = title;
|
||||||
titleField.text = icon;
|
iconField.text = icon;
|
||||||
colorField.text = color;
|
colorField.text = color;
|
||||||
|
|
||||||
modal.inProgress = true;
|
modal.inProgress = true;
|
||||||
|
6
root.cpp
6
root.cpp
@ -38,9 +38,9 @@ Root::Root(const QUrl& root, int& argc, char* argv[]) :
|
|||||||
connect(&api, &API::addressChanged, this, &Root::onAPIAddressChanged);
|
connect(&api, &API::addressChanged, this, &Root::onAPIAddressChanged);
|
||||||
connect(&api, &API::storeTokens, this, &Root::onStoreTokens);
|
connect(&api, &API::storeTokens, this, &Root::onStoreTokens);
|
||||||
|
|
||||||
qmlRegisterSingletonType<API>("magpie.API", 1, 0, "API", [this] (QQmlEngine *engine, QJSEngine *scriptEngine) {
|
qmlRegisterSingletonInstance("magpie.API", 1, 0, "API", &api);
|
||||||
return &api;
|
|
||||||
});
|
qmlRegisterSingletonInstance("magpie.Models", 1, 0, "Assets", &api.assets);
|
||||||
|
|
||||||
engine.addImportPath(":/");
|
engine.addImportPath(":/");
|
||||||
engine.load(root);
|
engine.load(root);
|
||||||
|
Loading…
Reference in New Issue
Block a user