From c99aacdb91fa6b22b25efd7c09ad2601eaf92f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 27 Apr 2022 21:32:30 +0200 Subject: notify-send: Move server capabilities check to a separate function --- tools/notify-send.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/notify-send.c b/tools/notify-send.c index c992180..a72dc94 100644 --- a/tools/notify-send.c +++ b/tools/notify-send.c @@ -176,6 +176,22 @@ on_wait_timeout (gpointer data) return FALSE; } +static gboolean +server_has_capability (const gchar *capability) +{ + GList *server_caps = notify_get_server_caps (); + gboolean supported; + + supported = !!g_list_find_custom (server_caps, + capability, + (GCompareFunc) g_ascii_strcasecmp); + + g_list_foreach (server_caps, (GFunc) g_free, NULL); + g_list_free (server_caps); + + return supported; +} + int main (int argc, char *argv[]) { @@ -350,19 +366,12 @@ main (int argc, char *argv[]) } if (actions != NULL) { - GList *server_caps = notify_get_server_caps (); gint i = 0; char *action = NULL; gchar **spl = NULL; gboolean have_actions; - have_actions = - !!g_list_find_custom (server_caps, - "actions", - (GCompareFunc) g_ascii_strcasecmp); - g_list_foreach (server_caps, (GFunc) g_free, NULL); - g_list_free (server_caps); - + have_actions = server_has_capability ("actions"); if (!have_actions) { g_printerr (N_("Actions are not supported by this " "notifications server. " -- cgit v1.2.1