matrixion/src/ui/NhekoGlobalObject.cpp

105 lines
2.2 KiB
C++
Raw Normal View History

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>
#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"
#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)) {
QDesktopServices::openUrl(url);
}
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
}
void
Nheko::reparent(QWindow *win) const
{
2021-09-18 01:22:33 +03:00
win->setTransientParent(MainWindow::instance()->windowHandle());
}