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