2017-04-06 02:06:42 +03:00
|
|
|
/*
|
|
|
|
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-09-24 17:39:06 +03:00
|
|
|
#include <QApplication>
|
2017-04-06 02:06:42 +03:00
|
|
|
#include <QLayout>
|
|
|
|
#include <QSettings>
|
2017-09-24 13:58:36 +03:00
|
|
|
#include <QShortcut>
|
2017-10-28 15:46:39 +03:00
|
|
|
|
2018-03-04 14:40:30 +03:00
|
|
|
#include <mtx/requests.hpp>
|
|
|
|
|
2017-10-28 15:46:39 +03:00
|
|
|
#include "ChatPage.h"
|
|
|
|
#include "Config.h"
|
|
|
|
#include "LoadingIndicator.h"
|
2018-06-09 16:03:14 +03:00
|
|
|
#include "Logging.hpp"
|
2017-10-28 15:46:39 +03:00
|
|
|
#include "LoginPage.h"
|
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "MatrixClient.h"
|
|
|
|
#include "OverlayModal.h"
|
|
|
|
#include "RegisterPage.h"
|
|
|
|
#include "SnackBar.h"
|
|
|
|
#include "TrayIcon.h"
|
2017-11-02 01:41:13 +03:00
|
|
|
#include "UserSettingsPage.h"
|
2017-10-28 15:46:39 +03:00
|
|
|
#include "WelcomePage.h"
|
2018-03-04 14:40:30 +03:00
|
|
|
|
|
|
|
#include "dialogs/CreateRoom.h"
|
|
|
|
#include "dialogs/InviteUsers.h"
|
|
|
|
#include "dialogs/JoinRoom.h"
|
2018-02-10 17:05:31 +03:00
|
|
|
#include "dialogs/LeaveRoom.h"
|
2018-03-04 14:40:30 +03:00
|
|
|
#include "dialogs/Logout.h"
|
2018-05-01 19:35:28 +03:00
|
|
|
#include "dialogs/MemberList.hpp"
|
2018-04-30 21:41:47 +03:00
|
|
|
#include "dialogs/RoomSettings.hpp"
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-06-02 18:04:51 +03:00
|
|
|
MainWindow *MainWindow::instance_ = nullptr;
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QMainWindow(parent)
|
2017-11-06 00:04:55 +03:00
|
|
|
, progressModal_{nullptr}
|
|
|
|
, spinner_{nullptr}
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:58:00 +03:00
|
|
|
setWindowTitle("nheko");
|
|
|
|
setObjectName("MainWindow");
|
2017-05-14 21:10:03 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
restoreWindowSize();
|
2017-05-14 21:10:03 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
QFont font("Open Sans");
|
|
|
|
font.setPixelSize(conf::fontSize);
|
|
|
|
font.setStyleStrategy(QFont::PreferAntialias);
|
|
|
|
setFont(font);
|
2017-05-14 21:10:03 +03:00
|
|
|
|
2017-11-02 01:41:13 +03:00
|
|
|
userSettings_ = QSharedPointer<UserSettings>(new UserSettings);
|
|
|
|
trayIcon_ = new TrayIcon(":/logos/nheko-32.png", this);
|
2017-04-11 17:45:47 +03:00
|
|
|
|
2017-11-02 01:41:13 +03:00
|
|
|
welcome_page_ = new WelcomePage(this);
|
2018-05-08 18:43:56 +03:00
|
|
|
login_page_ = new LoginPage(this);
|
|
|
|
register_page_ = new RegisterPage(this);
|
|
|
|
chat_page_ = new ChatPage(userSettings_, this);
|
2017-11-02 01:41:13 +03:00
|
|
|
userSettingsPage_ = new UserSettingsPage(userSettings_, this);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
// Initialize sliding widget manager.
|
2017-09-30 17:05:05 +03:00
|
|
|
pageStack_ = new QStackedWidget(this);
|
|
|
|
pageStack_->addWidget(welcome_page_);
|
|
|
|
pageStack_->addWidget(login_page_);
|
|
|
|
pageStack_->addWidget(register_page_);
|
|
|
|
pageStack_->addWidget(chat_page_);
|
2017-11-02 01:41:13 +03:00
|
|
|
pageStack_->addWidget(userSettingsPage_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-30 17:05:05 +03:00
|
|
|
setCentralWidget(pageStack_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
connect(welcome_page_, SIGNAL(userLogin()), this, SLOT(showLoginPage()));
|
|
|
|
connect(welcome_page_, SIGNAL(userRegister()), this, SLOT(showRegisterPage()));
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
connect(login_page_, SIGNAL(backButtonClicked()), this, SLOT(showWelcomePage()));
|
2018-02-18 23:22:26 +03:00
|
|
|
connect(login_page_, &LoginPage::loggingIn, this, &MainWindow::showOverlayProgressBar);
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(
|
2018-03-12 23:23:26 +03:00
|
|
|
register_page_, &RegisterPage::registering, this, &MainWindow::showOverlayProgressBar);
|
|
|
|
connect(
|
|
|
|
login_page_, &LoginPage::errorOccurred, this, [this]() { removeOverlayProgressBar(); });
|
|
|
|
connect(register_page_, &RegisterPage::errorOccurred, this, [this]() {
|
|
|
|
removeOverlayProgressBar();
|
|
|
|
});
|
2017-09-10 12:58:00 +03:00
|
|
|
connect(register_page_, SIGNAL(backButtonClicked()), this, SLOT(showWelcomePage()));
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-04-24 23:57:49 +03:00
|
|
|
connect(chat_page_, &ChatPage::closing, this, &MainWindow::showWelcomePage);
|
2018-02-18 23:22:26 +03:00
|
|
|
connect(
|
|
|
|
chat_page_, &ChatPage::showOverlayProgressBar, this, &MainWindow::showOverlayProgressBar);
|
2017-09-10 12:58:00 +03:00
|
|
|
connect(
|
|
|
|
chat_page_, SIGNAL(changeWindowTitle(QString)), this, SLOT(setWindowTitle(QString)));
|
|
|
|
connect(chat_page_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int)));
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(chat_page_, &ChatPage::showLoginPage, this, [this](const QString &msg) {
|
2017-10-20 22:32:48 +03:00
|
|
|
login_page_->loginError(msg);
|
|
|
|
showLoginPage();
|
|
|
|
});
|
2017-05-21 16:36:06 +03:00
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(userSettingsPage_, &UserSettingsPage::moveBack, this, [this]() {
|
2017-11-02 01:41:13 +03:00
|
|
|
pageStack_->setCurrentWidget(chat_page_);
|
|
|
|
});
|
|
|
|
|
2017-11-02 23:02:31 +03:00
|
|
|
connect(
|
|
|
|
userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool)));
|
2017-11-02 23:00:43 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
connect(trayIcon_,
|
|
|
|
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
|
|
|
this,
|
|
|
|
SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
|
2017-04-09 02:17:04 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
connect(chat_page_, SIGNAL(contentLoaded()), this, SLOT(removeOverlayProgressBar()));
|
2017-11-02 01:41:13 +03:00
|
|
|
connect(
|
|
|
|
chat_page_, &ChatPage::showUserSettingsPage, this, &MainWindow::showUserSettingsPage);
|
2017-04-26 02:23:12 +03:00
|
|
|
|
2018-06-09 16:03:14 +03:00
|
|
|
connect(login_page_, &LoginPage::loginOk, this, [this](const mtx::responses::Login &res) {
|
|
|
|
http::v2::client()->set_user(res.user_id);
|
|
|
|
showChatPage();
|
2018-05-02 15:30:08 +03:00
|
|
|
});
|
2018-03-12 23:23:26 +03:00
|
|
|
|
2018-06-09 16:03:14 +03:00
|
|
|
connect(register_page_, &RegisterPage::registerOk, this, &MainWindow::showChatPage);
|
|
|
|
|
2017-09-24 13:58:36 +03:00
|
|
|
QShortcut *quitShortcut = new QShortcut(QKeySequence::Quit, this);
|
|
|
|
connect(quitShortcut, &QShortcut::activated, this, QApplication::quit);
|
|
|
|
|
2017-11-03 09:54:17 +03:00
|
|
|
QShortcut *quickSwitchShortcut = new QShortcut(QKeySequence("Ctrl+K"), this);
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(quickSwitchShortcut, &QShortcut::activated, this, [this]() {
|
2018-02-26 14:17:04 +03:00
|
|
|
if (chat_page_->isVisible() && !hasActiveDialogs())
|
|
|
|
chat_page_->showQuickSwitcher();
|
2017-11-03 09:54:17 +03:00
|
|
|
});
|
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
QSettings settings;
|
2017-05-22 18:03:37 +03:00
|
|
|
|
2017-11-02 23:00:43 +03:00
|
|
|
trayIcon_->setVisible(userSettings_->isTrayEnabled());
|
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
if (hasActiveUser()) {
|
|
|
|
QString token = settings.value("auth/access_token").toString();
|
|
|
|
QString home_server = settings.value("auth/home_server").toString();
|
|
|
|
QString user_id = settings.value("auth/user_id").toString();
|
2018-06-10 20:03:45 +03:00
|
|
|
QString device_id = settings.value("auth/device_id").toString();
|
2017-05-22 18:03:37 +03:00
|
|
|
|
2018-06-09 16:03:14 +03:00
|
|
|
http::v2::client()->set_access_token(token.toStdString());
|
|
|
|
http::v2::client()->set_server(home_server.toStdString());
|
2018-06-10 20:03:45 +03:00
|
|
|
http::v2::client()->set_device_id(device_id.toStdString());
|
2018-06-09 16:03:14 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
using namespace mtx::identifiers;
|
|
|
|
http::v2::client()->set_user(parse<User>(user_id.toStdString()));
|
|
|
|
} catch (const std::invalid_argument &e) {
|
2018-06-14 02:28:35 +03:00
|
|
|
nhlog::ui()->critical("bootstrapped with invalid user_id: {}",
|
2018-06-09 16:03:14 +03:00
|
|
|
user_id.toStdString());
|
|
|
|
}
|
|
|
|
|
|
|
|
showChatPage();
|
2017-09-10 12:58:00 +03:00
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2018-07-04 00:05:05 +03:00
|
|
|
void
|
|
|
|
MainWindow::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
adjustSideBars();
|
|
|
|
QMainWindow::showEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MainWindow::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
adjustSideBars();
|
|
|
|
QMainWindow::resizeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MainWindow::adjustSideBars()
|
|
|
|
{
|
|
|
|
const int timelineWidth = chat_page_->timelineWidth();
|
|
|
|
const int minAvailableWidth =
|
|
|
|
conf::sideBarCollapsePoint + ui::sidebar::CommunitiesSidebarSize;
|
|
|
|
|
|
|
|
if (timelineWidth < minAvailableWidth && !chat_page_->isSideBarExpanded()) {
|
|
|
|
chat_page_->hideSideBars();
|
|
|
|
} else {
|
|
|
|
chat_page_->showSideBars();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
MainWindow::restoreWindowSize()
|
2017-07-30 13:59:28 +03:00
|
|
|
{
|
2017-09-10 12:58:00 +03:00
|
|
|
QSettings settings;
|
|
|
|
int savedWidth = settings.value("window/width").toInt();
|
|
|
|
int savedheight = settings.value("window/height").toInt();
|
|
|
|
|
|
|
|
if (savedWidth == 0 || savedheight == 0)
|
|
|
|
resize(conf::window::width, conf::window::height);
|
|
|
|
else
|
|
|
|
resize(savedWidth, savedheight);
|
2017-07-30 13:59:28 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
MainWindow::saveCurrentWindowSize()
|
2017-07-30 13:59:28 +03:00
|
|
|
{
|
2017-09-10 12:58:00 +03:00
|
|
|
QSettings settings;
|
|
|
|
QSize current = size();
|
2017-07-30 13:59:28 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
settings.setValue("window/width", current.width());
|
|
|
|
settings.setValue("window/height", current.height());
|
2017-07-30 13:59:28 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
MainWindow::removeOverlayProgressBar()
|
2017-04-26 02:23:12 +03:00
|
|
|
{
|
2017-09-10 12:58:00 +03:00
|
|
|
QTimer *timer = new QTimer(this);
|
|
|
|
timer->setSingleShot(true);
|
2017-04-26 02:23:12 +03:00
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(timer, &QTimer::timeout, [this, timer]() {
|
2017-09-10 12:58:00 +03:00
|
|
|
timer->deleteLater();
|
2017-04-26 02:23:12 +03:00
|
|
|
|
2017-10-07 20:09:34 +03:00
|
|
|
if (!progressModal_.isNull())
|
2018-02-17 19:43:40 +03:00
|
|
|
progressModal_->hide();
|
2017-04-26 02:23:12 +03:00
|
|
|
|
2017-10-07 20:09:34 +03:00
|
|
|
if (!spinner_.isNull())
|
|
|
|
spinner_->stop();
|
2017-04-26 02:23:12 +03:00
|
|
|
|
2017-10-07 20:09:34 +03:00
|
|
|
progressModal_.reset();
|
|
|
|
spinner_.reset();
|
2017-09-10 12:58:00 +03:00
|
|
|
});
|
|
|
|
|
2017-10-08 22:38:38 +03:00
|
|
|
// FIXME: Snackbar doesn't work if it's initialized in the constructor.
|
2018-05-08 23:38:57 +03:00
|
|
|
QTimer::singleShot(0, this, [this]() {
|
2017-10-08 22:38:38 +03:00
|
|
|
snackBar_ = QSharedPointer<SnackBar>(new SnackBar(this));
|
|
|
|
connect(chat_page_,
|
|
|
|
&ChatPage::showNotification,
|
|
|
|
snackBar_.data(),
|
|
|
|
&SnackBar::showMessage);
|
|
|
|
});
|
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
timer->start(500);
|
2017-04-26 02:23:12 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
2018-06-09 16:03:14 +03:00
|
|
|
MainWindow::showChatPage()
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2018-06-09 16:03:14 +03:00
|
|
|
auto userid = QString::fromStdString(http::v2::client()->user_id().to_string());
|
2018-06-10 20:03:45 +03:00
|
|
|
auto device_id = QString::fromStdString(http::v2::client()->device_id());
|
2018-06-09 16:03:14 +03:00
|
|
|
auto homeserver = QString::fromStdString(http::v2::client()->server() + ":" +
|
|
|
|
std::to_string(http::v2::client()->port()));
|
|
|
|
auto token = QString::fromStdString(http::v2::client()->access_token());
|
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
QSettings settings;
|
|
|
|
settings.setValue("auth/access_token", token);
|
|
|
|
settings.setValue("auth/home_server", homeserver);
|
|
|
|
settings.setValue("auth/user_id", userid);
|
2018-06-10 20:03:45 +03:00
|
|
|
settings.setValue("auth/device_id", device_id);
|
2017-09-10 12:58:00 +03:00
|
|
|
|
2018-02-18 23:22:26 +03:00
|
|
|
showOverlayProgressBar();
|
2017-09-30 17:05:05 +03:00
|
|
|
|
2018-06-28 16:16:43 +03:00
|
|
|
pageStack_->setCurrentWidget(chat_page_);
|
2017-09-10 12:58:00 +03:00
|
|
|
|
2018-06-29 14:28:48 +03:00
|
|
|
pageStack_->removeWidget(welcome_page_);
|
|
|
|
pageStack_->removeWidget(login_page_);
|
|
|
|
pageStack_->removeWidget(register_page_);
|
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
login_page_->reset();
|
|
|
|
chat_page_->bootstrap(userid, homeserver, token);
|
|
|
|
|
|
|
|
instance_ = this;
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
MainWindow::closeEvent(QCloseEvent *event)
|
2017-05-21 16:36:06 +03:00
|
|
|
{
|
2018-07-11 20:55:13 +03:00
|
|
|
if (!qApp->isSavingSession() && isVisible() && pageSupportsTray() &&
|
|
|
|
userSettings_->isTrayEnabled()) {
|
2017-09-10 12:58:00 +03:00
|
|
|
event->ignore();
|
|
|
|
hide();
|
|
|
|
}
|
2017-05-21 16:36:06 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
|
2017-05-21 16:36:06 +03:00
|
|
|
{
|
2017-09-10 12:58:00 +03:00
|
|
|
switch (reason) {
|
|
|
|
case QSystemTrayIcon::Trigger:
|
|
|
|
if (!isVisible()) {
|
|
|
|
show();
|
|
|
|
} else {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-05-21 16:36:06 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
bool
|
|
|
|
MainWindow::hasActiveUser()
|
2017-05-22 18:03:37 +03:00
|
|
|
{
|
2017-09-10 12:58:00 +03:00
|
|
|
QSettings settings;
|
2017-05-22 18:03:37 +03:00
|
|
|
|
2017-09-10 12:58:00 +03:00
|
|
|
return settings.contains("auth/access_token") && settings.contains("auth/home_server") &&
|
|
|
|
settings.contains("auth/user_id");
|
2017-05-22 18:03:37 +03:00
|
|
|
}
|
|
|
|
|
2018-04-30 21:41:47 +03:00
|
|
|
void
|
|
|
|
MainWindow::openRoomSettings(const QString &room_id)
|
|
|
|
{
|
|
|
|
const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : "";
|
|
|
|
|
2018-05-08 20:30:09 +03:00
|
|
|
roomSettingsDialog_ =
|
|
|
|
QSharedPointer<dialogs::RoomSettings>(new dialogs::RoomSettings(roomToSearch, this));
|
2018-04-30 21:41:47 +03:00
|
|
|
|
|
|
|
connect(roomSettingsDialog_.data(), &dialogs::RoomSettings::closing, this, [this]() {
|
|
|
|
roomSettingsModal_->hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
roomSettingsModal_ =
|
|
|
|
QSharedPointer<OverlayModal>(new OverlayModal(this, roomSettingsDialog_.data()));
|
|
|
|
|
|
|
|
roomSettingsModal_->show();
|
|
|
|
}
|
|
|
|
|
2018-05-01 19:35:28 +03:00
|
|
|
void
|
|
|
|
MainWindow::openMemberListDialog(const QString &room_id)
|
|
|
|
{
|
|
|
|
const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : "";
|
|
|
|
|
2018-05-08 20:30:09 +03:00
|
|
|
memberListDialog_ =
|
|
|
|
QSharedPointer<dialogs::MemberList>(new dialogs::MemberList(roomToSearch, this));
|
2018-05-01 19:35:28 +03:00
|
|
|
|
|
|
|
memberListModal_ =
|
|
|
|
QSharedPointer<OverlayModal>(new OverlayModal(this, memberListDialog_.data()));
|
|
|
|
|
|
|
|
memberListModal_->show();
|
|
|
|
}
|
|
|
|
|
2018-02-10 17:05:31 +03:00
|
|
|
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));
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(leaveRoomDialog_.data(),
|
|
|
|
&dialogs::LeaveRoom::closing,
|
|
|
|
this,
|
2018-03-04 14:40:30 +03:00
|
|
|
[this, roomToLeave](bool leaving) {
|
2018-02-20 18:09:11 +03:00
|
|
|
leaveRoomModal_->hide();
|
2018-02-10 17:05:31 +03:00
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
if (leaving)
|
2018-06-09 16:03:14 +03:00
|
|
|
chat_page_->leaveRoom(roomToLeave);
|
2018-02-20 18:09:11 +03:00
|
|
|
});
|
2018-02-10 17:05:31 +03:00
|
|
|
|
|
|
|
leaveRoomModal_ =
|
|
|
|
QSharedPointer<OverlayModal>(new OverlayModal(this, leaveRoomDialog_.data()));
|
|
|
|
leaveRoomModal_->setColor(QColor(30, 30, 30, 170));
|
|
|
|
|
2018-02-17 19:43:40 +03:00
|
|
|
leaveRoomModal_->show();
|
2018-02-10 17:05:31 +03:00
|
|
|
}
|
2018-02-18 23:22:26 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
MainWindow::showOverlayProgressBar()
|
|
|
|
{
|
|
|
|
if (spinner_.isNull()) {
|
|
|
|
spinner_ = QSharedPointer<LoadingIndicator>(
|
|
|
|
new LoadingIndicator(this),
|
2018-02-20 18:09:11 +03:00
|
|
|
[](LoadingIndicator *indicator) { indicator->deleteLater(); });
|
2018-02-18 23:22:26 +03:00
|
|
|
spinner_->setFixedHeight(100);
|
|
|
|
spinner_->setFixedWidth(100);
|
|
|
|
spinner_->setObjectName("ChatPageLoadSpinner");
|
|
|
|
spinner_->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (progressModal_.isNull()) {
|
|
|
|
progressModal_ =
|
|
|
|
QSharedPointer<OverlayModal>(new OverlayModal(this, spinner_.data()),
|
2018-02-20 18:09:11 +03:00
|
|
|
[](OverlayModal *modal) { modal->deleteLater(); });
|
2018-05-01 19:35:28 +03:00
|
|
|
progressModal_->setColor(QColor(30, 30, 30));
|
2018-02-18 23:22:26 +03:00
|
|
|
progressModal_->setDismissible(false);
|
|
|
|
progressModal_->show();
|
|
|
|
}
|
|
|
|
}
|
2018-02-26 14:17:04 +03:00
|
|
|
|
2018-03-04 14:40:30 +03:00
|
|
|
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_->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_->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_->show();
|
|
|
|
}
|
|
|
|
|
2018-02-26 14:17:04 +03:00
|
|
|
bool
|
|
|
|
MainWindow::hasActiveDialogs() const
|
|
|
|
{
|
|
|
|
return (!leaveRoomModal_.isNull() && leaveRoomModal_->isVisible()) ||
|
2018-03-04 14:40:30 +03:00
|
|
|
(!progressModal_.isNull() && progressModal_->isVisible()) ||
|
|
|
|
(!inviteUsersModal_.isNull() && inviteUsersModal_->isVisible()) ||
|
|
|
|
(!joinRoomModal_.isNull() && joinRoomModal_->isVisible()) ||
|
|
|
|
(!createRoomModal_.isNull() && createRoomModal_->isVisible()) ||
|
|
|
|
(!logoutModal_.isNull() && logoutModal_->isVisible());
|
2018-02-26 14:17:04 +03:00
|
|
|
}
|
2018-07-11 20:55:13 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
MainWindow::pageSupportsTray() const
|
|
|
|
{
|
|
|
|
return !welcome_page_->isVisible() && !login_page_->isVisible() &&
|
|
|
|
!register_page_->isVisible();
|
|
|
|
}
|