From bb2cc550bee2f687ef8b699b01be1227531a7008 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Fri, 3 Mar 2023 12:26:00 +0600 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B4=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8=D1=87=D0=B5?= =?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/ublexec.cc | 132 ++++++++++++++++++++++++++++++++-------------- source/ublexec.h | 13 ++++- style.css | 5 -- ublexec.glade | 42 +++++++++++---- 4 files changed, 134 insertions(+), 58 deletions(-) diff --git a/source/ublexec.cc b/source/ublexec.cc index 1348cc5..e768d0f 100644 --- a/source/ublexec.cc +++ b/source/ublexec.cc @@ -162,9 +162,8 @@ void MainWindow::localization(){ 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)); @@ -197,9 +196,32 @@ void MainWindow::event(){ }); rbSu->signal_toggled().connect(sigc::mem_fun(*this,&MainWindow::nice_hight)); rbPkexec->signal_toggled().connect(sigc::mem_fun(*this,&MainWindow::nice_hight)); + cmbUser->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::denamic_cmd)); + 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)); +} + +bool MainWindow::focus_in_txt_cmd(GdkEventFocus* event){ + if (user_cmd.length() != 0){ + //txtCmd->set_text(user_cmd); + } + else if (name_app.length() != 0){ + //txtCmd->set_text(name_app); + } + else if (path_file.length() != 0){ + //txtCmd->set_text(path_file); + } + else{ + user_cmd = txtCmd->get_text(); + //txtCmd->set_text(user_cmd); + } + cmd_old = txtCmd->get_text(); + return true; } void MainWindow::nice_hight(){ + Glib::ustring entry_user = cmbUser->get_active_text(); if (geteuid() != 0){ spinPriority->set_range(0,19); @@ -208,7 +230,8 @@ void MainWindow::nice_hight(){ scalePriority->set_value(0); lblTimeEpriorityLow->set_text("19 (Низкий)"); lblTime4EpriorityHigh->set_text("0 (Высокий)"); - } + } + this->denamic_cmd(); } @@ -275,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(); @@ -351,6 +377,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(){ @@ -362,6 +389,8 @@ void MainWindow::close_filemaneg(){ } void MainWindow::get_path_filemaneg(){ + name_app = ""; + user_cmd = ""; path_file = wndChooseFileWallpaper->get_filename(); if (path_file.length() == 0){} else{ @@ -437,14 +466,10 @@ void MainWindow::open_list_app(){ } -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); @@ -489,10 +514,10 @@ void MainWindow::start_cmd(){ } if (user_cmd.length()==0 && name_app.length()==0 && path_file.length()==0){ messageError->show(); - return; + return ""; } - if (chbTerminal->get_active()){ + if (chbTerminal->get_active() == true){ str_cmd_terminal = "xterm -e "; } else{ @@ -505,41 +530,65 @@ void MainWindow::start_cmd(){ else if (name_app!=""){ cmd = "nohup " + str_nice_cmd + str_cmd_terminal + str_variants_root + name_app; } - else{ - bool flag_xdg = false; - if (user_cmd.find("xdg-open")!=string::npos){ - flag_xdg=true; - } - string str_del = " "; - this->str_remove(user_cmd, str_del); - str_del = "\""; - this->str_remove(user_cmd, str_del); - vector vec_user_cmd = this->split(user_cmd, ' '); - size_t vec_len = vec_user_cmd.size(); - user_cmd = vec_user_cmd[vec_len-1]; - if (flag_xdg==false){ - cmd = "nohup " + str_nice_cmd + str_cmd_terminal + str_variants_root + user_cmd; - if (cmd.find("-e su ") != string::npos){ - cmd += "\""; - } - } - else{ - cmd = "nohup " + str_nice_cmd + str_cmd_terminal + str_variants_root + " xdg-open " + user_cmd ; - } + else if (user_cmd.length()>0){ + cmd = "nohup " + str_nice_cmd + str_cmd_terminal + str_variants_root + " " + user_cmd; + } + if (cmd.find("-e su ")!=string::npos){ + cmd+=" \""; } - - txtCmd->set_text(cmd); cmd += " > /dev/null 2>&1"; - std::thread t(&me_thread, cmd); - t.detach(); - path_file_name = ""; + + return cmd; +} + +void MainWindow::call_app(string &cmd){ path_file = ""; name_app = ""; - + 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{ + if (user_cmd.length() != 0){ + txtCmd->set_text(this->start_cmd(user_cmd)); + } + } + } -void me_thread(string cmd){ - system(cmd.c_str()); +bool MainWindow::focus_out_txt_cmd(GdkEventFocus* event){ + //this->focus_in_txt_cmd(event); + if (cmd_old!=txtCmd->get_text()){ + user_cmd = txtCmd->get_text(); + } + this->denamic_cmd(); + return true; +} + +void MainWindow::entry_app(){ + if (name_app.length()==0 && path_file.length()==0){ + + } + string cmd = txtCmd->get_text(); + this->call_app(cmd); } void MainWindow::changed_user(){ @@ -576,14 +625,17 @@ void MainWindow::activ_or_block_other_user(){ 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(){ diff --git a/source/ublexec.h b/source/ublexec.h index 5c00d9d..e52cd06 100644 --- a/source/ublexec.h +++ b/source/ublexec.h @@ -52,10 +52,11 @@ 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 entry_app(); void nice_hight(); - void execute_terminal(){} void execute_another_User(){} void activ_or_block_other_user(); void change_scale_priority(); @@ -81,6 +82,9 @@ public: void icon_clear(); void set_icon_array(); void synopsis_show(); + void denamic_cmd(); + bool focus_out_txt_cmd(GdkEventFocus* event); + bool focus_in_txt_cmd(GdkEventFocus* event); //static void me_thread(string cmd); void unselect_icon(Gtk::IconView *icon_entry); void str_remove(std::string& source, std::string & to_remove); @@ -187,6 +191,11 @@ public: Glib::RefPtr list_Development; Glib::RefPtr list_System; public: + 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 1e38d36..5b6b638 100644 --- a/style.css +++ b/style.css @@ -29,28 +29,24 @@ margin:2px 2px 0 2px; padding: 5px 10px 3px 5px; background:@theme_selected_bg_color; - border-radius:2px; border-color:transparent; } .menuitemmiddle:hover* { margin:0 2px 0 2px; padding: 3px 10px 3px 5px; background:@theme_selected_bg_color; - border-radius:2px; border-color:transparent; } .menuitembottom:hover* { margin:0 2px 2px 2px; padding: 3px 10px 5px 5px; background:@theme_selected_bg_color; - border-radius:2px; border-color:transparent; } .menuitembottom{ margin-top:0px; border-color:alpha(@theme_text_color, 0.4); border-style:solid; - border-radius:0 0 5px 5px; border-left-width:1px; border-bottom-width:1px; border-right-width:1px; @@ -68,7 +64,6 @@ margin-bottom:0px; border-color:alpha(@theme_text_color, 0.4); border-style:solid; - border-radius:5px 5px 0 0; border-left-width:1px; border-top-width:1px; border-right-width:1px; diff --git a/ublexec.glade b/ublexec.glade index d4a0946..ca9d7b6 100644 --- a/ublexec.glade +++ b/ublexec.glade @@ -133,7 +133,9 @@ 1 horizontal 1 - 120 + 350 + 1 + 1 1 @@ -204,7 +206,9 @@ queue horizontal 1 - 120 + 350 + 1 + 1 1 @@ -279,7 +283,9 @@ queue horizontal 1 - 120 + 350 + 1 + 1 1 @@ -353,7 +359,9 @@ queue horizontal 1 - 120 + 350 + 1 + 1 1 @@ -427,7 +435,9 @@ queue horizontal 1 - 120 + 350 + 1 + 1 1 @@ -497,11 +507,13 @@ True True - 6 + 1 queue horizontal 1 - 120 + 350 + 1 + 1 1 @@ -575,7 +587,9 @@ queue horizontal 1 - 120 + 350 + 1 + 1 1 @@ -649,7 +663,9 @@ queue horizontal 1 - 120 + 350 + 1 + 1 1 @@ -723,7 +739,9 @@ queue horizontal 1 - 120 + 350 + 1 + 1 1 @@ -797,7 +815,9 @@ queue horizontal 1 - 120 + 350 + 1 + 1 1