Commit 767ae97b5eac07b9179a7ad1e2a1ee00cbe072c0

Authored by Perry Werneck
1 parent 957aa5c9
Exists in master and in 1 other branch develop

Refactoring error popup.

src/dialogs/load.c
... ... @@ -315,16 +315,13 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
315 315 GError * error = NULL;
316 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 327 debug("%s",__FUNCTION__);
... ...
src/dialogs/popups.c
... ... @@ -44,6 +44,9 @@
44 44  
45 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 50 g_return_val_if_fail(GTK_IS_WIDGET(widget),GTK_RESPONSE_NONE);
48 51  
49 52 // Check if the dialog is enabled
... ... @@ -178,6 +181,7 @@
178 181 GTK_RESPONSE_CANCEL
179 182 );
180 183  
  184 + // https://developer.gnome.org/Buttons/
181 185 v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_APPLY,"destructive-action");
182 186 v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_CANCEL,"suggested-action");
183 187 break;
... ... @@ -187,6 +191,8 @@
187 191 GTK_DIALOG(dialog),
188 192 GTK_RESPONSE_CANCEL
189 193 );
  194 +
  195 + // https://developer.gnome.org/Buttons/
190 196 v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_CANCEL,"suggested-action");
191 197 break;
192 198  
... ... @@ -195,6 +201,8 @@
195 201 GTK_DIALOG(dialog),
196 202 GTK_RESPONSE_APPLY
197 203 );
  204 +
  205 + // https://developer.gnome.org/Buttons/
198 206 v3270_dialog_add_class_for_response(dialog,GTK_RESPONSE_APPLY,"suggested-action");
199 207 break;
200 208  
... ... @@ -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 276 // Format message.
266 277 va_list arg_ptr;
... ... @@ -272,10 +283,15 @@
272 283 .type = LIB3270_NOTIFY_ERROR,
273 284 .title = title,
274 285 .summary = summary,
275   - .body = error->message
  286 + .body = (*error)->message
276 287 };
277 288  
278 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 96  
97 97 if(err)
98 98 {
99   - v3270_error_popup(
  99 + v3270_popup_gerror(
100 100 widget,
101   - NULL,
  101 + &err,
102 102 _("Print operation has failed"),
103 103 err->message
104 104 );
105 105  
106   - g_error_free(err);
107   -
108 106 rc = -1;
109 107 }
110 108 }
... ...
src/dialogs/print/print.c
... ... @@ -52,13 +52,11 @@
52 52  
53 53 v3270_popup_gerror(
54 54 GTK_WIDGET(operation->widget),
55   - err,
  55 + &err,
56 56 NULL,
57 57 "%s",_( "Print operation failed" )
58 58 );
59 59  
60   - g_error_free(err);
61   -
62 60 }
63 61  
64 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 618 GError * error = NULL;
619 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 86  
87 87 v3270_popup_gerror(
88 88 button,
89   - error,
  89 + &error,
90 90 NULL,
91 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 431  
432 432 v3270_popup_gerror(
433 433 widget,
434   - error,
  434 + &error,
435 435 NULL,
436 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 262 g_list_foreach(GTK_V3270FT(widget)->files,(GFunc) validate_item, error);
263 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 112  
113 113 v3270_popup_gerror(
114 114 widget,
115   - error,
  115 + &error,
116 116 NULL,
117 117 _("Can't save %s"),filename
118 118 );
119 119  
120   - g_error_free(error);
121   -
122 120 }
123 121  
124 122 g_free(text);
... ...
src/include/v3270.h
... ... @@ -238,13 +238,6 @@
238 238 LIB3270_EXPORT void v3270_set_remap_filename(GtkWidget *widget, const gchar *path);
239 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 241 // Auxiliary widgets
249 242 LIB3270_EXPORT void v3270_select_host(GtkWidget *widget);
250 243  
... ...
src/include/v3270/dialogs.h
... ... @@ -40,7 +40,7 @@
40 40  
41 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 45 LIB3270_EXPORT GtkWidget * v3270_save_dialog_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, const gchar *filename);
46 46 LIB3270_EXPORT void v3270_save_dialog_run(GtkWidget *widget);
... ... @@ -48,7 +48,19 @@
48 48 LIB3270_EXPORT GtkWidget * v3270_load_dialog_new(GtkWidget *widget, const gchar *filename);
49 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 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 183 V3270_SIGNAL_PASTENEXT,
184 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 187 return;
189 188 }
190 189  
... ...
src/terminal/charset.c
... ... @@ -317,13 +317,11 @@
317 317 {
318 318 v3270_popup_gerror(
319 319 widget,
320   - error,
  320 + &error,
321 321 _( "Remap Failed" ),
322 322 _( "Can't parse %s" ), path
323 323 );
324 324  
325   - g_error_free(error);
326   -
327 325 } else {
328 326  
329 327 unsigned int i;
... ...
src/terminal/mouse.c
... ... @@ -38,6 +38,7 @@
38 38 #include <lib3270/log.h>
39 39 #include <lib3270/trace.h>
40 40 #include <lib3270/ssl.h>
  41 + #include <v3270/security.h>
41 42  
42 43 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
43 44  
... ...
src/trace/trace.c
... ... @@ -477,18 +477,12 @@
477 477  
478 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  
... ...