diff --git a/source/ubl_settings_datetime.cc b/source/ubl_settings_datetime.cc index 88bbc94..3b3a562 100644 --- a/source/ubl_settings_datetime.cc +++ b/source/ubl_settings_datetime.cc @@ -124,6 +124,7 @@ void MainWindow::get_builder(){ builder->get_widget("txtNtpServer", _txtNtpServer); builder->get_widget("cldrDate", _cldrDate); builder->get_widget("mess_dchp", _mess_dchp); + builder->get_widget("lblMessage", _lblMessage); //this->add_CSS(); } void MainWindow::event(){ @@ -431,54 +432,65 @@ void MainWindow::append_zone_glob(){ void MainWindow::update_time_date(){ this->enter_zone(); bool flag = _cbxSynchronizeNtp->get_active(); + string cmd = ""; + if ((year!=0) && (month !=0) && (day !=0)){ + string str_month = ""; + string str_day = ""; + month+=2; + if (month <10){ + str_month = "0"+to_string(month); + } + else{ + str_month = to_string(month); + } + if (day <10){ + str_day = "0"+to_string(day); + } + else{ + str_day = to_string(day); + } + cmd = "date +%Y%m%d -s \"" + to_string(year)+ + str_month+str_day+"\""; + system(cmd.c_str()); + cmd = "hwclock --systohc"; + system(cmd.c_str()); + _txtDate->set_text(str_day+"." + str_month+"." + to_string(year)); + year=0; + month=0; + day=0; + } + else{ + string cmd = ""; + string data = _txtDate->get_text(); + if (data.length()==10){ + string str_day = data.substr(0,2); + string str_month = data.substr(3,2); + string str_year = data.substr(6,data.length()); + cmd = "date +%Y%m%d -s \"" + str_year+ + str_month+str_day+"\""; + string str_error_clock = this->call(cmd); + size_t index = str_error_clock.find("date: "); + if (index==std::string::npos){ + + } + } + else{ + _lblMessage->set_text("Не верный формат даты"); + _mess_dchp->show(); + } + } if (flag==false){ hour = _numTimeHrs->get_value_as_int(); minute = _numTimeMin->get_value_as_int(); time_t now = time(0); tm *ltm = localtime(&now); - string cmd = "date +%T -s \""+ + cmd = "date +%T -s \""+ to_string(hour) + ":" + to_string(minute) + ":" + to_string(ltm->tm_sec) +"\""; system(cmd.c_str()); - if ((year!=0) && (month !=0) && (day !=0)){ - string str_month = ""; - string str_day = ""; - month+=2; - if (month <10){ - str_month = "0"+to_string(month); - } - else{ - str_month = to_string(month); - } - if (day <10){ - str_day = "0"+to_string(day); - } - else{ - str_day = to_string(day); - } - cmd = "date +%Y%m%d -s \"" + to_string(year)+ - str_month+str_day+"\""; - system(cmd.c_str()); - cmd = "hwclock --systohc"; - system(cmd.c_str()); - _txtDate->set_text(str_day+"." + str_month+"." + to_string(year)); - } - else{ - string cmd = ""; - string data = _txtDate->get_text(); - if (data.length()==10){ - string str_day = data.substr(0,2); - string str_month = data.substr(3,2); - string str_year = data.substr(6,data.length()); - cmd = "date +%Y%m%d -s \"" + str_year+ - str_month+str_day+"\""; - system(cmd.c_str()); - } - cmd = "hwclock --systohc"; - system(cmd.c_str()); - } - } + cmd = "hwclock --systohc"; + system(cmd.c_str()); } void MainWindow::update_hour_minute(){ time_t now = time(0); diff --git a/source/ubl_settings_datetime.h b/source/ubl_settings_datetime.h index cfbe7aa..b277a72 100644 --- a/source/ubl_settings_datetime.h +++ b/source/ubl_settings_datetime.h @@ -104,6 +104,7 @@ private: Gtk::Window *_mess_dchp; Gtk::Popover *_popCalendar; Gtk::Calendar *_cldrDate; + Gtk::Label *_lblMessage; unsigned int year=0, month=0, day=0; int hour; int minute;