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.
ublexec/source/ublexec.h

347 lines
12 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 <gtkmm/window.h>
#include <glibmm/i18n.h>
#include <gtkmm/plug.h>
#include <gtkmm/stock.h>
#include <gtkmm.h>
#include <iostream>
#include <map>
#include <string>
#include <array>
#include <vector>
#include <fstream>
#include <filesystem>
#include <stdio.h>
#include <pwd.h>
#include <ostream>
#include <thread>
#include <algorithm>
#include <fstream>
#include <dlfcn.h>
#include "ubl-util-standard.c"
#include <stdbool.h>
#include "../compile/ubl-cmake.h"
#ifdef WEBKIT_FOUND
#include <webkit2/webkit2.h>
#endif
#define str_tooltip_filemanager _("Program view")
#define str_tooltip_list_app _("File view")
#define copyright _("Copyright © UBSoft LLC, 2022 - ")
#define define_name_app _("Run as...")
#define name_app_1 _("ublexec")
#define website _("https://wiki.ublinux.com")
#define home_page _("Project Home Page")
#define space_name_app _(" Run as...")
#define str_about_1 _("About")
#define str_about _("About ubl-settings-datetime")
#define str_help _("Help")
#define str_save _("Save")
#define str_load _("Load")
#define save_all _("Save to global and local configuration")
#define save_local _("Save local configuration")
#define save_global _("Save global configuration")
#define load_global _("Load global configuration")
#define load_local _("Load local configuration")
#define read_online _("Read online")
#define cancel _("Cancel")
#define always_redirect _("Always redirect")
#define nothing_save _("Nothing to save!")
#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\ntranslated and supported by community.")
#define str_help_h _("GTK \"Run applications as another user with the specified priority\" for ""UBLinux\n""\n""Usage: ublexec [OPTIONS...]\n""Options:\n"" -h, --help\t Show this help\n"" -V, --version\t Show package version\n"" -x APP_NAME Running the program\n"" -e FILE_NAME Running the file\n")
#define str_version _("ublexec version: ")
#define nice_19 _("19 (Low)")
#define nice_0 _("0 (High)")
#define nice__20 _("-20 (High)")
#define str_close _("Close")
#define str_localization_system _("System")
#define str_localization_development _("Development")
#define str_localization_other _("Other")
#define str_localization_office _("Office")
#define str_localization_education _("Education")
#define str_localization_settings _("Settings")
#define str_localization_multimedia _("Multimedia")
#define str_localization_internet _("Internet")
#define str_localization_tools _("Tools")
#define str_localization_graphics _("Graphics")
#define str_localization_attention _("Attention")
#define str_localization_priority _("Priority")
#define str_run_of_user _("Run as another user:")
#define str_select_app_program _("Select an executable file or program")
#define str_change_priority _("Change startup priority")
#define str_run_terminal _("Run in the terminal emulator")
#define str_file_overview _("File Overview")
#define str_application_overview _("Application Overview")
#define str_run_applications_as_another _("Run applications as another user\nwith the specified priority")
#define str_localization_username _("User Name:")
#define str_selecting_programs _("Selecting Programs")
#define str_please_select_file _("Please select File")
#define str_localization_cmd_line _("Command Line")
#define str_localization_user _("User")
#define str_localization_team _("Team:")
#define str_run _("Run")
#define const_link_doc "https://wiki.ublinux.com/ru/Программное_обеспечениерограммы_и_утилиты/Все/ublexec"
#define cmd_xdg "xdg-open "
#define cmd_execute "su -l %s -c \" DISPLAY=$DISPLAY %s \""
#define path_app "/usr/bin/"
#define path_glade "/com/ublinux/ui/ublexec.glade"
#define path_css "/com/ublinux/css/ublexec.css"
#define app_name "ublexec"
#define path_img_head_background "/com/ublinux/images/ublexec-banner.png"
#define path_all_applications "/usr/share/applications/"
#define file_source_login_min_max "/etc/login.defs"
#define no_print_cmd "nohup %s > /dev/null 2>&1"
using namespace std;
extern string name_app_cmd;
extern int socket_ext_id_I;
extern int socket_trd_id_I;
extern int flag_prog_file;
extern string version_application;
void me_thread(string cmd);
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:
MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder);
MainWindow(Glib::RefPtr<Gtk::Builder> const& builder);
~MainWindow();
void template_apps_obj(Gtk::IconView *icon, Glib::RefPtr<Gtk::ListStore> &gtk_list_app);
void get_builder();
void add_CSS();
void localization();
void event();
void settings();
void close_entry_app();
void start_menu_entry_app();
void message_gui_close();
void activ_or_block_execute_epriority();
void open_filemaneg();
void close_filemaneg();
void get_path_filemaneg();
void open_list_app();
string start_cmd(string user_cmd);
void call_app(string &cmd);
void changed_user();
void entry_app();
void execute_another_User(){}
void activ_or_block_other_user();
void change_scale_priority();
void change_spin_priority();
void pars_dir_bin();
void pars_users();
void pars_apps();
void select_Graphics();
void tmp_desktop(string cmd_name);
void on_item_activated(const Gtk::TreeModel::Path& path);
void tempalte_row(string Name, string Exec, string path , Glib::RefPtr<Gtk::ListStore> &dtk_list);
void tempate_icon_select(Gtk::IconView *icon, Glib::RefPtr<Gtk::ListStore> &gtk_list);
void ok_close_entry_app();
void select_Tools();
void select_Internet();
void select_Multimedia();
void select_Settings();
void select_Education();
void select_Office();
void select_Other();
void select_Development();
void select_System();
void icon_clear();
void set_icon_array();
void delete_cmd(const int &x,const int &y);
void help_show();
void denamic_cmd();
void temp_help_show();
void open_help();
void is_user_wheel();
void sudo_nice();
void template_open_browser(string link_doc);
void open_browser();
vector <size_t> find_all(string &text, string &word);
bool focus_out_txt_cmd(GdkEventFocus* event);
bool focus_in_txt_cmd(GdkEventFocus* event);
void unselect_icon(Gtk::IconView *icon_entry);
void pars_dir_terminal();
unsigned short read_uid_min_max(string filename, string search);
void str_remove(std::string& source, std::string to_remove);
string call(string cmd);
vector<std::string> split(const std::string &s, char delim);
public:
class ModelColumns : public Gtk::TreeModel::ColumnRecord {
public:
ModelColumns()
{
add(m_col_filename);
add(m_col_description);
add(m_col_pixbuf);
add(app_name_exec);
add(float_h_align);
add(float_w_align);
add(icon_name);
}
Gtk::TreeModelColumn<std::string> m_col_filename;
Gtk::TreeModelColumn<std::string> icon_name;
Gtk::TreeModelColumn<Glib::ustring> m_col_description;
Gtk::TreeModelColumn<Glib::ustring> app_name_exec;
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > m_col_pixbuf;
Gtk::TreeModelColumn<float> float_h_align;
Gtk::TreeModelColumn<float> float_w_align;
};
ModelColumns m_Columns;
public:
Glib::RefPtr<Gtk::Builder> builder;
Gtk::Button *btnFilemaneg;
Gtk::Button *btnListApp;
Gtk::Button *btnStart;
Gtk::CheckButton *chbTerminal;
Gtk::CheckButton *chbAnotherUser;
Gtk::CheckButton *cbxExecuteEpriority;
Gtk::ComboBoxText *cmbUser;
Gtk::SpinButton *spinPriority;
Gtk::Scale *scalePriority;
Gtk::RadioButton *rbPkexec;
Gtk::RadioButton *rbSu;
Gtk::RadioButton *rbSudo;
Gtk::Entry *txtCmd;
Gtk::FileChooserDialog *wndChooseFileWallpaper;
Gtk::Button *btnFilemangerExit;
Gtk::Button *btnFilemangerOk;
Gtk::Label *lblTimeEpriority;
Gtk::Label *lblTimeEpriorityLow;
Gtk::Label *lblTime4EpriorityHigh;
Gtk::Label *lblUserName;
Gtk::Window *messageError;
Gtk::Button *btnMessageErrorOk;
Gtk::Label *lblMessageError;
Gtk::Button *btnStartMenuOK;
Gtk::Button *btnStartMenuExit;
Gtk::Window *dialogStartMenu;
Gtk::Box *boxColor;
Gtk::Label *lblInfoHead;
Gtk::Label *lblinfoCmd;
Gtk::Label *lblInfoTime;
Gtk::Label *labInfoExecutTerm;
Gtk::Label *lblInfoUser;
Gtk::Label *lblInfoUserOther;
Gtk::Label *lblInfoUserName;
Gtk::Label *lblInfoNooPriority;
Gtk::Label *lblInfoExec;
Gtk::Label *lblInfoPriority;
Gtk::Label *lblGraphics;
Gtk::Label *lblTools;
Gtk::Label *lblInternet;
Gtk::Label *lblMultimedia;
Gtk::Label *lblSettings;
Gtk::Label *lblEducation;
Gtk::Label *lblOffice;
Gtk::Label *lblOther;
Gtk::Label *lblDevelopment;
Gtk::Label *lblSystem;
Gtk::Label *lblHeaderName;
Gtk::IconView *iconGraphics;
Gtk::IconView *iconTools;
Gtk::IconView *iconInternet;
Gtk::IconView *iconMultimedia;
Gtk::IconView *iconSettings;
Gtk::IconView *iconEducation;
Gtk::IconView *iconOffice;
Gtk::IconView *iconOther;
Gtk::IconView *iconDevelopment;
Gtk::IconView *iconSystem;
Gtk::IconView *iconEntry;
Gtk::MenuItem *btnAbout;
Gtk::MenuItem *btnhelp;
Gtk::AboutDialog *aboutWindows;
Gtk::MenuButton *btnSettings;
Gtk::ButtonBox *btnBoxAboutDialog;
Gtk::ComboBoxText *cmbTerminal;
Glib::RefPtr<Gtk::ListStore> list_Graphics;
Glib::RefPtr<Gtk::ListStore> list_Tools;
Glib::RefPtr<Gtk::ListStore> list_Internet;
Glib::RefPtr<Gtk::ListStore> list_Multimedia;
Glib::RefPtr<Gtk::ListStore> list_Settings;
Glib::RefPtr<Gtk::ListStore> list_Education;
Glib::RefPtr<Gtk::ListStore> list_Office;
Glib::RefPtr<Gtk::ListStore> list_Other;
Glib::RefPtr<Gtk::ListStore> list_Development;
Glib::RefPtr<Gtk::ListStore> list_System;
Gtk::Image *imgHeadBackground;
Gtk::Overlay *overHead;
Gtk::Widget *boxAbout;
Gtk::Label *lblHeaderAboutTopic;
Gtk::Label *lblHeadeWndWeb;
Gtk::Label *lblwebHeaderName;
Gtk::Label *lblhelpText;
Gtk::Label *lblhelpHeader;
Gtk::CheckButton *chkAlwaysOpenHelp;
Gtk::Button *btnReadHelp;
Gtk::Button *btnCancelHelp;
Gtk::Window *wndShowWeb;
#ifdef WEBKIT_FOUND
Gtk::Window *wndWeb;
Gtk::Widget *three;
WebKitWebView *my_web_kit = NULL;
#endif
public:
string termunal_cmd[3] = {"konsole -e ", "xfce4-terminal -x ", "xterm -e "};
string cmd_old = "";
string user_exec_app = "";
string user_cmd = "";
string user_cmd_old = "";
string name_app_old = "";
string path_file_old = "";
string execute_cmd = "";
string path_file = "";
string name_app = "";
int index_error = 0;
bool flag_pkexec = false;
bool flag_su = false;
bool flag_sudo = false;
bool flag_open_browser = false;
string path_file_name;
string global_lick_doc;
struct struct_App {
string Name_desktop;
string Name;
string Exec;
string Icon;
string MimeType;
string Type;
vector<std::string> Categories;
};
list <struct_App> list_app;
set <string> set_categories;
int index_exec_gui_apps = 0;
Gtk::IconView* array_icon[10];
};
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);