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