2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// Copyright (C) 2021 tytan652 <tytan652@tytanium.xyz>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2020-04-05 16:52:06 +00:00
|
|
|
|
|
|
|
#include "ui.hpp"
|
|
|
|
#include "strings.hpp"
|
2022-08-28 12:28:37 +00:00
|
|
|
#include "ui-common.hpp"
|
2020-04-05 16:52:06 +00:00
|
|
|
#include "configuration.hpp"
|
|
|
|
#include "obs/obs-tools.hpp"
|
|
|
|
#include "plugin.hpp"
|
2023-03-09 14:16:50 +00:00
|
|
|
#include "ui/ui-obs-browser-widget.hpp"
|
2020-04-05 16:52:06 +00:00
|
|
|
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-disable.hpp"
|
|
|
|
#include <string_view>
|
|
|
|
#include "warning-enable.hpp"
|
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
// Translation Keys
|
2021-10-17 12:28:33 +00:00
|
|
|
constexpr std::string_view _i18n_prefix = "StreamFX::";
|
|
|
|
constexpr std::string_view _i18n_menu = "UI.Menu";
|
|
|
|
constexpr std::string_view _i18n_menu_support = "UI.Menu.Support";
|
|
|
|
constexpr std::string_view _i18n_menu_wiki = "UI.Menu.Wiki";
|
|
|
|
constexpr std::string_view _i18n_menu_website = "UI.Menu.Website";
|
|
|
|
constexpr std::string_view _i18n_menu_discord = "UI.Menu.Discord";
|
|
|
|
constexpr std::string_view _i18n_menu_youtube = "UI.Menu.YouTube";
|
|
|
|
constexpr std::string_view _i18n_menu_twitter = "UI.Menu.Twitter";
|
|
|
|
constexpr std::string_view _i18n_menu_github = "UI.Menu.Github";
|
|
|
|
constexpr std::string_view _i18n_menu_about = "UI.Menu.About";
|
2020-04-05 16:52:06 +00:00
|
|
|
|
|
|
|
// Configuration
|
|
|
|
constexpr std::string_view _cfg_have_shown_about = "UI.HaveShownAboutStreamFX";
|
|
|
|
|
|
|
|
// URLs
|
2021-10-17 12:28:33 +00:00
|
|
|
constexpr std::string_view _url_support = "https://s.xaymar.com/streamfx-dc-support";
|
|
|
|
constexpr std::string_view _url_wiki = "https://github.com/Xaymar/obs-StreamFX/wiki";
|
|
|
|
constexpr std::string_view _url_website = "https://streamfx.xaymar.com";
|
|
|
|
constexpr std::string_view _url_discord = "https://s.xaymar.com/streamfx-dc";
|
|
|
|
constexpr std::string_view _url_twitter = "https://s.xaymar.com/streamfx-tw";
|
|
|
|
constexpr std::string_view _url_youtube = "https://s.xaymar.com/streamfx-yt";
|
2020-04-05 16:52:06 +00:00
|
|
|
|
2023-03-09 14:16:50 +00:00
|
|
|
static std::shared_ptr<streamfx::ui::obs_browser_cef> _obs_browser_cef;
|
|
|
|
|
2020-04-24 22:57:38 +00:00
|
|
|
inline void qt_init_resource()
|
|
|
|
{
|
|
|
|
Q_INIT_RESOURCE(streamfx);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void qt_cleanup_resource()
|
|
|
|
{
|
|
|
|
Q_CLEANUP_RESOURCE(streamfx);
|
|
|
|
}
|
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
bool streamfx::ui::handler::have_shown_about_streamfx(bool shown)
|
|
|
|
{
|
2020-07-26 16:32:53 +00:00
|
|
|
auto config = streamfx::configuration::instance();
|
|
|
|
auto data = config->get();
|
2020-04-05 16:52:06 +00:00
|
|
|
if (shown) {
|
2020-07-26 16:32:53 +00:00
|
|
|
obs_data_set_bool(data.get(), _cfg_have_shown_about.data(), true);
|
2022-09-18 17:53:11 +00:00
|
|
|
config->save();
|
2020-04-05 16:52:06 +00:00
|
|
|
}
|
2020-07-26 16:32:53 +00:00
|
|
|
if (config->is_different_version()) {
|
2020-04-05 16:52:06 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
2020-07-26 16:32:53 +00:00
|
|
|
return obs_data_get_bool(data.get(), _cfg_have_shown_about.data());
|
2020-04-05 16:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
streamfx::ui::handler::handler()
|
|
|
|
: QObject(), _menu_action(), _menu(),
|
|
|
|
|
2021-10-17 12:28:33 +00:00
|
|
|
_action_support(), _action_wiki(), _action_website(), _action_discord(), _action_twitter(), _action_youtube(),
|
2020-04-05 16:52:06 +00:00
|
|
|
|
2021-01-21 02:00:44 +00:00
|
|
|
_about_action(), _about_dialog(),
|
2020-04-05 16:52:06 +00:00
|
|
|
|
2021-02-02 20:48:17 +00:00
|
|
|
_translator()
|
|
|
|
#ifdef ENABLE_UPDATER
|
|
|
|
,
|
|
|
|
_updater()
|
|
|
|
#endif
|
2021-01-21 02:00:44 +00:00
|
|
|
{
|
2020-04-05 16:52:06 +00:00
|
|
|
obs_frontend_add_event_callback(frontend_event_handler, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
streamfx::ui::handler::~handler()
|
|
|
|
{
|
|
|
|
obs_frontend_remove_event_callback(frontend_event_handler, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::handler::frontend_event_handler(obs_frontend_event event, void* private_data)
|
|
|
|
{
|
|
|
|
streamfx::ui::handler* ptr = reinterpret_cast<streamfx::ui::handler*>(private_data);
|
|
|
|
switch (event) {
|
|
|
|
case OBS_FRONTEND_EVENT_FINISHED_LOADING:
|
|
|
|
ptr->on_obs_loaded();
|
|
|
|
break;
|
2021-01-21 02:00:44 +00:00
|
|
|
case OBS_FRONTEND_EVENT_EXIT:
|
|
|
|
ptr->on_obs_exit();
|
|
|
|
break;
|
2020-04-05 16:52:06 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::handler::on_obs_loaded()
|
|
|
|
{
|
2021-01-21 02:00:44 +00:00
|
|
|
// Initialize the required Qt resources.
|
|
|
|
qt_init_resource();
|
|
|
|
|
|
|
|
// Add our own translation helper to the Qt Application.
|
|
|
|
_translator = new streamfx::ui::translator(this);
|
|
|
|
QCoreApplication::installTranslator(_translator);
|
|
|
|
|
2023-03-09 14:36:53 +00:00
|
|
|
// Pre-load CEF if available.
|
|
|
|
if (streamfx::ui::obs_browser_widget::is_available()) {
|
|
|
|
try {
|
|
|
|
_obs_browser_cef = streamfx::ui::obs_browser_cef::instance();
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
}
|
2023-03-09 14:16:50 +00:00
|
|
|
|
2021-01-21 02:00:44 +00:00
|
|
|
// Create the 'About StreamFX' dialog.
|
|
|
|
_about_dialog = new streamfx::ui::about();
|
|
|
|
|
|
|
|
{ // Create and build the StreamFX menu
|
|
|
|
_menu = new QMenu(reinterpret_cast<QWidget*>(obs_frontend_get_main_window()));
|
|
|
|
|
2021-10-17 12:28:33 +00:00
|
|
|
// Wiki
|
|
|
|
// Help & Support
|
|
|
|
// ---
|
2021-01-21 02:00:44 +00:00
|
|
|
// Website
|
|
|
|
// Discord
|
2021-10-17 12:28:33 +00:00
|
|
|
// Twitter
|
|
|
|
// YouTube
|
|
|
|
// <--->
|
|
|
|
// <Updater>
|
|
|
|
// ---
|
|
|
|
// About StreamFX
|
|
|
|
|
|
|
|
{
|
|
|
|
// Wiki
|
|
|
|
_action_wiki = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_wiki.data())));
|
|
|
|
_action_wiki->setMenuRole(QAction::NoRole);
|
|
|
|
connect(_action_wiki, &QAction::triggered, this, &streamfx::ui::handler::on_action_wiki);
|
|
|
|
|
|
|
|
// Help & Support
|
|
|
|
_action_support = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_support.data())));
|
|
|
|
_action_support->setMenuRole(QAction::NoRole);
|
|
|
|
connect(_action_support, &QAction::triggered, this, &streamfx::ui::handler::on_action_support);
|
|
|
|
}
|
2021-01-21 02:00:44 +00:00
|
|
|
|
2021-10-17 12:28:33 +00:00
|
|
|
_menu->addSeparator();
|
|
|
|
{
|
|
|
|
_action_website = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_website.data())));
|
|
|
|
_action_website->setMenuRole(QAction::NoRole);
|
|
|
|
connect(_action_website, &QAction::triggered, this, &streamfx::ui::handler::on_action_website);
|
|
|
|
|
|
|
|
_action_discord = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_discord.data())));
|
|
|
|
_action_discord->setMenuRole(QAction::NoRole);
|
|
|
|
connect(_action_discord, &QAction::triggered, this, &streamfx::ui::handler::on_action_discord);
|
|
|
|
|
|
|
|
_action_twitter = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_twitter.data())));
|
|
|
|
_action_twitter->setMenuRole(QAction::NoRole);
|
|
|
|
connect(_action_twitter, &QAction::triggered, this, &streamfx::ui::handler::on_action_twitter);
|
|
|
|
|
|
|
|
_action_youtube = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_youtube.data())));
|
|
|
|
_action_youtube->setMenuRole(QAction::NoRole);
|
|
|
|
connect(_action_youtube, &QAction::triggered, this, &streamfx::ui::handler::on_action_youtube);
|
|
|
|
}
|
2021-01-21 02:00:44 +00:00
|
|
|
|
|
|
|
// Create the updater.
|
|
|
|
#ifdef ENABLE_UPDATER
|
|
|
|
_updater = streamfx::ui::updater::instance(_menu);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_menu->addSeparator();
|
|
|
|
|
|
|
|
// About
|
|
|
|
_about_action = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_about.data())));
|
2021-04-19 12:01:09 +00:00
|
|
|
_about_action->setMenuRole(QAction::NoRole);
|
2021-01-21 02:00:44 +00:00
|
|
|
connect(_about_action, &QAction::triggered, this, &streamfx::ui::handler::on_action_about);
|
|
|
|
}
|
|
|
|
|
2021-04-18 16:52:47 +00:00
|
|
|
{ // Add an actual Menu entry.
|
|
|
|
QMainWindow* main_widget = reinterpret_cast<QMainWindow*>(obs_frontend_get_main_window());
|
|
|
|
_menu_action = new QAction(main_widget);
|
2021-04-19 12:01:09 +00:00
|
|
|
_menu_action->setMenuRole(QAction::NoRole);
|
2021-04-18 16:52:47 +00:00
|
|
|
_menu_action->setMenu(_menu);
|
|
|
|
_menu_action->setText(QString::fromUtf8(D_TRANSLATE(_i18n_menu.data())));
|
|
|
|
|
|
|
|
// For unknown reasons, the "About StreamFX" menu replaces the OBS about menu.
|
|
|
|
QList<QMenu*> obs_menus = main_widget->menuBar()->findChildren<QMenu*>(QString(), Qt::FindDirectChildrenOnly);
|
|
|
|
if (QMenu* help_menu = obs_menus.at(1); help_menu) {
|
|
|
|
main_widget->menuBar()->insertAction(help_menu->menuAction(), _menu_action);
|
|
|
|
} else {
|
|
|
|
main_widget->menuBar()->addAction(_menu_action);
|
|
|
|
}
|
|
|
|
}
|
2020-05-30 23:24:16 +00:00
|
|
|
|
|
|
|
// Show the 'About StreamFX' dialog if that has not happened yet.
|
|
|
|
if (!have_shown_about_streamfx()) {
|
|
|
|
// Automatically show it if it has not yet been shown.
|
|
|
|
_about_dialog->show();
|
|
|
|
have_shown_about_streamfx(true);
|
|
|
|
}
|
2021-01-21 01:42:56 +00:00
|
|
|
|
|
|
|
// Let the Updater start its work.
|
2021-02-02 20:48:17 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_UPDATER
|
2021-01-21 01:42:56 +00:00
|
|
|
this->_updater->obs_ready();
|
2021-02-02 20:48:17 +00:00
|
|
|
#endif
|
2020-04-05 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 02:00:44 +00:00
|
|
|
void streamfx::ui::handler::on_obs_exit()
|
|
|
|
{
|
2023-03-09 14:16:50 +00:00
|
|
|
// Release CEF
|
|
|
|
_obs_browser_cef.reset();
|
|
|
|
|
2021-01-21 02:00:44 +00:00
|
|
|
// Remove translator.
|
|
|
|
QCoreApplication::removeTranslator(_translator);
|
|
|
|
|
|
|
|
// Clean up any Qt resources we added.
|
|
|
|
qt_cleanup_resource();
|
|
|
|
}
|
|
|
|
|
2021-10-17 12:28:33 +00:00
|
|
|
void streamfx::ui::handler::on_action_support(bool)
|
2020-04-05 16:52:06 +00:00
|
|
|
{
|
2021-10-17 12:28:33 +00:00
|
|
|
QDesktopServices::openUrl(QUrl(QString::fromUtf8(_url_support.data())));
|
2020-04-05 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 12:28:33 +00:00
|
|
|
void streamfx::ui::handler::on_action_wiki(bool)
|
2020-04-05 16:52:06 +00:00
|
|
|
{
|
2021-10-17 12:28:33 +00:00
|
|
|
QDesktopServices::openUrl(QUrl(QString::fromUtf8(_url_wiki.data())));
|
2020-04-05 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::handler::on_action_website(bool)
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(QString::fromUtf8(_url_website.data())));
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::handler::on_action_discord(bool)
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(QString::fromUtf8(_url_discord.data())));
|
|
|
|
}
|
|
|
|
|
2021-10-17 12:28:33 +00:00
|
|
|
void streamfx::ui::handler::on_action_twitter(bool)
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(QString::fromUtf8(_url_twitter.data())));
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::handler::on_action_youtube(bool)
|
2020-04-05 16:52:06 +00:00
|
|
|
{
|
2021-10-17 12:28:33 +00:00
|
|
|
QDesktopServices::openUrl(QUrl(QString::fromUtf8(_url_youtube.data())));
|
2020-04-05 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::handler::on_action_about(bool checked)
|
|
|
|
{
|
|
|
|
_about_dialog->show();
|
|
|
|
}
|
|
|
|
|
2023-05-14 04:50:27 +00:00
|
|
|
std::shared_ptr<streamfx::ui::handler> streamfx::ui::handler::instance()
|
2020-04-05 16:52:06 +00:00
|
|
|
{
|
2023-05-14 04:50:27 +00:00
|
|
|
static std::weak_ptr<streamfx::ui::handler> winst;
|
|
|
|
static std::mutex mtx;
|
|
|
|
|
|
|
|
std::unique_lock<decltype(mtx)> lock(mtx);
|
|
|
|
auto instance = winst.lock();
|
|
|
|
if (!instance) {
|
|
|
|
instance = std::shared_ptr<streamfx::ui::handler>(new streamfx::ui::handler());
|
|
|
|
winst = instance;
|
|
|
|
}
|
|
|
|
return instance;
|
2020-04-05 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
streamfx::ui::translator::translator(QObject* parent) {}
|
|
|
|
|
|
|
|
streamfx::ui::translator::~translator() {}
|
|
|
|
|
2023-05-13 12:35:46 +00:00
|
|
|
QString streamfx::ui::translator::translate(const char* context, const char* sourceText, const char* disambiguation, int n) const
|
2020-04-05 16:52:06 +00:00
|
|
|
{
|
2020-09-10 07:00:03 +00:00
|
|
|
if (sourceText) {
|
|
|
|
std::string_view sourceView{sourceText};
|
|
|
|
if (sourceView.substr(0, _i18n_prefix.length()) == _i18n_prefix) {
|
|
|
|
return QString::fromUtf8(D_TRANSLATE(sourceView.substr(_i18n_prefix.length()).data()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (disambiguation) {
|
|
|
|
std::string_view disambiguationView{disambiguation};
|
|
|
|
if (disambiguationView.substr(0, _i18n_prefix.length()) == _i18n_prefix) {
|
|
|
|
return QString::fromUtf8(D_TRANSLATE(disambiguationView.substr(_i18n_prefix.length()).data()));
|
|
|
|
}
|
2020-04-05 16:52:06 +00:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
2023-05-14 04:50:27 +00:00
|
|
|
|
|
|
|
static std::shared_ptr<streamfx::ui::handler> loader_instance;
|
|
|
|
|
|
|
|
static auto loader = streamfx::loader(
|
|
|
|
[]() { // Initalizer
|
|
|
|
loader_instance = streamfx::ui::handler::instance();
|
|
|
|
},
|
|
|
|
[]() { // Finalizer
|
|
|
|
loader_instance.reset();
|
|
|
|
},
|
|
|
|
streamfx::loader_priority::LOWEST); // Must be loaded after all other functionality.
|