Store user information & introduce connection status

This commit is contained in:
Sebastian J. Wolf 2020-08-13 17:08:14 +02:00
parent 6b68d8a276
commit 446338363f
12 changed files with 145 additions and 24 deletions

View file

@ -1,3 +1,21 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0 import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import "pages" import "pages"

View file

@ -3,12 +3,12 @@
This file is part of Fernschreiber. This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
fernschreiber is distributed in the hope that it will be useful, Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.

View file

@ -3,12 +3,12 @@
This file is part of Fernschreiber. This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
fernschreiber is distributed in the hope that it will be useful, Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.

View file

@ -3,12 +3,12 @@
This file is part of Fernschreiber. This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
fernschreiber is distributed in the hope that it will be useful, Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.

View file

@ -3,12 +3,12 @@
This file is part of Fernschreiber. This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
fernschreiber is distributed in the hope that it will be useful, Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
@ -37,6 +37,31 @@ Page {
running: overviewPage.loading running: overviewPage.loading
} }
function setPageStatus() {
switch (overviewPage.connectionState) {
case TelegramAPI.WaitingForNetwork:
pageStatus.color = "red";
pageHeader.title = qsTr("Waiting for network");
break;
case TelegramAPI.Connecting:
pageStatus.color = "gold";
pageHeader.title = qsTr("Connecting to network");
break;
case TelegramAPI.ConnectingToProxy:
pageStatus.color = "gold";
pageHeader.title = qsTr("Connecting to proxy");
break;
case TelegramAPI.ConnectionReady:
pageStatus.color = "green";
pageHeader.title = qsTr("Fernschreiber");
break;
case TelegramAPI.Updating:
pageStatus.color = "lightblue";
pageHeader.title = qsTr("Updating content");
break;
}
}
Connections { Connections {
target: tdLibWrapper target: tdLibWrapper
onAuthorizationStateChanged: { onAuthorizationStateChanged: {
@ -61,6 +86,7 @@ Page {
} }
onConnectionStateChanged: { onConnectionStateChanged: {
overviewPage.connectionState = connectionState; overviewPage.connectionState = connectionState;
setPageStatus();
} }
} }
@ -71,6 +97,7 @@ Page {
} }
overviewPage.connectionState = tdLibWrapper.getConnectionState(); overviewPage.connectionState = tdLibWrapper.getConnectionState();
overviewPage.setPageStatus();
} }
SilicaFlickable { SilicaFlickable {
@ -91,8 +118,24 @@ Page {
width: parent.width width: parent.width
spacing: Theme.paddingLarge spacing: Theme.paddingLarge
PageHeader { Row {
title: qsTr("Welcome to Fernschreiber") width: parent.width
GlassItem {
id: pageStatus
width: Theme.itemSizeMedium
height: Theme.itemSizeMedium
color: "red"
falloffRadius: 0.1
radius: 0.2
cache: false
}
PageHeader {
id: pageHeader
title: qsTr("Fernschreiber")
width: parent.width - pageStatus.width
}
} }
VerticalScrollDecorator {} VerticalScrollDecorator {}

View file

@ -3,12 +3,12 @@
This file is part of Fernschreiber. This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
fernschreiber is distributed in the hope that it will be useful, Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.

View file

@ -3,12 +3,12 @@
This file is part of Fernschreiber. This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
fernschreiber is distributed in the hope that it will be useful, Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
@ -65,6 +65,10 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "updateConnectionState") { if (objectTypeName == "updateConnectionState") {
this->processUpdateConnectionState(receivedInformation); this->processUpdateConnectionState(receivedInformation);
} }
if (objectTypeName == "updateUser") {
this->processUpdateUser(receivedInformation);
}
} }
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation) void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
@ -94,3 +98,10 @@ void TDLibReceiver::processUpdateConnectionState(const QVariantMap &receivedInfo
qDebug() << "[TDLibReceiver] Connection state changed: " << connectionState; qDebug() << "[TDLibReceiver] Connection state changed: " << connectionState;
emit connectionStateChanged(connectionState); emit connectionStateChanged(connectionState);
} }
void TDLibReceiver::processUpdateUser(const QVariantMap &receivedInformation)
{
QVariantMap userInformation = receivedInformation.value("user").toMap();
qDebug() << "[TDLibReceiver] User was updated: " << userInformation.value("username").toString() << userInformation.value("first_name").toString() << userInformation.value("last_name").toString();
emit userUpdated(userInformation);
}

View file

