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