Commit ed33abb70f0f75289e7ad56b571a1301e25981d8

Authored by Perry Werneck
1 parent 7727b019
Exists in master and in 1 other branch develop

Refactoring popup engine.

src/dialogs/popups.c
@@ -40,6 +40,24 @@ @@ -40,6 +40,24 @@
40 40
41 g_return_val_if_fail(GTK_IS_WIDGET(widget),GTK_RESPONSE_NONE); 41 g_return_val_if_fail(GTK_IS_WIDGET(widget),GTK_RESPONSE_NONE);
42 42
  43 + // Check if the dialog is enabled
  44 + if(popup->name && GTK_IS_V3270(widget)) {
  45 +
  46 + GtkResponseType response = GTK_RESPONSE_NONE;
  47 +
  48 + v3270_signal_emit(
  49 + widget,
  50 + V3270_SIGNAL_LOAD_POPUP_RESPONSE,
  51 + popup->name,
  52 + response,
  53 + &response
  54 + );
  55 +
  56 + if(response != GTK_RESPONSE_NONE)
  57 + return response;
  58 +
  59 + }
  60 +
43 // Popup settings. 61 // Popup settings.
44 static const struct _settings { 62 static const struct _settings {
45 GtkMessageType type; 63 GtkMessageType type;
@@ -51,40 +69,30 @@ @@ -51,40 +69,30 @@
51 { 69 {
52 .type = GTK_MESSAGE_INFO, 70 .type = GTK_MESSAGE_INFO,
53 .button = N_("_Ok"), 71 .button = N_("_Ok"),
54 - .title = N_("Information")  
55 -  
56 }, 72 },
57 73
58 // LIB3270_NOTIFY_WARNING - Warning message. 74 // LIB3270_NOTIFY_WARNING - Warning message.
59 { 75 {
60 .type = GTK_MESSAGE_WARNING, 76 .type = GTK_MESSAGE_WARNING,
61 .button = N_("_Ok"), 77 .button = N_("_Ok"),
62 - .title = N_("Warning")  
63 -  
64 }, 78 },
65 79
66 // LIB3270_NOTIFY_ERROR - Error message. 80 // LIB3270_NOTIFY_ERROR - Error message.
67 { 81 {
68 .type = GTK_MESSAGE_ERROR, 82 .type = GTK_MESSAGE_ERROR,
69 .button = N_("_Ok"), 83 .button = N_("_Ok"),
70 - .title = N_("Error")  
71 -  
72 }, 84 },
73 85
74 // LIB3270_NOTIFY_CRITICAL - Critical error, user can abort application. 86 // LIB3270_NOTIFY_CRITICAL - Critical error, user can abort application.
75 { 87 {
76 .type = GTK_MESSAGE_ERROR, 88 .type = GTK_MESSAGE_ERROR,
77 .button = N_("_Close"), 89 .button = N_("_Close"),
78 - .title = N_("Critical Error")  
79 -  
80 }, 90 },
81 91
82 // LIB3270_NOTIFY_SECURE - Secure host dialog. 92 // LIB3270_NOTIFY_SECURE - Secure host dialog.
83 { 93 {
84 .type = GTK_MESSAGE_OTHER, 94 .type = GTK_MESSAGE_OTHER,
85 .button = N_("_Ok"), 95 .button = N_("_Ok"),
86 - .title = N_("Security alert")  
87 -  
88 } 96 }
89 97
90 }; 98 };
@@ -96,22 +104,46 @@ @@ -96,22 +104,46 @@
96 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, 104 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
97 settings[popup->type].type, 105 settings[popup->type].type,
98 GTK_BUTTONS_NONE, 106 GTK_BUTTONS_NONE,
99 - "%s",popup->summary 107 + "<b><big>%s</big></b>",popup->summary
100 ); 108 );
101 109
102 if(popup->body) { 110 if(popup->body) {
103 - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",popup->body); 111 + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"<small>%s</small>",popup->body);
104 } 112 }
105 113
106 if(popup->title) { 114 if(popup->title) {
107 gtk_window_set_title(GTK_WINDOW(dialog),popup->title); 115 gtk_window_set_title(GTK_WINDOW(dialog),popup->title);
108 - } else {  
109 - gtk_window_set_title(GTK_WINDOW(dialog),g_dgettext(GETTEXT_PACKAGE,settings[popup->type].title));  
110 } 116 }
111 117
112 -  
113 if(wait) { 118 if(wait) {
114 119
  120 + GtkWidget * dont_ask = NULL;
  121 +
  122 +#ifdef DEBUG
  123 + if(popup->name && GTK_IS_V3270(widget)) {
  124 + // Set check button
  125 + dont_ask = gtk_check_button_new_with_label(_("Don't ask again"));
  126 +
  127 + gtk_widget_set_can_focus(dont_ask,FALSE);
  128 + gtk_widget_set_can_default(dont_ask,FALSE);
  129 +
  130 +#if GTK_CHECK_VERSION(3,20,0)
  131 + gtk_widget_set_focus_on_click(dont_ask,FALSE);
  132 +#endif // GTK 3,20,0
  133 +
  134 + //gtk_widget_set_valign(dont_ask, GTK_ALIGN_BASELINE);
  135 + //gtk_widget_set_halign(dont_ask, GTK_ALIGN_START);
  136 +
  137 + gtk_box_pack_start(
  138 + GTK_BOX(gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog))),
  139 + dont_ask,
  140 + TRUE,
  141 + TRUE,
  142 + 0
  143 + );
  144 + }
  145 +#endif // DEBUG
  146 +
