1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_callbacks.c,v 1.12 2001/03/21 13:42:34 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 *****************************************************************************/
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"
58 /****************************************************************************
61 void on_generic_drop_data_received( intf_thread_t * p_intf,
62 GtkSelectionData *data, guint info, int position);
66 /*****************************************************************************
68 ******************************************************************************/
70 on_menubar_open_activate (GtkMenuItem *menuitem,
73 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
75 /* If we have never used the file selector, open it */
76 if( p_intf->p_sys->p_fileopen == NULL)
78 p_intf->p_sys->p_fileopen = create_intf_fileopen();
79 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
83 gtk_widget_show( p_intf->p_sys->p_fileopen );
84 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
89 on_menubar_exit_activate (GtkMenuItem *menuitem,
92 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
94 vlc_mutex_lock( &p_intf->change_lock );
96 vlc_mutex_unlock( &p_intf->change_lock );
100 on_menubar_preferences_activate (GtkMenuItem *menuitem,
108 on_menubar_about_activate (GtkMenuItem *menuitem,
111 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
113 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
115 p_intf->p_sys->p_about = create_intf_about();
116 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
119 gtk_widget_show( p_intf->p_sys->p_about );
120 gdk_window_raise( p_intf->p_sys->p_about->window );
125 on_toolbar_open_clicked (GtkButton *button,
128 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
130 /* If we have never used the file selector, open it */
131 if( p_intf->p_sys->p_fileopen == NULL)
133 p_intf->p_sys->p_fileopen = create_intf_fileopen();
134 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
138 gtk_widget_show( p_intf->p_sys->p_fileopen );
139 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
144 on_toolbar_back_clicked (GtkButton *button,
152 on_toolbar_stop_clicked (GtkButton *button,
160 on_toolbar_play_clicked (GtkButton *button,
163 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
165 if( p_intf->p_input != NULL )
167 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
173 on_toolbar_pause_clicked (GtkButton *button,
176 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
178 if( p_intf->p_input != NULL )
180 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
185 on_toolbar_prev_clicked (GtkButton *button,
188 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
190 if( p_intf->p_input != NULL )
192 /* FIXME: temporary hack */
193 intf_PlaylistPrev( p_main->p_playlist );
194 intf_PlaylistPrev( p_main->p_playlist );
195 p_intf->p_input->b_eof = 1;
201 on_toolbar_next_clicked (GtkButton *button,
204 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
206 if( p_intf->p_input != NULL )
208 /* FIXME: temporary hack */
209 p_intf->p_input->b_eof = 1;
215 on_popup_play_activate (GtkMenuItem *menuitem,
218 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
220 if( p_intf->p_input != NULL )
222 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
228 on_popup_pause_activate (GtkMenuItem *menuitem,
231 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
233 if( p_intf->p_input != NULL )
235 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
241 on_popup_exit_activate (GtkMenuItem *menuitem,
244 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
246 vlc_mutex_lock( &p_intf->change_lock );
248 vlc_mutex_unlock( &p_intf->change_lock );
252 on_fileopen_ok_clicked (GtkButton *button,
258 filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
259 gtk_widget_hide (filesel);
260 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
262 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
267 on_fileopen_cancel_clicked (GtkButton *button,
270 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
275 on_intf_fileopen_destroy (GtkObject *object,
278 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
280 p_intf->p_sys->p_fileopen = NULL;
285 on_popup_open_activate (GtkMenuItem *menuitem,
288 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
290 /* If we have never used the file selector, open it */
291 if( p_intf->p_sys->p_fileopen == NULL)
293 p_intf->p_sys->p_fileopen = create_intf_fileopen();
294 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
298 gtk_widget_show( p_intf->p_sys->p_fileopen );
299 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
304 on_popup_about_activate (GtkMenuItem *menuitem,
307 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
309 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
311 p_intf->p_sys->p_about = create_intf_about();
312 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
315 gtk_widget_show( p_intf->p_sys->p_about );
316 gdk_window_raise( p_intf->p_sys->p_about->window );
319 on_popup_slow_activate (GtkMenuItem *menuitem,
322 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
324 if( p_intf->p_input != NULL )
326 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
332 on_popup_fast_activate (GtkMenuItem *menuitem,
335 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
337 if( p_intf->p_input != NULL )
339 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
345 on_toolbar_slow_clicked (GtkButton *button,
348 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
350 if( p_intf->p_input != NULL )
352 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
358 on_toolbar_fast_clicked (GtkButton *button,
361 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
363 if( p_intf->p_input != NULL )
365 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
371 on_intf_modules_destroy (GtkObject *object,
379 on_modules_ok_clicked (GtkButton *button,
382 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
384 gtk_widget_hide( p_intf->p_sys->p_modules );
390 on_modules_apply_clicked (GtkButton *button,
398 on_modules_cancel_clicked (GtkButton *button,
401 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
403 gtk_widget_hide( p_intf->p_sys->p_modules );
407 on_menubar_modules_activate (GtkMenuItem *menuitem,
410 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
412 if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
414 // p_intf->p_sys->p_modules = create_intf_modules();
415 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
418 gtk_widget_show( p_intf->p_sys->p_modules );
419 gdk_window_raise( p_intf->p_sys->p_modules->window );
424 on_intf_window_drag_data_received (GtkWidget *widget,
425 GdkDragContext *drag_context,
428 GtkSelectionData *data,
433 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
434 int end = p_main->p_playlist->i_size;
435 on_generic_drop_data_received( p_intf, data, info, PLAYLIST_END);
437 if( p_intf->p_input != NULL )
439 /* FIXME: temporary hack */
440 p_intf->p_input->b_eof = 1;
443 intf_PlaylistJumpto( p_main->p_playlist, end-1 );
449 on_about_ok_clicked (GtkButton *button,
452 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
454 gtk_widget_hide( p_intf->p_sys->p_about );
459 on_menubar_disc_activate (GtkMenuItem *menuitem,
462 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
464 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
466 p_intf->p_sys->p_disc = create_intf_disc();
467 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
470 gtk_widget_show( p_intf->p_sys->p_disc );
471 gdk_window_raise( p_intf->p_sys->p_disc->window );
476 on_toolbar_disc_clicked (GtkButton *button,
479 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
481 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
483 p_intf->p_sys->p_disc = create_intf_disc();
484 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
487 gtk_widget_show( p_intf->p_sys->p_disc );
488 gdk_window_raise( p_intf->p_sys->p_disc->window );
493 on_disc_ok_clicked (GtkButton *button,
496 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
497 char *psz_device, *psz_source, *psz_method;
499 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
500 GTK_WIDGET(button), "disc_name" ) ) );
502 /* "dvd:foo" has size 5 + strlen(foo) */
503 psz_source = malloc( 5 + strlen( psz_device ) );
504 if( psz_source == NULL )
509 /* Check which method was activated */
510 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
511 "disc_dvd" ) )->active )
515 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
516 "disc_vcd" ) )->active )
522 intf_ErrMsg( "intf error: unknown toggle button configuration" );
527 /* Select title and chapter */
528 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
529 GTK_SPIN_BUTTON( lookup_widget(
530 GTK_WIDGET(button), "disc_title" ) ) ) );
532 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
533 GTK_SPIN_BUTTON( lookup_widget(
534 GTK_WIDGET(button), "disc_chapter" ) ) ) );
536 /* Build source name and add it to playlist */
537 sprintf( psz_source, "%s:%s", psz_method, psz_device );
538 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
540 gtk_widget_hide( p_intf->p_sys->p_disc );
545 on_disc_cancel_clicked (GtkButton *button,
548 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
550 gtk_widget_hide( p_intf->p_sys->p_disc );
555 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
558 if( togglebutton->active )
560 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
561 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
567 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
570 if( togglebutton->active )
572 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
573 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
579 on_popup_disc_activate (GtkMenuItem *menuitem,
582 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
584 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
586 p_intf->p_sys->p_disc = create_intf_disc();
587 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
590 gtk_widget_show( p_intf->p_sys->p_disc );
591 gdk_window_raise( p_intf->p_sys->p_disc->window );
595 on_popup_audio_activate (GtkMenuItem *menuitem,
598 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
599 es_descriptor_t * p_es;
601 p_es = (es_descriptor_t*)user_data;
603 input_ChangeES( p_intf->p_input, p_es, 1 );
608 on_popup_subpictures_activate (GtkMenuItem *menuitem,
611 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
612 es_descriptor_t * p_es;
614 p_es = (es_descriptor_t*)user_data;
616 input_ChangeES( p_intf->p_input, p_es, 2 );
621 on_menubar_audio_activate (GtkMenuItem *menuitem,
624 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
625 es_descriptor_t * p_es;
627 p_es = (es_descriptor_t*)user_data;
629 input_ChangeES( p_intf->p_input, p_es, 1 );
634 on_menubar_subpictures_activate (GtkMenuItem *menuitem,
637 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
638 es_descriptor_t * p_es;
640 p_es = (es_descriptor_t*)user_data;
642 input_ChangeES( p_intf->p_input, p_es, 2 );
647 on_popup_navigation_activate (GtkMenuItem *menuitem,
650 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
651 input_area_t * p_area;
655 i_title = (gint)(user_data) / 100 ;
656 i_chapter = (gint)(user_data) - ( 100 * i_title );
657 p_area = p_intf->p_input->stream.pp_areas[i_title];
658 p_area->i_part = i_chapter;
660 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
661 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
666 on_menubar_title_activate (GtkMenuItem *menuitem,
669 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
671 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)user_data );
672 p_intf->p_sys->b_menus_update = 1;
673 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
678 on_menubar_chapter_activate (GtkMenuItem *menuitem,
681 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
682 input_area_t * p_area = p_intf->p_input->stream.p_selected_area;
683 gint i_chapter = (gint)user_data;
685 p_area->i_part = i_chapter;
687 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
688 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
692 on_intf_window_destroy (GtkWidget *widget,
696 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
698 vlc_mutex_lock( &p_intf->change_lock );
700 vlc_mutex_unlock( &p_intf->change_lock );
707 on_main_window_toggle (GtkMenuItem *menuitem,
710 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
712 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) ) {
713 gtk_widget_hide( p_intf->p_sys->p_window);
718 gtk_widget_show( p_intf->p_sys->p_window );
724 on_playlist_clist_drag_motion (GtkWidget *widget,
725 GdkDragContext *drag_context,
735 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_playlist" );
738 clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"playlist_clist"
741 if(!GTK_WIDGET_TOPLEVEL(widget))
743 gdk_window_raise( p_intf->p_sys->p_playlist->window );
747 color.green = 0xffff;
750 gtk_clist_freeze( clist );
752 for(dummy=0; dummy<clist->rows; dummy++)
754 gtk_clist_set_background ( clist, dummy , &color);
759 gtk_clist_set_background ( clist, p_main->p_playlist->i_index , &color);
761 if( gtk_clist_get_selection_info( clist,x,y ,&row,&col )== 1)
764 color.green = 0x9000;
766 gtk_clist_set_background ( clist, row-1 , &color);
767 gtk_clist_set_background ( clist, row , &color);
770 gtk_clist_thaw( clist );
777 on_intf_network_destroy (GtkObject *object,
780 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_network" );
782 p_intf->p_sys->p_network = NULL;
787 on_network_ok_clicked (GtkButton *button,
790 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
791 char *psz_source, *psz_server, *psz_protocol;
794 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
795 GTK_WIDGET(button), "network_server" ) ) );
797 /* Check which protocol was activated */
798 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
799 "network_ts" ) )->active )
803 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
804 "network_rtp" ) )->active )
806 psz_protocol = "rtp";
810 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
814 /* Get the port number and make sure it will not overflow 5 characters */
815 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
816 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
819 intf_ErrMsg( "intf error: invalid port %i", i_port );
822 /* Allocate room for "protocol://server:port" */
823 psz_source = malloc( strlen( psz_protocol ) + strlen( psz_server ) + 10 );
824 if( psz_source == NULL )
829 /* Build source name and add it to playlist */
830 sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
831 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
834 gtk_widget_hide( p_intf->p_sys->p_network );
839 on_network_cancel_clicked (GtkButton *button,
842 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
847 on_menubar_network_activate (GtkMenuItem *menuitem,
850 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
852 gtk_widget_show( p_intf->p_sys->p_network );
853 gdk_window_raise( p_intf->p_sys->p_network->window );
858 on_popup_network_activate (GtkMenuItem *menuitem,
861 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
863 gtk_widget_show( p_intf->p_sys->p_network );
864 gdk_window_raise( p_intf->p_sys->p_network->window );
868 on_toolbar_network_clicked (GtkButton *button,
871 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
873 gtk_widget_show( p_intf->p_sys->p_network );
874 gdk_window_raise( p_intf->p_sys->p_network->window );
879 on_slider_button_release_event (GtkWidget *widget,
880 GdkEventButton *event,
883 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
885 vlc_mutex_lock( &p_intf->change_lock );
886 p_intf->p_sys->b_slider_free = 1;
887 vlc_mutex_unlock( &p_intf->change_lock );
894 on_slider_button_press_event (GtkWidget *widget,
895 GdkEventButton *event,
898 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
900 vlc_mutex_lock( &p_intf->change_lock );
901 p_intf->p_sys->b_slider_free = 0;
902 vlc_mutex_unlock( &p_intf->change_lock );