diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 319a9c3..87ca686 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -8,8 +8,8 @@ include_directories(${GTK_INCLUDE_DIRS}) link_directories(${GTK_LIBRARY_DIRS}) add_definitions(${GTK_CFLAGS_OTHER}) -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -std=c++2a") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always") +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -std=c++2a -g") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -g") set(SOURCE_FILES main.cc diff --git a/source/ubl-settings-datetime.cc b/source/ubl-settings-datetime.cc index 9ea6713..f623641 100644 --- a/source/ubl-settings-datetime.cc +++ b/source/ubl-settings-datetime.cc @@ -65,115 +65,120 @@ void MainWindow::settings(){ year=0, month=0, day=0; this->get_builder(); this->event(); + this->lacalization(); if (this->check_root()==0){ - this->lacalization(); - _numTimeHrs->set_range(0,23); - _numTimeMin->set_range(0,59); - _numTimeHrs->set_increments(1.0,1.0); - _numTimeMin->set_increments(1.0,1.0); + numTimeHrs->set_range(0,23); + numTimeMin->set_range(0,59); + numTimeHrs->set_increments(1.0,1.0); + numTimeMin->set_increments(1.0,1.0); this->get_config(); this->flag_block_gui(); this->parse_text_date(); } else{ - _numTimeHrs->set_sensitive(false); - _numTimeMin->set_sensitive(false); - _lblTime->set_sensitive(false); - _lblData->set_sensitive(false); - _txtDate->set_sensitive(false); - _btnChooseDate->set_sensitive(false); - _btnUpdateDateTime->set_sensitive(false); - _btnHardwareTime->set_sensitive(false); - _cbRegion->set_sensitive(false); - _cbZone->set_sensitive(false); - _lblReg->set_sensitive(false); - _lblZone->set_sensitive(false); - _lblTimeZone->set_sensitive(false); - _lblDateTimeSettingGlob->set_sensitive(false); - _cbxSynchronizeNtpGlob->set_sensitive(false); - _lblSynchronizebChkGLob->set_sensitive(false); - _cbDhcp->set_sensitive(false); - _txtNtpServer->set_sensitive(false); - _lblTimeZoneGlob->set_sensitive(false); - _lblRegGlob->set_sensitive(false); - _lblZone1Glob->set_sensitive(false); - _lblDateTimeSetting->set_sensitive(false); + numTimeHrs->set_sensitive(false); + numTimeMin->set_sensitive(false); + lblTime->set_sensitive(false); + lblData->set_sensitive(false); + txtDate->set_sensitive(false); + btnChooseDate->set_sensitive(false); + btnUpdateDateTime->set_sensitive(false); + btnHardwareTime->set_sensitive(false); + cbRegion->set_sensitive(false); + cbZone->set_sensitive(false); + lblReg->set_sensitive(false); + lblZone->set_sensitive(false); + lblTimeZone->set_sensitive(false); + lblDateTimeSettingGlob->set_sensitive(false); + cbxSynchronizeNtpGlob->set_sensitive(false); + lblSynchronizebChkGLob->set_sensitive(false); + cbDhcp->set_sensitive(false); + txtNtpServer->set_sensitive(false); + lblTimeZoneGlob->set_sensitive(false); + lblRegGlob->set_sensitive(false); + lblZone1Glob->set_sensitive(false); + lblDateTimeSetting->set_sensitive(false); } } int MainWindow::check_root(){ if (geteuid()!=0){ - _lblMessageSudo->set_text(gettext("The program must be run with \nsuperuser privileges!")); - _mess_sudo->show(); + lblMessageSudo->set_text(gettext("The program must be run with \nsuperuser privileges!")); + mess_sudo->show(); return 1; } return 0; } void MainWindow::lacalization(){ - - _txtDate->set_tooltip_text(gettext("Date of\nFormat: DD.MM.YYYY")); - _lblSynchronizebChkGLob->set_text(gettext("Synchronize via NTP")); - _cbDhcp->append(gettext("DHCP")); - _cbDhcp->append(gettext("Manually")); - _lblDateTimeSetting->set_text(gettext("Local Configuration")); - _lblHead->set_text(gettext("Settings the date and time")); - _lblTime->set_text(gettext("Time")); - _lblData->set_text(gettext("Date")); - _lblTimeZone->set_text(gettext("Time zone")); - _lblReg->set_text(gettext("Region")); - _lblZone->set_text(gettext("Zone")); - _lblRegGlob->set_text(gettext("Region")); - _lblZone1Glob->set_text(gettext("Zone")); - _lblTimeZoneGlob->set_text(gettext("Time zone")); - _lblSynchronizeBtn->set_text(gettext("Sync by")); - _lblDateTimeSettingGlob->set_text(gettext("Global customization")); + txtDate->set_tooltip_text(gettext("Date of\nFormat: DD.MM.YYYY")); + lblSynchronizebChkGLob->set_text(gettext("Synchronize via NTP")); + cbDhcp->append(gettext("By default")); + cbDhcp->append(gettext("DHCP")); + cbDhcp->append(gettext("Manually")); + lblDateTimeSetting->set_text(gettext("Local Configuration")); + lblHead->set_text(gettext("Settings the date and time")); + lblTime->set_text(gettext("Time")); + lblData->set_text(gettext("Date")); + lblTimeZone->set_text(gettext("Time zone")); + lblReg->set_text(gettext("Region")); + lblZone->set_text(gettext("Zone")); + lblRegGlob->set_text(gettext("Region")); + lblZone1Glob->set_text(gettext("Zone")); + lblTimeZoneGlob->set_text(gettext("Time zone")); + lblSynchronizeBtn->set_text(gettext("Sync by")); + lblDateTimeSettingGlob->set_text(gettext("Global customization")); this->set_title(gettext("ubl-settings-datetime")); - _mess_dchp->set_title(gettext("Warning!")); - _lblTimeBios->set_text(gettext("Synchronize hardware time")); + windowsNnpClose->set_title(gettext("Warning!")); + mess_sudo->set_title(gettext("Warning!")); + mess_dchp->set_title(gettext("Warning!")); + lblTimeBios->set_text(gettext("Synchronize hardware time")); + lblBanerStopNtp->set_text(gettext("Active service detected\nAutomatic time and date synchronization service detected")); + lblNtpStop->set_text(gettext("Stop the synchronization service")); + lblNtpClose->set_text(gettext("Close")); //_lblSynchronizebChk->set_text(gettext("Synchronize via NTP")); } void MainWindow::flag_block_gui(){ if (flag_datetime==true){ - //_numTimeHrs->set_sensitive(false); - //_numTimeMin->set_sensitive(false); - //_txtDate->set_sensitive(false); - _btnUpdateDateTime->set_sensitive(false); - _numTimeHrs->set_sensitive(false); - _numTimeMin->set_sensitive(false); - _btnChooseDate->set_sensitive(false); - _txtDate->set_sensitive(false); - _lblTimeBios->set_sensitive(false); - _btnHardwareTime->set_sensitive(false); - _lblTime->set_sensitive(false); - _lblData->set_sensitive(false); - //_cbxSynchronizeNtpGlob->set_sensitive(false); + //numTimeHrs->set_sensitive(false); + //numTimeMin->set_sensitive(false); + //txtDate->set_sensitive(false); + btnUpdateDateTime->set_sensitive(false); + numTimeHrs->set_sensitive(false); + numTimeMin->set_sensitive(false); + btnChooseDate->set_sensitive(false); + txtDate->set_sensitive(false); + lblTimeBios->set_sensitive(false); + btnHardwareTime->set_sensitive(false); + lblTime->set_sensitive(false); + lblData->set_sensitive(false); + //cbxSynchronizeNtpGlob->set_sensitive(false); } if (flag_timezone==true){ - _cbRegion->set_sensitive(false); - _cbZone->set_sensitive(false); - _cbRegionGlob->set_sensitive(false); - _cbZoneGlob->set_sensitive(false); - //_btnChooseDate->set_sensitive(false); - _cbDhcp->set_sensitive(false); + cbRegion->set_sensitive(false); + cbZone->set_sensitive(false); + cbRegionGlob->set_sensitive(false); + cbZoneGlob->set_sensitive(false); + //btnChooseDate->set_sensitive(false); + cbDhcp->set_sensitive(false); } if (flag_ntp==true){ - _cbxSynchronizeNtpGlob->set_sensitive(false); - _cbDhcp->set_sensitive(false); - _txtNtpServer->set_sensitive(false); + cbxSynchronizeNtpGlob->set_sensitive(false); + cbDhcp->set_sensitive(false); + txtNtpServer->set_sensitive(false); } if (flag_update==true){ - _lblDateTimeSettingGlob->set_sensitive(false); - //_lblSynchronizebChkGLob->set_sensitive(false); - _cbxSynchronizeNtpGlob->set_sensitive(false); - _lblTimeZoneGlob->set_sensitive(false); - _lblRegGlob->set_sensitive(false); - _cbRegionGlob->set_sensitive(false); - _lblZone1Glob->set_sensitive(false); - _cbZoneGlob->set_sensitive(false); - _txtNtpServer->set_sensitive(false); - _cbDhcp->set_sensitive(false); + lblDateTimeSettingGlob->set_sensitive(false); + //lblSynchronizebChkGLob->set_sensitive(false); + cbxSynchronizeNtpGlob->set_sensitive(false); + lblTimeZoneGlob->set_sensitive(false); + lblRegGlob->set_sensitive(false); + cbRegionGlob->set_sensitive(false); + lblZone1Glob->set_sensitive(false); + cbZoneGlob->set_sensitive(false); + txtNtpServer->set_sensitive(false); + cbDhcp->set_sensitive(false); } } @@ -183,54 +188,59 @@ void MainWindow::add_CSS(){ Glib::RefPtr styleContext = Gtk::StyleContext::create(); Glib::RefPtr screen = Gdk::Screen::get_default();//get default screen styleContext->add_provider_for_screen(screen, cssProvider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);//add provider for screen in all application - Glib::RefPtr context = _boxColor->get_style_context(); - Glib::RefPtr context_lbl_head = _lblHead->get_style_context(); + Glib::RefPtr context = boxColor->get_style_context(); + Glib::RefPtr context_lbl_head = lblHead->get_style_context(); context->add_class("cssboxColor1"); context_lbl_head->add_class("textHead"); } void MainWindow::get_builder(){ builder->set_translation_domain(path_app); - builder->get_widget("boxColor", _boxColor); - builder->get_widget("btnUpdateDateTime", _btnUpdateDateTime); - builder->get_widget("btnChooseDate", _btnChooseDate); - builder->get_widget("btnMessClose", _btnMessClose); - builder->get_widget("cbxSynchronizeNtpGlob", _cbxSynchronizeNtpGlob); - builder->get_widget("popCalendar", _popCalendar); - builder->get_widget("numTimeHrs", _numTimeHrs); - builder->get_widget("numTimeMin", _numTimeMin); - builder->get_widget("cbDhcp", _cbDhcp); - builder->get_widget("txtDate", _txtDate); - builder->get_widget("cbRegion", _cbRegion); - builder->get_widget("cbRegionGlob", _cbRegionGlob); - builder->get_widget("cbZone", _cbZone); - builder->get_widget("cbZoneGlob", _cbZoneGlob); - builder->get_widget("txtNtpServer", _txtNtpServer); - builder->get_widget("cldrDate", _cldrDate); - builder->get_widget("mess_dchp", _mess_dchp); - builder->get_widget("lblMessage", _lblMessage); - builder->get_widget("lblDateTimeSetting",_lblDateTimeSetting); - builder->get_widget("lblHead",_lblHead); - builder->get_widget("lblTime",_lblTime); - builder->get_widget("lblData",_lblData); - builder->get_widget("lblTimeZone",_lblTimeZone); - builder->get_widget("lblReg",_lblReg); - builder->get_widget("lblZone",_lblZone); - builder->get_widget("lblRegGlob",_lblRegGlob); - builder->get_widget("lblZone1Glob",_lblZone1Glob); - builder->get_widget("lblTimeZoneGlob",_lblTimeZoneGlob); + builder->get_widget("boxColor", boxColor); + builder->get_widget("btnUpdateDateTime", btnUpdateDateTime); + builder->get_widget("btnChooseDate", btnChooseDate); + builder->get_widget("btnMessClose", btnMessClose); + builder->get_widget("cbxSynchronizeNtpGlob", cbxSynchronizeNtpGlob); + builder->get_widget("popCalendar", popCalendar); + builder->get_widget("numTimeHrs", numTimeHrs); + builder->get_widget("numTimeMin", numTimeMin); + builder->get_widget("cbDhcp", cbDhcp); + builder->get_widget("txtDate", txtDate); + builder->get_widget("cbRegion", cbRegion); + builder->get_widget("cbRegionGlob", cbRegionGlob); + builder->get_widget("cbZone", cbZone); + builder->get_widget("cbZoneGlob", cbZoneGlob); + builder->get_widget("txtNtpServer", txtNtpServer); + builder->get_widget("cldrDate", cldrDate); + builder->get_widget("mess_dchp", mess_dchp); + builder->get_widget("lblMessage", lblMessage); + builder->get_widget("lblDateTimeSetting",lblDateTimeSetting); + builder->get_widget("lblHead",lblHead); + builder->get_widget("lblTime",lblTime); + builder->get_widget("lblData",lblData); + builder->get_widget("lblTimeZone",lblTimeZone); + builder->get_widget("lblReg",lblReg); + builder->get_widget("lblZone",lblZone); + builder->get_widget("lblRegGlob",lblRegGlob); + builder->get_widget("lblZone1Glob",lblZone1Glob); + builder->get_widget("lblTimeZoneGlob",lblTimeZoneGlob); //builder->get_widget("lblSynchronizebChk",_lblSynchronizebChk); - builder->get_widget("lblSynchronizebChkGLob",_lblSynchronizebChkGLob); - builder->get_widget("lblSynchronizeBtn",_lblSynchronizeBtn); - builder->get_widget("lblDateTimeSettingGlob",_lblDateTimeSettingGlob); - builder->get_widget("lblTimeBios",_lblTimeBios); - builder->get_widget("btnHardwareTime",_btnHardwareTime); - builder->get_widget("mess_sudo",_mess_sudo); - builder->get_widget("lblMessageSudo",_lblMessageSudo); - builder->get_widget("btnMessCloseSudo",_btnMessCloseSudo); - + builder->get_widget("lblSynchronizebChkGLob",lblSynchronizebChkGLob); + builder->get_widget("lblSynchronizeBtn",lblSynchronizeBtn); + builder->get_widget("lblDateTimeSettingGlob",lblDateTimeSettingGlob); + builder->get_widget("lblTimeBios",lblTimeBios); + builder->get_widget("btnHardwareTime",btnHardwareTime); + builder->get_widget("mess_sudo",mess_sudo); + builder->get_widget("lblMessageSudo",lblMessageSudo); + builder->get_widget("btnMessCloseSudo",btnMessCloseSudo); + builder->get_widget("windowsNnpClose",windowsNnpClose); + builder->get_widget("btnNtpStop",btnNtpStop); + builder->get_widget("btnNtpWinClose",btnNtpWinClose); + builder->get_widget("lblNtpStop",lblNtpStop); + builder->get_widget("lblNtpClose",lblNtpClose); + builder->get_widget("lblBanerStopNtp",lblBanerStopNtp); - //builder->get_widget("cbxSynchronizeNtp",_cbxSynchronizeNtp); + //builder->get_widget("cbxSynchronizeNtp",cbxSynchronizeNtp); this->add_CSS(); } @@ -245,49 +255,41 @@ bool MainWindow::gui_exit_2(GdkEventAny* event){ } void MainWindow::event(){ - //_cbxSynchronizeNtpGlob->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_ntp_toggle)); - _btnHardwareTime->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::hardware_clock)); - _btnMessClose->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::gui_mess_close)); - _btnMessCloseSudo->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::gui_exit)); - //_cldrDate->signal_day_selected().connect(sigc::mem_fun(*this, &MainWindow::get_calendar)); - _cbxSynchronizeNtpGlob->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_ntp_toggle_glob)); - _btnUpdateDateTime->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::update_time_date)); - _btnChooseDate->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::calendar_show)); - _cbDhcp->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::event_entry_cbDhcp)); - _cbRegion->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone)); - _cbRegionGlob->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone_glob)); - _cbZone->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::enter_zone)); - _cbZoneGlob->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::enter_zone_glob)); - _txtNtpServer->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_ntp)); - _cldrDate->signal_day_selected_double_click().connect(sigc::mem_fun(*this, &MainWindow::get_calendar)); - _mess_sudo->signal_delete_event().connect(sigc::mem_fun(*this, &MainWindow::gui_exit_2)); -} - -void MainWindow::set_ntp_toggle(){ - bool flag = _cbxSynchronizeNtpGlob->get_active(); - if (flag_ntp==true || flag_datetime==true){ - } - else { - _numTimeHrs->set_sensitive(!flag); - _numTimeMin->set_sensitive(!flag); - _btnChooseDate->set_sensitive(!flag); - _txtDate->set_sensitive(!flag); - _lblTimeBios->set_sensitive(!flag); - _btnUpdateDateTime->set_sensitive(!flag); - _lblTime->set_sensitive(!flag); - _lblData->set_sensitive(!flag); - } - string cmd = ""; - if (flag==false){ - cmd="systemctl --now disable systemd-timesyncd.service ntpd.service"; - system(cmd.c_str()); - } - else { - cmd = "systemctl --now enable systemd-timesyncd.service"; - system(cmd.c_str()); - } -} + //cbxSynchronizeNtpGlob->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_ntp_toggle)); + btnHardwareTime->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::hardware_clock)); + btnMessClose->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::gui_mess_close)); + btnMessCloseSudo->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::gui_exit)); + //cldrDate->signal_day_selected().connect(sigc::mem_fun(*this, &MainWindow::get_calendar)); + cbxSynchronizeNtpGlob->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_ntp_toggle_glob)); + btnUpdateDateTime->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::wrapper_update_time_date)); + btnChooseDate->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::calendar_show)); + cbDhcp->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::event_entry_cbDhcp)); + cbRegion->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone)); + cbRegionGlob->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone_glob)); + cbZone->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::enter_zone)); + cbZoneGlob->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::enter_zone_glob)); + txtNtpServer->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_ntp)); + cldrDate->signal_day_selected_double_click().connect(sigc::mem_fun(*this, &MainWindow::get_calendar)); + mess_sudo->signal_delete_event().connect(sigc::mem_fun(*this, &MainWindow::gui_exit_2)); + btnNtpWinClose->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::wind_close_ntp)); + btnNtpStop->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::stop_ntp)); +} +void MainWindow::wind_close_ntp(){ + windowsNnpClose->hide(); +} + +void MainWindow::stop_ntp(){ + windowsNnpClose->hide(); + // string cmd = "systemd-timesyncd [[ systemctl --quiet is-active systemd-timesyncd &>/dev/null ]] && systemctl stop systemd-timesyncd"; + string cmd = "sudo systemctl stop systemd-timesyncd; " ; + cmd += "sudo systemctl stop ntp.service; sudo systemctl stop ntpdate.service; "; + cmd += "sudo systemctl stop chronyd; sudo service ntpd stop; sudo systemctl stop ptp4l; "; + cmd += "sudo systemctl stop openntpd.service; sudo timedatectl set-ntp false"; + cmd += "sudo systemctl stop phc2sys"; + system(cmd.c_str()); + this->update_time_date(); +} void MainWindow::hardware_clock(){ string cmd = "hwclock --systohc"; @@ -295,18 +297,18 @@ void MainWindow::hardware_clock(){ } void MainWindow::gui_mess_close(){ - _mess_dchp->hide(); + mess_dchp->hide(); } bool MainWindow::focus_ntp(GdkEventFocus* event){ if (event!=NULL){} - if (_txtNtpServer->get_text()=="" || _txtNtpServer->get_text()==" "){ - _lblMessage->set_text(gettext("Enter DHCP !")); - _mess_dchp->show(); + if (txtNtpServer->get_text()=="" || txtNtpServer->get_text()==" "){ + lblMessage->set_text(gettext("Enter DHCP!")); + mess_dchp->show(); } else{ string cmd = ""; - cmd = "/usr/bin/ubconfig set network NTPSERVERS=" + _txtNtpServer->get_text(); + cmd = "/usr/bin/ubconfig set network NTPSERVERS=" + txtNtpServer->get_text(); this->call(cmd.c_str()); } @@ -314,39 +316,62 @@ bool MainWindow::focus_ntp(GdkEventFocus* event){ } void MainWindow::event_entry_cbDhcp(){ - Glib::ustring str_dhcp = _cbDhcp->get_active_text(); + Glib::ustring str_dhcp = cbDhcp->get_active_text(); + int activ_index = cbDhcp->get_active_row_number(); + cout << activ_index << endl; if (str_dhcp.length()!=0){ - if (str_dhcp=="DHCP"){ + if (activ_index==0){ + string cmd = "/usr/bin/ubconfig set network NTPSERVERS=default"; + 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); + } + else if (activ_index==1){ string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp"; system(cmd.c_str()); - _txtNtpServer->set_sensitive(false); - _cbDhcp->set_active(0); - _txtNtpServer->set_text(""); + txtNtpServer->set_sensitive(false); + cbDhcp->set_active(activ_index); + txtNtpServer->set_text(""); } - else{ + else if (activ_index==2){ + txtNtpServer->set_sensitive(true); + 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!="") && (str_dhcp!="(null)") ){ + if ((str_dhcp!="") && (str_dhcp!="(null)") && (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); + txtNtpServer->set_text(str_dhcp); } - _txtNtpServer->set_sensitive(true); - _cbDhcp->set_active(1); + cbDhcp->set_active(activ_index); } } } else{ string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp"; system(cmd.c_str()); - _cbDhcp->set_active(0); + cbDhcp->set_active(0); } } + +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); + cldrDate->get_date(year, month, day); if (month <10){ str_month = "0"+to_string(month+1); } @@ -360,8 +385,8 @@ void MainWindow::get_calendar(){ str_day = to_string(day); } string date = str_day + '.' + str_month + '.' + to_string(year); - _txtDate->set_text(date); - _popCalendar->hide(); + txtDate->set_text(date); + popCalendar->hide(); } void MainWindow::calendar_show(){ @@ -371,47 +396,54 @@ void MainWindow::calendar_show(){ 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); + cldrDate->select_month(m,y); + cldrDate->select_day(d); } else{ - _cldrDate->select_month(month,year); - _cldrDate->select_day(day); + cldrDate->select_month(month,year); + cldrDate->select_day(day); } - _popCalendar->show(); + popCalendar->show(); } void MainWindow::enry_dhcp_mess(){ string str_dhcp = this->call("/usr/bin/ubconfig get network NTPSERVERS"); if ((str_dhcp!="") && (str_dhcp!="(null)")){ - _cbxSynchronizeNtpGlob->set_active(1); + this->set_ntp_toggle_glob(); + cbxSynchronizeNtpGlob->set_active(1); 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(0); - _txtNtpServer->set_sensitive(false); + cbDhcp->set_active(1); + txtNtpServer->set_text(""); + txtNtpServer->set_sensitive(false); + } + else if (str_dhcp=="default"){ + cbDhcp->set_active(0); + txtNtpServer->set_text(str_dhcp); + txtNtpServer->set_sensitive(false); } else{ if (str_dhcp==""){ - _lblMessage->set_text(gettext("Enter DHCP !")); - _mess_dchp->show(); + lblMessage->set_text(gettext("Enter DHCP!")); + mess_dchp->show(); } else if (str_dhcp=="(null)"){ - _cbDhcp->set_active(0); - _txtNtpServer->set_text(""); + cbDhcp->set_active(0); + txtNtpServer->set_text(""); } else{ - _cbDhcp->set_active(1); - _txtNtpServer->set_text(str_dhcp); + cbDhcp->set_active(2); + txtNtpServer->set_text(str_dhcp); + txtNtpServer->set_sensitive(true); } } - this->set_ntp_toggle_glob(); } else{ - _cbxSynchronizeNtpGlob->set_active(0); - _cbDhcp->set_sensitive(0); - _txtNtpServer->set_sensitive(0); + cbxSynchronizeNtpGlob->set_active(0); + cbDhcp->set_sensitive(0); + txtNtpServer->set_sensitive(0); } } @@ -420,23 +452,8 @@ void MainWindow::get_config(){ this->update_hour_minute(); this->update_calendar(); this->enry_dhcp_mess(); - string str_ntp = this->call("systemctl status ntpd.service systemd-timesyncd.service | grep \"Active: active\""); - if (str_ntp.length()<50) { - _cbxSynchronizeNtpGlob->set_active(false); - _numTimeHrs->set_sensitive(true); - _numTimeMin->set_sensitive(true); - _btnChooseDate->set_sensitive(true); - _txtDate->set_sensitive(true); - _lblTimeBios->set_sensitive(true); - } - else{ - _cbxSynchronizeNtpGlob->set_active(true); - _numTimeHrs->set_sensitive(false); - _numTimeMin->set_sensitive(false); - _btnChooseDate->set_sensitive(false); - _txtDate->set_sensitive(false); - _lblTimeBios->set_sensitive(false); - } + + string read_reg_zon_cfg = this->call("/usr/bin/ubconfig 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()); @@ -453,8 +470,8 @@ void MainWindow::get_config(){ } void MainWindow::enter_zone(){ - Glib::ustring zone_text = _cbZone->get_active_text(); - Glib::ustring reg_text = _cbRegion->get_active_text(); + Glib::ustring zone_text = cbZone->get_active_text(); + Glib::ustring reg_text = cbRegion->get_active_text(); if(!(zone_text.empty()) && !(reg_text.empty())){ str_zone=zone_text.substr(zone_text.find(") ")+2,zone_text.length()); str_region=reg_text; @@ -470,7 +487,7 @@ void MainWindow::enter_zone(){ } void MainWindow::parse_text_date(){ - string data = _txtDate->get_text(); + string data = txtDate->get_text(); if (data.length()==10){ string day = data.substr(0,2); string month1 = data.substr(3,2); @@ -479,8 +496,8 @@ void MainWindow::parse_text_date(){ } void MainWindow::enter_zone_glob(){ - Glib::ustring zone_text = _cbZoneGlob->get_active_text(); - Glib::ustring reg_text = _cbRegionGlob->get_active_text(); + Glib::ustring zone_text = cbZoneGlob->get_active_text(); + Glib::ustring reg_text = cbRegionGlob->get_active_text(); if(!(zone_text.empty()) && !(reg_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; @@ -493,16 +510,15 @@ void MainWindow::enter_zone_glob(){ } void MainWindow::set_ntp_toggle_glob(){ - this->set_ntp_toggle(); - bool flag = _cbxSynchronizeNtpGlob->get_active(); + bool flag = cbxSynchronizeNtpGlob->get_active(); if (flag==false){ system("/usr/bin/ubconfig remove network NTPSERVERS"); - _cbDhcp->set_sensitive(false); - _txtNtpServer->set_sensitive(false); + cbDhcp->set_sensitive(false); + txtNtpServer->set_sensitive(false); } else{ - _cbDhcp->set_sensitive(true); - _txtNtpServer->set_sensitive(true); + cbDhcp->set_sensitive(true); + txtNtpServer->set_sensitive(true); } } @@ -510,23 +526,22 @@ void MainWindow::set_ntp_toggle_glob(){ void MainWindow::append_region_zone(string region, string zone){ int index = 0; for ( const auto &text : time_reg_map ) { - _cbRegion->append(text.first); - _cbRegionGlob->append(text.first); + cbRegion->append(text.first); + cbRegionGlob->append(text.first); if (text.first == region){ - _cbRegionGlob->set_active(index); - _cbRegion->set_active(index); + cbRegionGlob->set_active(index); + cbRegion->set_active(index); } index+=1; } index = 0; - cout << zone; for (const auto &_str_zone : time_reg_map.at(region)){ - _cbZone->append(_str_zone); - _cbZoneGlob->append(_str_zone); + cbZone->append(_str_zone); + cbZoneGlob->append(_str_zone); if (_str_zone!=""){ if (_str_zone == zone){ - _cbZone->set_active(index); - _cbZoneGlob->set_active(index); + cbZone->set_active(index); + cbZoneGlob->set_active(index); } } index+=1; @@ -536,49 +551,58 @@ void MainWindow::append_region_zone(string region, string zone){ string MainWindow::call(string cmd){ FILE *fp; int status; - char path[PATH_MAX]; + char path[PATH_MAX]={0}; fp = popen(cmd.c_str(), "r"); if (fp == NULL){ exit(1); } while (fgets(path, PATH_MAX, fp) != NULL){ - printf("%s", path); + //printf("%s", path); break; } status = pclose(fp); if (status == -1) { exit(1); } - else { - } + return path; } void MainWindow::append_zone(){ - Glib::ustring text = _cbRegion->get_active_text(); - _cbZone->remove_all(); + Glib::ustring text = cbRegion->get_active_text(); + cbZone->remove_all(); if(!(text.empty())){ str_region = text; for (const auto &_str_zone : time_reg_map.at(str_region)){ - _cbZone->append(_str_zone); + cbZone->append(_str_zone); } } } void MainWindow::append_zone_glob(){ - Glib::ustring text = _cbRegionGlob->get_active_text(); - _cbZoneGlob->remove_all(); + Glib::ustring text = cbRegionGlob->get_active_text(); + cbZoneGlob->remove_all(); if(!(text.empty())){ str_region_glob = text; for (const auto &_str_zone : time_reg_map.at(str_region_glob)){ - _cbZoneGlob->append(_str_zone); + cbZoneGlob->append(_str_zone); } } } +void MainWindow::wrapper_update_time_date(){ + string cmd = "pidof systemd-timesyncd ntpd chronyd"; + string response = this->call(cmd); + if (response.length()==0){ + this->update_time_date(); + } + else{ + windowsNnpClose->show(); + } + +} void MainWindow::update_time_date(){ //this->enter_zone(); - bool flag = _cbxSynchronizeNtpGlob->get_active(); string cmd = ""; if ((year!=0) && (month !=0) && (day !=0)){ string str_month = ""; @@ -598,13 +622,13 @@ void MainWindow::update_time_date(){ } string str_data = ""; str_data = str_day+"." + str_month+"." + to_string(year); - string str_data_entry = _txtDate->get_text(); + string str_data_entry = txtDate->get_text(); if (str_data==str_data_entry){ cmd = "date +%Y%m%d -s \"" + to_string(year)+ str_month+str_day+"\""; system(cmd.c_str()); - _txtDate->set_text(str_data); + txtDate->set_text(str_data); year=0; month=0; day=0; @@ -616,21 +640,19 @@ void MainWindow::update_time_date(){ else{ this->post_entry_data(); } - if (flag==false){ - hour = _numTimeHrs->get_value_as_int(); - minute = _numTimeMin->get_value_as_int(); - time_t now = time(0); - tm *ltm = localtime(&now); - cmd = "date +%T -s \""+ - to_string(hour) + ":" + to_string(minute) - + ":" + to_string(ltm->tm_sec) +"\""; - system(cmd.c_str()); - } + hour = numTimeHrs->get_value_as_int(); + minute = numTimeMin->get_value_as_int(); + time_t now = time(0); + tm *ltm = localtime(&now); + cmd = "date +%T -s \""+ + to_string(hour) + ":" + to_string(minute) + + ":" + to_string(ltm->tm_sec) +"\""; + system(cmd.c_str()); } void MainWindow::post_entry_data(){ string cmd = ""; - string data = _txtDate->get_text(); + string data = txtDate->get_text(); if (data.length()==10){ string str_day = data.substr(0,2); string str_month = data.substr(3,2); @@ -643,16 +665,16 @@ void MainWindow::post_entry_data(){ } } else{ - _lblMessage->set_text(gettext("Incorrect date format")); - _mess_dchp->show(); + lblMessage->set_text(gettext("Incorrect date format")); + mess_dchp->show(); } } void MainWindow::update_hour_minute(){ time_t now = time(0); tm *ltm = localtime(&now); - _numTimeHrs->set_value(ltm->tm_hour); - _numTimeMin->set_value(ltm->tm_min); + numTimeHrs->set_value(ltm->tm_hour); + numTimeMin->set_value(ltm->tm_min); } void MainWindow::update_calendar(){ @@ -677,7 +699,7 @@ void MainWindow::update_calendar(){ str_day = to_string(day); } string date = str_day + '.' + str_month + '.' + to_string(year1); - _txtDate->set_text(date); + txtDate->set_text(date); } void MainWindow::read_file(){ diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index 20ff007..dd8ff92 100644 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -78,47 +78,57 @@ class MainWindow : public Gtk::ApplicationWindow { 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 str_remove(std::string& source, const std::string to_remove); vector split(const std::string &s, char delim); private: Glib::RefPtr builder; - Gtk::Button *_btnUpdateDateTime; - Gtk::Button *_btnChooseDate; - Gtk::Button *_btnMessCloseSudo; - Gtk::Button *_btnMessClose; - Gtk::ComboBoxText *_cbDhcp; - Gtk::SpinButton *_numTimeHrs; - Gtk::SpinButton *_numTimeMin; - Gtk::CheckButton *_cbxSynchronizeNtpGlob; - Gtk::Box *_boxColor; - Gtk::Entry *_txtDate; - Gtk::ComboBoxText *_cbRegion; - Gtk::ComboBoxText *_cbRegionGlob; - Gtk::ComboBoxText *_cbZone; - Gtk::ComboBoxText *_cbZoneGlob; - Gtk::Entry *_txtNtpServer; - Gtk::Window *_mess_dchp; - Gtk::Window *_mess_sudo; - Gtk::Popover *_popCalendar; - Gtk::Calendar *_cldrDate; - Gtk::Label *_lblMessage; - Gtk::Label *_lblMessageSudo; - Gtk::Label *_lblDateTimeSetting; - Gtk::Label *_lblHead; - Gtk::Label *_lblTime; - Gtk::Label *_lblData; - Gtk::Label *_lblTimeZone; - Gtk::Label *_lblReg; - Gtk::Label *_lblZone; - Gtk::Label *_lblRegGlob; - Gtk::Label *_lblZone1Glob; - Gtk::Label *_lblTimeZoneGlob; - Gtk::Label *_lblSynchronizebChk; - Gtk::Label *_lblSynchronizebChkGLob; - Gtk::Label *_lblSynchronizeBtn; - Gtk::Label *_lblDateTimeSettingGlob; - Gtk::Label *_lblTimeBios; - Gtk::Button *_btnHardwareTime; - Gtk::CheckButton *_cbxSynchronizeNtp; + Gtk::Button *btnUpdateDateTime; + Gtk::Button *btnChooseDate; + Gtk::Button *btnMessCloseSudo; + Gtk::Button *btnMessClose; + Gtk::ComboBoxText *cbDhcp; + Gtk::SpinButton *numTimeHrs; + Gtk::SpinButton *numTimeMin; + Gtk::CheckButton *cbxSynchronizeNtpGlob; + Gtk::Box *boxColor; + Gtk::ComboBoxText *cbRegion; + Gtk::ComboBoxText *cbRegionGlob; + Gtk::ComboBoxText *cbZone; + Gtk::ComboBoxText *cbZoneGlob; + Gtk::Window *mess_dchp; + Gtk::Window *mess_sudo; + Gtk::Popover *popCalendar; + Gtk::Calendar *cldrDate; + Gtk::Label *lblMessage; + Gtk::Label *lblMessageSudo; + Gtk::Label *lblDateTimeSetting; + Gtk::Label *lblHead; + Gtk::Label *lblTime; + Gtk::Label *lblData; + Gtk::Label *lblTimeZone; + Gtk::Label *lblReg; + Gtk::Label *lblZone; + Gtk::Label *lblRegGlob; + Gtk::Label *lblZone1Glob; + Gtk::Label *lblTimeZoneGlob; + Gtk::Label *lblSynchronizebChk; + Gtk::Label *lblSynchronizebChkGLob; + Gtk::Label *lblSynchronizeBtn; + Gtk::Label *lblDateTimeSettingGlob; + Gtk::Label *lblTimeBios; + Gtk::Label *lblBanerStopNtp; + Gtk::Button *btnHardwareTime; + Gtk::CheckButton *cbxSynchronizeNtp; + Gtk::Window *windowsNnpClose; + Gtk::Button *btnNtpStop; + Gtk::Button *btnNtpWinClose; + Gtk::Label *lblNtpStop; + Gtk::Label *lblNtpClose; + Gtk::Entry *txtNtpServer; + Gtk::Entry *txtDate; std::map > time_reg_map; unsigned int year=0; unsigned int month=0; @@ -128,7 +138,7 @@ class MainWindow : public Gtk::ApplicationWindow { string str_region=""; string str_region_glob=""; string str_txtDate; - string str_txtNtpServer; + string strtxtNtpServer; string str_zone=""; string str_zoneGlob; diff --git a/ubl-settings-datetime.glade b/ubl-settings-datetime.glade index a919ff1..828918b 100644 --- a/ubl-settings-datetime.glade +++ b/ubl-settings-datetime.glade @@ -298,6 +298,7 @@ 160 True False + 5 5 5 5 @@ -380,6 +381,7 @@ 160 True False + 5 5 5 5 @@ -538,7 +540,7 @@ Format: DD.MM.YYYY 5 5 5 - 5 + 10 6 6 @@ -571,7 +573,7 @@ Format: DD.MM.YYYY 5 5 5 - 5 + 10 6 0.019999999552965164 in @@ -596,9 +598,10 @@ Format: DD.MM.YYYY False 5 5 - 5 + 8 5 - 8 + 6 + 13 Region 0 @@ -616,7 +619,8 @@ Format: DD.MM.YYYY 5 5 5 - 8 + 6 + 13 False @@ -632,7 +636,8 @@ Format: DD.MM.YYYY 5 10 5 - 8 + 6 + 13 Area 0 @@ -650,7 +655,8 @@ Format: DD.MM.YYYY 5 5 5 - 8 + 6 + 13 False @@ -744,39 +750,51 @@ Format: DD.MM.YYYY 5 vertical - + True - False + True + False + Автоматическая синхронизация времени + 5 + 5 + 5 + 5 + 6 + True - + True - True - False - Автоматическая синхронизация времени + False 5 + 5 5 5 6 - True - - - True - False - Synchronize via NTP - - + 6 + Synchronize via NTP - - False - True - 0 - + + + False + True + 0 + + + + + True + False True False + 5 + 5 + 5 + 5 6 + 5 False @@ -793,8 +811,9 @@ Format: DD.MM.YYYY 5 5 5 - 5 + 10 6 + 5 True @@ -806,7 +825,7 @@ Format: DD.MM.YYYY False True - 0 + 1 @@ -816,7 +835,7 @@ Format: DD.MM.YYYY 5 5 5 - 5 + 10 6 0.019999999552965164 in @@ -839,11 +858,12 @@ Format: DD.MM.YYYY True False - 5 + 8 5 - 5 + 8 5 - 8 + 6 + 13 Region 0 @@ -861,7 +881,8 @@ Format: DD.MM.YYYY 5 5 5 - 8 + 6 + 13 False @@ -873,11 +894,12 @@ Format: DD.MM.YYYY True False - 5 + 10 5 10 5 - 8 + 5 + 13 Area 0 @@ -895,7 +917,8 @@ Format: DD.MM.YYYY 5 5 5 - 8 + 6 + 13 False @@ -912,6 +935,8 @@ Format: DD.MM.YYYY 5 15 5 + 5 + 5 False @@ -932,7 +957,7 @@ Format: DD.MM.YYYY False True - 1 + 2 @@ -984,4 +1009,178 @@ Format: DD.MM.YYYY + + False + + + True + False + vertical + + + True + False + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + 50 + emblem-important + + + False + True + 0 + + + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + Active service detected +Automatic time and date synchronization service detected + + + True + True + 1 + + + + + True + True + 0 + + + + + True + False + + + True + True + True + 5 + 5 + 5 + 5 + 6 + 6 + + + True + False + + + True + False + 5 + 5 + 5 + 5 + media-playback-stop + + + False + True + 0 + + + + + True + False + Stop the synchronization service + + + False + True + 1 + + + + + + + True + True + 0 + + + + + True + True + True + 5 + 5 + 5 + 5 + 6 + 6 + + + True + False + + + True + False + 6 + 5 + 5 + 5 + window-close + + + False + True + 0 + + + + + True + False + Close + + + False + True + 1 + + + + + + + True + True + 1 + + + + + False + True + 1 + + + + + diff --git a/ubl-settings-datetime_ru.po b/ubl-settings-datetime_ru.po index 7f7f769..b6a015e 100644 --- a/ubl-settings-datetime_ru.po +++ b/ubl-settings-datetime_ru.po @@ -6,6 +6,18 @@ msgid "" msgstr "" +msgid "Stop the synchronization service" +msgstr "Остановить сервис синхронизации" + +msgid "Close" +msgstr "Закрыть" + +msgid "Active service detected\nAutomatic time and date synchronization service detected" +msgstr "Обнаружен активный сервис\nавтоматической синхронизации времени и даты" + +msgid "By default" +msgstr "По умолчанию" + msgid "The program must be run with \nsuperuser privileges!" msgstr "Программа должна быть запущена с правами \nсуперпользователя!"