aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2023-10-02 16:51:12 +0200
committerRobert Tari <robert@tari.in>2023-10-02 16:51:12 +0200
commit254ae9a5ef7d893f725456f5e25f9ec245acba5b (patch)
treeed4e6048094317753e920dbe1f56822961cef082
parent6b6c2f9c7d92a7a505f1a54407590af0a329998e (diff)
downloadlibayatana-common-254ae9a5ef7d893f725456f5e25f9ec245acba5b.tar.gz
libayatana-common-254ae9a5ef7d893f725456f5e25f9ec245acba5b.tar.bz2
libayatana-common-254ae9a5ef7d893f725456f5e25f9ec245acba5b.zip
Add an execute_command with warning
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/utils.c37
-rw-r--r--src/utils.h4
3 files changed, 39 insertions, 4 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ee44f7a..c7d351d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,6 +7,8 @@ target_link_libraries(ayatana-common
${DEPS_LIBRARIES}
)
+target_compile_definitions (ayatana-common PUBLIC GETTEXT_PACKAGE="${GETTEXT_PACKAGE}" LOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}")
+
if(ENABLE_LOMIRI_FEATURES)
add_definitions( -DLOMIRI_FEATURES_ENABLED )
endif()
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 <marius@ubports.com>
- * Copyright 2021 Robert Tari <robert@tari.in>
+ * Copyright 2021-2023 Robert Tari <robert@tari.in>
*
* 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 <glib/gi18n-lib.h>
#include <string.h>
#ifdef LOMIRI_FEATURES_ENABLED
# include <lomiri-url-dispatcher.h>
#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;
+}
diff --git a/src/utils.h b/src/utils.h
index aaca08e..34cf2f4 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,6 +1,6 @@
/*
* Copyright 2021 Marius Gripsgard <marius@ubports.com>
- * Copyright 2021-2022 Robert Tari <robert@tari.in>
+ * Copyright 2021-2023 Robert Tari <robert@tari.in>
*
* 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
@@ -56,5 +56,5 @@ gboolean ayatana_common_utils_execute_command(const gchar * cmd);
gboolean ayatana_common_utils_open_url(const gchar * url);
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);