2024-03-23 18:41:26 -07:00
|
|
|
#include "main.h"
|
|
|
|
#include "main_window.hpp"
|
2024-03-26 18:39:02 -07:00
|
|
|
#include <assets/assets.h>
|
|
|
|
#include <license.hpp>
|
2024-04-14 10:19:46 -07:00
|
|
|
#include <log.hpp>
|
2024-03-23 18:41:26 -07:00
|
|
|
std::string GtkBackend::get_id() {
|
|
|
|
return "gtk";
|
|
|
|
}
|
|
|
|
std::string GtkBackend::get_name() {
|
|
|
|
return "GTK frontend";
|
|
|
|
}
|
2024-04-14 10:19:46 -07:00
|
|
|
void g_log_handler(const gchar *domain, GLogLevelFlags flags, const gchar *message, gpointer userdata) {
|
|
|
|
bool fatal = flags & GLogLevelFlags::G_LOG_FLAG_FATAL;
|
|
|
|
bool recursion = flags & GLogLevelFlags::G_LOG_FLAG_RECURSION;
|
|
|
|
GLogLevelFlags level = (GLogLevelFlags)(flags & GLogLevelFlags::G_LOG_LEVEL_MASK);
|
|
|
|
/*
|
|
|
|
G_LOG_LEVEL_ERROR = 1 << 2,
|
|
|
|
G_LOG_LEVEL_CRITICAL = 1 << 3,
|
|
|
|
G_LOG_LEVEL_WARNING = 1 << 4,
|
|
|
|
G_LOG_LEVEL_MESSAGE = 1 << 5,
|
|
|
|
G_LOG_LEVEL_INFO = 1 << 6,
|
|
|
|
G_LOG_LEVEL_DEBUG = 1 << 7,
|
|
|
|
*/
|
|
|
|
LogStream *stream;
|
|
|
|
switch (level) {
|
|
|
|
case GLogLevelFlags::G_LOG_LEVEL_ERROR: {
|
|
|
|
stream = new LogStream({domain}, {ERROR});
|
|
|
|
} break;
|
|
|
|
case GLogLevelFlags::G_LOG_LEVEL_CRITICAL: {
|
|
|
|
stream = new LogStream({"CRITICAL", domain}, {stderr});
|
|
|
|
} break;
|
|
|
|
case GLogLevelFlags::G_LOG_LEVEL_WARNING: {
|
|
|
|
stream = new LogStream({domain}, {WARNING});
|
|
|
|
} break;
|
|
|
|
case GLogLevelFlags::G_LOG_LEVEL_INFO: {
|
|
|
|
stream = new LogStream({domain}, {INFO});
|
|
|
|
} break;
|
|
|
|
case GLogLevelFlags::G_LOG_LEVEL_DEBUG: {
|
|
|
|
stream = new LogStream({domain}, {DEBUG});
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
stream = new LogStream({domain}, {stderr});
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
stream->writeln(message);
|
|
|
|
delete stream;
|
|
|
|
}
|
2024-03-23 18:41:26 -07:00
|
|
|
int GtkBackend::run(std::vector<std::string> realArgs, int argc, char **argv) {
|
|
|
|
int ret = UIBackend::run(realArgs, argc, argv);
|
|
|
|
if (ret != 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
2024-04-14 10:19:46 -07:00
|
|
|
g_log_set_default_handler(g_log_handler, nullptr);
|
|
|
|
g_log_writer
|
2024-03-26 18:39:02 -07:00
|
|
|
Glib::set_application_name("Looper");
|
2024-04-09 10:15:05 -07:00
|
|
|
auto app = Gtk::Application::create("com.complecwaft.Looper.GTK", Gio::Application::Flags::NON_UNIQUE);
|
2024-03-26 18:39:02 -07:00
|
|
|
char *gtk_frontend_css = (char*)malloc(gtk_frontend_css_size + 1);
|
|
|
|
memcpy(gtk_frontend_css, gtk_frontend_css_data, gtk_frontend_css_size);
|
|
|
|
gtk_frontend_css[gtk_frontend_css_size] = '\0';
|
|
|
|
std::string gtk_frontend_css_str = std::string(gtk_frontend_css);
|
|
|
|
free(gtk_frontend_css);
|
|
|
|
auto provider = Gtk::CssProvider::create();
|
|
|
|
provider->load_from_string(gtk_frontend_css_str);
|
|
|
|
app->signal_startup().connect([=,this]() {
|
|
|
|
app->add_action("quit", [app]() {
|
|
|
|
app->quit();
|
|
|
|
});
|
|
|
|
Gtk::StyleContext::add_provider_for_display(Gdk::Display::get_default(), provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
2024-03-23 18:41:26 -07:00
|
|
|
});
|
2024-03-26 18:39:02 -07:00
|
|
|
app->signal_activate().connect([=,this] {
|
|
|
|
auto *win = new MainWindow(playback, app);
|
|
|
|
win->present();
|
|
|
|
});
|
2024-04-09 10:15:05 -07:00
|
|
|
app_ptr = app.get();
|
2024-03-26 18:39:02 -07:00
|
|
|
ret = app->run(argc, argv);
|
2024-04-09 10:15:05 -07:00
|
|
|
app_ptr = nullptr;
|
2024-03-26 18:39:02 -07:00
|
|
|
return ret;
|
|
|
|
}
|
2024-04-09 10:15:05 -07:00
|
|
|
void GtkBackend::QuitHandler() {
|
|
|
|
if (app_ptr != nullptr) {
|
|
|
|
((Gtk::Application*)app_ptr)->quit();
|
|
|
|
}
|
|
|
|
}
|
2024-03-26 18:39:02 -07:00
|
|
|
void GtkBackend::add_licenses() {
|
|
|
|
auto &license_data = get_license_data();
|
|
|
|
auto gtkmm = LicenseData("GtkMM", "lgpl-2.1");
|
|
|
|
auto glibmm = LicenseData("GlibMM", "lgpl-2.1");
|
|
|
|
auto glib = LicenseData("Glib", "lgpl-2.1-or-later");
|
|
|
|
auto gtk = LicenseData("GTK", "lgpl-2.0");
|
|
|
|
LOAD_LICENSE(gtkmm, lgpl_2_1);
|
|
|
|
LOAD_LICENSE(glibmm, lgpl_2_1);
|
|
|
|
LOAD_LICENSE(glib, lgpl_2_1);
|
|
|
|
LOAD_LICENSE(gtk, lgpl_2_0);
|
|
|
|
license_data.insert(gtkmm);
|
|
|
|
license_data.insert(glibmm);
|
|
|
|
license_data.insert(glib);
|
|
|
|
license_data.insert(gtk);
|
2024-03-23 18:41:26 -07:00
|
|
|
}
|