aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2021-09-03 22:13:47 +0200
committerRobert Tari <robert@tari.in>2021-09-03 22:13:47 +0200
commitbaa08a2ea41872d6c3bf7c526a800ce99c8e73df (patch)
tree61b9796e074d8906cf825e63369007e54d5dc72e /src
parentce72a2c93d36789bb406d9053996396eeaa0dc56 (diff)
downloadayatana-indicator-keyboard-baa08a2ea41872d6c3bf7c526a800ce99c8e73df.tar.gz
ayatana-indicator-keyboard-baa08a2ea41872d6c3bf7c526a800ce99c8e73df.tar.bz2
ayatana-indicator-keyboard-baa08a2ea41872d6c3bf7c526a800ce99c8e73df.zip
Replace local code with libayatana-common
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/service.c6
-rw-r--r--src/utils.c167
-rw-r--r--src/utils.h38
4 files changed, 4 insertions, 209 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3eb7caf9..6efa4677 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,7 +5,7 @@ set (SERVICE_EXEC "ayatana-indicator-keyboard-service")
add_definitions(-DG_LOG_DOMAIN="ayatana-indicator-keyboard")
# handwritten sources
-set(SERVICE_MANUAL_SOURCES keyboard.c service.c utils.c)
+set(SERVICE_MANUAL_SOURCES keyboard.c service.c)
# generated sources
set(SERVICE_GENERATED_SOURCES)
diff --git a/src/service.c b/src/service.c
index 8d662a20..afeed80f 100644
--- a/src/service.c
+++ b/src/service.c
@@ -16,8 +16,8 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
+#include <ayatana/common/utils.h>
#include "service.h"
-#include "utils.h"
#define BUS_NAME "org.ayatana.indicator.keyboard"
#define BUS_PATH "/org/ayatana/indicator/keyboard"
@@ -256,9 +256,9 @@ static void onLayoutSelected(GSimpleAction *pAction, GVariant *pVariant, gpointe
static void onSettings(GSimpleAction *pAction, GVariant *pVariant, gpointer pUserData)
{
- if (is_mate())
+ if (ayatana_common_utils_is_mate())
{
- execute_command("mate-keyboard-properties");
+ ayatana_common_utils_execute_command("mate-keyboard-properties");
}
}
diff --git a/src/utils.c b/src/utils.c
deleted file mode 100644
index 82f9cff0..00000000
--- a/src/utils.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2021 Marius Gripsgard <marius@ubports.com>
- *
- * 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
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "utils.h"
-
-#include <string.h>
-
-#ifdef HAS_URLDISPATCHER
-# include <url-dispatcher.h>
-#endif
-
-// TODO: make case insensitive
-gboolean
-is_xdg_current_desktop (const gchar* desktop)
-{
- const gchar *xdg_current_desktop;
- gchar **desktop_names;
- int i;
-
- xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
- if (xdg_current_desktop != NULL) {
- desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
- for (i = 0; desktop_names[i]; ++i) {
- if (!g_strcmp0 (desktop_names[i], desktop)) {
- g_strfreev (desktop_names);
- return TRUE;
- }
- }
- g_strfreev (desktop_names);
- }
- return FALSE;
-}
-
-gboolean
-is_lomiri ()
-{
- // For legacy reasons keep the MIR_SOCKET hack
- return (g_getenv ("MIR_SOCKET") != NULL ||
- is_xdg_current_desktop(DESKTOP_LOMIRI));
-}
-
-gboolean
-is_gnome ()
-{
- return is_xdg_current_desktop(DESKTOP_GNOME);
-}
-
-gboolean
-is_unity ()
-{
- return is_xdg_current_desktop(DESKTOP_UNITY);
-}
-
-gboolean
-is_mate ()
-{
- return is_xdg_current_desktop(DESKTOP_MATE);
-}
-
-gboolean
-is_xfce ()
-{
- return is_xdg_current_desktop(DESKTOP_XFCE);
-}
-
-gboolean
-is_pantheon ()
-{
- return is_xdg_current_desktop(DESKTOP_PANTHEON);
-}
-
-// Bit of a hacky way? should use xdg open
-char *
-find_browser ()
-{
- static char * browser_path = NULL;
- char* tmp_browser_path;
- gchar **browser_names;
-
- int i;
-
- if (browser_path == NULL)
- {
- browser_names = g_strsplit ("x-www-browser,google-chrome,firefox,chromium", ",", 0);
-
- for (i = 0; browser_names[i]; ++i) {
- tmp_browser_path = g_find_program_in_path (browser_names[i]);
-
- if (tmp_browser_path) {
- browser_path = g_strdup (tmp_browser_path);
- g_free (tmp_browser_path);
- g_strfreev (browser_names);
- break;
- }
- }
- }
-
- return browser_path;
-}
-
-gboolean
-execute_command (const gchar * cmd)
-{
- GError * err = NULL;
-
- g_debug ("Issuing command '%s'", cmd);
-
- if (!g_spawn_command_line_async (cmd, &err))
- {
- g_warning ("Unable to start %s: %s", cmd, err->message);
- g_error_free (err);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-open_url (const gchar * url)
-{
- char * browser = NULL;
-
- if (is_lomiri())
- {
-#ifdef HAS_URLDISPATCHER
- url_dispatch_send("settings:///system/battery", NULL, NULL);
- return TRUE;
-#else
- g_warning("Built without url-dispatcher, is not able to open url");
-#endif
- }
-
- if (browser == NULL)
- browser = find_browser();
-
- if (browser != NULL)
- return execute_command(g_strdup_printf("%s '%s'", browser, url));
- else
- return FALSE;
-
-}
-
-gboolean
-have_program (const gchar * program)
-{
- gchar *path;
- gboolean have;
-
- path = g_find_program_in_path(program);
- have = path != NULL;
- g_free(path);
-
- return have;
-}
diff --git a/src/utils.h b/src/utils.h
deleted file mode 100644
index 52e491f2..00000000
--- a/src/utils.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2021 Marius Gripsgard <marius@ubports.com>
- *
- * 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
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#pragma once
-
-#include <glib.h>
-
-#define DESKTOP_LOMIRI "Lomiri"
-#define DESKTOP_UNITY "Unity"
-#define DESKTOP_MATE "MATE"
-#define DESKTOP_GNOME "GNOME"
-#define DESKTOP_XFCE "XFCE"
-#define DESKTOP_PANTHEON "PANTHEON"
-
-gboolean is_lomiri();
-gboolean is_unity();
-gboolean is_gnome();
-gboolean is_mate();
-gboolean is_xfce();
-gboolean is_pantheon();
-
-gboolean execute_command(const gchar * cmd);
-gboolean open_url(const gchar * url);
-gboolean have_program(const gchar * program);