diff --git a/source/ubl-settings-datetime.cc b/source/ubl-settings-datetime.cc index f138c94..04b3708 100644 --- a/source/ubl-settings-datetime.cc +++ b/source/ubl-settings-datetime.cc @@ -332,6 +332,14 @@ void MainWindow::event() { btnSaveGlob->signal_activate().connect([&]() {save_global_cfg();}); cbZone->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::event_zone)); cbHw->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::event_log_hw)); + txtNtpServer->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_ntp)); +} + +bool MainWindow::focus_ntp(GdkEventFocus* event) { + if (event!=NULL){ + } + this->focus_ntp_text(); + return true; } void MainWindow::event_log_hw() { @@ -741,7 +749,7 @@ void MainWindow::gui_mess_close() { windowMessDchp->hide(); } -bool MainWindow::focus_ntp(string &cmd_set_ntp) { +bool MainWindow::focus_ntp_text() { if (txtNtpServer->get_text() == "" || txtNtpServer->get_text() == " ") { lblMessage->set_text(_("Enter DHCP!")); windowMessDchp->show(); @@ -764,9 +772,8 @@ bool MainWindow::focus_ntp(string &cmd_set_ntp) { } } if ((flag_error == false) && (flag_error_check_ntp == false)) { - cmd = cmd_set_ntp + str_ntp + "\""; - this->write_config(str_ntp, "dhcp"); - wrapper_system(cmd, "&"); + + return true; } else { if (flag_error == true) { @@ -777,6 +784,7 @@ bool MainWindow::focus_ntp(string &cmd_set_ntp) { lblMessage->set_text(_("Error in the ntp name")); windowMessDchp->show(); } + return false; } } return true; @@ -919,8 +927,11 @@ void MainWindow::event_entry_cbDhcp() { cmd = "ubconfig --default --source global get network NTPSERVERS"; } string response = this->get_ubconfig_value(cmd); - if (response != "dhcp" && response != "default"){ + if (response != "dhcp" && response != "default") { txtNtpServer->set_text(response); + txtNtpServer->grab_focus(); + txtNtpServer->unset_cursor(); + cout << 222 << endl; } this->write_config(response, "dhcp"); txtNtpServer->set_sensitive(true); @@ -952,7 +963,13 @@ void MainWindow::save_Dhcp(string &cmd_default, string &cmd_dhcp, string &remove } else if (activ_index == 2) { - this->focus_ntp(cmd_set_ntp); + if (this->focus_ntp_text()){ + string str_ntp = txtNtpServer->get_text(); + string cmd = cmd_set_ntp + str_ntp + "\""; + this->write_config(str_ntp, "dhcp"); + wrapper_system(cmd, "&"); + } + } else if (activ_index== 3) { int start_error = error_info; diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index 27ea2dd..0742f9e 100644 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -163,6 +163,7 @@ class MainWindow : public Gtk::ApplicationWindow { void load_globl_cfg(); void save_local_cfg(); void event_zone(); + bool focus_ntp(GdkEventFocus* event); bool check_config(string key, int key_save); void event_log_hw(); void write_config(string data, string key); @@ -178,7 +179,7 @@ class MainWindow : public Gtk::ApplicationWindow { void get_builder(); void event(); void gui_mess_close(); - bool focus_ntp(string &cmd_set_ntp); + bool focus_ntp_text() ; void event_entry_cbDhcp(); void get_calendar(); void calendar_show();