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