Added notifications on error
This commit is contained in:
parent
385cdc4cca
commit
3e32fb94f9
7 changed files with 193 additions and 13 deletions
|
@ -95,7 +95,14 @@ ApplicationWindow
|
|||
expireTimeout: 0
|
||||
appName: "Nextcloud " + qsTr("Notes")
|
||||
summary: qsTr("Offline")
|
||||
body: qsTr("Synced") + ": " + new Date(notesApi.lastSync).toLocaleString(Qt.locale())
|
||||
body: qsTr("Synced") + ": " + new Date(account.update).toLocaleString(Qt.locale())
|
||||
Component.onDestruction: close(Notification.Expired)
|
||||
}
|
||||
|
||||
Notification {
|
||||
id: errorNotification
|
||||
appName: offlineNotification.appName
|
||||
summary: qsTr("Error")
|
||||
Component.onDestruction: close(Notification.Expired)
|
||||
}
|
||||
|
||||
|
@ -134,6 +141,14 @@ ApplicationWindow
|
|||
console.log("Device is " + (networkAccessible ? "online" : "offline"))
|
||||
networkAccessible ? offlineNotification.close(Notification.Closed) : offlineNotification.publish()
|
||||
}
|
||||
onError: {
|
||||
console.log("Error (" + error + "): " + errorMessage(error))
|
||||
errorNotification.close()
|
||||
if (error && networkAccessible) {
|
||||
errorNotification.body = errorMessage(error)
|
||||
errorNotification.publish()
|
||||
}
|
||||
}
|
||||
onLastSyncChanged: account.update = lastSync
|
||||
}
|
||||
|
||||
|
|
|
@ -45,13 +45,6 @@ void NotesApi::setSslVerify(bool verify) {
|
|||
}
|
||||
}
|
||||
|
||||
void NotesApi::requireAuthentication(QNetworkReply *reply, QAuthenticator *authenticator) {
|
||||
if (reply && authenticator) {
|
||||
authenticator->setUser(username());
|
||||
authenticator->setPassword(password());
|
||||
}
|
||||
}
|
||||
|
||||
void NotesApi::setUrl(QUrl url) {
|
||||
if (url != m_url) {
|
||||
QUrl oldUrl = m_url;
|
||||
|
@ -223,6 +216,15 @@ void NotesApi::verifyUrl(QUrl url) {
|
|||
emit urlValidChanged(url.isValid());
|
||||
}
|
||||
|
||||
void NotesApi::requireAuthentication(QNetworkReply *reply, QAuthenticator *authenticator) {
|
||||
if (reply && authenticator) {
|
||||
authenticator->setUser(username());
|
||||
authenticator->setPassword(password());
|
||||
}
|
||||
else
|
||||
emit error(AuthenticationError);
|
||||
}
|
||||
|
||||
void NotesApi::onNetworkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible) {
|
||||
m_online = accessible == QNetworkAccessManager::Accessible;
|
||||
//qDebug() << m_online;
|
||||
|
@ -230,7 +232,9 @@ void NotesApi::onNetworkAccessibleChanged(QNetworkAccessManager::NetworkAccessib
|
|||
}
|
||||
|
||||
void NotesApi::replyFinished(QNetworkReply *reply) {
|
||||
qDebug() << reply->error() << reply->errorString();
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
emit error(NoError);
|
||||
QByteArray data = reply->readAll();
|
||||
QJsonDocument json = QJsonDocument::fromJson(data);
|
||||
if (mp_model) {
|
||||
|
@ -241,9 +245,10 @@ void NotesApi::replyFinished(QNetworkReply *reply) {
|
|||
}
|
||||
//qDebug() << data;
|
||||
}
|
||||
else {
|
||||
qDebug() << reply->error() << reply->errorString();
|
||||
}
|
||||
else if (reply->error() == QNetworkReply::AuthenticationRequiredError)
|
||||
emit error(AuthenticationError);
|
||||
else
|
||||
emit error(CommunicationError);
|
||||
m_replies.removeAll(reply);
|
||||
reply->deleteLater();
|
||||
emit busyChanged(busy());
|
||||
|
@ -254,12 +259,47 @@ void NotesApi::sslError(QNetworkReply *reply, const QList<QSslError> &errors) {
|
|||
for (int i = 0; i < errors.size(); ++i) {
|
||||
qDebug() << errors[i].errorString();
|
||||
}
|
||||
emit error(SslHandshakeError);
|
||||
}
|
||||
|
||||
void NotesApi::saveToFile(QModelIndex, QModelIndex, QVector<int>) {
|
||||
if (m_jsonFile.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) {
|
||||
qDebug() << "Writing data to file" << m_jsonFile.fileName();
|
||||
m_jsonFile.write(mp_model->toJsonDocument().toJson());
|
||||
QByteArray data = mp_model->toJsonDocument().toJson();
|
||||
if (m_jsonFile.write(data) < data.size())
|
||||
emit error(LocalFileWriteError);
|
||||
m_jsonFile.close();
|
||||
}
|
||||
else
|
||||
emit error(LocalFileWriteError);
|
||||
}
|
||||
|
||||
const QString NotesApi::errorMessage(int error) const {
|
||||
QString message;
|
||||
switch (error) {
|
||||
case NoError:
|
||||
break;
|
||||
case NoConnectionError:
|
||||
message = tr("No network connection available");
|
||||
break;
|
||||
case CommunicationError:
|
||||
message = tr("Failed to communicate with the Nextcloud server");
|
||||
break;
|
||||
case LocalFileReadError:
|
||||
message = tr("An error happened while reading from the local storage");
|
||||
break;
|
||||
case LocalFileWriteError:
|
||||
message = tr("An error happened while writing to the local storage");
|
||||
break;
|
||||
case SslHandshakeError:
|
||||
message = tr("An error occured while establishing an encrypted connection");
|
||||
break;
|
||||
case AuthenticationError:
|
||||
message = tr("Could not authenticate to the Nextcloud instance");
|
||||
break;
|
||||
default:
|
||||
message = tr("Unknown error");
|
||||
break;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
|
|
@ -74,6 +74,17 @@ public:
|
|||
Q_INVOKABLE void deleteNote(double noteId);
|
||||
Q_INVOKABLE NotesProxyModel* model() const { return mp_modelProxy; }
|
||||
|
||||
enum ErrorCodes {
|
||||
NoError,
|
||||
NoConnectionError,
|
||||
CommunicationError,
|
||||
LocalFileReadError,
|
||||
LocalFileWriteError,
|
||||
SslHandshakeError,
|
||||
AuthenticationError
|
||||
};
|
||||
Q_INVOKABLE const QString errorMessage(int error) const;
|
||||
|
||||
signals:
|
||||
void sslVerifyChanged(bool verify);
|
||||
void urlChanged(QUrl url);
|
||||
|
@ -89,6 +100,7 @@ signals:
|
|||
void lastSyncChanged(QDateTime lastSync);
|
||||
void readyChanged(bool ready);
|
||||
void busyChanged(bool busy);
|
||||
void error(int error);
|
||||
|
||||
public slots:
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ bool NotesModel::fromJsonDocument(const QJsonDocument &jdoc) {
|
|||
}
|
||||
else if (jdoc.isObject()) {
|
||||
qDebug() << "- It's a single object...";
|
||||
insertNote(jdoc.object()) >= 0;
|
||||
insertNote(jdoc.object());
|
||||
}
|
||||
else if (jdoc.isEmpty()) {
|
||||
qDebug() << "- Empty JSON document.";
|
||||
|
|
|
@ -213,6 +213,37 @@
|
|||
<translation>Geändert</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NotesApi</name>
|
||||
<message>
|
||||
<source>No network connection available</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to communicate with the Nextcloud server</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>An error happened while reading from the local storage</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>An error happened while writing to the local storage</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>An error occured while establishing an encrypted connection</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Could not authenticate to the Nextcloud instance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unknown error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NotesPage</name>
|
||||
<message>
|
||||
|
@ -623,5 +654,9 @@ You can also use other markdown syntax inside them.</source>
|
|||
<source>Synced</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -213,6 +213,37 @@
|
|||
<translation>Ingen kategori</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NotesApi</name>
|
||||
<message>
|
||||
<source>No network connection available</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Failed to communicate with the Nextcloud server</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>An error happened while reading from the local storage</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>An error happened while writing to the local storage</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>An error occured while establishing an encrypted connection</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Could not authenticate to the Nextcloud instance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unknown error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NotesPage</name>
|
||||
<message>
|
||||
|
@ -623,5 +654,9 @@ You can also use other markdown syntax inside them.</source>
|
|||
<source>Synced</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -259,6 +259,44 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NotesApi</name>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="283"/>
|
||||
<source>No network connection available</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="286"/>
|
||||
<source>Failed to communicate with the Nextcloud server</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="289"/>
|
||||
<source>An error happened while reading from the local storage</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="292"/>
|
||||
<source>An error happened while writing to the local storage</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="295"/>
|
||||
<source>An error occured while establishing an encrypted connection</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="298"/>
|
||||
<source>Could not authenticate to the Nextcloud instance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/notesapi.cpp" line="301"/>
|
||||
<source>Unknown error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NotesPage</name>
|
||||
<message>
|
||||
|
@ -766,5 +804,10 @@ You can also use other markdown syntax inside them.</source>
|
|||
<source>Synced</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/harbour-nextcloudnotes.qml" line="105"/>
|
||||
<source>Error</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
Loading…
Reference in a new issue