Bring TDLib version to the UI
This commit is contained in:
parent
0e7dc04fa6
commit
26a885400d
7 changed files with 81 additions and 21 deletions
|
@ -121,7 +121,20 @@ Page {
|
||||||
Label {
|
Label {
|
||||||
x: Theme.horizontalPageMargin
|
x: Theme.horizontalPageMargin
|
||||||
width: parent.width - ( 2 * 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
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
wrapMode: Text.Wrap
|
wrapMode: Text.Wrap
|
||||||
anchors {
|
anchors {
|
||||||
|
@ -147,7 +160,7 @@ Page {
|
||||||
horizontalCenter: parent.horizontalCenter
|
horizontalCenter: parent.horizontalCenter
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Qt.openUrlExternally("https://telegram.orgprivacy")
|
Qt.openUrlExternally("https://telegram.org/privacy")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,11 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren
|
||||||
|
|
||||||
void TDLibReceiver::setActive(const bool &active)
|
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;
|
this->isActive = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,27 +25,27 @@ void TDLibReceiver::receiverLoop()
|
||||||
if (result) {
|
if (result) {
|
||||||
QJsonDocument receivedJsonDocument = QJsonDocument::fromJson(QByteArray(result));
|
QJsonDocument receivedJsonDocument = QJsonDocument::fromJson(QByteArray(result));
|
||||||
qDebug().noquote() << "[TDLibReceiver] Raw result: " << receivedJsonDocument.toJson(QJsonDocument::Indented);
|
qDebug().noquote() << "[TDLibReceiver] Raw result: " << receivedJsonDocument.toJson(QJsonDocument::Indented);
|
||||||
handleReceivedDocument(receivedJsonDocument);
|
processReceivedDocument(receivedJsonDocument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug() << "[TDLibReceiver] Stopping receiver loop";
|
qDebug() << "[TDLibReceiver] Stopping receiver loop";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TDLibReceiver::handleReceivedDocument(const QJsonDocument &receivedJsonDocument)
|
void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDocument)
|
||||||
{
|
{
|
||||||
QVariantMap receivedInformation = receivedJsonDocument.object().toVariantMap();
|
QVariantMap receivedInformation = receivedJsonDocument.object().toVariantMap();
|
||||||
QString objectTypeName = receivedInformation.value("@type").toString();
|
QString objectTypeName = receivedInformation.value("@type").toString();
|
||||||
|
|
||||||
if (objectTypeName == "updateOption") {
|
if (objectTypeName == "updateOption") {
|
||||||
this->handleUpdateOption(receivedInformation);
|
this->processUpdateOption(receivedInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectTypeName == "updateAuthorizationState") {
|
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();
|
QString currentOption = receivedInformation.value("name").toString();
|
||||||
if (currentOption == "version") {
|
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();
|
QString authorizationState = receivedInformation.value("authorization_state").toMap().value("@type").toString();
|
||||||
qDebug() << "[TDLibReceiver] Authorization state changed: " << authorizationState;
|
qDebug() << "[TDLibReceiver] Authorization state changed: " << authorizationState;
|
||||||
|
|
|
@ -26,9 +26,9 @@ private:
|
||||||
bool isActive;
|
bool isActive;
|
||||||
|
|
||||||
void receiverLoop();
|
void receiverLoop();
|
||||||
void handleReceivedDocument(const QJsonDocument &receivedJsonDocument);
|
void processReceivedDocument(const QJsonDocument &receivedJsonDocument);
|
||||||
void handleUpdateOption(const QVariantMap &receivedInformation);
|
void processUpdateOption(const QVariantMap &receivedInformation);
|
||||||
void handleUpdateAuthorizationState(const QVariantMap &receivedInformation);
|
void processUpdateAuthorizationState(const QVariantMap &receivedInformation);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TDLIBRECEIVER_H
|
#endif // TDLIBRECEIVER_H
|
||||||
|
|
|
@ -24,6 +24,10 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
|
||||||
qDebug() << "[TDLibWrapper] Initializing TD Lib...";
|
qDebug() << "[TDLibWrapper] Initializing TD Lib...";
|
||||||
this->tdLibClient = td_json_client_create();
|
this->tdLibClient = td_json_client_create();
|
||||||
this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this);
|
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();
|
this->tdLibReceiver->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,3 +41,25 @@ TDLibWrapper::~TDLibWrapper()
|
||||||
td_json_client_destroy(this->tdLibClient);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,24 @@ public:
|
||||||
explicit TDLibWrapper(QObject *parent = nullptr);
|
explicit TDLibWrapper(QObject *parent = nullptr);
|
||||||
~TDLibWrapper();
|
~TDLibWrapper();
|
||||||
|
|
||||||
|
Q_INVOKABLE QString getVersion();
|
||||||
|
Q_INVOKABLE QString getAuthorizationState();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void versionDetected(const QString &version);
|
||||||
|
void authorizationStateChanged(const QString &authorizationState);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void handleVersionDetected(const QString &version);
|
||||||
|
void handleAuthorizationStateChanged(const QString &authorizationState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *tdLibClient;
|
void *tdLibClient;
|
||||||
TDLibReceiver *tdLibReceiver;
|
TDLibReceiver *tdLibReceiver;
|
||||||
|
|
||||||
|
QString version;
|
||||||
|
QString authorizationState;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TDLIBWRAPPER_H
|
#endif // TDLIBWRAPPER_H
|
||||||
|
|
|
@ -27,10 +27,6 @@
|
||||||
<source>Sources on GitHub</source>
|
<source>Sources on GitHub</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
|
||||||
<source>This product uses the Telegram API but is not endorsed or certified by Telegram</source>
|
|
||||||
<translation type="unfinished"></translation>
|
|
||||||
</message>
|
|
||||||
<message>
|
<message>
|
||||||
<source>Terms of Service</source>
|
<source>Terms of Service</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
|
@ -55,6 +51,14 @@
|
||||||
<source>About Telegram</source>
|
<source>About Telegram</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</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>
|
||||||
<context>
|
<context>
|
||||||
<name>OverviewPage</name>
|
<name>OverviewPage</name>
|
||||||
|
|
|
@ -27,10 +27,6 @@
|
||||||
<source>Sources on GitHub</source>
|
<source>Sources on GitHub</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
|
||||||
<source>This product uses the Telegram API but is not endorsed or certified by Telegram</source>
|
|
||||||
<translation type="unfinished"></translation>
|
|
||||||
</message>
|
|
||||||
<message>
|
<message>
|
||||||
<source>Terms of Service</source>
|
<source>Terms of Service</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
|
@ -55,6 +51,14 @@
|
||||||
<source>About Telegram</source>
|
<source>About Telegram</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</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>
|
||||||
<context>
|
<context>
|
||||||
<name>OverviewPage</name>
|
<name>OverviewPage</name>
|
||||||
|
|
Loading…
Reference in a new issue