1 /*****************************************************************************
2 * intf_gnome.c: Gnome interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: intf_gnome.c,v 1.31 2001/04/20 05:40:03 stef Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Stéphane Borel <stef@via.ecp.fr>
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.
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.
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 *****************************************************************************/
25 #define MODULE_NAME gnome
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
33 #include <errno.h> /* ENOMEM */
34 #include <stdlib.h> /* free() */
35 #include <string.h> /* strerror() */
47 #include "stream_control.h"
48 #include "input_ext-intf.h"
51 #include "interface.h"
52 #include "intf_playlist.h"
54 #include "gnome_callbacks.h"
55 #include "gnome_interface.h"
56 #include "gnome_support.h"
57 #include "intf_gnome.h"
61 /*****************************************************************************
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 );
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 GnomeDiscModeManage( intf_thread_t * p_intf );
79 static gint GnomeFileModeManage( intf_thread_t * p_intf );
80 static gint GnomeNetworkModeManage( intf_thread_t * p_intf );
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 )
92 intf_thread_t *p_intf = p_main->p_intf;
94 if( p_intf->p_sys->pf_gdk_callback == NULL )
96 p_intf->p_sys->pf_gdk_callback = func;
98 else if( p_intf->p_sys->pf_gtk_callback == NULL )
100 p_intf->p_sys->pf_gtk_callback = func;
102 /* else nothing, but we could do something here */
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 )
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;
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 )
126 if( TestMethod( INTF_METHOD_VAR, "gnome" ) )
131 if( TestProgram( "gnome-vlc" ) )
139 /*****************************************************************************
140 * intf_Open: initialize and create window
141 *****************************************************************************/
142 static int intf_Open( intf_thread_t *p_intf )
144 /* Allocate instance and initialize some members */
145 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
146 if( p_intf->p_sys == NULL )
148 intf_ErrMsg("error: %s", strerror(ENOMEM));
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_title_update = 1;
157 p_intf->p_sys->b_chapter_update = 1;
158 p_intf->p_sys->b_audio_update = 1;
159 p_intf->p_sys->b_spu_update = 1;
161 p_intf->p_sys->b_slider_free = 1;
163 p_intf->p_sys->b_mode_changed = 1;
164 p_intf->p_sys->i_intf_mode = FILE_MODE;
166 p_intf->p_sys->i_part = 0;
168 p_intf->p_sys->pf_gtk_callback = NULL;
169 p_intf->p_sys->pf_gdk_callback = NULL;
174 /*****************************************************************************
175 * intf_Close: destroy interface window
176 *****************************************************************************/
177 static void intf_Close( intf_thread_t *p_intf )
179 /* Destroy structure */
180 free( p_intf->p_sys );
183 /*****************************************************************************
184 * intf_Run: Gnome thread
185 *****************************************************************************
186 * this part of the interface is in a separate thread so that we can call
187 * gtk_main() from within it without annoying the rest of the program.
188 * XXX: the approach may look kludgy, and probably is, but I could not find
189 * a better way to dynamically load a Gnome interface at runtime.
190 *****************************************************************************/
191 static void intf_Run( intf_thread_t *p_intf )
193 /* gnome_init needs to know the command line. We don't care, so we
194 * give it an empty one */
195 char *p_args[] = { "" };
198 /* The data types we are allowed to receive */
199 static GtkTargetEntry target_table[] =
201 { "text/uri-list", 0, DROP_ACCEPT_TEXT_URI_LIST },
202 { "text/plain", 0, DROP_ACCEPT_TEXT_PLAIN }
205 /* intf_Manage callback timeout */
208 /* Initialize Gnome */
209 gnome_init( p_main->psz_arg0, VERSION, i_args, p_args );
211 /* Create some useful widgets that will certainly be used */
212 p_intf->p_sys->p_window = create_intf_window( );
213 p_intf->p_sys->p_popup = create_intf_popup( );
214 p_intf->p_sys->p_disc = create_intf_disc( );
215 p_intf->p_sys->p_network = create_intf_network( );
217 /* Set the title of the main window */
218 gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
219 VOUT_TITLE " (Gnome interface)");
221 /* Accept file drops on the main window */
222 gtk_drag_dest_set( GTK_WIDGET( p_intf->p_sys->p_window ),
223 GTK_DEST_DEFAULT_ALL, target_table,
224 1, GDK_ACTION_COPY );
226 /* Get the interface labels */
227 #define P_LABEL( name ) GTK_LABEL( gtk_object_get_data( \
228 GTK_OBJECT( p_intf->p_sys->p_window ), name ) )
229 p_intf->p_sys->p_label_date = P_LABEL( "label_date" );
230 p_intf->p_sys->p_label_status = P_LABEL( "label_status" );
231 p_intf->p_sys->p_label_title = P_LABEL( "label_title" );
232 p_intf->p_sys->p_label_chapter = P_LABEL( "label_chapter" );
235 /* Connect the date display to the slider */
236 #define P_SLIDER GTK_RANGE( gtk_object_get_data( \
237 GTK_OBJECT( p_intf->p_sys->p_window ), "slider" ) )
238 p_intf->p_sys->p_adj = gtk_range_get_adjustment( P_SLIDER );
240 gtk_signal_connect ( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
241 GTK_SIGNAL_FUNC( GnomeDisplayDate ), NULL );
242 p_intf->p_sys->f_adj_oldvalue = 0;
245 /* We don't create these ones yet because we perhaps won't need them */
246 p_intf->p_sys->p_about = NULL;
247 p_intf->p_sys->p_playlist = NULL;
248 p_intf->p_sys->p_modules = NULL;
249 p_intf->p_sys->p_fileopen = NULL;
251 /* Store p_intf to keep an eye on it */
252 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
255 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_popup),
258 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_disc),
261 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_network),
264 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_adj),
267 /* Show the control window */
268 gtk_widget_show( p_intf->p_sys->p_window );
270 /* Sleep to avoid using all CPU - since some interfaces needs to access
271 * keyboard events, a 100ms delay is a good compromise */
272 i_timeout = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, GnomeManage, p_intf );
274 /* Enter gnome mode */
277 /* Remove the timeout */
278 gtk_timeout_remove( i_timeout );
280 /* Get rid of stored callbacks so we can unload the plugin */
281 if( p_intf->p_sys->pf_gtk_callback != NULL )
283 p_intf->p_sys->pf_gtk_callback( );
284 p_intf->p_sys->pf_gtk_callback = NULL;
288 if( p_intf->p_sys->pf_gdk_callback != NULL )
290 p_intf->p_sys->pf_gdk_callback( );
291 p_intf->p_sys->pf_gdk_callback = NULL;
295 /* following functions are local */
297 /*****************************************************************************
298 * GnomeManage: manage main thread messages
299 *****************************************************************************
300 * In this function, called approx. 10 times a second, we check what the
301 * main program wanted to tell us.
302 *****************************************************************************/
303 static gint GnomeManage( gpointer p_data )
305 #define p_intf ((intf_thread_t *)p_data)
307 vlc_mutex_lock( &p_intf->change_lock );
309 /* If the "display popup" flag has changed */
310 if( p_intf->b_menu_change )
312 gnome_popup_menu_do_popup( p_intf->p_sys->p_popup,
313 NULL, NULL, NULL, NULL );
314 p_intf->b_menu_change = 0;
317 if( p_intf->p_input != NULL )
321 /* New input or stream map change */
322 if( p_intf->p_input->stream.b_changed || p_intf->p_sys->b_mode_changed )
324 switch( p_intf->p_input->stream.i_method & 0xf0 )
326 case INPUT_METHOD_FILE:
327 GnomeFileModeManage( p_intf );
329 case INPUT_METHOD_DISC:
330 GnomeDiscModeManage( p_intf );
332 case INPUT_METHOD_NETWORK:
333 GnomeNetworkModeManage( p_intf );
336 intf_ErrMsg( "intf error: can't determine input method" );
340 p_intf->p_input->stream.b_changed = 0;
341 p_intf->p_sys->b_mode_changed = 0;
343 "Interface menus refreshed as stream has changed" );
346 /* Update language/chapter menus after user request */
347 GnomeSetupMenu( p_intf );
349 #define p_area p_intf->p_input->stream.p_selected_area
350 /* Update menus when chapter changes */
351 p_intf->p_sys->b_chapter_update =
352 ( p_intf->p_sys->i_part != p_area->i_part );
354 if( p_intf->p_input->stream.b_seekable )
356 /* Manage the slider */
357 newvalue = p_intf->p_sys->p_adj->value;
359 /* If the user hasn't touched the slider since the last time,
360 * then the input can safely change it */
361 if( newvalue == p_intf->p_sys->f_adj_oldvalue )
363 /* Update the value */
364 p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue =
365 ( 100. * p_area->i_tell ) / p_area->i_size;
367 gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
370 /* Otherwise, send message to the input if the user has
371 * finished dragging the slider */
372 else if( p_intf->p_sys->b_slider_free )
374 off_t i_seek = ( newvalue * p_area->i_size ) / 100;
376 input_Seek( p_intf->p_input, i_seek );
378 /* Update the old value */
379 p_intf->p_sys->f_adj_oldvalue = newvalue;
385 /* Manage core vlc functions through the callback */
386 p_intf->pf_manage( p_intf );
390 vlc_mutex_unlock( &p_intf->change_lock );
392 /* Prepare to die, young Skywalker */
399 vlc_mutex_unlock( &p_intf->change_lock );
406 /*****************************************************************************
407 * GnomeLanguageMenus: update interactive menus of the interface
408 *****************************************************************************
409 * Sets up menus with information from input:
412 * Warning: since this function is designed to be called by management
413 * function, the interface lock has to be taken
414 *****************************************************************************/
415 static gint GnomeLanguageMenus( gpointer p_data,
417 es_descriptor_t * p_es,
419 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
421 intf_thread_t * p_intf;
423 GtkWidget * p_separator;
425 GtkWidget * p_item_active;
434 p_intf = (intf_thread_t *)p_data;
436 /* removes previous menu */
437 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
438 gtk_widget_set_sensitive( p_root, FALSE );
443 p_menu = gtk_menu_new();
445 /* special case for "off" item */
448 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
449 p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
451 gtk_widget_show( p_item );
453 /* signal hanling for off */
454 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
455 GTK_SIGNAL_FUNC ( pf_toggle ), NULL );
457 gtk_menu_append( GTK_MENU( p_menu ), p_item );
459 p_separator = gtk_menu_item_new();
460 gtk_widget_set_sensitive( p_separator, FALSE );
461 gtk_widget_show( p_separator );
462 gtk_menu_append( GTK_MENU( p_menu ), p_separator );
464 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
465 p_item_active = NULL;
468 /* create a set of language buttons and append them to the container */
469 for( i = 0 ; i < p_intf->p_input->stream.i_es_number ; i++ )
471 if( p_intf->p_input->stream.pp_es[i]->i_cat == i_cat )
474 psz_name = p_intf->p_input->stream.pp_es[i]->psz_desc;
475 if( psz_name[0] == '\0' )
477 sprintf( psz_name, "Language %d", i_item );
480 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
482 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
484 if( p_es == p_intf->p_input->stream.pp_es[i] )
486 /* don't lose p_item when we append into menu */
487 p_item_active = p_item;
490 gtk_widget_show( p_item );
492 /* setup signal hanling */
493 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
494 GTK_SIGNAL_FUNC( pf_toggle ),
495 (gpointer)( p_intf->p_input->stream.pp_es[i] ) );
497 gtk_menu_append( GTK_MENU( p_menu ), p_item );
501 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
503 /* link the new menu to the menubar item */
504 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
506 /* acitvation will call signals so we can only do it
507 * when submenu is attached to menu - to get intf_window */
508 if( p_item_active != NULL )
510 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
514 /* be sure that menu is sensitive if non empty */
517 gtk_widget_set_sensitive( p_root, TRUE );
523 /*****************************************************************************
524 * GnomeChapterMenu: generate chapter menu for current title
525 *****************************************************************************/
526 static gint GnomeChapterMenu( gpointer p_data, GtkWidget * p_chapter,
527 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
529 intf_thread_t * p_intf;
531 GtkWidget * p_chapter_menu;
532 GtkWidget * p_chapter_submenu;
533 GtkWidget * p_menu_item;
535 GtkWidget * p_item_selected;
536 GSList * p_chapter_group;
542 p_intf = (intf_thread_t*)p_data;
544 /* removes previous menu */
545 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_chapter ) );
546 gtk_widget_set_sensitive( p_chapter, FALSE );
548 p_chapter_submenu = NULL;
549 p_chapter_group = NULL;
550 p_item_selected = NULL;
553 i_title = p_intf->p_input->stream.p_selected_area->i_id;
554 p_chapter_menu = gtk_menu_new();
555 i_nb = p_intf->p_input->stream.pp_areas[i_title]->i_part_nb;
557 for( i_chapter = 0 ; i_chapter < i_nb ; i_chapter++ )
559 /* we group chapters in packets of ten for small screens */
560 if( ( i_chapter % 10 == 0 ) && ( i_nb > 20 ) )
564 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_menu_item ),
566 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_menu_item );
569 sprintf( psz_name, "%d - %d", i_chapter + 1, i_chapter + 10);
570 p_menu_item = gtk_menu_item_new_with_label( psz_name );
571 gtk_widget_show( p_menu_item );
572 p_chapter_submenu = gtk_menu_new();
575 sprintf( psz_name, "Chapter %d", i_chapter + 1 );
577 p_item = gtk_radio_menu_item_new_with_label( p_chapter_group,
580 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
582 if( p_intf->p_input->stream.pp_areas[i_title]->i_part
585 p_item_selected = p_item;
588 gtk_widget_show( p_item );
590 /* setup signal hanling */
591 gtk_signal_connect( GTK_OBJECT( p_item ),
593 GTK_SIGNAL_FUNC( pf_toggle ),
594 (gpointer)(i_chapter + 1) );
598 gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
602 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
608 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_menu_item ),
610 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_menu_item );
613 /* link the new menu to the title menu item */
614 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter ),
617 /* toggle currently selected chapter */
618 if( p_item_selected != NULL )
620 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_selected ),
624 /* be sure that chapter menu is sensitive, if there are several items */
625 if( p_intf->p_input->stream.pp_areas[i_title]->i_part_nb > 1 )
627 gtk_widget_set_sensitive( p_chapter, TRUE );
633 /*****************************************************************************
634 * GnomeTitleMenu: sets menus for titles and chapters selection
635 *****************************************************************************
636 * Generates two types of menus:
637 * -simple list of titles
638 * -cascaded lists of chapters for each title
639 *****************************************************************************/
640 static gint GnomeTitleMenu( gpointer p_data,
641 GtkWidget * p_navigation,
642 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
644 intf_thread_t * p_intf;
646 GtkWidget * p_title_menu;
647 GtkWidget * p_title_submenu;
648 GtkWidget * p_title_item;
649 GtkWidget * p_item_active;
650 GtkWidget * p_chapter_menu;
651 GtkWidget * p_chapter_submenu;
652 GtkWidget * p_title_menu_item;
653 GtkWidget * p_chapter_menu_item;
655 GSList * p_title_group;
656 GSList * p_chapter_group;
663 p_intf = (intf_thread_t*)p_data;
665 p_title_menu = gtk_menu_new();
666 p_title_group = NULL;
667 p_title_submenu = NULL;
668 p_title_menu_item = NULL;
669 p_chapter_group = NULL;
670 p_chapter_submenu = NULL;
671 p_chapter_menu_item = NULL;
672 p_item_active = NULL;
673 i_title_nb = p_intf->p_input->stream.i_area_nb;
676 for( i_title = 1 ; i_title < i_title_nb ; i_title++ )
678 /* we group titles in packets of ten for small screens */
679 if( ( i_title % 10 == 1 ) && ( i_title_nb > 20 ) )
683 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
685 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
688 sprintf( psz_name, "%d - %d", i_title, i_title + 9 );
689 p_title_menu_item = gtk_menu_item_new_with_label( psz_name );
690 gtk_widget_show( p_title_menu_item );
691 p_title_submenu = gtk_menu_new();
694 sprintf( psz_name, "Title %d (%d)", i_title, p_intf->p_input->stream.pp_areas[i_title]->i_part_nb );
696 if( pf_toggle == on_menubar_title_toggle )
698 p_title_item = gtk_radio_menu_item_new_with_label( p_title_group,
701 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_title_item ) );
703 if( p_intf->p_input->stream.pp_areas[i_title] ==
704 p_intf->p_input->stream.p_selected_area )
706 p_item_active = p_title_item;
709 /* setup signal hanling */
710 gtk_signal_connect( GTK_OBJECT( p_title_item ),
712 GTK_SIGNAL_FUNC( pf_toggle ),
713 (gpointer)(p_intf->p_input->stream.pp_areas[i_title]) );
715 if( p_intf->p_input->stream.i_area_nb > 1 )
717 /* be sure that menu is sensitive */
718 gtk_widget_set_sensitive( p_navigation, TRUE );
724 p_title_item = gtk_menu_item_new_with_label( psz_name );
725 p_chapter_menu = gtk_menu_new();
727 p_intf->p_input->stream.pp_areas[i_title]->i_part_nb;
729 for( i_chapter = 0 ; i_chapter < i_chapter_nb ; i_chapter++ )
731 /* we group chapters in packets of ten for small screens */
732 if( ( i_chapter % 10 == 0 ) && ( i_chapter_nb > 20 ) )
736 gtk_menu_item_set_submenu(
737 GTK_MENU_ITEM( p_chapter_menu_item ),
739 gtk_menu_append( GTK_MENU( p_chapter_menu ),
740 p_chapter_menu_item );
743 sprintf( psz_name, "%d - %d", i_chapter + 1,
745 p_chapter_menu_item =
746 gtk_menu_item_new_with_label( psz_name );
747 gtk_widget_show( p_chapter_menu_item );
748 p_chapter_submenu = gtk_menu_new();
751 sprintf( psz_name, "Chapter %d", i_chapter + 1 );
753 p_item = gtk_radio_menu_item_new_with_label(
754 p_chapter_group, psz_name );
755 p_chapter_group = gtk_radio_menu_item_group(
756 GTK_RADIO_MENU_ITEM( p_item ) );
757 gtk_widget_show( p_item );
759 #define p_area p_intf->p_input->stream.pp_areas[i_title]
760 if( ( p_area == p_intf->p_input->stream.p_selected_area ) &&
761 ( p_area->i_part == i_chapter + 1 ) )
763 p_item_active = p_item;
767 /* setup signal hanling */
768 gtk_signal_connect( GTK_OBJECT( p_item ),
770 GTK_SIGNAL_FUNC( pf_toggle ),
771 (gpointer)( ( i_title * 100 ) + ( i_chapter + 1) ) );
773 if( i_chapter_nb > 20 )
775 gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
779 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
783 if( i_chapter_nb > 20 )
785 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter_menu_item ),
787 gtk_menu_append( GTK_MENU( p_chapter_menu ),
788 p_chapter_menu_item );
791 /* link the new menu to the title menu item */
792 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
795 if( p_intf->p_input->stream.pp_areas[i_title]->i_part_nb > 1 )
797 /* be sure that menu is sensitive */
798 gtk_widget_set_sensitive( p_navigation, TRUE );
801 gtk_widget_show( p_title_item );
803 if( i_title_nb > 20 )
805 gtk_menu_append( GTK_MENU( p_title_submenu ), p_title_item );
809 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_item );
813 if( i_title_nb > 20 )
815 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
817 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
820 /* be sure that menu is sensitive */
821 gtk_widget_set_sensitive( p_title_menu, TRUE );
823 /* link the new menu to the menubar item */
824 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
826 if( p_item_active != NULL )
828 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
836 /*****************************************************************************
837 * GnomeSetupMenu: function that generates title/chapter/audio/subpic
838 * menus with help from preceding functions
839 *****************************************************************************/
840 static gint GnomeSetupMenu( intf_thread_t * p_intf )
842 es_descriptor_t * p_audio_es;
843 es_descriptor_t * p_spu_es;
844 GtkWidget * p_menubar_menu;
845 GtkWidget * p_popup_menu;
848 p_intf->p_sys->b_title_update &= ( p_intf->p_input->stream.i_area_nb > 1 );
849 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
850 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update;
851 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update;
853 if( p_intf->p_sys->b_title_update )
857 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
858 p_intf->p_sys->p_window ), "menubar_title" ) );
859 GnomeTitleMenu( p_intf, p_menubar_menu, on_menubar_title_toggle );
861 snprintf( psz_title, 3, "%02d",
862 p_intf->p_input->stream.p_selected_area->i_id );
863 gtk_label_set_text( p_intf->p_sys->p_label_title, psz_title );
865 p_intf->p_sys->b_title_update = 0;
868 if( p_intf->p_sys->b_chapter_update )
872 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
873 p_intf->p_sys->p_popup ), "popup_navigation" ) );
874 GnomeTitleMenu( p_intf, p_popup_menu, on_popup_navigation_toggle );
876 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
877 p_intf->p_sys->p_window ), "menubar_chapter" ) );
878 GnomeChapterMenu( p_intf, p_menubar_menu, on_menubar_chapter_toggle );
880 snprintf( psz_chapter, 3, "%02d",
881 p_intf->p_input->stream.p_selected_area->i_part );
882 gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
884 p_intf->p_sys->i_part =
885 p_intf->p_input->stream.p_selected_area->i_part;
886 p_intf->p_sys->b_chapter_update = 0;
889 /* look for selected ES */
893 for( i = 0 ; i < p_intf->p_input->stream.i_selected_es_number ; i++ )
895 if( p_intf->p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
897 p_audio_es = p_intf->p_input->stream.pp_selected_es[i];
900 if( p_intf->p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
902 p_spu_es = p_intf->p_input->stream.pp_selected_es[i];
907 if( p_intf->p_sys->b_audio_update )
909 /* find audio root menu */
910 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
911 p_intf->p_sys->p_window ), "menubar_audio" ) );
913 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
914 p_intf->p_sys->p_popup ), "popup_audio" ) );
916 GnomeLanguageMenus( p_intf, p_menubar_menu, p_audio_es, AUDIO_ES,
917 on_menubar_audio_toggle );
918 GnomeLanguageMenus( p_intf, p_popup_menu, p_audio_es, AUDIO_ES,
919 on_popup_audio_toggle );
921 p_intf->p_sys->b_audio_update = 0;
924 /* sub picture menus */
925 if( p_intf->p_sys->b_spu_update )
927 /* find spu root menu */
928 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
929 p_intf->p_sys->p_window ), "menubar_subtitle" ) );
931 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
932 p_intf->p_sys->p_popup ), "popup_subtitle" ) );
934 GnomeLanguageMenus( p_intf, p_menubar_menu, p_spu_es, SPU_ES,
935 on_menubar_subtitle_toggle );
936 GnomeLanguageMenus( p_intf, p_popup_menu, p_spu_es, SPU_ES,
937 on_popup_subtitle_toggle );
939 p_intf->p_sys->b_spu_update = 0;
945 /*****************************************************************************
946 * GnomeDisplayDate: display stream date
947 *****************************************************************************
948 * This function displays the current date related to the position in
949 * the stream. It is called whenever the slider changes its value.
950 *****************************************************************************/
951 void GnomeDisplayDate( GtkAdjustment *p_adj )
953 intf_thread_t *p_intf;
955 p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
957 if( p_intf->p_input != NULL )
959 #define p_area p_intf->p_input->stream.p_selected_area
960 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
962 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
964 gtk_label_set_text( p_intf->p_sys->p_label_date,
965 input_OffsetToTime( p_intf->p_input, psz_time,
966 ( p_area->i_size * p_adj->value ) / 100 ) );
968 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
974 /*****************************************************************************
975 * GnomeDiscModeManage
976 *****************************************************************************/
977 static gint GnomeDiscModeManage( intf_thread_t * p_intf )
979 GtkWidget * p_dvd_box;
980 GtkWidget * p_file_box;
981 GtkWidget * p_network_box;
983 p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
984 p_intf->p_sys->p_window ), "file_box" ) );
985 gtk_widget_hide( GTK_WIDGET( p_file_box ) );
987 p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
988 p_intf->p_sys->p_window ), "network_box" ) );
989 gtk_widget_hide( GTK_WIDGET( p_network_box ) );
991 p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
992 p_intf->p_sys->p_window ), "dvd_box" ) );
993 gtk_widget_show( GTK_WIDGET( p_dvd_box ) );
995 gtk_label_set_text( p_intf->p_sys->p_label_status,
996 "Status: playing DVD" );
1001 /*****************************************************************************
1002 * GnomeFileModeManage
1003 *****************************************************************************/
1004 static gint GnomeFileModeManage( intf_thread_t * p_intf )
1006 GtkWidget * p_dvd_box;
1007 GtkWidget * p_file_box;
1008 GtkWidget * p_network_box;
1011 p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1012 p_intf->p_sys->p_window ), "network_box" ) );
1013 gtk_widget_hide( GTK_WIDGET( p_network_box ) );
1015 p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1016 p_intf->p_sys->p_window ), "dvd_box" ) );
1017 gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
1019 p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1020 p_intf->p_sys->p_window ), "file_box" ) );
1021 gtk_widget_show( GTK_WIDGET( p_file_box ) );
1023 psz_name = malloc( 16 + strlen( p_intf->p_input->p_source ) );
1024 sprintf( psz_name, "Status: playing %s", p_intf->p_input->p_source );
1026 gtk_label_set_text( p_intf->p_sys->p_label_status, psz_name );
1030 gtk_label_set_text( p_intf->p_sys->p_label_status,
1037 /*****************************************************************************
1038 * GnomeNetworkModeManage
1039 *****************************************************************************/
1040 static gint GnomeNetworkModeManage( intf_thread_t * p_intf )
1042 GtkWidget * p_dvd_box;
1043 GtkWidget * p_file_box;
1044 GtkWidget * p_network_box;
1046 p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1047 p_intf->p_sys->p_window ), "dvd_box" ) );
1048 gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
1050 p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1051 p_intf->p_sys->p_window ), "file_box" ) );
1052 gtk_widget_hide( GTK_WIDGET( p_file_box ) );
1054 p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1055 p_intf->p_sys->p_window ), "network_box" ) );
1056 gtk_widget_show( GTK_WIDGET( p_network_box ) );
1058 gtk_label_set_text( p_intf->p_sys->p_label_status,
1059 "Status: waiting for stream" );