Began implementing offline mode

This commit is contained in:
Scharel Clemens 2019-12-07 13:42:37 +01:00
parent 5fc566749f
commit 74ae7bd213
5 changed files with 26 additions and 9 deletions

View file

@ -92,7 +92,7 @@ ApplicationWindow
id: autoSyncTimer
interval: appSettings.autoSyncInterval * 1000
repeat: true
running: interval > 0 && appWindow.visible
running: interval > 0 && notesApi.networkAccessible && appWindow.visible
triggeredOnStart: false
onTriggered: {
if (!notesApi.busy) {
@ -117,6 +117,7 @@ ApplicationWindow
username: account.username
password: account.password
sslVerify: !account.doNotVerifySsl
dataDir: StandardPaths.data
Component.onCompleted: getAllNotes()
}

View file

@ -54,7 +54,7 @@ Page {
}
MenuItem {
text: enabled ? qsTr("Reload") : qsTr("Updating...")
enabled: appSettings.currentAccount.length > 0 && !notesApi.busy
enabled: appSettings.currentAccount.length > 0 && notesApi.networkAccessible && !notesApi.busy
onClicked: notesApi.getAllNotes()
}
MenuLabel {

View file

@ -3,6 +3,7 @@
#include <QAuthenticator>
#include <QJsonDocument>
#include <QJsonObject>
#include <QFile>
NotesApi::NotesApi(QObject *parent) : QObject(parent)
{
@ -120,10 +121,18 @@ void NotesApi::setPath(QString path) {
}
}
void NotesApi::setDataDir(QString dataDir) {
QDir newPath(dataDir);
if (newPath != m_jsonDir) {
m_jsonDir.setPath(dataDir);
emit dataDirChanged(m_jsonDir.absolutePath());
}
}
bool NotesApi::busy() const {
bool busy = false;
for (int i = 0; i < m_replies.size(); ++i) {
busy |=m_replies[i]->isRunning();
busy |= m_replies[i]->isRunning();
}
return busy;
}

View file

@ -5,6 +5,7 @@
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QDir>
#include <QDebug>
#include "notesmodel.h"
@ -50,6 +51,10 @@ public:
QString path() const { return m_url.path(); }
void setPath(QString path);
Q_PROPERTY(QString dataDir READ dataDir WRITE setDataDir NOTIFY dataDirChanged)
QString dataDir() const { return m_jsonDir.absolutePath(); }
void setDataDir(QString dataDir);
Q_PROPERTY(bool networkAccessible READ networkAccessible NOTIFY networkAccessibleChanged)
bool networkAccessible() const { return m_manager.networkAccessible() == QNetworkAccessManager::Accessible; }
@ -73,6 +78,7 @@ signals:
void usernameChanged(QString username);
void passwordChanged(QString password);
void pathChanged(QString path);
void dataDirChanged(QString dataDir);
void networkAccessibleChanged(bool accessible);
void busyChanged(bool busy);
@ -90,6 +96,7 @@ private:
QNetworkAccessManager m_manager;
QNetworkRequest m_request;
QVector<QNetworkReply*> m_replies;
QDir m_jsonDir;
NotesModel* mp_model;
NotesProxyModel* mp_modelProxy;
};

View file

@ -84,32 +84,32 @@
<context>
<name>EditPage</name>
<message>
<location filename="../qml/pages/EditPage.qml" line="39"/>
<location filename="../qml/pages/EditPage.qml" line="38"/>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="43"/>
<location filename="../qml/pages/EditPage.qml" line="42"/>
<source>Markdown syntax</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="71"/>
<location filename="../qml/pages/EditPage.qml" line="70"/>
<source>No content</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="156"/>
<location filename="../qml/pages/EditPage.qml" line="155"/>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="157"/>
<location filename="../qml/pages/EditPage.qml" line="156"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="172"/>
<location filename="../qml/pages/EditPage.qml" line="171"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>