~nik90/ubuntu/precise/eog/keywords

« back to all changes in this revision

Viewing changes to src/eog-error-message-area.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-07-26 15:28:21 UTC
  • mto: This revision was merged to the branch mainline in revision 116.
  • Revision ID: james.westby@ubuntu.com-20110726152821-g806mbptn727m1a5
Tags: upstream-3.1.4
Import upstream version 3.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include <glib-object.h>
35
35
#include <gtk/gtk.h>
36
36
 
 
37
typedef enum {
 
38
        EOG_ERROR_MESSAGE_AREA_NO_BUTTONS    = 0,
 
39
        EOG_ERROR_MESSAGE_AREA_CANCEL_BUTTON = 1 << 0,
 
40
        EOG_ERROR_MESSAGE_AREA_RELOAD_BUTTON = 1 << 1,
 
41
        EOG_ERROR_MESSAGE_AREA_SAVEAS_BUTTON = 1 << 2
 
42
} EogErrorMessageAreaButtons;
 
43
 
37
44
static void
38
45
set_message_area_text_and_icon (GtkInfoBar   *message_area,
39
46
                                const gchar  *icon_stock_id,
97
104
}
98
105
 
99
106
static GtkWidget *
100
 
create_error_message_area (const gchar *primary_text,
101
 
                           const gchar *secondary_text,
102
 
                           gboolean     recoverable)
 
107
create_error_message_area (const gchar                 *primary_text,
 
108
                           const gchar                 *secondary_text,
 
109
                           EogErrorMessageAreaButtons   buttons)
103
110
{
104
111
        GtkWidget *message_area;
105
112
 
106
 
        if (recoverable)
107
 
                message_area = gtk_info_bar_new_with_buttons (_("_Retry"),
108
 
                                                              GTK_RESPONSE_OK,
109
 
                                                              NULL);
110
 
        else
111
 
                message_area = gtk_info_bar_new ();
112
 
 
 
113
        /* create a new message area */
 
114
        message_area = gtk_info_bar_new ();
 
115
 
 
116
        /* add requested buttons to the message area */
 
117
        if (buttons & EOG_ERROR_MESSAGE_AREA_CANCEL_BUTTON)
 
118
                gtk_info_bar_add_button (GTK_INFO_BAR (message_area),
 
119
                                         _("_Cancel"),
 
120
                                         EOG_ERROR_MESSAGE_AREA_RESPONSE_CANCEL);
 
121
 
 
122
        if (buttons & EOG_ERROR_MESSAGE_AREA_RELOAD_BUTTON)
 
123
                gtk_info_bar_add_button (GTK_INFO_BAR (message_area),
 
124
                                         _("_Reload"),
 
125
                                         EOG_ERROR_MESSAGE_AREA_RESPONSE_RELOAD);
 
126
 
 
127
        if (buttons & EOG_ERROR_MESSAGE_AREA_SAVEAS_BUTTON)
 
128
                gtk_info_bar_add_button (GTK_INFO_BAR (message_area),
 
129
                                         _("Save _As…"),
 
130
                                         EOG_ERROR_MESSAGE_AREA_RESPONSE_SAVEAS);
 
131
 
 
132
        /* set message type */
113
133
        gtk_info_bar_set_message_type (GTK_INFO_BAR (message_area),
114
134
                                       GTK_MESSAGE_ERROR);
115
135
 
 
136
        /* set text and icon */
116
137
        set_message_area_text_and_icon (GTK_INFO_BAR (message_area),
117
138
                                        GTK_STOCK_DIALOG_ERROR,
118
139
                                        primary_text,
123
144
 
124
145
/**
125
146
 * eog_image_load_error_message_area_new: (skip):
126
 
 * @caption: 
127
 
 * @error: 
128
 
 *
129
 
 * 
 
147
 * @caption:
 
148
 * @error:
 
149
 *
 
150
 *
130
151
 *
131
152
 * Returns: (transfer full): a new #GtkInfoBar
132
153
 **/
154
175
 
155
176
        message_area = create_error_message_area (error_message,
156
177
                                                  message_details,
157
 
                                                  TRUE);
 
178
                                                  EOG_ERROR_MESSAGE_AREA_CANCEL_BUTTON);
 
179
 
 
180
        g_free (pango_escaped_caption);
 
181
        g_free (error_message);
 
182
        g_free (message_details);
 
183
 
 
184
        return message_area;
 
185
}
 
186
 
 
187
/**
 
188
 * eog_image_save_error_message_area_new: (skip):
 
189
 * @caption:
 
190
 * @error:
 
191
 *
 
192
 *
 
193
 *
 
194
 * Returns: (transfer full): a new #GtkInfoBar
 
195
 **/
 
196
GtkWidget *
 
197
eog_image_save_error_message_area_new (const gchar  *caption,
 
198
                                       const GError *error)
 
199
{
 
200
        GtkWidget *message_area;
 
201
        gchar *error_message = NULL;
 
202
        gchar *message_details = NULL;
 
203
        gchar *pango_escaped_caption = NULL;
 
204
 
 
205
        g_return_val_if_fail (caption != NULL, NULL);
 
206
        g_return_val_if_fail (error != NULL, NULL);
 
207
 
 
208
        /* Escape the caption string with respect to pango markup.
 
209
           This is necessary because otherwise characters like "&" will
 
210
           be interpreted as the beginning of a pango entity inside
 
211
           the message area GtkLabel. */
 
212
        pango_escaped_caption = g_markup_escape_text (caption, -1);
 
213
        error_message = g_strdup_printf (_("Could not save image '%s'."),
 
214
                                         pango_escaped_caption);
 
215
 
 
216
        message_details = g_strdup (error->message);
 
217
 
 
218
        message_area = create_error_message_area (error_message,
 
219
                                                  message_details,
 
220
                                                  EOG_ERROR_MESSAGE_AREA_CANCEL_BUTTON |
 
221
                                                  EOG_ERROR_MESSAGE_AREA_SAVEAS_BUTTON);
158
222
 
159
223
        g_free (pango_escaped_caption);
160
224
        g_free (error_message);
165
229
 
166
230
/**
167
231
 * eog_no_images_error_message_area_new: (skip):
168
 
 * @file: 
169
 
 *
170
 
 * 
 
232
 * @file:
 
233
 *
 
234
 *
171
235
 *
172
236
 * Returns: (transfer full): a new #GtkInfoBar
173
237
 **/
201
265
 
202
266
        message_area = create_error_message_area (error_message,
203
267
                                                  NULL,
204
 
                                                  FALSE);
 
268
                                                  EOG_ERROR_MESSAGE_AREA_NO_BUTTONS);
205
269
 
206
270
        g_free (error_message);
207
271