1 /*****************************************************************************
2 * intf_gnome.c: Gnome interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: intf_gnome.c,v 1.35 2001/05/01 15:12:22 sam 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 GnomeAngleMenu ( gpointer, GtkWidget *,
75 void (*pf_toggle)(GtkCheckMenuItem *, gpointer) );
76 static gint GnomeTitleMenu ( gpointer, GtkWidget *,
77 void (*pf_toggle)(GtkCheckMenuItem *, gpointer) );
78 static gint GnomeSetupMenu ( intf_thread_t * p_intf );
79 static void GnomeDisplayDate ( GtkAdjustment *p_adj );
80 static gint GnomeDiscModeManage( intf_thread_t * p_intf );
81 static gint GnomeFileModeManage( intf_thread_t * p_intf );
82 static gint GnomeNetworkModeManage( intf_thread_t * p_intf );
84 /*****************************************************************************
85 * g_atexit: kludge to avoid the Gnome thread to segfault at exit
86 *****************************************************************************
87 * gtk_init() makes several calls to g_atexit() which calls atexit() to
88 * register tidying callbacks to be called at program exit. Since the Gnome
89 * plugin is likely to be unloaded at program exit, we have to export this
90 * symbol to intercept the g_atexit() calls. Talk about crude hack.
91 *****************************************************************************/
92 void g_atexit( GVoidFunc func )
94 intf_thread_t *p_intf = p_main->p_intf;
96 if( p_intf->p_sys->pf_gdk_callback == NULL )
98 p_intf->p_sys->pf_gdk_callback = func;
100 else if( p_intf->p_sys->pf_gtk_callback == NULL )
102 p_intf->p_sys->pf_gtk_callback = func;
104 /* else nothing, but we could do something here */
108 /*****************************************************************************
109 * Functions exported as capabilities. They are declared as static so that
110 * we don't pollute the namespace too much.
111 *****************************************************************************/
112 void _M( intf_getfunctions )( function_list_t * p_function_list )
114 p_function_list->pf_probe = intf_Probe;
115 p_function_list->functions.intf.pf_open = intf_Open;
116 p_function_list->functions.intf.pf_close = intf_Close;
117 p_function_list->functions.intf.pf_run = intf_Run;
120 /*****************************************************************************
121 * intf_Probe: probe the interface and return a score
122 *****************************************************************************
123 * This function tries to initialize Gnome and returns a score to the
124 * plugin manager so that it can select the best plugin.
125 *****************************************************************************/
126 static int intf_Probe( probedata_t *p_data )
128 if( TestMethod( INTF_METHOD_VAR, "gnome" ) )
133 if( TestProgram( "gnome-vlc" ) )
141 /*****************************************************************************
142 * intf_Open: initialize and create window
143 *****************************************************************************/
144 static int intf_Open( intf_thread_t *p_intf )
146 /* Allocate instance and initialize some members */
147 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
148 if( p_intf->p_sys == NULL )
150 intf_ErrMsg("error: %s", strerror(ENOMEM));
154 /* Initialize Gnome thread */
155 p_intf->p_sys->b_popup_changed = 0;
156 p_intf->p_sys->b_window_changed = 0;
157 p_intf->p_sys->b_playlist_changed = 0;
159 p_intf->p_sys->b_slider_free = 1;
161 p_intf->p_sys->b_mode_changed = 1;
162 p_intf->p_sys->i_intf_mode = FILE_MODE;
164 p_intf->p_sys->pf_gtk_callback = NULL;
165 p_intf->p_sys->pf_gdk_callback = NULL;
170 /*****************************************************************************
171 * intf_Close: destroy interface window
172 *****************************************************************************/
173 static void intf_Close( intf_thread_t *p_intf )
175 /* Destroy structure */
176 free( p_intf->p_sys );
179 /*****************************************************************************
180 * intf_Run: Gnome thread
181 *****************************************************************************
182 * this part of the interface is in a separate thread so that we can call
183 * gtk_main() from within it without annoying the rest of the program.
184 * XXX: the approach may look kludgy, and probably is, but I could not find
185 * a better way to dynamically load a Gnome interface at runtime.
186 *****************************************************************************/
187 static void intf_Run( intf_thread_t *p_intf )
189 /* gnome_init needs to know the command line. We don't care, so we
190 * give it an empty one */
191 char *p_args[] = { "" };
194 /* The data types we are allowed to receive */
195 static GtkTargetEntry target_table[] =
197 { "text/uri-list", 0, DROP_ACCEPT_TEXT_URI_LIST },
198 { "text/plain", 0, DROP_ACCEPT_TEXT_PLAIN }
201 /* intf_Manage callback timeout */
204 /* Initialize Gnome */
205 gnome_init( p_main->psz_arg0, VERSION, i_args, p_args );
207 /* Create some useful widgets that will certainly be used */
208 p_intf->p_sys->p_window = create_intf_window( );
209 p_intf->p_sys->p_popup = create_intf_popup( );
210 p_intf->p_sys->p_disc = create_intf_disc( );
211 p_intf->p_sys->p_network = create_intf_network( );
213 /* Set the title of the main window */
214 gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
215 VOUT_TITLE " (Gnome interface)");
217 /* Accept file drops on the main window */
218 gtk_drag_dest_set( GTK_WIDGET( p_intf->p_sys->p_window ),
219 GTK_DEST_DEFAULT_ALL, target_table,
220 1, GDK_ACTION_COPY );
222 /* Get the interface labels */
223 #define P_LABEL( name ) GTK_LABEL( gtk_object_get_data( \
224 GTK_OBJECT( p_intf->p_sys->p_window ), name ) )
225 p_intf->p_sys->p_label_date = P_LABEL( "label_date" );
226 p_intf->p_sys->p_label_status = P_LABEL( "label_status" );
227 p_intf->p_sys->p_label_title = P_LABEL( "label_title" );
228 p_intf->p_sys->p_label_chapter = P_LABEL( "label_chapter" );
231 /* Connect the date display to the slider */
232 #define P_SLIDER GTK_RANGE( gtk_object_get_data( \
233 GTK_OBJECT( p_intf->p_sys->p_window ), "slider" ) )
234 p_intf->p_sys->p_adj = gtk_range_get_adjustment( P_SLIDER );
236 gtk_signal_connect ( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
237 GTK_SIGNAL_FUNC( GnomeDisplayDate ), NULL );
238 p_intf->p_sys->f_adj_oldvalue = 0;
241 /* We don't create these ones yet because we perhaps won't need them */
242 p_intf->p_sys->p_about = NULL;
243 p_intf->p_sys->p_playlist = NULL;
244 p_intf->p_sys->p_modules = NULL;
245 p_intf->p_sys->p_fileopen = NULL;
247 /* Store p_intf to keep an eye on it */
248 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
251 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_popup),
254 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_disc),
257 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_network),
260 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_adj),
263 /* Show the control window */
264 gtk_widget_show( p_intf->p_sys->p_window );
266 /* Sleep to avoid using all CPU - since some interfaces needs to access
267 * keyboard events, a 100ms delay is a good compromise */
268 i_timeout = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, GnomeManage, p_intf );
270 /* Enter gnome mode */
273 /* Remove the timeout */
274 gtk_timeout_remove( i_timeout );
276 /* Get rid of stored callbacks so we can unload the plugin */
277 if( p_intf->p_sys->pf_gtk_callback != NULL )
279 p_intf->p_sys->pf_gtk_callback( );
280 p_intf->p_sys->pf_gtk_callback = NULL;
284 if( p_intf->p_sys->pf_gdk_callback != NULL )
286 p_intf->p_sys->pf_gdk_callback( );
287 p_intf->p_sys->pf_gdk_callback = NULL;
291 /* following functions are local */
293 /*****************************************************************************
294 * GnomeManage: manage main thread messages
295 *****************************************************************************
296 * In this function, called approx. 10 times a second, we check what the
297 * main program wanted to tell us.
298 *****************************************************************************/
299 static gint GnomeManage( gpointer p_data )
301 #define p_intf ((intf_thread_t *)p_data)
303 vlc_mutex_lock( &p_intf->change_lock );
305 /* If the "display popup" flag has changed */
306 if( p_intf->b_menu_change )
308 gnome_popup_menu_do_popup( p_intf->p_sys->p_popup,
309 NULL, NULL, NULL, NULL );
310 p_intf->b_menu_change = 0;
313 if( p_intf->p_input != NULL )
315 GtkWidget * p_slider;
318 // vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
319 /* New input or stream map change */
320 if( p_intf->p_input->stream.b_changed || p_intf->p_sys->b_mode_changed )
322 switch( p_intf->p_input->stream.i_method & 0xf0 )
324 case INPUT_METHOD_FILE:
325 GnomeFileModeManage( p_intf );
327 case INPUT_METHOD_DISC:
328 GnomeDiscModeManage( p_intf );
330 case INPUT_METHOD_NETWORK:
331 GnomeNetworkModeManage( p_intf );
334 intf_ErrMsg( "intf error: can't determine input method" );
337 p_slider = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
338 p_intf->p_sys->p_window ), "slider" ) );
340 if( p_intf->p_input->stream.b_seekable )
342 gtk_widget_show( GTK_WIDGET( p_slider ) );
346 gtk_widget_hide( GTK_WIDGET( p_slider ) );
349 /* get ready for menu regeneration */
350 p_intf->p_sys->b_title_update = 1;
351 p_intf->p_sys->b_chapter_update = 1;
352 p_intf->p_sys->b_angle_update = 1;
353 p_intf->p_sys->b_audio_update = 1;
354 p_intf->p_sys->b_spu_update = 1;
355 p_intf->p_sys->i_part = 0;
357 p_intf->p_input->stream.b_changed = 0;
358 p_intf->p_sys->b_mode_changed = 0;
360 "intf info: menus refreshed as stream has changed" );
364 // vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
366 /* Update language/chapter menus after user request */
367 GnomeSetupMenu( p_intf );
369 #define p_area p_intf->p_input->stream.p_selected_area
370 /* Update menus when chapter changes */
371 p_intf->p_sys->b_chapter_update =
372 ( p_intf->p_sys->i_part != p_area->i_part );
374 if( p_intf->p_input->stream.b_seekable )
376 /* Manage the slider */
377 newvalue = p_intf->p_sys->p_adj->value;
379 /* If the user hasn't touched the slider since the last time,
380 * then the input can safely change it */
381 if( newvalue == p_intf->p_sys->f_adj_oldvalue )
383 /* Update the value */
384 p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue =
385 ( 100. * p_area->i_tell ) / p_area->i_size;
387 gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
390 /* Otherwise, send message to the input if the user has
391 * finished dragging the slider */
392 else if( p_intf->p_sys->b_slider_free )
394 off_t i_seek = ( newvalue * p_area->i_size ) / 100;
396 input_Seek( p_intf->p_input, i_seek );
398 /* Update the old value */
399 p_intf->p_sys->f_adj_oldvalue = newvalue;
405 /* Manage core vlc functions through the callback */
406 p_intf->pf_manage( p_intf );
410 vlc_mutex_unlock( &p_intf->change_lock );
412 /* Prepare to die, young Skywalker */
419 vlc_mutex_unlock( &p_intf->change_lock );
426 /*****************************************************************************
427 * GnomeLanguageMenus: update interactive menus of the interface
428 *****************************************************************************
429 * Sets up menus with information from input:
432 * Warning: since this function is designed to be called by management
433 * function, the interface lock has to be taken
434 *****************************************************************************/
435 static gint GnomeLanguageMenus( gpointer p_data,
437 es_descriptor_t * p_es,
439 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
441 intf_thread_t * p_intf;
443 GtkWidget * p_separator;
445 GtkWidget * p_item_active;
447 char psz_name[ GNOME_MENU_LABEL_SIZE ];
454 p_intf = (intf_thread_t *)p_data;
456 /* removes previous menu */
457 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
458 gtk_widget_set_sensitive( p_root, FALSE );
463 p_menu = gtk_menu_new();
465 /* special case for "off" item */
466 snprintf( psz_name, GNOME_MENU_LABEL_SIZE, "Off" );
467 psz_name[ GNOME_MENU_LABEL_SIZE - 1 ] = '\0';
469 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
470 p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
472 gtk_widget_show( p_item );
474 /* signal hanling for off */
475 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
476 GTK_SIGNAL_FUNC ( pf_toggle ), NULL );
478 gtk_menu_append( GTK_MENU( p_menu ), p_item );
480 p_separator = gtk_menu_item_new();
481 gtk_widget_set_sensitive( p_separator, FALSE );
482 gtk_widget_show( p_separator );
483 gtk_menu_append( GTK_MENU( p_menu ), p_separator );
485 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
486 p_item_active = NULL;
489 /* create a set of language buttons and append them to the container */
490 for( i = 0 ; i < p_intf->p_input->stream.i_es_number ; i++ )
492 if( p_intf->p_input->stream.pp_es[i]->i_cat == i_cat )
495 strcpy( psz_name, p_intf->p_input->stream.pp_es[i]->psz_desc );
496 if( psz_name[0] == '\0' )
498 snprintf( psz_name, GNOME_MENU_LABEL_SIZE,
499 "Language %d", i_item );
500 psz_name[ GNOME_MENU_LABEL_SIZE - 1 ] = '\0';
503 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
505 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
507 if( p_es == p_intf->p_input->stream.pp_es[i] )
509 /* don't lose p_item when we append into menu */
510 p_item_active = p_item;
513 gtk_widget_show( p_item );
515 /* setup signal hanling */
516 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
517 GTK_SIGNAL_FUNC( pf_toggle ),
518 (gpointer)( p_intf->p_input->stream.pp_es[i] ) );
520 gtk_menu_append( GTK_MENU( p_menu ), p_item );
524 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
526 /* link the new menu to the menubar item */
527 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
529 /* acitvation will call signals so we can only do it
530 * when submenu is attached to menu - to get intf_window */
531 if( p_item_active != NULL )
533 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
537 /* be sure that menu is sensitive if non empty */
540 gtk_widget_set_sensitive( p_root, TRUE );
546 /*****************************************************************************
547 * GnomeAngleMenu: generate angle menu for current title
548 *****************************************************************************/
549 static gint GnomeAngleMenu( gpointer p_data, GtkWidget * p_angle,
550 void(*pf_toggle)( GtkCheckMenuItem *, gpointer ) )
552 intf_thread_t * p_intf;
553 char psz_name[ GNOME_MENU_LABEL_SIZE ];
554 GtkWidget * p_angle_menu;
555 GSList * p_angle_group;
557 GtkWidget * p_item_active;
561 p_intf = (intf_thread_t*)p_data;
563 /* removes previous menu */
564 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_angle ) );
565 gtk_widget_set_sensitive( p_angle, FALSE );
567 p_angle_menu = gtk_menu_new();;
568 p_angle_group = NULL;
570 p_item_active = NULL;
573 i_angle < p_intf->p_input->stream.p_selected_area->i_angle_nb ;
576 snprintf( psz_name, GNOME_MENU_LABEL_SIZE, "Angle %d", i_angle + 1 );
577 psz_name[ GNOME_MENU_LABEL_SIZE - 1 ] = '\0';
579 p_item = gtk_radio_menu_item_new_with_label( p_angle_group,
582 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
584 if( p_intf->p_input->stream.p_selected_area->i_angle ==
587 p_item_active = p_item;
590 gtk_widget_show( p_item );
592 /* setup signal hanling */
593 gtk_signal_connect( GTK_OBJECT( p_item ),
595 GTK_SIGNAL_FUNC( pf_toggle ),
596 (gpointer)(i_angle + 1) );
598 gtk_menu_append( GTK_MENU( p_angle_menu ), p_item );
601 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_angle ), p_angle_menu );
603 if( p_item_active != NULL )
605 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
609 /* be sure that menu is sensitive if non empty */
610 if( p_intf->p_input->stream.p_selected_area->i_angle_nb > 1 )
612 gtk_widget_set_sensitive( p_angle, TRUE );
618 /*****************************************************************************
619 * GnomeChapterMenu: generate chapter menu for current title
620 *****************************************************************************/
621 static gint GnomeChapterMenu( gpointer p_data, GtkWidget * p_chapter,
622 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
624 intf_thread_t * p_intf;
625 char psz_name[ GNOME_MENU_LABEL_SIZE ];
626 GtkWidget * p_chapter_menu;
627 GtkWidget * p_chapter_submenu;
628 GtkWidget * p_menu_item;
630 GtkWidget * p_item_selected;
631 GSList * p_chapter_group;
637 p_intf = (intf_thread_t*)p_data;
639 /* Removes previous menu */
640 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_chapter ) );
641 gtk_widget_set_sensitive( p_chapter, FALSE );
643 p_chapter_submenu = NULL;
644 p_chapter_group = NULL;
645 p_item_selected = NULL;
648 i_title = p_intf->p_input->stream.p_selected_area->i_id;
649 p_chapter_menu = gtk_menu_new();
650 i_nb = p_intf->p_input->stream.pp_areas[i_title]->i_part_nb;
652 for( i_chapter = 0 ; i_chapter < i_nb ; i_chapter++ )
654 /* we group chapters in packets of ten for small screens */
655 if( ( i_chapter % 10 == 0 ) && ( i_nb > 20 ) )
659 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_menu_item ),
661 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_menu_item );
664 snprintf( psz_name, GNOME_MENU_LABEL_SIZE,
665 "%d - %d", i_chapter + 1, i_chapter + 10);
666 psz_name[ GNOME_MENU_LABEL_SIZE - 1 ] = '\0';
667 p_menu_item = gtk_menu_item_new_with_label( psz_name );
668 gtk_widget_show( p_menu_item );
669 p_chapter_submenu = gtk_menu_new();
672 snprintf( psz_name, GNOME_MENU_LABEL_SIZE,
673 "Chapter %d", i_chapter + 1 );
674 psz_name[ GNOME_MENU_LABEL_SIZE - 1 ] = '\0';
676 p_item = gtk_radio_menu_item_new_with_label( p_chapter_group,
679 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
681 if( p_intf->p_input->stream.pp_areas[i_title]->i_part
684 p_item_selected = p_item;
687 gtk_widget_show( p_item );
689 /* setup signal hanling */
690 gtk_signal_connect( GTK_OBJECT( p_item ),
692 GTK_SIGNAL_FUNC( pf_toggle ),
693 (gpointer)(i_chapter + 1) );
697 gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
701 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
707 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_menu_item ),
709 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_menu_item );
712 /* link the new menu to the title menu item */
713 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter ),
716 /* toggle currently selected chapter */
717 if( p_item_selected != NULL )
719 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_selected ),
723 /* be sure that chapter menu is sensitive, if there are several items */
724 if( p_intf->p_input->stream.pp_areas[i_title]->i_part_nb > 1 )
726 gtk_widget_set_sensitive( p_chapter, TRUE );
732 /*****************************************************************************
733 * GnomeTitleMenu: sets menus for titles and chapters selection
734 *****************************************************************************
735 * Generates two types of menus:
736 * -simple list of titles
737 * -cascaded lists of chapters for each title
738 *****************************************************************************/
739 static gint GnomeTitleMenu( gpointer p_data,
740 GtkWidget * p_navigation,
741 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
743 intf_thread_t * p_intf;
744 char psz_name[ GNOME_MENU_LABEL_SIZE ];
745 GtkWidget * p_title_menu;
746 GtkWidget * p_title_submenu;
747 GtkWidget * p_title_item;
748 GtkWidget * p_item_active;
749 GtkWidget * p_chapter_menu;
750 GtkWidget * p_chapter_submenu;
751 GtkWidget * p_title_menu_item;
752 GtkWidget * p_chapter_menu_item;
754 GSList * p_title_group;
755 GSList * p_chapter_group;
762 p_intf = (intf_thread_t*)p_data;
764 /* removes previous menu */
765 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_navigation ) );
766 gtk_widget_set_sensitive( p_navigation, FALSE );
768 p_title_menu = gtk_menu_new();
769 p_title_group = NULL;
770 p_title_submenu = NULL;
771 p_title_menu_item = NULL;
772 p_chapter_group = NULL;
773 p_chapter_submenu = NULL;
774 p_chapter_menu_item = NULL;
775 p_item_active = NULL;
776 i_title_nb = p_intf->p_input->stream.i_area_nb;
779 for( i_title = 1 ; i_title < i_title_nb ; i_title++ )
781 /* we group titles in packets of ten for small screens */
782 if( ( i_title % 10 == 1 ) && ( i_title_nb > 20 ) )
786 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
788 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
791 snprintf( psz_name, GNOME_MENU_LABEL_SIZE,
792 "%d - %d", i_title, i_title + 9 );
793 psz_name[ GNOME_MENU_LABEL_SIZE - 1 ] = '\0';
794 p_title_menu_item = gtk_menu_item_new_with_label( psz_name );
795 gtk_widget_show( p_title_menu_item );
796 p_title_submenu = gtk_menu_new();
799 snprintf( psz_name, GNOME_MENU_LABEL_SIZE, "Title %d (%d)", i_title,
800 p_intf->p_input->stream.pp_areas[i_title]->i_part_nb );
801 psz_name[ GNOME_MENU_LABEL_SIZE - 1 ] = '\0';
803 if( pf_toggle == on_menubar_title_toggle )
805 p_title_item = gtk_radio_menu_item_new_with_label( p_title_group,
808 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_title_item ) );
810 if( p_intf->p_input->stream.pp_areas[i_title] ==
811 p_intf->p_input->stream.p_selected_area )
813 p_item_active = p_title_item;
816 /* setup signal hanling */
817 gtk_signal_connect( GTK_OBJECT( p_title_item ),
819 GTK_SIGNAL_FUNC( pf_toggle ),
820 (gpointer)(p_intf->p_input->stream.pp_areas[i_title]) );
822 if( p_intf->p_input->stream.i_area_nb > 1 )
824 /* be sure that menu is sensitive */
825 gtk_widget_set_sensitive( p_navigation, TRUE );
831 p_title_item = gtk_menu_item_new_with_label( psz_name );
832 p_chapter_menu = gtk_menu_new();
834 p_intf->p_input->stream.pp_areas[i_title]->i_part_nb;
836 for( i_chapter = 0 ; i_chapter < i_chapter_nb ; i_chapter++ )
838 /* we group chapters in packets of ten for small screens */
839 if( ( i_chapter % 10 == 0 ) && ( i_chapter_nb > 20 ) )
843 gtk_menu_item_set_submenu(
844 GTK_MENU_ITEM( p_chapter_menu_item ),
846 gtk_menu_append( GTK_MENU( p_chapter_menu ),
847 p_chapter_menu_item );
850 snprintf( psz_name, GNOME_MENU_LABEL_SIZE,
851 "%d - %d", i_chapter + 1, i_chapter + 10 );
852 psz_name[ GNOME_MENU_LABEL_SIZE - 1 ] = '\0';
853 p_chapter_menu_item =
854 gtk_menu_item_new_with_label( psz_name );
855 gtk_widget_show( p_chapter_menu_item );
856 p_chapter_submenu = gtk_menu_new();
859 snprintf( psz_name, GNOME_MENU_LABEL_SIZE,
860 "Chapter %d", i_chapter + 1 );
861 psz_name[ GNOME_MENU_LABEL_SIZE - 1 ] = '\0';
863 p_item = gtk_radio_menu_item_new_with_label(
864 p_chapter_group, psz_name );
865 p_chapter_group = gtk_radio_menu_item_group(
866 GTK_RADIO_MENU_ITEM( p_item ) );
867 gtk_widget_show( p_item );
869 #define p_area p_intf->p_input->stream.pp_areas[i_title]
870 if( ( p_area == p_intf->p_input->stream.p_selected_area ) &&
871 ( p_area->i_part == i_chapter + 1 ) )
873 p_item_active = p_item;
877 /* setup signal hanling */
878 gtk_signal_connect( GTK_OBJECT( p_item ),
880 GTK_SIGNAL_FUNC( pf_toggle ),
881 (gpointer)( ( i_title * 100 ) + ( i_chapter + 1) ) );
883 if( i_chapter_nb > 20 )
885 gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
889 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
893 if( i_chapter_nb > 20 )
895 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter_menu_item ),
897 gtk_menu_append( GTK_MENU( p_chapter_menu ),
898 p_chapter_menu_item );
901 /* link the new menu to the title menu item */
902 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
905 if( p_intf->p_input->stream.pp_areas[i_title]->i_part_nb > 1 )
907 /* be sure that menu is sensitive */
908 gtk_widget_set_sensitive( p_navigation, TRUE );
911 gtk_widget_show( p_title_item );
913 if( i_title_nb > 20 )
915 gtk_menu_append( GTK_MENU( p_title_submenu ), p_title_item );
919 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_item );
923 if( i_title_nb > 20 )
925 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
927 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
930 /* be sure that menu is sensitive */
931 gtk_widget_set_sensitive( p_title_menu, TRUE );
933 /* link the new menu to the menubar item */
934 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
936 if( p_item_active != NULL )
938 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
945 /*****************************************************************************
946 * GnomeSetupMenu: function that generates title/chapter/audio/subpic
947 * menus with help from preceding functions
948 *****************************************************************************/
949 static gint GnomeSetupMenu( intf_thread_t * p_intf )
951 es_descriptor_t * p_audio_es;
952 es_descriptor_t * p_spu_es;
953 GtkWidget * p_menubar_menu;
954 GtkWidget * p_popup_menu;
957 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
958 p_intf->p_sys->b_angle_update |= p_intf->p_sys->b_title_update;
959 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update;
960 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update;
962 if( p_intf->p_sys->b_title_update )
966 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
967 p_intf->p_sys->p_window ), "menubar_title" ) );
968 GnomeTitleMenu( p_intf, p_menubar_menu, on_menubar_title_toggle );
970 snprintf( psz_title, 4, "%d",
971 p_intf->p_input->stream.p_selected_area->i_id );
972 psz_title[ 4 ] = '\0';
973 gtk_label_set_text( p_intf->p_sys->p_label_title, psz_title );
975 p_intf->p_sys->b_title_update = 0;
978 if( p_intf->p_sys->b_chapter_update )
982 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
983 p_intf->p_sys->p_popup ), "popup_navigation" ) );
984 GnomeTitleMenu( p_intf, p_popup_menu, on_popup_navigation_toggle );
986 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
987 p_intf->p_sys->p_window ), "menubar_chapter" ) );
988 GnomeChapterMenu( p_intf, p_menubar_menu, on_menubar_chapter_toggle );
990 snprintf( psz_chapter, 4, "%d",
991 p_intf->p_input->stream.p_selected_area->i_part );
992 psz_chapter[ 4 ] = '\0';
993 gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
995 p_intf->p_sys->i_part =
996 p_intf->p_input->stream.p_selected_area->i_part;
998 p_intf->p_sys->b_chapter_update = 0;
1001 if( p_intf->p_sys->b_angle_update )
1003 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1004 p_intf->p_sys->p_window ), "menubar_angle" ) );
1005 GnomeAngleMenu( p_intf, p_menubar_menu, on_menubar_angle_toggle );
1007 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1008 p_intf->p_sys->p_popup ), "popup_angle" ) );
1009 GnomeAngleMenu( p_intf, p_popup_menu, on_popup_angle_toggle );
1011 p_intf->p_sys->b_angle_update = 0;
1014 /* look for selected ES */
1018 for( i = 0 ; i < p_intf->p_input->stream.i_selected_es_number ; i++ )
1020 if( p_intf->p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
1022 p_audio_es = p_intf->p_input->stream.pp_selected_es[i];
1025 if( p_intf->p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
1027 p_spu_es = p_intf->p_input->stream.pp_selected_es[i];
1032 if( p_intf->p_sys->b_audio_update )
1034 /* find audio root menu */
1035 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1036 p_intf->p_sys->p_window ), "menubar_audio" ) );
1038 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1039 p_intf->p_sys->p_popup ), "popup_audio" ) );
1041 GnomeLanguageMenus( p_intf, p_menubar_menu, p_audio_es, AUDIO_ES,
1042 on_menubar_audio_toggle );
1043 GnomeLanguageMenus( p_intf, p_popup_menu, p_audio_es, AUDIO_ES,
1044 on_popup_audio_toggle );
1046 p_intf->p_sys->b_audio_update = 0;
1049 /* sub picture menus */
1050 if( p_intf->p_sys->b_spu_update )
1052 /* find spu root menu */
1053 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1054 p_intf->p_sys->p_window ), "menubar_subtitle" ) );
1056 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1057 p_intf->p_sys->p_popup ), "popup_subtitle" ) );
1059 GnomeLanguageMenus( p_intf, p_menubar_menu, p_spu_es, SPU_ES,
1060 on_menubar_subtitle_toggle );
1061 GnomeLanguageMenus( p_intf, p_popup_menu, p_spu_es, SPU_ES,
1062 on_popup_subtitle_toggle );
1064 p_intf->p_sys->b_spu_update = 0;
1070 /*****************************************************************************
1071 * GnomeDisplayDate: display stream date
1072 *****************************************************************************
1073 * This function displays the current date related to the position in
1074 * the stream. It is called whenever the slider changes its value.
1075 *****************************************************************************/
1076 void GnomeDisplayDate( GtkAdjustment *p_adj )
1078 intf_thread_t *p_intf;
1080 p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
1082 if( p_intf->p_input != NULL )
1084 #define p_area p_intf->p_input->stream.p_selected_area
1085 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1087 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
1089 gtk_label_set_text( p_intf->p_sys->p_label_date,
1090 input_OffsetToTime( p_intf->p_input, psz_time,
1091 ( p_area->i_size * p_adj->value ) / 100 ) );
1093 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
1099 /*****************************************************************************
1100 * GnomeDiscModeManage
1101 *****************************************************************************/
1102 static gint GnomeDiscModeManage( intf_thread_t * p_intf )
1104 GtkWidget * p_dvd_box;
1105 GtkWidget * p_file_box;
1106 GtkWidget * p_network_box;
1108 p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1109 p_intf->p_sys->p_window ), "file_box" ) );
1110 gtk_widget_hide( GTK_WIDGET( p_file_box ) );
1112 p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1113 p_intf->p_sys->p_window ), "network_box" ) );
1114 gtk_widget_hide( GTK_WIDGET( p_network_box ) );
1116 p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1117 p_intf->p_sys->p_window ), "dvd_box" ) );
1118 gtk_widget_show( GTK_WIDGET( p_dvd_box ) );
1120 gtk_label_set_text( p_intf->p_sys->p_label_status,
1121 "Status: playing DVD" );
1126 /*****************************************************************************
1127 * GnomeFileModeManage
1128 *****************************************************************************/
1129 static gint GnomeFileModeManage( intf_thread_t * p_intf )
1131 GtkWidget * p_dvd_box;
1132 GtkWidget * p_file_box;
1133 GtkWidget * p_network_box;
1136 p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1137 p_intf->p_sys->p_window ), "network_box" ) );
1138 gtk_widget_hide( GTK_WIDGET( p_network_box ) );
1140 p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1141 p_intf->p_sys->p_window ), "dvd_box" ) );
1142 gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
1144 p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1145 p_intf->p_sys->p_window ), "file_box" ) );
1146 gtk_widget_show( GTK_WIDGET( p_file_box ) );
1149 // psz_name = malloc( 16 + strlen( p_intf->p_input->p_source ) );
1150 // sprintf( psz_name, "Status: playing %s", p_intf->p_input->p_source );
1152 psz_name = strdup( p_intf->p_input->p_source );
1154 gtk_label_set_text( p_intf->p_sys->p_label_status, psz_name );
1158 gtk_label_set_text( p_intf->p_sys->p_label_status,
1165 /*****************************************************************************
1166 * GnomeNetworkModeManage
1167 *****************************************************************************/
1168 static gint GnomeNetworkModeManage( intf_thread_t * p_intf )
1170 GtkWidget * p_dvd_box;
1171 GtkWidget * p_file_box;
1172 GtkWidget * p_network_box;
1174 p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1175 p_intf->p_sys->p_window ), "dvd_box" ) );
1176 gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
1178 p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1179 p_intf->p_sys->p_window ), "file_box" ) );
1180 gtk_widget_hide( GTK_WIDGET( p_file_box ) );
1182 p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1183 p_intf->p_sys->p_window ), "network_box" ) );
1184 gtk_widget_show( GTK_WIDGET( p_network_box ) );
1186 gtk_label_set_text( p_intf->p_sys->p_label_status,
1187 "Status: waiting for stream" );