From 254ae9a5ef7d893f725456f5e25f9ec245acba5b Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Mon, 2 Oct 2023 16:51:12 +0200 Subject: Add an execute_command with warning --- src/utils.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 95aa1ce..f6c113a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,6 +1,6 @@ /* * Copyright 2021 Marius Gripsgard - * Copyright 2021 Robert Tari + * Copyright 2021-2023 Robert Tari * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published @@ -16,13 +16,25 @@ */ #include "utils.h" - +#include #include #ifdef LOMIRI_FEATURES_ENABLED # include #endif +static gboolean bI18nInit = FALSE; + +static void initI18n () +{ + if (!bI18nInit) + { + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + bI18nInit = TRUE; + } +} + // TODO: make case insensitive gboolean is_xdg_current_desktop (const gchar* desktop, const gchar* session) @@ -304,3 +316,24 @@ void ayatana_common_utils_ellipsize(char *sText) memcpy(pLastChar, "...\0", 4); } } + +gboolean ayatana_common_utils_execute_command_warn (const gchar *sProgram, const gchar *sArgs) +{ + gboolean bHasProgram = ayatana_common_utils_have_program (sProgram); + + if (!bHasProgram) + { + initI18n (); + gchar *sMessage = g_strdup_printf (_("The %s program is required for this action, but it was not found."), sProgram); + ayatana_common_utils_zenity_warning ("dialog-warning", _("Warning"), sMessage); + g_free (sMessage); + + return FALSE; + } + + gchar *sCommand = g_strdup_printf ("%s %s", sProgram, sArgs); + gboolean bSuccess = ayatana_common_utils_execute_command (sCommand); + g_free (sCommand); + + return bSuccess; +} -- cgit v1.2.3