From 6be744e3e05b4fc1ac9d188818b5356a36314a29 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Fri, 9 Feb 2024 17:55:25 +0600 Subject: [PATCH] Confirmation dialog for unstoppable services --- source/ubl-settings-services.c | 17 +++++++++++++++-- source/ubl-settings-services.h | 3 +++ source/ubl-strings.h | 3 ++- ubl-settings-services.pot | 10 ++++++++++ ubl-settings-services_ru.po | 11 +++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/source/ubl-settings-services.c b/source/ubl-settings-services.c index a780ee9..cc69b7f 100644 --- a/source/ubl-settings-services.c +++ b/source/ubl-settings-services.c @@ -221,6 +221,12 @@ void on_system_autostart_clicked(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(command); +} + void on_system_launch_clicked(GtkWidget *self, main_window *widgets){ if (self){}; GtkTreeIter iter; @@ -236,9 +242,16 @@ void on_system_launch_clicked(GtkWidget *self, main_window *widgets){ yon_char_remove_last_symbol(result[0],'\n'); if (size>0){ if (!strcmp(result[0],"active")){ - gtk_list_store_set(GTK_LIST_STORE(widgets->liststore2),&iter,4,1,-1); if (status){ - yon_ubl_status_box_render(SWITCH_OFF_ERROR_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); + dialog_confirmation_data data; + data.action_text=STOP_SERVICE_WARMING_LABEL(service_name); + data.function=(void*)(void*)on_system_kill_confirmed; + data.data=service_name; + int answer = yon_confirmation_dialog_call(self,&data); + if (answer) + gtk_list_store_set(GTK_LIST_STORE(widgets->liststore2),&iter,4,0,-1); + } else { + gtk_list_store_set(GTK_LIST_STORE(widgets->liststore2),&iter,4,1,-1); } } else { gtk_list_store_set(GTK_LIST_STORE(widgets->liststore2),&iter,4,0,-1); diff --git a/source/ubl-settings-services.h b/source/ubl-settings-services.h index 34578d9..b732787 100644 --- a/source/ubl-settings-services.h +++ b/source/ubl-settings-services.h @@ -42,6 +42,7 @@ #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_info_command(target) yon_char_append("systemctl status -l --no-pager ",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) typedef char* string; @@ -208,6 +209,8 @@ void on_config_block_clicked(); void on_system_autostart_clicked(); +void on_system_kill_confirmed(GtkWidget *self,char *service_name); + void on_system_launch_clicked(); gboolean yon_service_source_check(GtkTreeModel *model, GtkTreeIter *iter, void *data); diff --git a/source/ubl-strings.h b/source/ubl-strings.h index 885f79c..50562b6 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -48,4 +48,5 @@ #define LIST_LOAD_LABEL _("Service list is loading") #define STATUS_LABEL _("Status") -#define SWITCH_OFF_ERROR_LABEL _("Service were not stopped") \ No newline at end of file +#define SWITCH_OFF_ERROR_LABEL _("Service were not stopped") +#define STOP_SERVICE_WARMING_LABEL(target) yon_char_unite(_("Are you sure want to stop "),target,"? ",_("The stop will be forced.\nThe system may become unstable."),NULL) \ No newline at end of file diff --git a/ubl-settings-services.pot b/ubl-settings-services.pot index 64b7451..90c1107 100644 --- a/ubl-settings-services.pot +++ b/ubl-settings-services.pot @@ -204,3 +204,13 @@ msgstr "" #: source/ubl-strings.h:51 msgid "Service were not stopped" msgstr "" + +#: source/ubl-strings.h:52 +msgid "Are you sure want to stop " +msgstr "" + +#: source/ubl-strings.h:52 +msgid "" +"The stop will be forced.\n" +"The system may become unstable." +msgstr "" diff --git a/ubl-settings-services_ru.po b/ubl-settings-services_ru.po index b1646fc..588e6cb 100644 --- a/ubl-settings-services_ru.po +++ b/ubl-settings-services_ru.po @@ -205,3 +205,14 @@ msgstr "Статус" #: source/ubl-strings.h:51 msgid "Service were not stopped" msgstr "Сервис не был остановлен" + +#: source/ubl-strings.h:52 +msgid "Are you sure want to stop " +msgstr "Вы уверены что хотите остановить " + +#: source/ubl-strings.h:52 +msgid "" +"The stop will be forced.\n" +"The system may become unstable." +msgstr "Остановка будет произведена принудительно.\n" +"Возможна нестабильная работа системы."