Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Move LeaveRoom dialog to MainWindow (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
mujx committed Feb 10, 2018
1 parent 3fd2572 commit 26f221e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 86 deletions.
1 change: 1 addition & 0 deletions include/ChatPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ChatPage : public QWidget
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_; }

Expand Down
19 changes: 10 additions & 9 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -78,31 +83,27 @@ private slots:

//! 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> userSettings_;

//! Used to hide undefined states between page transitions.
QSharedPointer<OverlayModal> progressModal_;
QSharedPointer<LoadingIndicator> spinner_;

//! Matrix Client API provider.
QSharedPointer<MatrixClient> client_;

//! Tray icon that shows the unread message count.
TrayIcon *trayIcon_;

//! Notifications display.
QSharedPointer<SnackBar> snackBar_;
//! Leave room modal.
QSharedPointer<OverlayModal> leaveRoomModal_;
//! Leave room dialog.
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;
};
7 changes: 0 additions & 7 deletions include/RoomList.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

#include <mtx.hpp>

#include "dialogs/LeaveRoom.h"

class LeaveRoomDialog;
class MatrixClient;
class Cache;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -109,9 +105,6 @@ private slots:

OverlayModal *joinRoomModal_;

QSharedPointer<OverlayModal> leaveRoomModal_;
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;

std::map<QString, QSharedPointer<RoomInfoListItem>> rooms_;
QString selectedRoom_;

Expand Down
7 changes: 0 additions & 7 deletions include/TopRoomBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@ class TopRoomBar : public QWidget
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_;
Expand All @@ -79,9 +75,6 @@ private slots:

FlatButton *settingsBtn_;

QSharedPointer<OverlayModal> leaveRoomModal_;
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;

QSharedPointer<OverlayModal> inviteUsersModal_;
QSharedPointer<dialogs::InviteUsers> inviteUsersDialog_;

Expand Down
2 changes: 0 additions & 2 deletions src/ChatPage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> 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, [=]() {
Expand Down
23 changes: 22 additions & 1 deletion src/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "TrayIcon.h"
#include "UserSettingsPage.h"
#include "WelcomePage.h"
#include "dialogs/LeaveRoom.h"

MainWindow *MainWindow::instance_ = nullptr;

Expand Down Expand Up @@ -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<dialogs::LeaveRoom>(new dialogs::LeaveRoom(this));

connect(leaveRoomDialog_.data(), &dialogs::LeaveRoom::closing, this, [=](bool leaving) {
leaveRoomModal_->fadeOut();

if (leaving)
client_->leaveRoom(roomToLeave);
});

leaveRoomModal_ =
QSharedPointer<OverlayModal>(new OverlayModal(this, leaveRoomDialog_.data()));
leaveRoomModal_->setDuration(0);
leaveRoomModal_->setColor(QColor(30, 30, 30, 170));

leaveRoomModal_->fadeIn();
}
35 changes: 3 additions & 32 deletions src/RoomList.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ RoomList::addRoom(const QSharedPointer<RoomSettings> &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<RoomInfoListItem>(room_item));

Expand Down Expand Up @@ -189,28 +191,6 @@ RoomList::setInitialRooms(const std::map<QString, QSharedPointer<RoomSettings>>
emit roomChanged(room.first);
}

void
RoomList::openLeaveRoomDialog(const QString &room_id)
{
if (leaveRoomDialog_.isNull()) {
leaveRoomDialog_ = QSharedPointer<dialogs::LeaveRoom>(new dialogs::LeaveRoom(this));

connect(leaveRoomDialog_.data(),
&dialogs::LeaveRoom::closing,
this,
[=](bool leaving) { closeLeaveRoomDialog(leaving, room_id); });
}

if (leaveRoomModal_.isNull()) {
leaveRoomModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), leaveRoomDialog_.data()));
leaveRoomModal_->setDuration(0);
leaveRoomModal_->setColor(QColor(30, 30, 30, 170));
}

leaveRoomModal_->fadeIn();
}

void
RoomList::sync(const std::map<QString, QSharedPointer<RoomState>> &states,
const std::map<QString, QSharedPointer<RoomSettings>> &settings)
Expand Down Expand Up @@ -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)
{
Expand Down
29 changes: 1 addition & 28 deletions src/TopRoomBar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<dialogs::LeaveRoom>(new dialogs::LeaveRoom(this));

connect(leaveRoomDialog_.data(),
SIGNAL(closing(bool)),
this,
SLOT(closeLeaveRoomDialog(bool)));
}

if (leaveRoomModal_.isNull()) {
leaveRoomModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), leaveRoomDialog_.data()));
leaveRoomModal_->setDuration(0);
leaveRoomModal_->setColor(QColor(30, 30, 30, 170));
}

leaveRoomModal_->fadeIn();
MainWindow::instance()->openLeaveRoomDialog();
});

menu_->addAction(toggleNotifications_);
Expand All @@ -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)
{
Expand Down

0 comments on commit 26f221e

Please sign in to comment.