]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_callbacks.c
d39fa611b64bc975035f93d113c5cc7b3d316d17
[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.23 2001/05/30 23:02:03 stef 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 "config.h"
37 #include "common.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 #include "intf_msg.h"
47
48 #include "video.h"
49 #include "video_output.h"
50
51 #include "gtk_callbacks.h"
52 #include "gtk_interface.h"
53 #include "gtk_support.h"
54 #include "intf_gtk.h"
55
56 #include "main.h"
57 #include "netutils.h"
58
59 #include "modules_export.h"
60
61 /*****************************************************************************
62  * Callbacks
63  *****************************************************************************/
64
65 /*
66  * Main interface callbacks
67  */
68
69 gboolean GtkExit( GtkWidget       *widget,
70                   GdkEventButton  *event,
71                   gpointer         user_data )
72 {
73     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
74
75     vlc_mutex_lock( &p_intf->change_lock );
76     p_intf->b_die = 1;
77     vlc_mutex_unlock( &p_intf->change_lock );
78
79     return TRUE;
80 }
81
82 gboolean GtkWindowDelete( GtkWidget       *widget,
83                           GdkEvent        *event,
84                           gpointer         user_data )
85 {
86     GtkExit( GTK_WIDGET( widget ), NULL, user_data );
87
88     return TRUE;
89 }
90
91
92 gboolean GtkWindowToggle( GtkWidget       *widget,
93                           GdkEventButton  *event,
94                           gpointer         user_data )
95 {
96     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
97     
98     if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) )
99     {
100         gtk_widget_hide( p_intf->p_sys->p_window);
101
102     } 
103     else 
104     {
105         gtk_widget_show( p_intf->p_sys->p_window );
106     }
107
108     return TRUE;
109 }
110
111 gboolean GtkFullscreen( GtkWidget       *widget,
112                         GdkEventButton  *event,
113                         gpointer         user_data)
114 {
115     if( p_vout_bank->i_count )
116     {
117         vlc_mutex_lock( &p_vout_bank->pp_vout[0]->change_lock );
118
119         p_vout_bank->pp_vout[0]->i_changes |= VOUT_FULLSCREEN_CHANGE;
120
121         vlc_mutex_unlock( &p_vout_bank->pp_vout[0]->change_lock );
122
123         return TRUE;
124     }
125     else
126     {
127         return FALSE;
128     }
129 }
130
131 void GtkWindowDrag( GtkWidget       *widget,
132                     GdkDragContext  *drag_context,
133                     gint             x,
134                     gint             y,
135                     GtkSelectionData *data,
136                     guint            info,
137                     guint            time,
138                     gpointer         user_data)
139 {
140     intf_thread_t * p_intf =  GetIntf( GTK_WIDGET(widget), "intf_window" );
141     int end = p_main->p_playlist->i_size;
142     GtkDropDataReceived( p_intf, data, info, PLAYLIST_END );
143
144     if( p_intf->p_input != NULL )
145     {
146        /* FIXME: temporary hack */
147        p_intf->p_input->b_eof = 1;
148     }
149      
150     intf_PlaylistJumpto( p_main->p_playlist, end-1 );
151 }
152
153
154 /****************************************************************************
155  * Slider management
156  ****************************************************************************/
157
158 gboolean GtkSliderRelease( GtkWidget       *widget,
159                            GdkEventButton  *event,
160                            gpointer         user_data )
161 {
162     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
163
164     vlc_mutex_lock( &p_intf->change_lock );
165     p_intf->p_sys->b_slider_free = 1;
166     vlc_mutex_unlock( &p_intf->change_lock );
167
168     return FALSE;
169 }
170
171
172 gboolean GtkSliderPress( GtkWidget       *widget,
173                          GdkEventButton  *event,
174                          gpointer         user_data)
175 {
176     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
177
178     vlc_mutex_lock( &p_intf->change_lock );
179     p_intf->p_sys->b_slider_free = 0;
180     vlc_mutex_unlock( &p_intf->change_lock );
181
182     return FALSE;
183 }
184
185
186 /****************************************************************************
187  * DVD specific items
188  ****************************************************************************/
189
190 void GtkTitlePrev( GtkButton * button, gpointer user_data )
191 {
192     intf_thread_t * p_intf;
193     input_area_t *  p_area;
194     int             i_id;
195
196     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
197     i_id = p_intf->p_input->stream.p_selected_area->i_id - 1;
198
199     /* Disallow area 0 since it is used for video_ts.vob */
200     if( i_id > 0 )
201     {
202         p_area = p_intf->p_input->stream.pp_areas[i_id];
203         input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
204
205         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
206
207         p_intf->p_sys->b_title_update = 1;
208         GtkSetupMenus( p_intf );
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         GtkSetupMenus( p_intf );
231     }
232
233 }
234
235
236 void GtkChapterPrev( GtkButton * button, gpointer user_data )
237 {
238     intf_thread_t * p_intf;
239     input_area_t *  p_area;
240
241     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
242     p_area = p_intf->p_input->stream.p_selected_area;
243
244     if( p_area->i_part > 0 )
245     {
246         p_area->i_part--;
247         input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
248
249         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
250
251         p_intf->p_sys->b_chapter_update = 1;
252         GtkSetupMenus( p_intf );
253     }
254 }
255
256
257 void GtkChapterNext( GtkButton * button, gpointer user_data )
258 {
259     intf_thread_t * p_intf;
260     input_area_t *  p_area;
261
262     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
263     p_area = p_intf->p_input->stream.p_selected_area;
264
265     if( p_area->i_part < p_area->i_part_nb )
266     {
267         p_area->i_part++;
268         input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
269
270         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
271
272         p_intf->p_sys->b_chapter_update = 1;
273         GtkSetupMenus( p_intf );
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_intf->p_input != NULL )
307     {
308         /* end playing item */
309         p_intf->p_input->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         p_main->p_playlist->b_stopped = 0;
322         p_intf->pf_manage( p_intf );
323     }
324     vlc_mutex_unlock( &p_intf->change_lock );
325
326     network_ChannelJoin( i_channel );
327     input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
328 }
329
330
331 /****************************************************************************
332  * About box
333  ****************************************************************************/
334
335 gboolean GtkAboutShow( GtkWidget       *widget,
336                        GdkEventButton  *event,
337                        gpointer         user_data)
338 {
339     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
340
341     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
342     {
343         p_intf->p_sys->p_about = create_intf_about();
344         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
345                              "p_intf", p_intf );
346     }
347     gtk_widget_show( p_intf->p_sys->p_about );
348     gdk_window_raise( p_intf->p_sys->p_about->window );
349
350     return TRUE;
351 }
352
353 void GtkAboutOk( GtkButton * button, gpointer user_data)
354 {
355     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
356
357     gtk_widget_hide( p_intf->p_sys->p_about );
358 }
359
360
361 /****************************************************************************
362  * Jump box
363  ****************************************************************************/
364
365 gboolean GtkJumpShow( GtkWidget       *widget,
366                       GdkEventButton  *event,
367                       gpointer         user_data)
368 {
369     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
370
371     if( !GTK_IS_WIDGET( p_intf->p_sys->p_jump ) )
372     {
373         p_intf->p_sys->p_jump = create_intf_jump();
374         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_jump ),
375                              "p_intf", p_intf );
376     }
377
378     gtk_widget_show( p_intf->p_sys->p_jump );
379     gdk_window_raise( p_intf->p_sys->p_jump->window );
380
381     return FALSE;
382 }
383
384
385 void GtkJumpOk( GtkButton       *button,
386                 gpointer         user_data)
387 {
388     intf_thread_t * p_intf;
389     off_t           i_seek;
390     off_t           i_size;
391     int             i_hours;
392     int             i_minutes;
393     int             i_seconds;
394
395     p_intf = GetIntf( GTK_WIDGET( button ), (char*)user_data );
396
397 #define GET_VALUE( name )                                                   \
398     gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gtk_object_get_data( \
399         GTK_OBJECT( p_intf->p_sys->p_jump ), name ) ) )
400
401     i_hours   = GET_VALUE( "jump_hour_spinbutton" );
402     i_minutes = GET_VALUE( "jump_minute_spinbutton" );
403     i_seconds = GET_VALUE( "jump_second_spinbutton" );
404
405 #undef GET_VALUE
406
407     i_seconds += 60 *i_minutes + 3600* i_hours;
408
409     vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
410     i_seek = i_seconds * 50 * p_intf->p_input->stream.i_mux_rate;
411     i_size = p_intf->p_input->stream.p_selected_area->i_size;
412     vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
413
414     if( i_seek < i_size )
415     {
416         input_Seek( p_intf->p_input, i_seek );
417     }
418     p_main->p_playlist->b_stopped = 0;
419     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
420 }
421
422
423 void GtkJumpCancel( GtkButton       *button,
424                     gpointer         user_data)
425 {
426     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
427 }
428
429
430 /****************************************************************************
431  * Callbacks for menuitems
432  ****************************************************************************/
433 void GtkExitActivate( GtkMenuItem * menuitem, gpointer user_data )
434 {
435     GtkExit( GTK_WIDGET( menuitem ), NULL, user_data );
436 }
437
438
439 void GtkFullscreenActivate( GtkMenuItem * menuitem, gpointer user_data )
440 {
441     GtkFullscreen( GTK_WIDGET( menuitem ), NULL, user_data );
442 }
443
444
445 void GtkWindowToggleActivate( GtkMenuItem * menuitem, gpointer user_data )
446 {
447     GtkWindowToggle( GTK_WIDGET( menuitem ), NULL, user_data );
448 }
449
450
451 void GtkAboutActivate( GtkMenuItem * menuitem, gpointer user_data )
452 {
453     GtkAboutShow( GTK_WIDGET( menuitem ), NULL, user_data );
454 }
455
456
457 void GtkJumpActivate( GtkMenuItem * menuitem, gpointer user_data )
458 {
459     GtkJumpShow( GTK_WIDGET( menuitem ), NULL, user_data );
460 }
461