]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_callbacks.c
* Everything in place for the 0.2.63 release.
[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 <stdlib.h>
32
33 #include <gtk/gtk.h>
34
35 #include "config.h"
36 #include "common.h"
37 #include "threads.h"
38 #include "mtime.h"
39
40 #include "stream_control.h"
41 #include "input_ext-intf.h"
42
43 #include "interface.h"
44 #include "intf_plst.h"
45 #include "intf_msg.h"
46
47 #include "gtk_sys.h"
48 #include "gtk_callbacks.h"
49 #include "gtk_interface.h"
50 #include "gtk_support.h"
51
52 #include "main.h"
53
54 /*****************************************************************************
55  * Inline function to retrieve the interface structure
56  *****************************************************************************/
57 static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
58 {
59     return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
60                                  "p_intf" ) );
61 }
62
63 /*****************************************************************************
64  * Callbacks
65  ******************************************************************************/
66 void
67 on_menubar_open_activate               (GtkMenuItem     *menuitem,
68                                         gpointer         user_data)
69 {
70     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
71
72     /* If we have never used the file selector, open it */
73     if( p_intf->p_sys->p_fileopen == NULL)
74     {
75         p_intf->p_sys->p_fileopen = create_intf_fileopen();
76         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
77                              "p_intf", p_intf );
78     }
79
80     gtk_widget_show( p_intf->p_sys->p_fileopen );
81     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
82 }
83
84
85 void
86 on_menubar_exit_activate               (GtkMenuItem     *menuitem,
87                                         gpointer         user_data)
88 {
89     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
90
91     p_intf->b_die = 1;
92 }
93
94
95 void
96 on_menubar_playlist_activate           (GtkMenuItem     *menuitem,
97                                         gpointer         user_data)
98 {
99     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
100
101     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
102     {
103 //        p_intf->p_sys->p_playlist = create_intf_playlist();
104         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
105                              "p_intf", p_intf );
106     }
107     gtk_widget_show( p_intf->p_sys->p_playlist );
108     gdk_window_raise( p_intf->p_sys->p_playlist->window );
109 }
110
111
112 void
113 on_menubar_preferences_activate        (GtkMenuItem     *menuitem,
114                                         gpointer         user_data)
115 {
116
117 }
118
119
120 void
121 on_menubar_about_activate              (GtkMenuItem     *menuitem,
122                                         gpointer         user_data)
123 {
124     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
125
126     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
127     {
128         p_intf->p_sys->p_about = create_intf_about();
129         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
130                              "p_intf", p_intf );
131     }
132     gtk_widget_show( p_intf->p_sys->p_about );
133     gdk_window_raise( p_intf->p_sys->p_about->window );
134 }
135
136
137 void
138 on_toolbar_open_clicked                (GtkButton       *button,
139                                         gpointer         user_data)
140 {
141     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
142
143     /* If we have never used the file selector, open it */
144     if( p_intf->p_sys->p_fileopen == NULL)
145     {
146         p_intf->p_sys->p_fileopen = create_intf_fileopen();
147         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
148                              "p_intf", p_intf );
149     }
150
151     gtk_widget_show( p_intf->p_sys->p_fileopen );
152     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
153 }
154
155
156 void
157 on_toolbar_back_clicked                (GtkButton       *button,
158                                         gpointer         user_data)
159 {
160
161 }
162
163
164 void
165 on_toolbar_stop_clicked                (GtkButton       *button,
166                                         gpointer         user_data)
167 {
168
169 }
170
171
172 void
173 on_toolbar_play_clicked                (GtkButton       *button,
174                                         gpointer         user_data)
175 {
176     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
177
178     if( p_intf->p_input != NULL )
179     {
180         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
181     }
182 }
183
184
185 void
186 on_toolbar_pause_clicked               (GtkButton       *button,
187                                         gpointer         user_data)
188 {
189     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
190
191     if( p_intf->p_input != NULL )
192     {
193         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
194     }
195 }
196
197
198 void
199 on_toolbar_playlist_clicked            (GtkButton       *button,
200                                         gpointer         user_data)
201 {
202     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
203
204     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
205     {
206 //        p_intf->p_sys->p_playlist = create_intf_playlist();
207         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
208                              "p_intf", p_intf );
209     }
210     gtk_widget_show( p_intf->p_sys->p_playlist );
211     gdk_window_raise( p_intf->p_sys->p_playlist->window );
212 }
213
214
215 void
216 on_toolbar_prev_clicked                (GtkButton       *button,
217                                         gpointer         user_data)
218 {
219     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
220
221     if( p_intf->p_input != NULL )
222     {
223         /* FIXME: temporary hack */
224         intf_PlstPrev( p_main->p_playlist );
225         intf_PlstPrev( p_main->p_playlist );
226         p_intf->p_input->b_eof = 1;
227     }
228 }
229
230
231 void
232 on_toolbar_next_clicked                (GtkButton       *button,
233                                         gpointer         user_data)
234 {
235     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
236
237     if( p_intf->p_input != NULL )
238     {
239         /* FIXME: temporary hack */
240         p_intf->p_input->b_eof = 1;
241     }
242 }
243
244
245 void
246 on_popup_play_activate                 (GtkMenuItem     *menuitem,
247                                         gpointer         user_data)
248 {
249     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
250
251     if( p_intf->p_input != NULL )
252     {
253         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
254     }
255 }
256
257
258 void
259 on_popup_pause_activate                (GtkMenuItem     *menuitem,
260                                         gpointer         user_data)
261 {
262     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
263
264     if( p_intf->p_input != NULL )
265     {
266         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
267     }
268 }
269
270
271 void
272 on_popup_exit_activate                 (GtkMenuItem     *menuitem,
273                                         gpointer         user_data)
274 {
275     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
276
277     p_intf->b_die = 1;
278 }
279
280
281 void
282 on_intf_window_destroy                 (GtkObject       *object,
283                                         gpointer         user_data)
284 {
285     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
286
287     /* FIXME don't destroy the window, just hide it */
288     p_intf->b_die = 1;
289     p_intf->p_sys->p_window = NULL;
290 }
291
292
293 void
294 on_fileopen_ok_clicked                 (GtkButton       *button,
295                                         gpointer         user_data)
296 {
297     GtkWidget *filesel;
298     gchar *filename;
299
300     filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
301     gtk_widget_hide (filesel);
302     filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
303
304     intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
305 }
306
307
308 void
309 on_fileopen_cancel_clicked             (GtkButton       *button,
310                                         gpointer         user_data)
311 {
312     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
313 }
314
315
316 void
317 on_intf_fileopen_destroy               (GtkObject       *object,
318                                         gpointer         user_data)
319 {
320     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
321
322     p_intf->p_sys->p_fileopen = NULL;
323 }
324
325
326 void
327 on_popup_open_activate                 (GtkMenuItem     *menuitem,
328                                         gpointer         user_data)
329 {
330     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
331
332     /* If we have never used the file selector, open it */
333     if( p_intf->p_sys->p_fileopen == NULL)
334     {
335         p_intf->p_sys->p_fileopen = create_intf_fileopen();
336         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
337                              "p_intf", p_intf );
338     }
339
340     gtk_widget_show( p_intf->p_sys->p_fileopen );
341     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
342 }
343
344
345 void
346 on_popup_about_activate                (GtkMenuItem     *menuitem,
347                                         gpointer         user_data)
348 {
349     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
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
361
362 void
363 on_intf_playlist_destroy               (GtkObject       *object,
364                                         gpointer         user_data)
365 {
366     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
367
368     p_intf->p_sys->p_playlist = NULL;
369 }
370
371
372 void
373 on_playlist_close_clicked              (GtkButton       *button,
374                                         gpointer         user_data)
375 {
376     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
377 }
378
379
380 void
381 on_popup_slow_activate                 (GtkMenuItem     *menuitem,
382                                         gpointer         user_data)
383 {
384     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
385
386     if( p_intf->p_input != NULL )
387     {
388         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
389     }
390 }
391
392
393 void
394 on_popup_fast_activate                 (GtkMenuItem     *menuitem,
395                                         gpointer         user_data)
396 {
397     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
398
399     if( p_intf->p_input != NULL )
400     {
401         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
402     }
403 }
404
405
406 void
407 on_toolbar_slow_clicked                (GtkButton       *button,
408                                         gpointer         user_data)
409 {
410     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
411
412     if( p_intf->p_input != NULL )
413     {
414         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
415     }
416 }
417
418
419 void
420 on_toolbar_fast_clicked                (GtkButton       *button,
421                                         gpointer         user_data)
422 {
423     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
424
425     if( p_intf->p_input != NULL )
426     {
427         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
428     }
429 }
430
431
432 gboolean
433 on_hscale_button_release_event         (GtkWidget       *widget,
434                                         GdkEventButton  *event,
435                                         gpointer         user_data)
436 {
437     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
438
439     GtkAdjustment *p_adj = gtk_range_get_adjustment( GTK_RANGE(widget) );
440     off_t i_seek;
441
442     vlc_mutex_lock( &p_intf->p_sys->change_lock );
443
444     if( p_intf->p_input != NULL )
445     {
446         i_seek = (p_adj->value *
447                   p_intf->p_input->stream.p_selected_area->i_size) / 100;
448         input_Seek( p_intf->p_input, i_seek );
449     }
450     p_intf->p_sys->b_scale_isfree = 1;
451
452     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
453
454     return FALSE;
455 }
456
457
458 gboolean
459 on_hscale_button_press_event           (GtkWidget       *widget,
460                                         GdkEventButton  *event,
461                                         gpointer         user_data)
462 {
463     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
464
465     vlc_mutex_lock( &p_intf->p_sys->change_lock );
466     p_intf->p_sys->b_scale_isfree = 0;
467     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
468
469     return FALSE;
470 }
471
472
473
474 void
475 on_intf_modules_destroy                (GtkObject       *object,
476                                         gpointer         user_data)
477 {
478
479 }
480
481
482 void
483 on_modules_ok_clicked                  (GtkButton       *button,
484                                         gpointer         user_data)
485 {
486     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
487
488     gtk_widget_hide( p_intf->p_sys->p_modules );
489
490 }
491
492
493 void
494 on_modules_apply_clicked               (GtkButton       *button,
495                                         gpointer         user_data)
496 {
497
498 }
499
500
501 void
502 on_modules_cancel_clicked              (GtkButton       *button,
503                                         gpointer         user_data)
504 {
505     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
506
507     gtk_widget_hide( p_intf->p_sys->p_modules );
508 }
509
510
511 void
512 on_playlist_ok_clicked                 (GtkButton       *button,
513                                         gpointer         user_data)
514 {
515     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_playlist" );
516
517     gtk_widget_hide( p_intf->p_sys->p_playlist );
518 }
519
520
521 void
522 on_menubar_modules_activate            (GtkMenuItem     *menuitem,
523                                         gpointer         user_data)
524 {
525     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
526
527     if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
528     {
529 //        p_intf->p_sys->p_modules = create_intf_modules();
530         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
531                              "p_intf", p_intf );
532     }
533     gtk_widget_show( p_intf->p_sys->p_modules );
534     gdk_window_raise( p_intf->p_sys->p_modules->window );
535 }
536
537
538 void
539 on_intf_window_drag_data_received      (GtkWidget       *widget,
540                                         GdkDragContext  *drag_context,
541                                         gint             x,
542                                         gint             y,
543                                         GtkSelectionData *data,
544                                         guint            info,
545                                         guint            time,
546                                         gpointer         user_data)
547 {
548     char *psz_text = data->data;
549     int i_len      = strlen( psz_text );
550
551     switch( info )
552     {
553     case DROP_ACCEPT_TEXT_PLAIN: /* FIXME: handle multiple files */
554
555         if( i_len < 1 )
556         {
557             return;
558         }
559
560         /* get rid of ' ' at the end */
561         *( psz_text + i_len - 1 ) = 0;
562
563         intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
564         intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
565
566         break;
567
568     case DROP_ACCEPT_TEXT_URI_LIST: /* FIXME: handle multiple files */
569
570         if( i_len < 2 )
571         {
572             return;
573         }
574
575         /* get rid of \r\n at the end */
576         *( psz_text + i_len - 2 ) = 0;
577
578         intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
579         intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
580         break;
581
582     default:
583
584         intf_ErrMsg( "intf error: unknown dropped type");
585         break;
586     }
587 }
588
589
590 void
591 on_about_ok_clicked                    (GtkButton       *button,
592                                         gpointer         user_data)
593 {
594     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_about" );
595
596     gtk_widget_hide( p_intf->p_sys->p_about );
597 }
598
599
600 void
601 on_menubar_disc_activate               (GtkMenuItem     *menuitem,
602                                         gpointer         user_data)
603 {
604     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
605
606     if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
607     {
608         p_intf->p_sys->p_disc = create_intf_disc();
609         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
610                              "p_intf", p_intf );
611     }
612     gtk_widget_show( p_intf->p_sys->p_disc );
613     gdk_window_raise( p_intf->p_sys->p_disc->window );
614 }
615
616
617 void
618 on_toolbar_disc_clicked                (GtkButton       *button,
619                                         gpointer         user_data)
620 {
621     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
622
623     if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
624     {
625         p_intf->p_sys->p_disc = create_intf_disc();
626         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
627                              "p_intf", p_intf );
628     }
629     gtk_widget_show( p_intf->p_sys->p_disc );
630     gdk_window_raise( p_intf->p_sys->p_disc->window );
631 }
632
633
634 void
635 on_disc_ok_clicked                     (GtkButton       *button,
636                                         gpointer         user_data)
637 {
638     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
639     char *psz_device, *psz_source, *psz_method;
640
641     psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
642                                          GTK_WIDGET(button), "disc_name" ) ) );
643
644     /* "dvd:foo" has size 5 + strlen(foo) */
645     psz_source = malloc( 5 + strlen( psz_device ) );
646     if( psz_source == NULL )
647     {
648         return;
649     }
650
651     /* Check which method was activated */
652     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
653                                           "disc_dvd" ) )->active )
654     {
655         psz_method = "dvd";
656     }
657     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
658                                                "disc_vcd" ) )->active )
659     {
660         psz_method = "vcd";
661     }
662     else
663     {
664         intf_ErrMsg( "intf error: unknown toggle button configuration" );
665         free( psz_source );
666         return;
667     }
668     
669     /* Select title and chapter */
670     main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
671                               GTK_SPIN_BUTTON( lookup_widget(
672                                   GTK_WIDGET(button), "disc_title" ) ) ) );
673
674     main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
675                               GTK_SPIN_BUTTON( lookup_widget(
676                                   GTK_WIDGET(button), "disc_chapter" ) ) ) );
677
678     /* Build source name and add it to playlist */
679     sprintf( psz_source, "%s:%s", psz_method, psz_device );
680     intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
681
682     gtk_widget_hide( p_intf->p_sys->p_disc );
683 }
684
685
686 void
687 on_disc_cancel_clicked                 (GtkButton       *button,
688                                         gpointer         user_data)
689 {
690     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
691
692     gtk_widget_hide( p_intf->p_sys->p_disc );
693 }
694
695
696 void
697 on_disc_dvd_toggled                    (GtkToggleButton *togglebutton,
698                                         gpointer         user_data)
699 {
700     if( togglebutton->active )
701     {
702         gtk_entry_set_text( GTK_ENTRY( lookup_widget(
703             GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
704     }
705 }
706
707
708 void
709 on_disc_vcd_toggled                    (GtkToggleButton *togglebutton,
710                                         gpointer         user_data)
711 {
712     if( togglebutton->active )
713     {
714         gtk_entry_set_text( GTK_ENTRY( lookup_widget(
715             GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
716     }
717 }
718
719
720 void
721 on_popup_disc_activate                 (GtkMenuItem     *menuitem,
722                                         gpointer         user_data)
723 {
724     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
725
726     if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
727     {
728         p_intf->p_sys->p_disc = create_intf_disc();
729         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
730                              "p_intf", p_intf );
731     }
732     gtk_widget_show( p_intf->p_sys->p_disc );
733     gdk_window_raise( p_intf->p_sys->p_disc->window );
734 }
735