]> git.sesse.net Git - vlc/blob - plugins/gnome/intf_gnome.c
-changes in gnome interface
[vlc] / plugins / gnome / intf_gnome.c
1 /*****************************************************************************
2  * intf_gnome.c: Gnome interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: intf_gnome.c,v 1.26 2001/04/08 07:24:47 stef 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 gnome
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 <gnome.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 #include "intf_playlist.h"
53
54 #include "gnome_callbacks.h"
55 #include "gnome_interface.h"
56 #include "gnome_support.h"
57 #include "intf_gnome.h"
58
59 #include "main.h"
60
61 /*****************************************************************************
62  * Local prototypes.
63  *****************************************************************************/
64 static int  intf_Probe     ( probedata_t *p_data );
65 static int  intf_Open      ( intf_thread_t *p_intf );
66 static void intf_Close     ( intf_thread_t *p_intf );
67 static void intf_Run       ( intf_thread_t *p_intf );
68
69 static gint GnomeManage    ( gpointer p_data );
70 static gint GnomeLanguageMenus( gpointer, GtkWidget *, es_descriptor_t *, gint,
71                               void (*pf_toggle)(GtkCheckMenuItem *, gpointer) );
72 static gint GnomeChapterMenu  ( gpointer, GtkWidget *,
73                               void (*pf_toggle)(GtkCheckMenuItem *, gpointer) );
74 static gint GnomeTitleMenu    ( gpointer, GtkWidget *, 
75                               void (*pf_toggle)(GtkCheckMenuItem *, gpointer) );
76 static gint GnomeSetupMenu    ( intf_thread_t * p_intf );
77 static void GnomeDisplayDate  ( GtkAdjustment *p_adj );
78 static gint GnomeDVDModeManage( intf_thread_t * p_intf );
79 static gint GnomeFileModeManage( intf_thread_t * p_intf );
80 static gint GnomeNetworkModeManage( intf_thread_t * p_intf );
81
82 /*****************************************************************************
83  * g_atexit: kludge to avoid the Gnome thread to segfault at exit
84  *****************************************************************************
85  * gtk_init() makes several calls to g_atexit() which calls atexit() to
86  * register tidying callbacks to be called at program exit. Since the Gnome
87  * plugin is likely to be unloaded at program exit, we have to export this
88  * symbol to intercept the g_atexit() calls. Talk about crude hack.
89  *****************************************************************************/
90 void g_atexit( GVoidFunc func )
91 {
92     intf_thread_t *p_intf = p_main->p_intf;
93
94     if( p_intf->p_sys->pf_gdk_callback == NULL )
95     {
96         p_intf->p_sys->pf_gdk_callback = func;
97     }
98     else if( p_intf->p_sys->pf_gtk_callback == NULL )
99     {
100         p_intf->p_sys->pf_gtk_callback = func;
101     }
102     /* else nothing, but we could do something here */
103     return;
104 }
105
106 /*****************************************************************************
107  * Functions exported as capabilities. They are declared as static so that
108  * we don't pollute the namespace too much.
109  *****************************************************************************/
110 void _M( intf_getfunctions )( function_list_t * p_function_list )
111 {
112     p_function_list->pf_probe = intf_Probe;
113     p_function_list->functions.intf.pf_open  = intf_Open;
114     p_function_list->functions.intf.pf_close = intf_Close;
115     p_function_list->functions.intf.pf_run   = intf_Run;
116 }
117
118 /*****************************************************************************
119  * intf_Probe: probe the interface and return a score
120  *****************************************************************************
121  * This function tries to initialize Gnome and returns a score to the
122  * plugin manager so that it can select the best plugin.
123  *****************************************************************************/
124 static int intf_Probe( probedata_t *p_data )
125 {
126     if( TestMethod( INTF_METHOD_VAR, "gnome" ) )
127     {
128         return( 999 );
129     }
130
131     return( 100 );
132 }
133
134 /*****************************************************************************
135  * intf_Open: initialize and create window
136  *****************************************************************************/
137 static int intf_Open( intf_thread_t *p_intf )
138 {
139     /* Allocate instance and initialize some members */
140     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
141     if( p_intf->p_sys == NULL )
142     {
143         intf_ErrMsg("error: %s", strerror(ENOMEM));
144         return( 1 );
145     }
146
147     /* Initialize Gnome thread */
148     p_intf->p_sys->b_popup_changed = 0;
149     p_intf->p_sys->b_window_changed = 0;
150     p_intf->p_sys->b_playlist_changed = 0;
151     p_intf->p_sys->b_menus_update = 1;
152
153     p_intf->p_sys->b_slider_free = 1;
154
155     p_intf->p_sys->b_mode_changed = 1;
156     p_intf->p_sys->i_intf_mode = FILE_MODE;
157
158     p_intf->p_sys->i_part = 0;
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: Gnome 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 Gnome interface at runtime.
182  *****************************************************************************/
183 static void intf_Run( intf_thread_t *p_intf )
184 {
185     /* gnome_init needs to know the command line. We don't care, so we
186      * give it an empty one */
187     char *p_args[] = { "" };
188     int   i_args   = 1;
189
190     /* The data types we are allowed to receive */
191     static GtkTargetEntry target_table[] =
192     {
193         { "text/uri-list", 0, DROP_ACCEPT_TEXT_URI_LIST },
194         { "text/plain",    0, DROP_ACCEPT_TEXT_PLAIN }
195     };
196
197     /* intf_Manage callback timeout */
198     int i_timeout;
199
200     /* Initialize Gnome */
201     gnome_init( p_main->psz_arg0, VERSION, i_args, p_args );
202
203     /* Create some useful widgets that will certainly be used */
204     p_intf->p_sys->p_window = create_intf_window( );
205     p_intf->p_sys->p_popup = create_intf_popup( );
206     p_intf->p_sys->p_disc = create_intf_disc( );
207     p_intf->p_sys->p_network = create_intf_network( );
208
209     /* Set the title of the main window */
210     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
211                           VOUT_TITLE " (Gnome interface)");
212
213     /* Accept file drops on the main window */
214     gtk_drag_dest_set( GTK_WIDGET( p_intf->p_sys->p_window ),
215                        GTK_DEST_DEFAULT_ALL, target_table,
216                        1, GDK_ACTION_COPY );
217
218     /* Get the interface labels */
219     #define P_LABEL( name ) GTK_LABEL( gtk_object_get_data( \
220                          GTK_OBJECT( p_intf->p_sys->p_window ), name ) )
221     p_intf->p_sys->p_label_date = P_LABEL( "label_date" );
222     p_intf->p_sys->p_label_status = P_LABEL( "label_status" );
223     p_intf->p_sys->p_label_title = P_LABEL( "label_title" );
224     p_intf->p_sys->p_label_chapter = P_LABEL( "label_chapter" );
225     #undef P_LABEL
226
227     /* Connect the date display to the slider */
228     #define P_SLIDER GTK_RANGE( gtk_object_get_data( \
229                          GTK_OBJECT( p_intf->p_sys->p_window ), "slider" ) )
230     p_intf->p_sys->p_adj = gtk_range_get_adjustment( P_SLIDER );
231
232     gtk_signal_connect ( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
233                          GTK_SIGNAL_FUNC( GnomeDisplayDate ), NULL );
234     p_intf->p_sys->f_adj_oldvalue = 0;
235     #undef P_SLIDER
236
237     /* We don't create these ones yet because we perhaps won't need them */
238     p_intf->p_sys->p_about = NULL;
239     p_intf->p_sys->p_playlist = NULL;
240     p_intf->p_sys->p_modules = NULL;
241     p_intf->p_sys->p_fileopen = NULL;
242
243     /* Store p_intf to keep an eye on it */
244     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
245                          "p_intf", p_intf );
246
247     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_popup),
248                          "p_intf", p_intf );
249
250     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_disc),
251                          "p_intf", p_intf );
252
253     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_network),
254                          "p_intf", p_intf );
255
256     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_adj),
257                          "p_intf", p_intf );
258
259     /* Show the control window */
260     gtk_widget_show( p_intf->p_sys->p_window );
261
262     /* Sleep to avoid using all CPU - since some interfaces needs to access
263      * keyboard events, a 100ms delay is a good compromise */
264     i_timeout = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, GnomeManage, p_intf );
265
266     /* Enter gnome mode */
267     gtk_main();
268
269     /* Remove the timeout */
270     gtk_timeout_remove( i_timeout );
271
272     /* Get rid of stored callbacks so we can unload the plugin */
273     if( p_intf->p_sys->pf_gtk_callback != NULL )
274     {
275         p_intf->p_sys->pf_gtk_callback( );
276         p_intf->p_sys->pf_gtk_callback = NULL;
277
278     }
279
280     if( p_intf->p_sys->pf_gdk_callback != NULL )
281     {
282         p_intf->p_sys->pf_gdk_callback( );
283         p_intf->p_sys->pf_gdk_callback = NULL;
284     }
285 }
286
287 /* following functions are local */
288
289 /*****************************************************************************
290  * GnomeManage: manage main thread messages
291  *****************************************************************************
292  * In this function, called approx. 10 times a second, we check what the
293  * main program wanted to tell us.
294  *****************************************************************************/
295 static gint GnomeManage( gpointer p_data )
296 {
297 #define p_intf ((intf_thread_t *)p_data)
298
299     vlc_mutex_lock( &p_intf->change_lock );
300
301     /* If the "display popup" flag has changed */
302     if( p_intf->b_menu_change )
303     {
304         gnome_popup_menu_do_popup( p_intf->p_sys->p_popup,
305                                    NULL, NULL, NULL, NULL );
306         p_intf->b_menu_change = 0;
307     }
308
309     if( p_intf->p_sys->b_mode_changed )
310     {
311         /* Sets the interface mode according to playlist item */
312         if( p_main->p_playlist->p_item != NULL )
313         {
314             if( !strncmp( p_main->p_playlist->p_item->psz_name, "dvd:", 4 ) )
315             {
316                 p_intf->p_sys->i_intf_mode = DVD_MODE;
317             }
318             else if( !strncmp(
319                         p_main->p_playlist->p_item->psz_name, "ts:", 4 ) )
320             {
321                 p_intf->p_sys->i_intf_mode = NET_MODE;
322             }
323         }
324
325         switch( p_intf->p_sys->i_intf_mode )
326         {
327             case DVD_MODE:
328                 GnomeDVDModeManage( p_intf );
329                 break;
330             case NET_MODE:
331                 GnomeNetworkModeManage( p_intf );
332                 break;
333             case FILE_MODE:
334             default:
335                 GnomeFileModeManage( p_intf );
336                 break;
337         }
338
339         p_intf->p_sys->b_mode_changed = 0;
340     }
341
342
343     if( p_intf->p_input != NULL )
344     {
345         float           newvalue;
346         char            psz_title[3];
347         char            psz_chapter[3];
348
349 #define p_area p_intf->p_input->stream.p_selected_area
350         /* Update language/chapter menus after user request */
351         if( ( p_intf->p_sys->b_menus_update ) ||
352             ( p_intf->p_sys->i_part != p_area->i_part ) )
353         {
354             p_intf->p_sys->b_menus_update = 1;
355             GnomeSetupMenu( p_intf );
356             p_intf->p_sys->b_menus_update = 0;
357
358             snprintf( psz_title, 3, "%02d", p_area->i_id );
359             gtk_label_set_text( p_intf->p_sys->p_label_title, psz_title );
360
361             p_intf->p_sys->i_part = p_area->i_part;
362             snprintf( psz_chapter, 3, "%02d", p_area->i_part );
363             gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
364         }
365
366         /* Manage the slider */
367         newvalue = p_intf->p_sys->p_adj->value;
368
369         /* If the user hasn't touched the slider since the last time,
370          * then the input can safely change it */
371         if( newvalue == p_intf->p_sys->f_adj_oldvalue )
372         {
373             /* Update the value */
374             p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue =
375                 ( 100. * p_area->i_tell ) / p_area->i_size;
376
377             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
378                                      "value_changed" );
379         }
380         /* Otherwise, send message to the input if the user has
381          * finished dragging the slider */
382         else if( p_intf->p_sys->b_slider_free )
383         {
384             off_t i_seek = ( newvalue * p_area->i_size ) / 100;
385
386             input_Seek( p_intf->p_input, i_seek );
387
388             /* Update the old value */
389             p_intf->p_sys->f_adj_oldvalue = newvalue;
390         }
391 #undef p_area
392     }
393
394     /* Manage core vlc functions through the callback */
395     p_intf->pf_manage( p_intf );
396
397     if( p_intf->b_die )
398     {
399         vlc_mutex_unlock( &p_intf->change_lock );
400
401         /* Prepare to die, young Skywalker */
402         gtk_main_quit();
403
404         /* Just in case */
405         return( FALSE );
406     }
407
408     vlc_mutex_unlock( &p_intf->change_lock );
409
410     return( TRUE );
411
412 #undef p_intf
413 }
414
415 /*****************************************************************************
416  * GnomeLanguageMenus: update interactive menus of the interface
417  *****************************************************************************
418  * Sets up menus with information from input:
419  *  -languages
420  *  -sub-pictures
421  * Warning: since this function is designed to be called by management
422  * function, the interface lock has to be taken
423  *****************************************************************************/
424 static gint GnomeLanguageMenus( gpointer          p_data,
425                                 GtkWidget *       p_root,
426                                 es_descriptor_t * p_es,
427                                 gint              i_cat,
428                           void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
429 {
430     intf_thread_t *     p_intf;
431     GtkWidget *         p_menu;
432     GtkWidget *         p_separator;
433     GtkWidget *         p_item;
434     GtkWidget *         p_item_active;
435     GSList *            p_group;
436     char *              psz_name;
437     gint                i_item;
438     gint                i;
439
440     
441
442     /* cast */
443     p_intf = (intf_thread_t *)p_data;
444
445     /* removes previous menu */
446     gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
447     gtk_widget_set_sensitive( p_root, FALSE );
448
449     p_group = NULL;
450
451     /* menu container */
452     p_menu = gtk_menu_new();
453
454     /* special case for "off" item */
455     psz_name = "Off";
456
457     p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
458     p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
459
460     gtk_widget_show( p_item );
461
462     /* signal hanling for off */
463     gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
464                         GTK_SIGNAL_FUNC ( pf_toggle ), NULL );
465
466     gtk_menu_append( GTK_MENU( p_menu ), p_item );
467
468     p_separator = gtk_menu_item_new();
469     gtk_widget_set_sensitive( p_separator, FALSE );
470     gtk_widget_show( p_separator );
471     gtk_menu_append( GTK_MENU( p_menu ), p_separator );
472
473     vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
474     p_item_active = NULL;
475     i_item = 0;
476
477     /* create a set of language buttons and append them to the container */
478     for( i = 0 ; i < p_intf->p_input->stream.i_es_number ; i++ )
479     {
480         if( p_intf->p_input->stream.pp_es[i]->i_cat == i_cat )
481         {
482             i_item++;
483             psz_name = p_intf->p_input->stream.pp_es[i]->psz_desc;
484             if( psz_name[0] == '\0' )
485             {
486                 sprintf( psz_name, "Language %d", i_item );
487             }
488
489             p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
490             p_group =
491                 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
492
493             if( p_es == p_intf->p_input->stream.pp_es[i] )
494             {
495                 /* don't lose p_item when we append into menu */
496                 p_item_active = p_item;
497             }
498
499             gtk_widget_show( p_item );
500
501             /* setup signal hanling */
502             gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
503                             GTK_SIGNAL_FUNC( pf_toggle ),
504                             (gpointer)( p_intf->p_input->stream.pp_es[i] ) );
505
506             gtk_menu_append( GTK_MENU( p_menu ), p_item );
507         }
508     }
509
510     vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
511
512     /* link the new menu to the menubar item */
513     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
514
515     /* acitvation will call signals so we can only do it
516      * when submenu is attached to menu - to get intf_window */
517     if( p_item_active != NULL )
518     {
519         gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
520                                         TRUE );
521     }
522
523     /* be sure that menu is sensitive if non empty */
524     if( i_item > 0 )
525     {
526         gtk_widget_set_sensitive( p_root, TRUE );
527     }
528
529     return TRUE;
530 }
531
532 /*****************************************************************************
533  * GnomeChapterMenu: generate chapter menu for current title
534  *****************************************************************************/
535 static gint GnomeChapterMenu( gpointer p_data, GtkWidget * p_chapter,
536                         void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
537 {
538     intf_thread_t *     p_intf;
539     char                psz_name[10];
540     GtkWidget *         p_chapter_menu;
541     GtkWidget *         p_chapter_submenu;
542     GtkWidget *         p_menu_item;
543     GtkWidget *         p_item;
544     GtkWidget *         p_item_selected;
545     GSList *            p_chapter_group;
546     gint                i_title;
547     gint                i_chapter;
548     gint                i_nb;
549
550     /* cast */
551     p_intf = (intf_thread_t*)p_data;
552
553     /* removes previous menu */
554     gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_chapter ) );
555     gtk_widget_set_sensitive( p_chapter, FALSE );
556
557     p_chapter_submenu = NULL;
558     p_chapter_group = NULL;
559     p_item_selected = NULL;
560     p_menu_item = NULL;
561
562     i_title = p_intf->p_input->stream.p_selected_area->i_id;
563     p_chapter_menu = gtk_menu_new();
564     i_nb = p_intf->p_input->stream.pp_areas[i_title]->i_part_nb;
565
566     for( i_chapter = 0 ; i_chapter < i_nb ; i_chapter++ )
567     {
568         /* we group chapters in packets of ten for small screens */
569         if( ( i_chapter % 10 == 0 ) && ( i_nb > 20 ) )
570         {
571             if( i_chapter != 0 )
572             {
573                 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_menu_item ),
574                                            p_chapter_submenu );
575                 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_menu_item );
576             }
577
578             sprintf( psz_name, "%d - %d", i_chapter + 1, i_chapter + 10);
579             p_menu_item = gtk_menu_item_new_with_label( psz_name );
580             gtk_widget_show( p_menu_item );
581             p_chapter_submenu = gtk_menu_new();
582         }
583
584         sprintf( psz_name, "Chapter %d", i_chapter + 1 );
585
586         p_item = gtk_radio_menu_item_new_with_label( p_chapter_group,
587                                                      psz_name );
588         p_chapter_group =
589             gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
590
591         if( p_intf->p_input->stream.pp_areas[i_title]->i_part
592                      == i_chapter + 1 )
593         {
594             p_item_selected = p_item;
595         }
596         
597         gtk_widget_show( p_item );
598
599         /* setup signal hanling */
600         gtk_signal_connect( GTK_OBJECT( p_item ),
601                         "toggled",
602                         GTK_SIGNAL_FUNC( pf_toggle ),
603                         (gpointer)(i_chapter + 1) );
604
605         if( i_nb > 20 )
606         {
607             gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
608         }
609         else
610         {
611             gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
612         }
613     }
614
615     if( i_nb > 20 )
616     {
617         gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_menu_item ),
618                                    p_chapter_submenu );
619         gtk_menu_append( GTK_MENU( p_chapter_menu ), p_menu_item );
620     }
621
622     /* link the new menu to the title menu item */
623     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter ),
624                                p_chapter_menu );
625
626     /* toggle currently selected chapter */
627     if( p_item_selected != NULL )
628     {
629         gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_selected ),
630                                         TRUE );
631     }
632
633     /* be sure that chapter menu is sensitive, if there are several items */
634     if( p_intf->p_input->stream.pp_areas[i_title]->i_part_nb > 1 )
635     {
636         gtk_widget_set_sensitive( p_chapter, TRUE );
637     }
638
639     return TRUE;
640 }
641
642 /*****************************************************************************
643  * GnomeTitleMenu: sets menus for titles and chapters selection
644  *****************************************************************************
645  * Generates two types of menus:
646  *  -simple list of titles
647  *  -cascaded lists of chapters for each title
648  *****************************************************************************/
649 static gint GnomeTitleMenu( gpointer       p_data,
650                             GtkWidget *    p_navigation, 
651                             void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
652 {
653     intf_thread_t *     p_intf;
654     char                psz_name[10];
655     GtkWidget *         p_title_menu;
656     GtkWidget *         p_title_submenu;
657     GtkWidget *         p_title_item;
658     GtkWidget *         p_item_active;
659     GtkWidget *         p_chapter_menu;
660     GtkWidget *         p_chapter_submenu;
661     GtkWidget *         p_title_menu_item;
662     GtkWidget *         p_chapter_menu_item;
663     GtkWidget *         p_item;
664     GSList *            p_title_group;
665     GSList *            p_chapter_group;
666     gint                i_title;
667     gint                i_chapter;
668     gint                i_title_nb;
669     gint                i_chapter_nb;
670
671     /* cast */
672     p_intf = (intf_thread_t*)p_data;
673
674     p_title_menu = gtk_menu_new();
675     p_title_group = NULL;
676     p_title_submenu = NULL;
677     p_title_menu_item = NULL;
678     p_chapter_group = NULL;
679     p_chapter_submenu = NULL;
680     p_chapter_menu_item = NULL;
681     p_item_active = NULL;
682     i_title_nb = p_intf->p_input->stream.i_area_nb;
683
684     /* loop on titles */
685     for( i_title = 1 ; i_title < i_title_nb ; i_title++ )
686     {
687         /* we group titles in packets of ten for small screens */
688         if( ( i_title % 10 == 1 ) && ( i_title_nb > 20 ) )
689         {
690             if( i_title != 1 )
691             {
692                 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
693                                            p_title_submenu );
694                 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
695             }
696
697             sprintf( psz_name, "%d - %d", i_title, i_title + 9 );
698             p_title_menu_item = gtk_menu_item_new_with_label( psz_name );
699             gtk_widget_show( p_title_menu_item );
700             p_title_submenu = gtk_menu_new();
701         }
702
703         sprintf( psz_name, "Title %d", i_title );
704
705         if( pf_toggle == on_menubar_title_toggle )
706         {
707             p_title_item = gtk_radio_menu_item_new_with_label( p_title_group,
708                                                            psz_name );
709             p_title_group =
710               gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_title_item ) );
711
712             if( p_intf->p_input->stream.pp_areas[i_title] ==
713                          p_intf->p_input->stream.p_selected_area )
714             {
715                 p_item_active = p_title_item;
716             }
717
718             /* setup signal hanling */
719             gtk_signal_connect( GTK_OBJECT( p_title_item ),
720                      "toggled",
721                      GTK_SIGNAL_FUNC( pf_toggle ),
722                      (gpointer)(p_intf->p_input->stream.pp_areas[i_title]) );
723
724             if( p_intf->p_input->stream.i_area_nb > 1 )
725             {
726                 /* be sure that menu is sensitive */
727                 gtk_widget_set_sensitive( p_navigation, TRUE );
728             }
729         }
730         else
731         {
732     
733             p_title_item = gtk_menu_item_new_with_label( psz_name );
734             p_chapter_menu = gtk_menu_new();
735             i_chapter_nb =
736                     p_intf->p_input->stream.pp_areas[i_title]->i_part_nb;
737     
738             for( i_chapter = 0 ; i_chapter < i_chapter_nb ; i_chapter++ )
739             {
740                 /* we group chapters in packets of ten for small screens */
741                 if( ( i_chapter % 10 == 0 ) && ( i_chapter_nb > 20 ) )
742                 {
743                     if( i_chapter != 0 )
744                     {
745                         gtk_menu_item_set_submenu(
746                                     GTK_MENU_ITEM( p_chapter_menu_item ),
747                                     p_chapter_submenu );
748                         gtk_menu_append( GTK_MENU( p_chapter_menu ),
749                                          p_chapter_menu_item );
750                     }
751
752                     sprintf( psz_name, "%d - %d", i_chapter + 1,
753                                                   i_chapter + 10);
754                     p_chapter_menu_item =
755                             gtk_menu_item_new_with_label( psz_name );
756                     gtk_widget_show( p_chapter_menu_item );
757                     p_chapter_submenu = gtk_menu_new();
758                 }
759
760                 sprintf( psz_name, "Chapter %d", i_chapter + 1 );
761     
762                 p_item = gtk_radio_menu_item_new_with_label(
763                                                 p_chapter_group, psz_name );
764                 p_chapter_group = gtk_radio_menu_item_group(
765                                                 GTK_RADIO_MENU_ITEM( p_item ) );
766                 gtk_widget_show( p_item );
767
768 #define p_area p_intf->p_input->stream.pp_areas[i_title]
769                 if( ( p_area == p_intf->p_input->stream.p_selected_area ) &&
770                     ( p_area->i_part == i_chapter + 1 ) )
771                 {
772                     p_item_active = p_item;
773                 }
774 #undef p_area
775
776                 /* setup signal hanling */
777                 gtk_signal_connect( GTK_OBJECT( p_item ),
778                            "toggled",
779                            GTK_SIGNAL_FUNC( pf_toggle ),
780                            (gpointer)( ( i_title * 100 ) + ( i_chapter + 1) ) );
781
782                 if( i_chapter_nb > 20 )
783                 {
784                     gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
785                 }
786                 else
787                 {
788                     gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
789                 }
790             }
791
792             if( i_chapter_nb > 20 )
793             {
794                 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter_menu_item ),
795                                            p_chapter_submenu );
796                 gtk_menu_append( GTK_MENU( p_chapter_menu ),
797                                  p_chapter_menu_item );
798             }
799
800             /* link the new menu to the title menu item */
801             gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
802                                        p_chapter_menu );
803
804             if( p_intf->p_input->stream.pp_areas[i_title]->i_part_nb > 1 )
805             {
806                 /* be sure that menu is sensitive */
807                 gtk_widget_set_sensitive( p_navigation, TRUE );
808             }
809         }
810         gtk_widget_show( p_title_item );
811
812         if( i_title_nb > 20 )
813         {
814             gtk_menu_append( GTK_MENU( p_title_submenu ), p_title_item );
815         }
816         else
817         {
818             gtk_menu_append( GTK_MENU( p_title_menu ), p_title_item );
819         }
820     }
821
822     if( i_title_nb > 20 )
823     {
824         gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
825                                    p_title_submenu );
826         gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
827     }
828
829     /* be sure that menu is sensitive */
830     gtk_widget_set_sensitive( p_title_menu, TRUE );
831
832     /* link the new menu to the menubar item */
833     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
834
835     if( p_item_active != NULL )
836     {
837         gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
838                                         TRUE );
839     }
840
841
842     return TRUE;
843 }
844
845 /*****************************************************************************
846  * GnomeSetupMenu: function that generates title/chapter/audio/subpic
847  * menus with help from preceding functions
848  *****************************************************************************/
849 static gint GnomeSetupMenu( intf_thread_t * p_intf )
850 {
851     es_descriptor_t *   p_audio_es;
852     es_descriptor_t *   p_spu_es;
853     GtkWidget *         p_menubar_menu;
854     GtkWidget *         p_popup_menu;
855     gint                i;
856
857     if( p_intf->p_input->stream.i_area_nb > 1 )
858     {
859         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
860                             p_intf->p_sys->p_window ), "menubar_title" ) );
861         GnomeTitleMenu( p_intf, p_menubar_menu, on_menubar_title_toggle );
862
863         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
864                              p_intf->p_sys->p_popup ), "popup_navigation" ) );
865         GnomeTitleMenu( p_intf, p_popup_menu, on_popup_navigation_toggle );
866     
867         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
868                              p_intf->p_sys->p_window ), "menubar_chapter" ) );
869         GnomeChapterMenu( p_intf, p_menubar_menu, on_menubar_chapter_toggle );
870     }
871
872     /* look for selected ES */
873     p_audio_es = NULL;
874     p_spu_es = NULL;
875
876     for( i = 0 ; i < p_intf->p_input->stream.i_selected_es_number ; i++ )
877     {
878         if( p_intf->p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
879         {
880             p_audio_es = p_intf->p_input->stream.pp_selected_es[i];
881         }
882
883         if( p_intf->p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
884         {
885             p_spu_es = p_intf->p_input->stream.pp_selected_es[i];
886         }
887     }
888
889     /* audio menus */
890
891     /* find audio root menu */
892     p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
893                          p_intf->p_sys->p_window ), "menubar_audio" ) );
894
895     p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
896                  p_intf->p_sys->p_popup ), "popup_audio" ) );
897
898     GnomeLanguageMenus( p_intf, p_menubar_menu, p_audio_es, AUDIO_ES,
899                         on_menubar_audio_toggle );
900     GnomeLanguageMenus( p_intf, p_popup_menu, p_audio_es, AUDIO_ES,
901                         on_popup_audio_toggle );
902
903     /* sub picture menus */
904
905     /* find spu root menu */
906     p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
907                       p_intf->p_sys->p_window ), "menubar_subtitle" ) );
908
909     p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
910                  p_intf->p_sys->p_popup ), "popup_subtitle" ) );
911
912     GnomeLanguageMenus( p_intf, p_menubar_menu, p_spu_es, SPU_ES,
913                         on_menubar_subtitle_toggle  );
914     GnomeLanguageMenus( p_intf, p_popup_menu, p_spu_es, SPU_ES,
915                         on_popup_subtitle_toggle );
916
917     return TRUE;
918 }
919
920 /*****************************************************************************
921  * GnomeDisplayDate: display stream date
922  *****************************************************************************
923  * This function displays the current date related to the position in
924  * the stream. It is called whenever the slider changes its value.
925  *****************************************************************************/
926 void GnomeDisplayDate( GtkAdjustment *p_adj )
927 {
928     intf_thread_t *p_intf;
929    
930     p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
931
932     if( p_intf->p_input != NULL )
933     {
934 #define p_area p_intf->p_input->stream.p_selected_area
935         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
936
937         vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
938
939         gtk_label_set_text( p_intf->p_sys->p_label_date,
940                             input_OffsetToTime( p_intf->p_input, psz_time,
941                                    ( p_area->i_size * p_adj->value ) / 100 ) );
942
943         vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
944 #undef p_area
945      }
946 }
947
948
949 /*****************************************************************************
950  * GnomeDVDModeManage
951  *****************************************************************************/
952 static gint GnomeDVDModeManage( intf_thread_t * p_intf )
953 {
954     GtkWidget *     p_dvd_box;
955     GtkWidget *     p_file_box;
956     GtkWidget *     p_network_box;
957
958     p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
959                  p_intf->p_sys->p_window ), "file_box" ) );
960     gtk_widget_hide( GTK_WIDGET( p_file_box ) );
961
962     p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
963                  p_intf->p_sys->p_window ), "network_box" ) );
964     gtk_widget_hide( GTK_WIDGET( p_network_box ) );
965
966     p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
967                  p_intf->p_sys->p_window ), "dvd_box" ) );
968     gtk_widget_show( GTK_WIDGET( p_dvd_box ) );
969
970     gtk_label_set_text( p_intf->p_sys->p_label_status,
971                         "Status: playing DVD" );
972
973     return TRUE;
974 }
975
976 /*****************************************************************************
977  * GnomeFileModeManage
978  *****************************************************************************/
979 static gint GnomeFileModeManage( intf_thread_t * p_intf )
980 {
981     GtkWidget *     p_dvd_box;
982     GtkWidget *     p_file_box;
983     GtkWidget *     p_network_box;
984
985     p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
986                  p_intf->p_sys->p_window ), "network_box" ) );
987     gtk_widget_hide( GTK_WIDGET( p_network_box ) );
988
989     p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
990                  p_intf->p_sys->p_window ), "dvd_box" ) );
991     gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
992
993     p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
994                  p_intf->p_sys->p_window ), "file_box" ) );
995     gtk_widget_show( GTK_WIDGET( p_file_box ) );
996
997     gtk_label_set_text( p_intf->p_sys->p_label_status,
998                         "Status: foo" );
999
1000     return TRUE;
1001 }
1002
1003 /*****************************************************************************
1004  * GnomeNetworkModeManage
1005  *****************************************************************************/
1006 static gint GnomeNetworkModeManage( intf_thread_t * p_intf )
1007 {
1008     GtkWidget *     p_dvd_box;
1009     GtkWidget *     p_file_box;
1010     GtkWidget *     p_network_box;
1011
1012     p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1013                  p_intf->p_sys->p_window ), "dvd_box" ) );
1014     gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
1015
1016     p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1017                  p_intf->p_sys->p_window ), "file_box" ) );
1018     gtk_widget_hide( GTK_WIDGET( p_file_box ) );
1019
1020     p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1021                  p_intf->p_sys->p_window ), "network_box" ) );
1022     gtk_widget_show( GTK_WIDGET( p_network_box ) );
1023
1024     gtk_label_set_text( p_intf->p_sys->p_label_status,
1025                         "Status: waiting for stream" );
1026
1027     return TRUE;
1028 }