Commit 367055b65bdd6b7465a0cb2fdffe3c5163bb1285

Authored by Perry Werneck
1 parent f06eec2e

Replacing save dialog with the new version from v3270.

src/include/pw3270.h
@@ -89,7 +89,7 @@ @@ -89,7 +89,7 @@
89 89
90 LIB3270_EXPORT void pw3270_set_action_state(GtkAction *action, gboolean on); 90 LIB3270_EXPORT void pw3270_set_action_state(GtkAction *action, gboolean on);
91 91
92 - LIB3270_EXPORT int pw3270_print(GtkWidget *widget, GObject *action, GtkPrintOperationAction oper, LIB3270_PRINT_MODE src); 92 + LIB3270_EXPORT int pw3270_print(GtkWidget *widget, GObject *action, GtkPrintOperationAction oper, LIB3270_CONTENT_OPTION src);
93 93
94 LIB3270_EXPORT gboolean pw3270_set_keyboard_action(GtkWidget *widget, const gchar *key_name, GtkAction *action); 94 LIB3270_EXPORT gboolean pw3270_set_keyboard_action(GtkWidget *widget, const gchar *key_name, GtkAction *action);
95 95
src/pw3270/dialog.c
@@ -185,193 +185,19 @@ @@ -185,193 +185,19 @@
185 185
186 } 186 }
187 187
188 - static void save_text(GtkWindow *toplevel,const gchar *filename, const gchar *text, const gchar *encoding, const gchar *errmsg)  
189 - {  
190 - GError * error = NULL;  
191 -  
192 - if(encoding && g_ascii_strcasecmp(encoding,"UTF-8"))  
193 - {  
194 - // Convert to target charset and save  
195 - gsize bytes_written;  
196 - gchar * converted = g_convert_with_fallback(text,-1,encoding,"UTF-8",NULL,NULL,&bytes_written,&error);  
197 -  
198 - if(!error)  
199 - g_file_set_contents(filename,converted,-1,&error);  
200 -  
201 - g_free(converted);  
202 - }  
203 - else  
204 - {  
205 - // Same charset, save file  
206 - g_file_set_contents(filename,text,-1,&error);  
207 - }  
208 -  
209 - if(error)  
210 - {  
211 - GtkWidget *popup = gtk_message_dialog_new_with_markup(  
212 - toplevel,  
213 - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,  
214 - GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,  
215 - gettext(errmsg),filename);  
216 -  
217 - gtk_window_set_title(GTK_WINDOW(popup),_("Can't save file"));  
218 -  
219 - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",error->message);  
220 - g_error_free(error);  
221 -  
222 - gtk_dialog_run(GTK_DIALOG(popup));  
223 - gtk_widget_destroy(popup);  
224 -  
225 - }  
226 -  
227 - }  
228 -  
229 - static GtkFileChooserConfirmation confirm_overwrite(GtkFileChooser *chooser, GObject *action)  
230 - {  
231 - const gchar * attr = g_object_get_data(action,"overwrite");  
232 - GtkFileChooserConfirmation ret = GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;  
233 - GtkWidget * dialog;  
234 -  
235 - if(attr && !g_ascii_strcasecmp(attr,"yes"))  
236 - return ret;  
237 -  
238 - dialog = gtk_message_dialog_new_with_markup( GTK_WINDOW(chooser),  
239 - GTK_DIALOG_DESTROY_WITH_PARENT,  
240 - GTK_MESSAGE_QUESTION,GTK_BUTTONS_OK_CANCEL,  
241 - "%s",_("The file already exists. Replace it?"));  
242 -  
243 -  
244 - if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)  
245 - ret = GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;  
246 -  
247 - gtk_widget_destroy(dialog);  
248 -  
249 - return ret;  
250 -  
251 - }  
252 -  
253 - static int save_dialog(GtkAction *action, GtkWidget *widget, const gchar *title, const gchar *errmsg, const gchar *text)  
254 - {  
255 - GtkWindow * toplevel = GTK_WINDOW(gtk_widget_get_toplevel(widget));  
256 - const gchar * user_title = g_object_get_data(G_OBJECT(action),"title");  
257 - const gchar * filename = g_object_get_data(G_OBJECT(action),"filename");  
258 -  
259 - /*  
260 - const gchar * extension = g_object_get_data(G_OBJECT(action),"extension");  
261 -  
262 - if(!extension)  
263 - extension = "txt";  
264 - */  
265 -  
266 - if(!text)  
267 - return 0;  
268 -  
269 -  
270 - if(filename)  
271 - {  
272 - save_text(toplevel,filename,text,g_object_get_data(G_OBJECT(action),"encoding"),errmsg);  
273 - }  
274 - else  
275 - {  
276 - GtkWidget * dialog;  
277 - gchar * ptr;  
278 - gchar * encattr = NULL;  
279 -  
280 - dialog = gtk_file_chooser_dialog_new( gettext(user_title ? user_title : title),  
281 - toplevel,  
282 - GTK_FILE_CHOOSER_ACTION_SAVE,  
283 - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,  
284 - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,  
285 - NULL );  
286 -  
287 - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);  
288 - g_signal_connect(GTK_FILE_CHOOSER(dialog), "confirm-overwrite", G_CALLBACK(confirm_overwrite), G_OBJECT(action));  
289 -  
290 - add_option_menus(dialog, action, &encattr);  
291 -  
292 - ptr = get_string_from_config("save",gtk_action_get_name(action),"");  
293 - if(*ptr)  
294 - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),ptr);  
295 - else  
296 - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS));  
297 - g_free(ptr);  
298 -  
299 - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)  
300 - {  
301 - ptr = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));  
302 - if(ptr)  
303 - {  
304 - trace("Saving \"%s\"",ptr);  
305 - set_string_to_config("save",gtk_action_get_name(action),"%s",ptr);  
306 - save_text(toplevel,ptr,text,encattr,errmsg);  
307 - g_free(ptr);  
308 - }  
309 - }  
310 -  
311 - if(encattr)  
312 - g_free(encattr);  
313 -  
314 - trace("Removing dialog %p",dialog);  
315 - gtk_widget_destroy(dialog);  
316 - }  
317 -  
318 - return 0;  
319 - }  
320 -  
321 void save_all_action(GtkAction *action, GtkWidget *widget) 188 void save_all_action(GtkAction *action, GtkWidget *widget)
322 { 189 {
323 - gchar *text = v3270_get_text(widget,0,-1);  
324 -  
325 - trace("Action %s activated on widget %p text=%p",gtk_action_get_name(action),widget,text);  
326 -  
327 - if(!text)  
328 - {  
329 - g_warning("%s","Buffer contents was NULL");  
330 - return;  
331 - }  
332 -  
333 - save_dialog( action,  
334 - widget,  
335 - N_( "Save screen to file" ),  
336 - N_( "Can't save screen to file\n%s" ),  
337 - text);  
338 -  
339 - g_free(text);  
340 - 190 + v3270_save_all(widget,g_object_get_data(G_OBJECT(action),"filename"),NULL);
341 } 191 }
342 192
343 void save_selected_action(GtkAction *action, GtkWidget *widget) 193 void save_selected_action(GtkAction *action, GtkWidget *widget)
344 { 194 {
345 - gchar *text = v3270_get_selected(widget,FALSE);  
346 -  
347 - trace("Action %s activated on widget %p",gtk_action_get_name(action),widget);  
348 -  
349 - if(text)  
350 - {  
351 - save_dialog( action,  
352 - widget,  
353 - N_( "Save selection to file" ),  
354 - N_( "Can't save selection to file\n%s" ),  
355 - text);  
356 - g_free(text);  
357 - } 195 + v3270_save_selected(widget,g_object_get_data(G_OBJECT(action),"filename"),NULL);
358 } 196 }
359 197
360 void save_copy_action(GtkAction *action, GtkWidget *widget) 198 void save_copy_action(GtkAction *action, GtkWidget *widget)
361 { 199 {
362 - gchar *text = v3270_get_copy(widget);  
363 -  
364 - trace("Action %s activated on widget %p",gtk_action_get_name(action),widget);  
365 -  
366 - if(text)  
367 - {  
368 - save_dialog( action,  
369 - widget,  
370 - N_( "Save copy to file" ),  
371 - N_( "Can't save copy to file\n%s" ),  
372 - text);  
373 - g_free(text);  
374 - } 200 + v3270_save_copy(widget,g_object_get_data(G_OBJECT(action),"filename"),NULL);
375 } 201 }
376 202
377 static void paste_filename(GtkWidget *widget, const gchar *filename, const gchar *encoding) 203 static void paste_filename(GtkWidget *widget, const gchar *filename, const gchar *encoding)
src/pw3270/print.c
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 { 50 {
51 GdkRGBA color[V3270_COLOR_COUNT]; 51 GdkRGBA color[V3270_COLOR_COUNT];
52 int show_selection : 1; 52 int show_selection : 1;
53 - LIB3270_PRINT_MODE src; 53 + LIB3270_CONTENT_OPTION src;
54 54
55 GtkWidget * widget; 55 GtkWidget * widget;
56 H3270 * session; 56 H3270 * session;
@@ -185,7 +185,7 @@ @@ -185,7 +185,7 @@
185 unsigned char c; 185 unsigned char c;
186 unsigned short attr; 186 unsigned short attr;
187 187
188 - if(!lib3270_get_element(info->session,baddr++,&c,&attr) && (info->src == LIB3270_PRINT_ALL || (attr & LIB3270_ATTR_SELECTED))) 188 + if(!lib3270_get_element(info->session,baddr++,&c,&attr) && (info->src == LIB3270_CONTENT_ALL || (attr & LIB3270_ATTR_SELECTED)))
189 { 189 {
190 if(!info->show_selection) 190 if(!info->show_selection)
191 attr &= ~LIB3270_ATTR_SELECTED; 191 attr &= ~LIB3270_ATTR_SELECTED;
@@ -506,7 +506,7 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -506,7 +506,7 @@ static gchar * enum_to_string(GType type, guint enum_value)
506 // Selection checkbox 506 // Selection checkbox
507 widget = gtk_check_button_new_with_label( _("Print selection box") ); 507 widget = gtk_check_button_new_with_label( _("Print selection box") );
508 508
509 - if(info->src == LIB3270_PRINT_ALL) 509 + if(info->src == LIB3270_CONTENT_ALL)
510 { 510 {
511 info->show_selection = get_boolean_from_config("print","selection",FALSE); 511 info->show_selection = get_boolean_from_config("print","selection",FALSE);
512 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),info->show_selection); 512 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),info->show_selection);
@@ -798,12 +798,12 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -798,12 +798,12 @@ static gchar * enum_to_string(GType type, guint enum_value)
798 798
799 void print_all_action(GtkAction *action, GtkWidget *widget) 799 void print_all_action(GtkAction *action, GtkWidget *widget)
800 { 800 {
801 - pw3270_print(widget,G_OBJECT(action),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, LIB3270_PRINT_ALL); 801 + pw3270_print(widget,G_OBJECT(action),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, LIB3270_CONTENT_ALL);
802 } 802 }
803 803
804 void print_selected_action(GtkAction *action, GtkWidget *widget) 804 void print_selected_action(GtkAction *action, GtkWidget *widget)
805 { 805 {
806 - pw3270_print(widget,G_OBJECT(action),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, LIB3270_PRINT_SELECTED); 806 + pw3270_print(widget,G_OBJECT(action),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, LIB3270_CONTENT_SELECTED);
807 } 807 }
808 808
809 static void draw_text(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info) 809 static void draw_text(GtkPrintOperation *prt, GtkPrintContext *context, gint pg, PRINT_INFO *info)
@@ -833,10 +833,10 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -833,10 +833,10 @@ static gchar * enum_to_string(GType type, guint enum_value)
833 833
834 void print_copy_action(GtkAction *action, GtkWidget *widget) 834 void print_copy_action(GtkAction *action, GtkWidget *widget)
835 { 835 {
836 - pw3270_print(widget,G_OBJECT(action),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, LIB3270_PRINT_COPY); 836 + pw3270_print(widget,G_OBJECT(action),GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, LIB3270_CONTENT_COPY);
837 } 837 }
838 838
839 - LIB3270_EXPORT int pw3270_print(GtkWidget *widget, GObject *action, GtkPrintOperationAction oper, LIB3270_PRINT_MODE src) 839 + LIB3270_EXPORT int pw3270_print(GtkWidget *widget, GObject *action, GtkPrintOperationAction oper, LIB3270_CONTENT_OPTION src)
840 { 840 {
841 PRINT_INFO * info = NULL; 841 PRINT_INFO * info = NULL;
842 GtkPrintOperation * print; 842 GtkPrintOperation * print;
@@ -862,12 +862,12 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -862,12 +862,12 @@ static gchar * enum_to_string(GType type, guint enum_value)
862 862
863 switch(src) 863 switch(src)
864 { 864 {
865 - case LIB3270_PRINT_ALL:  
866 - case LIB3270_PRINT_SELECTED: 865 + case LIB3270_CONTENT_ALL:
  866 + case LIB3270_CONTENT_SELECTED:
867 g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info); 867 g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info);
868 break; 868 break;
869 869
870 - case LIB3270_PRINT_COPY: 870 + case LIB3270_CONTENT_COPY:
871 871
872 text = v3270_get_copy(widget); 872 text = v3270_get_copy(widget);
873 873
src/pw3270/window.c
@@ -644,7 +644,7 @@ static GtkWidget * trace_window = NULL; @@ -644,7 +644,7 @@ static GtkWidget * trace_window = NULL;
644 644
645 static void print_all(GtkWidget *widget, GtkWidget *window) 645 static void print_all(GtkWidget *widget, GtkWidget *window)
646 { 646 {
647 - pw3270_print(widget, NULL, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, LIB3270_PRINT_ALL); 647 + pw3270_print(widget, NULL, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, LIB3270_CONTENT_ALL);
648 } 648 }
649 649
650 static void toggle_changed(GtkWidget *widget, LIB3270_TOGGLE id, gboolean toggled, const gchar *name, GtkWindow *toplevel) 650 static void toggle_changed(GtkWidget *widget, LIB3270_TOGGLE id, gboolean toggled, const gchar *name, GtkWindow *toplevel)