1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_callbacks.c,v 1.15 2001/04/28 03:36:25 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 gtk
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
32 #include <sys/types.h> /* off_t */
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 );
550 gtk_widget_hide( p_intf->p_sys->p_disc );
555 on_disc_cancel_clicked (GtkButton *button,
558 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
560 gtk_widget_hide( p_intf->p_sys->p_disc );
565 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
568 if( togglebutton->active )
570 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
571 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
577 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
580 if( togglebutton->active )
582 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
583 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
589 on_popup_disc_activate (GtkMenuItem *menuitem,
592 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
594 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
596 p_intf->p_sys->p_disc = create_intf_disc();
597 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
600 gtk_widget_show( p_intf->p_sys->p_disc );
601 gdk_window_raise( p_intf->p_sys->p_disc->window );
605 on_popup_audio_activate (GtkMenuItem *menuitem,
608 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
609 es_descriptor_t * p_es;
611 p_es = (es_descriptor_t*)user_data;
613 input_ChangeES( p_intf->p_input, p_es, 1 );
618 on_popup_subpictures_activate (GtkMenuItem *menuitem,
621 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
622 es_descriptor_t * p_es;
624 p_es = (es_descriptor_t*)user_data;
626 input_ChangeES( p_intf->p_input, p_es, 2 );
631 on_menubar_audio_activate (GtkMenuItem *menuitem,
634 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
635 es_descriptor_t * p_es;
637 p_es = (es_descriptor_t*)user_data;
639 input_ChangeES( p_intf->p_input, p_es, 1 );
644 on_menubar_subpictures_activate (GtkMenuItem *menuitem,
647 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
648 es_descriptor_t * p_es;
650 p_es = (es_descriptor_t*)user_data;
652 input_ChangeES( p_intf->p_input, p_es, 2 );
657 on_popup_navigation_activate (GtkMenuItem *menuitem,
660 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
661 input_area_t * p_area;
665 i_title = (gint)(user_data) / 100 ;
666 i_chapter = (gint)(user_data) - ( 100 * i_title );
667 p_area = p_intf->p_input->stream.pp_areas[i_title];
668 p_area->i_part = i_chapter;
670 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
671 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
676 on_menubar_title_activate (GtkMenuItem *menuitem,
679 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
681 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)user_data );
682 p_intf->p_sys->b_menus_update = 1;
683 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
688 on_menubar_chapter_activate (GtkMenuItem *menuitem,
691 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
692 input_area_t * p_area = p_intf->p_input->stream.p_selected_area;
693 gint i_chapter = (gint)user_data;
695 p_area->i_part = i_chapter;
697 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
698 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
702 on_intf_window_destroy (GtkWidget *widget,
706 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
708 vlc_mutex_lock( &p_intf->change_lock );
710 vlc_mutex_unlock( &p_intf->change_lock );
717 on_main_window_toggle (GtkMenuItem *menuitem,
720 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
722 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) ) {
723 gtk_widget_hide( p_intf->p_sys->p_window);
728 gtk_widget_show( p_intf->p_sys->p_window );
734 on_playlist_clist_drag_motion (GtkWidget *widget,
735 GdkDragContext *drag_context,
745 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_playlist" );
748 clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"playlist_clist"
751 if(!GTK_WIDGET_TOPLEVEL(widget))
753 gdk_window_raise( p_intf->p_sys->p_playlist->window );
757 color.green = 0xffff;
760 gtk_clist_freeze( clist );
762 for(dummy=0; dummy<clist->rows; dummy++)
764 gtk_clist_set_background ( clist, dummy , &color);
769 gtk_clist_set_background ( clist, p_main->p_playlist->i_index , &color);
771 if( gtk_clist_get_selection_info( clist,x,y ,&row,&col )== 1)
774 color.green = 0x9000;
776 gtk_clist_set_background ( clist, row-1 , &color);
777 gtk_clist_set_background ( clist, row , &color);
780 gtk_clist_thaw( clist );
787 on_intf_network_destroy (GtkObject *object,
790 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_network" );
792 p_intf->p_sys->p_network = NULL;
797 on_network_ok_clicked (GtkButton *button,
800 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
801 char *psz_source, *psz_server, *psz_protocol;
804 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
805 GTK_WIDGET(button), "network_server" ) ) );
807 /* Check which protocol was activated */
808 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
809 "network_ts" ) )->active )
813 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
814 "network_rtp" ) )->active )
816 psz_protocol = "rtp";
820 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
824 /* Get the port number and make sure it will not overflow 5 characters */
825 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
826 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
829 intf_ErrMsg( "intf error: invalid port %i", i_port );
832 /* Allocate room for "protocol://server:port" */
833 psz_source = malloc( strlen( psz_protocol ) + strlen( psz_server ) + 10 );
834 if( psz_source == NULL )
839 /* Build source name and add it to playlist */
840 sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
841 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
844 gtk_widget_hide( p_intf->p_sys->p_network );
849 on_network_cancel_clicked (GtkButton *button,
852 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
857 on_menubar_network_activate (GtkMenuItem *menuitem,
860 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
862 gtk_widget_show( p_intf->p_sys->p_network );
863 gdk_window_raise( p_intf->p_sys->p_network->window );
868 on_popup_network_activate (GtkMenuItem *menuitem,
871 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
873 gtk_widget_show( p_intf->p_sys->p_network );
874 gdk_window_raise( p_intf->p_sys->p_network->window );
878 on_toolbar_network_clicked (GtkButton *button,
881 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
883 gtk_widget_show( p_intf->p_sys->p_network );
884 gdk_window_raise( p_intf->p_sys->p_network->window );
889 on_slider_button_release_event (GtkWidget *widget,
890 GdkEventButton *event,
893 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
895 vlc_mutex_lock( &p_intf->change_lock );
896 p_intf->p_sys->b_slider_free = 1;
897 vlc_mutex_unlock( &p_intf->change_lock );
904 on_slider_button_press_event (GtkWidget *widget,
905 GdkEventButton *event,
908 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
910 vlc_mutex_lock( &p_intf->change_lock );
911 p_intf->p_sys->b_slider_free = 0;
912 vlc_mutex_unlock( &p_intf->change_lock );