]> git.sesse.net Git - vlc/blob - plugins/gnome/gnome_callbacks.c
-fixed little poliotage
[vlc] / plugins / gnome / gnome_callbacks.c
1 /*****************************************************************************
2  * gnome_callbacks.c : Callbacks for the Gnome plugin.
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: gnome_callbacks.c,v 1.22 2001/04/08 07:45: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 #define MODULE_NAME gnome
26 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32
33 #include <gnome.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_playlist.h"
45 #include "intf_msg.h"
46
47 #include "gnome_callbacks.h"
48 #include "gnome_interface.h"
49 #include "gnome_support.h"
50 #include "intf_gnome.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 /*****************************************************************************
65  * Interface callbacks
66  *****************************************************************************
67  * The following callbacks are related to the main interface window.
68  *****************************************************************************/
69 void
70 on_intf_window_destroy                 (GtkObject       *object,
71                                         gpointer         user_data)
72 {
73     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
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
80
81 gboolean
82 on_slider_button_press_event           (GtkWidget       *widget,
83                                         GdkEventButton  *event,
84                                         gpointer         user_data)
85 {
86     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
87
88     vlc_mutex_lock( &p_intf->change_lock );
89     p_intf->p_sys->b_slider_free = 0;
90     vlc_mutex_unlock( &p_intf->change_lock );
91
92     return FALSE;
93 }
94
95
96 gboolean
97 on_slider_button_release_event         (GtkWidget       *widget,
98                                         GdkEventButton  *event,
99                                         gpointer         user_data)
100 {
101     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
102
103     vlc_mutex_lock( &p_intf->change_lock );
104     p_intf->p_sys->b_slider_free = 1;
105     vlc_mutex_unlock( &p_intf->change_lock );
106
107     return FALSE;
108 }
109
110
111 void
112 on_intf_window_drag_data_received      (GtkWidget       *widget,
113                                         GdkDragContext  *drag_context,
114                                         gint             x,
115                                         gint             y,
116                                         GtkSelectionData *data,
117                                         guint            info,
118                                         guint            time,
119                                         gpointer         user_data)
120 {
121     char *psz_text = data->data;
122     int i_len      = strlen( psz_text );
123
124     switch( info )
125     {
126     case DROP_ACCEPT_TEXT_PLAIN: /* FIXME: handle multiple files */
127
128         if( i_len < 1 )
129         {
130             return;
131         }
132
133         /* get rid of ' ' at the end */
134         *( psz_text + i_len - 1 ) = 0;
135
136         intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
137         intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
138
139         break;
140
141     case DROP_ACCEPT_TEXT_URI_LIST: /* FIXME: handle multiple files */
142
143         if( i_len < 2 )
144         {
145             return;
146         }
147
148         /* get rid of \r\n at the end */
149         *( psz_text + i_len - 2 ) = 0;
150
151         intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'", psz_text );
152         intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
153         break;
154
155     default:
156
157         intf_ErrMsg( "intf error: unknown dropped type");
158         break;
159     }
160 }
161
162
163 void
164 on_button_title_prev_clicked           (GtkButton       *button,
165                                         gpointer         user_data)
166 {
167     intf_thread_t * p_intf;
168     input_area_t *  p_area;
169     int             i_id;
170
171     p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
172     i_id = p_intf->p_input->stream.p_selected_area->i_id - 1;
173
174     if( i_id >= 0 )
175     {
176         p_area = p_intf->p_input->stream.pp_areas[i_id];
177         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
178         p_intf->p_sys->b_menus_update = 1;
179
180         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
181
182         p_intf->p_sys->b_menus_update = 1;
183     }
184 }
185
186
187 void
188 on_button_title_next_clicked           (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), "intf_window" );
196     i_id = p_intf->p_input->stream.p_selected_area->i_id + 1;
197
198     if( i_id < p_intf->p_input->stream.i_area_nb )
199     {
200         p_area = p_intf->p_input->stream.pp_areas[i_id];   
201         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
202         p_intf->p_sys->b_menus_update = 1;
203
204         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
205
206         p_intf->p_sys->b_menus_update = 1;
207     }
208 }
209
210
211 void
212 on_button_chapter_prev_clicked         (GtkButton       *button,
213                                         gpointer         user_data)
214 {
215     intf_thread_t * p_intf;
216     input_area_t *  p_area;
217
218     p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
219     p_area = p_intf->p_input->stream.p_selected_area;
220
221     if( p_area->i_part > 0 )
222     {
223         p_area->i_part--;
224         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
225
226         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
227
228         p_intf->p_sys->b_menus_update = 1;
229     }
230 }
231
232
233 void
234 on_button_chapter_next_clicked         (GtkButton       *button,
235                                         gpointer         user_data)
236 {
237     intf_thread_t * p_intf;
238     input_area_t *  p_area;
239
240     p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
241     p_area = p_intf->p_input->stream.p_selected_area;
242
243     if( p_area->i_part < p_area->i_part_nb )
244     {
245         p_area->i_part++;
246         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
247
248         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
249
250         p_intf->p_sys->b_menus_update = 1;
251     }
252 }
253
254
255 /*****************************************************************************
256  * Menubar callbacks
257  *****************************************************************************
258  * The following callbacks are related to the menubar of the main
259  * interface window.
260  *****************************************************************************/
261 void
262 on_menubar_open_activate               (GtkMenuItem     *menuitem,
263                                         gpointer         user_data)
264 {
265     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
266
267     /* If we have never used the file selector, open it */
268     if( p_intf->p_sys->p_fileopen == NULL)
269     {
270         p_intf->p_sys->p_fileopen = create_intf_fileopen();
271         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
272                              "p_intf", p_intf );
273     }
274
275     gtk_widget_show( p_intf->p_sys->p_fileopen );
276     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
277 }
278
279
280 void
281 on_menubar_disc_activate               (GtkMenuItem     *menuitem,
282                                         gpointer         user_data)
283 {
284     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
285
286     gtk_widget_show( p_intf->p_sys->p_disc );
287     gdk_window_raise( p_intf->p_sys->p_disc->window );
288 }
289
290
291 void
292 on_menubar_network_activate            (GtkMenuItem     *menuitem,
293                                         gpointer         user_data)
294 {
295     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
296
297     gtk_widget_show( p_intf->p_sys->p_network );
298     gdk_window_raise( p_intf->p_sys->p_network->window );
299 }
300
301
302 void
303 on_menubar_exit_activate               (GtkMenuItem     *menuitem,
304                                         gpointer         user_data)
305 {
306     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
307
308     vlc_mutex_lock( &p_intf->change_lock );
309     p_intf->b_die = 1;
310     vlc_mutex_unlock( &p_intf->change_lock );
311 }
312
313
314 void
315 on_menubar_playlist_activate           (GtkMenuItem     *menuitem,
316                                         gpointer         user_data)
317 {
318     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
319
320     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
321     {
322         p_intf->p_sys->p_playlist = create_intf_playlist();
323         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
324                              "p_intf", p_intf );
325     }
326     gtk_widget_show( p_intf->p_sys->p_playlist );
327     gdk_window_raise( p_intf->p_sys->p_playlist->window );
328 }
329
330
331 void
332 on_menubar_audio_toggle                (GtkCheckMenuItem     *menuitem,
333                                         gpointer              user_data)
334 {
335     intf_thread_t *         p_intf;
336     es_descriptor_t *       p_es;
337
338     p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
339
340     if( !p_intf->p_sys->b_menus_update )
341     {
342         p_es = (es_descriptor_t*)user_data;
343
344         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
345     }
346 }
347
348
349 void
350 on_menubar_subtitle_toggle             (GtkCheckMenuItem     *menuitem,
351                                         gpointer              user_data)
352 {
353     intf_thread_t *         p_intf;
354     es_descriptor_t *       p_es;
355
356     p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
357
358     if( !p_intf->p_sys->b_menus_update )
359     {
360         p_es = (es_descriptor_t*)user_data;
361
362         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
363     }
364 }
365
366
367 void
368 on_menubar_title_toggle                (GtkCheckMenuItem     *menuitem,
369                                         gpointer              user_data)
370 {
371     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
372
373     if( menuitem->active && !p_intf->p_sys->b_menus_update )
374     {
375         p_intf->p_input->pf_set_area( p_intf->p_input,
376                                      (input_area_t*)user_data );
377
378         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
379
380         p_intf->p_sys->b_menus_update = 1;
381     }
382 }
383
384
385 void
386 on_menubar_chapter_toggle              (GtkCheckMenuItem     *menuitem,
387                                         gpointer              user_data)
388 {
389     intf_thread_t * p_intf    = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
390     input_area_t *  p_area    = p_intf->p_input->stream.p_selected_area;
391     gint            i_chapter = (gint)user_data;
392     char            psz_chapter[3];
393
394     if( menuitem->active && !p_intf->p_sys->b_menus_update )
395     {
396         p_area->i_part = i_chapter;
397         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
398
399         snprintf( psz_chapter, 3, "%02d", p_area->i_part );
400         gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
401
402         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
403
404         p_intf->p_sys->b_menus_update = 1;
405     }
406
407 }
408
409 void
410 on_menubar_modules_activate            (GtkMenuItem     *menuitem,
411                                         gpointer         user_data)
412 {
413     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
414
415     if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
416     {
417         p_intf->p_sys->p_modules = create_intf_modules();
418         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
419                              "p_intf", p_intf );
420     }
421     gtk_widget_show( p_intf->p_sys->p_modules );
422     gdk_window_raise( p_intf->p_sys->p_modules->window );
423 }
424
425
426 void
427 on_menubar_preferences_activate        (GtkMenuItem     *menuitem,
428                                         gpointer         user_data)
429 {
430
431 }
432
433
434 void
435 on_menubar_about_activate              (GtkMenuItem     *menuitem,
436                                         gpointer         user_data)
437 {
438     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
439
440     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
441     {
442         p_intf->p_sys->p_about = create_intf_about();
443         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
444                              "p_intf", p_intf );
445     }
446     gtk_widget_show( p_intf->p_sys->p_about );
447     gdk_window_raise( p_intf->p_sys->p_about->window );
448 }
449
450
451 /*****************************************************************************
452  * Toolbar callbacks
453  *****************************************************************************
454  * The following callbacks are related to the toolbar of the main
455  * interface window.
456  *****************************************************************************/
457 void
458 on_toolbar_open_clicked                (GtkButton       *button,
459                                         gpointer         user_data)
460 {
461     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
462
463     /* If we have never used the file selector, open it */
464     if( p_intf->p_sys->p_fileopen == NULL)
465     {
466         p_intf->p_sys->p_fileopen = create_intf_fileopen();
467         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
468                              "p_intf", p_intf );
469     }
470
471     gtk_widget_show( p_intf->p_sys->p_fileopen );
472     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
473 }
474
475
476 void
477 on_toolbar_disc_clicked                (GtkButton       *button,
478                                         gpointer         user_data)
479 {
480     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
481
482     gtk_widget_show( p_intf->p_sys->p_disc );
483     gdk_window_raise( p_intf->p_sys->p_disc->window );
484 }
485
486
487 void
488 on_toolbar_network_clicked             (GtkButton       *button,
489                                         gpointer         user_data)
490 {
491     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
492
493     gtk_widget_show( p_intf->p_sys->p_network );
494     gdk_window_raise( p_intf->p_sys->p_network->window );
495 }
496
497
498 void
499 on_toolbar_back_clicked                (GtkButton       *button,
500                                         gpointer         user_data)
501 {
502
503 }
504
505
506 void
507 on_toolbar_stop_clicked                (GtkButton       *button,
508                                         gpointer         user_data)
509 {
510
511 }
512
513
514 void
515 on_toolbar_play_clicked                (GtkButton       *button,
516                                         gpointer         user_data)
517 {
518     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
519
520     if( p_intf->p_input != NULL )
521     {
522         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
523     }
524 }
525
526
527 void
528 on_toolbar_pause_clicked               (GtkButton       *button,
529                                         gpointer         user_data)
530 {
531     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
532
533     if( p_intf->p_input != NULL )
534     {
535         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
536     }
537 }
538
539
540 void
541 on_toolbar_slow_clicked                (GtkButton       *button,
542                                         gpointer         user_data)
543 {
544     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
545
546     if( p_intf->p_input != NULL )
547     {
548         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
549     }
550 }
551
552
553 void
554 on_toolbar_fast_clicked                (GtkButton       *button,
555                                         gpointer         user_data)
556 {
557     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
558
559     if( p_intf->p_input != NULL )
560     {
561         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
562     }
563 }
564
565
566 void
567 on_toolbar_playlist_clicked            (GtkButton       *button,
568                                         gpointer         user_data)
569 {
570     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
571
572     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
573     {
574         p_intf->p_sys->p_playlist = create_intf_playlist();
575         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
576                              "p_intf", p_intf );
577     }
578     gtk_widget_show( p_intf->p_sys->p_playlist );
579     gdk_window_raise( p_intf->p_sys->p_playlist->window );
580 }
581
582
583 void
584 on_toolbar_prev_clicked                (GtkButton       *button,
585                                         gpointer         user_data)
586 {
587     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
588
589     if( p_intf->p_input != NULL )
590     {
591         /* FIXME: temporary hack */
592         intf_PlaylistPrev( p_main->p_playlist );
593         intf_PlaylistPrev( p_main->p_playlist );
594         p_intf->p_input->b_eof = 1;
595     }
596
597     p_intf->p_sys->b_mode_changed = 1;
598 }
599
600
601 void
602 on_toolbar_next_clicked                (GtkButton       *button,
603                                         gpointer         user_data)
604 {
605     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
606
607     if( p_intf->p_input != NULL )
608     {
609         /* FIXME: temporary hack */
610         p_intf->p_input->b_eof = 1;
611     }
612
613     p_intf->p_sys->b_mode_changed = 1;
614 }
615
616
617 /*****************************************************************************
618  * Popup callbacks
619  *****************************************************************************
620  * The following callbacks are related to the popup menu. The popup
621  * menu is activated when right-clicking on the video output window.
622  *****************************************************************************/
623 void
624 on_popup_play_activate                 (GtkMenuItem     *menuitem,
625                                         gpointer         user_data)
626 {
627     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
628
629     if( p_intf->p_input != NULL )
630     {
631         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
632     }
633 }
634
635
636 void
637 on_popup_pause_activate                (GtkMenuItem     *menuitem,
638                                         gpointer         user_data)
639 {
640     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
641
642     if( p_intf->p_input != NULL )
643     {
644         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
645     }
646 }
647
648
649 void
650 on_popup_slow_activate                 (GtkMenuItem     *menuitem,
651                                         gpointer         user_data)
652 {
653     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
654
655     if( p_intf->p_input != NULL )
656     {
657         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
658     }
659 }
660
661
662 void
663 on_popup_fast_activate                 (GtkMenuItem     *menuitem,
664                                         gpointer         user_data)
665 {
666     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
667
668     if( p_intf->p_input != NULL )
669     {
670         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
671     }
672 }
673
674
675 void
676 on_popup_audio_toggle                  (GtkCheckMenuItem     *menuitem,
677                                         gpointer              user_data)
678 {
679     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
680     es_descriptor_t *       p_es;
681
682     p_es = (es_descriptor_t*)user_data;
683
684     if( !p_intf->p_sys->b_menus_update )
685     {
686         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
687     }
688 }
689
690
691 void
692 on_popup_subtitle_toggle            (GtkCheckMenuItem     *menuitem,
693                                      gpointer              user_data)
694 {
695     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
696     es_descriptor_t *       p_es;
697
698     p_es = (es_descriptor_t*)user_data;
699
700     if( !p_intf->p_sys->b_menus_update )
701     {
702         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
703     }
704 }
705
706
707 void
708 on_popup_navigation_toggle             (GtkCheckMenuItem     *menuitem,
709                                         gpointer             user_data)
710 {
711     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
712
713     if( menuitem->active && !p_intf->p_sys->b_menus_update )
714     {
715         input_area_t *  p_area;
716         gint            i_title;
717         gint            i_chapter;
718
719         i_title   = (gint)(user_data) / 100;
720         i_chapter = (gint)(user_data) - ( 100 * i_title );
721
722         p_area = p_intf->p_input->stream.pp_areas[i_title];
723         p_area->i_part = i_chapter;
724
725         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
726
727         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
728
729         p_intf->p_sys->b_menus_update = 1;
730     }
731 }
732
733
734 void
735 on_popup_open_activate                 (GtkMenuItem     *menuitem,
736                                         gpointer         user_data)
737 {
738     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
739
740     /* If we have never used the file selector, open it */
741     if( p_intf->p_sys->p_fileopen == NULL)
742     {
743         p_intf->p_sys->p_fileopen = create_intf_fileopen();
744         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
745                              "p_intf", p_intf );
746     }
747
748     gtk_widget_show( p_intf->p_sys->p_fileopen );
749     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
750 }
751
752
753 void
754 on_popup_disc_activate                 (GtkMenuItem     *menuitem,
755                                         gpointer         user_data)
756 {
757     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
758
759     gtk_widget_show( p_intf->p_sys->p_disc );
760     gdk_window_raise( p_intf->p_sys->p_disc->window );
761 }
762
763
764 void
765 on_popup_network_activate              (GtkMenuItem     *menuitem,
766                                         gpointer         user_data)
767 {
768     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
769
770     gtk_widget_show( p_intf->p_sys->p_network );
771     gdk_window_raise( p_intf->p_sys->p_network->window );
772 }
773
774
775 void
776 on_popup_about_activate                (GtkMenuItem     *menuitem,
777                                         gpointer         user_data)
778 {
779     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
780
781     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
782     {
783         p_intf->p_sys->p_about = create_intf_about();
784         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
785                              "p_intf", p_intf );
786     }
787     gtk_widget_show( p_intf->p_sys->p_about );
788     gdk_window_raise( p_intf->p_sys->p_about->window );
789 }
790
791
792 void
793 on_popup_exit_activate                 (GtkMenuItem     *menuitem,
794                                         gpointer         user_data)
795 {
796     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
797
798     vlc_mutex_lock( &p_intf->change_lock );
799     p_intf->b_die = 1;
800     vlc_mutex_unlock( &p_intf->change_lock );
801 }
802
803
804 /*****************************************************************************
805  * Fileopen callbacks
806  *****************************************************************************
807  * The following callbacks are related to the file requester.
808  *****************************************************************************/
809 void
810 on_intf_fileopen_destroy               (GtkObject       *object,
811                                         gpointer         user_data)
812 {
813     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
814
815     p_intf->p_sys->p_fileopen = NULL;
816 }
817
818
819 void
820 on_fileopen_ok_clicked                 (GtkButton       *button,
821                                         gpointer         user_data)
822 {
823     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
824
825     GtkWidget *filesel;
826     gchar *filename;
827
828     filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
829     gtk_widget_hide (filesel);
830     filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
831
832     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
833
834     /* Select added item and switch to file interface */
835     intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );
836     if( p_intf->p_input != NULL )
837         p_intf->p_input->b_eof = 1;
838     p_intf->p_sys->i_intf_mode = FILE_MODE;
839     p_intf->p_sys->b_mode_changed = 1;
840 }
841
842
843 void
844 on_fileopen_cancel_clicked             (GtkButton       *button,
845                                         gpointer         user_data)
846 {
847     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
848 }
849
850
851 /*****************************************************************************
852  * Playlist callbacks
853  *****************************************************************************
854  * The following callbacks are related to the playlist.
855  *****************************************************************************/
856 void
857 on_intf_playlist_destroy               (GtkObject       *object,
858                                         gpointer         user_data)
859 {
860     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
861
862     p_intf->p_sys->p_playlist = NULL;
863 }
864
865
866 void
867 on_playlist_ok_clicked                 (GtkButton       *button,
868                                         gpointer         user_data)
869 {
870     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_playlist" );
871
872     gtk_widget_hide( p_intf->p_sys->p_playlist );
873 }
874
875
876 void
877 on_playlist_close_clicked              (GtkButton       *button,
878                                         gpointer         user_data)
879 {
880     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
881 }
882
883
884
885 /*****************************************************************************
886  * Module manager callbacks
887  *****************************************************************************
888  * The following callbacks are related to the module manager.
889  *****************************************************************************/
890 void
891 on_intf_modules_destroy                (GtkObject       *object,
892                                         gpointer         user_data)
893 {
894
895 }
896
897
898 void
899 on_modules_ok_clicked                  (GtkButton       *button,
900                                         gpointer         user_data)
901 {
902     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
903
904     gtk_widget_hide( p_intf->p_sys->p_modules );
905 }
906
907
908 void
909 on_modules_apply_clicked               (GtkButton       *button,
910                                         gpointer         user_data)
911 {
912
913 }
914
915
916 void
917 on_modules_cancel_clicked              (GtkButton       *button,
918                                         gpointer         user_data)
919 {
920     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
921 }
922
923
924 /*****************************************************************************
925  * Open disc callbacks
926  *****************************************************************************
927  * The following callbacks are related to the disc manager.
928  *****************************************************************************/
929 void
930 on_disc_dvd_toggled                    (GtkToggleButton *togglebutton,
931                                         gpointer         user_data)
932 {
933     if( togglebutton->active )
934     {
935         gtk_entry_set_text( GTK_ENTRY( lookup_widget(
936             GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
937     }
938 }
939
940
941 void
942 on_disc_vcd_toggled                    (GtkToggleButton *togglebutton,
943                                         gpointer         user_data)
944 {
945     if( togglebutton->active )
946     {
947         gtk_entry_set_text( GTK_ENTRY( lookup_widget(
948             GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
949     }
950 }
951
952
953 void
954 on_disc_ok_clicked                     (GtkButton       *button,
955                                         gpointer         user_data)
956 {
957     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
958     char *psz_device, *psz_source, *psz_method;
959
960     psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
961                                          GTK_WIDGET(button), "disc_name" ) ) );
962
963     /* "dvd:foo" has size 5 + strlen(foo) */
964     psz_source = malloc( 5 + strlen( psz_device ) );
965     if( psz_source == NULL )
966     {
967         return;
968     }
969
970     /* Check which method was activated */
971     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
972                                           "disc_dvd" ) )->active )
973     {
974         psz_method = "dvd";
975         p_intf->p_sys->i_intf_mode = DVD_MODE;
976     }
977     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
978                                                "disc_vcd" ) )->active )
979     {
980         psz_method = "vcd";
981     }
982     else
983     {
984         intf_ErrMsg( "intf error: unknown disc type toggle button position" );
985         free( psz_source );
986         return;
987     }
988     
989     /* Select title and chapter */
990     main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
991                               GTK_SPIN_BUTTON( lookup_widget(
992                                   GTK_WIDGET(button), "disc_title" ) ) ) );
993
994     main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
995                               GTK_SPIN_BUTTON( lookup_widget(
996                                   GTK_WIDGET(button), "disc_chapter" ) ) ) );
997
998     /* Build source name and add it to playlist */
999     sprintf( psz_source, "%s:%s", psz_method, psz_device );
1000     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
1001     free( psz_source );
1002
1003     /* Select added item and switch to DVD interface */
1004     intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );
1005     if( p_intf->p_input != NULL )
1006         p_intf->p_input->b_eof = 1;
1007     p_intf->p_sys->b_mode_changed = 1;
1008
1009     gtk_widget_hide( p_intf->p_sys->p_disc );
1010 }
1011
1012
1013 void
1014 on_disc_cancel_clicked                 (GtkButton       *button,
1015                                         gpointer         user_data)
1016 {
1017     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1018 }
1019
1020
1021 /*****************************************************************************
1022  * Network stream callbacks
1023  *****************************************************************************
1024  * The following callbacks are related to the network stream manager.
1025  *****************************************************************************/
1026 void
1027 on_network_ok_clicked                  (GtkButton       *button,
1028                                         gpointer         user_data)
1029 {
1030     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
1031     char *psz_source, *psz_server, *psz_protocol;
1032     unsigned int i_port;
1033
1034     psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
1035                                  GTK_WIDGET(button), "network_server" ) ) );
1036
1037     /* Check which protocol was activated */
1038     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
1039                                           "network_ts" ) )->active )
1040     {
1041         psz_protocol = "ts";
1042     }
1043     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
1044                                                "network_rtp" ) )->active )
1045     {
1046         psz_protocol = "rtp";
1047     }
1048     else
1049     {
1050         intf_ErrMsg( "intf error: unknown protocol toggle button position" );
1051         return;
1052     }
1053
1054     /* Get the port number and make sure it will not overflow 5 characters */
1055     i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
1056                  lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
1057     if( i_port > 65535 )
1058     {
1059         intf_ErrMsg( "intf error: invalid port %i", i_port );
1060     }
1061
1062     /* Allocate room for "protocol://server:port" */
1063     psz_source = malloc( strlen( psz_protocol ) + strlen( psz_server ) + 10 );
1064     if( psz_source == NULL )
1065     {
1066         return;
1067     }
1068    
1069     /* Build source name and add it to playlist */
1070     sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
1071     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
1072     free( psz_source );
1073
1074     /* Select added item and switch to network interface */
1075     intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );
1076     if( p_intf->p_input != NULL )
1077         p_intf->p_input->b_eof = 1;
1078     p_intf->p_sys->b_mode_changed = 1;
1079     p_intf->p_sys->i_intf_mode = NET_MODE;
1080
1081     gtk_widget_hide( p_intf->p_sys->p_network );
1082 }
1083
1084
1085 void
1086 on_network_cancel_clicked              (GtkButton       *button,
1087                                         gpointer         user_data)
1088 {
1089     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1090 }
1091