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