diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ba3a677 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,71 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "hash_map": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "valarray": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/source/ubl-settings-datetime.cc b/source/ubl-settings-datetime.cc index afc890c..75df98e 100644 --- a/source/ubl-settings-datetime.cc +++ b/source/ubl-settings-datetime.cc @@ -331,6 +331,45 @@ void MainWindow::event() { btnSaveLocalGlob->signal_activate().connect([&]() {save_global_local_cfg();}); btnSaveLocal->signal_activate().connect([&]() {save_local_cfg();}); btnSaveGlob->signal_activate().connect([&]() {save_global_cfg();}); + cbZone->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::event_zone)); + cbHw->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::event_log_hw)); +} + +void MainWindow::event_log_hw() { + string str_hw = cbHw->get_active_text(); + if (str_hw.length() > 0) { + int size_hw = sizeof(array_hw)/sizeof(array_hw[0]); + for (int i = 0; i < size_hw; i++) { + if (str_hw == array_hw_local[i]) { + this->write_config(map_config_data, array_hw[i], "hw"); + } + } + } +} + +void MainWindow::event_zone() { + int activ_index_reg = cbRegion->get_active_row_number(); + if (activ_index_reg == -1) { + this->write_config(map_config_data, "error", "zone"); + return; + } + string reg_text = array_region[activ_index_reg]; + int activ_index = cbZone->get_active_row_number(); + if (activ_index == -1) { + this->write_config(map_config_data, "error", "zone"); + return; + } + string zone_text = ""; + if(!(reg_text.empty())) { + int index= 0; + for (const auto &zone: time_reg_map.at(reg_text)) { + if (index == activ_index) { + zone_text = zone; + } + index+= 1; + } + } + this->write_config(map_config_data, zone_text, "zone"); } void MainWindow::synopsis_show() { @@ -343,8 +382,9 @@ void MainWindow::synopsis_show() { } void MainWindow::load_local_cfg() { - string cmd = "ubconfig --default --source system get clock ZONE"; - this->fill_in_reg_zone(cmd); + flag_load = false; + string cmd_zone = "ubconfig --default --source system get clock ZONE"; + this->fill_in_reg_zone(cmd_zone); this->update_hour_minute(); this->update_calendar(); string cmd_get_dhcp = "ubconfig --default --source system get network NTPSERVERS"; @@ -352,11 +392,13 @@ void MainWindow::load_local_cfg() { this->entry_dhcp_mess(cmd_get_dhcp, cmd_default_get_dhcp); string hw = "ubconfig --default --source system get clock HWCLOCK_SYNC"; this->get_hardware_clock(hw); - flag_load = false; info_warning_error(0); + map_config_data_old = map_config_data; } void MainWindow::load_globl_cfg() { + flag_load = true; + string cmd_get_dhcp = "ubconfig --default --source global get network NTPSERVERS"; string cmd_default_get_dhcp = "ubconfig --source default get [] NTPSERVERS_DEFAULT"; this->entry_dhcp_mess(cmd_get_dhcp, cmd_default_get_dhcp); @@ -364,36 +406,134 @@ void MainWindow::load_globl_cfg() { this->fill_in_reg_zone(cmd_zone); string hw = "ubconfig --source global get clock HWCLOCK_SYNC"; this->get_hardware_clock(hw); - flag_load = true; info_warning_error(1); + map_config_data_old = map_config_data; } void MainWindow::save_local_cfg() { string cmd_zone = "ubconfig --target system set clock ZONE="; - this->enter_zone(cmd_zone); string cmd_default = "ubconfig --target system set network NTPSERVERS=default"; string cmd_dhcp = "ubconfig --target system set network NTPSERVERS=dhcp"; string cmd_set_ntp = "ubconfig --target system set network NTPSERVERS=\""; string remove_ntp = "ubconfig --target system remove network NTPSERVERS"; - this->save_Dhcp(cmd_default, cmd_dhcp, remove_ntp, cmd_set_ntp); string local = "ubconfig --target system set clock HWCLOCK_SYNC=localtime"; string hw = "ubconfig --target system set clock HWCLOCK_SYNC=utc"; - this->set_hardware_clock(local, hw); + if (this->check_config("region") == false || this->check_config("zone") == false) { + this->enter_zone(cmd_zone); + } + if (this->check_config("dhcp") == false) { + this->save_Dhcp(cmd_default, cmd_dhcp, remove_ntp, cmd_set_ntp); + } + if (this->check_config("hw") == false) { + this->set_hardware_clock(local, hw); + } info_warning_error(2); + map_config_data_old = map_config_data; + if (this->check_config("region") || this->check_config("zone") || + this->check_config("dhcp") || this->check_config("hw")){ + lblWarning->set_text(_("Nothing to save!")); + } } void MainWindow::save_global_cfg() { string cmd = "ubconfig --target global set clock ZONE="; - this->enter_zone(cmd); string cmd_default = "ubconfig --target global set network NTPSERVERS=default"; string cmd_dhcp = "ubconfig --target global set network NTPSERVERS=dhcp"; string cmd_set_ntp = "ubconfig --target global set network NTPSERVERS=\""; string remove_ntp = "ubconfig --target global remove network NTPSERVERS"; - this->save_Dhcp(cmd_default, cmd_dhcp, remove_ntp, cmd_set_ntp); string local = "ubconfig --target global set clock HWCLOCK_SYNC=localtime"; string hw = "ubconfig --target global set clock HWCLOCK_SYNC=utc"; - this->set_hardware_clock(local, hw); + if (this->check_config("region") == false || this->check_config("zone") == false) { + this->enter_zone(cmd); + } + if (this->check_config("dhcp") == false) { + this->save_Dhcp(cmd_default, cmd_dhcp, remove_ntp, cmd_set_ntp); + } + if (this->check_config("hw") == false) { + this->set_hardware_clock(local, hw); + } info_warning_error(3); + map_config_data_old = map_config_data; + if (this->check_config("region") || this->check_config("zone") || + this->check_config("dhcp") || this->check_config("hw")){ + lblWarning->set_text(_("Nothing to save!")); + } +} +void MainWindow::save_global_local_cfg() { + string cmd = ""; + string cmd_default = ""; + string cmd_dhcp = ""; + string cmd_set_ntp = ""; + string remove = ""; + string local = ""; + string hw = ""; + string remove_ntp = ""; + string cmd_zone = ""; + if (this->check_config("region") == false || this->check_config("zone") == false) { + cmd_zone = "ubconfig --target system set clock ZONE="; + this->enter_zone(cmd_zone); + cmd_zone = "ubconfig --target global set clock ZONE="; + this->enter_zone(cmd_zone); + } + if (this->check_config("dhcp") == false) { + cmd_default = "ubconfig --target system set network NTPSERVERS=default"; + cmd_dhcp = "ubconfig --target system set network NTPSERVERS=dhcp"; + cmd_set_ntp = "ubconfig --target system set network NTPSERVERS=\""; + remove_ntp = "ubconfig --target system remove network NTPSERVERS"; + this->save_Dhcp(cmd_default, cmd_dhcp, remove_ntp, cmd_set_ntp); + cmd_default = "ubconfig --target global set network NTPSERVERS=default"; + cmd_dhcp = "ubconfig --target global set network NTPSERVERS=dhcp"; + cmd_set_ntp = "ubconfig --target global set network NTPSERVERS=\""; + remove_ntp = "ubconfig --target global remove network NTPSERVERS"; + this->save_Dhcp(cmd_default, cmd_dhcp, remove_ntp, cmd_set_ntp); + } + if (this->check_config("hw") == false) { + local = "ubconfig --target system set clock HWCLOCK_SYNC=localtime"; + hw = "ubconfig --target system set clock HWCLOCK_SYNC=utc"; + this->set_hardware_clock(local, hw); + local = "ubconfig --target global set clock HWCLOCK_SYNC=localtime"; + hw = "ubconfig --target global set clock HWCLOCK_SYNC=utc"; + this->set_hardware_clock(local, hw); + } + map_config_data_old = map_config_data; + info_warning_error(4); + if (this->check_config("region") || this->check_config("zone") || + this->check_config("dhcp") || this->check_config("hw")){ + lblWarning->set_text(_("Nothing to save!")); + } +} + +void MainWindow::write_config(std::map &map_config, string data, string key) { + cout << data << " " << key << endl; + map_config[key] = data; +} + +bool MainWindow::check_config(string key) { + std::map :: iterator iter_map_config_data; + std::map :: iterator iter_map_config_data_old; + iter_map_config_data = map_config_data.find(key); + iter_map_config_data_old = map_config_data_old.find(key); + if (iter_map_config_data == map_config_data.end()) { + cout << 1 << endl; + return false; + } + else if (iter_map_config_data_old == map_config_data_old.end()) { + cout << 2 << endl; + return false; + } + else if (iter_map_config_data->second != iter_map_config_data_old->second) { + return false; + } + else if (iter_map_config_data->second.length() == 0 || iter_map_config_data_old->second.length() == 0) { + return false; + } + else if (iter_map_config_data->second == iter_map_config_data_old->second) { + return true; + } + else { + return false; + } + return false; } string MainWindow::get_ubconfig_value(string &cmd){ @@ -410,21 +550,6 @@ string MainWindow::get_ubconfig_value(string &cmd){ } -void MainWindow::save_global_local_cfg() { - string cmd = ""; - string cmd_default = ""; - string cmd_dhcp = ""; - string cmd_set_ntp = ""; - string remove = ""; - if (flag_save_global == false) { - this->save_local_cfg(); - } - if (flag_save_local == false) { - this->save_global_cfg(); - } - info_warning_error(4); -} - void MainWindow::info_warning_error(int mess) { if (error_info > 0 || warning_info > 0) { info_status_app("boxInfoMessError"); @@ -505,7 +630,7 @@ void MainWindow::set_hardware_clock(string &local, string &etc) { string str_hw = cbHw->get_active_text(); for (int index = 0; index < 2; index++) { if (array_hw_local[index] == str_hw){ - if (array_hw[index] == "utc"){ + if (array_hw[index] == "utc") { wrapper_system(etc, "&"); } else{ @@ -519,6 +644,7 @@ void MainWindow::get_hardware_clock(string &cmd) { int error = warning_info; struct Result obj_result = this->wrapper_call(cmd); if (obj_result.error == 0) { + this->write_config(map_config_data, obj_result.response, "hw"); if (obj_result.response.find("localtime") != string::npos) { if (array_hw[0] == "localtime"){ cbHw->set_active(0); @@ -541,6 +667,7 @@ void MainWindow::get_hardware_clock(string &cmd) { } } else { + this->write_config(map_config_data, "", "hw"); cbHw->set_active(-1); } if (error != warning_info){ @@ -582,6 +709,7 @@ bool MainWindow::focus_ntp(string &cmd_set_ntp) { } if ((flag_error == false) && (flag_error_check_ntp == false)) { cmd = cmd_set_ntp + str_ntp + "\""; + this->write_config(map_config_data, str_ntp, "dhcp"); wrapper_system(cmd, "&"); } else { @@ -711,15 +839,18 @@ void MainWindow::event_entry_cbDhcp() { int activ_index = cbDhcp->get_active_row_number(); if (str_dhcp.length() == 0) { cbDhcp->set_active(0); + this->write_config(map_config_data, "default", "dhcp"); } else if (activ_index == 0) { txtNtpServer->set_text(default_get_dhcp); txtNtpServer->set_sensitive(false); + this->write_config(map_config_data, "default", "dhcp"); } else if (activ_index == 1) { // btnUpdateDateTime->set_sensitive(false); txtNtpServer->set_sensitive(false); txtNtpServer->set_text(""); + this->write_config(map_config_data, "dhcp", "dhcp"); } else if (activ_index == 2) { txtNtpServer->set_text(""); @@ -735,11 +866,15 @@ void MainWindow::event_entry_cbDhcp() { if (response != "dhcp" && response != "default"){ txtNtpServer->set_text(response); } - + this->write_config(map_config_data, response, "dhcp"); txtNtpServer->set_sensitive(true); } + else { + this->write_config(map_config_data, "", "dhcp"); + } } else if (activ_index == 3) { + this->write_config(map_config_data, "", "dhcp"); txtNtpServer->set_text(""); txtNtpServer->set_sensitive(false); // btnUpdateDateTime->set_sensitive(true); @@ -752,12 +887,15 @@ void MainWindow::save_Dhcp(string &cmd_default, string &cmd_dhcp, string &remove if (str_dhcp.length() == 0) { } else if (activ_index == 0) { + this->write_config(map_config_data, "default", "dhcp"); wrapper_system(cmd_default, "&"); } else if (activ_index == 1) { + this->write_config(map_config_data, "dhcp", "dhcp"); wrapper_system(cmd_dhcp, "&"); } else if (activ_index == 2) { + this->focus_ntp(cmd_set_ntp); } else if (activ_index== 3) { @@ -766,18 +904,20 @@ void MainWindow::save_Dhcp(string &cmd_default, string &cmd_dhcp, string &remove if (start_error != error_info) { error_info=start_error; } + this->write_config(map_config_data, "", "dhcp"); } } void MainWindow::entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhcp) { string cmd = cmd_get_dhcp; struct Result obj_result = this->wrapper_call(cmd); - if (obj_result.error== 0) { + if (obj_result.error == 0) { string str_dhcp = obj_result.response; // btnUpdateDateTime->set_sensitive(false); - str_dhcp = str_dhcp.substr(str_dhcp.find("=")+1,str_dhcp.length()); - str_dhcp = str_dhcp.substr(0,str_dhcp.find("\n")); + str_dhcp = str_dhcp.substr(str_dhcp.find("=")+1, str_dhcp.length()); + str_dhcp = str_dhcp.substr(0, str_dhcp.find("\n")); if (str_dhcp == "dhcp") { + this->write_config(map_config_data, "dhcp", "dhcp"); cbDhcp->set_active(1); txtNtpServer->set_text(""); txtNtpServer->set_sensitive(false); @@ -787,6 +927,7 @@ void MainWindow::entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhc cbDhcp->set_active(0); cmd = cmd_default_get_dhcp; struct Result obj_result = this->wrapper_call(cmd); + this->write_config(map_config_data, "default", "dhcp"); txtNtpServer->set_sensitive(false); if (obj_result.error== 0) { txtNtpServer->set_text(obj_result.response); @@ -800,15 +941,18 @@ void MainWindow::entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhc else { // btnUpdateDateTime->set_sensitive(false); if (str_dhcp == "") { + this->write_config(map_config_data, "", "dhcp"); lblMessage->set_text(_("Enter DHCP!")); windowMessDchp->show(); } else if (str_dhcp == "(null)") { cbDhcp->set_active(0); txtNtpServer->set_text(""); + this->write_config(map_config_data, "", "dhcp"); } else { cbDhcp->set_active(2); + this->write_config(map_config_data, str_dhcp, "dhcp"); txtNtpServer->set_text(str_dhcp); if (flag_ntp_edit ==false) { txtNtpServer->set_sensitive(true); @@ -817,6 +961,7 @@ void MainWindow::entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhc } } else { + this->write_config(map_config_data, "", "dhcp"); cbDhcp->set_active(3); txtNtpServer->set_text(""); txtNtpServer->set_sensitive(false); @@ -924,20 +1069,26 @@ array MainWindow::split_region_zone(string &read_reg_zon_cfg) { void MainWindow::enter_zone(string &cmd) { int activ_index_reg = cbRegion->get_active_row_number(); + if (activ_index_reg == -1) { + return; + } string reg_text = array_region[activ_index_reg]; int activ_index = cbZone->get_active_row_number(); + if (activ_index == -1) { + return; + } string zone_text = ""; if(!(reg_text.empty())) { int index= 0; for (const auto &zone: time_reg_map.at(reg_text)) { if (index == activ_index) { - zone_text=zone; + zone_text = zone; } index+= 1; } if (!(zone_text.empty())) { - str_zone=zone_text; - str_region=reg_text; + str_zone = zone_text; + str_region = reg_text; cmd = cmd + str_region + "/" + str_zone; wrapper_system(cmd, "&"); } @@ -962,6 +1113,8 @@ void MainWindow::parse_text_date() { } void MainWindow::append_region_zone(string region, string zone, Gtk::ComboBoxText *tmpCbReg, Gtk::ComboBoxText *tmpCbZone) { + this->write_config(map_config_data, region, "region"); + this->write_config(map_config_data, zone, "zone"); str_region = region; int index = 0; Glib::ustring reg_local = ""; @@ -1060,11 +1213,13 @@ string MainWindow::call(string cmd) { } void MainWindow::append_zone() { + cbZone->remove_all(); int index = cbRegion->get_active_row_number(); if (index!=-1) { string str_region = array_region[index]; string zone_mixing = ""; + this->write_config(map_config_data, str_region, "region"); string path_dir = ""; if(str_region.length() != 0) { for (const auto &_str_zone : time_reg_map_local.at(str_region)) { diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index 44b5838..3fa8d31 100644 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -135,6 +135,9 @@ class MainWindow : public Gtk::ApplicationWindow { vector array_region_local; vector array_region; std::map map_error; + std::map map_config_data; + std::map map_config_data_old; + public: MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); @@ -149,6 +152,10 @@ class MainWindow : public Gtk::ApplicationWindow { void fill_in_reg_zone(string &cmd); void load_globl_cfg(); void save_local_cfg(); + void event_zone(); + bool check_config(string key); + void event_log_hw(); + void write_config(std::map &map_config, string data, string key); string get_ubconfig_value(string &cmd); void save_global_cfg(); void save_Dhcp(string &cmd_default, string &cmd_dhcp, string &remove, string &cmd_set_ntp); diff --git a/ubl-settings-datetime_ru.po b/ubl-settings-datetime_ru.po index 3b7347b..3898417 100644 --- a/ubl-settings-datetime_ru.po +++ b/ubl-settings-datetime_ru.po @@ -22,6 +22,9 @@ msgstr "https://wiki.ublinux.ru/ru/Программное_обеспечение msgid "Copyright © UBSoft LLC, 2022 - " msgstr "Авторские права © ООО \"Юбисофт\", 2022 - " +msgid "Nothing to save!" +msgstr "Нечего сохранять!" + msgid "Select the method of hardware time synchronization" msgstr "Выберите способ синхронизации аппаратного времени"