Skip to content

Commit

Permalink
Don't open room switcher when another dialog is open
Browse files Browse the repository at this point in the history
fixes mujx#251
  • Loading branch information
mujx committed Mar 4, 2018
1 parent 2976e74 commit 746f74a
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 118 deletions.
31 changes: 31 additions & 0 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ class SnackBar;
class TrayIcon;
class UserSettings;

namespace mtx {
namespace requests {
struct CreateRoom;
}
}

namespace dialogs {
class CreateRoom;
class InviteUsers;
class JoinRoom;
class LeaveRoom;
class Logout;
}

class MainWindow : public QMainWindow
Expand All @@ -50,6 +60,11 @@ class MainWindow : public QMainWindow
void saveCurrentWindowSize();

void openLeaveRoomDialog(const QString &room_id = "");
void openInviteUsersDialog(std::function<void(const QStringList &invitees)> callback);
void openCreateRoomDialog(
std::function<void(const mtx::requests::CreateRoom &request)> callback);
void openJoinRoomDialog(std::function<void(const QString &room_id)> callback);
void openLogoutDialog(std::function<void()> callback);

protected:
void closeEvent(QCloseEvent *event);
Expand Down Expand Up @@ -113,4 +128,20 @@ private slots:
QSharedPointer<OverlayModal> leaveRoomModal_;
//! Leave room dialog.
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;
//! Invite users modal.
QSharedPointer<OverlayModal> inviteUsersModal_;
//! Invite users dialog.
QSharedPointer<dialogs::InviteUsers> inviteUsersDialog_;
//! Join room modal.
QSharedPointer<OverlayModal> joinRoomModal_;
//! Join room dialog.
QSharedPointer<dialogs::JoinRoom> joinRoomDialog_;
//! Create room modal.
QSharedPointer<OverlayModal> createRoomModal_;
//! Create room dialog.
QSharedPointer<dialogs::CreateRoom> createRoomDialog_;
//! Logout modal.
QSharedPointer<OverlayModal> logoutModal_;
//! Logout dialog.
QSharedPointer<dialogs::Logout> logoutDialog_;
};
15 changes: 5 additions & 10 deletions include/SideBarActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include "FlatButton.h"
#include "Menu.h"

#include "dialogs/CreateRoom.h"
#include "dialogs/JoinRoom.h"

class OverlayModal;
namespace mtx {
namespace requests {
struct CreateRoom;
}
}

class SideBarActions : public QWidget
{
Expand All @@ -36,12 +37,6 @@ class SideBarActions : public QWidget
QAction *createRoomAction_;
QAction *joinRoomAction_;

QSharedPointer<OverlayModal> joinRoomModal_;
QSharedPointer<dialogs::JoinRoom> joinRoomDialog_;

QSharedPointer<OverlayModal> createRoomModal_;
QSharedPointer<dialogs::CreateRoom> createRoomDialog_;

FlatButton *settingsBtn_;
FlatButton *createRoomBtn_;
FlatButton *joinRoomBtn_;
Expand Down
6 changes: 0 additions & 6 deletions include/TopRoomBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
#include <QSharedPointer>
#include <QVBoxLayout>

#include "dialogs/InviteUsers.h"
#include "dialogs/LeaveRoom.h"

class Avatar;
class FlatButton;
class Label;
Expand Down Expand Up @@ -74,9 +71,6 @@ class TopRoomBar : public QWidget

FlatButton *settingsBtn_;

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

Avatar *avatar_;

int buttonSize_;
Expand Down
8 changes: 0 additions & 8 deletions include/UserInfoWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <QLabel>
#include <QLayout>

#include "dialogs/Logout.h"

class Avatar;
class FlatButton;
class OverlayModal;
Expand All @@ -46,9 +44,6 @@ class UserInfoWidget : public QWidget
void resizeEvent(QResizeEvent *event) override;
void paintEvent(QPaintEvent *event) override;

private slots:
void closeLogoutDialog(bool isLoggingOut);

private:
Avatar *userAvatar_;

Expand All @@ -67,8 +62,5 @@ private slots:

QImage avatar_image_;

QSharedPointer<OverlayModal> logoutModal_;
QSharedPointer<dialogs::Logout> logoutDialog_;

int logoutButtonSize_;
};
122 changes: 120 additions & 2 deletions src/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <QSettings>
#include <QShortcut>

#include <mtx/requests.hpp>

#include "ChatPage.h"
#include "Config.h"
#include "LoadingIndicator.h"
Expand All @@ -33,7 +35,12 @@
#include "TrayIcon.h"
#include "UserSettingsPage.h"
#include "WelcomePage.h"

#include "dialogs/CreateRoom.h"
#include "dialogs/InviteUsers.h"
#include "dialogs/JoinRoom.h"
#include "dialogs/LeaveRoom.h"
#include "dialogs/Logout.h"

MainWindow *MainWindow::instance_ = nullptr;