@ -3,12 +3,12 @@
This file is part of Fernschreiber. This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
fernschreiber is distributed in the hope that it will be useful, Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
@ -40,6 +40,7 @@ signals:
void authorizationStateChanged(const QString &authorizationState); void authorizationStateChanged(const QString &authorizationState);
void optionUpdated(const QString &optionName, const QVariant &optionValue); void optionUpdated(const QString &optionName, const QVariant &optionValue);
void connectionStateChanged(const QString &connectionState); void connectionStateChanged(const QString &connectionState);
void userUpdated(const QVariantMap &userInformation);
private: private:
void *tdLibClient; void *tdLibClient;
@ -50,6 +51,7 @@ private:
void processUpdateOption(const QVariantMap &receivedInformation); void processUpdateOption(const QVariantMap &receivedInformation);
void processUpdateAuthorizationState(const QVariantMap &receivedInformation); void processUpdateAuthorizationState(const QVariantMap &receivedInformation);
void processUpdateConnectionState(const QVariantMap &receivedInformation); void processUpdateConnectionState(const QVariantMap &receivedInformation);
void processUpdateUser(const QVariantMap &receivedInformation);
}; };
#endif // TDLIBRECEIVER_H #endif // TDLIBRECEIVER_H

View file

@ -3,12 +3,12 @@
This file is part of Fernschreiber. This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
fernschreiber is distributed in the hope that it will be useful, Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
@ -40,6 +40,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(authorizationStateChanged(QString)), this, SLOT(handleAuthorizationStateChanged(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(optionUpdated(QString, QVariant)), this, SLOT(handleOptionUpdated(QString, QVariant)));
connect(this->tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString))); connect(this->tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString)));
connect(this->tdLibReceiver, SIGNAL(userUpdated(QVariantMap)), this, SLOT(handleUserUpdated(QVariantMap)));
this->tdLibReceiver->start(); this->tdLibReceiver->start();
} }
@ -183,6 +184,16 @@ void TDLibWrapper::handleConnectionStateChanged(const QString &connectionState)
emit connectionStateChanged(this->connectionState); emit connectionStateChanged(this->connectionState);
} }
void TDLibWrapper::handleUserUpdated(const QVariantMap &userInformation)
{
if (userInformation.value("id") == this->options.value("my_id")) {
qDebug() << "[TDLibWrapper] Own user information updated :)";
this->userInformation = userInformation;
} else {
qDebug() << "[TDLibWrapper] Other user information updated";
}
}
void TDLibWrapper::setInitialParameters() void TDLibWrapper::setInitialParameters()
{ {
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib"; qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";
@ -192,6 +203,8 @@ void TDLibWrapper::setInitialParameters()
initialParameters.insert("api_id", TDLIB_API_ID); initialParameters.insert("api_id", TDLIB_API_ID);
initialParameters.insert("api_hash", TDLIB_API_HASH); initialParameters.insert("api_hash", TDLIB_API_HASH);
initialParameters.insert("database_directory", QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib"); initialParameters.insert("database_directory", QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib");
initialParameters.insert("use_file_database", true);
initialParameters.insert("use_chat_info_database", true);
initialParameters.insert("use_message_database", true); initialParameters.insert("use_message_database", true);
initialParameters.insert("use_secret_chats", false); initialParameters.insert("use_secret_chats", false);
initialParameters.insert("system_language_code", QLocale::system().name()); initialParameters.insert("system_language_code", QLocale::system().name());

View file

@ -3,12 +3,12 @@
This file is part of Fernschreiber. This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
fernschreiber is distributed in the hope that it will be useful, Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
@ -76,6 +76,7 @@ public slots:
void handleAuthorizationStateChanged(const QString &authorizationState); void handleAuthorizationStateChanged(const QString &authorizationState);
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue); void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
void handleConnectionStateChanged(const QString &connectionState); void handleConnectionStateChanged(const QString &connectionState);
void handleUserUpdated(const QVariantMap &userInformation);
private: private:
void *tdLibClient; void *tdLibClient;
@ -84,6 +85,7 @@ private:
TDLibWrapper::AuthorizationState authorizationState; TDLibWrapper::AuthorizationState authorizationState;
TDLibWrapper::ConnectionState connectionState; TDLibWrapper::ConnectionState connectionState;
QVariantMap options; QVariantMap options;
QVariantMap userInformation;
void setInitialParameters(); void setInitialParameters();
void setEncryptionKey(); void setEncryptionKey();

View file

@ -106,11 +106,27 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Welcome to Fernschreiber</source> <source>Loading...</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Loading...</source> <source>Fernschreiber</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for network</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connecting to network</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connecting to proxy</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Updating content</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>

View file

@ -106,11 +106,27 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Welcome to Fernschreiber</source> <source>Loading...</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Loading...</source> <source>Fernschreiber</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for network</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connecting to network</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connecting to proxy</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Updating content</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>