1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ 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 gtk
24 #include "modules_inner.h"
26 /*****************************************************************************
28 *****************************************************************************/
40 #include "stream_control.h"
41 #include "input_ext-intf.h"
43 #include "interface.h"
44 #include "intf_plst.h"
48 #include "gtk_callbacks.h"
49 #include "gtk_interface.h"
50 #include "gtk_support.h"
54 /*****************************************************************************
55 * Inline function to retrieve the interface structure
56 *****************************************************************************/
57 static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
59 return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
63 /*****************************************************************************
65 ******************************************************************************/
67 on_menubar_open_activate (GtkMenuItem *menuitem,
70 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
72 /* If we have never used the file selector, open it */
73 if( p_intf->p_sys->p_fileopen == NULL)
75 p_intf->p_sys->p_fileopen = create_intf_fileopen();
76 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
80 gtk_widget_show( p_intf->p_sys->p_fileopen );
81 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
86 on_menubar_exit_activate (GtkMenuItem *menuitem,
89 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
96 on_menubar_playlist_activate (GtkMenuItem *menuitem,
99 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
101 if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
103 // p_intf->p_sys->p_playlist = create_intf_playlist();
104 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
107 gtk_widget_show( p_intf->p_sys->p_playlist );
108 gdk_window_raise( p_intf->p_sys->p_playlist->window );
113 on_menubar_preferences_activate (GtkMenuItem *menuitem,
121 on_menubar_about_activate (GtkMenuItem *menuitem,
124 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
126 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
128 p_intf->p_sys->p_about = create_intf_about();
129 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
132 gtk_widget_show( p_intf->p_sys->p_about );
133 gdk_window_raise( p_intf->p_sys->p_about->window );
138 on_toolbar_open_clicked (GtkButton *button,
141 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
143 /* If we have never used the file selector, open it */
144 if( p_intf->p_sys->p_fileopen == NULL)
146 p_intf->p_sys->p_fileopen = create_intf_fileopen();
147 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
151 gtk_widget_show( p_intf->p_sys->p_fileopen );
152 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
157 on_toolbar_back_clicked (GtkButton *button,
165 on_toolbar_stop_clicked (GtkButton *button,
173 on_toolbar_play_clicked (GtkButton *button,
176 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
178 if( p_intf->p_input != NULL )
180 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
186 on_toolbar_pause_clicked (GtkButton *button,
189 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
191 if( p_intf->p_input != NULL )
193 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
199 on_toolbar_playlist_clicked (GtkButton *button,
202 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
204 if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
206 // p_intf->p_sys->p_playlist = create_intf_playlist();
207 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
210 gtk_widget_show( p_intf->p_sys->p_playlist );
211 gdk_window_raise( p_intf->p_sys->p_playlist->window );
216 on_toolbar_prev_clicked (GtkButton *button,
219 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
221 if( p_intf->p_input != NULL )
223 /* FIXME: temporary hack */
224 intf_PlstPrev( p_main->p_playlist );
225 intf_PlstPrev( p_main->p_playlist );
226 p_intf->p_input->b_eof = 1;
232 on_toolbar_next_clicked (GtkButton *button,
235 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
237 if( p_intf->p_input != NULL )
239 /* FIXME: temporary hack */
240 p_intf->p_input->b_eof = 1;
246 on_popup_play_activate (GtkMenuItem *menuitem,
249 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
251 if( p_intf->p_input != NULL )
253 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
259 on_popup_pause_activate (GtkMenuItem *menuitem,
262 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
264 if( p_intf->p_input != NULL )
266 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
272 on_popup_exit_activate (GtkMenuItem *menuitem,
275 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
282 on_intf_window_destroy (GtkObject *object,
285 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
287 /* FIXME don't destroy the window, just hide it */
289 p_intf->p_sys->p_window = NULL;
294 on_fileopen_ok_clicked (GtkButton *button,
300 filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
301 gtk_widget_hide (filesel);
302 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
304 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
309 on_fileopen_cancel_clicked (GtkButton *button,
312 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
317 on_intf_fileopen_destroy (GtkObject *object,
320 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
322 p_intf->p_sys->p_fileopen = NULL;
327 on_popup_open_activate (GtkMenuItem *menuitem,
330 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
332 /* If we have never used the file selector, open it */
333 if( p_intf->p_sys->p_fileopen == NULL)
335 p_intf->p_sys->p_fileopen = create_intf_fileopen();
336 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
340 gtk_widget_show( p_intf->p_sys->p_fileopen );
341 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
346 on_popup_about_activate (GtkMenuItem *menuitem,
349 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
351 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
353 p_intf->p_sys->p_about = create_intf_about();
354 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
357 gtk_widget_show( p_intf->p_sys->p_about );
358 gdk_window_raise( p_intf->p_sys->p_about->window );
363 on_intf_playlist_destroy (GtkObject *object,
366 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
368 p_intf->p_sys->p_playlist = NULL;
373 on_playlist_close_clicked (GtkButton *button,
376 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
381 on_popup_slow_activate (GtkMenuItem *menuitem,
384 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
386 if( p_intf->p_input != NULL )
388 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
394 on_popup_fast_activate (GtkMenuItem *menuitem,
397 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
399 if( p_intf->p_input != NULL )
401 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
407 on_toolbar_slow_clicked (GtkButton *button,
410 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
412 if( p_intf->p_input != NULL )
414 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
420 on_toolbar_fast_clicked (GtkButton *button,
423 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
425 if( p_intf->p_input != NULL )
427 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
433 on_hscale_button_release_event (GtkWidget *widget,
434 GdkEventButton *event,
437 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
439 GtkAdjustment *p_adj = gtk_range_get_adjustment( GTK_RANGE(widget) );
442 vlc_mutex_lock( &p_intf->p_sys->change_lock );
444 if( p_intf->p_input != NULL )
446 i_seek = (p_adj->value *
447 p_intf->p_input->stream.p_selected_area->i_size) / 100;
448 input_Seek( p_intf->p_input, i_seek );
450 p_intf->p_sys->b_scale_isfree = 1;
452 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
459 on_hscale_button_press_event (GtkWidget *widget,
460 GdkEventButton *event,
463 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
465 vlc_mutex_lock( &p_intf->p_sys->change_lock );
466 p_intf->p_sys->b_scale_isfree = 0;
467 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
475 on_intf_modules_destroy (GtkObject *object,
483 on_modules_ok_clicked (GtkButton *button,
486 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
488 gtk_widget_hide( p_intf->p_sys->p_modules );
494 on_modules_apply_clicked (GtkButton *button,
502 on_modules_cancel_clicked (GtkButton *button,
505 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
507 gtk_widget_hide( p_intf->p_sys->p_modules );
512 on_playlist_ok_clicked (GtkButton *button,
515 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_playlist" );
517 gtk_widget_hide( p_intf->p_sys->p_playlist );
522 on_menubar_modules_activate (GtkMenuItem *menuitem,
525 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
527 if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
529 // p_intf->p_sys->p_modules = create_intf_modules();
530 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
533 gtk_widget_show( p_intf->p_sys->p_modules );
534 gdk_window_raise( p_intf->p_sys->p_modules->window );
539 on_intf_window_drag_data_received (GtkWidget *widget,
540 GdkDragContext *drag_context,
543 GtkSelectionData *data,
548 char *psz_text = data->data;
549 int i_len = strlen( psz_text );
553 case DROP_ACCEPT_TEXT_PLAIN: /* FIXME: handle multiple files */
560 /* get rid of ' ' at the end */
561 *( psz_text + i_len - 1 ) = 0;
563 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
564 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
568 case DROP_ACCEPT_TEXT_URI_LIST: /* FIXME: handle multiple files */
575 /* get rid of \r\n at the end */
576 *( psz_text + i_len - 2 ) = 0;
578 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
579 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
584 intf_ErrMsg( "intf error: unknown dropped type");
591 on_about_ok_clicked (GtkButton *button,
594 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
596 gtk_widget_hide( p_intf->p_sys->p_about );
601 on_menubar_disc_activate (GtkMenuItem *menuitem,
604 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
606 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
608 p_intf->p_sys->p_disc = create_intf_disc();
609 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
612 gtk_widget_show( p_intf->p_sys->p_disc );
613 gdk_window_raise( p_intf->p_sys->p_disc->window );
618 on_toolbar_disc_clicked (GtkButton *button,
621 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
623 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
625 p_intf->p_sys->p_disc = create_intf_disc();
626 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
629 gtk_widget_show( p_intf->p_sys->p_disc );
630 gdk_window_raise( p_intf->p_sys->p_disc->window );
635 on_disc_ok_clicked (GtkButton *button,
638 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
639 char *psz_device, *psz_source, *psz_method;
641 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
642 GTK_WIDGET(button), "disc_name" ) ) );
644 /* "dvd:foo" has size 5 + strlen(foo) */
645 psz_source = malloc( 5 + strlen( psz_device ) );
646 if( psz_source == NULL )
651 /* Check which method was activated */
652 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
653 "disc_dvd" ) )->active )
657 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
658 "disc_vcd" ) )->active )
664 intf_ErrMsg( "intf error: unknown toggle button configuration" );
669 /* Build source name and add it to playlist */
670 sprintf( psz_source, "%s:%s", psz_method, psz_device );
671 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
673 gtk_widget_hide( p_intf->p_sys->p_disc );
678 on_disc_cancel_clicked (GtkButton *button,
681 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
683 gtk_widget_hide( p_intf->p_sys->p_disc );
688 on_disc_dvd_toggled (GtkToggleButton *togglebutton,
691 if( togglebutton->active )
693 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
694 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
700 on_disc_vcd_toggled (GtkToggleButton *togglebutton,
703 if( togglebutton->active )
705 gtk_entry_set_text( GTK_ENTRY( lookup_widget(
706 GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
712 on_popup_disc_activate (GtkMenuItem *menuitem,
715 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
717 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
719 p_intf->p_sys->p_disc = create_intf_disc();
720 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
723 gtk_widget_show( p_intf->p_sys->p_disc );
724 gdk_window_raise( p_intf->p_sys->p_disc->window );