Начата работа по реализации функционала проверки изменений перед сохранением

pull/11/head
Igor Belitskiy 3 years ago
parent 5de6ad547d
commit c8087ee164

@ -170,25 +170,32 @@ void MainWindow::get_download_mode(string cmd) {
str_replace_all(res_response.response, "\"","");
if (res_response.response == "splash") {
cmbDownloadMode->set_active(0);
map_cmd_selection["GRUB_BOOT_SILENT"] = "";
}
else if (res_response.response == "splash quiet ub.silent") {
cmbDownloadMode->set_active(1);
map_cmd_selection["GRUB_BOOT_SILENT"] = "";
}
else if (res_response.response == "quiet ub.silent") {
cmbDownloadMode->set_active(2);
map_cmd_selection["GRUB_BOOT_SILENT"] = "";
}
else if (res_response.response == "plymouth.enable=0") {
cmbDownloadMode->set_active(3);
map_cmd_selection["GRUB_BOOT_SILENT"] = "";
}
else{
cmbDownloadMode->set_active(-1);
map_cmd_selection["GRUB_BOOT_SILENT"] = "";
}
}
else if (res_response.error == 3) {
cmbDownloadMode->set_active(-1);
map_cmd_selection["GRUB_BOOT_SILENT"] = "";
}
else {
cmbDownloadMode->set_active(-1);
map_cmd_selection["GRUB_BOOT_SILENT"] = "";
}
}
@ -219,7 +226,10 @@ void MainWindow::set_security_login(string cmd) {
int index = chbSecurityLogin->get_active_row_number();
string key = "";
if (index == 0){
// TODO:
// Не правильно
key = "superadmin";
}
else if (index == 1) {
key = string(getlogin());
@ -231,6 +241,7 @@ void MainWindow::set_security_login(string cmd) {
cmd = cmd + key;
wrapper_system(cmd, "");
}
void MainWindow::get_security_login(string cmd) {
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
@ -239,42 +250,80 @@ void MainWindow::get_security_login(string cmd) {
entrySecurityLogin->set_text(res_response.response);
if (res_response.response == getlogin()) {
chbSecurityLogin->set_active(1);
map_cmd_selection["GRUB_USER"] = "";
}
else if (res_response.response.length() != 0) {
chbSecurityLogin->set_active(0);
map_cmd_selection["GRUB_USER"] = "";
}
else{
chbSecurityLogin->set_active(-1);
map_cmd_selection["GRUB_USER"] = "";
}
}
else if (res_response.error == 3) {
chbSecurityLogin->set_active(-1);
map_cmd_selection["GRUB_USER"] = "";
}
else {
chbSecurityLogin->set_active(-1);
map_cmd_selection["GRUB_USER"] = "";
}
}
void MainWindow::set_password_protec(string cmd) {
// TODO:
// Не работает
int index = chbSecurityLogin->get_active_row_number();
string key = "";
if (index == 0){
key = "";
}
else if (index == 1) {
key = "";
}
else if (index == 2) {
key = "";
}
else {
return;
}
entrySecurityLogin->set_text(key);
cmd = cmd + key;
wrapper_system(cmd, "");
}
void MainWindow::get_password_protec(string cmd) {
// TODO:
// Не работает
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
cout << res_response.response << endl;
str_replace_all(res_response.response, "\"","");
entrySecurityLogin->set_text(res_response.response);
if (res_response.response == getlogin()) {
chbSecurityLogin->set_active(0);
map_cmd_selection["GRUB_PASSWORD"] = "";
}
else if (res_response.response.length() != 0) {
chbSecurityLogin->set_active(1);
map_cmd_selection["GRUB_PASSWORD"] = "";
}
else if (res_response.response.length() != 0) {
chbSecurityLogin->set_active(0);
chbSecurityLogin->set_active(2);
map_cmd_selection["GRUB_PASSWORD"] = "";
}
else{
map_cmd_selection["GRUB_PASSWORD"] = "";
chbSecurityLogin->set_active(-1);
}
}
else if (res_response.error == 3) {
map_cmd_selection["GRUB_PASSWORD"] = "";
chbSecurityLogin->set_active(-1);
}
else {
map_cmd_selection["GRUB_PASSWORD"] = "";
chbSecurityLogin->set_active(-1);
}
}
@ -434,6 +483,10 @@ void MainWindow::localization(){
chbSecurityLogin->append(gettext("Default"));
chbSecurityLogin->append(gettext("Mine"));
chbPasswordProtecc->append(gettext("Default"));
chbPasswordProtecc->append(gettext("Mine"));
chbPasswordProtecc->append(gettext("Disabled"));
cmbDownloadMode->append(gettext("Plymouth graphics, full log"));
cmbDownloadMode->append(gettext("Plymouth graphics, no log"));
cmbDownloadMode->append(gettext("No plymouth, minimal log"));
@ -492,8 +545,8 @@ void MainWindow::set_entry_to_tree_view(Glib::RefPtr<Gtk::ListStore> &list_store
}
void MainWindow::get_menu_boot(string cmd) {
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
map_cmd_selection["GRUB_TIMEOUT"] = res_response.response;
spbSecond->set_value(atoi(res_response.response.c_str()));
}
else if (res_response.error == 3) {
@ -509,34 +562,16 @@ void MainWindow::set_menu_boot(string cmd) {
int value = spbSecond->get_value();
std::string seconds = to_string(value);
cmd += seconds;
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
}
else if (res_response.error == 3) {
}
else {
this->wrapper_system(cmd, "");
}
}
void MainWindow::cmd_entry_all(string cmd_settings_kernel,string cmd_settings_IPT,string cmd_settings_OTT) {
string cmd_kernel = entryKernel->get_text();
string cmd_IPT = entryIPT->get_text();
string cmd_OTT = entryOTT->get_text();
str_remove(cmd_kernel, ",");
str_remove(cmd_IPT, ",");
str_remove(cmd_OTT, ",");
cmd_settings_kernel += "\"" + cmd_kernel + "\"";
cmd_settings_IPT += "\"" + cmd_IPT + "\"";
cmd_settings_OTT += "\"" + cmd_OTT + "\"";
str_replace_all(cmd_settings_kernel, " \"", "\"");
str_replace_all(cmd_settings_IPT, " \"", "\"");
str_replace_all(cmd_settings_OTT, " \"", "\"");
this->wrapper_system(cmd_settings_kernel, "");
this->wrapper_system(cmd_settings_IPT, "");
this->wrapper_system(cmd_settings_OTT, "");
void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings) {
string cmds = entry.get_text();
str_remove(cmds, ",");
cmd_settings += "\"" + cmds + "\"";
str_replace_all(cmd_settings, " \"", "\"");
this->wrapper_system(cmd_settings, "");
}
void MainWindow::event(){
btnSynopsis->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::synopsis_show));
@ -565,78 +600,116 @@ void MainWindow::event(){
void MainWindow::save_global_local_cfg() {
if (flag_save_global) {
std::string cmd_boot_time = "ubconfig --target global set boot GRUB_TIMEOUT=";
this->set_menu_boot(cmd_boot_time);
string cmd_settings_kernel = "ubconfig --target global set boot GRUB_CMDLINE_LINUX=";
string cmd_settings_IPT = "ubconfig --target global set boot GRUB_TERMINAL_OUTPUT=";
string cmd_settings_OTT = "ubconfig --target global set boot GRUB_TERMINAL_INPUT=";
this->cmd_entry_all(cmd_settings_kernel,cmd_settings_IPT,cmd_settings_OTT);
this->set_download_mode("ubconfig --target global set boot GRUB_BOOT_SILENT=");
this->set_security_login("ubconfig --target global set boot GRUB_USER=");
flag_save_all = false;
}
if (flag_save_local) {
std::string cmd_boot_time = "ubconfig --target system set boot GRUB_TIMEOUT=";
this->set_menu_boot(cmd_boot_time);
string cmd_settings_kernel = "ubconfig --target system set boot GRUB_CMDLINE_LINUX=";
string cmd_settings_IPT = "ubconfig --target system set boot GRUB_TERMINAL_OUTPUT=";
string cmd_settings_OTT = "ubconfig --target system set boot GRUB_TERMINAL_INPUT=";
this->cmd_entry_all(cmd_settings_kernel,cmd_settings_IPT,cmd_settings_OTT);
this->set_download_mode("ubconfig --target system set boot GRUB_BOOT_SILENT=");
this->set_security_login("ubconfig --target system set boot GRUB_USER=");
flag_save_all = false;
}
else if (flag_save_local == false && flag_save_local == false) {
info_status_app("boxInfoMessOK");
lblWarning->set_text(gettext("Nothing to save!"));
}
info_warning_error(4);
}
void MainWindow::save_global_cfg() {
string flag_save = "global";
bool flag_no_save = true;
if (flag_save_global) {
if (flag_save_all) {
std::string cmd_boot_time = "ubconfig --target global set boot GRUB_TIMEOUT=";
this->set_menu_boot(cmd_boot_time);
string cmd_settings_kernel = "ubconfig --target global set boot GRUB_CMDLINE_LINUX=";
string cmd_settings_IPT = "ubconfig --target global set boot GRUB_TERMINAL_OUTPUT";
string cmd_settings_OTT = "ubconfig --target global set boot GRUB_TERMINAL_INPUT=";
this->cmd_entry_all(cmd_settings_kernel,cmd_settings_IPT,cmd_settings_OTT);
this->set_download_mode("ubconfig --target global set boot GRUB_BOOT_SILENT=");
this->set_security_login("ubconfig --target global set boot GRUB_USER=");
flag_save_global = false;
if (this->check_save(flag_save, "GRUB_TIMEOUT")) {
std::string cmd_boot_time = "ubconfig --target global set boot GRUB_TIMEOUT=";
this->set_menu_boot(cmd_boot_time);
flag_no_save = false;
}
if (this->check_save(flag_save, "")) {
string cmd_settings_kernel = "ubconfig --target global set boot GRUB_CMDLINE_LINUX=";
this->cmd_entry_all(*entryKernel, cmd_settings_kernel);
flag_no_save = false;
}
if (this->check_save(flag_save, "")) {
string cmd_settings_IPT = "ubconfig --target global set boot GRUB_TERMINAL_OUTPUT";
this->cmd_entry_all(*entryIPT, cmd_settings_IPT);
flag_no_save = false;
}
if (this->check_save(flag_save, "")) {
string cmd_settings_OTT = "ubconfig --target global set boot GRUB_TERMINAL_INPUT=";
this->cmd_entry_all(*entryOTT, cmd_settings_OTT);
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_BOOT_SILENT")) {
this->set_download_mode("ubconfig --target global set boot GRUB_BOOT_SILENT=");
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_USER")) {
this->set_security_login("ubconfig --target global set boot GRUB_USER=");
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_PASSWORD")) {
this->set_password_protec("ubconfig --target global set boot GRUB_PASSWORD=");
flag_no_save = false;
}
flag_save_local = true;
}
}
else{
else {
info_status_app("boxInfoMessOK");
lblWarning->set_text(gettext("Nothing to save!"));
}
info_warning_error(3);
map_global_cmd_selection = map_cmd_selection;
map_global_cmd_selection = map_local_cmd_selection;
if (flag_no_save){
info_status_app("boxInfoMessOK");
lblWarning->set_text(gettext("Nothing to save!"));
}
else {
info_warning_error(3);
}
}
void MainWindow::save_local_cfg() {
string flag_save = "local";
bool flag_no_save = true;
if (flag_save_local) {
if (flag_save_all) {
std::string cmd_boot_time = "ubconfig --target system set boot GRUB_TIMEOUT=";
this->set_menu_boot(cmd_boot_time);
string cmd_settings_kernel = "ubconfig --target system set boot GRUB_CMDLINE_LINUX=";
string cmd_settings_IPT = "ubconfig --target system set boot GRUB_TERMINAL_OUTPUT";
string cmd_settings_OTT = "ubconfig --target system set boot GRUB_TERMINAL_INPUT=";
this->cmd_entry_all(cmd_settings_kernel,cmd_settings_IPT,cmd_settings_OTT);
this->set_download_mode("ubconfig --target system set boot GRUB_BOOT_SILENT=");
this->set_security_login("ubconfig --target system set boot GRUB_USER=");
if (this->check_save(flag_save, "GRUB_TIMEOUT")) {
std::string cmd_boot_time = "ubconfig --target system set boot GRUB_TIMEOUT=";
this->set_menu_boot(cmd_boot_time);
flag_no_save = false;
}
if (this->check_save(flag_save, "")) {
string cmd_settings_kernel = "ubconfig --target system set boot GRUB_CMDLINE_LINUX=";
this->cmd_entry_all(*entryKernel, cmd_settings_kernel);
flag_no_save = false;
}
if (this->check_save(flag_save, "")) {
string cmd_settings_IPT = "ubconfig --target system set boot GRUB_TERMINAL_OUTPUT";
this->cmd_entry_all(*entryIPT, cmd_settings_IPT);
flag_no_save = false;
}
if (this->check_save(flag_save, "")) {
string cmd_settings_OTT = "ubconfig --target system set boot GRUB_TERMINAL_INPUT=";
this->cmd_entry_all(*entryOTT, cmd_settings_OTT);
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_BOOT_SILENT")) {
this->set_download_mode("ubconfig --target system set boot GRUB_BOOT_SILENT=");
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_USER")) {
this->set_security_login("ubconfig --target system set boot GRUB_USER=");
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_PASSWORD")) {
this->set_password_protec("ubconfig --target system set boot GRUB_PASSWORD=");
flag_no_save = false;
}
flag_save_local = true;
}
}
else {
flag_no_save = false;
}
map_global_cmd_selection = map_cmd_selection;
map_global_cmd_selection = map_local_cmd_selection;
if (flag_no_save){
info_status_app("boxInfoMessOK");
lblWarning->set_text(gettext("Nothing to save!"));
}
info_warning_error(2);
else {
info_warning_error(2);
}
}
void MainWindow::download_globl_cfg() {
@ -660,6 +733,7 @@ void MainWindow::download_globl_cfg() {
this->set_row_all(map_global_cmd_selection, list_store_OTT, vec_Option_OTT, size_OTT);
this->get_download_mode("ubconfig --default --source global get boot GRUB_BOOT_SILENT");
this->get_security_login("ubconfig --default --source global get boot GRUB_USER");
this->get_password_protec("ubconfig --default --source global get boot GRUB_PASSWORD");
info_warning_error(1);
}
@ -684,7 +758,58 @@ void MainWindow::download_local_cfg() {
this->set_row_all(map_local_cmd_selection, list_store_OTT, vec_Option_OTT, size_OTT);
this->get_download_mode("ubconfig --default --source system get boot GRUB_BOOT_SILENT");
this->get_security_login("ubconfig --default --source system get boot GRUB_USER");
this->get_password_protec("ubconfig --default --source system get boot GRUB_PASSWORD");
info_warning_error(0);
}
bool MainWindow::check_save(string flag_save, string key_name="") {
std::map <string, string>:: iterator iter_map_data;
std::map <string, string>:: iterator iter_map_data_local;
std::map <string, string>:: iterator iter_map_data_global;
std::map <string, string>:: iterator iter_map_data_old;
std::map <string, string> map_config_data;
std::map <string, string> map_config_data_local;
std::map <string, string> map_config_data_global;
std::map <string, string> map_config_data_old;
if (flag_save == "all") {
map_config_data = map_cmd_selection;
}
else if (flag_save == "local") {
map_config_data_old = map_local_cmd_selection;
map_config_data_local = map_local_cmd_selection;
}
else if (flag_save == "global") {
map_config_data_old = map_global_cmd_selection;
map_config_data_global = map_global_cmd_selection;
}
else {
// TODO:
// Убрать
throw std::logic_error("Ошибка по невнимательности");
}
iter_map_data = map_config_data.find(key_name);
iter_map_data_old = map_config_data_old.find(key_name);
if (iter_map_data == map_config_data.end()) {
return false;
}
else if (iter_map_data_old == map_config_data_old.end()) {
return false;
}
else if (iter_map_data->second != iter_map_data_old->second) {
return false;
}
else if (iter_map_data->second.length() == 0 || iter_map_data_old->second.length() == 0) {
return true;
}
else if (iter_map_data->second == iter_map_data_old->second) {
return true;
}
else {
return false;
}
return false;
}

@ -160,6 +160,7 @@ class MainWindow : public Gtk::ApplicationWindow {
void download_local_cfg();
void download_globl_cfg();
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*);
@ -168,9 +169,12 @@ class MainWindow : public Gtk::ApplicationWindow {
void fill_in_view();
void set_security_login(string cmd);
void get_security_login(string cmd);
bool check_flag_save(string flag_save);
void set_download_mode(string cmd);
void get_password_protec(string cmd);
void set_password_protec(string cmd);
vector<string> get_setting_entry_all(string cmd, Gtk::Entry &entry_text, std::map <string, string> &map_temp);
void cmd_entry_all(string cmd_settings_kernel,string cmd_settings_IPT,string cmd_settings_OTT);
void cmd_entry_all(Gtk::Entry &entry, string cmd_settings);
string dynamic_update_entry(std::map<string, string> &map_view, vector<string> &vec_allowed);
void item_selected_kernel(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&);
void item_selected_OTT(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&);

@ -22,6 +22,9 @@ msgstr "Графика plymouth, полный лог"
msgid "Mine"
msgstr "Свой"
msgid "Disabled"
msgstr "Отключён"
msgid "Default"
msgstr "По умолчанию"

Loading…
Cancel
Save