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"
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" );
97 on_menubar_preferences_activate (GtkMenuItem *menuitem,
105 on_menubar_about_activate (GtkMenuItem *menuitem,
108 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
110 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
112 p_intf->p_sys->p_about = create_intf_about();
113 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
116 gtk_widget_show( p_intf->p_sys->p_about );
117 gdk_window_raise( p_intf->p_sys->p_about->window );
122 on_toolbar_open_clicked (GtkButton *button,
125 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
127 /* If we have never used the file selector, open it */
128 if( p_intf->p_sys->p_fileopen == NULL)
130 p_intf->p_sys->p_fileopen = create_intf_fileopen();
131 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
135 gtk_widget_show( p_intf->p_sys->p_fileopen );
136 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
141 on_toolbar_back_clicked (GtkButton *button,
149 on_toolbar_stop_clicked (GtkButton *button,
157 on_toolbar_play_clicked (GtkButton *button,
160 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
162 if( p_intf->p_input != NULL )
164 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
170 on_toolbar_pause_clicked (GtkButton *button,
173 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
175 if( p_intf->p_input != NULL )
177 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
182 on_toolbar_prev_clicked (GtkButton *button,
185 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
187 if( p_intf->p_input != NULL )
189 /* FIXME: temporary hack */
190 intf_PlstPrev( p_main->p_playlist );
191 intf_PlstPrev( p_main->p_playlist );
192 p_intf->p_input->b_eof = 1;
198 on_toolbar_next_clicked (GtkButton *button,
201 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
203 if( p_intf->p_input != NULL )
205 /* FIXME: temporary hack */
206 p_intf->p_input->b_eof = 1;
212 on_popup_play_activate (GtkMenuItem *menuitem,
215 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
217 if( p_intf->p_input != NULL )
219 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
225 on_popup_pause_activate (GtkMenuItem *menuitem,
228 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
230 if( p_intf->p_input != NULL )
232 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
238 on_popup_exit_activate (GtkMenuItem *menuitem,
241 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
247 on_fileopen_ok_clicked (GtkButton *button,
253 filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
254 gtk_widget_hide (filesel);
255 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
257 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
262 on_fileopen_cancel_clicked (GtkButton *button,
265 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
270 on_intf_fileopen_destroy (GtkObject *object,
273 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
275 p_intf->p_sys->p_fileopen = NULL;
280 on_popup_open_activate (GtkMenuItem *menuitem,
283 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
285 /* If we have never used the file selector, open it */
286 if( p_intf->p_sys->p_fileopen == NULL)
288 p_intf->p_sys->p_fileopen = create_intf_fileopen();
289 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
293 gtk_widget_show( p_intf->p_sys->p_fileopen );
294 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
299 on_popup_about_activate (GtkMenuItem *menuitem,
302 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
304 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
306 p_intf->p_sys->p_about = create_intf_about();
307 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
310 gtk_widget_show( p_intf->p_sys->p_about );
311 gdk_window_raise( p_intf->p_sys->p_about->window );
314 on_popup_slow_activate (GtkMenuItem *menuitem,
317 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
319 if( p_intf->p_input != NULL )
321 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
327 on_popup_fast_activate (GtkMenuItem *menuitem,
330 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
332 if( p_intf->p_input != NULL )
334 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
340 on_toolbar_slow_clicked (GtkButton *button,
343 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
345 if( p_intf->p_input != NULL )
347 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
353 on_toolbar_fast_clicked (GtkButton *button,
356 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
358 if( p_intf->p_input != NULL )
360 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
366 on_hscale_button_release_event (GtkWidget *widget,
367 GdkEventButton *event,
370 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
372 GtkAdjustment *p_adj = gtk_range_get_adjustment( GTK_RANGE(widget) );
375 vlc_mutex_lock( &p_intf->p_sys->change_lock );
377 if( p_intf->p_input != NULL )
379 i_seek = (p_adj->value *
380 p_intf->p_input->stream.p_selected_area->i_size) / 100;
381 input_Seek( p_intf->p_input, i_seek );
383 p_intf->p_sys->b_scale_isfree = 1;
385 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
392 on_hscale_button_press_event (GtkWidget *widget,
393 GdkEventButton *event,
396 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
398 vlc_mutex_lock( &p_intf->p_sys->change_lock );
399 p_intf->p_sys->b_scale_isfree = 0;
400 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
408 on_intf_modules_destroy (GtkObject *object,
416 on_modules_ok_clicked (GtkButton *button,
419 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
421 gtk_widget_hide( p_intf->p_sys->p_modules );
427 on_modules_apply_clicked (GtkButton *button,
435 on_modules_cancel_clicked (GtkButton *button,
438 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
440 gtk_widget_hide( p_intf->p_sys->p_modules );
444 on_menubar_modules_activate (GtkMenuItem *menuitem,
447 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
449 if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
451 // p_intf->p_sys->p_modules = create_intf_modules();
452 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
455 gtk_widget_show( p_intf->p_sys->p_modules );
456 gdk_window_raise( p_intf->p_sys->p_modules->window );
461 on_intf_window_drag_data_received (GtkWidget *widget,
462 GdkDragContext *drag_context,
465 GtkSelectionData *data,
470 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
471 int end = p_main->p_playlist->i_size;
472 on_generic_drop_data_received( p_intf, data, info, PLAYLIST_END);
474 if( p_intf->p_input != NULL )
476 /* FIXME: temporary hack */
477 p_intf->p_input->b_eof = 1;
480 intf_PlstJumpto( p_main->p_playlist, end-1 );
486 on_about_ok_clicked (GtkButton *button,
489 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
491 gtk_widget_hide( p_intf->p_sys->p_about );
496 on_menubar_disc_activate (GtkMenuItem *menuitem,
499 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
501 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
503 p_intf->p_sys->p_disc = create_intf_disc();
504 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
507 gtk_widget_show( p_intf->p_sys->p_disc );
508 gdk_window_raise( p_intf->p_sys->p_disc->window );
513 on_toolbar_disc_clicked (GtkButton *button,
516 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
518 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
520 p_intf->p_sys->p_disc = create_intf_disc();
521 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
524 gtk_widget_show( p_intf->p_sys->p_disc );
525 gdk_window_raise( p_intf->p_sys->p_disc->window );
530 on_disc_ok_clicked (GtkButton *button,
533 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
534 char *psz_device, *psz_source, *psz_method;
536 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
537 GTK_WIDGET(button), "disc_name" ) ) );
539 /* "dvd:foo" has size 5 + strlen(foo) */
540 psz_source = malloc( 5 + strlen( psz_device ) );
541 if( psz_source == NULL )
546 /* Check which method was activated */
547 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
548 "disc_dvd" ) )->active )
552 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
553 "disc_vcd" ) )->active )
559 intf_ErrMsg( "intf error: unknown toggle button configuration" );
564 /* Select title and chapter */
565 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
566 GTK_SPIN_BUTTON( lookup_widget(
567 GTK_WIDGET(button), "disc_title" ) ) ) );
569 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
570 GTK_SPIN_BUTTON( lookup_widget(
571 GTK_WIDGET(button), "disc_chapter" ) ) ) );
573 /* Build source name and add it to playlist */
574 sprintf( psz_source, "%s:%s", psz_method, psz_device );
575 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
577 gtk_widget_hide( p_intf->p_sys->p_disc );
582 on_disc_cancel_clicked (GtkButton *button,
585 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
587 gtk_widget_hide( p_intf->p_sys->p_disc );
592 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
595 if( togglebutton->active )
597 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
598 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
604 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
607 if( togglebutton->active )
609 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
610 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
616 on_popup_disc_activate (GtkMenuItem *menuitem,
619 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
621 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
623 p_intf->p_sys->p_disc = create_intf_disc();
624 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
627 gtk_widget_show( p_intf->p_sys->p_disc );
628 gdk_window_raise( p_intf->p_sys->p_disc->window );
632 on_popup_audio_activate (GtkMenuItem *menuitem,
635 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
636 es_descriptor_t * p_es;
638 p_es = (es_descriptor_t*)user_data;
640 input_ChangeES( p_intf->p_input, p_es, 1 );
645 on_popup_subpictures_activate (GtkMenuItem *menuitem,
648 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
649 es_descriptor_t * p_es;
651 p_es = (es_descriptor_t*)user_data;
653 input_ChangeES( p_intf->p_input, p_es, 2 );
658 on_menubar_audio_activate (GtkMenuItem *menuitem,
661 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
662 es_descriptor_t * p_es;
664 p_es = (es_descriptor_t*)user_data;
666 input_ChangeES( p_intf->p_input, p_es, 1 );
671 on_menubar_subpictures_activate (GtkMenuItem *menuitem,
674 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
675 es_descriptor_t * p_es;
677 p_es = (es_descriptor_t*)user_data;
679 input_ChangeES( p_intf->p_input, p_es, 2 );
684 on_popup_navigation_activate (GtkMenuItem *menuitem,
687 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
688 input_area_t * p_area;
692 i_title = (gint)(user_data) / 100 ;
693 i_chapter = (gint)(user_data) - ( 100 * i_title );
694 p_area = p_intf->p_input->stream.pp_areas[i_title];
695 p_area->i_part = i_chapter;
697 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
698 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
703 on_menubar_title_activate (GtkMenuItem *menuitem,
706 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
708 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)user_data );
709 p_intf->p_sys->b_menus_update = 1;
710 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
715 on_menubar_chapter_activate (GtkMenuItem *menuitem,
718 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
719 input_area_t * p_area = p_intf->p_input->stream.p_selected_area;
720 gint i_chapter = (gint)user_data;
722 p_area->i_part = i_chapter;
724 p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
725 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
729 on_intf_window_destroy (GtkWidget *widget,
733 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
740 on_main_window_toggle (GtkMenuItem *menuitem,
743 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
745 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) ) {
746 gtk_widget_hide( p_intf->p_sys->p_window);
751 gtk_widget_show( p_intf->p_sys->p_window );
757 on_playlist_clist_drag_motion (GtkWidget *widget,
758 GdkDragContext *drag_context,
769 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_playlist" );
772 clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"playlist_clist"
775 if(!GTK_WIDGET_TOPLEVEL(widget))
777 gdk_window_raise( p_intf->p_sys->p_playlist->window );
781 color.green = 0xffff;
784 gtk_clist_freeze( clist );
786 for(dummy=0; dummy<clist->rows; dummy++)
788 gtk_clist_set_background ( clist, dummy , &color);
793 gtk_clist_set_background ( clist, p_main->p_playlist->i_index , &color);
795 if( gtk_clist_get_selection_info( clist,x,y ,&row,&col )== 1)
798 color.green = 0x9000;
800 gtk_clist_set_background ( clist, row-1 , &color);
801 gtk_clist_set_background ( clist, row , &color);
804 gtk_clist_thaw( clist );