Add config for background
This commit is contained in:
parent
1dc85f56fc
commit
2522fff485
|
@ -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);
|
||||
|
|
|
@ -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<Gtk::Builder> ref_Glade;
|
||||
|
|
|
@ -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);
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
|
|
|
@ -40,6 +40,8 @@ private:
|
|||
MsgBox msg_dialog;
|
||||
|
||||
// Backgrounds
|
||||
int back_id;
|
||||
bool start = true;
|
||||
void background1();
|
||||
void background2();
|
||||
void background3();
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue