From bb45aa7aae7353e18e6735e662604f297d4e4e79 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Wed, 1 Mar 2023 11:26:16 +0600 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BF=D0=B0?= =?UTF-8?q?=D1=80=D0=BC=D0=B5=D1=82=D1=80=D1=8B=20=D0=B1=D0=BB=D0=BE=D0=BA?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- #ubl-settings-datetime.glade#~ | 1398 +++++++++++++++++++++++++++++++ source/main.cc | 87 +- source/ubl-settings-datetime.cc | 132 ++- source/ubl-settings-datetime.h | 9 +- ubl-settings-datetime.glade | 0 5 files changed, 1505 insertions(+), 121 deletions(-) create mode 100644 #ubl-settings-datetime.glade#~ mode change 100755 => 100644 ubl-settings-datetime.glade diff --git a/#ubl-settings-datetime.glade#~ b/#ubl-settings-datetime.glade#~ new file mode 100644 index 0000000..720e5a8 --- /dev/null +++ b/#ubl-settings-datetime.glade#~ @@ -0,0 +1,1398 @@ + + + + + + False + О Программе + False + True + center + ubl-settings-datetime + dialog + True + ubl-settings-datetime + 1.2 + Copyright © 2023 - UBSoft Software LLC + Setting the date and time + https://ublinux.ru/ + Project Home Page + Это приложение распространяется без каких-либо гарантий. +Подробнее в <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GNU General Public License, версии 2 или позднее</a>. + UBGroup + UBGroup + ubl-settings-datetime + True + gpl-2-0 + + + False + vertical + 2 + + + False + end + + + + + + False + False + 0 + + + + + + + + + + 730 + 530 + False + center + ubconfig-gui + south-west + + + + + + True + False + + + + + + True + False + 5 + 10 + 5 + 10 + 25 + ubconfig-gui + + + + + + + + + + False + Внимание! + dialog + + + True + False + vertical + + + True + False + 5 + 5 + 5 + 5 + + + True + False + 5 + 5 + 5 + 6 + 6 + 50 + gtk-dialog-warning + + + True + True + 0 + + + + + 160 + True + False + start + center + 6 + 6 + Enter DHCP ! + + + True + True + 1 + + + + + False + True + 1 + + + + + OK + True + True + True + 5 + 5 + 5 + 5 + 3 + 3 + + + False + True + 1 + + + + + + + False + Внимание! + center + dialog + + + True + False + vertical + + + True + False + 5 + 5 + 5 + 5 + + + True + False + 5 + 5 + 5 + 6 + 6 + 50 + gtk-dialog-warning + + + True + True + 0 + + + + + 160 + True + False + start + center + 5 + 5 + 5 + 5 + 6 + 6 + Enter DHCP ! + + + True + True + 1 + + + + + False + True + 1 + + + + + OK + True + True + True + 5 + 5 + 5 + 5 + 3 + 3 + + + False + True + 1 + + + + + + + False + + + True + False + 0 + none + + + True + False + 5 + 5 + 5 + 5 + + + True + False + vertical + + + True + True + True + Synopsis + + + False + True + 2 + + + + + True + True + True + About the program + + + False + True + 3 + + + + + + + + + + + + + + False + + + True + False + 0 + none + + + True + False + 5 + 5 + 5 + 5 + + + True + False + vertical + + + True + True + True + Download local + + + False + True + 2 + + + + + True + True + True + Download global + + + False + True + 3 + + + + + + + + + + + + + + False + + + True + False + 0 + none + + + True + False + 5 + 5 + 5 + 5 + + + True + False + vertical + + + True + True + True + Save to global and local configuration + + + False + True + 3 + + + + + True + True + True + Save to local configuration + + + False + True + 4 + + + + + True + True + True + Save to Global configuration + + + False + True + 5 + + + + + + + + + + + + + + False + + + True + False + vertical + + + True + False + vertical + + + True + False + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + gtk-missing-image + + + False + True + 0 + + + + + True + False + start + 5 + 5 + 5 + 5 + 6 + 6 + + + + + + + True + True + 1 + + + + + False + True + 0 + + + + + True + False + vertical + + + True + False + + + 90 + True + False + 5 + 5 + 5 + 5 + 6 + 6 + 69 + ubl-settings-datetime + + + False + True + 0 + + + + + True + False + + + True + False + + + True + False + vertical + + + 255 + True + False + Date and time settings + + + + + + + + + True + True + 0 + + + + + False + True + 0 + + + + + True + True + 0 + + + + + True + False + + + False + True + 1 + + + + + True + True + 1 + + + + + False + True + 0 + + + + + False + True + 1 + + + + + True + False + vertical + + + True + False + vertical + + + True + False + 5 + 5 + 5 + 5 + 0.019999999552965164 + in + + + True + False + 5 + 5 + 5 + vertical + + + True + False + + + 0 + True + False + 5 + 5 + 5 + 5 + 6 + 6 + Time + True + 0 + + + False + True + 0 + + + + + True + True + 5 + 5 + 5 + 5 + 6 + 6 + 2 + 0.099999999776482579 + True + + + False + True + 1 + + + + + True + False + : + + + False + True + 2 + + + + + True + True + 5 + 5 + 5 + 5 + 6 + 6 + 2 + True + + + False + True + 3 + + + + + 20 + True + False + 5 + 5 + 5 + 5 + 6 + 6 + Date + True + 0 + + + False + True + 4 + + + + + -1 + True + True + Date +Format: DD.MM.YYYY + 5 + 5 + 5 + 5 + 6 + 6 + + + True + True + 5 + + + + + True + True + True + Интерактивный выбор даты + 5 + 10 + 5 + 10 + 6 + 6 + + + True + False + x-office-calendar + + + + + False + True + 6 + + + + + False + True + 1 + + + + + True + False + + + True + True + True + 7 + 5 + 7 + 5 + 6 + 6 + + + True + False + center + center + + + True + False + 5 + 5 + 5 + 5 + media-playlist-repeat + + + False + True + 0 + + + + + True + False + center + center + Sync by + + + False + True + 1 + + + + + + + False + True + 0 + + + + + True + False + + + False + True + 1 + + + + + True + False + + + False + True + 2 + + + + + True + True + True + 5 + 10 + 5 + 10 + 6 + 6 + + + True + False + center + center + Synchronize hardware time + + + + + True + True + 3 + + + + + False + True + 3 + + + + + + + True + False + Current date and time + + + + + False + True + 0 + + + + + False + True + 1 + + + + + True + False + vertical + + + True + False + 5 + 5 + 5 + 5 + 0.019999999552965164 + in + + + True + False + 5 + 5 + 5 + vertical + + + True + False + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + + + False + True + 1 + + + + + -1 + True + True + Enter the name of the ntp server or its ip address. When entering multiple addresses, separate them with spaces. + center + 5 + 10 + 5 + 10 + 6 + 6 + + + True + True + 3 + + + + + False + True + 1 + + + + + + + True + False + Synchronize via NTP: + + + + + False + True + 0 + + + + + False + True + 2 + + + + + True + False + 5 + 5 + 5 + 5 + 5 + 0.019999999552965164 + in + + + True + False + + + True + False + + + False + True + 1 + + + + + True + False + 8 + 5 + 8 + 5 + 6 + 13 + Region + 0 + + + False + True + 2 + + + + + True + False + 5 + 5 + 5 + 5 + 6 + 10 + False + False + + + False + True + 3 + + + + + True + False + 10 + 5 + 10 + 5 + 6 + 13 + Area + 0 + + + False + True + 4 + + + + + True + False + 5 + 5 + 5 + 5 + 6 + 10 + False + False + + + False + True + 5 + + + + + 5 + True + False + + + False + True + 6 + + + + + True + False + + + False + True + 7 + + + + + + + True + False + Time Zone + + + + + False + True + 3 + + + + + False + True + 2 + + + + + False + True + 0 + + + + + + + True + False + True + + + True + False + 5 + 5 + 5 + 5 + 2 + ubl-settings-datetime + + + + + + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + 32 + ubl-settings-datetime + + + + + True + False + + + True + True + False + True + True + none + popDownloadMenu + + + True + False + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + Download + + + False + True + 0 + + + + + True + False + True + False + True + False + + + + + + False + True + 1 + + + + + + + False + True + 0 + + + + + + 1 + + + + + True + False + + + True + True + False + True + True + none + popSaveMenu + + + True + False + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + Save + + + + False + True + 0 + + + + + True + False + True + False + True + + + + + + False + True + 1 + + + + + + + False + True + 0 + + + + + True + True + False + True + True + none + popAbout + + + + + + False + True + 1 + + + + + + end + 3 + + + + + + + 240 + 185 + False + btnChooseDate + bottom + none + + + True + True + 10 + 10 + 10 + 10 + 10 + 10 + 2023 + 1 + 10 + + + + diff --git a/source/main.cc b/source/main.cc index a77bd61..42b4f43 100755 --- a/source/main.cc +++ b/source/main.cc @@ -1,4 +1,7 @@ #include "ubl-settings-datetime.h" + +void pars_flag(int index_start, int argc, char* argv[]); + int main(int argc, char* argv[]) { string str_argv=""; string str_cmd_argv = ""; @@ -14,24 +17,9 @@ int main(int argc, char* argv[]) { str_argv = argv[1]; } - if ((str_argv.find("-s")!=std::string::npos) || (str_argv.find("--socket-id")!=std::string::npos)){ + if (str_argv.find("--socket-id")!=std::string::npos){ - for (int i=3; iget_widget_derived("window", wnd); auto r = app->run(*wnd); @@ -93,4 +59,45 @@ int main(int argc, char* argv[]) { cout << gettext("Argument not recognized"); return 0; } +} + +void pars_flag(int index_start, int argc, char* argv[]){ + string str_argv=""; + for (int i=index_start; ievent(); this->parse_text_date(); this->download_local_cfg(); - - //orevrlayInfo->add_overlay(*boxInfoError); - //imgInfo->set("/usr/share/ubl-settings-datetime/images/checked.svg"); - //GdkPixbuf* pixbuf_image = gdk_pixbuf_new_from_file_at_size("/usr/share/ubl-settings-datetime/images/close.svg", 12,12,NULL); - //GtkWidget* imageInfo = GTK_WIDGET(imageCloseInfo->gobj()); - //gtk_image_set_from_pixbuf(GTK_IMAGE(imageInfo), pixbuf_image); } else{ btnDownload->set_sensitive(false); @@ -109,11 +106,7 @@ void MainWindow::settings(){ btnBoxAboutDialog->set_visible(false); this->event(); imgInfo->set("/usr/share/ubl-settings-datetime/images/checked.svg"); - - - } - //popCalendar->show_all(); } @@ -159,14 +152,10 @@ void MainWindow::lacalization(){ mess_sudo->set_title(_("Warning!")); mess_dchp->set_title(_("Warning!")); lblTimeBios->set_text(_("Synchronize hardware time")); - //_lblSynchronizebChk->set_text(_("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); @@ -180,17 +169,28 @@ void MainWindow::flag_block_gui(){ if (flag_timezone==true){ cbRegion->set_sensitive(false); cbZone->set_sensitive(false); - //btnChooseDate->set_sensitive(false); - cbDhcp->set_sensitive(false); } - if (flag_ntp==true){ + if (flag_ntp_mode==true){ cbDhcp->set_sensitive(false); txtNtpServer->set_sensitive(false); + flag_ntp_edit = true; } - if (flag_update==true){ + if (flag_ntp_edit==true){ txtNtpServer->set_sensitive(false); - cbDhcp->set_sensitive(false); } + if (flag_load_global==true){ + btnDonwlolGlob->set_sensitive(false); + } + if (flag_save==true){ + btnSave->set_sensitive(false); + } + if (flag_save_local==true){ + btnSaveLocal->set_sensitive(false); + } + if (flag_save_global==true){ + btnSaveGlob->set_sensitive(false); + } + } void MainWindow::add_CSS(){ @@ -201,11 +201,8 @@ void MainWindow::add_CSS(){ 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(); - context->add_class("cssboxColor1"); context_lbl_head->add_class("textHead"); - - } @@ -240,7 +237,6 @@ void MainWindow::get_builder(){ builder->get_widget("lblTimeZone",lblTimeZone); builder->get_widget("lblReg",lblReg); builder->get_widget("lblZone",lblZone); - //builder->get_widget("lblSynchronizebChk",_lblSynchronizebChk); builder->get_widget("lblSynchronizebChkGLob",lblSynchronizebChkGLob); builder->get_widget("lblSynchronizeBtn",lblSynchronizeBtn); builder->get_widget("lblTimeBios",lblTimeBios); @@ -249,7 +245,6 @@ void MainWindow::get_builder(){ builder->get_widget("lblMessageSudo",lblMessageSudo); builder->get_widget("btnMessCloseSudo",btnMessCloseSudo); builder->get_widget("lblSave",lblSave); - builder->get_widget("lblDownload",lblDownload); builder->get_widget("aboutWindows", aboutWindows); builder->get_widget("btnBoxAboutDialog", btnBoxAboutDialog); @@ -356,20 +351,29 @@ void MainWindow::save_global_cfg(){ info_warning_error(3); } void MainWindow::save_global_local_cfg(){ - string cmd = "ubconfig --target system set clock ZONE="; - this->enter_zone(cmd); - cmd = "/usr/bin/ubconfig --target global set clock ZONE="; - this->enter_zone(cmd); - 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); + string cmd = ""; + string cmd_default = ""; + string cmd_dhcp = ""; + string cmd_set_ntp = ""; + string remove = ""; + if (flag_save_global==false){ + cmd = "/usr/bin/ubconfig --target global set clock ZONE="; + this->enter_zone(cmd); + cmd_default = "/usr/bin/ubconfig --target global set network NTPSERVERS=default"; + cmd_dhcp = "/usr/bin/ubconfig --target global set network NTPSERVERS=dhcp"; + cmd_set_ntp = "/usr/bin/ubconfig --target global set network NTPSERVERS=\""; + remove = "/usr/bin/ubconfig --target global remove network NTPSERVERS"; + this->save_Dhcp(cmd_default, cmd_dhcp, remove, cmd_set_ntp); + } + if (flag_save_local==false){ + cmd = "ubconfig --target system set clock ZONE="; + this->enter_zone(cmd); + 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); + } info_warning_error(4); } @@ -417,28 +421,6 @@ void MainWindow::info_warning_error(int mess){ } -void MainWindow::stop_ntp(){ - int start_error = error_info; - string cmd = "SEL_SERVICE=\"systemd-timesyncd\"; systemctl --quiet is-active ${SEL_SERVICE}.service &>/dev/null && systemctl stop ${SEL_SERVICE}.service; "; - wrapper_system(cmd); - cmd ="SEL_SERVICE=\"ntpd\"; systemctl --quiet is-active ${SEL_SERVICE}.service &>/dev/null && systemctl stop ${SEL_SERVICE}.service || pkill -9 ${SEL_SERVICE}; "; - wrapper_system(cmd); - cmd ="SEL_SERVICE=\"ntpdate\"; systemctl --quiet is-active ${SEL_SERVICE}.service &>/dev/null && systemctl stop ${SEL_SERVICE}.service || pkill -9 ${SEL_SERVICE}; "; - wrapper_system(cmd); - cmd = "SEL_SERVICE=\"chronyd\"; systemctl --quiet is-active ${SEL_SERVICE}.service &>/dev/null && systemctl stop ${SEL_SERVICE}.service || pkill -9 ${SEL_SERVICE}; "; - wrapper_system(cmd); - cmd ="SEL_SERVICE=\"openntpd\"; systemctl --quiet is-active ${SEL_SERVICE}.service &>/dev/null && systemctl stop ${SEL_SERVICE}.service || pkill -9 ntpd; "; - wrapper_system(cmd); - cmd ="SEL_SERVICE=\"ptp4l\"; systemctl --quiet is-active ${SEL_SERVICE}.service &>/dev/null && systemctl stop ${SEL_SERVICE}.service || pkill -9 ${SEL_SERVICE}; "; - wrapper_system(cmd); - cmd ="SEL_SERVICE=\"phc2sys\"; systemctl --quiet is-active ${SEL_SERVICE}.service &>/dev/null && systemctl stop ${SEL_SERVICE}.service || pkill -9 ${SEL_SERVICE} "; - wrapper_system(cmd); - if (start_error!=error_info){ - error_info=start_error; - } - cout << error_info << endl; -} - void MainWindow::wrapper_system(string cmd){ int response_cmd = system(cmd.c_str()); if (response_cmd!=0){ @@ -620,13 +602,14 @@ void MainWindow::event_entry_cbDhcp(){ txtNtpServer->set_text(""); } else if (activ_index==2){ - txtNtpServer->set_sensitive(true); + if (flag_ntp_edit==false){ + txtNtpServer->set_sensitive(true); + } } else if (activ_index==3){ txtNtpServer->set_text(""); txtNtpServer->set_sensitive(false); btnUpdateDateTime->set_sensitive(true); - this->stop_ntp(); } } @@ -655,7 +638,6 @@ void MainWindow::save_Dhcp(string &cmd_default, string &cmd_dhcp, string &remove } 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){ @@ -671,7 +653,6 @@ void MainWindow::entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhc else if (str_dhcp=="default"){ btnUpdateDateTime->set_sensitive(false); cbDhcp->set_active(0); - //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); @@ -682,10 +663,6 @@ void MainWindow::entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhc if (obj_result.error==2){ warning_info-=1; } - //string error = ""; - //error = string(_("ERROR")) + "\n" + obj_result.response; - //lblMessage->set_text(error); - //mess_dchp->show(); } } else{ @@ -701,7 +678,9 @@ void MainWindow::entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhc else{ cbDhcp->set_active(2); txtNtpServer->set_text(str_dhcp); - txtNtpServer->set_sensitive(true); + if (flag_ntp_edit==false){ + txtNtpServer->set_sensitive(true); + } } } } @@ -921,7 +900,6 @@ string MainWindow::call(string cmd){ exit(1); } while (fgets(path, PATH_MAX, fp) != NULL){ - //printf("%s", path); break; } status = pclose(fp); @@ -933,7 +911,6 @@ string MainWindow::call(string cmd){ } void MainWindow::append_zone(){ - //int length_zone = time_reg_map.at(str_region).size(); cbZone->remove_all(); int index = cbRegion->get_active_row_number(); string str_region = array_region[index]; @@ -1052,26 +1029,25 @@ void MainWindow::read_file(){ string path_reg_zone = ""; namespace fs = std::filesystem; for (const auto & entry : fs::directory_iterator("/usr/share/zoneinfo/")){ - std::ifstream in(entry.path()); // окрываем файл для чтения + std::ifstream in(entry.path()); if (in.is_open()){ string key_reg = entry.path().filename().string(); string path_dir = "/usr/share/zoneinfo/"+key_reg; if (fs::is_directory(path_dir)){ if (key_reg!="Pacific"){ if (key_reg!="posix"){ - //if (key_reg!="Etc"){ if (key_reg!="right"){ vector zone; vector zone_local; for (const auto & entry_zone : fs::directory_iterator(path_dir)){ - std::ifstream in1(entry_zone.path()); // окрываем файл для чтения + std::ifstream in1(entry_zone.path()); if (in1.is_open()){ string key_zone = entry_zone.path().filename().string(); if (fs::is_directory(path_dir+"/"+key_zone)){ string reg_reg_zone = path_dir+"/"+key_zone; for (const auto & entry_reg_reg_zone : fs::directory_iterator(reg_reg_zone)){ - std::ifstream in2(entry_zone.path()); // окрываем файл для чтения + std::ifstream in2(entry_zone.path()); if (in2.is_open()){ string reg_reg_zone = entry_reg_reg_zone.path().filename().string(); zone.push_back(reg_reg_zone); diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index 06d3f45..9859a5a 100755 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -27,8 +27,12 @@ extern string path_locale; extern string path_css; extern bool flag_datetime; extern bool flag_timezone; -extern bool flag_ntp; -extern bool flag_update; +extern bool flag_ntp_mode; +extern bool flag_ntp_edit; +extern bool flag_save; +extern bool flag_save_local; +extern bool flag_save_global; +extern bool flag_load_global; extern int socket_ext_id_I; extern int socket_trd_id_I; class CmdArgParser : public Glib::OptionGroup @@ -163,7 +167,6 @@ 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_system(string cmd); void info_status_app(string stule); diff --git a/ubl-settings-datetime.glade b/ubl-settings-datetime.glade old mode 100755 new mode 100644