Bring TDLib version to the UI

This commit is contained in:
Sebastian J. Wolf 2020-08-12 10:50:01 +02:00
parent 0e7dc04fa6
commit 26a885400d
7 changed files with 81 additions and 21 deletions

View file

@ -121,7 +121,20 @@ Page {
Label {
x: Theme.horizontalPageMargin
width: parent.width - ( 2 * Theme.horizontalPageMargin )
text: qsTr("This product uses the Telegram API but is not endorsed or certified by Telegram")
horizontalAlignment: Text.AlignHCenter
text: qsTr("This product uses the Telegram API but is not endorsed or certified by Telegram.")
font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.Wrap
anchors {
horizontalCenter: parent.horizontalCenter
}
}
Label {
x: Theme.horizontalPageMargin
width: parent.width - ( 2 * Theme.horizontalPageMargin )
horizontalAlignment: Text.AlignHCenter
text: qsTr("TDLib version %1").arg(tdLibWrapper.getVersion())
font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.Wrap
anchors {
@ -147,7 +160,7 @@ Page {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
Qt.openUrlExternally("https://telegram.orgprivacy")
Qt.openUrlExternally("https://telegram.org/privacy")
}
}

View file

@ -8,7 +8,11 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren
void TDLibReceiver::setActive(const bool &active)
{
qDebug() << "[TDLibReceiver] setActive " << active;
if (active) {
qDebug() << "[TDLibReceiver] Activating receiver loop...";
} else {
qDebug() << "[TDLibReceiver] Deactivating receiver loop, this may take a while...";
}
this->isActive = active;
}
@ -21,27 +25,27 @@ void TDLibReceiver::receiverLoop()
if (result) {
QJsonDocument receivedJsonDocument = QJsonDocument::fromJson(QByteArray(result));
qDebug().noquote() << "[TDLibReceiver] Raw result: " << receivedJsonDocument.toJson(QJsonDocument::Indented);
handleReceivedDocument(receivedJsonDocument);
processReceivedDocument(receivedJsonDocument);
}
}
qDebug() << "[TDLibReceiver] Stopping receiver loop";
}
void TDLibReceiver::handleReceivedDocument(const QJsonDocument &receivedJsonDocument)
void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDocument)
{
QVariantMap receivedInformation = receivedJsonDocument.object().toVariantMap();
QString objectTypeName = receivedInformation.value("@type").toString();
if (objectTypeName == "updateOption") {
this->handleUpdateOption(receivedInformation);
this->processUpdateOption(receivedInformation);
}
if (objectTypeName == "updateAuthorizationState") {
this->handleUpdateAuthorizationState(receivedInformation);
this->processUpdateAuthorizationState(receivedInformation);
}
}
void TDLibReceiver::handleUpdateOption(const QVariantMap &receivedInformation)
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
{
QString currentOption = receivedInformation.value("name").toString();
if (currentOption == "version") {
@ -51,7 +55,7 @@ void TDLibReceiver::handleUpdateOption(const QVariantMap &receivedInformation)
}
}
void TDLibReceiver::handleUpdateAuthorizationState(const QVariantMap &receivedInformation)
void TDLibReceiver::processUpdateAuthorizationState(const QVariantMap &receivedInformation)
{
QString authorizationState = receivedInformation.value("authorization_state").toMap().value("@type").toString();
qDebug() << "[TDLibReceiver] Authorization state changed: " << authorizationState;

View file

@ -26,9 +26,9 @@ private:
bool isActive;
void receiverLoop();
void handleReceivedDocument(const QJsonDocument &receivedJsonDocument);
void handleUpdateOption(const QVariantMap &receivedInformation);
void handleUpdateAuthorizationState(const QVariantMap &receivedInformation);
void processReceivedDocument(const QJsonDocument &receivedJsonDocument);
void processUpdateOption(const QVariantMap &receivedInformation);
void processUpdateAuthorizationState(const QVariantMap &receivedInformation);
};
#endif // TDLIBRECEIVER_H

View file

@ -24,6 +24,10 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
qDebug() << "[TDLibWrapper] Initializing TD Lib...";
this->tdLibClient = td_json_client_create();
this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this);
connect(this->tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString)));
connect(this->tdLibReceiver, SIGNAL(authorizationStateChanged(QString)), this, SLOT(handleAuthorizationStateChanged(QString)));
this->tdLibReceiver->start();
}
@ -37,3 +41,25 @@ TDLibWrapper::~TDLibWrapper()
td_json_client_destroy(this->tdLibClient);
}
QString TDLibWrapper::getVersion()
{
return this->version;
}
QString TDLibWrapper::getAuthorizationState()
{
return this->authorizationState;
}
void TDLibWrapper::handleVersionDetected(const QString &version)
{
this->version = version;
emit versionDetected(version);
}
void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationState)
{
this->authorizationState = authorizationState;
emit authorizationStateChanged(authorizationState);
}

View file

@ -14,15 +14,24 @@ public:
explicit TDLibWrapper(QObject *parent = nullptr);
~TDLibWrapper();
Q_INVOKABLE QString getVersion();
Q_INVOKABLE QString getAuthorizationState();
signals:
void versionDetected(const QString &version);
void authorizationStateChanged(const QString &authorizationState);
public slots:
void handleVersionDetected(const QString &version);
void handleAuthorizationStateChanged(const QString &authorizationState);
private:
void *tdLibClient;
TDLibReceiver *tdLibReceiver;
QString version;
QString authorizationState;
};
#endif // TDLIBWRAPPER_H

View file

@ -27,10 +27,6 @@
<source>Sources on GitHub</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This product uses the Telegram API but is not endorsed or certified by Telegram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terms of Service</source>
<translation type="unfinished"></translation>
@ -55,6 +51,14 @@
<source>About Telegram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This product uses the Telegram API but is not endorsed or certified by Telegram.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TDLib version %1</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OverviewPage</name>

View file

@ -27,10 +27,6 @@
<source>Sources on GitHub</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This product uses the Telegram API but is not endorsed or certified by Telegram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terms of Service</source>
<translation type="unfinished"></translation>
@ -55,6 +51,14 @@
<source>About Telegram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This product uses the Telegram API but is not endorsed or certified by Telegram.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TDLib version %1</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OverviewPage</name>