From 2522fff485c0e0e0203ca99c95e0406a32c402c6 Mon Sep 17 00:00:00 2001 From: daleclack Date: Wed, 28 Dec 2022 15:20:35 +0800 Subject: [PATCH] Add config for background --- XeRelease_Gtkmm4/src/MyPrefs.cc | 6 ++- XeRelease_Gtkmm4/src/MyPrefs.hh | 1 + XeRelease_Gtkmm4/src/MyWin.cc | 72 +++++++++++++++++++++++++++------ XeRelease_Gtkmm4/src/MyWin.hh | 2 + XeRelease_Gtkmm4/src/main.cc | 4 +- 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/XeRelease_Gtkmm4/src/MyPrefs.cc b/XeRelease_Gtkmm4/src/MyPrefs.cc index f5f5eb8..ecd1204 100644 --- a/XeRelease_Gtkmm4/src/MyPrefs.cc +++ b/XeRelease_Gtkmm4/src/MyPrefs.cc @@ -56,6 +56,7 @@ void MyPrefs::btnok_clicked() "Stable":"x.x", "Develop":"x.x", "dark_mode":false, + "background":0 "Release_Path_Unix":"", "Release_Path_Win32":"", "Release_Path_Darwin":"" @@ -75,7 +76,8 @@ void MyPrefs::btnok_clicked() "Release_Path_Unix":"", "Release_Path_Win32":"", "Release_Path_Darwin":"", - "dark_mode":false + "dark_mode":false, + "background":2 } )"); @@ -87,6 +89,7 @@ void MyPrefs::btnok_clicked() out_data["Release_Path_Win32"] = config_win32; out_data["Release_Path_Darwin"] = config_darwin; out_data["dark_mode"] = dark_mode; + out_data["background"] = background_id; outfile << out_data; // Set Current json data @@ -135,6 +138,7 @@ void MyPrefs::reset_entries() config_win32 = data["Release_Path_Win32"]; config_darwin = data["Release_Path_Darwin"]; dark_mode = data["dark_mode"]; + background_id = data["background"]; // Set text from json file data entry_lts->set_text(config_longterm); diff --git a/XeRelease_Gtkmm4/src/MyPrefs.hh b/XeRelease_Gtkmm4/src/MyPrefs.hh index be21773..d595a23 100644 --- a/XeRelease_Gtkmm4/src/MyPrefs.hh +++ b/XeRelease_Gtkmm4/src/MyPrefs.hh @@ -34,6 +34,7 @@ public: void init_json_data(json &data1); void save_config_now(); void set_dark_mode(bool dark_mode_enabled); + int background_id; private: Glib::RefPtr ref_Glade; diff --git a/XeRelease_Gtkmm4/src/MyWin.cc b/XeRelease_Gtkmm4/src/MyWin.cc index 8f1a6e3..0cf9bdd 100644 --- a/XeRelease_Gtkmm4/src/MyWin.cc +++ b/XeRelease_Gtkmm4/src/MyWin.cc @@ -25,10 +25,10 @@ MyWin::MyWin() set_default_size(640, 360); titlebar_init(); - // Set Background Image - auto pixbuf = Gdk::Pixbuf::create_from_xpm_data(fly); - auto sized = pixbuf->scale_simple(640, 360, Gdk::InterpType::BILINEAR); - background.set_pixbuf(sized); + // // Set Background Image + // auto pixbuf = Gdk::Pixbuf::create_from_xpm_data(fly); + // auto sized = pixbuf->scale_simple(640, 360, Gdk::InterpType::BILINEAR); + // background.set_pixbuf(sized); back_overlay.set_child(background); background.set_size_request(640, 360); back_overlay.set_halign(Gtk::Align::FILL); @@ -64,7 +64,7 @@ MyWin::MyWin() back_overlay.add_overlay(stack1); stack1.add(overlay, "main_page", "WelCome"); - //Add Config Page + // Add Config Page prefs = MyPrefs::create(); prefs->set_parent_win(this); load_config(); @@ -76,11 +76,28 @@ MyWin::MyWin() cfg_box.set_opacity(0.7); stack1.add(cfg_box, "config_page", "Config"); + // Set background from the config + switch (back_id) + { + case 1: + background1(); + break; + case 2: + background2(); + break; + case 3: + background3(); + break; + } + // Create Style for widgets provider = Gtk::CssProvider::create(); - if(check_dark.get_active()){ + if (check_dark.get_active()) + { provider->load_from_resource("/org/gtk/daleclack/style_dark.css"); - }else{ + } + else + { provider->load_from_resource("/org/gtk/daleclack/style.css"); } auto style1 = btn_box.get_style_context(); @@ -95,9 +112,9 @@ MyWin::MyWin() btn_ver.signal_clicked().connect(sigc::mem_fun(*this, &MyWin::main_releases)); check_dark.signal_toggled().connect(sigc::mem_fun(*this, &MyWin::check_toggled)); - // Free Memory - pixbuf.reset(); - sized.reset(); + // // Free Memory + // pixbuf.reset(); + // sized.reset(); } void MyWin::titlebar_init() @@ -106,7 +123,7 @@ void MyWin::titlebar_init() // header.set_title("Xe Release 15"); // Add stack widget - //header.set_custom_title(switcher); + // header.set_custom_title(switcher); header.set_title_widget(switcher); header.set_show_title_buttons(); header.set_decoration_layout("close,minimize:menu"); @@ -145,6 +162,14 @@ void MyWin::background1() // Free Memory pixbuf.reset(); sized.reset(); + + // Update config + if(!start){ + prefs->background_id = 1; + prefs->save_config_now(); + }else{ + start = false; + } } void MyWin::background2() @@ -158,6 +183,14 @@ void MyWin::background2() // Free Memory pixbuf.reset(); sized.reset(); + + // Update config + if(!start){ + prefs->background_id = 2; + prefs->save_config_now(); + }else{ + start = false; + } } void MyWin::background3() @@ -171,6 +204,14 @@ void MyWin::background3() // Free Memory pixbuf.reset(); sized.reset(); + + // Update config + if(!start){ + prefs->background_id = 3; + prefs->save_config_now(); + }else{ + start = false; + } } void MyWin::config_dialog() @@ -180,7 +221,8 @@ void MyWin::config_dialog() stack1.set_visible_child(cfg_box); } -void MyWin::load_config(){ +void MyWin::load_config() +{ // Load/Reload json config file // Open json file @@ -193,11 +235,14 @@ void MyWin::load_config(){ config_stable = data["Stable"]; config_devel = data["Develop"]; check_dark.set_active(data["dark_mode"]); + back_id = data["background"]; } else { msg_dialog.Init("The config doesn't exist!\nPlease use \"Config\" menu to set releases"); msg_dialog.show(); + check_dark.set_active(false); + back_id = 3; return; } json_config_init(data); @@ -236,7 +281,8 @@ void MyWin::main_releases() } } -void MyWin::check_toggled(){ +void MyWin::check_toggled() +{ // Get the state of check button and set the config to json file prefs->set_dark_mode(check_dark.get_active()); prefs->save_config_now(); diff --git a/XeRelease_Gtkmm4/src/MyWin.hh b/XeRelease_Gtkmm4/src/MyWin.hh index 382c662..c24ea13 100644 --- a/XeRelease_Gtkmm4/src/MyWin.hh +++ b/XeRelease_Gtkmm4/src/MyWin.hh @@ -40,6 +40,8 @@ private: MsgBox msg_dialog; // Backgrounds + int back_id; + bool start = true; void background1(); void background2(); void background3(); diff --git a/XeRelease_Gtkmm4/src/main.cc b/XeRelease_Gtkmm4/src/main.cc index 77a77c4..1d61de1 100644 --- a/XeRelease_Gtkmm4/src/main.cc +++ b/XeRelease_Gtkmm4/src/main.cc @@ -2,7 +2,9 @@ /* Xe Release Gtkmm4 Reset Version -The project is originally build with Gtk3, in 2020, +The project is originally build as a console app, in 2020, +and after several months, I add a dialog for the application, +the next is Gtk3 builds, and at that time, the project is uploaded to github, the first Gtk4 build is finished, but there is some font rendering issues, and the Gtkmm3 and Gtkmm4 build is finished in 2021, in a long time, the Gtkmm3 is the main framework for Xe Release,