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.
694 lines
26 KiB
694 lines
26 KiB
#include <cstddef>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <gtkmm.h>
|
|
#include <ostream>
|
|
#include <string>
|
|
#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 <stdio.h>
|
|
#include <gtkmm/plug.h>
|
|
#include <gtkmm/stock.h>
|
|
#include <gtkmm/window.h>
|
|
#include <string>
|
|
#include <gtkmm.h>
|
|
#include <gtkmm/plug.h>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <iostream>
|
|
#include <sys/types.h>
|
|
#include <pwd.h>
|
|
#include <set>
|
|
#include <regex>
|
|
#include "ublexec.h"
|
|
using namespace std;
|
|
|
|
string path_app= "/usr/bin/";
|
|
string path_glade= "/usr/share/ublexec/ui/ublexec.glade";
|
|
string path_css = "/usr/share/ublexec/css/style.css";
|
|
//string path_app = "/home/superadmin/Документы/Проект/ubconfig_new/ubcall/";
|
|
string app_name = "ublexec";
|
|
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;
|
|
}
|
|
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::get_builder(){
|
|
builder->get_widget("btnFilemaneg", btnFilemaneg);
|
|
builder->get_widget("btnListApp", btnListApp);
|
|
builder->get_widget("btnStart", btnStart);
|
|
builder->get_widget("chbTerminal", chbTerminal);
|
|
builder->get_widget("chbAnotherUser", chbAnotherUser);
|
|
builder->get_widget("cbxExecuteEpriority", cbxExecuteEpriority);
|
|
builder->get_widget("cmbUser", cmbUser);
|
|
builder->get_widget("spinPriority", spinPriority);
|
|
builder->get_widget("scalePriority", scalePriority);
|
|
builder->get_widget("rbPkexec", rbPkexec);
|
|
builder->get_widget("rbSu", rbSu);
|
|
builder->get_widget("rbSudo", rbSudo);
|
|
builder->get_widget("txtCmd", txtCmd);
|
|
builder->get_widget("wndChooseFileWallpaper", wndChooseFileWallpaper);
|
|
builder->get_widget("btnFilemangerExit", btnFilemangerExit);
|
|
builder->get_widget("btnFilemangerOk", btnFilemangerOk);
|
|
builder->get_widget("lblTimeEpriorityLow", lblTimeEpriorityLow);
|
|
builder->get_widget("lblTime4EpriorityHigh", lblTime4EpriorityHigh);
|
|
//builder->get_widget("lblUserName", lblUserName);
|
|
builder->get_widget("messageError", messageError);
|
|
builder->get_widget("lblMessageError", lblMessageError);
|
|
builder->get_widget("btnMessageErrorOk", btnMessageErrorOk);
|
|
builder->get_widget("btnMessageErrorOk", btnMessageErrorOk);
|
|
builder->get_widget("btnMessageErrorOk", btnMessageErrorOk);
|
|
builder->get_widget("dialogStartMenu", dialogStartMenu);
|
|
builder->get_widget("btnStartMenuOK", btnStartMenuOK);
|
|
builder->get_widget("btnStartMenuExit", btnStartMenuExit);
|
|
builder->get_widget("lblInfoHead", lblInfoHead);
|
|
builder->get_widget("lblinfoCmd", lblinfoCmd);
|
|
builder->get_widget("lblInfoTime", lblInfoTime);
|
|
builder->get_widget("labInfoExecutTerm", labInfoExecutTerm);
|
|
builder->get_widget("lblInfoUser", lblInfoUser);
|
|
builder->get_widget("lblInfoUserOther", lblInfoUserOther);
|
|
builder->get_widget("lblInfoUserName", lblInfoUserName);
|
|
builder->get_widget("lblInfoNooPriority", lblInfoNooPriority);
|
|
builder->get_widget("lblInfoExec", lblInfoExec);
|
|
builder->get_widget("lblInfoPriority", lblInfoPriority);
|
|
builder->get_widget("lblInfoPriority", lblInfoEnterProg);
|
|
builder->get_widget("boxColor", boxColor);
|
|
builder->get_widget("lblGraphics", lblGraphics);
|
|
builder->get_widget("lblTools", lblTools);
|
|
builder->get_widget("lblInternet", lblInternet);
|
|
builder->get_widget("lblMultimedia", lblMultimedia);
|
|
builder->get_widget("lblSettings", lblSettings);
|
|
builder->get_widget("lblEducation", lblEducation);
|
|
builder->get_widget("lblOffice", lblOffice);
|
|
builder->get_widget("lblOther", lblOther);
|
|
builder->get_widget("lblDevelopment", lblDevelopment);
|
|
builder->get_widget("iconGraphics", iconGraphics);
|
|
builder->get_widget("iconTools", iconTools);
|
|
builder->get_widget("iconInternet", iconInternet);
|
|
builder->get_widget("iconMultimedia", iconMultimedia);
|
|
builder->get_widget("iconSettings", iconSettings);
|
|
builder->get_widget("iconEducation", iconEducation);
|
|
builder->get_widget("iconOffice", iconOffice);
|
|
builder->get_widget("iconOther", iconOther);
|
|
builder->get_widget("iconDevelopment", iconDevelopment);
|
|
builder->get_widget("iconSystem", iconSystem);
|
|
builder->get_widget("lblSystem", lblSystem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::template_apps_obj(Gtk::IconView *icon, Glib::RefPtr<Gtk::ListStore> >k_list_app){
|
|
gtk_list_app = Gtk::ListStore::create(m_Columns);
|
|
gtk_list_app->set_sort_column(m_Columns.m_col_description, Gtk::SORT_ASCENDING);
|
|
icon->set_model(gtk_list_app);
|
|
icon->set_markup_column(m_Columns.m_col_description);
|
|
icon->set_pixbuf_column(m_Columns.m_col_pixbuf);
|
|
//icon->set_tooltip_column(m_Columns.app_name_exec);
|
|
}
|
|
|
|
|
|
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");
|
|
}
|
|
|
|
void MainWindow::localization(){
|
|
this->set_title(gettext("ublexec"));
|
|
btnStart->set_label(gettext("Run"));
|
|
wndChooseFileWallpaper->set_title(gettext("Please select File"));
|
|
dialogStartMenu->set_title(gettext("Warning!"));
|
|
lblInfoHead->set_text(gettext("Running applications as a user with a\n 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"));
|
|
lblInfoEnterProg->set_text(gettext("Selecting Programs"));
|
|
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"));
|
|
}
|
|
|
|
void MainWindow::event(){
|
|
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::start_cmd));
|
|
cmbUser->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::changed_user));
|
|
//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));
|
|
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));
|
|
btnFilemangerExit->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::close_filemaneg));
|
|
btnFilemangerOk->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::get_path_filemaneg));
|
|
cbxExecuteEpriority->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::activ_or_block_execute_epriority));
|
|
btnMessageErrorOk->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::message_gui_close));
|
|
btnStartMenuOK->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::start_menu_entry_app));
|
|
btnStartMenuExit->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::close_entry_app));
|
|
btnStartMenuOK->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::ok_close_entry_app));
|
|
iconGraphics->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_Graphics));
|
|
iconTools->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_Tools));
|
|
iconInternet->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_Internet));
|
|
iconMultimedia->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_Multimedia));
|
|
iconSettings->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_Settings));
|
|
iconEducation->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_Education));
|
|
iconOffice->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_Office));
|
|
iconOther->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_Other));
|
|
iconDevelopment->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_Development));
|
|
iconSystem->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_System));
|
|
|
|
|
|
}
|
|
|
|
void MainWindow::icon_clear(){
|
|
list_Graphics->clear();
|
|
list_Tools->clear();
|
|
list_Internet->clear();
|
|
list_Multimedia->clear();
|
|
list_Settings->clear();
|
|
list_Education->clear();
|
|
list_Graphics->clear();
|
|
list_Office->clear();
|
|
list_Other->clear();
|
|
list_Development->clear();
|
|
list_System->clear();
|
|
}
|
|
|
|
void MainWindow::ok_close_entry_app(){
|
|
this->icon_clear();
|
|
dialogStartMenu->hide();
|
|
}
|
|
|
|
void MainWindow::select_Graphics(){
|
|
this->tempate_icon_select(iconGraphics,list_Graphics);
|
|
}
|
|
void MainWindow::select_Tools(){
|
|
this->tempate_icon_select(iconTools,list_Tools);
|
|
}
|
|
void MainWindow::select_Internet(){
|
|
this->tempate_icon_select(iconInternet,list_Internet);
|
|
}
|
|
void MainWindow::select_Multimedia(){
|
|
this->tempate_icon_select(iconMultimedia,list_Multimedia);
|
|
}
|
|
void MainWindow::select_Settings(){
|
|
this->tempate_icon_select(iconSettings,list_Settings);
|
|
}
|
|
void MainWindow::select_Education(){
|
|
this->tempate_icon_select(iconEducation,list_Education);
|
|
}
|
|
void MainWindow::select_Office(){
|
|
this->tempate_icon_select(iconOffice,list_Office);
|
|
}
|
|
void MainWindow::select_Other(){
|
|
this->tempate_icon_select(iconOther,list_Other);
|
|
}
|
|
void MainWindow::select_Development(){
|
|
this->tempate_icon_select(iconDevelopment,list_Development);
|
|
}
|
|
void MainWindow::select_System(){
|
|
this->tempate_icon_select(iconSystem,list_System);
|
|
}
|
|
void MainWindow::tempate_icon_select(Gtk::IconView *icon, Glib::RefPtr<Gtk::ListStore> >k_list){
|
|
auto selected = (*icon).get_selected_items();
|
|
|
|
if(!selected.empty())
|
|
{
|
|
this->unselect_icon(icon);
|
|
const Gtk::TreeModel::Path& path = *selected.begin();
|
|
Gtk::TreeModel::iterator iter = gtk_list->get_iter(path);
|
|
Gtk::TreeModel::Row row = *iter;
|
|
|
|
auto app_name_exec = row[m_Columns.app_name_exec];
|
|
const Glib::ustring description = row[m_Columns.m_col_description];
|
|
txtCmd->set_text(app_name_exec);
|
|
name_app = txtCmd->get_text();
|
|
int len_name_app = name_app.length();
|
|
string array_del[] = {"%f","%F","%d","%D","%n","%N"};
|
|
for (auto &del_sim: array_del){
|
|
str_remove(name_app, del_sim);
|
|
if (name_app.length()!=len_name_app){
|
|
txtCmd->set_text(name_app);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
void MainWindow::unselect_icon(Gtk::IconView *icon_entry){
|
|
for (Gtk::IconView* &icon : array_icon) {
|
|
|
|
if (icon_entry!=icon){
|
|
cout << "22222" << endl;
|
|
//icon->unselect_all();
|
|
}
|
|
else{
|
|
cout << "11111" << endl;
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::settings(){
|
|
this->pars_apps();
|
|
this->get_builder();
|
|
this->event();
|
|
this->localization();
|
|
this->add_CSS();
|
|
spinPriority->set_range(0,19);
|
|
spinPriority->set_increments(1.0,-1.0);
|
|
scalePriority->set_range(0,19);
|
|
scalePriority->set_value(0);
|
|
lblTimeEpriorityLow->set_text("19 (Низкий)");
|
|
lblTime4EpriorityHigh->set_text("0 (Высокий)");
|
|
scalePriority->set_inverted(true);
|
|
this->pars_dir_bin();
|
|
this->pars_users();
|
|
this->activ_or_block_execute_epriority();
|
|
cmbUser->set_active(0);
|
|
cmbUser->set_sensitive(false);
|
|
lblInfoUserName->set_sensitive(false);
|
|
rbPkexec->set_sensitive(false);
|
|
rbSu->set_sensitive(false);
|
|
rbSudo->set_sensitive(false);
|
|
|
|
|
|
}
|
|
void MainWindow::close_entry_app(){
|
|
this->icon_clear();
|
|
dialogStartMenu->hide();
|
|
}
|
|
|
|
void MainWindow::start_menu_entry_app(){}
|
|
|
|
void MainWindow::message_gui_close(){
|
|
messageError->hide();
|
|
}
|
|
|
|
void MainWindow::activ_or_block_execute_epriority(){
|
|
bool flag = cbxExecuteEpriority->get_active();
|
|
scalePriority->set_sensitive(flag);
|
|
spinPriority->set_sensitive(flag);
|
|
lblInfoNooPriority->set_sensitive(flag);
|
|
lblTimeEpriorityLow->set_sensitive(flag);
|
|
lblTime4EpriorityHigh->set_sensitive(flag);
|
|
}
|
|
|
|
void MainWindow::open_filemaneg(){
|
|
wndChooseFileWallpaper->show();
|
|
}
|
|
void MainWindow::close_filemaneg(){
|
|
wndChooseFileWallpaper->hide();
|
|
}
|
|
void MainWindow::get_path_filemaneg(){
|
|
path_file = wndChooseFileWallpaper->get_filename();
|
|
if (path_file.length()==0){}
|
|
else{
|
|
txtCmd->set_text(path_file);
|
|
this->close_filemaneg();
|
|
}
|
|
}
|
|
|
|
void MainWindow::tempalte_row(string Name, string Exec, string path , Glib::RefPtr<Gtk::ListStore> &dtk_list){
|
|
Gtk::TreeModel::Row row = *(dtk_list->append());
|
|
row[m_Columns.m_col_filename] = path;
|
|
row[m_Columns.m_col_description] = Name;
|
|
row[m_Columns.app_name_exec] = Exec;
|
|
if (std::ifstream(path)){
|
|
row[m_Columns.m_col_pixbuf] = Gdk::Pixbuf::create_from_file(path);
|
|
}
|
|
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(){
|
|
this->template_apps_obj(iconGraphics, list_Graphics);
|
|
|
|
this->template_apps_obj(iconTools, list_Tools);
|
|
this->template_apps_obj(iconInternet, list_Internet);
|
|
this->template_apps_obj(iconMultimedia, list_Multimedia);
|
|
this->template_apps_obj(iconSettings, list_Settings);
|
|
this->template_apps_obj(iconEducation, list_Education);
|
|
this->template_apps_obj(iconOffice, list_Office);
|
|
this->template_apps_obj(iconOther, list_Other);
|
|
this->template_apps_obj(iconDevelopment, list_Development);
|
|
this->template_apps_obj(iconSystem, list_System);
|
|
string path = "";
|
|
for ( const auto &st_app : list_app){
|
|
for ( const auto &str_categor : st_app.Categories){
|
|
path = "/usr/share/icons/hicolor/16x16/apps/" + st_app.Icon + ".png";
|
|
if (str_categor=="Graphics"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path, list_Graphics);
|
|
}
|
|
else if (str_categor=="Utility"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path, list_Tools);
|
|
}
|
|
else if (str_categor=="Network"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path,list_Internet);
|
|
}
|
|
else if (str_categor== "AudioVideo"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path, list_Multimedia);
|
|
}
|
|
else if (str_categor=="Settings"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path, list_Settings);
|
|
}
|
|
else if (str_categor=="Education"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path, list_Education);
|
|
}
|
|
else if (str_categor=="Office"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path, list_Office);
|
|
}
|
|
else if (str_categor=="Other"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path, list_Other);
|
|
}
|
|
else if (str_categor=="Development"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path, list_Development);
|
|
}
|
|
else if (str_categor=="System"){
|
|
this->tempalte_row(st_app.Name,st_app.Exec, path, list_System);
|
|
}
|
|
|
|
}
|
|
}
|
|
dialogStartMenu->show_all();
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::start_cmd(){
|
|
//txtCmd->set_text("");
|
|
string str_cmd_terminal="";
|
|
string str_variants_root = "";
|
|
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 (geteuid()!=0){
|
|
chbTerminal->set_active(true);
|
|
}
|
|
if (rbPkexec->get_active()){
|
|
|
|
if ((chbAnotherUser->get_active()) && (cmbUser->get_active_text().length()==0)) {
|
|
str_variants_root = "pkexec env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY ";
|
|
//this->tmp_desktop(user_cmd);
|
|
|
|
}
|
|
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 env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY ";
|
|
//this->tmp_desktop(user_cmd);
|
|
//user_cmd = "/tmp/" + user_cmd + ".desktop";
|
|
}
|
|
}
|
|
else if (rbSu->get_active()){
|
|
if ((chbAnotherUser->get_active()) && (cmbUser->get_active_text().length()==0)) {
|
|
str_variants_root="su ";
|
|
}
|
|
else if (chbAnotherUser->get_active()){
|
|
str_variants_root="su --user " + cmbUser->get_active_text() + " ";
|
|
}
|
|
else{
|
|
str_variants_root="su" ;
|
|
}
|
|
}
|
|
else if (rbSudo->get_active()){
|
|
if ((chbAnotherUser->get_active()) && (cmbUser->get_active_text().length()==0)) {
|
|
str_variants_root="sudo ";
|
|
}
|
|
else if (chbAnotherUser->get_active()){
|
|
str_variants_root="sudo --user " + cmbUser->get_active_text() + " ";
|
|
}
|
|
else{
|
|
str_variants_root="sudo ";
|
|
}
|
|
}
|
|
}
|
|
if (cbxExecuteEpriority->get_active()){
|
|
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->show();
|
|
return;
|
|
}
|
|
|
|
if (chbTerminal->get_active()){
|
|
str_cmd_terminal=" xterm -e ";
|
|
}
|
|
else{
|
|
str_cmd_terminal="";
|
|
}
|
|
string cmd = "";
|
|
if (path_file!=""){
|
|
cmd = "" + str_cmd_terminal + str_variants_root + str_nice_cmd + " xdg-open '" + path_file + "' ";
|
|
//cmd = format_cmd(str_cmd_terminal,str_variants_root,str_nice_cmd,path_file, cmd);
|
|
}
|
|
else if (name_app!=""){
|
|
cmd = "" + str_cmd_terminal + str_variants_root + str_nice_cmd + name_app;
|
|
//cmd = format_cmd(str_cmd_terminal,str_variants_root,str_nice_cmd,path_file, cmd);
|
|
}
|
|
else{
|
|
user_cmd = this->str_remove(user_cmd,str_cmd_terminal);
|
|
user_cmd = this->str_remove(user_cmd,str_variants_root);
|
|
user_cmd = this->str_remove(user_cmd,str_nice_cmd);
|
|
string amp = " &";
|
|
user_cmd = this->str_remove(user_cmd, amp);
|
|
cmd = "" + str_cmd_terminal + str_variants_root + str_nice_cmd + user_cmd;
|
|
//cmd = format_cmd(str_cmd_terminal,str_variants_root,str_nice_cmd,path_file, cmd);
|
|
}
|
|
txtCmd->set_text(cmd);
|
|
cmd=cmd+ " &";
|
|
system(cmd.c_str());
|
|
|
|
path_file_name="";
|
|
path_file="";
|
|
name_app="";
|
|
}
|
|
|
|
|
|
void MainWindow::changed_user(){
|
|
Glib::ustring entry_user = cmbUser->get_active_text();
|
|
if (geteuid()==0 || entry_user == "root"){
|
|
spinPriority->set_range(-20,19);
|
|
spinPriority->set_increments(1.0,-1.0);
|
|
scalePriority->set_range(-20,19);
|
|
scalePriority->set_value(0);
|
|
lblTimeEpriorityLow->set_text("19 (Низкий)");
|
|
lblTime4EpriorityHigh->set_text("-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("19 (Низкий)");
|
|
lblTime4EpriorityHigh->set_text("0 (Высокий)");
|
|
}
|
|
}
|
|
//void MainWindow::execute_terminal(){}
|
|
//void MainWindow::execute_another_User(){}
|
|
void MainWindow::activ_or_block_other_user(){
|
|
bool flag = chbAnotherUser->get_active();
|
|
cmbUser->set_active(0);
|
|
cmbUser->set_sensitive(flag);
|
|
lblInfoUserName->set_sensitive(flag);
|
|
//lblInfoUserOther->set_sensitive(flag);
|
|
|
|
if (flag_pkexec==true){
|
|
rbPkexec->set_sensitive(flag);
|
|
}
|
|
if (flag_su==true){
|
|
rbSu->set_sensitive(flag);
|
|
}
|
|
if (flag_sudo==true){
|
|
rbSudo->set_sensitive(flag);
|
|
}
|
|
}
|
|
void MainWindow::change_scale_priority(){
|
|
scalePriority->set_value(spinPriority->get_value_as_int());
|
|
}
|
|
void MainWindow::change_spin_priority(){
|
|
spinPriority->set_value(scalePriority->get_value());
|
|
}
|
|
void MainWindow::pars_dir_bin(){
|
|
namespace fs = std::filesystem;
|
|
std::string path = "/bin";
|
|
string file_name = "";
|
|
for (const auto & entry : fs::directory_iterator(path)){
|
|
file_name = entry.path().filename().string();
|
|
if (file_name=="su"){
|
|
flag_su=true;
|
|
}
|
|
else if (file_name=="sudo"){
|
|
flag_sudo=true;
|
|
}
|
|
else if (file_name=="pkexec"){
|
|
flag_pkexec=true;
|
|
}
|
|
}
|
|
rbPkexec->set_sensitive(flag_pkexec);
|
|
rbSu->set_sensitive(flag_su);
|
|
rbSudo->set_sensitive(flag_sudo);
|
|
}
|
|
void MainWindow::pars_users(){
|
|
while (true) {
|
|
errno = 0; // so we can distinguish errors from no more entries
|
|
passwd* entry = getpwent();
|
|
if (!entry) {
|
|
if (errno) {
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (entry->pw_uid>=1000 && entry->pw_uid!=65534){
|
|
cmbUser->append(entry->pw_name);
|
|
}
|
|
}
|
|
|
|
cmbUser->append("root");
|
|
endpwent();
|
|
}
|
|
|
|
vector<std::string> MainWindow::split(const std::string &s, char delim) {
|
|
std::stringstream ss(s);
|
|
std::string item;
|
|
std::vector<std::string> elems;
|
|
while (std::getline(ss, item, delim)) {
|
|
elems.push_back(item);
|
|
// elems.push_back(std::move(item)); // if C++11 (based on comment from @mchiasson)
|
|
}
|
|
return elems;
|
|
}
|
|
|
|
string MainWindow::str_remove(std::string& source, const std::string& to_remove){
|
|
auto begin = source.find(to_remove);
|
|
if (begin!=std::string::npos){
|
|
int len_to_remove = to_remove.length();
|
|
source.erase(begin, begin+len_to_remove);
|
|
}
|
|
return source;
|
|
}
|
|
|
|
void MainWindow::pars_apps(){
|
|
if (list_app.size()!=0){return;}
|
|
namespace fs = std::filesystem;
|
|
struct struct_App App;
|
|
string file_name = "";
|
|
string str_Categories;
|
|
string path = "/usr/share/applications/";
|
|
for (const auto & entry : fs::directory_iterator(path)){
|
|
file_name = entry.path().filename().string();
|
|
path = "/usr/share/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);
|
|
char *Type=g_key_file_get_string(gfile,"Desktop Entry", "Type",NULL);
|
|
char *Name=g_key_file_get_locale_string(gfile,"Desktop Entry","Name",setlocale(LC_ALL,NULL),NULL);
|
|
char *Exec=g_key_file_get_string(gfile,"Desktop Entry", "Exec",NULL);
|
|
char *Categories=g_key_file_get_locale_string(gfile,"Desktop Entry", "Categories",setlocale(LC_ALL,""),NULL);
|
|
char *Icon=g_key_file_get_string(gfile,"Desktop Entry", "Icon",NULL);
|
|
char *Mime=g_key_file_get_string(gfile,"Desktop Entry", "MimeType",NULL);
|
|
if (Type==NULL) continue;
|
|
if (Name==NULL) continue;
|
|
if (Exec==NULL) continue;
|
|
if (Categories==NULL) continue;
|
|
if (Icon==NULL) continue;
|
|
str_Categories = Categories;
|
|
App.Name = Name;
|
|
App.Type = Type;
|
|
App.Exec = Exec;
|
|
App.Icon = Icon;
|
|
if (Mime!=NULL){
|
|
App.MimeType = Mime;
|
|
}
|
|
else{
|
|
App.MimeType = "";
|
|
}
|
|
App.Name_desktop = file_name;
|
|
App.Categories = split(str_Categories, ';');
|
|
for ( const auto &text : App.Categories){
|
|
set_categories.insert(text);
|
|
|
|
}
|
|
|
|
}
|
|
list_app.push_back(App);
|
|
}
|
|
}
|
|
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();
|
|
}
|
|
|
|
|
|
|
|
|
|
|