diff --git a/.gitignore b/.gitignore index 45460e9..8a32e88 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ compile/ source/**/ubl_settings_datetime source/**/main.o source/**/ubl_settings_datetime.o -reg/ \ No newline at end of file +reg/ +ubl-util-standard.h +ubl-util-standard.c \ No newline at end of file diff --git a/Makefile b/Makefile index 39c6a5d..7d04dae 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,12 @@ all: init build init: @echo "Initialize ..."; \ + if [ ! -f source/ubl-util-standard.h ]; then \ + ln -s /usr/share/ubl-util-standard/ubl-util-standard.h source/ubl-util-standard.h; \ + fi; \ + if [ ! -f source/ubl-util-standard.c ]; then \ + ln -s /usr/share/ubl-util-standard/ubl-util-standard.c source/ubl-util-standard.c; \ + fi; \ echo "-- Build path: ${CMAKE_BUILD_DIR}" depend: diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 27292b0..09e128f 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -13,9 +13,11 @@ find_package(ICU REQUIRED COMPONENTS uc dt in io) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always \ -O2 -pipe -fno-plt -fexceptions \ -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \ - -fstack-clash-protection -fcf-protection ") + -fstack-clash-protection -fcf-protection -g") set(SOURCE_FILES + ubl-util-standard.h + ubl-util-standard.c main.cc ubl-settings-datetime.cc ubl-settings-datetime.h) diff --git a/source/main.cc b/source/main.cc index 4c57ffb..a77bd61 100644 --- a/source/main.cc +++ b/source/main.cc @@ -1,9 +1,3 @@ -#include -#include -#include -#include -#include -#include #include "ubl-settings-datetime.h" int main(int argc, char* argv[]) { string str_argv=""; @@ -22,6 +16,22 @@ int main(int argc, char* argv[]) { if ((str_argv.find("-s")!=std::string::npos) || (str_argv.find("--socket-id")!=std::string::npos)){ + for (int i=3; i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + #include "ubl-settings-datetime.h" using namespace std; @@ -25,6 +11,7 @@ bool flag_datetime = false; bool flag_timezone = false; bool flag_ntp = false; bool flag_update = false; +int socket_ext_id_I=0; CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help) : Glib::OptionGroup{p_name, p_description, p_help} { @@ -33,7 +20,14 @@ CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_descr socketIDArg.set_short_name('s'); socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketIDArg.set_description("Settings manager socket"); + + Glib::OptionEntry socketExtId; + socketExtId.set_long_name("socket-ext-id"); + socketExtId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); + socketExtId.set_description("Settings manager secondary socket"); + add_entry(socketIDArg, m_socketID); + add_entry(socketExtId, socket_ext_id_I); } ::Window CmdArgParser::GetSocketID() const{ return m_socketID; @@ -51,6 +45,17 @@ MainWindow::MainWindow(Glib::RefPtr const& builder) { } void MainWindow::settings(){ + Gtk::Widget *standartHead; + Gtk::Widget *plugBox; + Gtk::Window *window; + Gtk::Widget *boxButton; + builder->get_widget("standartHead",standartHead); + builder->get_widget("plugBox",plugBox); + builder->get_widget("window",window); + builder->get_widget("boxButton",boxButton); + + + ubl_get_standard_ui(standartHead,plugBox,boxButton,window,"ubl-settings-datetime.svg",_("Settings the date and time"),_("ubl-settings-datetime"),0,socket_ext_id_I); year=0, month=0, day=0; this->get_builder(); this->lacalization(); @@ -63,8 +68,6 @@ void MainWindow::settings(){ this->flag_block_gui(); this->event(); this->parse_text_date(); - - } else{ numTimeHrs->set_sensitive(false); @@ -102,6 +105,12 @@ int MainWindow::check_root(){ return 0; } void MainWindow::lacalization(){ + lblSave->set_label(_("Save")); + lblDownload->set_label(_("Download")); + btnDownloadGlobal->set_label(_("Download global")); + btnSaveLocal->set_label(_("Save global")); + btnSaveGlobl->set_label(_("Save local")); + txtDate->set_tooltip_text(_("Date of\nFormat: DD.MM.YYYY")); txtNtpServer->set_tooltip_text(_("Enter the name of the ntp-server or its ip-address.\nWhen entering multiple addresses, separate them with commas.")); lblSynchronizebChkGLob->set_text(_("Synchronize via NTP:")); @@ -230,6 +239,12 @@ void MainWindow::get_builder(){ builder->get_widget("lblNtpStop",lblNtpStop); builder->get_widget("lblNtpClose",lblNtpClose); builder->get_widget("lblBanerStopNtp",lblBanerStopNtp); + builder->get_widget("btnSaveLocal",btnSaveLocal); + builder->get_widget("btnSaveGlobl",btnSaveGlobl); + builder->get_widget("lblSave",lblSave); + builder->get_widget("btnDownload",btnDownload); + builder->get_widget("lblDownload",lblDownload); + builder->get_widget("btnDownloadGlobal", btnDownloadGlobal); //builder->get_widget("cbxSynchronizeNtp",cbxSynchronizeNtp); @@ -307,7 +322,9 @@ bool MainWindow::focus_ntp(GdkEventFocus* event){ "@","[","]","\\","{","}","|","~", " " }; bool flag_error = false; + bool flag_error_check_ntp = false; string str_ntp = txtNtpServer->get_text(); + flag_error_check_ntp = this->check_ntp(str_ntp); for (const auto &simvol: array_simvol){ if (str_ntp.find(simvol)!=std::string::npos){ flag_error=true; @@ -315,19 +332,102 @@ bool MainWindow::focus_ntp(GdkEventFocus* event){ } } - if (flag_error==false){ + if ((flag_error==false) && (flag_error_check_ntp==false)){ cmd = "/usr/bin/ubconfig set network NTPSERVERS=\"" + str_ntp + "\""; response_cmd = system(cmd.c_str()); } else{ - lblMessage->set_text(_("An invalid character is entered")); - mess_dchp->show(); - } + if (flag_error==true){ + lblMessage->set_text(_("An invalid character is entered")); + mess_dchp->show(); + } + else if (flag_error_check_ntp==true){ + lblMessage->set_text(_("Error in the ntp name")); + mess_dchp->show(); + } } + + } + return true; } +vector MainWindow::find_all(string &str_ntp, string substr){ + size_t index = 0; + vector sub_index; + while ((index = str_ntp.find(substr, index)) != std::string::npos) { + index += substr.length(); + sub_index.push_back(index); + } + return sub_index; +} + +bool MainWindow::check_ntp(string &str_ntp){ + vector sub_index = this->find_all(str_ntp,"."); + if (sub_index.size()==1){ + int index_point = sub_index[0]; + int len_str_ntp = str_ntp.length(); + if (((len_str_ntp-index_point)>=2) && (index_point>2)){ + return false; + } + else{ + return true; + } + } + else if (sub_index.size()==3){ + int index_str_ntp = sub_index[0]; + int index_str_ntp_1 = sub_index[1]; + int index_str_ntp_2 = sub_index[2]; + if (((index_str_ntp>0) && (index_str_ntp<=4)) && + (index_str_ntp_1>(index_str_ntp+1)) && + ((index_str_ntp_1-index_str_ntp)<=4) && + (index_str_ntp_2>(index_str_ntp_1+1)) && + ((index_str_ntp_2-index_str_ntp_1)<=4) && + ((str_ntp.length()-index_str_ntp_2)<=3)) { + string simvol; + bool flag_error=false; + char char_ntp; + for (size_t i = 0; i < str_ntp.size(); i++){ + flag_error=false; + cout << str_ntp[i] << endl; + char_ntp = char(str_ntp[i]); + cout << char_ntp << endl; + for (int index=0;index<11;index++){ + + if (index==10){ + simvol="."; + } + else{ + simvol = to_string(index); + } + cout << (simvol==to_string(char_ntp)) << endl; + cout << simvol << " " << to_string(char_ntp) << endl; + if (simvol==to_string(char_ntp)){ + flag_error=false; + + break; + } + else{ + flag_error=true; + } + } + if (flag_error==true){ + return true; + } + } + } + else{ + return true; + } + } + else{ + return true; + } + return false; + +} + struct MainWindow::Result MainWindow::wrapper_call(string cmd){ struct Result obj_result; string response=this->call(cmd); diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index c1572ab..35ec850 100644 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -1,14 +1,21 @@ #ifndef UBL_SETTINGS_DATETIME_H #define UBL_SETTINGS_DATETIME_H #include -#include -#include -#include -#include -#include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ubl-util-standard.c" using namespace std; @@ -22,7 +29,7 @@ extern bool flag_datetime; extern bool flag_timezone; extern bool flag_ntp; extern bool flag_update; - +extern int socket_ext_id_I; class CmdArgParser : public Glib::OptionGroup { public: @@ -70,6 +77,8 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::Label *lblSynchronizeBtn; Gtk::Label *lblDateTimeSettingGlob; Gtk::Label *lblTimeBios; + Gtk::Label *lblSave; + Gtk::Label *lblDownload; Gtk::Label *lblBanerStopNtp; Gtk::Button *btnHardwareTime; Gtk::CheckButton *cbxSynchronizeNtp; @@ -80,6 +89,11 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::Label *lblNtpClose; Gtk::Entry *txtNtpServer; Gtk::Entry *txtDate; + Gtk::Widget *btnSave; + Gtk::Widget *btnDownload; + Gtk::MenuItem *btnSaveLocal; + Gtk::MenuItem *btnSaveGlobl; + Gtk::MenuItem *btnDownloadGlobal; std::map > time_reg_map; std::map > time_reg_map_local; unsigned int year=0; @@ -101,6 +115,7 @@ class MainWindow : public Gtk::ApplicationWindow { }; vector array_region_local; vector array_region; + public: MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); MainWindow(Glib::RefPtr const& builder); @@ -145,6 +160,8 @@ class MainWindow : public Gtk::ApplicationWindow { string str_remove(std::string& source, const std::string to_remove); vector split(const std::string &s, char delim); struct Result wrapper_call(string cmd); + bool check_ntp(string &str_ntp); + vector find_all(string &str_ntp, string substr); }; diff --git a/ubl-settings-datetime.desktop b/ubl-settings-datetime.desktop index 1037bf7..521b6fe 100644 --- a/ubl-settings-datetime.desktop +++ b/ubl-settings-datetime.desktop @@ -7,8 +7,9 @@ GenericName[ru]=Настройка даты и времени Comment=Date time settings Comment[ru]=Приложение для настройки даты и времени Type=Application -Exec=pkexec ubl-settings-datetime +Exec=pkexec ubl-settings-datetime --lock-datetime Icon=ubl-settings-datetime Terminal=false X-XfcePluggable=true +X-UBLPluggable=true Categories=XFCE;GTK;Settings;DesktopSettings;X-XFCE-SettingsDialog;X-XFCE-SystemSettings;X-UBL-SettingsManager;X-UBL-SystemSettings; \ No newline at end of file diff --git a/ubl-settings-datetime.glade b/ubl-settings-datetime.glade index ccf56b9..da31a0f 100644 --- a/ubl-settings-datetime.glade +++ b/ubl-settings-datetime.glade @@ -2,183 +2,47 @@ - + + True 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 - - + Save Local + True + + + + + True + False + Save Global + True - + + True 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 - - + Download Global + True False - Настройки даты и времени True False vertical - + True False vertical @@ -277,6 +141,18 @@ 0 + + + False + True + 0 + + + + + True + False + vertical True @@ -460,7 +336,7 @@ Format: DD.MM.YYYY True True 5 - 8 + 5 5 5 6 @@ -538,7 +414,7 @@ Format: DD.MM.YYYY True True 5 - 8 + 10 5 10 6 @@ -938,7 +814,7 @@ Format: DD.MM.YYYY True False - Часовой пояс + Time Zone @@ -975,7 +851,90 @@ Format: DD.MM.YYYY False True - 0 + 1 + + + + + + + True + False + True + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + ubl-settings-datetime + + + + + True + False + + + True + True + False + True + menu1 + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + Save + + + + + False + True + 1 + + + + + True + True + False + True + menu2 + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + Download + + + + + False + True + 2 + + + + + 1 @@ -1004,6 +963,173 @@ Format: DD.MM.YYYY + + 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 diff --git a/ubl-settings-datetime_ru.po b/ubl-settings-datetime_ru.po index e6017e0..49531f0 100644 --- a/ubl-settings-datetime_ru.po +++ b/ubl-settings-datetime_ru.po @@ -22,6 +22,9 @@ msgstr "Введён недопустимый символ" msgid "Longyearbyen" msgstr "Лонгйир" +msgid "Error in the ntp name" +msgstr "Ошибка в имени ntp" + msgid "Stop the synchronization service" msgstr "Остановить сервис синхронизации" @@ -1633,9 +1636,24 @@ msgstr " --lock-update Отключить сохранение измене msgid "Options:\n" msgstr "Опции:\n" +msgid "Save" +msgstr "Сохранить" + +msgid "Save global" +msgstr "Сохранить глобально" + +msgid "Save local" +msgstr "Сохранить локально" + +msgid "Download global" +msgstr "Загрузить глобально" + msgid "Disabled" msgstr "Отключено" +msgid "Download" +msgstr "Загрузить" + msgid "Argument not recognized\n" -msgstr "Не распознанный аргумент\n" +msgstr "Нepacпoзнaнный аргумент\n"