2021-05-13 09:23:56 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
2022-01-01 06:57:53 +03:00
|
|
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
2021-05-13 09:23:56 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#include "NhekoGlobalObject.h"
|
|
|
|
|
2021-12-31 02:47:14 +03:00
|
|
|
#include <QApplication>
|
2021-05-13 09:52:02 +03:00
|
|
|
#include <QDesktopServices>
|
2021-12-31 02:47:14 +03:00
|
|
|
#include <QStyle>
|
2021-05-13 09:52:02 +03:00
|
|
|
#include <QUrl>
|
|
|
|
|
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-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())
|
2021-12-29 08:01:38 +03:00
|
|
|
currentUser_.reset(new UserProfile(
|
|
|
|
QLatin1String(""), utils::localUser(), ChatPage::instance()->timelineManager()));
|
2021-09-18 01:22:33 +03:00
|
|
|
else
|
|
|
|
currentUser_.reset();
|
|
|
|
emit profileChanged();
|
2021-05-13 09:23:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QPalette
|
|
|
|
Nheko::colors() const
|
|
|
|
{
|
2021-12-29 10:05:29 +03:00
|
|
|
return Theme::paletteFromTheme(UserSettings::instance()->theme());
|
2021-05-13 09:23:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QPalette
|
|
|
|
Nheko::inactiveColors() const
|
|
|
|
{
|
2021-12-29 10:05:29 +03:00
|
|
|
auto theme = UserSettings::instance()->theme();
|
|
|
|
if (theme == QLatin1String("light")) {
|
|
|
|
static QPalette lightInactive = [] {
|
|
|
|
auto lightInactive = Theme::paletteFromTheme(u"light");
|
|
|
|
lightInactive.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
|
|
|
return lightInactive;
|
|
|
|
}();
|
|
|
|
return lightInactive;
|
|
|
|
} else if (theme == QLatin1String("dark")) {
|
|
|
|
static QPalette darkInactive = [] {
|
|
|
|
auto darkInactive = Theme::paletteFromTheme(u"dark");
|
|
|
|
darkInactive.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
|
|
|
return darkInactive;
|
|
|
|
}();
|
|
|
|
return darkInactive;
|
|
|
|
} else {
|
|
|
|
static QPalette originalInactive = [] {
|
|
|
|
auto originalInactive = Theme::paletteFromTheme(u"system");
|
|
|
|
originalInactive.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
|
|
|
return originalInactive;
|
|
|
|
}();
|
|
|
|
return originalInactive;
|
|
|
|
}
|
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-12-29 10:05:29 +03:00
|
|
|
return Theme(UserSettings::instance()->theme());
|
2021-05-15 00:35:34 +03:00
|
|
|
}
|
|
|
|
|
2021-12-31 02:47:14 +03:00
|
|
|
int
|
|
|
|
Nheko::tooltipDelay() const
|
|
|
|
{
|
|
|
|
return QApplication::style()->styleHint(QStyle::StyleHint::SH_ToolTip_WakeUpDelay);
|
|
|
|
}
|
|
|
|
|
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-12-29 10:05:29 +03:00
|
|
|
static const QStringList allowedUrlSchemes = {
|
|
|
|
QStringLiteral("http"),
|
|
|
|
QStringLiteral("https"),
|
|
|
|
QStringLiteral("mailto"),
|
2021-10-17 18:18:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2022-03-29 05:50:25 +03:00
|
|
|
Nheko::createRoom(QString name, QString topic, QString aliasLocalpart, bool isEncrypted, int preset)
|
2021-05-30 13:41:44 +03:00
|
|
|
{
|
2022-03-29 05:50:25 +03:00
|
|
|
mtx::requests::CreateRoom req;
|
|
|
|
|
|
|
|
switch (preset) {
|
|
|
|
case 1:
|
|
|
|
req.preset = mtx::requests::Preset::PublicChat;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
req.preset = mtx::requests::Preset::TrustedPrivateChat;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
req.preset = mtx::requests::Preset::PrivateChat;
|
|
|
|
}
|
|
|
|
|
|
|
|
req.name = name.toStdString();
|
|
|
|
req.topic = topic.toStdString();
|
|
|
|
req.room_alias_name = aliasLocalpart.toStdString();
|
|
|
|
|
|
|
|
if (isEncrypted) {
|
|
|
|
mtx::events::StrippedEvent<mtx::events::state::Encryption> enc;
|
|
|
|
enc.type = mtx::events::EventType::RoomEncryption;
|
|
|
|
enc.content.algorithm = mtx::crypto::MEGOLM_ALGO;
|
|
|
|
req.initial_state.emplace_back(std::move(enc));
|
|
|
|
}
|
|
|
|
|
|
|
|
emit ChatPage::instance()->createRoom(req);
|
2021-05-30 13:41:44 +03:00
|
|
|
}
|