Частично код приведён стандарту Стэнфордского университет

pull/12/head
Igor Belitskiy 3 years ago
parent 42e104243c
commit 881f9f08ec

@ -1,18 +1,11 @@
#include "ublexec.h" #include "ublexec.h"
int main(int argc, char** argv) int main(int argc, char** argv) {
{
string str_cmd_argv = ""; string str_cmd_argv = "";
for (int i=1; i<argc; i++){ for (int i=1; i<argc; i++){
str_cmd_argv += to_string(*argv[i]) + " "; str_cmd_argv += to_string(*argv[i]) + " ";
} }
if (geteuid()!=0){
//string cmd = "pkexec " + app_name + " " + str_cmd_argv;
//system(cmd.c_str());
//return 0;
}
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example.plug"); auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example.plug");
auto builder = Gtk::Builder::create_from_file(path_glade); auto builder = Gtk::Builder::create_from_file(path_glade);
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@ -23,7 +16,6 @@ int main(int argc, char** argv)
Glib::init(); Glib::init();
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
Glib::OptionContext context; Glib::OptionContext context;
CmdArgParser parser{ CmdArgParser parser{
"Socket ID", "Socket ID",
"Command line argument for socket ID communication.", "Command line argument for socket ID communication.",
@ -32,18 +24,13 @@ int main(int argc, char** argv)
context.set_main_group(parser); context.set_main_group(parser);
context.parse(argc, argv); context.parse(argc, argv);
::Window socketID = parser.GetSocketID(); ::Window socketID = parser.GetSocketID();
// Handle plug:
SettingsPlug plug{socketID, builder}; SettingsPlug plug{socketID, builder};
plug.show(); plug.show();
app->run(plug); app->run(plug);
return 0; return 0;
} }
else { else {
MainWindow* wnd = nullptr; MainWindow* wnd = nullptr;
builder->get_widget_derived("window", wnd); builder->get_widget_derived("window", wnd);
auto r = app->run(*wnd); auto r = app->run(*wnd);

@ -1,9 +1,9 @@
#include "ublexec.h" #include "ublexec.h"
using namespace std; using namespace std;
string path_app= "/usr/bin/"; const string path_app = "/usr/bin/";
string path_glade= "/usr/share/ublexec/ui/ublexec.glade"; const string path_glade = "/usr/share/ublexec/ui/ublexec.glade";
string path_css = "/usr/share/ublexec/css/style.css"; const string path_css = "/usr/share/ublexec/css/style.css";
string app_name = "ublexec"; const string app_name = "ublexec";
int socket_ext_id_I = 0; int socket_ext_id_I = 0;
int socket_trd_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)
@ -12,17 +12,14 @@ CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_descr
socketIDArg.set_long_name("socket-id"); socketIDArg.set_long_name("socket-id");
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; Glib::OptionEntry socketExtId;
socketExtId.set_long_name("socket-ext-id"); socketExtId.set_long_name("socket-ext-id");
socketExtId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketExtId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN);
socketExtId.set_description("Settings manager secondary socket"); socketExtId.set_description("Settings manager secondary socket");
Glib::OptionEntry socketTrdId; Glib::OptionEntry socketTrdId;
socketTrdId.set_long_name("socket-trd-id"); socketTrdId.set_long_name("socket-trd-id");
socketTrdId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketTrdId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN);
socketTrdId.set_description("Settings manager secondary socket"); 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(socketExtId, socket_ext_id_I);
add_entry(socketTrdId, socket_trd_id_I); add_entry(socketTrdId, socket_trd_id_I);
@ -208,6 +205,7 @@ void MainWindow::event(){
txtCmd->signal_focus_in_event().connect(sigc::mem_fun(*this, &MainWindow::focus_in_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)); txtCmd->signal_delete_text().connect(sigc::mem_fun(*this, &MainWindow::delete_cmd));
} }
void MainWindow::delete_cmd(const int &x, const int &y) { void MainWindow::delete_cmd(const int &x, const int &y) {
if (y > 1) { if (y > 1) {
chbTerminal->set_active(false); chbTerminal->set_active(false);
@ -219,13 +217,10 @@ void MainWindow::delete_cmd(const int &x,const int &y){
bool MainWindow::focus_in_txt_cmd(GdkEventFocus* event) { bool MainWindow::focus_in_txt_cmd(GdkEventFocus* event) {
if (user_cmd.length() != 0) { if (user_cmd.length() != 0) {
//user_cmd_old = user_cmd;gi
} }
else if (name_app.length() != 0) { else if (name_app.length() != 0) {
//name_app_old = name_app;
} }
else if (path_file.length() != 0) { else if (path_file.length() != 0) {
//path_file_old = path_file;
} }
else{ else{
user_cmd = txtCmd->get_text(); user_cmd = txtCmd->get_text();
@ -234,7 +229,6 @@ bool MainWindow::focus_in_txt_cmd(GdkEventFocus* event){
return true; return true;
} }
void MainWindow::synopsis_show() { void MainWindow::synopsis_show() {
system("xdg-open https://wiki.ublinux.ru/ru/home &"); system("xdg-open https://wiki.ublinux.ru/ru/home &");
} }
@ -289,8 +283,7 @@ void MainWindow::select_System(){
} }
void MainWindow::tempate_icon_select(Gtk::IconView *icon, Glib::RefPtr<Gtk::ListStore> &gtk_list) { void MainWindow::tempate_icon_select(Gtk::IconView *icon, Glib::RefPtr<Gtk::ListStore> &gtk_list) {
auto selected = (*icon).get_selected_items(); auto selected = (*icon).get_selected_items();
if(!selected.empty()) if(!selected.empty()) {
{
this->set_icon_array(); this->set_icon_array();
this->unselect_icon(icon); this->unselect_icon(icon);
const Gtk::TreeModel::Path& path = *selected.begin(); const Gtk::TreeModel::Path& path = *selected.begin();
@ -350,10 +343,9 @@ void MainWindow::settings(){
btnBoxAboutDialog->set_visible(false); btnBoxAboutDialog->set_visible(false);
Gtk::Widget *boxAbout; Gtk::Widget *boxAbout;
builder->get_widget("boxAbout",boxAbout); builder->get_widget("boxAbout",boxAbout);
ubl_make_plugs(boxAbout, boxAbout,0 , socket_trd_id_I); ubl_make_plugs(boxAbout, boxAbout,0 , socket_trd_id_I);
} }
void MainWindow::close_entry_app() { void MainWindow::close_entry_app() {
this->icon_clear(); this->icon_clear();
dialogStartMenu->hide(); dialogStartMenu->hide();
@ -481,7 +473,6 @@ string MainWindow::start_cmd(string user_cmd){
else{ else{
str_variants_root = "su "; str_variants_root = "su ";
} }
str_variants_root += + " -c \" DISPLAY=$DISPLAY "; str_variants_root += + " -c \" DISPLAY=$DISPLAY ";
if (cbxExecuteEpriority->get_active()) { if (cbxExecuteEpriority->get_active()) {
str_variants_root += "nice -n " + to_string(spinPriority->get_value_as_int()) + " "; str_variants_root += "nice -n " + to_string(spinPriority->get_value_as_int()) + " ";
@ -503,6 +494,7 @@ string MainWindow::start_cmd(string user_cmd){
if (cmbUser->get_active_text().length() != 0) { if (cmbUser->get_active_text().length() != 0) {
string user_cmd_X = "xhost +SI:localuser:"; string user_cmd_X = "xhost +SI:localuser:";
user_cmd_X += cmbUser->get_active_text(); user_cmd_X += cmbUser->get_active_text();
user_cmd_X += " > /dev/null 2>&1";
system(user_cmd_X.c_str()); system(user_cmd_X.c_str());
} }
if ((cbxExecuteEpriority->get_active()) && (chbAnotherUser->get_active() == false)) { if ((cbxExecuteEpriority->get_active()) && (chbAnotherUser->get_active() == false)) {
@ -512,14 +504,12 @@ string MainWindow::start_cmd(string user_cmd){
messageError->show(); messageError->show();
return ""; return "";
} }
if (chbTerminal->get_active() == true) { 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.length() > 0) { if (path_file.length() > 0) {
cmd = "nohup " + str_nice_cmd + 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 + "' ";
@ -534,7 +524,6 @@ string MainWindow::start_cmd(string user_cmd){
cmd+=" \""; cmd+=" \"";
} }
cmd += " > /dev/null 2>&1"; cmd += " > /dev/null 2>&1";
return cmd; return cmd;
} }
@ -583,7 +572,6 @@ bool MainWindow::focus_out_txt_cmd(GdkEventFocus* event){
void MainWindow::entry_app() { void MainWindow::entry_app() {
this->denamic_cmd(); this->denamic_cmd();
if (name_app.length() == 0 && path_file.length() == 0) { if (name_app.length() == 0 && path_file.length() == 0) {
} }
string cmd = txtCmd->get_text(); string cmd = txtCmd->get_text();
this->call_app(cmd); this->call_app(cmd);
@ -667,7 +655,6 @@ 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);
} }
@ -731,7 +718,6 @@ void MainWindow::pars_apps(){
} }
App.Name_desktop = file_name; App.Name_desktop = file_name;
App.Categories = split(str_Categories, ';'); App.Categories = split(str_Categories, ';');
} }
list_app.push_back(App); list_app.push_back(App);
} }

@ -19,10 +19,10 @@
using namespace std; using namespace std;
extern string path_app; extern const string path_app;
extern string app_name; extern const string app_name;
extern string path_glade; extern const string path_glade;
extern string path_css; extern const string path_css;
extern int socket_ext_id_I; extern int socket_ext_id_I;
extern int socket_trd_id_I; extern int socket_trd_id_I;
void me_thread(string cmd); void me_thread(string cmd);
@ -92,8 +92,7 @@ public:
void str_remove(std::string& source, std::string & to_remove); void str_remove(std::string& source, std::string & to_remove);
vector<std::string> split(const std::string &s, char delim); vector<std::string> split(const std::string &s, char delim);
public: public:
class ModelColumns : public Gtk::TreeModel::ColumnRecord class ModelColumns : public Gtk::TreeModel::ColumnRecord {
{
public: public:
ModelColumns() ModelColumns()
{ {
@ -154,7 +153,6 @@ public:
Gtk::Label *lblInfoNooPriority; Gtk::Label *lblInfoNooPriority;
Gtk::Label *lblInfoExec; Gtk::Label *lblInfoExec;
Gtk::Label *lblInfoPriority; Gtk::Label *lblInfoPriority;
Gtk::Label *lblGraphics; Gtk::Label *lblGraphics;
Gtk::Label *lblTools; Gtk::Label *lblTools;
Gtk::Label *lblInternet; Gtk::Label *lblInternet;
@ -166,7 +164,6 @@ public:
Gtk::Label *lblDevelopment; Gtk::Label *lblDevelopment;
Gtk::Label *lblSystem; Gtk::Label *lblSystem;
Gtk::Label *lblHeaderName; Gtk::Label *lblHeaderName;
Gtk::IconView *iconGraphics; Gtk::IconView *iconGraphics;
Gtk::IconView *iconTools; Gtk::IconView *iconTools;
Gtk::IconView *iconInternet; Gtk::IconView *iconInternet;
@ -183,7 +180,6 @@ public:
Gtk::AboutDialog *aboutWindows; Gtk::AboutDialog *aboutWindows;
Gtk::MenuButton *btnSettings; Gtk::MenuButton *btnSettings;
Gtk::ButtonBox *btnBoxAboutDialog; Gtk::ButtonBox *btnBoxAboutDialog;
Glib::RefPtr<Gtk::ListStore> list_Graphics; Glib::RefPtr<Gtk::ListStore> list_Graphics;
Glib::RefPtr<Gtk::ListStore> list_Tools; Glib::RefPtr<Gtk::ListStore> list_Tools;
Glib::RefPtr<Gtk::ListStore> list_Internet; Glib::RefPtr<Gtk::ListStore> list_Internet;
@ -215,13 +211,13 @@ public:
string Icon; string Icon;
string MimeType; string MimeType;
string Type; string Type;
vector<std::string> Categories;}; vector<std::string> Categories;
};
list <struct_App> list_app; list <struct_App> list_app;
set <string> set_categories; set <string> set_categories;
int index_exec_gui_apps = 0; int index_exec_gui_apps = 0;
Gtk::IconView* array_icon[10]; Gtk::IconView* array_icon[10];
}; };
class SettingsPlug : public Gtk::Plug{ class SettingsPlug : public Gtk::Plug{

Loading…
Cancel
Save