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 *****************************************************************************/
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
44 #include "interface.h"
45 #include "intf_plst.h"
49 #include "gtk_callbacks.h"
50 #include "gtk_interface.h"
51 #include "gtk_support.h"
55 /*****************************************************************************
56 * Inline function to retrieve the interface structure
57 *****************************************************************************/
58 static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
60 return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
64 /*****************************************************************************
66 ******************************************************************************/
68 on_menubar_open_activate (GtkMenuItem *menuitem,
71 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
73 /* If we have never used the file selector, open it */
74 if( p_intf->p_sys->p_fileopen == NULL)
76 p_intf->p_sys->p_fileopen = create_intf_fileopen();
77 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
81 gtk_widget_show( p_intf->p_sys->p_fileopen );
82 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
87 on_menubar_exit_activate (GtkMenuItem *menuitem,
90 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
97 on_menubar_playlist_activate (GtkMenuItem *menuitem,
100 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
102 if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
104 // p_intf->p_sys->p_playlist = create_intf_playlist();
105 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
108 gtk_widget_show( p_intf->p_sys->p_playlist );
109 gdk_window_raise( p_intf->p_sys->p_playlist->window );
114 on_menubar_preferences_activate (GtkMenuItem *menuitem,
122 on_menubar_about_activate (GtkMenuItem *menuitem,
125 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
127 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
129 p_intf->p_sys->p_about = create_intf_about();
130 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
133 gtk_widget_show( p_intf->p_sys->p_about );
134 gdk_window_raise( p_intf->p_sys->p_about->window );
139 on_toolbar_open_clicked (GtkButton *button,
142 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
144 /* If we have never used the file selector, open it */
145 if( p_intf->p_sys->p_fileopen == NULL)
147 p_intf->p_sys->p_fileopen = create_intf_fileopen();
148 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
152 gtk_widget_show( p_intf->p_sys->p_fileopen );
153 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
158 on_toolbar_back_clicked (GtkButton *button,
166 on_toolbar_stop_clicked (GtkButton *button,
174 on_toolbar_play_clicked (GtkButton *button,
177 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
179 if( p_intf->p_input != NULL )
181 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
187 on_toolbar_pause_clicked (GtkButton *button,
190 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
192 if( p_intf->p_input != NULL )
194 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
200 on_toolbar_playlist_clicked (GtkButton *button,
203 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
205 if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
207 // p_intf->p_sys->p_playlist = create_intf_playlist();
208 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
211 gtk_widget_show( p_intf->p_sys->p_playlist );
212 gdk_window_raise( p_intf->p_sys->p_playlist->window );
217 on_toolbar_prev_clicked (GtkButton *button,
220 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
222 if( p_intf->p_input != NULL )
224 /* FIXME: temporary hack */
225 intf_PlstPrev( p_main->p_playlist );
226 intf_PlstPrev( p_main->p_playlist );
227 p_intf->p_input->b_eof = 1;
233 on_toolbar_next_clicked (GtkButton *button,
236 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
238 if( p_intf->p_input != NULL )
240 /* FIXME: temporary hack */
241 p_intf->p_input->b_eof = 1;
247 on_popup_play_activate (GtkMenuItem *menuitem,
250 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
252 if( p_intf->p_input != NULL )
254 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
260 on_popup_pause_activate (GtkMenuItem *menuitem,
263 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
265 if( p_intf->p_input != NULL )
267 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
273 on_popup_exit_activate (GtkMenuItem *menuitem,
276 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
283 on_intf_window_destroy (GtkObject *object,
286 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
288 /* FIXME don't destroy the window, just hide it */
290 p_intf->p_sys->p_window = NULL;
295 on_fileopen_ok_clicked (GtkButton *button,
301 filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
302 gtk_widget_hide (filesel);
303 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
305 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
310 on_fileopen_cancel_clicked (GtkButton *button,
313 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
318 on_intf_fileopen_destroy (GtkObject *object,
321 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
323 p_intf->p_sys->p_fileopen = NULL;
328 on_popup_open_activate (GtkMenuItem *menuitem,
331 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
333 /* If we have never used the file selector, open it */
334 if( p_intf->p_sys->p_fileopen == NULL)
336 p_intf->p_sys->p_fileopen = create_intf_fileopen();
337 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
341 gtk_widget_show( p_intf->p_sys->p_fileopen );
342 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
347 on_popup_about_activate (GtkMenuItem *menuitem,
350 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
352 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
354 p_intf->p_sys->p_about = create_intf_about();
355 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
358 gtk_widget_show( p_intf->p_sys->p_about );
359 gdk_window_raise( p_intf->p_sys->p_about->window );
364 on_intf_playlist_destroy (GtkObject *object,
367 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
369 p_intf->p_sys->p_playlist = NULL;
374 on_playlist_close_clicked (GtkButton *button,
377 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
382 on_popup_slow_activate (GtkMenuItem *menuitem,
385 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
387 if( p_intf->p_input != NULL )
389 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
395 on_popup_fast_activate (GtkMenuItem *menuitem,
398 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
400 if( p_intf->p_input != NULL )
402 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
408 on_toolbar_slow_clicked (GtkButton *button,
411 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
413 if( p_intf->p_input != NULL )
415 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
421 on_toolbar_fast_clicked (GtkButton *button,
424 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
426 if( p_intf->p_input != NULL )
428 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
434 on_hscale_button_release_event (GtkWidget *widget,
435 GdkEventButton *event,
438 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
440 GtkAdjustment *p_adj = gtk_range_get_adjustment( GTK_RANGE(widget) );
443 vlc_mutex_lock( &p_intf->p_sys->change_lock );
445 if( p_intf->p_input != NULL )
447 i_seek = (p_adj->value *
448 p_intf->p_input->stream.p_selected_area->i_size) / 100;
449 input_Seek( p_intf->p_input, i_seek );
451 p_intf->p_sys->b_scale_isfree = 1;
453 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
460 on_hscale_button_press_event (GtkWidget *widget,
461 GdkEventButton *event,
464 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
466 vlc_mutex_lock( &p_intf->p_sys->change_lock );
467 p_intf->p_sys->b_scale_isfree = 0;
468 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
476 on_intf_modules_destroy (GtkObject *object,
484 on_modules_ok_clicked (GtkButton *button,
487 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
489 gtk_widget_hide( p_intf->p_sys->p_modules );
495 on_modules_apply_clicked (GtkButton *button,
503 on_modules_cancel_clicked (GtkButton *button,
506 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
508 gtk_widget_hide( p_intf->p_sys->p_modules );
513 on_playlist_ok_clicked (GtkButton *button,
516 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_playlist" );
518 gtk_widget_hide( p_intf->p_sys->p_playlist );
523 on_menubar_modules_activate (GtkMenuItem *menuitem,
526 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
528 if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
530 // p_intf->p_sys->p_modules = create_intf_modules();
531 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
534 gtk_widget_show( p_intf->p_sys->p_modules );
535 gdk_window_raise( p_intf->p_sys->p_modules->window );
540 on_intf_window_drag_data_received (GtkWidget *widget,
541 GdkDragContext *drag_context,
544 GtkSelectionData *data,
549 char *psz_text = data->data;
550 int i_len = strlen( psz_text );
554 case DROP_ACCEPT_TEXT_PLAIN: /* FIXME: handle multiple files */
561 /* get rid of ' ' at the end */
562 *( psz_text + i_len - 1 ) = 0;
564 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
565 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
569 case DROP_ACCEPT_TEXT_URI_LIST: /* FIXME: handle multiple files */
576 /* get rid of \r\n at the end */
577 *( psz_text + i_len - 2 ) = 0;
579 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
580 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
585 intf_ErrMsg( "intf error: unknown dropped type");
592 on_about_ok_clicked (GtkButton *button,
595 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
597 gtk_widget_hide( p_intf->p_sys->p_about );
602 on_menubar_disc_activate (GtkMenuItem *menuitem,
605 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
607 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
609 p_intf->p_sys->p_disc = create_intf_disc();
610 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
613 gtk_widget_show( p_intf->p_sys->p_disc );
614 gdk_window_raise( p_intf->p_sys->p_disc->window );
619 on_toolbar_disc_clicked (GtkButton *button,
622 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
624 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
626 p_intf->p_sys->p_disc = create_intf_disc();
627 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
630 gtk_widget_show( p_intf->p_sys->p_disc );
631 gdk_window_raise( p_intf->p_sys->p_disc->window );
636 on_disc_ok_clicked (GtkButton *button,
639 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
640 char *psz_device, *psz_source, *psz_method;
642 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
643 GTK_WIDGET(button), "disc_name" ) ) );
645 /* "dvd:foo" has size 5 + strlen(foo) */
646 psz_source = malloc( 5 + strlen( psz_device ) );
647 if( psz_source == NULL )
652 /* Check which method was activated */
653 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
654 "disc_dvd" ) )->active )
658 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
659 "disc_vcd" ) )->active )
665 intf_ErrMsg( "intf error: unknown toggle button configuration" );
670 /* Select title and chapter */
671 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
672 GTK_SPIN_BUTTON( lookup_widget(
673 GTK_WIDGET(button), "disc_title" ) ) ) );
675 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
676 GTK_SPIN_BUTTON( lookup_widget(
677 GTK_WIDGET(button), "disc_chapter" ) ) ) );
679 /* Build source name and add it to playlist */
680 sprintf( psz_source, "%s:%s", psz_method, psz_device );
681 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
683 gtk_widget_hide( p_intf->p_sys->p_disc );
688 on_disc_cancel_clicked (GtkButton *button,
691 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
693 gtk_widget_hide( p_intf->p_sys->p_disc );
698 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
701 if( togglebutton->active )
703 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
704 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
710 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
713 if( togglebutton->active )
715 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
716 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
722 on_popup_disc_activate (GtkMenuItem *menuitem,
725 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
727 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
729 p_intf->p_sys->p_disc = create_intf_disc();
730 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
733 gtk_widget_show( p_intf->p_sys->p_disc );
734 gdk_window_raise( p_intf->p_sys->p_disc->window );
739 on_popup_audio_activate (GtkMenuItem *menuitem,
742 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
743 es_descriptor_t * p_es;
745 p_es = (es_descriptor_t*)user_data;
747 input_ChangeES( p_intf->p_input, p_es, 1 );
752 on_popup_subpictures_activate (GtkMenuItem *menuitem,
755 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
756 es_descriptor_t * p_es;
758 p_es = (es_descriptor_t*)user_data;
760 input_ChangeES( p_intf->p_input, p_es, 2 );
765 on_menubar_audio_activate (GtkMenuItem *menuitem,
768 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
769 es_descriptor_t * p_es;
771 p_es = (es_descriptor_t*)user_data;
773 input_ChangeES( p_intf->p_input, p_es, 1 );
778 on_menubar_subpictures_activate (GtkMenuItem *menuitem,
781 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
782 es_descriptor_t * p_es;
784 p_es = (es_descriptor_t*)user_data;
786 input_ChangeES( p_intf->p_input, p_es, 2 );
791 on_popup_navigation_activate (GtkMenuItem *menuitem,
794 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
795 input_area_t * p_area;
799 i_title = (gint)(user_data) / 100 ;
800 i_chapter = (gint)(user_data) - ( 100 * i_title );
801 fprintf(stderr, "title %d chapter %d\n", i_title, i_chapter );
802 p_area = p_intf->p_input->stream.pp_areas[i_title];
803 p_area->i_part = i_chapter;
805 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
806 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
811 on_menubar_title_activate (GtkMenuItem *menuitem,
814 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
816 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)user_data );
817 p_intf->p_sys->b_menus_update = 1;
818 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
823 on_menubar_chapter_activate (GtkMenuItem *menuitem,
826 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
827 input_area_t * p_area = p_intf->p_input->stream.p_selected_area;
828 gint i_chapter = (gint)user_data;
830 p_area->i_part = i_chapter;
832 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
833 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );