Verified Commit df15c17b authored by Linus Jahn's avatar Linus Jahn 🍙

client: Transmit connection errors to UI (again)

This was still missing in the QXmpp-rewrite. It's currently not perfect:
There are still some codes that are never used (i.e. ConnTlsNotAvailable),
because I haven't found a way to check those errors in QXmpp.

Closes #268.
parent 8de3d732
Pipeline #190 passed with stage
in 4 minutes and 31 seconds
......@@ -148,6 +148,37 @@ void ClientWorker::onConnectionError(QXmppClient::Error error)
// always request new credentials, when failed to connect on first time
emit kaidan->newCredentialsNeeded();
}
if (error == QXmppClient::NoError) {
emit disconnReasonChanged(DisconnReason::ConnUserDisconnected);
} else if (error == QXmppClient::KeepAliveError) {
emit disconnReasonChanged(DisconnReason::ConnKeepAliveError);
} else if (error == QXmppClient::XmppStreamError) {
QXmppStanza::Error::Condition xError = client->xmppStreamError();
qDebug() << xError;
if (xError == QXmppStanza::Error::NotAuthorized) {
emit disconnReasonChanged(DisconnReason::ConnAuthenticationFailed);
} else {
emit disconnReasonChanged(DisconnReason::ConnNotConnected);
}
} else if (error == QXmppClient::SocketError) {
QAbstractSocket::SocketError sError = client->socketError();
if (sError == QAbstractSocket::ConnectionRefusedError ||
sError == QAbstractSocket::RemoteHostClosedError) {
emit disconnReasonChanged(DisconnReason::ConnConnectionRefused);
} else if (sError == QAbstractSocket::HostNotFoundError) {
emit disconnReasonChanged(DisconnReason::ConnDnsError);
} else if (sError == QAbstractSocket::SocketAccessError) {
emit disconnReasonChanged(DisconnReason::ConnNoNetworkPermission);
} else if (sError == QAbstractSocket::SocketTimeoutError) {
emit disconnReasonChanged(DisconnReason::ConnKeepAliveError);
} else if (sError == QAbstractSocket::SslHandshakeFailedError ||
sError == QAbstractSocket::SslInternalError) {
emit disconnReasonChanged(DisconnReason::ConnTlsFailed);
} else {
emit disconnReasonChanged(DisconnReason::ConnNotConnected);
}
}
}
QString ClientWorker::generateRandomString(unsigned int length) const
......
......@@ -41,6 +41,7 @@ class QGuiApplication;
#include <QXmppClient.h>
// Kaidan
#include "Globals.h"
#include "Enums.h"
#include "Database.h"
#include "MessageModel.h"
#include "RosterModel.h"
......@@ -55,6 +56,8 @@ class DiscoveryManager;
class VCardManager;
class UploadManager;
using namespace Enums;
class ClientThread : public QThread
{
Q_OBJECT
......@@ -155,13 +158,14 @@ public slots:
void xmppConnect();
signals:
// emitted by 'Kaidan' to us:
void connectRequested();
void disconnectRequested();
void credentialsUpdated(Credentials creds);
void sendMessageRequested(QString jid, QString message);
void sendFileRequested(QString jid, QString filePath, QString message);
void addContactRequested(QString jid, QString nick, QString message);
void removeContactRequested(QString jid);
// emitted by us:
// connection state is directly connected (client -> kaidan) without this step
void disconnReasonChanged(DisconnectionReason reason);
private slots:
/**
......
......@@ -53,6 +53,7 @@ namespace Enums {
*/
enum class DisconnectionReason : quint8 {
ConnNoError,
ConnUserDisconnected,
ConnAuthenticationFailed,
ConnNotConnected,
ConnTlsFailed,
......@@ -60,12 +61,8 @@ namespace Enums {
ConnDnsError,
ConnConnectionRefused,
ConnNoSupportedAuth,
ConnProxyUnreachable,
ConnProxyAuthRequired,
ConnProxyAuthFailed,
ConnProxyNoSupportedAuth,
ConnStreamError,
ConnUserDisconnected,
ConnKeepAliveError,
ConnNoNetworkPermission
};
Q_ENUM_NS(DisconnectionReason)
......
......@@ -87,10 +87,10 @@ Kaidan::Kaidan(QGuiApplication *app, bool enableLogging, QObject *parent) : QObj
cltThrd = new ClientThread();
client = new ClientWorker(caches, this, enableLogging, app);
client->setCredentials(creds);
connect(client, &ClientWorker::disconnReasonChanged, this, &Kaidan::setDisconnReason);
client->moveToThread(cltThrd);
connect(cltThrd, &QThread::started, client, &ClientWorker::main);
cltThrd->start();
}
......@@ -156,10 +156,10 @@ void Kaidan::setConnectionState(QXmppClient::State state)
}
}
void Kaidan::setDisconnReason(Enums::DisconnectionReason reason)
void Kaidan::setDisconnReason(DisconnectionReason reason)
{
disconnReason = reason;
emit disconnReasonChanged((quint8) reason);
emit disconnReasonChanged();
}
void Kaidan::setJid(QString jid)
......
......@@ -266,7 +266,7 @@ signals:
* Emitted, when the client failed to connect and gives the reason in
* a DisconnectionReason enumatrion.
*/
void disconnReasonChanged(quint8 reason);
void disconnReasonChanged();
/**
* Emitted when the JID was changed
......
......@@ -163,6 +163,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
qRegisterMetaType<Qt::ApplicationState>("Qt::ApplicationState");
qRegisterMetaType<QXmppClient::State>("QXmppClient::State");
qRegisterMetaType<MessageType>("MessageType");
qRegisterMetaType<DisconnectionReason>("DisconnectionReason");
// Qt-Translator
QTranslator qtTranslator;
......
......@@ -192,7 +192,8 @@ Kirigami.Page {
}
}
function handleConnectionError(error) {
function handleConnectionError() {
var error = kaidan.disconnReason
if (error === Enums.ConnAuthenticationFailed) {
passiveNotification(qsTr("Invalid username or password."))
} else if (error === Enums.ConnNotConnected) {
......
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