1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_callbacks.c,v 1.30 2002/01/07 02:12:29 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Stéphane Borel <stef@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <sys/types.h> /* off_t */
31 #include <videolan/vlc.h>
37 #include "stream_control.h"
38 #include "input_ext-intf.h"
40 #include "interface.h"
41 #include "intf_playlist.h"
44 #include "video_output.h"
46 #include "gtk_callbacks.h"
47 #include "gtk_interface.h"
48 #include "gtk_support.h"
49 #include "gtk_common.h"
53 /*****************************************************************************
55 *****************************************************************************/
58 * Main interface callbacks
61 gboolean GtkExit( GtkWidget *widget,
62 GdkEventButton *event,
65 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
67 vlc_mutex_lock( &p_intf->change_lock );
69 vlc_mutex_unlock( &p_intf->change_lock );
74 gboolean GtkWindowDelete( GtkWidget *widget,
78 GtkExit( GTK_WIDGET( widget ), NULL, user_data );
84 gboolean GtkWindowToggle( GtkWidget *widget,
85 GdkEventButton *event,
88 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
90 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) )
92 gtk_widget_hide( p_intf->p_sys->p_window);
97 gtk_widget_show( p_intf->p_sys->p_window );
103 gboolean GtkFullscreen( GtkWidget *widget,
104 GdkEventButton *event,
107 if( p_vout_bank->i_count )
109 vlc_mutex_lock( &p_vout_bank->pp_vout[0]->change_lock );
111 p_vout_bank->pp_vout[0]->i_changes |= VOUT_FULLSCREEN_CHANGE;
113 vlc_mutex_unlock( &p_vout_bank->pp_vout[0]->change_lock );
123 void GtkWindowDrag( GtkWidget *widget,
124 GdkDragContext *drag_context,
127 GtkSelectionData *data,
132 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
133 int end = p_main->p_playlist->i_size;
134 GtkDropDataReceived( p_intf, data, info, PLAYLIST_END );
136 if( p_input_bank->pp_input[0] != NULL )
138 /* FIXME: temporary hack */
139 p_input_bank->pp_input[0]->b_eof = 1;
142 intf_PlaylistJumpto( p_main->p_playlist, end-1 );
146 /****************************************************************************
148 ****************************************************************************/
150 gboolean GtkSliderRelease( GtkWidget *widget,
151 GdkEventButton *event,
154 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
156 vlc_mutex_lock( &p_intf->change_lock );
157 p_intf->p_sys->b_slider_free = 1;
158 vlc_mutex_unlock( &p_intf->change_lock );
164 gboolean GtkSliderPress( GtkWidget *widget,
165 GdkEventButton *event,
168 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
170 vlc_mutex_lock( &p_intf->change_lock );
171 p_intf->p_sys->b_slider_free = 0;
172 vlc_mutex_unlock( &p_intf->change_lock );
178 /****************************************************************************
180 ****************************************************************************/
182 void GtkTitlePrev( GtkButton * button, gpointer user_data )
184 intf_thread_t * p_intf;
185 input_area_t * p_area;
188 p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
189 i_id = p_input_bank->pp_input[0]->stream.p_selected_area->i_id - 1;
191 /* Disallow area 0 since it is used for video_ts.vob */
194 p_area = p_input_bank->pp_input[0]->stream.pp_areas[i_id];
195 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
197 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
199 p_intf->p_sys->b_title_update = 1;
200 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
201 GtkSetupMenus( p_intf );
202 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
207 void GtkTitleNext( GtkButton * button, gpointer user_data )
209 intf_thread_t * p_intf;
210 input_area_t * p_area;
213 p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
214 i_id = p_input_bank->pp_input[0]->stream.p_selected_area->i_id + 1;
216 if( i_id < p_input_bank->pp_input[0]->stream.i_area_nb )
218 p_area = p_input_bank->pp_input[0]->stream.pp_areas[i_id];
219 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
221 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
223 p_intf->p_sys->b_title_update = 1;
224 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
225 GtkSetupMenus( p_intf );
226 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
232 void GtkChapterPrev( GtkButton * button, gpointer user_data )
234 intf_thread_t * p_intf;
235 input_area_t * p_area;
237 p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
238 p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
240 if( p_area->i_part > 0 )
243 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
245 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
247 p_intf->p_sys->b_chapter_update = 1;
248 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
249 GtkSetupMenus( p_intf );
250 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
255 void GtkChapterNext( GtkButton * button, gpointer user_data )
257 intf_thread_t * p_intf;
258 input_area_t * p_area;
260 p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
261 p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
263 if( p_area->i_part < p_area->i_part_nb )
266 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
268 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
270 p_intf->p_sys->b_chapter_update = 1;
271 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
272 GtkSetupMenus( p_intf );
273 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
277 /****************************************************************************
278 * Network specific items
279 ****************************************************************************/
280 void GtkNetworkJoin( GtkEditable * editable, gpointer user_data )
284 i_channel = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( editable ) );
285 // intf_WarnMsg( 3, "intf info: joining channel %d", i_channel );
287 // network_ChannelJoin( i_channel );
290 void GtkChannelGo( GtkButton * button, gpointer user_data )
296 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
298 window = gtk_widget_get_toplevel( GTK_WIDGET (button) );
299 spin = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( window ),
300 "network_channel_spinbutton" ) );
302 i_channel = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spin ) );
303 intf_WarnMsg( 3, "intf info: joining channel %d", i_channel );
305 vlc_mutex_lock( &p_intf->change_lock );
306 if( p_input_bank->pp_input[0] != NULL )
308 /* end playing item */
309 p_input_bank->pp_input[0]->b_eof = 1;
311 /* update playlist */
312 vlc_mutex_lock( &p_main->p_playlist->change_lock );
314 p_main->p_playlist->i_index--;
315 p_main->p_playlist->b_stopped = 1;
317 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
319 /* FIXME: ugly hack to close input and outputs */
320 p_intf->pf_manage( p_intf );
323 network_ChannelJoin( i_channel );
326 p_main->p_playlist->b_stopped = 0;
327 p_intf->pf_manage( p_intf );
329 vlc_mutex_unlock( &p_intf->change_lock );
331 // input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
335 /****************************************************************************
337 ****************************************************************************/
339 gboolean GtkAboutShow( GtkWidget *widget,
340 GdkEventButton *event,
343 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
345 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
347 p_intf->p_sys->p_about = create_intf_about();
348 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
351 gtk_widget_show( p_intf->p_sys->p_about );
352 gdk_window_raise( p_intf->p_sys->p_about->window );
357 void GtkAboutOk( GtkButton * button, gpointer user_data)
359 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
361 gtk_widget_hide( p_intf->p_sys->p_about );
365 /****************************************************************************
367 ****************************************************************************/
369 gboolean GtkJumpShow( GtkWidget *widget,
370 GdkEventButton *event,
373 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
375 if( !GTK_IS_WIDGET( p_intf->p_sys->p_jump ) )
377 p_intf->p_sys->p_jump = create_intf_jump();
378 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_jump ),
382 gtk_widget_show( p_intf->p_sys->p_jump );
383 gdk_window_raise( p_intf->p_sys->p_jump->window );
389 void GtkJumpOk( GtkButton *button,
392 intf_thread_t * p_intf;
399 p_intf = GetIntf( GTK_WIDGET( button ), (char*)user_data );
401 #define GET_VALUE( name ) \
402 gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gtk_object_get_data( \
403 GTK_OBJECT( p_intf->p_sys->p_jump ), name ) ) )
405 i_hours = GET_VALUE( "jump_hour_spinbutton" );
406 i_minutes = GET_VALUE( "jump_minute_spinbutton" );
407 i_seconds = GET_VALUE( "jump_second_spinbutton" );
411 i_seconds += 60 *i_minutes + 3600* i_hours;
413 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
414 i_seek = i_seconds * 50 * p_input_bank->pp_input[0]->stream.i_mux_rate;
415 i_size = p_input_bank->pp_input[0]->stream.p_selected_area->i_size;
416 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
418 if( i_seek < i_size )
420 input_Seek( p_input_bank->pp_input[0], i_seek );
422 p_main->p_playlist->b_stopped = 0;
423 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
427 void GtkJumpCancel( GtkButton *button,
430 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
434 /****************************************************************************
435 * Callbacks for menuitems
436 ****************************************************************************/
437 void GtkExitActivate( GtkMenuItem * menuitem, gpointer user_data )
439 GtkExit( GTK_WIDGET( menuitem ), NULL, user_data );
443 void GtkFullscreenActivate( GtkMenuItem * menuitem, gpointer user_data )
445 GtkFullscreen( GTK_WIDGET( menuitem ), NULL, user_data );
449 void GtkWindowToggleActivate( GtkMenuItem * menuitem, gpointer user_data )
451 GtkWindowToggle( GTK_WIDGET( menuitem ), NULL, user_data );
455 void GtkAboutActivate( GtkMenuItem * menuitem, gpointer user_data )
457 GtkAboutShow( GTK_WIDGET( menuitem ), NULL, user_data );
461 void GtkJumpActivate( GtkMenuItem * menuitem, gpointer user_data )
463 GtkJumpShow( GTK_WIDGET( menuitem ), NULL, user_data );