Добавлено пространство имен в util.cc

pull/11/head
Igor Belitskiy 3 years ago
parent f0ea5a538b
commit 88724fa6cb

@ -169,7 +169,7 @@ void MainWindow::get_download_mode(string cmd, std::map <string, string> &map_te
int start_error = index_error; int start_error = index_error;
struct Result<string> res_response = this->wrapper_call(cmd); struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) { if (res_response.error == 0) {
str_replace_all(res_response.response, "\"",""); Utils::str_replace_all(res_response.response, "\"","");
if (res_response.response == "splash") { if (res_response.response == "splash") {
cmbDownloadMode->set_active(0); cmbDownloadMode->set_active(0);
map_temp["GRUB_BOOT_SILENT"] = "splash"; map_temp["GRUB_BOOT_SILENT"] = "splash";
@ -274,8 +274,8 @@ void MainWindow::get_security_login(string cmd, std::map <string, string> &map_t
// Убрать в будущем // Убрать в будущем
string default_login = "superadmin"; string default_login = "superadmin";
if (res_response.error == 0) { if (res_response.error == 0) {
str_replace_all(res_response.response, " ",""); Utils::str_replace_all(res_response.response, " ","");
str_replace_all(res_response.response, "\"",""); Utils::str_replace_all(res_response.response, "\"","");
if (res_response.response.length() > 0) { if (res_response.response.length() > 0) {
chbSecurityLogin->set_active(1); chbSecurityLogin->set_active(1);
map_temp["GRUB_USER"] = res_response.response; map_temp["GRUB_USER"] = res_response.response;
@ -343,7 +343,7 @@ void MainWindow::get_password_protec(string cmd, std::map <string, string> &map_
int start_error = index_error; int start_error = index_error;
struct Result<string> res_response = this->wrapper_call(cmd); struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) { if (res_response.error == 0) {
str_replace_all(res_response.response, "\"",""); Utils::str_replace_all(res_response.response, "\"","");
if (res_response.response.length() != 0) { if (res_response.response.length() != 0) {
chbPasswordProtecc->set_active(1); chbPasswordProtecc->set_active(1);
map_temp["GRUB_PASSWORD"] = res_response.response; map_temp["GRUB_PASSWORD"] = res_response.response;
@ -402,7 +402,7 @@ string MainWindow::dynamic_update_entry(std::map<string, string> &map_view, vect
vector<string> MainWindow::read_file_and_view(string file_name ,Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m) { vector<string> MainWindow::read_file_and_view(string file_name ,Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m) {
std::array<std::vector<std::string>, 5> arr_view = read_csv(path_resources + "/" + file_name); std::array<std::vector<std::string>, 5> arr_view = Utils::read_csv(path_resources + "/" + file_name);
std::vector<std::string> vec_Option = arr_view[0]; std::vector<std::string> vec_Option = arr_view[0];
for (size_t index = 0; index < vec_Option.size(); index++) { for (size_t index = 0; index < vec_Option.size(); index++) {
@ -540,15 +540,15 @@ vector<string> MainWindow::get_setting_entry_all(string key, string cmd, Gtk::En
vector<string> vec_params; vector<string> vec_params;
struct Result<string> res_response = this->wrapper_call(cmd); struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) { if (res_response.error == 0) {
str_replace_all(res_response.response, "\"", ""); Utils::str_replace_all(res_response.response, "\"", "");
vec_params = split(res_response.response, ' '); vec_params = Utils::split(res_response.response, ' ');
str_replace_all(res_response.response, " ", ", "); Utils::str_replace_all(res_response.response, " ", ", ");
entry_text.set_text(res_response.response); entry_text.set_text(res_response.response);
for (auto &param: vec_params) { for (auto &param: vec_params) {
map_cmd_selection[param] = "1"; map_cmd_selection[param] = "1";
map_temp[param] = "1"; map_temp[param] = "1";
} }
str_remove(res_response.response, ","); Utils::str_remove(res_response.response, ",");
map_temp[key] = res_response.response; map_temp[key] = res_response.response;
} }
else if (res_response.error == 3) { else if (res_response.error == 3) {
@ -609,8 +609,8 @@ void MainWindow::set_entry_to_tree_view(Glib::RefPtr<Gtk::ListStore> &list_store
flag_blocked_tree_view = true; flag_blocked_tree_view = true;
vector<string> vec_params; vector<string> vec_params;
std::string text = entry.get_text(); std::string text = entry.get_text();
str_replace_all(text, " ", ""); Utils::str_replace_all(text, " ", "");
vec_params = split(text, ','); vec_params = Utils::split(text, ',');
for (auto &name: vec_Option) { for (auto &name: vec_Option) {
this->set_row(list_store, size, name, false); this->set_row(list_store, size, name, false);
} }
@ -680,10 +680,10 @@ void MainWindow::set_menu_boot(string cmd = "", string cmd_remove = "") {
void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove) { void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove) {
string cmds = entry.get_text(); string cmds = entry.get_text();
str_remove(cmds, ","); Utils::str_remove(cmds, ",");
if (cmds.length() != 0) { if (cmds.length() != 0) {
cmd_settings += "\"" + cmds + "\""; cmd_settings += "\"" + cmds + "\"";
str_replace_all(cmd_settings, " \"", "\""); Utils::str_replace_all(cmd_settings, " \"", "\"");
this->wrapper_system(cmd_settings, ""); this->wrapper_system(cmd_settings, "");
} }
else { else {
@ -709,6 +709,7 @@ void MainWindow::event(){
chbSecurityLogin->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::change_security_login)); chbSecurityLogin->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::change_security_login));
cmbDownloadMode->signal_changed().connect([&]() {set_download_mode();}); cmbDownloadMode->signal_changed().connect([&]() {set_download_mode();});
chbSecurityLogin->signal_changed().connect([&]() {set_security_login();}); chbSecurityLogin->signal_changed().connect([&]() {set_security_login();});
cmbDefaultDonw->signal_changed().connect([&]() {set_default_load("","");});
spbSecond->signal_changed().connect([&]() {set_menu_boot();}); spbSecond->signal_changed().connect([&]() {set_menu_boot();});
if (this->check_root() == 0) { if (this->check_root() == 0) {
Glib::RefPtr<Gtk::TreeModel> treeViewKernelModel = treeViewKernel->get_model(); Glib::RefPtr<Gtk::TreeModel> treeViewKernelModel = treeViewKernel->get_model();
@ -742,6 +743,55 @@ void MainWindow::change_security_login() {
boxSave->set_sensitive(true); boxSave->set_sensitive(true);
} }
} }
void MainWindow::set_default_load(string cmd = "", string cmd_remove = "") {
int index = cmbDefaultDonw->get_active_row_number();
if (index == 0) {
if (cmd.length() != 0) {
wrapper_system(cmd, "");
}
else {
flag_save_local = true;
flag_save_global = true;
flag_save_all = true;
}
}
else if (index > 0) {
if (cmd_remove.length() != 0) {
wrapper_system(cmd_remove, "");
}
else {
flag_save_local = true;
flag_save_global = true;
flag_save_all = true;
}
}
if (index != 0 && index != -1) {
map_cmd_selection["GRUB_DEFAULT"] = cmbDefaultDonw->get_active_text();
}
else {
map_cmd_selection["GRUB_DEFAULT"] = "";
}
}
void MainWindow::get_default_load(string cmd, std::map <string, string> &map_temp) {
int start_error = index_error;
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
map_temp["GRUB_DEFAULT"] = res_response.response;
cmbDefaultDonw->set_active_text(res_response.response);
}
else if (res_response.error == 3) {
if (start_error != index_error) {
index_error = start_error;
cmbDefaultDonw->set_active(0);
}
map_temp["GRUB_DEFAULT"] = "";
}
else {
map_temp["GRUB_DEFAULT"] = "";
}
}
void MainWindow::change_password_protecc() { void MainWindow::change_password_protecc() {
int index = chbPasswordProtecc->get_active_row_number(); int index = chbPasswordProtecc->get_active_row_number();
@ -835,6 +885,12 @@ bool MainWindow::save_global_cfg() {
this->set_password_protec(cmd_password, cmd_password_remove); this->set_password_protec(cmd_password, cmd_password_remove);
flag_no_save = false; flag_no_save = false;
} }
if (this->check_save(flag_save, "GRUB_DEFAULT")) {
string cmd_load = "ubconfig --target global set boot GRUB_DEFAULT=";
string cmd_load_remove = "ubconfig --target global remove boot GRUB_DEFAULT";
this->set_default_load(cmd_load, cmd_load_remove);
flag_no_save = false;
}
} }
} }
map_global_cmd_selection = map_cmd_selection; map_global_cmd_selection = map_cmd_selection;
@ -897,6 +953,13 @@ bool MainWindow::save_local_cfg() {
this->set_password_protec(cmd_password, cmd_password_remove); this->set_password_protec(cmd_password, cmd_password_remove);
flag_no_save = false; flag_no_save = false;
} }
if (this->check_save(flag_save, "GRUB_DEFAULT")) {
string cmd_load = "ubconfig --target system set boot GRUB_DEFAULT=";
string cmd_load_remove = "ubconfig --target system remove boot GRUB_DEFAULT";
this->set_default_load(cmd_load, cmd_load_remove);
flag_no_save = false;
}
} }
} }
map_local_cmd_selection = map_cmd_selection; map_local_cmd_selection = map_cmd_selection;
@ -905,16 +968,16 @@ bool MainWindow::save_local_cfg() {
void MainWindow::set_data_cfg() { void MainWindow::set_data_cfg() {
string str_flags = entryKernel->get_text(); string str_flags = entryKernel->get_text();
str_remove(str_flags, ","); Utils::str_remove(str_flags, ",");
str_replace_all(str_flags, " \"", "\""); Utils::str_replace_all(str_flags, " \"", "\"");
map_cmd_selection["GRUB_CMDLINE_LINUX"] = str_flags; map_cmd_selection["GRUB_CMDLINE_LINUX"] = str_flags;
str_flags = entryIPT->get_text(); str_flags = entryIPT->get_text();
str_remove(str_flags, ","); Utils::str_remove(str_flags, ",");
str_replace_all(str_flags, " \"", "\""); Utils::str_replace_all(str_flags, " \"", "\"");
map_cmd_selection["GRUB_TERMINAL_INPUT"] = str_flags; map_cmd_selection["GRUB_TERMINAL_INPUT"] = str_flags;
str_flags = entryOTT->get_text(); str_flags = entryOTT->get_text();
str_remove(str_flags, ","); Utils::str_remove(str_flags, ",");
str_replace_all(str_flags, " \"", "\""); Utils::str_replace_all(str_flags, " \"", "\"");
map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = str_flags; map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = str_flags;
} }
@ -940,6 +1003,7 @@ void MainWindow::download_globl_cfg() {
this->get_download_mode("ubconfig --default --source global get boot GRUB_BOOT_SILENT", map_global_cmd_selection); this->get_download_mode("ubconfig --default --source global get boot GRUB_BOOT_SILENT", map_global_cmd_selection);
this->get_security_login("ubconfig --default --source global get boot GRUB_USER", map_global_cmd_selection); this->get_security_login("ubconfig --default --source global get boot GRUB_USER", map_global_cmd_selection);
this->get_password_protec("ubconfig --default --source global get boot GRUB_PASSWORD", map_global_cmd_selection); this->get_password_protec("ubconfig --default --source global get boot GRUB_PASSWORD", map_global_cmd_selection);
this->get_default_load("ubconfig --default --source global get boot GRUB_DEFAULT", map_global_cmd_selection);
info_warning_error(1); info_warning_error(1);
map_cmd_selection = map_global_cmd_selection; map_cmd_selection = map_global_cmd_selection;
@ -967,6 +1031,7 @@ void MainWindow::download_local_cfg() {
this->get_download_mode("ubconfig --default --source system get boot GRUB_BOOT_SILENT", map_local_cmd_selection); this->get_download_mode("ubconfig --default --source system get boot GRUB_BOOT_SILENT", map_local_cmd_selection);
this->get_security_login("ubconfig --default --source system get boot GRUB_USER", map_local_cmd_selection); this->get_security_login("ubconfig --default --source system get boot GRUB_USER", map_local_cmd_selection);
this->get_password_protec("ubconfig --default --source system get boot GRUB_PASSWORD", map_local_cmd_selection); this->get_password_protec("ubconfig --default --source system get boot GRUB_PASSWORD", map_local_cmd_selection);
this->get_default_load("ubconfig --default --source system get boot GRUB_DEFAULT", map_local_cmd_selection);
info_warning_error(0); info_warning_error(0);
map_cmd_selection = map_local_cmd_selection; map_cmd_selection = map_local_cmd_selection;
} }
@ -1051,7 +1116,6 @@ void MainWindow::wrapper_system(string cmd, string thread_str = "") {
} }
void MainWindow::info_status_app(string stule) { void MainWindow::info_status_app(string stule) {
boxInfo->remove_class("boxInfoMessOK"); boxInfo->remove_class("boxInfoMessOK");
boxInfo->remove_class("boxInfoMessError"); boxInfo->remove_class("boxInfoMessError");
boxInfo->add_class(stule); boxInfo->add_class(stule);
@ -1111,7 +1175,7 @@ void MainWindow::info_warning_error(int mess) {
struct MainWindow::Result<string> MainWindow::wrapper_call(string cmd) { struct MainWindow::Result<string> MainWindow::wrapper_call(string cmd) {
struct Result<string> obj_result; struct Result<string> obj_result;
string response = call(cmd); string response = Utils::call(cmd);
if ((response.find("(null)") == std::string::npos) && (response.length() != 0 )) { if ((response.find("(null)") == std::string::npos) && (response.length() != 0 )) {
if (response.find("=") != std::string::npos) { if (response.find("=") != std::string::npos) {
if (response.find("\n") != std::string::npos) { if (response.find("\n") != std::string::npos) {
@ -1152,7 +1216,7 @@ void MainWindow::log_mess_error(string &cmd) {
str_cmd_error = map_cmd_error[cmd]; str_cmd_error = map_cmd_error[cmd];
} }
else { else {
for ( const auto &map_iter: map_cmd_error ) { for (const auto &map_iter: map_cmd_error) {
key = map_iter.first; key = map_iter.first;
if (cmd.find(key) != std::string::npos){ if (cmd.find(key) != std::string::npos){
str_cmd_error = map_iter.second; str_cmd_error = map_iter.second;

@ -137,6 +137,7 @@ class MainWindow : public Gtk::ApplicationWindow {
MainWindow(Glib::RefPtr<Gtk::Builder> const& builder); MainWindow(Glib::RefPtr<Gtk::Builder> const& builder);
void get_menu_boot(string cmd, std::map <string, string> &map_temp); void get_menu_boot(string cmd, std::map <string, string> &map_temp);
void set_menu_boot(string cmd, string cmd_remove); void set_menu_boot(string cmd, string cmd_remove);
void set_default_load(string cmd, string cmd_remove);
void set_row_all(std::map <string, string> &map_cmd, Glib::RefPtr<Gtk::ListStore> &list_store, vector<string> &list_params, size_t size); void set_row_all(std::map <string, string> &map_cmd, Glib::RefPtr<Gtk::ListStore> &list_store, vector<string> &list_params, size_t size);
void set_row(Glib::RefPtr<Gtk::ListStore> &list_store, int size, std::string name, bool flag_chbox); void set_row(Glib::RefPtr<Gtk::ListStore> &list_store, int size, std::string name, bool flag_chbox);
void get_builder(); void get_builder();
@ -179,6 +180,7 @@ class MainWindow : public Gtk::ApplicationWindow {
void change_password_protecc(); void change_password_protecc();
bool focus_out_txt_login(GdkEventFocus*); bool focus_out_txt_login(GdkEventFocus*);
void change_security_login(); void change_security_login();
void get_default_load(string cmd, std::map <string, string> &map_temp);
bool focus_out_txt_password(GdkEventFocus*); bool focus_out_txt_password(GdkEventFocus*);
void get_password_protec(string cmd, std::map <string, string> &map_temp); void get_password_protec(string cmd, std::map <string, string> &map_temp);
void set_password_protec(string cmd, string cmd_remove); void set_password_protec(string cmd, string cmd_remove);

@ -1,5 +1,7 @@
#include "util.h" #include "util.h"
namespace Utils {
array<vector<string>, 5> read_csv(const string& filename) { array<vector<string>, 5> read_csv(const string& filename) {
array<vector<string>, 5> array_vectors; array<vector<string>, 5> array_vectors;
vector<string> vec_option; vector<string> vec_option;
@ -65,6 +67,7 @@ string call(string cmd) {
} }
return path; return path;
} }
vector<int> find_all(string &str_ntp, string substr) { vector<int> find_all(string &str_ntp, string substr) {
size_t index = 0; size_t index = 0;
vector<int> sub_index; vector<int> sub_index;
@ -181,4 +184,15 @@ string read_passwd(string username) {
} }
in.close(); in.close();
return passwd; return passwd;
}
int synopsis_show(string str_link) {
// gettext("https://wiki.ublinux.com/ru/Программное_обеспечениерограммы_и_утилиты/Все/")
string cmd = "xdg-open " + str_link;
if (geteuid() == 0) {
string response_user = getlogin();
cmd = "su -l " + response_user + " -c \" DISPLAY=$DISPLAY " + cmd + " \"";
}
return system(cmd.c_str());
}
} }

@ -1,3 +1,5 @@
#ifndef UTIL_H
#define UTIL_H
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -8,13 +10,26 @@
#include <linux/limits.h> #include <linux/limits.h>
#include <sys/types.h> #include <sys/types.h>
#include <pwd.h> #include <pwd.h>
#include <unistd.h>
#include <sys/types.h>
#include <iostream>
#include <map>
#include <string>
#include <array>
#include <vector>
#include <fstream>
#include <filesystem>
#include <stdio.h>
#include <map>
#include <pwd.h>
using namespace std; using namespace std;
namespace Utils {
template<typename Type> template<typename Type>
struct Result{ struct Result{
Type response; Type response;
int error; int error;
}; };
struct Passwd { struct Passwd {
@ -31,3 +46,6 @@ std::vector<std::string> split(std::string text, char delim);
unsigned short read_uid_min_max(string filename, string search); unsigned short read_uid_min_max(string filename, string search);
vector <string> pars_users(); vector <string> pars_users();
string read_passwd(string username); string read_passwd(string username);
int synopsis_show(string str_link);
}
#endif

@ -12,10 +12,10 @@
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="modal">True</property> <property name="modal">True</property>
<property name="window-position">center</property> <property name="window-position">center</property>
<property name="icon-name">ubl-settings-datetime</property> <property name="icon-name">ubl-settings-bootloader</property>
<property name="type-hint">dialog</property> <property name="type-hint">dialog</property>
<property name="urgency-hint">True</property> <property name="urgency-hint">True</property>
<property name="program-name">ubl-settings-datetime</property> <property name="program-name">ubl-settings-bootloader</property>
<property name="version">1.2</property> <property name="version">1.2</property>
<property name="copyright" translatable="yes">Copyright © 2023 - UBSoft Software LLC</property> <property name="copyright" translatable="yes">Copyright © 2023 - UBSoft Software LLC</property>
<property name="comments" translatable="yes">ubl-settings-bootloader</property> <property name="comments" translatable="yes">ubl-settings-bootloader</property>
@ -387,7 +387,7 @@ specified priority</property>
<property name="margin-end">5</property> <property name="margin-end">5</property>
<property name="margin-top">6</property> <property name="margin-top">6</property>
<property name="margin-bottom">6</property> <property name="margin-bottom">6</property>
<property name="label" translatable="yes">Default download</property> <property name="label" translatable="yes">Default load</property>
<property name="ellipsize">start</property> <property name="ellipsize">start</property>
<property name="xalign">0</property> <property name="xalign">0</property>
</object> </object>

Loading…
Cancel
Save