1 /*****************************************************************************
2 * gtk_preferences.c: functions to handle the preferences dialog box.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_preferences.c,v 1.24 2002/04/21 10:32:20 sam Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
8 * Loïc Minier <lool@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
26 * Preamble: Our main job is to build a nice interface from the modules config
27 * structure. Once this is done, we need to track each change made by the
28 * user to the data contained in this interface so that when/if he decides to
29 * apply his changes we can quickly commit them into the modules config
30 * structure. (for this last task we use a GHashTable to accumulate the
31 * changes. To commit them, we then just have to circle through it )
33 *****************************************************************************/
34 #include <sys/types.h> /* off_t */
37 #include <videolan/vlc.h>
39 #ifdef MODULE_NAME_IS_gnome
47 #include "interface.h"
49 #include "gtk_support.h"
50 #include "gtk_common.h"
51 #include "gtk_preferences.h"
54 static void GtkCreateConfigDialog( char *, intf_thread_t * );
56 static void GtkConfigOk ( GtkButton *, gpointer );
57 static void GtkConfigApply ( GtkButton *, gpointer );
58 static void GtkConfigCancel ( GtkButton *, gpointer );
59 static void GtkConfigSave ( GtkButton *, gpointer );
61 static void GtkConfigDialogDestroyed ( GtkObject *, gpointer );
63 static void GtkStringChanged ( GtkEditable *, gpointer );
64 static void GtkIntChanged ( GtkEditable *, gpointer );
65 static void GtkBoolChanged ( GtkToggleButton *, gpointer );
67 static void GtkFreeHashTable ( gpointer );
68 static void GtkFreeHashValue ( gpointer, gpointer, gpointer );
69 static void GtkSaveHashValue ( gpointer, gpointer, gpointer );
71 static void GtkPluginConfigure ( GtkButton *, gpointer );
72 static void GtkPluginSelected ( GtkButton *, gpointer );
73 static void GtkPluginHighlighted ( GtkCList *, int, int, GdkEventButton *,
76 /****************************************************************************
77 * Callback for menuitems: display configuration interface window
78 ****************************************************************************/
79 void GtkPreferencesActivate( GtkMenuItem * menuitem, gpointer user_data )
81 intf_thread_t * p_intf;
83 p_intf = GetIntf( GTK_WIDGET(menuitem), (char*)user_data );
85 GtkCreateConfigDialog( "main", p_intf );
88 /****************************************************************************
89 * GtkCreateConfigDialog: dynamically creates the configuration dialog
90 * box from all the configuration data provided by the selected module.
91 ****************************************************************************/
93 /* create a new tooltipped area */
94 #define TOOLTIP( text ) \
95 /* create an event box to catch some events */ \
96 item_event_box = gtk_event_box_new(); \
97 /* add a tooltip on mouseover */ \
98 gtk_tooltips_set_tip( p_intf->p_sys->p_tooltips, \
99 item_event_box, text, "" ); \
100 gtk_container_set_border_width( GTK_CONTAINER(item_event_box), 4 );
102 /* draws a right aligned label in side of a widget */
103 #define LABEL_AND_WIDGET( label_text, widget, tooltip ) \
104 gtk_table_resize( GTK_TABLE(category_table), ++rows, 2 ); \
105 item_align = gtk_alignment_new( 1, .5, 0, 0 ); \
106 item_label = gtk_label_new( label_text ); \
107 gtk_container_add( GTK_CONTAINER(item_align), item_label ); \
108 gtk_table_attach_defaults( GTK_TABLE(category_table), item_align, \
109 0, 1, rows - 1, rows ); \
110 item_align = gtk_alignment_new( 0, .5, .5, 0 ); \
111 gtk_container_add( GTK_CONTAINER(item_align), widget ); \
113 gtk_container_add( GTK_CONTAINER(item_event_box), item_align ); \
114 gtk_table_attach_defaults( GTK_TABLE(category_table), item_event_box, \
115 1, 2, rows - 1, rows );
117 static void GtkCreateConfigDialog( char *psz_module_name,
118 intf_thread_t *p_intf )
120 module_t *p_module, *p_module_bis;
121 module_config_t *p_item;
125 GHashTable *config_hash_table;
127 GtkWidget *item_event_box;
129 GtkWidget *config_dialog;
130 GtkWidget *config_dialog_vbox;
131 GtkWidget *config_notebook;
133 GtkWidget *category_table = NULL;
134 GtkWidget *category_label = NULL;
136 #ifndef MODULE_NAME_IS_gnome
137 GtkWidget *dialog_action_area;
140 GtkWidget *ok_button;
141 GtkWidget *apply_button;
142 GtkWidget *save_button;
143 GtkWidget *cancel_button;
145 GtkWidget *item_align;
146 GtkWidget *item_frame;
147 GtkWidget *item_hbox;
148 GtkWidget *item_label;
149 GtkWidget *item_vbox;
150 GtkWidget *string_entry;
151 GtkWidget *integer_spinbutton;
153 GtkWidget *bool_checkbutton;
154 GtkWidget *plugin_clist;
155 GtkWidget *plugin_config_button;
156 GtkWidget *plugin_select_button;
158 gint category_max_height;
160 /* Check if the dialog box is already opened, if so this will save us
161 * quite a bit of work. (the interface will be destroyed when you actually
162 * close the dialog window, but remember that it is only hidden if you
163 * clicked on the action buttons). This trick also allows us not to
164 * duplicate identical dialog windows. */
166 config_dialog = (GtkWidget *)gtk_object_get_data(
167 GTK_OBJECT(p_intf->p_sys->p_window), psz_module_name );
170 /* Yeah it was open */
171 gtk_widget_show( config_dialog );
172 gtk_widget_grab_focus( config_dialog );
177 /* Look for the selected module */
178 for( p_module = p_module_bank->first ; p_module != NULL ;
179 p_module = p_module->next )
182 if( psz_module_name && !strcmp( psz_module_name, p_module->psz_name ) )
185 if( !p_module ) return;
187 /* We found it, now we can start building its configuration interface */
188 /* Create the configuration dialog box */
190 #ifdef MODULE_NAME_IS_gnome
191 config_dialog = gnome_dialog_new( p_module->psz_longname, NULL );
192 config_dialog_vbox = GNOME_DIALOG(config_dialog)->vbox;
193 category_max_height = config_GetIntVariable( "gnome_prefs_maxh" );
195 config_dialog = gtk_dialog_new();
196 gtk_window_set_title( GTK_WINDOW(config_dialog), p_module->psz_longname );
197 config_dialog_vbox = GTK_DIALOG(config_dialog)->vbox;
198 category_max_height = config_GetIntVariable( "gtk_prefs_maxh" );
201 gtk_window_set_policy( GTK_WINDOW(config_dialog), TRUE, TRUE, FALSE );
202 gtk_container_set_border_width( GTK_CONTAINER(config_dialog_vbox), 0 );
204 /* Create our config hash table and associate it with the dialog box */
205 config_hash_table = g_hash_table_new( NULL, NULL );
206 gtk_object_set_data_full( GTK_OBJECT(config_dialog),
207 "config_hash_table", config_hash_table,
208 (GtkDestroyNotify)GtkFreeHashTable );
210 /* Create notebook */
211 config_notebook = gtk_notebook_new();
212 gtk_notebook_set_scrollable( GTK_NOTEBOOK(config_notebook), TRUE );
213 gtk_container_add( GTK_CONTAINER(config_dialog_vbox), config_notebook );
215 /* Enumerate config options and add corresponding config boxes */
216 p_item = p_module->p_config;
219 switch( p_item->i_type )
222 case MODULE_CONFIG_HINT_CATEGORY:
223 case MODULE_CONFIG_HINT_END:
226 * Before we start building the interface for the new category, we
227 * must close/finish the previous one we were generating.
231 GtkWidget *_scrolled_window;
232 GtkWidget *_viewport;
234 GtkRequisition _requisition;
236 /* create a vbox to deal with EXPAND/FILL issues in the
237 * notebook page, and pack it with the previously generated
239 _vbox = gtk_vbox_new( FALSE, 0 );
240 gtk_container_set_border_width( GTK_CONTAINER(_vbox), 4 );
241 gtk_box_pack_start( GTK_BOX(_vbox), category_table,
244 /* create a new scrolled window that will contain all of the
246 _scrolled_window = gtk_scrolled_window_new( NULL, NULL );
247 gtk_scrolled_window_set_policy(
248 GTK_SCROLLED_WINDOW(_scrolled_window), GTK_POLICY_NEVER,
249 GTK_POLICY_AUTOMATIC );
250 /* add scrolled window as a notebook page */
251 gtk_notebook_append_page( GTK_NOTEBOOK(config_notebook),
252 _scrolled_window, category_label );
253 /* pack the vbox into the scrolled window */
254 _viewport = gtk_viewport_new( NULL, NULL );
255 gtk_viewport_set_shadow_type( GTK_VIEWPORT(_viewport),
257 gtk_container_add( GTK_CONTAINER(_viewport), _vbox );
258 gtk_container_add( GTK_CONTAINER(_scrolled_window),
261 /* set the size of the scrolled window to the size of the
263 gtk_widget_show_all( _vbox );
264 gtk_widget_size_request( _vbox, &_requisition );
265 if( _requisition.height > category_max_height )
266 gtk_widget_set_usize( _scrolled_window, -1,
267 category_max_height );
269 gtk_widget_set_usize( _scrolled_window, -1,
270 _requisition.height );
275 * Now we can start taking care of the new category
278 if( p_item->i_type == MODULE_CONFIG_HINT_CATEGORY )
280 /* create a new table for right-left alignment of children */
281 category_table = gtk_table_new( 0, 0, FALSE );
282 gtk_table_set_col_spacings( GTK_TABLE(category_table), 4 );
285 /* create a new category label */
286 category_label = gtk_label_new( p_item->psz_text );
291 case MODULE_CONFIG_ITEM_PLUGIN:
293 item_frame = gtk_frame_new( p_item->psz_text );
295 gtk_table_resize( GTK_TABLE(category_table), ++rows, 2 );
296 gtk_table_attach_defaults( GTK_TABLE(category_table), item_frame,
297 0, 2, rows - 1, rows );
299 item_vbox = gtk_vbox_new( FALSE, 4 );
300 gtk_container_add( GTK_CONTAINER(item_frame), item_vbox );
302 /* create a new clist widget */
304 gchar * titles[] = { _("Name"), _("Description") };
307 gtk_clist_new_with_titles( 2, titles );
309 gtk_clist_column_titles_passive( GTK_CLIST(plugin_clist) );
310 gtk_clist_set_selection_mode( GTK_CLIST(plugin_clist),
311 GTK_SELECTION_SINGLE);
312 gtk_container_add( GTK_CONTAINER(item_vbox), plugin_clist );
314 /* build a list of available plugins */
318 for( p_module_bis = p_module_bank->first ;
319 p_module_bis != NULL ;
320 p_module_bis = p_module_bis->next )
322 if( p_module_bis->i_capabilities & (1 << p_item->i_value) )
324 entry[0] = p_module_bis->psz_name;
325 entry[1] = p_module_bis->psz_longname;
326 gtk_clist_append( GTK_CLIST(plugin_clist), entry );
331 gtk_clist_set_column_auto_resize( GTK_CLIST(plugin_clist),
333 gtk_clist_set_column_auto_resize( GTK_CLIST(plugin_clist),
336 /* connect signals to the plugins list */
337 gtk_signal_connect( GTK_OBJECT(plugin_clist), "select_row",
338 GTK_SIGNAL_FUNC(GtkPluginHighlighted),
341 /* hbox holding the "select" and "configure" buttons */
342 item_hbox = gtk_hbox_new( FALSE, 4 );
343 gtk_container_add( GTK_CONTAINER(item_vbox), item_hbox);
345 /* add configure button */
346 plugin_config_button =
347 gtk_button_new_with_label( _("Configure") );
348 gtk_widget_set_sensitive( plugin_config_button, FALSE );
349 gtk_container_add( GTK_CONTAINER(item_hbox),
350 plugin_config_button );
351 gtk_object_set_data( GTK_OBJECT(plugin_config_button),
353 gtk_object_set_data( GTK_OBJECT(plugin_clist),
354 "config_button", plugin_config_button );
356 /* add select button */
357 plugin_select_button =
358 gtk_button_new_with_label( _("Select") );
359 gtk_container_add( GTK_CONTAINER(item_hbox),
360 plugin_select_button );
361 /* add a tooltip on mouseover */
362 gtk_tooltips_set_tip( p_intf->p_sys->p_tooltips,
363 plugin_select_button,
364 p_item->psz_longtext, "" );
366 /* hbox holding the "selected" label and text input */
367 item_hbox = gtk_hbox_new( FALSE, 4 );
368 gtk_container_add( GTK_CONTAINER(item_vbox), item_hbox);
370 item_label = gtk_label_new( _("Selected:") );
371 gtk_container_add( GTK_CONTAINER(item_hbox), item_label );
373 /* add input box with default value */
374 string_entry = gtk_entry_new();
375 gtk_object_set_data( GTK_OBJECT(plugin_clist),
376 "plugin_entry", string_entry );
377 gtk_container_add( GTK_CONTAINER(item_hbox), string_entry );
378 vlc_mutex_lock( p_item->p_lock );
379 gtk_entry_set_text( GTK_ENTRY(string_entry),
380 p_item->psz_value ? p_item->psz_value : "" );
381 vlc_mutex_unlock( p_item->p_lock );
382 /* add a tooltip on mouseover */
383 gtk_tooltips_set_tip( p_intf->p_sys->p_tooltips,
384 string_entry, p_item->psz_longtext, "" );
386 /* connect signals to the buttons */
387 gtk_signal_connect( GTK_OBJECT(plugin_config_button), "clicked",
388 GTK_SIGNAL_FUNC(GtkPluginConfigure),
389 (gpointer)plugin_clist );
390 gtk_signal_connect( GTK_OBJECT(plugin_select_button), "clicked",
391 GTK_SIGNAL_FUNC(GtkPluginSelected),
392 (gpointer)plugin_clist );
394 /* connect signal to track changes in the text box */
395 gtk_object_set_data( GTK_OBJECT(string_entry), "config_option",
397 gtk_signal_connect( GTK_OBJECT(string_entry), "changed",
398 GTK_SIGNAL_FUNC(GtkStringChanged),
399 (gpointer)config_dialog );
402 case MODULE_CONFIG_ITEM_STRING:
403 case MODULE_CONFIG_ITEM_FILE:
405 /* add input box with default value */
406 string_entry = gtk_entry_new();
407 vlc_mutex_lock( p_item->p_lock );
408 gtk_entry_set_text( GTK_ENTRY(string_entry),
409 p_item->psz_value ? p_item->psz_value : "" );
410 vlc_mutex_unlock( p_item->p_lock );
412 /* connect signal to track changes in the text box */
413 gtk_object_set_data( GTK_OBJECT(string_entry), "config_option",
415 gtk_signal_connect( GTK_OBJECT(string_entry), "changed",
416 GTK_SIGNAL_FUNC(GtkStringChanged),
417 (gpointer)config_dialog );
419 LABEL_AND_WIDGET( p_item->psz_text,
420 string_entry, p_item->psz_longtext );
423 case MODULE_CONFIG_ITEM_INTEGER:
425 /* add input box with default value */
426 item_adj = gtk_adjustment_new( p_item->i_value,
427 -1, 99999, 1, 10, 10 );
428 integer_spinbutton = gtk_spin_button_new( GTK_ADJUSTMENT(item_adj),
431 /* connect signal to track changes in the spinbutton value */
432 gtk_object_set_data( GTK_OBJECT(integer_spinbutton),
433 "config_option", p_item->psz_name );
434 gtk_signal_connect( GTK_OBJECT(integer_spinbutton), "changed",
435 GTK_SIGNAL_FUNC(GtkIntChanged),
436 (gpointer)config_dialog );
438 LABEL_AND_WIDGET( p_item->psz_text,
439 integer_spinbutton, p_item->psz_longtext );
442 case MODULE_CONFIG_ITEM_BOOL:
444 /* add check button */
445 bool_checkbutton = gtk_check_button_new();
446 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(bool_checkbutton),
449 /* connect signal to track changes in the button state */
450 gtk_object_set_data( GTK_OBJECT(bool_checkbutton), "config_option",
452 gtk_signal_connect( GTK_OBJECT(bool_checkbutton), "toggled",
453 GTK_SIGNAL_FUNC(GtkBoolChanged),
454 (gpointer)config_dialog );
456 LABEL_AND_WIDGET( p_item->psz_text,
457 bool_checkbutton, p_item->psz_longtext );
463 while( p_item->i_type != MODULE_CONFIG_HINT_END && p_item++ );
465 #ifndef MODULE_NAME_IS_gnome
466 /* Now let's add the action buttons at the bottom of the page */
467 dialog_action_area = GTK_DIALOG(config_dialog)->action_area;
468 gtk_container_set_border_width( GTK_CONTAINER(dialog_action_area), 4 );
470 /* add a new table for the config option */
471 item_hbox = gtk_hbox_new( FALSE, 0 );
472 gtk_box_pack_end( GTK_BOX(dialog_action_area), item_hbox,
474 item_hbox = gtk_hbox_new( FALSE, 0 );
475 gtk_box_pack_end( GTK_BOX(dialog_action_area), item_hbox,
479 /* Create the OK button */
480 #ifdef MODULE_NAME_IS_gnome
481 gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
482 GNOME_STOCK_BUTTON_OK );
484 GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
486 gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
487 GNOME_STOCK_BUTTON_APPLY );
489 GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
491 gnome_dialog_append_button_with_pixmap(
492 GNOME_DIALOG(config_dialog), _("Save"), GNOME_STOCK_PIXMAP_SAVE );
494 GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
496 gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
497 GNOME_STOCK_BUTTON_CANCEL );
499 GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
501 ok_button = gtk_button_new_with_label( _("OK") );
502 gtk_box_pack_start( GTK_BOX(dialog_action_area), ok_button,
505 apply_button = gtk_button_new_with_label( _("Apply") );
506 gtk_box_pack_start( GTK_BOX(dialog_action_area), apply_button,
509 save_button = gtk_button_new_with_label( _("Save") );
510 gtk_box_pack_start( GTK_BOX(dialog_action_area), save_button,
513 cancel_button = gtk_button_new_with_label( _("Cancel") );
514 gtk_box_pack_start( GTK_BOX(dialog_action_area), cancel_button,
518 gtk_signal_connect( GTK_OBJECT(ok_button), "clicked",
519 GTK_SIGNAL_FUNC(GtkConfigOk),
521 gtk_signal_connect( GTK_OBJECT(apply_button), "clicked",
522 GTK_SIGNAL_FUNC(GtkConfigApply),
524 gtk_signal_connect( GTK_OBJECT(save_button), "clicked",
525 GTK_SIGNAL_FUNC(GtkConfigSave),
527 gtk_signal_connect( GTK_OBJECT(cancel_button), "clicked",
528 GTK_SIGNAL_FUNC(GtkConfigCancel),
533 /* Ok, job done successfully. Let's keep a reference to the dialog box */
534 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
535 psz_module_name, config_dialog );
536 gtk_object_set_data( GTK_OBJECT(config_dialog), "psz_module_name",
539 /* we want this ref to be destroyed if the object is destroyed */
540 gtk_signal_connect( GTK_OBJECT(config_dialog), "destroy",
541 GTK_SIGNAL_FUNC(GtkConfigDialogDestroyed),
544 gtk_widget_show_all( config_dialog );
547 #undef LABEL_AND_WIDGET
550 /****************************************************************************
551 * GtkConfigApply: store the changes to the config inside the modules
552 * configuration structure
553 ****************************************************************************/
554 void GtkConfigApply( GtkButton * button, gpointer user_data )
556 GHashTable *hash_table;
557 hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
558 "config_hash_table" );
559 g_hash_table_foreach( hash_table, GtkSaveHashValue, NULL );
563 void GtkConfigOk( GtkButton * button, gpointer user_data )
565 GtkConfigApply( button, user_data );
566 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
570 void GtkConfigCancel( GtkButton * button, gpointer user_data )
572 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
575 void GtkConfigSave( GtkButton * button, gpointer user_data )
577 GtkConfigApply( button, user_data );
578 config_SaveConfigFile( NULL );
581 /****************************************************************************
582 * GtkPluginHighlighted: display plugin description when an entry is selected
583 * in the clist, and activate the configure button if necessary.
584 ****************************************************************************/
585 void GtkPluginHighlighted( GtkCList *plugin_clist, int row, int column,
586 GdkEventButton *event, gpointer user_data )
588 GtkWidget *config_button;
592 if( gtk_clist_get_text( GTK_CLIST(plugin_clist), row, 0, &psz_name ) )
594 /* look for plugin 'psz_name' */
595 for( p_module = p_module_bank->first ;
597 p_module = p_module->next )
599 if( !strcmp( p_module->psz_name, psz_name ) )
601 gtk_object_set_data( GTK_OBJECT(plugin_clist),
602 "plugin_highlighted", p_module );
603 config_button = gtk_object_get_data( GTK_OBJECT(plugin_clist),
605 if( p_module->i_config_items )
606 gtk_widget_set_sensitive( config_button, TRUE );
608 gtk_widget_set_sensitive( config_button, FALSE );
617 /****************************************************************************
618 * GtkPluginConfigure: display plugin configuration dialog box.
619 ****************************************************************************/
620 void GtkPluginConfigure( GtkButton *button, gpointer user_data )
623 intf_thread_t *p_intf;
625 p_module = (module_t *)gtk_object_get_data( GTK_OBJECT(user_data),
626 "plugin_highlighted" );
628 if( !p_module ) return;
629 p_intf = (intf_thread_t *)gtk_object_get_data( GTK_OBJECT(button),
631 GtkCreateConfigDialog( p_module->psz_name, (gpointer)p_intf );
635 /****************************************************************************
636 * GtkPluginSelected: select plugin.
637 ****************************************************************************/
638 void GtkPluginSelected( GtkButton *button, gpointer user_data )
643 p_module = (module_t *)gtk_object_get_data( GTK_OBJECT(user_data),
644 "plugin_highlighted" );
645 widget = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(user_data),
647 if( !p_module ) return;
649 gtk_entry_set_text( GTK_ENTRY(widget), p_module->psz_name );
653 /****************************************************************************
654 * GtkStringChanged: signal called when the user changes a string value.
655 ****************************************************************************/
656 static void GtkStringChanged( GtkEditable *editable, gpointer user_data )
658 module_config_t *p_config;
660 GHashTable *hash_table;
662 hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
663 "config_hash_table" );
664 /* free old p_config */
665 p_config = (module_config_t *)g_hash_table_lookup( hash_table,
666 (gpointer)editable );
667 if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
669 p_config = malloc( sizeof(module_config_t) );
670 p_config->i_type = MODULE_CONFIG_ITEM_STRING;
671 p_config->psz_value = gtk_editable_get_chars( editable, 0, -1 );
672 p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(editable),
675 g_hash_table_insert( hash_table, (gpointer)editable,
676 (gpointer)p_config );
679 /****************************************************************************
680 * GtkIntChanged: signal called when the user changes a an integer value.
681 ****************************************************************************/
682 static void GtkIntChanged( GtkEditable *editable, gpointer user_data )
684 module_config_t *p_config;
686 GHashTable *hash_table;
688 hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
689 "config_hash_table" );
691 /* free old p_config */
692 p_config = (module_config_t *)g_hash_table_lookup( hash_table,
693 (gpointer)editable );
694 if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
696 p_config = malloc( sizeof(module_config_t) );
697 p_config->i_type = MODULE_CONFIG_ITEM_INTEGER;
698 p_config->i_value = gtk_spin_button_get_value_as_int(
699 GTK_SPIN_BUTTON(editable) );
700 p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(editable),
703 g_hash_table_insert( hash_table, (gpointer)editable,
704 (gpointer)p_config );
707 /****************************************************************************
708 * GtkStringChanged: signal called when the user changes a bool value.
709 ****************************************************************************/
710 static void GtkBoolChanged( GtkToggleButton *button, gpointer user_data )
712 module_config_t *p_config;
714 GHashTable *hash_table;
716 hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
717 "config_hash_table" );
719 /* free old p_config */
720 p_config = (module_config_t *)g_hash_table_lookup( hash_table,
722 if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
724 p_config = malloc( sizeof(module_config_t) );
725 p_config->i_type = MODULE_CONFIG_ITEM_BOOL;
726 p_config->i_value = gtk_toggle_button_get_active( button );
727 p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(button),
730 g_hash_table_insert( hash_table, (gpointer)button,
731 (gpointer)p_config );
734 /****************************************************************************
735 * GtkFreeHashTable: signal called when the config hash table is destroyed.
736 ****************************************************************************/
737 static void GtkFreeHashTable( gpointer user_data )
739 GHashTable *hash_table = (GHashTable *)user_data;
741 g_hash_table_foreach( hash_table, GtkFreeHashValue, NULL );
742 g_hash_table_destroy( hash_table );
745 /****************************************************************************
746 * GtkFreeHashValue: signal called when an element of the config hash table
748 ****************************************************************************/
749 static void GtkFreeHashValue( gpointer key, gpointer value, gpointer user_data)
751 module_config_t *p_config = (module_config_t *)value;
753 if( p_config->i_type == MODULE_CONFIG_ITEM_STRING )
754 g_free( p_config->psz_value );
758 /****************************************************************************
759 * GtkSaveHashValue: callback used when enumerating the hash table in
761 ****************************************************************************/
762 static void GtkSaveHashValue( gpointer key, gpointer value, gpointer user_data)
764 module_config_t *p_config = (module_config_t *)value;
766 switch( p_config->i_type )
769 case MODULE_CONFIG_ITEM_STRING:
770 case MODULE_CONFIG_ITEM_FILE:
771 case MODULE_CONFIG_ITEM_PLUGIN:
772 config_PutPszVariable( p_config->psz_name,
773 *p_config->psz_value? p_config->psz_value : NULL );
775 case MODULE_CONFIG_ITEM_INTEGER:
776 case MODULE_CONFIG_ITEM_BOOL:
777 config_PutIntVariable( p_config->psz_name, p_config->i_value );
782 /****************************************************************************
783 * GtkConfigDialogDestroyed: callback triggered when the config dialog box is
785 ****************************************************************************/
786 static void GtkConfigDialogDestroyed( GtkObject *object, gpointer user_data )
788 intf_thread_t *p_intf = (intf_thread_t *)user_data;
789 char *psz_module_name;
791 psz_module_name = gtk_object_get_data( object, "psz_module_name" );
793 /* remove the ref to the dialog box */
794 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
795 psz_module_name, NULL );