diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 17 | ||||
-rw-r--r-- | src/meson.build | 7 | ||||
-rw-r--r-- | src/notification.c | 249 | ||||
-rw-r--r-- | src/option.c | 23 | ||||
-rw-r--r-- | src/option.h | 4 | ||||
-rw-r--r-- | src/util.c | 6 | ||||
-rw-r--r-- | src/util.h | 2 | ||||
-rw-r--r-- | src/zenity.h | 6 |
8 files changed, 65 insertions, 249 deletions
@@ -43,7 +43,7 @@ command_line_cb (GtkApplication *app, GApplicationCommandLine *command_line, gpointer user_data) { - g_autofree ZenityArgs *args = user_data; + ZenityArgs *args = user_data; ZenityParsingOptions *results; results = zenity_option_parse (args->argc, args->argv); @@ -83,11 +83,9 @@ command_line_cb (GtkApplication *app, zenity_tree (results->data, results->tree_data); break; -#ifdef HAVE_LIBNOTIFY case MODE_NOTIFICATION: zenity_notification (results->data, results->notification_data); break; -#endif case MODE_PROGRESS: zenity_progress (results->data, results->progress_data); @@ -129,12 +127,14 @@ command_line_cb (GtkApplication *app, g_application_command_line_set_exit_status (command_line, results->data->exit_code); + + g_free (args); } int main (int argc, char *argv[]) { - g_autofree ZenityArgs *args = NULL; + ZenityArgs *args; g_autoptr(GtkApplication) app = NULL; int status; @@ -146,15 +146,12 @@ main (int argc, char *argv[]) textdomain (GETTEXT_PACKAGE); /* </i18n> */ - args = g_new (ZenityArgs, 1); + args = g_new0 (ZenityArgs, 1); args->argc = argc; args->argv = argv; - app = gtk_application_new ("org.gnome.Zenity", - G_APPLICATION_HANDLES_COMMAND_LINE); - - g_signal_connect (app, "command-line", - G_CALLBACK(command_line_cb), args); + app = gtk_application_new (APP_ID, G_APPLICATION_HANDLES_COMMAND_LINE); + g_signal_connect (app, "command-line", G_CALLBACK(command_line_cb), args); status = g_application_run (G_APPLICATION(app), 0, NULL); diff --git a/src/meson.build b/src/meson.build index 1d3cd82..7e5401f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -18,11 +18,6 @@ zenity_sources = [ 'util.c' ] -zenity_deps = [ - gtk_dep, - libnotify -] - zenity_res = gnome.compile_resources( 'zenity-resources', 'zenity.gresource.xml', @@ -37,8 +32,8 @@ zenity = executable( meson.project_name(), zenity_sources + zenity_res, include_directories: zenity_root_dir, - dependencies: zenity_deps, c_args: zenity_c_args, + dependencies: gtk_dep, install: true ) diff --git a/src/notification.c b/src/notification.c index 70b65bc..78f26c2 100644 --- a/src/notification.c +++ b/src/notification.c @@ -5,7 +5,7 @@ * * Copyright © 2002 Sun Microsystems, Inc. * Copyright © 2006 Christian Persch - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2022 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,164 +32,70 @@ #include <string.h> #include <time.h> #include <unistd.h> -#ifdef HAVE_LIBNOTIFY -#include <libnotify/notify.h> #include "util.h" #include "zenity.h" #define MAX_HINTS 16 -static NotifyNotification * -zenity_notification_new (char *message, char *icon_file) +static void +zenity_send_notification (GNotification *notification) { - NotifyNotification *notif; + g_application_send_notification (g_application_get_default (), + "zenity-notification", + notification); +} + +static GNotification * +zenity_notification_new (char *message, char *icon_path) +{ + g_autoptr (GNotification) notif; g_auto(GStrv) text = NULL; + g_autoptr(GFile) icon_file = NULL; + g_autoptr(GIcon) icon = NULL; + /* Accept a title and optional body in the form of `my title\nmy body'. + * The way this is displayed by the notification system is implementation + * defined. + */ text = g_strsplit (g_strcompress (message), "\n", 2); if (*text == NULL) { - g_printerr (_ ("Could not parse message\n")); + g_printerr (_("Could not parse message\n")); return NULL; } - notif = notify_notification_new (text[0], /* title */ - text[1], /* summary */ - icon_file); - - return notif; -} - -static void -on_notification_default_action (NotifyNotification *n, - const char *action, void *user_data) -{ - ZenityData *zen_data = user_data; - - notify_notification_close (n, NULL); - - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - - zenity_util_gapp_quit (NULL); -} - -static GHashTable * -zenity_notification_parse_hints_array (char **hints) -{ - g_autoptr(GHashTable) result = NULL; - g_auto(GStrv) pair = NULL; - int i; + notif = g_notification_new (text[0]); /* title */ - result = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + if (text[1]) + g_notification_set_body (notif, text[1]); - for (i = 0; i < (int)g_strv_length (hints); i++) + if (icon_path) { - pair = g_strsplit (hints[i], ":", 2); - g_hash_table_replace (result, g_strdup (pair[0]), g_strdup (pair[1])); - } + icon_file = g_file_new_for_path (icon_path); - if (g_hash_table_size (result) == 0) { - return NULL; - } else { - return result; + if (g_file_query_exists (icon_file, NULL)) + { + icon = g_file_icon_new (icon_file); + g_notification_set_icon (notif, icon); + } + else + g_printerr (_("Icon file not found: %s\n"), icon_path); } -} - -static GHashTable * -zenity_notification_parse_hints (char *hints) -{ - GHashTable *result; - g_auto(GStrv) hint_array = NULL; - - hint_array = g_strsplit (g_strcompress (hints), "\n", MAX_HINTS); - result = zenity_notification_parse_hints_array (hint_array); - return result; + return g_steal_pointer (¬if); } static void -zenity_notification_set_hint (gpointer key, gpointer value, +on_notification_default_action (GSimpleAction *self, + GVariant *parameter, gpointer user_data) { - NotifyNotification *notification = user_data; - char *hint_name = key; - char *string_value = value; - - GVariant *hint_value; - gboolean boolean_value; - gint32 int_value; - guchar byte_value; - - if ((g_ascii_strcasecmp ("action-icons", hint_name) == 0) || - (g_ascii_strcasecmp ("resident", hint_name) == 0) || - (g_ascii_strcasecmp ("suppress-sound", hint_name) == 0) || - (g_ascii_strcasecmp ("transient", hint_name) == 0)) - { - /* boolean hints */ - if (g_ascii_strcasecmp ("true", string_value) == 0) { - boolean_value = TRUE; - } else if (g_ascii_strcasecmp ("false", string_value) == 0) { - boolean_value = FALSE; - } else { - g_printerr (_ ("Invalid value for a boolean typed hint.\nSupported " - "values are 'true' or 'false'.\n")); - return; - } - hint_value = g_variant_new_boolean (boolean_value); - } - else if ((g_ascii_strcasecmp ("category", hint_name) == 0) || - (g_ascii_strcasecmp ("desktop-entry", hint_name) == 0) || - (g_ascii_strcasecmp ("image-path", hint_name) == 0) || - (g_ascii_strcasecmp ("image_path", hint_name) == 0) || - (g_ascii_strcasecmp ("sound-file", hint_name) == 0) || - (g_ascii_strcasecmp ("sound-name", hint_name) == 0)) - { - /* string hints */ - hint_value = g_variant_new_string (string_value); - } - else if ((g_ascii_strcasecmp ("image-data", hint_name) == 0) || - (g_ascii_strcasecmp ("image_data", hint_name) == 0) || - (g_ascii_strcasecmp ("icon-data", hint_name) == 0)) - { - /* (iibiiay) */ - g_printerr (_ ("Unsupported hint. Skipping.\n")); - return; - } - else if ((g_ascii_strcasecmp ("x", hint_name) == 0) || - (g_ascii_strcasecmp ("y", hint_name) == 0)) - { - /* int hints */ - if (string_value == NULL) - string_value = ""; - int_value = (gint32) g_ascii_strtoll (string_value, NULL, 0); - hint_value = g_variant_new_int32 (int_value); - } - else if ((g_ascii_strcasecmp ("urgency", hint_name) == 0)) - { - /* byte hints */ - if (string_value == NULL) - string_value = ""; - byte_value = (guchar) g_ascii_strtoll (string_value, NULL, 0); - hint_value = g_variant_new_byte (byte_value); - } - else - { - /* unknown hints */ - g_printerr (_("Unknown hint name. Skipping.\n")); - return; - } - - notify_notification_set_hint (notification, hint_name, hint_value); -} + ZenityData *zen_data = user_data; -static void -zenity_notification_set_hints (NotifyNotification *notification, - GHashTable *hints) -{ - if (hints == NULL) - return; + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - g_hash_table_foreach (hints, zenity_notification_set_hint, notification); + zenity_util_gapp_quit (NULL); } static gboolean @@ -197,7 +103,6 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition, gpointer user_data) { g_autofree char *icon_file = NULL; - g_autoptr(GHashTable) notification_hints = NULL; if ((condition & G_IO_IN) != 0) { @@ -254,10 +159,6 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition, { icon_file = g_strdup (value); } - else if (!g_ascii_strcasecmp (command, "hints")) - { - notification_hints = zenity_notification_parse_hints (value); - } else if (!g_ascii_strcasecmp (command, "message")) { /* display a notification bubble */ @@ -267,23 +168,13 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition, } else { - NotifyNotification *notif; - error = NULL; + g_autoptr(GNotification) notif = NULL; notif = zenity_notification_new (value, icon_file); if (notif == NULL) continue; - zenity_notification_set_hints (notif, notification_hints); - - notify_notification_show (notif, &error); - if (error) { - g_warning ( - "Error showing notification: %s", error->message); - error = NULL; - } - - g_object_unref (notif); + zenity_send_notification (notif); } } else if (! g_ascii_strcasecmp (command, "tooltip")) @@ -294,22 +185,14 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition, } else { - NotifyNotification *notif = - zenity_notification_new (value, icon_file); + g_autoptr(GNotification) notif = NULL; + + notif = zenity_notification_new (value, icon_file); if (notif == NULL) continue; - zenity_notification_set_hints (notif, notification_hints); - - notify_notification_show (notif, &error); - if (error) - { - g_warning ("Error showing notification: %s", - error->message); - - error = NULL; - } + zenity_send_notification (notif); } } else if (!g_ascii_strcasecmp (command, "visible")) @@ -351,14 +234,7 @@ void zenity_notification (ZenityData *data, ZenityNotificationData *notification_data) { - g_autoptr(GError) error = NULL; - NotifyNotification *notification; - g_autoptr(GHashTable) notification_hints = NULL; - - /* create the notification widget */ - if (!notify_is_initted ()) { - notify_init (_ ("Zenity notification")); - } + GNotification *notification; if (notification_data->listen) { @@ -368,42 +244,25 @@ zenity_notification (ZenityData *data, } else { + g_autoptr(GSimpleAction) action = NULL; + if (notification_data->notification_text == NULL) exit (1); - notification = - zenity_notification_new (notification_data->notification_text, - notification_data->icon); + notification = zenity_notification_new ( + notification_data->notification_text, notification_data->icon); if (notification == NULL) exit (1); /* if we aren't listening for changes, then close on default action */ - notify_notification_add_action (notification, - "default", - "Do Default Action", - (NotifyActionCallback) on_notification_default_action, - data, - NULL); + action = g_simple_action_new ("app.default", NULL); + g_signal_connect (action, "activate", + G_CALLBACK(on_notification_default_action), data); - /* set the notification hints for the displayed notification */ - if (notification_data->notification_hints != NULL) - { - notification_hints = zenity_notification_parse_hints_array ( - notification_data->notification_hints); - - zenity_notification_set_hints (notification, notification_hints); - } + g_notification_set_default_action (notification, "app.default"); - /* Show icon and wait */ - error = NULL; - if (! notify_notification_show (notification, &error)) - { - if (error != NULL) { - g_warning ("Error showing notification: %s", error->message); - } - exit (1); - } + zenity_send_notification (notification); } if (data->timeout_delay > 0) { @@ -414,5 +273,3 @@ zenity_notification (ZenityData *data, zenity_util_gapp_main (NULL); } } - -#endif diff --git a/src/option.c b/src/option.c index f46d691..0daa493 100644 --- a/src/option.c +++ b/src/option.c @@ -87,13 +87,10 @@ static gboolean zenity_list_hide_header; static gboolean zenity_list_imagelist; static gboolean zenity_list_mid_search; -#ifdef HAVE_LIBNOTIFY /* Notification Dialog Options */ static gboolean zenity_notification_active; static gboolean zenity_notification_listen; static char *zenity_notification_icon; -static char **zenity_notification_hints; -#endif /* Progress Dialog Options */ static gboolean zenity_progress_active; @@ -539,7 +536,6 @@ static GOptionEntry list_options[] = NULL}, {NULL}}; -#ifdef HAVE_LIBNOTIFY static GOptionEntry notification_options[] = {{"notification", '\0', @@ -569,17 +565,8 @@ static GOptionEntry notification_options[] = &zenity_notification_listen, N_ ("Listen for commands on stdin"), NULL}, - {"hint", - '\0', - G_OPTION_FLAG_NOALIAS, - G_OPTION_ARG_STRING_ARRAY, - &zenity_notification_hints, - N_ ("Set the notification hints"), - N_ ("TEXT")}, {NULL}}; -#endif - static GOptionEntry progress_options[] = {{"progress", '\0', @@ -1060,9 +1047,7 @@ zenity_option_init (void) results->progress_data = g_new0 (ZenityProgressData, 1); results->text_data = g_new0 (ZenityTextData, 1); results->tree_data = g_new0 (ZenityTreeData, 1); -#ifdef HAVE_LIBNOTIFY results->notification_data = g_new0 (ZenityNotificationData, 1); -#endif results->color_data = g_new0 (ZenityColorData, 1); results->password_data = g_new0 (ZenityPasswordData, 1); results->forms_data = g_new0 (ZenityFormsData, 1); @@ -1221,7 +1206,6 @@ zenity_list_pre_callback (GOptionContext *context, GOptionGroup *group, return TRUE; } -#ifdef HAVE_LIBNOTIFY static gboolean zenity_notification_pre_callback (GOptionContext *context, GOptionGroup *group, gpointer data, GError **error) @@ -1232,7 +1216,6 @@ zenity_notification_pre_callback (GOptionContext *context, GOptionGroup *group, return TRUE; } -#endif static gboolean zenity_progress_pre_callback (GOptionContext *context, GOptionGroup *group, @@ -1609,7 +1592,6 @@ zenity_list_post_callback (GOptionContext *context, GOptionGroup *group, return TRUE; } -#ifdef HAVE_LIBNOTIFY static gboolean zenity_notification_post_callback (GOptionContext *context, GOptionGroup *group, gpointer data, GError **error) @@ -1623,8 +1605,6 @@ zenity_notification_post_callback (GOptionContext *context, GOptionGroup *group, zenity_general_dialog_text; results->notification_data->listen = zenity_notification_listen; results->notification_data->icon = zenity_notification_icon; - results->notification_data->notification_hints = - zenity_notification_hints; } else { @@ -1636,7 +1616,6 @@ zenity_notification_post_callback (GOptionContext *context, GOptionGroup *group, } return TRUE; } -#endif static gboolean zenity_progress_post_callback (GOptionContext *context, GOptionGroup *group, @@ -2025,7 +2004,6 @@ zenity_create_context (void) g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE); g_option_context_add_group (tmp_ctx, a_group); -#ifdef HAVE_LIBNOTIFY /* Adds notification option entries */ a_group = g_option_group_new ("notification", N_ ("Notification icon options"), @@ -2039,7 +2017,6 @@ zenity_create_context (void) g_option_group_set_error_hook (a_group, zenity_option_error_callback); g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE); g_option_context_add_group (tmp_ctx, a_group); -#endif /* Adds progress option entries */ a_group = g_option_group_new ("progress", diff --git a/src/option.h b/src/option.h index 40cdcb0..df4150a 100644 --- a/src/option.h +++ b/src/option.h @@ -41,9 +41,7 @@ typedef enum { MODE_WARNING, MODE_SCALE, MODE_INFO, -#ifdef HAVE_LIBNOTIFY MODE_NOTIFICATION, -#endif MODE_COLOR, MODE_PASSWORD, MODE_FORMS, @@ -71,9 +69,7 @@ typedef struct { ZenityProgressData *progress_data; ZenityTextData *text_data; ZenityTreeData *tree_data; -#ifdef HAVE_LIBNOTIFY ZenityNotificationData *notification_data; -#endif ZenityColorData *color_data; ZenityPasswordData *password_data; ZenityFormsData *forms_data; @@ -30,9 +30,6 @@ * Tom Tromey <tromey@redhat.com> */ -#include "config.h" - -#include "config.h" #include "util.h" #include "zenity.h" #include <errno.h> @@ -42,11 +39,14 @@ #include <stdlib.h> #include <string.h> +#include "config.h" + #define ZENITY_OK_DEFAULT 0 #define ZENITY_CANCEL_DEFAULT 1 #define ZENITY_ESC_DEFAULT 1 #define ZENITY_ERROR_DEFAULT -1 #define ZENITY_EXTRA_DEFAULT 127 +#define ZENITY_UI_RESOURCE_PATH RESOURCE_BASE_PATH "/zenity.ui" GtkBuilder * zenity_util_load_ui_file (const char *root_widget, ...) @@ -41,8 +41,6 @@ G_BEGIN_DECLS -#define ZENITY_UI_RESOURCE_PATH "/org/gnome/Zenity/zenity.ui" - #define ZENITY_IMAGE_FULLPATH(filename) (PACKAGE_DATADIR "/" filename) GtkBuilder *zenity_util_load_ui_file (const char *widget_root, diff --git a/src/zenity.h b/src/zenity.h index 8eb8553..bcfb83b 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -125,14 +125,12 @@ typedef struct { const char **data; } ZenityTreeData; -#ifdef HAVE_LIBNOTIFY typedef struct { char *notification_text; gboolean listen; char *icon; - char **notification_hints; +// char **notification_hints; } ZenityNotificationData; -#endif typedef struct { char *color; @@ -179,10 +177,8 @@ void zenity_entry (ZenityData *data, ZenityEntryData *entry_data); void zenity_progress (ZenityData *data, ZenityProgressData *progress_data); void zenity_text (ZenityData *data, ZenityTextData *text_data); void zenity_tree (ZenityData *data, ZenityTreeData *tree_data); -#ifdef HAVE_LIBNOTIFY void zenity_notification (ZenityData *data, ZenityNotificationData *notification_data); -#endif void zenity_colorselection ( ZenityData *data, ZenityColorData *notification_data); |