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
This commit is contained in:
Florian Müllner 2012-09-18 22:51:08 +02:00 committed by Matthias Clasen
parent 0628bd3291
commit bbcb2a3783
4 changed files with 55 additions and 4 deletions

View File

@ -58,12 +58,14 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *ok_button; GtkWidget *ok_button;
GObject *text; GObject *text;
GObject *image;
switch (msg_data->mode) { switch (msg_data->mode) {
case ZENITY_MSG_WARNING: case ZENITY_MSG_WARNING:
builder = zenity_util_load_ui_file ("zenity_warning_dialog", NULL); builder = zenity_util_load_ui_file ("zenity_warning_dialog", NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_warning_dialog")); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_warning_dialog"));
text = gtk_builder_get_object (builder, "zenity_warning_text"); 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")); ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_warning_ok_button"));
break; break;
@ -71,6 +73,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
builder = zenity_util_load_ui_file ("zenity_question_dialog", NULL); builder = zenity_util_load_ui_file ("zenity_question_dialog", NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_question_dialog")); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_question_dialog"));
text = gtk_builder_get_object (builder, "zenity_question_text"); text = gtk_builder_get_object (builder, "zenity_question_text");
image = gtk_builder_get_object (builder, "zenity_question_image");
ok_button = NULL; ok_button = NULL;
break; break;
@ -78,6 +81,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
builder = zenity_util_load_ui_file ("zenity_error_dialog", NULL); builder = zenity_util_load_ui_file ("zenity_error_dialog", NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_error_dialog")); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_error_dialog"));
text = gtk_builder_get_object (builder, "zenity_error_text"); 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")); ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_error_ok_button"));
break; break;
@ -85,6 +89,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
builder = zenity_util_load_ui_file ("zenity_info_dialog", NULL); builder = zenity_util_load_ui_file ("zenity_info_dialog", NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_info_dialog")); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_info_dialog"));
text = gtk_builder_get_object (builder, "zenity_info_text"); 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")); ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_info_ok_button"));
break; break;
@ -92,6 +97,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
builder = NULL; builder = NULL;
dialog = NULL; dialog = NULL;
text = NULL; text = NULL;
image = NULL;
ok_button = NULL; ok_button = NULL;
g_assert_not_reached (); g_assert_not_reached ();
break; break;
@ -153,6 +159,9 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
gtk_label_set_markup (GTK_LABEL (text), g_strcompress (msg_data->dialog_text)); 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) if (msg_data->no_wrap)
gtk_label_set_line_wrap (GTK_LABEL (text), FALSE); gtk_label_set_line_wrap (GTK_LABEL (text), FALSE);

View File

@ -35,6 +35,7 @@ static gchar *zenity_general_window_icon;
static int zenity_general_width; static int zenity_general_width;
static int zenity_general_height; static int zenity_general_height;
static gchar *zenity_general_dialog_text; static gchar *zenity_general_dialog_text;
static gchar *zenity_general_dialog_icon;
static gchar *zenity_general_separator; static gchar *zenity_general_separator;
static gboolean zenity_general_multiple; static gboolean zenity_general_multiple;
static gboolean zenity_general_editable; static gboolean zenity_general_editable;
@ -347,6 +348,15 @@ static GOptionEntry error_options[] = {
N_("Set the dialog text"), N_("Set the dialog text"),
N_("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", "no-wrap",
'\0', '\0',
@ -388,6 +398,15 @@ static GOptionEntry info_options[] = {
N_("Set the dialog text"), N_("Set the dialog text"),
N_("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", "no-wrap",
'\0', '\0',
@ -731,6 +750,15 @@ static GOptionEntry question_options[] = {
N_("Set the dialog text"), N_("Set the dialog text"),
N_("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", "no-wrap",
'\0', '\0',
@ -843,6 +871,15 @@ static GOptionEntry warning_options[] = {
N_("Set the dialog text"), N_("Set the dialog text"),
N_("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", "no-wrap",
'\0', '\0',
@ -1627,6 +1664,7 @@ zenity_error_post_callback (GOptionContext *context,
if (results->mode == MODE_ERROR) { if (results->mode == MODE_ERROR) {
results->msg_data->dialog_text = zenity_general_dialog_text; 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->mode = ZENITY_MSG_ERROR;
results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_wrap = zenity_general_dialog_no_wrap;
results->msg_data->no_markup = zenity_general_dialog_no_markup; 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) { if (results->mode == MODE_INFO) {
results->msg_data->dialog_text = zenity_general_dialog_text; 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->mode = ZENITY_MSG_INFO;
results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_wrap = zenity_general_dialog_no_wrap;
results->msg_data->no_markup = zenity_general_dialog_no_markup; 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); zenity_option_set_dialog_mode (zenity_question_active, MODE_QUESTION);
if (results->mode == MODE_QUESTION) { if (results->mode == MODE_QUESTION) {
results->msg_data->dialog_text = zenity_general_dialog_text; 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->mode = ZENITY_MSG_QUESTION;
results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_wrap = zenity_general_dialog_no_wrap;
results->msg_data->no_markup = zenity_general_dialog_no_markup; 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) { if (results->mode == MODE_WARNING) {
results->msg_data->dialog_text = zenity_general_dialog_text; 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->mode = ZENITY_MSG_WARNING;
results->msg_data->no_wrap = zenity_general_dialog_no_wrap; results->msg_data->no_wrap = zenity_general_dialog_no_wrap;
results->msg_data->no_markup = zenity_general_dialog_no_markup; results->msg_data->no_markup = zenity_general_dialog_no_markup;

View File

@ -61,6 +61,7 @@ typedef enum {
typedef struct { typedef struct {
gchar *dialog_text; gchar *dialog_text;
gchar *dialog_icon;
MsgMode mode; MsgMode mode;
gboolean no_wrap; gboolean no_wrap;
gboolean no_markup; gboolean no_markup;

View File

@ -299,7 +299,7 @@
<property name="border_width">5</property> <property name="border_width">5</property>
<property name="spacing">12</property> <property name="spacing">12</property>
<child> <child>
<object class="GtkImage" id="image3"> <object class="GtkImage" id="zenity_error_image">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="yalign">0</property> <property name="yalign">0</property>
@ -500,7 +500,7 @@
<property name="border_width">5</property> <property name="border_width">5</property>
<property name="spacing">12</property> <property name="spacing">12</property>
<child> <child>
<object class="GtkImage" id="image4"> <object class="GtkImage" id="zenity_info_image">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="yalign">0</property> <property name="yalign">0</property>
@ -677,7 +677,7 @@
<property name="border_width">5</property> <property name="border_width">5</property>
<property name="spacing">12</property> <property name="spacing">12</property>
<child> <child>
<object class="GtkImage" id="image1"> <object class="GtkImage" id="zenity_question_image">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">0</property> <property name="xalign">0</property>
@ -1101,7 +1101,7 @@
<property name="border_width">5</property> <property name="border_width">5</property>
<property name="spacing">12</property> <property name="spacing">12</property>
<child> <child>
<object class="GtkImage" id="image2"> <object class="GtkImage" id="zenity_warning_image">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">0</property> <property name="xalign">0</property>