Merge pull request 'Изменение логики регионов и зон' (#13) from develop into master

Reviewed-on: Igor1/ubl-settings-datetime#13
pull/43/head
Igor Belitskiy 3 years ago
commit 849e806c79

@ -31,6 +31,7 @@
#include <unicode/timezone.h>
#include <unicode/calendar.h>
#include <array>
#include "ubl-settings-datetime.h"
using namespace std;
@ -492,21 +493,41 @@ void MainWindow::get_config(){
this->update_hour_minute();
this->update_calendar();
this->enry_dhcp_mess();
string read_reg_zon_cfg = this->call("/usr/bin/ubconfig get clock ZONE");
string read_reg_zon_cfg = this->call("/usr/bin/ubconfig --source global get clock ZONE");
if ((read_reg_zon_cfg != "") && (strstr(read_reg_zon_cfg.c_str() ,"(null)")==NULL)){
read_reg_zon_cfg = read_reg_zon_cfg.substr(read_reg_zon_cfg.find("=")+1,read_reg_zon_cfg.length());
read_reg_zon_cfg = read_reg_zon_cfg.substr(0,read_reg_zon_cfg.find("\n"));
string str_filling_reg = read_reg_zon_cfg.substr(0,read_reg_zon_cfg.find("/"));
string str_filling_zon = read_reg_zon_cfg.substr(read_reg_zon_cfg.find("/")+1,read_reg_zon_cfg.length());
str_filling_zon = str_filling_zon.substr(0,str_filling_zon.find("\n"));
string str_zone_check = "";
this->append_region_zone(str_filling_reg,str_filling_zon);
auto arr_reg_zone_glob = this->split_region_zone(read_reg_zon_cfg);
this->append_region_zone(arr_reg_zone_glob[0],arr_reg_zone_glob[1],cbRegionGlob,cbZoneGlob);
}
else {
this->append_region_zone("Africa","Abidjan");
this->append_region_zone("Africa","Abidjan",cbRegionGlob,cbZoneGlob);
}
read_reg_zon_cfg = this->call("/usr/bin/ubconfig --source system get clock ZONE");
if ((read_reg_zon_cfg != "") && (strstr(read_reg_zon_cfg.c_str() ,"(null)")==NULL)){
auto arr_reg_zone_glob = this->split_region_zone(read_reg_zon_cfg);
this->append_region_zone(arr_reg_zone_glob[0],arr_reg_zone_glob[1], cbRegion, cbZone);
}
else {
this->append_region_zone("Africa","Abidjan", cbRegion, cbZone);
}
}
array<string, 2> MainWindow::split_region_zone(string read_reg_zon_cfg){
read_reg_zon_cfg = read_reg_zon_cfg.substr(read_reg_zon_cfg.find("=")+1,read_reg_zon_cfg.length());
read_reg_zon_cfg = read_reg_zon_cfg.substr(0,read_reg_zon_cfg.find("\n"));
string str_filling_reg = read_reg_zon_cfg.substr(0,read_reg_zon_cfg.find("/"));
string str_filling_zon = read_reg_zon_cfg.substr(read_reg_zon_cfg.find("/")+1,read_reg_zon_cfg.length());
str_filling_zon = str_filling_zon.substr(0,str_filling_zon.find("\n"));
array<string, 2> arr;
arr[0] = str_filling_reg;
arr[1] = str_filling_zon;
return arr;
}
void MainWindow::enter_zone(){
int activ_index_reg = cbRegion->get_active_row_number();
string reg_text=array_region[activ_index_reg];
@ -523,10 +544,9 @@ void MainWindow::enter_zone(){
if (!(zone_text.empty())){
str_zone=zone_text;
str_region=reg_text;
string cmd = "rm -f /etc/localtime";
string cmd = "";
cmd = " ubconfig --target system set clock ZONE=" + str_region + "/" + str_zone;
system(cmd.c_str());
string cmd1 = "ln -s /usr/share/zoneinfo/" + str_region + "/" + str_zone+" /etc/localtime";
system(cmd1.c_str());
}
else{
str_zone="";
@ -563,7 +583,7 @@ void MainWindow::enter_zone_glob(){
}
if (!(zone_text.empty())){
//str_zoneGlob = zone_text.substr(zone_text.find(") ")+2,zone_text.length());
string cmd = "/usr/bin/ubconfig set clock ZONE=" +reg_text +"/" + zone_text;
string cmd = "/usr/bin/ubconfig --target global set clock ZONE=" +reg_text +"/" + zone_text;
system(cmd.c_str());
}
else{
@ -594,7 +614,7 @@ void MainWindow::set_ntp_toggle_glob(){
}
void MainWindow::append_region_zone(string region, string zone){
void MainWindow::append_region_zone(string region, string zone, Gtk::ComboBoxText *tmpCbReg, Gtk::ComboBoxText *tmpCbZone){
str_region=region;
str_region_glob=region;
int index = 0;
@ -602,11 +622,9 @@ void MainWindow::append_region_zone(string region, string zone){
for (const auto &text : array_region) {
reg_local = text;
reg_local = string(_(reg_local.c_str()));
cbRegion->append(Glib::ustring(reg_local));
cbRegionGlob->append(Glib::ustring(reg_local));
tmpCbReg->append(Glib::ustring(reg_local));
if (text == region){
cbRegionGlob->set_active_text(reg_local);
cbRegion->set_active_text(reg_local);
tmpCbReg->set_active_text(reg_local);
}
index+=1;
}
@ -618,12 +636,10 @@ void MainWindow::append_region_zone(string region, string zone){
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)){
cbZone->append(_str_zone);
cbZoneGlob->append(_str_zone);
tmpCbZone->append(_str_zone);
if (_str_zone!=""){
if (zone_offest == _str_zone){
cbZone->set_active(index);
cbZoneGlob->set_active(index);
tmpCbZone->set_active(index);
}
}
index+=1;
@ -893,4 +909,5 @@ void help(){
g_print(" --lock-ntp Disable ntp field editing\n");
g_print(" --lock-datetime Disable datetime field editing\n");
g_print(" --lock-update Disable save changes\n");
}
}

@ -54,7 +54,7 @@ class MainWindow : public Gtk::ApplicationWindow {
void enter_zone();
void enter_zone_glob();
void set_ntp_toggle();
void append_region_zone(string region, string zone);
void append_region_zone(string region, string zone, Gtk::ComboBoxText *tmpCbReg, Gtk::ComboBoxText *tmpCbZone);
string call(string cmd);
void append_zone();
void append_zone_glob();
@ -72,6 +72,7 @@ class MainWindow : public Gtk::ApplicationWindow {
void wind_close_ntp();
void wrapper_update_time_date();
string zone_file_read(string zone);
array<string, 2> split_region_zone(string read_reg_zon_cfg);
string str_remove(std::string& source, const std::string to_remove);
vector<std::string> split(const std::string &s, char delim);
private:

@ -15,11 +15,14 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">5</property>
<property name="margin-right">5</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">5</property>
<property name="margin-right">5</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
@ -94,11 +97,14 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">5</property>
<property name="margin-right">5</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">5</property>
<property name="margin-right">5</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>

Loading…
Cancel
Save