1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_callbacks.c,v 1.13 2001/04/08 13:09:32 octplane 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 gtk
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
44 #include "stream_control.h"
45 #include "input_ext-intf.h"
47 #include "interface.h"
48 #include "intf_playlist.h"
51 #include "gtk_callbacks.h"
52 #include "gtk_interface.h"
53 #include "gtk_support.h"
54 #include "gtk_playlist.h"
59 /*****************************************************************************
61 ******************************************************************************/
63 on_menubar_open_activate (GtkMenuItem *menuitem,
66 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
68 /* If we have never used the file selector, open it */
69 if( p_intf->p_sys->p_fileopen == NULL)
71 p_intf->p_sys->p_fileopen = create_intf_fileopen();
72 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
76 gtk_widget_show( p_intf->p_sys->p_fileopen );
77 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
82 on_menubar_exit_activate (GtkMenuItem *menuitem,
85 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
87 vlc_mutex_lock( &p_intf->change_lock );
89 vlc_mutex_unlock( &p_intf->change_lock );
93 on_menubar_preferences_activate (GtkMenuItem *menuitem,
101 on_menubar_about_activate (GtkMenuItem *menuitem,
104 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
106 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
108 p_intf->p_sys->p_about = create_intf_about();
109 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
112 gtk_widget_show( p_intf->p_sys->p_about );
113 gdk_window_raise( p_intf->p_sys->p_about->window );
118 on_toolbar_open_clicked (GtkButton *button,
121 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
123 /* If we have never used the file selector, open it */
124 if( p_intf->p_sys->p_fileopen == NULL)
126 p_intf->p_sys->p_fileopen = create_intf_fileopen();
127 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
131 gtk_widget_show( p_intf->p_sys->p_fileopen );
132 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
137 on_toolbar_back_clicked (GtkButton *button,
145 on_toolbar_stop_clicked (GtkButton *button,
153 on_toolbar_play_clicked (GtkButton *button,
156 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
158 if( p_intf->p_input != NULL )
160 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
166 on_toolbar_pause_clicked (GtkButton *button,
169 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
171 if( p_intf->p_input != NULL )
173 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
178 on_toolbar_prev_clicked (GtkButton *button,
181 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
183 if( p_intf->p_input != NULL )
185 /* FIXME: temporary hack */
186 intf_PlaylistPrev( p_main->p_playlist );
187 intf_PlaylistPrev( p_main->p_playlist );
188 p_intf->p_input->b_eof = 1;
194 on_toolbar_next_clicked (GtkButton *button,
197 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
199 if( p_intf->p_input != NULL )
201 /* FIXME: temporary hack */
202 p_intf->p_input->b_eof = 1;
208 on_popup_play_activate (GtkMenuItem *menuitem,
211 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
213 if( p_intf->p_input != NULL )
215 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
221 on_popup_pause_activate (GtkMenuItem *menuitem,
224 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
226 if( p_intf->p_input != NULL )
228 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
234 on_popup_exit_activate (GtkMenuItem *menuitem,
237 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
239 vlc_mutex_lock( &p_intf->change_lock );
241 vlc_mutex_unlock( &p_intf->change_lock );
245 on_fileopen_ok_clicked (GtkButton *button,
248 GtkCList *playlist_clist;
251 GtkWidget *filesel = gtk_widget_get_toplevel ( GTK_WIDGET (button) );
253 /* retrieve the interface */
254 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(filesel), "intf_fileopen" );
256 /* hide the widget */
257 gtk_widget_hide (filesel);
258 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
260 /* catch the GTK CList */
261 playlist_clist = GTK_CLIST(
262 lookup_widget(p_intf->p_sys->p_playlist,"playlist_clist"));
264 intf_PlaylistAdd( p_main->p_playlist,
268 /* update the display */
269 rebuildCList( playlist_clist ,
270 p_main->p_playlist );
276 on_fileopen_cancel_clicked (GtkButton *button,
279 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
284 on_intf_fileopen_destroy (GtkObject *object,
287 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
289 p_intf->p_sys->p_fileopen = NULL;
294 on_popup_open_activate (GtkMenuItem *menuitem,
297 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
299 /* If we have never used the file selector, open it */
300 if( p_intf->p_sys->p_fileopen == NULL)
302 p_intf->p_sys->p_fileopen = create_intf_fileopen();
303 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
307 gtk_widget_show( p_intf->p_sys->p_fileopen );
308 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
313 on_popup_about_activate (GtkMenuItem *menuitem,
316 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
318 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
320 p_intf->p_sys->p_about = create_intf_about();
321 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
324 gtk_widget_show( p_intf->p_sys->p_about );
325 gdk_window_raise( p_intf->p_sys->p_about->window );
328 on_popup_slow_activate (GtkMenuItem *menuitem,
331 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
333 if( p_intf->p_input != NULL )
335 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
341 on_popup_fast_activate (GtkMenuItem *menuitem,
344 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
346 if( p_intf->p_input != NULL )
348 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
354 on_toolbar_slow_clicked (GtkButton *button,
357 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
359 if( p_intf->p_input != NULL )
361 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
367 on_toolbar_fast_clicked (GtkButton *button,
370 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
372 if( p_intf->p_input != NULL )
374 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
380 on_intf_modules_destroy (GtkObject *object,
388 on_modules_ok_clicked (GtkButton *button,
391 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
393 gtk_widget_hide( p_intf->p_sys->p_modules );
399 on_modules_apply_clicked (GtkButton *button,
407 on_modules_cancel_clicked (GtkButton *button,
410 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
412 gtk_widget_hide( p_intf->p_sys->p_modules );
416 on_menubar_modules_activate (GtkMenuItem *menuitem,
419 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
421 if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
423 // p_intf->p_sys->p_modules = create_intf_modules();
424 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
427 gtk_widget_show( p_intf->p_sys->p_modules );
428 gdk_window_raise( p_intf->p_sys->p_modules->window );
433 on_intf_window_drag_data_received (GtkWidget *widget,
434 GdkDragContext *drag_context,
437 GtkSelectionData *data,
442 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
443 int end = p_main->p_playlist->i_size;
444 on_generic_drop_data_received( p_intf, data, info, PLAYLIST_END);
446 if( p_intf->p_input != NULL )
448 /* FIXME: temporary hack */
449 p_intf->p_input->b_eof = 1;
452 intf_PlaylistJumpto( p_main->p_playlist, end-1 );
458 on_about_ok_clicked (GtkButton *button,
461 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
463 gtk_widget_hide( p_intf->p_sys->p_about );
468 on_menubar_disc_activate (GtkMenuItem *menuitem,
471 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
473 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
475 p_intf->p_sys->p_disc = create_intf_disc();
476 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
479 gtk_widget_show( p_intf->p_sys->p_disc );
480 gdk_window_raise( p_intf->p_sys->p_disc->window );
485 on_toolbar_disc_clicked (GtkButton *button,
488 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
490 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
492 p_intf->p_sys->p_disc = create_intf_disc();
493 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
496 gtk_widget_show( p_intf->p_sys->p_disc );
497 gdk_window_raise( p_intf->p_sys->p_disc->window );
502 on_disc_ok_clicked (GtkButton *button,
505 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
506 char *psz_device, *psz_source, *psz_method;
508 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
509 GTK_WIDGET(button), "disc_name" ) ) );
511 /* "dvd:foo" has size 5 + strlen(foo) */
512 psz_source = malloc( 5 + strlen( psz_device ) );
513 if( psz_source == NULL )
518 /* Check which method was activated */
519 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
520 "disc_dvd" ) )->active )
524 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
525 "disc_vcd" ) )->active )
531 intf_ErrMsg( "intf error: unknown toggle button configuration" );
536 /* Select title and chapter */
537 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
538 GTK_SPIN_BUTTON( lookup_widget(
539 GTK_WIDGET(button), "disc_title" ) ) ) );
541 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
542 GTK_SPIN_BUTTON( lookup_widget(
543 GTK_WIDGET(button), "disc_chapter" ) ) ) );
545 /* Build source name and add it to playlist */
546 sprintf( psz_source, "%s:%s", psz_method, psz_device );
547 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
549 gtk_widget_hide( p_intf->p_sys->p_disc );
554 on_disc_cancel_clicked (GtkButton *button,
557 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
559 gtk_widget_hide( p_intf->p_sys->p_disc );
564 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
567 if( togglebutton->active )
569 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
570 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
576 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
579 if( togglebutton->active )
581 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
582 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
588 on_popup_disc_activate (GtkMenuItem *menuitem,
591 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
593 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
595 p_intf->p_sys->p_disc = create_intf_disc();
596 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
599 gtk_widget_show( p_intf->p_sys->p_disc );
600 gdk_window_raise( p_intf->p_sys->p_disc->window );
604 on_popup_audio_activate (GtkMenuItem *menuitem,
607 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
608 es_descriptor_t * p_es;
610 p_es = (es_descriptor_t*)user_data;
612 input_ChangeES( p_intf->p_input, p_es, 1 );
617 on_popup_subpictures_activate (GtkMenuItem *menuitem,
620 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
621 es_descriptor_t * p_es;
623 p_es = (es_descriptor_t*)user_data;
625 input_ChangeES( p_intf->p_input, p_es, 2 );
630 on_menubar_audio_activate (GtkMenuItem *menuitem,
633 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
634 es_descriptor_t * p_es;
636 p_es = (es_descriptor_t*)user_data;
638 input_ChangeES( p_intf->p_input, p_es, 1 );
643 on_menubar_subpictures_activate (GtkMenuItem *menuitem,
646 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
647 es_descriptor_t * p_es;
649 p_es = (es_descriptor_t*)user_data;
651 input_ChangeES( p_intf->p_input, p_es, 2 );
656 on_popup_navigation_activate (GtkMenuItem *menuitem,
659 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
660 input_area_t * p_area;
664 i_title = (gint)(user_data) / 100 ;
665 i_chapter = (gint)(user_data) - ( 100 * i_title );
666 p_area = p_intf->p_input->stream.pp_areas[i_title];
667 p_area->i_part = i_chapter;
669 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
670 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
675 on_menubar_title_activate (GtkMenuItem *menuitem,
678 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
680 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)user_data );
681 p_intf->p_sys->b_menus_update = 1;
682 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
687 on_menubar_chapter_activate (GtkMenuItem *menuitem,
690 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
691 input_area_t * p_area = p_intf->p_input->stream.p_selected_area;
692 gint i_chapter = (gint)user_data;
694 p_area->i_part = i_chapter;
696 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
697 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
701 on_intf_window_destroy (GtkWidget *widget,
705 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
707 vlc_mutex_lock( &p_intf->change_lock );
709 vlc_mutex_unlock( &p_intf->change_lock );
716 on_main_window_toggle (GtkMenuItem *menuitem,
719 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
721 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) ) {
722 gtk_widget_hide( p_intf->p_sys->p_window);
727 gtk_widget_show( p_intf->p_sys->p_window );
733 on_playlist_clist_drag_motion (GtkWidget *widget,
734 GdkDragContext *drag_context,
744 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_playlist" );
747 clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"playlist_clist"
750 if(!GTK_WIDGET_TOPLEVEL(widget))
752 gdk_window_raise( p_intf->p_sys->p_playlist->window );
756 color.green = 0xffff;
759 gtk_clist_freeze( clist );
761 for(dummy=0; dummy<clist->rows; dummy++)
763 gtk_clist_set_background ( clist, dummy , &color);
768 gtk_clist_set_background ( clist, p_main->p_playlist->i_index , &color);
770 if( gtk_clist_get_selection_info( clist,x,y ,&row,&col )== 1)
773 color.green = 0x9000;
775 gtk_clist_set_background ( clist, row-1 , &color);
776 gtk_clist_set_background ( clist, row , &color);
779 gtk_clist_thaw( clist );
786 on_intf_network_destroy (GtkObject *object,
789 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_network" );
791 p_intf->p_sys->p_network = NULL;
796 on_network_ok_clicked (GtkButton *button,
799 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
800 char *psz_source, *psz_server, *psz_protocol;
803 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
804 GTK_WIDGET(button), "network_server" ) ) );
806 /* Check which protocol was activated */
807 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
808 "network_ts" ) )->active )
812 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
813 "network_rtp" ) )->active )
815 psz_protocol = "rtp";
819 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
823 /* Get the port number and make sure it will not overflow 5 characters */
824 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
825 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
828 intf_ErrMsg( "intf error: invalid port %i", i_port );
831 /* Allocate room for "protocol://server:port" */
832 psz_source = malloc( strlen( psz_protocol ) + strlen( psz_server ) + 10 );
833 if( psz_source == NULL )
838 /* Build source name and add it to playlist */
839 sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
840 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
843 gtk_widget_hide( p_intf->p_sys->p_network );
848 on_network_cancel_clicked (GtkButton *button,
851 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
856 on_menubar_network_activate (GtkMenuItem *menuitem,
859 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
861 gtk_widget_show( p_intf->p_sys->p_network );
862 gdk_window_raise( p_intf->p_sys->p_network->window );
867 on_popup_network_activate (GtkMenuItem *menuitem,
870 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
872 gtk_widget_show( p_intf->p_sys->p_network );
873 gdk_window_raise( p_intf->p_sys->p_network->window );
877 on_toolbar_network_clicked (GtkButton *button,
880 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
882 gtk_widget_show( p_intf->p_sys->p_network );
883 gdk_window_raise( p_intf->p_sys->p_network->window );
888 on_slider_button_release_event (GtkWidget *widget,
889 GdkEventButton *event,
892 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
894 vlc_mutex_lock( &p_intf->change_lock );
895 p_intf->p_sys->b_slider_free = 1;
896 vlc_mutex_unlock( &p_intf->change_lock );
903 on_slider_button_press_event (GtkWidget *widget,
904 GdkEventButton *event,
907 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
909 vlc_mutex_lock( &p_intf->change_lock );
910 p_intf->p_sys->b_slider_free = 0;
911 vlc_mutex_unlock( &p_intf->change_lock );