diff --git a/source/ubl-settings-bootloader.cc b/source/ubl-settings-bootloader.cc index 1c5f3bf..244f1e6 100755 --- a/source/ubl-settings-bootloader.cc +++ b/source/ubl-settings-bootloader.cc @@ -84,7 +84,9 @@ void MainWindow::settings(){ this->download_local_cfg(); this->download_globl_cfg(); entrySecurityLogin->set_sensitive(false); + this->set_active_boot_second(); this->event(); + } else{ boxWidgetAll->set_sensitive(false); @@ -93,6 +95,7 @@ void MainWindow::settings(){ imgInfo->set_from_icon_name("com.ublinux.ubl-settings-bootloader.warning", Gtk::ICON_SIZE_MENU); info_status_app("boxInfoMessError"); lblWarning->set_text(gettext("The program must be run as root")); + this->set_active_boot_second(); this->event(); } } @@ -114,7 +117,6 @@ void MainWindow::fill_in_view() { this->view_add_colums(*treeViewKernel); this->view_add_colums(*treeViewIPT); this->view_add_colums(*treeViewOTT); - std::vector treeViewKernalCol = treeViewKernel->get_columns(); } void MainWindow::item_selected_kernel(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&) { @@ -161,45 +163,44 @@ void MainWindow::item_selected_IPT(const Gtk::TreeModel::Path& path, const Gtk:: string str_flags = this->dynamic_update_entry(map_cmd_selection, vec_Option_IPT); entryIPT->set_text(str_flags); } - } -void MainWindow::get_download_mode(string cmd) { +void MainWindow::get_download_mode(string cmd, std::map &map_temp) { struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { str_replace_all(res_response.response, "\"",""); if (res_response.response == "splash") { cmbDownloadMode->set_active(0); - map_cmd_selection["GRUB_BOOT_SILENT"] = ""; + map_temp["GRUB_BOOT_SILENT"] = "splash"; } else if (res_response.response == "splash quiet ub.silent") { cmbDownloadMode->set_active(1); - map_cmd_selection["GRUB_BOOT_SILENT"] = ""; + map_temp["GRUB_BOOT_SILENT"] = "splash quiet ub.silent"; } else if (res_response.response == "quiet ub.silent") { cmbDownloadMode->set_active(2); - map_cmd_selection["GRUB_BOOT_SILENT"] = ""; + map_temp["GRUB_BOOT_SILENT"] = "quiet ub.silent"; } else if (res_response.response == "plymouth.enable=0") { cmbDownloadMode->set_active(3); - map_cmd_selection["GRUB_BOOT_SILENT"] = ""; + map_temp["GRUB_BOOT_SILENT"] = "plymouth.enable=0"; } else{ cmbDownloadMode->set_active(-1); - map_cmd_selection["GRUB_BOOT_SILENT"] = ""; + map_temp["GRUB_BOOT_SILENT"] = ""; } } else if (res_response.error == 3) { cmbDownloadMode->set_active(-1); - map_cmd_selection["GRUB_BOOT_SILENT"] = ""; + map_temp["GRUB_BOOT_SILENT"] = ""; } else { cmbDownloadMode->set_active(-1); - map_cmd_selection["GRUB_BOOT_SILENT"] = ""; + map_temp["GRUB_BOOT_SILENT"] = ""; } } -void MainWindow::set_download_mode(string cmd) { +void MainWindow::set_download_mode(string cmd="") { int index = cmbDownloadMode->get_active_row_number(); string key = ""; if (index == 0) { @@ -217,12 +218,15 @@ void MainWindow::set_download_mode(string cmd) { else{ return; } - cmd +="\"" + key + "\""; - wrapper_system(cmd, ""); + if (cmd.length() !=0 ) { + cmd +="\"" + key + "\""; + wrapper_system(cmd, ""); + } + map_cmd_selection["GRUB_BOOT_SILENT"] = key; } -void MainWindow::set_security_login(string cmd) { +void MainWindow::set_security_login(string cmd="") { int index = chbSecurityLogin->get_active_row_number(); string key = ""; if (index == 0){ @@ -237,41 +241,43 @@ void MainWindow::set_security_login(string cmd) { else { return; } - entrySecurityLogin->set_text(key); - cmd = cmd + key; - wrapper_system(cmd, ""); + if (cmd.length() != 0) { + entrySecurityLogin->set_text(key); + cmd = cmd + key; + wrapper_system(cmd, ""); + } + map_cmd_selection["GRUB_USER"] = key; } -void MainWindow::get_security_login(string cmd) { +void MainWindow::get_security_login(string cmd, std::map &map_temp) { struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { - cout << res_response.response << endl; str_replace_all(res_response.response, "\"",""); entrySecurityLogin->set_text(res_response.response); if (res_response.response == getlogin()) { chbSecurityLogin->set_active(1); - map_cmd_selection["GRUB_USER"] = ""; + map_temp["GRUB_USER"] = getlogin(); } else if (res_response.response.length() != 0) { chbSecurityLogin->set_active(0); - map_cmd_selection["GRUB_USER"] = ""; + map_temp["GRUB_USER"] = res_response.response; } else{ chbSecurityLogin->set_active(-1); - map_cmd_selection["GRUB_USER"] = ""; + map_temp["GRUB_USER"] = ""; } } else if (res_response.error == 3) { chbSecurityLogin->set_active(-1); - map_cmd_selection["GRUB_USER"] = ""; + map_temp["GRUB_USER"] = ""; } else { chbSecurityLogin->set_active(-1); - map_cmd_selection["GRUB_USER"] = ""; + map_temp["GRUB_USER"] = ""; } } -void MainWindow::set_password_protec(string cmd) { +void MainWindow::set_password_protec(string cmd="") { // TODO: // Не работает int index = chbSecurityLogin->get_active_row_number(); @@ -290,40 +296,40 @@ void MainWindow::set_password_protec(string cmd) { } entrySecurityLogin->set_text(key); cmd = cmd + key; + map_cmd_selection["GRUB_PASSWORD"] = key; wrapper_system(cmd, ""); } -void MainWindow::get_password_protec(string cmd) { +void MainWindow::get_password_protec(string cmd, std::map &map_temp) { // TODO: // Не работает struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { - cout << res_response.response << endl; str_replace_all(res_response.response, "\"",""); entrySecurityLogin->set_text(res_response.response); if (res_response.response == getlogin()) { chbSecurityLogin->set_active(0); - map_cmd_selection["GRUB_PASSWORD"] = ""; + map_temp["GRUB_PASSWORD"] = ""; } else if (res_response.response.length() != 0) { chbSecurityLogin->set_active(1); - map_cmd_selection["GRUB_PASSWORD"] = ""; + map_temp["GRUB_PASSWORD"] = ""; } else if (res_response.response.length() != 0) { chbSecurityLogin->set_active(2); - map_cmd_selection["GRUB_PASSWORD"] = ""; + map_temp["GRUB_PASSWORD"] = ""; } else{ - map_cmd_selection["GRUB_PASSWORD"] = ""; + map_temp["GRUB_PASSWORD"] = ""; chbSecurityLogin->set_active(-1); } } else if (res_response.error == 3) { - map_cmd_selection["GRUB_PASSWORD"] = ""; + map_temp["GRUB_PASSWORD"] = ""; chbSecurityLogin->set_active(-1); } else { - map_cmd_selection["GRUB_PASSWORD"] = ""; + map_temp["GRUB_PASSWORD"] = ""; chbSecurityLogin->set_active(-1); } } @@ -543,10 +549,10 @@ void MainWindow::set_entry_to_tree_view(Glib::RefPtr &list_store } flag_blocked_tree_view = false; } -void MainWindow::get_menu_boot(string cmd) { +void MainWindow::get_menu_boot(string cmd, std::map &map_temp) { struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { - map_cmd_selection["GRUB_TIMEOUT"] = res_response.response; + map_temp["GRUB_TIMEOUT"] = res_response.response; spbSecond->set_value(atoi(res_response.response.c_str())); } else if (res_response.error == 3) { @@ -558,11 +564,14 @@ void MainWindow::get_menu_boot(string cmd) { } -void MainWindow::set_menu_boot(string cmd) { +void MainWindow::set_menu_boot(string cmd="") { int value = spbSecond->get_value(); std::string seconds = to_string(value); cmd += seconds; - this->wrapper_system(cmd, ""); + if (cmd.length() != 0) { + this->wrapper_system(cmd, ""); + } + map_cmd_selection["GRUB_TIMEOUT"] = to_string(value); } @@ -573,14 +582,15 @@ void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings) { str_replace_all(cmd_settings, " \"", "\""); this->wrapper_system(cmd_settings, ""); } + void MainWindow::event(){ btnSynopsis->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::synopsis_show)); btnAbout->signal_activate().connect([&]() {aboutWindows->show();}); btnLoadLocal->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::download_local_cfg)); btnLoadGlob->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::download_globl_cfg)); - btnSaveLocalGlob->signal_activate().connect([&]() {save_global_local_cfg();}); - btnSaveLocal->signal_activate().connect([&]() {save_local_cfg();}); - btnSaveGlob->signal_activate().connect([&]() {save_global_cfg();}); + btnSaveLocalGlob->signal_activate().connect([&]() {wrapper_save_all_cfg();}); + btnSaveLocal->signal_activate().connect([&]() {wrapper_save_local_cfg();}); + btnSaveGlob->signal_activate().connect([&]() {wrapper_save_global_cfg();}); entryKernel->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_kernel)); entryIPT->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_IPT)); entryOTT->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_OTT)); @@ -595,35 +605,57 @@ void MainWindow::event(){ entryIPT->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_IPT)); entryOTT->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_OTT)); } + chbLoadVariantSelectionTimer->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_active_boot_second)); } +void MainWindow::set_active_boot_second() { + spbSecond->set_sensitive(chbLoadVariantSelectionTimer->get_active()); + lblInfoSeconds->set_sensitive(chbLoadVariantSelectionTimer->get_active()); +} +void MainWindow::wrapper_save_all_cfg() { + if (this->save_global_cfg() && this->save_local_cfg()) { + info_status_app("boxInfoMessOK"); + lblWarning->set_text(gettext("Nothing to save!")); + } + else { + info_warning_error(4); + } + +} -void MainWindow::save_global_local_cfg() { - info_warning_error(4); +void MainWindow::wrapper_save_global_cfg() { + if (this->save_global_cfg()) { + info_status_app("boxInfoMessOK"); + lblWarning->set_text(gettext("Nothing to save!")); + } + else { + info_warning_error(3); + } } -void MainWindow::save_global_cfg() { +bool MainWindow::save_global_cfg() { string flag_save = "global"; bool flag_no_save = true; if (flag_save_global) { if (flag_save_all) { + this->set_data_cfg(); if (this->check_save(flag_save, "GRUB_TIMEOUT")) { std::string cmd_boot_time = "ubconfig --target global set boot GRUB_TIMEOUT="; this->set_menu_boot(cmd_boot_time); flag_no_save = false; } - if (this->check_save(flag_save, "")) { + if (this->check_save(flag_save, "GRUB_CMDLINE_LINUX")) { string cmd_settings_kernel = "ubconfig --target global set boot GRUB_CMDLINE_LINUX="; this->cmd_entry_all(*entryKernel, cmd_settings_kernel); flag_no_save = false; } - if (this->check_save(flag_save, "")) { - string cmd_settings_IPT = "ubconfig --target global set boot GRUB_TERMINAL_OUTPUT"; + if (this->check_save(flag_save, "GRUB_TERMINAL_OUTPUT")) { + string cmd_settings_IPT = "ubconfig --target global set boot GRUB_TERMINAL_OUTPUT="; this->cmd_entry_all(*entryIPT, cmd_settings_IPT); flag_no_save = false; } - if (this->check_save(flag_save, "")) { + if (this->check_save(flag_save, "GRUB_TERMINAL_INPUT")) { string cmd_settings_OTT = "ubconfig --target global set boot GRUB_TERMINAL_INPUT="; this->cmd_entry_all(*entryOTT, cmd_settings_OTT); flag_no_save = false; @@ -640,45 +672,47 @@ void MainWindow::save_global_cfg() { this->set_password_protec("ubconfig --target global set boot GRUB_PASSWORD="); flag_no_save = false; } - flag_save_local = true; } } else { - info_status_app("boxInfoMessOK"); - lblWarning->set_text(gettext("Nothing to save!")); + flag_no_save = true; } map_global_cmd_selection = map_cmd_selection; - map_global_cmd_selection = map_local_cmd_selection; - if (flag_no_save){ + return flag_no_save; +} + +void MainWindow::wrapper_save_local_cfg() { + if (this->save_local_cfg()){ info_status_app("boxInfoMessOK"); lblWarning->set_text(gettext("Nothing to save!")); } else { - info_warning_error(3); + info_warning_error(2); } } -void MainWindow::save_local_cfg() { +bool MainWindow::save_local_cfg() { string flag_save = "local"; bool flag_no_save = true; if (flag_save_local) { if (flag_save_all) { + this->set_data_cfg(); if (this->check_save(flag_save, "GRUB_TIMEOUT")) { std::string cmd_boot_time = "ubconfig --target system set boot GRUB_TIMEOUT="; this->set_menu_boot(cmd_boot_time); flag_no_save = false; } - if (this->check_save(flag_save, "")) { + if (this->check_save(flag_save, "GRUB_CMDLINE_LINUX")) { string cmd_settings_kernel = "ubconfig --target system set boot GRUB_CMDLINE_LINUX="; this->cmd_entry_all(*entryKernel, cmd_settings_kernel); flag_no_save = false; } - if (this->check_save(flag_save, "")) { - string cmd_settings_IPT = "ubconfig --target system set boot GRUB_TERMINAL_OUTPUT"; + if (this->check_save(flag_save, "GRUB_TERMINAL_OUTPUT")) { + string cmd_settings_IPT = "ubconfig --target system set boot GRUB_TERMINAL_OUTPUT="; this->cmd_entry_all(*entryIPT, cmd_settings_IPT); flag_no_save = false; } - if (this->check_save(flag_save, "")) { + if (this->check_save(flag_save, "GRUB_TERMINAL_INPUT")) { string cmd_settings_OTT = "ubconfig --target system set boot GRUB_TERMINAL_INPUT="; this->cmd_entry_all(*entryOTT, cmd_settings_OTT); flag_no_save = false; @@ -695,21 +729,31 @@ void MainWindow::save_local_cfg() { this->set_password_protec("ubconfig --target system set boot GRUB_PASSWORD="); flag_no_save = false; } - flag_save_local = true; } } else { - flag_no_save = false; - } - map_global_cmd_selection = map_cmd_selection; - map_global_cmd_selection = map_local_cmd_selection; - if (flag_no_save){ - info_status_app("boxInfoMessOK"); - lblWarning->set_text(gettext("Nothing to save!")); - } - else { - info_warning_error(2); + flag_no_save = true; } + map_local_cmd_selection = map_cmd_selection; + return flag_no_save; +} +void MainWindow::set_data_cfg() { + this->set_security_login(); + this->set_download_mode(); + this->set_password_protec(); + this->set_menu_boot(); + string str_flags = entryKernel->get_text(); + str_remove(str_flags, ","); + 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, " \"", "\""); + map_cmd_selection["GRUB_TERMINAL_INPUT"] = str_flags; + str_flags = entryOTT->get_text(); + str_remove(str_flags, ","); + str_replace_all(str_flags, " \"", "\""); + map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = str_flags; } void MainWindow::download_globl_cfg() { @@ -721,7 +765,7 @@ void MainWindow::download_globl_cfg() { flag_save_all = false; flag_load = true; std::string cmd_boot_time = "ubconfig --default --source global get boot GRUB_TIMEOUT"; - this->get_menu_boot(cmd_boot_time); + this->get_menu_boot(cmd_boot_time, map_global_cmd_selection); string cmd_kernel_entry = "ubconfig --default --source global get boot GRUB_CMDLINE_LINUX"; this->get_setting_entry_all(cmd_kernel_entry, *entryKernel, map_global_cmd_selection); string cmd_ipt_entry = "ubconfig --default --source global get boot GRUB_TERMINAL_INPUT"; @@ -731,10 +775,11 @@ void MainWindow::download_globl_cfg() { this->set_row_all(map_global_cmd_selection, list_store_kernel, vec_Option_kernel, size_kernel); this->set_row_all(map_global_cmd_selection, list_store_IPT, vec_Option_IPT, size_IPT); this->set_row_all(map_global_cmd_selection, list_store_OTT, vec_Option_OTT, size_OTT); - this->get_download_mode("ubconfig --default --source global get boot GRUB_BOOT_SILENT"); - this->get_security_login("ubconfig --default --source global get boot GRUB_USER"); - this->get_password_protec("ubconfig --default --source global get boot GRUB_PASSWORD"); + 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); info_warning_error(1); + map_cmd_selection = map_global_cmd_selection; } void MainWindow::download_local_cfg() { @@ -746,7 +791,7 @@ void MainWindow::download_local_cfg() { flag_save_all = false; flag_load = false; std::string cmd_boot_time = "ubconfig --default --source system get boot GRUB_TIMEOUT"; - this->get_menu_boot(cmd_boot_time); + this->get_menu_boot(cmd_boot_time, map_local_cmd_selection); string cmd_kernel_entry = "ubconfig --default --source system get boot GRUB_CMDLINE_LINUX"; this->get_setting_entry_all(cmd_kernel_entry, *entryKernel, map_local_cmd_selection); string cmd_ipt_entry = "ubconfig --default --source system get boot GRUB_TERMINAL_INPUT"; @@ -756,60 +801,52 @@ void MainWindow::download_local_cfg() { this->set_row_all(map_local_cmd_selection, list_store_kernel, vec_Option_kernel, size_kernel); this->set_row_all(map_local_cmd_selection, list_store_IPT, vec_Option_IPT, size_IPT); this->set_row_all(map_local_cmd_selection, list_store_OTT, vec_Option_OTT, size_OTT); - this->get_download_mode("ubconfig --default --source system get boot GRUB_BOOT_SILENT"); - this->get_security_login("ubconfig --default --source system get boot GRUB_USER"); - this->get_password_protec("ubconfig --default --source system get boot GRUB_PASSWORD"); + 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); info_warning_error(0); + map_cmd_selection = map_local_cmd_selection; } bool MainWindow::check_save(string flag_save, string key_name="") { std::map :: iterator iter_map_data; - std::map :: iterator iter_map_data_local; - std::map :: iterator iter_map_data_global; std::map :: iterator iter_map_data_old; - std::map map_config_data; - std::map map_config_data_local; - std::map map_config_data_global; std::map map_config_data_old; - if (flag_save == "all") { - map_config_data = map_cmd_selection; - } - else if (flag_save == "local") { + if (flag_save == "local") { map_config_data_old = map_local_cmd_selection; - map_config_data_local = map_local_cmd_selection; - } else if (flag_save == "global") { map_config_data_old = map_global_cmd_selection; - map_config_data_global = map_global_cmd_selection; } - else { - // TODO: - // Убрать - throw std::logic_error("Ошибка по невнимательности"); - } - - iter_map_data = map_config_data.find(key_name); + iter_map_data = map_cmd_selection.find(key_name); iter_map_data_old = map_config_data_old.find(key_name); - if (iter_map_data == map_config_data.end()) { - return false; + + if (iter_map_data == map_cmd_selection.end()) { + cout << 1 << endl; + return true; } else if (iter_map_data_old == map_config_data_old.end()) { - return false; + cout << 2 << endl; + return true; } else if (iter_map_data->second != iter_map_data_old->second) { - return false; + cout << 3 << endl; + return true; } else if (iter_map_data->second.length() == 0 || iter_map_data_old->second.length() == 0) { - return true; + cout << 4 << " " << key_name << endl; + return false; } else if (iter_map_data->second == iter_map_data_old->second) { - return true; + cout << 5 << " " << key_name << endl; + return false; } else { - return false; + cout << 6 << endl; + return true; } - return false; + cout << 7 << endl; + return true; } diff --git a/source/ubl-settings-bootloader.h b/source/ubl-settings-bootloader.h index 4b4ff34..ce06be7 100644 --- a/source/ubl-settings-bootloader.h +++ b/source/ubl-settings-bootloader.h @@ -135,7 +135,7 @@ class MainWindow : public Gtk::ApplicationWindow { MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); MainWindow(Glib::RefPtr const& builder); - void get_menu_boot(string cmd); + void get_menu_boot(string cmd, std::map &map_temp); void set_menu_boot(string cmd); 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); @@ -147,15 +147,19 @@ class MainWindow : public Gtk::ApplicationWindow { void fn_event_intelMax1(); void fn_event_intelMax4(); void synopsis_show(); - void get_download_mode(string cmd); + void set_data_cfg(); + void set_active_boot_second(); + void get_download_mode(string cmd, std::map &map_temp); void view_add_cell(Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m , std::array, 5> &arr_view, size_t index); void wrapper_system(string cmd, string thread_str); struct Result wrapper_call(string cmd); void log_mess_error(string &cmd); - void save_global_local_cfg(); - void save_local_cfg(); + void wrapper_save_all_cfg(); + bool save_local_cfg(); + void wrapper_save_local_cfg(); + void wrapper_save_global_cfg(); void view_add_colums(Gtk::TreeView &treeView); - void save_global_cfg(); + bool save_global_cfg(); vector read_file_and_view(string file_name ,Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m); void download_local_cfg(); void download_globl_cfg(); @@ -168,10 +172,10 @@ class MainWindow : public Gtk::ApplicationWindow { bool focus_out_txt_OTT(GdkEventFocus*); void fill_in_view(); void set_security_login(string cmd); - void get_security_login(string cmd); + void get_security_login(string cmd, std::map &map_temp); bool check_flag_save(string flag_save); void set_download_mode(string cmd); - void get_password_protec(string cmd); + void get_password_protec(string cmd, std::map &map_temp); void set_password_protec(string cmd); vector get_setting_entry_all(string cmd, Gtk::Entry &entry_text, std::map &map_temp); void cmd_entry_all(Gtk::Entry &entry, string cmd_settings); diff --git a/ubl-settings-bootloader.glade b/ubl-settings-bootloader.glade index 792091f..3ff4e67 100644 --- a/ubl-settings-bootloader.glade +++ b/ubl-settings-bootloader.glade @@ -1,5 +1,5 @@ - + @@ -192,6 +192,7 @@ specified priority 750 550 False + com.ublinux.ubl-settings-bootloader True