diff options
author | Logan Rathbone <poprocks@gmail.com> | 2022-01-12 01:28:20 -0500 |
---|---|---|
committer | Logan Rathbone <poprocks@gmail.com> | 2022-01-12 01:28:20 -0500 |
commit | c686bdb1b45e95acf010efd9ca0c75527fbb4dea (patch) | |
tree | e282c7e781d10d5e4a2fcfcf4cddccb6a9dac20c | |
parent | f139f34c514baa09100f3fd9ad556428c7d33e6f (diff) | |
download | zenity-c686bdb1b45e95acf010efd9ca0c75527fbb4dea.tar.gz |
Icon handling improvements.
Update manpage to reflect proper usage of --icon.
Add handling of zenity3 --window-icon option, with deprecation warning.
-rw-r--r-- | data/zenity.1 | 2 | ||||
-rw-r--r-- | src/msg.c | 8 | ||||
-rw-r--r-- | src/notification.c | 17 | ||||
-rw-r--r-- | src/option.c | 124 | ||||
-rw-r--r-- | src/util.c | 24 | ||||
-rw-r--r-- | src/util.h | 1 | ||||
-rw-r--r-- | src/zenity.h | 1 |
7 files changed, 133 insertions, 44 deletions
diff --git a/data/zenity.1 b/data/zenity.1 index d876044..6f7f9bf 100644 --- a/data/zenity.1 +++ b/data/zenity.1 @@ -76,7 +76,7 @@ find . \-name '*.h' | zenity \-\-list \-\-title "Search Results" \-\-text "Findi .PP Show a passive notification .IP -zenity \-\-notification \-\-icon=update.png \-\-text "System update necessary!" +zenity \-\-notification \-\-icon=software-update-available \-\-text "System update necessary!" .PP Display a weekly shopping list in a check list dialog with \fIApples\fP and \fIOranges\fP pre selected .IP @@ -234,8 +234,12 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) gtk_label_set_ellipsize (GTK_LABEL (text), PANGO_ELLIPSIZE_END); if (msg_data->dialog_icon) - gtk_image_set_from_icon_name ( - GTK_IMAGE (image), msg_data->dialog_icon); + { + g_autoptr(GIcon) icon = NULL; + + icon = zenity_util_gicon_from_string (msg_data->dialog_icon); + gtk_image_set_from_gicon (GTK_IMAGE (image), icon); + } if (msg_data->no_wrap) gtk_label_set_wrap (GTK_LABEL(text), FALSE); diff --git a/src/notification.c b/src/notification.c index 75c3035..dc25e59 100644 --- a/src/notification.c +++ b/src/notification.c @@ -51,8 +51,6 @@ 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 @@ -72,20 +70,9 @@ zenity_notification_new (char *message, char *icon_path) if (icon_path) { - icon_file = g_file_new_for_path (icon_path); - - if (g_file_query_exists (icon_file, NULL)) - { - icon = g_file_icon_new (icon_file); - } - else - { - g_debug (_("Icon filename %s not found; trying theme icon."), - icon_path); - icon = g_themed_icon_new_with_default_fallbacks (icon_path); -// icon = g_themed_icon_new (icon_path); - } + g_autoptr(GIcon) icon = NULL; + icon = zenity_util_gicon_from_string (icon_path); g_notification_set_icon (notif, icon); } diff --git a/src/option.c b/src/option.c index 5da6a8f..ee58af1 100644 --- a/src/option.c +++ b/src/option.c @@ -38,7 +38,7 @@ static char *zenity_general_dialog_title; static int zenity_general_width; static int zenity_general_height; static char *zenity_general_dialog_text; -static char *zenity_general_dialog_icon; +static char *zenity_general_icon; static char *zenity_general_separator; static gboolean zenity_general_multiple; static gboolean zenity_general_editable; @@ -90,7 +90,6 @@ static gboolean zenity_list_mid_search; /* Notification Dialog Options */ static gboolean zenity_notification_active; static gboolean zenity_notification_listen; -static char *zenity_notification_icon; /* Progress Dialog Options */ static gboolean zenity_progress_active; @@ -151,6 +150,10 @@ static char **zenity_forms_combo_values; static gboolean zenity_misc_about; static gboolean zenity_misc_version; +/* DEPRECATED Options */ + +static char *zenity_general_icon_DEPRECATED; + static gboolean zenity_forms_callback (const char *option_name, const char *value, gpointer data, GError **error); @@ -305,12 +308,19 @@ static GOptionEntry error_options[] = &zenity_general_dialog_text, N_ ("Set the dialog text"), N_ ("TEXT")}, - {"icon-name", + {"icon", '\0', G_OPTION_FLAG_NOALIAS, G_OPTION_ARG_STRING, - &zenity_general_dialog_icon, - N_ ("Set the dialog icon"), + &zenity_general_icon, + N_ ("Set the icon name"), + N_ ("ICON-NAME")}, + {"window-icon", + '\0', + G_OPTION_FLAG_HIDDEN, + G_OPTION_ARG_STRING, + &zenity_general_icon_DEPRECATED, + N_ ("DEPRECATED; use `--icon`"), N_ ("ICON-NAME")}, {"no-wrap", '\0', @@ -352,12 +362,19 @@ static GOptionEntry info_options[] = &zenity_general_dialog_text, N_ ("Set the dialog text"), N_ ("TEXT")}, - {"icon-name", + {"icon", '\0', G_OPTION_FLAG_NOALIAS, G_OPTION_ARG_STRING, - &zenity_general_dialog_icon, - N_ ("Set the dialog icon"), + &zenity_general_icon, + N_ ("Set the icon name"), + N_ ("ICON-NAME")}, + {"window-icon", + '\0', + G_OPTION_FLAG_HIDDEN, + G_OPTION_ARG_STRING, + &zenity_general_icon_DEPRECATED, + N_ ("DEPRECATED; use `--icon`"), N_ ("ICON-NAME")}, {"no-wrap", '\0', @@ -553,11 +570,18 @@ static GOptionEntry notification_options[] = N_ ("TEXT")}, {"icon", '\0', - 0, - G_OPTION_ARG_FILENAME, - &zenity_notification_icon, - N_ ("Set the notification icon"), - N_ ("ICONPATH")}, + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_general_icon, + N_ ("Set the icon name"), + N_ ("ICON-NAME")}, + {"window-icon", + '\0', + G_OPTION_FLAG_HIDDEN, + G_OPTION_ARG_STRING, + &zenity_general_icon_DEPRECATED, + N_ ("DEPRECATED; use `--icon`"), + N_ ("ICON-NAME")}, {"listen", '\0', 0, @@ -643,12 +667,19 @@ static GOptionEntry question_options[] = &zenity_general_dialog_text, N_ ("Set the dialog text"), N_ ("TEXT")}, - {"icon-name", + {"icon", '\0', G_OPTION_FLAG_NOALIAS, G_OPTION_ARG_STRING, - &zenity_general_dialog_icon, - N_ ("Set the dialog icon"), + &zenity_general_icon, + N_ ("Set the icon name"), + N_ ("ICON-NAME")}, + {"window-icon", + '\0', + G_OPTION_FLAG_HIDDEN, + G_OPTION_ARG_STRING, + &zenity_general_icon_DEPRECATED, + N_ ("DEPRECATED; use `--icon`"), N_ ("ICON-NAME")}, {"no-wrap", '\0', @@ -775,12 +806,19 @@ static GOptionEntry warning_options[] = &zenity_general_dialog_text, N_ ("Set the dialog text"), N_ ("TEXT")}, - {"icon-name", + {"icon", '\0', G_OPTION_FLAG_NOALIAS, G_OPTION_ARG_STRING, - &zenity_general_dialog_icon, - N_ ("Set the dialog icon"), + &zenity_general_icon, + N_ ("Set the icon name"), + N_ ("ICON-NAME")}, + {"window-icon", + '\0', + G_OPTION_FLAG_HIDDEN, + G_OPTION_ARG_STRING, + &zenity_general_icon_DEPRECATED, + N_ ("DEPRECATED; use `--icon`"), N_ ("ICON-NAME")}, {"no-wrap", '\0', @@ -1212,7 +1250,6 @@ zenity_notification_pre_callback (GOptionContext *context, GOptionGroup *group, { zenity_notification_active = FALSE; zenity_notification_listen = FALSE; - zenity_notification_icon = NULL; return TRUE; } @@ -1436,6 +1473,13 @@ zenity_entry_post_callback (GOptionContext *context, GOptionGroup *group, return TRUE; } +static void +show_window_icon_deprecation_warning (void) +{ + g_printerr ("Warning: --window-icon is deprecated and will be removed in a " + "future version of zenity. Please use --icon instead.\n"); +} + static gboolean zenity_error_post_callback (GOptionContext *context, GOptionGroup *group, gpointer data, GError **error) @@ -1445,11 +1489,17 @@ zenity_error_post_callback (GOptionContext *context, GOptionGroup *group, if (results->mode == MODE_ERROR) { results->msg_data->dialog_text = zenity_general_dialog_text; - results->msg_data->dialog_icon = zenity_general_dialog_icon; + results->msg_data->dialog_icon = zenity_general_icon; results->msg_data->mode = ZENITY_MSG_ERROR; results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_markup = zenity_general_dialog_no_markup; results->msg_data->ellipsize = zenity_general_dialog_ellipsize; + + if (zenity_general_icon_DEPRECATED) + { + results->msg_data->dialog_icon = zenity_general_icon_DEPRECATED; + show_window_icon_deprecation_warning (); + } } return TRUE; @@ -1464,11 +1514,17 @@ zenity_info_post_callback (GOptionContext *context, GOptionGroup *group, if (results->mode == MODE_INFO) { results->msg_data->dialog_text = zenity_general_dialog_text; - results->msg_data->dialog_icon = zenity_general_dialog_icon; + results->msg_data->dialog_icon = zenity_general_icon; results->msg_data->mode = ZENITY_MSG_INFO; results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_markup = zenity_general_dialog_no_markup; results->msg_data->ellipsize = zenity_general_dialog_ellipsize; + + if (zenity_general_icon_DEPRECATED) + { + results->msg_data->dialog_icon = zenity_general_icon_DEPRECATED; + show_window_icon_deprecation_warning (); + } } return TRUE; @@ -1604,7 +1660,13 @@ zenity_notification_post_callback (GOptionContext *context, GOptionGroup *group, results->notification_data->notification_text = zenity_general_dialog_text; results->notification_data->listen = zenity_notification_listen; - results->notification_data->icon = zenity_notification_icon; + results->notification_data->icon = zenity_general_icon; + + if (zenity_general_icon_DEPRECATED) + { + results->notification_data->icon = zenity_general_icon_DEPRECATED; + show_window_icon_deprecation_warning (); + } } else { @@ -1682,7 +1744,7 @@ zenity_question_post_callback (GOptionContext *context, GOptionGroup *group, if (results->mode == MODE_QUESTION) { results->msg_data->dialog_text = zenity_general_dialog_text; - results->msg_data->dialog_icon = zenity_general_dialog_icon; + results->msg_data->dialog_icon = zenity_general_icon; if (zenity_question_switch) results->msg_data->mode = ZENITY_MSG_SWITCH; else @@ -1691,6 +1753,12 @@ zenity_question_post_callback (GOptionContext *context, GOptionGroup *group, results->msg_data->no_markup = zenity_general_dialog_no_markup; results->msg_data->ellipsize = zenity_general_dialog_ellipsize; results->msg_data->default_cancel = zenity_question_default_cancel; + + if (zenity_general_icon_DEPRECATED) + { + results->msg_data->dialog_icon = zenity_general_icon_DEPRECATED; + show_window_icon_deprecation_warning (); + } } if (zenity_question_switch && zenity_general_extra_buttons == NULL) @@ -1749,11 +1817,17 @@ zenity_warning_post_callback (GOptionContext *context, GOptionGroup *group, if (results->mode == MODE_WARNING) { results->msg_data->dialog_text = zenity_general_dialog_text; - results->msg_data->dialog_icon = zenity_general_dialog_icon; + results->msg_data->dialog_icon = zenity_general_icon; results->msg_data->mode = ZENITY_MSG_WARNING; results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_markup = zenity_general_dialog_no_markup; results->msg_data->ellipsize = zenity_general_dialog_ellipsize; + + if (zenity_general_icon_DEPRECATED) + { + results->msg_data->dialog_icon = zenity_general_icon_DEPRECATED; + show_window_icon_deprecation_warning (); + } } return TRUE; @@ -48,6 +48,30 @@ #define ZENITY_EXTRA_DEFAULT 127 #define ZENITY_UI_RESOURCE_PATH RESOURCE_BASE_PATH "/zenity.ui" +GIcon * +zenity_util_gicon_from_string (const char *str) +{ + GIcon *icon = NULL; + g_autoptr(GFile) icon_file = NULL; + + if (str) + { + icon_file = g_file_new_for_path (str); + + if (g_file_query_exists (icon_file, NULL)) + { + icon = g_file_icon_new (icon_file); + } + else + { + g_debug (_("Icon filename %s not found; trying theme icon."), str); + icon = g_themed_icon_new_with_default_fallbacks (str); + } + } + + return icon; +} + GtkBuilder * zenity_util_load_ui_file (const char *root_widget, ...) { @@ -43,6 +43,7 @@ G_BEGIN_DECLS #define ZENITY_IMAGE_FULLPATH(filename) (PACKAGE_DATADIR "/" filename) +GIcon *zenity_util_gicon_from_string (const char *str); GtkBuilder *zenity_util_load_ui_file (const char *widget_root, ...) G_GNUC_NULL_TERMINATED; char *zenity_util_strip_newline (char *string); diff --git a/src/zenity.h b/src/zenity.h index bcfb83b..0316ce5 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -129,7 +129,6 @@ typedef struct { char *notification_text; gboolean listen; char *icon; -// char **notification_hints; } ZenityNotificationData; typedef struct { |