You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ubl-settings-bootloader/source/ubl-settings-bootloader.cc

884 lines
35 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "ubl-settings-bootloader.h"
using namespace std;
string path_app = "/usr/bin/";
string path_glade= "/usr/share/ubl-settings-bootloader/ui/ubl-settings-bootloader.glade";
string path_css = "/usr/share/ubl-settings-bootloader/css/ubl-settings-bootloader.css";
string app_name = "ubl-settings-bootloader";
string path_resources = "/usr/share/ubl-settings-bootloader";
const string path_img_head_background = "/usr/share/ubl-settings-bootloader/images/logo-background.png";
int socket_ext_id_I = 0;
int socket_trd_id_I = 0;
string version_application = "1.0";
CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_description, const std::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);
}
::Window CmdArgParser::GetSocketID() const{
return m_socketID;
}
SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr<Gtk::Builder> builder)
: Gtk::Plug{p_socketID} {
MainWindow* wnd = nullptr;
builder->get_widget_derived("window", wnd);
builder->get_widget("plugBox", plugBox);
plugBox->get_parent()->remove(*plugBox);
add(*plugBox);
show_all_children();
}
int MainWindow::check_root() {
if (geteuid() != 0) {
//lblMessageSudo->set_text(gettext("The program must be run with \nsuperuser privileges!"));
//mess_sudo->show();
return 1;
}
return 0;
}
MainWindow::MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder)
: Gtk::ApplicationWindow(obj), builder{builder} {
this->builder = builder;
this->settings();
}
MainWindow::MainWindow(Glib::RefPtr<Gtk::Builder> const& builder) {
this->builder = builder;
this->settings();
}
void MainWindow::settings(){
map_cmd_error[""] = "";
this->get_builder();
this->localization();
this->add_CSS();
Gtk::Widget *boxWidget;
builder->get_widget("boxColor", boxWidget);
overHead->add_overlay(*boxWidget);
btnBoxAboutDialog->set_visible(false);
ubl_make_plugs(boxSave,boxButton, socket_ext_id_I, socket_trd_id_I);
if (this->check_root() == 0) {
spbSecond->set_range(1, 60);
spbSecond->set_increments(1.0, 1.0);
this->fill_in_view();
this->download_local_cfg();
this->download_globl_cfg();
entrySecurityLogin->set_sensitive(false);
this->event();
}
else{
boxWidgetAll->set_sensitive(false);
btnLoad->set_sensitive(false);
boxSave->set_sensitive(false);
imgInfo->set_from_icon_name("com.ublinux.ubl-settings-bootloader.warning", Gtk::ICON_SIZE_MENU);
info_status_app("boxInfoMessError");
lblWarning->set_text(gettext("The program must be run as root"));
this->event();
}
}
void MainWindow::fill_in_view() {
list_store_kernel = Gtk::ListStore::create(m_columns);
list_store_IPT = Gtk::ListStore::create(m_columns);
list_store_OTT = Gtk::ListStore::create(m_columns);
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("boot-options.csv", row_kernel, list_store_kernel);
vec_Option_IPT = this->read_file_and_view("input-options.csv", row_IPT, list_store_IPT);
vec_Option_OTT = this->read_file_and_view("output-options.csv", row_OTT, list_store_OTT);
size_kernel = vec_Option_kernel.size();
size_IPT = vec_Option_IPT.size();
size_OTT = vec_Option_OTT.size();
this->view_add_colums(*treeViewKernel);
this->view_add_colums(*treeViewIPT);
this->view_add_colums(*treeViewOTT);
std::vector<Gtk::TreeViewColumn*> treeViewKernalCol = treeViewKernel->get_columns();
}
void MainWindow::item_selected_kernel(const Gtk::TreeModel::Path& 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();
flag_save_local = true;
flag_save_global = true;
flag_save_all = true;
if (flag_blocked_tree_view == false) {
template_item_selected(map_cmd_selection, path, list_store_kernel);
string str_flags = this->dynamic_update_entry(map_cmd_selection, vec_Option_kernel);
entryKernel->set_text(str_flags);
}
}
void MainWindow::item_selected_OTT(const Gtk::TreeModel::Path& 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();
flag_save_local = true;
flag_save_global = true;
flag_save_all = true;
if (flag_blocked_tree_view == false) {
template_item_selected(map_cmd_selection , path, list_store_OTT);
string str_flags = this->dynamic_update_entry(map_cmd_selection, vec_Option_OTT);
entryOTT->set_text(str_flags);
}
}
void MainWindow::item_selected_IPT(const Gtk::TreeModel::Path& 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();
flag_save_local = true;
flag_save_global = true;
flag_save_all = true;
if (flag_blocked_tree_view == false) {
template_item_selected(map_cmd_selection , path, list_store_IPT);
string str_flags = this->dynamic_update_entry(map_cmd_selection, vec_Option_IPT);
entryIPT->set_text(str_flags);
}
}
void MainWindow::get_download_mode(string cmd) {
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
str_replace_all(res_response.response, "\"","");
if (res_response.response == "splash") {
cmbDownloadMode->set_active(0);
}
else if (res_response.response == "splash quiet ub.silent") {
cmbDownloadMode->set_active(1);
}
else if (res_response.response == "quiet ub.silent") {
cmbDownloadMode->set_active(2);
}
else if (res_response.response == "plymouth.enable=0") {
cmbDownloadMode->set_active(3);
}
else{
cmbDownloadMode->set_active(-1);
}
}
else if (res_response.error == 3) {
cmbDownloadMode->set_active(-1);
}
else {
cmbDownloadMode->set_active(-1);
}
}
void MainWindow::set_download_mode(string cmd) {
int index = cmbDownloadMode->get_active_row_number();
string key = "";
if (index == 0) {
key = "splash";
}
else if (index == 1) {
key = "splash quiet ub.silent";
}
else if (index == 2) {
key = "quiet ub.silent";
}
else if (index == 3) {
key = "plymouth.enable=0";
}
else{
return;
}
cmd +="\"" + key + "\"";
wrapper_system(cmd, "");
}
void MainWindow::set_security_login(string cmd) {
int index = chbSecurityLogin->get_active_row_number();
string key = "";
if (index == 0){
key = "superadmin";
}
else if (index == 1) {
key = string(getlogin());
}
else {
return;
}
entrySecurityLogin->set_text(key);
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) {
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(1);
}
else if (res_response.response.length() != 0) {
chbSecurityLogin->set_active(0);
}
else{
chbSecurityLogin->set_active(-1);
}
}
else if (res_response.error == 3) {
chbSecurityLogin->set_active(-1);
}
else {
chbSecurityLogin->set_active(-1);
}
}
void MainWindow::set_password_protec(string cmd) {
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(1);
}
else if (res_response.response.length() != 0) {
chbSecurityLogin->set_active(0);
}
else{
chbSecurityLogin->set_active(-1);
}
}
else if (res_response.error == 3) {
chbSecurityLogin->set_active(-1);
}
else {
chbSecurityLogin->set_active(-1);
}
}
void MainWindow::template_item_selected(std::map<string, string> &map_view, const Gtk::TreeModel::Path& path, Glib::RefPtr<Gtk::ListStore> &list_store) {
const auto iter = list_store->get_iter(path);
if(iter) {
const auto row = *iter;
Glib::ustring cmd;
bool check_btn = row[m_columns.check_button];
if (check_btn) {
cmd = "1";
}
else {
cmd = "0";
}
Glib::ustring name = row[m_columns.name];
map_view[name] = cmd;
}
}
string MainWindow::dynamic_update_entry(std::map<string, string> &map_view, vector<string> &vec_allowed) {
string keys = "";
for (auto &key: vec_allowed) {
if (map_view.find(key) != map_view.end()) {
if (map_view[key] == "1") {
keys += string(key) + ", ";
}
}
}
return keys;
}
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::vector<std::string> 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);
}
return vec_Option;
}
void MainWindow::view_add_colums(Gtk::TreeView &treeView) {
treeView.append_column_editable(gettext("Active"), m_columns.check_button);
treeView.append_column(gettext("Option"), m_columns.name);
treeView.append_column(gettext("Description"), m_columns.description);
}
void MainWindow::view_add_cell(Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m , std::array<std::vector<std::string>, 5> &arr_view , size_t index) {
row = *(list_store_m->append());
bool flag_chb = false;
string name = arr_view[0][index];
row[m_columns.check_button] = flag_chb;
row[m_columns.name] = gettext(name.c_str());
row[m_columns.description] = gettext(arr_view[1][index].c_str());
}
void MainWindow::get_builder(){
builder->get_widget("chbLoadVariantSelectionTimer", chbLoadVariantSelectionTimer);
builder->get_widget("chbLastSelectionWillBecome", chbLastSelectionWillBecome);
builder->get_widget("lblInfoCommand", lblInfoCommand);
builder->get_widget("lblInfoCommand1", lblInfoCommand1);
builder->get_widget("lblInfoCommand2", lblInfoCommand2);
builder->get_widget("lblInfoDefaultDonw", lblInfoDefaultDonw);
builder->get_widget("lblInfoSeconds", lblInfoSeconds);
builder->get_widget("lblLoadMenu", lblLoadMenu);
builder->get_widget("lblInfoInputTerminal", lblInfoInputTerminal);
builder->get_widget("lblInfoOutputTerminal", lblInfoOutputTerminal);
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);
builder->get_widget("btnLoadLocal", btnLoadLocal);
builder->get_widget("btnLoadGlob", btnLoadGlob);
builder->get_widget("btnSaveLocalGlob", btnSaveLocalGlob);
builder->get_widget("btnSaveLocal", btnSaveLocal);
builder->get_widget("btnSaveGlob", btnSaveGlob);
builder->get_widget("btnSettings", btnSettings);
builder->get_widget("btnLoad", btnLoad);
builder->get_widget("btnSave", btnSave);
builder->get_widget("boxButton", boxButton);
builder->get_widget("boxSave", boxSave);
builder->get_widget("boxInfoError", boxInfoError);
builder->get_widget("lblWarning", lblWarning);
builder->get_widget("imgInfo", imgInfo);
builder->get_widget("btnBoxAboutDialog", btnBoxAboutDialog);
builder->get_widget("treeViewKernel", treeViewKernel);
builder->get_widget("treeViewOTT", treeViewOTT);
builder->get_widget("treeViewIPT", treeViewIPT);
builder->get_widget("imgBG", imgBG);
builder->get_widget("overHead", overHead);
builder->get_widget("lblDownloadMode", lblDownloadMode);
builder->get_widget("lblSecurityLogin", lblSecurityLogin);
builder->get_widget("lblPasswordProtec", lblPasswordProtec);
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);
}
void MainWindow::localization(){
time_t now = time(0);
tm *ltm = localtime(&now);
unsigned int year = 1900+ ltm->tm_year;
string str_authors = string(gettext("Copyright © UBSoft LLC, 2022 - ")) + to_string(year);
aboutWindows->set_copyright(str_authors);
aboutWindows->set_comments(gettext("ubl-settings-bootloader"));
aboutWindows->set_website(gettext("https://wiki.ublinux.com"));
aboutWindows->set_version(gettext(version_application.c_str()));
aboutWindows->set_website_label(gettext("Project Home Page"));
lblInfoHead->set_text(gettext("Configuring system boot parameters"));
lblHeaderName->set_text(gettext("ubl-settings-bootloader"));
aboutWindows->set_comments(gettext("Setting bootloader"));
aboutWindows->set_website_label(gettext("Project Home Page"));
lblInfoCommand->set_text(gettext("Command line parameters:"));
lblInfoCommand1->set_text(gettext("Command line parameters:"));
lblInfoCommand2->set_text(gettext("Command line parameters:"));
lblInfoDefaultDonw->set_text(gettext("Default download"));
lblInfoSeconds->set_text(gettext("Seconds"));
lblLoadMenu->set_text(gettext("Download menu"));
lblInfoInputTerminal->set_text(gettext("Terminal for input"));
lblInfoOutputTerminal->set_text(gettext("Terminal for output"));
chbLoadVariantSelectionTimer->set_label(gettext("Load variant selection timer"));
chbLastSelectionWillBecome->set_label(gettext("The last selection will become the default boot choice"));
btnSynopsis->set_label(gettext("Help"));
btnAbout->set_label(gettext("About"));
btnSaveLocalGlob->set_label(gettext("Save to global and local configuration"));
btnSaveLocal->set_label(gettext("Save local configuration"));
btnSaveGlob->set_label(gettext("Save global configuration"));
btnLoadGlob->set_label(gettext("Load global configuration"));
btnLoadLocal->set_label(gettext("Load local configuration"));
btnSave->set_label(gettext("Save"));
btnLoad->set_label(gettext("Load"));
this->set_title(gettext("ubl-settings-bootloader"));
lblDownloadMode->set_text(gettext("Download mode:"));
lblSecurityLogin->set_text(gettext("Security login:"));
lblPasswordProtec->set_text(gettext("Password protection:"));
chbSecurityLogin->append(gettext("Default"));
chbSecurityLogin->append(gettext("Mine"));
cmbDownloadMode->append(gettext("Plymouth graphics, full log"));
cmbDownloadMode->append(gettext("Plymouth graphics, no log"));
cmbDownloadMode->append(gettext("No plymouth, minimal log"));
cmbDownloadMode->append(gettext("Without plymouth, full log"));
}
vector<string> MainWindow::get_setting_entry_all(string cmd, Gtk::Entry &entry_text, std::map <string, string> &map_temp) {
vector<string> vec_params;
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
str_replace_all(res_response.response, "\"", "");
vec_params = split(res_response.response, ' ');
str_replace_all(res_response.response, " ", ", ");
entry_text.set_text(res_response.response);
for (auto &param: vec_params) {
map_cmd_selection[param] = "1";
map_temp[param] = "1";
}
}
else if (res_response.error == 3) {
}
else {
}
return vec_params;
}
bool MainWindow::focus_out_txt_kernel(GdkEventFocus*) {
this->set_entry_to_tree_view(list_store_kernel, *entryKernel, vec_Option_kernel, size_kernel);
return true;
}
bool MainWindow::focus_out_txt_IPT(GdkEventFocus*) {
this->set_entry_to_tree_view(list_store_IPT, *entryIPT, vec_Option_IPT, size_IPT);
return true;
}
bool MainWindow::focus_out_txt_OTT(GdkEventFocus*) {
this->set_entry_to_tree_view(list_store_OTT, *entryOTT, vec_Option_OTT, size_OTT);
return true;
}
void MainWindow::set_entry_to_tree_view(Glib::RefPtr<Gtk::ListStore> &list_store, Gtk::Entry &entry, std::vector<std::string> &vec_Option, int size) {
flag_blocked_tree_view = true;
vector<string> vec_params;
std::string text = entry.get_text();
str_replace_all(text, " ", "");
vec_params = split(text, ',');
for (auto &name: vec_Option) {
this->set_row(list_store, size, name, false);
}
for (auto &name: vec_params) {
this->set_row(list_store, size, name, true);
}
flag_blocked_tree_view = false;
}
void MainWindow::get_menu_boot(string cmd) {
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
spbSecond->set_value(atoi(res_response.response.c_str()));
}
else if (res_response.error == 3) {
}
else {
}
}
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 {
}
}
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::event(){
btnSynopsis->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::synopsis_show));
btnAbout->signal_activate().connect([&]() {aboutWindows->show();});
btnLoadLocal->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::download_local_cfg));
btnLoadGlob->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::download_globl_cfg));
btnSaveLocalGlob->signal_activate().connect([&]() {save_global_local_cfg();});
btnSaveLocal->signal_activate().connect([&]() {save_local_cfg();});
btnSaveGlob->signal_activate().connect([&]() {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));
if (this->check_root() == 0) {
Glib::RefPtr<Gtk::TreeModel> treeViewKernelModel = treeViewKernel->get_model();
treeViewKernelModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::item_selected_kernel));
Glib::RefPtr<Gtk::TreeModel> treeViewIPTModel = treeViewIPT->get_model();
treeViewIPTModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::item_selected_IPT));
Glib::RefPtr<Gtk::TreeModel> 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));
}
}
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() {
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;
}
}
else{
info_status_app("boxInfoMessOK");
lblWarning->set_text(gettext("Nothing to save!"));
}
info_warning_error(3);
}
void MainWindow::save_local_cfg() {
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=");
flag_save_local = true;
}
}
else {
info_status_app("boxInfoMessOK");
lblWarning->set_text(gettext("Nothing to save!"));
}
info_warning_error(2);
}
void MainWindow::download_globl_cfg() {
entryKernel->set_text("");
entryOTT->set_text("");
entryIPT->set_text("");
flag_save_local = false;
flag_save_global = false;
flag_save_all = false;
flag_load = true;
std::string cmd_boot_time = "ubconfig --default --source global get boot GRUB_TIMEOUT";
this->get_menu_boot(cmd_boot_time);
string cmd_kernel_entry = "ubconfig --default --source global get boot GRUB_CMDLINE_LINUX";
this->get_setting_entry_all(cmd_kernel_entry, *entryKernel, map_global_cmd_selection);
string cmd_ipt_entry = "ubconfig --default --source global get boot GRUB_TERMINAL_INPUT";
this->get_setting_entry_all(cmd_ipt_entry, *entryIPT, map_global_cmd_selection);
string cmd_opt_entry = "ubconfig --default --source global get boot GRUB_TERMINAL_OUTPUT";
this->get_setting_entry_all(cmd_opt_entry, *entryOTT, map_global_cmd_selection);
this->set_row_all(map_global_cmd_selection, list_store_kernel, vec_Option_kernel, size_kernel);
this->set_row_all(map_global_cmd_selection, list_store_IPT, vec_Option_IPT, size_IPT);
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");
info_warning_error(1);
}
void MainWindow::download_local_cfg() {
entryKernel->set_text("");
entryOTT->set_text("");
entryIPT->set_text("");
flag_save_local = false;
flag_save_global = false;
flag_save_all = false;
flag_load = false;
std::string cmd_boot_time = "ubconfig --default --source system get boot GRUB_TIMEOUT";
this->get_menu_boot(cmd_boot_time);
string cmd_kernel_entry = "ubconfig --default --source system get boot GRUB_CMDLINE_LINUX";
this->get_setting_entry_all(cmd_kernel_entry, *entryKernel, map_local_cmd_selection);
string cmd_ipt_entry = "ubconfig --default --source system get boot GRUB_TERMINAL_INPUT";
this->get_setting_entry_all(cmd_ipt_entry, *entryIPT, map_local_cmd_selection);
string cmd_opt_entry = "ubconfig --default --source system get boot GRUB_TERMINAL_OUTPUT";
this->get_setting_entry_all(cmd_opt_entry, *entryOTT, map_local_cmd_selection);
this->set_row_all(map_local_cmd_selection, list_store_kernel, vec_Option_kernel, size_kernel);
this->set_row_all(map_local_cmd_selection, list_store_IPT, vec_Option_IPT, size_IPT);
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");
info_warning_error(0);
}
void MainWindow::set_row_all(std::map <string, string> &map_cmd, Glib::RefPtr<Gtk::ListStore> &list_store, vector<string> &list_params, size_t size) {
for (auto &name: list_params) {
if (map_cmd.find(name) != map_cmd.end()){
this->set_row(list_store, size, name, true);
}
else {
this->set_row(list_store, size, name, false);
}
}
}
void MainWindow::set_row(Glib::RefPtr<Gtk::ListStore> &list_store, int size, std::string name, bool flag_chbox) {
for (int index = 0; index < size; index++) {
Gtk::TreeModel::Row row = list_store->children()[index];
if(row) {
if (row[m_columns.name] == name) {
row[m_columns.check_button] = flag_chbox;
}
}
}
}
void MainWindow::synopsis_show() {
string cmd = "xdg-open " + string(gettext("https://wiki.ublinux.com/ru/Программное_обеспечениерограммы_и_утилиты/Все/")) + app_name + " &";
if (geteuid() == 0) {
string response_user = getlogin();
cmd = "su -l " + response_user + " -c \" DISPLAY=$DISPLAY " + cmd + " \"";
}
wrapper_system(cmd, "&");
}
void MainWindow::wrapper_system(string cmd, string thread_str = "") {
string cmd_new = cmd + " " + thread_str;
int response_cmd = system(cmd_new.c_str());
if (response_cmd != 0) {
index_error += 1;
this->log_mess_error(cmd);
}
}
void MainWindow::info_status_app(string stule) {
Glib::RefPtr<Gtk::StyleContext> boxInfo = boxInfoError->get_style_context();
boxInfo->remove_class("boxInfoMessOK");
boxInfo->remove_class("boxInfoMessError");
boxInfo->add_class(stule);
}
void MainWindow::info_warning_error(int mess) {
if (index_error > 0) {
info_status_app("boxInfoMessError");
imgInfo->set_from_icon_name("com.ublinux.ubl-settings-bootloader.warning", Gtk::ICON_SIZE_MENU);
index_error = 0;
string mess_error = "";
if (mess == 0) {
mess_error = string(gettext("Local configuration reading error")) + str_cmd_error;
lblWarning->set_text(mess_error);
}
else if (mess == 1) {
mess_error = string(gettext("Global configuration read error")) + str_cmd_error;
lblWarning->set_text(mess_error);
}
else if (mess == 2) {
mess_error = string(gettext("Local configuration write error")) + str_cmd_error;
lblWarning->set_text(mess_error);
}
else if (mess == 3) {
mess_error = string(gettext("Global configuration write error")) + str_cmd_error;
lblWarning->set_text(mess_error);
}
else if (mess == 4) {
mess_error = string(gettext("Error saved local and global configuration")) + str_cmd_error;
lblWarning->set_text(mess_error);
}
str_cmd_error = "";
}
else {
info_status_app("boxInfoMessOK");
imgInfo->set_from_icon_name("com.ublinux.ubl-settings-bootloader.checked", Gtk::ICON_SIZE_MENU);
if (mess == 0) {
lblWarning->set_text(gettext("Local configuration downloaded successfully"));
}
else if (mess == 1) {
lblWarning->set_text(gettext("Global configuration downloaded successfully"));
}
else if (mess == 2) {
lblWarning->set_text(gettext("Local configuration successfully written"));
}
else if (mess == 3) {
lblWarning->set_text(gettext("Global configuration successfully written"));
}
else if (mess == 4) {
lblWarning->set_text(gettext("Successfully saved local and global configuration"));
}
}
}
struct MainWindow::Result<string> MainWindow::wrapper_call(string cmd) {
struct Result<string> obj_result;
string response = call(cmd);
if ((response.find("(null)") == std::string::npos) && (response.length() != 0 )) {
if (response.find("=") != std::string::npos) {
if (response.find("\n") != std::string::npos) {
response = response.substr(response.find("=")+1,response.length());
response = response.substr(0,response.find("\n"));
obj_result.response = response;
obj_result.error = 0;
}
else {
obj_result.response = response;
obj_result.error = 1;
index_error += 1;
this->log_mess_error(cmd);
}
}
else {
obj_result.response = response;
obj_result.error = 2;
index_error += 1;
str_cmd_error = cmd;
this->log_mess_error(cmd);
}
}
else {
obj_result.response = response;
obj_result.error = 3;
index_error += 1;
str_cmd_error = cmd;
this->log_mess_error(cmd);
}
return obj_result;
}
void MainWindow::log_mess_error(string &cmd) {
string key = "";
if (map_cmd_error.find(cmd) != map_cmd_error.end()){
str_cmd_error = map_cmd_error[cmd];
}
else {
for ( const auto &map_iter: map_cmd_error ) {
key = map_iter.first;
if (cmd.find(key) != std::string::npos){
str_cmd_error = map_iter.second;
break;
}
}
}
}
void MainWindow::fn_event_intelMax1(){
chbintelMax4->set_active(false);
}
void MainWindow::fn_event_intelMax4(){
chbintelMax1->set_active(false);
}
void MainWindow::add_CSS(){
Glib::RefPtr<Gtk::CssProvider> cssProvider = Gtk::CssProvider::create();
cssProvider->load_from_path(path_css);
Glib::RefPtr<Gtk::StyleContext> styleContext = Gtk::StyleContext::create();
Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default();//get default screen
styleContext->add_provider_for_screen(screen, cssProvider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);//add provider for screen in all application
Glib::RefPtr<Gtk::StyleContext> lblInfoHead_css = lblInfoHead->get_style_context();
Glib::RefPtr<Gtk::StyleContext> boxButton_css = boxButton->get_style_context();
Glib::RefPtr<Gtk::StyleContext> boxSave_css = boxSave->get_style_context();
imgBG->set(path_img_head_background);
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");
}
lblInfoHead_css->add_class("textHead");
}
void help() {
string version = string(gettext("ubl-settings-bootloader version: ")) + version_application + "\n";
cout << version.c_str();
string help;
help = "GTK settings bootloader for UBLinux\n\n"
"Usage: ubl-settings-bootloader [OPTIONS...]\n"
"Options:\n"
" -h, --help Show this help\n"
" -V, --version Show package version\n";
cout << gettext(help.c_str());
}