115 // Wait for response. 147 // Wait for response.
116 if(popup->label) { 148 if(popup->label) {
117 149
@@ -129,7 +161,24 @@ @@ -129,7 +161,24 @@
129 } 161 }
130 162
131 gtk_widget_show_all(dialog); 163 gtk_widget_show_all(dialog);
132 - gint rc = gtk_dialog_run(GTK_DIALOG(dialog)); 164 + GtkResponseType rc = gtk_dialog_run(GTK_DIALOG(dialog));
  165 +
  166 + if(dont_ask && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dont_ask))) {
  167 +
  168 + gboolean saved = FALSE;
  169 +
  170 + v3270_signal_emit(
  171 + widget,
  172 + V3270_SIGNAL_SAVE_POPUP_RESPONSE,
  173 + popup->name,
  174 + rc,
  175 + &saved
  176 + );
  177 +
  178 + debug("response was %s",saved ? "saved" : "not saved");
  179 +
  180 + }
  181 +
133 gtk_widget_destroy(dialog); 182 gtk_widget_destroy(dialog);
134 return rc; 183 return rc;
135 184
@@ -147,26 +196,6 @@ @@ -147,26 +196,6 @@
147 196
148 } 197 }
149 198
150 - /*  
151 - void v3270_popup_message(GtkWidget *widget, LIB3270_NOTIFY type , const gchar *title, const gchar *message, const gchar *text) {  
152 -  
153 - LIB3270_POPUP popup = {  
154 - .type = type,  
155 - .body = text  
156 - };  
157 -  
158 - if(message) {  
159 - popup.summary = message;  
160 - popup.title = title;  
161 - } else {  
162 - popup.summary = title;  
163 - }  
164 -  
165 - v3270_show_popup(widget, &popup, FALSE);  
166 -  
167 - }  
168 - */  
169 -  
170 void v3270_error_popup(GtkWidget *widget, const gchar *title, const gchar *summary, const gchar *body) { 199 void v3270_error_popup(GtkWidget *widget, const gchar *title, const gchar *summary, const gchar *body) {
171 200
172 LIB3270_POPUP popup = { 201 LIB3270_POPUP popup = {
src/include/internals.h
@@ -114,7 +114,9 @@ @@ -114,7 +114,9 @@
114 // 114 //
115 // Settings signals (Mostly fired by V3270Settings dialogs). 115 // Settings signals (Mostly fired by V3270Settings dialogs).
116 // 116 //
117 - V3270_SIGNAL_SAVE_SETTINGS, ///< @brief Notify main application to save all widget settings. 117 + V3270_SIGNAL_SAVE_SETTINGS, ///< @brief Notify main application to save all widget settings.
  118 + V3270_SIGNAL_LOAD_POPUP_RESPONSE, ///< @brief Load popup response (GTK_RESPONSE_NONE to show popup).
  119 + V3270_SIGNAL_SAVE_POPUP_RESPONSE, ///< @brief Save popup response.
118 120
119 V3270_SIGNAL_LAST 121 V3270_SIGNAL_LAST
120 }; 122 };
src/include/terminal.h
@@ -105,6 +105,8 @@ G_BEGIN_DECLS @@ -105,6 +105,8 @@ G_BEGIN_DECLS
105 void (*activate)(GtkWidget *widget); 105 void (*activate)(GtkWidget *widget);
106 void (*toggle_changed)(v3270 *widget,LIB3270_TOGGLE_ID toggle_id,gboolean toggle_state,const gchar *toggle_name); 106 void (*toggle_changed)(v3270 *widget,LIB3270_TOGGLE_ID toggle_id,gboolean toggle_state,const gchar *toggle_name);
107 void (*message_changed)(v3270 *widget, LIB3270_MESSAGE id); 107 void (*message_changed)(v3270 *widget, LIB3270_MESSAGE id);
  108 + guint (*load_popup_response)(v3270 *widget, const gchar *popup_name, guint response);
  109 + gboolean (*save_popup_response)(v3270 *widget, const gchar *popup_name, guint response);
108 110
109 }; 111 };
110 112
src/terminal/marshal
@@ -6,6 +6,8 @@ VOID:POINTER @@ -6,6 +6,8 @@ VOID:POINTER
6 VOID:VOID,POINTER,POINTER 6 VOID:VOID,POINTER,POINTER
7 VOID:VOID,UINT,POINTER 7 VOID:VOID,UINT,POINTER
8 BOOLEAN:UINT,ENUM 8 BOOLEAN:UINT,ENUM
  9 +UINT:POINTER,UINT
  10 +BOOLEAN:POINTER,UINT
