Commit 5a9d0cdaa799932d393b29118055fd2fb1a65b8a

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

Updating popup engine.

Showing 1 changed file with 116 additions and 60 deletions   Show diff stats
src/dialogs/popups.c
@@ -32,66 +32,134 @@ @@ -32,66 +32,134 @@
32 #include <terminal.h> 32 #include <terminal.h>
33 #include <v3270/dialogs.h> 33 #include <v3270/dialogs.h>
34 #include <v3270/settings.h> 34 #include <v3270/settings.h>
  35 + #include <lib3270/popup.h>
35 36
36 /*--[ Implement ]------------------------------------------------------------------------------------*/ 37 /*--[ Implement ]------------------------------------------------------------------------------------*/
37 38
38 - void v3270_popup_message(GtkWidget *widget, LIB3270_NOTIFY type , const gchar *title, const gchar *message, const gchar *text) {  
39 - GtkWidget * dialog;  
40 - GtkWidget * toplevel = NULL;  
41 - GtkMessageType msgtype = GTK_MESSAGE_WARNING;  
42 - GtkButtonsType buttons = GTK_BUTTONS_OK; 39 + GtkResponseType v3270_show_popup(GtkWidget *widget, const LIB3270_POPUP *popup, gboolean wait) {
43 40
44 - if(widget && GTK_IS_WIDGET(widget))  
45 - toplevel = gtk_widget_get_toplevel(GTK_WIDGET(widget)); 41 + g_return_val_if_fail(GTK_IS_WIDGET(widget),GTK_RESPONSE_NONE);
46 42
47 - if(!GTK_IS_WINDOW(toplevel))  
48 - toplevel = NULL; 43 + // Popup settings.
  44 + static const struct _settings {
  45 + GtkMessageType type;
  46 + GtkButtonsType buttons;
  47 + const gchar *title;
  48 + } settings[LIB3270_NOTIFY_USER] = {
49 49
50 - if(type == LIB3270_NOTIFY_CRITICAL) {  
51 - msgtype = GTK_MESSAGE_ERROR;  
52 - buttons = GTK_BUTTONS_CLOSE;  
53 - } 50 + // LIB3270_NOTIFY_INFO - Simple information dialog.
  51 + {
  52 + .type = GTK_MESSAGE_INFO,
  53 + .buttons = GTK_BUTTONS_OK,
  54 + .title = N_("Information")
54 55
55 - if(!title)  
56 - title = _( "Error" ); 56 + },
57 57
58 - if(message) {  
59 - dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",message);  
60 - if(text && *text)  
61 - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",text);  
62 - } else if(text && *text) {  
63 - dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",text);  
64 - } else {  
65 - dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(toplevel),GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,msgtype,buttons,"%s",title);  
66 - } 58 + // LIB3270_NOTIFY_WARNING - Warning message.
  59 + {
  60 + .type = GTK_MESSAGE_WARNING,
  61 + .buttons = GTK_BUTTONS_OK,
  62 + .title = N_("Warning")
67 63
68 - gtk_window_set_title(GTK_WINDOW(dialog),title);  
69 - gtk_widget_show_all(dialog);  
70 - gtk_dialog_run(GTK_DIALOG (dialog));  
71 - gtk_widget_destroy(dialog); 64 + },
72 65
73 - } 66 + // LIB3270_NOTIFY_ERROR - Error message.
  67 + {
  68 + .type = GTK_MESSAGE_ERROR,
  69 + .buttons = GTK_BUTTONS_OK,
  70 + .title = N_("Error")
74 71
75 - void v3270_error_popup(GtkWidget *widget, const gchar *title, const gchar *summary, const gchar *body) { 72 + },
  73 +
  74 + // LIB3270_NOTIFY_CRITICAL - Critical error, user can abort application.
  75 + {
  76 + .type = GTK_MESSAGE_ERROR,
  77 + .buttons = GTK_BUTTONS_CLOSE,
  78 + .title = N_("Critical Error")
  79 +
  80 + },
  81 +
  82 + // LIB3270_NOTIFY_SECURE - Secure host dialog.
  83 + {
  84 + .type = GTK_MESSAGE_OTHER,
  85 + .buttons = GTK_BUTTONS_OK,
  86 + .title = N_("Security alert")
  87 +
  88 + }
  89 +
  90 +
  91 + };
  92 +
  93 + // Create dialog
76 GtkWidget * dialog = 94 GtkWidget * dialog =
77 - gtk_message_dialog_new_with_markup(  
78 - GTK_WINDOW(gtk_widget_get_toplevel(widget)),  
79 - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,  
80 - GTK_MESSAGE_ERROR,  
81 - GTK_BUTTONS_CLOSE,  
82 - "%s",summary  
83 - ); 95 + gtk_message_dialog_new_with_markup(
  96 + GTK_WINDOW(gtk_widget_get_toplevel(widget)),
  97 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  98 + settings[popup->type].type,
  99 + settings[popup->type].buttons,
  100 + "%s",popup->summary
  101 + );
  102 +
  103 + if(popup->body) {
  104 + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",popup->body);
  105 + }
  106 +
  107 + if(popup->title) {
  108 + gtk_window_set_title(GTK_WINDOW(dialog),popup->title);
  109 + } else {
  110 + gtk_window_set_title(GTK_WINDOW(dialog),g_dgettext(GETTEXT_PACKAGE,settings[popup->type].title));
  111 + }
  112 +
  113 +
  114 + if(wait) {
84 115
85 - gtk_window_set_title(GTK_WINDOW(dialog), (title ? title : _("Error"))); 116 + // Wait for response.
  117 + gtk_widget_show_all(dialog);
  118 + gint rc = gtk_dialog_run(GTK_DIALOG(dialog));
  119 + gtk_widget_destroy(dialog);
  120 + return rc;
86 121
87 - if(body)  
88 - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",body); 122 + }
89 123
  124 + // Unnamed dialog, no need for wait.
90 g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); 125 g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL);
91 g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL); 126 g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL);
92 127
93 gtk_widget_show_all(dialog); 128 gtk_widget_show_all(dialog);
94 129
  130 + return GTK_RESPONSE_NONE;
  131 +
  132 + }
  133 +
  134 + void v3270_popup_message(GtkWidget *widget, LIB3270_NOTIFY type , const gchar *title, const gchar *message, const gchar *text) {
  135 +
  136 + LIB3270_POPUP popup = {
  137 + .type = type,
  138 + .body = text
  139 + };
  140 +
  141 + if(message) {
  142 + popup.summary = message;
  143 + popup.title = title;
  144 + } else {
  145 + popup.summary = title;
  146 + }
  147 +
  148 + v3270_show_popup(widget, &popup, FALSE);
  149 +
  150 + }
  151 +
  152 + void v3270_error_popup(GtkWidget *widget, const gchar *title, const gchar *summary, const gchar *body) {
  153 +
  154 + LIB3270_POPUP popup = {
  155 + .type = LIB3270_NOTIFY_ERROR,
  156 + .title = title,
  157 + .summary = summary,
  158 + .body = body
  159 + };
  160 +
  161 + v3270_show_popup(widget, &popup, FALSE);
  162 +
95 } 163 }
96 164
97 void v3270_popup_gerror(GtkWidget *widget, GError *error, const gchar *title, const gchar *fmt, ...) { 165 void v3270_popup_gerror(GtkWidget *widget, GError *error, const gchar *title, const gchar *fmt, ...) {
@@ -99,29 +167,17 @@ @@ -99,29 +167,17 @@
99 // Format message. 167 // Format message.
100 va_list arg_ptr; 168 va_list arg_ptr;
101 va_start(arg_ptr, fmt); 169 va_start(arg_ptr, fmt);
102 - g_autofree gchar *text = g_strdup_vprintf(fmt,arg_ptr); 170 + g_autofree gchar *summary = g_strdup_vprintf(fmt,arg_ptr);
103 va_end(arg_ptr); 171 va_end(arg_ptr);
104 172
105 - GtkWidget *dialog = gtk_message_dialog_new(  
106 - GTK_WINDOW(gtk_widget_get_toplevel(widget)),  
107 - GTK_DIALOG_DESTROY_WITH_PARENT,  
108 - GTK_MESSAGE_ERROR,  
109 - GTK_BUTTONS_OK,  
110 - "%s",text  
111 - ); 173 + LIB3270_POPUP popup = {
  174 + .type = LIB3270_NOTIFY_ERROR,
  175 + .title = title,
  176 + .summary = summary,
  177 + .body = error->message
  178 + };
112 179
113 - if(title)  
114 - gtk_window_set_title(GTK_WINDOW(dialog), title);  
115 - else  
116 - gtk_window_set_title(GTK_WINDOW(dialog), (title ? title : _("Operation failed")));  
117 -  
118 - if(error)  
119 - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message);  
120 -  
121 - g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL);  
122 - g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL);  
123 -  
124 - gtk_widget_show_all(dialog); 180 + v3270_show_popup(widget, &popup, FALSE);
125 181
126 } 182 }
127 183