ublexec has been reworked - single serious but presents

pull/51/head
parent e85aa7545a
commit 253f3c17e2

@ -1,5 +1,5 @@
#define VERSION_LABEL yon_char_unite(_("Version:")," ",version_application,"\n",NULL)
#define HELP_LABEL yon_char_unite(_("ublexec version:")," ", version_application,"\n",_("Run as..."),"\n",_("Usage:"), " ublexec ",_("[OPTIONS]"),"\n",_("Options:"),"\n\t--help, -h\t\t\t",_("Show this help"),"\n\t--version, -V\t\t\t",_("Show package version"),"\n\t--lock-help\t\t\t",_("Lock this help menu"),"\n\t--lock-save\t\t\t",_("Lock configuration saving"),"\n\t--lock-save-local\t\t",_("Lock local configration saving"),"\n\t--lock-save-global\t\t",_("Lock global configration saving"),"\n\t--lock-load-global\t\t",_("Lock global configration loading"),"\n",NULL)
#define HELP_LABEL yon_char_unite(_("ublexec version:")," ", version_application,"\n",_("Run as..."),"\n",_("Usage:"), " ublexec ",_("[OPTIONS]"),"\n",_("Options:"),"\n\t--help, -h\t\t\t",_("Show this help"),"\n\t--version, -V\t\t\t",_("Show package version"),"\n\t--lock-help\t\t\t",_("Lock this help menu"),"\n",NULL)
#define TITLE_LABEL _("Run as...")
#define TITLE_INFO_LABEL _("Run the application as a user with a changed priority")
@ -28,3 +28,20 @@
#define OTHER_LABEL _("Other")
#define DEVELOPMENT_LABEL _("Development")
#define SYSTEM_LABEL _("System")
#define PRIORITY_ROOT_LABEL _("-20 (High)")
#define PRIORITY_USER_LABEL _("0 (High)")
#define PRIORITY_LOW_LABEL _("19 (Low)")
#define CHOOSE_APP_OR_FILE_LABEL _("Choose application or file for running")
#define TERMINAL_LABEL _("Run in the terminal emulator")
#define APP_LABEL _("File or app for running")
#define RUN_AS_USER_LABEL _("Run as another user:")
#define USER_LABEL _("User Name:")
#define PRIORITY_LABEL _("Priority")
#define PRIORITY_CHECK_LABEL _("Change startup priority")
#define PRIORITY_SCALE_LABEL _("Priority:")
#define COMMAND_LABEL _("Command line")
#define RUN_LABEL _("Run")
#define EDIT_LABEL _("Edit")

