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_plst.h"
51 #include "gtk_callbacks.h"
52 #include "gtk_interface.h"
53 #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 /*****************************************************************************
66 * Inline function to retrieve the interface structure
67 *****************************************************************************/
68 static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
70 return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
74 /*****************************************************************************
76 ******************************************************************************/
78 on_menubar_open_activate (GtkMenuItem *menuitem,
81 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
83 /* If we have never used the file selector, open it */
84 if( p_intf->p_sys->p_fileopen == NULL)
86 p_intf->p_sys->p_fileopen = create_intf_fileopen();
87 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
91 gtk_widget_show( p_intf->p_sys->p_fileopen );
92 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
97 on_menubar_exit_activate (GtkMenuItem *menuitem,
100 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
106 on_menubar_preferences_activate (GtkMenuItem *menuitem,
114 on_menubar_about_activate (GtkMenuItem *menuitem,
117 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
119 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
121 p_intf->p_sys->p_about = create_intf_about();
122 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
125 gtk_widget_show( p_intf->p_sys->p_about );
126 gdk_window_raise( p_intf->p_sys->p_about->window );
131 on_toolbar_open_clicked (GtkButton *button,
134 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
136 /* If we have never used the file selector, open it */
137 if( p_intf->p_sys->p_fileopen == NULL)
139 p_intf->p_sys->p_fileopen = create_intf_fileopen();
140 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
144 gtk_widget_show( p_intf->p_sys->p_fileopen );
145 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
150 on_toolbar_back_clicked (GtkButton *button,
158 on_toolbar_stop_clicked (GtkButton *button,
166 on_toolbar_play_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_PLAY );
179 on_toolbar_pause_clicked (GtkButton *button,
182 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
184 if( p_intf->p_input != NULL )
186 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
191 on_toolbar_prev_clicked (GtkButton *button,
194 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
196 if( p_intf->p_input != NULL )
198 /* FIXME: temporary hack */
199 intf_PlstPrev( p_main->p_playlist );
200 intf_PlstPrev( p_main->p_playlist );
201 p_intf->p_input->b_eof = 1;
207 on_toolbar_next_clicked (GtkButton *button,
210 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
212 if( p_intf->p_input != NULL )
214 /* FIXME: temporary hack */
215 p_intf->p_input->b_eof = 1;
221 on_popup_play_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_PLAY );
234 on_popup_pause_activate (GtkMenuItem *menuitem,
237 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
239 if( p_intf->p_input != NULL )
241 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
247 on_popup_exit_activate (GtkMenuItem *menuitem,
250 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
256 on_fileopen_ok_clicked (GtkButton *button,
262 filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
263 gtk_widget_hide (filesel);
264 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
266 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
271 on_fileopen_cancel_clicked (GtkButton *button,
274 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
279 on_intf_fileopen_destroy (GtkObject *object,
282 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
284 p_intf->p_sys->p_fileopen = NULL;
289 on_popup_open_activate (GtkMenuItem *menuitem,
292 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
294 /* If we have never used the file selector, open it */
295 if( p_intf->p_sys->p_fileopen == NULL)
297 p_intf->p_sys->p_fileopen = create_intf_fileopen();
298 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
302 gtk_widget_show( p_intf->p_sys->p_fileopen );
303 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
308 on_popup_about_activate (GtkMenuItem *menuitem,
311 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
313 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
315 p_intf->p_sys->p_about = create_intf_about();
316 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
319 gtk_widget_show( p_intf->p_sys->p_about );
320 gdk_window_raise( p_intf->p_sys->p_about->window );
323 on_popup_slow_activate (GtkMenuItem *menuitem,
326 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
328 if( p_intf->p_input != NULL )
330 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
336 on_popup_fast_activate (GtkMenuItem *menuitem,
339 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
341 if( p_intf->p_input != NULL )
343 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
349 on_toolbar_slow_clicked (GtkButton *button,
352 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
354 if( p_intf->p_input != NULL )
356 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
362 on_toolbar_fast_clicked (GtkButton *button,
365 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
367 if( p_intf->p_input != NULL )
369 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
375 on_hscale_button_release_event (GtkWidget *widget,
376 GdkEventButton *event,
379 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
381 GtkAdjustment *p_adj = gtk_range_get_adjustment( GTK_RANGE(widget) );
384 vlc_mutex_lock( &p_intf->p_sys->change_lock );
386 if( p_intf->p_input != NULL )
388 i_seek = (p_adj->value *
389 p_intf->p_input->stream.p_selected_area->i_size) / 100;
390 input_Seek( p_intf->p_input, i_seek );
392 p_intf->p_sys->b_scale_isfree = 1;
394 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
401 on_hscale_button_press_event (GtkWidget *widget,
402 GdkEventButton *event,
405 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
407 vlc_mutex_lock( &p_intf->p_sys->change_lock );
408 p_intf->p_sys->b_scale_isfree = 0;
409 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
417 on_intf_modules_destroy (GtkObject *object,
425 on_modules_ok_clicked (GtkButton *button,
428 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
430 gtk_widget_hide( p_intf->p_sys->p_modules );
436 on_modules_apply_clicked (GtkButton *button,
444 on_modules_cancel_clicked (GtkButton *button,
447 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
449 gtk_widget_hide( p_intf->p_sys->p_modules );
453 on_menubar_modules_activate (GtkMenuItem *menuitem,
456 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
458 if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
460 // p_intf->p_sys->p_modules = create_intf_modules();
461 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
464 gtk_widget_show( p_intf->p_sys->p_modules );
465 gdk_window_raise( p_intf->p_sys->p_modules->window );
470 on_intf_window_drag_data_received (GtkWidget *widget,
471 GdkDragContext *drag_context,
474 GtkSelectionData *data,
479 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
480 on_generic_drop_data_received( p_intf, data, info, 0);
481 if( p_intf->p_input != NULL )
483 /* FIXME: temporary hack */
484 p_intf->p_input->b_eof = 1;
487 intf_PlstJumpto( p_main->p_playlist, -1 );
493 on_about_ok_clicked (GtkButton *button,
496 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
498 gtk_widget_hide( p_intf->p_sys->p_about );
503 on_menubar_disc_activate (GtkMenuItem *menuitem,
506 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
508 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
510 p_intf->p_sys->p_disc = create_intf_disc();
511 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
514 gtk_widget_show( p_intf->p_sys->p_disc );
515 gdk_window_raise( p_intf->p_sys->p_disc->window );
520 on_toolbar_disc_clicked (GtkButton *button,
523 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
525 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
527 p_intf->p_sys->p_disc = create_intf_disc();
528 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
531 gtk_widget_show( p_intf->p_sys->p_disc );
532 gdk_window_raise( p_intf->p_sys->p_disc->window );
537 on_disc_ok_clicked (GtkButton *button,
540 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
541 char *psz_device, *psz_source, *psz_method;
543 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
544 GTK_WIDGET(button), "disc_name" ) ) );
546 /* "dvd:foo" has size 5 + strlen(foo) */
547 psz_source = malloc( 5 + strlen( psz_device ) );
548 if( psz_source == NULL )
553 /* Check which method was activated */
554 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
555 "disc_dvd" ) )->active )
559 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
560 "disc_vcd" ) )->active )
566 intf_ErrMsg( "intf error: unknown toggle button configuration" );
571 /* Select title and chapter */
572 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
573 GTK_SPIN_BUTTON( lookup_widget(
574 GTK_WIDGET(button), "disc_title" ) ) ) );
576 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
577 GTK_SPIN_BUTTON( lookup_widget(
578 GTK_WIDGET(button), "disc_chapter" ) ) ) );
580 /* Build source name and add it to playlist */
581 sprintf( psz_source, "%s:%s", psz_method, psz_device );
582 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
584 gtk_widget_hide( p_intf->p_sys->p_disc );
589 on_disc_cancel_clicked (GtkButton *button,
592 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
594 gtk_widget_hide( p_intf->p_sys->p_disc );
599 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
602 if( togglebutton->active )
604 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
605 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
611 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
614 if( togglebutton->active )
616 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
617 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
623 on_popup_disc_activate (GtkMenuItem *menuitem,
626 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
628 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
630 p_intf->p_sys->p_disc = create_intf_disc();
631 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
634 gtk_widget_show( p_intf->p_sys->p_disc );
635 gdk_window_raise( p_intf->p_sys->p_disc->window );
639 on_popup_audio_activate (GtkMenuItem *menuitem,
642 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
643 es_descriptor_t * p_es;
645 p_es = (es_descriptor_t*)user_data;
647 input_ChangeES( p_intf->p_input, p_es, 1 );
652 on_popup_subpictures_activate (GtkMenuItem *menuitem,
655 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
656 es_descriptor_t * p_es;
658 p_es = (es_descriptor_t*)user_data;
660 input_ChangeES( p_intf->p_input, p_es, 2 );
665 on_menubar_audio_activate (GtkMenuItem *menuitem,
668 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
669 es_descriptor_t * p_es;
671 p_es = (es_descriptor_t*)user_data;
673 input_ChangeES( p_intf->p_input, p_es, 1 );
678 on_menubar_subpictures_activate (GtkMenuItem *menuitem,
681 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
682 es_descriptor_t * p_es;
684 p_es = (es_descriptor_t*)user_data;
686 input_ChangeES( p_intf->p_input, p_es, 2 );
691 on_popup_navigation_activate (GtkMenuItem *menuitem,
694 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
695 input_area_t * p_area;
699 i_title = (gint)(user_data) / 100 ;
700 i_chapter = (gint)(user_data) - ( 100 * i_title );
701 p_area = p_intf->p_input->stream.pp_areas[i_title];
702 p_area->i_part = i_chapter;
704 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
705 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
710 on_menubar_title_activate (GtkMenuItem *menuitem,
713 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
715 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)user_data );
716 p_intf->p_sys->b_menus_update = 1;
717 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
722 on_menubar_chapter_activate (GtkMenuItem *menuitem,
725 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
726 input_area_t * p_area = p_intf->p_input->stream.p_selected_area;
727 gint i_chapter = (gint)user_data;
729 p_area->i_part = i_chapter;
731 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
732 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
736 on_intf_window_destroy (GtkWidget *widget,
740 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
741 /* is there an output thread ? */
742 if(p_main->b_video == 1)
744 gtk_widget_hide(widget);
747 gtk_widget_destroy(widget);
754 on_main_window_toggle (GtkMenuItem *menuitem,
757 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
759 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) ) {
760 gtk_widget_hide( p_intf->p_sys->p_window);
763 gtk_widget_show( p_intf->p_sys->p_window );