From 9f6064b4073d80f0635e3f61d1e5d28e2f1d1182 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 2 Apr 2021 22:38:21 +0200 Subject: Add the Zenity warning function --- src/utils.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/utils.h | 1 + 2 files changed, 47 insertions(+) (limited to 'src') diff --git a/src/utils.c b/src/utils.c index 152f226..e5e96fa 100644 --- a/src/utils.c +++ b/src/utils.c @@ -172,3 +172,49 @@ have_program (const gchar * program) return have; } + +gboolean +zenity_warning (const char * icon_name, + const char * title, + const char * text) +{ + char * command_line; + int exit_status; + GError * error; + gboolean confirmed; + char * zenity; + + confirmed = FALSE; + zenity = g_find_program_in_path ("zenity"); + + if (zenity) + { + command_line = g_strdup_printf ("%s" + " --warning" + " --icon-name=\"%s\"" + " --title=\"%s\"" + " --text=\"%s\"" + " --no-wrap", + zenity, + icon_name, + title, + text); + + /* Treat errors as user confirmation. + Otherwise how will the user ever log out? */ + exit_status = -1; + error = NULL; + if (!g_spawn_command_line_sync (command_line, NULL, NULL, &exit_status, &error)) + { + confirmed = TRUE; + } + else + { + confirmed = g_spawn_check_exit_status (exit_status, &error); + } + + g_free (command_line); + } + g_free (zenity); + return confirmed; +} diff --git a/src/utils.h b/src/utils.h index 60c5ed4..a433a23 100644 --- a/src/utils.h +++ b/src/utils.h @@ -39,3 +39,4 @@ gboolean is_budgie(); gboolean execute_command(const gchar * cmd); gboolean open_url(const gchar * url); gboolean have_program(const gchar * program); +gboolean zenity_warning(const char *icon_name, const char *title, const char *text); -- cgit v1.2.3