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.
307 lines
18 KiB
307 lines
18 KiB
#include "ublexec.h"
|
|
|
|
config main_config;
|
|
|
|
//functions
|
|
|
|
void on_file_chooser_open(GtkWidget *, main_window *widgets){
|
|
GtkWidget *dialog = gtk_file_chooser_dialog_new(TITLE_LABEL,NULL,GTK_FILE_CHOOSER_ACTION_OPEN,CANCEL_LABEL,GTK_RESPONSE_CANCEL,OPEN_LABEL,GTK_RESPONSE_ACCEPT,NULL);
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),"/usr/bin/");
|
|
gtk_window_set_icon_name(GTK_WINDOW(dialog),icon_path);
|
|
|
|
int res = gtk_dialog_run(GTK_DIALOG(dialog));
|
|
if (res==GTK_RESPONSE_ACCEPT){
|
|
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
|
gtk_entry_set_text(GTK_ENTRY(widgets->TargetNameEntry),filename);
|
|
}
|
|
on_subwindow_close(dialog);
|
|
|
|
}
|
|
|
|
void on_application_chooser_open(GtkWidget *, main_window *widgets){
|
|
yon_app_chooser_window *window = yon_app_chooser_window_new(0,GRAPHICS_LABEL,"Graphics",
|
|
TOOLS_LABEL,"Utility",
|
|
INTERNET_LABEL,"Network",
|
|
MULTIMEDIA_LABEL,"AudioVideo",
|
|
SETTINGS_LABEL,"Settings",
|
|
EDUCATION_LABEL,"Education",
|
|
OFFICE_LABEL,"Office",
|
|
DEVELOPMENT_LABEL,"Development",
|
|
SYSTEM_LABEL,"System",NULL);
|
|
int size;
|
|
config_str apps_list = yon_app_chooser_window_run(window,&size);
|
|
if (size){
|
|
apps *cur_app = yon_apps_get(apps_list[0]);
|
|
gtk_entry_set_text(GTK_ENTRY(widgets->TargetNameEntry),cur_app->Desktop_path);
|
|
}
|
|
}
|
|
|
|
void on_user_changed(GtkWidget *self, main_window *widgets){
|
|
GtkAdjustment *adj = gtk_range_get_adjustment(GTK_RANGE(widgets->priorityScale));
|
|
if (gtk_combo_box_get_active(GTK_COMBO_BOX(self))==0){
|
|
gtk_adjustment_set_lower(adj,-20);
|
|
gtk_label_set_text(GTK_LABEL(widgets->highestPriorityLabel),PRIORITY_ROOT_LABEL);
|
|
}
|
|
else {
|
|
gtk_adjustment_set_lower(adj,0);
|
|
gtk_label_set_text(GTK_LABEL(widgets->highestPriorityLabel),PRIORITY_USER_LABEL);
|
|
}
|
|
if (gtk_adjustment_get_value(adj)<gtk_adjustment_get_lower(adj)) gtk_adjustment_set_value(adj,gtk_adjustment_get_lower(adj));
|
|
}
|
|
|
|
void on_su_sudo_activate(GtkWidget *self, main_window *widgets){
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self))){
|
|
gtk_widget_set_sensitive(widgets->runWithTerminalCheck,0);
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck),1);
|
|
} else {
|
|
gtk_widget_set_sensitive(widgets->runWithTerminalCheck,1);
|
|
}
|
|
}
|
|
|
|
void on_user_activate(GtkToggleButton *self, main_window *widgets){
|
|
if (!gtk_toggle_button_get_active(self)) gtk_widget_set_sensitive((widgets->runWithTerminalCheck),1);
|
|
if (gtk_toggle_button_get_active(self)&&(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSuCheck))||gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSudoCheck))))
|
|
gtk_widget_set_sensitive((widgets->runWithTerminalCheck),0);
|
|
}
|
|
|
|
void on_user_switching(GtkToggleButton *self, main_window *widgets){
|
|
GtkAdjustment *adj = gtk_range_get_adjustment(GTK_RANGE(widgets->priorityScale));
|
|
if (gtk_toggle_button_get_active(self)){
|
|
if (!gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))){
|
|
gtk_adjustment_set_lower(adj,-20);
|
|
gtk_label_set_text(GTK_LABEL(widgets->highestPriorityLabel),PRIORITY_ROOT_LABEL);
|
|
} else {
|
|
gtk_adjustment_set_lower(adj,0);
|
|
gtk_label_set_text(GTK_LABEL(widgets->highestPriorityLabel),PRIORITY_USER_LABEL);
|
|
}
|
|
} else {
|
|
gtk_adjustment_set_lower(adj,0);
|
|
gtk_label_set_text(GTK_LABEL(widgets->highestPriorityLabel),PRIORITY_USER_LABEL);
|
|
}
|
|
if (gtk_adjustment_get_value(adj)<gtk_adjustment_get_lower(adj)) gtk_adjustment_set_value(adj,gtk_adjustment_get_lower(adj));
|
|
}
|
|
|
|
void on_setup_command(GtkWidget *, main_window *widgets){
|
|
char *target = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->TargetNameEntry));
|
|
if (target&&strcmp(target,"")){
|
|
char *final_command;
|
|
int terminal_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck));
|
|
int chosen_terminal = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithTerminalCombo));
|
|
terminal_info *terminal = yon_dictionary_get_data(yon_dictionary_get_nth(main_config.terminals,chosen_terminal),terminal_info*);
|
|
int user_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserCheck));
|
|
char *user = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->runWithUserCombo));
|
|
int pkexec_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserPkexecCheck));
|
|
int su_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSuCheck));
|
|
int sudo_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSudoCheck));
|
|
int priority_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck));
|
|
char *priority = priority_check ? yon_char_append(" --priority=",yon_char_from_long(gtk_adjustment_get_value(gtk_range_get_adjustment(GTK_RANGE(widgets->priorityScale))))) : "";
|
|
int size;
|
|
char *command = yon_char_unite(get_run_command_command, " -o",
|
|
terminal_check ? yon_char_append(" --terminal=", terminal->name_simple) : "",
|
|
user_check ? yon_char_append(" --user=", user) : "",
|
|
user_check&&pkexec_check ? " --exec=pkexec" : "",
|
|
user_check&&su_check ? " --exec=su" : "",
|
|
user_check&&sudo_check ? " --exec=sudo" : "",
|
|
priority_check ? priority : "",
|
|
yon_char_append(" ",target),
|
|
NULL);
|
|
config_str gotten_command = yon_config_load(yon_debug_output("%s\n",command),&size);
|
|
final_command = yon_char_divide_search(*gotten_command,"\n",-1);
|
|
gtk_entry_set_text(GTK_ENTRY(widgets->commandEntry),final_command);
|
|
free(final_command);
|
|
}
|
|
else {
|
|
gtk_entry_set_text(GTK_ENTRY(widgets->commandEntry),"");
|
|
}
|
|
}
|
|
|
|
void on_command_run(GtkWidget *, main_window *widgets){
|
|
if (strcmp(gtk_entry_get_text(GTK_ENTRY(widgets->commandEntry)),"")){
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->commandCheck))){
|
|
const char *command = gtk_entry_get_text(GTK_ENTRY(widgets->commandEntry));
|
|
yon_launch_app_with_arguments((char*)command,NULL);
|
|
} else {
|
|
char *target = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->TargetNameEntry));
|
|
if (target&&strcmp(target,"")){
|
|
int terminal_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck));
|
|
int chosen_terminal = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithTerminalCombo));
|
|
terminal_info *terminal = yon_dictionary_get_data(yon_dictionary_get_nth(main_config.terminals,chosen_terminal),terminal_info*);
|
|
int user_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserCheck));
|
|
char *user = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->runWithUserCombo));
|
|
int pkexec_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserPkexecCheck));
|
|
int su_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSuCheck));
|
|
int sudo_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSudoCheck));
|
|
int priority_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck));
|
|
char *priority = priority_check ? yon_char_append(" --priority=",yon_char_from_long(gtk_adjustment_get_value(gtk_range_get_adjustment(GTK_RANGE(widgets->priorityScale))))) : "";
|
|
char *command = yon_char_unite(get_run_command_command,
|
|
terminal_check ? yon_char_append(" --terminal=", terminal->name_simple) : "",
|
|
user_check ? yon_char_append(" --user=", user) : "",
|
|
user_check&&pkexec_check ? " --exec=pkexec" : "",
|
|
user_check&&su_check ? " --exec=su" : "",
|
|
user_check&&sudo_check ? " --exec=sudo" : "",
|
|
priority_check ? priority : "",
|
|
yon_char_append(" ",target),
|
|
NULL);
|
|
yon_launch(command);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// standard functions
|
|
|
|
void config_init(){
|
|
}
|
|
|
|
void on_adjustment_changed(GtkAdjustment *self, main_window *widgets){
|
|
gtk_entry_set_text(GTK_ENTRY(widgets->prioritySpinEntry),yon_char_from_long(gtk_adjustment_get_value(self)));
|
|
}
|
|
|
|
void on_adjustment_increase(GtkWidget *, main_window *widgets) {
|
|
long current = gtk_adjustment_get_value(gtk_range_get_adjustment(GTK_RANGE(widgets->priorityScale)));
|
|
current ++;
|
|
gtk_adjustment_set_value(gtk_range_get_adjustment(GTK_RANGE(widgets->priorityScale)),current);
|
|
}
|
|
|
|
void on_adjustment_decrease(GtkWidget *, main_window *widgets) {
|
|
long current = gtk_adjustment_get_value(gtk_range_get_adjustment(GTK_RANGE(widgets->priorityScale)));
|
|
current --;
|
|
gtk_adjustment_set_value(gtk_range_get_adjustment(GTK_RANGE(widgets->priorityScale)),current);
|
|
}
|
|
|
|
main_window *yon_main_window_complete(main_window *widgets){
|
|
widgets = yon_remalloc(widgets,sizeof(main_window));
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
|
|
gtk_box_pack_start(GTK_BOX(widgets->InterfaceBox),yon_gtk_builder_get_widget(builder,"BoxMain"),1,1,0);
|
|
widgets->PlugBox = yon_gtk_builder_get_widget(builder,"plugBox");
|
|
widgets->TargetNameEntry = yon_gtk_builder_get_widget(builder,"targetNameEntry");
|
|
widgets->chooseFileButton = yon_gtk_builder_get_widget(builder,"chooseFileButton");
|
|
widgets->chooseDesktopButton = yon_gtk_builder_get_widget(builder,"chooseDesktopButton");
|
|
|
|
widgets->runWithTerminalCheck = yon_gtk_builder_get_widget(builder,"runWithTerminalCheck");
|
|
widgets->runWithTerminalCombo = yon_gtk_builder_get_widget(builder,"runWithTerminalCombo");
|
|
|
|
widgets->runWithUserCheck = yon_gtk_builder_get_widget(builder,"runWithUserCheck");
|
|
widgets->runWithUserPkexecCheck = yon_gtk_builder_get_widget(builder,"runWithUserPkexecCheck");
|
|
widgets->runWithUserSuCheck = yon_gtk_builder_get_widget(builder,"runWithUserSuCheck");
|
|
widgets->runWithUserSudoCheck = yon_gtk_builder_get_widget(builder,"runWithUserSudoCheck");
|
|
widgets->runWithUserCombo = yon_gtk_builder_get_widget(builder,"runWithUserCombo");
|
|
|
|
widgets->priorityCheck = yon_gtk_builder_get_widget(builder,"priorityCheck");
|
|
widgets->priorityScale = yon_gtk_builder_get_widget(builder,"priorityScale");
|
|
widgets->prioritySpinEntry = yon_gtk_builder_get_widget(builder,"prioritySpinEntry");
|
|
widgets->prioritySpinIncreaseButton = yon_gtk_builder_get_widget(builder,"prioritySpinIncreaseButton");
|
|
widgets->prioritySpinDecreaseButton = yon_gtk_builder_get_widget(builder,"prioritySpinDecreaseButton");
|
|
widgets->highestPriorityLabel = yon_gtk_builder_get_widget(builder,"highestPriorityLabel");
|
|
|
|
widgets->commandCheck = yon_gtk_builder_get_widget(builder,"commandCheck");
|
|
widgets->commandEntry = yon_gtk_builder_get_widget(builder,"commandEntry");
|
|
|
|
widgets->runButton = yon_gtk_builder_get_widget(builder,"runButton");
|
|
|
|
gtk_window_set_title(GTK_WINDOW(widgets->Window),TITLE_LABEL);
|
|
|
|
/* Widget registration for config monitoring | Регистрация виджетов для мониторинга конфига */
|
|
// yon_window_config_add_custom_parameter(widgets->HeadInfoLabel,"head-text","label",YON_TYPE_STRING);
|
|
|
|
/* Signal connection | Присоединение сигналов */
|
|
g_signal_connect(G_OBJECT(widgets->chooseFileButton),"clicked",G_CALLBACK(on_file_chooser_open),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->chooseDesktopButton),"clicked",G_CALLBACK(on_application_chooser_open),widgets);
|
|
|
|
g_signal_connect(G_OBJECT(widgets->priorityCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->priorityScale);
|
|
g_signal_connect(G_OBJECT(widgets->priorityCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),gtk_widget_get_parent(widgets->prioritySpinEntry));
|
|
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->runWithUserPkexecCheck);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->runWithUserSuCheck);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->runWithUserSudoCheck);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->runWithUserCombo);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserCheck),"toggled",G_CALLBACK(on_user_switching),widgets);
|
|
|
|
g_signal_connect(G_OBJECT(widgets->runWithTerminalCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->runWithTerminalCombo);
|
|
|
|
g_signal_connect(G_OBJECT(widgets->commandCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->commandEntry);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserCombo),"changed",G_CALLBACK(on_user_changed),widgets);
|
|
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserSuCheck),"toggled",G_CALLBACK(on_su_sudo_activate),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserSudoCheck),"toggled",G_CALLBACK(on_su_sudo_activate),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserCheck),"toggled",G_CALLBACK(on_user_activate),widgets);
|
|
|
|
g_signal_connect(G_OBJECT(widgets->TargetNameEntry),"changed",G_CALLBACK(on_setup_command),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->runWithTerminalCheck),"toggled",G_CALLBACK(on_setup_command),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->runWithTerminalCombo),"changed",G_CALLBACK(on_setup_command),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserCheck),"toggled",G_CALLBACK(on_setup_command),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserPkexecCheck),"toggled",G_CALLBACK(on_setup_command),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserSuCheck),"toggled",G_CALLBACK(on_setup_command),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserSudoCheck),"toggled",G_CALLBACK(on_setup_command),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->runWithUserCombo),"changed",G_CALLBACK(on_setup_command),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->priorityCheck),"toggled",G_CALLBACK(on_setup_command),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->priorityScale),"value-changed",G_CALLBACK(on_setup_command),widgets);
|
|
|
|
g_signal_connect(G_OBJECT(widgets->prioritySpinIncreaseButton),"clicked",G_CALLBACK(on_adjustment_increase),widgets);
|
|
g_signal_connect(G_OBJECT(widgets->prioritySpinDecreaseButton),"clicked",G_CALLBACK(on_adjustment_decrease),widgets);
|
|
|
|
g_signal_connect(G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(widgets->priorityScale))),"value-changed",G_CALLBACK(on_adjustment_changed),widgets);
|
|
|
|
g_signal_connect(G_OBJECT(widgets->runButton),"clicked",G_CALLBACK(on_command_run),widgets);
|
|
int size;
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->runWithUserCombo),"root");
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->runWithUserCombo),0);
|
|
main_config.user_id_min = atoi(yon_config_load(get_user_id_min_command,&size)[0]);
|
|
main_config.user_id_max = atoi(yon_config_load(get_user_id_max_command,&size)[0]);
|
|
config_str users = yon_config_load(get_users_command,&size);
|
|
for (int i=0;i<size;i++){
|
|
users[i]=yon_char_divide_search(users[i],"\n",-1);
|
|
if (strstr(users[i],":")&&atoi(strstr(users[i],":")+1)>=main_config.user_id_min&&atoi(strstr(users[i],":")+1)<=main_config.user_id_max)
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->runWithUserCombo),yon_char_divide_search(users[i],":",-1));
|
|
}
|
|
|
|
|
|
config_str terminals = yon_config_load(get_terminals_info_command,&size);
|
|
for (int i=1;i<size;i++){
|
|
int parsed_size;
|
|
terminals[i] = yon_char_divide_search(terminals[i],"\n",-1);
|
|
config_str terminal_parsed = yon_char_parse(terminals[i], &parsed_size,":");
|
|
terminal_info *term = g_malloc0(sizeof(terminal_info));
|
|
term->exec = terminal_parsed[0];
|
|
term->name_simple = terminal_parsed[1];
|
|
term->name = terminal_parsed[2];
|
|
if (!access(term->exec,F_OK)) {gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->runWithTerminalCombo),term->name);
|
|
yon_dictionary_add_or_create_if_exists_with_data(main_config.terminals,term->name,term);
|
|
}
|
|
}
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->runWithTerminalCombo),0);
|
|
gtk_widget_show(widgets->Window);
|
|
return widgets;
|
|
}
|
|
|
|
gboolean yon_interface_update(main_window *){
|
|
|
|
return G_SOURCE_REMOVE;
|
|
}
|
|
// standard functions
|
|
|
|
int main(int argc, char *argv[]){
|
|
setlocale(LC_ALL, "");
|
|
textdomain (LocaleName);
|
|
|
|
yon_ubl_connect_config((_template_config*)&main_config);
|
|
yon_ubl_window_init(TITLE_LABEL,TITLE_INFO_LABEL,LocaleName,CssPath,LocaleName,version_application,WIKI_LINK);
|
|
config_str unfound = NULL;
|
|
yon_apps_init();
|
|
int size=0;
|
|
yon_ubl_setup_arguments(argc,argv,&unfound,&size,NULL);
|
|
gtk_init(&argc,&argv);
|
|
template_main_window *widgets = yon_ubl_window_setup();
|
|
|
|
//turn off if custom presented
|
|
|
|
yon_main_window_complete((main_window*)widgets);
|
|
yon_ubl_status_box_render(CHOOSE_APP_OR_FILE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
char *path = yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL);
|
|
yon_window_config_load(path);
|
|
main_config.launch_arguments=yon_char_parsed_copy(argv,argc);
|
|
main_config.launch_size=argc;
|
|
gtk_main();
|
|
yon_apps_uninit();
|
|
return 0;
|
|
} |