diff --git a/qml/pages/AboutPage.qml b/qml/pages/AboutPage.qml index 539fc59..2d0898d 100644 --- a/qml/pages/AboutPage.qml +++ b/qml/pages/AboutPage.qml @@ -25,6 +25,7 @@ Page { id: aboutPage allowedOrientations: Orientation.All + property bool isLoggedIn : false property var userInformation : tdLibWrapper.getUserInformation(); SilicaFlickable { @@ -156,7 +157,8 @@ Page { } Loader { - active: !!aboutPage.userInformation.phone_number + id: userInformationLoader + active: isLoggedIn width: parent.width sourceComponent: Component { Column { @@ -196,6 +198,33 @@ Page { horizontalCenter: parent.horizontalCenter } } + BackgroundItem { + width: parent.width + + BackgroundItem { + id: logOutItem + width: parent.width + function showRemorseItem() { + remorse.execute(logOutItem, qsTr("Logged out"), function() { + tdLibWrapper.logout(); + pageStack.pop(); + }); + } + RemorseItem { + id: remorse + } + Button { + id: logOutButton + text: qsTr("Log Out") + anchors { + horizontalCenter: parent.horizontalCenter + } + onClicked: { + logOutItem.showRemorseItem(); + } + } + } + } } } } diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index 404f0d3..1fb16ea 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -31,13 +31,14 @@ Page { property bool initializationCompleted: false; property bool loading: true; + property bool logoutLoading: false; property int authorizationState: TelegramAPI.Closed property int connectionState: TelegramAPI.WaitingForNetwork property int ownUserId; property bool chatListCreated: false; onStatusChanged: { - if (status === PageStatus.Active && initializationCompleted && !chatListCreated) { + if (status === PageStatus.Active && initializationCompleted && !chatListCreated && !logoutLoading) { updateContent(); } } @@ -143,7 +144,9 @@ Page { case TelegramAPI.WaitCode: case TelegramAPI.WaitPassword: case TelegramAPI.WaitRegistration: + case TelegramAPI.AuthorizationStateClosed: overviewPage.loading = false; + overviewPage.logoutLoading = false; if(isOnInitialization) { // pageStack isn't ready on Component.onCompleted openInitializationPageTimer.start() } else { @@ -155,6 +158,19 @@ Page { overviewPage.initializationCompleted = true; overviewPage.updateContent(); break; + case TelegramAPI.AuthorizationStateLoggingOut: + if (logoutLoading) { + Debug.log("Resources cleared already"); + return; + } + Debug.log("Logging out") + overviewPage.initializationCompleted = false; + overviewPage.loading = false; + chatListCreatedTimer.stop(); + updateSecondaryContentTimer.stop(); + overviewPage.logoutLoading = true; + chatListModel.reset(); + break; default: // Nothing ;) } @@ -236,7 +252,7 @@ Page { } MenuItem { text: qsTr("About Fernschreiber") - onClicked: pageStack.push(Qt.resolvedUrl("../pages/AboutPage.qml")) + onClicked: pageStack.push(Qt.resolvedUrl("../pages/AboutPage.qml"), {isLoggedIn : (overviewPage.authorizationState == TelegramAPI.AuthorizationReady)}) } MenuItem { text: qsTr("Settings") @@ -328,7 +344,7 @@ Page { right: parent.right } clip: true - opacity: overviewPage.chatListCreated ? 1 : 0 + opacity: (overviewPage.chatListCreated && !overviewPage.logoutLoading) ? 1 : 0 Behavior on opacity { FadeAnimation {} } model: chatListModel delegate: ChatListViewItem { @@ -357,7 +373,7 @@ Page { opacity: overviewPage.chatListCreated ? 0 : 1 Behavior on opacity { FadeAnimation {} } - visible: !overviewPage.chatListCreated + visible: !overviewPage.chatListCreated && !overviewPage.logoutLoading InfoLabel { id: loadingLabel @@ -371,5 +387,20 @@ Page { size: BusyIndicatorSize.Large } } + + Column { + width: parent.width + spacing: Theme.paddingMedium + anchors.verticalCenter: chatListView.verticalCenter + + opacity: overviewPage.logoutLoading ? 1 : 0 + Behavior on opacity { FadeAnimation {} } + visible: overviewPage.logoutLoading + + BusyLabel { + text: qsTr("Logging out") + running: true + } + } } } diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index a3b9d23..7d2ed45 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -380,6 +380,12 @@ ChatListModel::~ChatListModel() qDeleteAll(hiddenChats.values()); } +void ChatListModel::reset() +{ + chatList.clear(); + hiddenChats.clear(); +} + QHash ChatListModel::roleNames() const { QHash roles; diff --git a/src/chatlistmodel.h b/src/chatlistmodel.h index 51b8ce0..964f9f7 100644 --- a/src/chatlistmodel.h +++ b/src/chatlistmodel.h @@ -62,6 +62,8 @@ public: Q_INVOKABLE void redrawModel(); Q_INVOKABLE QVariantMap get(int row); Q_INVOKABLE QVariantMap getById(qlonglong chatId); + Q_INVOKABLE void reset(); + bool showAllChats() const; void setShowAllChats(bool showAll); diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index fe436c8..f3c41e5 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -58,7 +58,9 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, this->mceInterface = mceInterface; this->tdLibClient = td_json_client_create(); this->authorizationState = AuthorizationState::Closed; - this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this); + this->isLoggingOut = false; + + initializeTDLibReciever(); QString tdLibDatabaseDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib"; QDir tdLibDatabaseDirectory(tdLibDatabaseDirectoryPath); @@ -73,6 +75,29 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, this->removeOpenWith(); } + connect(&emojiSearchWorker, SIGNAL(searchCompleted(QString, QVariantList)), this, SLOT(handleEmojiSearchCompleted(QString, QVariantList))); + + connect(this->appSettings, SIGNAL(useOpenWithChanged()), this, SLOT(handleOpenWithChanged())); + connect(this->appSettings, SIGNAL(storageOptimizerChanged()), this, SLOT(handleStorageOptimizerChanged())); + + this->setLogVerbosityLevel(); + this->setOptionInteger("notification_group_count_max", 5); +} + +TDLibWrapper::~TDLibWrapper() +{ + LOG("Destroying TD Lib..."); + this->tdLibReceiver->setActive(false); + while (this->tdLibReceiver->isRunning()) { + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + } + qDeleteAll(basicGroups.values()); + qDeleteAll(superGroups.values()); + td_json_client_destroy(this->tdLibClient); +} + +void TDLibWrapper::initializeTDLibReciever() { + this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this); connect(this->tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString))); connect(this->tdLibReceiver, SIGNAL(authorizationStateChanged(QString, QVariantMap)), this, SLOT(handleAuthorizationStateChanged(QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(optionUpdated(QString, QVariant)), this, SLOT(handleOptionUpdated(QString, QVariant))); @@ -128,32 +153,15 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, connect(this->tdLibReceiver, SIGNAL(messageEditedUpdated(qlonglong, qlonglong, QVariantMap)), this, SIGNAL(messageEditedUpdated(qlonglong, qlonglong, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(chatIsMarkedAsUnreadUpdated(qlonglong, bool)), this, SIGNAL(chatIsMarkedAsUnreadUpdated(qlonglong, bool))); connect(this->tdLibReceiver, SIGNAL(chatDraftMessageUpdated(qlonglong, QVariantMap, QString)), this, SIGNAL(chatDraftMessageUpdated(qlonglong, QVariantMap, QString))); - - connect(&emojiSearchWorker, SIGNAL(searchCompleted(QString, QVariantList)), this, SLOT(handleEmojiSearchCompleted(QString, QVariantList))); - - connect(this->appSettings, SIGNAL(useOpenWithChanged()), this, SLOT(handleOpenWithChanged())); - connect(this->appSettings, SIGNAL(storageOptimizerChanged()), this, SLOT(handleStorageOptimizerChanged())); - this->tdLibReceiver->start(); - - this->setLogVerbosityLevel(); - this->setOptionInteger("notification_group_count_max", 5); -} - -TDLibWrapper::~TDLibWrapper() -{ - LOG("Destroying TD Lib..."); - this->tdLibReceiver->setActive(false); - while (this->tdLibReceiver->isRunning()) { - QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); - } - qDeleteAll(basicGroups.values()); - qDeleteAll(superGroups.values()); - td_json_client_destroy(this->tdLibClient); } void TDLibWrapper::sendRequest(const QVariantMap &requestObject) { + if (this->isLoggingOut) { + LOG("Sending request to TD Lib skipped as logging out is in progress, object type name:" << requestObject.value(_TYPE).toString()); + return; + } LOG("Sending request to TD Lib, object type name:" << requestObject.value(_TYPE).toString()); QJsonDocument requestDocument = QJsonDocument::fromVariant(requestObject); VERBOSE(requestDocument.toJson().constData()); @@ -221,6 +229,16 @@ void TDLibWrapper::registerUser(const QString &firstName, const QString &lastNam this->sendRequest(requestObject); } +void TDLibWrapper::logout() +{ + LOG("Logging out"); + QVariantMap requestObject; + requestObject.insert("@type", "logOut"); + this->sendRequest(requestObject); + this->isLoggingOut = true; + +} + void TDLibWrapper::getChats() { LOG("Getting chats"); @@ -1199,6 +1217,28 @@ void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationS this->setInitialParameters(); this->authorizationState = AuthorizationState::WaitTdlibParameters; } + if (authorizationState == "authorizationStateLoggingOut") { + this->authorizationState = AuthorizationState::AuthorizationStateLoggingOut; + } + if (authorizationState == "authorizationStateClosed") { + this->authorizationState = AuthorizationState::AuthorizationStateClosed; + LOG("Reloading TD Lib..."); + this->basicGroups.clear(); + this->superGroups.clear(); + this->allUsers.clear(); + this->allUserNames.clear(); + this->tdLibReceiver->setActive(false); + while (this->tdLibReceiver->isRunning()) { + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + } + td_json_client_destroy(this->tdLibClient); + this->tdLibReceiver->terminate(); + QDir appPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.local/share/harbour-fernschreiber"); + appPath.removeRecursively(); + this->tdLibClient = td_json_client_create(); + initializeTDLibReciever(); + this->isLoggingOut = false; + } this->authorizationStateData = authorizationStateData; emit authorizationStateChanged(this->authorizationState, this->authorizationStateData); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index c24941b..72c66a8 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -46,7 +46,9 @@ public: WaitPassword, WaitPhoneNumber, WaitRegistration, - WaitTdlibParameters + WaitTdlibParameters, + AuthorizationStateClosed, + AuthorizationStateLoggingOut }; Q_ENUM(AuthorizationState) @@ -125,6 +127,7 @@ public: Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode); Q_INVOKABLE void setAuthenticationPassword(const QString &authenticationPassword); Q_INVOKABLE void registerUser(const QString &firstName, const QString &lastName); + Q_INVOKABLE void logout(); Q_INVOKABLE void getChats(); Q_INVOKABLE void downloadFile(int fileId); Q_INVOKABLE void openChat(const QString &chatId); @@ -286,6 +289,7 @@ private: void setEncryptionKey(); void setLogVerbosityLevel(); const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash *groups); + void initializeTDLibReciever(); private: void *tdLibClient; @@ -311,6 +315,7 @@ private: QString activeChatSearchName; bool joinChatRequested; + bool isLoggingOut; }; diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 489527b..aa5579c 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub rlottie auf GitHub öffnen + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1036,10 +1044,6 @@ Waiting for network... Warte auf Netzwerk... - - Connecting to network... - Verbinde zum Netzwerk... - Connecting to proxy... Verbinde zum Proxy... @@ -1080,6 +1084,14 @@ Download failed. Download fehlgeschlagen. + + Connecting to network... + Verbinde zum Netzwerk... + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index 701afc6..66f406b 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Open rlottie on GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1036,10 +1044,6 @@ Waiting for network... Waiting for network... - - Connecting to network... - Connecting to network... - Connecting to proxy... Connecting to proxy... @@ -1080,6 +1084,14 @@ Download failed. Download failed. + + Connecting to network... + Connecting to network... + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index 828b71c..c460743 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Librería rlottie + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1025,10 +1033,6 @@ Waiting for network... Esperando conexión... - - Connecting to network... - Conectando al servidor... - Connecting to proxy... Conectando a proxy... @@ -1069,6 +1073,14 @@ Download failed. Error al bajar + + Connecting to network... + Conectando al servidor... + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index 0882c32..da59c9a 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Avaa rlottie GitHubissa + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1037,10 +1045,6 @@ Waiting for network... Odotetaan verkkoa... - - Connecting to network... - Yhdistetään verkkoon... - Connecting to proxy... Yhdistetään välityspalvelimeen... @@ -1081,6 +1085,14 @@ Download failed. Lataus epäonnistui. + + Connecting to network... + Yhdistetään verkkoon... + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index 7ca1400..9491de2 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1025,10 +1033,6 @@ Waiting for network... Hálózatra várakozás... - - Connecting to network... - Csatlakozás a hálózathoz... - Connecting to proxy... Csatlakozás a proxy-hoz... @@ -1069,6 +1073,14 @@ Download failed. A letöltés nem sikerült. + + Connecting to network... + Csatlakozás a hálózathoz... + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index 3c2baf9..50911b1 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Apri rlottie su GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1044,10 +1052,6 @@ Waiting for network... Attendo la rete... - - Connecting to network... - Connetto alla rete... - Connecting to proxy... Connetto al proxy... @@ -1080,6 +1084,14 @@ Download failed. Download non riuscito. + + Connecting to network... + Connetto alla rete... + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index c2b925d..f3c30d7 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Otwórz rlottie na GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1047,10 +1055,6 @@ Waiting for network... Czekanie na sieć - - Connecting to network... - Łączenie z siecią... - Connecting to proxy... Łączenie z proxy @@ -1091,6 +1095,14 @@ Download failed. + + Connecting to network... + Łączenie z siecią... + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index 72454c2..8d1ec48 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Открыть rlottie на GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1047,10 +1055,6 @@ Waiting for network... Ожидание сети... - - Connecting to network... - Подключение к сети... - Connecting to proxy... Подключение к прокси... @@ -1091,6 +1095,14 @@ Download failed. Ошибка скачивания. + + Connecting to network... + Подключение к сети... + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index c649561..16cc679 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Öppna rlottie på GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1036,10 +1044,6 @@ Waiting for network... Väntar på nätverk... - - Connecting to network... - Ansluter till nätverket... - Connecting to proxy... Ansluter till proxy... @@ -1080,6 +1084,14 @@ Download failed. Nerladdning misslyckades. + + Connecting to network... + Ansluter till nätverket... + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 8e4f8f9..9b057bf 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub 在 Github 打开 rlottie + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1025,10 +1033,6 @@ Waiting for network... 等候网络连接… - - Connecting to network... - 正在连接到网络… - Connecting to proxy... 正在连接到代理… @@ -1069,6 +1073,14 @@ Download failed. 下载失败。 + + Connecting to network... + 正在连接到网络… + + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 8005242..99c085d 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Open rlottie on GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1036,10 +1044,6 @@ Waiting for network... Waiting for network... - - Connecting to network... - Connecting to network... - Connecting to proxy... Connecting to proxy... @@ -1080,6 +1084,14 @@ Download failed. Download failed. + + Connecting to network... + Connecting to network... + + + Logging out + + PinnedMessageItem