From bbcb2a3783de925b93707b8e76110ec9ebaed552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 18 Sep 2012 22:51:08 +0200 Subject: [PATCH] msg: Add an option to set a custom dialog icon The predefined dialog icons work well in many cases, but sometimes it makes sense to use a more specific icon, so add an option to specify an icon-name to use instead. https://bugzilla.gnome.org/show_bug.cgi?id=684329 --- src/msg.c | 9 +++++++++ src/option.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/zenity.h | 1 + src/zenity.ui | 8 ++++---- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/msg.c b/src/msg.c index 505f961..229f0ce 100644 --- a/src/msg.c +++ b/src/msg.c @@ -58,12 +58,14 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) GtkWidget *dialog; GtkWidget *ok_button; GObject *text; + GObject *image; switch (msg_data->mode) { case ZENITY_MSG_WARNING: builder = zenity_util_load_ui_file ("zenity_warning_dialog", NULL); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_warning_dialog")); text = gtk_builder_get_object (builder, "zenity_warning_text"); + image = gtk_builder_get_object (builder, "zenity_warning_image"); ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_warning_ok_button")); break; @@ -71,6 +73,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) builder = zenity_util_load_ui_file ("zenity_question_dialog", NULL); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_question_dialog")); text = gtk_builder_get_object (builder, "zenity_question_text"); + image = gtk_builder_get_object (builder, "zenity_question_image"); ok_button = NULL; break; @@ -78,6 +81,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) builder = zenity_util_load_ui_file ("zenity_error_dialog", NULL); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_error_dialog")); text = gtk_builder_get_object (builder, "zenity_error_text"); + image = gtk_builder_get_object (builder, "zenity_error_image"); ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_error_ok_button")); break; @@ -85,6 +89,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) builder = zenity_util_load_ui_file ("zenity_info_dialog", NULL); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_info_dialog")); text = gtk_builder_get_object (builder, "zenity_info_text"); + image = gtk_builder_get_object (builder, "zenity_info_image"); ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_info_ok_button")); break; @@ -92,6 +97,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) builder = NULL; dialog = NULL; text = NULL; + image = NULL; ok_button = NULL; g_assert_not_reached (); break; @@ -152,6 +158,9 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) else gtk_label_set_markup (GTK_LABEL (text), g_strcompress (msg_data->dialog_text)); } + + if (msg_data->dialog_icon) + gtk_image_set_from_icon_name (GTK_IMAGE (image), msg_data->dialog_icon, GTK_ICON_SIZE_DIALOG); if (msg_data->no_wrap) gtk_label_set_line_wrap (GTK_LABEL (text), FALSE); diff --git a/src/option.c b/src/option.c index ba4691d..13275d1 100644 --- a/src/option.c +++ b/src/option.c @@ -35,6 +35,7 @@ static gchar *zenity_general_window_icon; static int zenity_general_width; static int zenity_general_height; static gchar *zenity_general_dialog_text; +static gchar *zenity_general_dialog_icon; static gchar *zenity_general_separator; static gboolean zenity_general_multiple; static gboolean zenity_general_editable; @@ -347,6 +348,15 @@ static GOptionEntry error_options[] = { N_("Set the dialog text"), N_("TEXT") }, + { + "icon-name", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_general_dialog_icon, + N_("Set the dialog icon"), + N_("ICON-NAME") + }, { "no-wrap", '\0', @@ -388,6 +398,15 @@ static GOptionEntry info_options[] = { N_("Set the dialog text"), N_("TEXT") }, + { + "icon-name", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_general_dialog_icon, + N_("Set the dialog icon"), + N_("ICON-NAME") + }, { "no-wrap", '\0', @@ -731,6 +750,15 @@ static GOptionEntry question_options[] = { N_("Set the dialog text"), N_("TEXT") }, + { + "icon-name", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_general_dialog_icon, + N_("Set the dialog icon"), + N_("ICON-NAME") + }, { "no-wrap", '\0', @@ -843,6 +871,15 @@ static GOptionEntry warning_options[] = { N_("Set the dialog text"), N_("TEXT") }, + { + "icon-name", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_general_dialog_icon, + N_("Set the dialog icon"), + N_("ICON-NAME") + }, { "no-wrap", '\0', @@ -1627,6 +1664,7 @@ zenity_error_post_callback (GOptionContext *context, 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->mode = ZENITY_MSG_ERROR; results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_markup = zenity_general_dialog_no_markup; @@ -1645,6 +1683,7 @@ zenity_info_post_callback (GOptionContext *context, 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->mode = ZENITY_MSG_INFO; results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_markup = zenity_general_dialog_no_markup; @@ -1819,6 +1858,7 @@ zenity_question_post_callback (GOptionContext *context, zenity_option_set_dialog_mode (zenity_question_active, MODE_QUESTION); 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->mode = ZENITY_MSG_QUESTION; results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_markup = zenity_general_dialog_no_markup; @@ -1863,6 +1903,7 @@ zenity_warning_post_callback (GOptionContext *context, 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->mode = ZENITY_MSG_WARNING; results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_markup = zenity_general_dialog_no_markup; diff --git a/src/zenity.h b/src/zenity.h index 2eec3aa..4c94129 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -61,6 +61,7 @@ typedef enum { typedef struct { gchar *dialog_text; + gchar *dialog_icon; MsgMode mode; gboolean no_wrap; gboolean no_markup; diff --git a/src/zenity.ui b/src/zenity.ui index d656ad4..ee89093 100644 --- a/src/zenity.ui +++ b/src/zenity.ui @@ -299,7 +299,7 @@ 5 12 - + True False 0 @@ -500,7 +500,7 @@ 5 12 - + True False 0 @@ -677,7 +677,7 @@ 5 12 - + True False 0 @@ -1101,7 +1101,7 @@ 5 12 - + True False 0