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