Process connection status updates

This commit is contained in:
Sebastian J. Wolf 2020-08-13 00:20:28 +02:00
parent 154113afc4
commit 6c4cb405b1
4 changed files with 53 additions and 1 deletions

View file

@ -43,6 +43,10 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "updateAuthorizationState") {
this->processUpdateAuthorizationState(receivedInformation);
}
if (objectTypeName == "updateConnectionState") {
this->processUpdateConnectionState(receivedInformation);
}
}
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
@ -65,3 +69,10 @@ void TDLibReceiver::processUpdateAuthorizationState(const QVariantMap &receivedI
qDebug() << "[TDLibReceiver] Authorization state changed: " << authorizationState;
emit authorizationStateChanged(authorizationState);
}
void TDLibReceiver::processUpdateConnectionState(const QVariantMap &receivedInformation)
{
QString connectionState = receivedInformation.value("state").toMap().value("@type").toString();
qDebug() << "[TDLibReceiver] Connection state changed: " << connectionState;
emit connectionStateChanged(connectionState);
}

View file

@ -21,6 +21,7 @@ signals:
void versionDetected(const QString &version);
void authorizationStateChanged(const QString &authorizationState);
void optionUpdated(const QString &optionName, const QVariant &optionValue);
void connectionStateChanged(const QString &connectionState);
private:
void *tdLibClient;
@ -30,6 +31,7 @@ private:
void processReceivedDocument(const QJsonDocument &receivedJsonDocument);
void processUpdateOption(const QVariantMap &receivedInformation);
void processUpdateAuthorizationState(const QVariantMap &receivedInformation);
void processUpdateConnectionState(const QVariantMap &receivedInformation);
};
#endif // TDLIBRECEIVER_H

View file

@ -39,6 +39,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString)));
connect(this->tdLibReceiver, SIGNAL(authorizationStateChanged(QString)), this, SLOT(handleAuthorizationStateChanged(QString)));
connect(this->tdLibReceiver, SIGNAL(optionUpdated(QString, QVariant)), this, SLOT(handleOptionUpdated(QString, QVariant)));
connect(this->tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString)));
this->tdLibReceiver->start();
}
@ -70,6 +71,11 @@ TDLibWrapper::AuthorizationState TDLibWrapper::getAuthorizationState()
return this->authorizationState;
}
TDLibWrapper::ConnectionState TDLibWrapper::getConnectionState()
{
return this->connectionState;
}
void TDLibWrapper::handleVersionDetected(const QString &version)
{
this->version = version;
@ -78,7 +84,7 @@ void TDLibWrapper::handleVersionDetected(const QString &version)
void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationState)
{
if (authorizationState == "authorizationStateClosed") {
if (authorizationState == "authorizationStateClosed") {
this->authorizationState = AuthorizationState::Closed;
}
@ -134,6 +140,27 @@ void TDLibWrapper::handleOptionUpdated(const QString &optionName, const QVariant
emit optionUpdated(optionName, optionValue);
}
void TDLibWrapper::handleConnectionStateChanged(const QString &connectionState)
{
if (connectionState == "connectionStateConnecting") {
this->connectionState = ConnectionState::Connecting;
}
if (connectionState == "connectionStateConnectingToProxy") {
this->connectionState = ConnectionState::ConnectingToProxy;
}
if (connectionState == "connectionStateReady") {
this->connectionState = ConnectionState::IsReady;
}
if (connectionState == "connectionStateUpdating") {
this->connectionState = ConnectionState::Updating;
}
if (connectionState == "connectionStateWaitingForNetwork") {
this->connectionState = ConnectionState::WaitingForNetwork;
}
emit connectionStateChanged(this->connectionState);
}
void TDLibWrapper::setInitialParameters()
{
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";

View file

@ -30,25 +30,37 @@ public:
WaitTdlibParameters
};
enum ConnectionState {
Connecting,
ConnectingToProxy,
IsReady,
Updating,
WaitingForNetwork
};
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
Q_INVOKABLE QString getVersion();
Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState();
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
signals:
void versionDetected(const QString &version);
void authorizationStateChanged(const TDLibWrapper::AuthorizationState &authorizationState);
void optionUpdated(const QString &optionName, const QVariant &optionValue);
void connectionStateChanged(const TDLibWrapper::ConnectionState &connectionState);
public slots:
void handleVersionDetected(const QString &version);
void handleAuthorizationStateChanged(const QString &authorizationState);
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
void handleConnectionStateChanged(const QString &connectionState);
private:
void *tdLibClient;
TDLibReceiver *tdLibReceiver;
QString version;
TDLibWrapper::AuthorizationState authorizationState;
TDLibWrapper::ConnectionState connectionState;
QVariantMap options;
void setInitialParameters();