diff --git a/qml/harbour-nextcloudnotes.qml b/qml/harbour-nextcloudnotes.qml index 7f744c1..cf974f8 100644 --- a/qml/harbour-nextcloudnotes.qml +++ b/qml/harbour-nextcloudnotes.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 import Nemo.Configuration 1.0 +import Nemo.Notifications 1.0 import harbour.nextcloudnotes.notesapi 1.0 import "pages" @@ -89,6 +90,15 @@ ApplicationWindow } } + Notification { + id: offlineNotification + expireTimeout: 0 + appName: "Nextcloud " + qsTr("Notes") + summary: qsTr("Offline") + body: qsTr("Synced") + ": " + new Date(notesApi.lastSync).toLocaleString(Qt.locale()) + Component.onDestruction: close(Notification.Expired) + } + Timer { id: autoSyncTimer interval: appSettings.autoSyncInterval * 1000 @@ -120,6 +130,11 @@ ApplicationWindow sslVerify: !account.doNotVerifySsl dataFile: appSettings.currentAccount !== "" ? StandardPaths.data + "/" + appSettings.currentAccount + ".json" : "" Component.onCompleted: getAllNotes() + onNetworkAccessibleChanged: { + console.log("Device is " + (networkAccessible ? "online" : "offline")) + networkAccessible ? offlineNotification.close(Notification.Closed) : offlineNotification.publish() + } + onLastSyncChanged: account.update = lastSync } initialPage: Component { NotesPage { } } diff --git a/src/notesapi.cpp b/src/notesapi.cpp index ccbe85a..a3f5add 100644 --- a/src/notesapi.cpp +++ b/src/notesapi.cpp @@ -6,6 +6,7 @@ NotesApi::NotesApi(QObject *parent) : QObject(parent) { + m_online = m_manager.networkAccessible() == QNetworkAccessManager::Accessible; mp_model = new NotesModel(this); mp_modelProxy = new NotesProxyModel(this); mp_modelProxy->setSourceModel(mp_model); @@ -225,16 +226,21 @@ void NotesApi::verifyUrl(QUrl url) { } void NotesApi::onNetworkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible) { - qDebug() << m_manager.networkAccessible(); - emit networkAccessibleChanged(accessible == QNetworkAccessManager::Accessible); + m_online = accessible == QNetworkAccessManager::Accessible; + //qDebug() << m_online; + emit networkAccessibleChanged(m_online); } void NotesApi::replyFinished(QNetworkReply *reply) { if (reply->error() == QNetworkReply::NoError) { QByteArray data = reply->readAll(); QJsonDocument json = QJsonDocument::fromJson(data); - if (mp_model) - mp_model->fromJsonDocument(json); + if (mp_model) { + if (mp_model->fromJsonDocument(json)) { + m_lastSync = QDateTime::currentDateTimeUtc(); + emit lastSyncChanged(m_lastSync); + } + } //qDebug() << data; } else { diff --git a/src/notesapi.h b/src/notesapi.h index 90c4cb6..49445d5 100644 --- a/src/notesapi.h +++ b/src/notesapi.h @@ -56,7 +56,10 @@ public: void setDataFile(QString dataFile); Q_PROPERTY(bool networkAccessible READ networkAccessible NOTIFY networkAccessibleChanged) - bool networkAccessible() const { return m_manager.networkAccessible() == QNetworkAccessManager::Accessible; } + bool networkAccessible() const { return m_online; } + + Q_PROPERTY(QDateTime lastSync READ lastSync NOTIFY lastSyncChanged) + QDateTime lastSync() const { return m_lastSync; } Q_PROPERTY(bool ready READ ready NOTIFY readyChanged) bool ready() const; @@ -83,6 +86,7 @@ signals: void pathChanged(QString path); void dataFileChanged(QString dataFile); void networkAccessibleChanged(bool accessible); + void lastSyncChanged(QDateTime lastSync); void readyChanged(bool ready); void busyChanged(bool busy); @@ -97,6 +101,8 @@ private slots: void saveToFile(QModelIndex,QModelIndex,QVector); private: + bool m_online; + QDateTime m_lastSync; QUrl m_url; QNetworkAccessManager m_manager; QNetworkRequest m_request; diff --git a/src/notesmodel.cpp b/src/notesmodel.cpp index 0279965..7816f2a 100644 --- a/src/notesmodel.cpp +++ b/src/notesmodel.cpp @@ -81,7 +81,7 @@ bool NotesModel::fromJsonDocument(const QJsonDocument &jdoc) { } else if (jdoc.isObject()) { qDebug() << "- It's a single object..."; - return insertNote(jdoc.object()) >= 0; + insertNote(jdoc.object()) >= 0; } else if (jdoc.isEmpty()) { qDebug() << "- Empty JSON document."; diff --git a/translations/harbour-nextcloudnotes-de.ts b/translations/harbour-nextcloudnotes-de.ts index c1c0d3c..8c925e7 100644 --- a/translations/harbour-nextcloudnotes-de.ts +++ b/translations/harbour-nextcloudnotes-de.ts @@ -609,4 +609,19 @@ You can also use other markdown syntax inside them. Ich benutze diese Option auf eigene Gefahr + + harbour-nextcloudnotes + + Offline + + + + Notes + Notizen + + + Synced + + + diff --git a/translations/harbour-nextcloudnotes-sv.ts b/translations/harbour-nextcloudnotes-sv.ts index ea553ac..d17e432 100644 --- a/translations/harbour-nextcloudnotes-sv.ts +++ b/translations/harbour-nextcloudnotes-sv.ts @@ -609,4 +609,19 @@ You can also use other markdown syntax inside them. Ditt användarnamn och lösenord överförs okrypterat över nätverket när du aktiverar det här alternativet. + + harbour-nextcloudnotes + + Offline + + + + Notes + Anteckningar + + + Synced + + + diff --git a/translations/harbour-nextcloudnotes.ts b/translations/harbour-nextcloudnotes.ts index 51884d7..45f6a05 100644 --- a/translations/harbour-nextcloudnotes.ts +++ b/translations/harbour-nextcloudnotes.ts @@ -749,4 +749,22 @@ You can also use other markdown syntax inside them. + + harbour-nextcloudnotes + + + Notes + + + + + Offline + + + + + Synced + + +