From 81406171a0d6b6751e9eb1777faf6ea895affcc7 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Wed, 29 Sep 2021 20:15:25 -0400 Subject: [PATCH] QML the logout dialog --- resources/qml/Root.qml | 16 ++++++++++++++++ resources/qml/dialogs/LogoutDialog.qml | 19 +++++++++++++++++++ resources/res.qrc | 1 + src/MainWindow.cpp | 19 ------------------- src/MainWindow.h | 1 - src/ui/NhekoGlobalObject.cpp | 5 +++-- src/ui/NhekoGlobalObject.h | 4 +++- 7 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 resources/qml/dialogs/LogoutDialog.qml diff --git a/resources/qml/Root.qml b/resources/qml/Root.qml index 4207f35b..29da45eb 100644 --- a/resources/qml/Root.qml +++ b/resources/qml/Root.qml @@ -111,6 +111,13 @@ Page { } + Component { + id: logoutDialog + + LogoutDialog { + } + } + Shortcut { sequence: "Ctrl+K" onActivated: { @@ -135,6 +142,15 @@ Page { onActivated: Rooms.previousRoom() } + Connections { + function onOpenLogoutDialog() { + var dialog = logoutDialog.createObject(timelineRoot); + dialog.open(); + } + + target: Nheko + } + Connections { function onNewDeviceVerificationRequest(flow) { var dialog = deviceVerificationDialog.createObject(timelineRoot, { diff --git a/resources/qml/dialogs/LogoutDialog.qml b/resources/qml/dialogs/LogoutDialog.qml new file mode 100644 index 00000000..9e107097 --- /dev/null +++ b/resources/qml/dialogs/LogoutDialog.qml @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import Qt.labs.platform 1.1 +import im.nheko 1.0 + +MessageDialog { + id: logoutRoot + + title: qsTr("Log out") + text: CallManager.isOnCall ? qsTr("A call is in progress. Log out?") : qsTr("Are you sure you want to log out?") + modality: Qt.WindowModal + flags: Qt.Tool | Qt.WindowStaysOnTopHint | Qt.WindowCloseButtonHint | Qt.WindowTitleHint + buttons: Dialog.Ok | Dialog.Cancel + onAccepted: Nheko.logout() +} diff --git a/resources/res.qrc b/resources/res.qrc index a001a929..af684fc0 100644 --- a/resources/res.qrc +++ b/resources/res.qrc @@ -183,6 +183,7 @@ qml/dialogs/RoomMembers.qml qml/dialogs/RoomSettings.qml qml/dialogs/UserProfile.qml + qml/dialogs/LogoutDialog.qml media/ring.ogg diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index bc53b906..0978fc25 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -35,7 +35,6 @@ #include "dialogs/CreateRoom.h" #include "dialogs/JoinRoom.h" #include "dialogs/LeaveRoom.h" -#include "dialogs/Logout.h" MainWindow *MainWindow::instance_ = nullptr; @@ -372,24 +371,6 @@ MainWindow::showSolidOverlayModal(QWidget *content, QFlags fl modal_->show(); } -void -MainWindow::openLogoutDialog() -{ - auto dialog = new dialogs::Logout(this); - connect(dialog, &dialogs::Logout::loggingOut, this, [this]() { - if (WebRTCSession::instance().state() != webrtc::State::DISCONNECTED) { - if (QMessageBox::question(this, "nheko", "A call is in progress. Log out?") != - QMessageBox::Yes) { - return; - } - WebRTCSession::instance().end(); - } - chat_page_->initiateLogout(); - }); - - showDialog(dialog); -} - bool MainWindow::hasActiveDialogs() const { diff --git a/src/MainWindow.h b/src/MainWindow.h index eff8fbe7..a3c3c767 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -64,7 +64,6 @@ public: void openCreateRoomDialog( std::function callback); void openJoinRoomDialog(std::function callback); - void openLogoutDialog(); void hideOverlay(); void showSolidOverlayModal(QWidget *content, QFlags flags = Qt::AlignCenter); diff --git a/src/ui/NhekoGlobalObject.cpp b/src/ui/NhekoGlobalObject.cpp index d6824996..1a20cbc2 100644 --- a/src/ui/NhekoGlobalObject.cpp +++ b/src/ui/NhekoGlobalObject.cpp @@ -13,6 +13,7 @@ #include "Logging.h" #include "MainWindow.h" #include "UserSettingsPage.h" +#include "WebRTCSession.h" #include "Utils.h" Nheko::Nheko() @@ -83,9 +84,9 @@ Nheko::showUserSettingsPage() const } void -Nheko::openLogoutDialog() const +Nheko::logout() const { - MainWindow::instance()->openLogoutDialog(); + ChatPage::instance()->initiateLogout(); } void diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h index aa8435d1..64aad941 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h @@ -48,7 +48,7 @@ public: Q_INVOKABLE void openLink(QString link) const; Q_INVOKABLE void setStatusMessage(QString msg) const; Q_INVOKABLE void showUserSettingsPage() const; - Q_INVOKABLE void openLogoutDialog() const; + Q_INVOKABLE void logout() const; Q_INVOKABLE void openCreateRoomDialog() const; Q_INVOKABLE void openJoinRoomDialog() const; Q_INVOKABLE void reparent(QWindow *win) const; @@ -60,6 +60,8 @@ signals: void colorsChanged(); void profileChanged(); + void openLogoutDialog(); + private: QScopedPointer currentUser_; };