aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-10-02 23:15:43 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-10-02 23:15:43 +0200
commit9bdaeabc50a0ea4568bc93bf9e790380813ab11a (patch)
treeed4e6048094317753e920dbe1f56822961cef082
parent2097646924efa849076c0527f9a0dcf178504d22 (diff)
parent254ae9a5ef7d893f725456f5e25f9ec245acba5b (diff)
downloadlibayatana-common-9bdaeabc50a0ea4568bc93bf9e790380813ab11a.tar.gz
libayatana-common-9bdaeabc50a0ea4568bc93bf9e790380813ab11a.tar.bz2
libayatana-common-9bdaeabc50a0ea4568bc93bf9e790380813ab11a.zip
Merge branch 'tari01-pr/execute-command-warn'
Attributes GH PR #62: https://github.com/AyatanaIndicators/libayatana-common/pull/62
-rw-r--r--CMakeLists.txt6
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/libayatana-common.pc.in2
-rw-r--r--src/utils.c37
-rw-r--r--src/utils.h4
5 files changed, 42 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 49c093b..2da6637 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
-project (libayatana-common C CXX)
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required (VERSION 3.13)
+project (libayatana-common VERSION "0.9.8" LANGUAGES C CXX)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
@@ -7,8 +7,6 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
-set(PROJECT_VERSION "0.9.8")
-set(PACKAGE ${CMAKE_PROJECT_NAME})
set(GETTEXT_PACKAGE "ayatana-common")
set(API_VERSION 0)
set(ABI_VERSION 0)
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/libayatana-common.pc.in b/src/libayatana-common.pc.in
index df79e1f..4800e81 100644
--- a/src/libayatana-common.pc.in
+++ b/src/libayatana-common.pc.in
@@ -5,6 +5,6 @@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@/ayatana
Name: Ayatana common
Description: Ayatana common library
-Version: @PROJECT_VERSION@
+Version: @CMAKE_PROJECT_VERSION@
Libs: -L${libdir} -layatana-common
Cflags: -I${includedir}
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);