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