]> git.sesse.net Git - vlc/blob - plugins/gtk/intf_gtk.c
e9c85b766033e3d7363c0b6e230ea4bb7b129567
[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.13 2001/04/13 01:49:22 henri 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     if( p_intf->p_input != NULL )
325     {
326         /* Used by TS input when PMT changes */
327         if( p_intf->p_input->stream.b_changed )
328         {
329             p_intf->p_sys->b_menus_update = 1;
330             p_intf->p_input->stream.b_changed = 0;
331             intf_WarnMsg( 2, 
332                           "Interface menus refreshed as stream has changed" );
333         }
334
335     }
336     
337     /* Update language/chapter menus after user request */
338     if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL &&
339         p_intf->p_sys->b_menus_update )
340     {
341         es_descriptor_t *   p_audio_es;
342         es_descriptor_t *   p_spu_es;
343         GtkWidget *         p_menubar_menu;
344         GtkWidget *         p_popup_menu;
345         gint                i;
346
347         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
348                      p_intf->p_sys->p_window ), "menubar_title" ) );
349
350         GtkTitleMenu( p_intf, p_menubar_menu, on_menubar_title_activate );
351
352         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
353                      p_intf->p_sys->p_window ), "menubar_chapter" ) );
354
355         GtkChapterMenu( p_intf, p_menubar_menu, on_menubar_chapter_activate );
356
357         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
358                      p_intf->p_sys->p_popup ), "popup_navigation" ) );
359
360         GtkTitleMenu( p_intf, p_popup_menu, on_popup_navigation_activate );
361     
362         /* look for selected ES */
363         p_audio_es = NULL;
364         p_spu_es = NULL;
365
366         for( i = 0 ; i < p_intf->p_input->stream.i_selected_es_number ; i++ )
367         {
368             if( p_intf->p_input->stream.pp_es[i]->i_cat == AUDIO_ES )
369             {
370                 p_audio_es = p_intf->p_input->stream.pp_es[i];
371             }
372     
373             if( p_intf->p_input->stream.pp_es[i]->i_cat == SPU_ES )
374             {
375                 p_spu_es = p_intf->p_input->stream.pp_es[i];
376             }
377         }
378
379         /* audio menus */
380
381         /* find audio root menu */
382         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
383                              p_intf->p_sys->p_window ), "menubar_audio" ) );
384
385         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
386                      p_intf->p_sys->p_popup ), "popup_audio" ) );
387
388         GtkLanguageMenus( p_intf, p_menubar_menu, p_audio_es, AUDIO_ES,
389                           on_menubar_audio_activate );
390         GtkLanguageMenus( p_intf, p_popup_menu, p_audio_es, AUDIO_ES,
391                           on_popup_audio_activate );
392
393         /* sub picture menus */
394
395         /* find spu root menu */
396         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
397                           p_intf->p_sys->p_window ), "menubar_subpictures" ) );
398
399         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
400                      p_intf->p_sys->p_popup ), "popup_subpictures" ) );
401
402         GtkLanguageMenus( p_intf, p_menubar_menu, p_spu_es, SPU_ES,
403                           on_menubar_subpictures_activate  );
404         GtkLanguageMenus( p_intf, p_popup_menu, p_spu_es, SPU_ES,
405                           on_popup_subpictures_activate );
406
407         /* everything is ready */
408         p_intf->p_sys->b_menus_update = 0;
409     }
410
411     /* Manage the slider */
412     if( p_intf->p_input != NULL )
413     {
414         float newvalue = p_intf->p_sys->p_adj->value;
415
416 #define p_area p_intf->p_input->stream.p_selected_area
417         /* If the user hasn't touched the slider since the last time,
418          * then the input can safely change it */
419         if( newvalue == p_intf->p_sys->f_adj_oldvalue )
420         {
421             /* Update the value */
422             p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue =
423                 ( 100. * p_area->i_tell ) / p_area->i_size;
424
425             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
426                                      "value_changed" );
427         }
428         /* Otherwise, send message to the input if the user has
429          * finished dragging the slider */
430         else if( p_intf->p_sys->b_slider_free )
431         {
432             off_t i_seek = ( newvalue * p_area->i_size ) / 100;
433
434             input_Seek( p_intf->p_input, i_seek );
435
436             /* Update the old value */
437             p_intf->p_sys->f_adj_oldvalue = newvalue;
438         }
439 #undef p_area
440     }
441
442     /* Manage core vlc functions through the callback */
443     p_intf->pf_manage( p_intf );
444
445     if( p_intf->b_die )
446     {
447         vlc_mutex_unlock( &p_intf->change_lock );
448
449         /* Prepare to die, young Skywalker */
450         gtk_main_quit();
451
452         /* Just in case */
453         return( FALSE );
454     }
455
456     vlc_mutex_unlock( &p_intf->change_lock );
457
458     return( TRUE );
459
460 #undef p_intf
461 }
462
463 /*****************************************************************************
464  * GtkMenuRadioItem: give a menu item adapted to language/title selection,
465  * ie the menu item is a radio button.
466  *****************************************************************************/
467 static GtkWidget * GtkMenuRadioItem( GtkWidget * p_menu,
468                                      GSList **   p_button_group,
469                                      gint        b_active,
470                                      char *      psz_name )
471 {
472     GtkWidget *     p_item;
473
474 #if 0
475     GtkWidget *     p_button;
476
477     /* create button */
478     p_button =
479         gtk_radio_button_new_with_label( *p_button_group, psz_name );
480
481     /* add button to group */
482     *p_button_group =
483         gtk_radio_button_group( GTK_RADIO_BUTTON( p_button ) );
484
485     /* prepare button for display */
486     gtk_widget_show( p_button );
487
488     /* create menu item to store button */
489     p_item = gtk_menu_item_new();
490
491     /* put button inside item */
492     gtk_container_add( GTK_CONTAINER( p_item ), p_button );
493
494     /* add item to menu */
495     gtk_menu_append( GTK_MENU( p_menu ), p_item );
496
497           gtk_signal_connect( GTK_OBJECT( p_item ), "activate",
498                GTK_SIGNAL_FUNC( on_audio_toggle ),
499                NULL );
500
501
502     /* prepare item for display */
503     gtk_widget_show( p_item );
504
505     /* is it the selected item ? */
506     if( b_active )
507     {
508         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( p_button ), TRUE );
509     }
510 #else
511     p_item = gtk_menu_item_new_with_label( psz_name );
512     gtk_menu_append( GTK_MENU( p_menu ), p_item );
513     gtk_widget_show( p_item );
514 #endif
515
516     return p_item;
517 }
518
519 /*****************************************************************************
520  * GtkLanguageMenus: update interactive menus of the interface
521  *****************************************************************************
522  * Sets up menus with information from input:
523  *  -languages
524  *  -sub-pictures
525  * Warning: since this function is designed to be called by management
526  * function, the interface lock has to be taken
527  *****************************************************************************/
528 static gint GtkLanguageMenus( gpointer          p_data,
529                               GtkWidget *       p_root,
530                               es_descriptor_t * p_es,
531                               gint              i_cat,
532                         void(*pf_activate )( GtkMenuItem *, gpointer ) )
533 {
534     intf_thread_t *     p_intf;
535     GtkWidget *         p_menu;
536     GtkWidget *         p_separator;
537     GtkWidget *         p_item;
538     GSList *            p_button_group;
539     char *              psz_name;
540     gint                b_active;
541     gint                i;
542
543     
544
545     /* cast */
546     p_intf = (intf_thread_t *)p_data;
547
548     vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
549
550     p_button_group = NULL;
551
552     /* menu container for audio */
553     p_menu = gtk_menu_new();
554
555     /* create a set of language buttons and append them to the container */
556     b_active = ( p_es == NULL );
557     psz_name = "Off";
558
559     p_item = GtkMenuRadioItem( p_menu, &p_button_group, b_active, psz_name );
560
561     /* setup signal hanling */
562     gtk_signal_connect( GTK_OBJECT( p_item ), "activate",
563             GTK_SIGNAL_FUNC ( pf_activate ), NULL );
564
565     p_separator = gtk_menu_item_new();
566     gtk_widget_show( p_separator );
567     gtk_menu_append( GTK_MENU( p_menu ), p_separator );
568     gtk_widget_set_sensitive( p_separator, FALSE );
569
570     for( i = 0 ; i < p_intf->p_input->stream.i_es_number ; i++ )
571     {
572         if( p_intf->p_input->stream.pp_es[i]->i_cat == i_cat )
573         {
574             b_active = ( p_es == p_intf->p_input->stream.pp_es[i] ) ? 1 : 0;
575             psz_name = p_intf->p_input->stream.pp_es[i]->psz_desc;
576
577             p_item = GtkMenuRadioItem( p_menu, &p_button_group,
578                                        b_active, psz_name );
579
580             /* setup signal hanling */
581             gtk_signal_connect( GTK_OBJECT( p_item ), "activate",
582                GTK_SIGNAL_FUNC( pf_activate ),
583                  (gpointer)( p_intf->p_input->stream.pp_es[i] ) );
584
585         }
586     }
587
588     /* link the new menu to the menubar item */
589     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
590
591     /* be sure that menu is sensitive */
592     gtk_widget_set_sensitive( p_root, TRUE );
593
594     vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
595
596     return TRUE;
597 }
598
599 /*****************************************************************************
600  * GtkChapterMenu: generate chapter menu for current title
601  *****************************************************************************/
602 static gint GtkChapterMenu( gpointer p_data, GtkWidget * p_chapter,
603                         void(*pf_activate )( GtkMenuItem *, gpointer ) )
604 {
605     intf_thread_t *     p_intf;
606     char                psz_name[10];
607     GtkWidget *         p_chapter_menu;
608     GtkWidget *         p_item;
609     GSList *            p_chapter_button_group;
610     gint                i_title;
611     gint                i_chapter;
612     gint                b_active;
613
614     /* cast */
615     p_intf = (intf_thread_t*)p_data;
616
617     i_title = p_intf->p_input->stream.p_selected_area->i_id;
618     p_chapter_menu = gtk_menu_new();
619
620     for( i_chapter = 0;
621          i_chapter < p_intf->p_input->stream.pp_areas[i_title]->i_part_nb ;
622          i_chapter++ )
623     {
624         b_active = ( p_intf->p_input->stream.pp_areas[i_title]->i_part
625                      == i_chapter + 1 ) ? 1 : 0;
626         
627         sprintf( psz_name, "Chapter %d", i_chapter + 1 );
628
629         p_item = GtkMenuRadioItem( p_chapter_menu, &p_chapter_button_group,
630                                    b_active, psz_name );
631         /* setup signal hanling */
632         gtk_signal_connect( GTK_OBJECT( p_item ),
633                         "activate",
634                         GTK_SIGNAL_FUNC( pf_activate ),
635                         (gpointer)(i_chapter + 1) );
636     }
637
638     /* link the new menu to the title menu item */
639     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter ),
640                                p_chapter_menu );
641
642     /* be sure that chapter menu is sensitive */
643     gtk_widget_set_sensitive( p_chapter, TRUE );
644
645     return TRUE;
646 }
647
648 /*****************************************************************************
649  * GtkTitleMenu: sets menus for titles and chapters selection
650  *****************************************************************************
651  * Generates two type of menus:
652  *  -simple list of titles
653  *  -cascaded lists of chapters for each title
654  *****************************************************************************/
655 static gint GtkTitleMenu( gpointer       p_data,
656                           GtkWidget *    p_navigation, 
657                           void(*pf_activate )( GtkMenuItem *, gpointer ) )
658 {
659     intf_thread_t *     p_intf;
660     char                psz_name[10];
661     GtkWidget *         p_title_menu;
662     GtkWidget *         p_title_item;
663     GtkWidget *         p_chapter_menu;
664     GtkWidget *         p_item;
665     GSList *            p_title_button_group;
666     GSList *            p_chapter_button_group;
667     gint                i_title;
668     gint                i_chapter;
669     gint                b_active;
670
671     /* cast */
672     p_intf = (intf_thread_t*)p_data;
673
674     p_title_menu = gtk_menu_new();
675     p_title_button_group = NULL;
676     p_chapter_button_group = NULL;
677
678     /* loop on titles */
679     for( i_title = 1 ;
680          i_title < p_intf->p_input->stream.i_area_nb ;
681          i_title++ )
682     {
683         b_active = ( p_intf->p_input->stream.pp_areas[i_title] ==
684                      p_intf->p_input->stream.p_selected_area ) ? 1 : 0;
685         sprintf( psz_name, "Title %d", i_title );
686
687         p_title_item = GtkMenuRadioItem( p_title_menu, &p_title_button_group,
688                                          b_active, psz_name );
689
690         if( pf_activate == on_menubar_title_activate )
691         {
692             /* setup signal hanling */
693             gtk_signal_connect( GTK_OBJECT( p_title_item ),
694                      "activate",
695                      GTK_SIGNAL_FUNC( pf_activate ),
696                      (gpointer)(p_intf->p_input->stream.pp_areas[i_title]) );
697         }
698         else
699         {
700             p_chapter_menu = gtk_menu_new();
701     
702             for( i_chapter = 0;
703                  i_chapter <
704                         p_intf->p_input->stream.pp_areas[i_title]->i_part_nb ;
705                  i_chapter++ )
706             {
707                 b_active = ( p_intf->p_input->stream.pp_areas[i_title]->i_part
708                              == i_chapter + 1 ) ? 1 : 0;
709                 
710                 sprintf( psz_name, "Chapter %d", i_chapter + 1 );
711     
712                 p_item = GtkMenuRadioItem( p_chapter_menu,
713                                            &p_chapter_button_group,
714                                            b_active, psz_name );
715     
716                 /* setup signal hanling */
717                 gtk_signal_connect( GTK_OBJECT( p_item ),
718                            "activate",
719                            GTK_SIGNAL_FUNC( pf_activate ),
720                            (gpointer)( ( i_title * 100 ) + ( i_chapter + 1) ) );
721         }
722
723         /* link the new menu to the title menu item */
724         gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
725                                    p_chapter_menu );
726         }
727
728         /* be sure that chapter menu is sensitive */
729         gtk_widget_set_sensitive( p_title_menu, TRUE );
730
731     }
732
733     /* link the new menu to the menubar audio item */
734     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
735
736     /* be sure that audio menu is sensitive */
737     gtk_widget_set_sensitive( p_navigation, TRUE );
738
739
740     return TRUE;
741 }
742
743 void GtkDisplayDate( GtkAdjustment *p_adj )
744 {
745     intf_thread_t *p_intf;
746
747     p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
748
749     if( p_intf->p_input != NULL )
750     {
751 #define p_area p_intf->p_input->stream.p_selected_area
752         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
753
754         vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
755
756         gtk_label_set_text( p_intf->p_sys->p_label_date,
757                             input_OffsetToTime( p_intf->p_input, psz_time,
758                                    ( p_area->i_size * p_adj->value ) / 100 ) );
759
760         vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
761 #undef p_area
762      }
763 }
764
765