Commit 0bd7e473044fad59eb73e41697332f4fb84452c7

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

Fixing memory leaks, improving print dialog.

src/dialogs/colors.c
... ... @@ -189,6 +189,7 @@
189 189  
190 190 update_color_chooser(widget,g_value_get_int(&value));
191 191  
  192 + g_value_unset(&value);
192 193 }
193 194  
194 195  
... ...
src/dialogs/colorscheme.c
... ... @@ -88,6 +88,8 @@
88 88 debug("%s=%p",__FUNCTION__,clr);
89 89 g_signal_emit(widget, color_signal[CHANGED], 0, clr);
90 90  
  91 + g_value_unset(&value);
  92 +
91 93 }
92 94  
93 95 static void V3270ColorScheme_class_init(G_GNUC_UNUSED V3270ColorSchemeClass *klass)
... ... @@ -370,19 +372,22 @@
370 372  
371 373 gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget)),&iter,1,&value);
372 374 clr = g_value_get_pointer(&value);
373   - if(!clr)
374   - return g_strdup("");
375   -
376 375 GString *str = g_string_new("");
377   - for(f=0;f<V3270_COLOR_COUNT;f++)
  376 +
  377 + if(clr)
378 378 {
379   - if(f)
380   - g_string_append_c(str,';');
  379 + for(f=0;f<V3270_COLOR_COUNT;f++)
  380 + {
  381 + if(f)
  382 + g_string_append_c(str,';');
381 383  
382   - g_autofree gchar * color = gdk_rgba_to_string(clr+f);
383   - g_string_append_printf(str,"%s",color);
  384 + g_autofree gchar * color = gdk_rgba_to_string(clr+f);
  385 + g_string_append_printf(str,"%s",color);
  386 + }
384 387 }
385 388  
  389 + g_value_unset(&value);
  390 +
386 391 return g_string_free(str,FALSE);
387 392  
388 393 }
... ...
src/dialogs/fontselect.c
... ... @@ -100,9 +100,12 @@
100 100 if(!g_ascii_strcasecmp(fontname,g_value_get_string(&value)))
101 101 {
102 102 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter);
  103 + g_value_unset(&value);
103 104 return TRUE;
104 105 }
105 106  
  107 + g_value_unset(&value);
  108 +
106 109 } while(gtk_tree_model_iter_next(model,&iter));
107 110 }
108 111  
... ... @@ -110,7 +113,7 @@
110 113  
111 114 }
112 115  
113   - LIB3270_EXPORT const gchar * v3270_font_selection_get_family(GtkWidget *widget)
  116 + LIB3270_EXPORT gchar * v3270_font_selection_get_family(GtkWidget *widget)
114 117 {
115 118 GtkTreeIter iter;
116 119  
... ... @@ -119,7 +122,12 @@
119 122 GValue value = { 0, };
120 123  
121 124 gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget)),&iter,0,&value);
122   - return g_value_get_string(&value);
  125 +
  126 + gchar * rc = g_value_dup_string(&value);
  127 +
  128 + g_value_unset(&value);
  129 +
  130 + return rc;
123 131  
124 132 }
125 133  
... ...
src/dialogs/print/convenience.c
... ... @@ -34,7 +34,7 @@
34 34  
35 35 /*--[ Implement ]------------------------------------------------------------------------------------*/
36 36  
37   - int v3270_print(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, GError **error)
  37 + int v3270_print_dialog(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, GError **error)
