1 /*****************************************************************************
2 * gnome_callbacks.c : Callbacks for the Gnome plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 #define MODULE_NAME gnome
24 #include "modules_inner.h"
26 /*****************************************************************************
28 *****************************************************************************/
38 #include "stream_control.h"
39 #include "input_ext-intf.h"
41 #include "interface.h"
42 #include "intf_plst.h"
45 #include "gnome_sys.h"
46 #include "gnome_callbacks.h"
47 #include "gnome_interface.h"
48 #include "gnome_support.h"
52 /*****************************************************************************
53 * Inline function to retrieve the interface structure
54 *****************************************************************************/
55 static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
57 return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
61 /*****************************************************************************
63 ******************************************************************************/
65 on_menubar_open_activate (GtkMenuItem *menuitem,
68 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
70 /* If we have never used the file selector, open it */
71 if( p_intf->p_sys->p_fileopen == NULL)
73 p_intf->p_sys->p_fileopen = create_intf_fileopen();
74 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
78 gtk_widget_show( p_intf->p_sys->p_fileopen );
79 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
84 on_menubar_exit_activate (GtkMenuItem *menuitem,
87 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
94 on_menubar_playlist_activate (GtkMenuItem *menuitem,
97 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
99 if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
101 p_intf->p_sys->p_playlist = create_intf_playlist();
102 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
105 gtk_widget_show( p_intf->p_sys->p_playlist );
106 gdk_window_raise( p_intf->p_sys->p_playlist->window );
111 on_menubar_preferences_activate (GtkMenuItem *menuitem,
119 on_menubar_about_activate (GtkMenuItem *menuitem,
122 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
124 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
126 p_intf->p_sys->p_about = create_intf_about();
127 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
130 gtk_widget_show( p_intf->p_sys->p_about );
131 gdk_window_raise( p_intf->p_sys->p_about->window );
136 on_toolbar_open_clicked (GtkButton *button,
139 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
141 /* If we have never used the file selector, open it */
142 if( p_intf->p_sys->p_fileopen == NULL)
144 p_intf->p_sys->p_fileopen = create_intf_fileopen();
145 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
149 gtk_widget_show( p_intf->p_sys->p_fileopen );
150 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
155 on_toolbar_back_clicked (GtkButton *button,
163 on_toolbar_stop_clicked (GtkButton *button,
171 on_toolbar_play_clicked (GtkButton *button,
174 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
176 if( p_intf->p_input != NULL )
178 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
184 on_toolbar_pause_clicked (GtkButton *button,
187 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
189 if( p_intf->p_input != NULL )
191 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
197 on_toolbar_playlist_clicked (GtkButton *button,
200 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
202 if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
204 p_intf->p_sys->p_playlist = create_intf_playlist();
205 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
208 gtk_widget_show( p_intf->p_sys->p_playlist );
209 gdk_window_raise( p_intf->p_sys->p_playlist->window );
214 on_toolbar_prev_clicked (GtkButton *button,
217 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
219 if( p_intf->p_input != NULL )
221 /* FIXME: temporary hack */
222 intf_PlstPrev( p_main->p_playlist );
223 intf_PlstPrev( p_main->p_playlist );
224 p_intf->p_input->b_eof = 1;
230 on_toolbar_next_clicked (GtkButton *button,
233 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
235 if( p_intf->p_input != NULL )
237 /* FIXME: temporary hack */
238 p_intf->p_input->b_eof = 1;
244 on_popup_play_activate (GtkMenuItem *menuitem,
247 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
249 if( p_intf->p_input != NULL )
251 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
257 on_popup_pause_activate (GtkMenuItem *menuitem,
260 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
262 if( p_intf->p_input != NULL )
264 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
270 on_popup_exit_activate (GtkMenuItem *menuitem,
273 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
280 on_intf_window_destroy (GtkObject *object,
283 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
285 /* FIXME don't destroy the window, just hide it */
287 p_intf->p_sys->p_window = NULL;
292 on_fileopen_ok_clicked (GtkButton *button,
298 filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
299 gtk_widget_hide (filesel);
300 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
302 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
307 on_fileopen_cancel_clicked (GtkButton *button,
310 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
315 on_intf_fileopen_destroy (GtkObject *object,
318 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
320 p_intf->p_sys->p_fileopen = NULL;
325 on_popup_open_activate (GtkMenuItem *menuitem,
328 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
330 /* If we have never used the file selector, open it */
331 if( p_intf->p_sys->p_fileopen == NULL)
333 p_intf->p_sys->p_fileopen = create_intf_fileopen();
334 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
338 gtk_widget_show( p_intf->p_sys->p_fileopen );
339 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
344 on_popup_about_activate (GtkMenuItem *menuitem,
347 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
349 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
351 p_intf->p_sys->p_about = create_intf_about();
352 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
355 gtk_widget_show( p_intf->p_sys->p_about );
356 gdk_window_raise( p_intf->p_sys->p_about->window );
361 on_intf_playlist_destroy (GtkObject *object,
364 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
366 p_intf->p_sys->p_playlist = NULL;
371 on_playlist_close_clicked (GtkButton *button,
374 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
379 on_popup_slow_activate (GtkMenuItem *menuitem,
382 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
384 if( p_intf->p_input != NULL )
386 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
392 on_popup_fast_activate (GtkMenuItem *menuitem,
395 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
397 if( p_intf->p_input != NULL )
399 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
405 on_toolbar_slow_clicked (GtkButton *button,
408 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
410 if( p_intf->p_input != NULL )
412 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
418 on_toolbar_fast_clicked (GtkButton *button,
421 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
423 if( p_intf->p_input != NULL )
425 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
431 on_hscale_button_release_event (GtkWidget *widget,
432 GdkEventButton *event,
435 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
437 GtkAdjustment *p_adj = gtk_range_get_adjustment( GTK_RANGE(widget) );
440 vlc_mutex_lock( &p_intf->p_sys->change_lock );
442 if( p_intf->p_input != NULL )
444 i_seek = (p_adj->value *
445 p_intf->p_input->stream.p_selected_area->i_size) / 100;
446 input_Seek( p_intf->p_input, i_seek );
448 p_intf->p_sys->b_scale_isfree = 1;
450 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
457 on_hscale_button_press_event (GtkWidget *widget,
458 GdkEventButton *event,
461 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
463 vlc_mutex_lock( &p_intf->p_sys->change_lock );
464 p_intf->p_sys->b_scale_isfree = 0;
465 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
473 on_intf_modules_destroy (GtkObject *object,
481 on_modules_ok_clicked (GtkButton *button,
484 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
486 gtk_widget_hide( p_intf->p_sys->p_modules );
492 on_modules_apply_clicked (GtkButton *button,
500 on_modules_cancel_clicked (GtkButton *button,
503 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
505 gtk_widget_hide( p_intf->p_sys->p_modules );
510 on_playlist_ok_clicked (GtkButton *button,
513 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_playlist" );
515 gtk_widget_hide( p_intf->p_sys->p_playlist );
520 on_menubar_modules_activate (GtkMenuItem *menuitem,
523 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
525 if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
527 p_intf->p_sys->p_modules = create_intf_modules();
528 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
531 gtk_widget_show( p_intf->p_sys->p_modules );
532 gdk_window_raise( p_intf->p_sys->p_modules->window );
537 on_intf_window_drag_data_received (GtkWidget *widget,
538 GdkDragContext *drag_context,
541 GtkSelectionData *data,
546 char *psz_text = data->data;
547 int i_len = strlen( psz_text );
551 case DROP_ACCEPT_TEXT_PLAIN: /* FIXME: handle multiple files */
558 /* get rid of ' ' at the end */
559 *( psz_text + i_len - 1 ) = 0;
561 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
562 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
566 case DROP_ACCEPT_TEXT_URI_LIST: /* FIXME: handle multiple files */
573 /* get rid of \r\n at the end */
574 *( psz_text + i_len - 2 ) = 0;
576 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
577 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
582 intf_ErrMsg( "intf error: unknown dropped type");
589 on_menubar_audio_activate (GtkMenuItem *menuitem,
597 on_menubar_subtitles_activate (GtkMenuItem *menuitem,
605 on_popup_title_activate (GtkMenuItem *menuitem,
613 on_popup_chapter_activate (GtkMenuItem *menuitem,
621 on_popup_audio_activate (GtkMenuItem *menuitem,
629 on_popup_subtitle_activate (GtkMenuItem *menuitem,
637 on_menubar_disc_activate (GtkMenuItem *menuitem,
640 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
642 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
644 p_intf->p_sys->p_disc = create_intf_disc();
645 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
648 gtk_widget_show( p_intf->p_sys->p_disc );
649 gdk_window_raise( p_intf->p_sys->p_disc->window );
654 on_toolbar_disc_clicked (GtkButton *button,
657 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
659 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
661 p_intf->p_sys->p_disc = create_intf_disc();
662 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
665 gtk_widget_show( p_intf->p_sys->p_disc );
666 gdk_window_raise( p_intf->p_sys->p_disc->window );
671 on_disc_ok_clicked (GtkButton *button,
674 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
675 char *psz_device, *psz_source, *psz_method;
677 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
678 GTK_WIDGET(button), "disc_name" ) ) );
680 /* "dvd:foo" has size 5 + strlen(foo) */
681 psz_source = malloc( 5 + strlen( psz_device ) );
682 if( psz_source == NULL )
687 /* Check which method was activated */
688 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
689 "disc_dvd" ) )->active )
693 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
694 "disc_vcd" ) )->active )
700 intf_ErrMsg( "intf error: unknown toggle button configuration" );
705 /* Select title and chapter */
706 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
707 GTK_SPIN_BUTTON( lookup_widget(
708 GTK_WIDGET(button), "disc_title" ) ) ) );
710 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
711 GTK_SPIN_BUTTON( lookup_widget(
712 GTK_WIDGET(button), "disc_chapter" ) ) ) );
714 /* Build source name and add it to playlist */
715 sprintf( psz_source, "%s:%s", psz_method, psz_device );
716 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
718 gtk_widget_hide( p_intf->p_sys->p_disc );
723 on_disc_cancel_clicked (GtkButton *button,
726 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
728 gtk_widget_hide( p_intf->p_sys->p_disc );
733 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
736 if( togglebutton->active )
738 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
739 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
745 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
748 if( togglebutton->active )
750 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
751 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
757 on_popup_disc_activate (GtkMenuItem *menuitem,
760 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
762 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
764 p_intf->p_sys->p_disc = create_intf_disc();
765 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
768 gtk_widget_show( p_intf->p_sys->p_disc );
769 gdk_window_raise( p_intf->p_sys->p_disc->window );