]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_callbacks.c
96c9405ca56463290872ea4c8b26a629cc61eb0a
[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.21 2001/05/30 05:19: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 /*****************************************************************************
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         GtkSetupMenus( p_intf );
207     }
208 }
209
210
211 void GtkTitleNext( GtkButton * button, gpointer user_data )
212 {
213     intf_thread_t * p_intf;
214     input_area_t *  p_area;
215     int             i_id;
216
217     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
218     i_id = p_intf->p_input->stream.p_selected_area->i_id + 1;
219
220     if( i_id < p_intf->p_input->stream.i_area_nb )
221     {
222         p_area = p_intf->p_input->stream.pp_areas[i_id];   
223         input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
224
225         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
226
227         p_intf->p_sys->b_title_update = 1;
228         GtkSetupMenus( p_intf );
229     }
230
231 }
232
233
234 void GtkChapterPrev( GtkButton * button, gpointer user_data )
235 {
236     intf_thread_t * p_intf;
237     input_area_t *  p_area;
238
239     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
240     p_area = p_intf->p_input->stream.p_selected_area;
241
242     if( p_area->i_part > 0 )
243     {
244         p_area->i_part--;
245         input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
246
247         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
248
249         p_intf->p_sys->b_chapter_update = 1;
250         GtkSetupMenus( p_intf );
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_intf->p_input->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_intf->p_input, (input_area_t*)p_area );
267
268         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
269
270         p_intf->p_sys->b_chapter_update = 1;
271         GtkSetupMenus( p_intf );
272     }
273 }
274
275 /****************************************************************************
276  * Network specific items
277  ****************************************************************************/
278 void GtkNetworkJoin( GtkEditable * editable, gpointer user_data )
279 {
280     int     i_channel;
281
282     i_channel = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( editable ) );
283     intf_WarnMsg( 3, "intf info: joining channel %d", i_channel );
284
285 //    network_ChannelJoin( i_channel );
286 }
287
288 void GtkChannelGo( GtkButton * button, gpointer user_data )
289 {
290     GtkWidget *     window;
291     GtkWidget *     spin;
292     int             i_channel;
293
294     window = gtk_widget_get_toplevel( GTK_WIDGET (button) );
295     spin = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( window ),
296                        "network_channel_spinbutton" ) );
297
298     i_channel = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spin ) );
299     intf_WarnMsg( 3, "intf info: joining channel %d", i_channel );
300
301     network_ChannelJoin( i_channel );
302 }
303
304
305 /****************************************************************************
306  * About box
307  ****************************************************************************/
308
309 gboolean GtkAboutShow( GtkWidget       *widget,
310                        GdkEventButton  *event,
311                        gpointer         user_data)
312 {
313     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
314
315     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
316     {
317         p_intf->p_sys->p_about = create_intf_about();
318         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
319                              "p_intf", p_intf );
320     }
321     gtk_widget_show( p_intf->p_sys->p_about );
322     gdk_window_raise( p_intf->p_sys->p_about->window );
323
324     return TRUE;
325 }
326
327 void GtkAboutOk( GtkButton * button, gpointer user_data)
328 {
329     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
330
331     gtk_widget_hide( p_intf->p_sys->p_about );
332 }
333
334
335 /****************************************************************************
336  * Jump box
337  ****************************************************************************/
338
339 gboolean GtkJumpShow( 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_jump ) )
346     {
347         p_intf->p_sys->p_jump = create_intf_jump();
348         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_jump ),
349                              "p_intf", p_intf );
350     }
351
352     gtk_widget_show( p_intf->p_sys->p_jump );
353     gdk_window_raise( p_intf->p_sys->p_jump->window );
354
355     return FALSE;
356 }
357
358
359 void GtkJumpOk( GtkButton       *button,
360                 gpointer         user_data)
361 {
362     intf_thread_t * p_intf;
363     off_t           i_seek;
364     off_t           i_size;
365     int             i_hours;
366     int             i_minutes;
367     int             i_seconds;
368
369     p_intf = GetIntf( GTK_WIDGET( button ), (char*)user_data );
370
371 #define GET_VALUE( name )                                                   \
372     gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gtk_object_get_data( \
373         GTK_OBJECT( p_intf->p_sys->p_jump ), name ) ) )
374
375     i_hours   = GET_VALUE( "jump_hour_spinbutton" );
376     i_minutes = GET_VALUE( "jump_minute_spinbutton" );
377     i_seconds = GET_VALUE( "jump_second_spinbutton" );
378
379 #undef GET_VALUE
380
381     i_seconds += 60 *i_minutes + 3600* i_hours;
382
383     vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
384     i_seek = i_seconds * 50 * p_intf->p_input->stream.i_mux_rate;
385     i_size = p_intf->p_input->stream.p_selected_area->i_size;
386     vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
387
388     if( i_seek < i_size )
389     {
390         input_Seek( p_intf->p_input, i_seek );
391     }
392     p_main->p_playlist->b_stopped = 0;
393     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
394 }
395
396
397 void GtkJumpCancel( GtkButton       *button,
398                     gpointer         user_data)
399 {
400     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
401 }
402
403
404 /****************************************************************************
405  * Callbacks for menuitems
406  ****************************************************************************/
407 void GtkExitActivate( GtkMenuItem * menuitem, gpointer user_data )
408 {
409     GtkExit( GTK_WIDGET( menuitem ), NULL, user_data );
410 }
411
412
413 void GtkFullscreenActivate( GtkMenuItem * menuitem, gpointer user_data )
414 {
415     GtkFullscreen( GTK_WIDGET( menuitem ), NULL, user_data );
416 }
417
418
419 void GtkWindowToggleActivate( GtkMenuItem * menuitem, gpointer user_data )
420 {
421     GtkWindowToggle( GTK_WIDGET( menuitem ), NULL, user_data );
422 }
423
424
425 void GtkAboutActivate( GtkMenuItem * menuitem, gpointer user_data )
426 {
427     GtkAboutShow( GTK_WIDGET( menuitem ), NULL, user_data );
428 }
429
430
431 void GtkJumpActivate( GtkMenuItem * menuitem, gpointer user_data )
432 {
433     GtkJumpShow( GTK_WIDGET( menuitem ), NULL, user_data );
434 }
435