From 294cdcf19f18c6b5e142d053cf56f547f61b6cfd Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Mon, 24 Apr 2023 10:27:40 +0600 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BE=D0=BA=D0=BD=D0=BE=20=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/CMakeLists.txt | 26 +++- source/my_cmd.h | 3 +- source/ubl-settings-datetime.cc | 58 ++++++- source/ubl-settings-datetime.h | 24 ++- source/ubl-settings-datetime.h.in | 1 + ubl-settings-datetime.glade | 251 ++++++++++++++++++++++++------ ubl-settings-datetime.pot | 19 +++ ubl-settings-datetime_ru.po | 22 +++ 8 files changed, 336 insertions(+), 68 deletions(-) create mode 100644 source/ubl-settings-datetime.h.in diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 00b511b..06976d8 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -4,16 +4,25 @@ project(ubl-settings-datetime) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED gtkmm-3.0) -pkg_check_modules(WEBKIT REQUIRED webkit2gtk-4.0 webkit2gtk-web-extension-4.0) -include_directories(${WEBKIT_INCLUDE_DIRS}) -link_directories(${WEBKIT_LIBRARY_DIRS}) -add_definitions(${WEBKIT_CFLAGS_OTHER}) - include_directories(${GTK_INCLUDE_DIRS}) link_directories(${GTK_LIBRARY_DIRS}) add_definitions(${GTK_CFLAGS_OTHER}) find_package(ICU REQUIRED COMPONENTS uc dt in io) +find_library(WEBKIT_LIBRARIES_FOUND webkit2gtk-4.0 webkit2gtk-web-extension-4.0) + +option(WEBKIT_FOUND "No" OFF) + +find_library(WEBKIT_LIBRARIES_FOUND webkit2gtk-4.0 webkit2gtk-web-extension-4.0) +if(WEBKIT_LIBRARIES_FOUND) + option(WEBKIT_FOUND "Yes" ON) + PKG_CHECK_MODULES(WEBKIT REQUIRED webkit2gtk-4.0 webkit2gtk-web-extension-4.0) + include_directories(${WEBKIT_INCLUDE_DIRS}) + link_directories(${WEBKIT_LIBRARY_DIRS}) + add_definitions(${WEBKIT_CFLAGS_OTHER}) +endif() +configure_file(ubl-settings-datetime.h.in ubl-settings-datetime-cm.h) + #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 \ -O2 -pipe -fno-plt -fexceptions \ @@ -21,6 +30,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissin -fstack-clash-protection -fcf-protection") set(SOURCE_FILES + ubl-settings-datetime-cm.h ubl-util-standard.h ubl-util-standard.c my_cmd.h @@ -33,5 +43,9 @@ set(LIBRARIES pthread) add_executable(ubl-settings-datetime ${SOURCE_FILES}) -target_link_libraries(ubl-settings-datetime ${LIBRARIES} ${ICU_LIBRARIES} ${WEBKIT_LIBRARIES}) +target_link_libraries(ubl-settings-datetime PUBLIC ${ICU_LIBRARIES} ${WEBKIT_LIBRARIES} ${LIBRARIES}) +target_include_directories(ubl-settings-datetime PUBLIC + "${PROJECT_BINARY_DIR}" + ${WEBKIT_INCLUDE_DIRS} + ) install(TARGETS ubl-settings-datetime DESTINATION bin) \ No newline at end of file diff --git a/source/my_cmd.h b/source/my_cmd.h index be562ae..7dbdc80 100644 --- a/source/my_cmd.h +++ b/source/my_cmd.h @@ -2,7 +2,8 @@ #define MY_CMD_H #define 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" #define get_global_NTPSERVERS "ubconfig --default --source global get network NTPSERVERS" #define get_system_ZONE "ubconfig --default --source system get clock ZONE" diff --git a/source/ubl-settings-datetime.cc b/source/ubl-settings-datetime.cc index ba39577..7a84818 100755 --- a/source/ubl-settings-datetime.cc +++ b/source/ubl-settings-datetime.cc @@ -92,9 +92,11 @@ void MainWindow::settings() { day = 0; this->lacalization(); btnBoxAboutDialog->set_visible(false); - one = WEBKIT_WEB_VIEW( webkit_web_view_new() ); - three = Glib::wrap( GTK_WIDGET( one ) ); - wndWeb->add( *three ); + #ifdef WEBKIT_FOUND + one = WEBKIT_WEB_VIEW( webkit_web_view_new() ); + three = Glib::wrap(GTK_WIDGET(one)); + wndWeb->add(*three); + #endif if (geteuid() == 0) { numTimeHrs->set_range(0, 23); numTimeMin->set_range(0, 59); @@ -162,6 +164,14 @@ void MainWindow::lacalization() { this->bubble_sort(array_hw, array_hw_local, 2); cbHw->append(array_hw_local[0]); cbHw->append(array_hw_local[1]); + + lblhelpHeader->set_text(_("Would you like to read documentation in the Web?")); + lblhelpText->set_text(_("You will be redirected to documentation site, where user help pages are " + "translated and supported by community.")); + btnReadHelp->set_label(_("Read online")); + btnCancelHelp->set_label(_("Cancel")); + chkAlwaysOpenHelp->set_label(_("Always redirect")); + lblwebHeaderName->set_label(_("ubl-settings-bootloader")); } void MainWindow::bubble_sort(string arr[],string arr_local[], int len_arr) { @@ -315,13 +325,26 @@ void MainWindow::get_builder() { builder->get_widget("boxWidgetFunc", boxWidgetFunc); builder->get_widget("overHead", overHead); builder->get_widget("imgHeadBackground", imgHeadBackground); - builder->get_widget("wndWeb", wndWeb); + #ifdef WEBKIT_FOUND + builder->get_widget("wndWeb", wndWeb); + #endif builder->get_widget("lblHeadeWndWeb", lblHeadeWndWeb); builder->get_widget("lblHeaderAboutTopic", lblHeaderAboutTopic); + builder->get_widget("lblwebHeaderName", lblwebHeaderName); + builder->get_widget("lblhelpText", lblhelpText); + builder->get_widget("lblhelpHeader", lblhelpHeader); + builder->get_widget("chkAlwaysOpenHelp", chkAlwaysOpenHelp); + builder->get_widget("btnReadHelp", btnReadHelp); + builder->get_widget("btnCancelHelp", btnCancelHelp); + builder->get_widget("wndShowWeb", wndShowWeb); } void MainWindow::event() { + 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)); 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)); @@ -389,9 +412,32 @@ void MainWindow::event_zone() { } void MainWindow::synopsis_show() { - webkit_web_view_load_uri(one, link_doc); - wndWeb->show_all(); + if (flag_open_browser == true) { + this->open_browser(); + } + else { + wndShowWeb->show_all(); + } + +} +void MainWindow::open_browser() { + #ifdef WEBKIT_FOUND + webkit_web_view_load_uri(one, link_doc); + wndWeb->show_all(); + #else + string cmd = cmd_xdg + string(gettext(link_doc)) + " &"; + 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 ); + } + obj_process_system.call(cmd, "&"); + #endif } void MainWindow::load_local_cfg() { diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index c702cd9..9b0dfa5 100644 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -17,10 +17,12 @@ #include #include #include -#include #include "ubl-util-standard.c" #include "my_cmd.h" - +#include "ubl-settings-datetime-cm.h" +#ifdef WEBKIT_FOUND +#include +#endif using namespace std; @@ -117,11 +119,22 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::Image *imgSettings; Gtk::Overlay *overHead; Gtk::Image *imgHeadBackground; - Gtk::Window *wndWeb; Gtk::Label *lblHeadeWndWeb; - Gtk::Widget *three; - WebKitWebView * one; Gtk::Label *lblHeaderAboutTopic; + + Gtk::Label *lblwebHeaderName; + Gtk::Label *lblhelpText; + Gtk::Label *lblhelpHeader; + Gtk::CheckButton *chkAlwaysOpenHelp; + Gtk::Button *btnReadHelp; + Gtk::Button *btnCancelHelp; + Gtk::Window *wndShowWeb; + bool flag_open_browser = false; + #ifdef WEBKIT_FOUND + Gtk::Window *wndWeb; + Gtk::Widget *three; + WebKitWebView *one; + #endif string array_hw[2]; string array_hw_local[2]; bool flag_load = false; @@ -162,6 +175,7 @@ class MainWindow : public Gtk::ApplicationWindow { public: MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); MainWindow(Glib::RefPtr const& builder); + void open_browser(); virtual ~MainWindow() = default; void log_mess_error(string &cmd); void set_hardware_clock(string &local, string &etc); diff --git a/source/ubl-settings-datetime.h.in b/source/ubl-settings-datetime.h.in new file mode 100644 index 0000000..17ba454 --- /dev/null +++ b/source/ubl-settings-datetime.h.in @@ -0,0 +1 @@ +#cmakedefine WEBKIT_FOUND \ No newline at end of file diff --git a/ubl-settings-datetime.glade b/ubl-settings-datetime.glade index 2622658..cba6c55 100644 --- a/ubl-settings-datetime.glade +++ b/ubl-settings-datetime.glade @@ -1,5 +1,5 @@ - + @@ -84,54 +84,6 @@ - - False - О Программе - False - True - center - com.ublinux.ubl-settings-datetime - dialog - True - False - False - ubl-settings-datetime - 1.2 - Copyright © 2023 - UBSoft Software LLC - 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 - com.ublinux.ubl-settings-datetime - True - gpl-2-0 - - - False - vertical - 2 - - - False - end - - - - - - False - False - 0 - - - - - - - - False False @@ -190,7 +142,7 @@ 5 5 2 - System quotas + ubl-settings-datetime @@ -1445,6 +1397,205 @@ Format: DD.MM.YYYY + + False + start + start + False + 450 + 250 + dialog-question-symbolic + + + True + False + vertical + + + True + False + + + True + False + start + 20 + 20 + dialog-question-symbolic + 6 + + + False + True + 0 + + + + + True + False + vertical + + + True + False + start + 10 + 5 + Would you like to read documentation in the Web? + True + 0 + + + + + + + False + True + 0 + + + + + True + False + start + start + 10 + 10 + You will be redirected to documentation website where documentation is translated and supported by community. + True + 0 + + + + True + True + 1 + + + + + Always redirect to online documentation + True + True + False + end + 10 + True + + + + False + True + 2 + + + + + + True + True + 1 + + + + + + True + True + 0 + + + + + True + False + 5 + 5 + 5 + 5 + 5 + 5 + 30 + True + + + Cancel + True + True + True + + + + True + True + 0 + + + + + Read Online + True + True + True + + + + True + True + 1 + + + + + False + True + 1 + + + + + + + True + False + + + True + False + ubl-settings-bootloader + + + + + + + + True + False + 32 + dialog-question-symbolic + + + + + 800 600 diff --git a/ubl-settings-datetime.pot b/ubl-settings-datetime.pot index 80bae74..d60a7e6 100644 --- a/ubl-settings-datetime.pot +++ b/ubl-settings-datetime.pot @@ -17,6 +17,25 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" + + +msgid "Would you like to read documentation in the Web?" +msgstr "" + +msgid "" +"You will be redirected to documentation site, where user help pages are " +"translated and supported by community." +msgstr "" + +msgid "Cancel" +msgstr "" + +msgid "Read online" +msgstr "" + +msgid "Always redirect" +msgstr "" + msgid ":" msgstr "" diff --git a/ubl-settings-datetime_ru.po b/ubl-settings-datetime_ru.po index b68c210..30f16a6 100644 --- a/ubl-settings-datetime_ru.po +++ b/ubl-settings-datetime_ru.po @@ -17,6 +17,28 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +msgid "Would you like to read documentation in the Web?" +msgstr "Вы хотите прочитать справку в Сети?" + +msgid "" +"You will be redirected to documentation site, where user help pages are " +"translated and supported by community." +msgstr "" +"Вы будете перенаправлены на сайт с документацией где страницы помощи " +"переводятся и поддерживаются сообществом." + +msgid "Cancel" +msgstr "Отменить" + +msgid "Always redirect" +msgstr "Всегда перенаправлять" + +msgid "Read online" +msgstr "Прочитать онлайн" + +msgid "About ubl-settings-bootloader" +msgstr "О программе Загрузка системы" + msgid ":" msgstr ":"