]> git.sesse.net Git - vlc/blob - plugins/gtk/intf_gtk.c
-Working menus for run-time audio/spu/title/chapter selection with gtk
[vlc] / plugins / gtk / intf_gtk.c
1 /*****************************************************************************
2  * intf_gtk.c: Gtk+ interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: intf_gtk.c,v 1.4 2001/03/07 10:31:10 stef Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Stéphane Borel <stef@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 #define MODULE_NAME gtk
26 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32
33 #include <errno.h>                                                 /* ENOMEM */
34 #include <stdlib.h>                                                /* free() */
35 #include <string.h>                                            /* strerror() */
36 #include <stdio.h>
37
38 #include <gtk/gtk.h>
39
40 #include "config.h"
41 #include "common.h"
42 #include "threads.h"
43 #include "mtime.h"
44 #include "tests.h"
45 #include "modules.h"
46
47 #include "stream_control.h"
48 #include "input_ext-intf.h"
49
50 #include "intf_msg.h"
51 #include "interface.h"
52
53 #include "gtk_sys.h"
54 #include "gtk_callbacks.h"
55 #include "gtk_interface.h"
56 #include "gtk_support.h"
57
58 #include "main.h"
59
60 /*****************************************************************************
61  * Local prototypes.
62  *****************************************************************************/
63 static int  intf_Probe      ( probedata_t *p_data );
64 static int  intf_Open       ( intf_thread_t *p_intf );
65 static void intf_Close      ( intf_thread_t *p_intf );
66 static void intf_Run        ( intf_thread_t *p_intf );
67
68 static gint GtkManage       ( gpointer p_data );
69 static gint GtkLanguageMenus( gpointer, GtkWidget *, es_descriptor_t *, gint,
70                               void (*pf_activate)(GtkMenuItem *, gpointer) );
71 static gint GtkChapterMenu  ( gpointer, GtkWidget *,
72                               void (*pf_activate)(GtkMenuItem *, gpointer) );
73 static gint GtkTitleMenu    ( gpointer, GtkWidget *, 
74                               void (*pf_activate)(GtkMenuItem *, gpointer) );
75
76
77 /*****************************************************************************
78  * g_atexit: kludge to avoid the Gtk+ thread to segfault at exit
79  *****************************************************************************
80  * gtk_init() makes several calls to g_atexit() which calls atexit() to
81  * register tidying callbacks to be called at program exit. Since the Gtk+
82  * plugin is likely to be unloaded at program exit, we have to export this
83  * symbol to intercept the g_atexit() calls. Talk about crude hack.
84  *****************************************************************************/
85 void g_atexit( GVoidFunc func )
86 {
87     intf_thread_t *p_intf = p_main->p_intf;
88
89     if( p_intf->p_sys->pf_gdk_callback == NULL )
90     {
91         p_intf->p_sys->pf_gdk_callback = func;
92     }
93     else if( p_intf->p_sys->pf_gtk_callback == NULL )
94     {
95         p_intf->p_sys->pf_gtk_callback = func;
96     }
97     /* else nothing, but we could do something here */
98     return;
99 }
100
101 /*****************************************************************************
102  * Functions exported as capabilities. They are declared as static so that
103  * we don't pollute the namespace too much.
104  *****************************************************************************/
105 void _M( intf_getfunctions )( function_list_t * p_function_list )
106 {
107     p_function_list->pf_probe = intf_Probe;
108     p_function_list->functions.intf.pf_open  = intf_Open;
109     p_function_list->functions.intf.pf_close = intf_Close;
110     p_function_list->functions.intf.pf_run   = intf_Run;
111 }
112
113 /*****************************************************************************
114  * intf_Probe: probe the interface and return a score
115  *****************************************************************************
116  * This function tries to initialize Gtk+ and returns a score to the
117  * plugin manager so that it can select the best plugin.
118  *****************************************************************************/
119 static int intf_Probe( probedata_t *p_data )
120 {
121     if( TestMethod( INTF_METHOD_VAR, "gtk" ) )
122     {
123         return( 999 );
124     }
125
126     return( 90 );
127 }
128
129 /*****************************************************************************
130  * intf_Open: initialize and create window
131  *****************************************************************************/
132 static int intf_Open( intf_thread_t *p_intf )
133 {
134     /* Allocate instance and initialize some members */
135     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
136     if( p_intf->p_sys == NULL )
137     {
138         intf_ErrMsg("error: %s", strerror(ENOMEM));
139         return( 1 );
140     }
141
142     /* Initialize Gtk+ thread */
143     p_intf->p_sys->b_popup_changed = 0;
144     p_intf->p_sys->b_window_changed = 0;
145     p_intf->p_sys->b_playlist_changed = 0;
146
147     p_intf->p_sys->b_menus_update = 1;
148     p_intf->p_sys->b_scale_isfree = 1;
149
150     p_intf->p_sys->pf_gtk_callback = NULL;
151     p_intf->p_sys->pf_gdk_callback = NULL;
152
153     /* Initialize lock */
154     vlc_mutex_init( &p_intf->p_sys->change_lock );
155
156     return( 0 );
157 }
158
159 /*****************************************************************************
160  * intf_Close: destroy interface window
161  *****************************************************************************/
162 static void intf_Close( intf_thread_t *p_intf )
163 {
164     /* Destroy lock */
165     vlc_mutex_destroy( &p_intf->p_sys->change_lock );
166
167     /* Destroy structure */
168     free( p_intf->p_sys );
169 }
170
171 /*****************************************************************************
172  * intf_Run: Gtk+ thread
173  *****************************************************************************
174  * this part of the interface is in a separate thread so that we can call
175  * gtk_main() from within it without annoying the rest of the program.
176  * XXX: the approach may look kludgy, and probably is, but I could not find
177  * a better way to dynamically load a Gtk+ interface at runtime.
178  *****************************************************************************/
179 static void intf_Run( intf_thread_t *p_intf )
180 {
181     /* gtk_init needs to know the command line. We don't care, so we
182      * give it an empty one */
183     char *p_args[] = { "" };
184     char **pp_args = p_args;
185     int i_args = 1;
186
187     /* The data types we are allowed to receive */
188     static GtkTargetEntry target_table[] =
189     {
190         { "text/uri-list", 0, DROP_ACCEPT_TEXT_URI_LIST },
191         { "text/plain", 0, DROP_ACCEPT_TEXT_PLAIN }
192     };
193
194     /* Initialize Gtk+ */
195     gtk_init( &i_args, &pp_args );
196
197     /* Create some useful widgets that will certainly be used */
198     p_intf->p_sys->p_window = create_intf_window( );
199     p_intf->p_sys->p_popup = create_intf_popup( );
200
201     /* Set the title of the main window */
202     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
203                           VOUT_TITLE " (Gtk+ interface)");
204
205     /* Accept file drops on the main window */
206     gtk_drag_dest_set( GTK_WIDGET( p_intf->p_sys->p_window ),
207                        GTK_DEST_DEFAULT_ALL, target_table,
208                        1, GDK_ACTION_COPY );
209
210     /* We don't create these ones yet because we perhaps won't need them */
211     p_intf->p_sys->p_about = NULL;
212     p_intf->p_sys->p_playlist = NULL;
213     p_intf->p_sys->p_modules = NULL;
214     p_intf->p_sys->p_fileopen = NULL;
215     p_intf->p_sys->p_disc = NULL;
216
217     /* Store p_intf to keep an eye on it */
218     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
219                          "p_intf", p_intf );
220
221     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_popup),
222                          "p_intf", p_intf );
223
224     /* Show the control window */
225     gtk_widget_show( p_intf->p_sys->p_window );
226
227
228     /* Sleep to avoid using all CPU - since some interfaces needs to access
229      * keyboard events, a 100ms delay is a good compromise */
230     p_intf->p_sys->i_timeout = gtk_timeout_add( INTF_IDLE_SLEEP / 1000,
231                                                 GtkManage, p_intf );
232  
233
234     /* Enter Gtk mode */
235     gtk_main();
236
237     /* launch stored callbacks */
238     if( p_intf->p_sys->pf_gtk_callback != NULL )
239     {
240         p_intf->p_sys->pf_gtk_callback();
241
242         if( p_intf->p_sys->pf_gdk_callback != NULL )
243         {
244             p_intf->p_sys->pf_gdk_callback();
245         }
246     }
247 }
248
249 /* following functions are local */
250
251 /*****************************************************************************
252  * GtkManage: manage main thread messages
253  *****************************************************************************
254  * In this function, called approx. 10 times a second, we check what the
255  * main program wanted to tell us.
256  *****************************************************************************/
257 static gint GtkManage( gpointer p_data )
258 {
259     intf_thread_t *p_intf = (void *)p_data;
260
261     vlc_mutex_lock( &p_intf->p_sys->change_lock );
262
263     /* If the "display popup" flag has changed */
264     if( p_intf->b_menu_change )
265     {
266         if( !GTK_IS_WIDGET( p_intf->p_sys->p_popup ) )
267         {
268             p_intf->p_sys->p_popup = create_intf_popup();
269             gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_popup ),
270                                  "p_popup", p_intf );
271         }
272         gtk_menu_popup( GTK_MENU( p_intf->p_sys->p_popup ),
273                         NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME );
274         p_intf->b_menu_change = 0;
275     }
276
277     /* Update language/chapter menus after user request */
278     if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL &&
279         p_intf->p_sys->b_menus_update )
280     {
281         es_descriptor_t *   p_audio_es;
282         es_descriptor_t *   p_spu_es;
283         GtkWidget *         p_menubar_menu;
284         GtkWidget *         p_popup_menu;
285         gint                i;
286
287         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
288                      p_intf->p_sys->p_window ), "menubar_title" ) );
289
290         GtkTitleMenu( p_intf, p_menubar_menu, on_menubar_title_activate );
291
292         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
293                      p_intf->p_sys->p_window ), "menubar_chapter" ) );
294
295         GtkChapterMenu( p_intf, p_menubar_menu, on_menubar_chapter_activate );
296
297         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
298                      p_intf->p_sys->p_popup ), "popup_navigation" ) );
299
300         GtkTitleMenu( p_intf, p_popup_menu, on_popup_navigation_activate );
301     
302         /* look for selected ES */
303         p_audio_es = NULL;
304         p_spu_es = NULL;
305
306         for( i = 0 ; i < p_intf->p_input->stream.i_selected_es_number ; i++ )
307         {
308             if( p_intf->p_input->stream.pp_es[i]->b_audio )
309             {
310                 p_audio_es = p_intf->p_input->stream.pp_es[i];
311             }
312     
313             if( p_intf->p_input->stream.pp_es[i]->b_spu )
314             {
315                 p_spu_es = p_intf->p_input->stream.pp_es[i];
316             }
317         }
318
319         /* audio menus */
320
321         /* find audio root menu */
322         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
323                              p_intf->p_sys->p_window ), "menubar_audio" ) );
324
325         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
326                      p_intf->p_sys->p_popup ), "popup_audio" ) );
327
328         GtkLanguageMenus( p_intf, p_menubar_menu, p_audio_es, 1,
329                           on_menubar_audio_activate );
330         GtkLanguageMenus( p_intf, p_popup_menu, p_audio_es, 1,
331                           on_popup_audio_activate );
332
333         /* sub picture menus */
334
335         /* find spu root menu */
336         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
337                           p_intf->p_sys->p_window ), "menubar_subpictures" ) );
338
339         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
340                      p_intf->p_sys->p_popup ), "popup_subpictures" ) );
341
342         GtkLanguageMenus( p_intf, p_menubar_menu, p_spu_es, 2,
343                           on_menubar_subpictures_activate  );
344         GtkLanguageMenus( p_intf, p_popup_menu, p_spu_es, 2,
345                           on_popup_subpictures_activate );
346
347         /* everything is ready */
348         p_intf->p_sys->b_menus_update = 0;
349     }
350
351     /* Manage the slider */
352     if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL
353          && p_intf->p_sys->b_scale_isfree )
354     {
355         GtkWidget *p_scale;
356         GtkAdjustment *p_adj;
357    
358         p_scale = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
359                                   p_intf->p_sys->p_window ), "hscale" ) );
360         p_adj = gtk_range_get_adjustment ( GTK_RANGE( p_scale ) );
361
362         /* Update the value */
363         p_adj->value = ( 100. *
364                          p_intf->p_input->stream.p_selected_area->i_tell ) /
365                          p_intf->p_input->stream.p_selected_area->i_size;
366
367         /* Gtv does it this way. Why not. */
368         gtk_range_set_adjustment ( GTK_RANGE( p_scale ), p_adj );
369         gtk_range_slider_update ( GTK_RANGE( p_scale ) );
370         gtk_range_clear_background ( GTK_RANGE( p_scale ) );
371         gtk_range_draw_background ( GTK_RANGE( p_scale ) );
372     }
373
374     /* Manage core vlc functions through the callback */
375     p_intf->pf_manage( p_intf );
376
377     if( p_intf->b_die )
378     {
379         /* Make sure we won't be called again */
380         gtk_timeout_remove( p_intf->p_sys->i_timeout );
381
382         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
383
384         /* Prepare to die, young Skywalker */
385         gtk_main_quit();
386         return( FALSE );
387     }
388
389     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
390
391     return( TRUE );
392 }
393
394 /*****************************************************************************
395  * GtkMenuRadioItem: give a menu item adapted to language/title selection,
396  * ie the menu item is a radio button.
397  *****************************************************************************/
398 static GtkWidget * GtkMenuRadioItem( GtkWidget * p_menu,
399                                      GSList **   p_button_group,
400                                      gint        b_active,
401                                      char *      psz_name )
402 {
403     GtkWidget *     p_item;
404
405 #if 0
406     GtkWidget *     p_button;
407
408     /* create button */
409     p_button =
410         gtk_radio_button_new_with_label( *p_button_group, psz_name );
411
412     /* add button to group */
413     *p_button_group =
414         gtk_radio_button_group( GTK_RADIO_BUTTON( p_button ) );
415
416     /* prepare button for display */
417     gtk_widget_show( p_button );
418
419     /* create menu item to store button */
420     p_item = gtk_menu_item_new();
421
422     /* put button inside item */
423     gtk_container_add( GTK_CONTAINER( p_item ), p_button );
424
425     /* add item to menu */
426     gtk_menu_append( GTK_MENU( p_menu ), p_item );
427
428           gtk_signal_connect( GTK_OBJECT( p_item ), "activate",
429                GTK_SIGNAL_FUNC( on_audio_toggle ),
430                NULL );
431
432
433     /* prepare item for display */
434     gtk_widget_show( p_item );
435
436     /* is it the selected item ? */
437     if( b_active )
438     {
439         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( p_button ), TRUE );
440     }
441 #else
442     p_item = gtk_menu_item_new_with_label( psz_name );
443     gtk_menu_append( GTK_MENU( p_menu ), p_item );
444     gtk_widget_show( p_item );
445
446 #endif
447     return p_item;
448 }
449
450 /*****************************************************************************
451  * GtkLanguageMenus: update interactive menus of the interface
452  *****************************************************************************
453  * Sets up menus with information from input:
454  *  -languages
455  *  -sub-pictures
456  * Warning: since this function is designed to be called by management
457  * function, the interface lock has to be taken
458  *****************************************************************************/
459 static gint GtkLanguageMenus( gpointer          p_data,
460                               GtkWidget *       p_root,
461                               es_descriptor_t * p_es,
462                               gint              i_type,
463                         void(*pf_activate )( GtkMenuItem *, gpointer ) )
464 {
465     intf_thread_t *     p_intf;
466     GtkWidget *         p_menu;
467     GtkWidget *         p_separator;
468     GtkWidget *         p_item;
469     GSList *            p_button_group;
470     char *              psz_name;
471     gint                b_active;
472     gint                b_audio;
473     gint                b_spu;
474     gint                i;
475
476     
477
478     /* cast */
479     p_intf = (intf_thread_t *)p_data;
480
481     vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
482
483     b_audio = ( i_type == 1 );
484     p_button_group = NULL;
485
486     /* menu container for audio */
487     p_menu = gtk_menu_new();
488
489     /* create a set of language buttons and append them to the container */
490     b_active = ( p_es == NULL ) ? 1 : 0;
491     psz_name = "Off";
492
493     p_item = GtkMenuRadioItem( p_menu, &p_button_group, b_active, psz_name );
494
495     /* setup signal hanling */
496     gtk_signal_connect( GTK_OBJECT( p_item ), "activate",
497             GTK_SIGNAL_FUNC ( pf_activate ), NULL );
498
499     p_separator = gtk_menu_item_new();
500     gtk_widget_show( p_separator );
501     gtk_menu_append( GTK_MENU( p_menu ), p_separator );
502     gtk_widget_set_sensitive( p_separator, FALSE );
503
504     for( i = 0 ; i < p_intf->p_input->stream.i_es_number ; i++ )
505     {
506
507         b_audio = ( i_type == 1 ) && p_intf->p_input->stream.pp_es[i]->b_audio;
508         b_spu   = ( i_type == 2 ) && p_intf->p_input->stream.pp_es[i]->b_spu;
509
510         if( b_audio || b_spu )
511         {
512             b_active = ( p_es == p_intf->p_input->stream.pp_es[i] ) ? 1 : 0;
513             psz_name = p_intf->p_input->stream.pp_es[i]->psz_desc;
514
515             p_item = GtkMenuRadioItem( p_menu, &p_button_group,
516                                        b_active, psz_name );
517
518             /* setup signal hanling */
519             gtk_signal_connect( GTK_OBJECT( p_item ), "activate",
520                GTK_SIGNAL_FUNC( pf_activate ),
521                  (gpointer)( p_intf->p_input->stream.pp_es[i] ) );
522
523         }
524     }
525
526     /* link the new menu to the menubar item */
527     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
528
529     /* be sure that menu is sensitive */
530     gtk_widget_set_sensitive( p_root, TRUE );
531
532     vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
533
534     return TRUE;
535 }
536
537 /*****************************************************************************
538  * GtkChapterMenu: generate chapter menu foir current title
539  *****************************************************************************/
540 static gint GtkChapterMenu( gpointer p_data, GtkWidget * p_chapter,
541                         void(*pf_activate )( GtkMenuItem *, gpointer ) )
542 {
543     intf_thread_t *     p_intf;
544     char                psz_name[10];
545     GtkWidget *         p_chapter_menu;
546     GtkWidget *         p_item;
547     GSList *            p_chapter_button_group;
548     gint                i_title;
549     gint                i_chapter;
550     gint                b_active;
551
552     /* cast */
553     p_intf = (intf_thread_t*)p_data;
554
555     i_title = p_intf->p_input->stream.p_selected_area->i_id;
556     p_chapter_menu = gtk_menu_new();
557
558     for( i_chapter = 0;
559          i_chapter < p_intf->p_input->stream.pp_areas[i_title]->i_part_nb ;
560          i_chapter++ )
561     {
562         b_active = ( p_intf->p_input->stream.pp_areas[i_title]->i_part
563                      == i_chapter + 1 ) ? 1 : 0;
564         
565         sprintf( psz_name, "Chapter %d", i_chapter + 1 );
566
567         p_item = GtkMenuRadioItem( p_chapter_menu, &p_chapter_button_group,
568                                    b_active, psz_name );
569         /* setup signal hanling */
570         gtk_signal_connect( GTK_OBJECT( p_item ),
571                         "activate",
572                         GTK_SIGNAL_FUNC( pf_activate ),
573                         (gpointer)(i_chapter + 1) );
574     }
575
576     /* link the new menu to the title menu item */
577     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter ),
578                                p_chapter_menu );
579
580     /* be sure that chapter menu is sensitive */
581     gtk_widget_set_sensitive( p_chapter, TRUE );
582
583     return TRUE;
584 }
585
586 /*****************************************************************************
587  * GtkTitleMenu: sets menus for titles and chapters selection
588  * ---
589  * Generates two type of menus:
590  *  -simple list of titles
591  *  -cascaded lists of chapters for each title
592  *****************************************************************************/
593 static gint GtkTitleMenu( gpointer       p_data,
594                           GtkWidget *    p_navigation, 
595                           void(*pf_activate )( GtkMenuItem *, gpointer ) )
596 {
597     intf_thread_t *     p_intf;
598     char                psz_name[10];
599     GtkWidget *         p_title_menu;
600     GtkWidget *         p_title_item;
601     GtkWidget *         p_chapter_menu;
602     GtkWidget *         p_item;
603     GSList *            p_title_button_group;
604     GSList *            p_chapter_button_group;
605     gint                i_title;
606     gint                i_chapter;
607     gint                b_active;
608
609     /* cast */
610     p_intf = (intf_thread_t*)p_data;
611
612     p_title_menu = gtk_menu_new();
613     p_title_button_group = NULL;
614     p_chapter_button_group = NULL;
615
616     /* loop on titles */
617     for( i_title = 1 ;
618          i_title < p_intf->p_input->stream.i_area_nb ;
619          i_title++ )
620     {
621         b_active = ( p_intf->p_input->stream.pp_areas[i_title] ==
622                      p_intf->p_input->stream.p_selected_area ) ? 1 : 0;
623         sprintf( psz_name, "Title %d", i_title );
624
625         p_title_item = GtkMenuRadioItem( p_title_menu, &p_title_button_group,
626                                          b_active, psz_name );
627
628         if( pf_activate == on_menubar_title_activate )
629         {
630             /* setup signal hanling */
631             gtk_signal_connect( GTK_OBJECT( p_title_item ),
632                      "activate",
633                      GTK_SIGNAL_FUNC( pf_activate ),
634                      (gpointer)(p_intf->p_input->stream.pp_areas[i_title]) );
635         }
636         else
637         {
638             p_chapter_menu = gtk_menu_new();
639     
640             for( i_chapter = 0;
641                  i_chapter <
642                         p_intf->p_input->stream.pp_areas[i_title]->i_part_nb ;
643                  i_chapter++ )
644             {
645                 b_active = ( p_intf->p_input->stream.pp_areas[i_title]->i_part
646                              == i_chapter + 1 ) ? 1 : 0;
647                 
648                 sprintf( psz_name, "Chapter %d", i_chapter + 1 );
649     
650                 p_item = GtkMenuRadioItem( p_chapter_menu,
651                                            &p_chapter_button_group,
652                                            b_active, psz_name );
653     
654                 /* setup signal hanling */
655                 gtk_signal_connect( GTK_OBJECT( p_item ),
656                            "activate",
657                            GTK_SIGNAL_FUNC( pf_activate ),
658                            (gpointer)( ( i_title * 100 ) + ( i_chapter + 1) ) );
659         }
660
661         /* link the new menu to the title menu item */
662         gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
663                                    p_chapter_menu );
664         }
665
666         /* be sure that chapter menu is sensitive */
667         gtk_widget_set_sensitive( p_title_menu, TRUE );
668
669     }
670
671     /* link the new menu to the menubar audio item */
672     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
673
674     /* be sure that audio menu is sensitive */
675     gtk_widget_set_sensitive( p_navigation, TRUE );
676
677
678     return TRUE;
679 }