]> git.sesse.net Git - vlc/blob - plugins/gnome/gnome_callbacks.c
-changes in gnome interface
[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.21 2001/04/08 07:24:47 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     if( !p_intf->p_sys->b_menus_update )
339     {
340         p_es = (es_descriptor_t*)user_data;
341
342         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
343     }
344 }
345
346
347 void
348 on_menubar_subtitle_toggle             (GtkCheckMenuItem     *menuitem,
349                                         gpointer              user_data)
350 {
351     intf_thread_t *         p_intf;
352     es_descriptor_t *       p_es;
353
354     p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
355
356     if( !p_intf->p_sys->b_menus_update )
357     {
358         p_es = (es_descriptor_t*)user_data;
359
360         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
361     }
362 }
363
364
365 void
366 on_menubar_title_toggle                (GtkCheckMenuItem     *menuitem,
367                                         gpointer              user_data)
368 {
369     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
370
371     if( menuitem->active && !p_intf->p_sys->b_menus_update )
372     {
373         p_intf->p_input->pf_set_area( p_intf->p_input,
374                                      (input_area_t*)user_data );
375
376         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
377
378         p_intf->p_sys->b_menus_update = 1;
379     }
380 }
381
382
383 void
384 on_menubar_chapter_toggle              (GtkCheckMenuItem     *menuitem,
385                                         gpointer              user_data)
386 {
387     intf_thread_t * p_intf    = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
388     input_area_t *  p_area    = p_intf->p_input->stream.p_selected_area;
389     gint            i_chapter = (gint)user_data;
390     char            psz_chapter[3];
391
392     if( menuitem->active && !p_intf->p_sys->b_menus_update )
393     {
394         p_area->i_part = i_chapter;
395         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
396
397         snprintf( psz_chapter, 3, "%02d", p_area->i_part );
398         gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
399
400         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
401
402         p_intf->p_sys->b_menus_update = 1;
403     }
404
405 }
406
407 void
408 on_menubar_modules_activate            (GtkMenuItem     *menuitem,
409                                         gpointer         user_data)
410 {
411     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
412
413     if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
414     {
415         p_intf->p_sys->p_modules = create_intf_modules();
416         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
417                              "p_intf", p_intf );
418     }
419     gtk_widget_show( p_intf->p_sys->p_modules );
420     gdk_window_raise( p_intf->p_sys->p_modules->window );
421 }
422
423
424 void
425 on_menubar_preferences_activate        (GtkMenuItem     *menuitem,
426                                         gpointer         user_data)
427 {
428
429 }
430
431
432 void
433 on_menubar_about_activate              (GtkMenuItem     *menuitem,
434                                         gpointer         user_data)
435 {
436     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
437
438     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
439     {
440         p_intf->p_sys->p_about = create_intf_about();
441         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
442                              "p_intf", p_intf );
443     }
444     gtk_widget_show( p_intf->p_sys->p_about );
445     gdk_window_raise( p_intf->p_sys->p_about->window );
446 }
447
448
449 /*****************************************************************************
450  * Toolbar callbacks
451  *****************************************************************************
452  * The following callbacks are related to the toolbar of the main
453  * interface window.
454  *****************************************************************************/
455 void
456 on_toolbar_open_clicked                (GtkButton       *button,
457                                         gpointer         user_data)
458 {
459     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
460
461     /* If we have never used the file selector, open it */
462     if( p_intf->p_sys->p_fileopen == NULL)
463     {
464         p_intf->p_sys->p_fileopen = create_intf_fileopen();
465         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
466                              "p_intf", p_intf );
467     }
468
469     gtk_widget_show( p_intf->p_sys->p_fileopen );
470     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
471 }
472
473
474 void
475 on_toolbar_disc_clicked                (GtkButton       *button,
476                                         gpointer         user_data)
477 {
478     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
479
480     gtk_widget_show( p_intf->p_sys->p_disc );
481     gdk_window_raise( p_intf->p_sys->p_disc->window );
482 }
483
484
485 void
486 on_toolbar_network_clicked             (GtkButton       *button,
487                                         gpointer         user_data)
488 {
489     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
490
491     gtk_widget_show( p_intf->p_sys->p_network );
492     gdk_window_raise( p_intf->p_sys->p_network->window );
493 }
494
495
496 void
497 on_toolbar_back_clicked                (GtkButton       *button,
498                                         gpointer         user_data)
499 {
500
501 }
502
503
504 void
505 on_toolbar_stop_clicked                (GtkButton       *button,
506                                         gpointer         user_data)
507 {
508
509 }
510
511
512 void
513 on_toolbar_play_clicked                (GtkButton       *button,
514                                         gpointer         user_data)
515 {
516     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
517
518     if( p_intf->p_input != NULL )
519     {
520         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
521     }
522 }
523
524
525 void
526 on_toolbar_pause_clicked               (GtkButton       *button,
527                                         gpointer         user_data)
528 {
529     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
530
531     if( p_intf->p_input != NULL )
532     {
533         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
534     }
535 }
536
537
538 void
539 on_toolbar_slow_clicked                (GtkButton       *button,
540                                         gpointer         user_data)
541 {
542     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
543
544     if( p_intf->p_input != NULL )
545     {
546         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
547     }
548 }
549
550
551 void
552 on_toolbar_fast_clicked                (GtkButton       *button,
553                                         gpointer         user_data)
554 {
555     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
556
557     if( p_intf->p_input != NULL )
558     {
559         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
560     }
561 }
562
563
564 void
565 on_toolbar_playlist_clicked            (GtkButton       *button,
566                                         gpointer         user_data)
567 {
568     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
569
570     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
571     {
572         p_intf->p_sys->p_playlist = create_intf_playlist();
573         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
574                              "p_intf", p_intf );
575     }
576     gtk_widget_show( p_intf->p_sys->p_playlist );
577     gdk_window_raise( p_intf->p_sys->p_playlist->window );
578 }
579
580
581 void
582 on_toolbar_prev_clicked                (GtkButton       *button,
583                                         gpointer         user_data)
584 {
585     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
586
587     if( p_intf->p_input != NULL )
588     {
589         /* FIXME: temporary hack */
590         intf_PlaylistPrev( p_main->p_playlist );
591         intf_PlaylistPrev( p_main->p_playlist );
592         p_intf->p_input->b_eof = 1;
593     }
594
595     p_intf->p_sys->b_mode_changed = 1;
596 }
597
598
599 void
600 on_toolbar_next_clicked                (GtkButton       *button,
601                                         gpointer         user_data)
602 {
603     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
604
605     if( p_intf->p_input != NULL )
606     {
607         /* FIXME: temporary hack */
608         p_intf->p_input->b_eof = 1;
609     }
610
611     p_intf->p_sys->b_mode_changed = 1;
612 }
613
614
615 /*****************************************************************************
616  * Popup callbacks
617  *****************************************************************************
618  * The following callbacks are related to the popup menu. The popup
619  * menu is activated when right-clicking on the video output window.
620  *****************************************************************************/
621 void
622 on_popup_play_activate                 (GtkMenuItem     *menuitem,
623                                         gpointer         user_data)
624 {
625     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
626
627     if( p_intf->p_input != NULL )
628     {
629         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
630     }
631 }
632
633
634 void
635 on_popup_pause_activate                (GtkMenuItem     *menuitem,
636                                         gpointer         user_data)
637 {
638     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
639
640     if( p_intf->p_input != NULL )
641     {
642         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
643     }
644 }
645
646
647 void
648 on_popup_slow_activate                 (GtkMenuItem     *menuitem,
649                                         gpointer         user_data)
650 {
651     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
652
653     if( p_intf->p_input != NULL )
654     {
655         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
656     }
657 }
658
659
660 void
661 on_popup_fast_activate                 (GtkMenuItem     *menuitem,
662                                         gpointer         user_data)
663 {
664     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
665
666     if( p_intf->p_input != NULL )
667     {
668         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
669     }
670 }
671
672
673 void
674 on_popup_audio_toggle                  (GtkCheckMenuItem     *menuitem,
675                                         gpointer              user_data)
676 {
677     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
678     es_descriptor_t *       p_es;
679
680     p_es = (es_descriptor_t*)user_data;
681
682     if( !p_intf->p_sys->b_menus_update )
683     {
684         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
685     }
686 }
687
688
689 void
690 on_popup_subtitle_toggle            (GtkCheckMenuItem     *menuitem,
691                                      gpointer              user_data)
692 {
693     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
694     es_descriptor_t *       p_es;
695
696     p_es = (es_descriptor_t*)user_data;
697
698     if( !p_intf->p_sys->b_menus_update )
699     {
700         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
701     }
702 }
703
704
705 void
706 on_popup_navigation_toggle             (GtkCheckMenuItem     *menuitem,
707                                         gpointer             user_data)
708 {
709     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
710
711     if( menuitem->active && !p_intf->p_sys->b_menus_update )
712     {
713         input_area_t *  p_area;
714         gint            i_title;
715         gint            i_chapter;
716
717         i_title   = (gint)(user_data) / 100;
718         i_chapter = (gint)(user_data) - ( 100 * i_title );
719
720         p_area = p_intf->p_input->stream.pp_areas[i_title];
721         p_area->i_part = i_chapter;
722
723         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
724
725         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
726
727         p_intf->p_sys->b_menus_update = 1;
728     }
729 }
730
731
732 void
733 on_popup_open_activate                 (GtkMenuItem     *menuitem,
734                                         gpointer         user_data)
735 {
736     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
737
738     /* If we have never used the file selector, open it */
739     if( p_intf->p_sys->p_fileopen == NULL)
740     {
741         p_intf->p_sys->p_fileopen = create_intf_fileopen();
742         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
743                              "p_intf", p_intf );
744     }
745
746     gtk_widget_show( p_intf->p_sys->p_fileopen );
747     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
748 }
749
750
751 void
752 on_popup_disc_activate                 (GtkMenuItem     *menuitem,
753                                         gpointer         user_data)
754 {
755     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
756
757     gtk_widget_show( p_intf->p_sys->p_disc );
758     gdk_window_raise( p_intf->p_sys->p_disc->window );
759 }
760
761
762 void
763 on_popup_network_activate              (GtkMenuItem     *menuitem,
764                                         gpointer         user_data)
765 {
766     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
767
768     gtk_widget_show( p_intf->p_sys->p_network );
769     gdk_window_raise( p_intf->p_sys->p_network->window );
770 }
771
772
773 void
774 on_popup_about_activate                (GtkMenuItem     *menuitem,
775                                         gpointer         user_data)
776 {
777     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
778
779     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
780     {
781         p_intf->p_sys->p_about = create_intf_about();
782         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
783                              "p_intf", p_intf );
784     }
785     gtk_widget_show( p_intf->p_sys->p_about );
786     gdk_window_raise( p_intf->p_sys->p_about->window );
787 }
788
789
790 void
791 on_popup_exit_activate                 (GtkMenuItem     *menuitem,
792                                         gpointer         user_data)
793 {
794     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
795
796     vlc_mutex_lock( &p_intf->change_lock );
797     p_intf->b_die = 1;
798     vlc_mutex_unlock( &p_intf->change_lock );
799 }
800
801
802 /*****************************************************************************
803  * Fileopen callbacks
804  *****************************************************************************
805  * The following callbacks are related to the file requester.
806  *****************************************************************************/
807 void
808 on_intf_fileopen_destroy               (GtkObject       *object,
809                                         gpointer         user_data)
810 {
811     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_fileopen" );
812
813     p_intf->p_sys->p_fileopen = NULL;
814 }
815
816
817 void
818 on_fileopen_ok_clicked                 (GtkButton       *button,
819                                         gpointer         user_data)
820 {
821     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
822
823     GtkWidget *filesel;
824     gchar *filename;
825
826     filesel = gtk_widget_get_toplevel (GTK_WIDGET (button));
827     gtk_widget_hide (filesel);
828     filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
829
830     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)filename );
831
832     /* Select added item and switch to file interface */
833     intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );
834     if( p_intf->p_input != NULL )
835         p_intf->p_input->b_eof = 1;
836     p_intf->p_sys->i_intf_mode = FILE_MODE;
837     p_intf->p_sys->b_mode_changed = 1;
838 }
839
840
841 void
842 on_fileopen_cancel_clicked             (GtkButton       *button,
843                                         gpointer         user_data)
844 {
845     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
846 }
847
848
849 /*****************************************************************************
850  * Playlist callbacks
851  *****************************************************************************
852  * The following callbacks are related to the playlist.
853  *****************************************************************************/
854 void
855 on_intf_playlist_destroy               (GtkObject       *object,
856                                         gpointer         user_data)
857 {
858     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_playlist" );
859
860     p_intf->p_sys->p_playlist = NULL;
861 }
862
863
864 void
865 on_playlist_ok_clicked                 (GtkButton       *button,
866                                         gpointer         user_data)
867 {
868     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_playlist" );
869
870     gtk_widget_hide( p_intf->p_sys->p_playlist );
871 }
872
873
874 void
875 on_playlist_close_clicked              (GtkButton       *button,
876                                         gpointer         user_data)
877 {
878     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
879 }
880
881
882
883 /*****************************************************************************
884  * Module manager callbacks
885  *****************************************************************************
886  * The following callbacks are related to the module manager.
887  *****************************************************************************/
888 void
889 on_intf_modules_destroy                (GtkObject       *object,
890                                         gpointer         user_data)
891 {
892
893 }
894
895
896 void
897 on_modules_ok_clicked                  (GtkButton       *button,
898                                         gpointer         user_data)
899 {
900     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
901
902     gtk_widget_hide( p_intf->p_sys->p_modules );
903 }
904
905
906 void
907 on_modules_apply_clicked               (GtkButton       *button,
908                                         gpointer         user_data)
909 {
910
911 }
912
913
914 void
915 on_modules_cancel_clicked              (GtkButton       *button,
916                                         gpointer         user_data)
917 {
918     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
919 }
920
921
922 /*****************************************************************************
923  * Open disc callbacks
924  *****************************************************************************
925  * The following callbacks are related to the disc manager.
926  *****************************************************************************/
927 void
928 on_disc_dvd_toggled                    (GtkToggleButton *togglebutton,
929                                         gpointer         user_data)
930 {
931     if( togglebutton->active )
932     {
933         gtk_entry_set_text( GTK_ENTRY( lookup_widget(
934             GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
935     }
936 }
937
938
939 void
940 on_disc_vcd_toggled                    (GtkToggleButton *togglebutton,
941                                         gpointer         user_data)
942 {
943     if( togglebutton->active )
944     {
945         gtk_entry_set_text( GTK_ENTRY( lookup_widget(
946             GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
947     }
948 }
949
950
951 void
952 on_disc_ok_clicked                     (GtkButton       *button,
953                                         gpointer         user_data)
954 {
955     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
956     char *psz_device, *psz_source, *psz_method;
957
958     psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
959                                          GTK_WIDGET(button), "disc_name" ) ) );
960
961     /* "dvd:foo" has size 5 + strlen(foo) */
962     psz_source = malloc( 5 + strlen( psz_device ) );
963     if( psz_source == NULL )
964     {
965         return;
966     }
967
968     /* Check which method was activated */
969     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
970                                           "disc_dvd" ) )->active )
971     {
972         psz_method = "dvd";
973         p_intf->p_sys->i_intf_mode = DVD_MODE;
974     }
975     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
976                                                "disc_vcd" ) )->active )
977     {
978         psz_method = "vcd";
979     }
980     else
981     {
982         intf_ErrMsg( "intf error: unknown disc type toggle button position" );
983         free( psz_source );
984         return;
985     }
986     
987     /* Select title and chapter */
988     main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
989                               GTK_SPIN_BUTTON( lookup_widget(
990                                   GTK_WIDGET(button), "disc_title" ) ) ) );
991
992     main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
993                               GTK_SPIN_BUTTON( lookup_widget(
994                                   GTK_WIDGET(button), "disc_chapter" ) ) ) );
995
996     /* Build source name and add it to playlist */
997     sprintf( psz_source, "%s:%s", psz_method, psz_device );
998     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
999     free( psz_source );
1000
1001     /* Select added item and switch to DVD interface */
1002     intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );
1003     if( p_intf->p_input != NULL )
1004         p_intf->p_input->b_eof = 1;
1005     p_intf->p_sys->b_mode_changed = 1;
1006
1007     gtk_widget_hide( p_intf->p_sys->p_disc );
1008 }
1009
1010
1011 void
1012 on_disc_cancel_clicked                 (GtkButton       *button,
1013                                         gpointer         user_data)
1014 {
1015     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1016 }
1017
1018
1019 /*****************************************************************************
1020  * Network stream callbacks
1021  *****************************************************************************
1022  * The following callbacks are related to the network stream manager.
1023  *****************************************************************************/
1024 void
1025 on_network_ok_clicked                  (GtkButton       *button,
1026                                         gpointer         user_data)
1027 {
1028     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
1029     char *psz_source, *psz_server, *psz_protocol;
1030     unsigned int i_port;
1031
1032     psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
1033                                  GTK_WIDGET(button), "network_server" ) ) );
1034
1035     /* Check which protocol was activated */
1036     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
1037                                           "network_ts" ) )->active )
1038     {
1039         psz_protocol = "ts";
1040     }
1041     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
1042                                                "network_rtp" ) )->active )
1043     {
1044         psz_protocol = "rtp";
1045     }
1046     else
1047     {
1048         intf_ErrMsg( "intf error: unknown protocol toggle button position" );
1049         return;
1050     }
1051
1052     /* Get the port number and make sure it will not overflow 5 characters */
1053     i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
1054                  lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
1055     if( i_port > 65535 )
1056     {
1057         intf_ErrMsg( "intf error: invalid port %i", i_port );
1058     }
1059
1060     /* Allocate room for "protocol://server:port" */
1061     psz_source = malloc( strlen( psz_protocol ) + strlen( psz_server ) + 10 );
1062     if( psz_source == NULL )
1063     {
1064         return;
1065     }
1066    
1067     /* Build source name and add it to playlist */
1068     sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
1069     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
1070     free( psz_source );
1071
1072     /* Select added item and switch to network interface */
1073     intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );
1074     if( p_intf->p_input != NULL )
1075         p_intf->p_input->b_eof = 1;
1076     p_intf->p_sys->b_mode_changed = 1;
1077     p_intf->p_sys->i_intf_mode = NET_MODE;
1078
1079     gtk_widget_hide( p_intf->p_sys->p_network );
1080 }
1081
1082
1083 void
1084 on_network_cancel_clicked              (GtkButton       *button,
1085                                         gpointer         user_data)
1086 {
1087     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1088 }
1089