|
|
|
|
|
#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/style.css";
|
|
|
string app_name = "ubl-settings-bootloader";
|
|
|
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_short_name('s');
|
|
|
socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN);
|
|
|
socketIDArg.set_description("Settings manager socket");
|
|
|
add_entry(socketIDArg, m_socketID);
|
|
|
}
|
|
|
::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();
|
|
|
}
|
|
|
|
|
|
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->event();
|
|
|
this->add_CSS();
|
|
|
}
|
|
|
|
|
|
void MainWindow::get_monitor_size(){
|
|
|
GdkRectangle workarea;
|
|
|
gdk_monitor_get_workarea(
|
|
|
gdk_display_get_primary_monitor(gdk_display_get_default()),&workarea);
|
|
|
screen_width = workarea.width;
|
|
|
screen_hight = workarea.height;
|
|
|
}
|
|
|
|
|
|
void MainWindow::get_builder(){
|
|
|
builder->get_widget("chbLoadVariantSelectionTimer", chbLoadVariantSelectionTimer);
|
|
|
builder->get_widget("chbLastSelectionWillBecome", chbLastSelectionWillBecome);
|
|
|
builder->get_widget("chbQuiet", chbQuiet);
|
|
|
builder->get_widget("chbSplash", chbSplash);
|
|
|
builder->get_widget("chbPlymouth", chbPlymouth);
|
|
|
builder->get_widget("chbAcpi", chbAcpi);
|
|
|
builder->get_widget("chbNоapic", chbNоapic);
|
|
|
builder->get_widget("chbNolapic", chbNolapic);
|
|
|
builder->get_widget("chbSingle", chbSingle);
|
|
|
builder->get_widget("chbHomodeset", chbHomodeset);
|
|
|
builder->get_widget("chbI915Enable", chbI915Enable);
|
|
|
builder->get_widget("chbAhci", chbAhci);
|
|
|
builder->get_widget("chbSndIntel", chbSndIntel);
|
|
|
builder->get_widget("chbintelMax1", chbintelMax1);
|
|
|
builder->get_widget("chbintelMax4", chbintelMax4);
|
|
|
builder->get_widget("chbconsoleIT", chbconsoleIT);
|
|
|
builder->get_widget("chbSerialIT", chbSerialIT);
|
|
|
builder->get_widget("chbofConsoleIT", chbofConsoleIT);
|
|
|
builder->get_widget("chbAtKeyboard", chbAtKeyboard);
|
|
|
builder->get_widget("chbUsbKeyboard", chbUsbKeyboard);
|
|
|
builder->get_widget("chbofConsoleOT", chbofConsoleOT);
|
|
|
builder->get_widget("chbSerialOT", chbSerialOT);
|
|
|
builder->get_widget("chbconsoleOT", chbconsoleOT);
|
|
|
builder->get_widget("chbGfxterm", chbGfxterm);
|
|
|
builder->get_widget("chbVgaText", chbVgaText);
|
|
|
|
|
|
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("lblDownloadMenu", lblDownloadMenu);
|
|
|
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("entryIT", entryIT);
|
|
|
builder->get_widget("entryOT", entryOT);
|
|
|
|
|
|
builder->get_widget("boxInput1", boxInput1);
|
|
|
builder->get_widget("boxInput2", boxInput2);
|
|
|
builder->get_widget("boxOtput1", boxOtput1);
|
|
|
builder->get_widget("boxOtput2", boxOtput2);
|
|
|
builder->get_widget("boxKernel", boxKernel);
|
|
|
builder->get_widget("boxKernel1", boxKernel1);
|
|
|
builder->get_widget("boxKernel2", boxKernel2);
|
|
|
builder->get_widget("boxColor", boxColor);
|
|
|
builder->get_widget("aboutWindows", aboutWindows);
|
|
|
|
|
|
builder->get_widget("btnSynopsis", btnSynopsis);
|
|
|
builder->get_widget("btnAbout", btnAbout);
|
|
|
builder->get_widget("btnDonwlodLocal", btnDonwlodLocal);
|
|
|
builder->get_widget("btnDonwlolGlob", btnDonwlolGlob);
|
|
|
builder->get_widget("btnSaveLocalGlob", btnSaveLocalGlob);
|
|
|
builder->get_widget("btnSaveLocal", btnSaveLocal);
|
|
|
builder->get_widget("btnSaveGlob", btnSaveGlob);
|
|
|
builder->get_widget("btnSettings", btnSettings);
|
|
|
builder->get_widget("btnDownload", btnDownload);
|
|
|
builder->get_widget("btnSave", btnSave);
|
|
|
}
|
|
|
|
|
|
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("Date and Time"));
|
|
|
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("UBConfig - Loading"));
|
|
|
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"));
|
|
|
lblDownloadMenu->set_text(gettext("Download menu"));
|
|
|
lblInfoInputTerminal->set_text(gettext("Input terminal"));
|
|
|
lblInfoOutputTerminal->set_text(gettext("Output terminal"));
|
|
|
|
|
|
chbLoadVariantSelectionTimer->set_label(gettext("Load variant selection timer"));
|
|
|
chbLastSelectionWillBecome->set_label(gettext("The last selection will become the default boot choice"));
|
|
|
chbQuiet->set_label(gettext("quiet (Downloading without text messages)"));
|
|
|
chbSplash->set_label(gettext("splash (Show welcome window)"));
|
|
|
chbPlymouth->set_label(gettext("no plymouth (Disable Plymouth)"));
|
|
|
chbAcpi->set_label(gettext("acpi=off (Disable ACPI)"));
|
|
|
chbNоapic->set_label(gettext("nоapic (Disable APIC)"));
|
|
|
chbNolapic->set_label(gettext("nolapic (Disable local APIC)"));
|
|
|
chbSingle->set_label(gettext("single (Single User Mode)"));
|
|
|
chbHomodeset->set_label(gettext("nomodeset (Disable kernel selection and loading of video drivers)"));
|
|
|
chbI915Enable->set_label(gettext("i915.enable_dc=0 (Disable GPU power management)"));
|
|
|
chbAhci->set_label(gettext("ahci.mobile_jpm_policy=1 (Maximum performance, power management)"));
|
|
|
chbSndIntel->set_label(gettext("snd-intel-dspcfg.dsp_driver=1 (Forced selection of a sound device driver from Intel)"));
|
|
|
chbintelMax1->set_label(gettext("intel_idle max_cstate=1 (Prevents the processor from going into a deep sleep state)"));
|
|
|
chbintelMax4->set_label(gettext("intel_idle.max_cstate=4 (Eliminates flickering laptop display on processors Ultra Voltage)"));
|
|
|
chbconsoleIT->set_label(gettext("console (PC BIOS & console EFI)"));
|
|
|
chbSerialIT->set_label(gettext("serial (Serial terminal)"));
|
|
|
chbofConsoleIT->set_label(gettext("ofconsole (Console Open Firmware)"));
|
|
|
chbAtKeyboard ->set_label(gettext("at_keyboard (Keyboard PC AT (Coreboot))"));
|
|
|
chbUsbKeyboard->set_label(gettext("usb_keyboard (Keyboard USB Keyboard (protocol HID Boot))"));
|
|
|
chbofConsoleOT->set_label(gettext("ofconsole (Console Open Firmware)"));
|
|
|
chbSerialOT->set_label(gettext("serial (Serial terminal)"));
|
|
|
chbconsoleOT->set_label(gettext("console (PC BIOS & console EFI)"));
|
|
|
chbGfxterm->set_label(gettext("gfxterm (Output in graphical mode)"));
|
|
|
chbVgaText->set_label(gettext("chbVgaText"));
|
|
|
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"));
|
|
|
btnDonwlolGlob->set_label(gettext("Load global configuration"));
|
|
|
btnDonwlodLocal->set_label(gettext("Load local configuration"));
|
|
|
btnSave->set_label(gettext("Save"));
|
|
|
btnDownload->set_label(gettext("Donwload"));
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::event(){
|
|
|
chbintelMax1->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::fn_event_intelMax1));
|
|
|
chbintelMax4->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::fn_event_intelMax4));
|
|
|
signal_configure_event().connect(sigc::mem_fun(*this, &MainWindow::gui_set_orientation), false);
|
|
|
btnSynopsis->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::synopsis_show));
|
|
|
btnAbout->signal_activate().connect([&]() {aboutWindows->show();});
|
|
|
btnDonwlodLocal->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::download_local_cfg));
|
|
|
btnDonwlolGlob->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();});
|
|
|
}
|
|
|
|
|
|
void MainWindow::save_global_local_cfg(){
|
|
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::save_local_cfg(){
|
|
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::save_global_cfg(){
|
|
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::download_local_cfg(){
|
|
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::download_globl_cfg(){
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
void MainWindow::synopsis_show() {
|
|
|
wrapper_system("xdg-open https://wiki.ublinux.ru/ru/home", "&");
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
struct MainWindow::Result<string> MainWindow::wrapper_call(string cmd) {
|
|
|
struct Result<string> obj_result;
|
|
|
string response = this->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;
|
|
|
}
|
|
|
|
|
|
string MainWindow::call(string cmd) {
|
|
|
FILE *fp;
|
|
|
int status;
|
|
|
char path[PATH_MAX] = {0};
|
|
|
fp = popen(cmd.c_str(), "r");
|
|
|
if (fp == NULL) {
|
|
|
exit(1);
|
|
|
}
|
|
|
while (fgets(path, PATH_MAX, fp) != NULL) {
|
|
|
break;
|
|
|
}
|
|
|
status = pclose(fp);
|
|
|
if (status == -1) {
|
|
|
exit(1);
|
|
|
}
|
|
|
return path;
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
bool MainWindow::gui_set_orientation(GdkEventConfigure* event){
|
|
|
if (event){}
|
|
|
int w,h;
|
|
|
this->get_monitor_size();
|
|
|
w = this->get_width();
|
|
|
h = this->get_height();
|
|
|
int padding = w*0.11;
|
|
|
float padding_interest = 0.6;
|
|
|
if ((width!=w) || heigh!=h){
|
|
|
if (((screen_width/2)<=w) && ((screen_hight-padding)<=h)){
|
|
|
boxOtput1->set_orientation(Gtk::ORIENTATION_VERTICAL);
|
|
|
boxOtput2->set_orientation(Gtk::ORIENTATION_VERTICAL);
|
|
|
boxInput1->set_orientation(Gtk::ORIENTATION_VERTICAL);
|
|
|
boxInput2->set_orientation(Gtk::ORIENTATION_VERTICAL);
|
|
|
boxKernel->set_orientation(Gtk::ORIENTATION_VERTICAL);
|
|
|
boxKernel1->set_orientation(Gtk::ORIENTATION_VERTICAL);
|
|
|
boxKernel2->set_orientation(Gtk::ORIENTATION_VERTICAL);
|
|
|
cout << 1 << endl;
|
|
|
}
|
|
|
else if (((screen_width*padding_interest)<=w) && ((screen_hight*padding_interest)<=h)){
|
|
|
boxOtput1->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
|
|
boxOtput2->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
|
|
boxInput1->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
|
|
boxInput2->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
|
|
boxKernel->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
|
|
boxKernel1->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
|
|
boxKernel2->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
|
|
cout << 2 << endl;
|
|
|
}
|
|
|
else{
|
|
|
}
|
|
|
|
|
|
|
|
|
width=w;
|
|
|
heigh=h;
|
|
|
}
|
|
|
|
|
|
|
|
|
return 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> context_box = boxColor->get_style_context();
|
|
|
Glib::RefPtr<Gtk::StyleContext> context_lbl_head = lblInfoHead->get_style_context();
|
|
|
context_box->add_class("cssboxColor1");
|
|
|
context_lbl_head->add_class("textHead");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|