diff --git a/.gitignore b/.gitignore index 3716db2..e4c2d7b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ ublexec.glade~ +#ublexec.glade# test.cpp .vscode -ublexec \ No newline at end of file +ublexec +nohup.out \ No newline at end of file diff --git a/Makefile b/Makefile index 69aebbf..178739f 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,11 @@ all: init build init: @echo "Initialize ..."; \ + version="$$(cat VERSION.md)"; \ + version=$${version:8}; \ + search="s/string version_application.*$&"; \ + replace="string version_application = \"$${version}\";"; \ + sed -i -e "$$search/$$replace/gi" source/ublexec.h; \ echo "-- Build path: ${CMAKE_BUILD_DIR}" depend: diff --git a/VERSION.md b/VERSION.md new file mode 100644 index 0000000..12ebd01 --- /dev/null +++ b/VERSION.md @@ -0,0 +1 @@ +VERSION 1.0 diff --git a/screenshot/screenshot.png b/screenshot/screenshot.png index 1b575f2..f2c3476 100644 Binary files a/screenshot/screenshot.png and b/screenshot/screenshot.png differ diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 82357c3..543d234 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -17,7 +17,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(SOURCE_FILES main.cc ublexec.cc - ublexec.h) + ublexec.h + ubl-util-standard.h + ubl-util-standard.c) set(LIBRARIES ${GTK_LIBRARIES} diff --git a/source/main.cc b/source/main.cc old mode 100644 new mode 100755 index 0995b90..dea0329 --- a/source/main.cc +++ b/source/main.cc @@ -1,21 +1,6 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "ublexec.h" - - - int main(int argc, char** argv) { @@ -30,6 +15,7 @@ int main(int argc, char** argv) } auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example.plug"); auto builder = Gtk::Builder::create_from_file(path_glade); + setlocale(LC_ALL, ""); bindtextdomain("ublexec", "/usr/share/locale/"); bind_textdomain_codeset("ublexec", "UTF-8"); textdomain("ublexec"); @@ -65,4 +51,4 @@ int main(int argc, char** argv) return r; } -} +} \ No newline at end of file diff --git a/source/ubl-util-standard.c b/source/ubl-util-standard.c new file mode 100644 index 0000000..8cff122 --- /dev/null +++ b/source/ubl-util-standard.c @@ -0,0 +1,69 @@ +#include "ubl-util-standard.h" +#ifndef __cplusplus +#ifndef UBL_GET_STANDARD_UI +#define UBL_GET_STANDARD_UI + + +inline returnstruct *ubl_make_plugs(GtkWidget *LeftWidget, GtkWidget *RightWidget, int left_plug_id, int right_plug_id){ + returnstruct *ret=(returnstruct*)malloc(sizeof(returnstruct*)); + if (left_plug_id>0&&LeftWidget){ + GtkWidget *plug=gtk_plug_new(left_plug_id); + GtkWidget *toplug=LeftWidget; + if (gtk_widget_get_parent(GTK_WIDGET(toplug))){ + g_object_ref(G_OBJECT(toplug)); + GtkWidget *parent=gtk_widget_get_parent(toplug); + gtk_container_remove(GTK_CONTAINER(parent),toplug); + gtk_container_add(GTK_CONTAINER(plug),GTK_WIDGET(toplug)); + } else + gtk_container_add(GTK_CONTAINER(plug),GTK_WIDGET(toplug)); + gtk_widget_show(GTK_WIDGET(plug)); + ret->plugLeft=plug; + } + if (right_plug_id>0&&RightWidget){ + GtkWidget *plug=gtk_plug_new(right_plug_id); + GtkWidget *toplug=RightWidget; + if (gtk_widget_get_parent(GTK_WIDGET(toplug))){ + g_object_ref(G_OBJECT(toplug)); + GtkWidget *parent=gtk_widget_get_parent(toplug); + gtk_container_remove(GTK_CONTAINER(parent),toplug); + gtk_container_add(GTK_CONTAINER(plug),GTK_WIDGET(toplug)); + } else + gtk_container_add(GTK_CONTAINER(plug),GTK_WIDGET(toplug)); + gtk_widget_show(GTK_WIDGET(plug)); + ret->plugRight=plug; + } + return ret; +} + +#endif + +#else + + +inline void ubl_make_plugs(Gtk::Widget *LeftWidget, Gtk::Widget *RightWidget, int left_plug_id, int right_plug_id){ + if (left_plug_id>0&&LeftWidget){ + GtkWidget *plug=gtk_plug_new(left_plug_id); + GtkWidget *toplug=GTK_WIDGET(LeftWidget->gobj()); + if (gtk_widget_get_parent(GTK_WIDGET(toplug))){ + g_object_ref(G_OBJECT(toplug)); + GtkWidget *parent=gtk_widget_get_parent(toplug); + gtk_container_remove(GTK_CONTAINER(parent),toplug); + gtk_container_add(GTK_CONTAINER(plug),GTK_WIDGET(toplug)); + } else + gtk_container_add(GTK_CONTAINER(plug),GTK_WIDGET(toplug)); + gtk_widget_show(GTK_WIDGET(plug)); + } + if (right_plug_id>0&&RightWidget){ + GtkWidget *plug=gtk_plug_new(right_plug_id); + GtkWidget *toplug=GTK_WIDGET(RightWidget->gobj()); + if (gtk_widget_get_parent(GTK_WIDGET(toplug))){ + g_object_ref(G_OBJECT(toplug)); + GtkWidget *parent=gtk_widget_get_parent(toplug); + gtk_container_remove(GTK_CONTAINER(parent),toplug); + gtk_container_add(GTK_CONTAINER(plug),GTK_WIDGET(toplug)); + } else + gtk_container_add(GTK_CONTAINER(plug),GTK_WIDGET(toplug)); + gtk_widget_show(GTK_WIDGET(plug)); + } +} +#endif \ No newline at end of file diff --git a/source/ubl-util-standard.h b/source/ubl-util-standard.h new file mode 100644 index 0000000..3209625 --- /dev/null +++ b/source/ubl-util-standard.h @@ -0,0 +1,20 @@ +#ifndef __cplusplus +#include +#include + +typedef struct { + GtkWidget *plugLeft; + GtkWidget *plugRight; + + +} returnstruct; +static returnstruct *ubl_make_plugs(GtkWidget *LeftWidget, GtkWidget *RightWidget, int left_plug_id, int right_plug_id); +#else +#include +#include +#include +#include + + +static void ubl_make_plugs(Gtk::Widget *LeftWidget, Gtk::Widget *RightWidget, int left_plug_id, int right_plug_id); +#endif \ No newline at end of file diff --git a/source/ublexec.cc b/source/ublexec.cc index 10eb8dc..11fa404 100644 --- a/source/ublexec.cc +++ b/source/ublexec.cc @@ -1,40 +1,31 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #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 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) : 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"); + + 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(socketExtId, socket_ext_id_I); + add_entry(socketTrdId, socket_trd_id_I); } ::Window CmdArgParser::GetSocketID() const{ return m_socketID; @@ -88,7 +79,6 @@ void MainWindow::get_builder(){ builder->get_widget("lblInfoNooPriority", lblInfoNooPriority); builder->get_widget("lblInfoExec", lblInfoExec); builder->get_widget("lblInfoPriority", lblInfoPriority); - builder->get_widget("lblInfoEnterProg", lblInfoEnterProg); builder->get_widget("boxColor", boxColor); builder->get_widget("lblGraphics", lblGraphics); builder->get_widget("lblTools", lblTools); @@ -110,6 +100,12 @@ void MainWindow::get_builder(){ builder->get_widget("iconDevelopment", iconDevelopment); builder->get_widget("iconSystem", iconSystem); 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(){ @@ -125,18 +121,14 @@ void MainWindow::set_icon_array(){ array_icon[9]=this->iconSystem; } - void MainWindow::template_apps_obj(Gtk::IconView *icon, Glib::RefPtr >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_text_column(m_Columns.m_col_description); } - void MainWindow::add_CSS(){ - Glib::RefPtr cssProvider = Gtk::CssProvider::create(); cssProvider->load_from_path(path_css); Glib::RefPtr styleContext = Gtk::StyleContext::create(); @@ -146,44 +138,48 @@ void MainWindow::add_CSS(){ Glib::RefPtr 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("Selecting Programs")); - lblInfoHead->set_text(gettext("Running applications as a user with a\nspecified 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")); + aboutWindows->set_website(_("https://wiki.ublinux.com")); + btnSynopsis->set_label(_("Help")); + btnAbout->set_label(_("About the program")); + aboutWindows->set_comments(_("ublexec")); + aboutWindows->set_website_label(_("Project Home Page")); + aboutWindows->set_version(_(version_application.c_str())); + lblHeaderName->set_text(_("ublexec")); + this->set_title(_("ublexec")); + btnStart->set_label(_("Run")); + wndChooseFileWallpaper->set_title(_("Please select File")); + dialogStartMenu->set_title(_("Selecting Programs")); + lblInfoHead->set_text(_("Running applications as a user with a\nspecified priority")); + lblinfoCmd->set_text(_("Command Line")); + lblInfoTime->set_text(_("Team")); + labInfoExecutTerm->set_text(_("Run in the terminal emulator")); + lblInfoUser->set_text(_("User")); + lblInfoUserOther->set_text(_("Run as another user")); + lblInfoUserName->set_text(_("User Name")); + lblInfoNooPriority->set_text(_("Priority")); + lblInfoExec->set_text(_("Change startup priority")); + lblInfoPriority->set_text(_("Priority")); + lblMessageError->set_text(_("Select an executable file or program")); + lblGraphics->set_text(_("Graphics")); + lblTools->set_text(_("Tools")); + lblInternet->set_text(_("Internet")); + 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(){ 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)); + btnStart->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::entry_app)); + chbTerminal->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::denamic_cmd)); 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)); @@ -204,6 +200,43 @@ void MainWindow::event(){ 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)); + 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(){ @@ -213,7 +246,6 @@ void MainWindow::icon_clear(){ list_Multimedia->clear(); list_Settings->clear(); list_Education->clear(); - list_Graphics->clear(); list_Office->clear(); list_Other->clear(); list_Development->clear(); @@ -266,6 +298,9 @@ void MainWindow::tempate_icon_select(Gtk::IconView *icon, Glib::RefPtrset_text(app_name_exec); name_app = txtCmd->get_text(); int len_name_app = name_app.length(); @@ -312,18 +347,13 @@ void MainWindow::settings(){ rbPkexec->set_sensitive(false); rbSu->set_sensitive(false); rbSudo->set_sensitive(false); + btnBoxAboutDialog->set_visible(false); + Gtk::Widget *boxAbout; + builder->get_widget("boxAbout",boxAbout); - //Gtk::Widget *standartHead; - //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); - -} + ubl_make_plugs(boxAbout,boxAbout, 0, socket_trd_id_I); + +} void MainWindow::close_entry_app(){ this->icon_clear(); dialogStartMenu->hide(); @@ -342,6 +372,7 @@ void MainWindow::activ_or_block_execute_epriority(){ lblInfoNooPriority->set_sensitive(flag); lblTimeEpriorityLow->set_sensitive(flag); lblTime4EpriorityHigh->set_sensitive(flag); + this->denamic_cmd(); } void MainWindow::open_filemaneg(){ @@ -353,26 +384,26 @@ void MainWindow::close_filemaneg(){ } void MainWindow::get_path_filemaneg(){ + name_app = ""; + user_cmd = ""; path_file = wndChooseFileWallpaper->get_filename(); - if (path_file.length()==0){} + if (path_file.length() == 0){} else{ txtCmd->set_text(path_file); this->close_filemaneg(); + } + this->denamic_cmd(); } void MainWindow::tempalte_row(string Name, string Exec, string path , Glib::RefPtr &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.icon_name] = path; 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); - } + row[m_Columns.float_h_align] = 0.5; + row[m_Columns.float_w_align] = 0.5; } void MainWindow::open_list_app(){ @@ -389,7 +420,7 @@ void MainWindow::open_list_app(){ 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"; + path = st_app.Icon; if (str_categor=="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"){ this->tempalte_row(st_app.Name,st_app.Exec, path, list_System); } - } } dialogStartMenu->show_all(); } -void MainWindow::start_cmd(){ +string MainWindow::start_cmd(string user_cmd){ 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 --user ${USER} env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY "; - - } - 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 = " pkexec --user " + cmbUser->get_active_text(); + if (cbxExecuteEpriority->get_active()){ + str_variants_root += " nice -n " + to_string(spinPriority->get_value_as_int()); } + str_variants_root += " env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY "; } 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() + " "; + chbTerminal->set_active(true); + string str_user = cmbUser->get_active_text(); + if (str_user!="root"){ + str_variants_root = "su -l " + cmbUser->get_active_text(); } 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()){ - if ((chbAnotherUser->get_active()) && (cmbUser->get_active_text().length()==0)) { + chbTerminal->set_active(true); + if (getlogin()==cmbUser->get_active_text()){ str_variants_root="sudo "; } - else if (chbAnotherUser->get_active()){ - str_variants_root="sudo --user " + cmbUser->get_active_text() + " "; - } 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()){ - str_nice_cmd = "nice -n " + to_string(spinPriority->get_value_as_int()) + " "; + if (cmbUser->get_active_text().length()!=0){ + 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){ messageError->show(); - return; + return ""; } - if (chbTerminal->get_active()){ - str_cmd_terminal=" xterm -e "; + if (chbTerminal->get_active() == true){ + str_cmd_terminal = "xterm -e "; } else{ - str_cmd_terminal=""; + str_cmd_terminal = ""; } + string cmd = ""; - if (path_file!=""){ - cmd = str_nice_cmd + " nohup " + str_cmd_terminal + str_variants_root + " xdg-open '" + path_file + "' "; + if (path_file.length()>0){ + 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!=""){ - cmd = str_nice_cmd + " nohup " + str_cmd_terminal + str_variants_root + name_app; + if (cmd.find("-e su ")!=string::npos){ + 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{ - 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 str_del = "xterm -e"; - user_cmd = this->str_remove(user_cmd, str_del); - str_del = "nohup"; - user_cmd = this->str_remove(user_cmd, str_del); - str_del = "pkexec --user superadmin env PATH=$PATH DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY"; - 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); + if (user_cmd.length() != 0){ + txtCmd->set_text(this->start_cmd(user_cmd)); + } + else if (path_file.length() != 0){ + txtCmd->set_text(this->start_cmd(user_cmd)); + } + else if (name_app.length() != 0){ + txtCmd->set_text(this->start_cmd(user_cmd)); } - 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){ - system(cmd.c_str()); +bool MainWindow::focus_out_txt_cmd(GdkEventFocus* event){ + 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(){ @@ -559,23 +614,26 @@ void MainWindow::activ_or_block_other_user(){ cmbUser->set_active(0); cmbUser->set_sensitive(flag); lblInfoUserName->set_sensitive(flag); - if (flag_pkexec==true){ + if (flag_pkexec == true){ rbPkexec->set_sensitive(flag); } - if (flag_su==true){ + if (flag_su == true){ rbSu->set_sensitive(flag); } - if (flag_sudo==true){ + if (flag_sudo == true){ rbSudo->set_sensitive(flag); } + this->denamic_cmd(); } void MainWindow::change_scale_priority(){ scalePriority->set_value(spinPriority->get_value_as_int()); + this->denamic_cmd(); } void MainWindow::change_spin_priority(){ spinPriority->set_value(scalePriority->get_value()); + this->denamic_cmd(); } void MainWindow::pars_dir_bin(){ @@ -585,13 +643,13 @@ void MainWindow::pars_dir_bin(){ for (const auto & entry : fs::directory_iterator(path)){ file_name = entry.path().filename().string(); if (file_name=="su"){ - flag_su=true; + flag_su = true; } else if (file_name=="sudo"){ - flag_sudo=true; + flag_sudo = true; } else if (file_name=="pkexec"){ - flag_pkexec=true; + flag_pkexec = true; } } rbPkexec->set_sensitive(flag_pkexec); @@ -610,7 +668,7 @@ void MainWindow::pars_users(){ break; } - if (entry->pw_uid>=1000 && entry->pw_uid!=65534){ + if (entry->pw_uid >= 1000 && entry->pw_uid!=65534){ cmbUser->append(entry->pw_name); } } @@ -628,13 +686,12 @@ vector MainWindow::split(const std::string &s, char delim) { 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::str_remove(std::string& source, std::string & to_remove){ + string::size_type n = to_remove.length(); + for (string::size_type i = source.find(to_remove); + i != string::npos; + i = source.find(to_remove)) + source.erase(i, n); } void MainWindow::pars_apps(){ diff --git a/source/ublexec.h b/source/ublexec.h index a06c417..5f34098 100644 --- a/source/ublexec.h +++ b/source/ublexec.h @@ -1,15 +1,21 @@ - -#include +#include +#include +#include +#include #include +#include +#include #include +#include #include -#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include "ubl-util-standard.c" using namespace std; @@ -17,6 +23,8 @@ extern string path_app; extern string app_name; extern string path_glade; extern string path_css; +extern int socket_ext_id_I; +extern int socket_trd_id_I; void me_thread(string cmd); class CmdArgParser : public Glib::OptionGroup { @@ -47,9 +55,10 @@ public: void close_filemaneg(); void get_path_filemaneg(); void open_list_app(); - void start_cmd(); + string start_cmd(string user_cmd); + void call_app(string &cmd); void changed_user(); - void execute_terminal(){} + void entry_app(); void execute_another_User(){} void activ_or_block_other_user(); void change_scale_priority(); @@ -74,9 +83,13 @@ public: void select_System(); void icon_clear(); void set_icon_array(); - //static void me_thread(string cmd); + void delete_cmd(const int &x,const int &y); + void synopsis_show(); + void denamic_cmd(); + bool focus_out_txt_cmd(GdkEventFocus* event); + bool focus_in_txt_cmd(GdkEventFocus* event); void unselect_icon(Gtk::IconView *icon_entry); - string str_remove(std::string& source, const std::string& to_remove); + void str_remove(std::string& source, std::string & to_remove); vector split(const std::string &s, char delim); public: class ModelColumns : public Gtk::TreeModel::ColumnRecord @@ -88,12 +101,18 @@ public: 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 m_col_filename; + Gtk::TreeModelColumn icon_name; Gtk::TreeModelColumn m_col_description; Gtk::TreeModelColumn app_name_exec; Gtk::TreeModelColumn > m_col_pixbuf; + Gtk::TreeModelColumn float_h_align; + Gtk::TreeModelColumn float_w_align; }; ModelColumns m_Columns; public: @@ -135,7 +154,6 @@ public: Gtk::Label *lblInfoNooPriority; Gtk::Label *lblInfoExec; Gtk::Label *lblInfoPriority; - Gtk::Label *lblInfoEnterProg; Gtk::Label *lblGraphics; Gtk::Label *lblTools; @@ -147,6 +165,7 @@ public: Gtk::Label *lblOther; Gtk::Label *lblDevelopment; Gtk::Label *lblSystem; + Gtk::Label *lblHeaderName; Gtk::IconView *iconGraphics; Gtk::IconView *iconTools; @@ -159,6 +178,11 @@ public: Gtk::IconView *iconDevelopment; Gtk::IconView *iconSystem; Gtk::IconView *iconEntry; + Gtk::MenuItem *btnAbout; + Gtk::MenuItem *btnSynopsis; + Gtk::AboutDialog *aboutWindows; + Gtk::MenuButton *btnSettings; + Gtk::ButtonBox *btnBoxAboutDialog; Glib::RefPtr list_Graphics; Glib::RefPtr list_Tools; @@ -171,6 +195,12 @@ public: Glib::RefPtr list_Development; Glib::RefPtr list_System; public: + string version_application = "1.0"; + string cmd_old = ""; + string user_cmd=""; + string user_cmd_old=""; + string name_app_old=""; + string path_file_old=""; string execute_cmd = ""; string path_file = ""; string name_app = ""; diff --git a/style.css b/style.css index 41a96a0..0ea8eb1 100644 --- a/style.css +++ b/style.css @@ -4,4 +4,69 @@ .textHead{ text-shadow: 1px 1px #ffffff; } +.menuitemtop *{ + margin:2px 2px 0 2px; + padding: 5px 10px 3px 5px; +} +.menuitemmiddle *{ + margin:0 2px 0 2px; + padding: 3px 10px 3px 5px; +} +.menuitembottom *{ + margin:0 2px 2px 2px; + padding: 3px 10px 5px 5px; +} +.menuitemtop:hover { + border-radius:3px; + background:@theme_bg_color; +} +.menuitemmiddle:hover { + border-radius:3px; + background:@theme_bg_color; +} +.menuitembottom:hover { + border-radius:3px; + background:@theme_bg_color; + +} +.menuitemtop:hover* { + border-radius:3px; + margin:2px 2px 0 2px; + padding: 5px 10px 3px 5px; + background:@theme_selected_bg_color; + border-color:transparent; +} +.menuitemmiddle:hover* { + border-radius:3px; + margin:0 2px 0 2px; + padding: 3px 10px 3px 5px; + background:@theme_selected_bg_color; + border-color:transparent; +} +.menuitembottom:hover* { + border-radius:3px; + margin:0 2px 2px 2px; + padding: 3px 10px 5px 5px; + background:@theme_selected_bg_color; + border-color:transparent; +} +.menuitembottom{ + margin-top:0px; +} +.menuitemmiddle{ + margin-top:0px; + margin-bottom:0px; +} + +.menuitemtop{ + margin-bottom:0px; +} +.bkim{ + background-image: -gtk-gradient(linear, + left top, left bottom, + from(@entry_background_a), + color-stop(0.20, @entry_background_b), + color-stop(0.85, @entry_background_c), + to(@entry_background_d)); +} \ No newline at end of file diff --git a/ublexec.glade b/ublexec.glade index 6ecef10..09eb905 100644 --- a/ublexec.glade +++ b/ublexec.glade @@ -2,6 +2,58 @@ + + True + True + 6 + + + False + О Программе + False + True + center + ubl-settings-datetime + dialog + True + ublexec + 1.0 + Copyright © 2023 - UBSoft Software LLC + Setting the date and time + https://ublinux.ru/ + Project Home Page + Это приложение распространяется без каких-либо гарантий. +Подробнее в <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GNU General Public License, версии 2 или позднее</a>. + UBGroup + UBGroup + ublexec + True + gpl-2-0 + + + False + vertical + 2 + + + False + end + + + + + + False + False + 0 + + + + + + + + -20 19 @@ -9,26 +61,14 @@ 10 - 500 - 400 + 450 + 240 False True False vertical - - - True - False - Selecting Programs - - - False - True - 0 - - True @@ -36,6 +76,7 @@ in + True False 5 5 @@ -63,321 +104,768 @@ False vertical - - True - False - start - Graphics - - - False - True - 0 - - - - + True True - 1 - queue - 1 - 1 - 1 - - - - True - True - 1 - - - - - True - False - start - Tools + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 4 + 5 + + + + + False + True + 1 + + + + + + + True + False + Graphics + + False True - 2 + 1 - + True True - 1 - queue - 1 - 1 - 1 - - - - True - True - 3 - - - - - True - False - start - Internet + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + queue + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 5 + 4 + + + + + + False + True + 1 + + + + + + + True + False + Tools + + False True - 4 + 3 - + True True - 1 - queue - 1 - 1 - 1 - - - - True - True - 5 - - - - - True - False - start - Multimedia + 1 + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + queue + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 5 + 4 + + + + + + False + True + 1 + + + + + + + True + False + Internet + + False True - 6 + 5 - + True True - 1 - queue - 1 - 1 - 1 - - - - True - True - 7 - - - - - True - False - start - Settings + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + queue + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 5 + 4 + + + + + + False + True + 1 + + + + + + + True + False + Multimedia + + False True - 8 + 7 - + True True - 1 - queue - 1 - 1 - 1 - - - - True - True - 9 - - - - - True - False - start - Education + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + queue + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 5 + 4 + + + + + + False + True + 1 + + + + + + + True + False + Settings + + False True - 10 + 9 - + True True - 1 - queue - 1 - 1 - 1 - - - - True - True - 11 - - - - - True - False - start - Office + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + queue + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 5 + 4 + + + + + + False + True + 1 + + + + + + + True + False + Education + + False True - 12 + 11 - + True True - 1 - queue - 1 - 1 - 1 - - - - True - True - 13 - - - - - True - False - start - Other + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + queue + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 5 + 4 + + + + + + False + True + 1 + + + + + + + True + False + Office + + False True - 14 + 13 - + True True - 1 - queue - 1 - 1 - 1 - - - - True - True - 15 - - - - - True - False - start - Development + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + queue + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 5 + 4 + + + + + + False + True + 1 + + + + + + + True + False + Other + + False True - 16 + 15 - + True True - 1 - queue - 1 - 1 - 1 - - - - True - True - 17 - - - - - True - False - start - System + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + queue + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 5 + 4 + + + + + + False + True + 1 + + + + + + + True + False + Development + + False True - 18 + 17 - + True True - 1 - queue - 1 - 1 - 1 - + + + True + False + + + True + False + 7 + 7 + 7 + 7 + + + False + True + 0 + + + + + True + True + 1 + queue + horizontal + 1 + 350 + 1 + 1 + 1 + + + + 5 + 5 + 6 + 2 + + + + + + 5 + 4 + + + + + + False + True + 1 + + + + + + + True + False + System + + - True + False True 19 @@ -470,64 +958,57 @@ 6 gtk-media-play - +<<<<<<< HEAD +======= + + + + + + + + + + + + + + + + + + True False - Внимание! - dialog - - + False + False + 4 + dropdown-menu + + + True False - vertical - 2 - - - False - True - end - - - - - - ОК - True - True - True - - - True - True - 1 - - - - - False - False - 0 - - - - - True - False - 10 - 10 - 15 - Select an executable file or program - - - True - True - 2 - - + Synopsis + True + + + + + + True + False + About the program + True + +>>>>>>> devel False - UBConfig - ubexec True @@ -687,8 +1168,8 @@ specified priority 5 5 5 - 6 - 6 + 3 + 3 gtk-directory @@ -721,8 +1202,6 @@ specified priority 5 5 5 - 6 - 6 edit-select-all @@ -807,14 +1286,14 @@ specified priority - False + True True 0 - False + True True 1 @@ -1004,14 +1483,14 @@ specified priority - False + True True 0 - False + True True 2 @@ -1237,14 +1716,14 @@ specified priority - False + True True 0 - False + True True 3 @@ -1278,8 +1757,124 @@ specified priority + + True + True + 2 + + + + +<<<<<<< HEAD +======= + + + True + False + True + + + True + False + Ublexec + + + + + + + + True + False + 32 + ublexec + + + + + True + False + + + True + True + False + True + True + menu1 + none + + + True + False + open-menu-symbolic + + + + + False + True + 0 + + + + + end + 1 + + + + +>>>>>>> devel + + + False + Внимание! + dialog + + + False + vertical + 2 + + + False + True + end + + + + + + ОК + True + True + True + + + True + True + 1 + + + False + False + 0 + + + + + True + False + 10 + 10 + 15 + Select an executable file or program + + + True True 2 diff --git a/ublexec_ru.po b/ublexec_ru.po index 926e51a..5f16e42 100644 --- a/ublexec_ru.po +++ b/ublexec_ru.po @@ -6,6 +6,18 @@ msgid "" msgstr "" +msgid "https://wiki.ublinux.com" +msgstr "https://wiki.ublinux.ru" + +msgid "About the program" +msgstr "О программе" + +msgid "Help" +msgstr "Справка" + +msgid "Project Home Page" +msgstr "Домашняя страница проекта" + msgid "System" msgstr "Система"