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

Reviewed-on: #50
pull/59/head
Dmitry Razumov 3 years ago
commit 313436d656

@ -336,7 +336,7 @@ bool MainWindow::focus_ntp(GdkEventFocus* event){
}
if (flag_error==false){
cmd = "/usr/bin/ubconfig set network NTPSERVERS=\"" + str_ntp + "\"";
this->call(cmd.c_str());
response_cmd = system(cmd.c_str());
}
else{
lblMessage->set_text(_("An invalid character is entered"));
@ -347,6 +347,34 @@ bool MainWindow::focus_ntp(GdkEventFocus* event){
return true;
}
struct MainWindow::Result<string> MainWindow::wrapper_call(string cmd){
struct Result<string> obj_result;
string response=this->call(cmd);
if ((response.find("(null)")==std::string::npos) && (response.length()!=0)){
if (response.find("=")!=std::string::npos){
if (response.find("\n")!=std::string::npos){
response = response.substr(response.find("=")+1,response.length());
response = response.substr(0,response.find("\n"));
obj_result.response = response;
obj_result.error = 0;
}
else{
obj_result.response = response;
obj_result.error = 1;
}
}
else{
obj_result.response = response;
obj_result.error = 2;
}
}
else{
obj_result.response = response;
obj_result.error = 3;
}
return obj_result;
}
void MainWindow::event_entry_cbDhcp(){
Glib::ustring str_dhcp = cbDhcp->get_active_text();
int activ_index = cbDhcp->get_active_row_number();
@ -357,9 +385,17 @@ void MainWindow::event_entry_cbDhcp(){
response_cmd=system(cmd.c_str());
txtNtpServer->set_sensitive(false);
cbDhcp->set_active(activ_index);
string response = this->call("/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT");
this->str_remove(response, "\n");
txtNtpServer->set_text(response);
cmd = "/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT";
struct Result<string> obj_result = this->wrapper_call(cmd);
if (obj_result.error==0){
txtNtpServer->set_text(obj_result.response);
}
else{
//string error = "";
//error = string(_("ERROR")) + "\n" + obj_result.response;
//lblMessage->set_text(error);
//mess_dchp->show();
}
}
else if (activ_index==1){
btnUpdateDateTime->set_sensitive(false);
@ -375,16 +411,24 @@ void MainWindow::event_entry_cbDhcp(){
if (txtNtpServer->get_text().find("default")!=std::string::npos){
txtNtpServer->set_text("");
}
string str_dhcp = this->call("/usr/bin/ubconfig get network NTPSERVERS");
if ((str_dhcp.find("(null)")==std::string::npos) && (str_dhcp.find("default")==std::string::npos)){
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" && str_dhcp!="(null)"){
txtNtpServer->set_text(str_dhcp);
string cmd = "/usr/bin/ubconfig get network NTPSERVERS";
struct Result<string> obj_result = this->wrapper_call(cmd);
if (obj_result.error==0){
if (obj_result.response.find("default")==std::string::npos){
if (obj_result.response.find("dhcp")==std::string::npos){
txtNtpServer->set_text(obj_result.response);
}
cbDhcp->set_active(activ_index);
}
}
else if (obj_result.error==3){}
else{
string error = "";
error = string(_("ERROR")) + "\n" + obj_result.response;
lblMessage->set_text(error);
mess_dchp->show();
}
}
else if (activ_index==3){
string cmd = "/usr/bin/ubconfig remove network NTPSERVERS";
response_cmd=system(cmd.c_str());
@ -433,6 +477,7 @@ void MainWindow::get_calendar(){
}
void MainWindow::calendar_show(){
cout << 2222 << endl;
if (year==0){
time_t now = time(0);
tm *ltm = localtime(&now);
@ -451,13 +496,14 @@ void MainWindow::calendar_show(){
}
void MainWindow::enry_dhcp_mess(){
string str_dhcp = this->call("/usr/bin/ubconfig get network NTPSERVERS");
if (str_dhcp.find("(null)")==std::string::npos){
string cmd = "/usr/bin/ubconfig get network NTPSERVERS";
struct Result<string> obj_result = this->wrapper_call(cmd);
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"));
if (str_dhcp=="dhcp"){
cbDhcp->set_active(1);
txtNtpServer->set_text("");
txtNtpServer->set_sensitive(false);
@ -465,10 +511,18 @@ void MainWindow::enry_dhcp_mess(){
else if (str_dhcp=="default"){
btnUpdateDateTime->set_sensitive(false);
cbDhcp->set_active(0);
string response = this->call("/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT");
this->str_remove(response, "\n");
txtNtpServer->set_text(response);
string cmd = "/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT";
struct Result<string> obj_result = this->wrapper_call(cmd);
txtNtpServer->set_sensitive(false);
if (obj_result.error==0){
txtNtpServer->set_text(obj_result.response);
}
else{
//string error = "";
//error = string(_("ERROR")) + "\n" + obj_result.response;
//lblMessage->set_text(error);
//mess_dchp->show();
}
}
else{
btnUpdateDateTime->set_sensitive(false);
@ -500,21 +554,31 @@ 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 --source global 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);
string cmd = "/usr/bin/ubconfig --source global get clock ZONE";
struct Result<string> obj_result = this->wrapper_call(cmd);
if (obj_result.error==0){
auto arr_reg_zone_glob = this->split_region_zone(obj_result.response);
if (arr_reg_zone_glob[0].length()!=0){
this->append_region_zone(arr_reg_zone_glob[0],arr_reg_zone_glob[1],cbRegionGlob,cbZoneGlob);
}
else{
this->append_region_zone("Africa","Abidjan",cbRegionGlob,cbZoneGlob);
this->append_region_zone("Africa","Abidjan", cbRegion, cbZone);
}
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",cbRegionGlob,cbZoneGlob);
}
cmd = "/usr/bin/ubconfig --source system get clock ZONE";
struct Result<string> 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);
if (arr_reg_zone[0].length()!=0){
this->append_region_zone(arr_reg_zone[0],arr_reg_zone[1], cbRegion, cbZone);
}
else{
this->append_region_zone("Africa","Abidjan", cbRegion, cbZone);
}
}
else {
this->append_region_zone("Africa","Abidjan", cbRegion, cbZone);
@ -522,14 +586,18 @@ void MainWindow::get_config(){
}
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"));
array<string, 2> arr;
if (read_reg_zon_cfg.find("/")!=std::string::npos){
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;
}
else{
arr[0] = "";
arr[1] = "";
}
return arr;
}

@ -35,49 +35,6 @@ private:
class MainWindow : public Gtk::ApplicationWindow {
public:
MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder);
MainWindow(Glib::RefPtr<Gtk::Builder> const& builder);
virtual ~MainWindow() = default;
void post_entry_data();
void lacalization();
void settings();
void flag_block_gui();
void add_CSS();
void get_builder();
void event();
void gui_mess_close();
bool focus_ntp(GdkEventFocus* event);
void event_entry_cbDhcp();
void get_calendar();
void calendar_show();
void enry_dhcp_mess();
void get_config();
void enter_zone();
void enter_zone_glob();
void set_ntp_toggle();
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();
void update_time_date();
void update_hour_minute();
void update_calendar();
void read_file();
void parse_text_date();
void hardware_clock();
void set_ntp_toggle_glob();
int check_root();
void gui_exit();
bool gui_exit_2(GdkEventAny* event);
void stop_ntp();
void wind_close_ntp();
void wrapper_update_time_date();
string zone_file_read(string zone);
void sort_zone(vector<string> *time_reg_map_local,vector<string> *time_reg_map);
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:
Glib::RefPtr<Gtk::Builder> builder;
Gtk::Button *btnUpdateDateTime;
Gtk::Button *btnChooseDate;
@ -137,6 +94,11 @@ class MainWindow : public Gtk::ApplicationWindow {
string str_zone="";
string str_zoneGlob;
int response_cmd;
template<typename Type>
struct Result{
Type response;
int error;
};
string array_region[14]={
"Africa",
"America",
@ -152,6 +114,52 @@ class MainWindow : public Gtk::ApplicationWindow {
"Indian",
"Mexico",
"US"};
public:
MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder);
MainWindow(Glib::RefPtr<Gtk::Builder> const& builder);
virtual ~MainWindow() = default;
void post_entry_data();
void lacalization();
void settings();
void flag_block_gui();
void add_CSS();
void get_builder();
void event();
void gui_mess_close();
bool focus_ntp(GdkEventFocus* event);
void event_entry_cbDhcp();
void get_calendar();
void calendar_show();
void enry_dhcp_mess();
void get_config();
void enter_zone();
void enter_zone_glob();
void set_ntp_toggle();
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();
void update_time_date();
void update_hour_minute();
void update_calendar();
void read_file();
void parse_text_date();
void hardware_clock();
void set_ntp_toggle_glob();
int check_root();
void gui_exit();
bool gui_exit_2(GdkEventAny* event);
void stop_ntp();
void wind_close_ntp();
void wrapper_update_time_date();
string zone_file_read(string zone);
void sort_zone(vector<string> *time_reg_map_local,vector<string> *time_reg_map);
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);
struct Result<string> wrapper_call(string cmd);
};
class SettingsPlug : public Gtk::Plug{

@ -115,6 +115,9 @@ msgstr "Синхронизировать аппаратное время"
msgid "Warning!"
msgstr "Внимание!"
msgid "ERROR"
msgstr "ОШИБКА"
msgid "America"
msgstr "Америка"

Loading…
Cancel
Save