Commit 767ae97b5eac07b9179a7ad1e2a1ee00cbe072c0
1 parent
957aa5c9
Exists in
master
and in
1 other branch
Refactoring error popup.
Showing
15 changed files
with
66 additions
and
76 deletions
Show diff stats
src/dialogs/load.c
@@ -315,16 +315,13 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ | @@ -315,16 +315,13 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ | ||
315 | GError * error = NULL; | 315 | GError * error = NULL; |
316 | v3270_load_dialog_apply(widget,&error); | 316 | v3270_load_dialog_apply(widget,&error); |
317 | 317 | ||
318 | - if(error) | ||
319 | - { | ||
320 | - v3270_popup_gerror( | ||
321 | - widget, | ||
322 | - error, | ||
323 | - NULL, | ||
324 | - _("Can't open %s"),gtk_entry_get_text(GTK_ENTRY(V3270_LOAD_DIALOG(widget)->filename)) | ||
325 | - ); | ||
326 | - g_error_free(error); | ||
327 | - } | 318 | + // The operation has failed? If yes notify user and free error object. |
319 | + v3270_popup_gerror( | ||
320 | + widget, | ||
321 | + &error, | ||
322 | + NULL, | ||
323 | + _("Can't open %s"),gtk_entry_get_text(GTK_ENTRY(V3270_LOAD_DIALOG(widget)->filename)) | ||
324 | + ); | ||
328 | 325 | ||
329 | } | 326 | } |
330 | debug("%s",__FUNCTION__); | 327 | debug("%s",__FUNCTION__); |
src/dialogs/popups.c
@@ -44,6 +44,9 @@ | @@ -44,6 +44,9 @@ | ||
44 | 44 | ||
45 | GtkResponseType v3270_popup_dialog_show(GtkWidget *widget, const LIB3270_POPUP *popup, gboolean wait) { | 45 | GtkResponseType v3270_popup_dialog_show(GtkWidget *widget, const LIB3270_POPUP *popup, gboolean wait) { |
46 | 46 | ||
47 | + // https://developer.gnome.org/hig/stable/dialogs.html.en | ||
48 | + // https://developer.gnome.org/hig/stable/visual-layout.html.en | ||
49 | + | ||
47 | g_return_val_if_fail(GTK_IS_WIDGET(widget),GTK_RESPONSE_NONE); | 50 | g_return_val_if_fail(GTK_IS_WIDGET(widget),GTK_RESPONSE_NONE); |
48 | 51 | ||
49 | // Check if the dialog is enabled | 52 | // Check if the dialog is enabled |
@@ -178,6 +181,7 @@ | @@ -178,6 +181,7 @@ | ||
178 | GTK_RESPONSE_CANCEL | 181 | GTK_RESPONSE_CANCEL |
179 | ); | 182 | ); |
180 | 183 | ||
184 | + // https://developer.gnome.org/Buttons/ | ||
181 | v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_APPLY,"destructive-action"); | 185 | v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_APPLY,"destructive-action"); |
182 | v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_CANCEL,"suggested-action"); | 186 | v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_CANCEL,"suggested-action"); |
183 | break; | 187 | break; |
@@ -187,6 +191,8 @@ | @@ -187,6 +191,8 @@ | ||
187 | GTK_DIALOG(dialog), | 191 | GTK_DIALOG(dialog), |
188 | GTK_RESPONSE_CANCEL | 192 | GTK_RESPONSE_CANCEL |
189 | ); | 193 | ); |
194 | + | ||
195 | + // https://developer.gnome.org/Buttons/ | ||
190 | v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_CANCEL,"suggested-action"); | 196 | v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_CANCEL,"suggested-action"); |
191 | break; | 197 | break; |
192 | 198 | ||
@@ -195,6 +201,8 @@ | @@ -195,6 +201,8 @@ | ||
195 | GTK_DIALOG(dialog), | 201 | GTK_DIALOG(dialog), |
196 | GTK_RESPONSE_APPLY | 202 | GTK_RESPONSE_APPLY |
197 | ); | 203 | ); |
204 | + | ||
205 | + // https://developer.gnome.org/Buttons/ | ||
198 | v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_APPLY,"suggested-action"); | 206 | v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_APPLY,"suggested-action"); |
199 | break; | 207 | break; |
200 | 208 | ||
@@ -260,7 +268,10 @@ | @@ -260,7 +268,10 @@ | ||
260 | 268 | ||
261 | } | 269 | } |
262 | 270 | ||
263 | - void v3270_popup_gerror(GtkWidget *widget, GError *error, const gchar *title, const gchar *fmt, ...) { | 271 | + gboolean v3270_popup_gerror(GtkWidget *widget, GError **error, const gchar *title, const gchar *fmt, ...) { |
272 | + | ||
273 | + if(!(error && *error)) | ||
274 | + return FALSE; | ||
264 | 275 | ||
265 | // Format message. | 276 | // Format message. |
266 | va_list arg_ptr; | 277 | va_list arg_ptr; |
@@ -272,10 +283,15 @@ | @@ -272,10 +283,15 @@ | ||
272 | .type = LIB3270_NOTIFY_ERROR, | 283 | .type = LIB3270_NOTIFY_ERROR, |
273 | .title = title, | 284 | .title = title, |
274 | .summary = summary, | 285 | .summary = summary, |
275 | - .body = error->message | 286 | + .body = (*error)->message |
276 | }; | 287 | }; |
277 | 288 | ||
278 | v3270_popup_dialog_show(widget, &popup, FALSE); | 289 | v3270_popup_dialog_show(widget, &popup, FALSE); |
279 | 290 | ||
291 | + g_error_free(*error); | ||
292 | + *error = NULL; | ||
293 | + | ||
294 | + return TRUE; | ||
295 | + | ||
280 | } | 296 | } |
281 | 297 |
src/dialogs/print/convenience.c
@@ -96,15 +96,13 @@ | @@ -96,15 +96,13 @@ | ||
96 | 96 | ||
97 | if(err) | 97 | if(err) |
98 | { | 98 | { |
99 | - v3270_error_popup( | 99 | + v3270_popup_gerror( |
100 | widget, | 100 | widget, |
101 | - NULL, | 101 | + &err, |
102 | _("Print operation has failed"), | 102 | _("Print operation has failed"), |
103 | err->message | 103 | err->message |
104 | ); | 104 | ); |
105 | 105 | ||
106 | - g_error_free(err); | ||
107 | - | ||
108 | rc = -1; | 106 | rc = -1; |
109 | } | 107 | } |
110 | } | 108 | } |
src/dialogs/print/print.c
@@ -52,13 +52,11 @@ | @@ -52,13 +52,11 @@ | ||
52 | 52 | ||
53 | v3270_popup_gerror( | 53 | v3270_popup_gerror( |
54 | GTK_WIDGET(operation->widget), | 54 | GTK_WIDGET(operation->widget), |
55 | - err, | 55 | + &err, |
56 | NULL, | 56 | NULL, |
57 | "%s",_( "Print operation failed" ) | 57 | "%s",_( "Print operation failed" ) |
58 | ); | 58 | ); |
59 | 59 | ||
60 | - g_error_free(err); | ||
61 | - | ||
62 | } | 60 | } |
63 | 61 | ||
64 | if(operation->widget) | 62 | if(operation->widget) |
src/dialogs/save/save.c
@@ -618,17 +618,12 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ | @@ -618,17 +618,12 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ | ||
618 | GError * error = NULL; | 618 | GError * error = NULL; |
619 | v3270_save_dialog_apply(widget,&error); | 619 | v3270_save_dialog_apply(widget,&error); |
620 | 620 | ||
621 | - if(error) | ||
622 | - { | ||
623 | - v3270_popup_gerror( | ||
624 | - widget, | ||
625 | - error, | ||
626 | - NULL, | ||
627 | - _("Can't save %s"),gtk_entry_get_text(GTK_ENTRY(V3270_SAVE_DIALOG(widget)->filename)) | ||
628 | - ); | ||
629 | - | ||
630 | - g_error_free(error); | ||
631 | - } | 621 | + v3270_popup_gerror( |
622 | + widget, | ||
623 | + &error, | ||
624 | + NULL, | ||
625 | + _("Can't save %s"),gtk_entry_get_text(GTK_ENTRY(V3270_SAVE_DIALOG(widget)->filename)) | ||
626 | + ); | ||
632 | 627 | ||
633 | } | 628 | } |
634 | 629 |
src/dialogs/transfer.c
@@ -86,13 +86,11 @@ static void save_activity_clicked(GtkWidget *button, GObject *activity) | @@ -86,13 +86,11 @@ static void save_activity_clicked(GtkWidget *button, GObject *activity) | ||
86 | 86 | ||
87 | v3270_popup_gerror( | 87 | v3270_popup_gerror( |
88 | button, | 88 | button, |
89 | - error, | 89 | + &error, |
90 | NULL, | 90 | NULL, |
91 | _("Can't save %s"),filename | 91 | _("Can't save %s"),filename |
92 | ); | 92 | ); |
93 | 93 | ||
94 | - g_error_free(error); | ||
95 | - | ||
96 | } | 94 | } |
97 | 95 | ||
98 | } | 96 | } |
src/filetransfer/activitylist.c
@@ -431,13 +431,11 @@ | @@ -431,13 +431,11 @@ | ||
431 | 431 | ||
432 | v3270_popup_gerror( | 432 | v3270_popup_gerror( |
433 | widget, | 433 | widget, |
434 | - error, | 434 | + &error, |
435 | NULL, | 435 | NULL, |
436 | _("Can't save %s"),list->filename | 436 | _("Can't save %s"),list->filename |
437 | ); | 437 | ); |
438 | 438 | ||
439 | - g_error_free(error); | ||
440 | - | ||
441 | } | 439 | } |
442 | 440 | ||
443 | 441 |
src/filetransfer/load.c
@@ -262,18 +262,13 @@ LIB3270_EXPORT void v3270ft_load(GtkWidget *widget,const gchar *filename) { | @@ -262,18 +262,13 @@ LIB3270_EXPORT void v3270ft_load(GtkWidget *widget,const gchar *filename) { | ||
262 | g_list_foreach(GTK_V3270FT(widget)->files,(GFunc) validate_item, error); | 262 | g_list_foreach(GTK_V3270FT(widget)->files,(GFunc) validate_item, error); |
263 | v3270ft_select_last(widget); | 263 | v3270ft_select_last(widget); |
264 | 264 | ||
265 | - if(error) { | 265 | + v3270_popup_gerror( |
266 | + widget, | ||
267 | + &error, | ||
268 | + NULL, | ||
269 | + _("Can't load %s"),filename | ||
270 | + ); | ||
266 | 271 | ||
267 | - v3270_popup_gerror( | ||
268 | - widget, | ||
269 | - error, | ||
270 | - NULL, | ||
271 | - _("Can't load %s"),filename | ||
272 | - ); | ||
273 | - | ||
274 | - g_error_free(error); | ||
275 | - | ||
276 | - } | ||
277 | 272 | ||
278 | } | 273 | } |
279 | 274 |
src/filetransfer/save.c
@@ -112,13 +112,11 @@ static const gchar * getNameByFlag(LIB3270_FT_OPTION opt, LIB3270_FT_OPTION mask | @@ -112,13 +112,11 @@ static const gchar * getNameByFlag(LIB3270_FT_OPTION opt, LIB3270_FT_OPTION mask | ||
112 | 112 | ||
113 | v3270_popup_gerror( | 113 | v3270_popup_gerror( |
114 | widget, | 114 | widget, |
115 | - error, | 115 | + &error, |
116 | NULL, | 116 | NULL, |
117 | _("Can't save %s"),filename | 117 | _("Can't save %s"),filename |
118 | ); | 118 | ); |
119 | 119 | ||
120 | - g_error_free(error); | ||
121 | - | ||
122 | } | 120 | } |
123 | 121 | ||
124 | g_free(text); | 122 | g_free(text); |
src/include/v3270.h
@@ -238,13 +238,6 @@ | @@ -238,13 +238,6 @@ | ||
238 | LIB3270_EXPORT void v3270_set_remap_filename(GtkWidget *widget, const gchar *path); | 238 | LIB3270_EXPORT void v3270_set_remap_filename(GtkWidget *widget, const gchar *path); |
239 | LIB3270_EXPORT const gchar * v3270_get_remap_filename(GtkWidget *widget); | 239 | LIB3270_EXPORT const gchar * v3270_get_remap_filename(GtkWidget *widget); |
240 | 240 | ||
241 | - // SSL & Security | ||
242 | - LIB3270_EXPORT const gchar * v3270_get_ssl_state_icon_name(GtkWidget *widget); | ||
243 | - LIB3270_EXPORT const gchar * v3270_get_ssl_state_message(GtkWidget *widget); | ||
244 | - LIB3270_EXPORT const gchar * v3270_get_ssl_state_description(GtkWidget *widget); | ||
245 | - LIB3270_EXPORT GtkWidget * v3270_security_dialog_new(GtkWidget *widget); | ||
246 | - LIB3270_EXPORT void v3270_popup_security_dialog(GtkWidget *widget); | ||
247 | - | ||
248 | // Auxiliary widgets | 241 | // Auxiliary widgets |
249 | LIB3270_EXPORT void v3270_select_host(GtkWidget *widget); | 242 | LIB3270_EXPORT void v3270_select_host(GtkWidget *widget); |
250 | 243 |
src/include/v3270/dialogs.h
@@ -40,7 +40,7 @@ | @@ -40,7 +40,7 @@ | ||
40 | 40 | ||
41 | LIB3270_EXPORT GtkWidget * v3270_dialog_section_new(const gchar * title, const gchar *tooltip, GtkWidget *child); | 41 | LIB3270_EXPORT GtkWidget * v3270_dialog_section_new(const gchar * title, const gchar *tooltip, GtkWidget *child); |
42 | 42 | ||
43 | - LIB3270_EXPORT void v3270_error_popup(GtkWidget *widget, const gchar *title, const gchar *summary, const gchar *body); | 43 | + LIB3270_EXPORT void v3270_error_popup(GtkWidget *widget, const gchar *title, const gchar *summary, const gchar *body) G_GNUC_DEPRECATED; |
44 | 44 | ||
45 | LIB3270_EXPORT GtkWidget * v3270_save_dialog_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, const gchar *filename); | 45 | LIB3270_EXPORT GtkWidget * v3270_save_dialog_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, const gchar *filename); |
46 | LIB3270_EXPORT void v3270_save_dialog_run(GtkWidget *widget); | 46 | LIB3270_EXPORT void v3270_save_dialog_run(GtkWidget *widget); |
@@ -48,7 +48,19 @@ | @@ -48,7 +48,19 @@ | ||
48 | LIB3270_EXPORT GtkWidget * v3270_load_dialog_new(GtkWidget *widget, const gchar *filename); | 48 | LIB3270_EXPORT GtkWidget * v3270_load_dialog_new(GtkWidget *widget, const gchar *filename); |
49 | LIB3270_EXPORT void v3270_load_dialog_run(GtkWidget *widget); | 49 | LIB3270_EXPORT void v3270_load_dialog_run(GtkWidget *widget); |
50 | 50 | ||
51 | - LIB3270_EXPORT void v3270_popup_gerror(GtkWidget *widget, GError *error, const gchar *title, const gchar *fmt, ...) G_GNUC_PRINTF(4,5); | 51 | + /// @brief Popup an error message. |
52 | + /// | ||
53 | + /// If the error is set show popup message and "free" the error. | ||
54 | + /// | ||
55 | + /// @param widget The terminal widget. | ||
56 | + /// @param error The GError (it null doesn't show popup). | ||
57 | + /// @param title The window title (can be NULL). | ||
58 | + /// @param fmt Format for the popup message. | ||
59 | + /// @param ... Arguments for fmt. | ||
60 | + /// | ||
61 | + /// @return TRUE if the popup was sent. | ||
62 | + /// | ||
63 | + LIB3270_EXPORT gboolean v3270_popup_gerror(GtkWidget *widget, GError **error, const gchar *title, const gchar *fmt, ...) G_GNUC_PRINTF(4,5); | ||
52 | 64 | ||
53 | LIB3270_EXPORT GtkTreeModel * v3270_font_family_model_new(GtkWidget *widget, const gchar *selected, GtkTreeIter * active); | 65 | LIB3270_EXPORT GtkTreeModel * v3270_font_family_model_new(GtkWidget *widget, const gchar *selected, GtkTreeIter * active); |
54 | 66 |
src/selection/text.c
@@ -183,8 +183,7 @@ LIB3270_EXPORT void v3270_input_text(GtkWidget *widget, const gchar *text, const | @@ -183,8 +183,7 @@ LIB3270_EXPORT void v3270_input_text(GtkWidget *widget, const gchar *text, const | ||
183 | V3270_SIGNAL_PASTENEXT, | 183 | V3270_SIGNAL_PASTENEXT, |
184 | FALSE | 184 | FALSE |
185 | ); | 185 | ); |
186 | - v3270_popup_gerror(widget,error,NULL,"%s",_("Can't paste text")); | ||
187 | - g_error_free(error); | 186 | + v3270_popup_gerror(widget,&error,NULL,"%s",_("Can't paste text")); |
188 | return; | 187 | return; |
189 | } | 188 | } |
190 | 189 |
src/terminal/charset.c
@@ -317,13 +317,11 @@ | @@ -317,13 +317,11 @@ | ||
317 | { | 317 | { |
318 | v3270_popup_gerror( | 318 | v3270_popup_gerror( |
319 | widget, | 319 | widget, |
320 | - error, | 320 | + &error, |
321 | _( "Remap Failed" ), | 321 | _( "Remap Failed" ), |
322 | _( "Can't parse %s" ), path | 322 | _( "Can't parse %s" ), path |
323 | ); | 323 | ); |
324 | 324 | ||
325 | - g_error_free(error); | ||
326 | - | ||
327 | } else { | 325 | } else { |
328 | 326 | ||
329 | unsigned int i; | 327 | unsigned int i; |
src/terminal/mouse.c
@@ -38,6 +38,7 @@ | @@ -38,6 +38,7 @@ | ||
38 | #include <lib3270/log.h> | 38 | #include <lib3270/log.h> |
39 | #include <lib3270/trace.h> | 39 | #include <lib3270/trace.h> |
40 | #include <lib3270/ssl.h> | 40 | #include <lib3270/ssl.h> |
41 | + #include <v3270/security.h> | ||
41 | 42 | ||
42 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | 43 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
43 | 44 |
src/trace/trace.c
@@ -477,18 +477,12 @@ | @@ -477,18 +477,12 @@ | ||
477 | 477 | ||
478 | g_free(text); | 478 | g_free(text); |
479 | 479 | ||
480 | - if(error) | ||
481 | - { | ||
482 | - v3270_popup_gerror( | ||
483 | - widget, | ||
484 | - error, | ||
485 | - NULL, | ||
486 | - _( "Can't save %s" ), filename | ||
487 | - ); | ||
488 | - | ||
489 | - g_error_free(error); | ||
490 | - | ||
491 | - } | 480 | + v3270_popup_gerror( |
481 | + widget, | ||
482 | + &error, | ||
483 | + NULL, | ||
484 | + _( "Can't save %s" ), filename | ||
485 | + ); | ||
492 | 486 | ||
493 | } | 487 | } |
494 | 488 |