diff --git a/Makefile b/Makefile index 76288d0..cf46ddb 100644 --- a/Makefile +++ b/Makefile @@ -126,6 +126,7 @@ install: check uninstall @install -Dm644 -t /usr/share/${PKGNAME}/ cmdline-linux.csv @install -Dm644 -t /usr/share/${PKGNAME}/ grub-terminal-input.csv @install -Dm644 -t /usr/share/${PKGNAME}/ grub-terminal-output.csv + @install -Dm644 -t /usr/share/${PKGNAME}/ grub-melodylist.csv @if [ -z ${DESTDIR} ]; then \ [ -d "${DESTDIR}${PREFIX}/share/icons/hicolor/" ] && gtk-update-icon-cache -fiq "${DESTDIR}${PREFIX}/share/icons/hicolor/" &>/dev/null || true; \ update-desktop-database --quiet &>/dev/null || true; \ diff --git a/grub-melodylist.csv b/grub-melodylist.csv new file mode 100644 index 0000000..79edc2e --- /dev/null +++ b/grub-melodylist.csv @@ -0,0 +1 @@ +ubbeep,1 22 333 4444 5555 \ No newline at end of file diff --git a/screenshot/screenshot.png b/screenshot/screenshot.png index 9f7ddbf..2999a83 100644 Binary files a/screenshot/screenshot.png and b/screenshot/screenshot.png differ diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 39fe799..670aa0b 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -31,6 +31,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissin -fstack-clash-protection -fcf-protection") set(SOURCE_FILES + menu_os.h + menu_os.cc ubl-settings-bootloader-cm.h ubl-settings-bootloader.h ubl-settings-bootloader.cc diff --git a/source/main.cc b/source/main.cc index edab5c2..4dd1d03 100644 --- a/source/main.cc +++ b/source/main.cc @@ -85,7 +85,7 @@ void pars_flag(int index_start, int argc, char* argv[]) { } else{ if (index_start == 1){ - g_print(_(no_recognized)); + g_print(no_recognized); } } diff --git a/source/menu_os.cc b/source/menu_os.cc new file mode 100644 index 0000000..71910dd --- /dev/null +++ b/source/menu_os.cc @@ -0,0 +1,173 @@ +#include "menu_os.h" + + +Menu_os::Menu_os(/* args */) +{ +} + +Menu_os::~Menu_os() +{ +} + +void Menu_os::set_last_launched_os(string str_last_launched_os) { + this->str_last_launched_os = str_last_launched_os; +} + +void Menu_os::set_builder(Glib::RefPtr& builder, string path_glade) { + this->builder = builder; + this->path_glade = path_glade; + builder->get_widget("popoverMenuOS", popoverMenuOS); + builder->get_widget("revealerL1", revealerL1); + builder->get_widget("revealerL2", revealerL2); + builder->get_widget("boxALLL3", boxALLL3); + builder->get_widget("boxLevel1", boxLevel1); + builder->get_widget("btnToLev1", btnToLev1); + + revealerL1->set_reveal_child(true); +} + +void Menu_os::set_map(vector>> &vec_list_os) { + this->vec_list_os = vec_list_os; +} + +void Menu_os::init() { + revealerL1->set_reveal_child(true); + revealerL2->set_reveal_child(true); + size_t index_l1 = 0; + string key = ""; + + for (tuple> tuple_os: vec_list_os) { + key = get<0>(tuple_os); + vector vec_value = get<1>(tuple_os); + map_menu_level_1[key] = new struct_menu_level1; + Glib::RefPtr builder_level_1 = Gtk::Builder::create_from_file(path_glade); + builder_level_1->get_widget("lblRevL1", map_menu_level_1[key]->lblRevL1); + builder_level_1->get_widget("btnToL2AndLv3", map_menu_level_1[key]->btnToL2AndLv3); + builder_level_1->get_widget("boxMenuLevel1", map_menu_level_1[key]->boxMenuLevel1); + map_menu_level_1[key]->btnToL2AndLv3_css = map_menu_level_1[key]->btnToL2AndLv3->get_style_context(); + map_menu_level_1[key]->btnToL2AndLv3_css->add_class("noborder"); + map_menu_level_1[key]->builder = builder_level_1; + boxLevel1->pack_start(*(map_menu_level_1[key]->boxMenuLevel1)); + map_menu_level_1[key]->name = key; + this->html_last_launched_os(key, map_menu_level_1[key]->lblRevL1); + map_menu_level_1[key]->btnToL2AndLv3->signal_clicked().connect( + sigc::bind (sigc::mem_fun( *this, + &Menu_os::event_template), map_menu_level_1[key]->lblRevL1, + name_level_1, map_menu_level_1[key]->name)); + if (vec_value.size()!= 0) { + builder_level_1->get_widget("revealerL3", map_menu_level_1[key]->revealer); + builder_level_1->get_widget("boxLevel3", map_menu_level_1[key]->boxLevel3); + boxALLL3->pack_start(*(map_menu_level_1[key]->revealer)); + } + else { + map_menu_level_1[key]->revealer = NULL; + map_menu_level_1[key]->boxLevel3 = NULL; + } + size_t index_l3 = 0; + for (string& str_level_3: vec_value) { + auto builder_level_3 = Gtk::Builder::create_from_file(path_glade); + map_menu_level_1[key]->vec_menu_level_3.push_back(new struct_menu_level_3); + builder_level_3->get_widget("btnToL3", + map_menu_level_1[key]->vec_menu_level_3[index_l3]->btnToL3); + builder_level_3->get_widget("lblToL3", + map_menu_level_1[key]->vec_menu_level_3[index_l3]->lblToL3); + map_menu_level_1[key]->vec_menu_level_3[index_l3]->btnToL3_css = + map_menu_level_1[key]->vec_menu_level_3[index_l3]->btnToL3->get_style_context(); + map_menu_level_1[key]->vec_menu_level_3[index_l3]->btnToL3_css->add_class("noborder"); + this->html_last_launched_os(str_level_3, map_menu_level_1[key]->vec_menu_level_3[index_l3]->lblToL3); + map_menu_level_1[key]->boxLevel3->pack_start( + *(map_menu_level_1[key]->vec_menu_level_3[index_l3]->btnToL3)); + map_menu_level_1[key]->vec_menu_level_3[index_l3]->btnToL3->signal_clicked().connect( + sigc::bind (sigc::mem_fun(*this, + &Menu_os::event_template), map_menu_level_1[key]->vec_menu_level_3[index_l3]->lblToL3, + name_level_3, map_menu_level_1[key]->name)); + map_menu_level_1[key]->vec_menu_level_3[index_l3]->builder_level_3 = builder_level_3; + index_l3 += 1; + + } + index_l1 += 1; + } +} +void Menu_os::close_revealer() { + for (auto& [key, values]: map_menu_level_1) { + if (values->revealer != NULL) { + values->revealer->set_reveal_child(false); + } + } +} + +void Menu_os::show() { + revealerL1->set_reveal_child(true); + revealerL2->set_reveal_child(false); + this->close_revealer(); + popoverMenuOS->show_all(); +} +void Menu_os::event() { + btnToLev1->signal_clicked().connect(sigc::mem_fun(*this, &Menu_os::to_l1)); +} +void Menu_os::set_entry(Gtk::Entry *entry) { + this->entry = entry; +} +void Menu_os::event_template(Gtk::Label* label, string& name_level, string& key) { + name_level = label->get_label(); + key_global = key; + Utils::str_remove(name_level_1, ""); + Utils::str_remove(name_level_1, ""); + Utils::str_remove(name_level_3, ""); + Utils::str_remove(name_level_3, ""); + Gtk::Revealer *revealer = map_menu_level_1[key]->revealer; + if (&name_level == &name_level_1 && map_menu_level_1[key]->vec_menu_level_3.size() != 0) { + revealerL1->set_reveal_child(false); + revealerL2->set_reveal_child(true); + this->close_revealer(); + revealer->set_reveal_child(true); + name_level_3 = ""; + //entry->set_text(name_level_1); + } + else if (map_menu_level_1[key]->vec_menu_level_3.size() == 0) { + entry->set_text(name_level_1); + name_level_3 = ""; + popoverMenuOS->hide(); + } + else { + popoverMenuOS->hide(); + entry->set_text(name_level_1 + name_level_3); + } +} +void Menu_os::to_l1() { + revealerL1->set_reveal_child(true); + revealerL2->set_reveal_child(false); + map_menu_level_1[key_global]->revealer->set_reveal_child(false); + key_global = ""; +} + +void Menu_os::html_last_launched_os(string name_os, Gtk::Label *label) { + string margin_name_os = ""; + size_t index_find = this->str_last_launched_os.find(">"); + size_t len_last_launched_os = this->str_last_launched_os.length(); + if (index_find != string::npos) { + string level_1 = this->str_last_launched_os.substr(0, index_find + 1); + string level_3 = this->str_last_launched_os.substr(index_find + 1, len_last_launched_os - 1); + if (name_os == level_1) { + margin_name_os = "" + name_os + ""; + label->set_markup(margin_name_os); + } + else if (name_os == level_3) { + margin_name_os = "" + name_os + ""; + label->set_markup(margin_name_os); + } + else { + label->set_text(name_os); + } + } + else { + if (this->str_last_launched_os == name_os) { + margin_name_os = "" + name_os + ""; + label->set_markup(margin_name_os); + } + else { + label->set_text(name_os); + } + } +} + diff --git a/source/menu_os.h b/source/menu_os.h new file mode 100644 index 0000000..0768c7b --- /dev/null +++ b/source/menu_os.h @@ -0,0 +1,67 @@ +#ifndef Menu_os_H +#define Menu_os_H +#include +#include +#include +#include +#include "util.h" +using namespace std; + +class Menu_os +{ +private: + Glib::RefPtr builder; + vector>> vec_list_os; + + Gtk::Popover *popoverMenuOS; + Gtk::Revealer *revealerL1; + Gtk::Revealer *revealerL2; + Gtk::Button *btnToLev1; + string str_last_launched_os = ""; + private: + string name_level_1 = ""; + string name_level_3 = ""; + string key_global = ""; + Gtk::Entry *entry; + string path_glade = ""; + Gtk::Box *boxALLL3; + Gtk::Box *boxLevel1; + struct struct_menu_level_3 { + Gtk::Button *btnToL3; + Gtk::Label *lblToL3; + Glib::RefPtr builder_level_3; + Glib::RefPtr btnToL3_css; + }; + struct struct_menu_level1 { + Gtk::Label *lblRevL1; + Gtk::Button *btnToL2AndLv3; + Gtk::Revealer *revealer; + Gtk::Box *boxLevel3; + Gtk::Box *boxMenuLevel1; + string name; + Glib::RefPtr builder; + vector vec_menu_level_3; + Glib::RefPtr btnToL2AndLv3_css; + }; + + std::map map_menu_level_1; + + +public: + Menu_os(/* args */); + void set_builder(Glib::RefPtr& builder, string path_glade); + void set_map(vector>> &vec_list_os); + void init(); + void show(); + void close_revealer(); + void settings(); + void html_last_launched_os(string name_os, Gtk::Label *label); + void set_last_launched_os(string str_last_launched_os); + void set_entry(Gtk::Entry *entry); + void event_template(Gtk::Label* label, string& name_level, string& key); + void event(); + void to_l1(); + ~Menu_os(); +}; +#endif + diff --git a/source/ubl-settings-bootloader.cc b/source/ubl-settings-bootloader.cc index 66ee893..7ab2130 100755 --- a/source/ubl-settings-bootloader.cc +++ b/source/ubl-settings-bootloader.cc @@ -11,23 +11,20 @@ bool flag_load_global = false; bool flag_lock_help = false; string version_application = "1.0"; -CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help) +CmdArgParser::CmdArgParser(const string& p_name, const string& p_description, const string& p_help) : Glib::OptionGroup{p_name, p_description, p_help} { Glib::OptionEntry socketIDArg; socketIDArg.set_long_name("socket-id"); socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketIDArg.set_description("Settings manager socket"); - Glib::OptionEntry socketExtId; socketExtId.set_long_name("socket-ext-id"); socketExtId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketExtId.set_description("Settings manager secondary socket"); - Glib::OptionEntry socketTrdId; socketTrdId.set_long_name("socket-trd-id"); socketTrdId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketTrdId.set_description("Settings manager secondary socket"); - add_entry(socketIDArg, m_socketID); add_entry(socketExtId, socket_ext_id_I); add_entry(socketTrdId, socket_trd_id_I); @@ -64,16 +61,17 @@ MainWindow::MainWindow(Glib::RefPtr const& builder) { this->settings(); } -void MainWindow::settings(){ +void MainWindow::settings() { map_cmd_error[""] = ""; vec_param_names.push_back("GRUB_TIMEOUT"); vec_param_names.push_back("GRUB_CMDLINE_LINUX"); vec_param_names.push_back("GRUB_TERMINAL_INPUT"); vec_param_names.push_back("GRUB_TERMINAL_OUTPUT"); vec_param_names.push_back("GRUB_BOOT_SILENT"); - vec_param_names.push_back("GRUB_USER"); vec_param_names.push_back("GRUB_PASSWORD"); vec_param_names.push_back("GRUB_DEFAULT"); + vec_param_names.push_back("GRUB_PLAY"); + vec_param_names.push_back("GRUB_SUPERUSERS"); this->get_builder(); this->localization(); this->add_CSS(); @@ -83,7 +81,7 @@ void MainWindow::settings(){ btnBoxAboutDialog->set_visible(false); ubl_make_plugs(boxSave,boxButton, socket_ext_id_I, socket_trd_id_I); #ifdef WEBKIT_FOUND - one = WEBKIT_WEB_VIEW( webkit_web_view_new() ); + one = WEBKIT_WEB_VIEW(webkit_web_view_new()); three = Glib::wrap(GTK_WIDGET(one)); wndWeb->add(*three); #endif @@ -93,15 +91,20 @@ void MainWindow::settings(){ spbSecond->set_increments(1.0, 1.0); spbSecond->set_value(1); this->fill_in_view(); - this->change_password_protecc(); - this->change_security_login(); this->set_active_boot_second(); this->str_last_launched_os = this->pars_last_launched_os(); vector os_control_list; this->pars_os(os_control_list); - this->write_list_entry_os(os_control_list); this->download_local_cfg(); this->download_globl_cfg(); + vector>> vec_list_os = format_os_list(os_control_list); + obj_menu_os.set_builder(builder, path_glade); + obj_menu_os.set_map(vec_list_os); + obj_menu_os.set_entry(entrListOS); + // obj_menu_os.set_last_launched_os(map_global_cmd_selection["GRUB_DEFAULT"]); + obj_menu_os.set_last_launched_os(this->str_last_launched_os); + obj_menu_os.init(); + obj_menu_os.event(); } else{ boxWidgetAll->set_sensitive(false); @@ -116,6 +119,39 @@ void MainWindow::settings(){ this->event(); } +vector>> MainWindow::format_os_list(vector &os_control_list) { + vector>> vec_list_os; + set set_key; + for (string& name_os : os_control_list) { + if (name_os.find(">") != string::npos) { + set_key.insert(name_os.substr(0,name_os.find(">")+1)); + } + else { + vector vec_os; + tuple> t1(name_os, vec_os); + vec_list_os.push_back(t1); + } + } + set::iterator it = set_key.begin(); + for (int index = 1; it != set_key.end(); index++, it++) { + bool flag = false; + string name_os_buff = ""; + vector vec_os_values; + for (string& name_os : os_control_list) { + if (name_os.find(*it) != string::npos) { + flag = true; + vec_os_values.push_back(name_os.substr(name_os.find(">")+1, name_os.length() - 1)); + name_os_buff = *it; + } + } + if (flag) { + tuple> t1(name_os_buff, vec_os_values); + vec_list_os.push_back(t1); + } + } + return vec_list_os; +} + vector MainWindow::pars_os(vector &os_control_list) { string str_list_os = obj_process_call.call_all_sections(cmd_pars_list_os); os_control_list = Utils::split(str_list_os, '\n'); @@ -127,12 +163,6 @@ string MainWindow::pars_last_launched_os() { return str_list_os; } -void MainWindow::write_list_entry_os(vector &os_control_list) { - for (string &name_os: os_control_list) { - cmbDefaultDonw->append(name_os); - } -} - void MainWindow::flag_block_gui() { if (flag_load_global == true) { btnLoadGlob->set_sensitive(false); @@ -163,7 +193,6 @@ void MainWindow::fill_in_view() { treeViewKernel->set_model(list_store_kernel); treeViewIPT->set_model(list_store_IPT); treeViewOTT->set_model(list_store_OTT); - vec_Option_kernel = this->read_file_and_view(kernel_csv, row_kernel, list_store_kernel); vec_Option_IPT = this->read_file_and_view(IPT_csv, row_IPT, list_store_IPT); vec_Option_OTT = this->read_file_and_view(OTT_csv, row_OTT, list_store_OTT); @@ -175,13 +204,25 @@ void MainWindow::fill_in_view() { this->view_add_colums(*treeViewOTT); } +void MainWindow::view_add_colums_user(Gtk::TreeView &treeView) { + treeView.append_column_editable(str_administrator, m_columns_user.check_button); + treeView.append_column_editable(str_user, m_columns_user.name); + treeView.append_column_editable(str_password, m_columns_user.password); +} + +void MainWindow::view_add_colums_melody(Gtk::TreeView &treeView) { + treeView.append_column_editable(str_active, m_columns_melody.check_button); + treeView.append_column_editable(str_option, m_columns_melody.title); + treeView.append_column_editable(str_melody_code, m_columns_melody.melody_code); +} + 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(); + treeViewIPT->get_selection()->unselect_all(); + treeViewOTT->get_selection()->unselect_all(); + treeViewUser->get_selection()->unselect_all(); + treeViewMelody->get_selection()->unselect_all(); if (flag_blocked_tree_view == false) { - string str_flags = template_item_selected(size_kernel, list_store_kernel); + string str_flags = template_item_selected(size_kernel, list_store_kernel, "GRUB_CMDLINE_LINUX"); Utils::str_replace_all(str_flags, " \"", "\""); Utils::str_replace_all(str_flags, "\"", ""); map_cmd_selection["GRUB_CMDLINE_LINUX"] = str_flags; @@ -191,12 +232,12 @@ void MainWindow::item_selected_kernel(const Gtk::TreeModel::Path&, const Gtk::Tr } 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(); + treeViewIPT->get_selection()->unselect_all(); + treeViewKernel->get_selection()->unselect_all(); + treeViewUser->get_selection()->unselect_all(); + treeViewMelody->get_selection()->unselect_all(); if (flag_blocked_tree_view == false) { - string str_flags = template_item_selected(size_OTT, list_store_OTT); + string str_flags = template_item_selected(size_OTT, list_store_OTT, "GRUB_TERMINAL_OUTPUT"); Utils::str_replace_all(str_flags, " \"", "\""); Utils::str_replace_all(str_flags, "\"", ""); map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = str_flags; @@ -204,13 +245,14 @@ void MainWindow::item_selected_OTT(const Gtk::TreeModel::Path&, const Gtk::TreeM entryOTT->set_text(str_flags); } } + void MainWindow::item_selected_IPT(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&) { - auto selection_kernel = treeViewKernel->get_selection(); - auto selection_OTT = treeViewOTT->get_selection(); - selection_kernel->unselect_all(); - selection_OTT->unselect_all(); + treeViewKernel->get_selection()->unselect_all(); + treeViewOTT->get_selection()->unselect_all(); + treeViewUser->get_selection()->unselect_all(); + treeViewMelody->get_selection()->unselect_all(); if (flag_blocked_tree_view == false) { - string str_flags = template_item_selected(size_IPT, list_store_IPT); + string str_flags = template_item_selected(size_IPT, list_store_IPT, "GRUB_TERMINAL_INPUT"); Utils::str_replace_all(str_flags, " \"", "\""); Utils::str_replace_all(str_flags, "\"", ""); map_cmd_selection["GRUB_TERMINAL_INPUT"] = str_flags; @@ -272,97 +314,35 @@ void MainWindow::set_download_mode() { map_cmd_selection["GRUB_BOOT_SILENT"] = key; } -void MainWindow::set_security_login() { - bool index = chbSecurityLogin->get_active(); - string key = ""; - if (index == false) { - key = ""; - } - else if (index == true) { - key = entrySecurityLogin->get_text(); - } - map_cmd_selection["GRUB_USER"] = key; -} - -void MainWindow::get_security_login(std::map &map_temp) { - // Todo; - std::map :: iterator iter_map_data; - iter_map_data = map_temp.find("GRUB_USER"); - if (iter_map_data != map_temp.end()) { - string value = iter_map_data->second; - if (value.length() != 0) { - Utils::str_replace_all(value, " ",""); - Utils::str_replace_all(value, "\"",""); - chbSecurityLogin->set_active(1); - entrySecurityLogin->set_sensitive(true); - entrySecurityLogin->set_text(value); - } - else { - chbSecurityLogin->set_active(0); - entrySecurityLogin->set_text(""); - entrySecurityLogin->set_sensitive(false); - } - } - else { - chbSecurityLogin->set_active(0); - entrySecurityLogin->set_text(""); - entrySecurityLogin->set_sensitive(false); - } -} - -void MainWindow::set_password_protec() { - bool index = chbPasswordProtecc->get_active(); - string key = ""; - if (index == false){ - key = ""; - } - else if (index == true) { - key = entryPasswordProtecc->get_text(); - } - if (key != "************") { - map_cmd_selection["GRUB_PASSWORD"] = key; - } -} - -void MainWindow::get_password_protec(std::map &map_temp) { - std::map :: iterator iter_map_data; - iter_map_data = map_temp.find("GRUB_PASSWORD"); - if (iter_map_data != map_temp.end()) { - string value = iter_map_data->second; - if (value.length() != 0) { - Utils::str_replace_all(value, "\"",""); - chbPasswordProtecc->set_active(1); - entryPasswordProtecc->set_text("************"); - entryPasswordProtecc->set_sensitive(true); - } - else{ - chbPasswordProtecc->set_active(0); - entryPasswordProtecc->set_text(""); - } - } - else { - chbPasswordProtecc->set_active(-1); - } -} - -string MainWindow::template_item_selected(int size, Glib::RefPtr &list_store) { - string cmds = ""; +string MainWindow::template_item_selected(int size, Glib::RefPtr &list_store, string key) { + string cmds = map_cmd_selection[key]; + Utils::str_replace_all(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] + " "; + string param = row[m_columns.name] + ""; + if (row[m_columns.check_button] == true && cmds.find(param) == string::npos) { + cmds += " " + param + " "; + } + if (row[m_columns.check_button] == false && cmds.find(param) != string::npos) { + Utils::str_remove(cmds, param); } } } + Utils::str_replace_all(cmds, " ", " "); + if (cmds.length() > 0) { + if (cmds[0] == ' ') { + cmds = cmds.substr(1, cmds.length() - 1); + } + } cmds = "\"" + cmds + "\""; return cmds; } vector MainWindow::read_file_and_view(string file_name ,Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m) { - std::array, 5> arr_view = Utils::read_csv(string(path_resources) + "/" + file_name); - std::vector vec_Option = arr_view[0]; + std::array, 5> arr_view = Utils::read_csv(string(path_resources) + "/" + file_name); + std::vector vec_Option = arr_view[0]; for (size_t index = 0; index < vec_Option.size(); index++) { this->view_add_cell(row, list_store_m , arr_view, index); @@ -376,7 +356,7 @@ void MainWindow::view_add_colums(Gtk::TreeView &treeView) { treeView.append_column(str_description, m_columns.description); } -void MainWindow::view_add_cell(Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m , std::array, 5> &arr_view , size_t index) { +void MainWindow::view_add_cell(Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m , std::array, 5> &arr_view , size_t index) { row = *(list_store_m->append()); bool flag_chb = false; string name = arr_view[0][index]; @@ -399,15 +379,12 @@ void MainWindow::get_builder() { builder->get_widget("lblInfoSeconds", lblInfoSeconds); builder->get_widget("lblHeaderName", lblHeaderName); builder->get_widget("lblInfoHead", lblInfoHead); - builder->get_widget("spbSecond", spbSecond); builder->get_widget("entryKernel", entryKernel); builder->get_widget("entryIPT", entryIPT); builder->get_widget("entryOTT", entryOTT); - builder->get_widget("boxColor", boxColor); builder->get_widget("boxWidgetAll", boxWidgetAll); - builder->get_widget("aboutWindows", aboutWindows); builder->get_widget("btnSynopsis", btnSynopsis); builder->get_widget("btnAbout", btnAbout); @@ -432,16 +409,10 @@ void MainWindow::get_builder() { builder->get_widget("overHead", overHead); builder->get_widget("lblDownloadMode", lblDownloadMode); builder->get_widget("cmbDownloadMode", cmbDownloadMode); - builder->get_widget("chbSecurityLogin", chbSecurityLogin); - builder->get_widget("chbPasswordProtecc", chbPasswordProtecc); - builder->get_widget("entryPasswordProtecc", entryPasswordProtecc); - builder->get_widget("entrySecurityLogin", entrySecurityLogin); - builder->get_widget("cmbDefaultDonw", cmbDefaultDonw); #ifdef WEBKIT_FOUND builder->get_widget("wndWeb", wndWeb); #endif builder->get_widget("lblHeadeWndWeb", lblHeadeWndWeb); - builder->get_widget("lblwebHeaderName", lblwebHeaderName); builder->get_widget("lblhelpText", lblhelpText); builder->get_widget("lblhelpHeader", lblhelpHeader); @@ -449,10 +420,19 @@ void MainWindow::get_builder() { builder->get_widget("btnReadHelp", btnReadHelp); builder->get_widget("btnCancelHelp", btnCancelHelp); builder->get_widget("wndShowWeb", wndShowWeb); - + builder->get_widget("btnOpenMenuOS", btnOpenMenuOS); + builder->get_widget("entrListOS", entrListOS); + builder->get_widget("treeViewUser", treeViewUser); + builder->get_widget("treeViewMelody", treeViewMelody); + builder->get_widget("lblBootMenuUsers", lblBootMenuUsers); + builder->get_widget("lblRingtoneStartup", lblRingtoneStartup); + builder->get_widget("btnAddUser", btnAddUser); + builder->get_widget("btnRemoveUser", btnRemoveUser); + builder->get_widget("btnAddMusic", btnAddMusic); + builder->get_widget("btnRemoveMusic", btnRemoveMusic); } -void MainWindow::localization(){ +void MainWindow::localization() { time_t now = time(0); tm *ltm = localtime(&now); unsigned int year = 1900+ ltm->tm_year; @@ -467,6 +447,8 @@ void MainWindow::localization(){ lblHeaderName->set_text(name_app); aboutWindows->set_comments(system_boot); lblHeaderAboutTopic->set_label(str_about); + lblBootMenuUsers->set_text(str_title_Boot_Menu_Users); + lblRingtoneStartup->set_text(str_title_Ringtone_Startup); aboutWindows->set_website_label(project_Home_page); lblInfoCommand->set_text(command_line_parameters); lblInfoCommand1->set_text(command_line_parameters); @@ -489,19 +471,12 @@ void MainWindow::localization(){ btnLoad->set_label(str_load); this->set_title(name_app); // Todo: check - entrySecurityLogin->set_tooltip_text(loading_animation_without); - entryPasswordProtecc->set_tooltip_text(user_password_configuration_edit_mode); - chbSecurityLogin->set_tooltip_text(loading_animation_without); - chbPasswordProtecc->set_tooltip_text(user_password_configuration_edit_mode); lblDownloadMode->set_text(boot_screen_display_mode); - chbSecurityLogin->set_label(boot_menu_user_name); - chbPasswordProtecc->set_label(boot_menu_user_password); cmbDownloadMode->append(loading_animation_with); cmbDownloadMode->append(loading_animation_without); cmbDownloadMode->append(no_loading_animation); cmbDownloadMode->append(lack_loading_animation); - cmbDefaultDonw->append(last_successful_upload); - + lblhelpHeader->set_text(read_documentation_web); lblhelpText->set_text(_(redirected_documentation)); btnReadHelp->set_label(read_online); @@ -527,58 +502,34 @@ vector MainWindow::get_setting_entry_all(string key, std::map get_text().length() == 0) { - info_status_app(info_box_error_css); - imgInfo->set_from_icon_name(icon_warning, Gtk::ICON_SIZE_MENU); - lblWarning->set_text(enter_password); - boxSave->set_sensitive(false); - } - else { - info_status_app(info_box_ok_css); - imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU); - lblWarning->set_text(""); - boxSave->set_sensitive(true); - string key = entryPasswordProtecc->get_text(); - if (key != "************") { - map_cmd_selection["GRUB_PASSWORD"] = key; - } - - } - return true; -} -bool MainWindow::focus_out_txt_login(GdkEventFocus*) { - if (entrySecurityLogin->get_text().length() == 0) { - info_status_app(info_box_error_css); - imgInfo->set_from_icon_name(icon_warning, Gtk::ICON_SIZE_MENU); - lblWarning->set_text(enter_login); - boxSave->set_sensitive(false); - } - else { - info_status_app(info_box_ok_css); - imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU); - lblWarning->set_text(""); - map_cmd_selection["GRUB_USER"] = entrySecurityLogin->get_text(); - boxSave->set_sensitive(true); - } - return true; +void MainWindow::focus_out_txt_kernel() { + this->set_entry_to_tree_view(list_store_kernel, *entryKernel, vec_Option_kernel, size_kernel, "GRUB_CMDLINE_LINUX"); + this->set_row_all(map_cmd_selection, list_store_kernel, vec_Option_kernel, size_kernel, "GRUB_CMDLINE_LINUX"); + flag_blocked_tree_view = false; } -bool MainWindow::focus_out_txt_kernel(GdkEventFocus*) { - this->set_entry_to_tree_view(list_store_kernel, *entryKernel, vec_Option_kernel, size_kernel); - return true; +void MainWindow::focus_out_txt_IPT() { + this->set_entry_to_tree_view(list_store_IPT, *entryIPT, vec_Option_IPT, size_IPT, "GRUB_TERMINAL_INPUT"); + this->set_row_all(map_cmd_selection, list_store_IPT, vec_Option_IPT, size_IPT, "GRUB_TERMINAL_INPUT"); + flag_blocked_tree_view = false; } -bool MainWindow::focus_out_txt_IPT(GdkEventFocus*) { - this->set_entry_to_tree_view(list_store_IPT, *entryIPT, vec_Option_IPT, size_IPT); - return true; +void MainWindow::focus_out_txt_OTT() { + this->set_entry_to_tree_view(list_store_OTT, *entryOTT, vec_Option_OTT, size_OTT, "GRUB_TERMINAL_OUTPUT"); + this->set_row_all(map_cmd_selection, list_store_OTT, vec_Option_OTT, size_OTT, "GRUB_TERMINAL_OUTPUT"); + flag_blocked_tree_view = false; } -bool MainWindow::focus_out_txt_OTT(GdkEventFocus*) { - this->set_entry_to_tree_view(list_store_OTT, *entryOTT, vec_Option_OTT, size_OTT); + +bool MainWindow::focus_in_txt_entry(GdkEventFocus*) { + treeViewKernel->get_selection()->unselect_all(); + treeViewIPT->get_selection()->unselect_all(); + treeViewOTT->get_selection()->unselect_all(); + treeViewUser->get_selection()->unselect_all(); + treeViewMelody->get_selection()->unselect_all(); return true; } -void MainWindow::set_entry_to_tree_view(Glib::RefPtr &list_store, Gtk::Entry &entry, std::vector &vec_Option, int size) { +void MainWindow::set_entry_to_tree_view(Glib::RefPtr &list_store, Gtk::Entry &entry, std::vector &vec_Option, int size, string key) { flag_blocked_tree_view = true; vector vec_params; std::string text = entry.get_text(); @@ -590,7 +541,16 @@ void MainWindow::set_entry_to_tree_view(Glib::RefPtr &list_store for (auto &name: vec_params) { this->set_row(list_store, size, name, true); } - flag_blocked_tree_view = false; + Utils::str_replace_all(text, ",", " "); + if (text.length() > 0) { + if (text[0] == ' ') { + text = text.substr(1, text.length() - 1); + } + } + if (text.find("\"") == string::npos && text.length() != 0) { + text = "\"" + text + "\""; + } + map_cmd_selection[key] = text; } void MainWindow::get_menu_boot(std::map &map_temp) { @@ -629,10 +589,16 @@ void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cm else { obj_process_system.call(cmd_remove, ""); } - } -void MainWindow::event(){ +void MainWindow::event() { + btnRemoveUser->signal_clicked().connect([&]() {remove_user();}); + btnRemoveMusic->signal_clicked().connect([&]() {remove_melody();}); + btnAddUser->signal_clicked().connect([&]() {string name = "", passwd = ""; + set_add_data_user(row_user, false, name, passwd);}); + btnAddMusic->signal_clicked().connect([&]() {string code = "", name = ""; + set_add_data_melody(row_melody, false,name, code);}); + btnOpenMenuOS->signal_clicked().connect([&]() {obj_menu_os.show();}); 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)); @@ -643,13 +609,9 @@ void MainWindow::event(){ 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)); - entrySecurityLogin->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_login)); - entryPasswordProtecc->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_password)); - chbPasswordProtecc->signal_toggled().connect([&]() {change_password_protecc();}); - chbSecurityLogin->signal_toggled().connect([&]() {change_security_login();}); + entryKernel->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_kernel)); + entryIPT->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_IPT)); + entryOTT->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_OTT)); if (this->check_root() == 0) { Glib::RefPtr treeViewKernelModel = treeViewKernel->get_model(); treeViewKernelModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::item_selected_kernel)); @@ -657,71 +619,324 @@ void MainWindow::event(){ treeViewIPTModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::item_selected_IPT)); Glib::RefPtr treeViewOTTModel = treeViewOTT->get_model(); treeViewOTTModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::item_selected_OTT)); - 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)); + entryKernel->signal_focus_in_event().connect(sigc::mem_fun(*this, &MainWindow::focus_in_txt_entry)); + entryIPT->signal_focus_in_event().connect(sigc::mem_fun(*this, &MainWindow::focus_in_txt_entry)); + entryOTT->signal_focus_in_event().connect(sigc::mem_fun(*this, &MainWindow::focus_in_txt_entry)); } this->signal_delete_event().connect(sigc::mem_fun(*this, &MainWindow::gui_exit)); chbLoadVariantSelectionTimer->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_active_boot_second)); } -bool MainWindow::gui_exit(GdkEventAny*) { - exit(1); - return true; +void MainWindow::set_tree_view_user() { + string key = ""; + string users_root = ""; + string password = ""; + bool flag_available = false; + Glib::RefPtr treeViewUser_model = treeViewUser->get_model(); + Gtk::TreeModel::Children children = treeViewUser_model->children(); + for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; + if(row) { + string superuser_name = row[m_columns_user.name] + ""; + if (row[m_columns_user.check_button] && superuser_name.length() != 0) { + key = "GRUB_PASSWORD[" + superuser_name + "]"; + password = row[m_columns_user.password] + ""; + if (password != "************") { + map_cmd_selection[key] = password; + flag_available = false; + for (size_t index = 0; index < vec_param_names.size(); index++) { + if (vec_param_names[index] == map_cmd_selection[key]) { + flag_available = true; + } + } + if (flag_available == false) { + vec_param_names.push_back(key); + } + + } + else { + // map_cmd_selection[key] = ""; + } + if (row[m_columns_user.check_button]) { + if (users_root.length() != 0) { + users_root = users_root + "," + superuser_name; + } + else { + users_root = users_root + row[m_columns_user.name]; + } + } + } + } + } + if (users_root.length() != 0) { + map_cmd_selection["GRUB_SUPERUSERS"] = users_root; + } + else { + map_cmd_selection["GRUB_SUPERUSERS"] = ""; + } } -void MainWindow::change_security_login() { - bool index = chbSecurityLogin->get_active(); - if (index == false) { - entrySecurityLogin->set_sensitive(false); - entrySecurityLogin->set_text(""); - boxSave->set_sensitive(true); - info_status_app(info_box_ok_css); - imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU); - lblWarning->set_text(""); +void MainWindow::set_init_data_user(std::map &map_temp) { + treeViewUser->remove_all_columns(); + list_store_user = Gtk::ListStore::create(m_columns_user); + treeViewUser->set_model(list_store_user); + vector vec_users; + string buf_key = ""; + string password = ""; + for (auto& [key, value]: map_temp) { + if (key.find("GRUB_PASSWORD[") != string::npos) { + buf_key = key; + vec_param_names.push_back(buf_key); + Utils::str_remove(buf_key,"GRUB_PASSWORD["); + Utils::str_remove(buf_key,"]"); + if (value.length() != 0) { + password = "************"; + this->set_add_data_user(row_user, false, buf_key, password); + } + } } - else if (index == true) { - entrySecurityLogin->set_sensitive(true); - entrySecurityLogin->set_text(""); - boxSave->set_sensitive(true); + Glib::RefPtr treeViewUserModel = treeViewUser->get_model(); + treeViewUserModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::remove_line_user)); + this->view_add_colums_user(*treeViewUser); +} + +void MainWindow::set_init_data_superuser(std::map &map_temp) { + Glib::RefPtr treeViewUser_model = treeViewUser->get_model(); + string names_superusers = map_temp["GRUB_SUPERUSERS"]; + vector vec_superusers = Utils::split(names_superusers, ','); + Gtk::TreeModel::Children children = treeViewUser_model->children(); + for (string& str_superuser: vec_superusers) { + for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; + if (row[m_columns_user.name] == str_superuser) { + row[m_columns_user.check_button] = true; + } + } } } -void MainWindow::get_default_load(std::map &map_temp) { - std::map :: iterator iter_map_data; - iter_map_data = map_temp.find("GRUB_DEFAULT"); - if (iter_map_data != map_temp.end()) { - string value = iter_map_data->second; - if (value.length() != 0) { - cmbDefaultDonw->set_active_text(value); +void MainWindow::set_data_csv_melody() { + string path_name = ""; + path_name = path_name + path_resources + "/" + "grub-melodylist.csv"; + string line; + string all_melody = ""; + string all_melody_old = ""; + string code_melodyes = ""; + ifstream in(path_name); + if (in.is_open()) { + while (getline(in, line)) { + all_melody_old += line + "\n"; + } + } + Glib::RefPtr treeViewMelody_model = treeViewMelody->get_model(); + Gtk::TreeModel::Children children = treeViewMelody_model->children(); + for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; + code_melodyes = row[m_columns_melody.melody_code] + ""; + if (code_melodyes.length() != 0 && (row[m_columns_melody.title] + "").length() != 0) { + all_melody += row[m_columns_melody.title] + "," + code_melodyes + "\n"; + if (row[m_columns_melody.check_button]) { + map_cmd_selection["GRUB_PLAY"] = code_melodyes + ""; + } + else { + map_cmd_selection["GRUB_PLAY"] = ""; + } } else { - cmbDefaultDonw->set_active(0); + imgInfo->set_from_icon_name(icon_warning, Gtk::ICON_SIZE_MENU); + info_status_app(info_box_error_css); + lblWarning->set_text(str_null_melody_name); + } + } + if (all_melody_old != all_melody) { + ofstream fout(path_name, ios_base::out | ios_base::trunc); + if (fout.is_open()) { + fout << all_melody; + fout.close(); + } + } +} + +void MainWindow::set_add_data_user(Gtk::TreeModel::Row &row, bool flag, string &name, string &password) { + row = *(list_store_user->append()); + row[m_columns_user.check_button] = flag; + row[m_columns_user.name] = name; + row[m_columns_user.password] = password; +} + +void MainWindow::set_init_data_melody(std::map &map_temp) { + treeViewMelody->remove_all_columns(); + list_store_melody = Gtk::ListStore::create(m_columns_melody); + treeViewMelody->set_model(list_store_melody); + string path_name = ""; + path_name = path_name + path_resources + "/" + "grub-melodylist.csv"; + vector> vec_melody = Utils::read_csv_melody(path_name); + bool flag = false; + string cgf_code_melody = map_temp["GRUB_PLAY"]; + for (tuple& tuple_melody: vec_melody) { + string name = get<0>(tuple_melody); + string code = get<1>(tuple_melody); + flag = (cgf_code_melody == code); + this->set_add_data_melody(row_melody, flag, name, code); + } + Glib::RefPtr treeViewMelodyModel = treeViewMelody->get_model(); + treeViewMelodyModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::remove_line_melody)); + this->view_add_colums_melody(*treeViewMelody); +} + +void MainWindow::set_add_data_melody(Gtk::TreeModel::Row &row, bool flag, string &name, string &code) { + row = *(list_store_melody->append()); + row[m_columns_melody.check_button] = flag; + row[m_columns_melody.title] = name; + row[m_columns_melody.melody_code] = code; +} + +void MainWindow::remove_user() { + if (flag_validate_del_user && list_store_user->iter_is_valid(iter_user_del)) { + Gtk::TreeModel::Row row = *iter_user_del; + if(row) { + string name = row[m_columns_user.name] + ""; + string key = "GRUB_PASSWORD[" + name + "]"; + map_cmd_selection[key] = ""; } + list_store_user->erase(iter_user_del); + flag_validate_del_user = false; + info_status_app(info_box_ok_css); + imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU); + lblWarning->set_text(""); + } + flag_validate_del_user = false; +} + +void MainWindow::remove_melody() { + if (flag_validate_del_melody && list_store_melody->iter_is_valid(iter_melody_del)) { + list_store_melody->erase(iter_melody_del); + flag_validate_del_melody = false; + info_status_app(info_box_ok_css); + imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU); + lblWarning->set_text(""); + } + flag_validate_del_melody = false; +} + +void MainWindow::remove_line_user(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter) { + treeViewKernel->get_selection()->unselect_all(); + treeViewOTT->get_selection()->unselect_all(); + treeViewIPT->get_selection()->unselect_all(); + treeViewMelody->get_selection()->unselect_all(); + iter_user_del = iter; + flag_validate_del_user = true; + bool flag_error = false; + string name = ""; + string password = ""; + Glib::RefPtr treeViewUser_model = treeViewUser->get_model(); + Gtk::TreeModel::Children children = treeViewUser_model->children(); + for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; + name = row[m_columns_user.name] + ""; + password = row[m_columns_user.password] + ""; + if (name.length() == 0 || password.length() == 0) { + flag_error = true; + break; + } + } + if (flag_error == true) { + imgInfo->set_from_icon_name(icon_warning, Gtk::ICON_SIZE_MENU); + info_status_app(info_box_error_css); + lblWarning->set_text(str_null_username); } else { - cmbDefaultDonw->set_active(-1); + info_status_app(info_box_ok_css); + imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU); + lblWarning->set_text(""); } } -void MainWindow::change_password_protecc() { - // Todo; - bool index = chbPasswordProtecc->get_active(); - if (index == false) { - entryPasswordProtecc->set_sensitive(false); - entryPasswordProtecc->set_text(""); - boxSave->set_sensitive(true); +void MainWindow::remove_line_melody(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter) { + treeViewKernel->get_selection()->unselect_all(); + treeViewOTT->get_selection()->unselect_all(); + treeViewIPT->get_selection()->unselect_all(); + treeViewUser->get_selection()->unselect_all(); + iter_melody_del = iter; + flag_validate_del_melody = true; + string code_melodyes = ""; + string melody_title = ""; + bool flag_error = false; + Glib::RefPtr treeViewMelody_model = treeViewMelody->get_model(); + Gtk::TreeModel::Children children = treeViewMelody_model->children(); + for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; + code_melodyes = row[m_columns_melody.melody_code] + ""; + melody_title = row[m_columns_melody.title] + ""; + if (code_melodyes.length() == 0 || melody_title.length() == 0) { + flag_error = true; + break; + } + } + if (flag_error == true) { + imgInfo->set_from_icon_name(icon_warning, Gtk::ICON_SIZE_MENU); + info_status_app(info_box_error_css); + lblWarning->set_text(str_null_melody_name); + } + else { info_status_app(info_box_ok_css); imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU); lblWarning->set_text(""); } - else if (index == true) { - entryPasswordProtecc->set_sensitive(true); - entryPasswordProtecc->set_text(""); - boxSave->set_sensitive(true); + this->validate_melody(); + +} + +void MainWindow::validate_melody() { + Glib::RefPtr treeViewMelody_model = treeViewMelody->get_model(); + Gtk::TreeModel::Children children = treeViewMelody_model->children(); + int count = 0; + for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; + if (row[m_columns_melody.check_button]) { + count+=1; + } + } + if (count>1) { + for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; + if (row[m_columns_melody.check_button]) { + count-=1; + row[m_columns_melody.check_button] = false; + } + } + } +} + +bool MainWindow::focus_tree_view(GdkEventFocus*) { + treeViewKernel->set_can_focus(false); + treeViewIPT->set_can_focus(false); + treeViewOTT->set_can_focus(false); + treeViewKernel->collapse_all(); + treeViewIPT->collapse_all(); + treeViewOTT->collapse_all(); + return true; +} + +bool MainWindow::gui_exit(GdkEventAny*) { + exit(1); + return true; +} + +void MainWindow::get_default_load(std::map &map_temp) { + std::map :: iterator iter_map_data; + iter_map_data = map_temp.find("GRUB_DEFAULT"); + if (iter_map_data != map_temp.end()) { + string value = iter_map_data->second; + if (value.length() != 0) { + entrListOS->set_text(value); + } + else { + entrListOS->set_text(""); + } } else { - boxSave->set_sensitive(true); + entrListOS->set_text(""); } } @@ -794,7 +1009,6 @@ void MainWindow::wrapper_save_local_cfg() { map_local_cmd_selection = map_cmd_selection; } - void MainWindow::set_data_cfg() { string str_flags = entryKernel->get_text(); Utils::str_remove(str_flags, ","); @@ -815,25 +1029,27 @@ void MainWindow::set_data_cfg() { else { map_cmd_selection["GRUB_TIMEOUT"] = ""; } - int index = cmbDefaultDonw->get_active_row_number(); - if (index != 0 && index != -1) { - map_cmd_selection["GRUB_DEFAULT"] = cmbDefaultDonw->get_active_text(); + string name_os = entrListOS->get_text(); + if (name_os.length() != 0) { + map_cmd_selection["GRUB_DEFAULT"] = name_os; } else { map_cmd_selection["GRUB_DEFAULT"] = ""; } this->set_download_mode(); - this->set_security_login(); - this->set_password_protec(); + this->set_tree_view_user(); + this->set_data_csv_melody(); } void MainWindow::download_globl_cfg() { + str_flag_load = "global"; this->load_template(&map_global_cmd_selection, global_load); info_warning_error(1); map_cmd_selection = map_global_cmd_selection; } void MainWindow::download_local_cfg() { + str_flag_load = "system"; this->load_template(&map_local_cmd_selection, system_load); info_warning_error(0); map_cmd_selection = map_local_cmd_selection; @@ -858,23 +1074,24 @@ void MainWindow::load_template(std::map* map_temp, string cmd) { 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"); this->get_download_mode(*map_temp); - 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"); string str_last_launched_os_ubconfig = (*map_temp)["GRUB_DEFAULT"]; + this->set_init_data_user(*map_temp); + this->set_init_data_melody(*map_temp); + this->set_init_data_superuser(*map_temp); if (str_last_launched_os_ubconfig.length() != 0) { - cmbDefaultDonw->set_active_text(str_last_launched_os_ubconfig); + entrListOS->set_text(str_last_launched_os_ubconfig); } else { - cmbDefaultDonw->set_active_text(str_last_launched_os); + entrListOS->set_text(str_last_launched_os); } } -void MainWindow::set_entry(Gtk::Entry* entry , std::map &map_temp, string key) { +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, "\"", ""); @@ -884,19 +1101,19 @@ void MainWindow::set_entry(Gtk::Entry* entry , std::map &map_tem else { entry->set_text(""); } - } void MainWindow::init_dict(string flag_load) { - std::map map_cmd_selection_n; + 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_n["GRUB_PLAY"] = ""; + map_cmd_selection_n["GRUB_SUPERUSERS"] = ""; map_cmd_selection = map_cmd_selection_n; if (flag_load == "global") { map_global_cmd_selection = map_cmd_selection_n; @@ -918,7 +1135,7 @@ void MainWindow::set_row_all(std::map &map_cmd, Glib::RefPtr &list_store, int size, std::string name, bool flag_chbox) { +void MainWindow::set_row(Glib::RefPtr &list_store, int size, string name, bool flag_chbox) { for (int index = 0; index < size; index++) { Gtk::TreeModel::Row row = list_store->children()[index]; if(row) { @@ -956,8 +1173,8 @@ void MainWindow::template_open_browser() { 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 ); + std::snprintf(buf.get(), size, cmd_execute, response_user.c_str(), cmd.c_str()); + cmd = string(buf.get(), buf.get() + size - 1); } index_error = system(cmd.c_str()); } @@ -1025,7 +1242,7 @@ MainWindow::~MainWindow() { #endif } -void MainWindow::add_CSS(){ +void MainWindow::add_CSS() { Glib::RefPtr cssProvider = Gtk::CssProvider::create(); cssProvider->load_from_path(path_css); Glib::RefPtr styleContext = Gtk::StyleContext::create(); @@ -1036,7 +1253,7 @@ void MainWindow::add_CSS(){ Glib::RefPtr boxSave_css = boxSave->get_style_context(); boxInfo = boxInfoError->get_style_context(); imgBG->set(path_img_head_background); - if (socket_trd_id_I == 0 && socket_ext_id_I == 0){ + if (socket_trd_id_I == 0 && socket_ext_id_I == 0) { boxButton_css->add_class("bkim_no_plug"); boxSave_css->add_class("bkim_no_plug"); } diff --git a/source/ubl-settings-bootloader.h b/source/ubl-settings-bootloader.h index 1d2871a..21ec440 100644 --- a/source/ubl-settings-bootloader.h +++ b/source/ubl-settings-bootloader.h @@ -18,6 +18,7 @@ #include "load.h" #include #include "ubl-settings-bootloader-cm.h" +#include "menu_os.h" #ifdef WEBKIT_FOUND #include #endif @@ -36,11 +37,11 @@ extern bool flag_lock_help; void me_thread(string cmd); #define copyright _("Copyright © UBSoft LLC, 2022 - ") -#define name_app _("ubl-settings-bootloader") +#define name_app _("ubl-settings-bootloader") #define website _("https://wiki.ublinux.com") -#define project_Home_page _("Project Home Page") +#define project_Home_page _("Project Home Page") #define configuring_system_boot _("Configuring system boot parameters") -#define system_boot _("System boot") +#define system_boot _("System boot setup") #define str_about _("About ubl-settings-bootloader") #define command_line_parameters _("Command line parameters:") #define load_default _("Load default:") @@ -67,7 +68,8 @@ void me_thread(string cmd); #define boot_menu_user_password _("Boot menu user password:") #define last_successful_upload _("Last successful upload") #define read_documentation_web _("Would you like to read documentation in the Web?") -#define redirected_documentation _("You will be redirected to documentation site, where user help pages are ""translated and supported by community.") +#define redirected_documentation _("You will be redirected to documentation site, where user help pages are " \ + "translated and supported by community.") #define user_name_configuration_editing_code _("User name to enter boot configuration editing mode") #define user_password_configuration_edit_mode _("User password to enter boot configuration edit mode") #define loading_animation_with _("Loading animation with the magazine") @@ -91,11 +93,31 @@ void me_thread(string cmd); #define program_as_root _("The program must be run as root") #define str_active _("Active") #define str_option _("Option") +#define str_title _("Title") +#define str_user _("User") +#define str_password _("Password") +#define str_administrator _("Administrator") +#define str_select _("Select") +#define str_melody_code _("Melody code") +#define str_ringtone_at_startup _("Ringtone at startup") #define str_description _("Description") -#define str_help_h _("GTK settings bootloader for UBLinux\n""\n""Usage: ubl-settings-bootloader [OPTIONS...]\n""Options:\n"" -h, --help\t Show this help\n"" -V, --version\t Show package version\n"" --lock-help Lock utility help\n"" --lock-save Lock saving local and global configuration\n"" --lock-save-local Lock save global configuration\n"" --lock-save-global Lock load global configuration\n"" --lock-load-global Lock load global configuration\n") +#define str_title_Boot_Menu_Users _("Boot Menu Users") +#define str_title_Ringtone_Startup _("Ringtone at startup") +#define str_null_melody_name _("Enter the name and code of the tune in the \"Ringtone at startup\" field") +#define str_null_username _("Enter name and password code in the \"Boot Menu Users\" field") +#define str_help_h _("GTK settings bootloader for UBLinux\n" \ + "\n" \ + "Usage: ubl-settings-bootloader [OPTIONS...]\n" \ + "Options:\n" \ + " -h, --help\t Show this help\n" \ + " -V, --version\t Show package version\n" \ + " --lock-help Lock utility help\n" \ + " --lock-save Lock saving local and global configuration\n" \ + " --lock-save-local Lock save global configuration\n" \ + " --lock-save-global Lock load global configuration\n" \ + " --lock-load-global Lock load global configuration\n") #define no_recognized _("Argument not recognized\n") - #define global_load "ubconfig --default --source global get boot" #define system_load "ubconfig --default --source system get boot" #define global_save "ubconfig --target global set boot " @@ -124,197 +146,256 @@ void me_thread(string cmd); class CmdArgParser : public Glib::OptionGroup { public: - CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help); + CmdArgParser(const std::string &p_name, const std::string &p_description, const std::string &p_help); ::Window GetSocketID() const; private: int m_socketID = 0; - }; -class MainWindow : public Gtk::ApplicationWindow { +class MainWindow : public Gtk::ApplicationWindow +{ +public: + class ModelColumns : public Gtk::TreeModel::ColumnRecord + { public: - class ModelColumns : public Gtk::TreeModel::ColumnRecord { - public: - ModelColumns() {add(check_button), add(name); add(description); } - //Gtk::TreeModelColumn check_button; - Gtk::TreeModelColumn check_button; - Gtk::TreeModelColumn name; - Gtk::TreeModelColumn description; - }; - ModelColumns m_columns; - Glib::RefPtr builder; - Gtk::SpinButton *spbSecond; - Gtk::Label *lblInfoSeconds; - Gtk::Label *lblInfoDefaultDonw; - Gtk::Label *lblInfoCommand; - Gtk::Label *lblInfoCommand1; - Gtk::Label *lblHeaderAboutTopic; - Gtk::Label *lblInfoCommand2; - Gtk::Label *lblLoadMenu; - Gtk::Label *lblInfoInputTerminal; - Gtk::Label *lblInfoOutputTerminal; - Gtk::Label *lblHeaderName; - Gtk::Label *lblInfoHead; - Gtk::CheckButton *chbVgaText; - Gtk::CheckButton *chbLoadVariantSelectionTimer; - Gtk::Entry *entryKernel; - Gtk::Entry *entryIPT; - Gtk::Entry *entryOTT; - Gtk::Box *boxColor; - Gtk::AboutDialog *aboutWindows; - Gtk::MenuItem *btnAbout; - Gtk::MenuItem *btnSynopsis; - Gtk::MenuItem *btnSaveLocalGlob; - Gtk::MenuItem *btnSaveLocal; - Gtk::MenuItem *btnSaveGlob; - Gtk::MenuItem *btnLoadGlob; - Gtk::MenuItem *btnLoadLocal; - Gtk::Button *btnLoad; - Gtk::Button *btnSave; - Gtk::Button *btnSettings; - Gtk::Widget *boxButton; - Gtk::Widget *boxSave; - Gtk::Box *boxInfoError; - Gtk::Box *boxWidgetAll; - Gtk::Label *lblWarning; - Gtk::Image *imgInfo; - Gtk::ButtonBox *btnBoxAboutDialog; - Gtk::TreeView *treeViewKernel; - Gtk::TreeView *treeViewIPT; - Gtk::TreeView *treeViewOTT; - Gtk::Image *imgBG; - Gtk::Overlay *overHead; - Gtk::ComboBoxText *cmbDefaultDonw; - Gtk::ComboBoxText *cmbDownloadMode; - Gtk::CheckButton *chbSecurityLogin; - Gtk::CheckButton *chbPasswordProtecc; - Gtk::Entry *entrySecurityLogin; - Gtk::Entry *entryPasswordProtecc; - Gtk::Label *lblHeadeWndWeb; + ModelColumns() + { + add(check_button), add(name); + add(description); + } + // Gtk::TreeModelColumn check_button; + Gtk::TreeModelColumn check_button; + Gtk::TreeModelColumn name; + Gtk::TreeModelColumn description; + }; + class ModelColumnsUser : public Gtk::TreeModel::ColumnRecord + { + public: + ModelColumnsUser() + { + add(check_button), add(name); + add(password); + } + // Gtk::TreeModelColumn check_button; + Gtk::TreeModelColumn check_button; + Gtk::TreeModelColumn name; + Gtk::TreeModelColumn password; + }; + class ModelColumnsMelody : public Gtk::TreeModel::ColumnRecord + { + public: + ModelColumnsMelody() + { + add(check_button), add(title); + add(melody_code); + } + // Gtk::TreeModelColumn check_button; + Gtk::TreeModelColumn check_button; + Gtk::TreeModelColumn title; + Gtk::TreeModelColumn melody_code; + }; - Gtk::Label *lblwebHeaderName; - Gtk::Label *lblhelpText; - Gtk::Label *lblhelpHeader; - Gtk::CheckButton *chkAlwaysOpenHelp; - Gtk::Button *btnReadHelp; - Gtk::Button *btnCancelHelp; - Gtk::Window *wndShowWeb; + ModelColumns m_columns; + ModelColumnsUser m_columns_user; + ModelColumnsMelody m_columns_melody; + Glib::RefPtr builder; + Gtk::SpinButton *spbSecond; + Gtk::Label *lblBootMenuUsers; + Gtk::Label *lblRingtoneStartup; + Gtk::Label *lblInfoSeconds; + Gtk::Label *lblInfoDefaultDonw; + Gtk::Label *lblInfoCommand; + Gtk::Label *lblInfoCommand1; + Gtk::Label *lblHeaderAboutTopic; + Gtk::Label *lblInfoCommand2; + Gtk::Label *lblLoadMenu; + Gtk::Label *lblInfoInputTerminal; + Gtk::Label *lblInfoOutputTerminal; + Gtk::Label *lblHeaderName; + Gtk::Label *lblInfoHead; + Gtk::Button *btnAddUser; + Gtk::Button *btnRemoveUser; + Gtk::Button *btnAddMusic; + Gtk::Button *btnRemoveMusic; + Gtk::CheckButton *chbVgaText; + Gtk::CheckButton *chbLoadVariantSelectionTimer; + Gtk::Entry *entryKernel; + Gtk::Entry *entryIPT; + Gtk::Entry *entryOTT; + Gtk::Box *boxColor; + Gtk::AboutDialog *aboutWindows; + Gtk::MenuItem *btnAbout; + Gtk::MenuItem *btnSynopsis; + Gtk::MenuItem *btnSaveLocalGlob; + Gtk::MenuItem *btnSaveLocal; + Gtk::MenuItem *btnSaveGlob; + Gtk::MenuItem *btnLoadGlob; + Gtk::MenuItem *btnLoadLocal; + Gtk::Button *btnLoad; + Gtk::Button *btnSave; + Gtk::Button *btnSettings; + Gtk::Widget *boxButton; + Gtk::Widget *boxSave; + Gtk::Box *boxInfoError; + Gtk::Box *boxWidgetAll; + Gtk::Label *lblWarning; + Gtk::Image *imgInfo; + Gtk::ButtonBox *btnBoxAboutDialog; + Gtk::TreeView *treeViewKernel; + Gtk::TreeView *treeViewIPT; + Gtk::TreeView *treeViewOTT; + Gtk::TreeView *treeViewUser; + Gtk::TreeView *treeViewMelody; + Gtk::Image *imgBG; + Gtk::Overlay *overHead; + Gtk::ComboBoxText *cmbDownloadMode; + Gtk::CheckButton *chbPasswordProtecc; + Gtk::Label *lblHeadeWndWeb; - std::vector vec_Option_kernel; - std::vector vec_Option_IPT; - std::vector vec_Option_OTT; + Gtk::Label *lblwebHeaderName; + Gtk::Label *lblhelpText; + Gtk::Label *lblhelpHeader; + Gtk::CheckButton *chkAlwaysOpenHelp; + Gtk::Button *btnReadHelp; + Gtk::Button *btnCancelHelp; + Gtk::Window *wndShowWeb; + Gtk::Button *btnOpenMenuOS; + Gtk::Entry *entrListOS; - Glib::RefPtr list_store_kernel; - Glib::RefPtr list_store_IPT; - Glib::RefPtr list_store_OTT; - #ifdef WEBKIT_FOUND - Gtk::Window *wndWeb; - Gtk::Widget *three; - WebKitWebView *one; - #endif - - void set_entry_to_tree_view(Glib::RefPtr &list_store, Gtk::Entry &entry, std::vector &vec_Option, int size); - Gtk::TreeModel::Row row_kernel; - Gtk::TreeModel::Row row_IPT; - Gtk::TreeModel::Row row_OTT; - std::map map_cmd_selection; - std::map map_global_cmd_selection; - std::map map_local_cmd_selection; + std::vector vec_Option_kernel; + std::vector vec_Option_IPT; + std::vector vec_Option_OTT; - Gtk::Label *lblDownloadMode; - Lib_save::Save obj_save = Lib_save::Save(); - Lib_Load::Load obj_load = Lib_Load::Load(); - vector vec_param_names; - My_Process::My_Process_system obj_process_system = My_Process::My_Process_system(); - My_Process::My_Process_call obj_process_call = My_Process::My_Process_call(); - bool flag_load = false; - bool flag_save_all = false; - bool flag_blocked_tree_view = false; - bool flag_save_block = false; - bool flag_open_browser = false; - string str_last_launched_os = ""; - int index_error = 0; - size_t size_kernel = 0; - size_t size_IPT = 0; - size_t size_OTT = 0; - Glib::RefPtr boxInfo; - string str_cmd_error = ""; - template - struct Result{ - Type response; - int error; - }; - std::map map_cmd_error; - - MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); - MainWindow(Glib::RefPtr const& builder); - ~MainWindow(); - void open_browser(); - void get_menu_boot(std::map &map_temp); - void set_row_all(std::map &map_cmd, Glib::RefPtr &list_store, vector &list_params, size_t size,string key); - void set_row(Glib::RefPtr &list_store, int size, std::string name, bool flag_chbox); - void get_builder(); - bool gui_exit(GdkEventAny*); - void init_dict(string flag_load); - void add_CSS(); - void show_pass(); - void localization(); - void event(); - void settings(); - string pars_last_launched_os(); - vector pars_os(vector &os_control_list); - void fn_event_intelMax1(); - void write_list_entry_os(vector &os_control_list); - void fn_event_intelMax4(); - void synopsis_show(); - void set_data_cfg(); - void set_active_boot_second(); - void get_download_mode(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 wrapper_save_all_cfg(); - void wrapper_save_local_cfg(); - void wrapper_save_global_cfg(); - bool save_template(string cmd, string cmd_remove, string flag_save); - void view_add_colums(Gtk::TreeView &treeView); - vector read_file_and_view(string file_name ,Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m); - void download_local_cfg(); - void template_open_browser(); - void download_globl_cfg(); - void flag_block_gui(); - void info_status_app(string stule); - bool check_save(string flag_save, string key_name); - void info_warning_error(int mess); - int check_root(); - bool focus_out_txt_kernel(GdkEventFocus*); - bool focus_out_txt_IPT(GdkEventFocus*); - bool focus_out_txt_OTT(GdkEventFocus*); - void fill_in_view(); - void set_security_login(); - void get_security_login(std::map &map_temp); - bool check_flag_save(string flag_save); - void set_download_mode(); - void change_password_protecc(); - bool focus_out_txt_login(GdkEventFocus*); - void change_security_login(); - void get_default_load(std::map &map_temp); - 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 cmd); - vector get_setting_entry_all(string key, std::map * map_temp); - void cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove); - 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); + Glib::RefPtr list_store_kernel; + Glib::RefPtr list_store_IPT; + Glib::RefPtr list_store_OTT; + Glib::RefPtr list_store_user; + Glib::RefPtr list_store_melody; +#ifdef WEBKIT_FOUND + Gtk::Window *wndWeb; + Gtk::Widget *three; + WebKitWebView *one; +#endif + Gtk::TreeModel::Row row_kernel; + Gtk::TreeModel::Row row_IPT; + Gtk::TreeModel::Row row_OTT; + Gtk::TreeModel::Row row_user; + Gtk::TreeModel::Row row_melody; + std::map map_cmd_selection; + std::map map_global_cmd_selection; + std::map map_local_cmd_selection; + Gtk::TreeModel::iterator iter_user_del; + Gtk::TreeModel::iterator iter_melody_del; + bool flag_validate_del_user = false; + bool flag_validate_del_melody = false; + + Gtk::Label *lblDownloadMode; + Lib_save::Save obj_save = Lib_save::Save(); + Lib_Load::Load obj_load = Lib_Load::Load(); + Menu_os obj_menu_os = Menu_os(); + vector vec_param_names; + My_Process::My_Process_system obj_process_system = My_Process::My_Process_system(); + My_Process::My_Process_call obj_process_call = My_Process::My_Process_call(); + bool flag_load = false; + bool flag_save_all = false; + bool flag_blocked_tree_view = false; + bool flag_save_block = false; + bool flag_open_browser = false; + string str_last_launched_os = ""; + int index_error = 0; + string str_flag_load = ""; + size_t size_kernel = 0; + size_t size_IPT = 0; + size_t size_OTT = 0; + Glib::RefPtr boxInfo; + string str_cmd_error = ""; + template + struct Result { + Type response; + int error; + }; + std::map map_cmd_error; + + MainWindow(BaseObjectType *obj, Glib::RefPtr const &builder); + MainWindow(Glib::RefPtr const &builder); + ~MainWindow(); + void open_browser(); + void remove_line_user(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter); + void set_entry_to_tree_view(Glib::RefPtr &list_store, Gtk::Entry &entry, std::vector &vec_Option, int size, string key); + void get_menu_boot(std::map &map_temp); + void set_row_all(std::map &map_cmd, Glib::RefPtr &list_store, vector &list_params, size_t size, string key); + void set_row(Glib::RefPtr &list_store, int size, std::string name, bool flag_chbox); + void get_builder(); + bool gui_exit(GdkEventAny *); + void init_dict(string flag_load); + void add_CSS(); + void show_pass(); + void localization(); + void event(); + void remove_user(); + void remove_melody(); + void settings(); + void validate_melody(); + void remove_line_melody(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter); + void view_add_colums_user(Gtk::TreeView &treeView); + void view_add_colums_melody(Gtk::TreeView &treeView); + void set_bat_save(Gtk::Button *btnSave); + string pars_last_launched_os(); + vector pars_os(vector &os_control_list); + void fn_event_intelMax1(); + void fn_event_intelMax4(); + void synopsis_show(); + void set_data_cfg(); + void set_data_csv_melody(); + vector>> format_os_list(vector &os_control_list); + void set_active_boot_second(); + void get_download_mode(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 wrapper_save_all_cfg(); + void wrapper_save_local_cfg(); + void wrapper_save_global_cfg(); + bool save_template(string cmd, string cmd_remove, string flag_save); + void view_add_colums(Gtk::TreeView &treeView); + vector read_file_and_view(string file_name, Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m); + void download_local_cfg(); + void set_tree_view_user(); + void template_open_browser(); + void download_globl_cfg(); + void flag_block_gui(); + void info_status_app(string stule); + bool check_save(string flag_save, string key_name); + void info_warning_error(int mess); + int check_root(); + void focus_out_txt_kernel(); + void focus_out_txt_IPT(); + void focus_out_txt_OTT(); + bool focus_in_txt_entry(GdkEventFocus*); + void fill_in_view(); + bool focus_tree_view(GdkEventFocus *); + bool check_flag_save(string flag_save); + void set_download_mode(); + void get_default_load(std::map &map_temp); + void set_entry(Gtk::Entry *entry, std::map &map_temp, string key); + void load_template(std::map *map_temp, string cmd); + vector get_setting_entry_all(string key, std::map *map_temp); + void cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove); + 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, string key); + void set_add_data_melody(Gtk::TreeModel::Row &row, bool flag, string &name, string &code); + void set_init_data_melody(std::map &map_temp); + void set_add_data_user(Gtk::TreeModel::Row &row, bool flag, string &name, string &password); + void set_init_data_user(std::map &map_temp); + void set_init_data_superuser(std::map &map_temp); }; -class SettingsPlug : public Gtk::Plug{ +class SettingsPlug : public Gtk::Plug +{ public: Gtk::Window *window; SettingsPlug(::Window p_socketID, Glib::RefPtr builder); @@ -325,5 +406,3 @@ private: }; void help(); - - diff --git a/source/util.cc b/source/util.cc index 3236cc1..f2e47de 100644 --- a/source/util.cc +++ b/source/util.cc @@ -50,6 +50,23 @@ array, 5> read_csv(const string& filename) { return array_vectors; } +vector> read_csv_melody(const string& filename) { + vector> vec_music; + ifstream file(filename); + string line; + char delimiter = ','; + while (getline(file, line)) { + stringstream stream(line); + string name; + string code; + getline(stream, name, delimiter); + getline(stream, code, delimiter); + tuple tuple_music(name, code); + vec_music.push_back(tuple_music); + } + return vec_music; +} + string call(string cmd) { FILE *fp; int status; @@ -104,66 +121,5 @@ std::vector split(std::string text, char delim) { } return vec; } -unsigned short read_uid_min_max(string filename, string search) { - std::string line; - int uid = 0; - string remove_tab = "\t"; - string remove_space = " "; - std::ifstream in(filename); // окрываем файл для чтения - if (in.is_open()){ - while (getline(in, line)){ - try{ - if (line.find(search) != string::npos && (line.find("SYS_"+search) == string::npos)) { - str_remove(line, search); - str_remove(line, remove_space); - str_remove(line, remove_tab); - uid = atoi(line.c_str()); - } - } - catch (int x) { - if (search == "UID_MIN"){ - uid = 1000; - } - else{ - uid = 65534; - } - - } - - } - } - else{ - if (search == "UID_MIN") { - uid = 1000; - } - else{ - uid = 65534; - } - } - in.close(); - return uid; - -} - -vector pars_users() { - vector vec_users; - unsigned short uid_min = read_uid_min_max("/etc/login.defs", "UID_MIN"); - unsigned short uid_max =read_uid_min_max("/etc/login.defs", "UID_MAX"); - while (true) { - errno = 0; - passwd* entry = getpwent(); - if (!entry) { - if (errno) { - break; - } - break; - } - if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) { - vec_users.push_back(string(entry->pw_name)); - } - } - endpwent(); - return vec_users; -} } \ No newline at end of file diff --git a/source/util.h b/source/util.h index 9044b95..59909c2 100644 --- a/source/util.h +++ b/source/util.h @@ -1,6 +1,7 @@ #ifndef UTIL_H #define UTIL_H #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include #include +#include using namespace std; @@ -43,9 +45,6 @@ vector find_all(string &str_ntp, string substr); void str_remove(std::string& source, std::string to_remove); void str_replace_all(string &str_base, string str_find, string str_replace); 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); +vector> read_csv_melody(const string& filename); } #endif \ No newline at end of file diff --git a/ubl-settings-bootloader.desktop b/ubl-settings-bootloader.desktop index 6e5f0d7..4a08f9a 100644 --- a/ubl-settings-bootloader.desktop +++ b/ubl-settings-bootloader.desktop @@ -1,11 +1,11 @@ [Desktop Entry] Encoding=UTF-8 Name=ubl-settings-bootloader -Name[ru]=Настройка загрузчика -GenericName=Настройка загрузчика -GenericName[ru]=Настройка загрузчика +Name[ru]=Настройка загрузки системы +GenericName=Настройка загрузки системы +GenericName[ru]=Настройка загрузки системы Comment=Bootloader setup application -Comment[ru]=Приложение для настройки загрузчика +Comment[ru]=Приложение для настройки параметров загрузки системы Type=Application Exec=pkexec ubl-settings-bootloader Icon=com.ublinux.ubl-settings-bootloader diff --git a/ubl-settings-bootloader.glade b/ubl-settings-bootloader.glade index c7a83df..c981f5d 100644 --- a/ubl-settings-bootloader.glade +++ b/ubl-settings-bootloader.glade @@ -8,46 +8,6 @@ - - True - True - True - - - True - False - - - True - False - label - - - False - True - 0 - - - - - True - True - False - True - right - - - - - - False - True - 1 - - - - - False False @@ -128,8 +88,8 @@ 5 5 5 - 6 - 6 + 5 + 5 69 com.ublinux.ubl-settings-bootloader @@ -148,8 +108,8 @@ 5 5 5 - 6 - 6 + 5 + 5 Running applications as a user with a specified priority @@ -165,6 +125,65 @@ specified priority + + True + False + + + 1 + 1 + True + False + **** + 0.009999999776482582 + + + True + True + 0 + + + + + 1 + 1 + True + True + True + + + True + False + gtk-goto-last + + + + + + False + True + 1 + + + + + 1 + 1 + True + True + True + + + 1 + 1 + True + False + 0 + + + True False @@ -261,8 +280,8 @@ specified priority - 750 - 550 + 760 + 560 False com.ublinux.ubl-settings-bootloader @@ -282,8 +301,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 25 1 @@ -302,8 +321,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 @@ -367,13 +386,19 @@ specified priority True False + 5 + 5 + 5 + 5 + 5 + 5 0.019999999552965164 in True False - 12 + 5 True @@ -393,8 +418,8 @@ specified priority 5 3 5 - 6 - 6 + 5 + 5 True @@ -411,8 +436,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 False @@ -428,8 +453,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 Seconds @@ -458,8 +483,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 Default load start 0 @@ -471,20 +496,45 @@ specified priority - + True - False + True 5 5 5 5 - 6 - 6 + 5 + 5 True True - 1 + 2 + + + + + True + True + True + 5 + 10 + 5 + 10 + 5 + 5 + + + True + False + open-menu-symbolic + + + + + False + True + 3 @@ -507,8 +557,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 Load screen display mode: start 0 @@ -524,11 +574,11 @@ specified priority True False 5 - 5 + 10 5 - 5 - 6 - 6 + 10 + 5 + 5 True @@ -540,97 +590,307 @@ specified priority False True - 3 + 2 - + True False + 5 + 10 + 5 + 10 + 5 + 5 + 0.019999999552965164 + in - - Boot menu user name: + True - True - False - 2 - 5 - 2 - 5 - 6 - 6 - True + False + + + True + False + 5 + + + True + False + vertical + + + 65 + True + True + 3 + 5 + 3 + 5 + in + + + True + False + + + True + True + + + + + + + + + + False + True + 0 + + + + + + + True + True + 0 + + + + + True + False + vertical + + + True + True + True + 5 + 10 + 5 + 10 + 5 + 5 + + + True + False + list-add + + + + + False + True + 0 + + + + + True + True + True + 5 + 10 + 5 + 10 + 3 + 10 + + + True + False + gtk-remove + + + + + False + True + 1 + + + + + False + True + 1 + + - - False - True - 0 - - - + + True - True + False + start 5 5 5 5 - 6 - 6 + 5 + 5 + Boot Menu Users + start - - True - True - 2 - False True - 4 + 5 - + True False + 5 + 10 + 5 + 10 + 5 + 5 + 0.019999999552965164 + in - - Boot menu user password: + True - True - False - 2 - 5 - 2 - 5 - 6 - 6 - True + False + + + True + False + 5 + + + True + False + vertical + + + 65 + True + True + 5 + 5 + 5 + 5 + in + + + True + False + + + True + True + + + + + + + + + + False + True + 0 + + + + + + + True + True + 0 + + + + + True + False + vertical + + + True + True + True + 5 + 10 + 5 + 10 + 5 + 5 + + + True + False + list-add + + + + + False + True + 0 + + + + + True + True + True + 5 + 10 + 5 + 10 + 3 + 10 + + + True + False + gtk-remove + + + + + False + True + 1 + + + + + False + True + 1 + + - - False - True - 0 - - - + + True - True + False + start 5 5 5 5 - 6 - 6 + 5 + 5 + Ringtone at startup + start - - True - True - 2 - @@ -651,8 +911,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 Download menu @@ -667,13 +927,19 @@ specified priority True False + 5 + 5 + 5 + 5 + 5 + 5 0.019999999552965164 in True False - 12 + 5 True @@ -684,8 +950,12 @@ specified priority 140 True True - 5 - 5 + 5 + 10 + 5 + 10 + 5 + 5 in @@ -693,7 +963,6 @@ specified priority False - -1 True True @@ -722,8 +991,8 @@ specified priority 5 5 5 - 6 - 6 + 1 + 5 Command line parameters: @@ -737,11 +1006,11 @@ specified priority True True 5 - 5 + 10 5 - 5 - 6 - 6 + 10 + 5 + 5 True @@ -769,8 +1038,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 Parameters passed to the kernel start @@ -786,13 +1055,19 @@ specified priority True False + 5 + 5 + 5 + 5 + 5 + 5 0.019999999552965164 in True False - 12 + 5 True @@ -803,8 +1078,12 @@ specified priority 140 True True - 5 - 5 + 5 + 10 + 5 + 10 + 5 + 5 in @@ -840,8 +1119,8 @@ specified priority 5 5 5 - 6 - 6 + 1 + 5 Command line parameters: @@ -855,11 +1134,11 @@ specified priority True True 5 - 5 + 10 5 - 5 - 6 - 6 + 10 + 5 + 5 True @@ -887,8 +1166,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 Terminal for input start @@ -904,13 +1183,19 @@ specified priority True False + 5 + 5 + 5 + 5 + 5 + 5 0.019999999552965164 in True False - 12 + 5 True @@ -921,8 +1206,12 @@ specified priority 140 True True - 5 - 5 + 5 + 10 + 5 + 10 + 5 + 5 in @@ -958,8 +1247,8 @@ specified priority 5 5 5 - 6 - 6 + 1 + 5 Command line parameters: @@ -973,11 +1262,11 @@ specified priority True True 5 - 5 + 10 5 - 5 - 6 - 6 + 10 + 5 + 5 True @@ -1005,8 +1294,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 Terminal for output start @@ -1242,10 +1531,110 @@ specified priority - - + + + + + + + + + False + btnOpenMenuOS + bottom + + + True + False + + + 0 + 0 + True + False + none + + + True + False + vertical + + + + + + + + True + True + 0 + + + + + 0 + 0 + True + False + none + True + + + True + False + vertical + + + 1 + 1 + True + True + True + + + True + False + start + 0 + gtk-goto-first + + + + + False + True + 0 + + + + + True + False + vertical + + + + + + False + True + 1 + + + + + + + False + True + 1 + + + + + False Внимание! @@ -1272,8 +1661,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 50 gtk-dialog-warning @@ -1294,8 +1683,8 @@ specified priority 5 5 5 - 6 - 6 + 5 + 5 Warning! @@ -1333,6 +1722,21 @@ specified priority + + True + False + none + + + True + False + vertical + + + + + + False start @@ -1358,7 +1762,7 @@ specified priority 20 20 dialog-question-symbolic - 6 + 5 False diff --git a/ubl-settings-bootloader.pot b/ubl-settings-bootloader.pot index 88dec94..7dedcd7 100644 --- a/ubl-settings-bootloader.pot +++ b/ubl-settings-bootloader.pot @@ -17,6 +17,37 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" + +msgid "Enter the name and code of the tune in the \"Ringtone at startup\" field" +msgstr "" + +msgid "Enter name and password code in the \"Boot Menu Users\" field" +msgstr "" + +msgid "Boot Menu Users" +msgstr "" + +msgid "Title" +msgstr "" + +msgid "" +msgstr "" + +msgid "Password" +msgstr "" + +msgid "Administrator" +msgstr "" + +msgid "Select" +msgstr "" + +msgid "Melody code" +msgstr "" + +msgid "Ringtone at startup" +msgstr "" + #: source/ubl-settings-bootloader.h:53 source/ubl-settings-bootloader.h:52 #: source/ubl-settings-bootloader.cc:431 source/ubl-settings-bootloader.cc:301 msgid "About" @@ -369,7 +400,7 @@ msgstr "" #: source/ubl-settings-bootloader.h:43 source/ubl-settings-bootloader.h:42 #: source/ubl-settings-bootloader.cc:419 -msgid "System boot" +msgid "System boot setup" msgstr "" #: source/ubl-settings-bootloader.h:49 source/ubl-settings-bootloader.h:48 diff --git a/ubl-settings-bootloader_ru.po b/ubl-settings-bootloader_ru.po index 73ae7f5..46c2af2 100644 --- a/ubl-settings-bootloader_ru.po +++ b/ubl-settings-bootloader_ru.po @@ -24,7 +24,7 @@ msgstr "О программе" #: source/ubl-settings-bootloader.h:44 source/ubl-settings-bootloader.h:43 msgid "About ubl-settings-bootloader" -msgstr "О программе Загрузка системы" +msgstr "О программе Настройка загрузки системы" #: source/ubl-settings-bootloader.h:92 source/ubl-settings-bootloader.h:91 #: source/ubl-settings-bootloader.cc:337 source/ubl-settings-bootloader.cc:199 @@ -37,7 +37,7 @@ msgstr "Всегда перенаправлять" #: source/ubl-settings-bootloader.h:96 source/ubl-settings-bootloader.h:95 msgid "Argument not recognized\n" -msgstr "" +msgstr "Аргумент не распознан\n" #: source/ubl-settings-bootloader.h:66 source/ubl-settings-bootloader.h:65 msgid "Boot menu user name:" @@ -349,6 +349,36 @@ msgstr "Прочитать онлайн" msgid "Save" msgstr "Сохранить" +msgid "Boot Menu Users" +msgstr "Пользователи меню загрузчика" + +msgid "Title" +msgstr "Название" + +msgid "User" +msgstr "Пользователь" + +msgid "Enter the name and code of the tune in the \"Ringtone at startup\" field" +msgstr "Введите название и код мелодии в поле \"Мелодия при загрузке\"" + +msgid "Enter name and password code in the \"Boot Menu Users\" field" +msgstr "Введите имя и код пароль в поле \"Пользователи меню загрузчика\"" + +msgid "Password" +msgstr "Пароль" + +msgid "Administrator" +msgstr "Администратор" + +msgid "Select" +msgstr "Выбор" + +msgid "Melody code" +msgstr "Код мелодии" + +msgid "Ringtone at startup" +msgstr "Мелодия при загрузке" + #: source/ubl-settings-bootloader.h:58 source/ubl-settings-bootloader.h:57 #: source/ubl-settings-bootloader.cc:434 source/ubl-settings-bootloader.cc:304 msgid "Save in global configuration" @@ -389,8 +419,8 @@ msgstr "Успешно записаны локальная и глобальна #: source/ubl-settings-bootloader.h:43 source/ubl-settings-bootloader.h:42 #: source/ubl-settings-bootloader.cc:419 -msgid "System boot" -msgstr "Загрузка системы" +msgid "System boot setup" +msgstr "Настройка загрузки системы" #: source/ubl-settings-bootloader.h:49 source/ubl-settings-bootloader.h:48 #: source/ubl-settings-bootloader.cc:427 @@ -537,7 +567,7 @@ msgstr "splash (Показать окно приветствия)" #: source/ubl-settings-bootloader.cc:439 source/ubl-settings-bootloader.cc:281 #: source/ubl-settings-bootloader.cc:286 source/ubl-settings-bootloader.cc:309 msgid "ubl-settings-bootloader" -msgstr "Загрузка системы" +msgstr "Настройка загрузки системы" #: source/ubl-settings-bootloader.h:79 source/ubl-settings-bootloader.h:78 #: source/ubl-settings-bootloader.cc:947 source/ubl-settings-bootloader.cc:547