2021-05-13 09:23:56 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#include "NhekoGlobalObject.h"
|
|
|
|
|
2021-05-13 09:52:02 +03:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
2021-08-04 03:27:50 +03:00
|
|
|
#include <QWindow>
|
2021-05-13 09:52:02 +03:00
|
|
|
|
2021-05-15 00:35:34 +03:00
|
|
|
#include "Cache_p.h"
|
2021-05-13 09:52:02 +03:00
|
|
|
#include "ChatPage.h"
|
2021-05-15 00:35:34 +03:00
|
|
|
#include "Logging.h"
|
2021-05-30 13:41:44 +03:00
|
|
|
#include "MainWindow.h"
|
2021-05-13 09:23:56 +03:00
|
|
|
#include "UserSettingsPage.h"
|
2021-05-15 00:35:34 +03:00
|
|
|
#include "Utils.h"
|
2021-10-14 23:53:11 +03:00
|
|
|
#include "voip/WebRTCSession.h"
|
2021-05-13 09:23:56 +03:00
|
|
|
|
|
|
|
Nheko::Nheko()
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
connect(
|
|
|
|
UserSettings::instance().get(), &UserSettings::themeChanged, this, &Nheko::colorsChanged);
|
|
|
|
connect(ChatPage::instance(), &ChatPage::contentLoaded, this, &Nheko::updateUserProfile);
|
2021-09-25 04:32:06 +03:00
|
|
|
connect(this, &Nheko::joinRoom, ChatPage::instance(), &ChatPage::joinRoom);
|
2021-05-15 00:35:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Nheko::updateUserProfile()
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (cache::client() && cache::client()->isInitialized())
|
|
|
|
currentUser_.reset(
|
|
|
|
new UserProfile("", utils::localUser(), ChatPage::instance()->timelineManager()));
|
|
|
|
else
|
|
|
|
currentUser_.reset();
|
|
|
|
emit profileChanged();
|
2021-05-13 09:23:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QPalette
|
|
|
|
Nheko::colors() const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
return Theme::paletteFromTheme(UserSettings::instance()->theme().toStdString());
|
2021-05-13 09:23:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QPalette
|
|
|
|
Nheko::inactiveColors() const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
auto p = colors();
|
|
|
|
p.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
|
|
|
return p;
|
2021-05-13 09:23:56 +03:00
|
|
|
}
|
2021-05-13 09:52:02 +03:00
|
|
|
|
2021-05-15 00:35:34 +03:00
|
|
|
Theme
|
|
|
|
Nheko::theme() const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
return Theme(UserSettings::instance()->theme().toStdString());
|
2021-05-15 00:35:34 +03:00
|
|
|
}
|
|
|
|
|
2021-05-13 09:52:02 +03:00
|
|
|
void
|
|
|
|
Nheko::openLink(QString link) const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
QUrl url(link);
|
|
|
|
// Open externally if we couldn't handle it internally
|
|
|
|
if (!ChatPage::instance()->handleMatrixUri(url)) {
|
2021-10-17 18:18:02 +03:00
|
|
|
const QStringList allowedUrlSchemes = {
|
|
|
|
"http",
|
|
|
|
"https",
|
|
|
|
"mailto",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (allowedUrlSchemes.contains(url.scheme()))
|
|
|
|
QDesktopServices::openUrl(url);
|
|
|
|
else
|
|
|
|
nhlog::ui()->warn("Url '{}' not opened, because the scheme is not in the allow list",
|
|
|
|
url.toDisplayString().toStdString());
|
2021-09-18 01:22:33 +03:00
|
|
|
}
|
2021-05-13 09:52:02 +03:00
|
|
|
}
|
2021-05-22 16:19:44 +03:00
|
|
|
void
|
|
|
|
Nheko::setStatusMessage(QString msg) const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
ChatPage::instance()->setStatus(msg);
|
2021-05-22 16:19:44 +03:00
|
|
|
}
|
2021-05-15 00:35:34 +03:00
|
|
|
|
|
|
|
UserProfile *
|
|
|
|
Nheko::currentUser() const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
nhlog::ui()->debug("Profile requested");
|
2021-05-15 00:35:34 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
return currentUser_.get();
|
2021-05-15 00:35:34 +03:00
|
|
|
}
|
2021-05-30 13:41:44 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
Nheko::showUserSettingsPage() const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
ChatPage::instance()->showUserSettingsPage();
|
2021-05-30 13:41:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-09-30 03:15:25 +03:00
|
|
|
Nheko::logout() const
|
2021-05-30 13:41:44 +03:00
|
|
|
{
|
2021-09-30 03:15:25 +03:00
|
|
|
ChatPage::instance()->initiateLogout();
|
2021-05-30 13:41:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Nheko::openCreateRoomDialog() const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
MainWindow::instance()->openCreateRoomDialog(
|
|
|
|
[](const mtx::requests::CreateRoom &req) { ChatPage::instance()->createRoom(req); });
|
2021-05-30 13:41:44 +03:00
|
|
|
}
|
|
|
|
|
2021-08-04 03:27:50 +03:00
|
|
|
void
|
|
|
|
Nheko::reparent(QWindow *win) const
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
win->setTransientParent(MainWindow::instance()->windowHandle());
|
2021-08-04 03:27:50 +03:00
|
|
|
}
|