@ -664,7 +664,7 @@ char **yon_char_parse(char *parameters, int *size, char *divider){
char *param;
if (!strstr(parameters,divider)) return NULL;
while ((param=yon_char_divide_search(paramline,divider,1))){
if (strcmp(param,paramline)==0||param[0]=='\0') break;
if (strcmp(param,paramline)==0||paramline[0]=='\0') break;
string=realloc(string,sizeof(char*)*i);
string[i-1]=yon_char_new(param);
i++;
@ -994,6 +994,18 @@ apps *yon_apps_get_by_name(apps *applist, char *name, int size)
return NULL;
};
void __yon_on_app_chooser_selection(GtkTreeView *self, GtkTreeStore *store){
GtkTreeModel *model = GTK_TREE_MODEL(store);
GtkTreeIter iter, parentiter;
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(self),&model,&iter)){
if (!gtk_tree_model_iter_parent(model,&parentiter,&iter)){
gtk_tree_view_expand_row(self,gtk_tree_model_get_path(model,&iter),0);
if (gtk_tree_model_iter_nth_child(model,&parentiter,&iter,0))
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(self),&parentiter);
}
}
}
/**yon_app_chooser_open_with_sections(char *section_name, char *section_filter, char *section_icon, ...)
* [EN]
*
@ -1018,6 +1030,9 @@ char *yon_app_chooser_open_with_sections(char *section_name, char *section_filte
GtkTreeStore *store = GTK_TREE_STORE(gtk_builder_get_object(builder,"treestore1"));
va_list args;
GtkTreeIter iter, childiter;
g_signal_connect(G_OBJECT(main_tree),"cursor-changed",G_CALLBACK(__yon_on_app_chooser_selection),store);
gtk_tree_store_append(GTK_TREE_STORE(store),&iter,NULL);
gtk_tree_store_set(GTK_TREE_STORE(store),&iter,0,section_icon,1,section_name,2,section_filter,-1);
va_start(args,section_icon);
@ -1396,7 +1411,7 @@ char *yon_config_get_parameter(config_str parameters, int size, char *param)
*/
int yon_launch_app_with_arguments(char *name, char *args)
{
char *path = yon_char_unite("/usr/bin/", name, " ", args,NULL);
char *path = yon_char_unite(name, " ", args,NULL);
pthread_t thread_id;
char *command = NULL;
command = path;
@ -1414,6 +1429,19 @@ void yon_launch(char *command)
system(command);
}
/**yon_launch(char *command)
* [EN]
* Execute command [command]
* [RU]
* Выполнить команду [command]
*/
void yon_launch_thread(char *command)
{
pthread_t thread_id;
pthread_create(&thread_id, NULL, (void *)yon_launch, command);
}
// Gtk functions
@ -1811,7 +1839,7 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end
GtkWidget *yon_ubl_menu_item_about_new(char *buttonname){
GtkWidget *menu_item = gtk_menu_item_new();
gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitembottom");
gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"aaa");
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
GtkWidget *label = gtk_label_new(buttonname);
GtkWidget *image = gtk_image_new_from_icon_name("dialog-information-symbolic",GTK_ICON_SIZE_BUTTON);
@ -1825,7 +1853,7 @@ GtkWidget *yon_ubl_menu_item_about_new(char *buttonname){
GtkWidget *yon_ubl_menu_item_documentation_new(char *buttonname){
GtkWidget *menu_item = gtk_menu_item_new();
gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitemtop");
gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"aaa");
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
GtkWidget *label = gtk_label_new(buttonname);
GtkWidget *image = gtk_image_new_from_icon_name("dialog-question-symbolic",GTK_ICON_SIZE_BUTTON);

@ -228,6 +228,8 @@ int yon_launch_app_with_arguments(char *name, char *args);
void yon_launch(char *command);
void yon_launch_thread(char *command);
// Gtk functions
#ifdef __GTK_H__

@ -37,16 +37,7 @@ void on_open_documentation_confirmation(GtkWidget *self, char *link){
widgets->Window = yon_gtk_builder_get_widget(builder,"helpConfirmationWindow");
widgets->AcceptButton = yon_gtk_builder_get_widget(builder,"ReadHelpButton");
widgets->CloseButton = yon_gtk_builder_get_widget(builder,"CancelHelpButton");
widgets->HatText = yon_gtk_builder_get_widget(builder,"webHeaderNameLabel");
widgets->HeaderText = yon_gtk_builder_get_widget(builder,"helpHeader");
widgets->InfoText = yon_gtk_builder_get_widget(builder,"helpText");
widgets->AlwaysOpenCheck = yon_gtk_builder_get_widget(builder,"AlwaysOpenDocumentationCheckbox");
gtk_label_set_text(GTK_LABEL(widgets->HatText),TITLE_LABEL);
gtk_label_set_text(GTK_LABEL(widgets->HeaderText),HELP_TITLE_LABEL);
gtk_label_set_text(GTK_LABEL(widgets->InfoText),HELP_INFO_LABEL);
gtk_button_set_label(GTK_BUTTON(widgets->AcceptButton),OPEN_HELP_LABEL);
gtk_button_set_label(GTK_BUTTON(widgets->AlwaysOpenCheck),HELP_ALWAYS_OPEN_LABEL);
gtk_button_set_label(GTK_BUTTON(widgets->CloseButton),CANCEL_LABEL);
gtk_widget_show_all(widgets->Window);
g_signal_connect(G_OBJECT(widgets->CloseButton),"clicked",G_CALLBACK(on_close_subwindow),NULL);
g_signal_connect(G_OBJECT(widgets->AcceptButton),"clicked",G_CALLBACK(yon_open_browser),yon_char_new(link));
@ -118,13 +109,12 @@ void on_file_chooser_open(GtkWidget *self, main_window *widgets){
void on_application_chooser_open(GtkWidget *self, main_window *widgets){
char *app = yon_app_chooser_open_with_sections(GRAPHICS_LABEL,"Graphics","",
TOOLS_LABEL,"Graphics","",
TOOLS_LABEL,"Utility","",
INTERNET_LABEL,"Network","",
MULTIMEDIA_LABEL,"AudioVideo","",
SETTINGS_LABEL,"Settings","",
EDUCATION_LABEL,"Education","",
OFFICE_LABEL,"Office","",
OTHER_LABEL,"Utility","",
DEVELOPMENT_LABEL,"Development","",
SYSTEM_LABEL,"System","",NULL);
if (app){
@ -132,6 +122,127 @@ void on_application_chooser_open(GtkWidget *self, main_window *widgets){
}
}
void on_user_changed(GtkWidget *self, main_window *widgets){
GtkAdjustment *adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(widgets->prioritySpin));
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_spin_button_get_adjustment(GTK_SPIN_BUTTON(widgets->prioritySpin));
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 *self, main_window *widgets){
char *target = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->TargetNameEntry));
if (target&&strcmp(target,"")){
char *final_command;
char *terminal_exec = yon_dictionary_get_data(yon_dictionary_get(&main_config.terminals,(char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->runWithTerminalCombo))),terminal_info*)->exec_file;
char *terminal_hold = yon_dictionary_get_data(main_config.terminals,terminal_info*)->hold;
char *terminal_exec_arg = yon_dictionary_get_data(main_config.terminals,terminal_info*)->exec_arg;
char *user = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->runWithUserCombo));
char *priority = yon_char_append("nice -n ",yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->prioritySpin))));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserCheck))){
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserPkexecCheck))){
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ",!strstr(target,".") ? terminal_hold : ""," ",terminal_exec_arg," ",NULL) : "", "pkexec ", NULL);
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))==0){ //root
final_command = yon_char_unite(final_command, " --user root env HOME=$HOME DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_SESSION_TYPE=$XDG_SESSION_TYPE XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR SESSION_MANAGER=$SESSION_MANAGER GNOME_DESKTOP_SESSION_ID=$GNOME_DESKTOP_SESSION_ID KDE_FULL_SESSION=$KDE_FULL_SESSION ",NULL);
} else {
final_command = yon_char_unite(final_command, " --user ",user," env HOME=$HOME DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_SESSION_TYPE=$XDG_SESSION_TYPE ",NULL);
}
if (strstr(target,".")){
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "", "xdg-open ",target,NULL);
} else {
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority," ") : "",target,NULL);
}
} else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSuCheck))){
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ",!strstr(target,".") ? terminal_hold : ""," ",terminal_exec_arg," ",NULL) : "", "su ", NULL);
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))==0){ //root
final_command = yon_char_unite(final_command, " --preserve-environment --command \"setsid ",NULL);
} else {
final_command = yon_char_unite("xhost +SI:localuser:",user,"; ",final_command, " --login ",user," --command \"setsid env DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_SESSION_TYPE=$XDG_SESSION_TYPE ",NULL);
}
if (strstr(target,".")){
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "", "xdg-open ",target,"\"",NULL);
} else {
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority," ") : "",target,"\"",NULL);
}
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))){
final_command = yon_char_unite(final_command,"; sleep 10 && xhost -SI:localuser:",user,NULL);
}
} else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSudoCheck))){
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ",!strstr(target,".") ? terminal_hold : ""," ",terminal_exec_arg," ",NULL) : "", "sudo ", NULL);
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))==0){ //root
final_command = yon_char_unite(final_command, " --preserve-env setsid ",NULL);
} else {
final_command = yon_char_unite("xhost +SI:localuser:",user,"; ",final_command, " --user ",user," setsid env DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_SESSION_TYPE=$XDG_SESSION_TYPE ",NULL);
}
if (strstr(target,".")){
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "", "xdg-open '",target,"'",NULL);
} else {
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority," '") : "'",target,"'",NULL);
}
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))){
final_command = yon_char_unite(final_command,"; sleep 10 && xhost -SI:localuser:",user,NULL);
}
}
} else {
if (strstr(target,".")){
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ", !strstr(target,".") ? terminal_hold : "",!strstr(target,".") ? " " : "", terminal_exec_arg, " ",NULL) : "",gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "", "setsid xdg-open ",target,NULL);
} else {
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ", !strstr(target,".") ? terminal_hold : "",!strstr(target,".") ? " " : "", terminal_exec_arg, " ",NULL) : "",gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "",target,NULL);
}
}
gtk_entry_set_text(GTK_ENTRY(widgets->commandEntry),final_command);
free(final_command);
}
}
void on_command_run(GtkWidget *self, main_window *widgets){
const char *command = gtk_entry_get_text(GTK_ENTRY(widgets->commandEntry));
yon_launch_thread((char*)command);
}
// standard functions
void config_init(){
@ -160,6 +271,10 @@ main_window *setup_window(){
widgets->chooseFileButton = yon_gtk_builder_get_widget(builder,"chooseFileButton");
widgets->chooseDesktopButton = yon_gtk_builder_get_widget(builder,"chooseDesktopButton");
widgets->StatusBox = yon_gtk_builder_get_widget(builder,"mainStatusBox");
widgets->StatusIcon = yon_gtk_builder_get_widget(builder,"mainStatusIcon");
widgets->StatusLabel = yon_gtk_builder_get_widget(builder,"mainStatusLabel");
widgets->runWithTerminalCheck = yon_gtk_builder_get_widget(builder,"runWithTerminalCheck");
widgets->runWithTerminalCombo = yon_gtk_builder_get_widget(builder,"runWithTerminalCombo");
@ -209,15 +324,59 @@ main_window *setup_window(){
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->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));
}
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->runWithUserCombo),);
config_str terminals = yon_config_load(get_terminals_info_command,&size);
for (int i=0;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,":");
if (!access(terminal_parsed[1],F_OK)){
terminal_info *term = g_malloc0(sizeof(terminal_info));
term->name = terminal_parsed[0];
term->exec_file = terminal_parsed[1];
term->hold = terminal_parsed[2];
term->exec_arg = terminal_parsed[3];
yon_dictionary_add_or_create_if_exists_with_data(main_config.terminals,term->name,term);
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->runWithTerminalCombo),term->name);
}
}
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->runWithTerminalCombo),0);
gtk_widget_show(widgets->Window);
return widgets;
}
@ -300,7 +459,9 @@ int main(int argc, char *argv[]){
main_window *widgets = setup_window();
yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel);
yon_ubl_header_setup_resource(widgets->HeadOverlay,widgets->HeadBox,widgets->HeadImage,banner_path);
yon_ubl_status_box_render(CHOOSE_APP_OR_FILE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
yon_window_config_setup(GTK_WINDOW(widgets->Window));
yon_window_config_load(config_path);
GtkCssProvider *css=gtk_css_provider_new();

@ -23,6 +23,11 @@
#define icon_path "com.ublinux.ublexec"
#define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
#define get_user_id_min_command "grep \"^UID_MIN\" /etc/login.defs |grep -vE '(nologin|false)$' | sed -e 's/\t/ /g' -e 's/ */ /g'|grep -oE \"[0-9]{1,}\""
#define get_user_id_max_command "grep \"^UID_MAX\" /etc/login.defs | sed -e 's/\t/ /g' -e 's/ */ /g'|grep -oE \"[0-9]{1,}\""
#define get_users_command "getent passwd |cut -d: -f1,3"
#define get_terminals_info_command "grep \"\" /usr/share/ublexec/csv/ublexec_terminals.csv"
#define LocalePath "/usr/share/locale"
#define LocaleName "ublexec"
typedef char* string;
@ -45,8 +50,19 @@ typedef struct {
int lock_save_local;
int lock_save_global;
int lock_load_global;
int user_id_min;
int user_id_max;
dictionary *terminals;
} config;
typedef struct {
char *name;
char *exec_file;
char *hold;
char *exec_arg;
} terminal_info;
typedef struct {
//Standard
GtkWidget *Window;
@ -59,6 +75,10 @@ typedef struct {
GtkWidget *HeadTitleLabel;
GtkWidget *HeadInfoLabel;
GtkWidget *StatusBox;
GtkWidget *StatusIcon;
GtkWidget *StatusLabel;
GtkWidget *TargetNameEntry;
GtkWidget *AboutMenuItem;
GtkWidget *DocumentationMenuItem;

Loading…
Cancel
Save