Don't open room switcher when another dialog is open

fixes #251
This commit is contained in:
Konstantinos Sideris 2018-03-04 13:40:30 +02:00
parent 47c31b9a18
commit b15a04b00a
8 changed files with 165 additions and 118 deletions

View file

@ -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
@ -50,6 +60,11 @@ public:
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);
@ -113,4 +128,20 @@ private:
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_;
};

View file

@ -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
{
@ -36,12 +37,6 @@ private:
QAction *createRoomAction_;
QAction *joinRoomAction_;
QSharedPointer<OverlayModal> joinRoomModal_;
QSharedPointer<dialogs::JoinRoom> joinRoomDialog_;
QSharedPointer<OverlayModal> createRoomModal_;
QSharedPointer<dialogs::CreateRoom> createRoomDialog_;
FlatButton *settingsBtn_;
FlatButton *createRoomBtn_;
FlatButton *joinRoomBtn_;

View file

@ -26,9 +26,6 @@
#include <QSharedPointer>
#include <QVBoxLayout>
#include "dialogs/InviteUsers.h"
#include "dialogs/LeaveRoom.h"
class Avatar;
class FlatButton;
class Label;
@ -74,9 +71,6 @@ private:
FlatButton *settingsBtn_;
QSharedPointer<OverlayModal> inviteUsersModal_;
QSharedPointer<dialogs::InviteUsers> inviteUsersDialog_;
Avatar *avatar_;
int buttonSize_;

View file

@ -20,8 +20,6 @@
#include <QLabel>
#include <QLayout>
#include "dialogs/Logout.h"
class Avatar;
class FlatButton;
class OverlayModal;
@ -46,9 +44,6 @@ protected:
void resizeEvent(QResizeEvent *event) override;
void paintEvent(QPaintEvent *event) override;
private slots:
void closeLogoutDialog(bool isLoggingOut);
private:
Avatar *userAvatar_;
@ -67,8 +62,5 @@ private:
QImage avatar_image_;
QSharedPointer<OverlayModal> logoutModal_;
QSharedPointer<dialogs::Logout> logoutDialog_;
int logoutButtonSize_;
};

View file

@ -21,6 +21,8 @@
#include <QSettings>
#include <QShortcut>
#include <mtx/requests.hpp>
#include "ChatPage.h"
#include "Config.h"
#include "LoadingIndicator.h"
@ -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;
@ -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)
@ -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());
}

View file

@ -1,6 +1,8 @@
#include <QDebug>
#include <QIcon>
#include <mtx/requests.hpp>
#include "Config.h"
#include "MainWindow.h"
#include "OverlayModal.h"
@ -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_);

View file

@ -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);

View file

@ -28,8 +28,6 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
: QWidget(parent)
, display_name_("User")
, user_id_("@user:homeserver.org")
, logoutModal_{nullptr}
, logoutDialog_{nullptr}
, logoutButtonSize_{20}
{
setFixedHeight(65);
@ -91,33 +89,10 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
// Show the confirmation dialog.
connect(logoutButton_, &QPushButton::clicked, this, [this]() {
if (logoutDialog_.isNull()) {
logoutDialog_ = QSharedPointer<dialogs::Logout>(new dialogs::Logout(this));
connect(logoutDialog_.data(),
SIGNAL(closing(bool)),
this,
SLOT(closeLogoutDialog(bool)));
}
if (logoutModal_.isNull()) {
logoutModal_ = QSharedPointer<OverlayModal>(
new OverlayModal(MainWindow::instance(), logoutDialog_.data()));
logoutModal_->setColor(QColor(30, 30, 30, 170));
}
logoutModal_->show();
MainWindow::instance()->openLogoutDialog([this]() { emit logout(); });
});
}
void
UserInfoWidget::closeLogoutDialog(bool isLoggingOut)
{
logoutModal_->hide();
if (isLoggingOut)
emit logout();
}
void
UserInfoWidget::resizeEvent(QResizeEvent *event)
{