]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_preferences.c
* modified the directx video plugin to try to create an YUV surface before
[vlc] / 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.28 2002/05/18 13:30:28 gbazin 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 GtkFloatChanged      ( GtkEditable *, gpointer );
66 static void GtkBoolChanged       ( GtkToggleButton *, gpointer );
67
68 static void GtkFreeHashTable     ( gpointer );
69 static void GtkFreeHashValue     ( gpointer, gpointer, gpointer );
70 static gboolean GtkSaveHashValue ( gpointer, gpointer, gpointer );
71
72 static void GtkModuleConfigure   ( GtkButton *, gpointer );
73 static void GtkModuleSelected    ( GtkButton *, gpointer );
74 static void GtkModuleHighlighted ( GtkCList *, int, int, GdkEventButton *,
75                                    gpointer );
76
77 /****************************************************************************
78  * Callback for menuitems: display configuration interface window
79  ****************************************************************************/
80 void GtkPreferencesActivate( GtkMenuItem * menuitem, gpointer user_data )
81 {
82     intf_thread_t * p_intf;
83
84     p_intf = GetIntf( GTK_WIDGET(menuitem), (char*)user_data );
85
86     GtkCreateConfigDialog( "main", p_intf );
87 }
88
89 /****************************************************************************
90  * GtkCreateConfigDialog: dynamically creates the configuration dialog
91  * box from all the configuration data provided by the selected module.
92  ****************************************************************************/
93
94 /* create a new tooltipped area */
95 #define TOOLTIP( text )                                                   \
96     /* create an event box to catch some events */                        \
97     item_event_box = gtk_event_box_new();                                 \
98     /* add a tooltip on mouseover */                                      \
99     gtk_tooltips_set_tip( p_intf->p_sys->p_tooltips,                      \
100                           item_event_box, text, "" );                     \
101     gtk_container_set_border_width( GTK_CONTAINER(item_event_box), 4 );
102
103 /* draws a right aligned label in side of a widget */
104 #define LABEL_AND_WIDGET( label_text, widget, tooltip )                   \
105     gtk_table_resize( GTK_TABLE(category_table), ++rows, 2 );             \
106     item_align = gtk_alignment_new( 1, .5, 0, 0 );                        \
107     item_label = gtk_label_new( label_text );                             \
108     gtk_container_add( GTK_CONTAINER(item_align), item_label );           \
109     gtk_table_attach_defaults( GTK_TABLE(category_table), item_align,     \
110                                0, 1, rows - 1, rows );                    \
111     item_align = gtk_alignment_new( 0, .5, .5, 0 );                       \
112     gtk_container_add( GTK_CONTAINER(item_align), widget );               \
113     TOOLTIP(tooltip)                                                      \
114     gtk_container_add( GTK_CONTAINER(item_event_box), item_align );       \
115     gtk_table_attach_defaults( GTK_TABLE(category_table), item_event_box, \
116                                1, 2, rows - 1, rows );
117
118 static void GtkCreateConfigDialog( char *psz_module_name,
119                                    intf_thread_t *p_intf )
120 {
121     module_t *p_module, *p_module_bis;
122     module_config_t *p_item;
123
124     guint rows = 0;
125
126     GHashTable *config_hash_table;
127
128     GtkWidget *item_event_box;
129
130     GtkWidget *config_dialog;
131     GtkWidget *config_dialog_vbox;
132     GtkWidget *config_notebook;
133
134     GtkWidget *category_table = NULL;
135     GtkWidget *category_label = NULL;
136
137 #ifndef MODULE_NAME_IS_gnome
138     GtkWidget *dialog_action_area;
139 #endif
140
141     GtkWidget *ok_button;
142     GtkWidget *apply_button;
143     GtkWidget *save_button;
144     GtkWidget *cancel_button;
145
146     GtkWidget *item_align;
147     GtkWidget *item_frame;
148     GtkWidget *item_hbox;
149     GtkWidget *item_label;
150     GtkWidget *item_vbox;
151     GtkWidget *string_entry;
152     GtkWidget *integer_spinbutton;
153     GtkWidget *float_spinbutton;
154     GtkObject *item_adj;
155     GtkWidget *bool_checkbutton;
156     GtkWidget *module_clist;
157     GtkWidget *module_config_button;
158     GtkWidget *module_select_button;
159
160     gint category_max_height;
161
162     /* Check if the dialog box is already opened, if so this will save us
163      * quite a bit of work. (the interface will be destroyed when you actually
164      * close the dialog window, but remember that it is only hidden if you
165      * clicked on the action buttons). This trick also allows us not to
166      * duplicate identical dialog windows. */
167
168     config_dialog = (GtkWidget *)gtk_object_get_data(
169                     GTK_OBJECT(p_intf->p_sys->p_window), psz_module_name );
170     if( config_dialog )
171     {
172         /* Yeah it was open */
173         gtk_widget_show( config_dialog );
174         gtk_widget_grab_focus( config_dialog );
175         return;
176     }
177
178
179     /* Look for the selected module */
180     for( p_module = p_module_bank->first ; p_module != NULL ;
181          p_module = p_module->next )
182     {
183
184         if( psz_module_name && !strcmp( psz_module_name, p_module->psz_name ) )
185             break;
186     }
187     if( !p_module ) return;
188
189     /* We found it, now we can start building its configuration interface */
190     /* Create the configuration dialog box */
191
192 #ifdef MODULE_NAME_IS_gnome
193     config_dialog = gnome_dialog_new( p_module->psz_longname, NULL );
194     config_dialog_vbox = GNOME_DIALOG(config_dialog)->vbox;
195 #else
196     config_dialog = gtk_dialog_new();
197     gtk_window_set_title( GTK_WINDOW(config_dialog), p_module->psz_longname );
198     config_dialog_vbox = GTK_DIALOG(config_dialog)->vbox;
199 #endif
200
201     category_max_height = config_GetIntVariable( MODULE_STRING "-prefs-maxh" );
202
203     gtk_window_set_policy( GTK_WINDOW(config_dialog), TRUE, TRUE, FALSE );
204     gtk_container_set_border_width( GTK_CONTAINER(config_dialog_vbox), 0 );
205
206     /* Create our config hash table and associate it with the dialog box */
207     config_hash_table = g_hash_table_new( NULL, NULL );
208     gtk_object_set_data_full( GTK_OBJECT(config_dialog),
209                               "config_hash_table", config_hash_table,
210                               (GtkDestroyNotify)GtkFreeHashTable );
211
212     /* Create notebook */
213     config_notebook = gtk_notebook_new();
214     gtk_notebook_set_scrollable( GTK_NOTEBOOK(config_notebook), TRUE );
215     gtk_container_add( GTK_CONTAINER(config_dialog_vbox), config_notebook );
216
217     /* Enumerate config options and add corresponding config boxes */
218     p_item = p_module->p_config;
219     do
220     {
221         switch( p_item->i_type )
222         {
223
224         case MODULE_CONFIG_HINT_CATEGORY:
225         case MODULE_CONFIG_HINT_END:
226
227             /*
228              * Before we start building the interface for the new category, we
229              * must close/finish the previous one we were generating.
230              */
231             if( category_table )
232             {
233                 GtkWidget *_scrolled_window;
234                 GtkWidget *_viewport;
235                 GtkWidget *_vbox;
236                 GtkRequisition _requisition;
237
238                 /* create a vbox to deal with EXPAND/FILL issues in the
239                  * notebook page, and pack it with the previously generated
240                  * category_table */
241                 _vbox = gtk_vbox_new( FALSE, 0 );
242                 gtk_container_set_border_width( GTK_CONTAINER(_vbox), 4 );
243                 gtk_box_pack_start( GTK_BOX(_vbox), category_table,
244                                     FALSE, FALSE, 0 );
245
246                 /* create a new scrolled window that will contain all of the
247                  * above. */
248                 _scrolled_window = gtk_scrolled_window_new( NULL, NULL );
249                 gtk_scrolled_window_set_policy(
250                     GTK_SCROLLED_WINDOW(_scrolled_window), GTK_POLICY_NEVER,
251                     GTK_POLICY_AUTOMATIC );
252                 /* add scrolled window as a notebook page */
253                 gtk_notebook_append_page( GTK_NOTEBOOK(config_notebook),
254                                           _scrolled_window, category_label );
255                 /* pack the vbox into the scrolled window */
256                 _viewport = gtk_viewport_new( NULL, NULL );
257                 gtk_viewport_set_shadow_type( GTK_VIEWPORT(_viewport),
258                                               GTK_SHADOW_NONE );
259                 gtk_container_add( GTK_CONTAINER(_viewport), _vbox );
260                 gtk_container_add( GTK_CONTAINER(_scrolled_window),
261                                    _viewport );
262
263                 /* set the size of the scrolled window to the size of the
264                  * child widget */
265                 gtk_widget_show_all( _vbox );
266                 gtk_widget_size_request( _vbox, &_requisition );
267                 if( _requisition.height > category_max_height )
268                     gtk_widget_set_usize( _scrolled_window, -1,
269                                           category_max_height );
270                 else
271                     gtk_widget_set_usize( _scrolled_window, -1,
272                                           _requisition.height );
273
274             }
275
276             /*
277              * Now we can start taking care of the new category
278              */
279
280             if( p_item->i_type == MODULE_CONFIG_HINT_CATEGORY )
281             {
282                 /* create a new table for right-left alignment of children */
283                 category_table = gtk_table_new( 0, 0, FALSE );
284                 gtk_table_set_col_spacings( GTK_TABLE(category_table), 4 );
285                 rows = 0;
286
287                 /* create a new category label */
288                 category_label = gtk_label_new( p_item->psz_text );
289             }
290
291             break;
292
293         case MODULE_CONFIG_ITEM_MODULE:
294
295             item_frame = gtk_frame_new( p_item->psz_text );
296
297             gtk_table_resize( GTK_TABLE(category_table), ++rows, 2 );
298             gtk_table_attach_defaults( GTK_TABLE(category_table), item_frame,
299                                        0, 2, rows - 1, rows );
300
301             item_vbox = gtk_vbox_new( FALSE, 4 );
302             gtk_container_add( GTK_CONTAINER(item_frame), item_vbox );
303
304             /* create a new clist widget */
305             {
306                 gchar * titles[] = { _("Name"), _("Description") };
307
308                 module_clist =
309                     gtk_clist_new_with_titles( 2, titles );
310             }
311             gtk_clist_column_titles_passive( GTK_CLIST(module_clist) );
312             gtk_clist_set_selection_mode( GTK_CLIST(module_clist),
313                                           GTK_SELECTION_SINGLE);
314             gtk_container_add( GTK_CONTAINER(item_vbox), module_clist );
315
316             /* build a list of available modules */
317             {
318                 gchar * entry[2];
319
320                 for( p_module_bis = p_module_bank->first ;
321                      p_module_bis != NULL ;
322                      p_module_bis = p_module_bis->next )
323                 {
324                     if( p_module_bis->i_capabilities & (1 << p_item->i_value) )
325                     {
326                         entry[0] = p_module_bis->psz_name;
327                         entry[1] = p_module_bis->psz_longname;
328                         gtk_clist_append( GTK_CLIST(module_clist), entry );
329                     }
330                 }
331             }
332
333             gtk_clist_set_column_auto_resize( GTK_CLIST(module_clist),
334                                               0, TRUE );
335             gtk_clist_set_column_auto_resize( GTK_CLIST(module_clist),
336                                               1, TRUE );
337
338             /* connect signals to the modules list */
339             gtk_signal_connect( GTK_OBJECT(module_clist), "select_row",
340                                 GTK_SIGNAL_FUNC(GtkModuleHighlighted),
341                                 NULL );
342
343             /* hbox holding the "select" and "configure" buttons */
344             item_hbox = gtk_hbox_new( FALSE, 4 );
345             gtk_container_add( GTK_CONTAINER(item_vbox), item_hbox);
346
347             /* add configure button */
348             module_config_button =
349                 gtk_button_new_with_label( _("Configure") );
350             gtk_widget_set_sensitive( module_config_button, FALSE );
351             gtk_container_add( GTK_CONTAINER(item_hbox),
352                                module_config_button );
353             gtk_object_set_data( GTK_OBJECT(module_config_button),
354                                  "p_intf", p_intf );
355             gtk_object_set_data( GTK_OBJECT(module_clist),
356                                  "config_button", module_config_button );
357
358             /* add select button */
359             module_select_button =
360                 gtk_button_new_with_label( _("Select") );
361             gtk_container_add( GTK_CONTAINER(item_hbox),
362                                module_select_button );
363             /* add a tooltip on mouseover */
364             gtk_tooltips_set_tip( p_intf->p_sys->p_tooltips,
365                                   module_select_button,
366                                   p_item->psz_longtext, "" );
367
368             /* hbox holding the "selected" label and text input */
369             item_hbox = gtk_hbox_new( FALSE, 4 );
370             gtk_container_add( GTK_CONTAINER(item_vbox), item_hbox);
371             /* add new label */
372             item_label = gtk_label_new( _("Selected:") );
373             gtk_container_add( GTK_CONTAINER(item_hbox), item_label );
374
375             /* add input box with default value */
376             string_entry = gtk_entry_new();
377             gtk_object_set_data( GTK_OBJECT(module_clist),
378                                  "module_entry", string_entry );
379             gtk_container_add( GTK_CONTAINER(item_hbox), string_entry );
380             vlc_mutex_lock( p_item->p_lock );
381             gtk_entry_set_text( GTK_ENTRY(string_entry),
382                                 p_item->psz_value ? p_item->psz_value : "" );
383             vlc_mutex_unlock( p_item->p_lock );
384             /* add a tooltip on mouseover */
385             gtk_tooltips_set_tip( p_intf->p_sys->p_tooltips,
386                                   string_entry, p_item->psz_longtext, "" );
387
388             /* connect signals to the buttons */
389             gtk_signal_connect( GTK_OBJECT(module_config_button), "clicked",
390                                 GTK_SIGNAL_FUNC(GtkModuleConfigure),
391                                 (gpointer)module_clist );
392             gtk_signal_connect( GTK_OBJECT(module_select_button), "clicked",
393                                 GTK_SIGNAL_FUNC(GtkModuleSelected),
394                                 (gpointer)module_clist );
395
396             /* connect signal to track changes in the text box */
397             gtk_object_set_data( GTK_OBJECT(string_entry), "config_option",
398                                  p_item->psz_name );
399             gtk_signal_connect( GTK_OBJECT(string_entry), "changed",
400                                 GTK_SIGNAL_FUNC(GtkStringChanged),
401                                 (gpointer)config_dialog );
402             break;
403
404         case MODULE_CONFIG_ITEM_STRING:
405         case MODULE_CONFIG_ITEM_FILE:
406
407             /* add input box with default value */
408             string_entry = gtk_entry_new();
409             vlc_mutex_lock( p_item->p_lock );
410             gtk_entry_set_text( GTK_ENTRY(string_entry),
411                                 p_item->psz_value ? p_item->psz_value : "" );
412             vlc_mutex_unlock( p_item->p_lock );
413
414             /* connect signal to track changes in the text box */
415             gtk_object_set_data( GTK_OBJECT(string_entry), "config_option",
416                                  p_item->psz_name );
417             gtk_signal_connect( GTK_OBJECT(string_entry), "changed",
418                                 GTK_SIGNAL_FUNC(GtkStringChanged),
419                                 (gpointer)config_dialog );
420
421             LABEL_AND_WIDGET( p_item->psz_text,
422                               string_entry, p_item->psz_longtext );
423             break;
424
425         case MODULE_CONFIG_ITEM_INTEGER:
426
427             /* add input box with default value */
428             item_adj = gtk_adjustment_new( p_item->i_value,
429                                            -1, 99999, 1, 10, 10 );
430             integer_spinbutton = gtk_spin_button_new( GTK_ADJUSTMENT(item_adj),
431                                                       1, 0 );
432
433             /* connect signal to track changes in the spinbutton value */
434             gtk_object_set_data( GTK_OBJECT(integer_spinbutton),
435                                  "config_option", p_item->psz_name );
436             gtk_signal_connect( GTK_OBJECT(integer_spinbutton), "changed",
437                                 GTK_SIGNAL_FUNC(GtkIntChanged),
438                                 (gpointer)config_dialog );
439
440             LABEL_AND_WIDGET( p_item->psz_text,
441                               integer_spinbutton, p_item->psz_longtext );
442             break;
443
444         case MODULE_CONFIG_ITEM_FLOAT:
445
446             /* add input box with default value */
447             item_adj = gtk_adjustment_new( p_item->f_value,
448                                            0, 99999, 0.01, 10, 10 );
449             float_spinbutton = gtk_spin_button_new( GTK_ADJUSTMENT(item_adj),
450                                                     0.01, 2 );
451
452             /* connect signal to track changes in the spinbutton value */
453             gtk_object_set_data( GTK_OBJECT(float_spinbutton),
454                                  "config_option", p_item->psz_name );
455             gtk_signal_connect( GTK_OBJECT(float_spinbutton), "changed",
456                                 GTK_SIGNAL_FUNC(GtkFloatChanged),
457                                 (gpointer)config_dialog );
458
459             LABEL_AND_WIDGET( p_item->psz_text,
460                               float_spinbutton, p_item->psz_longtext );
461             break;
462
463         case MODULE_CONFIG_ITEM_BOOL:
464
465             /* add check button */
466             bool_checkbutton = gtk_check_button_new();
467             gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(bool_checkbutton),
468                                           p_item->i_value );
469
470             /* connect signal to track changes in the button state */
471             gtk_object_set_data( GTK_OBJECT(bool_checkbutton), "config_option",
472                                  p_item->psz_name );
473             gtk_signal_connect( GTK_OBJECT(bool_checkbutton), "toggled",
474                                 GTK_SIGNAL_FUNC(GtkBoolChanged),
475                                 (gpointer)config_dialog );
476
477             LABEL_AND_WIDGET( p_item->psz_text,
478                               bool_checkbutton, p_item->psz_longtext );
479             break;
480
481         }
482
483     }
484     while( p_item->i_type != MODULE_CONFIG_HINT_END && p_item++ );
485
486 #ifndef MODULE_NAME_IS_gnome
487     /* Now let's add the action buttons at the bottom of the page */
488     dialog_action_area = GTK_DIALOG(config_dialog)->action_area;
489     gtk_container_set_border_width( GTK_CONTAINER(dialog_action_area), 4 );
490
491     /* add a new table for the config option */
492     item_hbox = gtk_hbox_new( FALSE, 0 );
493     gtk_box_pack_end( GTK_BOX(dialog_action_area), item_hbox,
494                       TRUE, FALSE, 0 );
495     item_hbox = gtk_hbox_new( FALSE, 0 );
496     gtk_box_pack_end( GTK_BOX(dialog_action_area), item_hbox,
497                       TRUE, FALSE, 0 );
498 #endif
499
500     /* Create the OK button */
501 #ifdef MODULE_NAME_IS_gnome
502     gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
503                                 GNOME_STOCK_BUTTON_OK );
504     ok_button =
505         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
506
507     gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
508                                 GNOME_STOCK_BUTTON_APPLY );
509     apply_button =
510         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
511
512     gnome_dialog_append_button_with_pixmap(
513         GNOME_DIALOG(config_dialog), _("Save"), GNOME_STOCK_PIXMAP_SAVE );
514     save_button =
515         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
516
517     gnome_dialog_append_button( GNOME_DIALOG(config_dialog),
518                                 GNOME_STOCK_BUTTON_CANCEL );
519     cancel_button =
520         GTK_WIDGET(g_list_last(GNOME_DIALOG(config_dialog)->buttons)->data);
521 #else
522     ok_button = gtk_button_new_with_label( _("OK") );
523     gtk_box_pack_start( GTK_BOX(dialog_action_area), ok_button,
524                         TRUE, TRUE, 0 );
525
526     apply_button = gtk_button_new_with_label( _("Apply") );
527     gtk_box_pack_start( GTK_BOX(dialog_action_area), apply_button,
528                         TRUE, TRUE, 0 );
529
530     save_button = gtk_button_new_with_label( _("Save") );
531     gtk_box_pack_start( GTK_BOX(dialog_action_area), save_button,
532                         TRUE, TRUE, 0 );
533
534     cancel_button = gtk_button_new_with_label( _("Cancel") );
535     gtk_box_pack_start( GTK_BOX(dialog_action_area), cancel_button,
536                         TRUE, TRUE, 0 );
537 #endif
538
539     gtk_signal_connect( GTK_OBJECT(ok_button), "clicked",
540                         GTK_SIGNAL_FUNC(GtkConfigOk),
541                         config_dialog );
542     gtk_widget_set_sensitive( apply_button, FALSE );
543     gtk_object_set_data( GTK_OBJECT(config_dialog), "apply_button",
544                          apply_button );
545     gtk_signal_connect( GTK_OBJECT(apply_button), "clicked",
546                         GTK_SIGNAL_FUNC(GtkConfigApply),
547                         config_dialog );
548     gtk_signal_connect( GTK_OBJECT(save_button), "clicked",
549                         GTK_SIGNAL_FUNC(GtkConfigSave),
550                         config_dialog );
551     gtk_signal_connect( GTK_OBJECT(cancel_button), "clicked",
552                         GTK_SIGNAL_FUNC(GtkConfigCancel),
553                         config_dialog );
554
555
556
557     /* Ok, job done successfully. Let's keep a reference to the dialog box */
558     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
559                          psz_module_name, config_dialog );
560     gtk_object_set_data( GTK_OBJECT(config_dialog), "psz_module_name",
561                          psz_module_name );
562
563     /* we want this ref to be destroyed if the object is destroyed */
564     gtk_signal_connect( GTK_OBJECT(config_dialog), "destroy",
565                        GTK_SIGNAL_FUNC(GtkConfigDialogDestroyed),
566                        (gpointer)p_intf );
567
568     gtk_widget_show_all( config_dialog );
569 }
570
571 #undef LABEL_AND_WIDGET
572 #undef TOOLTIP
573
574 /****************************************************************************
575  * GtkConfigApply: store the changes to the config inside the modules
576  * configuration structure and clear the hash table.
577  ****************************************************************************/
578 void GtkConfigApply( GtkButton * button, gpointer user_data )
579 {
580     GHashTable *hash_table;
581     GtkWidget *apply_button;
582
583     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
584                                                     "config_hash_table" );
585     g_hash_table_foreach_remove( hash_table, GtkSaveHashValue, NULL );
586
587     /* change the highlight status of the Apply button */
588     apply_button = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(user_data),
589                                                     "apply_button" );
590     gtk_widget_set_sensitive( apply_button, FALSE );
591
592 }
593
594 void GtkConfigOk( GtkButton * button, gpointer user_data )
595 {
596     GtkConfigApply( button, user_data );
597     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
598 }
599
600
601 void GtkConfigCancel( GtkButton * button, gpointer user_data )
602 {
603     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
604 }
605
606 void GtkConfigSave( GtkButton * button, gpointer user_data )
607 {
608     GtkConfigApply( button, user_data );
609     config_SaveConfigFile( NULL );
610 }
611
612 /****************************************************************************
613  * GtkModuleHighlighted: display module description when an entry is selected
614  *   in the clist, and activate the configure button if necessary.
615  ****************************************************************************/
616 void GtkModuleHighlighted( GtkCList *module_clist, int row, int column,
617                            GdkEventButton *event, gpointer user_data )
618 {
619     GtkWidget *config_button;
620     module_t *p_module;
621     char *psz_name;
622
623     if( gtk_clist_get_text( GTK_CLIST(module_clist), row, 0, &psz_name ) )
624     {
625         /* look for module 'psz_name' */
626         for( p_module = p_module_bank->first ;
627              p_module != NULL ;
628              p_module = p_module->next )
629         {
630           if( !strcmp( p_module->psz_name, psz_name ) )
631           {
632               gtk_object_set_data( GTK_OBJECT(module_clist),
633                                    "module_highlighted", p_module );
634               config_button = gtk_object_get_data( GTK_OBJECT(module_clist),
635                                                    "config_button" );
636               if( p_module->i_config_items )
637                   gtk_widget_set_sensitive( config_button, TRUE );
638               else
639                   gtk_widget_set_sensitive( config_button, FALSE );
640
641               break;
642           }
643         }
644
645     }
646 }
647
648 /****************************************************************************
649  * GtkModuleConfigure: display module configuration dialog box.
650  ****************************************************************************/
651 void GtkModuleConfigure( GtkButton *button, gpointer user_data )
652 {
653     module_t *p_module;
654     intf_thread_t *p_intf;
655
656     p_module = (module_t *)gtk_object_get_data( GTK_OBJECT(user_data),
657                                                 "module_highlighted" );
658
659     if( !p_module ) return;
660     p_intf = (intf_thread_t *)gtk_object_get_data( GTK_OBJECT(button),
661                                                    "p_intf" );
662     GtkCreateConfigDialog( p_module->psz_name, (gpointer)p_intf );
663
664 }
665
666 /****************************************************************************
667  * GtkModuleSelected: select module.
668  ****************************************************************************/
669 void GtkModuleSelected( GtkButton *button, gpointer user_data )
670 {
671     module_t *p_module;
672     GtkWidget *widget;
673
674     p_module = (module_t *)gtk_object_get_data( GTK_OBJECT(user_data),
675                                                 "module_highlighted" );
676     widget = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(user_data),
677                                                "module_entry" );
678     if( !p_module ) return;
679
680     gtk_entry_set_text( GTK_ENTRY(widget), p_module->psz_name );
681
682 }
683
684 /****************************************************************************
685  * GtkStringChanged: signal called when the user changes a string value.
686  ****************************************************************************/
687 static void GtkStringChanged( GtkEditable *editable, gpointer user_data )
688 {
689     module_config_t *p_config;
690
691     GHashTable *hash_table;
692     GtkWidget *apply_button;
693
694     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
695                                                     "config_hash_table" );
696     /* free old p_config */
697     p_config = (module_config_t *)g_hash_table_lookup( hash_table,
698                                                        (gpointer)editable );
699     if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
700
701     p_config = malloc( sizeof(module_config_t) );
702     p_config->i_type = MODULE_CONFIG_ITEM_STRING;
703     p_config->psz_value = gtk_editable_get_chars( editable, 0, -1 );
704     p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(editable),
705                                                       "config_option" );
706
707     g_hash_table_insert( hash_table, (gpointer)editable,
708                          (gpointer)p_config );
709
710     /* change the highlight status of the Apply button */
711     apply_button = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(user_data),
712                                                     "apply_button" );
713     gtk_widget_set_sensitive( apply_button, TRUE );
714 }
715
716 /****************************************************************************
717  * GtkIntChanged: signal called when the user changes an integer value.
718  ****************************************************************************/
719 static void GtkIntChanged( GtkEditable *editable, gpointer user_data )
720 {
721     module_config_t *p_config;
722
723     GHashTable *hash_table;
724     GtkWidget *apply_button;
725
726     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
727                                                     "config_hash_table" );
728
729     /* free old p_config */
730     p_config = (module_config_t *)g_hash_table_lookup( hash_table,
731                                                        (gpointer)editable );
732     if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
733
734     p_config = malloc( sizeof(module_config_t) );
735     p_config->i_type = MODULE_CONFIG_ITEM_INTEGER;
736     gtk_spin_button_update( GTK_SPIN_BUTTON(editable) );
737     p_config->i_value = gtk_spin_button_get_value_as_int(
738                             GTK_SPIN_BUTTON(editable) );
739     p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(editable),
740                                                       "config_option" );
741
742     g_hash_table_insert( hash_table, (gpointer)editable,
743                          (gpointer)p_config );
744
745     /* change the highlight status of the Apply button */
746     apply_button = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(user_data),
747                                                     "apply_button" );
748     gtk_widget_set_sensitive( apply_button, TRUE );
749 }
750
751 /****************************************************************************
752  * GtkFloatChanged: signal called when the user changes a float value.
753  ****************************************************************************/
754 static void GtkFloatChanged( GtkEditable *editable, gpointer user_data )
755 {
756     module_config_t *p_config;
757
758     GHashTable *hash_table;
759     GtkWidget *apply_button;
760
761     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
762                                                     "config_hash_table" );
763
764     /* free old p_config */
765     p_config = (module_config_t *)g_hash_table_lookup( hash_table,
766                                                        (gpointer)editable );
767     if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
768
769     p_config = malloc( sizeof(module_config_t) );
770     p_config->i_type = MODULE_CONFIG_ITEM_FLOAT;
771     gtk_spin_button_update( GTK_SPIN_BUTTON(editable) );
772     p_config->f_value = gtk_spin_button_get_value_as_float(
773                            GTK_SPIN_BUTTON(editable) );
774     p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(editable),
775                                                       "config_option" );
776
777     g_hash_table_insert( hash_table, (gpointer)editable,
778                          (gpointer)p_config );
779
780     /* change the highlight status of the Apply button */
781     apply_button = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(user_data),
782                                                     "apply_button" );
783     gtk_widget_set_sensitive( apply_button, TRUE );
784 }
785
786 /****************************************************************************
787  * GtkStringChanged: signal called when the user changes a bool value.
788  ****************************************************************************/
789 static void GtkBoolChanged( GtkToggleButton *button, gpointer user_data )
790 {
791     module_config_t *p_config;
792
793     GHashTable *hash_table;
794     GtkWidget *apply_button;
795
796     hash_table = (GHashTable *)gtk_object_get_data( GTK_OBJECT(user_data),
797                                                     "config_hash_table" );
798
799     /* free old p_config */
800     p_config = (module_config_t *)g_hash_table_lookup( hash_table,
801                                                        (gpointer)button );
802     if( p_config ) GtkFreeHashValue( NULL, (gpointer)p_config, NULL );
803
804     p_config = malloc( sizeof(module_config_t) );
805     p_config->i_type = MODULE_CONFIG_ITEM_BOOL;
806     p_config->i_value = gtk_toggle_button_get_active( button );
807     p_config->psz_name = (char *)gtk_object_get_data( GTK_OBJECT(button),
808                                                       "config_option" );
809
810     g_hash_table_insert( hash_table, (gpointer)button,
811                          (gpointer)p_config );
812
813     /* change the highlight status of the Apply button */
814     apply_button = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(user_data),
815                                                     "apply_button" );
816     gtk_widget_set_sensitive( apply_button, TRUE );
817 }
818
819 /****************************************************************************
820  * GtkFreeHashTable: signal called when the config hash table is destroyed.
821  ****************************************************************************/
822 static void GtkFreeHashTable( gpointer user_data )
823 {
824     GHashTable *hash_table = (GHashTable *)user_data;
825
826     g_hash_table_foreach( hash_table, GtkFreeHashValue, NULL );
827     g_hash_table_destroy( hash_table );
828 }
829
830 /****************************************************************************
831  * GtkFreeHashValue: signal called when an element of the config hash table
832  * is destroyed.
833  ****************************************************************************/
834 static void GtkFreeHashValue( gpointer key, gpointer value, gpointer user_data)
835 {
836     module_config_t *p_config = (module_config_t *)value;
837
838     if( p_config->i_type == MODULE_CONFIG_ITEM_STRING )
839         g_free( p_config->psz_value );
840     free( p_config );
841 }
842
843 /****************************************************************************
844  * GtkSaveHashValue: callback used when enumerating the hash table in
845  * GtkConfigApply().
846  ****************************************************************************/
847 static gboolean GtkSaveHashValue( gpointer key, gpointer value,
848                                   gpointer user_data )
849 {
850     module_config_t *p_config = (module_config_t *)value;
851
852     switch( p_config->i_type )
853     {
854
855     case MODULE_CONFIG_ITEM_STRING:
856     case MODULE_CONFIG_ITEM_FILE:
857     case MODULE_CONFIG_ITEM_MODULE:
858         config_PutPszVariable( p_config->psz_name,
859             *p_config->psz_value? p_config->psz_value : NULL );
860         break;
861     case MODULE_CONFIG_ITEM_INTEGER:
862     case MODULE_CONFIG_ITEM_BOOL:
863         config_PutIntVariable( p_config->psz_name, p_config->i_value );
864         break;
865     case MODULE_CONFIG_ITEM_FLOAT:
866         config_PutFloatVariable( p_config->psz_name, p_config->f_value );
867         break;
868     }
869
870     /* free the hash value we allocated */
871     if( p_config->i_type == MODULE_CONFIG_ITEM_STRING )
872         g_free( p_config->psz_value );
873     free( p_config );
874
875     /* return TRUE so glib will free the hash entry */
876     return TRUE;
877 }
878
879 /****************************************************************************
880  * GtkConfigDialogDestroyed: callback triggered when the config dialog box is
881  * destroyed.
882  ****************************************************************************/
883 static void GtkConfigDialogDestroyed( GtkObject *object, gpointer user_data )
884 {
885     intf_thread_t *p_intf = (intf_thread_t *)user_data;
886     char *psz_module_name;
887
888     psz_module_name = gtk_object_get_data( object, "psz_module_name" );
889
890     /* remove the ref to the dialog box */
891     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
892                          psz_module_name, NULL );
893
894 }