9 VOID:VOID,BOOLEAN 11 VOID:VOID,BOOLEAN
10 BOOLEAN:VOID,BOOLEAN,BOOLEAN,POINTER 12 BOOLEAN:VOID,BOOLEAN,BOOLEAN,POINTER
11 VOID:VOID,UINT,UINT 13 VOID:VOID,UINT,UINT
src/terminal/widget.c
@@ -201,6 +201,14 @@ static void finalize(GObject *object) { @@ -201,6 +201,14 @@ static void finalize(GObject *object) {
201 G_OBJECT_CLASS(v3270_parent_class)->finalize(object); 201 G_OBJECT_CLASS(v3270_parent_class)->finalize(object);
202 } 202 }
203 203
  204 + static GtkResponseType load_popup_response(v3270 G_GNUC_UNUSED(*widget), const gchar G_GNUC_UNUSED(*popup_name), GtkResponseType response) {
  205 + return response;
  206 + }
  207 +
  208 + static gboolean save_popup_response(v3270 G_GNUC_UNUSED(*widget), const gchar G_GNUC_UNUSED(*popup_name), GtkResponseType G_GNUC_UNUSED(response)) {
  209 + return FALSE;
  210 + }
  211 +
204 static void v3270_class_init(v3270Class *klass) 212 static void v3270_class_init(v3270Class *klass)
205 { 213 {
206 GObjectClass * gobject_class = G_OBJECT_CLASS(klass); 214 GObjectClass * gobject_class = G_OBJECT_CLASS(klass);
@@ -242,10 +250,13 @@ static void v3270_class_init(v3270Class *klass) @@ -242,10 +250,13 @@ static void v3270_class_init(v3270Class *klass)
242 klass->activate = v3270_activate; 250 klass->activate = v3270_activate;
243 klass->toggle_changed = v3270_toggle_changed; 251 klass->toggle_changed = v3270_toggle_changed;
244 klass->message_changed = v3270_update_message; 252 klass->message_changed = v3270_update_message;
  253 + klass->load_popup_response = load_popup_response;
  254 + klass->save_popup_response = save_popup_response;
245 255
246 // Register I/O Handlers 256 // Register I/O Handlers
247 v3270_register_io_handlers(klass); 257 v3270_register_io_handlers(klass);
248 258
  259 +
249 // Cursors 260 // Cursors
250 { 261 {
251 #ifdef WIN32 262 #ifdef WIN32
@@ -464,6 +475,24 @@ static void v3270_class_init(v3270Class *klass) @@ -464,6 +475,24 @@ static void v3270_class_init(v3270Class *klass)
464 v3270_VOID__VOID, 475 v3270_VOID__VOID,
465 G_TYPE_NONE, 0); 476 G_TYPE_NONE, 0);
466 477
  478 + v3270_widget_signal[V3270_SIGNAL_LOAD_POPUP_RESPONSE] =
  479 + g_signal_new( I_("load-popup-response"),
  480 + G_OBJECT_CLASS_TYPE (gobject_class),
  481 + G_SIGNAL_RUN_LAST,
  482 + G_STRUCT_OFFSET (v3270Class, load_popup_response),
  483 + NULL, NULL,
  484 + v3270_UINT__POINTER_UINT,
  485 + G_TYPE_UINT, 2, G_TYPE_POINTER, G_TYPE_UINT);
  486 +
  487 + v3270_widget_signal[V3270_SIGNAL_SAVE_POPUP_RESPONSE] =
  488 + g_signal_new( I_("save-popup-response"),
  489 + G_OBJECT_CLASS_TYPE (gobject_class),
  490 + G_SIGNAL_RUN_LAST,
  491 + G_STRUCT_OFFSET (v3270Class, save_popup_response),
  492 + NULL, NULL,
  493 + v3270_BOOLEAN__POINTER_UINT,
  494 + G_TYPE_BOOLEAN, 2, G_TYPE_POINTER, G_TYPE_UINT);
  495 +
467 v3270_init_properties(gobject_class); 496 v3270_init_properties(gobject_class);
468 497
469 } 498 }
src/testprogram/toolbar.c
@@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
37 #include <v3270/selection.h> 37 #include <v3270/selection.h>
38 #include <v3270/trace.h> 38 #include <v3270/trace.h>
39 #include <lib3270/log.h> 39 #include <lib3270/log.h>
  40 + #include <lib3270/popup.h>
