Добавлена сортировка регионов

pull/51/head
Igor Belitskiy 3 years ago
parent 331f665eec
commit 8e2a8dd95a

@ -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 \ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always \
-O2 -pipe -fno-plt -fexceptions \ -O2 -pipe -fno-plt -fexceptions \
-Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \ -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \
-fstack-clash-protection -fcf-protection") -fstack-clash-protection -fcf-protection -g ")
set(SOURCE_FILES set(SOURCE_FILES
main.cc main.cc

@ -28,7 +28,6 @@
#include <unicode/uldnames.h> #include <unicode/uldnames.h>
#include "unicode/utypes.h" #include "unicode/utypes.h"
#include "unicode/utext.h" #include "unicode/utext.h"
#include <unicode/timezone.h> #include <unicode/timezone.h>
#include <unicode/calendar.h> #include <unicode/calendar.h>
#include <array> #include <array>
@ -553,7 +552,7 @@ void MainWindow::get_config(){
this->update_hour_minute(); this->update_hour_minute();
this->update_calendar(); this->update_calendar();
this->enry_dhcp_mess(); 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<string> obj_result = this->wrapper_call(cmd); struct Result<string> obj_result = this->wrapper_call(cmd);
if (obj_result.error==0){ if (obj_result.error==0){
auto arr_reg_zone_glob = this->split_region_zone(obj_result.response); 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); this->append_region_zone(arr_reg_zone_glob[0],arr_reg_zone_glob[1],cbRegionGlob,cbZoneGlob);
} }
else{ else{
this->append_region_zone("Africa","Abidjan", cbRegion, cbZone); this->append_region_zone("","",cbRegionGlob,cbZoneGlob);
} }
} }
else { 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<string> obj_result_1 = this->wrapper_call(cmd); struct Result<string> obj_result_1 = this->wrapper_call(cmd);
if (obj_result_1.error==0){ if (obj_result_1.error==0){
auto arr_reg_zone = this->split_region_zone(obj_result_1.response); 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); this->append_region_zone(arr_reg_zone[0],arr_reg_zone[1], cbRegion, cbZone);
} }
else{ else{
this->append_region_zone("Africa","Abidjan", cbRegion, cbZone); this->append_region_zone("","",cbRegion,cbZone);
} }
} }
else { else {
this->append_region_zone("Africa","Abidjan", cbRegion, cbZone); this->append_region_zone("","",cbRegion,cbZone);
} }
} }
array<string, 2> MainWindow::split_region_zone(string read_reg_zon_cfg){ array<string, 2> 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; str_region_glob=region;
int index = 0; int index = 0;
Glib::ustring reg_local = ""; Glib::ustring reg_local = "";
for (const auto &text : array_region) { int size_vec = array_region_local.size();
reg_local = text; if (size_vec==0){
reg_local = string(_(reg_local.c_str())); for (auto& [key, value]: time_reg_map){
tmpCbReg->append(Glib::ustring(reg_local)); array_region_local.push_back(string(_(key.c_str())));
if (text == region){ array_region.push_back(key);
tmpCbReg->set_active_text(reg_local); 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 &reg : array_region_local){
tmpCbReg->append(Glib::ustring(reg));
if (reg == string(_(region.c_str()))){
tmpCbReg->set_active_text(reg);
} }
index+=1;
} }
index = 0; index = 0;
string zone_mixing = ""; string zone_mixing = "";
@ -692,14 +712,25 @@ void MainWindow::append_region_zone(string region, string zone, Gtk::ComboBoxTex
string zone_offest = ""; string zone_offest = "";
path_reg_zone=region+"/"+zone; path_reg_zone=region+"/"+zone;
zone_offest = this->zone_file_read(path_reg_zone) + _(zone.c_str()); zone_offest = this->zone_file_read(path_reg_zone) + _(zone.c_str());
for (string &_str_zone : time_reg_map_local.at(region)){ if (region==""){
tmpCbZone->append(_str_zone); tmpCbZone->append(" ");
if (_str_zone!=""){ tmpCbZone->set_active(0);
if (zone_offest == _str_zone){ return;
tmpCbZone->set_active(index); }
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 (fs::is_directory(path_dir)){
if (key_reg!="Pacific"){ if (key_reg!="Pacific"){
if (key_reg!="posix"){ if (key_reg!="posix"){
if (key_reg!="Etc"){ //if (key_reg!="Etc"){
if (key_reg!="right"){ if (key_reg!="right"){
vector<string> zone; vector<string> zone;
vector<string> zone_local; vector<string> zone_local;
//zone.push_back("");
for (const auto & entry_zone : fs::directory_iterator(path_dir)){ for (const auto & entry_zone : fs::directory_iterator(path_dir)){
std::ifstream in1(entry_zone.path()); // окрываем файл для чтения std::ifstream in1(entry_zone.path()); // окрываем файл для чтения
if (in1.is_open()){ if (in1.is_open()){
@ -887,7 +917,7 @@ void MainWindow::read_file(){
this->sort_zone(&zone_local, &zone); this->sort_zone(&zone_local, &zone);
time_reg_map.insert({key_reg, zone}); time_reg_map.insert({key_reg, zone});
time_reg_map_local.insert({key_reg, zone_local}); time_reg_map_local.insert({key_reg, zone_local});
}}}} }}}
} }
} }
in.close(); in.close();
@ -900,46 +930,47 @@ void MainWindow::sort_zone(vector<string> *time_reg_map_local,vector<string> *ti
string str_j_1 = ""; string str_j_1 = "";
int j_i_1; int j_i_1;
int size_vec = time_reg_map_local->size(); int size_vec = time_reg_map_local->size();
for (int i = 0; i < size_vec; i++) { for (int i = 1; i < size_vec; i++) {
for (int j = 0; j < size_vec-1; j++) { for (int j = 1; j < size_vec-1; j++) {
str_j=(*time_reg_map_local)[j]; str_j=(*time_reg_map_local)[j];
str_j = str_j.substr(5,str_j.find(")")-5); if (str_j!=" "){
if (str_j[1]=='0'){ str_j = str_j.substr(5,str_j.find(")")-5);
str_j.replace(1,1,"0"); if (str_j[1]=='0'){
} str_j.replace(1,1,"0");
}
if (str_j.find("+") != std::string::npos){
str_j.replace(0,1,"+"); if (str_j.find("+") != std::string::npos){
j_i = stoi(str_j); str_j.replace(0,1,"+");
} j_i = stoi(str_j);
else{ }
str_j.replace(0,1,"-"); else{
j_i = stoi(str_j); str_j.replace(0,1,"-");
j_i=-j_i; 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); str_j_1=(*time_reg_map_local)[j+1];
if (str_j_1[1]=='0'){ str_j_1 = str_j_1.substr(5,str_j_1.find(")")-5);
str_j_1.replace(1,1,"0"); 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,"+"); if (str_j_1.find("+") != std::string::npos){
j_i_1 = stoi(str_j_1); str_j_1.replace(0,1,"+");
} j_i_1 = stoi(str_j_1);
else{ }
str_j_1.replace(0,1,"-"); else{
j_i_1 = stoi(str_j_1); str_j_1.replace(0,1,"-");
j_i_1 = -j_i_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]; if (j_i > j_i_1) {
(*time_reg_map_local)[j] = (*time_reg_map_local)[j + 1]; string b = (*time_reg_map_local)[j];
(*time_reg_map_local)[j + 1] = b; (*time_reg_map_local)[j] = (*time_reg_map_local)[j + 1];
(*time_reg_map_local)[j + 1] = b;
b = (*time_reg_map)[j]; b = (*time_reg_map)[j];
(*time_reg_map)[j] = (*time_reg_map)[j + 1]; (*time_reg_map)[j] = (*time_reg_map)[j + 1];
(*time_reg_map)[j + 1] = b; (*time_reg_map)[j + 1] = b;
} } }
} }
} }
} }

@ -99,12 +99,14 @@ class MainWindow : public Gtk::ApplicationWindow {
Type response; Type response;
int error; int error;
}; };
string array_region[14]={ vector<string> array_region_local;
"Africa", vector<string> array_region;/*={
"America", "America",
"Antarctica", "Antarctica",
"Arctic", "Arctic",
"Asia", "Asia",
"Africa",
"Etc",
"Atlantic", "Atlantic",
"Australia", "Australia",
"Brazil", "Brazil",
@ -113,7 +115,7 @@ class MainWindow : public Gtk::ApplicationWindow {
"Europe", "Europe",
"Indian", "Indian",
"Mexico", "Mexico",
"US"}; "US"};*/
public: public:
MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder); MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder);
MainWindow(Glib::RefPtr<Gtk::Builder> const& builder); MainWindow(Glib::RefPtr<Gtk::Builder> const& builder);

Loading…
Cancel
Save