Merge pull request 'develop' (#52) from develop into master

Reviewed-on: #52
pull/59/head
Dmitry Razumov 3 years ago
commit 8a4f9b8636

@ -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 ")
set(SOURCE_FILES set(SOURCE_FILES
main.cc main.cc

@ -1,37 +1,18 @@
#include <gtkmm/window.h> #include <gtkmm/window.h>
#include <stddef.h> #include <glibmm/i18n.h>
#include <cstddef> #include <gtkmm/plug.h>
#include <cstdlib> #include <gtkmm/stock.h>
#include <iostream>
#include <memory>
#include <gtkmm.h> #include <gtkmm.h>
#include <ostream> #include <iostream>
#include <map>
#include <string> #include <string>
#include <ctime> #include <array>
#include <vector> #include <vector>
#include <map>
#include <fstream> #include <fstream>
#include <filesystem> #include <filesystem>
#include <glibmm/i18n.h>
#include <stdio.h>
#include <gtkmm/plug.h>
#include <gtkmm/stock.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h> #include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <unicode/unistr.h>
#include <unicode/ustdio.h>
#include <unicode/uloc.h>
#include <unicode/uldnames.h>
#include "unicode/utypes.h"
#include "unicode/utext.h"
#include <unicode/timezone.h> #include <unicode/timezone.h>
#include <unicode/calendar.h> #include <unicode/calendar.h>
#include <array>
#include "ubl-settings-datetime.h" #include "ubl-settings-datetime.h"
using namespace std; using namespace std;
@ -477,7 +458,6 @@ void MainWindow::get_calendar(){
} }
void MainWindow::calendar_show(){ void MainWindow::calendar_show(){
cout << 2222 << endl;
if (year==0){ if (year==0){
time_t now = time(0); time_t now = time(0);
tm *ltm = localtime(&now); tm *ltm = localtime(&now);
@ -554,7 +534,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);
@ -562,14 +542,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);
@ -577,12 +557,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){
@ -678,14 +659,35 @@ 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){
size_vec = array_region_local.size();
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 = "";
@ -693,14 +695,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; }
} }
} }
@ -867,11 +880,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()){
@ -888,7 +900,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();
@ -901,46 +913,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){ if (str_j.find("+") != std::string::npos){
str_j.replace(0,1,"+"); str_j.replace(0,1,"+");
j_i = stoi(str_j); j_i = stoi(str_j);
} }
else{ else{
str_j.replace(0,1,"-"); str_j.replace(0,1,"-");
j_i = stoi(str_j); j_i = stoi(str_j);
j_i=-j_i; j_i=-j_i;
} }
str_j_1=(*time_reg_map_local)[j+1]; 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 = str_j_1.substr(5,str_j_1.find(")")-5);
if (str_j_1[1]=='0'){ if (str_j_1[1]=='0'){
str_j_1.replace(1,1,"0"); str_j_1.replace(1,1,"0");
} }
if (str_j_1.find("+") != std::string::npos){ if (str_j_1.find("+") != std::string::npos){
str_j_1.replace(0,1,"+"); str_j_1.replace(0,1,"+");
j_i_1 = stoi(str_j_1); j_i_1 = stoi(str_j_1);
} }
else{ else{
str_j_1.replace(0,1,"-"); str_j_1.replace(0,1,"-");
j_i_1 = stoi(str_j_1); j_i_1 = stoi(str_j_1);
j_i_1 = -j_i_1; j_i_1 = -j_i_1;
} }
if (j_i > j_i_1) { if (j_i > j_i_1) {
string b = (*time_reg_map_local)[j]; string b = (*time_reg_map_local)[j];
(*time_reg_map_local)[j] = (*time_reg_map_local)[j + 1]; (*time_reg_map_local)[j] = (*time_reg_map_local)[j + 1];
(*time_reg_map_local)[j + 1] = b; (*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,21 +99,8 @@ 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",
"Antarctica",
"Arctic",
"Asia",
"Atlantic",
"Australia",
"Brazil",
"Canada",
"Chile",
"Europe",
"Indian",
"Mexico",
"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);

@ -169,28 +169,6 @@
</object> </object>
</child> </child>
</object> </object>
<object class="GtkPopover" id="popCalendar">
<property name="width-request">240</property>
<property name="height-request">185</property>
<property name="can-focus">False</property>
<property name="position">bottom</property>
<property name="constrain-to">none</property>
<child>
<object class="GtkCalendar" id="cldrDate">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-left">10</property>
<property name="margin-right">10</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<property name="margin-top">10</property>
<property name="margin-bottom">10</property>
<property name="year">2023</property>
<property name="month">1</property>
<property name="day">10</property>
</object>
</child>
</object>
<object class="GtkWindow" id="window"> <object class="GtkWindow" id="window">
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="title" translatable="yes" context="Settings the date and time" comments="Date and Time Settings">Настройки даты и времени</property> <property name="title" translatable="yes" context="Settings the date and time" comments="Date and Time Settings">Настройки даты и времени</property>
@ -1003,6 +981,29 @@ Format: DD.MM.YYYY</property>
</object> </object>
</child> </child>
</object> </object>
<object class="GtkPopover" id="popCalendar">
<property name="width-request">240</property>
<property name="height-request">185</property>
<property name="can-focus">False</property>
<property name="relative-to">btnChooseDate</property>
<property name="position">bottom</property>
<property name="constrain-to">none</property>
<child>
<object class="GtkCalendar" id="cldrDate">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-left">10</property>
<property name="margin-right">10</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<property name="margin-top">10</property>
<property name="margin-bottom">10</property>
<property name="year">2023</property>
<property name="month">1</property>
<property name="day">10</property>
</object>
</child>
</object>
<object class="GtkWindow" id="windowsNnpClose"> <object class="GtkWindow" id="windowsNnpClose">
<property name="can-focus">False</property> <property name="can-focus">False</property>
<child> <child>

Loading…
Cancel
Save