diff --git a/source/ubl-settings-bootloader.cc b/source/ubl-settings-bootloader.cc index 271baed..e3c8ca9 100644 --- a/source/ubl-settings-bootloader.cc +++ b/source/ubl-settings-bootloader.cc @@ -44,6 +44,15 @@ SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr build show_all_children(); } +int MainWindow::check_root() { + if (geteuid() != 0) { + //lblMessageSudo->set_text(_("The program must be run with \nsuperuser privileges!")); + //mess_sudo->show(); + return 1; + } + return 0; +} + MainWindow::MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder) : Gtk::ApplicationWindow(obj), builder{builder} { this->builder = builder; @@ -59,9 +68,20 @@ void MainWindow::settings(){ map_cmd_error[""] = ""; this->get_builder(); this->localization(); - ubl_make_plugs(boxSave,boxButton, socket_ext_id_I, socket_trd_id_I); this->add_CSS(); this->event(); + ubl_make_plugs(boxSave,boxButton, socket_ext_id_I, socket_trd_id_I); + if (this->check_root() == 0) { + + } + else{ + imgInfo->set("/usr/share/icons/hicolor/scalable/status/warning.svg"); + info_status_app("boxInfoMessError"); + lblWarning->set_text(_("The program must be run with superuser privileges!")); + } + + + } void MainWindow::get_monitor_size(){ @@ -138,65 +158,68 @@ void MainWindow::get_builder(){ builder->get_widget("btnSave", btnSave); builder->get_widget("boxButton", boxButton); builder->get_widget("boxSave", boxSave); + builder->get_widget("boxInfoError", boxInfoError); + builder->get_widget("lblWarning", lblWarning); + builder->get_widget("imgInfo", imgInfo); } void MainWindow::localization(){ time_t now = time(0); tm *ltm = localtime(&now); unsigned int year = 1900+ ltm->tm_year; - string str_authors = string(gettext("Copyright © UBSoft LLC, 2022 - ")) + to_string(year); + string str_authors = string(_("Copyright © UBSoft LLC, 2022 - ")) + to_string(year); aboutWindows->set_copyright(str_authors); - aboutWindows->set_comments(gettext("ubl-settings-bootloader")); - aboutWindows->set_website(gettext("https://wiki.ublinux.com")); - aboutWindows->set_version(gettext(version_application.c_str())); - aboutWindows->set_website_label(gettext("Project Home Page")); - lblInfoHead->set_text(gettext("Configuring system boot parameters")); - lblHeaderName->set_text(gettext("UBConfig - Loading")); - aboutWindows->set_comments(gettext("Setting bootloader")); - aboutWindows->set_website_label(gettext("Project Home Page")); - lblInfoCommand->set_text(gettext("Command line parameters:")); - lblInfoCommand1->set_text(gettext("Command line parameters:")); - lblInfoCommand2->set_text(gettext("Command line parameters:")); - lblInfoDefaultDonw->set_text(gettext("Default download")); - lblInfoSeconds->set_text(gettext("Seconds")); - lblDownloadMenu->set_text(gettext("Download menu")); - lblInfoInputTerminal->set_text(gettext("Input terminal")); - lblInfoOutputTerminal->set_text(gettext("Output terminal")); + aboutWindows->set_comments(_("ubl-settings-bootloader")); + aboutWindows->set_website(_("https://wiki.ublinux.com")); + aboutWindows->set_version(_(version_application.c_str())); + aboutWindows->set_website_label(_("Project Home Page")); + lblInfoHead->set_text(_("Configuring system boot parameters")); + lblHeaderName->set_text(_("UBConfig - Loading")); + aboutWindows->set_comments(_("Setting bootloader")); + aboutWindows->set_website_label(_("Project Home Page")); + lblInfoCommand->set_text(_("Command line parameters:")); + lblInfoCommand1->set_text(_("Command line parameters:")); + lblInfoCommand2->set_text(_("Command line parameters:")); + lblInfoDefaultDonw->set_text(_("Default download")); + lblInfoSeconds->set_text(_("Seconds")); + lblDownloadMenu->set_text(_("Download menu")); + lblInfoInputTerminal->set_text(_("Input terminal")); + lblInfoOutputTerminal->set_text(_("Output terminal")); - chbLoadVariantSelectionTimer->set_label(gettext("Load variant selection timer")); - chbLastSelectionWillBecome->set_label(gettext("The last selection will become the default boot choice")); - chbQuiet->set_label(gettext("quiet (Downloading without text messages)")); - chbSplash->set_label(gettext("splash (Show welcome window)")); - chbPlymouth->set_label(gettext("no plymouth (Disable Plymouth)")); - chbAcpi->set_label(gettext("acpi=off (Disable ACPI)")); - chbNоapic->set_label(gettext("nоapic (Disable APIC)")); - chbNolapic->set_label(gettext("nolapic (Disable local APIC)")); - chbSingle->set_label(gettext("single (Single User Mode)")); - chbHomodeset->set_label(gettext("nomodeset (Disable kernel selection and loading of video drivers)")); - chbI915Enable->set_label(gettext("i915.enable_dc=0 (Disable GPU power management)")); - chbAhci->set_label(gettext("ahci.mobile_jpm_policy=1 (Maximum performance, power management)")); - chbSndIntel->set_label(gettext("snd-intel-dspcfg.dsp_driver=1 (Forced selection of a sound device driver from Intel)")); - chbintelMax1->set_label(gettext("intel_idle max_cstate=1 (Prevents the processor from going into a deep sleep state)")); - chbintelMax4->set_label(gettext("intel_idle.max_cstate=4 (Eliminates flickering laptop display on processors Ultra Voltage)")); - chbconsoleIT->set_label(gettext("console (PC BIOS & console EFI)")); - chbSerialIT->set_label(gettext("serial (Serial terminal)")); - chbofConsoleIT->set_label(gettext("ofconsole (Console Open Firmware)")); - chbAtKeyboard ->set_label(gettext("at_keyboard (Keyboard PC AT (Coreboot))")); - chbUsbKeyboard->set_label(gettext("usb_keyboard (Keyboard USB Keyboard (protocol HID Boot))")); - chbofConsoleOT->set_label(gettext("ofconsole (Console Open Firmware)")); - chbSerialOT->set_label(gettext("serial (Serial terminal)")); - chbconsoleOT->set_label(gettext("console (PC BIOS & console EFI)")); - chbGfxterm->set_label(gettext("gfxterm (Output in graphical mode)")); - chbVgaText->set_label(gettext("chbVgaText")); - btnSynopsis->set_label(gettext("Help")); - btnAbout->set_label(gettext("About")); - btnSaveLocalGlob->set_label(gettext("Save to global and local configuration")); - btnSaveLocal->set_label(gettext("Save local configuration")); - btnSaveGlob->set_label(gettext("Save global configuration")); - btnDonwlolGlob->set_label(gettext("Load global configuration")); - btnDonwlodLocal->set_label(gettext("Load local configuration")); - btnSave->set_label(gettext("Save")); - btnDownload->set_label(gettext("Donwload")); + chbLoadVariantSelectionTimer->set_label(_("Load variant selection timer")); + chbLastSelectionWillBecome->set_label(_("The last selection will become the default boot choice")); + chbQuiet->set_label(_("quiet (Downloading without text messages)")); + chbSplash->set_label(_("splash (Show welcome window)")); + chbPlymouth->set_label(_("no plymouth (Disable Plymouth)")); + chbAcpi->set_label(_("acpi=off (Disable ACPI)")); + chbNоapic->set_label(_("nоapic (Disable APIC)")); + chbNolapic->set_label(_("nolapic (Disable local APIC)")); + chbSingle->set_label(_("single (Single User Mode)")); + chbHomodeset->set_label(_("nomodeset (Disable kernel selection and loading of video drivers)")); + chbI915Enable->set_label(_("i915.enable_dc=0 (Disable GPU power management)")); + chbAhci->set_label(_("ahci.mobile_jpm_policy=1 (Maximum performance, power management)")); + chbSndIntel->set_label(_("snd-intel-dspcfg.dsp_driver=1 (Forced selection of a sound device driver from Intel)")); + chbintelMax1->set_label(_("intel_idle max_cstate=1 (Prevents the processor from going into a deep sleep state)")); + chbintelMax4->set_label(_("intel_idle.max_cstate=4 (Eliminates flickering laptop display on processors Ultra Voltage)")); + chbconsoleIT->set_label(_("console (PC BIOS & console EFI)")); + chbSerialIT->set_label(_("serial (Serial terminal)")); + chbofConsoleIT->set_label(_("ofconsole (Console Open Firmware)")); + chbAtKeyboard ->set_label(_("at_keyboard (Keyboard PC AT (Coreboot))")); + chbUsbKeyboard->set_label(_("usb_keyboard (Keyboard USB Keyboard (protocol HID Boot))")); + chbofConsoleOT->set_label(_("ofconsole (Console Open Firmware)")); + chbSerialOT->set_label(_("serial (Serial terminal)")); + chbconsoleOT->set_label(_("console (PC BIOS & console EFI)")); + chbGfxterm->set_label(_("gfxterm (Output in graphical mode)")); + chbVgaText->set_label(_("chbVgaText")); + btnSynopsis->set_label(_("Help")); + btnAbout->set_label(_("About")); + btnSaveLocalGlob->set_label(_("Save to global and local configuration")); + btnSaveLocal->set_label(_("Save local configuration")); + btnSaveGlob->set_label(_("Save global configuration")); + btnDonwlolGlob->set_label(_("Load global configuration")); + btnDonwlodLocal->set_label(_("Load local configuration")); + btnSave->set_label(_("Save")); + btnDownload->set_label(_("Donwload")); } @@ -215,23 +238,23 @@ void MainWindow::event(){ } void MainWindow::save_global_local_cfg(){ - -} - -void MainWindow::save_local_cfg(){ - + info_warning_error(4); } void MainWindow::save_global_cfg(){ - + info_warning_error(3); } -void MainWindow::download_local_cfg(){ - +void MainWindow::save_local_cfg(){ + info_warning_error(2); } void MainWindow::download_globl_cfg(){ + info_warning_error(1); +} +void MainWindow::download_local_cfg(){ + info_warning_error(0); } @@ -244,7 +267,63 @@ void MainWindow::wrapper_system(string cmd, string thread_str = "") { int response_cmd = system(cmd_new.c_str()); if (response_cmd != 0) { index_error += 1; - //this->log_mess_error(cmd); + this->log_mess_error(cmd); + } +} + +void MainWindow::info_status_app(string stule) { + Glib::RefPtr boxInfo = boxInfoError->get_style_context(); + boxInfo->remove_class("boxInfoMessOK"); + boxInfo->remove_class("boxInfoMessError"); + boxInfo->add_class(stule); +} + +void MainWindow::info_warning_error(int mess) { + if (index_error > 0) { + info_status_app("boxInfoMessError"); + imgInfo->set("/usr/share/icons/hicolor/scalable/status/warning.svg"); + index_error = 0; + string mess_error = ""; + if (mess == 0) { + mess_error = string(_("Local configuration reading error")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + else if (mess == 1) { + mess_error = string(_("Global configuration read error")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + else if (mess == 2) { + mess_error = string(_("Local configuration write error")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + else if (mess == 3) { + mess_error = string(_("Global configuration write error")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + else if (mess == 4) { + mess_error = string(_("Error saved local and global configuration")) + str_cmd_error; + lblWarning->set_text(mess_error); + } + str_cmd_error = ""; + } + else { + info_status_app("boxInfoMessOK"); + imgInfo->set("/usr/share/icons/hicolor/scalable/status/checked.svg"); + if (mess == 0) { + lblWarning->set_text(_("Local configuration downloaded successfully")); + } + else if (mess == 1) { + lblWarning->set_text(_("Global configuration downloaded successfully")); + } + else if (mess == 2) { + lblWarning->set_text(_("Local configuration successfully written")); + } + else if (mess == 3) { + lblWarning->set_text(_("Global configuration successfully written")); + } + else if (mess == 4) { + lblWarning->set_text(_("Successfully saved local and global configuration")); + } } } diff --git a/source/ubl-settings-bootloader.h b/source/ubl-settings-bootloader.h index c107e1e..e552999 100644 --- a/source/ubl-settings-bootloader.h +++ b/source/ubl-settings-bootloader.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "ubl-util-standard.c" using namespace std; @@ -93,7 +94,9 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::Button *btnSettings; Gtk::Widget *boxButton; Gtk::Widget *boxSave; - + Gtk::Box *boxInfoError; + Gtk::Label *lblWarning; + Gtk::Image *imgInfo; private: int width; @@ -132,6 +135,9 @@ class MainWindow : public Gtk::ApplicationWindow { void save_global_cfg(); void download_local_cfg(); void download_globl_cfg(); + void info_status_app(string stule); + void info_warning_error(int mess); + int check_root(); }; class SettingsPlug : public Gtk::Plug{ diff --git a/ubl-settings-bootloader_ru.po b/ubl-settings-bootloader_ru.po index ab3e5cd..d650a7b 100644 --- a/ubl-settings-bootloader_ru.po +++ b/ubl-settings-bootloader_ru.po @@ -166,3 +166,9 @@ msgstr "Успешно записана глобальная конфигура msgid "Local configuration successfully written" msgstr "Успешно записана локальная конфигурация" +msgid "The program must be run with \nsuperuser privileges!" +msgstr "Программа должна быть запущена с правами \nсуперпользователя!" + +msgid "The program must be run with superuser privileges!" +msgstr "Программа должна быть запущена с правами суперпользователя!" +