]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_callbacks.c
(note: empty CVS mails mean that a new directory has been created,
[vlc] / plugins / gtk / gtk_callbacks.c
1 /*****************************************************************************
2  * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
7  *      
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 #define MODULE_NAME gtk
24 #include "modules_inner.h"
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include "defs.h"
30
31 #include <gtk/gtk.h>
32
33 #include "config.h"
34 #include "common.h"
35 #include "threads.h"
36 #include "mtime.h"
37
38 #include "stream_control.h"
39 #include "input_ext-intf.h"
40
41 #include "interface.h"
42 #include "intf_plst.h"
43 #include "intf_msg.h"
44
45 #include "gtk_sys.h"
46 #include "gtk_callbacks.h"
47 #include "gtk_interface.h"
48 #include "gtk_support.h"
49
50 #include "main.h"
51
52 /*****************************************************************************
53  * Inline function to retrieve the interface structure
54  *****************************************************************************/
55 static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
56 {
57     return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
58                                  "p_intf" ) );
59 }
60
61 /*****************************************************************************
62  * Callbacks
63  ******************************************************************************/
64 void
65 on_menubar_open_activate               (GtkMenuItem     *menuitem,
66                                         gpointer         user_data)
67 {
68     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
69
70     /* If we have never used the file selector, open it */
71     if( p_intf->p_sys->p_fileopen == NULL)
72     {
73         p_intf->p_sys->p_fileopen = create_intf_fileopen();
74         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
75                              "p_intf", p_intf );
76     }
77
78     gtk_widget_show( p_intf->p_sys->p_fileopen );
79     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
80 }
81
82
83 void
84 on_menubar_exit_activate               (GtkMenuItem     *menuitem,
85                                         gpointer         user_data)
86 {
87     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
88
89     p_intf->b_die = 1;
90 }
91
92
93 void
94 on_menubar_playlist_activate           (GtkMenuItem     *menuitem,
95                                         gpointer         user_data)
96 {
97     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
98
99     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
100     {
101 //        p_intf->p_sys->p_playlist = create_intf_playlist();
102         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
103                              "p_intf", p_intf );
104     }
105     gtk_widget_show( p_intf->p_sys->p_playlist );
106     gdk_window_raise( p_intf->p_sys->p_playlist->window );
107 }
108
109
110 void
111 on_menubar_preferences_activate        (GtkMenuItem     *menuitem,
112                                         gpointer         user_data)
113 {
114
115 }
116
117
118 void
119 on_menubar_about_activate              (GtkMenuItem     *menuitem,
120                                         gpointer         user_data)
121 {
122     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
123
124     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
125     {
126         p_intf->p_sys->p_about = create_intf_about();
127         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
128                              "p_intf", p_intf );
129     }
130     gtk_widget_show( p_intf->p_sys->p_about );
131     gdk_window_raise( p_intf->p_sys->p_about->window );
132 }
133
134
135 void
136 on_toolbar_open_clicked                (GtkButton       *button,
137                                         gpointer         user_data)
138 {
139     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
140
141     /* If we have never used the file selector, open it */
142     if( p_intf->p_sys->p_fileopen == NULL)
143     {
144         p_intf->p_sys->p_fileopen = create_intf_fileopen();
145         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
146                              "p_intf", p_intf );
147     }
148
149     gtk_widget_show( p_intf->p_sys->p_fileopen );
150     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
151 }
152
153
154 void
155 on_toolbar_back_clicked                (GtkButton       *button,
156                                         gpointer         user_data)
157 {
158
159 }
160
161
162 void
163 on_toolbar_stop_clicked                (GtkButton       *button,
164                                         gpointer         user_data)
165 {
166
167 }
168
169
170 void
171 on_toolbar_play_clicked                (GtkButton       *button,
172                                         gpointer         user_data)
173 {
174     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
175
176     if( p_intf->p_input != NULL )
177     {
178         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
179     }
180 }
181
182
183 void
184 on_toolbar_pause_clicked               (GtkButton       *button,
185                                         gpointer         user_data)
186 {
187     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
188
189     if( p_intf->p_input != NULL )
190     {
191         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
192     }
193 }
194
195
196 void
197 on_toolbar_playlist_clicked            (GtkButton       *button,
198                                         gpointer         user_data)
199 {
200     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
201
202     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
203     {
204 //        p_intf->p_sys->p_playlist = create_intf_playlist();
205         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
206                              "p_intf", p_intf );
207     }
208     gtk_widget_show( p_intf->p_sys->p_playlist );
209     gdk_window_raise( p_intf->p_sys->p_playlist->window );
210 }
211
212
213 void
214 on_toolbar_prev_clicked                (GtkButton       *button,
215                                         gpointer         user_data)
216 {
217     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
218
219     if( p_intf->p_input != NULL )
220     {
221         /* FIXME: temporary hack */
222         intf_PlstPrev( p_main->p_playlist );
223         intf_PlstPrev( p_main->p_playlist );
224         p_intf->p_input->b_eof = 1;
225     }
226 }
227
228
229 void
230 on_toolbar_next_clicked                (GtkButton       *button,
231                                         gpointer         user_data)
232 {
233     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
234
235     if( p_intf->p_input != NULL )
236     {
237         /* FIXME: temporary hack */
238         p_intf->p_input->b_eof = 1;
239     }
240 }
241
242
243 void
244 on_popup_play_activate                 (GtkMenuItem     *menuitem,
245                                         gpointer         user_data)
246 {
247     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
248
249     if( p_intf->p_input != NULL )
250     {
251         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
252     }
253 }
254
255
256 void
257 on_popup_pause_activate                (GtkMenuItem     *menuitem,
258                                         gpointer         user_data)
259 {
260     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
261
262     if( p_intf->p_input != NULL )
263     {
264         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
265     }
266 }
267
268
269 void
270 on_popup_exit_activate                 (GtkMenuItem     *menuitem,
271                                         gpointer         user_data)
272 {
273     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
274
275     p_intf->b_die = 1;
276 }
277
278
279 void
280 on_intf_window_destroy                 (GtkObject       *object,
281                                         gpointer         user_data)
282 {
283     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
284
285     /* FIXME don't destroy the window, just hide it */
286     p_intf->b_die = 1;
287     p_intf->p_sys->p_window = NULL;
288 }
289
290
291 void
292 on_fileopen_ok_clicked                 (GtkButton       *button,
293                                         gpointer         user_data)
294 {
295     GtkWidget *filesel;
296     gchar *filename;
297
298     filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
299     gtk_widget_hide (filesel);
300     filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
301
302     intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
303 }
304
305
306 void
307 on_fileopen_cancel_clicked             (GtkButton       *button,
308                                         gpointer         user_data)
309 {
310     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
311 }
312
313
314 void
315 on_intf_fileopen_destroy               (GtkObject       *object,
316                                         gpointer         user_data)
317 {
318     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
319
320     p_intf->p_sys->p_fileopen = NULL;
321 }
322
323
324 void
325 on_popup_open_activate                 (GtkMenuItem     *menuitem,
326                                         gpointer         user_data)
327 {
328     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
329
330     /* If we have never used the file selector, open it */
331     if( p_intf->p_sys->p_fileopen == NULL)
332     {
333         p_intf->p_sys->p_fileopen = create_intf_fileopen();
334         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
335                              "p_intf", p_intf );
336     }
337
338     gtk_widget_show( p_intf->p_sys->p_fileopen );
339     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
340 }
341
342
343 void
344 on_popup_about_activate                (GtkMenuItem     *menuitem,
345                                         gpointer         user_data)
346 {
347     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
348
349     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
350     {
351         p_intf->p_sys->p_about = create_intf_about();
352         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
353                              "p_intf", p_intf );
354     }
355     gtk_widget_show( p_intf->p_sys->p_about );
356     gdk_window_raise( p_intf->p_sys->p_about->window );
357 }
358
359
360 void
361 on_intf_playlist_destroy               (GtkObject       *object,
362                                         gpointer         user_data)
363 {
364     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
365
366     p_intf->p_sys->p_playlist = NULL;
367 }
368
369
370 void
371 on_playlist_close_clicked              (GtkButton       *button,
372                                         gpointer         user_data)
373 {
374     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
375 }
376
377
378 void
379 on_popup_slow_activate                 (GtkMenuItem     *menuitem,
380                                         gpointer         user_data)
381 {
382     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
383
384     if( p_intf->p_input != NULL )
385     {
386         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
387     }
388 }
389
390
391 void
392 on_popup_fast_activate                 (GtkMenuItem     *menuitem,
393                                         gpointer         user_data)
394 {
395     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
396
397     if( p_intf->p_input != NULL )
398     {
399         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
400     }
401 }
402
403
404 void
405 on_toolbar_slow_clicked                (GtkButton       *button,
406                                         gpointer         user_data)
407 {
408     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
409
410     if( p_intf->p_input != NULL )
411     {
412         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
413     }
414 }
415
416
417 void
418 on_toolbar_fast_clicked                (GtkButton       *button,
419                                         gpointer         user_data)
420 {
421     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
422
423     if( p_intf->p_input != NULL )
424     {
425         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
426     }
427 }
428
429
430 gboolean
431 on_hscale_button_release_event         (GtkWidget       *widget,
432                                         GdkEventButton  *event,
433                                         gpointer         user_data)
434 {
435     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
436
437     GtkAdjustment *p_adj = gtk_range_get_adjustment( GTK_RANGE(widget) );
438     off_t i_seek;
439
440     vlc_mutex_lock( &p_intf->p_sys->change_lock );
441
442     if( p_intf->p_input != NULL )
443     {
444         i_seek = (p_adj->value *
445                   p_intf->p_input->stream.p_selected_area->i_size) / 100;
446         input_Seek( p_intf->p_input, i_seek );
447     }
448     p_intf->p_sys->b_scale_isfree = 1;
449
450     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
451
452     return FALSE;
453 }
454
455
456 gboolean
457 on_hscale_button_press_event           (GtkWidget       *widget,
458                                         GdkEventButton  *event,
459                                         gpointer         user_data)
460 {
461     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
462
463     vlc_mutex_lock( &p_intf->p_sys->change_lock );
464     p_intf->p_sys->b_scale_isfree = 0;
465     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
466
467     return FALSE;
468 }
469
470
471
472 void
473 on_intf_modules_destroy                (GtkObject       *object,
474                                         gpointer         user_data)
475 {
476
477 }
478
479
480 void
481 on_modules_ok_clicked                  (GtkButton       *button,
482                                         gpointer         user_data)
483 {
484     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
485
486     gtk_widget_hide( p_intf->p_sys->p_modules );
487
488 }
489
490
491 void
492 on_modules_apply_clicked               (GtkButton       *button,
493                                         gpointer         user_data)
494 {
495
496 }
497
498
499 void
500 on_modules_cancel_clicked              (GtkButton       *button,
501                                         gpointer         user_data)
502 {
503     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
504
505     gtk_widget_hide( p_intf->p_sys->p_modules );
506 }
507
508
509 void
510 on_playlist_ok_clicked                 (GtkButton       *button,
511                                         gpointer         user_data)
512 {
513     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_playlist" );
514
515     gtk_widget_hide( p_intf->p_sys->p_playlist );
516 }
517
518
519 void
520 on_menubar_modules_activate            (GtkMenuItem     *menuitem,
521                                         gpointer         user_data)
522 {
523     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
524
525     if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
526     {
527 //        p_intf->p_sys->p_modules = create_intf_modules();
528         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
529                              "p_intf", p_intf );
530     }
531     gtk_widget_show( p_intf->p_sys->p_modules );
532     gdk_window_raise( p_intf->p_sys->p_modules->window );
533 }
534
535
536 void
537 on_intf_window_drag_data_received      (GtkWidget       *widget,
538                                         GdkDragContext  *drag_context,
539                                         gint             x,
540                                         gint             y,
541                                         GtkSelectionData *data,
542                                         guint            info,
543                                         guint            time,
544                                         gpointer         user_data)
545 {
546     char *psz_text = data->data;
547     int i_len      = strlen( psz_text );
548
549     switch( info )
550     {
551     case DROP_ACCEPT_TEXT_PLAIN: /* FIXME: handle multiple files */
552
553         if( i_len < 1 )
554         {
555             return;
556         }
557
558         /* get rid of ' ' at the end */
559         *( psz_text + i_len - 1 ) = 0;
560
561         intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
562         intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
563
564         break;
565
566     case DROP_ACCEPT_TEXT_URI_LIST: /* FIXME: handle multiple files */
567
568         if( i_len < 2 )
569         {
570             return;
571         }
572
573         /* get rid of \r\n at the end */
574         *( psz_text + i_len - 2 ) = 0;
575
576         intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
577         intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
578         break;
579
580     default:
581
582         intf_ErrMsg( "intf error: unknown dropped type");
583         break;
584     }
585 }
586
587
588 void
589 on_about_ok_clicked                    (GtkButton       *button,
590                                         gpointer         user_data)
591 {
592     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
593
594     gtk_widget_hide( p_intf->p_sys->p_about );
595 }
596