* ./po/*: re-ran make update-po, fixed a few translations.
[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.24 2002/04/21 10:32:20 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     }
463     while( p_item->i_type != MODULE_CONFIG_HINT_END && p_item++ );
464
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 );
469
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,
473                       TRUE, FALSE, 0 );
474     item_hbox = gtk_hbox_new( FALSE, 0 );
475     gtk_box_pack_end( GTK_BOX(dialog_action_area), item_hbox,
476                       TRUE, FALSE, 0 );
477 #endif
478
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 );
483     ok_button =
484         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
485
486     gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
487                                 GNOME_STOCK_BUTTON_APPLY );
488     apply_button =
489         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
490
491     gnome_dialog_append_button_with_pixmap(
492         GNOME_DIALOG(config_dialog), _("Save"), GNOME_STOCK_PIXMAP_SAVE );
493     save_button =
494         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
495
496     gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
497                                 GNOME_STOCK_BUTTON_CANCEL );
498     cancel_button =
499         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
500 #else
501     ok_button = gtk_button_new_with_label( _("OK") );
502     gtk_box_pack_start( GTK_BOX(dialog_action_area), ok_button,
503                         TRUE, TRUE, 0 );
504
505     apply_button = gtk_button_new_with_label( _("Apply") );
506     gtk_box_pack_start( GTK_BOX(dialog_action_area), apply_button,
507                         TRUE, TRUE, 0 );
508
509     save_button = gtk_button_new_with_label( _("Save") );
510     gtk_box_pack_start( GTK_BOX(dialog_action_area), save_button,
511                         TRUE, TRUE, 0 );
512
513     cancel_button = gtk_button_new_with_label( _("Cancel") );
514     gtk_box_pack_start( GTK_BOX(dialog_action_area), cancel_button,
515                         TRUE, TRUE, 0 );
516 #endif
517
518     gtk_signal_connect( GTK_OBJECT(ok_button), "clicked",
519                         GTK_SIGNAL_FUNC(GtkConfigOk),
520                         config_dialog );
521     gtk_signal_connect( GTK_OBJECT(apply_button), "clicked",
522                         GTK_SIGNAL_FUNC(GtkConfigApply),
523                         config_dialog );
524     gtk_signal_connect( GTK_OBJECT(save_button), "clicked",
525                         GTK_SIGNAL_FUNC(GtkConfigSave),
526                         config_dialog );
527     gtk_signal_connect( GTK_OBJECT(cancel_button), "clicked",
528                         GTK_SIGNAL_FUNC(GtkConfigCancel),
529                         config_dialog );
530
531
532
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",
537                          psz_module_name );
538
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),
542                        (gpointer)p_intf );
543
544     gtk_widget_show_all( config_dialog );
545 }
546
547 #undef LABEL_AND_WIDGET
548 #undef TOOLTIP
549
550 /****************************************************************************
551  * GtkConfigApply: store the changes to the config inside the modules
552  * configuration structure
553  ****************************************************************************/
554 void GtkConfigApply( GtkButton * button, gpointer user_data )
555 {
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 );
560
561 }
562
563 void GtkConfigOk( GtkButton * button, gpointer user_data )
564 {
565     GtkConfigApply( button, user_data );
566     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
567 }
568
569
570 void GtkConfigCancel( GtkButton * button, gpointer user_data )
571 {
572     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
573 }
574
575 void GtkConfigSave( GtkButton * button, gpointer user_data )
576 {
577     GtkConfigApply( button, user_data );
578     config_SaveConfigFile( NULL );
579 }
580
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 )
587 {
588     GtkWidget *config_button;
589     module_t *p_module;
590     char *psz_name;
591
592     if( gtk_clist_get_text( GTK_CLIST(plugin_clist), row, 0, &psz_name ) )
593     {
594         /* look for plugin 'psz_name' */
595         for( p_module = p_module_bank->first ;
596              p_module != NULL ;
597              p_module = p_module->next )
598         {
599           if( !strcmp( p_module->psz_name, psz_name ) )
600           {
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),
604                                                    "config_button" );
605               if( p_module->i_config_items )
606                   gtk_widget_set_sensitive( config_button, TRUE );
607               else
608                   gtk_widget_set_sensitive( config_button, FALSE );
609
610               break;
611           }
612         }
613
614     }
615 }
616
617 /****************************************************************************
618  * GtkPluginConfigure: display plugin configuration dialog box.
619  ****************************************************************************/
620 void GtkPluginConfigure( GtkButton *button, gpointer user_data )
621 {
622     module_t *p_module;
623     intf_thread_t *p_intf;
624
625     p_module = (module_t *)gtk_object_get_data( GTK_OBJECT(user_data),
626                                                 "plugin_highlighted" );
627
628     if( !p_module ) return;
629     p_intf = (intf_thread_t *)gtk_object_get_data( GTK_OBJECT(button),
630                                                    "p_intf" );
631     GtkCreateConfigDialog( p_module->psz_name, (gpointer)p_intf );
632
633 }
634
635 /****************************************************************************
636  * GtkPluginSelected: select plugin.
637  ****************************************************************************/
638 void GtkPluginSelected( GtkButton *button, gpointer user_data )
639 {
640     module_t *p_module;
641     GtkWidget *widget;
642
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),
646                                                "plugin_entry" );
647     if( !p_module ) return;
648
649     gtk_entry_set_text( GTK_ENTRY(widget), p_module->psz_name );
650
651 }
652
653 /****************************************************************************
654  * GtkStringChanged: signal called when the user changes a string value.
655  ****************************************************************************/
656 static void GtkStringChanged( GtkEditable *editable, gpointer user_data )
657 {
658     module_config_t *p_config;
659
660     GHashTable *hash_table;
661
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 );
668
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),
673                                                       "config_option" );
674
675     g_hash_table_insert( hash_table, (gpointer)editable,
676                          (gpointer)p_config );
677 }
678
679 /****************************************************************************
680  * GtkIntChanged: signal called when the user changes a an integer value.
681  ****************************************************************************/
682 static void GtkIntChanged( GtkEditable *editable, gpointer user_data )
683 {
684     module_config_t *p_config;
685
686     GHashTable *hash_table;
687
688     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
689                                                     "config_hash_table" );
690
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 );
695
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),
701                                                       "config_option" );
702
703     g_hash_table_insert( hash_table, (gpointer)editable,
704                          (gpointer)p_config );
705 }
706
707 /****************************************************************************
708  * GtkStringChanged: signal called when the user changes a bool value.
709  ****************************************************************************/
710 static void GtkBoolChanged( GtkToggleButton *button, gpointer user_data )
711 {
712     module_config_t *p_config;
713
714     GHashTable *hash_table;
715
716     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
717                                                     "config_hash_table" );
718
719     /* free old p_config */
720     p_config = (module_config_t *)g_hash_table_lookup( hash_table,
721                                                        (gpointer)button );
722     if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
723
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),
728                                                       "config_option" );
729
730     g_hash_table_insert( hash_table, (gpointer)button,
731                          (gpointer)p_config );
732 }
733
734 /****************************************************************************
735  * GtkFreeHashTable: signal called when the config hash table is destroyed.
736  ****************************************************************************/
737 static void GtkFreeHashTable( gpointer user_data )
738 {
739     GHashTable *hash_table = (GHashTable *)user_data;
740
741     g_hash_table_foreach( hash_table, GtkFreeHashValue, NULL );
742     g_hash_table_destroy( hash_table );
743 }
744
745 /****************************************************************************
746  * GtkFreeHashValue: signal called when an element of the config hash table
747  * is destroyed.
748  ****************************************************************************/
749 static void GtkFreeHashValue( gpointer key, gpointer value, gpointer user_data)
750 {
751     module_config_t *p_config = (module_config_t *)value;
752
753     if( p_config->i_type == MODULE_CONFIG_ITEM_STRING )
754         g_free( p_config->psz_value );
755     free( p_config );
756 }
757
758 /****************************************************************************
759  * GtkSaveHashValue: callback used when enumerating the hash table in
760  * GtkConfigApply().
761  ****************************************************************************/
762 static void GtkSaveHashValue( gpointer key, gpointer value, gpointer user_data)
763 {
764     module_config_t *p_config = (module_config_t *)value;
765
766     switch( p_config->i_type )
767     {
768
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 );
774         break;
775     case MODULE_CONFIG_ITEM_INTEGER:
776     case MODULE_CONFIG_ITEM_BOOL:
777         config_PutIntVariable( p_config->psz_name, p_config->i_value );
778         break;
779     }
780 }
781
782 /****************************************************************************
783  * GtkConfigDialogDestroyed: callback triggered when the config dialog box is
784  * destroyed.
785  ****************************************************************************/
786 static void GtkConfigDialogDestroyed( GtkObject *object, gpointer user_data )
787 {
788     intf_thread_t *p_intf = (intf_thread_t *)user_data;
789     char *psz_module_name;
790
791     psz_module_name = gtk_object_get_data( object, "psz_module_name" );
792
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 );
796
797 }