1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_callbacks.c,v 1.42 2002/06/04 00:11:12 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Stéphane Borel <stef@via.ecp.fr>
9 * Julien BLACHE <jb@technologeek.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <sys/types.h> /* off_t */
42 #include "gtk_callbacks.h"
43 #include "gtk_interface.h"
44 #include "gtk_support.h"
45 #include "gtk_common.h"
49 /*****************************************************************************
51 *****************************************************************************/
54 * Main interface callbacks
57 gboolean GtkExit( GtkWidget *widget,
58 GdkEventButton *event,
61 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
63 vlc_mutex_lock( &p_intf->change_lock );
64 p_intf->p_vlc->b_die = 1;
65 vlc_mutex_unlock( &p_intf->change_lock );
70 gboolean GtkWindowDelete( GtkWidget *widget,
74 GtkExit( GTK_WIDGET( widget ), NULL, user_data );
80 gboolean GtkWindowToggle( GtkWidget *widget,
81 GdkEventButton *event,
84 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
86 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) )
88 gtk_widget_hide( p_intf->p_sys->p_window);
93 gtk_widget_show( p_intf->p_sys->p_window );
99 gboolean GtkFullscreen( GtkWidget *widget,
100 GdkEventButton *event,
103 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
104 vout_thread_t *p_vout;
106 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_CHILD );
110 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
111 vlc_object_release( p_vout );
118 void GtkWindowDrag( GtkWidget *widget,
119 GdkDragContext *drag_context,
122 GtkSelectionData *data,
127 #if 0 /* PLAYLIST TARASS */
128 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
129 int end = p_intf->p_vlc->p_playlist->i_size;
130 GtkDropDataReceived( p_intf, data, info, PLAYLIST_END );
132 if( p_intf->p_sys->p_input != NULL )
134 /* FIXME: temporary hack */
135 p_intf->p_sys->p_input->b_eof = 1;
138 intf_PlaylistJumpto( p_intf->p_vlc->p_playlist, end-1 );
143 /****************************************************************************
145 ****************************************************************************/
147 gboolean GtkSliderRelease( GtkWidget *widget,
148 GdkEventButton *event,
151 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
153 vlc_mutex_lock( &p_intf->change_lock );
154 p_intf->p_sys->b_slider_free = 1;
155 vlc_mutex_unlock( &p_intf->change_lock );
161 gboolean GtkSliderPress( GtkWidget *widget,
162 GdkEventButton *event,
165 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
167 vlc_mutex_lock( &p_intf->change_lock );
168 p_intf->p_sys->b_slider_free = 0;
169 vlc_mutex_unlock( &p_intf->change_lock );
175 /****************************************************************************
177 ****************************************************************************/
179 void GtkTitlePrev( GtkButton * button, gpointer user_data )
181 intf_thread_t * p_intf;
182 input_area_t * p_area;
185 p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
187 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id - 1;
189 /* Disallow area 0 since it is used for video_ts.vob */
192 p_area = p_intf->p_sys->p_input->stream.pp_areas[i_id];
193 input_ChangeArea( p_intf->p_sys->p_input, (input_area_t*)p_area );
195 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
197 p_intf->p_sys->b_title_update = 1;
198 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
199 GtkSetupMenus( p_intf );
200 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
203 vlc_object_release( p_intf->p_sys->p_input );
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_intf->p_sys->p_input->stream.p_selected_area->i_id + 1;
216 if( i_id < p_intf->p_sys->p_input->stream.i_area_nb )
218 p_area = p_intf->p_sys->p_input->stream.pp_areas[i_id];
219 input_ChangeArea( p_intf->p_sys->p_input, (input_area_t*)p_area );
221 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
223 p_intf->p_sys->b_title_update = 1;
224 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
225 GtkSetupMenus( p_intf );
226 vlc_mutex_unlock( &p_intf->p_sys->p_input->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_intf->p_sys->p_input->stream.p_selected_area;
240 if( p_area->i_part > 0 )
243 input_ChangeArea( p_intf->p_sys->p_input, (input_area_t*)p_area );
245 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
247 p_intf->p_sys->b_chapter_update = 1;
248 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
249 GtkSetupMenus( p_intf );
250 vlc_mutex_unlock( &p_intf->p_sys->p_input->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_intf->p_sys->p_input->stream.p_selected_area;
263 if( p_area->i_part < p_area->i_part_nb )
266 input_ChangeArea( p_intf->p_sys->p_input, (input_area_t*)p_area );
268 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
270 p_intf->p_sys->b_chapter_update = 1;
271 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
272 GtkSetupMenus( p_intf );
273 vlc_mutex_unlock( &p_intf->p_sys->p_input->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 // msg_Dbg( "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 msg_Dbg( p_intf, "joining channel %d", i_channel );
305 vlc_mutex_lock( &p_intf->change_lock );
306 network_ChannelJoin( p_intf, i_channel );
307 vlc_mutex_unlock( &p_intf->change_lock );
309 // input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
313 /****************************************************************************
315 ****************************************************************************/
317 gboolean GtkAboutShow( GtkWidget *widget,
318 GdkEventButton *event,
321 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
323 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
325 p_intf->p_sys->p_about = create_intf_about();
326 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
329 gtk_widget_show( p_intf->p_sys->p_about );
330 gdk_window_raise( p_intf->p_sys->p_about->window );
335 void GtkAboutOk( GtkButton * button, gpointer user_data)
337 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
339 gtk_widget_hide( p_intf->p_sys->p_about );
343 /****************************************************************************
345 ****************************************************************************/
347 gboolean GtkJumpShow( GtkWidget *widget,
348 GdkEventButton *event,
351 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
353 if( !GTK_IS_WIDGET( p_intf->p_sys->p_jump ) )
355 p_intf->p_sys->p_jump = create_intf_jump();
356 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_jump ),
360 gtk_widget_show( p_intf->p_sys->p_jump );
361 gdk_window_raise( p_intf->p_sys->p_jump->window );
367 void GtkJumpOk( GtkButton *button,
370 intf_thread_t * p_intf = GetIntf( GTK_WIDGET( button ), (char*)user_data );
371 int i_hours, i_minutes, i_seconds;
373 #define GET_VALUE( name ) \
374 gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gtk_object_get_data( \
375 GTK_OBJECT( p_intf->p_sys->p_jump ), name ) ) )
376 i_hours = GET_VALUE( "jump_hour_spinbutton" );
377 i_minutes = GET_VALUE( "jump_minute_spinbutton" );
378 i_seconds = GET_VALUE( "jump_second_spinbutton" );
381 input_Seek( p_intf, i_seconds + 60 * i_minutes + 3600 * i_hours,
382 INPUT_SEEK_SECONDS | INPUT_SEEK_SET );
384 #if 0 /* PLAYLIST TARASS */
385 p_intf->p_vlc->p_playlist->b_stopped = 0;
387 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
391 void GtkJumpCancel( GtkButton *button,
394 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
398 /****************************************************************************
399 * Callbacks for menuitems
400 ****************************************************************************/
401 void GtkExitActivate( GtkMenuItem * menuitem, gpointer user_data )
403 GtkExit( GTK_WIDGET( menuitem ), NULL, user_data );
407 void GtkFullscreenActivate( GtkMenuItem * menuitem, gpointer user_data )
409 GtkFullscreen( GTK_WIDGET( menuitem ), NULL, user_data );
413 void GtkWindowToggleActivate( GtkMenuItem * menuitem, gpointer user_data )
415 GtkWindowToggle( GTK_WIDGET( menuitem ), NULL, user_data );
419 void GtkAboutActivate( GtkMenuItem * menuitem, gpointer user_data )
421 GtkAboutShow( GTK_WIDGET( menuitem ), NULL, user_data );
425 void GtkJumpActivate( GtkMenuItem * menuitem, gpointer user_data )
427 GtkJumpShow( GTK_WIDGET( menuitem ), NULL, user_data );
431 void GtkMessagesActivate( GtkMenuItem * menuitem, gpointer user_data )
433 GtkMessagesShow( GTK_WIDGET( menuitem ), NULL, user_data );
437 /****************************************************************************
438 * Callbacks for disc ejection
439 ****************************************************************************/
440 gboolean GtkDiscEject ( GtkWidget *widget, GdkEventButton *event,
443 #if 0 /* PLAYLIST TARASS */
444 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
446 char *psz_device = NULL;
448 char *psz_current = p_intf->p_vlc->p_playlist->current.psz_name;
451 * Get the active input
452 * Determine whether we can eject a media, ie it's a VCD or DVD
453 * If it's neither a VCD nor a DVD, then return
457 * Don't really know if I must lock the stuff here, we're using it read-only
460 if( psz_current != NULL )
462 if( !strncmp(psz_current, "dvd:", 4) )
464 switch( psz_current[4] )
468 psz_device = config_GetPsz( p_intf, "dvd" );
471 /* Omit the first 4 characters */
472 psz_device = strdup( psz_current + 4 );
476 else if( !strncmp(psz_current, "vcd:", 4) )
478 switch( psz_current[4] )
482 psz_device = config_GetPsz( p_intf, "vcd" );
485 /* Omit the first 4 characters */
486 psz_device = strdup( psz_current + 4 );
492 psz_device = strdup( psz_current );
496 if( psz_device == NULL )
501 /* Remove what we have after @ */
502 psz_parser = psz_device;
503 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
505 if( *psz_parser == '@' )
512 /* If there's a stream playing, we aren't allowed to eject ! */
513 if( p_intf->p_sys->p_input == NULL )
515 msg_Dbg( p_intf, "ejecting %s", psz_device );
517 intf_Eject( p_intf, psz_device );
525 void GtkEjectDiscActivate ( GtkMenuItem *menuitem, gpointer user_data )
527 GtkDiscEject( GTK_WIDGET( menuitem ), NULL, user_data );
530 /****************************************************************************
532 ****************************************************************************/
534 gboolean GtkMessagesShow( GtkWidget *widget,
535 GdkEventButton *event,
538 static GdkColor black = { 0, 0x0000, 0x0000, 0x0000 };
539 static GdkColormap *colormap;
540 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
542 gtk_widget_show( p_intf->p_sys->p_messages );
543 colormap = gdk_colormap_get_system ();
544 gdk_color_alloc( colormap, &black );
545 gdk_window_set_background( p_intf->p_sys->p_messages_text->text_area,
548 gdk_window_raise( p_intf->p_sys->p_messages->window );
550 gtk_text_set_point( p_intf->p_sys->p_messages_text,
551 gtk_text_get_length( p_intf->p_sys->p_messages_text ) );
558 GtkMessagesOk (GtkButton *button,
561 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
562 gtk_widget_hide( p_intf->p_sys->p_messages );
567 GtkMessagesDelete (GtkWidget *widget,
571 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
572 gtk_widget_hide( p_intf->p_sys->p_messages );