diff --git a/include/ChatPage.h b/include/ChatPage.h index dcd925e7..67ddd1ed 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -66,6 +66,7 @@ public: void bootstrap(QString userid, QString homeserver, QString token); void showQuickSwitcher(); void showReadReceipts(const QString &event_id); + QString currentRoom() const { return current_room_; } static ChatPage *instance() { return instance_; } diff --git a/include/MainWindow.h b/include/MainWindow.h index b899e2d3..e4ffe2f4 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -35,17 +35,22 @@ class SnackBar; class TrayIcon; class UserSettings; +namespace dialogs { +class LeaveRoom; +} + class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); static MainWindow *instance() { return instance_; }; void saveCurrentWindowSize(); + void openLeaveRoomDialog(const QString &room_id = ""); + protected: void closeEvent(QCloseEvent *event); @@ -78,31 +83,27 @@ private: //! The initial welcome screen. WelcomePage *welcome_page_; - //! The login screen. LoginPage *login_page_; - //! The register page. RegisterPage *register_page_; - //! A stacked widget that handles the transitions between widgets. QStackedWidget *pageStack_; - //! The main chat area. ChatPage *chat_page_; UserSettingsPage *userSettingsPage_; QSharedPointer userSettings_; - //! Used to hide undefined states between page transitions. QSharedPointer progressModal_; QSharedPointer spinner_; - //! Matrix Client API provider. QSharedPointer client_; - //! Tray icon that shows the unread message count. TrayIcon *trayIcon_; - //! Notifications display. QSharedPointer snackBar_; + //! Leave room modal. + QSharedPointer leaveRoomModal_; + //! Leave room dialog. + QSharedPointer leaveRoomDialog_; }; diff --git a/include/RoomList.h b/include/RoomList.h index ed93f17d..b99b354f 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -25,8 +25,6 @@ #include -#include "dialogs/LeaveRoom.h" - class LeaveRoomDialog; class MatrixClient; class Cache; @@ -79,8 +77,6 @@ public slots: void updateUnreadMessageCount(const QString &roomid, int count); void updateRoomDescription(const QString &roomid, const DescInfo &info); void closeJoinRoomDialog(bool isJoining, QString roomAlias); - void openLeaveRoomDialog(const QString &room_id); - void closeLeaveRoomDialog(bool leaving, const QString &room_id); void clearRoomMessageCount(const QString &room_id); protected: @@ -109,9 +105,6 @@ private: OverlayModal *joinRoomModal_; - QSharedPointer leaveRoomModal_; - QSharedPointer leaveRoomDialog_; - std::map> rooms_; QString selectedRoom_; diff --git a/include/TopRoomBar.h b/include/TopRoomBar.h index 13eaaa38..2ee25361 100644 --- a/include/TopRoomBar.h +++ b/include/TopRoomBar.h @@ -53,16 +53,12 @@ public: void reset(); signals: - void leaveRoom(); void inviteUsers(QStringList users); protected: void paintEvent(QPaintEvent *event) override; void mousePressEvent(QMouseEvent *event) override; -private slots: - void closeLeaveRoomDialog(bool leaving); - private: QHBoxLayout *topLayout_; QVBoxLayout *textLayout_; @@ -79,9 +75,6 @@ private: FlatButton *settingsBtn_; - QSharedPointer leaveRoomModal_; - QSharedPointer leaveRoomDialog_; - QSharedPointer inviteUsersModal_; QSharedPointer inviteUsersDialog_; diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 78435713..ba7e2797 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -144,8 +144,6 @@ ChatPage::ChatPage(QSharedPointer client, connect(user_info_widget_, SIGNAL(logout()), client_.data(), SLOT(logout())); connect(client_.data(), SIGNAL(loggedOut()), this, SLOT(logout())); - connect( - top_bar_, &TopRoomBar::leaveRoom, this, [=]() { client_->leaveRoom(current_room_); }); connect(top_bar_, &TopRoomBar::inviteUsers, this, [=](QStringList users) { for (int ii = 0; ii < users.size(); ++ii) { QTimer::singleShot(ii * 1000, this, [=]() { diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 9437b401..2ada704a 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -33,6 +33,7 @@ #include "TrayIcon.h" #include "UserSettingsPage.h" #include "WelcomePage.h" +#include "dialogs/LeaveRoom.h" MainWindow *MainWindow::instance_ = nullptr; @@ -262,4 +263,24 @@ MainWindow::hasActiveUser() settings.contains("auth/user_id"); } -MainWindow::~MainWindow() {} +void +MainWindow::openLeaveRoomDialog(const QString &room_id) +{ + auto roomToLeave = room_id.isEmpty() ? chat_page_->currentRoom() : room_id; + + leaveRoomDialog_ = QSharedPointer(new dialogs::LeaveRoom(this)); + + connect(leaveRoomDialog_.data(), &dialogs::LeaveRoom::closing, this, [=](bool leaving) { + leaveRoomModal_->fadeOut(); + + if (leaving) + client_->leaveRoom(roomToLeave); + }); + + leaveRoomModal_ = + QSharedPointer(new OverlayModal(this, leaveRoomDialog_.data())); + leaveRoomModal_->setDuration(0); + leaveRoomModal_->setColor(QColor(30, 30, 30, 170)); + + leaveRoomModal_->fadeIn(); +} diff --git a/src/RoomList.cc b/src/RoomList.cc index 8d4cf30b..099e5b1c 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -88,7 +88,9 @@ RoomList::addRoom(const QSharedPointer &settings, { auto room_item = new RoomInfoListItem(settings, state, room_id, scrollArea_); connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom); - connect(room_item, &RoomInfoListItem::leaveRoom, this, &RoomList::openLeaveRoomDialog); + connect(room_item, &RoomInfoListItem::leaveRoom, this, [=](const QString &room_id) { + MainWindow::instance()->openLeaveRoomDialog(room_id); + }); rooms_.emplace(room_id, QSharedPointer(room_item)); @@ -189,28 +191,6 @@ RoomList::setInitialRooms(const std::map> emit roomChanged(room.first); } -void -RoomList::openLeaveRoomDialog(const QString &room_id) -{ - if (leaveRoomDialog_.isNull()) { - leaveRoomDialog_ = QSharedPointer(new dialogs::LeaveRoom(this)); - - connect(leaveRoomDialog_.data(), - &dialogs::LeaveRoom::closing, - this, - [=](bool leaving) { closeLeaveRoomDialog(leaving, room_id); }); - } - - if (leaveRoomModal_.isNull()) { - leaveRoomModal_ = QSharedPointer( - new OverlayModal(MainWindow::instance(), leaveRoomDialog_.data())); - leaveRoomModal_->setDuration(0); - leaveRoomModal_->setColor(QColor(30, 30, 30, 170)); - } - - leaveRoomModal_->fadeIn(); -} - void RoomList::sync(const std::map> &states, const std::map> &settings) @@ -362,15 +342,6 @@ RoomList::closeJoinRoomDialog(bool isJoining, QString roomAlias) client_->joinRoom(roomAlias); } -void -RoomList::closeLeaveRoomDialog(bool leaving, const QString &room_id) -{ - leaveRoomModal_->fadeOut(); - - if (leaving) - client_->leaveRoom(room_id); -} - void RoomList::setFilterRooms(bool isFilteringEnabled) { diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc index d34e59ad..d3ae307f 100644 --- a/src/TopRoomBar.cc +++ b/src/TopRoomBar.cc @@ -119,24 +119,7 @@ TopRoomBar::TopRoomBar(QWidget *parent) leaveRoom_ = new QAction(tr("Leave room"), this); connect(leaveRoom_, &QAction::triggered, this, [=]() { - if (leaveRoomDialog_.isNull()) { - leaveRoomDialog_ = - QSharedPointer(new dialogs::LeaveRoom(this)); - - connect(leaveRoomDialog_.data(), - SIGNAL(closing(bool)), - this, - SLOT(closeLeaveRoomDialog(bool))); - } - - if (leaveRoomModal_.isNull()) { - leaveRoomModal_ = QSharedPointer( - new OverlayModal(MainWindow::instance(), leaveRoomDialog_.data())); - leaveRoomModal_->setDuration(0); - leaveRoomModal_->setColor(QColor(30, 30, 30, 170)); - } - - leaveRoomModal_->fadeIn(); + MainWindow::instance()->openLeaveRoomDialog(); }); menu_->addAction(toggleNotifications_); @@ -160,16 +143,6 @@ TopRoomBar::TopRoomBar(QWidget *parent) setLayout(topLayout_); } -void -TopRoomBar::closeLeaveRoomDialog(bool leaving) -{ - leaveRoomModal_->fadeOut(); - - if (leaving) { - emit leaveRoom(); - } -} - void TopRoomBar::updateRoomAvatarFromName(const QString &name) {