👷 add gtk4 branch
This commit is contained in:
parent
250819c596
commit
0aef4b8275
|
@ -23,17 +23,18 @@ pkg_check_modules(
|
||||||
GTKMM
|
GTKMM
|
||||||
REQUIRED
|
REQUIRED
|
||||||
IMPORTED_TARGET
|
IMPORTED_TARGET
|
||||||
gtkmm-3.0)
|
gtkmm-4.0)
|
||||||
|
|
||||||
FetchContent_Declare(fmt
|
FetchContent_Declare(fmt
|
||||||
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
|
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
|
||||||
GIT_TAG "3b6e409cd8573f63e4acad7717d9082bd898ec87"
|
GIT_TAG "a44716f58e943905d1357160b98cae2618d053cf"
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(fmt)
|
FetchContent_MakeAvailable(fmt)
|
||||||
|
|
||||||
##
|
##
|
||||||
## CONFIGURATION
|
## CONFIGURATION
|
||||||
##
|
##
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--export-dynamic")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
|
|
79
meson.build
79
meson.build
|
@ -1,18 +1,35 @@
|
||||||
project('cachyos-hello', 'cpp',
|
project('cachyos-hello', 'cpp',
|
||||||
version: '0.6.10',
|
version: '0.6.9',
|
||||||
license: 'GPLv3',
|
license: 'GPLv3',
|
||||||
meson_version: '>=0.55.0',
|
meson_version: '>=0.55.0',
|
||||||
default_options: ['cpp_std=c++17',
|
default_options: ['cpp_std=c++17',
|
||||||
'buildtype=debugoptimized',
|
'buildtype=debugoptimized',
|
||||||
'warning_level=3',
|
'warning_level=3',
|
||||||
'werror=true',
|
'werror=false',
|
||||||
'b_ndebug=if-release'])
|
'b_ndebug=if-release'])
|
||||||
|
|
||||||
|
is_debug_build = get_option('buildtype').startswith('debug')
|
||||||
cc = meson.get_compiler('cpp')
|
cc = meson.get_compiler('cpp')
|
||||||
|
if cc.get_id() == 'clang'
|
||||||
|
specific_cc_flags = [
|
||||||
|
'-nostdlib++',
|
||||||
|
#'-stdlib=libc++',
|
||||||
|
'-nodefaultlibs',
|
||||||
|
]
|
||||||
|
specific_link_flags = [
|
||||||
|
'-fuse-ld=lld',
|
||||||
|
]
|
||||||
|
add_global_arguments(cc.get_supported_arguments(specific_cc_flags), language : 'cpp')
|
||||||
|
add_global_link_arguments(cc.get_supported_link_arguments(specific_link_flags), language : 'cpp')
|
||||||
|
endif
|
||||||
|
|
||||||
|
if is_debug_build
|
||||||
|
add_global_arguments('-D_GLIBCXX_ASSERTIONS', language : 'cpp')
|
||||||
|
endif
|
||||||
|
|
||||||
# Common dependencies
|
# Common dependencies
|
||||||
fmt = dependency('fmt', version : ['>=8.0.0'], fallback : ['fmt', 'fmt_dep'])
|
fmt = dependency('fmt', version : ['>=8.0.0'], fallback : ['fmt', 'fmt_dep'])
|
||||||
gtkmm = dependency('gtkmm-3.0', version : ['>=3.22.0'])
|
gtkmm = dependency('gtkmm-4.0', version : ['>=1.8.0'])
|
||||||
|
|
||||||
src_files = files(
|
src_files = files(
|
||||||
'src/hello.cpp', 'src/hello.hpp',
|
'src/hello.cpp', 'src/hello.hpp',
|
||||||
|
@ -20,43 +37,65 @@ src_files = files(
|
||||||
)
|
)
|
||||||
|
|
||||||
possible_cc_flags = [
|
possible_cc_flags = [
|
||||||
'-Wshadow',
|
'-Wshadow',
|
||||||
|
|
||||||
'-Wnon-virtual-dtor',
|
'-Wnon-virtual-dtor',
|
||||||
|
|
||||||
'-Wcast-align',
|
'-Wold-style-cast',
|
||||||
'-Wunused',
|
'-Wcast-align',
|
||||||
'-Woverloaded-virtual',
|
'-Wunused',
|
||||||
|
'-Woverloaded-virtual',
|
||||||
|
|
||||||
'-Wpedantic', # non-standard C++
|
'-Wpedantic', # non-standard C++
|
||||||
'-Wconversion', # type conversion that may lose data
|
'-Wconversion', # type conversion that may lose data
|
||||||
'-Wnull-dereference',
|
'-Wsign-conversion',
|
||||||
'-Wdouble-promotion', # float to double
|
'-Wnull-dereference',
|
||||||
|
'-Wdouble-promotion', # float to double
|
||||||
|
|
||||||
'-Wformat=2',
|
'-Wformat=2',
|
||||||
|
'-Wimplicit-fallthrough', # fallthrough without an explicit annotation
|
||||||
]
|
]
|
||||||
|
|
||||||
if cc.get_id() == 'gcc'
|
if cc.get_id() == 'gcc'
|
||||||
possible_cc_flags += [
|
possible_cc_flags += [
|
||||||
'-Wmisleading-indentation',
|
'-Wmisleading-indentation',
|
||||||
|
|
||||||
'-Wduplicated-cond',
|
'-Wduplicated-cond',
|
||||||
'-Wduplicated-branches',
|
'-Wduplicated-branches',
|
||||||
'-Wlogical-op',
|
'-Wlogical-op',
|
||||||
]
|
'-Wuseless-cast',
|
||||||
|
|
||||||
|
'-Wsuggest-attribute=cold',
|
||||||
|
'-Wsuggest-attribute=format',
|
||||||
|
'-Wsuggest-attribute=malloc',
|
||||||
|
'-Wsuggest-attribute=noreturn',
|
||||||
|
'-Wsuggest-attribute=pure',
|
||||||
|
'-Wsuggest-final-methods',
|
||||||
|
'-Wsuggest-final-types',
|
||||||
|
'-Wdiv-by-zero',
|
||||||
|
'-Wanalyzer-double-fclose',
|
||||||
|
'-Wanalyzer-double-free',
|
||||||
|
'-Wanalyzer-malloc-leak',
|
||||||
|
'-Wanalyzer-use-after-free',
|
||||||
|
]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if get_option('buildtype') != 'debug'
|
if not is_debug_build
|
||||||
if cc.get_id() == 'gcc'
|
if cc.get_id() == 'gcc'
|
||||||
possible_cc_flags += [
|
possible_cc_flags += [
|
||||||
'-flto',
|
'-flto',
|
||||||
'-fwhole-program',
|
'-fwhole-program',
|
||||||
|
'-fuse-linker-plugin',
|
||||||
]
|
]
|
||||||
else
|
else
|
||||||
possible_cc_flags += [
|
possible_cc_flags += [
|
||||||
'-flto=thin',
|
'-flto=thin',
|
||||||
]
|
]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
possible_cc_flags += ['-fdata-sections', '-ffunction-sections']
|
||||||
|
possible_link_flags = ['-Wl,--gc-sections', '-Wl,--export-dynamic']
|
||||||
|
add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'cpp')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'cpp')
|
add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'cpp')
|
||||||
|
|
172
src/hello.cpp
172
src/hello.cpp
|
@ -88,30 +88,30 @@ void quick_message(Gtk::Window* parent, const std::string& message) {
|
||||||
// Create the widgets
|
// Create the widgets
|
||||||
const auto& flags = static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT);
|
const auto& flags = static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT);
|
||||||
auto* dialog = gtk_dialog_new_with_buttons(message.c_str(),
|
auto* dialog = gtk_dialog_new_with_buttons(message.c_str(),
|
||||||
parent->gobj(),
|
parent->gobj(),
|
||||||
flags,
|
flags,
|
||||||
_("_Offline"),
|
_("_Offline"),
|
||||||
GTK_RESPONSE_NO,
|
GTK_RESPONSE_NO,
|
||||||
_("_Online"),
|
_("_Online"),
|
||||||
GTK_RESPONSE_YES,
|
GTK_RESPONSE_YES,
|
||||||
nullptr);
|
nullptr);
|
||||||
auto* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
auto* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||||||
auto* label = gtk_label_new(message.c_str());
|
auto* label = gtk_label_new(message.c_str());
|
||||||
|
|
||||||
// Add the label, and show everything we’ve added
|
// Add the label, and show everything we’ve added
|
||||||
gtk_container_add(GTK_CONTAINER(content_area), label);
|
gtk_box_append(GTK_BOX(content_area), label);
|
||||||
gtk_widget_show_all(dialog);
|
gtk_widget_show(dialog);
|
||||||
|
|
||||||
int result = gtk_dialog_run(GTK_DIALOG(dialog));
|
// int result = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||||
std::vector<std::string> argv{};
|
std::vector<std::string> argv{};
|
||||||
if (result == GTK_RESPONSE_NO) {
|
// if (result == GTK_RESPONSE_NO) {
|
||||||
argv = {fix_path("/usr/local/bin/calamares-offline.sh")};
|
// argv = {fix_path("/usr/local/bin/calamares-offline.sh")};
|
||||||
} else if (result == GTK_RESPONSE_YES) {
|
// } else if (result == GTK_RESPONSE_YES) {
|
||||||
argv = {fix_path("/usr/local/bin/calamares-online.sh")};
|
// argv = {fix_path("/usr/local/bin/calamares-online.sh")};
|
||||||
} else {
|
// } else {
|
||||||
gtk_widget_destroy(dialog);
|
// gtk_window_destroy(GTK_WINDOW(dialog));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
int child_stdout{};
|
int child_stdout{};
|
||||||
int child_stderr{};
|
int child_stderr{};
|
||||||
|
@ -119,31 +119,28 @@ void quick_message(Gtk::Window* parent, const std::string& message) {
|
||||||
|
|
||||||
// Spawn child process.
|
// Spawn child process.
|
||||||
try {
|
try {
|
||||||
Glib::spawn_async_with_pipes(".", argv, Glib::SpawnFlags::SPAWN_DO_NOT_REAP_CHILD, Glib::SlotSpawnChildSetup(), &child_pid, nullptr, &child_stdout, &child_stderr);
|
Glib::spawn_async_with_pipes(".", argv, Glib::SpawnFlags::DO_NOT_REAP_CHILD, Glib::SlotSpawnChildSetup(), &child_pid, nullptr, &child_stdout, &child_stderr);
|
||||||
} catch (Glib::Error& error) {
|
} catch (Glib::Error& error) {
|
||||||
g_critical("%s", error.what().c_str());
|
g_critical("%s", error.what());
|
||||||
}
|
}
|
||||||
// Add a child watch function which will be called when the child process
|
// Add a child watch function which will be called when the child process
|
||||||
// exits.
|
// exits.
|
||||||
g_child_watch_add(child_pid, child_watch_cb, nullptr);
|
g_child_watch_add(child_pid, child_watch_cb, nullptr);
|
||||||
|
|
||||||
gtk_widget_destroy(dialog);
|
gtk_window_destroy(GTK_WINDOW(dialog));
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Hello::Hello(int argc, char** argv) {
|
Hello::Hello(bool is_dev) {
|
||||||
set_title("CachyOS Hello");
|
set_title("CachyOS Hello");
|
||||||
set_border_width(6);
|
// set_border_width(6);
|
||||||
if (argc > 1 && (strncmp(argv[1], "--dev", 5) == 0)) {
|
|
||||||
m_dev = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_refHello = this;
|
g_refHello = this;
|
||||||
|
|
||||||
auto screen = Gdk::Screen::get_default();
|
// auto screen = Gdk::Screen::get_default();
|
||||||
|
|
||||||
// Load preferences
|
// Load preferences
|
||||||
if (m_dev) {
|
if (is_dev) {
|
||||||
m_preferences = read_json("data/preferences.json");
|
m_preferences = read_json("data/preferences.json");
|
||||||
m_preferences["data_path"] = "data/";
|
m_preferences["data_path"] = "data/";
|
||||||
m_preferences["desktop_path"] = fmt::format("{}/{}.desktop", fs::current_path().string(), m_app);
|
m_preferences["desktop_path"] = fmt::format("{}/{}.desktop", fs::current_path().string(), m_app);
|
||||||
|
@ -159,54 +156,55 @@ Hello::Hello(int argc, char** argv) {
|
||||||
m_save = (!fs::exists(save_path)) ? nlohmann::json({{"locale", ""}}) : read_json(save_path);
|
m_save = (!fs::exists(save_path)) ? nlohmann::json({{"locale", ""}}) : read_json(save_path);
|
||||||
|
|
||||||
// Import Css
|
// Import Css
|
||||||
auto provider = Gtk::CssProvider::create();
|
// auto provider = Gtk::CssProvider::create();
|
||||||
provider->load_from_path(m_preferences["style_path"]);
|
// provider->load_from_path(m_preferences["style_path"]);
|
||||||
Gtk::StyleContext::add_provider_for_screen(screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
// Gtk::StyleContext::add_provider_for_screen(screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
|
|
||||||
// Init window
|
// Init window
|
||||||
m_builder = Gtk::Builder::create_from_file(m_preferences["ui_path"]);
|
m_builder = Gtk::Builder::create_from_file(m_preferences["ui_path"]);
|
||||||
gtk_builder_add_callback_symbol(m_builder->gobj(), "on_languages_changed", G_CALLBACK(on_languages_changed));
|
// auto* scope = gtk_builder_get_scope(m_builder->gobj());
|
||||||
gtk_builder_add_callback_symbol(m_builder->gobj(), "on_action_clicked", G_CALLBACK(on_action_clicked));
|
|
||||||
gtk_builder_add_callback_symbol(m_builder->gobj(), "on_btn_clicked", G_CALLBACK(on_btn_clicked));
|
// gtk_builder_cscope_add_callback_symbols(scope, "on_languages_changed", G_CALLBACK(on_languages_changed));
|
||||||
gtk_builder_add_callback_symbol(m_builder->gobj(), "on_link_clicked", G_CALLBACK(on_link_clicked));
|
// gtk_builder_add_callback_symbol(m_builder->gobj(), "on_languages_changed", G_CALLBACK(on_languages_changed));
|
||||||
gtk_builder_add_callback_symbol(m_builder->gobj(), "on_delete_window", G_CALLBACK(on_delete_window));
|
// gtk_builder_add_callback_symbol(m_builder->gobj(), "on_action_clicked", G_CALLBACK(on_action_clicked));
|
||||||
gtk_builder_connect_signals(m_builder->gobj(), nullptr);
|
// gtk_builder_add_callback_symbol(m_builder->gobj(), "on_btn_clicked", G_CALLBACK(on_btn_clicked));
|
||||||
Gtk::Window* ref_window;
|
// gtk_builder_add_callback_symbol(m_builder->gobj(), "on_link_clicked", G_CALLBACK(on_link_clicked));
|
||||||
m_builder->get_widget("window", ref_window);
|
// gtk_builder_add_callback_symbol(m_builder->gobj(), "on_delete_window", G_CALLBACK(on_delete_window));
|
||||||
gobject_ = reinterpret_cast<GObject*>(ref_window->gobj());
|
// gtk_builder_connect_signals(m_builder->gobj(), nullptr);
|
||||||
|
auto* ref_window = m_builder->get_widget<Gtk::Window>("window");
|
||||||
|
gobject_ = reinterpret_cast<GObject*>(ref_window->gobj());
|
||||||
|
|
||||||
// Subtitle of headerbar
|
// Subtitle of headerbar
|
||||||
Gtk::HeaderBar* header;
|
auto* header = m_builder->get_widget<Gtk::HeaderBar>("headerbar");
|
||||||
m_builder->get_widget("headerbar", header);
|
|
||||||
const auto& lsb_info = get_lsb_infos();
|
const auto& lsb_info = get_lsb_infos();
|
||||||
header->set_subtitle(lsb_info[0] + " " + lsb_info[1]);
|
// header->set_title_widget(Gtk::Label(lsb_info[0] + " " + lsb_info[1], false));
|
||||||
|
// header->set_subtitle(lsb_info[0] + " " + lsb_info[1]);
|
||||||
|
|
||||||
// Load images
|
// Load images
|
||||||
if (fs::is_regular_file(m_preferences["logo_path"])) {
|
if (fs::is_regular_file(m_preferences["logo_path"])) {
|
||||||
const auto& logo = Gdk::Pixbuf::create_from_file(m_preferences["logo_path"]);
|
// const std::string& logo = m_preferences["logo_path"];
|
||||||
set_icon(logo);
|
// set_icon(logo);
|
||||||
|
// Glib::Error err;
|
||||||
|
// auto* native_er = err.gobj();
|
||||||
|
// gtk_window_set_icon_from_file(this->gobj(), logo.c_str(), &native_er);
|
||||||
|
|
||||||
Gtk::Image* image;
|
// auto* image = m_builder->get_widget<Gtk::Image>("distriblogo");
|
||||||
m_builder->get_widget("distriblogo", image);
|
// image->set(logo);
|
||||||
image->set(logo);
|
|
||||||
|
|
||||||
Gtk::AboutDialog* dialog;
|
// auto* dialog = m_builder->get_widget<Gtk::AboutDialog>("aboutdialog");
|
||||||
m_builder->get_widget("aboutdialog", dialog);
|
// dialog->set_logo(logo);
|
||||||
dialog->set_logo(logo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gtk::Box* social_box;
|
/*
|
||||||
m_builder->get_widget("social", social_box);
|
auto* social_box = m_builder->get_widget<Gtk::Box>("social");
|
||||||
for (const auto& btn : social_box->get_children()) {
|
for (const auto& btn : social_box->get_children()) {
|
||||||
const auto& name = btn->get_name();
|
const auto& name = btn->get_name();
|
||||||
const auto& icon_path = fmt::format("{}img/{}.png", m_preferences["data_path"], name.c_str());
|
const auto& icon_path = fmt::format("{}img/{}.png", m_preferences["data_path"], name.c_str());
|
||||||
Gtk::Image* image;
|
auto* image = m_builder->get_widget<Gtk::Image>(name);
|
||||||
m_builder->get_widget(name, image);
|
|
||||||
image->set(icon_path);
|
image->set(icon_path);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
Gtk::Grid* homepage_grid;
|
/*auto* homepage_grid = m_builder->get_widget<Gtk::Grid>("homepage");
|
||||||
m_builder->get_widget("homepage", homepage_grid);
|
|
||||||
for (const auto& widget : homepage_grid->get_children()) {
|
for (const auto& widget : homepage_grid->get_children()) {
|
||||||
if (!G_TYPE_CHECK_INSTANCE_TYPE(widget->gobj(), GTK_TYPE_BUTTON)) {
|
if (!G_TYPE_CHECK_INSTANCE_TYPE(widget->gobj(), GTK_TYPE_BUTTON)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -221,29 +219,29 @@ Hello::Hello(int argc, char** argv) {
|
||||||
image.set(image_path);
|
image.set(image_path);
|
||||||
image.set_margin_start(2);
|
image.set_margin_start(2);
|
||||||
casted_widget->set_image(image);
|
casted_widget->set_image(image);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Create pages
|
// Create pages
|
||||||
m_pages = fmt::format("{}pages/{}", m_preferences["data_path"], m_preferences["default_locale"]);
|
m_pages = fmt::format("{}pages/{}", m_preferences["data_path"], m_preferences["default_locale"]);
|
||||||
|
|
||||||
for (const auto& page : fs::directory_iterator(m_pages)) {
|
for (const auto& page : fs::directory_iterator(m_pages)) {
|
||||||
auto* scrolled_window = gtk_scrolled_window_new(nullptr, nullptr);
|
auto* scrolled_window = gtk_scrolled_window_new();
|
||||||
auto* viewport = gtk_viewport_new(nullptr, nullptr);
|
auto* viewport = gtk_viewport_new(nullptr, nullptr);
|
||||||
gtk_container_set_border_width(GTK_CONTAINER(viewport), 10);
|
// gtk_container_set_border_width(GTK_CONTAINER(viewport), 10);
|
||||||
auto* label = gtk_label_new(nullptr);
|
auto* label = gtk_label_new(nullptr);
|
||||||
gtk_label_set_line_wrap(GTK_LABEL(label), true);
|
gtk_label_set_wrap(GTK_LABEL(label), true);
|
||||||
auto* image = gtk_image_new_from_icon_name("go-previous", GTK_ICON_SIZE_BUTTON);
|
auto* image = gtk_image_new_from_icon_name("go-previous");
|
||||||
auto* backBtn = gtk_button_new();
|
auto* backBtn = gtk_button_new();
|
||||||
gtk_button_set_image(GTK_BUTTON(backBtn), image);
|
gtk_button_set_child(GTK_BUTTON(backBtn), image);
|
||||||
gtk_widget_set_name(backBtn, "home");
|
gtk_widget_set_name(backBtn, "home");
|
||||||
g_signal_connect(backBtn, "clicked", G_CALLBACK(&on_btn_clicked), nullptr);
|
g_signal_connect(backBtn, "clicked", G_CALLBACK(&on_btn_clicked), nullptr);
|
||||||
|
|
||||||
auto* grid = GTK_GRID(gtk_grid_new());
|
auto* grid = GTK_GRID(gtk_grid_new());
|
||||||
gtk_grid_attach(grid, backBtn, 0, 1, 1, 1);
|
gtk_grid_attach(grid, backBtn, 0, 1, 1, 1);
|
||||||
gtk_grid_attach(grid, label, 1, 2, 1, 1);
|
gtk_grid_attach(grid, label, 1, 2, 1, 1);
|
||||||
gtk_container_add(GTK_CONTAINER(viewport), GTK_WIDGET(grid));
|
gtk_box_append(GTK_BOX(viewport), GTK_WIDGET(grid));
|
||||||
gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(viewport));
|
gtk_box_append(GTK_BOX(scrolled_window), GTK_WIDGET(viewport));
|
||||||
gtk_widget_show_all(scrolled_window);
|
gtk_widget_show(scrolled_window);
|
||||||
|
|
||||||
Glib::RefPtr<Glib::Object> stack = m_builder->get_object("stack");
|
Glib::RefPtr<Glib::Object> stack = m_builder->get_object("stack");
|
||||||
const auto& child_name = page.path().filename().string() + "page";
|
const auto& child_name = page.path().filename().string() + "page";
|
||||||
|
@ -252,26 +250,23 @@ Hello::Hello(int argc, char** argv) {
|
||||||
|
|
||||||
// Init translation
|
// Init translation
|
||||||
const std::string& locale_path = m_preferences["locale_path"];
|
const std::string& locale_path = m_preferences["locale_path"];
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
bindtextdomain(m_app, locale_path.c_str());
|
bindtextdomain(m_app, locale_path.c_str());
|
||||||
bind_textdomain_codeset(m_app, "UTF-8");
|
bind_textdomain_codeset(m_app, "UTF-8");
|
||||||
textdomain(m_app);
|
textdomain(m_app);
|
||||||
Gtk::ComboBoxText* languages;
|
auto* languages = m_builder->get_widget<Gtk::ComboBoxText>("languages");
|
||||||
m_builder->get_widget("languages", languages);
|
|
||||||
languages->set_active_id(get_best_locale());
|
languages->set_active_id(get_best_locale());
|
||||||
|
|
||||||
// Set autostart switcher state
|
// Set autostart switcher state
|
||||||
m_autostart = fs::exists(fix_path(m_preferences["autostart_path"]));
|
m_autostart = fs::exists(fix_path(m_preferences["autostart_path"]));
|
||||||
Gtk::Switch* autostart_switch;
|
auto* autostart_switch = m_builder->get_widget<Gtk::Switch>("autostart");
|
||||||
m_builder->get_widget("autostart", autostart_switch);
|
|
||||||
autostart_switch->set_active(m_autostart);
|
autostart_switch->set_active(m_autostart);
|
||||||
|
|
||||||
// Live systems
|
// Live systems
|
||||||
if (fs::exists(m_preferences["live_path"]) && fs::is_regular_file(m_preferences["installer_path"])) {
|
if (fs::exists(m_preferences["live_path"]) && fs::is_regular_file(m_preferences["installer_path"])) {
|
||||||
Gtk::Label* installlabel;
|
auto* installlabel = m_builder->get_widget<Gtk::Label>("installlabel");
|
||||||
m_builder->get_widget("installlabel", installlabel);
|
|
||||||
installlabel->set_visible(true);
|
installlabel->set_visible(true);
|
||||||
Gtk::Button* install;
|
auto* install = m_builder->get_widget<Gtk::Button>("install");
|
||||||
m_builder->get_widget("install", install);
|
|
||||||
install->set_visible(true);
|
install->set_visible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,8 +356,7 @@ void Hello::set_locale(const std::string_view& use_locale) noexcept {
|
||||||
}
|
}
|
||||||
for (const auto& elt : elts[method.key()].items()) {
|
for (const auto& elt : elts[method.key()].items()) {
|
||||||
const std::string& elt_value = elt.value();
|
const std::string& elt_value = elt.value();
|
||||||
Gtk::Widget* item;
|
auto* item = m_builder->get_widget<Gtk::Widget>(elt_value);
|
||||||
m_builder->get_widget(elt_value, item);
|
|
||||||
if (!m_default_texts[method.key()].contains(elt_value)) {
|
if (!m_default_texts[method.key()].contains(elt_value)) {
|
||||||
gchar* item_buf;
|
gchar* item_buf;
|
||||||
g_object_get(G_OBJECT(item->gobj()), method.key().c_str(), &item_buf, nullptr);
|
g_object_get(G_OBJECT(item->gobj()), method.key().c_str(), &item_buf, nullptr);
|
||||||
|
@ -377,19 +371,18 @@ void Hello::set_locale(const std::string_view& use_locale) noexcept {
|
||||||
|
|
||||||
// Change content of pages
|
// Change content of pages
|
||||||
for (const auto& page : fs::directory_iterator(m_pages)) {
|
for (const auto& page : fs::directory_iterator(m_pages)) {
|
||||||
Gtk::Stack* stack;
|
auto* stack = m_builder->get_widget<Gtk::Stack>("stack");
|
||||||
m_builder->get_widget("stack", stack);
|
|
||||||
const auto& child = stack->get_child_by_name((page.path().filename().string() + "page").c_str());
|
const auto& child = stack->get_child_by_name((page.path().filename().string() + "page").c_str());
|
||||||
if (child == nullptr) {
|
if (child == nullptr) {
|
||||||
fmt::print(stderr, "child not found\n");
|
fmt::print(stderr, "child not found\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto& first_child = reinterpret_cast<Gtk::Container*>(child)->get_children();
|
// const auto& first_child = reinterpret_cast<Gtk::Container*>(child)->get_children();
|
||||||
const auto& second_child = reinterpret_cast<Gtk::Container*>(first_child[0])->get_children();
|
// const auto& second_child = reinterpret_cast<Gtk::Container*>(first_child[0])->get_children();
|
||||||
const auto& third_child = reinterpret_cast<Gtk::Container*>(second_child[0])->get_children();
|
// const auto& third_child = reinterpret_cast<Gtk::Container*>(second_child[0])->get_children();
|
||||||
|
|
||||||
const auto& label = reinterpret_cast<Gtk::Label*>(third_child[0]);
|
// const auto& label = reinterpret_cast<Gtk::Label*>(third_child[0]);
|
||||||
label->set_markup(get_page(page.path().filename().string()));
|
// label->set_markup(get_page(page.path().filename().string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,23 +427,20 @@ void Hello::on_action_clicked(GtkWidget* widget) noexcept {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gtk::AboutDialog* dialog;
|
auto* dialog = g_refHello->m_builder->get_widget<Gtk::AboutDialog>("aboutdialog");
|
||||||
g_refHello->m_builder->get_widget("aboutdialog", dialog);
|
|
||||||
dialog->set_decorated(false);
|
dialog->set_decorated(false);
|
||||||
dialog->run();
|
|
||||||
dialog->hide();
|
dialog->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hello::on_btn_clicked(GtkWidget* widget) noexcept {
|
void Hello::on_btn_clicked(GtkWidget* widget) noexcept {
|
||||||
const auto& name = gtk_widget_get_name(widget);
|
const auto& name = gtk_widget_get_name(widget);
|
||||||
Gtk::Stack* stack;
|
auto* stack = g_refHello->m_builder->get_widget<Gtk::Stack>("stack");
|
||||||
g_refHello->m_builder->get_widget("stack", stack);
|
|
||||||
stack->set_visible_child(fmt::format("{}page", name).c_str());
|
stack->set_visible_child(fmt::format("{}page", name).c_str());
|
||||||
}
|
}
|
||||||
void Hello::on_link_clicked(GtkWidget* widget) noexcept {
|
void Hello::on_link_clicked(GtkWidget* widget) noexcept {
|
||||||
const auto& name = gtk_widget_get_name(widget);
|
const auto& name = gtk_widget_get_name(widget);
|
||||||
const std::string uri = g_refHello->m_preferences["urls"][name];
|
const std::string uri = g_refHello->m_preferences["urls"][name];
|
||||||
gtk_show_uri_on_window(nullptr, uri.c_str(), GDK_CURRENT_TIME, nullptr);
|
gtk_show_uri(nullptr, uri.c_str(), GDK_CURRENT_TIME);
|
||||||
}
|
}
|
||||||
void Hello::on_delete_window(GtkWidget* /*widget*/) noexcept {
|
void Hello::on_delete_window(GtkWidget* /*widget*/) noexcept {
|
||||||
write_json(g_refHello->m_preferences["save_path"].get<std::string>(), g_refHello->m_save);
|
write_json(g_refHello->m_preferences["save_path"].get<std::string>(), g_refHello->m_save);
|
||||||
|
|
|
@ -1,12 +1,32 @@
|
||||||
#ifndef HELLO_HPP_
|
#ifndef HELLO_HPP_
|
||||||
#define HELLO_HPP_
|
#define HELLO_HPP_
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||||
|
#pragma clang diagnostic ignored "-Wsign-conversion"
|
||||||
|
#pragma clang diagnostic ignored "-Wdouble-promotion"
|
||||||
|
#else
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||||
|
#pragma GCC diagnostic ignored "-Wdouble-promotion"
|
||||||
|
#pragma GCC diagnostic ignored "-Wuseless-cast"
|
||||||
|
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#else
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
|
|
||||||
class Hello final : public Gtk::Window {
|
class Hello final : public Gtk::Window {
|
||||||
public:
|
public:
|
||||||
Hello(int argc, char** argv);
|
Hello(bool is_dev);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Handlers
|
// Handlers
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
auto app = Gtk::Application::create();
|
auto app = Gtk::Application::create();
|
||||||
|
|
||||||
Hello hello(argc, argv);
|
const bool is_dev = 1;
|
||||||
|
|
||||||
// Shows the window and returns when it is closed.
|
// Shows the window and returns when it is closed.
|
||||||
return app->run(hello);
|
return app->make_window_and_run<Hello>(argc, argv, is_dev);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue