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