aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-10-05 23:33:29 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-10-05 23:33:29 +0200
commit04d4738d2faf0b070fd01fec7398cf64b25ea425 (patch)
tree0d40d170cff9018312616bf9947d550c2819aa5e
parent9bdaeabc50a0ea4568bc93bf9e790380813ab11a (diff)
parent166860944067cf27c1784dd5364d70afbaa4c1be (diff)
downloadlibayatana-common-04d4738d2faf0b070fd01fec7398cf64b25ea425.tar.gz
libayatana-common-04d4738d2faf0b070fd01fec7398cf64b25ea425.tar.bz2
libayatana-common-04d4738d2faf0b070fd01fec7398cf64b25ea425.zip
Merge branch 'tari01-pr/zenity-question'
Attributes GH PR #63: https://github.com/AyatanaIndicators/libayatana-common/pull/63
-rw-r--r--src/utils.c37
-rw-r--r--src/utils.h1
2 files changed, 38 insertions, 0 deletions
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);