]>
Commit | Line | Data |
---|---|---|
f33aa4e0 EB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
4 | * Copyright (C) 2003-2007, Evan Battaglia <gtoevan@gmx.net> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
d9d1084e GB |
21 | #ifdef HAVE_CONFIG_H |
22 | #include "config.h" | |
23 | #endif | |
24 | ||
f33aa4e0 | 25 | #include <gtk/gtk.h> |
d9d1084e | 26 | #include <glib/gi18n.h> |
f33aa4e0 EB |
27 | #include "uibuilder.h" |
28 | #include "vikradiogroup.h" | |
29 | #include "vikfileentry.h" | |
30 | #include "vikfilelist.h" | |
31 | ||
a7023a1b RN |
32 | VikLayerParamData vik_lpd_true_default ( void ) { return VIK_LPD_BOOLEAN ( TRUE ); } |
33 | VikLayerParamData vik_lpd_false_default ( void ) { return VIK_LPD_BOOLEAN ( FALSE ); } | |
34 | ||
f33aa4e0 EB |
35 | GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data ) |
36 | { | |
37 | GtkWidget *rv = NULL; | |
38 | switch ( param->widget_type ) | |
39 | { | |
40 | case VIK_LAYER_WIDGET_COLOR: | |
41 | if ( param->type == VIK_LAYER_PARAM_COLOR ) | |
42 | rv = gtk_color_button_new_with_color ( &(data.c) ); | |
43 | break; | |
44 | case VIK_LAYER_WIDGET_CHECKBUTTON: | |
45 | if ( param->type == VIK_LAYER_PARAM_BOOLEAN ) | |
46 | { | |
47 | //rv = gtk_check_button_new_with_label ( //param->title ); | |
48 | rv = gtk_check_button_new (); | |
49 | if ( data.b ) | |
50 | gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(rv), TRUE ); | |
51 | } | |
52 | break; | |
53 | case VIK_LAYER_WIDGET_COMBOBOX: | |
f33aa4e0 EB |
54 | if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data ) |
55 | { | |
56 | gchar **pstr = param->widget_data; | |
1bc1c05b | 57 | rv = vik_combo_box_text_new (); |
f33aa4e0 | 58 | while ( *pstr ) |
1bc1c05b | 59 | vik_combo_box_text_append ( rv, *(pstr++) ); |
f33aa4e0 EB |
60 | if ( param->extra_widget_data ) /* map of alternate uint values for options */ |
61 | { | |
62 | int i; | |
63 | for ( i = 0; ((const char **)param->widget_data)[i]; i++ ) | |
64 | if ( ((guint *)param->extra_widget_data)[i] == data.u ) | |
65 | { | |
66 | gtk_combo_box_set_active ( GTK_COMBO_BOX(rv), i ); | |
67 | break; | |
68 | } | |
69 | } | |
a8876892 GB |
70 | else |
71 | gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), data.u ); | |
f33aa4e0 | 72 | } |
ce37ab9b GB |
73 | else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data ) |
74 | { | |
75 | gchar **pstr = param->widget_data; | |
1bc1c05b RN |
76 | #if GTK_CHECK_VERSION (2, 24, 0) |
77 | rv = gtk_combo_box_text_new_with_entry (); | |
78 | #else | |
79 | rv = gtk_combo_box_entry_new_text (); | |
80 | #endif | |
ce37ab9b | 81 | if ( data.s ) |
1bc1c05b | 82 | vik_combo_box_text_append ( rv, data.s ); |
ce37ab9b | 83 | while ( *pstr ) |
1bc1c05b | 84 | vik_combo_box_text_append ( rv, *(pstr++) ); |
ce37ab9b GB |
85 | if ( data.s ) |
86 | gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 ); | |
87 | } | |
f33aa4e0 | 88 | break; |
f33aa4e0 EB |
89 | case VIK_LAYER_WIDGET_RADIOGROUP: |
90 | /* widget_data and extra_widget_data are GList */ | |
91 | if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data ) | |
92 | { | |
93 | rv = vik_radio_group_new ( param->widget_data ); | |
94 | if ( param->extra_widget_data ) /* map of alternate uint values for options */ | |
95 | { | |
96 | int i; | |
a8876892 | 97 | int nb_elem = g_list_length(param->widget_data); |
f33aa4e0 | 98 | for ( i = 0; i < nb_elem; i++ ) |
dc2c040e | 99 | if ( GPOINTER_TO_UINT ( g_list_nth_data(param->extra_widget_data, i) ) == data.u ) |
f33aa4e0 EB |
100 | { |
101 | vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), i ); | |
102 | break; | |
103 | } | |
104 | } | |
105 | else if ( data.u ) /* zero is already default */ | |
106 | vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), data.u ); | |
107 | } | |
108 | break; | |
109 | case VIK_LAYER_WIDGET_RADIOGROUP_STATIC: | |
110 | if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data ) | |
111 | { | |
112 | rv = vik_radio_group_new_static ( (const gchar **) param->widget_data ); | |
113 | if ( param->extra_widget_data ) /* map of alternate uint values for options */ | |
114 | { | |
115 | int i; | |
116 | for ( i = 0; ((const char **)param->widget_data)[i]; i++ ) | |
117 | if ( ((guint *)param->extra_widget_data)[i] == data.u ) | |
118 | { | |
119 | vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), i ); | |
120 | break; | |
121 | } | |
122 | } | |
123 | else if ( data.u ) /* zero is already default */ | |
124 | vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), data.u ); | |
125 | } | |
126 | break; | |
127 | case VIK_LAYER_WIDGET_SPINBUTTON: | |
128 | if ( (param->type == VIK_LAYER_PARAM_DOUBLE || param->type == VIK_LAYER_PARAM_UINT | |
129 | || param->type == VIK_LAYER_PARAM_INT) && param->widget_data ) | |
130 | { | |
131 | gdouble init_val = (param->type == VIK_LAYER_PARAM_DOUBLE) ? data.d : (param->type == VIK_LAYER_PARAM_UINT ? data.u : data.i); | |
132 | VikLayerParamScale *scale = (VikLayerParamScale *) param->widget_data; | |
ac33062d | 133 | rv = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new( init_val, scale->min, scale->max, scale->step, scale->step, 0 )), scale->step, scale->digits ); |
f33aa4e0 EB |
134 | } |
135 | break; | |
136 | case VIK_LAYER_WIDGET_ENTRY: | |
137 | if ( param->type == VIK_LAYER_PARAM_STRING ) | |
138 | { | |
139 | rv = gtk_entry_new (); | |
2f9b9d48 GS |
140 | if (data.s) |
141 | gtk_entry_set_text ( GTK_ENTRY(rv), data.s ); | |
f33aa4e0 EB |
142 | } |
143 | break; | |
d9d1084e GB |
144 | case VIK_LAYER_WIDGET_PASSWORD: |
145 | if ( param->type == VIK_LAYER_PARAM_STRING ) | |
146 | { | |
147 | rv = gtk_entry_new (); | |
148 | gtk_entry_set_visibility ( GTK_ENTRY(rv), FALSE ); | |
2f9b9d48 GS |
149 | if (data.s) |
150 | gtk_entry_set_text ( GTK_ENTRY(rv), data.s ); | |
e6994d8d RN |
151 | gtk_widget_set_tooltip_text ( GTK_WIDGET(rv), |
152 | _("Take care that this password will be stored clearly in a plain file.") ); | |
d9d1084e GB |
153 | } |
154 | break; | |
f33aa4e0 EB |
155 | case VIK_LAYER_WIDGET_FILEENTRY: |
156 | if ( param->type == VIK_LAYER_PARAM_STRING ) | |
157 | { | |
79672b85 | 158 | rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN); |
f33aa4e0 EB |
159 | vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), data.s ); |
160 | } | |
161 | break; | |
79672b85 JJ |
162 | case VIK_LAYER_WIDGET_FOLDERENTRY: |
163 | if ( param->type == VIK_LAYER_PARAM_STRING ) | |
164 | { | |
165 | rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); | |
166 | vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), data.s ); | |
167 | } | |
168 | break; | |
169 | ||
f33aa4e0 EB |
170 | case VIK_LAYER_WIDGET_FILELIST: |
171 | if ( param->type == VIK_LAYER_PARAM_STRING_LIST ) | |
172 | { | |
0d109127 | 173 | rv = vik_file_list_new ( _(param->title) ); |
f33aa4e0 EB |
174 | vik_file_list_set_files ( VIK_FILE_LIST(rv), data.sl ); |
175 | } | |
176 | break; | |
177 | case VIK_LAYER_WIDGET_HSCALE: | |
178 | if ( (param->type == VIK_LAYER_PARAM_DOUBLE || param->type == VIK_LAYER_PARAM_UINT | |
179 | || param->type == VIK_LAYER_PARAM_INT) && param->widget_data ) | |
180 | { | |
181 | gdouble init_val = (param->type == VIK_LAYER_PARAM_DOUBLE) ? data.d : (param->type == VIK_LAYER_PARAM_UINT ? data.u : data.i); | |
182 | VikLayerParamScale *scale = (VikLayerParamScale *) param->widget_data; | |
183 | rv = gtk_hscale_new_with_range ( scale->min, scale->max, scale->step ); | |
184 | gtk_scale_set_digits ( GTK_SCALE(rv), scale->digits ); | |
185 | gtk_range_set_value ( GTK_RANGE(rv), init_val ); | |
186 | } | |
187 | } | |
e6994d8d RN |
188 | if ( rv && !gtk_widget_get_tooltip_text ( rv ) ) { |
189 | if ( param->tooltip ) | |
190 | gtk_widget_set_tooltip_text ( rv, _(param->tooltip) ); | |
191 | } | |
f33aa4e0 EB |
192 | return rv; |
193 | } | |
194 | ||
195 | VikLayerParamData a_uibuilder_widget_get_value ( GtkWidget *widget, VikLayerParam *param ) | |
196 | { | |
197 | VikLayerParamData rv; | |
198 | switch ( param->widget_type ) | |
199 | { | |
200 | case VIK_LAYER_WIDGET_COLOR: | |
201 | gtk_color_button_get_color ( GTK_COLOR_BUTTON(widget), &(rv.c) ); | |
202 | break; | |
203 | case VIK_LAYER_WIDGET_CHECKBUTTON: | |
204 | rv.b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
205 | break; | |
206 | case VIK_LAYER_WIDGET_COMBOBOX: | |
ce37ab9b GB |
207 | if ( param->type == VIK_LAYER_PARAM_UINT ) |
208 | { | |
209 | rv.i = gtk_combo_box_get_active ( GTK_COMBO_BOX(widget) ); | |
210 | if ( rv.i == -1 ) rv.i = 0; | |
211 | rv.u = rv.i; | |
212 | if ( param->extra_widget_data ) | |
213 | rv.u = ((guint *)param->extra_widget_data)[rv.u]; | |
214 | } | |
215 | if ( param->type == VIK_LAYER_PARAM_STRING) | |
216 | { | |
1bc1c05b RN |
217 | #if GTK_CHECK_VERSION (2, 24, 0) |
218 | rv.s = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (widget)))); | |
219 | #else | |
ce37ab9b | 220 | rv.s = gtk_combo_box_get_active_text ( GTK_COMBO_BOX(widget) ); |
1bc1c05b | 221 | #endif |
ce37ab9b GB |
222 | g_debug("%s: %s", __FUNCTION__, rv.s); |
223 | } | |
f33aa4e0 | 224 | break; |
f33aa4e0 EB |
225 | case VIK_LAYER_WIDGET_RADIOGROUP: |
226 | case VIK_LAYER_WIDGET_RADIOGROUP_STATIC: | |
227 | rv.u = vik_radio_group_get_selected(VIK_RADIO_GROUP(widget)); | |
228 | if ( param->extra_widget_data ) | |
dc2c040e | 229 | rv.u = GPOINTER_TO_UINT ( g_list_nth_data(param->extra_widget_data, rv.u) ); |
f33aa4e0 EB |
230 | break; |
231 | case VIK_LAYER_WIDGET_SPINBUTTON: | |
232 | if ( param->type == VIK_LAYER_PARAM_UINT ) | |
233 | rv.u = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widget) ); | |
234 | else if ( param->type == VIK_LAYER_PARAM_INT ) | |
235 | rv.i = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widget) ); | |
236 | else | |
237 | rv.d = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(widget) ); | |
238 | break; | |
239 | case VIK_LAYER_WIDGET_ENTRY: | |
d9d1084e | 240 | case VIK_LAYER_WIDGET_PASSWORD: |
f33aa4e0 EB |
241 | rv.s = gtk_entry_get_text ( GTK_ENTRY(widget) ); |
242 | break; | |
243 | case VIK_LAYER_WIDGET_FILEENTRY: | |
79672b85 | 244 | case VIK_LAYER_WIDGET_FOLDERENTRY: |
f33aa4e0 EB |
245 | rv.s = vik_file_entry_get_filename ( VIK_FILE_ENTRY(widget) ); |
246 | break; | |
247 | case VIK_LAYER_WIDGET_FILELIST: | |
248 | rv.sl = vik_file_list_get_files ( VIK_FILE_LIST(widget) ); | |
249 | break; | |
250 | case VIK_LAYER_WIDGET_HSCALE: | |
251 | if ( param->type == VIK_LAYER_PARAM_UINT ) | |
252 | rv.u = (guint32) gtk_range_get_value ( GTK_RANGE(widget) ); | |
253 | else if ( param->type == VIK_LAYER_PARAM_INT ) | |
254 | rv.i = (gint32) gtk_range_get_value ( GTK_RANGE(widget) ); | |
255 | else | |
256 | rv.d = gtk_range_get_value ( GTK_RANGE(widget) ); | |
257 | break; | |
258 | } | |
259 | return rv; | |
260 | } | |
261 | ||
13fde155 | 262 | gint a_uibuilder_properties_factory ( const gchar *dialog_name, GtkWindow *parent, VikLayerParam *params, |
158b3642 RN |
263 | guint16 params_count, gchar **groups, guint8 groups_count, |
264 | gboolean (*setparam) (gpointer,guint16,VikLayerParamData,gpointer,gboolean), | |
265 | gpointer pass_along1, gpointer pass_along2, | |
266 | VikLayerParamData (*getparam) (gpointer,guint16,gboolean), | |
267 | gpointer pass_along_getparam ) | |
268 | /* pass_along1 and pass_along2 are for set_param first and last params */ | |
f33aa4e0 EB |
269 | { |
270 | guint16 i, j, widget_count = 0; | |
271 | gboolean must_redraw = FALSE; | |
272 | ||
273 | if ( ! params ) | |
274 | return 1; /* no params == no options, so all is good */ | |
275 | ||
276 | for ( i = 0; i < params_count; i++ ) | |
277 | if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES ) | |
278 | widget_count++; | |
279 | ||
280 | if ( widget_count == 0) | |
281 | return 0; /* TODO -- should be one? */ | |
282 | else | |
283 | { | |
284 | /* create widgets and titles; place in table */ | |
13fde155 | 285 | GtkWidget *dialog = gtk_dialog_new_with_buttons ( dialog_name, |
9be0449f RN |
286 | parent, |
287 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
288 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, | |
289 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL ); | |
f9d4faa9 RN |
290 | gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); |
291 | GtkWidget *response_w = NULL; | |
292 | #if GTK_CHECK_VERSION (2, 20, 0) | |
293 | response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); | |
294 | #endif | |
f33aa4e0 EB |
295 | gint resp; |
296 | ||
f33aa4e0 EB |
297 | GtkWidget *table = NULL; |
298 | GtkWidget **tables = NULL; /* for more than one group */ | |
299 | ||
300 | GtkWidget *notebook = NULL; | |
301 | GtkWidget **widgets = g_malloc ( sizeof(GtkWidget *) * widget_count ); | |
302 | ||
303 | if ( groups && groups_count > 1 ) | |
304 | { | |
305 | guint8 current_group; | |
306 | guint16 tab_widget_count; | |
307 | notebook = gtk_notebook_new (); | |
9b082b39 | 308 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), notebook, FALSE, FALSE, 0); |
f33aa4e0 EB |
309 | tables = g_malloc ( sizeof(GtkWidget *) * groups_count ); |
310 | for ( current_group = 0; current_group < groups_count; current_group++ ) | |
311 | { | |
312 | tab_widget_count = 0; | |
313 | for ( j = 0; j < params_count; j ++ ) | |
314 | if ( params[j].group == current_group ) | |
315 | tab_widget_count++; | |
316 | ||
317 | if ( tab_widget_count ) | |
318 | { | |
319 | tables[current_group] = gtk_table_new ( tab_widget_count, 1, FALSE ); | |
320 | gtk_notebook_append_page ( GTK_NOTEBOOK(notebook), tables[current_group], gtk_label_new(groups[current_group]) ); | |
321 | } | |
322 | } | |
323 | } | |
324 | else | |
325 | { | |
326 | table = gtk_table_new( widget_count, 1, FALSE ); | |
9b082b39 | 327 | gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, FALSE, FALSE, 0); |
f33aa4e0 EB |
328 | } |
329 | ||
330 | for ( i = 0, j = 0; i < params_count; i++ ) | |
331 | { | |
332 | if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES ) | |
333 | { | |
334 | if ( tables ) | |
335 | table = tables[MAX(0, params[i].group)]; /* round up NOT_IN_GROUP, that's not reasonable here */ | |
336 | ||
158b3642 | 337 | widgets[j] = a_uibuilder_new_widget ( &(params[i]), getparam ( pass_along_getparam, i, FALSE ) ); |
f33aa4e0 | 338 | |
a7023a1b RN |
339 | if ( widgets[j] ) { |
340 | gtk_table_attach ( GTK_TABLE(table), gtk_label_new(_(params[i].title)), 0, 1, j, j+1, 0, 0, 0, 0 ); | |
341 | gtk_table_attach ( GTK_TABLE(table), widgets[j], 1, 2, j, j+1, GTK_EXPAND | GTK_FILL, 0, 2, 2 ); | |
342 | } | |
f33aa4e0 EB |
343 | j++; |
344 | } | |
345 | } | |
346 | ||
f9d4faa9 RN |
347 | if ( response_w ) |
348 | gtk_widget_grab_focus ( response_w ); | |
349 | ||
f33aa4e0 EB |
350 | gtk_widget_show_all ( dialog ); |
351 | ||
352 | resp = gtk_dialog_run (GTK_DIALOG (dialog)); | |
353 | if ( resp == GTK_RESPONSE_ACCEPT ) | |
354 | { | |
355 | for ( i = 0, j = 0; i < params_count; i++ ) | |
356 | { | |
357 | if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES ) | |
358 | { | |
158b3642 RN |
359 | if ( setparam ( pass_along1, |
360 | i, | |
361 | a_uibuilder_widget_get_value ( widgets[j], &(params[i]) ), | |
362 | pass_along2, | |
363 | FALSE ) ) | |
f33aa4e0 EB |
364 | must_redraw = TRUE; |
365 | j++; | |
366 | } | |
367 | } | |
368 | ||
369 | gtk_widget_destroy ( dialog ); /* hide before redrawing. */ | |
370 | g_free ( widgets ); | |
74ace2b1 RN |
371 | if ( tables ) |
372 | g_free ( tables ); | |
f33aa4e0 EB |
373 | |
374 | return must_redraw ? 2 : 3; /* user clicked OK */ | |
375 | } | |
376 | ||
377 | if ( tables ) | |
378 | g_free ( tables ); | |
379 | gtk_widget_destroy ( dialog ); | |
380 | g_free ( widgets ); | |
381 | return 0; | |
382 | } | |
383 | } | |
384 | ||
385 | ||
386 | static void uibuilder_run_setparam ( VikLayerParamData *paramdatas, guint16 i, VikLayerParamData data, VikLayerParam *params ) | |
387 | { | |
388 | /* could have to copy it if it's a string! */ | |
389 | switch ( params[i].type ) { | |
390 | case VIK_LAYER_PARAM_STRING: | |
391 | paramdatas[i].s = g_strdup ( data.s ); | |
392 | break; | |
393 | default: | |
394 | paramdatas[i] = data; /* string list will have to be freed by layer. anything else not freed */ | |
395 | } | |
396 | } | |
397 | ||
398 | static VikLayerParamData uibuilder_run_getparam ( VikLayerParamData *params_defaults, guint16 i ) | |
399 | { | |
400 | return params_defaults[i]; | |
401 | } | |
402 | ||
403 | ||
13fde155 | 404 | VikLayerParamData *a_uibuilder_run_dialog ( const gchar *dialog_name, GtkWindow *parent, VikLayerParam *params, |
f33aa4e0 EB |
405 | guint16 params_count, gchar **groups, guint8 groups_count, |
406 | VikLayerParamData *params_defaults ) | |
407 | { | |
408 | VikLayerParamData *paramdatas = g_new(VikLayerParamData, params_count); | |
13fde155 RN |
409 | if ( a_uibuilder_properties_factory ( dialog_name, |
410 | parent, | |
dc2c040e RN |
411 | params, |
412 | params_count, | |
413 | groups, | |
414 | groups_count, | |
415 | (gpointer) uibuilder_run_setparam, | |
416 | paramdatas, | |
417 | params, | |
418 | (gpointer) uibuilder_run_getparam, | |
419 | params_defaults ) > 0 ) { | |
f33aa4e0 EB |
420 | |
421 | return paramdatas; | |
422 | } | |
423 | g_free ( paramdatas ); | |
424 | return NULL; | |
425 | } | |
426 | ||
427 | /* frees data from last (if ness) */ | |
428 | void a_uibuilder_free_paramdatas ( VikLayerParamData *paramdatas, VikLayerParam *params, guint16 params_count ) | |
429 | { | |
430 | int i; | |
431 | /* may have to free strings, etc. */ | |
432 | for ( i = 0; i < params_count; i++ ) { | |
433 | switch ( params[i].type ) { | |
434 | case VIK_LAYER_PARAM_STRING: | |
435 | g_free ( (gchar *) paramdatas[i].s ); | |
436 | break; | |
437 | case VIK_LAYER_PARAM_STRING_LIST: { | |
438 | /* should make a util function out of this */ | |
439 | GList *iter = paramdatas[i].sl; | |
440 | while ( iter ) { | |
441 | g_free ( iter->data ); | |
442 | iter = iter->next; | |
443 | } | |
444 | g_list_free ( paramdatas[i].sl ); | |
445 | break; | |
b5926b35 RN |
446 | default: |
447 | break; | |
f33aa4e0 EB |
448 | } |
449 | } | |
450 | } | |
451 | g_free ( paramdatas ); | |
452 | } |