38 38 {
39 39 int rc;
40 40  
... ... @@ -76,6 +76,8 @@
76 76 // Print operation.
77 77 V3270PrintOperation * operation = v3270_print_operation_new(widget, mode);
78 78  
  79 + gtk_print_operation_set_show_progress(GTK_PRINT_OPERATION(operation),TRUE);
  80 +
79 81 if(error)
80 82 {
81 83 gtk_print_operation_run(
... ... @@ -127,18 +129,24 @@
127 129  
128 130 }
129 131  
  132 + int v3270_print(GtkWidget *widget, GError **error)
  133 + {
  134 + return v3270_print_dialog(widget,(lib3270_has_selection(GTK_V3270(widget)->host) ? LIB3270_CONTENT_SELECTED : LIB3270_CONTENT_ALL),error);
  135 + }
  136 +
  137 +
130 138 int v3270_print_all(GtkWidget *widget, GError **error)
131 139 {
132   - return v3270_print(widget,LIB3270_CONTENT_ALL,error);
  140 + return v3270_print_dialog(widget,LIB3270_CONTENT_ALL,error);
133 141 }
134 142  
135 143 int v3270_print_selected(GtkWidget *widget, GError **error)
136 144 {
137   - return v3270_print(widget,LIB3270_CONTENT_SELECTED,error);
  145 + return v3270_print_dialog(widget,LIB3270_CONTENT_SELECTED,error);
138 146 }
139 147  
140 148 int v3270_print_copy(GtkWidget *widget, GError **error)
141 149 {
142   - return v3270_print(widget,LIB3270_CONTENT_COPY,error);
  150 + return v3270_print_dialog(widget,LIB3270_CONTENT_COPY,error);
143 151 }
144 152  
... ...
src/dialogs/print/print.c
... ... @@ -130,12 +130,12 @@
130 130  
131 131 // Setup options.
132 132 operation->show_selection = v3270_print_settings_get_show_selection(settings);
133   - operation->font.name = g_strdup(v3270_font_selection_get_family(settings));
  133 + operation->font.name = v3270_print_settings_get_font_family(settings);
134 134  
135 135 v3270_print_settings_get_rgba(settings, operation->settings.colors, V3270_COLOR_COUNT);
136 136  
137 137 }
138   -#endif // _WIN32
  138 +#endif // !_WIN32
139 139  
140 140 static void V3270PrintOperation_class_init(V3270PrintOperationClass *klass)
141 141 {
... ... @@ -149,7 +149,7 @@
149 149 #ifndef _WIN32
150 150 operation->create_custom_widget = custom_widget_new;
151 151 operation->custom_widget_apply = custom_widget_apply;
152   -#endif // _WIN32
  152 +#endif // !_WIN32
153 153  
154 154 }
155 155  
... ...
src/dialogs/print/settings.c
... ... @@ -146,7 +146,7 @@ LIB3270_EXPORT void v3270_print_settings_set_color_scheme(GtkWidget *widget, con
146 146 v3270_color_scheme_set_text(GTK_V3270_PRINT_SETTINGS(widget)->color, colors);
147 147 }
148 148  
149   -LIB3270_EXPORT const gchar * v3270_print_settings_get_font_family(GtkWidget *widget)
  149 +LIB3270_EXPORT gchar * v3270_print_settings_get_font_family(GtkWidget *widget)
150 150 {
151 151 return v3270_font_selection_get_family(GTK_V3270_PRINT_SETTINGS(widget)->font);
152 152 }
... ...
src/include/v3270.h
... ... @@ -265,10 +265,11 @@
265 265 LIB3270_EXPORT void v3270_select_host(GtkWidget *widget);
266 266  
267 267 // Print
268   - LIB3270_EXPORT int v3270_print(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, GError **error);
  268 + LIB3270_EXPORT int v3270_print(GtkWidget *widget, GError **error);
269 269 LIB3270_EXPORT int v3270_print_all(GtkWidget *widget, GError **error);
270 270 LIB3270_EXPORT int v3270_print_selected(GtkWidget *widget, GError **error);
271 271 LIB3270_EXPORT int v3270_print_copy(GtkWidget *widget, GError **error);
  272 + LIB3270_EXPORT int v3270_print_dialog(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, GError **error);
272 273  
273 274 // Save
274 275 LIB3270_EXPORT int v3270_save(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, const gchar *filename, GError **error);
... ...
src/include/v3270/print.h
... ... @@ -69,7 +69,7 @@
69 69  
70 70 LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname);
71 71 LIB3270_EXPORT gboolean v3270_font_selection_set_family(GtkWidget *widget, const gchar *fontname);
72   - LIB3270_EXPORT const gchar * v3270_font_selection_get_family(GtkWidget *widget);
  72 + LIB3270_EXPORT gchar * v3270_font_selection_get_family(GtkWidget *widget);
73 73  
74 74 LIB3270_EXPORT GType V3270PrintSettings_get_type(void);
75 75 LIB3270_EXPORT GtkWidget * V3270_print_settings_new(GtkWidget *widget);
... ... @@ -77,7 +77,7 @@
77 77 LIB3270_EXPORT void v3270_print_settings_set_show_selection(GtkWidget *widget, gboolean is_active);
78 78 LIB3270_EXPORT gchar * v3270_print_settings_get_color_scheme(GtkWidget *widget);
79 79 LIB3270_EXPORT void v3270_print_settings_set_color_scheme(GtkWidget *widget, const gchar *colors);
80   - LIB3270_EXPORT const gchar * v3270_print_settings_get_font_family(GtkWidget *widget);
  80 + LIB3270_EXPORT gchar * v3270_print_settings_get_font_family(GtkWidget *widget);
81 81 LIB3270_EXPORT gboolean v3270_print_settings_set_font_family(GtkWidget *widget, const gchar *fontname);
82 82 LIB3270_EXPORT int v3270_print_settings_get_rgba(GtkWidget *widget, GdkRGBA *colors, size_t num_colors);
83 83  
... ...
src/terminal/callbacks.c
... ... @@ -329,7 +329,7 @@ static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const
329 329  
330 330 static int print(H3270 *session, LIB3270_CONTENT_OPTION mode)
331 331 {
332   - return v3270_print(GTK_WIDGET(lib3270_get_user_data(session)), mode, NULL);
  332 + return v3270_print_dialog(GTK_WIDGET(lib3270_get_user_data(session)), mode, NULL);
333 333 }
334 334  
335 335 static int save(H3270 *session, LIB3270_CONTENT_OPTION mode, const char *filename)
... ...
src/testprogram/toolbar.c
... ... @@ -40,7 +40,7 @@
40 40  
41 41 static void print_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal)
42 42 {
43   - lib3270_print_all(v3270_get_session(terminal));
  43 + v3270_print(terminal,NULL);
44 44 }
45 45  
46 46 static void host_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal)
... ...