Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Verified Commit 961517cb authored by Melvin Keskin's avatar Melvin Keskin Committed by Jonah Brüchert

Use consistent method for showing an error message notification

parent 6e2cd3d7
......@@ -137,6 +137,31 @@ QColor QmlUtils::presenceTypeToColor(AvailabilityTypes type)
return { };
}
QString QmlUtils::connectionErrorMessage(ClientWorker::ConnectionError error)
{
switch (error) {
case ClientWorker::AuthenticationFailed:
return tr("Invalid username or password.");
case ClientWorker::NotConnected:
return tr("Cannot connect to the server. Please check your internet connection.");
case ClientWorker::TlsNotAvailable:
return tr("The server doesn't support secure connections.");
case ClientWorker::TlsFailed:
return tr("Error while trying to connect securely.");
case ClientWorker::DnsError:
return tr("Could not resolve the server's address. Please check your server name.");
case ClientWorker::ConnectionRefused:
return tr("Could not connect to the server.");
case ClientWorker::NoSupportedAuth:
return tr("Authentification protocol not supported by the server.");
case ClientWorker::RegistrationUnsupported:
return tr("This server does not support registration.");
default:
return tr("An unknown error occured.");
}
Q_UNREACHABLE();
}
QString QmlUtils::getResourcePath(const QString &name)
{
// We generally prefer to first search for files in application resources
......
......@@ -34,6 +34,7 @@
#include <QObject>
#include <QUrl>
#include "ClientWorker.h"
#include "Globals.h"
#include "Enums.h"
......@@ -70,6 +71,13 @@ public:
*/
Q_INVOKABLE static QColor presenceTypeToColor(Enums::AvailabilityTypes type);
/**
* Returns an error message for a connection error.
*
* @param error error for which an error message should be returned
*/
Q_INVOKABLE static QString connectionErrorMessage(ClientWorker::ConnectionError error);
/**
* Returns a URL to a given resource file name
*
......
......@@ -137,32 +137,9 @@ Kirigami.Page {
}
}
function handleConnectionError() {
var error = kaidan.connectionError
if (error === ClientWorker.AuthenticationFailed) {
passiveNotification(qsTr("Invalid username or password."))
} else if (error === ClientWorker.NotConnected) {
passiveNotification(qsTr("Cannot connect to the server. Please check your internet connection."))
} else if (error === ClientWorker.TlsNotAvailable) {
passiveNotification(qsTr("The server doesn't support secure connections."))
} else if (error === ClientWorker.TlsFailed) {
passiveNotification(qsTr("Error while trying to connect securely."))
} else if (error === ClientWorker.DnsError) {
passiveNotification(qsTr("Could not resolve the server's address. Please check your JID again."))
} else if (error === ClientWorker.ConnectionRefused) {
passiveNotification(qsTr("Could not connect to the server."))
} else if (error === ClientWorker.NoSupportedAuth) {
passiveNotification(qsTr("Authentification protocol not supported by the server."))
} else {
passiveNotification(qsTr("An unknown error occured; see log for details."))
}
}
Component.onCompleted: {
kaidan.connectionErrorChanged.connect(handleConnectionError)
}
Connections {
target: kaidan
Component.onDestruction: {
kaidan.connectionErrorChanged.disconnect(handleConnectionError)
onConnectionErrorChanged: showPassiveNotificationForConnectionError()
}
}
......@@ -81,10 +81,17 @@ Kirigami.ApplicationWindow {
Component {id: userProfilePage; UserProfilePage {}}
Component {id: multimediaSettingsPage; MultimediaSettingsPage {}}
/**
* Shows a passive notification for a long period.
*/
function passiveNotification(text) {
showPassiveNotification(text, "long")
}
function showPassiveNotificationForConnectionError() {
passiveNotification(Utils.connectionErrorMessage(kaidan.connectionError))
}
function openLogInPage() {
// close all pages (we don't know on which page we're on,
// thus we don't use replace)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment