From 47ed45a3cccac1467445dcdeaa487fa9db2f2da9 Mon Sep 17 00:00:00 2001 From: Scharel Clemens Date: Fri, 29 May 2020 17:46:46 +0200 Subject: [PATCH] Began implementing OCS capabilities --- src/notesapi.cpp | 50 +++++++++++++++++++++++++++++++++++++++--------- src/notesapi.h | 5 +++-- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/notesapi.cpp b/src/notesapi.cpp index a1e4319..dfefc68 100644 --- a/src/notesapi.cpp +++ b/src/notesapi.cpp @@ -491,6 +491,47 @@ QUrl NotesApi::apiEndpointUrl(const QString endpoint) const { return url; } +bool NotesApi::updateCapabilities(const QJsonObject &capabilities) { + QJsonValue ocsValue = capabilities.value("ocs"); + if (!ocsValue.isUndefined() && ocsValue.isObject()) { + QJsonObject ocsObject = ocsValue.toObject(); + QJsonValue metaValue = ocsObject.value("meta"); + if (!metaValue.isUndefined() && metaValue.isObject()) { + QJsonObject metaObject = metaValue.toObject(); + if (metaObject.value("status").toString() == "ok") { + QJsonValue dataValue = ocsObject.value("data"); + if (!dataValue.isUndefined() && dataValue.isObject()) { + QJsonObject dataObject = dataValue.toObject(); + QJsonValue capabilitiesValue = dataObject.value("capabilities"); + if (!capabilitiesValue.isUndefined() && capabilitiesValue.isObject()) { + QJsonObject capabilitiesObject = capabilitiesValue.toObject(); + QJsonValue notesValue = capabilitiesObject.value("notes"); + if (!notesValue.isUndefined() && notesValue.isObject()) { + QJsonObject notesObject = notesValue.toObject(); + QJsonValue api_versionsValue = notesObject.value("api_versions"); + if (!api_versionsValue.isUndefined() && api_versionsValue.isArray()) { + QJsonArray api_versions = api_versionsValue.toArray(); + // TODO + } + } + } + } + return true; + } + } + } + return false; +} + +void NotesApi::setCababilitiesStatus(CapabilitiesStatus status, bool *changed) { + if (status != m_capabilitiesStatus) { + if (changed) + *changed = true; + m_capabilitiesStatus = status; + emit capabilitiesStatusChanged(m_capabilitiesStatus); + } +} + void NotesApi::updateNcStatus(const QJsonObject &status) { bool tmpStatus = status.value("installed").toBool(); if (m_status_installed != tmpStatus) { @@ -534,15 +575,6 @@ void NotesApi::updateNcStatus(const QJsonObject &status) { setNcStatusStatus(NextcloudStatus::NextcloudSuccess); } -void NotesApi::setCababilitiesStatus(CapabilitiesStatus status, bool *changed) { - if (status != m_capabilitiesStatus) { - if (changed) - *changed = true; - m_capabilitiesStatus = status; - emit capabilitiesStatusChanged(m_capabilitiesStatus); - } -} - void NotesApi::setNcStatusStatus(NextcloudStatus status, bool *changed) { if (status != m_ncStatusStatus) { if (changed) diff --git a/src/notesapi.h b/src/notesapi.h index 3c288ae..8c513e8 100644 --- a/src/notesapi.h +++ b/src/notesapi.h @@ -25,8 +25,8 @@ class NotesApi : public QObject Q_OBJECT // Generic API properties - Q_PROPERTY(bool verifySsl READ verifySsl WRITE setVerifySsl NOTIFY verifySslChanged) - Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + Q_PROPERTY(bool verifySsl READ verifySsl WRITE setVerifySsl NOTIFY verifySslChanged) // to allow selfsigned certificates + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) // complete API URL = ://:@[:]/ Q_PROPERTY(QString server READ server WRITE setServer NOTIFY serverChanged) Q_PROPERTY(QString scheme READ scheme WRITE setScheme NOTIFY schemeChanged) Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged) @@ -231,6 +231,7 @@ private: QNetworkRequest m_ocsRequest; QUrl apiEndpointUrl(const QString endpoint) const; + bool updateCapabilities(const QJsonObject & capabilities); CapabilitiesStatus m_capabilitiesStatus; void setCababilitiesStatus(CapabilitiesStatus status, bool *changed = NULL);