* ALL: internationalized all configuration strings.
[vlc.git] / plugins / gtk / gtk_preferences.c
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.22 2002/04/19 13:56:11 sam Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *          Loïc Minier <lool@via.ecp.fr>
9  *
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.
14  * 
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.
19  *
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  *****************************************************************************/
24
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 )
32  *
33  *****************************************************************************/
34 #include <sys/types.h>                                              /* off_t */
35 #include <stdlib.h>
36
37 #include <videolan/vlc.h>
38
39 #ifdef MODULE_NAME_IS_gnome
40 #   include <gnome.h>
41 #else
42 #   include <gtk/gtk.h>
43 #endif
44
45 #include <string.h>
46
47 #include "interface.h"
48
49 #include "gtk_support.h"
50 #include "gtk_common.h"
51 #include "gtk_preferences.h"
52
53 /* local functions */
54 static void GtkCreateConfigDialog( char *, intf_thread_t * );
55
56 static void GtkConfigOk          ( GtkButton *, gpointer );
57 static void GtkConfigApply       ( GtkButton *, gpointer );
58 static void GtkConfigCancel      ( GtkButton *, gpointer );
59 static void GtkConfigSave        ( GtkButton *, gpointer );
60
61 static void GtkConfigDialogDestroyed ( GtkObject *, gpointer );
62
63 static void GtkStringChanged     ( GtkEditable *, gpointer );
64 static void GtkIntChanged        ( GtkEditable *, gpointer );
65 static void GtkBoolChanged       ( GtkToggleButton *, gpointer );
66
67 static void GtkFreeHashTable     ( gpointer );
68 static void GtkFreeHashValue     ( gpointer, gpointer, gpointer );
69 static void GtkSaveHashValue     ( gpointer, gpointer, gpointer );
70
71 static void GtkPluginConfigure   ( GtkButton *, gpointer );
72 static void GtkPluginSelected    ( GtkButton *, gpointer );
73 static void GtkPluginHighlighted ( GtkCList *, int, int, GdkEventButton *,
74                                    gpointer );
75
76 /****************************************************************************
77  * Callback for menuitems: display configuration interface window
78  ****************************************************************************/
79 void GtkPreferencesActivate( GtkMenuItem * menuitem, gpointer user_data )
80 {
81     intf_thread_t * p_intf;
82
83     p_intf = GetIntf( GTK_WIDGET(menuitem), (char*)user_data );
84
85     GtkCreateConfigDialog( "main", p_intf );
86 }
87
88 /****************************************************************************
89  * GtkCreateConfigDialog: dynamically creates the configuration dialog
90  * box from all the configuration data provided by the selected module.
91  ****************************************************************************/
92
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 );
101
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 );               \
112     TOOLTIP(tooltip)                                                      \
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 );
116
117 static void GtkCreateConfigDialog( char *psz_module_name,
118                                    intf_thread_t *p_intf )
119 {
120     module_t *p_module, *p_module_bis;
121     module_config_t *p_item;
122
123     guint rows = 0;
124
125     GHashTable *config_hash_table;
126
127     GtkWidget *item_event_box;
128
129     GtkWidget *config_dialog;
130     GtkWidget *config_dialog_vbox;
131     GtkWidget *config_notebook;
132
133     GtkWidget *category_table = NULL;
134     GtkWidget *category_label = NULL;
135
136 #ifndef MODULE_NAME_IS_gnome
137     GtkWidget *dialog_action_area;
138 #endif
139
140     GtkWidget *ok_button;
141     GtkWidget *apply_button;
142     GtkWidget *save_button;
143     GtkWidget *cancel_button;
144
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;
152     GtkObject *item_adj;
153     GtkWidget *bool_checkbutton;
154     GtkWidget *plugin_clist;
155     GtkWidget *plugin_config_button;
156     GtkWidget *plugin_select_button;
157
158     gint category_max_height;
159
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. */
165
166     config_dialog = (GtkWidget *)gtk_object_get_data(
167                     GTK_OBJECT(p_intf->p_sys->p_window), psz_module_name );
168     if( config_dialog )
169     {
170         /* Yeah it was open */
171         gtk_widget_show( config_dialog );
172         gtk_widget_grab_focus( config_dialog );
173         return;
174     }
175
176
177     /* Look for the selected module */
178     for( p_module = p_module_bank->first ; p_module != NULL ;
179          p_module = p_module->next )
180     {
181
182         if( psz_module_name && !strcmp( psz_module_name, p_module->psz_name ) )
183             break;
184     }
185     if( !p_module ) return;
186
187     /* We found it, now we can start building its configuration interface */
188     /* Create the configuration dialog box */
189
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" );
194 #else
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" );
199 #endif
200
201     gtk_window_set_policy( GTK_WINDOW(config_dialog), TRUE, TRUE, FALSE );
202     gtk_container_set_border_width( GTK_CONTAINER(config_dialog_vbox), 0 );
203
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 );
209
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 );
214
215     /* Enumerate config options and add corresponding config boxes */
216     p_item = p_module->p_config;
217     do
218     {
219         switch( p_item->i_type )
220         {
221
222         case MODULE_CONFIG_HINT_CATEGORY:
223         case MODULE_CONFIG_HINT_END:
224
225             /*
226              * Before we start building the interface for the new category, we
227              * must close/finish the previous one we were generating.
228              */
229             if( category_table )
230             {
231                 GtkWidget *_scrolled_window;
232                 GtkWidget *_viewport;
233                 GtkWidget *_vbox;
234                 GtkRequisition _requisition;
235
236                 /* create a vbox to deal with EXPAND/FILL issues in the
237                  * notebook page, and pack it with the previously generated
238                  * category_table */
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,
242                                     FALSE, FALSE, 0 );
243
244                 /* create a new scrolled window that will contain all of the
245                  * above. */
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),
256                                               GTK_SHADOW_NONE );
257                 gtk_container_add( GTK_CONTAINER(_viewport), _vbox );
258                 gtk_container_add( GTK_CONTAINER(_scrolled_window),
259                                    _viewport );
260
261                 /* set the size of the scrolled window to the size of the
262                  * child widget */
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 );
268                 else
269                     gtk_widget_set_usize( _scrolled_window, -1,
270                                           _requisition.height );
271
272             }
273
274             /*
275              * Now we can start taking care of the new category
276              */
277
278             if( p_item->i_type == MODULE_CONFIG_HINT_CATEGORY )
279             {
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 );
283                 rows = 0;
284
285                 /* create a new category label */
286                 category_label = gtk_label_new( p_item->psz_text );
287             }
288
289             break;
290
291         case MODULE_CONFIG_ITEM_PLUGIN:
292
293             item_frame = gtk_frame_new( p_item->psz_text );
294
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 );
298
299             item_vbox = gtk_vbox_new( FALSE, 4 );
300             gtk_container_add( GTK_CONTAINER(item_frame), item_vbox );
301
302             /* create a new clist widget */
303             {
304                 gchar * titles[] = { _("Name"), _("Description") };
305
306                 plugin_clist =
307                     gtk_clist_new_with_titles( 2, titles );
308             }
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 );
313
314             /* build a list of available plugins */
315             {
316                 gchar * entry[2];
317
318                 for( p_module_bis = p_module_bank->first ;
319                      p_module_bis != NULL ;
320                      p_module_bis = p_module_bis->next )
321                 {
322                     if( p_module_bis->i_capabilities & (1 << p_item->i_value) )
323                     {
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 );
327                     }
328                 }
329             }
330
331             gtk_clist_set_column_auto_resize( GTK_CLIST(plugin_clist),
332                                               0, TRUE );
333             gtk_clist_set_column_auto_resize( GTK_CLIST(plugin_clist),
334                                               1, TRUE );
335
336             /* connect signals to the plugins list */
337             gtk_signal_connect( GTK_OBJECT(plugin_clist), "select_row",
338                                 GTK_SIGNAL_FUNC(GtkPluginHighlighted),
339                                 NULL );
340
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);
344
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),
352                                  "p_intf", p_intf );
353             gtk_object_set_data( GTK_OBJECT(plugin_clist),
354                                  "config_button", plugin_config_button );
355
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, "" );
365
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);
369             /* add new label */
370             item_label = gtk_label_new( _("Selected:") );
371             gtk_container_add( GTK_CONTAINER(item_hbox), item_label );
372
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, "" );
385
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 );
393
394             /* connect signal to track changes in the text box */
395             gtk_object_set_data( GTK_OBJECT(string_entry), "config_option",
396                                  p_item->psz_name );
397             gtk_signal_connect( GTK_OBJECT(string_entry), "changed",
398                                 GTK_SIGNAL_FUNC(GtkStringChanged),
399                                 (gpointer)config_dialog );
400             break;
401
402         case MODULE_CONFIG_ITEM_STRING:
403         case MODULE_CONFIG_ITEM_FILE:
404
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 );
411
412             /* connect signal to track changes in the text box */
413             gtk_object_set_data( GTK_OBJECT(string_entry), "config_option",
414                                  p_item->psz_name );
415             gtk_signal_connect( GTK_OBJECT(string_entry), "changed",
416                                 GTK_SIGNAL_FUNC(GtkStringChanged),
417                                 (gpointer)config_dialog );
418
419             LABEL_AND_WIDGET( p_item->psz_text,
420                               string_entry, p_item->psz_longtext );
421             break;
422
423         case MODULE_CONFIG_ITEM_INTEGER:
424
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),
429                                                       1, 0 );
430
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 );
437
438             LABEL_AND_WIDGET( p_item->psz_text,
439                               integer_spinbutton, p_item->psz_longtext );
440             break;
441
442         case MODULE_CONFIG_ITEM_BOOL:
443
444             /* add check button */
445             bool_checkbutton = gtk_check_button_new();
446             gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(bool_checkbutton),
447                                           p_item->i_value );
448
449             /* connect signal to track changes in the button state */
450             gtk_object_set_data( GTK_OBJECT(bool_checkbutton), "config_option",
451                                  p_item->psz_name );
452             gtk_signal_connect( GTK_OBJECT(bool_checkbutton), "toggled",
453                                 GTK_SIGNAL_FUNC(GtkBoolChanged),
454                                 (gpointer)config_dialog );
455
456             LABEL_AND_WIDGET( p_item->psz_text,
457                               bool_checkbutton, p_item->psz_longtext );
458             break;
459
460         }
461
462         p_item++;
463     }
464     while( p_item->i_type != MODULE_CONFIG_HINT_END );
465
466 #ifndef MODULE_NAME_IS_gnome
467     /* Now let's add the action buttons at the bottom of the page */
468     dialog_action_area = GTK_DIALOG(config_dialog)->action_area;
469     gtk_container_set_border_width( GTK_CONTAINER(dialog_action_area), 4 );
470
471     /* add a new table for the config option */
472     item_hbox = gtk_hbox_new( FALSE, 0 );
473     gtk_box_pack_end( GTK_BOX(dialog_action_area), item_hbox,
474                       TRUE, FALSE, 0 );
475     item_hbox = gtk_hbox_new( FALSE, 0 );
476     gtk_box_pack_end( GTK_BOX(dialog_action_area), item_hbox,
477                       TRUE, FALSE, 0 );
478 #endif
479
480     /* Create the OK button */
481 #ifdef MODULE_NAME_IS_gnome
482     gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
483                                 GNOME_STOCK_BUTTON_OK );
484     ok_button =
485         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
486
487     gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
488                                 GNOME_STOCK_BUTTON_APPLY );
489     apply_button =
490         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
491
492     gnome_dialog_append_button_with_pixmap(
493         GNOME_DIALOG(config_dialog), _("Save"), GNOME_STOCK_PIXMAP_SAVE );
494     save_button =
495         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
496
497     gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
498                                 GNOME_STOCK_BUTTON_CANCEL );
499     cancel_button =
500         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
501 #else
502     ok_button = gtk_button_new_with_label( _("Ok") );
503     gtk_box_pack_start( GTK_BOX(dialog_action_area), ok_button,
504                         TRUE, TRUE, 0 );
505
506     apply_button = gtk_button_new_with_label( _("Apply") );
507     gtk_box_pack_start( GTK_BOX(dialog_action_area), apply_button,
508                         TRUE, TRUE, 0 );
509
510     save_button = gtk_button_new_with_label( _("Save") );
511     gtk_box_pack_start( GTK_BOX(dialog_action_area), save_button,
512                         TRUE, TRUE, 0 );
513
514     cancel_button = gtk_button_new_with_label( _("Cancel") );
515     gtk_box_pack_start( GTK_BOX(dialog_action_area), cancel_button,
516                         TRUE, TRUE, 0 );
517 #endif
518
519     gtk_signal_connect( GTK_OBJECT(ok_button), "clicked",
520                         GTK_SIGNAL_FUNC(GtkConfigOk),
521                         config_dialog );
522     gtk_signal_connect( GTK_OBJECT(apply_button), "clicked",
523                         GTK_SIGNAL_FUNC(GtkConfigApply),
524                         config_dialog );
525     gtk_signal_connect( GTK_OBJECT(save_button), "clicked",
526                         GTK_SIGNAL_FUNC(GtkConfigSave),
527                         config_dialog );
528     gtk_signal_connect( GTK_OBJECT(cancel_button), "clicked",
529                         GTK_SIGNAL_FUNC(GtkConfigCancel),
530                         config_dialog );
531
532
533
534     /* Ok, job done successfully. Let's keep a reference to the dialog box */
535     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
536                          psz_module_name, config_dialog );
537     gtk_object_set_data( GTK_OBJECT(config_dialog), "psz_module_name",
538                          psz_module_name );
539
540     /* we want this ref to be destroyed if the object is destroyed */
541     gtk_signal_connect( GTK_OBJECT(config_dialog), "destroy",
542                        GTK_SIGNAL_FUNC(GtkConfigDialogDestroyed),
543                        (gpointer)p_intf );
544
545     gtk_widget_show_all( config_dialog );
546 }
547
548 #undef LABEL_AND_WIDGET
549 #undef TOOLTIP
550
551 /****************************************************************************
552  * GtkConfigApply: store the changes to the config inside the modules
553  * configuration structure
554  ****************************************************************************/
555 void GtkConfigApply( GtkButton * button, gpointer user_data )
556 {
557     GHashTable *hash_table;
558     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
559                                                     "config_hash_table" );
560     g_hash_table_foreach( hash_table, GtkSaveHashValue, NULL );
561
562 }
563
564 void GtkConfigOk( GtkButton * button, gpointer user_data )
565 {
566     GtkConfigApply( button, user_data );
567     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
568 }
569
570
571 void GtkConfigCancel( GtkButton * button, gpointer user_data )
572 {
573     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
574 }
575
576 void GtkConfigSave( GtkButton * button, gpointer user_data )
577 {
578     GtkConfigApply( button, user_data );
579     config_SaveConfigFile( NULL );
580 }
581
582 /****************************************************************************
583  * GtkPluginHighlighted: display plugin description when an entry is selected
584  *   in the clist, and activate the configure button if necessary.
585  ****************************************************************************/
586 void GtkPluginHighlighted( GtkCList *plugin_clist, int row, int column,
587                            GdkEventButton *event, gpointer user_data )
588 {
589     GtkWidget *config_button;
590     module_t *p_module;
591     char *psz_name;
592
593     if( gtk_clist_get_text( GTK_CLIST(plugin_clist), row, 0, &psz_name ) )
594     {
595         /* look for plugin 'psz_name' */
596         for( p_module = p_module_bank->first ;
597              p_module != NULL ;
598              p_module = p_module->next )
599         {
600           if( !strcmp( p_module->psz_name, psz_name ) )
601           {
602               gtk_object_set_data( GTK_OBJECT(plugin_clist),
603                                    "plugin_highlighted", p_module );
604               config_button = gtk_object_get_data( GTK_OBJECT(plugin_clist),
605                                                    "config_button" );
606               if( p_module->i_config_items )
607                   gtk_widget_set_sensitive( config_button, TRUE );
608               else
609                   gtk_widget_set_sensitive( config_button, FALSE );
610
611               break;
612           }
613         }
614
615     }
616 }
617
618 /****************************************************************************
619  * GtkPluginConfigure: display plugin configuration dialog box.
620  ****************************************************************************/
621 void GtkPluginConfigure( GtkButton *button, gpointer user_data )
622 {
623     module_t *p_module;
624     intf_thread_t *p_intf;
625
626     p_module = (module_t *)gtk_object_get_data( GTK_OBJECT(user_data),
627                                                 "plugin_highlighted" );
628
629     if( !p_module ) return;
630     p_intf = (intf_thread_t *)gtk_object_get_data( GTK_OBJECT(button),
631                                                    "p_intf" );
632     GtkCreateConfigDialog( p_module->psz_name, (gpointer)p_intf );
633
634 }
635
636 /****************************************************************************
637  * GtkPluginSelected: select plugin.
638  ****************************************************************************/
639 void GtkPluginSelected( GtkButton *button, gpointer user_data )
640 {
641     module_t *p_module;
642     GtkWidget *widget;
643
644     p_module = (module_t *)gtk_object_get_data( GTK_OBJECT(user_data),
645                                                 "plugin_highlighted" );
646     widget = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(user_data),
647                                                "plugin_entry" );
648     if( !p_module ) return;
649
650     gtk_entry_set_text( GTK_ENTRY(widget), p_module->psz_name );
651
652 }
653
654 /****************************************************************************
655  * GtkStringChanged: signal called when the user changes a string value.
656  ****************************************************************************/
657 static void GtkStringChanged( GtkEditable *editable, gpointer user_data )
658 {
659     module_config_t *p_config;
660
661     GHashTable *hash_table;
662
663     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
664                                                     "config_hash_table" );
665     /* free old p_config */
666     p_config = (module_config_t *)g_hash_table_lookup( hash_table,
667                                                        (gpointer)editable );
668     if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
669
670     p_config = malloc( sizeof(module_config_t) );
671     p_config->i_type = MODULE_CONFIG_ITEM_STRING;
672     p_config->psz_value = gtk_editable_get_chars( editable, 0, -1 );
673     p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(editable),
674                                                       "config_option" );
675
676     g_hash_table_insert( hash_table, (gpointer)editable,
677                          (gpointer)p_config );
678 }
679
680 /****************************************************************************
681  * GtkIntChanged: signal called when the user changes a an integer value.
682  ****************************************************************************/
683 static void GtkIntChanged( GtkEditable *editable, gpointer user_data )
684 {
685     module_config_t *p_config;
686
687     GHashTable *hash_table;
688
689     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
690                                                     "config_hash_table" );
691
692     /* free old p_config */
693     p_config = (module_config_t *)g_hash_table_lookup( hash_table,
694                                                        (gpointer)editable );
695     if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
696
697     p_config = malloc( sizeof(module_config_t) );
698     p_config->i_type = MODULE_CONFIG_ITEM_INTEGER;
699     p_config->i_value =  gtk_spin_button_get_value_as_int(
700                              GTK_SPIN_BUTTON(editable) );
701     p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(editable),
702                                                       "config_option" );
703
704     g_hash_table_insert( hash_table, (gpointer)editable,
705                          (gpointer)p_config );
706 }
707
708 /****************************************************************************
709  * GtkStringChanged: signal called when the user changes a bool value.
710  ****************************************************************************/
711 static void GtkBoolChanged( GtkToggleButton *button, gpointer user_data )
712 {
713     module_config_t *p_config;
714
715     GHashTable *hash_table;
716
717     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
718                                                     "config_hash_table" );
719
720     /* free old p_config */
721     p_config = (module_config_t *)g_hash_table_lookup( hash_table,
722                                                        (gpointer)button );
723     if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
724
725     p_config = malloc( sizeof(module_config_t) );
726     p_config->i_type = MODULE_CONFIG_ITEM_BOOL;
727     p_config->i_value = gtk_toggle_button_get_active( button );
728     p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(button),
729                                                       "config_option" );
730
731     g_hash_table_insert( hash_table, (gpointer)button,
732                          (gpointer)p_config );
733 }
734
735 /****************************************************************************
736  * GtkFreeHashTable: signal called when the config hash table is destroyed.
737  ****************************************************************************/
738 static void GtkFreeHashTable( gpointer user_data )
739 {
740     GHashTable *hash_table = (GHashTable *)user_data;
741
742     g_hash_table_foreach( hash_table, GtkFreeHashValue, NULL );
743     g_hash_table_destroy( hash_table );
744 }
745
746 /****************************************************************************
747  * GtkFreeHashValue: signal called when an element of the config hash table
748  * is destroyed.
749  ****************************************************************************/
750 static void GtkFreeHashValue( gpointer key, gpointer value, gpointer user_data)
751 {
752     module_config_t *p_config = (module_config_t *)value;
753
754     if( p_config->i_type == MODULE_CONFIG_ITEM_STRING )
755         g_free( p_config->psz_value );
756     free( p_config );
757 }
758
759 /****************************************************************************
760  * GtkSaveHashValue: callback used when enumerating the hash table in
761  * GtkConfigApply().
762  ****************************************************************************/
763 static void GtkSaveHashValue( gpointer key, gpointer value, gpointer user_data)
764 {
765     module_config_t *p_config = (module_config_t *)value;
766
767     switch( p_config->i_type )
768     {
769
770     case MODULE_CONFIG_ITEM_STRING:
771     case MODULE_CONFIG_ITEM_FILE:
772     case MODULE_CONFIG_ITEM_PLUGIN:
773         config_PutPszVariable( p_config->psz_name,
774             *p_config->psz_value? p_config->psz_value : NULL );
775         break;
776     case MODULE_CONFIG_ITEM_INTEGER:
777     case MODULE_CONFIG_ITEM_BOOL:
778         config_PutIntVariable( p_config->psz_name, p_config->i_value );
779         break;
780     }
781 }
782
783 /****************************************************************************
784  * GtkConfigDialogDestroyed: callback triggered when the config dialog box is
785  * destroyed.
786  ****************************************************************************/
787 static void GtkConfigDialogDestroyed( GtkObject *object, gpointer user_data )
788 {
789     intf_thread_t *p_intf = (intf_thread_t *)user_data;
790     char *psz_module_name;
791
792     psz_module_name = gtk_object_get_data( object, "psz_module_name" );
793
794     /* remove the ref to the dialog box */
795     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
796                          psz_module_name, NULL );
797
798 }