diff --git a/source/ubl-settings-datetime.cc b/source/ubl-settings-datetime.cc index c773f88..f51b484 100755 --- a/source/ubl-settings-datetime.cc +++ b/source/ubl-settings-datetime.cc @@ -79,7 +79,6 @@ void MainWindow::settings(){ this->event(); this->parse_text_date(); this->download_local_cfg(); - this->download_globl_cfg(); //orevrlayInfo->add_overlay(*boxInfoError); //imgInfo->set("/usr/share/ubl-settings-datetime/images/checked.svg"); @@ -319,11 +318,16 @@ void MainWindow::download_local_cfg(){ this->fill_in_reg_zone(cmd); this->update_hour_minute(); this->update_calendar(); + string cmd_get_dhcp = "/usr/bin/ubconfig --source system get network NTPSERVERS"; + string cmd_default_get_dhcp = "/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT"; + this->entry_dhcp_mess(cmd_get_dhcp, cmd_default_get_dhcp); info_warning_error(0); } void MainWindow::download_globl_cfg(){ - this->entry_dhcp_mess(); + string cmd_get_dhcp = "/usr/bin/ubconfig --target global get network NTPSERVERS"; + string cmd_default_get_dhcp = "/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT"; + this->entry_dhcp_mess(cmd_get_dhcp, cmd_default_get_dhcp); string cmd = "/usr/bin/ubconfig --default --source global get clock ZONE"; this->fill_in_reg_zone(cmd); info_warning_error(1); @@ -333,12 +337,22 @@ void MainWindow::save_local_cfg(){ string cmd = "ubconfig --target system set clock ZONE="; this->enter_zone(cmd); info_warning_error(2); + + string cmd_default = "/usr/bin/ubconfig --target system set network NTPSERVERS=default"; + string cmd_dhcp = "/usr/bin/ubconfig --target system set network NTPSERVERS=dhcp"; + string cmd_set_ntp = "/usr/bin/ubconfig --target system set network NTPSERVERS=\""; + string remove = "/usr/bin/ubconfig --target system remove network NTPSERVERS"; + this->save_Dhcp(cmd_default, cmd_dhcp, remove, cmd_set_ntp); } void MainWindow::save_global_cfg(){ string cmd = "/usr/bin/ubconfig --target global set clock ZONE="; this->enter_zone(cmd); - this->save_Dhcp(); + string cmd_default = "/usr/bin/ubconfig --target global set network NTPSERVERS=default"; + string cmd_dhcp = "/usr/bin/ubconfig --target global set network NTPSERVERS=dhcp"; + string cmd_set_ntp = "/usr/bin/ubconfig --target global set network NTPSERVERS=\""; + string remove = "/usr/bin/ubconfig --target global remove network NTPSERVERS"; + this->save_Dhcp(cmd_default, cmd_dhcp, remove, cmd_set_ntp); info_warning_error(3); } void MainWindow::save_global_local_cfg(){ @@ -347,7 +361,17 @@ void MainWindow::save_global_local_cfg(){ info_warning_error(4); cmd = "/usr/bin/ubconfig --target global set clock ZONE="; this->enter_zone(cmd); - this->save_Dhcp(); + string cmd_default = "/usr/bin/ubconfig --target global set network NTPSERVERS=default"; + string cmd_dhcp = "/usr/bin/ubconfig --target global set network NTPSERVERS=dhcp"; + string cmd_set_ntp = "/usr/bin/ubconfig --target global set network NTPSERVERS=\""; + string remove = "/usr/bin/ubconfig --target global remove network NTPSERVERS"; + this->save_Dhcp(cmd_default, cmd_dhcp, remove, cmd_set_ntp); + + cmd_default = "/usr/bin/ubconfig --target system set network NTPSERVERS=default"; + cmd_dhcp = "/usr/bin/ubconfig --target system set network NTPSERVERS=dhcp"; + cmd_set_ntp = "/usr/bin/ubconfig --target system set network NTPSERVERS=\""; + remove = "/usr/bin/ubconfig --target system remove network NTPSERVERS"; + this->save_Dhcp(cmd_default, cmd_dhcp, remove, cmd_set_ntp); } void MainWindow::info_warning_error(int mess){ @@ -429,7 +453,7 @@ void MainWindow::gui_mess_close(){ mess_dchp->hide(); } -bool MainWindow::focus_ntp(){ +bool MainWindow::focus_ntp(string &cmd_set_ntp){ if (txtNtpServer->get_text()=="" || txtNtpServer->get_text()==" "){ lblMessage->set_text(_("Enter DHCP!")); mess_dchp->show(); @@ -452,7 +476,8 @@ bool MainWindow::focus_ntp(){ } } if ((flag_error==false) && (flag_error_check_ntp==false)){ - cmd = "/usr/bin/ubconfig set network NTPSERVERS=\"" + str_ntp + "\""; + cmd = cmd_set_ntp + str_ntp + "\""; + //cmd = "/usr/bin/ubconfig set network NTPSERVERS=\"" + str_ntp + "\""; wrapper_system(cmd); } else{ @@ -603,80 +628,33 @@ void MainWindow::event_entry_cbDhcp(){ } } -void MainWindow::save_Dhcp(){ - int activ_index = cbDhcp->get_active_row_number(); +void MainWindow::save_Dhcp(string &cmd_default, string &cmd_dhcp, string &remove, string &cmd_set_ntp){ + int activ_index = cbDhcp->get_active_row_number(); string str_dhcp = cbDhcp->get_active_text(); - string cmd = ""; if (str_dhcp.length()==0){ } else if (activ_index==0){ - string cmd = "/usr/bin/ubconfig set network NTPSERVERS=default"; - wrapper_system(cmd); + //string cmd = "/usr/bin/ubconfig set network NTPSERVERS=default"; + wrapper_system(cmd_default); } else if (activ_index==1){ - string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp"; - wrapper_system(cmd); + //string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp"; + wrapper_system(cmd_dhcp); } else if (activ_index==2){ - this->focus_ntp(); + this->focus_ntp(cmd_set_ntp); + //this->focus_ntp("/usr/bin/ubconfig set network NTPSERVERS=\""); } else if (activ_index==3){ - string cmd = "/usr/bin/ubconfig remove network NTPSERVERS"; - wrapper_system(cmd); + //string cmd = "/usr/bin/ubconfig remove network NTPSERVERS"; + wrapper_system(remove); } } -string MainWindow::str_remove(std::string& source, const std::string to_remove){ - auto begin = source.find(to_remove); - if (begin!=std::string::npos){ - int len_to_remove = to_remove.length(); - source.erase(begin, begin+len_to_remove); - } - return source; -} - -void MainWindow::get_calendar(){ - string str_month = ""; - string str_day = ""; - cldrDate->get_date(year, month, day); - if (month <10){ - str_month = "0"+to_string(month+1); - } - else{ - str_month = to_string(month+1); - } - if (day <10){ - str_day = "0"+to_string(day); - } - else{ - str_day = to_string(day); - } - string date = str_day + '.' + str_month + '.' + to_string(year); - txtDate->set_text(date); - popCalendar->hide(); -} - -void MainWindow::calendar_show(){ - if (year==0){ - time_t now = time(0); - tm *ltm = localtime(&now); - unsigned int y=1900+ ltm->tm_year; - unsigned int m=ltm->tm_mon; - unsigned int d=ltm->tm_mday; - cldrDate->select_month(m,y); - cldrDate->select_day(d); - } - else{ - cldrDate->select_month(month,year); - cldrDate->select_day(day); - - } - popCalendar->show(); -} - -void MainWindow::entry_dhcp_mess(){ - string cmd = "/usr/bin/ubconfig get network NTPSERVERS"; +void MainWindow::entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhcp){ + //string cmd = "/usr/bin/ubconfig get network NTPSERVERS"; + string cmd = cmd_get_dhcp; struct Result obj_result = this->wrapper_call(cmd); if (obj_result.error==0){ string str_dhcp = obj_result.response; @@ -691,7 +669,8 @@ void MainWindow::entry_dhcp_mess(){ else if (str_dhcp=="default"){ btnUpdateDateTime->set_sensitive(false); cbDhcp->set_active(0); - string cmd = "/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT"; + //string cmd = "/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT"; + cmd = cmd_default_get_dhcp; struct Result obj_result = this->wrapper_call(cmd); txtNtpServer->set_sensitive(false); if (obj_result.error==0){ @@ -733,6 +712,53 @@ void MainWindow::entry_dhcp_mess(){ } } +string MainWindow::str_remove(std::string& source, const std::string to_remove){ + auto begin = source.find(to_remove); + if (begin!=std::string::npos){ + int len_to_remove = to_remove.length(); + source.erase(begin, begin+len_to_remove); + } + return source; +} + +void MainWindow::get_calendar(){ + string str_month = ""; + string str_day = ""; + cldrDate->get_date(year, month, day); + if (month <10){ + str_month = "0"+to_string(month+1); + } + else{ + str_month = to_string(month+1); + } + if (day <10){ + str_day = "0"+to_string(day); + } + else{ + str_day = to_string(day); + } + string date = str_day + '.' + str_month + '.' + to_string(year); + txtDate->set_text(date); + popCalendar->hide(); +} + +void MainWindow::calendar_show(){ + if (year==0){ + time_t now = time(0); + tm *ltm = localtime(&now); + unsigned int y=1900+ ltm->tm_year; + unsigned int m=ltm->tm_mon; + unsigned int d=ltm->tm_mday; + cldrDate->select_month(m,y); + cldrDate->select_day(d); + } + else{ + cldrDate->select_month(month,year); + cldrDate->select_day(day); + + } + popCalendar->show(); +} void MainWindow::fill_in_reg_zone(string &cmd){ struct Result obj_result_1 = this->wrapper_call(cmd); diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index 1831d81..ee4ed48 100755 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -136,7 +136,7 @@ class MainWindow : public Gtk::ApplicationWindow { void download_globl_cfg(); void save_local_cfg(); void save_global_cfg(); - void save_Dhcp(); + void save_Dhcp(string &cmd_default, string &cmd_dhcp, string &remove, string &cmd_set_ntp); void download_local_cfg(); void post_entry_data(); void lacalization(); @@ -146,11 +146,11 @@ class MainWindow : public Gtk::ApplicationWindow { void get_builder(); void event(); void gui_mess_close(); - bool focus_ntp(); + bool focus_ntp(string &cmd_set_ntp); void event_entry_cbDhcp(); void get_calendar(); void calendar_show(); - void entry_dhcp_mess(); + void entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhcp); void get_config(); void enter_zone(string &cmd); void set_ntp_toggle();