40 #include <stdlib.h> 41 #include <stdlib.h>
41 42
42 #pragma GCC diagnostic ignored "-Wunused-parameter" 43 #pragma GCC diagnostic ignored "-Wunused-parameter"
@@ -163,6 +164,7 @@ @@ -163,6 +164,7 @@
163 */ 164 */
164 165
165 166
  167 + /*
166 { 168 {
167 // 169 //
168 // Test V3270 FT Dialog 170 // Test V3270 FT Dialog
@@ -180,7 +182,22 @@ @@ -180,7 +182,22 @@
180 gtk_widget_show_all(dialog); 182 gtk_widget_show_all(dialog);
181 183
182 } 184 }
  185 + */
  186 +
  187 +
  188 + }
  189 +
  190 + static void popup_clicked(GtkButton *button, GtkWidget *terminal)
  191 + {
  192 +
  193 + static const LIB3270_POPUP popup = {
  194 + .name = "sample_popup",
  195 + .type = LIB3270_NOTIFY_INFO,
  196 + .summary = "This is the summary of message",
  197 + .body = "This it the body of the message, can be used for a bigger explanation"
  198 + };
183 199
  200 + lib3270_popup_show(v3270_get_session(terminal), &popup, 1);
184 201
185 } 202 }
186 203
@@ -232,6 +249,7 @@ @@ -232,6 +249,7 @@
232 { "gtk-paste", G_CALLBACK(paste_clicked), "Paste data" }, 249 { "gtk-paste", G_CALLBACK(paste_clicked), "Paste data" },
233 { "document-save", G_CALLBACK(save_clicked), "Save screen or selection" }, 250 { "document-save", G_CALLBACK(save_clicked), "Save screen or selection" },
234 { "document-open", G_CALLBACK(load_clicked), "Paste file" }, 251 { "document-open", G_CALLBACK(load_clicked), "Paste file" },
  252 + { "dialog-information", G_CALLBACK(popup_clicked), "Show test popup" },
235 253
236 { "applications-system", G_CALLBACK(preferences_clicked), "Session properties" }, 254 { "applications-system", G_CALLBACK(preferences_clicked), "Session properties" },
237 255