From 88ffdb3784b81bfee452677393e180aa1b51cd48 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Thu, 18 Apr 2024 16:16:12 +0600 Subject: [PATCH] Confirmation window for service launching --- source/ubl-settings-services.c | 29 ++++++++++++++++++++++------- source/ubl-settings-services.h | 8 ++++---- source/ubl-strings.h | 2 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/source/ubl-settings-services.c b/source/ubl-settings-services.c index 2e41ed2..45e6a7c 100644 --- a/source/ubl-settings-services.c +++ b/source/ubl-settings-services.c @@ -451,8 +451,7 @@ void on_filter_changed(GtkWidget *self, main_window *widgets){ void on_system_kill_confirmed(GtkWidget *self,char *service_name){ if (self){}; - char *command = service_kill_command(service_name); - yon_launch_app_with_arguments(command,""); + yon_launch_app_with_arguments(service_name,""); } void on_system_launch_clicked(GtkWidget *self, char *path, main_window *widgets){ @@ -477,7 +476,7 @@ void on_system_launch_clicked(GtkWidget *self, char *path, main_window *widgets) if (status){ dialog_confirmation_data *data = malloc(sizeof(dialog_confirmation_data)); data->action_text=SERVICE_STOP_WARNING_LABEL(service_name); - data->data=service_name; + data->data=service_stop_command(service_name); data->function=(void*)(void*)on_system_kill_confirmed; int size; config_str result = yon_config_load(service_check_active_command(service_name),&size); @@ -491,15 +490,31 @@ void on_system_launch_clicked(GtkWidget *self, char *path, main_window *widgets) } yon_char_parsed_free(result,size); } else { - yon_launch(service_start_command(service_name)); + dialog_confirmation_data *data = malloc(sizeof(dialog_confirmation_data)); + data->action_text=SERVICE_START_WARNING_LABEL(service_name); + data->data=service_start_command(service_name); + data->function=(void*)(void*)on_system_kill_confirmed; int size; config_str result = yon_config_load(service_check_active_command(service_name),&size); yon_char_remove_last_symbol(result[0],'\n'); if (size>0&&!strcmp(result[0],"active")){ - gtk_list_store_set(GTK_LIST_STORE(model),&iter,4,1,-1); - } else { - yon_ubl_status_box_render(SERVICE_START_FAILED_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); + int responce = yon_confirmation_dialog_call(widgets->Window,data); + if (responce == GTK_RESPONSE_ACCEPT){ + gtk_list_store_set(GTK_LIST_STORE(model),&iter,4,1,-1); + + } } + + // yon_char_parsed_free(result,size); + // yon_launch(service_start_command(service_name)); + // int size; + // config_str result = yon_config_load(service_check_active_command(service_name),&size); + // yon_char_remove_last_symbol(result[0],'\n'); + // if (size>0&&!strcmp(result[0],"active")){ + // gtk_list_store_set(GTK_LIST_STORE(model),&iter,4,1,-1); + // } else { + // yon_ubl_status_box_render(SERVICE_START_FAILED_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); + // } } } diff --git a/source/ubl-settings-services.h b/source/ubl-settings-services.h index e73afd7..f2cab65 100644 --- a/source/ubl-settings-services.h +++ b/source/ubl-settings-services.h @@ -38,10 +38,10 @@ #define load_system_services_command "systemctl --system list-units --no-pager --all |grep -E \"^ \" |grep -v \"UNIT\" |sed -e 's/ */;/g' -e 's/^;//g' |cut -f1 -d';'" #define load_enabled_command "systemctl list-unit-files --no-pager --state=enabled --all |sed -e 's/ */:/g' -e 's/ *: */:/g'|cut -f1 -d:" #define load_launched_command "systemctl list-units --no-pager --state=active --all --no-legend|sed -e 's/^ //g' -e 's/ */:/g' |cut -f1 -d:" -#define service_start_command(target) yon_char_append("systemctl start --no-pager ",target) -#define service_stop_command(target) yon_char_append("systemctl stop --no-pager ",target) -#define service_enable_command(target) yon_char_append("systemctl enable --no-pager ",target) -#define service_disable_command(target) yon_char_append("systemctl disable --no-pager ",target) +#define service_start_command(target) yon_char_append("systemctl start ",target) +#define service_stop_command(target) yon_char_append("systemctl stop ",target) +#define service_enable_command(target) yon_char_append("systemctl enable ",target) +#define service_disable_command(target) yon_char_append("systemctl disable ",target) #define service_kill_command(target) yon_char_append("systemctl kill ",target) #define service_check_active_command(target) yon_char_append("systemctl is-active ",target) diff --git a/source/ubl-strings.h b/source/ubl-strings.h index 62bc354..2bcb8af 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -63,7 +63,7 @@ #define SWITCH_OFF_ERROR_LABEL _("Service were not stopped") #define SERVICE_STOP_WARNING_LABEL(target) yon_char_unite(_("Are you sure want to stop "),target,"?\n",_("The system may become unstable."),NULL) -#define SERVICE_SART_WARNING_LABEL(target) yon_char_unite(_("Are you sure want to start "),target,"?\n",_("The system may become unstable."),NULL) +#define SERVICE_START_WARNING_LABEL(target) yon_char_unite(_("Are you sure want to start "),target,"?\n",_("The system may become unstable."),NULL) #define REEXEC_SERVICE_WARMING_LABEL(target) yon_char_unite(_("Are you sure want to restart "),target,"?\n",_("The system may become unstable."),NULL) #define RELOAD_SERVICE_WARMING_LABEL(target) yon_char_unite(_("Are you sure want to reload "),target,"?\n",_("The system may become unstable."),NULL) #define SERVICE_ENABLE_WARNING_LABEL(target) yon_char_unite(_("Are you sure want to enable "),target,"?\n",_("The system may become unstable."),NULL)