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);
482 if( p_intf->p_input != NULL )
484 /* FIXME: temporary hack */
485 p_intf->p_input->b_eof = 1;
488 intf_PlstJumpto( p_main->p_playlist, -1 );
494 on_about_ok_clicked (GtkButton *button,
497 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
499 gtk_widget_hide( p_intf->p_sys->p_about );
504 on_menubar_disc_activate (GtkMenuItem *menuitem,
507 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
509 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
511 p_intf->p_sys->p_disc = create_intf_disc();
512 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
515 gtk_widget_show( p_intf->p_sys->p_disc );
516 gdk_window_raise( p_intf->p_sys->p_disc->window );
521 on_toolbar_disc_clicked (GtkButton *button,
524 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
526 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
528 p_intf->p_sys->p_disc = create_intf_disc();
529 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
532 gtk_widget_show( p_intf->p_sys->p_disc );
533 gdk_window_raise( p_intf->p_sys->p_disc->window );
538 on_disc_ok_clicked (GtkButton *button,
541 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
542 char *psz_device, *psz_source, *psz_method;
544 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
545 GTK_WIDGET(button), "disc_name" ) ) );
547 /* "dvd:foo" has size 5 + strlen(foo) */
548 psz_source = malloc( 5 + strlen( psz_device ) );
549 if( psz_source == NULL )
554 /* Check which method was activated */
555 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
556 "disc_dvd" ) )->active )
560 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
561 "disc_vcd" ) )->active )
567 intf_ErrMsg( "intf error: unknown toggle button configuration" );
572 /* Select title and chapter */
573 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
574 GTK_SPIN_BUTTON( lookup_widget(
575 GTK_WIDGET(button), "disc_title" ) ) ) );
577 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
578 GTK_SPIN_BUTTON( lookup_widget(
579 GTK_WIDGET(button), "disc_chapter" ) ) ) );
581 /* Build source name and add it to playlist */
582 sprintf( psz_source, "%s:%s", psz_method, psz_device );
583 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
585 gtk_widget_hide( p_intf->p_sys->p_disc );
590 on_disc_cancel_clicked (GtkButton *button,
593 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
595 gtk_widget_hide( p_intf->p_sys->p_disc );
600 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
603 if( togglebutton->active )
605 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
606 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
612 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
615 if( togglebutton->active )
617 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
618 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
624 on_popup_disc_activate (GtkMenuItem *menuitem,
627 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
629 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
631 p_intf->p_sys->p_disc = create_intf_disc();
632 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
635 gtk_widget_show( p_intf->p_sys->p_disc );
636 gdk_window_raise( p_intf->p_sys->p_disc->window );
640 on_popup_audio_activate (GtkMenuItem *menuitem,
643 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
644 es_descriptor_t * p_es;
646 p_es = (es_descriptor_t*)user_data;
648 input_ChangeES( p_intf->p_input, p_es, 1 );
653 on_popup_subpictures_activate (GtkMenuItem *menuitem,
656 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
657 es_descriptor_t * p_es;
659 p_es = (es_descriptor_t*)user_data;
661 input_ChangeES( p_intf->p_input, p_es, 2 );
666 on_menubar_audio_activate (GtkMenuItem *menuitem,
669 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
670 es_descriptor_t * p_es;
672 p_es = (es_descriptor_t*)user_data;
674 input_ChangeES( p_intf->p_input, p_es, 1 );
679 on_menubar_subpictures_activate (GtkMenuItem *menuitem,
682 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
683 es_descriptor_t * p_es;
685 p_es = (es_descriptor_t*)user_data;
687 input_ChangeES( p_intf->p_input, p_es, 2 );
692 on_popup_navigation_activate (GtkMenuItem *menuitem,
695 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
696 input_area_t * p_area;
700 i_title = (gint)(user_data) / 100 ;
701 i_chapter = (gint)(user_data) - ( 100 * i_title );
702 p_area = p_intf->p_input->stream.pp_areas[i_title];
703 p_area->i_part = i_chapter;
705 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
706 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
711 on_menubar_title_activate (GtkMenuItem *menuitem,
714 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
716 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)user_data );
717 p_intf->p_sys->b_menus_update = 1;
718 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
723 on_menubar_chapter_activate (GtkMenuItem *menuitem,
726 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
727 input_area_t * p_area = p_intf->p_input->stream.p_selected_area;
728 gint i_chapter = (gint)user_data;
730 p_area->i_part = i_chapter;
732 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
733 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
737 on_intf_window_destroy (GtkWidget *widget,
741 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
742 /* is there an output thread ? */
743 if(p_main->b_video == 1)
745 gtk_widget_hide(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 );