]> git.sesse.net Git - vlc/blob - plugins/gtk/intf_gtk.c
Hurg !
[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.6 2001/03/08 13:32:55 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_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 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     /* Set the title of the main window */
208     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
209                           VOUT_TITLE " (Gtk+ interface)");
210
211     /* Accept file drops on the main window */
212     gtk_drag_dest_set( GTK_WIDGET( p_intf->p_sys->p_window ),
213                        GTK_DEST_DEFAULT_ALL, target_table,
214                        1, GDK_ACTION_COPY );
215
216     /* Accept file drops on the playlist window */
217     temp = lookup_widget(p_intf->p_sys->p_playlist, "clist1"); 
218     gtk_drag_dest_set( GTK_WIDGET( temp ),
219                        GTK_DEST_DEFAULT_ALL, target_table,
220                        1, GDK_ACTION_COPY );
221
222     /* We don't create these ones yet because we perhaps won't need them */
223     p_intf->p_sys->p_about = NULL;
224     p_intf->p_sys->p_modules = NULL;
225     p_intf->p_sys->p_fileopen = NULL;
226     p_intf->p_sys->p_disc = NULL;
227
228     /* Store p_intf to keep an eye on it */
229     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
230                          "p_intf", p_intf );
231
232     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_popup),
233                          "p_intf", p_intf );
234
235     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_playlist),
236                          "p_intf", p_intf );
237
238  
239
240     /* Show the control window */
241     gtk_widget_show( p_intf->p_sys->p_window );
242
243
244     /* Sleep to avoid using all CPU - since some interfaces needs to access
245      * keyboard events, a 100ms delay is a good compromise */
246     p_intf->p_sys->i_timeout = gtk_timeout_add( INTF_IDLE_SLEEP / 1000,
247                                                 GtkManage, p_intf );
248  
249
250     /* Enter Gtk mode */
251     gtk_main();
252
253     /* launch stored callbacks */
254     if( p_intf->p_sys->pf_gtk_callback != NULL )
255     {
256         p_intf->p_sys->pf_gtk_callback();
257
258         if( p_intf->p_sys->pf_gdk_callback != NULL )
259         {
260             p_intf->p_sys->pf_gdk_callback();
261         }
262     }
263 }
264
265 /* following functions are local */
266
267 /*****************************************************************************
268  * GtkManage: manage main thread messages
269  *****************************************************************************
270  * In this function, called approx. 10 times a second, we check what the
271  * main program wanted to tell us.
272  *****************************************************************************/
273
274 static gint GtkManage( gpointer p_data )
275 {
276     intf_thread_t *p_intf = (void *)p_data;
277
278     GtkPlayListManage( p_data ); 
279
280     vlc_mutex_lock( &p_intf->p_sys->change_lock );
281
282     
283     /* If the "display popup" flag has changed */
284     if( p_intf->b_menu_change )
285     {
286         if( !GTK_IS_WIDGET( p_intf->p_sys->p_popup ) )
287         {
288             p_intf->p_sys->p_popup = create_intf_popup();
289             gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_popup ),
290                                  "p_popup", p_intf );
291         }
292         gtk_menu_popup( GTK_MENU( p_intf->p_sys->p_popup ),
293                         NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME );
294         p_intf->b_menu_change = 0;
295     }
296
297     /* Update language/chapter menus after user request */
298     if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL &&
299         p_intf->p_sys->b_menus_update )
300     {
301         es_descriptor_t *   p_audio_es;
302         es_descriptor_t *   p_spu_es;
303         GtkWidget *         p_menubar_menu;
304         GtkWidget *         p_popup_menu;
305         gint                i;
306
307         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
308                      p_intf->p_sys->p_window ), "menubar_title" ) );
309
310         GtkTitleMenu( p_intf, p_menubar_menu, on_menubar_title_activate );
311
312         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
313                      p_intf->p_sys->p_window ), "menubar_chapter" ) );
314
315         GtkChapterMenu( p_intf, p_menubar_menu, on_menubar_chapter_activate );
316
317         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
318                      p_intf->p_sys->p_popup ), "popup_navigation" ) );
319
320         GtkTitleMenu( p_intf, p_popup_menu, on_popup_navigation_activate );
321     
322         /* look for selected ES */
323         p_audio_es = NULL;
324         p_spu_es = NULL;
325
326         for( i = 0 ; i < p_intf->p_input->stream.i_selected_es_number ; i++ )
327         {
328             if( p_intf->p_input->stream.pp_es[i]->b_audio )
329             {
330                 p_audio_es = p_intf->p_input->stream.pp_es[i];
331             }
332     
333             if( p_intf->p_input->stream.pp_es[i]->b_spu )
334             {
335                 p_spu_es = p_intf->p_input->stream.pp_es[i];
336             }
337         }
338
339         /* audio menus */
340
341         /* find audio root menu */
342         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
343                              p_intf->p_sys->p_window ), "menubar_audio" ) );
344
345         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
346                      p_intf->p_sys->p_popup ), "popup_audio" ) );
347
348         GtkLanguageMenus( p_intf, p_menubar_menu, p_audio_es, 1,
349                           on_menubar_audio_activate );
350         GtkLanguageMenus( p_intf, p_popup_menu, p_audio_es, 1,
351                           on_popup_audio_activate );
352
353         /* sub picture menus */
354
355         /* find spu root menu */
356         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
357                           p_intf->p_sys->p_window ), "menubar_subpictures" ) );
358
359         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
360                      p_intf->p_sys->p_popup ), "popup_subpictures" ) );
361
362         GtkLanguageMenus( p_intf, p_menubar_menu, p_spu_es, 2,
363                           on_menubar_subpictures_activate  );
364         GtkLanguageMenus( p_intf, p_popup_menu, p_spu_es, 2,
365                           on_popup_subpictures_activate );
366
367         /* everything is ready */
368         p_intf->p_sys->b_menus_update = 0;
369     }
370
371     /* Manage the slider */
372     if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL
373          && p_intf->p_sys->b_scale_isfree )
374     {
375         GtkWidget *p_scale;
376         GtkAdjustment *p_adj;
377    
378         p_scale = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
379                                   p_intf->p_sys->p_window ), "hscale" ) );
380         p_adj = gtk_range_get_adjustment ( GTK_RANGE( p_scale ) );
381
382         /* Update the value */
383         p_adj->value = ( 100. *
384                          p_intf->p_input->stream.p_selected_area->i_tell ) /
385                          p_intf->p_input->stream.p_selected_area->i_size;
386
387         /* Gtv does it this way. Why not. */
388         gtk_range_set_adjustment ( GTK_RANGE( p_scale ), p_adj );
389         gtk_range_slider_update ( GTK_RANGE( p_scale ) );
390         gtk_range_clear_background ( GTK_RANGE( p_scale ) );
391         gtk_range_draw_background ( GTK_RANGE( p_scale ) );
392     }
393
394
395     /* Manage core vlc functions through the callback */
396     p_intf->pf_manage( p_intf );
397
398     if( p_intf->b_die )
399     {
400         /* Make sure we won't be called again */
401         gtk_timeout_remove( p_intf->p_sys->i_timeout );
402
403         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
404
405         /* Prepare to die, young Skywalker */
406         gtk_main_quit();
407         return( FALSE );
408     }
409
410     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
411
412     return( TRUE );
413 }
414
415 /*****************************************************************************
416  * GtkMenuRadioItem: give a menu item adapted to language/title selection,
417  * ie the menu item is a radio button.
418  *****************************************************************************/
419 static GtkWidget * GtkMenuRadioItem( GtkWidget * p_menu,
420                                      GSList **   p_button_group,
421                                      gint        b_active,
422                                      char *      psz_name )
423 {
424     GtkWidget *     p_item;
425
426 #if 0
427     GtkWidget *     p_button;
428
429     /* create button */
430     p_button =
431         gtk_radio_button_new_with_label( *p_button_group, psz_name );
432
433     /* add button to group */
434     *p_button_group =
435         gtk_radio_button_group( GTK_RADIO_BUTTON( p_button ) );
436
437     /* prepare button for display */
438     gtk_widget_show( p_button );
439
440     /* create menu item to store button */
441     p_item = gtk_menu_item_new();
442
443     /* put button inside item */
444     gtk_container_add( GTK_CONTAINER( p_item ), p_button );
445
446     /* add item to menu */
447     gtk_menu_append( GTK_MENU( p_menu ), p_item );
448
449           gtk_signal_connect( GTK_OBJECT( p_item ), "activate",
450                GTK_SIGNAL_FUNC( on_audio_toggle ),
451                NULL );
452
453
454     /* prepare item for display */
455     gtk_widget_show( p_item );
456
457     /* is it the selected item ? */
458     if( b_active )
459     {
460         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( p_button ), TRUE );
461     }
462 #else
463     p_item = gtk_menu_item_new_with_label( psz_name );
464     gtk_menu_append( GTK_MENU( p_menu ), p_item );
465     gtk_widget_show( p_item );
466 #endif
467
468     return p_item;
469 }
470
471 /*****************************************************************************
472  * GtkLanguageMenus: update interactive menus of the interface
473  *****************************************************************************
474  * Sets up menus with information from input:
475  *  -languages
476  *  -sub-pictures
477  * Warning: since this function is designed to be called by management
478  * function, the interface lock has to be taken
479  *****************************************************************************/
480 static gint GtkLanguageMenus( gpointer          p_data,
481                               GtkWidget *       p_root,
482                               es_descriptor_t * p_es,
483                               gint              i_type,
484                         void(*pf_activate )( GtkMenuItem *, gpointer ) )
485 {
486     intf_thread_t *     p_intf;
487     GtkWidget *         p_menu;
488     GtkWidget *         p_separator;
489     GtkWidget *         p_item;
490     GSList *            p_button_group;
491     char *              psz_name;
492     gint                b_active;
493     gint                b_audio;
494     gint                b_spu;
495     gint                i;
496
497     
498
499     /* cast */
500     p_intf = (intf_thread_t *)p_data;
501
502     vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
503
504     b_audio = ( i_type == 1 );
505     p_button_group = NULL;
506
507     /* menu container for audio */
508     p_menu = gtk_menu_new();
509
510     /* create a set of language buttons and append them to the container */
511     b_active = ( p_es == NULL ) ? 1 : 0;
512     psz_name = "Off";
513
514     p_item = GtkMenuRadioItem( p_menu, &p_button_group, b_active, psz_name );
515
516     /* setup signal hanling */
517     gtk_signal_connect( GTK_OBJECT( p_item ), "activate",
518             GTK_SIGNAL_FUNC ( pf_activate ), NULL );
519
520     p_separator = gtk_menu_item_new();
521     gtk_widget_show( p_separator );
522     gtk_menu_append( GTK_MENU( p_menu ), p_separator );
523     gtk_widget_set_sensitive( p_separator, FALSE );
524
525     for( i = 0 ; i < p_intf->p_input->stream.i_es_number ; i++ )
526     {
527
528         b_audio = ( i_type == 1 ) && p_intf->p_input->stream.pp_es[i]->b_audio;
529         b_spu   = ( i_type == 2 ) && p_intf->p_input->stream.pp_es[i]->b_spu;
530
531         if( b_audio || b_spu )
532         {
533             b_active = ( p_es == p_intf->p_input->stream.pp_es[i] ) ? 1 : 0;
534             psz_name = p_intf->p_input->stream.pp_es[i]->psz_desc;
535
536             p_item = GtkMenuRadioItem( p_menu, &p_button_group,
537                                        b_active, psz_name );
538
539             /* setup signal hanling */
540             gtk_signal_connect( GTK_OBJECT( p_item ), "activate",
541                GTK_SIGNAL_FUNC( pf_activate ),
542                  (gpointer)( p_intf->p_input->stream.pp_es[i] ) );
543
544         }
545     }
546
547     /* link the new menu to the menubar item */
548     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
549
550     /* be sure that menu is sensitive */
551     gtk_widget_set_sensitive( p_root, TRUE );
552
553     vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
554
555     return TRUE;
556 }
557
558 /*****************************************************************************
559  * GtkChapterMenu: generate chapter menu for current title
560  *****************************************************************************/
561 static gint GtkChapterMenu( gpointer p_data, GtkWidget * p_chapter,
562                         void(*pf_activate )( GtkMenuItem *, gpointer ) )
563 {
564     intf_thread_t *     p_intf;
565     char                psz_name[10];
566     GtkWidget *         p_chapter_menu;
567     GtkWidget *         p_item;
568     GSList *            p_chapter_button_group;
569     gint                i_title;
570     gint                i_chapter;
571     gint                b_active;
572
573     /* cast */
574     p_intf = (intf_thread_t*)p_data;
575
576     i_title = p_intf->p_input->stream.p_selected_area->i_id;
577     p_chapter_menu = gtk_menu_new();
578
579     for( i_chapter = 0;
580          i_chapter < p_intf->p_input->stream.pp_areas[i_title]->i_part_nb ;
581          i_chapter++ )
582     {
583         b_active = ( p_intf->p_input->stream.pp_areas[i_title]->i_part
584                      == i_chapter + 1 ) ? 1 : 0;
585         
586         sprintf( psz_name, "Chapter %d", i_chapter + 1 );
587
588         p_item = GtkMenuRadioItem( p_chapter_menu, &p_chapter_button_group,
589                                    b_active, psz_name );
590         /* setup signal hanling */
591         gtk_signal_connect( GTK_OBJECT( p_item ),
592                         "activate",
593                         GTK_SIGNAL_FUNC( pf_activate ),
594                         (gpointer)(i_chapter + 1) );
595     }
596
597     /* link the new menu to the title menu item */
598     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter ),
599                                p_chapter_menu );
600
601     /* be sure that chapter menu is sensitive */
602     gtk_widget_set_sensitive( p_chapter, TRUE );
603
604     return TRUE;
605 }
606
607 /*****************************************************************************
608  * GtkTitleMenu: sets menus for titles and chapters selection
609  *****************************************************************************
610  * Generates two type of menus:
611  *  -simple list of titles
612  *  -cascaded lists of chapters for each title
613  *****************************************************************************/
614 static gint GtkTitleMenu( gpointer       p_data,
615                           GtkWidget *    p_navigation, 
616                           void(*pf_activate )( GtkMenuItem *, gpointer ) )
617 {
618     intf_thread_t *     p_intf;
619     char                psz_name[10];
620     GtkWidget *         p_title_menu;
621     GtkWidget *         p_title_item;
622     GtkWidget *         p_chapter_menu;
623     GtkWidget *         p_item;
624     GSList *            p_title_button_group;
625     GSList *            p_chapter_button_group;
626     gint                i_title;
627     gint                i_chapter;
628     gint                b_active;
629
630     /* cast */
631     p_intf = (intf_thread_t*)p_data;
632
633     p_title_menu = gtk_menu_new();
634     p_title_button_group = NULL;
635     p_chapter_button_group = NULL;
636
637     /* loop on titles */
638     for( i_title = 1 ;
639          i_title < p_intf->p_input->stream.i_area_nb ;
640          i_title++ )
641     {
642         b_active = ( p_intf->p_input->stream.pp_areas[i_title] ==
643                      p_intf->p_input->stream.p_selected_area ) ? 1 : 0;
644         sprintf( psz_name, "Title %d", i_title );
645
646         p_title_item = GtkMenuRadioItem( p_title_menu, &p_title_button_group,
647                                          b_active, psz_name );
648
649         if( pf_activate == on_menubar_title_activate )
650         {
651             /* setup signal hanling */
652             gtk_signal_connect( GTK_OBJECT( p_title_item ),
653                      "activate",
654                      GTK_SIGNAL_FUNC( pf_activate ),
655                      (gpointer)(p_intf->p_input->stream.pp_areas[i_title]) );
656         }
657         else
658         {
659             p_chapter_menu = gtk_menu_new();
660     
661             for( i_chapter = 0;
662                  i_chapter <
663                         p_intf->p_input->stream.pp_areas[i_title]->i_part_nb ;
664                  i_chapter++ )
665             {
666                 b_active = ( p_intf->p_input->stream.pp_areas[i_title]->i_part
667                              == i_chapter + 1 ) ? 1 : 0;
668                 
669                 sprintf( psz_name, "Chapter %d", i_chapter + 1 );
670     
671                 p_item = GtkMenuRadioItem( p_chapter_menu,
672                                            &p_chapter_button_group,
673                                            b_active, psz_name );
674     
675                 /* setup signal hanling */
676                 gtk_signal_connect( GTK_OBJECT( p_item ),
677                            "activate",
678                            GTK_SIGNAL_FUNC( pf_activate ),
679                            (gpointer)( ( i_title * 100 ) + ( i_chapter + 1) ) );
680         }
681
682         /* link the new menu to the title menu item */
683         gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
684                                    p_chapter_menu );
685         }
686
687         /* be sure that chapter menu is sensitive */
688         gtk_widget_set_sensitive( p_title_menu, TRUE );
689
690     }
691
692     /* link the new menu to the menubar audio item */
693     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
694
695     /* be sure that audio menu is sensitive */
696     gtk_widget_set_sensitive( p_navigation, TRUE );
697
698
699     return TRUE;
700 }