]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_callbacks.c
1fbeda4f806cae6500123be2fb7592fed9a1b6ce
[vlc] / plugins / gtk / gtk_callbacks.c
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 $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Stéphane Borel <stef@via.ecp.fr>
9  *      
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.
14  * 
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <sys/types.h>                                              /* off_t */
29 #include <stdlib.h>
30
31 #include <videolan/vlc.h>
32
33 #include <gtk/gtk.h>
34
35 #include <string.h>
36
37 #include "stream_control.h"
38 #include "input_ext-intf.h"
39
40 #include "interface.h"
41 #include "intf_playlist.h"
42
43 #include "video.h"
44 #include "video_output.h"
45
46 #include "gtk_callbacks.h"
47 #include "gtk_interface.h"
48 #include "gtk_support.h"
49 #include "gtk_common.h"
50
51 #include "netutils.h"
52
53 /*****************************************************************************
54  * Callbacks
55  *****************************************************************************/
56
57 /*
58  * Main interface callbacks
59  */
60
61 gboolean GtkExit( GtkWidget       *widget,
62                   GdkEventButton  *event,
63                   gpointer         user_data )
64 {
65     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
66
67     vlc_mutex_lock( &p_intf->change_lock );
68     p_intf->b_die = 1;
69     vlc_mutex_unlock( &p_intf->change_lock );
70
71     return TRUE;
72 }
73
74 gboolean GtkWindowDelete( GtkWidget       *widget,
75                           GdkEvent        *event,
76                           gpointer         user_data )
77 {
78     GtkExit( GTK_WIDGET( widget ), NULL, user_data );
79
80     return TRUE;
81 }
82
83
84 gboolean GtkWindowToggle( GtkWidget       *widget,
85                           GdkEventButton  *event,
86                           gpointer         user_data )
87 {
88     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
89     
90     if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) )
91     {
92         gtk_widget_hide( p_intf->p_sys->p_window);
93
94     } 
95     else 
96     {
97         gtk_widget_show( p_intf->p_sys->p_window );
98     }
99
100     return TRUE;
101 }
102
103 gboolean GtkFullscreen( GtkWidget       *widget,
104                         GdkEventButton  *event,
105                         gpointer         user_data)
106 {
107     if( p_vout_bank->i_count )
108     {
109         vlc_mutex_lock( &p_vout_bank->pp_vout[0]->change_lock );
110
111         p_vout_bank->pp_vout[0]->i_changes |= VOUT_FULLSCREEN_CHANGE;
112
113         vlc_mutex_unlock( &p_vout_bank->pp_vout[0]->change_lock );
114
115         return TRUE;
116     }
117     else
118     {
119         return FALSE;
120     }
121 }
122
123 void GtkWindowDrag( GtkWidget       *widget,
124                     GdkDragContext  *drag_context,
125                     gint             x,
126                     gint             y,
127                     GtkSelectionData *data,
128                     guint            info,
129                     guint            time,
130                     gpointer         user_data)
131 {
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 );
135
136     if( p_input_bank->pp_input[0] != NULL )
137     {
138        /* FIXME: temporary hack */
139        p_input_bank->pp_input[0]->b_eof = 1;
140     }
141      
142     intf_PlaylistJumpto( p_main->p_playlist, end-1 );
143 }
144
145
146 /****************************************************************************
147  * Slider management
148  ****************************************************************************/
149
150 gboolean GtkSliderRelease( GtkWidget       *widget,
151                            GdkEventButton  *event,
152                            gpointer         user_data )
153 {
154     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
155
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 );
159
160     return FALSE;
161 }
162
163
164 gboolean GtkSliderPress( GtkWidget       *widget,
165                          GdkEventButton  *event,
166                          gpointer         user_data)
167 {
168     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
169
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 );
173
174     return FALSE;
175 }
176
177
178 /****************************************************************************
179  * DVD specific items
180  ****************************************************************************/
181
182 void GtkTitlePrev( GtkButton * button, gpointer user_data )
183 {
184     intf_thread_t * p_intf;
185     input_area_t *  p_area;
186     int             i_id;
187
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;
190
191     /* Disallow area 0 since it is used for video_ts.vob */
192     if( i_id > 0 )
193     {
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 );
196
197         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
198
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 );
203     }
204 }
205
206
207 void GtkTitleNext( GtkButton * button, gpointer user_data )
208 {
209     intf_thread_t * p_intf;
210     input_area_t *  p_area;
211     int             i_id;
212
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;
215
216     if( i_id < p_input_bank->pp_input[0]->stream.i_area_nb )
217     {
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 );
220
221         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
222
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 );
227     }
228
229 }
230
231
232 void GtkChapterPrev( GtkButton * button, gpointer user_data )
233 {
234     intf_thread_t * p_intf;
235     input_area_t *  p_area;
236
237     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
238     p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
239
240     if( p_area->i_part > 0 )
241     {
242         p_area->i_part--;
243         input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
244
245         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
246
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 );
251     }
252 }
253
254
255 void GtkChapterNext( GtkButton * button, gpointer user_data )
256 {
257     intf_thread_t * p_intf;
258     input_area_t *  p_area;
259
260     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
261     p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
262
263     if( p_area->i_part < p_area->i_part_nb )
264     {
265         p_area->i_part++;
266         input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
267
268         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
269
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 );
274     }
275 }
276
277 /****************************************************************************
278  * Network specific items
279  ****************************************************************************/
280 void GtkNetworkJoin( GtkEditable * editable, gpointer user_data )
281 {
282     int     i_channel;
283
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 );
286
287 //    network_ChannelJoin( i_channel );
288 }
289
290 void GtkChannelGo( GtkButton * button, gpointer user_data )
291 {
292     GtkWidget *     window;
293     GtkWidget *     spin;
294     int             i_channel;
295
296     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
297
298     window = gtk_widget_get_toplevel( GTK_WIDGET (button) );
299     spin = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( window ),
300                        "network_channel_spinbutton" ) );
301
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 );
304
305     vlc_mutex_lock( &p_intf->change_lock );
306     if( p_input_bank->pp_input[0] != NULL )
307     {
308         /* end playing item */
309         p_input_bank->pp_input[0]->b_eof = 1;
310
311         /* update playlist */
312         vlc_mutex_lock( &p_main->p_playlist->change_lock );
313
314         p_main->p_playlist->i_index--;
315         p_main->p_playlist->b_stopped = 1;
316
317         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
318
319         /* FIXME: ugly hack to close input and outputs */
320         p_intf->pf_manage( p_intf );
321     }
322
323     network_ChannelJoin( i_channel );
324
325     /* FIXME 2 */
326     p_main->p_playlist->b_stopped = 0;
327     p_intf->pf_manage( p_intf );
328
329     vlc_mutex_unlock( &p_intf->change_lock );
330
331 //    input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
332 }
333
334
335 /****************************************************************************
336  * About box
337  ****************************************************************************/
338
339 gboolean GtkAboutShow( GtkWidget       *widget,
340                        GdkEventButton  *event,
341                        gpointer         user_data)
342 {
343     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
344
345     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
346     {
347         p_intf->p_sys->p_about = create_intf_about();
348         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
349                              "p_intf", p_intf );
350     }
351     gtk_widget_show( p_intf->p_sys->p_about );
352     gdk_window_raise( p_intf->p_sys->p_about->window );
353
354     return TRUE;
355 }
356
357 void GtkAboutOk( GtkButton * button, gpointer user_data)
358 {
359     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
360
361     gtk_widget_hide( p_intf->p_sys->p_about );
362 }
363
364
365 /****************************************************************************
366  * Jump box
367  ****************************************************************************/
368
369 gboolean GtkJumpShow( GtkWidget       *widget,
370                       GdkEventButton  *event,
371                       gpointer         user_data)
372 {
373     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
374
375     if( !GTK_IS_WIDGET( p_intf->p_sys->p_jump ) )
376     {
377         p_intf->p_sys->p_jump = create_intf_jump();
378         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_jump ),
379                              "p_intf", p_intf );
380     }
381
382     gtk_widget_show( p_intf->p_sys->p_jump );
383     gdk_window_raise( p_intf->p_sys->p_jump->window );
384
385     return FALSE;
386 }
387
388
389 void GtkJumpOk( GtkButton       *button,
390                 gpointer         user_data)
391 {
392     intf_thread_t * p_intf;
393     off_t           i_seek;
394     off_t           i_size;
395     int             i_hours;
396     int             i_minutes;
397     int             i_seconds;
398
399     p_intf = GetIntf( GTK_WIDGET( button ), (char*)user_data );
400
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
405     i_hours   = GET_VALUE( "jump_hour_spinbutton" );
406     i_minutes = GET_VALUE( "jump_minute_spinbutton" );
407     i_seconds = GET_VALUE( "jump_second_spinbutton" );
408
409 #undef GET_VALUE
410
411     i_seconds += 60 *i_minutes + 3600* i_hours;
412
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 );
417
418     if( i_seek < i_size )
419     {
420         input_Seek( p_input_bank->pp_input[0], i_seek );
421     }
422     p_main->p_playlist->b_stopped = 0;
423     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
424 }
425
426
427 void GtkJumpCancel( GtkButton       *button,
428                     gpointer         user_data)
429 {
430     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
431 }
432
433
434 /****************************************************************************
435  * Callbacks for menuitems
436  ****************************************************************************/
437 void GtkExitActivate( GtkMenuItem * menuitem, gpointer user_data )
438 {
439     GtkExit( GTK_WIDGET( menuitem ), NULL, user_data );
440 }
441
442
443 void GtkFullscreenActivate( GtkMenuItem * menuitem, gpointer user_data )
444 {
445     GtkFullscreen( GTK_WIDGET( menuitem ), NULL, user_data );
446 }
447
448
449 void GtkWindowToggleActivate( GtkMenuItem * menuitem, gpointer user_data )
450 {
451     GtkWindowToggle( GTK_WIDGET( menuitem ), NULL, user_data );
452 }
453
454
455 void GtkAboutActivate( GtkMenuItem * menuitem, gpointer user_data )
456 {
457     GtkAboutShow( GTK_WIDGET( menuitem ), NULL, user_data );
458 }
459
460
461 void GtkJumpActivate( GtkMenuItem * menuitem, gpointer user_data )
462 {
463     GtkJumpShow( GTK_WIDGET( menuitem ), NULL, user_data );
464 }
465