mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58: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 showQuickSwitcher();
|
||||
void showReadReceipts(const QString &event_id);
|
||||
QString currentRoom() const { return current_room_; }
|
||||
|
||||
static ChatPage *instance() { return instance_; }
|
||||
|
||||
|
|
|
@ -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> 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_;
|
||||
};
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
|
||||
#include <mtx.hpp>
|
||||
|
||||
#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<OverlayModal> leaveRoomModal_;
|
||||
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;
|
||||
|
||||
std::map<QString, QSharedPointer<RoomInfoListItem>> rooms_;
|
||||
QString selectedRoom_;
|
||||
|
||||
|
|
|
@ -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<OverlayModal> leaveRoomModal_;
|
||||
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;
|
||||
|
||||
QSharedPointer<OverlayModal> inviteUsersModal_;
|
||||
QSharedPointer<dialogs::InviteUsers> inviteUsersDialog_;
|
||||
|
||||
|
|
|
@ -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, [=]() {
|
||||
|
|
|
@ -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<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_);
|
||||
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));
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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_);
|
||||
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue