diff --git a/source/ubl-settings-bootloader.cc b/source/ubl-settings-bootloader.cc index 18c06ab..241e9ca 100755 --- a/source/ubl-settings-bootloader.cc +++ b/source/ubl-settings-bootloader.cc @@ -169,7 +169,7 @@ void MainWindow::get_download_mode(string cmd, std::map &map_te int start_error = index_error; struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { - str_replace_all(res_response.response, "\"",""); + Utils::str_replace_all(res_response.response, "\"",""); if (res_response.response == "splash") { cmbDownloadMode->set_active(0); map_temp["GRUB_BOOT_SILENT"] = "splash"; @@ -274,8 +274,8 @@ void MainWindow::get_security_login(string cmd, std::map &map_t // Убрать в будущем string default_login = "superadmin"; if (res_response.error == 0) { - str_replace_all(res_response.response, " ",""); - str_replace_all(res_response.response, "\"",""); + Utils::str_replace_all(res_response.response, " ",""); + Utils::str_replace_all(res_response.response, "\"",""); if (res_response.response.length() > 0) { chbSecurityLogin->set_active(1); map_temp["GRUB_USER"] = res_response.response; @@ -343,7 +343,7 @@ void MainWindow::get_password_protec(string cmd, std::map &map_ int start_error = index_error; struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { - str_replace_all(res_response.response, "\"",""); + Utils::str_replace_all(res_response.response, "\"",""); if (res_response.response.length() != 0) { chbPasswordProtecc->set_active(1); map_temp["GRUB_PASSWORD"] = res_response.response; @@ -402,7 +402,7 @@ string MainWindow::dynamic_update_entry(std::map &map_view, vect vector MainWindow::read_file_and_view(string file_name ,Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m) { - std::array, 5> arr_view = read_csv(path_resources + "/" + file_name); + std::array, 5> arr_view = Utils::read_csv(path_resources + "/" + file_name); std::vector vec_Option = arr_view[0]; for (size_t index = 0; index < vec_Option.size(); index++) { @@ -540,15 +540,15 @@ vector MainWindow::get_setting_entry_all(string key, string cmd, Gtk::En vector vec_params; struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { - str_replace_all(res_response.response, "\"", ""); - vec_params = split(res_response.response, ' '); - str_replace_all(res_response.response, " ", ", "); + Utils::str_replace_all(res_response.response, "\"", ""); + vec_params = Utils::split(res_response.response, ' '); + Utils::str_replace_all(res_response.response, " ", ", "); entry_text.set_text(res_response.response); for (auto ¶m: vec_params) { map_cmd_selection[param] = "1"; map_temp[param] = "1"; } - str_remove(res_response.response, ","); + Utils::str_remove(res_response.response, ","); map_temp[key] = res_response.response; } else if (res_response.error == 3) { @@ -609,8 +609,8 @@ void MainWindow::set_entry_to_tree_view(Glib::RefPtr &list_store flag_blocked_tree_view = true; vector vec_params; std::string text = entry.get_text(); - str_replace_all(text, " ", ""); - vec_params = split(text, ','); + Utils::str_replace_all(text, " ", ""); + vec_params = Utils::split(text, ','); for (auto &name: vec_Option) { this->set_row(list_store, size, name, false); } @@ -680,10 +680,10 @@ void MainWindow::set_menu_boot(string cmd = "", string cmd_remove = "") { void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove) { string cmds = entry.get_text(); - str_remove(cmds, ","); + Utils::str_remove(cmds, ","); if (cmds.length() != 0) { cmd_settings += "\"" + cmds + "\""; - str_replace_all(cmd_settings, " \"", "\""); + Utils::str_replace_all(cmd_settings, " \"", "\""); this->wrapper_system(cmd_settings, ""); } else { @@ -709,6 +709,7 @@ void MainWindow::event(){ chbSecurityLogin->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::change_security_login)); cmbDownloadMode->signal_changed().connect([&]() {set_download_mode();}); chbSecurityLogin->signal_changed().connect([&]() {set_security_login();}); + cmbDefaultDonw->signal_changed().connect([&]() {set_default_load("","");}); spbSecond->signal_changed().connect([&]() {set_menu_boot();}); if (this->check_root() == 0) { Glib::RefPtr treeViewKernelModel = treeViewKernel->get_model(); @@ -742,6 +743,55 @@ void MainWindow::change_security_login() { boxSave->set_sensitive(true); } } +void MainWindow::set_default_load(string cmd = "", string cmd_remove = "") { + int index = cmbDefaultDonw->get_active_row_number(); + if (index == 0) { + if (cmd.length() != 0) { + wrapper_system(cmd, ""); + } + else { + flag_save_local = true; + flag_save_global = true; + flag_save_all = true; + } + } + else if (index > 0) { + if (cmd_remove.length() != 0) { + wrapper_system(cmd_remove, ""); + } + else { + flag_save_local = true; + flag_save_global = true; + flag_save_all = true; + } + } + if (index != 0 && index != -1) { + map_cmd_selection["GRUB_DEFAULT"] = cmbDefaultDonw->get_active_text(); + } + else { + map_cmd_selection["GRUB_DEFAULT"] = ""; + } +} + +void MainWindow::get_default_load(string cmd, std::map &map_temp) { + int start_error = index_error; + struct Result res_response = this->wrapper_call(cmd); + if (res_response.error == 0) { + map_temp["GRUB_DEFAULT"] = res_response.response; + cmbDefaultDonw->set_active_text(res_response.response); + } + else if (res_response.error == 3) { + if (start_error != index_error) { + index_error = start_error; + cmbDefaultDonw->set_active(0); + } + map_temp["GRUB_DEFAULT"] = ""; + + } + else { + map_temp["GRUB_DEFAULT"] = ""; + } +} void MainWindow::change_password_protecc() { int index = chbPasswordProtecc->get_active_row_number(); @@ -835,6 +885,12 @@ bool MainWindow::save_global_cfg() { this->set_password_protec(cmd_password, cmd_password_remove); flag_no_save = false; } + if (this->check_save(flag_save, "GRUB_DEFAULT")) { + string cmd_load = "ubconfig --target global set boot GRUB_DEFAULT="; + string cmd_load_remove = "ubconfig --target global remove boot GRUB_DEFAULT"; + this->set_default_load(cmd_load, cmd_load_remove); + flag_no_save = false; + } } } map_global_cmd_selection = map_cmd_selection; @@ -897,6 +953,13 @@ bool MainWindow::save_local_cfg() { this->set_password_protec(cmd_password, cmd_password_remove); flag_no_save = false; } + if (this->check_save(flag_save, "GRUB_DEFAULT")) { + string cmd_load = "ubconfig --target system set boot GRUB_DEFAULT="; + string cmd_load_remove = "ubconfig --target system remove boot GRUB_DEFAULT"; + this->set_default_load(cmd_load, cmd_load_remove); + flag_no_save = false; + } + } } map_local_cmd_selection = map_cmd_selection; @@ -905,16 +968,16 @@ bool MainWindow::save_local_cfg() { void MainWindow::set_data_cfg() { string str_flags = entryKernel->get_text(); - str_remove(str_flags, ","); - str_replace_all(str_flags, " \"", "\""); + Utils::str_remove(str_flags, ","); + Utils::str_replace_all(str_flags, " \"", "\""); map_cmd_selection["GRUB_CMDLINE_LINUX"] = str_flags; str_flags = entryIPT->get_text(); - str_remove(str_flags, ","); - str_replace_all(str_flags, " \"", "\""); + Utils::str_remove(str_flags, ","); + Utils::str_replace_all(str_flags, " \"", "\""); map_cmd_selection["GRUB_TERMINAL_INPUT"] = str_flags; str_flags = entryOTT->get_text(); - str_remove(str_flags, ","); - str_replace_all(str_flags, " \"", "\""); + Utils::str_remove(str_flags, ","); + Utils::str_replace_all(str_flags, " \"", "\""); map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = str_flags; } @@ -940,6 +1003,7 @@ void MainWindow::download_globl_cfg() { this->get_download_mode("ubconfig --default --source global get boot GRUB_BOOT_SILENT", map_global_cmd_selection); this->get_security_login("ubconfig --default --source global get boot GRUB_USER", map_global_cmd_selection); this->get_password_protec("ubconfig --default --source global get boot GRUB_PASSWORD", map_global_cmd_selection); + this->get_default_load("ubconfig --default --source global get boot GRUB_DEFAULT", map_global_cmd_selection); info_warning_error(1); map_cmd_selection = map_global_cmd_selection; @@ -967,6 +1031,7 @@ void MainWindow::download_local_cfg() { this->get_download_mode("ubconfig --default --source system get boot GRUB_BOOT_SILENT", map_local_cmd_selection); this->get_security_login("ubconfig --default --source system get boot GRUB_USER", map_local_cmd_selection); this->get_password_protec("ubconfig --default --source system get boot GRUB_PASSWORD", map_local_cmd_selection); + this->get_default_load("ubconfig --default --source system get boot GRUB_DEFAULT", map_local_cmd_selection); info_warning_error(0); map_cmd_selection = map_local_cmd_selection; } @@ -1051,7 +1116,6 @@ void MainWindow::wrapper_system(string cmd, string thread_str = "") { } void MainWindow::info_status_app(string stule) { - boxInfo->remove_class("boxInfoMessOK"); boxInfo->remove_class("boxInfoMessError"); boxInfo->add_class(stule); @@ -1111,7 +1175,7 @@ void MainWindow::info_warning_error(int mess) { struct MainWindow::Result MainWindow::wrapper_call(string cmd) { struct Result obj_result; - string response = call(cmd); + string response = Utils::call(cmd); if ((response.find("(null)") == std::string::npos) && (response.length() != 0 )) { if (response.find("=") != std::string::npos) { if (response.find("\n") != std::string::npos) { @@ -1152,7 +1216,7 @@ void MainWindow::log_mess_error(string &cmd) { str_cmd_error = map_cmd_error[cmd]; } else { - for ( const auto &map_iter: map_cmd_error ) { + for (const auto &map_iter: map_cmd_error) { key = map_iter.first; if (cmd.find(key) != std::string::npos){ str_cmd_error = map_iter.second; diff --git a/source/ubl-settings-bootloader.h b/source/ubl-settings-bootloader.h index c6914e5..63466d1 100644 --- a/source/ubl-settings-bootloader.h +++ b/source/ubl-settings-bootloader.h @@ -137,6 +137,7 @@ class MainWindow : public Gtk::ApplicationWindow { MainWindow(Glib::RefPtr const& builder); void get_menu_boot(string cmd, std::map &map_temp); void set_menu_boot(string cmd, string cmd_remove); + void set_default_load(string cmd, string cmd_remove); void set_row_all(std::map &map_cmd, Glib::RefPtr &list_store, vector &list_params, size_t size); void set_row(Glib::RefPtr &list_store, int size, std::string name, bool flag_chbox); void get_builder(); @@ -179,6 +180,7 @@ class MainWindow : public Gtk::ApplicationWindow { void change_password_protecc(); bool focus_out_txt_login(GdkEventFocus*); void change_security_login(); + void get_default_load(string cmd, std::map &map_temp); bool focus_out_txt_password(GdkEventFocus*); void get_password_protec(string cmd, std::map &map_temp); void set_password_protec(string cmd, string cmd_remove); diff --git a/source/util.cc b/source/util.cc index ed9a3ce..8d8c496 100644 --- a/source/util.cc +++ b/source/util.cc @@ -1,5 +1,7 @@ #include "util.h" +namespace Utils { + array, 5> read_csv(const string& filename) { array, 5> array_vectors; vector vec_option; @@ -65,6 +67,7 @@ string call(string cmd) { } return path; } + vector find_all(string &str_ntp, string substr) { size_t index = 0; vector sub_index; @@ -181,4 +184,15 @@ string read_passwd(string username) { } in.close(); return passwd; +} + +int synopsis_show(string str_link) { + // gettext("https://wiki.ublinux.com/ru/Программное_обеспечение/Программы_и_утилиты/Все/") + string cmd = "xdg-open " + str_link; + if (geteuid() == 0) { + string response_user = getlogin(); + cmd = "su -l " + response_user + " -c \" DISPLAY=$DISPLAY " + cmd + " \""; + } + return system(cmd.c_str()); +} } \ No newline at end of file diff --git a/source/util.h b/source/util.h index 54b56fd..9044b95 100644 --- a/source/util.h +++ b/source/util.h @@ -1,3 +1,5 @@ +#ifndef UTIL_H +#define UTIL_H #include #include #include @@ -8,13 +10,26 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace std; +namespace Utils { template - struct Result{ - Type response; - int error; +struct Result{ + Type response; + int error; }; struct Passwd { @@ -31,3 +46,6 @@ std::vector split(std::string text, char delim); unsigned short read_uid_min_max(string filename, string search); vector pars_users(); string read_passwd(string username); +int synopsis_show(string str_link); +} +#endif \ No newline at end of file diff --git a/ubl-settings-bootloader.glade b/ubl-settings-bootloader.glade index d6bcd4a..2066813 100644 --- a/ubl-settings-bootloader.glade +++ b/ubl-settings-bootloader.glade @@ -12,10 +12,10 @@ False True center - ubl-settings-datetime + ubl-settings-bootloader dialog True - ubl-settings-datetime + ubl-settings-bootloader 1.2 Copyright © 2023 - UBSoft Software LLC ubl-settings-bootloader @@ -387,7 +387,7 @@ specified priority 5 6 6 - Default download + Default load start 0