1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_callbacks.c,v 1.28 2001/12/07 18:33:07 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 *****************************************************************************/
29 #include <sys/types.h> /* off_t */
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
44 #include "interface.h"
45 #include "intf_playlist.h"
48 #include "video_output.h"
50 #include "gtk_callbacks.h"
51 #include "gtk_interface.h"
52 #include "gtk_support.h"
57 #include "modules_export.h"
59 /*****************************************************************************
61 *****************************************************************************/
64 * Main interface callbacks
67 gboolean GtkExit( GtkWidget *widget,
68 GdkEventButton *event,
71 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
73 vlc_mutex_lock( &p_intf->change_lock );
75 vlc_mutex_unlock( &p_intf->change_lock );
80 gboolean GtkWindowDelete( GtkWidget *widget,
84 GtkExit( GTK_WIDGET( widget ), NULL, user_data );
90 gboolean GtkWindowToggle( GtkWidget *widget,
91 GdkEventButton *event,
94 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
96 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) )
98 gtk_widget_hide( p_intf->p_sys->p_window);
103 gtk_widget_show( p_intf->p_sys->p_window );
109 gboolean GtkFullscreen( GtkWidget *widget,
110 GdkEventButton *event,
113 if( p_vout_bank->i_count )
115 vlc_mutex_lock( &p_vout_bank->pp_vout[0]->change_lock );
117 p_vout_bank->pp_vout[0]->i_changes |= VOUT_FULLSCREEN_CHANGE;
119 vlc_mutex_unlock( &p_vout_bank->pp_vout[0]->change_lock );
129 void GtkWindowDrag( GtkWidget *widget,
130 GdkDragContext *drag_context,
133 GtkSelectionData *data,
138 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
139 int end = p_main->p_playlist->i_size;
140 GtkDropDataReceived( p_intf, data, info, PLAYLIST_END );
142 if( p_intf->p_input != NULL )
144 /* FIXME: temporary hack */
145 p_intf->p_input->b_eof = 1;
148 intf_PlaylistJumpto( p_main->p_playlist, end-1 );
152 /****************************************************************************
154 ****************************************************************************/
156 gboolean GtkSliderRelease( GtkWidget *widget,
157 GdkEventButton *event,
160 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
162 vlc_mutex_lock( &p_intf->change_lock );
163 p_intf->p_sys->b_slider_free = 1;
164 vlc_mutex_unlock( &p_intf->change_lock );
170 gboolean GtkSliderPress( GtkWidget *widget,
171 GdkEventButton *event,
174 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
176 vlc_mutex_lock( &p_intf->change_lock );
177 p_intf->p_sys->b_slider_free = 0;
178 vlc_mutex_unlock( &p_intf->change_lock );
184 /****************************************************************************
186 ****************************************************************************/
188 void GtkTitlePrev( GtkButton * button, gpointer user_data )
190 intf_thread_t * p_intf;
191 input_area_t * p_area;
194 p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
195 i_id = p_intf->p_input->stream.p_selected_area->i_id - 1;
197 /* Disallow area 0 since it is used for video_ts.vob */
200 p_area = p_intf->p_input->stream.pp_areas[i_id];
201 input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
203 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
205 p_intf->p_sys->b_title_update = 1;
206 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
207 GtkSetupMenus( p_intf );
208 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
213 void GtkTitleNext( GtkButton * button, gpointer user_data )
215 intf_thread_t * p_intf;
216 input_area_t * p_area;
219 p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
220 i_id = p_intf->p_input->stream.p_selected_area->i_id + 1;
222 if( i_id < p_intf->p_input->stream.i_area_nb )
224 p_area = p_intf->p_input->stream.pp_areas[i_id];
225 input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
227 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
229 p_intf->p_sys->b_title_update = 1;
230 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
231 GtkSetupMenus( p_intf );
232 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
238 void GtkChapterPrev( GtkButton * button, gpointer user_data )
240 intf_thread_t * p_intf;
241 input_area_t * p_area;
243 p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
244 p_area = p_intf->p_input->stream.p_selected_area;
246 if( p_area->i_part > 0 )
249 input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
251 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
253 p_intf->p_sys->b_chapter_update = 1;
254 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
255 GtkSetupMenus( p_intf );
256 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
261 void GtkChapterNext( GtkButton * button, gpointer user_data )
263 intf_thread_t * p_intf;
264 input_area_t * p_area;
266 p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
267 p_area = p_intf->p_input->stream.p_selected_area;
269 if( p_area->i_part < p_area->i_part_nb )
272 input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
274 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
276 p_intf->p_sys->b_chapter_update = 1;
277 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
278 GtkSetupMenus( p_intf );
279 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
283 /****************************************************************************
284 * Network specific items
285 ****************************************************************************/
286 void GtkNetworkJoin( GtkEditable * editable, gpointer user_data )
290 i_channel = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( editable ) );
291 // intf_WarnMsg( 3, "intf info: joining channel %d", i_channel );
293 // network_ChannelJoin( i_channel );
296 void GtkChannelGo( GtkButton * button, gpointer user_data )
302 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
304 window = gtk_widget_get_toplevel( GTK_WIDGET (button) );
305 spin = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( window ),
306 "network_channel_spinbutton" ) );
308 i_channel = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spin ) );
309 intf_WarnMsg( 3, "intf info: joining channel %d", i_channel );
311 vlc_mutex_lock( &p_intf->change_lock );
312 if( p_intf->p_input != NULL )
314 /* end playing item */
315 p_intf->p_input->b_eof = 1;
317 /* update playlist */
318 vlc_mutex_lock( &p_main->p_playlist->change_lock );
320 p_main->p_playlist->i_index--;
321 p_main->p_playlist->b_stopped = 1;
323 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
325 /* FIXME: ugly hack to close input and outputs */
326 p_intf->pf_manage( p_intf );
329 network_ChannelJoin( i_channel );
332 p_main->p_playlist->b_stopped = 0;
333 p_intf->pf_manage( p_intf );
335 vlc_mutex_unlock( &p_intf->change_lock );
337 // input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
341 /****************************************************************************
343 ****************************************************************************/
345 gboolean GtkAboutShow( GtkWidget *widget,
346 GdkEventButton *event,
349 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
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 void GtkAboutOk( GtkButton * button, gpointer user_data)
365 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
367 gtk_widget_hide( p_intf->p_sys->p_about );
371 /****************************************************************************
373 ****************************************************************************/
375 gboolean GtkJumpShow( GtkWidget *widget,
376 GdkEventButton *event,
379 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
381 if( !GTK_IS_WIDGET( p_intf->p_sys->p_jump ) )
383 p_intf->p_sys->p_jump = create_intf_jump();
384 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_jump ),
388 gtk_widget_show( p_intf->p_sys->p_jump );
389 gdk_window_raise( p_intf->p_sys->p_jump->window );
395 void GtkJumpOk( GtkButton *button,
398 intf_thread_t * p_intf;
405 p_intf = GetIntf( GTK_WIDGET( button ), (char*)user_data );
407 #define GET_VALUE( name ) \
408 gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gtk_object_get_data( \
409 GTK_OBJECT( p_intf->p_sys->p_jump ), name ) ) )
411 i_hours = GET_VALUE( "jump_hour_spinbutton" );
412 i_minutes = GET_VALUE( "jump_minute_spinbutton" );
413 i_seconds = GET_VALUE( "jump_second_spinbutton" );
417 i_seconds += 60 *i_minutes + 3600* i_hours;
419 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
420 i_seek = i_seconds * 50 * p_intf->p_input->stream.i_mux_rate;
421 i_size = p_intf->p_input->stream.p_selected_area->i_size;
422 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
424 if( i_seek < i_size )
426 input_Seek( p_intf->p_input, i_seek );
428 p_main->p_playlist->b_stopped = 0;
429 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
433 void GtkJumpCancel( GtkButton *button,
436 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
440 /****************************************************************************
441 * Callbacks for menuitems
442 ****************************************************************************/
443 void GtkExitActivate( GtkMenuItem * menuitem, gpointer user_data )
445 GtkExit( GTK_WIDGET( menuitem ), NULL, user_data );
449 void GtkFullscreenActivate( GtkMenuItem * menuitem, gpointer user_data )
451 GtkFullscreen( GTK_WIDGET( menuitem ), NULL, user_data );
455 void GtkWindowToggleActivate( GtkMenuItem * menuitem, gpointer user_data )
457 GtkWindowToggle( GTK_WIDGET( menuitem ), NULL, user_data );
461 void GtkAboutActivate( GtkMenuItem * menuitem, gpointer user_data )
463 GtkAboutShow( GTK_WIDGET( menuitem ), NULL, user_data );
467 void GtkJumpActivate( GtkMenuItem * menuitem, gpointer user_data )
469 GtkJumpShow( GTK_WIDGET( menuitem ), NULL, user_data );