Implemented Nextcloud capabilities

This commit is contained in:
Scharel Clemens 2020-06-08 07:53:49 +02:00
parent 47ed45a3cc
commit d8934d4a8a
3 changed files with 28 additions and 10 deletions

View file

@ -8,7 +8,7 @@ Dialog {
property int id property int id
property var note property var note
onIdChanged: note = notesModel.getNoteById(id) onIdChanged: note = notesModel.note(id)
onNoteChanged: { onNoteChanged: {
if (note["content"].split('\n')[0].indexOf(note["title"]) > 0) { if (note["content"].split('\n')[0].indexOf(note["title"]) > 0) {
dialogHeader.title = "" dialogHeader.title = ""
@ -38,7 +38,7 @@ Dialog {
} }
onStatusChanged: { onStatusChanged: {
if (status === PageStatus.Activating) { if (status === PageStatus.Activating) {
notesModel.getNote(id) notesModel.note(id)
} }
} }
@ -104,7 +104,7 @@ Dialog {
MenuItem { MenuItem {
text: enabled ? qsTr("Reload") : qsTr("Updating...") text: enabled ? qsTr("Reload") : qsTr("Updating...")
enabled: !notesApi.busy enabled: !notesApi.busy
onClicked: notesModel.getNote(note["id"]) onClicked: notesModel.note(note["id"])
} }
/*MenuItem { /*MenuItem {
text: qsTr("Edit") text: qsTr("Edit")

View file

@ -6,6 +6,8 @@
#include <QJsonArray> #include <QJsonArray>
#include <QDir> #include <QDir>
QVersionNumber NotesApi::m_capabilities_implementedApiVersion = QVersionNumber(1, 1);
NotesApi::NotesApi(const QString statusEndpoint, const QString loginEndpoint, const QString ocsEndpoint, const QString notesEndpoint, QObject *parent) NotesApi::NotesApi(const QString statusEndpoint, const QString loginEndpoint, const QString ocsEndpoint, const QString notesEndpoint, QObject *parent)
: m_statusEndpoint(statusEndpoint), m_loginEndpoint(loginEndpoint), m_ocsEndpoint(ocsEndpoint), m_notesEndpoint(notesEndpoint) : m_statusEndpoint(statusEndpoint), m_loginEndpoint(loginEndpoint), m_ocsEndpoint(ocsEndpoint), m_notesEndpoint(notesEndpoint)
{ {
@ -16,6 +18,7 @@ NotesApi::NotesApi(const QString statusEndpoint, const QString loginEndpoint, co
setNcStatusStatus(NextcloudStatus::NextcloudUnknown); setNcStatusStatus(NextcloudStatus::NextcloudUnknown);
setLoginStatus(LoginStatus::LoginUnknown); setLoginStatus(LoginStatus::LoginUnknown);
m_ncStatusStatus = NextcloudStatus::NextcloudUnknown; m_ncStatusStatus = NextcloudStatus::NextcloudUnknown;
m_capabilities_notesInstalled = false;
m_status_installed = false; m_status_installed = false;
m_status_maintenance = false; m_status_maintenance = false;
m_status_needsDbUpgrade = false; m_status_needsDbUpgrade = false;
@ -507,11 +510,19 @@ bool NotesApi::updateCapabilities(const QJsonObject &capabilities) {
QJsonObject capabilitiesObject = capabilitiesValue.toObject(); QJsonObject capabilitiesObject = capabilitiesValue.toObject();
QJsonValue notesValue = capabilitiesObject.value("notes"); QJsonValue notesValue = capabilitiesObject.value("notes");
if (!notesValue.isUndefined() && notesValue.isObject()) { if (!notesValue.isUndefined() && notesValue.isObject()) {
if (!m_capabilities_notesInstalled) {
m_capabilities_notesInstalled = true;
emit notesAppInstalledChanged(m_capabilities_notesInstalled);
}
QJsonObject notesObject = notesValue.toObject(); QJsonObject notesObject = notesValue.toObject();
QJsonValue api_versionsValue = notesObject.value("api_versions"); QJsonValue api_versionsValue = notesObject.value("api_versions");
if (!api_versionsValue.isUndefined() && api_versionsValue.isArray()) { if (!api_versionsValue.isUndefined() && api_versionsValue.isArray()) {
QJsonArray api_versions = api_versionsValue.toArray(); QJsonArray api_versions = api_versionsValue.toArray();
// TODO m_capabilities_notesApiVersions.clear();
for (int i = 0; i < api_versions.size(); ++i) {
m_capabilities_notesApiVersions << api_versions.at(i).toString();
}
emit notesAppApiVersionsChanged(m_capabilities_notesApiVersions);
} }
} }
} }

View file

@ -35,7 +35,7 @@ class NotesApi : public QObject
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
// Status information // Class status information
Q_PROPERTY(bool urlValid READ urlValid NOTIFY urlValidChanged) Q_PROPERTY(bool urlValid READ urlValid NOTIFY urlValidChanged)
Q_PROPERTY(bool networkAccessible READ networkAccessible NOTIFY networkAccessibleChanged) Q_PROPERTY(bool networkAccessible READ networkAccessible NOTIFY networkAccessibleChanged)
Q_PROPERTY(QDateTime lastSync READ lastSync NOTIFY lastSyncChanged) Q_PROPERTY(QDateTime lastSync READ lastSync NOTIFY lastSyncChanged)
@ -43,10 +43,9 @@ class NotesApi : public QObject
// Nextcloud capabilities // Nextcloud capabilities
Q_PROPERTY(CapabilitiesStatus capabilitiesStatus READ capabilitiesStatus NOTIFY capabilitiesStatusChanged) Q_PROPERTY(CapabilitiesStatus capabilitiesStatus READ capabilitiesStatus NOTIFY capabilitiesStatusChanged)
//Q_PROPERTY(bool notesAppInstalled READ notesAppInstalled NOTIFY notesAppInstalledChanged) Q_PROPERTY(bool notesAppInstalled READ notesAppInstalled NOTIFY notesAppInstalledChanged)
//Q_PROPERTY(QStringList notesAppApiVersions READ notesAppApiVersions NOTIFY notesAppApiVersionsChanged) Q_PROPERTY(QStringList notesAppApiVersions READ notesAppApiVersions NOTIFY notesAppApiVersionsChanged)
//Q_PROPERTY(QString notesAppApiMaxVersion READ notesAppApiMaxVersion NOTIFY notesAppApiMaxVersionChanged) Q_PROPERTY(QString notesAppApiUsedVersion READ notesAppApiUsedVersion NOTIFY notesAppApiUsedVersionChanged)
//Q_PROPERTY(QString notesAppApiMinVersion READ notesAppApiMinVersion NOTIFY notesAppApiMinVersionChanged)
// Nextcloud status (status.php) // Nextcloud status (status.php)
Q_PROPERTY(NextcloudStatus ncStatusStatus READ ncStatusStatus NOTIFY ncStatusStatusChanged) Q_PROPERTY(NextcloudStatus ncStatusStatus READ ncStatusStatus NOTIFY ncStatusStatusChanged)
@ -135,6 +134,9 @@ public:
bool busy() const; bool busy() const;
CapabilitiesStatus capabilitiesStatus() const { return m_capabilitiesStatus; } CapabilitiesStatus capabilitiesStatus() const { return m_capabilitiesStatus; }
bool notesAppInstalled() const { return m_capabilities_notesInstalled; }
QStringList notesAppApiVersions() const { return m_capabilities_notesApiVersions; }
static QString notesAppApiUsedVersion() { return m_capabilities_implementedApiVersion.toString(); }
NextcloudStatus ncStatusStatus() const { return m_ncStatusStatus; } NextcloudStatus ncStatusStatus() const { return m_ncStatusStatus; }
bool statusInstalled() const { return m_status_installed; } bool statusInstalled() const { return m_status_installed; }
@ -195,6 +197,9 @@ signals:
void busyChanged(bool busy); void busyChanged(bool busy);
void capabilitiesStatusChanged(CapabilitiesStatus status); void capabilitiesStatusChanged(CapabilitiesStatus status);
void notesAppInstalledChanged(bool installed);
void notesAppApiVersionsChanged(QStringList versions);
void notesAppApiUsedVersionChanged(QString version);
void ncStatusStatusChanged(NextcloudStatus status); void ncStatusStatusChanged(NextcloudStatus status);
void statusInstalledChanged(bool installed); void statusInstalledChanged(bool installed);
@ -234,6 +239,9 @@ private:
bool updateCapabilities(const QJsonObject & capabilities); bool updateCapabilities(const QJsonObject & capabilities);
CapabilitiesStatus m_capabilitiesStatus; CapabilitiesStatus m_capabilitiesStatus;
void setCababilitiesStatus(CapabilitiesStatus status, bool *changed = NULL); void setCababilitiesStatus(CapabilitiesStatus status, bool *changed = NULL);
bool m_capabilities_notesInstalled;
static QVersionNumber m_capabilities_implementedApiVersion;
QStringList m_capabilities_notesApiVersions;
// Nextcloud status.php // Nextcloud status.php
const QString m_statusEndpoint; const QString m_statusEndpoint;
@ -245,7 +253,6 @@ private:
bool m_status_maintenance; bool m_status_maintenance;
bool m_status_needsDbUpgrade; bool m_status_needsDbUpgrade;
QVersionNumber m_status_version; QVersionNumber m_status_version;
//QString m_status_version;
QString m_status_versionstring; QString m_status_versionstring;
QString m_status_edition; QString m_status_edition;
QString m_status_productname; QString m_status_productname;