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.h

493 lines
20 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 <cstddef>
#include <iostream>
#include <gtkmm.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <gtkmm/stock.h>
#include <gtkmm/window.h>
#include <gtkmm/plug.h>
#include <locale.h>
#include <libintl.h>
#include <glibmm/i18n.h>
#include <map>
#include "ubl-util-standard.c"
#include "util.h"
#include "save.h"
#include "load.h"
#include <dlfcn.h>
#include "ubl-settings-bootloader-cm.h"
#include "menu_os.h"
#ifdef WEBKIT_FOUND
#include <webkit2/webkit2.h>
#endif
#include "my_process.h"
using namespace std;
extern int socket_ext_id_I;
extern int socket_trd_id_I;
extern string version_application;
extern bool flag_save;
extern bool flag_save_local;
extern bool flag_save_global;
extern bool flag_load_global;
extern bool flag_lock_help;
void me_thread(string cmd);
#define minimal_width 640
#define minimal_height 500
#define str_tooltip_add_user _("Add user")
#define str_tooltip_del_user _("Delete user")
#define str_tooltip_add_melody _("Add melody")
#define str_tooltip_del_melody _("Delete melody")
#define str_tooltip_boot_menu _("Selecting the loading mode option")
#define copyright _("Copyright © UBSoft LLC, 2022 - ")
#define name_app _("ubl-settings-bootloader")
#define website _("https://wiki.ublinux.com")
#define project_Home_page _("Project Home Page")
#define configuring_system_boot _("Configuring system boot parameters")
#define system_boot _("System boot setup")
#define str_about _("About ubl-settings-bootloader")
#define command_line_parameters _("Command line parameters:")
#define load_default _("Load default:")
#define seconds _("seconds")
#define download_menu _("Download menu")
#define terminal_for_input _("Terminal for input")
#define terminal_for_output _("Terminal for output")
#define boot_selection_menu_timer _("Boot selection menu timer")
#define str_help _("Help")
#define str_about_1 _("About")
#define str_save _("Save")
#define str_load _("Load")
#define str_edit _("Edit")
#define str_adding _("Adding")
#define save_all _("Save configuration")
#define save_local _("Save in local configuration")
#define save_global _("Save in global configuration")
#define load_global _("Load global configuration")
#define load_local _("Load local configuration")
#define read_online _("Read online")
#define str_cancel _("Cancel")
#define always_redirect _("Always redirect")
#define boot_screen_display_mode _("Boot screen display mode:")
#define no_loading_animation_800_600 _("No loading animation,\nfull log")
#define no_loading_animation _("No loading animation, full log")
#define boot_menu_user_name _("Boot menu user name:")
#define boot_menu_user_password _("Boot menu user password:")
#define last_successful_upload _("Last successful upload")
#define read_documentation_web _("Would you like to read documentation in the Web?")
#define redirected_documentation _("You will be redirected to documentation website where documentation is\n""translated and supported by community.")
#define user_name_configuration_editing_code _("User name to enter boot configuration editing mode")
#define user_password_configuration_edit_mode _("User password to enter boot configuration edit mode")
#define loading_animation_with _("Loading animation with the magazine")
#define loading_animation_without _("Loading animation without a magazine")
#define lack_loading_animation_800_600 _("Lack of loading animation with the\noutput of the abbreviated log")
#define lack_loading_animation _("Lack of loading animation with the output of the abbreviated log")
#define web_url _("https://wiki.ublinux.com")
#define enter_password _("Enter your password")
#define enter_login _("Enter login")
#define str_version _("ubl-settings-bootloader version: ")
#define local_read_error _("Local configuration reading error")
#define global_read_error _("Global configuration read error")
#define local_write_error _("Local configuration write error")
#define global_write_error _("Global configuration write error")
#define error_save_all _("Error saved local and global configuration")
#define local_load_ok _("Local configuration downloaded successfully")
#define global_load_ok _("Global configuration downloaded successfully")
#define local_ok_written _("Local configuration successfully written")
#define global_ok_written _("Global configuration successfully written")
#define successfully_save_all _("Successfully saved local and global configuration")
#define nothing_save _("Nothing to save!")
#define program_as_root _("The program must be run as root")
#define str_active _("Active")
#define str_option _("Option")
#define str_title _("Title")
#define str_user _("User")
#define str_password _("Password")
#define str_administrator _("Administrator")
#define str_select _("Select")
#define str_melody_code _("Melody code")
#define str_ringtone_at_startup _("Ringtone at startup")
#define str_description _("Description")
#define str_title_Boot_Menu_Users _("Boot Menu Users")
#define str_title_Ringtone_Startup _("Ringtone at startup")
#define str_null_melody_name _("Enter the name and code of the tune in the \"Ringtone at startup\" field")
#define str_null_username _("Enter name and password in the \"Boot Menu Users\" field")
#define str_help_h _("GTK settings bootloader for UBLinux\n" \
"\n" \
"Usage: ubl-settings-bootloader [OPTIONS...]\n" \
"Options:\n" \
" -h, --help\t Show this help\n" \
" -V, --version\t Show package version\n" \
" --lock-help Lock utility help\n" \
" --lock-save Lock saving local and global configuration\n" \
" --lock-save-local Lock save global configuration\n" \
" --lock-save-global Lock load global configuration\n" \
" --lock-load-global Lock load global configuration\n")
#define no_recognized _("Argument not recognized\n")
#define global_load "ubconfig --default --source global get boot"
#define system_load "ubconfig --default --source system get boot"
#define all_save "ubconfig set boot "
#define all_remove "ubconfig remove boot "
#define global_save "ubconfig --target global --noexecute set boot "
#define system_save "ubconfig --target system set boot "
#define global_remove "ubconfig --target global --noexecute remove boot "
#define system_remove "ubconfig --target system remove boot "
#define const_link_doc "https://wiki.ublinux.com/ru/Программное_обеспечениерограммы_и_утилиты/Все/ubl-settings-bootloader"
#define cmd_xdg "xdg-open "
#define cmd_execute "su -l %s -c \" DISPLAY=$DISPLAY %s \""
#define icon_checked "com.ublinux.ubl-settings-bootloader.checked"
#define icon_warning "com.ublinux.ubl-settings-bootloader.warning"
#define kernel_csv "grub-cmdline-linux.csv"
#define melody_csv "grub-play.csv"
#define IPT_csv "grub-terminal-input.csv"
#define OTT_csv "grub-terminal-output.csv"
#define path_app "/usr/bin/"
#define path_glade "/usr/share/ubl-settings-bootloader/ui/ubl-settings-bootloader.glade"
#define path_css "/usr/share/ubl-settings-bootloader/css/ubl-settings-bootloader.css"
#define app_name "ubl-settings-bootloader"
#define path_resources "/usr/share/ubl-settings-bootloader"
#define path_img_head_background "/usr/share/ubl-settings-bootloader/images/logo-background.png"
#define cmd_pars_list_os "/usr/lib/ublinux/scripts/grub-functions exec_get_all_menuentry"
#define cmd_last_launched_os "/usr/lib/ublinux/scripts/grub-functions exec_get_last_menuentry"
#define info_box_ok_css "boxInfoMessOK"
#define info_box_error_css "boxInfoMessError"
#define str_add_user _("User added")
#define str_add_melody _("Melody added")
#define str_del_user _("User deleted")
#define str_del_melody _("Melody deleted")
class View_edit_add_table {
private:
Glib::RefPtr<Gtk::Builder> builder;
Gtk::Window* wndAddEditData;
Gtk::Button* btnCancel;
Gtk::Button* btnSaveEditSave;
Gtk::CheckButton* chkAddEdit;
Gtk::Entry* entryCol1;
Gtk::Entry* entryCol2;
Gtk::Label* lblAddEditCheckBox;
Gtk::Label* lblAddEditCol1;
Gtk::Label* lblAddEditCol2;
Gtk::Label* lblEditAddHead;
bool flag_save = false;
string mode_show = "";
public:
struct struct_data {
bool check;
string column1;
string column2;
};
struct struct_data old_data;
struct struct_data new_data;
public:
View_edit_add_table();
//~View_edit_add_table();
void settings();
void event();
void localization();
void cancel();
void save();
void check_space_entry();
void set_data(bool check, string column1, string column2);
struct struct_data get_data();
void show();
void show_melody_edit();
void show_melody_add();
void show_user_edit();
void show_user_add();
void get_builder();
};
class CmdArgParser : public Glib::OptionGroup
{
public:
CmdArgParser(const std::string &p_name, const std::string &p_description, const std::string &p_help);
::Window GetSocketID() const;
private:
int m_socketID = 0;
};
class MainWindow : public Gtk::ApplicationWindow
{
public:
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{
add(check_button), add(name);
add(description);
}
// Gtk::TreeModelColumn<Gtk::CheckButton> check_button;
Gtk::TreeModelColumn<bool> check_button;
Gtk::TreeModelColumn<Glib::ustring> name;
Gtk::TreeModelColumn<Glib::ustring> description;
};
class ModelColumnsUser : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumnsUser()
{
add(check_button), add(name);
add(password);
}
// Gtk::TreeModelColumn<Gtk::CheckButton> check_button;
Gtk::TreeModelColumn<bool> check_button;
Gtk::TreeModelColumn<Glib::ustring> name;
Gtk::TreeModelColumn<Glib::ustring> password;
};
class ModelColumnsMelody : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumnsMelody()
{
add(check_button), add(title);
add(melody_code);
}
// Gtk::TreeModelColumn<Gtk::CheckButton> check_button;
Gtk::TreeModelColumn<bool> check_button;
Gtk::TreeModelColumn<Glib::ustring> title;
Gtk::TreeModelColumn<Glib::ustring> melody_code;
};
ModelColumns m_columns;
ModelColumnsUser m_columns_user;
ModelColumnsMelody m_columns_melody;
Glib::RefPtr<Gtk::Builder> builder;
Gtk::Widget *plug = NULL;
Gtk::SpinButton *spbSecond;
Gtk::Label *lblBootMenuUsers;
Gtk::Label *lblRingtoneStartup;
Gtk::Label *lblInfoSeconds;
Gtk::Label *lblInfoDefaultDonw;
Gtk::Label *lblInfoCommand;
Gtk::Label *lblInfoCommand1;
Gtk::Label *lblHeaderAboutTopic;
Gtk::Label *lblInfoCommand2;
Gtk::Label *lblLoadMenu;
Gtk::Label *lblInfoInputTerminal;
Gtk::Label *lblInfoOutputTerminal;
Gtk::Label *lblHeaderName;
Gtk::Label *lblInfoHead;
Gtk::Button *btnAddUser;
Gtk::Button *btnRemoveUser;
Gtk::Button *btnAddMusic;
Gtk::Button *btnRemoveMusic;
Gtk::Button *btnEditUser;
Gtk::Button *btnEditMusic;
Gtk::CheckButton *chbVgaText;
Gtk::CheckButton *chbLoadVariantSelectionTimer;
Gtk::Entry *entryKernel;
Gtk::Entry *entryIPT;
Gtk::Entry *entryOTT;
Gtk::Box *boxColor;
Gtk::AboutDialog *aboutWindows;
Gtk::MenuItem *btnAbout;
Gtk::MenuItem *btnHelp;
Gtk::MenuItem *btnSaveLocalGlob;
Gtk::MenuItem *btnSaveLocal;
Gtk::MenuItem *btnSaveGlob;
Gtk::MenuItem *btnLoadGlob;
Gtk::MenuItem *btnLoadLocal;
Gtk::Button *btnLoad;
Gtk::Button *btnSave;
Gtk::Button *btnSettings;
Gtk::Widget *boxButton;
Gtk::Widget *boxSave;
Gtk::Box *boxInfoError;
Gtk::Box *boxWidgetAll;
Gtk::Label *lblWarning;
Gtk::Image *imgInfo;
Gtk::ButtonBox *btnBoxAboutDialog;
Gtk::TreeView *treeViewKernel;
Gtk::TreeView *treeViewIPT;
Gtk::TreeView *treeViewOTT;
Gtk::TreeView *treeViewUser;
Gtk::TreeView *treeViewMelody;
Gtk::Image *imgBG;
Gtk::Overlay *overHead;
Gtk::ComboBoxText *cmbDownloadMode;
Gtk::CheckButton *chbPasswordProtecc;
Gtk::Label *lblHeadeWndWeb;
Gtk::Label *lblwebHeaderName;
Gtk::Label *lblhelpText;
Gtk::Label *lblhelpHeader;
Gtk::CheckButton *chkAlwaysOpenHelp;
Gtk::Button *btnReadHelp;
Gtk::Button *btnCancelHelp;
Gtk::Window *wndShowWeb;
Gtk::Button *btnOpenMenuOS1;
Gtk::Entry *entrListOS;
std::vector<std::string> vec_Option_kernel;
std::vector<std::string> vec_Option_IPT;
std::vector<std::string> vec_Option_OTT;
Glib::RefPtr<Gtk::ListStore> list_store_kernel;
Glib::RefPtr<Gtk::ListStore> list_store_IPT;
Glib::RefPtr<Gtk::ListStore> list_store_OTT;
Glib::RefPtr<Gtk::ListStore> list_store_user;
Glib::RefPtr<Gtk::ListStore> list_store_melody;
#ifdef WEBKIT_FOUND
Gtk::Window *wndWeb;
Gtk::Widget *three;
WebKitWebView *one;
#endif
Gtk::TreeModel::Row row_kernel;
Gtk::TreeModel::Row row_IPT;
Gtk::TreeModel::Row row_OTT;
Gtk::TreeModel::Row row_user;
Gtk::TreeModel::Row row_melody;
std::map<string, string> map_cmd_selection;
std::map<string, string> map_global_cmd_selection;
std::map<string, string> map_local_cmd_selection;
Gtk::TreeModel::iterator iter_user_del;
Gtk::TreeModel::iterator iter_melody_del;
bool flag_validate_del_user = false;
bool flag_validate_del_melody = false;
Gtk::Label *lblDownloadMode;
Lib_save::Save obj_save = Lib_save::Save();
Lib_Load::Load obj_load = Lib_Load::Load();
Menu_os obj_menu_os = Menu_os();
vector<string> vec_param_names;
My_Process::My_Process_system obj_process_system = My_Process::My_Process_system();
My_Process::My_Process_call obj_process_call = My_Process::My_Process_call();
View_edit_add_table obj_view_edit_add_table = View_edit_add_table();
bool flag_load = false;
bool flag_save_all = false;
bool flag_blocked_tree_view = false;
bool flag_save_block = false;
bool flag_open_browser = false;
string str_last_launched_os = "";
int index_error = 0;
string str_flag_load = "";
size_t size_kernel = 0;
size_t size_IPT = 0;
size_t size_OTT = 0;
size_t len_old_melody = 0;
size_t len_old_user = 0;
int old_height = 0;
int old_width = 0;
Glib::RefPtr<Gtk::StyleContext> boxInfo;
string str_cmd_error = "";
template <typename Type>
struct Result {
Type response;
int error;
};
public:
std::map<string, string> map_cmd_error;
string global_lick_doc = "";
MainWindow(BaseObjectType *obj, Glib::RefPtr<Gtk::Builder> const &builder);
MainWindow(Glib::RefPtr<Gtk::Builder> const &builder);
~MainWindow();
void open_browser();
void select_line_user(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter);
void set_entry_to_tree_view(Glib::RefPtr<Gtk::ListStore> &list_store, Gtk::Entry &entry, std::vector<std::string> &vec_Option, int size, string key);
void get_menu_boot(std::map<string, string> &map_temp);
void set_row_all(std::map<string, string> &map_cmd, Glib::RefPtr<Gtk::ListStore> &list_store, vector<string> &list_params, size_t size, string key);
void set_row(Glib::RefPtr<Gtk::ListStore> &list_store, int size, std::string name, bool flag_chbox);
void get_builder();
bool gui_exit(GdkEventAny *);
void init_dict(string flag_load);
void add_CSS();
void show_pass();
void localization();
void event();
void remove_user();
void remove_melody();
void settings();
void open_help();
void validate_melody();
void select_line_melody(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter);
void view_add_colums_user(Gtk::TreeView &treeView);
void view_add_colums_melody(Gtk::TreeView &treeView);
void set_bat_save(Gtk::Button *btnSave);
string pars_last_launched_os();
vector<string> pars_os(vector<string> &os_control_list);
void fn_event_intelMax1();
void fn_event_intelMax4();
void temp_help_show();
void set_data_cfg();
void set_data_csv_melody();
vector<tuple<string, vector<string>>> format_os_list(vector<string> &os_control_list);
void set_active_boot_second();
void get_download_mode(std::map<string, string> &map_temp);
void 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);
void wrapper_system(string cmd, string thread_str);
struct Result<string> wrapper_call(string cmd);
void log_mess_error(string &cmd);
void wrapper_save_all_cfg();
void wrapper_save_local_cfg();
void wrapper_save_global_cfg();
bool save_template(string cmd, string cmd_remove, string flag_save);
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);
void download_local_cfg();
void set_tree_view_user();
void template_open_browser(string link_doc);
void download_globl_cfg();
void flag_block_gui();
void info_status_app(string stule);
bool check_save(string flag_save, string key_name);
void info_warning_error(int mess);
int check_root();
void focus_out_txt_kernel();
void focus_out_txt_IPT();
void focus_out_txt_OTT();
bool focus_in_txt_entry(GdkEventFocus*);
void fill_in_view();
bool focus_tree_view(GdkEventFocus *);
bool check_flag_save(string flag_save);
void set_download_mode();
void get_default_load(std::map<string, string> &map_temp);
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);
vector<string> get_setting_entry_all(string key, std::map<string, string> *map_temp);
void cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove);
void item_selected_kernel(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 &);
string template_item_selected(int size, Glib::RefPtr<Gtk::ListStore> &list_store, string key);
void set_add_data_melody(Gtk::TreeModel::Row &row, bool flag, string &name, string &code);
void set_init_data_melody(std::map<string, string> &map_temp);
void set_add_data_user(Gtk::TreeModel::Row &row, bool flag, string &name, string &password);
void set_init_data_user(std::map<string, string> &map_temp);
void set_init_data_superuser(std::map<string, string> &map_temp);
bool intel_idle_cstate_check(int size, Glib::RefPtr<Gtk::ListStore> &list_store, string key);
void wrapper_add_data_user();
void wrapper_add_data_melody();
void check_resize_window();
void set_plug(Gtk::Widget *plug);
void wrapper_edit_show_user();
void wrapper_edit_show_melody();
void wrapper_edit_melody(bool check, string column1, string column2);
void wrapper_edit_user(bool check, string column1, string column2);
void wrapper_set_add_data_melody(bool flag, string &name, string &code);
void wrapper_set_add_data_user(bool flag, string &name, string &password);
void set_menu_os_to_button();
};
class SettingsPlug : public Gtk::Plug
{
public:
Gtk::Window *window;
SettingsPlug(::Window p_socketID, Glib::RefPtr<Gtk::Builder> builder);
private:
Gtk::Widget *plugBox;
Gtk::Widget *parent;
};
void help();
void wrapper_help_show(GtkWidget *self, char* link, gpointer user_data);