1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_callbacks.c,v 1.41 2002/06/01 18:04:48 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 if( p_intf->p_sys->p_input != NULL )
308 /* end playing item */
309 p_intf->p_sys->p_input->b_eof = 1;
311 #if 0 /* PLAYLIST TARASS */
312 /* update playlist */
313 vlc_mutex_lock( &p_intf->p_vlc->p_playlist->change_lock );
315 p_intf->p_vlc->p_playlist->i_index--;
316 p_intf->p_vlc->p_playlist->b_stopped = 1;
318 vlc_mutex_unlock( &p_intf->p_vlc->p_playlist->change_lock );
322 network_ChannelJoin( p_intf, i_channel );
325 #if 0 /* PLAYLIST TARASS */
326 p_intf->p_vlc->p_playlist->b_stopped = 0;
329 vlc_mutex_unlock( &p_intf->change_lock );
331 // input_SetStatus( p_intf->p_sys->p_input, 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 = GetIntf( GTK_WIDGET( button ), (char*)user_data );
393 int i_hours, i_minutes, i_seconds;
395 #define GET_VALUE( name ) \
396 gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gtk_object_get_data( \
397 GTK_OBJECT( p_intf->p_sys->p_jump ), name ) ) )
398 i_hours = GET_VALUE( "jump_hour_spinbutton" );
399 i_minutes = GET_VALUE( "jump_minute_spinbutton" );
400 i_seconds = GET_VALUE( "jump_second_spinbutton" );
403 input_Seek( p_intf, i_seconds + 60 * i_minutes + 3600 * i_hours,
404 INPUT_SEEK_SECONDS | INPUT_SEEK_SET );
406 #if 0 /* PLAYLIST TARASS */
407 p_intf->p_vlc->p_playlist->b_stopped = 0;
409 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
413 void GtkJumpCancel( GtkButton *button,
416 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
420 /****************************************************************************
421 * Callbacks for menuitems
422 ****************************************************************************/
423 void GtkExitActivate( GtkMenuItem * menuitem, gpointer user_data )
425 GtkExit( GTK_WIDGET( menuitem ), NULL, user_data );
429 void GtkFullscreenActivate( GtkMenuItem * menuitem, gpointer user_data )
431 GtkFullscreen( GTK_WIDGET( menuitem ), NULL, user_data );
435 void GtkWindowToggleActivate( GtkMenuItem * menuitem, gpointer user_data )
437 GtkWindowToggle( GTK_WIDGET( menuitem ), NULL, user_data );
441 void GtkAboutActivate( GtkMenuItem * menuitem, gpointer user_data )
443 GtkAboutShow( GTK_WIDGET( menuitem ), NULL, user_data );
447 void GtkJumpActivate( GtkMenuItem * menuitem, gpointer user_data )
449 GtkJumpShow( GTK_WIDGET( menuitem ), NULL, user_data );
453 void GtkMessagesActivate( GtkMenuItem * menuitem, gpointer user_data )
455 GtkMessagesShow( GTK_WIDGET( menuitem ), NULL, user_data );
459 /****************************************************************************
460 * Callbacks for disc ejection
461 ****************************************************************************/
462 gboolean GtkDiscEject ( GtkWidget *widget, GdkEventButton *event,
465 #if 0 /* PLAYLIST TARASS */
466 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
468 char *psz_device = NULL;
470 char *psz_current = p_intf->p_vlc->p_playlist->current.psz_name;
473 * Get the active input
474 * Determine whether we can eject a media, ie it's a VCD or DVD
475 * If it's neither a VCD nor a DVD, then return
479 * Don't really know if I must lock the stuff here, we're using it read-only
482 if( psz_current != NULL )
484 if( !strncmp(psz_current, "dvd:", 4) )
486 switch( psz_current[4] )
490 psz_device = config_GetPsz( p_intf, "dvd" );
493 /* Omit the first 4 characters */
494 psz_device = strdup( psz_current + 4 );
498 else if( !strncmp(psz_current, "vcd:", 4) )
500 switch( psz_current[4] )
504 psz_device = config_GetPsz( p_intf, "vcd" );
507 /* Omit the first 4 characters */
508 psz_device = strdup( psz_current + 4 );
514 psz_device = strdup( psz_current );
518 if( psz_device == NULL )
523 /* Remove what we have after @ */
524 psz_parser = psz_device;
525 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
527 if( *psz_parser == '@' )
534 /* If there's a stream playing, we aren't allowed to eject ! */
535 if( p_intf->p_sys->p_input == NULL )
537 msg_Dbg( p_intf, "ejecting %s", psz_device );
539 intf_Eject( p_intf, psz_device );
547 void GtkEjectDiscActivate ( GtkMenuItem *menuitem, gpointer user_data )
549 GtkDiscEject( GTK_WIDGET( menuitem ), NULL, user_data );
552 /****************************************************************************
554 ****************************************************************************/
556 gboolean GtkMessagesShow( GtkWidget *widget,
557 GdkEventButton *event,
560 static GdkColor black = { 0, 0x0000, 0x0000, 0x0000 };
561 static GdkColormap *colormap;
562 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
564 gtk_widget_show( p_intf->p_sys->p_messages );
565 colormap = gdk_colormap_get_system ();
566 gdk_color_alloc( colormap, &black );
567 gdk_window_set_background( p_intf->p_sys->p_messages_text->text_area,
570 gdk_window_raise( p_intf->p_sys->p_messages->window );
572 gtk_text_set_point( p_intf->p_sys->p_messages_text,
573 gtk_text_get_length( p_intf->p_sys->p_messages_text ) );
580 GtkMessagesOk (GtkButton *button,
583 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
584 gtk_widget_hide( p_intf->p_sys->p_messages );
589 GtkMessagesDelete (GtkWidget *widget,
593 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
594 gtk_widget_hide( p_intf->p_sys->p_messages );