1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
7 * Stéphane Borel <stef@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 #define MODULE_NAME gtk
25 #include "modules_inner.h"
27 /*****************************************************************************
29 *****************************************************************************/
43 #include "stream_control.h"
44 #include "input_ext-intf.h"
46 #include "interface.h"
47 #include "intf_playlist.h"
50 #include "gtk_callbacks.h"
51 #include "gtk_interface.h"
52 #include "gtk_support.h"
57 /****************************************************************************
60 void on_generic_drop_data_received( intf_thread_t * p_intf,
61 GtkSelectionData *data, guint info, int position);
65 /*****************************************************************************
67 ******************************************************************************/
69 on_menubar_open_activate (GtkMenuItem *menuitem,
72 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
74 /* If we have never used the file selector, open it */
75 if( p_intf->p_sys->p_fileopen == NULL)
77 p_intf->p_sys->p_fileopen = create_intf_fileopen();
78 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
82 gtk_widget_show( p_intf->p_sys->p_fileopen );
83 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
88 on_menubar_exit_activate (GtkMenuItem *menuitem,
91 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
93 vlc_mutex_lock( &p_intf->change_lock );
95 vlc_mutex_unlock( &p_intf->change_lock );
99 on_menubar_preferences_activate (GtkMenuItem *menuitem,
107 on_menubar_about_activate (GtkMenuItem *menuitem,
110 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
112 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
114 p_intf->p_sys->p_about = create_intf_about();
115 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
118 gtk_widget_show( p_intf->p_sys->p_about );
119 gdk_window_raise( p_intf->p_sys->p_about->window );
124 on_toolbar_open_clicked (GtkButton *button,
127 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
129 /* If we have never used the file selector, open it */
130 if( p_intf->p_sys->p_fileopen == NULL)
132 p_intf->p_sys->p_fileopen = create_intf_fileopen();
133 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
137 gtk_widget_show( p_intf->p_sys->p_fileopen );
138 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
143 on_toolbar_back_clicked (GtkButton *button,
151 on_toolbar_stop_clicked (GtkButton *button,
159 on_toolbar_play_clicked (GtkButton *button,
162 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
164 if( p_intf->p_input != NULL )
166 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
172 on_toolbar_pause_clicked (GtkButton *button,
175 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
177 if( p_intf->p_input != NULL )
179 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
184 on_toolbar_prev_clicked (GtkButton *button,
187 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
189 if( p_intf->p_input != NULL )
191 /* FIXME: temporary hack */
192 intf_PlaylistPrev( p_main->p_playlist );
193 intf_PlaylistPrev( p_main->p_playlist );
194 p_intf->p_input->b_eof = 1;
200 on_toolbar_next_clicked (GtkButton *button,
203 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
205 if( p_intf->p_input != NULL )
207 /* FIXME: temporary hack */
208 p_intf->p_input->b_eof = 1;
214 on_popup_play_activate (GtkMenuItem *menuitem,
217 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
219 if( p_intf->p_input != NULL )
221 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
227 on_popup_pause_activate (GtkMenuItem *menuitem,
230 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
232 if( p_intf->p_input != NULL )
234 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
240 on_popup_exit_activate (GtkMenuItem *menuitem,
243 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
245 vlc_mutex_lock( &p_intf->change_lock );
247 vlc_mutex_unlock( &p_intf->change_lock );
251 on_fileopen_ok_clicked (GtkButton *button,
257 filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
258 gtk_widget_hide (filesel);
259 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
261 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
266 on_fileopen_cancel_clicked (GtkButton *button,
269 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
274 on_intf_fileopen_destroy (GtkObject *object,
277 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
279 p_intf->p_sys->p_fileopen = NULL;
284 on_popup_open_activate (GtkMenuItem *menuitem,
287 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
289 /* If we have never used the file selector, open it */
290 if( p_intf->p_sys->p_fileopen == NULL)
292 p_intf->p_sys->p_fileopen = create_intf_fileopen();
293 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
297 gtk_widget_show( p_intf->p_sys->p_fileopen );
298 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
303 on_popup_about_activate (GtkMenuItem *menuitem,
306 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
308 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
310 p_intf->p_sys->p_about = create_intf_about();
311 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
314 gtk_widget_show( p_intf->p_sys->p_about );
315 gdk_window_raise( p_intf->p_sys->p_about->window );
318 on_popup_slow_activate (GtkMenuItem *menuitem,
321 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
323 if( p_intf->p_input != NULL )
325 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
331 on_popup_fast_activate (GtkMenuItem *menuitem,
334 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
336 if( p_intf->p_input != NULL )
338 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
344 on_toolbar_slow_clicked (GtkButton *button,
347 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
349 if( p_intf->p_input != NULL )
351 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
357 on_toolbar_fast_clicked (GtkButton *button,
360 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
362 if( p_intf->p_input != NULL )
364 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
370 on_intf_modules_destroy (GtkObject *object,
378 on_modules_ok_clicked (GtkButton *button,
381 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
383 gtk_widget_hide( p_intf->p_sys->p_modules );
389 on_modules_apply_clicked (GtkButton *button,
397 on_modules_cancel_clicked (GtkButton *button,
400 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
402 gtk_widget_hide( p_intf->p_sys->p_modules );
406 on_menubar_modules_activate (GtkMenuItem *menuitem,
409 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
411 if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
413 // p_intf->p_sys->p_modules = create_intf_modules();
414 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
417 gtk_widget_show( p_intf->p_sys->p_modules );
418 gdk_window_raise( p_intf->p_sys->p_modules->window );
423 on_intf_window_drag_data_received (GtkWidget *widget,
424 GdkDragContext *drag_context,
427 GtkSelectionData *data,
432 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
433 int end = p_main->p_playlist->i_size;
434 on_generic_drop_data_received( p_intf, data, info, PLAYLIST_END);
436 if( p_intf->p_input != NULL )
438 /* FIXME: temporary hack */
439 p_intf->p_input->b_eof = 1;
442 intf_PlaylistJumpto( p_main->p_playlist, end-1 );
448 on_about_ok_clicked (GtkButton *button,
451 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
453 gtk_widget_hide( p_intf->p_sys->p_about );
458 on_menubar_disc_activate (GtkMenuItem *menuitem,
461 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
463 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
465 p_intf->p_sys->p_disc = create_intf_disc();
466 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
469 gtk_widget_show( p_intf->p_sys->p_disc );
470 gdk_window_raise( p_intf->p_sys->p_disc->window );
475 on_toolbar_disc_clicked (GtkButton *button,
478 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
480 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
482 p_intf->p_sys->p_disc = create_intf_disc();
483 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
486 gtk_widget_show( p_intf->p_sys->p_disc );
487 gdk_window_raise( p_intf->p_sys->p_disc->window );
492 on_disc_ok_clicked (GtkButton *button,
495 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
496 char *psz_device, *psz_source, *psz_method;
498 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
499 GTK_WIDGET(button), "disc_name" ) ) );
501 /* "dvd:foo" has size 5 + strlen(foo) */
502 psz_source = malloc( 5 + strlen( psz_device ) );
503 if( psz_source == NULL )
508 /* Check which method was activated */
509 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
510 "disc_dvd" ) )->active )
514 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
515 "disc_vcd" ) )->active )
521 intf_ErrMsg( "intf error: unknown toggle button configuration" );
526 /* Select title and chapter */
527 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
528 GTK_SPIN_BUTTON( lookup_widget(
529 GTK_WIDGET(button), "disc_title" ) ) ) );
531 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
532 GTK_SPIN_BUTTON( lookup_widget(
533 GTK_WIDGET(button), "disc_chapter" ) ) ) );
535 /* Build source name and add it to playlist */
536 sprintf( psz_source, "%s:%s", psz_method, psz_device );
537 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
539 gtk_widget_hide( p_intf->p_sys->p_disc );
544 on_disc_cancel_clicked (GtkButton *button,
547 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
549 gtk_widget_hide( p_intf->p_sys->p_disc );
554 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
557 if( togglebutton->active )
559 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
560 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
566 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
569 if( togglebutton->active )
571 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
572 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
578 on_popup_disc_activate (GtkMenuItem *menuitem,
581 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
583 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
585 p_intf->p_sys->p_disc = create_intf_disc();
586 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
589 gtk_widget_show( p_intf->p_sys->p_disc );
590 gdk_window_raise( p_intf->p_sys->p_disc->window );
594 on_popup_audio_activate (GtkMenuItem *menuitem,
597 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
598 es_descriptor_t * p_es;
600 p_es = (es_descriptor_t*)user_data;
602 input_ChangeES( p_intf->p_input, p_es, 1 );
607 on_popup_subpictures_activate (GtkMenuItem *menuitem,
610 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
611 es_descriptor_t * p_es;
613 p_es = (es_descriptor_t*)user_data;
615 input_ChangeES( p_intf->p_input, p_es, 2 );
620 on_menubar_audio_activate (GtkMenuItem *menuitem,
623 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
624 es_descriptor_t * p_es;
626 p_es = (es_descriptor_t*)user_data;
628 input_ChangeES( p_intf->p_input, p_es, 1 );
633 on_menubar_subpictures_activate (GtkMenuItem *menuitem,
636 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
637 es_descriptor_t * p_es;
639 p_es = (es_descriptor_t*)user_data;
641 input_ChangeES( p_intf->p_input, p_es, 2 );
646 on_popup_navigation_activate (GtkMenuItem *menuitem,
649 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
650 input_area_t * p_area;
654 i_title = (gint)(user_data) / 100 ;
655 i_chapter = (gint)(user_data) - ( 100 * i_title );
656 p_area = p_intf->p_input->stream.pp_areas[i_title];
657 p_area->i_part = i_chapter;
659 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
660 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
665 on_menubar_title_activate (GtkMenuItem *menuitem,
668 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
670 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)user_data );
671 p_intf->p_sys->b_menus_update = 1;
672 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
677 on_menubar_chapter_activate (GtkMenuItem *menuitem,
680 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
681 input_area_t * p_area = p_intf->p_input->stream.p_selected_area;
682 gint i_chapter = (gint)user_data;
684 p_area->i_part = i_chapter;
686 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
687 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
691 on_intf_window_destroy (GtkWidget *widget,
695 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
697 vlc_mutex_lock( &p_intf->change_lock );
699 vlc_mutex_unlock( &p_intf->change_lock );
706 on_main_window_toggle (GtkMenuItem *menuitem,
709 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
711 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) ) {
712 gtk_widget_hide( p_intf->p_sys->p_window);
717 gtk_widget_show( p_intf->p_sys->p_window );
723 on_playlist_clist_drag_motion (GtkWidget *widget,
724 GdkDragContext *drag_context,
734 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_playlist" );
737 clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"playlist_clist"
740 if(!GTK_WIDGET_TOPLEVEL(widget))
742 gdk_window_raise( p_intf->p_sys->p_playlist->window );
746 color.green = 0xffff;
749 gtk_clist_freeze( clist );
751 for(dummy=0; dummy<clist->rows; dummy++)
753 gtk_clist_set_background ( clist, dummy , &color);
758 gtk_clist_set_background ( clist, p_main->p_playlist->i_index , &color);
760 if( gtk_clist_get_selection_info( clist,x,y ,&row,&col )== 1)
763 color.green = 0x9000;
765 gtk_clist_set_background ( clist, row-1 , &color);
766 gtk_clist_set_background ( clist, row , &color);
769 gtk_clist_thaw( clist );
776 on_intf_network_destroy (GtkObject *object,
779 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_network" );
781 p_intf->p_sys->p_network = NULL;
786 on_network_ok_clicked (GtkButton *button,
789 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
790 char *psz_source, *psz_server, *psz_protocol;
793 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
794 GTK_WIDGET(button), "network_server" ) ) );
796 /* Check which protocol was activated */
797 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
798 "network_ts" ) )->active )
802 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
803 "network_rtp" ) )->active )
805 psz_protocol = "rtp";
809 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
813 /* Get the port number and make sure it will not overflow 5 characters */
814 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
815 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
818 intf_ErrMsg( "intf error: invalid port %i", i_port );
821 /* Allocate room for "protocol://server:port" */
822 psz_source = malloc( strlen( psz_protocol ) + strlen( psz_server ) + 10 );
823 if( psz_source == NULL )
828 /* Build source name and add it to playlist */
829 sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
830 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
833 gtk_widget_hide( p_intf->p_sys->p_network );
838 on_network_cancel_clicked (GtkButton *button,
841 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
846 on_menubar_network_activate (GtkMenuItem *menuitem,
849 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
851 gtk_widget_show( p_intf->p_sys->p_network );
852 gdk_window_raise( p_intf->p_sys->p_network->window );
857 on_popup_network_activate (GtkMenuItem *menuitem,
860 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
862 gtk_widget_show( p_intf->p_sys->p_network );
863 gdk_window_raise( p_intf->p_sys->p_network->window );
867 on_toolbar_network_clicked (GtkButton *button,
870 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
872 gtk_widget_show( p_intf->p_sys->p_network );
873 gdk_window_raise( p_intf->p_sys->p_network->window );
878 on_slider_button_release_event (GtkWidget *widget,
879 GdkEventButton *event,
882 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
884 vlc_mutex_lock( &p_intf->change_lock );
885 p_intf->p_sys->b_slider_free = 1;
886 vlc_mutex_unlock( &p_intf->change_lock );
893 on_slider_button_press_event (GtkWidget *widget,
894 GdkEventButton *event,
897 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
899 vlc_mutex_lock( &p_intf->change_lock );
900 p_intf->p_sys->b_slider_free = 0;
901 vlc_mutex_unlock( &p_intf->change_lock );