diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index e4e1133..a7ed26f 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -13,7 +13,7 @@ find_package(ICU REQUIRED COMPONENTS uc dt in io) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always \ -O2 -pipe -fno-plt -fexceptions \ -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \ - -fstack-clash-protection -fcf-protection") + -fstack-clash-protection -fcf-protection -g ") set(SOURCE_FILES main.cc diff --git a/source/ubl-settings-datetime.cc b/source/ubl-settings-datetime.cc index 646b6de..a3e7edf 100644 --- a/source/ubl-settings-datetime.cc +++ b/source/ubl-settings-datetime.cc @@ -28,7 +28,6 @@ #include #include "unicode/utypes.h" #include "unicode/utext.h" - #include #include #include @@ -553,7 +552,7 @@ void MainWindow::get_config(){ this->update_hour_minute(); this->update_calendar(); this->enry_dhcp_mess(); - string cmd = "/usr/bin/ubconfig --source global get clock ZONE"; + string cmd = "/usr/bin/ubconfig --default --source global get clock ZONE"; struct Result obj_result = this->wrapper_call(cmd); if (obj_result.error==0){ auto arr_reg_zone_glob = this->split_region_zone(obj_result.response); @@ -561,14 +560,14 @@ void MainWindow::get_config(){ this->append_region_zone(arr_reg_zone_glob[0],arr_reg_zone_glob[1],cbRegionGlob,cbZoneGlob); } else{ - this->append_region_zone("Africa","Abidjan", cbRegion, cbZone); + this->append_region_zone("","",cbRegionGlob,cbZoneGlob); } } else { - this->append_region_zone("Africa","Abidjan",cbRegionGlob,cbZoneGlob); + this->append_region_zone("","",cbRegionGlob,cbZoneGlob); } - cmd = "/usr/bin/ubconfig --source system get clock ZONE"; + cmd = "/usr/bin/ubconfig --default --source system get clock ZONE"; struct Result obj_result_1 = this->wrapper_call(cmd); if (obj_result_1.error==0){ auto arr_reg_zone = this->split_region_zone(obj_result_1.response); @@ -576,12 +575,13 @@ void MainWindow::get_config(){ this->append_region_zone(arr_reg_zone[0],arr_reg_zone[1], cbRegion, cbZone); } else{ - this->append_region_zone("Africa","Abidjan", cbRegion, cbZone); + this->append_region_zone("","",cbRegion,cbZone); } } else { - this->append_region_zone("Africa","Abidjan", cbRegion, cbZone); + this->append_region_zone("","",cbRegion,cbZone); } + } array MainWindow::split_region_zone(string read_reg_zon_cfg){ @@ -677,14 +677,34 @@ void MainWindow::append_region_zone(string region, string zone, Gtk::ComboBoxTex str_region_glob=region; int index = 0; Glib::ustring reg_local = ""; - for (const auto &text : array_region) { - reg_local = text; - reg_local = string(_(reg_local.c_str())); - tmpCbReg->append(Glib::ustring(reg_local)); - if (text == region){ - tmpCbReg->set_active_text(reg_local); + int size_vec = array_region_local.size(); + if (size_vec==0){ + for (auto& [key, value]: time_reg_map){ + array_region_local.push_back(string(_(key.c_str()))); + array_region.push_back(key); + index+=1; + } + } + // Cортировка пузырьком + if (size_vec==0){ + for (int i = 0; i < size_vec; i++) { + for (int j = 0; j < size_vec-1; j++) { + if (array_region_local[j] > array_region_local[j + 1]) { + auto b = array_region_local[j]; + array_region_local[j] = array_region_local[j + 1]; + array_region_local[j + 1] = b; + b = array_region[j]; + array_region[j] = array_region[j + 1]; + array_region[j + 1] = b; + } + } + } + } + for (string ® : array_region_local){ + tmpCbReg->append(Glib::ustring(reg)); + if (reg == string(_(region.c_str()))){ + tmpCbReg->set_active_text(reg); } - index+=1; } index = 0; string zone_mixing = ""; @@ -692,14 +712,25 @@ void MainWindow::append_region_zone(string region, string zone, Gtk::ComboBoxTex string zone_offest = ""; path_reg_zone=region+"/"+zone; zone_offest = this->zone_file_read(path_reg_zone) + _(zone.c_str()); - for (string &_str_zone : time_reg_map_local.at(region)){ - tmpCbZone->append(_str_zone); - if (_str_zone!=""){ - if (zone_offest == _str_zone){ - tmpCbZone->set_active(index); + if (region==""){ + tmpCbZone->append(" "); + tmpCbZone->set_active(0); + return; + } + if (time_reg_map_local.find(region) == time_reg_map_local.end()){ + tmpCbZone->append(" "); + tmpCbZone->set_active(0); + } + else{ + for (string &_str_zone : time_reg_map_local.at(region)){ + tmpCbZone->append(_str_zone); + if (_str_zone!=""){ + if (zone_offest == _str_zone){ + tmpCbZone->set_active(index); + } } - } - index+=1; + index+=1; + } } } @@ -866,11 +897,10 @@ void MainWindow::read_file(){ if (fs::is_directory(path_dir)){ if (key_reg!="Pacific"){ if (key_reg!="posix"){ - if (key_reg!="Etc"){ + //if (key_reg!="Etc"){ if (key_reg!="right"){ vector zone; vector zone_local; - //zone.push_back(""); for (const auto & entry_zone : fs::directory_iterator(path_dir)){ std::ifstream in1(entry_zone.path()); // окрываем файл для чтения if (in1.is_open()){ @@ -887,7 +917,7 @@ void MainWindow::read_file(){ this->sort_zone(&zone_local, &zone); time_reg_map.insert({key_reg, zone}); time_reg_map_local.insert({key_reg, zone_local}); - }}}} + }}} } } in.close(); @@ -900,46 +930,47 @@ void MainWindow::sort_zone(vector *time_reg_map_local,vector *ti string str_j_1 = ""; int j_i_1; int size_vec = time_reg_map_local->size(); - for (int i = 0; i < size_vec; i++) { - for (int j = 0; j < size_vec-1; j++) { + for (int i = 1; i < size_vec; i++) { + for (int j = 1; j < size_vec-1; j++) { str_j=(*time_reg_map_local)[j]; - str_j = str_j.substr(5,str_j.find(")")-5); - if (str_j[1]=='0'){ - str_j.replace(1,1,"0"); - } - - if (str_j.find("+") != std::string::npos){ - str_j.replace(0,1,"+"); - j_i = stoi(str_j); - } - else{ - str_j.replace(0,1,"-"); - j_i = stoi(str_j); - j_i=-j_i; - } - str_j_1=(*time_reg_map_local)[j+1]; - str_j_1 = str_j_1.substr(5,str_j_1.find(")")-5); - if (str_j_1[1]=='0'){ - str_j_1.replace(1,1,"0"); - } - if (str_j_1.find("+") != std::string::npos){ - str_j_1.replace(0,1,"+"); - j_i_1 = stoi(str_j_1); - } - else{ - str_j_1.replace(0,1,"-"); - j_i_1 = stoi(str_j_1); - j_i_1 = -j_i_1; - } - if (j_i > j_i_1) { - string b = (*time_reg_map_local)[j]; - (*time_reg_map_local)[j] = (*time_reg_map_local)[j + 1]; - (*time_reg_map_local)[j + 1] = b; + if (str_j!=" "){ + str_j = str_j.substr(5,str_j.find(")")-5); + if (str_j[1]=='0'){ + str_j.replace(1,1,"0"); + } + + if (str_j.find("+") != std::string::npos){ + str_j.replace(0,1,"+"); + j_i = stoi(str_j); + } + else{ + str_j.replace(0,1,"-"); + j_i = stoi(str_j); + j_i=-j_i; + } + str_j_1=(*time_reg_map_local)[j+1]; + str_j_1 = str_j_1.substr(5,str_j_1.find(")")-5); + if (str_j_1[1]=='0'){ + str_j_1.replace(1,1,"0"); + } + if (str_j_1.find("+") != std::string::npos){ + str_j_1.replace(0,1,"+"); + j_i_1 = stoi(str_j_1); + } + else{ + str_j_1.replace(0,1,"-"); + j_i_1 = stoi(str_j_1); + j_i_1 = -j_i_1; + } + if (j_i > j_i_1) { + string b = (*time_reg_map_local)[j]; + (*time_reg_map_local)[j] = (*time_reg_map_local)[j + 1]; + (*time_reg_map_local)[j + 1] = b; - b = (*time_reg_map)[j]; - (*time_reg_map)[j] = (*time_reg_map)[j + 1]; - (*time_reg_map)[j + 1] = b; - } + b = (*time_reg_map)[j]; + (*time_reg_map)[j] = (*time_reg_map)[j + 1]; + (*time_reg_map)[j + 1] = b; + } } } } } diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index a3266cc..4a5ef20 100644 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -99,12 +99,14 @@ class MainWindow : public Gtk::ApplicationWindow { Type response; int error; }; - string array_region[14]={ - "Africa", + vector array_region_local; + vector array_region;/*={ "America", "Antarctica", "Arctic", "Asia", + "Africa", + "Etc", "Atlantic", "Australia", "Brazil", @@ -113,7 +115,7 @@ class MainWindow : public Gtk::ApplicationWindow { "Europe", "Indian", "Mexico", - "US"}; + "US"};*/ public: MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); MainWindow(Glib::RefPtr const& builder);