@ -1,40 +1,31 @@
# include <cstddef>
# include <cstdlib>
# include <iostream>
# include <memory>
# include <gtkmm.h>
# include <ostream>
# include <ctime>
# include <vector>
# include <map>
# include <fstream>
# include <filesystem>
# include <libintl.h>
# include <locale.h>
# include <stdio.h>
# include <unistd.h>
# include <sys/types.h>
# include <gtkmm/plug.h>
# include <gtkmm/stock.h>
# include <gtkmm/window.h>
# include <string>
# include <pwd.h>
# include <thread>
# include "ublexec.h"
# include "ublexec.h"
using namespace std ;
using namespace std ;
string path_app = " /usr/bin/ " ;
string path_app = " /usr/bin/ " ;
string path_glade = " /usr/share/ublexec/ui/ublexec.glade " ;
string path_glade = " /usr/share/ublexec/ui/ublexec.glade " ;
string path_css = " /usr/share/ublexec/css/style.css " ;
string path_css = " /usr/share/ublexec/css/style.css " ;
string app_name = " ublexec " ;
string app_name = " ublexec " ;
int socket_ext_id_I = 0 ;
int socket_trd_id_I = 0 ;
CmdArgParser : : CmdArgParser ( const std : : string & p_name , const std : : string & p_description , const std : : string & p_help )
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 : : OptionGroup { p_name , p_description , p_help } {
Glib : : OptionEntry socketIDArg ;
Glib : : OptionEntry socketIDArg ;
socketIDArg . set_long_name ( " socket-id " ) ;
socketIDArg . set_long_name ( " socket-id " ) ;
socketIDArg . set_short_name ( ' s ' ) ;
socketIDArg . set_flags ( Glib : : OptionEntry : : FLAG_IN_MAIN ) ;
socketIDArg . set_flags ( Glib : : OptionEntry : : FLAG_IN_MAIN ) ;
socketIDArg . set_description ( " Settings manager socket " ) ;
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 ( socketIDArg , m_socketID ) ;
add_entry ( socketExtId , socket_ext_id_I ) ;
add_entry ( socketTrdId , socket_trd_id_I ) ;
}
}
: : Window CmdArgParser : : GetSocketID ( ) const {
: : Window CmdArgParser : : GetSocketID ( ) const {
return m_socketID ;
return m_socketID ;
@ -88,7 +79,6 @@ void MainWindow::get_builder(){
builder - > get_widget ( " lblInfoNooPriority " , lblInfoNooPriority ) ;
builder - > get_widget ( " lblInfoNooPriority " , lblInfoNooPriority ) ;
builder - > get_widget ( " lblInfoExec " , lblInfoExec ) ;
builder - > get_widget ( " lblInfoExec " , lblInfoExec ) ;
builder - > get_widget ( " lblInfoPriority " , lblInfoPriority ) ;
builder - > get_widget ( " lblInfoPriority " , lblInfoPriority ) ;
builder - > get_widget ( " lblInfoEnterProg " , lblInfoEnterProg ) ;
builder - > get_widget ( " boxColor " , boxColor ) ;
builder - > get_widget ( " boxColor " , boxColor ) ;
builder - > get_widget ( " lblGraphics " , lblGraphics ) ;
builder - > get_widget ( " lblGraphics " , lblGraphics ) ;
builder - > get_widget ( " lblTools " , lblTools ) ;
builder - > get_widget ( " lblTools " , lblTools ) ;
@ -110,6 +100,12 @@ void MainWindow::get_builder(){
builder - > get_widget ( " iconDevelopment " , iconDevelopment ) ;
builder - > get_widget ( " iconDevelopment " , iconDevelopment ) ;
builder - > get_widget ( " iconSystem " , iconSystem ) ;
builder - > get_widget ( " iconSystem " , iconSystem ) ;
builder - > get_widget ( " lblSystem " , lblSystem ) ;
builder - > get_widget ( " lblSystem " , lblSystem ) ;
builder - > get_widget ( " lblHeaderName " , lblHeaderName ) ;
builder - > get_widget ( " btnSynopsis " , btnSynopsis ) ;
builder - > get_widget ( " btnAbout " , btnAbout ) ;
builder - > get_widget ( " aboutWindows " , aboutWindows ) ;
builder - > get_widget ( " btnSettings " , btnSettings ) ;
builder - > get_widget ( " btnBoxAboutDialog " , btnBoxAboutDialog ) ;
}
}
void MainWindow : : set_icon_array ( ) {
void MainWindow : : set_icon_array ( ) {
@ -125,18 +121,14 @@ void MainWindow::set_icon_array(){
array_icon [ 9 ] = this - > iconSystem ;
array_icon [ 9 ] = this - > iconSystem ;
}
}
void MainWindow : : template_apps_obj ( Gtk : : IconView * icon , Glib : : RefPtr < Gtk : : ListStore > & gtk_list_app ) {
void MainWindow : : template_apps_obj ( Gtk : : IconView * icon , Glib : : RefPtr < Gtk : : ListStore > & gtk_list_app ) {
gtk_list_app = Gtk : : ListStore : : create ( m_Columns ) ;
gtk_list_app = Gtk : : ListStore : : create ( m_Columns ) ;
gtk_list_app - > set_sort_column ( m_Columns . m_col_description , Gtk : : SORT_ASCENDING ) ;
gtk_list_app - > set_sort_column ( m_Columns . m_col_description , Gtk : : SORT_ASCENDING ) ;
icon - > set_model ( gtk_list_app ) ;
icon - > set_model ( gtk_list_app ) ;
icon - > set_markup_column ( m_Columns . m_col_description ) ;
icon - > set_text_column ( m_Columns . m_col_description ) ;
icon - > set_pixbuf_column ( m_Columns . m_col_pixbuf ) ;
}
}
void MainWindow : : add_CSS ( ) {
void MainWindow : : add_CSS ( ) {
Glib : : RefPtr < Gtk : : CssProvider > cssProvider = Gtk : : CssProvider : : create ( ) ;
Glib : : RefPtr < Gtk : : CssProvider > cssProvider = Gtk : : CssProvider : : create ( ) ;
cssProvider - > load_from_path ( path_css ) ;
cssProvider - > load_from_path ( path_css ) ;
Glib : : RefPtr < Gtk : : StyleContext > styleContext = Gtk : : StyleContext : : create ( ) ;
Glib : : RefPtr < Gtk : : StyleContext > styleContext = Gtk : : StyleContext : : create ( ) ;
@ -146,44 +138,48 @@ void MainWindow::add_CSS(){
Glib : : RefPtr < Gtk : : StyleContext > context_lbl_head = lblInfoHead - > get_style_context ( ) ;
Glib : : RefPtr < Gtk : : StyleContext > context_lbl_head = lblInfoHead - > get_style_context ( ) ;
context_box - > add_class ( " cssboxColor1 " ) ;
context_box - > add_class ( " cssboxColor1 " ) ;
context_lbl_head - > add_class ( " textHead " ) ;
context_lbl_head - > add_class ( " textHead " ) ;
}
}
void MainWindow : : localization ( ) {
void MainWindow : : localization ( ) {
this - > set_title ( gettext ( " ublexec " ) ) ;
aboutWindows - > set_website ( _ ( " https://wiki.ublinux.com " ) ) ;
btnStart - > set_label ( gettext ( " Run " ) ) ;
btnSynopsis - > set_label ( _ ( " Help " ) ) ;
wndChooseFileWallpaper - > set_title ( gettext ( " Please select File " ) ) ;
btnAbout - > set_label ( _ ( " About the program " ) ) ;
dialogStartMenu - > set_title ( gettext ( " Selecting Programs " ) ) ;
aboutWindows - > set_comments ( _ ( " ublexec " ) ) ;
lblInfoHead - > set_text ( gettext ( " Running applications as a user with a \n specified priority " ) ) ;
aboutWindows - > set_website_label ( _ ( " Project Home Page " ) ) ;
lblinfoCmd - > set_text ( gettext ( " Command Line " ) ) ;
aboutWindows - > set_version ( _ ( version_application . c_str ( ) ) ) ;
lblInfoTime - > set_text ( gettext ( " Team " ) ) ;
lblHeaderName - > set_text ( _ ( " ublexec " ) ) ;
labInfoExecutTerm - > set_text ( gettext ( " Run in the terminal emulator " ) ) ;
this - > set_title ( _ ( " ublexec " ) ) ;
lblInfoUser - > set_text ( gettext ( " User " ) ) ;
btnStart - > set_label ( _ ( " Run " ) ) ;
lblInfoUserOther - > set_text ( gettext ( " Run as another user " ) ) ;
wndChooseFileWallpaper - > set_title ( _ ( " Please select File " ) ) ;
lblInfoUserName - > set_text ( gettext ( " User Name " ) ) ;
dialogStartMenu - > set_title ( _ ( " Selecting Programs " ) ) ;
lblInfoNooPriority - > set_text ( gettext ( " Priority " ) ) ;
lblInfoHead - > set_text ( _ ( " Running applications as a user with a \n specified priority " ) ) ;
lblInfoExec - > set_text ( gettext ( " Change startup priority " ) ) ;
lblinfoCmd - > set_text ( _ ( " Command Line " ) ) ;
lblInfoPriority - > set_text ( gettext ( " Priority " ) ) ;
lblInfoTime - > set_text ( _ ( " Team " ) ) ;
lblMessageError - > set_text ( gettext ( " Select an executable file or program " ) ) ;
labInfoExecutTerm - > set_text ( _ ( " Run in the terminal emulator " ) ) ;
lblInfoEnterProg - > set_text ( gettext ( " Selecting Programs " ) ) ;
lblInfoUser - > set_text ( _ ( " User " ) ) ;
lblGraphics - > set_text ( gettext ( " Graphics " ) ) ;
lblInfoUserOther - > set_text ( _ ( " Run as another user " ) ) ;
lblTools - > set_text ( gettext ( " Tools " ) ) ;
lblInfoUserName - > set_text ( _ ( " User Name " ) ) ;
lblInternet - > set_text ( gettext ( " Internet " ) ) ;
lblInfoNooPriority - > set_text ( _ ( " Priority " ) ) ;
lblMultimedia - > set_text ( gettext ( " Multimedia " ) ) ;
lblInfoExec - > set_text ( _ ( " Change startup priority " ) ) ;
lblSettings - > set_text ( gettext ( " Settings " ) ) ;
lblInfoPriority - > set_text ( _ ( " Priority " ) ) ;
lblEducation - > set_text ( gettext ( " Education " ) ) ;
lblMessageError - > set_text ( _ ( " Select an executable file or program " ) ) ;
lblOffice - > set_text ( gettext ( " Office " ) ) ;
lblGraphics - > set_text ( _ ( " Graphics " ) ) ;
lblOther - > set_text ( gettext ( " Other " ) ) ;
lblTools - > set_text ( _ ( " Tools " ) ) ;
lblDevelopment - > set_text ( gettext ( " Development " ) ) ;
lblInternet - > set_text ( _ ( " Internet " ) ) ;
lblSystem - > set_text ( gettext ( " System " ) ) ;
lblMultimedia - > set_text ( _ ( " Multimedia " ) ) ;
lblSettings - > set_text ( _ ( " Settings " ) ) ;
lblEducation - > set_text ( _ ( " Education " ) ) ;
lblOffice - > set_text ( _ ( " Office " ) ) ;
lblOther - > set_text ( _ ( " Other " ) ) ;
lblDevelopment - > set_text ( _ ( " Development " ) ) ;
lblSystem - > set_text ( _ ( " System " ) ) ;
}
}
void MainWindow : : event ( ) {
void MainWindow : : event ( ) {
btnFilemaneg - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : open_filemaneg ) ) ;
btnFilemaneg - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : open_filemaneg ) ) ;
btnListApp - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : open_list_app ) ) ;
btnListApp - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : open_list_app ) ) ;
btnStart - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : start_cmd ) ) ;
btnStart - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : entry_app ) ) ;
cmbUser - > signal_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : changed_user ) ) ;
chbTerminal - > signal_toggled ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : denamic_cmd ) ) ;
//chbTerminal->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::execute_terminal));
chbAnotherUser - > signal_toggled ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : activ_or_block_other_user ) ) ;
chbAnotherUser - > signal_toggled ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : activ_or_block_other_user ) ) ;
spinPriority - > signal_value_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : change_scale_priority ) ) ;
spinPriority - > signal_value_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : change_scale_priority ) ) ;
scalePriority - > signal_value_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : change_spin_priority ) ) ;
scalePriority - > signal_value_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : change_spin_priority ) ) ;
@ -204,6 +200,43 @@ void MainWindow::event(){
iconOther - > signal_selection_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : select_Other ) ) ;
iconOther - > signal_selection_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : select_Other ) ) ;
iconDevelopment - > signal_selection_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : select_Development ) ) ;
iconDevelopment - > signal_selection_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : select_Development ) ) ;
iconSystem - > signal_selection_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : select_System ) ) ;
iconSystem - > signal_selection_changed ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : select_System ) ) ;
btnSynopsis - > signal_activate ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : synopsis_show ) ) ;
btnAbout - > signal_activate ( ) . connect ( [ & ] ( ) { aboutWindows - > show ( ) ; } ) ;
cmbUser - > signal_changed ( ) . connect ( [ & ] ( ) { denamic_cmd ( ) ; changed_user ( ) ; } ) ;
rbSudo - > signal_toggled ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : denamic_cmd ) ) ;
txtCmd - > signal_focus_out_event ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : focus_out_txt_cmd ) ) ;
txtCmd - > signal_focus_in_event ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : focus_in_txt_cmd ) ) ;
txtCmd - > signal_delete_text ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : delete_cmd ) ) ;
}
void MainWindow : : delete_cmd ( const int & x , const int & y ) {
if ( y > 1 ) {
chbTerminal - > set_active ( false ) ;
chbAnotherUser - > set_active ( false ) ;
cbxExecuteEpriority - > set_active ( false ) ;
txtCmd - > set_text ( " " ) ;
}
}
bool MainWindow : : focus_in_txt_cmd ( GdkEventFocus * event ) {
if ( user_cmd . length ( ) ! = 0 ) {
//user_cmd_old = user_cmd;gi
}
else if ( name_app . length ( ) ! = 0 ) {
//name_app_old = name_app;
}
else if ( path_file . length ( ) ! = 0 ) {
//path_file_old = path_file;
}
else {
user_cmd = txtCmd - > get_text ( ) ;
}
cmd_old = txtCmd - > get_text ( ) ;
return true ;
}
void MainWindow : : synopsis_show ( ) {
system ( " xdg-open https://wiki.ublinux.ru/ru/home & " ) ;
}
}
void MainWindow : : icon_clear ( ) {
void MainWindow : : icon_clear ( ) {
@ -213,7 +246,6 @@ void MainWindow::icon_clear(){
list_Multimedia - > clear ( ) ;
list_Multimedia - > clear ( ) ;
list_Settings - > clear ( ) ;
list_Settings - > clear ( ) ;
list_Education - > clear ( ) ;
list_Education - > clear ( ) ;
list_Graphics - > clear ( ) ;
list_Office - > clear ( ) ;
list_Office - > clear ( ) ;
list_Other - > clear ( ) ;
list_Other - > clear ( ) ;
list_Development - > clear ( ) ;
list_Development - > clear ( ) ;
@ -266,6 +298,9 @@ void MainWindow::tempate_icon_select(Gtk::IconView *icon, Glib::RefPtr<Gtk::List
Gtk : : TreeModel : : Row row = * iter ;
Gtk : : TreeModel : : Row row = * iter ;
auto app_name_exec = row [ m_Columns . app_name_exec ] ;
auto app_name_exec = row [ m_Columns . app_name_exec ] ;
const Glib : : ustring description = row [ m_Columns . m_col_description ] ;
const Glib : : ustring description = row [ m_Columns . m_col_description ] ;
path_file = " " ;
name_app = " " ;
user_cmd = " " ;
txtCmd - > set_text ( app_name_exec ) ;
txtCmd - > set_text ( app_name_exec ) ;
name_app = txtCmd - > get_text ( ) ;
name_app = txtCmd - > get_text ( ) ;
int len_name_app = name_app . length ( ) ;
int len_name_app = name_app . length ( ) ;
@ -312,18 +347,13 @@ void MainWindow::settings(){
rbPkexec - > set_sensitive ( false ) ;
rbPkexec - > set_sensitive ( false ) ;
rbSu - > set_sensitive ( false ) ;
rbSu - > set_sensitive ( false ) ;
rbSudo - > set_sensitive ( false ) ;
rbSudo - > set_sensitive ( false ) ;
btnBoxAboutDialog - > set_visible ( false ) ;
Gtk : : Widget * boxAbout ;
builder - > get_widget ( " boxAbout " , boxAbout ) ;
//Gtk::Widget *standartHead;
ubl_make_plugs ( boxAbout , boxAbout , 0 , socket_trd_id_I ) ;
//Gtk::Widget *plugBox;
//Gtk::Window *window;
}
//Gtk::Widget *btnSave;
//builder->get_widget("standartHead",standartHead);
//builder->get_widget("plugBox",plugBox);
//builder->get_widget("window",window);
//builder->get_widget("btnSave",btnSave);
//ubl_get_standard_ui(standartHead,plugBox,btnSave,window,"ublexec.svg",gettext("Running applications as a user with a\nspecified priority"),gettext("ublexec"),0,0);
}
void MainWindow : : close_entry_app ( ) {
void MainWindow : : close_entry_app ( ) {
this - > icon_clear ( ) ;
this - > icon_clear ( ) ;
dialogStartMenu - > hide ( ) ;
dialogStartMenu - > hide ( ) ;
@ -342,6 +372,7 @@ void MainWindow::activ_or_block_execute_epriority(){
lblInfoNooPriority - > set_sensitive ( flag ) ;
lblInfoNooPriority - > set_sensitive ( flag ) ;
lblTimeEpriorityLow - > set_sensitive ( flag ) ;
lblTimeEpriorityLow - > set_sensitive ( flag ) ;
lblTime4EpriorityHigh - > set_sensitive ( flag ) ;
lblTime4EpriorityHigh - > set_sensitive ( flag ) ;
this - > denamic_cmd ( ) ;
}
}
void MainWindow : : open_filemaneg ( ) {
void MainWindow : : open_filemaneg ( ) {
@ -353,26 +384,26 @@ void MainWindow::close_filemaneg(){
}
}
void MainWindow : : get_path_filemaneg ( ) {
void MainWindow : : get_path_filemaneg ( ) {
name_app = " " ;
user_cmd = " " ;
path_file = wndChooseFileWallpaper - > get_filename ( ) ;
path_file = wndChooseFileWallpaper - > get_filename ( ) ;
if ( path_file . length ( ) = = 0 ) { }
if ( path_file . length ( ) = = 0 ) { }
else {
else {
txtCmd - > set_text ( path_file ) ;
txtCmd - > set_text ( path_file ) ;
this - > close_filemaneg ( ) ;
this - > close_filemaneg ( ) ;
}
}
this - > denamic_cmd ( ) ;
}
}
void MainWindow : : tempalte_row ( string Name , string Exec , string path , Glib : : RefPtr < Gtk : : ListStore > & dtk_list ) {
void MainWindow : : tempalte_row ( string Name , string Exec , string path , Glib : : RefPtr < Gtk : : ListStore > & dtk_list ) {
Gtk : : TreeModel : : Row row = * ( dtk_list - > append ( ) ) ;
Gtk : : TreeModel : : Row row = * ( dtk_list - > append ( ) ) ;
row [ m_Columns . m_col_filename ] = path ;
row [ m_Columns . m_col_filename ] = path ;
row [ m_Columns . m_col_description ] = Name ;
row [ m_Columns . m_col_description ] = Name ;
row [ m_Columns . icon_name ] = path ;
row [ m_Columns . app_name_exec ] = Exec ;
row [ m_Columns . app_name_exec ] = Exec ;
if ( std : : ifstream ( path ) ) {
row [ m_Columns . float_h_align ] = 0.5 ;
row [ m_Columns . m_col_pixbuf ] = Gdk : : Pixbuf : : create_from_file ( path ) ;
row [ m_Columns . float_w_align ] = 0.5 ;
}
else {
path = " /usr/share/icons/Faenza/emblems/16/emblem-danger.png " ;
row [ m_Columns . m_col_pixbuf ] = Gdk : : Pixbuf : : create_from_file ( path ) ;
}
}
}
void MainWindow : : open_list_app ( ) {
void MainWindow : : open_list_app ( ) {
@ -389,7 +420,7 @@ void MainWindow::open_list_app(){
string path = " " ;
string path = " " ;
for ( const auto & st_app : list_app ) {
for ( const auto & st_app : list_app ) {
for ( const auto & str_categor : st_app . Categories ) {
for ( const auto & str_categor : st_app . Categories ) {
path = " /usr/share/icons/hicolor/16x16/apps/ " + st_app . Icon + " .png " ;
path = st_app . Icon ;
if ( str_categor = = " Graphics " ) {
if ( str_categor = = " Graphics " ) {
this - > tempalte_row ( st_app . Name , st_app . Exec , path , list_Graphics ) ;
this - > tempalte_row ( st_app . Name , st_app . Exec , path , list_Graphics ) ;
}
}
@ -420,118 +451,142 @@ void MainWindow::open_list_app(){
else if ( str_categor = = " System " ) {
else if ( str_categor = = " System " ) {
this - > tempalte_row ( st_app . Name , st_app . Exec , path , list_System ) ;
this - > tempalte_row ( st_app . Name , st_app . Exec , path , list_System ) ;
}
}
}
}
}
}
dialogStartMenu - > show_all ( ) ;
dialogStartMenu - > show_all ( ) ;
}
}
void MainWindow : : start_cmd ( ) {
string MainWindow : : start_cmd ( string user_cmd ) {
string str_cmd_terminal = " " ;
string str_cmd_terminal = " " ;
string str_variants_root = " " ;
string str_variants_root = " " ;
string str_nice_cmd = " " ;
string str_nice_cmd = " " ;
string user_cmd = " " ;
if ( name_app . length ( ) = = 0 & & path_file . length ( ) = = 0 ) {
user_cmd = txtCmd - > get_text ( ) ;
}
//=========================================
if ( chbAnotherUser - > get_active ( ) ) {
if ( chbAnotherUser - > get_active ( ) ) {
if ( geteuid ( ) ! = 0 ) {
if ( geteuid ( ) ! = 0 ) {
//chbTerminal->set_active(true);
//chbTerminal->set_active(true);
}
}
if ( rbPkexec - > get_active ( ) ) {
if ( rbPkexec - > get_active ( ) ) {
if ( ( chbAnotherUser - > get_active ( ) ) & & ( cmbUser - > get_active_text ( ) . length ( ) = = 0 ) ) {
str_variants_root = " pkexec --user " + cmbUser - > get_active_text ( ) ;
if ( cbxExecuteEpriority - > get_active ( ) ) {
str_variants_root = " pkexec --user ${USER} env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY " ;
str_variants_root + = " nice -n " + to_string ( spinPriority - > get_value_as_int ( ) ) ;
}
else if ( chbAnotherUser - > get_active ( ) ) {
str_variants_root = " pkexec --user " + cmbUser - > get_active_text ( ) + " env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY " ;
}
else {
str_variants_root = " pkexec --user ${USER} env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY " ;
}
}
str_variants_root + = " env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY " ;
}
}
else if ( rbSu - > get_active ( ) ) {
else if ( rbSu - > get_active ( ) ) {
if ( ( chbAnotherUser - > get_active ( ) ) & & ( cmbUser - > get_active_text ( ) . length ( ) = = 0 ) ) {
chbTerminal - > set_active ( true ) ;
str_variants_root = " su " ;
string str_user = cmbUser - > get_active_text ( ) ;
}
if ( str_user ! = " root " ) {
else if ( chbAnotherUser - > get_active ( ) ) {
str_variants_root = " su -l " + cmbUser - > get_active_text ( ) ;
str_variants_root = " su --user " + cmbUser - > get_active_text ( ) + " " ;
}
}
else {
else {
str_variants_root = " su " ;
str_variants_root = " su " ;
}
str_variants_root + = + " -c \" DISPLAY=$DISPLAY " ;
if ( cbxExecuteEpriority - > get_active ( ) ) {
str_variants_root + = " nice -n " + to_string ( spinPriority - > get_value_as_int ( ) ) + " " ;
}
}
}
}
else if ( rbSudo - > get_active ( ) ) {
else if ( rbSudo - > get_active ( ) ) {
if ( ( chbAnotherUser - > get_active ( ) ) & & ( cmbUser - > get_active_text ( ) . length ( ) = = 0 ) ) {
chbTerminal - > set_active ( true ) ;
if ( getlogin ( ) = = cmbUser - > get_active_text ( ) ) {
str_variants_root = " sudo " ;
str_variants_root = " sudo " ;
}
}
else if ( chbAnotherUser - > get_active ( ) ) {
str_variants_root = " sudo --user " + cmbUser - > get_active_text ( ) + " " ;
}
else {
else {
str_variants_root = " sudo " ;
str_variants_root = " sudo -u " + cmbUser - > get_active_text ( ) + " " ;
}
if ( cbxExecuteEpriority - > get_active ( ) ) {
str_variants_root + = " nice -n " + to_string ( spinPriority - > get_value_as_int ( ) ) + " " ;
}
}
}
}
}
}
if ( cbxExecuteEpriority - > get_active ( ) ) {
if ( cmbUser - > get_active_text ( ) . length ( ) ! = 0 ) {
str_nice_cmd = " nice -n " + to_string ( spinPriority - > get_value_as_int ( ) ) + " " ;
string user_cmd_X = " xhost +SI:localuser: " ;
user_cmd_X + = cmbUser - > get_active_text ( ) ;
system ( user_cmd_X . c_str ( ) ) ;
}
if ( ( cbxExecuteEpriority - > get_active ( ) ) & & ( chbAnotherUser - > get_active ( ) = = false ) ) {
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 ) {
if ( user_cmd . length ( ) = = 0 & & name_app . length ( ) = = 0 & & path_file . length ( ) = = 0 ) {
messageError - > show ( ) ;
messageError - > show ( ) ;
return ;
return " " ;
}
}
if ( chbTerminal - > get_active ( ) ) {
if ( chbTerminal - > get_active ( ) = = true ) {
str_cmd_terminal = " xterm -e " ;
str_cmd_terminal = " xterm -e " ;
}
}
else {
else {
str_cmd_terminal = " " ;
str_cmd_terminal = " " ;
}
}
string cmd = " " ;
string cmd = " " ;
if ( path_file ! = " " ) {
if ( path_file . length ( ) > 0 ) {
cmd = str_nice_cmd + " nohup " + str_cmd_terminal + str_variants_root + " xdg-open ' " + path_file + " ' " ;
cmd = " nohup " + str_nice_cmd + str_cmd_terminal + str_variants_root + " xdg-open ' " + path_file + " ' " ;
}
else if ( name_app . length ( ) > 0 ) {
cmd = " nohup " + str_nice_cmd + str_cmd_terminal + str_variants_root + name_app ;
}
else if ( user_cmd . length ( ) > 0 ) {
cmd = " nohup " + str_nice_cmd + str_cmd_terminal + str_variants_root + " " + user_cmd ;
}
}
else if ( name_app ! = " " ) {
if ( cmd . find ( " -e su " ) ! = string : : npos ) {
cmd = str_nice_cmd + " nohup " + str_cmd_terminal + str_variants_root + name_app ;
cmd + = " \" " ;
}
cmd + = " > /dev/null 2>&1 " ;
return cmd ;
}
void MainWindow : : call_app ( string & cmd ) {
if ( cmd . length ( ) ! = 0 ) {
std : : thread t ( [ & ] ( string cmd ) { system ( cmd . c_str ( ) ) ; } , cmd ) ;
t . detach ( ) ;
}
}
void MainWindow : : denamic_cmd ( ) {
if ( chbTerminal - > get_active ( ) = = true | | chbAnotherUser - > get_active ( ) = = true | | cbxExecuteEpriority - > get_active ( ) = = true ) {
if ( txtCmd - > get_text ( ) . length ( ) = = 0 ) {
chbTerminal - > set_active ( false ) ;
chbAnotherUser - > set_active ( false ) ;
cbxExecuteEpriority - > set_active ( false ) ;
path_file = " " ;
name_app = " " ;
user_cmd = " " ;
txtCmd - > set_text ( user_cmd ) ;
messageError - > show ( ) ;
}
else {
txtCmd - > set_text ( this - > start_cmd ( user_cmd ) ) ;
}
}
}
else {
else {
user_cmd = this - > str_remove ( user_cmd , str_cmd_terminal ) ;
if ( user_cmd . length ( ) ! = 0 ) {
user_cmd = this - > str_remove ( user_cmd , str_variants_root ) ;
txtCmd - > set_text ( this - > start_cmd ( user_cmd ) ) ;
user_cmd = this - > str_remove ( user_cmd , str_nice_cmd ) ;
}
string str_del = " xterm -e " ;
else if ( path_file . length ( ) ! = 0 ) {
user_cmd = this - > str_remove ( user_cmd , str_del ) ;
txtCmd - > set_text ( this - > start_cmd ( user_cmd ) ) ;
str_del = " nohup " ;
}
user_cmd = this - > str_remove ( user_cmd , str_del ) ;
else if ( name_app . length ( ) ! = 0 ) {
str_del = " pkexec --user superadmin env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY " ;
txtCmd - > set_text ( this - > start_cmd ( user_cmd ) ) ;
user_cmd = this - > str_remove ( user_cmd , str_del ) ;
str_del = " & " ;
user_cmd = this - > str_remove ( user_cmd , str_del ) ;
for ( int index = - 20 ; index < 20 ; index + + ) {
str_del = to_string ( index ) ;
user_cmd = this - > str_remove ( user_cmd , str_del ) ;
}
}
str_del = cmbUser - > get_active_text ( ) ;
user_cmd = this - > str_remove ( user_cmd , str_del ) ;
cmd = str_nice_cmd + " nohup " + str_cmd_terminal + str_variants_root + user_cmd ;
}
}
txtCmd - > set_text ( cmd ) ;
cmd + = " > /dev/null 2>&1 " ;
std : : thread t ( & me_thread , cmd ) ;
t . detach ( ) ;
path_file_name = " " ;
path_file = " " ;
name_app = " " ;
}
}
void me_thread ( string cmd ) {
bool MainWindow : : focus_out_txt_cmd ( GdkEventFocus * event ) {
system ( cmd . c_str ( ) ) ;
if ( cmd_old ! = txtCmd - > get_text ( ) ) {
user_cmd = txtCmd - > get_text ( ) ;
}
return true ;
}
void MainWindow : : entry_app ( ) {
this - > denamic_cmd ( ) ;
if ( name_app . length ( ) = = 0 & & path_file . length ( ) = = 0 ) {
}
string cmd = txtCmd - > get_text ( ) ;
this - > call_app ( cmd ) ;
}
}
void MainWindow : : changed_user ( ) {
void MainWindow : : changed_user ( ) {
@ -559,23 +614,26 @@ void MainWindow::activ_or_block_other_user(){
cmbUser - > set_active ( 0 ) ;
cmbUser - > set_active ( 0 ) ;
cmbUser - > set_sensitive ( flag ) ;
cmbUser - > set_sensitive ( flag ) ;
lblInfoUserName - > set_sensitive ( flag ) ;
lblInfoUserName - > set_sensitive ( flag ) ;
if ( flag_pkexec = = true ) {
if ( flag_pkexec = = true ) {
rbPkexec - > set_sensitive ( flag ) ;
rbPkexec - > set_sensitive ( flag ) ;
}
}
if ( flag_su = = true ) {
if ( flag_su = = true ) {
rbSu - > set_sensitive ( flag ) ;
rbSu - > set_sensitive ( flag ) ;
}
}
if ( flag_sudo = = true ) {
if ( flag_sudo = = true ) {
rbSudo - > set_sensitive ( flag ) ;
rbSudo - > set_sensitive ( flag ) ;
}
}
this - > denamic_cmd ( ) ;
}
}
void MainWindow : : change_scale_priority ( ) {
void MainWindow : : change_scale_priority ( ) {
scalePriority - > set_value ( spinPriority - > get_value_as_int ( ) ) ;
scalePriority - > set_value ( spinPriority - > get_value_as_int ( ) ) ;
this - > denamic_cmd ( ) ;
}
}
void MainWindow : : change_spin_priority ( ) {
void MainWindow : : change_spin_priority ( ) {
spinPriority - > set_value ( scalePriority - > get_value ( ) ) ;
spinPriority - > set_value ( scalePriority - > get_value ( ) ) ;
this - > denamic_cmd ( ) ;
}
}
void MainWindow : : pars_dir_bin ( ) {
void MainWindow : : pars_dir_bin ( ) {
@ -585,13 +643,13 @@ void MainWindow::pars_dir_bin(){
for ( const auto & entry : fs : : directory_iterator ( path ) ) {
for ( const auto & entry : fs : : directory_iterator ( path ) ) {
file_name = entry . path ( ) . filename ( ) . string ( ) ;
file_name = entry . path ( ) . filename ( ) . string ( ) ;
if ( file_name = = " su " ) {
if ( file_name = = " su " ) {
flag_su = true ;
flag_su = true ;
}
}
else if ( file_name = = " sudo " ) {
else if ( file_name = = " sudo " ) {
flag_sudo = true ;
flag_sudo = true ;
}
}
else if ( file_name = = " pkexec " ) {
else if ( file_name = = " pkexec " ) {
flag_pkexec = true ;
flag_pkexec = true ;
}
}
}
}
rbPkexec - > set_sensitive ( flag_pkexec ) ;
rbPkexec - > set_sensitive ( flag_pkexec ) ;
@ -610,7 +668,7 @@ void MainWindow::pars_users(){
break ;
break ;
}
}
if ( entry - > pw_uid > = 1000 & & entry - > pw_uid ! = 65534 ) {
if ( entry - > pw_uid > = 1000 & & entry - > pw_uid ! = 65534 ) {
cmbUser - > append ( entry - > pw_name ) ;
cmbUser - > append ( entry - > pw_name ) ;
}
}
}
}
@ -628,13 +686,12 @@ vector<std::string> MainWindow::split(const std::string &s, char delim) {
return elems ;
return elems ;
}
}
string MainWindow : : str_remove ( std : : string & source , const std : : string & to_remove ) {
void MainWindow : : str_remove ( std : : string & source , std : : string & to_remove ) {
auto begin = source . find ( to_remove ) ;
string : : size_type n = to_remove . length ( ) ;
if ( begin ! = std : : string : : npos ) {
for ( string : : size_type i = source . find ( to_remove ) ;
int len_to_remove = to_remove . length ( ) ;
i ! = string : : npos ;
source . erase ( begin , begin + len_to_remove ) ;
i = source . find ( to_remove ) )
}
source . erase ( i , n ) ;
return source ;
}
}
void MainWindow : : pars_apps ( ) {
void MainWindow : : pars_apps ( ) {