From a7ac9b46498e3bebc41c96764fdcb05f90d43a54 Mon Sep 17 00:00:00 2001 From: daleclack Date: Tue, 26 Jul 2022 13:34:28 +0800 Subject: [PATCH] Update config page --- XeRelease_Gtkmm3/res/prefs.ui | 35 --------- XeRelease_Gtkmm3/src/MyPrefs.cc | 131 ++++++++++++++++++-------------- XeRelease_Gtkmm3/src/MyPrefs.hh | 43 ++++++----- 3 files changed, 101 insertions(+), 108 deletions(-) diff --git a/XeRelease_Gtkmm3/res/prefs.ui b/XeRelease_Gtkmm3/res/prefs.ui index 3b81d36..ff78274 100644 --- a/XeRelease_Gtkmm3/res/prefs.ui +++ b/XeRelease_Gtkmm3/res/prefs.ui @@ -208,39 +208,4 @@ - - False - 10 - dialog - - - False - vertical - 2 - - - False - end - - - - - - - - - - - - False - False - 0 - - - - - - - - diff --git a/XeRelease_Gtkmm3/src/MyPrefs.cc b/XeRelease_Gtkmm3/src/MyPrefs.cc index 0585793..d167f1b 100644 --- a/XeRelease_Gtkmm3/src/MyPrefs.cc +++ b/XeRelease_Gtkmm3/src/MyPrefs.cc @@ -4,8 +4,6 @@ MyPrefs::MyPrefs(BaseObjectType *cobject, const Glib::RefPtr &ref_ : Gtk::Box(cobject), ref_Glade(ref_builder) { - // // Initalize - // set_icon_name("XeRelease"); // Get Widgets ref_builder->get_widget("entry_lts", entry_lts); ref_builder->get_widget("entry_stable", entry_stable); @@ -13,25 +11,12 @@ MyPrefs::MyPrefs(BaseObjectType *cobject, const Glib::RefPtr &ref_ ref_builder->get_widget("entry_path", entry_path); ref_builder->get_widget("btnpath", btnpath); ref_builder->get_widget("btn_ok", btnok); - - // json_file.close(); - - // std::string config; - // if(readCfgFile("xe_config","Longterm",config)){ - // entry_lts->set_text(config); - // } - // if(readCfgFile("xe_config","Stable",config)){ - // entry_stable->set_text(config); - // } - // if(readCfgFile("xe_config","Develop",config)){ - // entry_dev->set_text(config); - // } - // readCfgFile("xe_config","Release_Path_Unix",config_unix); - // readCfgFile("xe_config","Release_Path_Win32",config_win32); + ref_builder->get_widget("btn_cancel", btncancel); // Connect Signal btnpath->signal_clicked().connect(sigc::mem_fun(*this, &MyPrefs::btnpath_clicked)); btnok->signal_clicked().connect(sigc::mem_fun(*this, &MyPrefs::btnok_clicked)); + btncancel->signal_clicked().connect(sigc::mem_fun(*this, &MyPrefs::btnreset_clicked)); } void MyPrefs::btnok_clicked() @@ -54,14 +39,19 @@ void MyPrefs::btnok_clicked() outfile.open("xe_config.json", std::ios_base::out); /*OutPut contents to the file Simple Contents of xe_config: - Longterm=x.x - Stable=x.x - Develop=x.x - Release_Path_Unix=/xxx/xxx - Release_Path_Win32=X:\xxx\xxx + { + "Longterm":"x.x", + "Stable":"x.x", + "Develop":"x.x", + "Release_Path_Unix":"", + "Release_Path_Win32":"" + } */ if (outfile.is_open()) { + // BackUp the original data + data_backup = data; + // Create json object json out_data = json::parse(R"( { @@ -80,50 +70,65 @@ void MyPrefs::btnok_clicked() out_data["Release_Path_Unix"] = config_unix; out_data["Release_Path_Win32"] = config_win32; outfile << out_data; - // outfile<<"This is the config file of Xe Release"<get_text(); - // outfile<<"Longterm="<get_text(); - // outfile<<"Stable="<get_text(); - // outfile<<"Develop="<set_text(config_longterm); - entry_stable->set_text(config_stable); - entry_dev->set_text(config_devel); +void MyPrefs::reset_entries() +{ + std::string config_longterm, config_stable, config_devel; + // Read json data + config_longterm = data["Longterm"]; + config_stable = data["Stable"]; + config_devel = data["Develop"]; + config_unix = data["Release_Path_Unix"]; + config_win32 = data["Release_Path_Win32"]; - // Use different path for Linux filesystem and Windows - if (unix_file_system_detected()) - { - entry_path->set_text(config_unix); - } - else - { - entry_path->set_text(config_win32); - } + // Set text from json file data + entry_lts->set_text(config_longterm); + entry_stable->set_text(config_stable); + entry_dev->set_text(config_devel); + + // Use different path for Linux filesystem and Windows + if (unix_file_system_detected()) + { + entry_path->set_text(config_unix); + } + else + { + entry_path->set_text(config_win32); } } @@ -138,8 +143,10 @@ MyPrefs *MyPrefs::create() return box; } -void MyPrefs::set_parent_win(Gtk::Window *parent){ +void MyPrefs::set_parent_win(Gtk::Window *parent) +{ parent_win = parent; + msg_dialog1.set_transient_for(*parent); } void MyPrefs::btnpath_clicked() @@ -179,6 +186,20 @@ MsgBox::MsgBox(Gtk::Window &parent) vbox->pack_start(hbox); } +MsgBox::MsgBox() +{ + // Initalize MsgBox + set_icon_name("Xe-Release"); + set_default_size(300, 150); + add_button("OK", Gtk::RESPONSE_OK); + // Add Message + image.set_from_icon_name("Xe-Release", Gtk::ICON_SIZE_DIALOG); + vbox = get_content_area(); + hbox.pack_start(image, Gtk::PACK_SHRINK); + hbox.pack_start(msg_label, Gtk::PACK_SHRINK); + vbox->pack_start(hbox); +} + void MsgBox::Init(Glib::ustring msg) { msg_label.set_label(msg); diff --git a/XeRelease_Gtkmm3/src/MyPrefs.hh b/XeRelease_Gtkmm3/src/MyPrefs.hh index f537fd4..3600f85 100644 --- a/XeRelease_Gtkmm3/src/MyPrefs.hh +++ b/XeRelease_Gtkmm3/src/MyPrefs.hh @@ -6,6 +6,24 @@ using json = nlohmann::json; +class MsgBox : public Gtk::Dialog +{ +public: + MsgBox(Gtk::Window &parent); + MsgBox(); + void Init(Glib::ustring msg); + +protected: + // Signal Handler + void on_response(int response_id) override; + +private: + // Child Widgets + Gtk::Image image; + Gtk::Label msg_label; + Gtk::Box *vbox, hbox; +}; + class MyPrefs : public Gtk::Box { public: @@ -21,33 +39,22 @@ private: // Child widgets Gtk::Entry *entry_lts, *entry_stable, *entry_dev, *entry_path; - Gtk::Button *btnpath, *btnok; + Gtk::Button *btnpath, *btnok, *btncancel; // Strings to store path on Windows and Unix-Like systems std::string config_win32, config_unix; + json data, data_backup; + + // Messagebox + MsgBox msg_dialog1; // Signal Handlers Glib::RefPtr dialog; void btnpath_clicked(); void dialog_response(int response_id); void btnok_clicked(); -}; - -class MsgBox : public Gtk::Dialog -{ -public: - MsgBox(Gtk::Window &parent); - void Init(Glib::ustring msg); - -protected: - // Signal Handler - void on_response(int response_id) override; - -private: - // Child Widgets - Gtk::Image image; - Gtk::Label msg_label; - Gtk::Box *vbox, hbox; + void btnreset_clicked(); + void reset_entries(); }; static inline bool unix_file_system_detected()