Expand Down Expand Up @@ -255,7 +262,7 @@ MainWindow::openLeaveRoomDialog(const QString &room_id)
connect(leaveRoomDialog_.data(),
&dialogs::LeaveRoom::closing,
this,
[this, &roomToLeave](bool leaving) {
[this, roomToLeave](bool leaving) {
leaveRoomModal_->hide();

if (leaving)
Expand Down Expand Up @@ -291,9 +298,120 @@ MainWindow::showOverlayProgressBar()
}
}

void
MainWindow::openInviteUsersDialog(std::function<void(const QStringList &invitees)> callback)
{
if (inviteUsersDialog_.isNull()) {
inviteUsersDialog_ =
QSharedPointer<dialogs::InviteUsers>(new dialogs::InviteUsers(this));

connect(inviteUsersDialog_.data(),
&dialogs::InviteUsers::closing,
this,
[this, callback](bool isSending, QStringList invitees) {
inviteUsersModal_->hide();

if (isSending && !invitees.isEmpty())
callback(invitees);
});
}

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

inviteUsersModal_->show();
}

void
MainWindow::openJoinRoomDialog(std::function<void(const QString &room_id)> callback)
{
if (joinRoomDialog_.isNull()) {
joinRoomDialog_ = QSharedPointer<dialogs::JoinRoom>(new dialogs::JoinRoom(this));

connect(joinRoomDialog_.data(),
&dialogs::JoinRoom::closing,
this,
[this, callback](bool isJoining, const QString &room) {
joinRoomModal_->hide();

if (isJoining && !room.isEmpty())
callback(room);
});
}

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

joinRoomModal_->show();
}

void
MainWindow::openCreateRoomDialog(
std::function<void(const mtx::requests::CreateRoom &request)> callback)
{
if (createRoomDialog_.isNull()) {
createRoomDialog_ =
QSharedPointer<dialogs::CreateRoom>(new dialogs::CreateRoom(this));

connect(
createRoomDialog_.data(),
&dialogs::CreateRoom::closing,
this,
[this, callback](bool isCreating, const mtx::requests::CreateRoom &request) {
createRoomModal_->hide();

if (isCreating)
callback(request);
});
}

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

createRoomModal_->show();
}

void
MainWindow::openLogoutDialog(std::function<void()> callback)
{
if (logoutDialog_.isNull()) {
logoutDialog_ = QSharedPointer<dialogs::Logout>(new dialogs::Logout(this));
connect(logoutDialog_.data(),
&dialogs::Logout::closing,
this,
[this, callback](bool logging_out) {
logoutModal_->hide();

if (logging_out)
callback();
});
}

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

logoutModal_->show();
}

bool
MainWindow::hasActiveDialogs() const
{
return (!leaveRoomModal_.isNull() && leaveRoomModal_->isVisible()) ||
(!progressModal_.isNull() && progressModal_->isVisible());
(!progressModal_.isNull() && progressModal_->isVisible()) ||
(!inviteUsersModal_.isNull() && inviteUsersModal_->isVisible()) ||
(!joinRoomModal_.isNull() && joinRoomModal_->isVisible()) ||
(!createRoomModal_.isNull() && createRoomModal_->isVisible()) ||
(!logoutModal_.isNull() && logoutModal_->isVisible());
}
50 changes: 6 additions & 44 deletions src/SideBarActions.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <QDebug>
#include <QIcon>

#include <mtx/requests.hpp>

#include "Config.h"
#include "MainWindow.h"
#include "OverlayModal.h"
Expand Down Expand Up @@ -35,53 +37,13 @@ SideBarActions::SideBarActions(QWidget *parent)
joinRoomAction_ = new QAction(tr("Join a room"), this);

connect(joinRoomAction_, &QAction::triggered, this, [this]() {
if (joinRoomDialog_.isNull()) {
joinRoomDialog_ =
QSharedPointer<dialogs::JoinRoom>(new dialogs::JoinRoom(this));

connect(joinRoomDialog_.data(),
&dialogs::JoinRoom::closing,
this,
[this](bool isJoining, const QString &room) {
joinRoomModal_->hide();

if (isJoining && !room.isEmpty())
emit joinRoom(room);
});
}

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

joinRoomModal_->show();
MainWindow::instance()->openJoinRoomDialog(
[this](const QString &room_id) { emit joinRoom(room_id); });
});

connect(createRoomAction_, &QAction::triggered, this, [this]() {
if (createRoomDialog_.isNull()) {
createRoomDialog_ =
QSharedPointer<dialogs::CreateRoom>(new dialogs::CreateRoom(this));

connect(createRoomDialog_.data(),
&dialogs::CreateRoom::closing,
this,
[this](bool isCreating, const mtx::requests::CreateRoom &request) {
createRoomModal_->hide();

if (isCreating)
emit createRoom(request);
});
}

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

createRoomModal_->show();
MainWindow::instance()->openCreateRoomDialog(
[this](const mtx::requests::CreateRoom &req) { emit createRoom(req); });
});

addMenu_->addAction(createRoomAction_);
Expand Down
24 changes: 2 additions & 22 deletions src/TopRoomBar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,8 @@ TopRoomBar::TopRoomBar(QWidget *parent)

inviteUsers_ = new QAction(tr("Invite users"), this);
connect(inviteUsers_, &QAction::triggered, this, [this]() {
if (inviteUsersDialog_.isNull()) {
inviteUsersDialog_ =
QSharedPointer<dialogs::InviteUsers>(new dialogs::InviteUsers(this));

connect(inviteUsersDialog_.data(),
&dialogs::InviteUsers::closing,
this,
[this](bool isSending, QStringList invitees) {
inviteUsersModal_->hide();

if (isSending && !invitees.isEmpty())
emit inviteUsers(invitees);
});
}

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

inviteUsersModal_->show();
MainWindow::instance()->openInviteUsersDialog(
[this](const QStringList &invitees) { emit inviteUsers(invitees); });
});

leaveRoom_ = new QAction(tr("Leave room"), this);
Expand Down
Loading

0 comments on commit 746f74a

Please sign in to comment.