]> git.street.me.uk Git - andy/viking.git/blob - src/uibuilder.c
Merge pull request #32 from davidedelvento/installnotes
[andy/viking.git] / src / uibuilder.c
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  */
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gtk/gtk.h>
26 #include <glib/gi18n.h>
27 #include "uibuilder.h"
28 #include "vikradiogroup.h"
29 #include "vikfileentry.h"
30 #include "vikfilelist.h"
31
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
35 /** i18n note
36  * Since UI builder often uses static structures, the text is marked with N_()
37  *  however to actually get it to apply the widget (e.g. to a label) then
38  *  an additional call to _() needs to occur on that string
39  **/
40
41 GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data )
42 {
43   // Perform pre conversion if necessary
44   VikLayerParamData vlpd = data;
45   if ( param->convert_to_display )
46    vlpd = param->convert_to_display ( data );
47
48   GtkWidget *rv = NULL;
49   switch ( param->widget_type )
50   {
51     case VIK_LAYER_WIDGET_COLOR:
52       if ( param->type == VIK_LAYER_PARAM_COLOR )
53         rv = gtk_color_button_new_with_color ( &(vlpd.c) );
54       break;
55     case VIK_LAYER_WIDGET_CHECKBUTTON:
56       if ( param->type == VIK_LAYER_PARAM_BOOLEAN )
57       {
58         //rv = gtk_check_button_new_with_label ( //param->title );
59         rv = gtk_check_button_new ();
60         if ( vlpd.b )
61           gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(rv), TRUE );
62       }
63       break;
64     case VIK_LAYER_WIDGET_COMBOBOX:
65       if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data )
66       {
67         /* Build a simple combobox */
68         gchar **pstr = param->widget_data;
69         rv = vik_combo_box_text_new ();
70         while ( *pstr )
71           vik_combo_box_text_append ( rv, _(*(pstr++)) );
72         if ( param->extra_widget_data ) /* map of alternate uint values for options */
73         {
74           /* Set the effective default value */
75           int i;
76           for ( i = 0; ((const char **)param->widget_data)[i]; i++ )
77             if ( ((guint *)param->extra_widget_data)[i] == vlpd.u )
78             {
79               /* Match default value */
80               gtk_combo_box_set_active ( GTK_COMBO_BOX(rv), i );
81               break;
82             }
83         }
84         else
85           gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), vlpd.u );
86       }
87       else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data && !param->extra_widget_data )
88       {
89         /* Build a combobox with editable text */
90         gchar **pstr = param->widget_data;
91 #if GTK_CHECK_VERSION (2, 24, 0)
92         rv = gtk_combo_box_text_new_with_entry ();
93 #else
94         rv = gtk_combo_box_entry_new_text ();
95 #endif
96         if ( vlpd.s )
97           vik_combo_box_text_append ( rv, _(vlpd.s) );
98         while ( *pstr )
99           vik_combo_box_text_append ( rv, _(*(pstr++)) );
100         if ( vlpd.s )
101           gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 );
102       }
103       else if ( param->type == VIK_LAYER_PARAM_STRING && param->widget_data && param->extra_widget_data)
104       {
105         /* Build a combobox with fixed selections without editable text */
106         gchar **pstr = param->widget_data;
107         rv = GTK_WIDGET ( vik_combo_box_text_new () );
108         while ( *pstr )
109           vik_combo_box_text_append ( rv, _(*(pstr++)) );
110         if ( vlpd.s )
111         {
112           /* Set the effective default value */
113           /* In case of value does not exist, set the first value */
114           gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 );
115           int i;
116           for ( i = 0; ((const char **)param->widget_data)[i]; i++ )
117             if ( strcmp(((const char **)param->extra_widget_data)[i], vlpd.s) == 0 )
118             {
119               /* Match default value */
120               gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), i );
121               break; 
122             }
123         }
124         else
125           gtk_combo_box_set_active ( GTK_COMBO_BOX ( rv ), 0 );
126       }
127       break;
128     case VIK_LAYER_WIDGET_RADIOGROUP:
129       /* widget_data and extra_widget_data are GList */
130       if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data )
131       {
132         rv = vik_radio_group_new ( param->widget_data );
133         if ( param->extra_widget_data ) /* map of alternate uint values for options */
134         {
135           int i;
136           int nb_elem = g_list_length(param->widget_data);
137           for ( i = 0; i < nb_elem; i++ )
138             if ( GPOINTER_TO_UINT ( g_list_nth_data(param->extra_widget_data, i) ) == vlpd.u )
139             {
140               vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), i );
141               break;
142             }
143         }
144         else if ( vlpd.u ) /* zero is already default */
145           vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), vlpd.u );
146       }
147       break;
148     case VIK_LAYER_WIDGET_RADIOGROUP_STATIC:
149       if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data )
150       {
151         rv = vik_radio_group_new_static ( (const gchar **) param->widget_data );
152         if ( param->extra_widget_data ) /* map of alternate uint values for options */
153         {
154           int i;
155           for ( i = 0; ((const char **)param->widget_data)[i]; i++ )
156             if ( ((guint *)param->extra_widget_data)[i] == vlpd.u )
157             {
158               vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), i );
159               break;
160             }
161         }
162         else if ( vlpd.u ) /* zero is already default */
163           vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), vlpd.u );
164       }
165       break;
166     case VIK_LAYER_WIDGET_SPINBUTTON:
167       if ( (param->type == VIK_LAYER_PARAM_DOUBLE || param->type == VIK_LAYER_PARAM_UINT
168            || param->type == VIK_LAYER_PARAM_INT)  && param->widget_data )
169       {
170         gdouble init_val = (param->type == VIK_LAYER_PARAM_DOUBLE) ? vlpd.d : (param->type == VIK_LAYER_PARAM_UINT ? vlpd.u : vlpd.i);
171         VikLayerParamScale *scale = (VikLayerParamScale *) param->widget_data;
172         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 );
173       }
174     break;
175     case VIK_LAYER_WIDGET_ENTRY:
176       if ( param->type == VIK_LAYER_PARAM_STRING )
177       {
178         rv = gtk_entry_new ();
179         if ( vlpd.s )
180           gtk_entry_set_text ( GTK_ENTRY(rv), vlpd.s );
181       }
182       break;
183     case VIK_LAYER_WIDGET_PASSWORD:
184       if ( param->type == VIK_LAYER_PARAM_STRING )
185       {
186         rv = gtk_entry_new ();
187         gtk_entry_set_visibility ( GTK_ENTRY(rv), FALSE );
188         if ( vlpd.s )
189           gtk_entry_set_text ( GTK_ENTRY(rv), vlpd.s );
190         gtk_widget_set_tooltip_text ( GTK_WIDGET(rv),
191                                      _("Take care that this password will be stored clearly in a plain file.") );
192       }
193       break;
194     case VIK_LAYER_WIDGET_FILEENTRY:
195       if ( param->type == VIK_LAYER_PARAM_STRING )
196       {
197         rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, GPOINTER_TO_INT(param->widget_data), NULL, NULL);
198         if ( vlpd.s )
199           vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), vlpd.s );
200       }
201       break;
202     case VIK_LAYER_WIDGET_FOLDERENTRY:
203       if ( param->type == VIK_LAYER_PARAM_STRING )
204       {
205         rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, VF_FILTER_NONE, NULL, NULL);
206         if ( vlpd.s )
207           vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), vlpd.s );
208       }
209       break;
210
211     case VIK_LAYER_WIDGET_FILELIST:
212       if ( param->type == VIK_LAYER_PARAM_STRING_LIST )
213       {
214         rv = vik_file_list_new ( _(param->title), NULL );
215         vik_file_list_set_files ( VIK_FILE_LIST(rv), vlpd.sl );
216       }
217       break;
218     case VIK_LAYER_WIDGET_HSCALE:
219       if ( (param->type == VIK_LAYER_PARAM_DOUBLE || param->type == VIK_LAYER_PARAM_UINT
220            || param->type == VIK_LAYER_PARAM_INT)  && param->widget_data )
221       {
222         gdouble init_val = (param->type == VIK_LAYER_PARAM_DOUBLE) ? vlpd.d : (param->type == VIK_LAYER_PARAM_UINT ? vlpd.u : vlpd.i);
223         VikLayerParamScale *scale = (VikLayerParamScale *) param->widget_data;
224         rv = gtk_hscale_new_with_range ( scale->min, scale->max, scale->step );
225         gtk_scale_set_digits ( GTK_SCALE(rv), scale->digits );
226         gtk_range_set_value ( GTK_RANGE(rv), init_val );
227       }
228       break;
229
230     case VIK_LAYER_WIDGET_BUTTON:
231       if ( param->type == VIK_LAYER_PARAM_PTR && param->widget_data ) {
232         rv = gtk_button_new_with_label ( _(param->widget_data) );
233         g_signal_connect ( G_OBJECT(rv), "clicked", G_CALLBACK (vlpd.ptr), param->extra_widget_data );
234       }
235       break;
236
237     default: break;
238   }
239   if ( rv && !gtk_widget_get_tooltip_text ( rv ) ) {
240     if ( param->tooltip )
241       gtk_widget_set_tooltip_text ( rv, _(param->tooltip) );
242   }
243   return rv;
244 }
245
246 VikLayerParamData a_uibuilder_widget_get_value ( GtkWidget *widget, VikLayerParam *param )
247 {
248   VikLayerParamData rv;
249   switch ( param->widget_type )
250   {
251     case VIK_LAYER_WIDGET_COLOR:
252       gtk_color_button_get_color ( GTK_COLOR_BUTTON(widget), &(rv.c) );
253       break;
254     case VIK_LAYER_WIDGET_CHECKBUTTON:
255       rv.b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
256       break;
257     case VIK_LAYER_WIDGET_COMBOBOX:
258       if ( param->type == VIK_LAYER_PARAM_UINT )
259       {
260         rv.i = gtk_combo_box_get_active ( GTK_COMBO_BOX(widget) );
261         if ( rv.i == -1 ) rv.i = 0;
262         rv.u = rv.i;
263         if ( param->extra_widget_data )
264           rv.u = ((guint *)param->extra_widget_data)[rv.u];
265       }
266       if ( param->type == VIK_LAYER_PARAM_STRING)
267       {
268         if ( param->extra_widget_data )
269         {
270           /* Combobox displays labels and we want values from extra */
271           int pos = gtk_combo_box_get_active ( GTK_COMBO_BOX(widget) );
272           rv.s = ((const char **)param->extra_widget_data)[pos];
273         }
274         else
275         {
276           /* Return raw value */
277 #if GTK_CHECK_VERSION (2, 24, 0)
278           rv.s = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (widget))));
279 #else
280           rv.s = gtk_combo_box_get_active_text ( GTK_COMBO_BOX(widget) );
281 #endif
282         }
283         g_debug("%s: %s", __FUNCTION__, rv.s);
284       }
285       break;
286     case VIK_LAYER_WIDGET_RADIOGROUP:
287     case VIK_LAYER_WIDGET_RADIOGROUP_STATIC:
288       rv.u = vik_radio_group_get_selected(VIK_RADIO_GROUP(widget));
289       if ( param->extra_widget_data )
290         rv.u = GPOINTER_TO_UINT ( g_list_nth_data(param->extra_widget_data, rv.u) );
291       break;
292     case VIK_LAYER_WIDGET_SPINBUTTON:
293       if ( param->type == VIK_LAYER_PARAM_UINT )
294         rv.u = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widget) );
295       else if ( param->type == VIK_LAYER_PARAM_INT )
296         rv.i = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widget) );
297       else
298         rv.d = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(widget) );
299       break;
300     case VIK_LAYER_WIDGET_ENTRY:
301     case VIK_LAYER_WIDGET_PASSWORD:
302       rv.s = gtk_entry_get_text ( GTK_ENTRY(widget) );
303       break;
304     case VIK_LAYER_WIDGET_FILEENTRY:
305     case VIK_LAYER_WIDGET_FOLDERENTRY:
306       rv.s = vik_file_entry_get_filename ( VIK_FILE_ENTRY(widget) );
307       break;
308     case VIK_LAYER_WIDGET_FILELIST:
309       rv.sl = vik_file_list_get_files ( VIK_FILE_LIST(widget) );
310       break;
311     case VIK_LAYER_WIDGET_HSCALE:
312       if ( param->type == VIK_LAYER_PARAM_UINT )
313         rv.u = (guint32) gtk_range_get_value ( GTK_RANGE(widget) );
314       else if ( param->type == VIK_LAYER_PARAM_INT )
315         rv.i = (gint32) gtk_range_get_value ( GTK_RANGE(widget) );
316       else
317         rv.d = gtk_range_get_value ( GTK_RANGE(widget) );
318       break;
319     default: break;
320   }
321
322   // Perform conversion if necessary
323   if ( param->convert_to_internal )
324     rv = param->convert_to_internal ( rv );
325
326   return rv;
327 }
328
329 //static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointer *pass_along)
330 gint a_uibuilder_properties_factory ( const gchar *dialog_name,
331                                       GtkWindow *parent,
332                                       VikLayerParam *params,
333                                       guint16 params_count,
334                                       gchar **groups,
335                                       guint8 groups_count,
336                                       gboolean (*setparam) (gpointer,gpointer),
337                                       gboolean (*setparam4) (gpointer,guint16,VikLayerParamData,gpointer),
338                                       gpointer pass_along1,
339                                       gpointer pass_along2,
340                                       VikLayerParamData (*getparam) (gpointer,guint16,gboolean),
341                                       gpointer pass_along_getparam,
342                                       void (*changeparam) (GtkWidget*, ui_change_values) )
343 {
344   guint16 i, j, widget_count = 0;
345   gboolean must_redraw = FALSE;
346
347   if ( ! params )
348     return 1; /* no params == no options, so all is good */
349
350   for ( i = 0; i < params_count; i++ )
351     if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES )
352       widget_count++;
353
354   if ( widget_count == 0)
355     return 0; /* TODO -- should be one? */
356   else
357   {
358     /* create widgets and titles; place in table */
359     GtkWidget *dialog = gtk_dialog_new_with_buttons ( dialog_name,
360                                                       parent,
361                                                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
362                                                       GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
363                                                       GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL );
364     gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
365     GtkWidget *response_w = NULL;
366 #if GTK_CHECK_VERSION (2, 20, 0)
367     response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
368 #endif
369     gint resp;
370
371     GtkWidget *table = NULL;
372     GtkWidget **tables = NULL; /* for more than one group */
373
374     GtkWidget *notebook = NULL;
375     GtkWidget **labels = g_malloc ( sizeof(GtkWidget *) * widget_count );
376     GtkWidget **widgets = g_malloc ( sizeof(GtkWidget *) * widget_count );
377     ui_change_values *change_values = g_malloc ( sizeof(ui_change_values) * widget_count );
378
379     if ( groups && groups_count > 1 )
380     {
381       guint8 current_group;
382       guint16 tab_widget_count;
383       notebook = gtk_notebook_new ();
384       // Switch to vertical notebook mode when many groups
385       if ( groups_count > 4 )
386         gtk_notebook_set_tab_pos ( GTK_NOTEBOOK(notebook), GTK_POS_LEFT );
387       gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), notebook, FALSE, FALSE, 0);
388       tables = g_malloc ( sizeof(GtkWidget *) * groups_count );
389       for ( current_group = 0; current_group < groups_count; current_group++ )
390       {
391         tab_widget_count = 0;
392         for ( j = 0; j < params_count; j ++ )
393           if ( params[j].group == current_group )
394             tab_widget_count++;
395
396         if ( tab_widget_count )
397         {
398           tables[current_group] = gtk_table_new ( tab_widget_count, 1, FALSE );
399           gtk_notebook_append_page ( GTK_NOTEBOOK(notebook), tables[current_group], gtk_label_new(groups[current_group]) );
400         }
401       }
402     }
403     else
404     {
405       table = gtk_table_new( widget_count, 1, FALSE );
406       gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table, FALSE, FALSE, 0);
407     }
408
409     for ( i = 0, j = 0; i < params_count; i++ )
410     {
411       if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES )
412       {
413         if ( tables )
414           table = tables[MAX(0, params[i].group)]; /* round up NOT_IN_GROUP, that's not reasonable here */
415
416         widgets[j] = a_uibuilder_new_widget ( &(params[i]), getparam ( pass_along_getparam, i, FALSE ) );
417
418         if ( widgets[j] ) {
419           labels[j] = gtk_label_new(_(params[i].title));
420           gtk_table_attach ( GTK_TABLE(table), labels[j], 0, 1, j, j+1, 0, 0, 0, 0 );
421           gtk_table_attach ( GTK_TABLE(table), widgets[j], 1, 2, j, j+1, GTK_EXPAND | GTK_FILL, 0, 2, 2 );
422
423           if ( changeparam )
424           {
425             change_values[j][UI_CHG_LAYER] = pass_along1;
426             change_values[j][UI_CHG_PARAM] = &params[i];
427             change_values[j][UI_CHG_PARAM_ID] = GINT_TO_POINTER((gint)i);
428             change_values[j][UI_CHG_WIDGETS] = widgets;
429             change_values[j][UI_CHG_LABELS] = labels;
430
431             switch ( params[i].widget_type )
432             {
433               // Change conditions for other widget types can be added when needed
434               case VIK_LAYER_WIDGET_COMBOBOX:
435                 g_signal_connect ( G_OBJECT(widgets[j]), "changed", G_CALLBACK(changeparam), change_values[j] );
436                 break;
437               case VIK_LAYER_WIDGET_CHECKBUTTON:
438                 g_signal_connect ( G_OBJECT(widgets[j]), "toggled", G_CALLBACK(changeparam), change_values[j] );
439                 break;
440               default: break;
441             }
442           }
443         }
444         j++;
445       }
446     }
447
448     // Repeat run through to force changeparam callbacks now that the widgets have been created
449     // This primarily so the widget sensitivities get set up
450     if ( changeparam ) {
451       for ( i = 0, j = 0; i < params_count; i++ ) {
452         if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES ) {
453           if ( widgets[j] ) {
454             changeparam ( widgets[j], change_values[j] );
455           }
456           j++;
457         }
458       }
459     }
460
461     if ( response_w )
462       gtk_widget_grab_focus ( response_w );
463
464     gtk_widget_show_all ( dialog );
465
466     resp = gtk_dialog_run (GTK_DIALOG (dialog));
467     if ( resp == GTK_RESPONSE_ACCEPT )
468     {
469       VikLayerSetParam vlsp;
470       vlsp.is_file_operation = FALSE;
471       vlsp.dirpath = NULL;
472       for ( i = 0, j = 0; i < params_count; i++ )
473       {
474         if ( params[i].group != VIK_LAYER_NOT_IN_PROPERTIES )
475         {
476           vlsp.id = i;
477           vlsp.vp = pass_along2;
478           vlsp.data = a_uibuilder_widget_get_value ( widgets[j], &(params[i]) );
479           // Main callback into each layer's setparam
480           if ( setparam && setparam ( pass_along1, &vlsp ) )
481             must_redraw = TRUE;
482           // Or a basic callback for each parameter
483           else if ( setparam4 && setparam4 ( pass_along1, i, vlsp.data, pass_along2 ) )
484             must_redraw = TRUE;
485           j++;
486         }
487       }
488
489       g_free ( widgets );
490       g_free ( labels );
491       g_free ( change_values );
492       if ( tables )
493         g_free ( tables );
494       gtk_widget_destroy ( dialog ); /* hide before redrawing. */
495
496       return must_redraw ? 2 : 3; /* user clicked OK */
497     }
498
499     g_free ( widgets );
500     g_free ( labels );
501     g_free ( change_values );
502     if ( tables )
503       g_free ( tables );
504     gtk_widget_destroy ( dialog );
505
506     return 0;
507   }
508 }
509
510
511 static void uibuilder_run_setparam ( VikLayerParamData *paramdatas, guint16 i, VikLayerParamData data, VikLayerParam *params )
512 {
513   /* could have to copy it if it's a string! */
514   switch ( params[i].type ) {
515     case VIK_LAYER_PARAM_STRING:
516       paramdatas[i].s = g_strdup ( data.s );
517       break;
518     default:
519      paramdatas[i] = data; /* string list will have to be freed by layer. anything else not freed */
520   }
521 }
522
523 static VikLayerParamData uibuilder_run_getparam ( VikLayerParamData *params_defaults, guint16 i )
524 {
525   return params_defaults[i];
526 }
527
528
529 VikLayerParamData *a_uibuilder_run_dialog (  const gchar *dialog_name, GtkWindow *parent, VikLayerParam *params,
530                         guint16 params_count, gchar **groups, guint8 groups_count,
531                         VikLayerParamData *params_defaults )
532 {
533     VikLayerParamData *paramdatas = g_new(VikLayerParamData, params_count);
534     if ( a_uibuilder_properties_factory ( dialog_name,
535                                           parent,
536                                           params, 
537                                           params_count, 
538                                           groups, 
539                                           groups_count,
540                                           NULL,
541                                           (gpointer) uibuilder_run_setparam, 
542                                           paramdatas, 
543                                           params,
544                                           (gpointer) uibuilder_run_getparam, 
545                                           params_defaults,
546                                           NULL ) > 0 ) {
547
548       return paramdatas;
549     }
550     g_free ( paramdatas );
551     return NULL;
552 }
553
554 /* frees data from last (if ness) */
555 void a_uibuilder_free_paramdatas ( VikLayerParamData *paramdatas, VikLayerParam *params, guint16 params_count )
556 {
557   int i;
558   /* may have to free strings, etc. */
559   for ( i = 0; i < params_count; i++ ) {
560     switch ( params[i].type ) {
561       case VIK_LAYER_PARAM_STRING:
562         g_free ( (gchar *) paramdatas[i].s );
563         break;
564       case VIK_LAYER_PARAM_STRING_LIST: {
565         /* should make a util function out of this */
566         GList *iter = paramdatas[i].sl;
567         while ( iter ) {
568           g_free ( iter->data );
569           iter = iter->next;
570         }
571         g_list_free ( paramdatas[i].sl );
572         break;
573       default:
574         break;
575       }
576     }
577   }
578   g_free ( paramdatas );
579 }