1 /*****************************************************************************
2 * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_callbacks.c,v 1.2 2002/08/08 22:28:22 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"
50 /*****************************************************************************
51 * Useful function to retrieve p_intf
52 ****************************************************************************/
53 void * __GtkGetIntf( GtkWidget * widget )
57 if( GTK_IS_MENU_ITEM( widget ) )
59 /* Look for a GTK_MENU */
60 while( widget->parent && !GTK_IS_MENU( widget ) )
62 widget = widget->parent;
65 /* Maybe this one has the data */
66 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
72 /* Otherwise, the parent widget has it */
73 widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
76 /* We look for the top widget */
77 widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
79 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
84 /*****************************************************************************
86 *****************************************************************************/
89 * Main interface callbacks
92 gboolean GtkExit( GtkWidget *widget,
95 intf_thread_t *p_intf = GtkGetIntf( widget );
97 vlc_mutex_lock( &p_intf->change_lock );
98 p_intf->p_vlc->b_die = VLC_TRUE;
99 vlc_mutex_unlock( &p_intf->change_lock );
104 void GtkClose( GtkMenuItem *menuitem,
107 intf_thread_t *p_intf = GtkGetIntf( menuitem );
108 p_intf->b_die = VLC_TRUE;
111 gboolean GtkWindowDelete( GtkWidget *widget,
115 GtkExit( GTK_WIDGET( widget ), user_data );
121 gboolean GtkWindowToggle( GtkWidget *widget,
124 intf_thread_t *p_intf = GtkGetIntf( widget );
126 if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) )
128 gtk_widget_hide( p_intf->p_sys->p_window);
132 gtk_widget_show( p_intf->p_sys->p_window );
138 gboolean GtkFullscreen( GtkWidget *widget,
141 intf_thread_t *p_intf = GtkGetIntf( widget );
142 vout_thread_t *p_vout;
144 p_vout = vlc_object_find( p_intf->p_sys->p_input,
145 VLC_OBJECT_VOUT, FIND_CHILD );
151 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
152 vlc_object_release( p_vout );
156 void GtkWindowDrag( GtkWidget *widget,
157 GdkDragContext *drag_context,
160 GtkSelectionData *data,
165 intf_thread_t * p_intf = GtkGetIntf( widget );
166 GtkDropDataReceived( p_intf, data, info, PLAYLIST_END );
170 /****************************************************************************
172 ****************************************************************************/
174 gboolean GtkSliderRelease( GtkWidget *widget,
175 GdkEventButton *event,
178 intf_thread_t *p_intf = GtkGetIntf( widget );
180 vlc_mutex_lock( &p_intf->change_lock );
181 p_intf->p_sys->b_slider_free = 1;
182 vlc_mutex_unlock( &p_intf->change_lock );
188 gboolean GtkSliderPress( GtkWidget *widget,
189 GdkEventButton *event,
192 intf_thread_t *p_intf = GtkGetIntf( widget );
194 vlc_mutex_lock( &p_intf->change_lock );
195 p_intf->p_sys->b_slider_free = 0;
196 vlc_mutex_unlock( &p_intf->change_lock );
202 /****************************************************************************
204 ****************************************************************************/
206 void GtkTitlePrev( GtkButton * button, gpointer user_data )
208 intf_thread_t * p_intf;
209 input_area_t * p_area;
212 p_intf = GtkGetIntf( button );
214 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id - 1;
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 );
231 void GtkTitleNext( GtkButton * button, gpointer user_data )
233 intf_thread_t * p_intf;
234 input_area_t * p_area;
237 p_intf = GtkGetIntf( button );
238 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id + 1;
240 if( i_id < p_intf->p_sys->p_input->stream.i_area_nb )
242 p_area = p_intf->p_sys->p_input->stream.pp_areas[i_id];
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_title_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 GtkChapterPrev( GtkButton * button, gpointer user_data )
257 intf_thread_t * p_intf;
258 input_area_t * p_area;
260 p_intf = GtkGetIntf( button );
261 p_area = p_intf->p_sys->p_input->stream.p_selected_area;
263 if( p_area->i_part > 0 )
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 );
278 void GtkChapterNext( GtkButton * button, gpointer user_data )
280 intf_thread_t * p_intf;
281 input_area_t * p_area;
283 p_intf = GtkGetIntf( button );
284 p_area = p_intf->p_sys->p_input->stream.p_selected_area;
286 if( p_area->i_part < p_area->i_part_nb )
289 input_ChangeArea( p_intf->p_sys->p_input, (input_area_t*)p_area );
291 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
293 p_intf->p_sys->b_chapter_update = 1;
294 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
295 GtkSetupMenus( p_intf );
296 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
300 /****************************************************************************
301 * Network specific items
302 ****************************************************************************/
303 void GtkNetworkJoin( GtkEditable * editable, gpointer user_data )
307 i_channel = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( editable ) );
309 msg_Dbg( "intf info: joining channel %d", i_channel );
311 network_ChannelJoin( i_channel );
315 void GtkChannelGo( GtkButton * button, gpointer user_data )
321 intf_thread_t *p_intf = GtkGetIntf( button );
323 window = gtk_widget_get_toplevel( GTK_WIDGET (button) );
324 spin = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( window ),
325 "network_channel_spinbutton" ) );
327 i_channel = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spin ) );
328 msg_Dbg( p_intf, "joining channel %d", i_channel );
330 vlc_mutex_lock( &p_intf->change_lock );
331 network_ChannelJoin( p_intf, i_channel );
332 vlc_mutex_unlock( &p_intf->change_lock );
334 /* input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY ); */
338 /****************************************************************************
340 ****************************************************************************/
342 gboolean GtkAboutShow( GtkWidget *widget,
345 intf_thread_t *p_intf = GtkGetIntf( widget );
347 if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
349 p_intf->p_sys->p_about = create_intf_about();
350 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
353 gtk_widget_show( p_intf->p_sys->p_about );
354 gdk_window_raise( p_intf->p_sys->p_about->window );
359 void GtkAboutOk( GtkButton * button, gpointer user_data)
361 intf_thread_t *p_intf = GtkGetIntf( button );
363 gtk_widget_hide( p_intf->p_sys->p_about );
367 /****************************************************************************
369 ****************************************************************************/
371 gboolean GtkJumpShow( GtkWidget *widget,
374 intf_thread_t *p_intf = GtkGetIntf( widget );
376 if( !GTK_IS_WIDGET( p_intf->p_sys->p_jump ) )
378 p_intf->p_sys->p_jump = create_intf_jump();
379 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_jump ),
383 gtk_widget_show( p_intf->p_sys->p_jump );
384 gdk_window_raise( p_intf->p_sys->p_jump->window );
390 void GtkJumpOk( GtkButton *button,
393 intf_thread_t * p_intf = GtkGetIntf( button );
394 int i_hours, i_minutes, i_seconds;
396 if( p_intf->p_sys->p_input == NULL )
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 ) ) )
404 i_hours = GET_VALUE( "jump_hour_spinbutton" );
405 i_minutes = GET_VALUE( "jump_minute_spinbutton" );
406 i_seconds = GET_VALUE( "jump_second_spinbutton" );
409 input_Seek( p_intf->p_sys->p_input,
410 i_seconds + 60 * i_minutes + 3600 * i_hours,
411 INPUT_SEEK_SECONDS | INPUT_SEEK_SET );
413 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
417 void GtkJumpCancel( GtkButton *button,
420 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
423 /****************************************************************************
424 * Callbacks for disc ejection
425 ****************************************************************************/
426 gboolean GtkDiscEject ( GtkWidget *widget, gpointer user_data )
428 char *psz_device = NULL;
432 intf_thread_t *p_intf = GtkGetIntf( widget );
433 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
435 if( p_playlist == NULL )
440 vlc_mutex_lock( &p_playlist->object_lock );
442 if( p_playlist->i_index < 0 )
444 vlc_mutex_unlock( &p_playlist->object_lock );
445 vlc_object_release( p_playlist );
449 psz_current = p_playlist->pp_items[ p_playlist->i_index ]->psz_name;
452 * Get the active input
453 * Determine whether we can eject a media, ie it's a VCD or DVD
454 * If it's neither a VCD nor a DVD, then return
458 * Don't really know if I must lock the stuff here, we're using it read-only
461 if( psz_current != NULL )
463 if( !strncmp(psz_current, "dvd:", 4) )
465 switch( psz_current[4] )
469 psz_device = config_GetPsz( p_intf, "dvd" );
472 /* Omit the first 4 characters */
473 psz_device = strdup( psz_current + 4 );
477 else if( !strncmp(psz_current, "vcd:", 4) )
479 switch( psz_current[4] )
483 psz_device = config_GetPsz( p_intf, "vcd" );
486 /* Omit the first 4 characters */
487 psz_device = strdup( psz_current + 4 );
493 psz_device = strdup( psz_current );
497 vlc_mutex_unlock( &p_playlist->object_lock );
498 vlc_object_release( p_playlist );
500 if( psz_device == NULL )
505 /* Remove what we have after @ */
506 psz_parser = psz_device;
507 for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
509 if( *psz_parser == '@' )
516 /* If there's a stream playing, we aren't allowed to eject ! */
517 if( p_intf->p_sys->p_input == NULL )
519 msg_Dbg( p_intf, "ejecting %s", psz_device );
521 intf_Eject( p_intf, psz_device );
529 /****************************************************************************
531 ****************************************************************************/
533 gboolean GtkMessagesShow( GtkWidget *widget,
536 static GdkColor black = { 0, 0x0000, 0x0000, 0x0000 };
537 static GdkColormap *colormap;
538 intf_thread_t *p_intf = GtkGetIntf( widget );
540 gtk_widget_show( p_intf->p_sys->p_messages );
541 colormap = gdk_colormap_get_system ();
542 gdk_color_alloc( colormap, &black );
543 gdk_window_set_background( p_intf->p_sys->p_messages_text->text_area,
546 gdk_window_raise( p_intf->p_sys->p_messages->window );
548 gtk_text_set_point( p_intf->p_sys->p_messages_text,
549 gtk_text_get_length( p_intf->p_sys->p_messages_text ) );
556 GtkMessagesOk (GtkButton *button,
559 intf_thread_t *p_intf = GtkGetIntf( button );
560 gtk_widget_hide( p_intf->p_sys->p_messages );
565 GtkMessagesDelete (GtkWidget *widget,
569 intf_thread_t *p_intf = GtkGetIntf( widget );
570 gtk_widget_hide( p_intf->p_sys->p_messages );
576 GtkOpenNotebookChanged (GtkNotebook *notebook,
577 GtkNotebookPage *page,
581 GtkOpenChanged( GTK_WIDGET( notebook ), user_data );