Исправлена проверка пустого поля в treeView

pull/18/head
Igor Belitskiy 3 years ago
parent 236e632e0a
commit abcaea34b9

@ -71,7 +71,6 @@ void MainWindow::settings(){
vec_param_names.push_back("GRUB_TERMINAL_INPUT"); vec_param_names.push_back("GRUB_TERMINAL_INPUT");
vec_param_names.push_back("GRUB_TERMINAL_OUTPUT"); vec_param_names.push_back("GRUB_TERMINAL_OUTPUT");
vec_param_names.push_back("GRUB_BOOT_SILENT"); 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_PASSWORD");
vec_param_names.push_back("GRUB_DEFAULT"); vec_param_names.push_back("GRUB_DEFAULT");
vec_param_names.push_back("GRUB_PLAY"); vec_param_names.push_back("GRUB_PLAY");
@ -228,22 +227,6 @@ void MainWindow::view_add_colums_music(Gtk::TreeView &treeView) {
treeView.append_column_editable(str_melody_code, m_columns_music.melody_code); treeView.append_column_editable(str_melody_code, m_columns_music.melody_code);
} }
void MainWindow::view_add_line_music(Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m) {
row = *(list_store_m->append());
row[m_columns_music.check_button] = false;
row[m_columns_music.title] = "";
row[m_columns_music.melody_code] = "";
}
void MainWindow::view_add_line_user(Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m) {
row = *(list_store_m->append());
row[m_columns_user.check_button] = false;
row[m_columns_user.name] = "";
row[m_columns_user.password] = "";
}
void MainWindow::item_selected_kernel(const Gtk::TreeModel::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_IPT = treeViewIPT->get_selection();
auto selection_OTT = treeViewOTT->get_selection(); auto selection_OTT = treeViewOTT->get_selection();
@ -341,79 +324,6 @@ void MainWindow::set_download_mode() {
map_cmd_selection["GRUB_BOOT_SILENT"] = key; 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 <string, string> &map_temp) {
// Todo;
std::map <string, string>:: 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 <string, string> &map_temp) {
std::map <string, string>:: 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<Gtk::ListStore> &list_store, string key) { string MainWindow::template_item_selected(int size, Glib::RefPtr<Gtk::ListStore> &list_store, string key) {
string cmds = map_cmd_selection[key]; string cmds = map_cmd_selection[key];
Utils::str_replace_all(cmds, "\"", ""); Utils::str_replace_all(cmds, "\"", "");
@ -773,8 +683,10 @@ void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cm
void MainWindow::event() { void MainWindow::event() {
btnRemoveUser->signal_clicked().connect([&]() {remove_user();}); btnRemoveUser->signal_clicked().connect([&]() {remove_user();});
btnRemoveMusic->signal_clicked().connect([&]() {remove_music();}); btnRemoveMusic->signal_clicked().connect([&]() {remove_music();});
btnAddUser->signal_clicked().connect([&]() {view_add_line_user(row_user, list_store_user);}); btnAddUser->signal_clicked().connect([&]() {string name = "", passwd = "";
btnAddMusic->signal_clicked().connect([&]() {view_add_line_music(row_music, list_store_music);}); set_add_data_user(row_user, false, name, passwd);});
btnAddMusic->signal_clicked().connect([&]() {string code = "", name = "";
set_add_data_music(row_music, false,name, code);});
btnOpenMenuOS->signal_clicked().connect([&]() {obj_menu_os.show();}); btnOpenMenuOS->signal_clicked().connect([&]() {obj_menu_os.show();});
btnCancelHelp->signal_clicked().connect([&]() {wndShowWeb->hide();}); btnCancelHelp->signal_clicked().connect([&]() {wndShowWeb->hide();});
chkAlwaysOpenHelp->signal_toggled().connect([&]() {flag_open_browser = true;}); chkAlwaysOpenHelp->signal_toggled().connect([&]() {flag_open_browser = true;});
@ -814,18 +726,27 @@ void MainWindow::event() {
this->signal_delete_event().connect(sigc::mem_fun(*this, &MainWindow::gui_exit)); 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)); chbLoadVariantSelectionTimer->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_active_boot_second));
} }
/*
void get_tree_view_user() { void MainWindow::set_tree_view_user() {
Gtk::TreeModel::Row row = list_store_user->children()[index];
string users_root = "";
string key = ""; string key = "";
string users_root = "";
Glib::RefPtr<Gtk::TreeModel> 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) { if(row) {
if (row[m_columns_user.name].length() != 0) { string superuser_name = row[m_columns_user.name] + "";
key = "GRUB_PASSWORD[" + row[m_columns_user.name] + "]="; if (row[m_columns_user.check_button] && superuser_name.length() != 0) {
map_cmd_selection[key] = row[m_columns_user.password]; key = "GRUB_PASSWORD[" + superuser_name + "]=";
if ((row[m_columns_user.password] + "") != "************") {
map_cmd_selection[key] = row[m_columns_user.password] + "";
}
else {
map_cmd_selection[key] = "";
}
if (row[m_columns_user.check_button]) { if (row[m_columns_user.check_button]) {
if (users_root.length() != 0) { if (users_root.length() != 0) {
users_root = users_root + "," + row[m_columns_user.name]; users_root = users_root + "," + superuser_name;
} }
else { else {
users_root = users_root + row[m_columns_user.name]; users_root = users_root + row[m_columns_user.name];
@ -833,13 +754,12 @@ void get_tree_view_user() {
} }
} }
} }
map_cmd_selection["GRUB_SUPERUSERS"] = users_root
} }
if (users_root.length() != 0) {
void get_tree_view_music() { map_cmd_selection["GRUB_SUPERUSERS"] = users_root;
}
} }
*/
void MainWindow::set_init_data_user(std::map<string, string> &map_temp) { void MainWindow::set_init_data_user(std::map<string, string> &map_temp) {
treeViewUser->reset_expander_column(); treeViewUser->reset_expander_column();
list_store_user = Gtk::ListStore::create(m_columns_user); list_store_user = Gtk::ListStore::create(m_columns_user);
@ -855,28 +775,65 @@ void MainWindow::set_init_data_user(std::map<string, string> &map_temp) {
Utils::str_remove(buf_key,"]"); Utils::str_remove(buf_key,"]");
if (value.length() != 0) { if (value.length() != 0) {
password = "************"; password = "************";
}
else {
password = "";
}
this->set_add_data_user(row_user, false, buf_key, password); this->set_add_data_user(row_user, false, buf_key, password);
} }
} }
}
} }
void MainWindow::set_init_data_superuser(std::map<string, string> &map_temp) { void MainWindow::set_init_data_superuser(std::map<string, string> &map_temp) {
Glib::RefPtr<Gtk::TreeModel> treeViewKernelUser = treeViewUser->get_model(); Glib::RefPtr<Gtk::TreeModel> treeViewUser_model = treeViewUser->get_model();
string names_superusers = map_temp["GRUB_SUPERUSERS"]; string names_superusers = map_temp["GRUB_SUPERUSERS"];
vector<string> vec_superusers = Utils::split(names_superusers, ','); vector<string> vec_superusers = Utils::split(names_superusers, ',');
Gtk::TreeModel::Children children = treeViewKernelUser->children(); Gtk::TreeModel::Children children = treeViewUser_model->children();
for (string& str_superuser: vec_superusers) { for (string& str_superuser: vec_superusers) {
for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter){ for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter){
Gtk::TreeModel::Row row = *iter; Gtk::TreeModel::Row row = *iter;
if (row[m_columns_user.name] == str_superuser) { if (row[m_columns_user.name] == str_superuser) {
row[m_columns_user.check_button] = true; row[m_columns_user.check_button] = true;
} }
}
}
}
void MainWindow::set_data_csv_music() {
string path_name = "";
path_name = path_name + path_resources + "/" + "grub-beeplist.csv";
string line;
string all_music = "";
string all_music_old = "";
string code_melodies = "";
ifstream in(path_name);
if (in.is_open()) {
while (getline(in, line)){
all_music_old += line + "\n";
}
}
Glib::RefPtr<Gtk::TreeModel> treeViewMusic_model = treeViewMusic->get_model();
Gtk::TreeModel::Children children = treeViewMusic_model->children();
for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter){
Gtk::TreeModel::Row row = *iter;
code_melodies = row[m_columns_music.melody_code] + "";
if (code_melodies.length() != 0 && (row[m_columns_music.title] + "").length() != 0) {
all_music += row[m_columns_music.title] + "," + code_melodies + "\n";
if (row[m_columns_music.check_button]) {
map_cmd_selection["GRUB_PLAY"] = code_melodies + "";
}
else {
map_cmd_selection["GRUB_PLAY"] = "";
}
}
else {
imgInfo->set_from_icon_name(icon_warning, Gtk::ICON_SIZE_MENU);
info_status_app(info_box_error_css);
lblWarning->set_text(str_null_music_name);
}
}
if (all_music_old != all_music) {
ofstream fout(path_name, ios_base::out | ios_base::trunc);
if (fout.is_open()) {
fout << all_music;
fout.close();
} }
} }
} }
@ -931,11 +888,58 @@ void MainWindow::remove_music() {
void MainWindow::remove_line_user(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter) { void MainWindow::remove_line_user(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter) {
iter_user_del = iter; iter_user_del = iter;
flag_validate_del_user = true; flag_validate_del_user = true;
bool flag_error = false;
string name = "";
string password = "";
Glib::RefPtr<Gtk::TreeModel> 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 {
info_status_app(info_box_ok_css);
imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU);
lblWarning->set_text("");
}
} }
void MainWindow::remove_line_music(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter) { void MainWindow::remove_line_music(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter) {
iter_music_del = iter; iter_music_del = iter;
flag_validate_del_music = true; flag_validate_del_music = true;
string code_melodies = "";
bool flag_error = false;
Glib::RefPtr<Gtk::TreeModel> treeViewMusic_model = treeViewMusic->get_model();
Gtk::TreeModel::Children children = treeViewMusic_model->children();
for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++iter){
Gtk::TreeModel::Row row = *iter;
code_melodies = row[m_columns_music.melody_code] + "";
if (code_melodies.length() == 0 && (row[m_columns_music.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_music_name);
}
else {
info_status_app(info_box_ok_css);
imgInfo->set_from_icon_name(icon_checked, Gtk::ICON_SIZE_MENU);
lblWarning->set_text("");
}
} }
bool MainWindow::focus_tree_view(GdkEventFocus*) { bool MainWindow::focus_tree_view(GdkEventFocus*) {
@ -1107,8 +1111,8 @@ void MainWindow::set_data_cfg() {
map_cmd_selection["GRUB_DEFAULT"] = ""; map_cmd_selection["GRUB_DEFAULT"] = "";
} }
this->set_download_mode(); this->set_download_mode();
this->set_security_login(); this->set_tree_view_user();
this->set_password_protec(); this->set_data_csv_music();
} }
void MainWindow::download_globl_cfg() { void MainWindow::download_globl_cfg() {
@ -1144,8 +1148,6 @@ void MainWindow::load_template(std::map<string, string>* 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_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->set_row_all(*map_temp, list_store_OTT, vec_Option_OTT, size_OTT, "GRUB_TERMINAL_OUTPUT");
this->get_download_mode(*map_temp); 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->get_default_load(*map_temp);
this->set_entry(entryKernel, *map_temp, "GRUB_CMDLINE_LINUX"); this->set_entry(entryKernel, *map_temp, "GRUB_CMDLINE_LINUX");
this->set_entry(entryIPT, *map_temp, "GRUB_TERMINAL_INPUT"); this->set_entry(entryIPT, *map_temp, "GRUB_TERMINAL_INPUT");
@ -1173,7 +1175,6 @@ void MainWindow::set_entry(Gtk::Entry* entry, std::map<string, string> &map_temp
else { else {
entry->set_text(""); entry->set_text("");
} }
} }
void MainWindow::init_dict(string flag_load) { void MainWindow::init_dict(string flag_load) {
@ -1183,7 +1184,6 @@ void MainWindow::init_dict(string flag_load) {
map_cmd_selection_n["GRUB_TERMINAL_INPUT"] = ""; map_cmd_selection_n["GRUB_TERMINAL_INPUT"] = "";
map_cmd_selection_n["GRUB_TERMINAL_OUTPUT"] = ""; map_cmd_selection_n["GRUB_TERMINAL_OUTPUT"] = "";
map_cmd_selection_n["GRUB_BOOT_SILENT"] = ""; map_cmd_selection_n["GRUB_BOOT_SILENT"] = "";
map_cmd_selection_n["GRUB_USER"] = "";
map_cmd_selection_n["GRUB_PASSWORD"] = ""; map_cmd_selection_n["GRUB_PASSWORD"] = "";
map_cmd_selection_n["GRUB_DEFAULT"] = ""; map_cmd_selection_n["GRUB_DEFAULT"] = "";
map_cmd_selection_n["GRUB_PLAY"] = ""; map_cmd_selection_n["GRUB_PLAY"] = "";

@ -103,6 +103,8 @@ void me_thread(string cmd);
#define str_description _("Description") #define str_description _("Description")
#define str_title_Boot_Menu_Users _("Boot Menu Users") #define str_title_Boot_Menu_Users _("Boot Menu Users")
#define str_title_Ringtone_Startup _("Ringtone at startup") #define str_title_Ringtone_Startup _("Ringtone at startup")
#define str_null_music_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" \ #define str_help_h _("GTK settings bootloader for UBLinux\n" \
"\n" \ "\n" \
"Usage: ubl-settings-bootloader [OPTIONS...]\n" \ "Usage: ubl-settings-bootloader [OPTIONS...]\n" \
@ -347,6 +349,7 @@ public:
void fn_event_intelMax4(); void fn_event_intelMax4();
void synopsis_show(); void synopsis_show();
void set_data_cfg(); void set_data_cfg();
void set_data_csv_music();
std::map<string, vector<string>> format_os_list(vector<string> &os_control_list); std::map<string, vector<string>> format_os_list(vector<string> &os_control_list);
void set_active_boot_second(); void set_active_boot_second();
void get_download_mode(std::map<string, string> &map_temp); void get_download_mode(std::map<string, string> &map_temp);
@ -361,6 +364,7 @@ public:
void view_add_colums(Gtk::TreeView &treeView); void view_add_colums(Gtk::TreeView &treeView);
vector<string> read_file_and_view(string file_name, Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m); vector<string> read_file_and_view(string file_name, Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m);
void download_local_cfg(); void download_local_cfg();
void set_tree_view_user();
void template_open_browser(); void template_open_browser();
void download_globl_cfg(); void download_globl_cfg();
void flag_block_gui(); void flag_block_gui();
@ -376,8 +380,6 @@ public:
bool focus_in_txt_OTT(GdkEventFocus *); bool focus_in_txt_OTT(GdkEventFocus *);
void fill_in_view(); void fill_in_view();
bool focus_tree_view(GdkEventFocus *); bool focus_tree_view(GdkEventFocus *);
void set_security_login();
void get_security_login(std::map<string, string> &map_temp);
bool check_flag_save(string flag_save); bool check_flag_save(string flag_save);
void set_download_mode(); void set_download_mode();
void change_password_protecc(); void change_password_protecc();
@ -385,8 +387,6 @@ public:
void change_security_login(); void change_security_login();
void get_default_load(std::map<string, string> &map_temp); void get_default_load(std::map<string, string> &map_temp);
bool focus_out_txt_password(GdkEventFocus *); bool focus_out_txt_password(GdkEventFocus *);
void get_password_protec(std::map<string, string> &map_temp);
void set_password_protec();
void set_entry(Gtk::Entry *entry, std::map<string, string> &map_temp, string key); void set_entry(Gtk::Entry *entry, std::map<string, string> &map_temp, string key);
void load_template(std::map<string, string> *map_temp, string cmd); void load_template(std::map<string, string> *map_temp, string cmd);
vector<string> get_setting_entry_all(string key, std::map<string, string> *map_temp); vector<string> get_setting_entry_all(string key, std::map<string, string> *map_temp);
@ -395,8 +395,6 @@ public:
void item_selected_OTT(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 &); void item_selected_IPT(const Gtk::TreeModel::Path &, const Gtk::TreeModel::iterator &);
string template_item_selected(int size, Glib::RefPtr<Gtk::ListStore> &list_store, string key); string template_item_selected(int size, Glib::RefPtr<Gtk::ListStore> &list_store, string key);
void view_add_line_user(Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m);
void view_add_line_music(Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m);
void set_add_data_music(Gtk::TreeModel::Row &row, bool flag, string &name, string &code); void set_add_data_music(Gtk::TreeModel::Row &row, bool flag, string &name, string &code);
void set_init_data_music(std::map<string, string> &map_temp); void set_init_data_music(std::map<string, string> &map_temp);
void set_add_data_user(Gtk::TreeModel::Row &row, bool flag, string &name, string &password); void set_add_data_user(Gtk::TreeModel::Row &row, bool flag, string &name, string &password);

@ -17,6 +17,13 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\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" msgid "Boot Menu Users"
msgstr "" msgstr ""

@ -358,6 +358,12 @@ msgstr "Название"
msgid "User" msgid "User"
msgstr "Пользователь" 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" msgid "Password"
msgstr "Пароль" msgstr "Пароль"

Loading…
Cancel
Save