From 166860944067cf27c1784dd5364d70afbaa4c1be Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 4 Oct 2023 01:49:50 +0200 Subject: Add a Zenity question function --- src/utils.c | 37 +++++++++++++++++++++++++++++++++++++ src/utils.h | 1 + 2 files changed, 38 insertions(+) (limited to 'src') diff --git a/src/utils.c b/src/utils.c index f6c113a..0a33a74 100644 --- a/src/utils.c +++ b/src/utils.c @@ -337,3 +337,40 @@ gboolean ayatana_common_utils_execute_command_warn (const gchar *sProgram, const return bSuccess; } + +gboolean ayatana_common_utils_zenity_question (const gchar *sIcon, const gchar *sTitle, const gchar *sText, const gchar *sOk, const gchar *sCancel) +{ + gchar *sZenity = g_find_program_in_path ("zenity"); + gchar *sCommand = g_strdup_printf ("%s --question --icon-name=\"%s\" --title=\"%s\" --text=\"%s\" --ok-label=\"%s\" --cancel-label=\"%s\" --no-wrap", sZenity, sIcon, sTitle, sText, sOk, sCancel); + g_free (sZenity); + int nStatus = -1; + GError *pError = NULL; + gboolean bConfirmed = FALSE; + + if (!g_spawn_command_line_sync (sCommand, NULL, NULL, &nStatus, &pError)) + { + bConfirmed = TRUE; + } + else + { + #if GLIB_CHECK_VERSION(2, 70, 0) + bConfirmed = g_spawn_check_wait_status (nStatus, &pError); + #else + bConfirmed = g_spawn_check_exit_status (nStatus, &pError); + #endif + } + + if (pError) + { + if (!g_error_matches (pError, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, pError->message); + } + + g_clear_error (&pError); + } + + g_free (sCommand); + + return bConfirmed; +} diff --git a/src/utils.h b/src/utils.h index 34cf2f4..9d3e641 100644 --- a/src/utils.h +++ b/src/utils.h @@ -58,3 +58,4 @@ gboolean ayatana_common_utils_have_program(const gchar * program); gboolean ayatana_common_utils_zenity_warning(const char *icon_name, const char *title, const char *text); void ayatana_common_utils_ellipsize(char *sText); gboolean ayatana_common_utils_execute_command_warn (const gchar *sProgram, const gchar *sArgs); +gboolean ayatana_common_utils_zenity_question (const gchar *sIcon, const gchar *sTitle, const gchar *sText, const gchar *sOk, const gchar *sCancel); -- cgit v1.2.3