From fbac0ac4d3eea42ae9a98b070ca199ec14ca7a60 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Thu, 6 Apr 2023 17:58:02 +0600 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B0=D1=81=D1=82=D0=B8=D1=87=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=B1=D0=B0=D0=B3=D0=B8=20=D1=81=20=D0=B7=D0=B0=D0=B3?= =?UTF-8?q?=D1=80=D1=83=D0=B7=D0=BA=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/ubl-settings-bootloader.cc | 136 +++++++++++++++--------------- source/ubl-settings-bootloader.h | 12 +-- 2 files changed, 73 insertions(+), 75 deletions(-) diff --git a/source/ubl-settings-bootloader.cc b/source/ubl-settings-bootloader.cc index 9987120..acf79da 100755 --- a/source/ubl-settings-bootloader.cc +++ b/source/ubl-settings-bootloader.cc @@ -94,8 +94,8 @@ void MainWindow::settings(){ this->change_security_login(); this->set_active_boot_second(); this->download_local_cfg(); - this->download_globl_cfg(); - this->event(); + //this->download_globl_cfg(); + } else{ @@ -106,8 +106,8 @@ void MainWindow::settings(){ info_status_app("boxInfoMessError"); lblWarning->set_text(_("The program must be run as root")); this->set_active_boot_second(); - this->event(); } + this->event(); } void MainWindow::fill_in_view() { @@ -129,37 +129,48 @@ void MainWindow::fill_in_view() { this->view_add_colums(*treeViewOTT); } -void MainWindow::item_selected_kernel(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&) { +void MainWindow::item_selected_kernel(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&) { auto selection_IPT = treeViewIPT->get_selection(); auto selection_OTT = treeViewOTT->get_selection(); selection_IPT->unselect_all(); selection_OTT->unselect_all(); if (flag_blocked_tree_view == false) { - template_item_selected("GRUB_CMDLINE_LINUX", map_cmd_selection, path, list_store_kernel); - string str_flags = this->dynamic_update_entry("GRUB_CMDLINE_LINUX", map_cmd_selection, vec_Option_kernel); + string str_flags = template_item_selected(size_kernel, list_store_kernel); + Utils::str_replace_all(str_flags, " \"", "\""); + Utils::str_replace_all(str_flags, "\"", ""); + map_cmd_selection["GRUB_CMDLINE_LINUX"] = str_flags; + Utils::str_replace_all(str_flags, " ", ", "); entryKernel->set_text(str_flags); } } -void MainWindow::item_selected_OTT(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&) { +void MainWindow::item_selected_OTT(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&) { auto selection_kernel = treeViewKernel->get_selection(); auto selection_IPT = treeViewIPT->get_selection(); selection_kernel->unselect_all(); selection_IPT->unselect_all(); if (flag_blocked_tree_view == false) { - template_item_selected("GRUB_TERMINAL_OUTPUT", map_cmd_selection , path, list_store_OTT); - string str_flags = this->dynamic_update_entry("GRUB_TERMINAL_OUTPUT", map_cmd_selection, vec_Option_OTT); + string str_flags = template_item_selected(size_OTT, list_store_OTT); + Utils::str_replace_all(str_flags, " \"", "\""); + Utils::str_replace_all(str_flags, "\"", ""); + map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = str_flags; + Utils::str_replace_all(str_flags, " ", ","); entryOTT->set_text(str_flags); } } -void MainWindow::item_selected_IPT(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&) { +void MainWindow::item_selected_IPT(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&) { + // TODO + // Баг auto selection_kernel = treeViewKernel->get_selection(); auto selection_OTT = treeViewOTT->get_selection(); selection_kernel->unselect_all(); selection_OTT->unselect_all(); - if (flag_blocked_tree_view == false) { - template_item_selected("GRUB_TERMINAL_INPUT", map_cmd_selection , path, list_store_IPT); - string str_flags = this->dynamic_update_entry("GRUB_TERMINAL_INPUT", map_cmd_selection, vec_Option_IPT); + if (flag_blocked_tree_view == false) { + string str_flags = template_item_selected(size_IPT, list_store_IPT); + Utils::str_replace_all(str_flags, " \"", "\""); + Utils::str_replace_all(str_flags, "\"", ""); + map_cmd_selection["GRUB_TERMINAL_INPUT"] = str_flags; + Utils::str_replace_all(str_flags, " ", ","); entryIPT->set_text(str_flags); } } @@ -298,37 +309,18 @@ void MainWindow::get_password_protec(std::map &map_temp) { } } -void MainWindow::template_item_selected(string key, std::map &map_view, const Gtk::TreeModel::Path& path, Glib::RefPtr &list_store) { - const auto iter = list_store->get_iter(path); - if(iter) { - const auto row = *iter; - Glib::ustring cmd; - bool check_btn = row[m_columns.check_button]; - if (check_btn) { - cmd = "1"; - - } - else { - cmd = "0"; - - } - Glib::ustring name = row[m_columns.name]; - cout << key + "_" + name << endl; - map_view[name] = cmd; - } -} - -string MainWindow::dynamic_update_entry(string key,std::map &map_view, vector &vec_allowed) { - string keys = ""; - cout << key << endl; - for (auto &key_local: vec_allowed) { - if (map_view.find(key_local) != map_view.end()) { - if (map_view[key_local] == "1") { - keys += string(key_local) + ", "; +string MainWindow::template_item_selected(int size, Glib::RefPtr &list_store) { + string cmds = ""; + for (int index = 0; index < size; index++) { + Gtk::TreeModel::Row row = list_store->children()[index]; + if(row) { + if (row[m_columns.check_button] == true) { + cmds += row[m_columns.name] + " "; } } } - return keys; + cmds = "\"" + cmds + "\""; + return cmds; } @@ -461,7 +453,7 @@ void MainWindow::localization(){ cmbDefaultDonw->append(_("Last Successful Download")); } -vector MainWindow::get_setting_entry_all(string key, Gtk::Entry &entry_text, std::map &map_temp) { +vector MainWindow::get_setting_entry_all(string key, std::map &map_temp) { vector vec_params; std::map :: iterator iter_map_data; iter_map_data = map_temp.find(key); @@ -471,24 +463,10 @@ vector MainWindow::get_setting_entry_all(string key, Gtk::Entry &entry_t Utils::str_replace_all(value, "\"", ""); vec_params = Utils::split(value, ' '); Utils::str_replace_all(value, " ", ", "); - cout << value << endl; - for (auto ¶m: vec_params) { - map_cmd_selection[param] = "1"; - map_temp[param] = "1"; - } - entry_text.set_text(value); Utils::str_remove(value, ","); map_temp[key] = value; } - else { - entry_text.set_text(""); - } - } - else { - entry_text.set_text(""); - } - return vec_params; } @@ -793,9 +771,9 @@ void MainWindow::load_template(std::map* map_temp, string str_lo obj_load.set_sections(vec_sections); *map_temp = obj_load.get_load_data(*map_temp, str_load); this->get_menu_boot(*map_temp); - this->get_setting_entry_all("GRUB_CMDLINE_LINUX", *entryKernel, *map_temp); - this->get_setting_entry_all("GRUB_TERMINAL_INPUT", *entryIPT, *map_temp); - this->get_setting_entry_all("GRUB_TERMINAL_OUTPUT", *entryOTT, *map_temp); + this->get_setting_entry_all("GRUB_CMDLINE_LINUX", *map_temp); + this->get_setting_entry_all("GRUB_TERMINAL_INPUT", *map_temp); + this->get_setting_entry_all("GRUB_TERMINAL_OUTPUT", *map_temp); this->set_row_all(*map_temp, list_store_kernel, vec_Option_kernel, size_kernel, "GRUB_CMDLINE_LINUX"); this->set_row_all(*map_temp, list_store_IPT, vec_Option_IPT, size_IPT, "GRUB_TERMINAL_INPUT"); this->set_row_all(*map_temp, list_store_OTT, vec_Option_OTT, size_OTT, "GRUB_TERMINAL_OUTPUT"); @@ -803,21 +781,40 @@ void MainWindow::load_template(std::map* map_temp, string str_lo this->get_security_login(*map_temp); this->get_password_protec(*map_temp); this->get_default_load(*map_temp); + this->set_entry(entryKernel, *map_temp, "GRUB_CMDLINE_LINUX"); + this->set_entry(entryIPT, *map_temp, "GRUB_TERMINAL_INPUT"); + this->set_entry(entryOTT, *map_temp, "GRUB_TERMINAL_OUTPUT"); info_warning_error(1); map_cmd_selection = *map_temp; } +void MainWindow::set_entry(Gtk::Entry* entry , std::map &map_temp, string key) { + if (map_temp.find(key) != map_temp.end()) { + string value = map_temp[key]; + Utils::str_replace_all(value, "\"", ""); + Utils::str_replace_all(value, " ", ", "); + cout << value << endl; + entry->set_text(value); + } + else { + entry->set_text(""); + } + +} + void MainWindow::init_dict() { - map_cmd_selection["GRUB_TIMEOUT"] = ""; - map_cmd_selection["GRUB_CMDLINE_LINUX"] = ""; - map_cmd_selection["GRUB_TERMINAL_INPUT"] = ""; - map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = ""; - map_cmd_selection["GRUB_BOOT_SILENT"] = ""; - map_cmd_selection["GRUB_USER"] = ""; - map_cmd_selection["GRUB_PASSWORD"] = ""; - map_cmd_selection["GRUB_DEFAULT"] = ""; - map_global_cmd_selection = map_cmd_selection; - map_local_cmd_selection = map_cmd_selection; + std::map map_cmd_selection_n; + map_cmd_selection_n["GRUB_TIMEOUT"] = ""; + map_cmd_selection_n["GRUB_CMDLINE_LINUX"] = ""; + map_cmd_selection_n["GRUB_TERMINAL_INPUT"] = ""; + map_cmd_selection_n["GRUB_TERMINAL_OUTPUT"] = ""; + map_cmd_selection_n["GRUB_BOOT_SILENT"] = ""; + map_cmd_selection_n["GRUB_USER"] = ""; + map_cmd_selection_n["GRUB_PASSWORD"] = ""; + map_cmd_selection_n["GRUB_DEFAULT"] = ""; + map_cmd_selection = map_cmd_selection_n; + map_global_cmd_selection = map_cmd_selection_n; + map_local_cmd_selection = map_cmd_selection_n; } void MainWindow::set_row_all(std::map &map_cmd, Glib::RefPtr &list_store, vector &list_params, size_t size,string key="") { @@ -828,6 +825,7 @@ void MainWindow::set_row_all(std::map &map_cmd, Glib::RefPtrset_row(list_store, size, name, true); } else { diff --git a/source/ubl-settings-bootloader.h b/source/ubl-settings-bootloader.h index 9c1699f..ede6a38 100644 --- a/source/ubl-settings-bootloader.h +++ b/source/ubl-settings-bootloader.h @@ -191,14 +191,14 @@ class MainWindow : public Gtk::ApplicationWindow { bool focus_out_txt_password(GdkEventFocus*); void get_password_protec(std::map &map_temp); void set_password_protec(); + void set_entry(Gtk::Entry* entry , std::map &map_temp, string key); void load_template(std::map* map_temp, string str_load); - vector get_setting_entry_all(string key, Gtk::Entry &entry_text, std::map &map_temp); + vector get_setting_entry_all(string key, std::map &map_temp); void cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove); - string dynamic_update_entry(string key, std::map &map_view, vector &vec_allowed); - void item_selected_kernel(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&); - void item_selected_OTT(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&); - void item_selected_IPT(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&); - void template_item_selected(string key, std::map &map_view, const Gtk::TreeModel::Path& path, Glib::RefPtr &list_store); + void item_selected_kernel(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&); + void item_selected_OTT(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&); + void item_selected_IPT(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&); + string template_item_selected(int size, Glib::RefPtr &list_store); }; class SettingsPlug : public Gtk::Plug{