diff --git a/source/ubl-settings-datetime.cc b/source/ubl-settings-datetime.cc index 1361c8c..a9e5bbe 100644 --- a/source/ubl-settings-datetime.cc +++ b/source/ubl-settings-datetime.cc @@ -15,9 +15,11 @@ int socket_ext_id_I = 0; int socket_trd_id_I = 0; string version_application = "2.2"; MainWindow* obj_main; -void wrapper_synopsis_show() { +void wrapper_help_show(GtkWidget *self, char* link, gpointer user_data) { + if (self && user_data) {} + obj_main->global_lick_doc = link; obj_main->aboutWindows->hide(); - obj_main->synopsis_show(); + obj_main->temp_help_show(); } CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help) @@ -128,7 +130,7 @@ void MainWindow::lacalization() { tm *ltm = localtime(&now); unsigned int year = 1900+ ltm->tm_year; string str_authors = string(copyright) + to_string(year); - aboutWindows->set_program_name(name_app); + aboutWindows->set_program_name(app_name); aboutWindows->set_copyright(str_authors); aboutWindows->set_comments(str_date_time); aboutWindows->set_website(website); @@ -145,7 +147,7 @@ void MainWindow::lacalization() { cbDhcp->append(str_manual); cbDhcp->append(str_disabled); lblDateTimeSetting->set_text(current_date_time); - lblHead->set_text(setting_date_time); + lblHead->set_text(str_date_time); lblTime->set_text(str_time); lblData->set_text(str_date); lblTimeZone->set_text(str_time_zone); @@ -300,7 +302,7 @@ void MainWindow::get_builder() { builder->get_widget("btnSave", btnSave); builder->get_widget("btnSettings", btnSettings); builder->get_widget("btnLoad", btnLoad); - builder->get_widget("btnSynopsis", btnSynopsis); + builder->get_widget("btnhelp", btnhelp); builder->get_widget("btnAbout", btnAbout); builder->get_widget("btnLoadLocal", btnLoadLocal); builder->get_widget("btnLoadGlob", btnLoadGlob); @@ -340,11 +342,11 @@ void MainWindow::get_builder() { } void MainWindow::event() { - g_signal_connect(G_OBJECT(aboutWindows->gobj()), "activate-link", G_CALLBACK(wrapper_synopsis_show), this); + g_signal_connect(G_OBJECT(aboutWindows->gobj()), "activate-link", G_CALLBACK(wrapper_help_show), this); btnCancelHelp->signal_clicked().connect([&]() {wndShowWeb->hide();}); chkAlwaysOpenHelp->signal_toggled().connect([&]() {flag_open_browser = true;}); btnReadHelp->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::open_browser)); - btnSynopsis->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::synopsis_show)); + btnhelp->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::open_help)); btnHardwareTime->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::hardware_clock)); btnMessClose->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::gui_mess_close)); //cldrDate->signal_day_selected().connect(sigc::mem_fun(*this, &MainWindow::get_calendar)); @@ -354,7 +356,7 @@ void MainWindow::event() { cbRegion->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone)); cldrDate->signal_day_selected_double_click().connect(sigc::mem_fun(*this, &MainWindow::get_calendar)); btnAbout->signal_activate().connect([&]() {aboutWindows->show();}); - btnSynopsis->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::synopsis_show)); + btnhelp->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::open_help)); btnLoadLocal->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::load_local_cfg)); btnLoadGlob->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::load_globl_cfg)); btnSaveLocalGlob->signal_activate().connect([&]() {save_global_local_cfg();}); @@ -411,7 +413,7 @@ void MainWindow::event_zone() { this->write_config(zone_text, "zone"); } -void MainWindow::synopsis_show() { +void MainWindow::temp_help_show() { if (flag_open_browser == true) { this->open_browser(); } @@ -421,26 +423,31 @@ void MainWindow::synopsis_show() { } +void MainWindow::open_help() { + global_lick_doc = const_link_doc; + temp_help_show(); +} + void MainWindow::open_browser() { #ifdef WEBKIT_FOUND - webkit_web_view_load_uri(one, link_doc); + webkit_web_view_load_uri(one, _(global_lick_doc.c_str())); wndWeb->show_all(); #else - this->template_open_browser(); + this->template_open_browser(global_lick_doc); #endif wndShowWeb->hide(); } -void MainWindow::template_open_browser() { - string cmd = cmd_xdg + string(_(link_doc)) + " &"; +void MainWindow::template_open_browser(string link_doc) { + string cmd = cmd_xdg + string(_(link_doc.c_str())) + " &"; string buf = ""; if (geteuid() == 0) { string response_user = getlogin(); int size_s = std::snprintf(nullptr, 0, cmd_execute, response_user.c_str(), cmd.c_str()) + 1; auto size = static_cast(size_s); std::unique_ptr buf(new char[ size ]); - std::snprintf( buf.get(), size, cmd_execute, response_user.c_str(), cmd.c_str() ); - cmd = std::string( buf.get(), buf.get() + size - 1 ); + std::snprintf(buf.get(), size, cmd_execute, response_user.c_str(), cmd.c_str()); + cmd = string(buf.get(), buf.get() + size - 1); } index_error = system(cmd.c_str()); } @@ -843,7 +850,7 @@ bool MainWindow::focus_ntp_text() { 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); + flag_error_check_ntp = this->wrapper_check_ntp(str_ntp); for (const auto &simvol: array_simvol) { if (str_ntp.find(simvol) != std::string::npos) { flag_error= true; @@ -886,19 +893,35 @@ vector MainWindow::find_all(string &str_ntp, string substr) { 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; +bool MainWindow::check_is_num_ntp(string &str_ntp) { + int code_ascii = 0; + bool flag_is_num = false; + for (size_t index = 0; index < str_ntp.length(); index++) { + code_ascii = static_cast(str_ntp[index]); + if (code_ascii >= 48 && code_ascii <= 57 ) { + flag_is_num = true; + break; } - else { - return true; + } + return flag_is_num; +} + +bool MainWindow::check_is_string_ntp(string &str_ntp) { + int code_ascii = 0; + bool flag_is_str = false; + for (size_t index = 0; index < str_ntp.length(); index++) { + code_ascii = static_cast(str_ntp[index]); + if ((code_ascii >= 65 && code_ascii <= 90) || (code_ascii >= 97 && code_ascii <= 122)) { + flag_is_str = true; + break; } } - else if (sub_index.size() == 3) { + return flag_is_str; +} + +bool MainWindow::validate_ip_address(string &str_ntp) { + vector sub_index = this->find_all(str_ntp, "."); + 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]; @@ -942,7 +965,60 @@ bool MainWindow::check_ntp(string &str_ntp) { return true; } return false; +} + +bool MainWindow::validate_domen(string &str_ntp) { + vector sub_index = this->find_all(str_ntp, "."); + if (sub_index.size() != 0) { + int index_point = sub_index[sub_index.size()-1]; + int len_str_ntp = str_ntp.length(); + if (((len_str_ntp-index_point) >= 2) && (index_point > 2)) { + return false; + } + else { + return true; + } + } + else { + return true; + } + return false; +} +bool MainWindow::check_ntp(string &str_ntp) { + bool flag_is_str = this->check_is_string_ntp(str_ntp); + bool flag_is_num = this->check_is_num_ntp(str_ntp); + if (flag_is_str) { + return this->validate_domen(str_ntp); + } + else if (flag_is_str && flag_is_num == false) { + return this->validate_ip_address(str_ntp); + } + else { + return false; + } + return false; +} + +bool MainWindow::wrapper_check_ntp(string &str_ntp) { + bool flag_check_error_ntp = false; + if (str_ntp.find(",") != string::npos) { + vector vec_ntp = split(str_ntp, ','); + for (string& str_split_ntp: vec_ntp) { + if (str_split_ntp.length() == 0) { + return true; + } + flag_check_error_ntp = this->check_ntp(str_split_ntp); + if (flag_check_error_ntp) { + return flag_check_error_ntp; + } + } + return false; + } + else { + return this->check_ntp(str_ntp); + } + return false; } struct MainWindow::Result MainWindow::wrapper_call(string cmd) { diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index 83528d7..6425c94 100644 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -26,7 +26,7 @@ #endif -#define link_doc "https://wiki.ublinux.com/ru/Программное_обеспечение/Программы_и_утилиты/Все/ubl-settings-datetime" +#define const_link_doc "https://wiki.ublinux.com/ru/Программное_обеспечение/Программы_и_утилиты/Все/ubl-settings-datetime" #define cmd_xdg "xdg-open " #define cmd_execute "su -l %s -c \" DISPLAY=$DISPLAY %s \"" #define get_NTPSERVERS_DEFAULT "ubconfig --source default get [] NTPSERVERS_DEFAULT" @@ -91,7 +91,7 @@ #define always_redirect _("Always redirect") #define nothing_save _("Nothing to save!") #define read_documentation_web _("Would you like to read documentation in the Web?") -#define redirected_documentation _("You will be redirected to documentation site, where user help pages are ""translated and supported by community.") +#define redirected_documentation _("You will be redirected to documentation website where documentation is\n""translated and supported by community.") #define str_help_h _("Setting up the date and time for UBLinux\n\n""Usage: ubl-settings-datetime [OPTIONS...]\n""Options:\n"" -h, --help Show this help\n"" -V, --version Show package version\n"" --lock-datetime Lock date and time changes\n"" --lock-timezone Lock time zone changes\n"" --lock-ntp-mode Lock NTP mode selection\n"" --lock-ntp-edit Lock editing NTP servers\n"" --lock-sync-hwclock Lock sync hwclock mode selection\n"" --lock-save Lock saving local and global configuration\n"" --lock-save-local Lock save global configuration\n"" --lock-save-global Lock load global configuration\n"" --lock-load-global Lock load global configuration\n") #define str_version _("ubl-settings-datetime version: ") #define local_read_error _("Local configuration reading error") @@ -207,7 +207,7 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::MenuItem *btnLoadGlob; Gtk::MenuItem *btnLoadLocal; Gtk::MenuItem *btnAbout; - Gtk::MenuItem *btnSynopsis; + Gtk::MenuItem *btnhelp; Gtk::HeaderBar *headerBar; Gtk::Label *lblHeader; Gtk::Label *lblHW; @@ -255,6 +255,7 @@ class MainWindow : public Gtk::ApplicationWindow { int minute; string str_region_buff = ""; string str_zone_buff = ""; + string global_lick_doc = ""; int count_edit = 0; bool flag_global = false; bool flag_local = false; @@ -285,13 +286,15 @@ class MainWindow : public Gtk::ApplicationWindow { void log_mess_error(string &cmd); void set_hardware_clock(string &local, string &etc); void info_warning_error(int mess); - void synopsis_show(); + void help_show(); + void temp_help_show(); + void open_help(); void get_hardware_clock(string cmd); void save_global_local_cfg(); void fill_in_reg_zone(string cmd); void load_globl_cfg(); void save_local_cfg(); - void template_open_browser(); + void template_open_browser(string link_doc); void event_zone(); bool focus_ntp(GdkEventFocus* event); bool check_config(string key, int key_save); @@ -306,8 +309,13 @@ class MainWindow : public Gtk::ApplicationWindow { void settings(); void flag_block_gui(); void add_CSS(); + bool check_is_string_ntp(string &str_ntp); + bool check_is_num_ntp(string &str_ntp); void get_builder(); void event(); + bool wrapper_check_ntp(string &str_ntp); + bool validate_domen(string &str_ntp); + bool validate_ip_address(string &str_ntp); void gui_mess_close(); bool focus_ntp_text() ; void event_entry_cbDhcp(); @@ -364,6 +372,6 @@ private: Gtk::Widget *parent; }; -void wrapper_synopsis_show(); +void wrapper_help_show(GtkWidget *self, char* link, gpointer user_data); void help(); #endif diff --git a/ubl-settings-datetime.glade b/ubl-settings-datetime.glade index e4e4767..a947538 100644 --- a/ubl-settings-datetime.glade +++ b/ubl-settings-datetime.glade @@ -27,8 +27,8 @@ 5 5 5 - 6 - 6 + 5 + 5 50 gtk-dialog-warning @@ -45,8 +45,8 @@ False start center - 6 - 6 + 5 + 5 Enter DHCP ! @@ -96,7 +96,7 @@ ubl-settings-datetime 1.0 Copyright © 2022 - 2023, UBSoft LLC - Setting the date and time + Date and Time https://ublinux.ru/ Project Home Page Это приложение распространяется без каких-либо гарантий. @@ -163,8 +163,8 @@ 5 5 5 - 6 - 6 + 5 + 5 69 com.ublinux.ubl-settings-datetime @@ -192,7 +192,8 @@ 255 True False - Date and time settings + Date and Time + 0.25 @@ -271,7 +272,7 @@ False 4 - + True False Help @@ -354,8 +355,8 @@ 5 5 5 - 6 - 6 + 5 + 5 25 1 @@ -374,8 +375,8 @@ 5 5 5 - 6 - 6 + 5 + 5 @@ -473,8 +474,8 @@ 5 5 5 - 6 - 6 + 5 + 5 Time: True 0 @@ -493,8 +494,8 @@ 5 5 5 - 6 - 6 + 5 + 5 2 0.099999999776482579 True @@ -525,8 +526,8 @@ 5 5 5 - 6 - 6 + 5 + 5 2 True @@ -552,8 +553,8 @@ 5 5 5 - 6 - 6 + 5 + 5 Date: True 0 @@ -564,26 +565,6 @@ 4 - - - -1 - True - True - Date -Format: DD.MM.YYYY - 5 - 5 - 5 - 5 - 6 - 6 - - - True - True - 5 - - True @@ -594,8 +575,8 @@ Format: DD.MM.YYYY 10 5 10 - 6 - 6 + 5 + 5 True @@ -607,7 +588,27 @@ Format: DD.MM.YYYY False True - 6 + 5 + + + + + -1 + True + True + Date +Format: DD.MM.YYYY + 5 + 5 + 5 + 5 + 5 + 5 + + + True + True + 5 @@ -631,8 +632,8 @@ Format: DD.MM.YYYY 5 7 5 - 6 - 6 + 5 + 5 True @@ -709,8 +710,8 @@ Format: DD.MM.YYYY 10 5 10 - 6 - 6 + 5 + 5 True @@ -792,8 +793,8 @@ Format: DD.MM.YYYY 5 5 5 - 6 - 6 + 5 + 5 False @@ -811,8 +812,8 @@ Format: DD.MM.YYYY 10 5 10 - 6 - 6 + 5 + 5 True @@ -879,7 +880,7 @@ Format: DD.MM.YYYY 5 8 5 - 6 + 5 13 Synchronize hardware time: @@ -897,7 +898,7 @@ Format: DD.MM.YYYY 5 5 10 - 6 + 5 10 False False @@ -938,7 +939,7 @@ Format: DD.MM.YYYY 5 8 5 - 6 + 5 13 Region: 0 @@ -957,7 +958,7 @@ Format: DD.MM.YYYY 5 5 5 - 6 + 5 10 False False @@ -976,7 +977,7 @@ Format: DD.MM.YYYY 5 5 5 - 6 + 5 13 Area: 0 @@ -987,6 +988,18 @@ Format: DD.MM.YYYY 4 + + + 5 + True + False + + + False + True + 5 + + True @@ -995,7 +1008,7 @@ Format: DD.MM.YYYY 5 5 5 - 6 + 5 10 False False @@ -1006,18 +1019,6 @@ Format: DD.MM.YYYY 5 - - - 5 - True - False - - - False - True - 6 - - True @@ -1321,7 +1322,7 @@ Format: DD.MM.YYYY 20 20 dialog-warning-symbolic - 6 + 5 False @@ -1422,7 +1423,7 @@ Format: DD.MM.YYYY 20 20 dialog-question-symbolic - 6 + 5 False diff --git a/ubl-settings-datetime.pot b/ubl-settings-datetime.pot index 2110e3a..a570d35 100644 --- a/ubl-settings-datetime.pot +++ b/ubl-settings-datetime.pot @@ -2030,7 +2030,7 @@ msgstr "" #: source/ubl-settings-datetime.h:85 source/ubl-settings-datetime.h:84 #: source/ubl-settings-datetime.cc:169 msgid "" -"You will be redirected to documentation site, where user help pages are " +"You will be redirected to documentation website where documentation is\n" "translated and supported by community." msgstr "" diff --git a/ubl-settings-datetime_ru.po b/ubl-settings-datetime_ru.po index d25c7fd..0812ab1 100644 --- a/ubl-settings-datetime_ru.po +++ b/ubl-settings-datetime_ru.po @@ -78,7 +78,7 @@ msgstr "О программе" #: source/ubl-settings-datetime.h:71 source/ubl-settings-datetime.h:70 #: source/ubl-settings-datetime.cc:137 msgid "About ubl-settings-datetime" -msgstr "О программе Настройка даты и времени" +msgstr "О программе Дата и время" msgid "Accra" msgstr "Аккра" @@ -2058,10 +2058,10 @@ msgstr "Ереван" #: source/ubl-settings-datetime.h:85 source/ubl-settings-datetime.h:84 #: source/ubl-settings-datetime.cc:169 msgid "" -"You will be redirected to documentation site, where user help pages are " +"You will be redirected to documentation website where documentation is\n" "translated and supported by community." msgstr "" -"Вы будете перенаправлены на сайт с документацией где страницы помощи " +"Вы будете перенаправлены на сайт с документацией где страницы помощи\n" "переводятся и поддерживаются сообществом." msgid "Yukon" @@ -2097,17 +2097,12 @@ msgid "" msgstr "" "https://wiki.ublinux.ru/ru/Программное_обеспечение/Программы_и_утилиты/Все/" -#: source/ubl-settings-datetime.cc:174 -#, fuzzy -msgid "ubl-settings-bootloader" -msgstr "О программе Загрузка системы" - #: source/ubl-settings-datetime.h:67 source/ubl-settings-datetime.h:66 #: source/ubl-settings-datetime.cc:131 source/ubl-settings-datetime.cc:155 #: source/ubl-settings-datetime.cc:156 source/ubl-settings-datetime.cc:151 #: source/ubl-settings-datetime.cc:146 msgid "ubl-settings-datetime" -msgstr "Настройка даты и времени" +msgstr "Дата и время" #: source/ubl-settings-datetime.h:87 source/ubl-settings-datetime.h:86 #: source/ubl-settings-datetime.cc:1714 source/ubl-settings-datetime.cc:1651