@ -1,14 +1,10 @@
# include "ublexec.h"
using namespace std ;
const string path_app = " /usr/bin/ " ;
const string path_glade = " /usr/share/ublexec/ui/ublexec.glade " ;
const string path_css = " /usr/share/ublexec/css/ublexec.css " ;
const string app_name = " ublexec " ;
int flag_prog_file = 0 ;
string name_app_cmd = " " ;
string version_application = " 2.23 " ;
const string path_img_head_background = " /usr/share/ublexec/images/logo-background.png " ;
string version_application = " 2.24 " ;
int socket_ext_id_I = 0 ;
int socket_trd_id_I = 0 ;
@ -111,6 +107,20 @@ void MainWindow::get_builder() {
builder - > get_widget ( " btnBoxAboutDialog " , btnBoxAboutDialog ) ;
builder - > get_widget ( " boxAbout " , boxAbout ) ;
builder - > get_widget ( " cmbTerminal " , cmbTerminal ) ;
builder - > get_widget ( " lblHeaderAboutTopic " , lblHeaderAboutTopic ) ;
builder - > get_widget ( " lblwebHeaderName " , lblwebHeaderName ) ;
builder - > get_widget ( " lblhelpText " , lblhelpText ) ;
builder - > get_widget ( " lblhelpHeader " , lblhelpHeader ) ;
builder - > get_widget ( " chkAlwaysOpenHelp " , chkAlwaysOpenHelp ) ;
builder - > get_widget ( " btnReadHelp " , btnReadHelp ) ;
builder - > get_widget ( " btnCancelHelp " , btnCancelHelp ) ;
builder - > get_widget ( " wndShowWeb " , wndShowWeb ) ;
builder - > get_widget ( " lblHeadeWndWeb " , lblHeadeWndWeb ) ;
# ifdef WEBKIT_FOUND
builder - > get_widget ( " wndWeb " , wndWeb ) ;
# endif
}
void MainWindow : : set_icon_array ( ) {
@ -156,48 +166,61 @@ 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 ) ;
string str_authors = string ( copyright ) + to_string ( year ) ;
aboutWindows - > set_copyright ( str_authors ) ;
aboutWindows - > set_website ( gettext ( " https://wiki.ublinux.com " ) ) ;
btnSynopsis - > set_label ( gettext ( " Help " ) ) ;
btnAbout - > set_label ( gettext ( " About " ) ) ;
aboutWindows - > set_comments ( gettext ( " Run as... " ) ) ;
aboutWindows - > set_website_label ( gettext ( " Project Home Page " ) ) ;
aboutWindows - > set_version ( gettext ( version_application . c_str ( ) ) ) ;
aboutWindows - > set_title ( gettext ( " Run as... " ) ) ;
lblHeaderName - > set_text ( gettext ( " Run as... " ) ) ;
this - > set_title ( gettext ( " Run as... " ) ) ;
btnStart - > set_label ( gettext ( " Run " ) ) ;
wndChooseFileWallpaper - > set_title ( gettext ( " Please select File " ) ) ;
dialogStartMenu - > set_title ( gettext ( " Selecting Programs " ) ) ;
lblInfoHead - > set_text ( gettext ( " Run applications as another user \n with the specified priority " ) ) ;
lblinfoCmd - > set_text ( gettext ( " Command Line " ) ) ;
lblInfoTime - > set_text ( gettext ( " Team: " ) ) ;
labInfoExecutTerm - > set_text ( gettext ( " Run in the terminal emulator " ) ) ;
lblInfoUser - > set_text ( gettext ( " User " ) ) ;
lblInfoUserOther - > set_text ( gettext ( " Run as another user: " ) ) ;
lblInfoUserName - > set_text ( gettext ( " User Name: " ) ) ;
lblInfoNooPriority - > set_text ( gettext ( " Priority " ) ) ;
lblInfoExec - > set_text ( gettext ( " Change startup priority " ) ) ;
lblInfoPriority - > set_text ( gettext ( " Priority: " ) ) ;
lblMessageError - > set_text ( gettext ( " Select an executable file or program " ) ) ;
messageError - > set_title ( gettext ( " Attention " ) ) ;
lblGraphics - > set_text ( gettext ( " Graphics " ) ) ;
lblTools - > set_text ( gettext ( " Tools " ) ) ;
lblInternet - > set_text ( gettext ( " Internet " ) ) ;
lblMultimedia - > set_text ( gettext ( " Multimedia " ) ) ;
lblSettings - > set_text ( gettext ( " Settings " ) ) ;
lblEducation - > set_text ( gettext ( " Education " ) ) ;
lblOffice - > set_text ( gettext ( " Office " ) ) ;
lblOther - > set_text ( gettext ( " Other " ) ) ;
lblDevelopment - > set_text ( gettext ( " Development " ) ) ;
lblSystem - > set_text ( gettext ( " System " ) ) ;
btnListApp - > set_tooltip_text ( gettext ( " Application Overview " ) ) ;
btnFilemaneg - > set_tooltip_text ( gettext ( " File Overview " ) ) ;
btnMessageErrorOk - > set_label ( gettext ( " Close " ) ) ;
aboutWindows - > set_website ( website ) ;
btnSynopsis - > set_label ( str_help ) ;
btnAbout - > set_label ( str_about_1 ) ;
aboutWindows - > set_comments ( define_name_app ) ;
aboutWindows - > set_website_label ( home_page ) ;
aboutWindows - > set_version ( _ ( version_application . c_str ( ) ) ) ;
aboutWindows - > set_title ( space_name_app ) ;
lblHeaderAboutTopic - > set_label ( space_name_app ) ;
lblHeaderName - > set_text ( define_name_app ) ;
this - > set_title ( define_name_app ) ;
btnStart - > set_label ( str_run ) ;
wndChooseFileWallpaper - > set_title ( str_please_select_file ) ;
dialogStartMenu - > set_title ( str_selecting_programs ) ;
lblInfoHead - > set_text ( str_run_applications_as_another ) ;
lblinfoCmd - > set_text ( str_localization_cmd_line ) ;
lblInfoTime - > set_text ( str_localization_team ) ;
labInfoExecutTerm - > set_text ( str_run_terminal ) ;
lblInfoUser - > set_text ( str_localization_user ) ;
lblInfoUserOther - > set_text ( str_run_of_user ) ;
lblInfoUserName - > set_text ( str_localization_username ) ;
lblInfoNooPriority - > set_text ( str_localization_priority ) ;
lblInfoExec - > set_text ( str_change_priority ) ;
lblInfoPriority - > set_text ( string ( str_localization_priority ) + " : " ) ;
lblMessageError - > set_text ( str_select_app_program ) ;
messageError - > set_title ( str_localization_attention ) ;
lblGraphics - > set_text ( str_localization_graphics ) ;
lblTools - > set_text ( str_localization_tools ) ;
lblInternet - > set_text ( str_localization_internet ) ;
lblMultimedia - > set_text ( str_localization_multimedia ) ;
lblSettings - > set_text ( str_localization_settings ) ;
lblEducation - > set_text ( str_localization_education ) ;
lblOffice - > set_text ( str_localization_office ) ;
lblOther - > set_text ( str_localization_other ) ;
lblDevelopment - > set_text ( str_localization_development ) ;
lblSystem - > set_text ( str_localization_system ) ;
btnListApp - > set_tooltip_text ( str_application_overview ) ;
btnFilemaneg - > set_tooltip_text ( str_file_overview ) ;
btnMessageErrorOk - > set_label ( str_close ) ;
lblhelpHeader - > set_text ( read_documentation_web ) ;
lblhelpText - > set_text ( redirected_documentation ) ;
btnReadHelp - > set_label ( read_online ) ;
btnCancelHelp - > set_label ( cancel ) ;
chkAlwaysOpenHelp - > set_label ( always_redirect ) ;
lblwebHeaderName - > set_label ( name_app_1 ) ;
lblHeadeWndWeb - > set_label ( define_name_app ) ;
lblwebHeaderName - > set_label ( define_name_app ) ;
}
void MainWindow : : event ( ) {
btnCancelHelp - > signal_clicked ( ) . connect ( [ & ] ( ) { wndShowWeb - > hide ( ) ; } ) ;
chkAlwaysOpenHelp - > signal_toggled ( ) . connect ( [ & ] ( ) { flag_open_browser = true ; } ) ;
btnReadHelp - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : open_browser ) ) ;
btnSynopsis - > signal_activate ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : synopsis_show ) ) ;
btnFilemaneg - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : open_filemaneg ) ) ;
btnListApp - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : open_list_app ) ) ;
btnStart - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : entry_app ) ) ;
@ -235,6 +258,7 @@ void MainWindow::event() {
}
void MainWindow : : sudo_nice ( ) {
string response = this - > call ( " id -Gn " ) ;
if ( geteuid ( ) = = 0 | | cmbUser - > get_active_text ( ) = = " root " ) {
@ -242,32 +266,32 @@ void MainWindow::sudo_nice(){
spinPriority - > set_increments ( 1.0 , - 1.0 ) ;
scalePriority - > set_range ( - 20 , 19 ) ;
scalePriority - > set_value ( 0 ) ;
lblTimeEpriorityLow - > set_text ( gettext( " 19 (Low) " ) ) ;
lblTime4EpriorityHigh - > set_text ( gettext( " -20 (High) " ) ) ;
lblTimeEpriorityLow - > set_text ( nice_19 ) ;
lblTime4EpriorityHigh - > set_text ( nice__20 ) ;
}
else if ( rbSudo - > get_active ( ) & & response . find ( " wheel " ) ! = string : : npos ) {
spinPriority - > set_range ( - 20 , 19 ) ;
spinPriority - > set_increments ( 1.0 , - 1.0 ) ;
scalePriority - > set_range ( - 20 , 19 ) ;
scalePriority - > set_value ( 0 ) ;
lblTimeEpriorityLow - > set_text ( gettext( " 19 (Low) " ) ) ;
lblTime4EpriorityHigh - > set_text ( gettext( " -20 (High) " ) ) ;
lblTimeEpriorityLow - > set_text ( nice_19 ) ;
lblTime4EpriorityHigh - > set_text ( nice__20 ) ;
}
else if ( rbSu - > get_active ( ) ) {
spinPriority - > set_range ( 0 , 19 ) ;
spinPriority - > set_increments ( 1.0 , - 1.0 ) ;
scalePriority - > set_range ( 0 , 19 ) ;
scalePriority - > set_value ( 0 ) ;
lblTimeEpriorityLow - > set_text ( gettext( " 19 (Low) " ) ) ;
lblTime4EpriorityHigh - > set_text ( gettext( " 0 (High) " ) ) ;
lblTimeEpriorityLow - > set_text ( nice_19 ) ;
lblTime4EpriorityHigh - > set_text ( nice_0 ) ;
}
else if ( rbPkexec - > get_active ( ) ) {
spinPriority - > set_range ( 0 , 19 ) ;
spinPriority - > set_increments ( 1.0 , - 1.0 ) ;
scalePriority - > set_range ( 0 , 19 ) ;
scalePriority - > set_value ( 0 ) ;
lblTimeEpriorityLow - > set_text ( gettext( " 19 (Low) " ) ) ;
lblTime4EpriorityHigh - > set_text ( gettext( " 0 (High) " ) ) ;
lblTimeEpriorityLow - > set_text ( nice_19 ) ;
lblTime4EpriorityHigh - > set_text ( nice_0 ) ;
}
this - > denamic_cmd ( ) ;
}
@ -281,16 +305,16 @@ void MainWindow::changed_user() {
spinPriority - > set_increments ( 1.0 , - 1.0 ) ;
scalePriority - > set_range ( - 20 , 19 ) ;
scalePriority - > set_value ( 0 ) ;
lblTimeEpriorityLow - > set_text ( gettext( " 19 (Low) " ) ) ;
lblTime4EpriorityHigh - > set_text ( gettext( " -20 (High) " ) ) ;
lblTimeEpriorityLow - > set_text ( nice_19 ) ;
lblTime4EpriorityHigh - > set_text ( nice__20 ) ;
}
else {
spinPriority - > set_range ( 0 , 19 ) ;
spinPriority - > set_increments ( 1.0 , - 1.0 ) ;
scalePriority - > set_range ( 0 , 19 ) ;
scalePriority - > set_value ( 0 ) ;
lblTimeEpriorityLow - > set_text ( gettext( " 19 (Low) " ) ) ;
lblTime4EpriorityHigh - > set_text ( gettext( " 0 (High) " ) ) ;
lblTimeEpriorityLow - > set_text ( nice_19 ) ;
lblTime4EpriorityHigh - > set_text ( nice_0 ) ;
}
}
@ -323,10 +347,34 @@ bool MainWindow::focus_in_txt_cmd(GdkEventFocus* event) {
}
void MainWindow : : synopsis_show ( ) {
string cmd = " xdg-open " + string ( gettext ( " https://wiki.ublinux.com/ru/Пр о г р а ммно е _о б е с пе че ние /Пр о г р а ммы_и_у тилиты/В с е / " ) ) + app_name + " & " ;
if ( flag_open_browser = = true ) {
this - > open_browser ( ) ;
}
else {
wndShowWeb - > show_all ( ) ;
}
}
void MainWindow : : open_browser ( ) {
# ifdef WEBKIT_FOUND
webkit_web_view_load_uri ( one , link_doc ) ;
wndWeb - > show_all ( ) ;
# else
this - > template_open_browser ( ) ;
# endif
}
void MainWindow : : template_open_browser ( ) {
string cmd = cmd_xdg + string ( _ ( link_doc ) ) + " & " ;
string buf = " " ;
if ( geteuid ( ) = = 0 ) {
string response_user = getlogin ( ) ;
cmd = " su -l " + response_user + " -c \" DISPLAY=$DISPLAY " + cmd + " \" " ;
int size_s = std : : snprintf ( nullptr , 0 , cmd_execute , response_user . c_str ( ) , cmd . c_str ( ) ) + 1 ;
auto size = static_cast < size_t > ( size_s ) ;
std : : unique_ptr < char [ ] > buf ( new char [ size ] ) ;
std : : snprintf ( buf . get ( ) , size , cmd_execute , response_user . c_str ( ) , cmd . c_str ( ) ) ;
cmd = std : : string ( buf . get ( ) , buf . get ( ) + size - 1 ) ;
}
index_error = system ( cmd . c_str ( ) ) ;
}
@ -435,8 +483,8 @@ void MainWindow::settings() {
spinPriority - > set_increments ( 1.0 , - 1.0 ) ;
scalePriority - > set_range ( 0 , 19 ) ;
scalePriority - > set_value ( 0 ) ;
lblTimeEpriorityLow - > set_text ( gettext( " 19 (Low) " ) ) ;
lblTime4EpriorityHigh - > set_text ( gettext( " 0 (High) " ) ) ;
lblTimeEpriorityLow - > set_text ( nice_19 ) ;
lblTime4EpriorityHigh - > set_text ( nice_0 ) ;
scalePriority - > set_inverted ( true ) ;
Gtk : : Widget * boxWidget ;
builder - > get_widget ( " boxColor " , boxWidget ) ;
@ -456,7 +504,11 @@ void MainWindow::settings() {
btnBoxAboutDialog - > set_visible ( false ) ;
cmbTerminal - > set_sensitive ( false ) ;
ubl_make_plugs ( boxAbout , boxAbout , socket_ext_id_I , 0 ) ;
# ifdef WEBKIT_FOUND
one = WEBKIT_WEB_VIEW ( webkit_web_view_new ( ) ) ;
three = Glib : : wrap ( GTK_WIDGET ( one ) ) ;
wndWeb - > add ( * three ) ;
# endif
}
void MainWindow : : close_entry_app ( ) {
@ -641,7 +693,7 @@ string MainWindow::start_cmd(string user_cmd) {
str_nice_cmd = " nice -n " + to_string ( spinPriority - > get_value_as_int ( ) ) + " " ;
}
if ( user_cmd . length ( ) = = 0 & & name_app . length ( ) = = 0 & & path_file . length ( ) = = 0 ) {
messageError - > set_title ( gettext( " Attention " ) ) ;
messageError - > set_title ( str_localization_attention ) ;
messageError - > show ( ) ;
return " " ;
}
@ -710,7 +762,7 @@ void MainWindow::denamic_cmd() {
name_app = " " ;
user_cmd = " " ;
txtCmd - > set_text ( user_cmd ) ;
messageError - > set_title ( gettext( " Attention " ) ) ;
messageError - > set_title ( str_localization_attention ) ;
messageError - > show ( ) ;
}
else {
@ -887,8 +939,8 @@ unsigned short MainWindow::read_uid_min_max(string filename, string search){
}
void MainWindow : : pars_users ( ) {
unsigned short uid_min = this - > read_uid_min_max ( " /etc/login.defs " , " UID_MIN " ) ;
unsigned short uid_max = this - > read_uid_min_max ( " /etc/login.defs " , " UID_MAX " ) ;
unsigned short uid_min = this - > read_uid_min_max ( file_source_login_min_max , " UID_MIN " ) ;
unsigned short uid_max = this - > read_uid_min_max ( file_source_login_min_max , " UID_MAX " ) ;
while ( true ) {
errno = 0 ;
passwd * entry = getpwent ( ) ;
@ -929,10 +981,10 @@ void MainWindow::pars_apps() {
struct struct_App App ;
string file_name = " " ;
string str_Categories ;
string path = " /usr/share/applications/ " ;
string path = path_all_applications ;
for ( const auto & entry : fs : : directory_iterator ( path ) ) {
file_name = entry . path ( ) . filename ( ) . string ( ) ;
path = " /usr/share/applications/ " + file_name ;
path = string ( path_all_applications ) + file_name ;
if ( file_name . find ( " .desktop " ) ! = std : : string : : npos ) {
GKeyFile * gfile = g_key_file_new ( ) ;
g_key_file_load_from_file ( gfile , path . c_str ( ) , G_KEY_FILE_KEEP_TRANSLATIONS , NULL ) ;
@ -975,15 +1027,11 @@ SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr<Gtk::Builder> build
show_all_children ( ) ;
}
MainWindow : : ~ MainWindow ( ) {
}
void help ( ) {
string help = " GTK \" Run applications as another user with the specified priority \" for UBLinux \n \n "
" Usage: ublexec [OPTIONS...] \n "
" Options: \n "
" -h, --help Show this help \n "
" -V, --version Show package version \n "
" -x APP_NAME Running the program \n "
" -e FILE_NAME Running the file \n " ;
cout < < gettext ( help . c_str ( ) ) ;
cout < < str_help_h ;
}