mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 14:18:49 +03:00
Move LeaveRoom dialog to MainWindow (#87)
This commit is contained in:
parent
3fd257243c
commit
26f221ec23
8 changed files with 37 additions and 86 deletions
|
@ -66,6 +66,7 @@ public:
|
||||||
void bootstrap(QString userid, QString homeserver, QString token);
|
void bootstrap(QString userid, QString homeserver, QString token);
|
||||||
void showQuickSwitcher();
|
void showQuickSwitcher();
|
||||||
void showReadReceipts(const QString &event_id);
|
void showReadReceipts(const QString &event_id);
|
||||||
|
QString currentRoom() const { return current_room_; }
|
||||||
|
|
||||||
static ChatPage *instance() { return instance_; }
|
static ChatPage *instance() { return instance_; }
|
||||||
|
|
||||||
|
|
|
@ -35,17 +35,22 @@ class SnackBar;
|
||||||
class TrayIcon;
|
class TrayIcon;
|
||||||
class UserSettings;
|
class UserSettings;
|
||||||
|
|
||||||
|
namespace dialogs {
|
||||||
|
class LeaveRoom;
|
||||||
|
}
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
|
||||||
|
|
||||||
static MainWindow *instance() { return instance_; };
|
static MainWindow *instance() { return instance_; };
|
||||||
void saveCurrentWindowSize();
|
void saveCurrentWindowSize();
|
||||||
|
|
||||||
|
void openLeaveRoomDialog(const QString &room_id = "");
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
||||||
|
@ -78,31 +83,27 @@ private:
|
||||||
|
|
||||||
//! The initial welcome screen.
|
//! The initial welcome screen.
|
||||||
WelcomePage *welcome_page_;
|
WelcomePage *welcome_page_;
|
||||||
|
|
||||||
//! The login screen.
|
//! The login screen.
|
||||||
LoginPage *login_page_;
|
LoginPage *login_page_;
|
||||||
|
|
||||||
//! The register page.
|
//! The register page.
|
||||||
RegisterPage *register_page_;
|
RegisterPage *register_page_;
|
||||||
|
|
||||||
//! A stacked widget that handles the transitions between widgets.
|
//! A stacked widget that handles the transitions between widgets.
|
||||||
QStackedWidget *pageStack_;
|
QStackedWidget *pageStack_;
|
||||||
|
|
||||||
//! The main chat area.
|
//! The main chat area.
|
||||||
ChatPage *chat_page_;
|
ChatPage *chat_page_;
|
||||||
UserSettingsPage *userSettingsPage_;
|
UserSettingsPage *userSettingsPage_;
|
||||||
QSharedPointer<UserSettings> userSettings_;
|
QSharedPointer<UserSettings> userSettings_;
|
||||||
|
|
||||||
//! Used to hide undefined states between page transitions.
|
//! Used to hide undefined states between page transitions.
|
||||||
QSharedPointer<OverlayModal> progressModal_;
|
QSharedPointer<OverlayModal> progressModal_;
|
||||||
QSharedPointer<LoadingIndicator> spinner_;
|
QSharedPointer<LoadingIndicator> spinner_;
|
||||||
|
|
||||||
//! Matrix Client API provider.
|
//! Matrix Client API provider.
|
||||||
QSharedPointer<MatrixClient> client_;
|
QSharedPointer<MatrixClient> client_;
|
||||||
|
|
||||||
//! Tray icon that shows the unread message count.
|
//! Tray icon that shows the unread message count.
|
||||||
TrayIcon *trayIcon_;
|
TrayIcon *trayIcon_;
|
||||||
|
|
||||||
//! Notifications display.
|
//! Notifications display.
|
||||||
QSharedPointer<SnackBar> snackBar_;
|
QSharedPointer<SnackBar> snackBar_;
|
||||||
|
//! Leave room modal.
|
||||||
|
QSharedPointer<OverlayModal> leaveRoomModal_;
|
||||||
|
//! Leave room dialog.
|
||||||
|
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
|
|
||||||
#include <mtx.hpp>
|
#include <mtx.hpp>
|
||||||
|
|
||||||
#include "dialogs/LeaveRoom.h"
|
|
||||||
|
|
||||||
class LeaveRoomDialog;
|
class LeaveRoomDialog;
|
||||||
class MatrixClient;
|
class MatrixClient;
|
||||||
class Cache;
|
class Cache;
|
||||||
|
@ -79,8 +77,6 @@ public slots:
|
||||||
void updateUnreadMessageCount(const QString &roomid, int count);
|
void updateUnreadMessageCount(const QString &roomid, int count);
|
||||||
void updateRoomDescription(const QString &roomid, const DescInfo &info);
|
void updateRoomDescription(const QString &roomid, const DescInfo &info);
|
||||||
void closeJoinRoomDialog(bool isJoining, QString roomAlias);
|
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);
|
void clearRoomMessageCount(const QString &room_id);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -109,9 +105,6 @@ private:
|
||||||
|
|
||||||
OverlayModal *joinRoomModal_;
|
OverlayModal *joinRoomModal_;
|
||||||
|
|
||||||
QSharedPointer<OverlayModal> leaveRoomModal_;
|
|
||||||
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;
|
|
||||||
|
|
||||||
std::map<QString, QSharedPointer<RoomInfoListItem>> rooms_;
|
std::map<QString, QSharedPointer<RoomInfoListItem>> rooms_;
|
||||||
QString selectedRoom_;
|
QString selectedRoom_;
|
||||||
|
|
||||||
|
|
|
@ -53,16 +53,12 @@ public:
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void leaveRoom();
|
|
||||||
void inviteUsers(QStringList users);
|
void inviteUsers(QStringList users);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
|
||||||
void closeLeaveRoomDialog(bool leaving);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHBoxLayout *topLayout_;
|
QHBoxLayout *topLayout_;
|
||||||
QVBoxLayout *textLayout_;
|
QVBoxLayout *textLayout_;
|
||||||
|
@ -79,9 +75,6 @@ private:
|
||||||
|
|
||||||
FlatButton *settingsBtn_;
|
FlatButton *settingsBtn_;
|
||||||
|
|
||||||
QSharedPointer<OverlayModal> leaveRoomModal_;
|
|
||||||
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;
|
|
||||||
|
|
||||||
QSharedPointer<OverlayModal> inviteUsersModal_;
|
QSharedPointer<OverlayModal> inviteUsersModal_;
|
||||||
QSharedPointer<dialogs::InviteUsers> inviteUsersDialog_;
|
QSharedPointer<dialogs::InviteUsers> inviteUsersDialog_;
|
||||||
|
|
||||||
|
|
|
@ -144,8 +144,6 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
|
||||||
connect(user_info_widget_, SIGNAL(logout()), client_.data(), SLOT(logout()));
|
connect(user_info_widget_, SIGNAL(logout()), client_.data(), SLOT(logout()));
|
||||||
connect(client_.data(), SIGNAL(loggedOut()), this, 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) {
|
connect(top_bar_, &TopRoomBar::inviteUsers, this, [=](QStringList users) {
|
||||||
for (int ii = 0; ii < users.size(); ++ii) {
|
for (int ii = 0; ii < users.size(); ++ii) {
|
||||||
QTimer::singleShot(ii * 1000, this, [=]() {
|
QTimer::singleShot(ii * 1000, this, [=]() {
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "TrayIcon.h"
|
#include "TrayIcon.h"
|
||||||
#include "UserSettingsPage.h"
|
#include "UserSettingsPage.h"
|
||||||
#include "WelcomePage.h"
|
#include "WelcomePage.h"
|
||||||
|
#include "dialogs/LeaveRoom.h"
|
||||||
|
|
||||||
MainWindow *MainWindow::instance_ = nullptr;
|
MainWindow *MainWindow::instance_ = nullptr;
|
||||||
|
|
||||||
|
@ -262,4 +263,24 @@ MainWindow::hasActiveUser()
|
||||||
settings.contains("auth/user_id");
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -88,7 +88,9 @@ RoomList::addRoom(const QSharedPointer<RoomSettings> &settings,
|
||||||
{
|
{
|
||||||
auto room_item = new RoomInfoListItem(settings, state, room_id, scrollArea_);
|
auto room_item = new RoomInfoListItem(settings, state, room_id, scrollArea_);
|
||||||
connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom);
|
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));
|
rooms_.emplace(room_id, QSharedPointer<RoomInfoListItem>(room_item));
|
||||||
|
|
||||||
|
@ -189,28 +191,6 @@ RoomList::setInitialRooms(const std::map<QString, QSharedPointer<RoomSettings>>
|
||||||
emit roomChanged(room.first);
|
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
|
void
|
||||||
RoomList::sync(const std::map<QString, QSharedPointer<RoomState>> &states,
|
RoomList::sync(const std::map<QString, QSharedPointer<RoomState>> &states,
|
||||||
const std::map<QString, QSharedPointer<RoomSettings>> &settings)
|
const std::map<QString, QSharedPointer<RoomSettings>> &settings)
|
||||||
|
@ -362,15 +342,6 @@ RoomList::closeJoinRoomDialog(bool isJoining, QString roomAlias)
|
||||||
client_->joinRoom(roomAlias);
|
client_->joinRoom(roomAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
RoomList::closeLeaveRoomDialog(bool leaving, const QString &room_id)
|
|
||||||
{
|
|
||||||
leaveRoomModal_->fadeOut();
|
|
||||||
|
|
||||||
if (leaving)
|
|
||||||
client_->leaveRoom(room_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RoomList::setFilterRooms(bool isFilteringEnabled)
|
RoomList::setFilterRooms(bool isFilteringEnabled)
|
||||||
{
|
{
|
||||||
|
|
|
@ -119,24 +119,7 @@ TopRoomBar::TopRoomBar(QWidget *parent)
|
||||||
|
|
||||||
leaveRoom_ = new QAction(tr("Leave room"), this);
|
leaveRoom_ = new QAction(tr("Leave room"), this);
|
||||||
connect(leaveRoom_, &QAction::triggered, this, [=]() {
|
connect(leaveRoom_, &QAction::triggered, this, [=]() {
|
||||||
if (leaveRoomDialog_.isNull()) {
|
MainWindow::instance()->openLeaveRoomDialog();
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
menu_->addAction(toggleNotifications_);
|
menu_->addAction(toggleNotifications_);
|
||||||
|
@ -160,16 +143,6 @@ TopRoomBar::TopRoomBar(QWidget *parent)
|
||||||
setLayout(topLayout_);
|
setLayout(topLayout_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
TopRoomBar::closeLeaveRoomDialog(bool leaving)
|
|
||||||
{
|
|
||||||
leaveRoomModal_->fadeOut();
|
|
||||||
|
|
||||||
if (leaving) {
|
|
||||||
emit leaveRoom();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TopRoomBar::updateRoomAvatarFromName(const QString &name)
|
TopRoomBar::updateRoomAvatarFromName(const QString &name)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue