From eae2a16ecf8fd0cd46663e3dc5b3cfc356bd62c4 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Mon, 24 Apr 2023 11:19:42 +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=20webkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/CMakeLists.txt | 24 ++++- source/my_cmd.h | 7 ++ source/ublexec.cc | 66 ++++++++++-- source/ublexec.h | 22 ++++ source/ublexec.h.in | 1 + ublexec.glade | 233 ++++++++++++++++++++++++++++++++++++++++++ ublexec.pot | 17 +++ ublexec_ru.po | 22 +++- 8 files changed, 380 insertions(+), 12 deletions(-) create mode 100644 source/my_cmd.h create mode 100644 source/ublexec.h.in diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index ab85d20..25b3ce3 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -8,13 +8,28 @@ include_directories(${GTK_INCLUDE_DIRS}) link_directories(${GTK_LIBRARY_DIRS}) add_definitions(${GTK_CFLAGS_OTHER}) +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(ublexec.h.in ublexec-cm.h) + #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 \ -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 + ublexec-cm.h main.cc ublexec.cc ublexec.h @@ -26,5 +41,10 @@ set(LIBRARIES pthread) add_executable(ublexec ${SOURCE_FILES}) -target_link_libraries(ublexec ${LIBRARIES}) + +target_link_libraries(ublexec PUBLIC ${WEBKIT_LIBRARIES} ${LIBRARIES}) +target_include_directories(ublexec PUBLIC + "${PROJECT_BINARY_DIR}" + ${WEBKIT_INCLUDE_DIRS} + ) install(TARGETS ublexec DESTINATION bin) diff --git a/source/my_cmd.h b/source/my_cmd.h new file mode 100644 index 0000000..3047992 --- /dev/null +++ b/source/my_cmd.h @@ -0,0 +1,7 @@ +#ifndef MY_CMD_H +#define MY_CMD_H + +#define link_doc "https://wiki.ublinux.com/ru/Программное_обеспечение/Программы_и_утилиты/Все/ublexec" +#define cmd_xdg "xdg-open " +#define cmd_execute "su -l %s -c \" DISPLAY=$DISPLAY %s \"" +#endif \ No newline at end of file diff --git a/source/ublexec.cc b/source/ublexec.cc index 39e5f01..b5c3afe 100644 --- a/source/ublexec.cc +++ b/source/ublexec.cc @@ -7,7 +7,7 @@ const string path_css = "/usr/share/ublexec/css/ublexec.css"; const string app_name = "ublexec"; int flag_prog_file = 0; string name_app_cmd = ""; -string version_application = "2.23"; +string version_application = "2.24"; const string path_img_head_background = "/usr/share/ublexec/images/logo-background.png"; int socket_ext_id_I = 0; int socket_trd_id_I = 0; @@ -111,6 +111,19 @@ void MainWindow::get_builder() { builder->get_widget("btnBoxAboutDialog", btnBoxAboutDialog); builder->get_widget("boxAbout", boxAbout); builder->get_widget("cmbTerminal", cmbTerminal); + + 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); + builder->get_widget("lblHeadeWndWeb", lblHeadeWndWeb); + + #ifdef WEBKIT_FOUND + builder->get_widget("wndWeb", wndWeb); + #endif } void MainWindow::set_icon_array() { @@ -195,9 +208,21 @@ void MainWindow::localization() { btnListApp->set_tooltip_text(gettext("Application Overview")); btnFilemaneg->set_tooltip_text(gettext("File Overview")); btnMessageErrorOk->set_label(gettext("Close")); + 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")); + lblHeadeWndWeb->set_label(_("Run as...")); } 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)); btnFilemaneg->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::open_filemaneg)); btnListApp->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::open_list_app)); btnStart->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::entry_app)); @@ -323,12 +348,32 @@ bool MainWindow::focus_in_txt_cmd(GdkEventFocus* event) { } void MainWindow::synopsis_show() { - string cmd = "xdg-open " + string(gettext("https://wiki.ublinux.com/ru/Программное_обеспечение/Программы_и_утилиты/Все/")) + app_name + " &"; - if (geteuid() == 0) { - string response_user = getlogin(); - cmd = "su -l " + response_user + " -c \" DISPLAY=$DISPLAY " + cmd + " \""; + if (flag_open_browser == true) { + this->open_browser(); } - index_error = system(cmd.c_str()); + 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 ); + } + index_error = system(cmd.c_str()); + #endif } void MainWindow::icon_clear() { @@ -456,7 +501,11 @@ void MainWindow::settings() { btnBoxAboutDialog->set_visible(false); cmbTerminal->set_sensitive(false); ubl_make_plugs(boxAbout, boxAbout, socket_ext_id_I, 0); - + #ifdef WEBKIT_FOUND + one = WEBKIT_WEB_VIEW( webkit_web_view_new() ); + three = Glib::wrap(GTK_WIDGET(one)); + wndWeb->add(*three); + #endif } void MainWindow::close_entry_app() { @@ -975,6 +1024,9 @@ SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr build show_all_children(); } +MainWindow::~MainWindow() { +} + void help() { string help = "GTK \"Run applications as another user with the specified priority\" for UBLinux\n\n" "Usage: ublexec [OPTIONS...]\n" diff --git a/source/ublexec.h b/source/ublexec.h index 407423d..3a715a4 100644 --- a/source/ublexec.h +++ b/source/ublexec.h @@ -17,6 +17,11 @@ #include #include #include "ubl-util-standard.c" +#include "ublexec-cm.h" +#include "my_cmd.h" +#ifdef WEBKIT_FOUND +#include +#endif using namespace std; @@ -46,6 +51,7 @@ class MainWindow : public Gtk::ApplicationWindow { public: MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); MainWindow(Glib::RefPtr const& builder); + ~MainWindow(); void template_apps_obj(Gtk::IconView *icon, Glib::RefPtr >k_list_app); void get_builder(); void add_CSS(); @@ -93,6 +99,7 @@ public: void denamic_cmd(); void is_user_wheel(); void sudo_nice(); + void open_browser(); vector find_all(string &text, string &word); bool focus_out_txt_cmd(GdkEventFocus* event); bool focus_in_txt_cmd(GdkEventFocus* event); @@ -205,6 +212,20 @@ public: Gtk::Image *imgHeadBackground; Gtk::Overlay *overHead; Gtk::Widget *boxAbout; + + Gtk::Label *lblHeadeWndWeb; + Gtk::Label *lblwebHeaderName; + Gtk::Label *lblhelpText; + Gtk::Label *lblhelpHeader; + Gtk::CheckButton *chkAlwaysOpenHelp; + Gtk::Button *btnReadHelp; + Gtk::Button *btnCancelHelp; + Gtk::Window *wndShowWeb; + #ifdef WEBKIT_FOUND + Gtk::Window *wndWeb; + Gtk::Widget *three; + WebKitWebView *one; + #endif public: string termunal_cmd[3] = {"konsole -e ", "xfce4-terminal -x ", "xterm -e "}; string cmd_old = ""; @@ -220,6 +241,7 @@ public: bool flag_pkexec = false; bool flag_su = false; bool flag_sudo = false; + bool flag_open_browser = false; string path_file_name; struct struct_App { string Name_desktop; diff --git a/source/ublexec.h.in b/source/ublexec.h.in new file mode 100644 index 0000000..17ba454 --- /dev/null +++ b/source/ublexec.h.in @@ -0,0 +1 @@ +#cmakedefine WEBKIT_FOUND \ No newline at end of file diff --git a/ublexec.glade b/ublexec.glade index 58c1d97..340b734 100644 --- a/ublexec.glade +++ b/ublexec.glade @@ -2060,4 +2060,237 @@ with the specified priority + + 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 + ublexec + + + + + + + + True + False + 32 + dialog-question-symbolic + + + + + + + 800 + 600 + False + True + True + com.ublinux.ubl-settings-datetime + + + + + + True + False + True + + + True + False + ublexec + + + + + True + False + 32 + com.ublinux.ubl-settings-datetime + 5 + + + + + diff --git a/ublexec.pot b/ublexec.pot index 9b8de70..d0fdbe4 100644 --- a/ublexec.pot +++ b/ublexec.pot @@ -17,6 +17,23 @@ 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/ublexec_ru.po b/ublexec_ru.po index d069d6b..b35777c 100644 --- a/ublexec_ru.po +++ b/ublexec_ru.po @@ -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 "Always redirect" +msgstr "Всегда перенаправлять" + +msgid "Read online" +msgstr "Прочитать онлайн" + #: source/ublexec.cc:163 msgid " Run as..." msgstr "О программе ublexec" @@ -48,9 +67,6 @@ msgstr "О программе" msgid "Application Overview" msgstr "Обзор приложений" -msgid "Cancel" -msgstr "Отмена" - #: source/ublexec.cc:177 source/ublexec.cc:173 msgid "Change startup priority" msgstr "Изменить приоритет запуска"