]> git.sesse.net Git - vlc/blob - plugins/gnome/gnome_callbacks.c
d2f4cc2b1ae4c217f53b5df96c4479a914854cf7
[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.27 2001/05/07 03:14:09 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 "video.h"
48 #include "video_output.h"
49 #include "audio_output.h"
50
51 #include "gnome_callbacks.h"
52 #include "gnome_playlist.h"
53 #include "gnome_interface.h"
54 #include "gnome_support.h"
55 #include "intf_gnome.h"
56
57 #include "main.h"
58
59 /*****************************************************************************
60  * Interface callbacks
61  *****************************************************************************
62  * The following callbacks are related to the main interface window.
63  *****************************************************************************/
64 void
65 on_intf_window_destroy                 (GtkObject       *object,
66                                         gpointer         user_data)
67 {
68     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(object), "intf_window" );
69
70     vlc_mutex_lock( &p_intf->change_lock );
71     p_intf->b_die = 1;
72     vlc_mutex_unlock( &p_intf->change_lock );
73 }
74
75
76 gboolean
77 on_slider_button_press_event           (GtkWidget       *widget,
78                                         GdkEventButton  *event,
79                                         gpointer         user_data)
80 {
81     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
82
83     vlc_mutex_lock( &p_intf->change_lock );
84     p_intf->p_sys->b_slider_free = 0;
85     vlc_mutex_unlock( &p_intf->change_lock );
86
87     return FALSE;
88 }
89
90
91 gboolean
92 on_slider_button_release_event         (GtkWidget       *widget,
93                                         GdkEventButton  *event,
94                                         gpointer         user_data)
95 {
96     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
97
98     vlc_mutex_lock( &p_intf->change_lock );
99     p_intf->p_sys->b_slider_free = 1;
100     vlc_mutex_unlock( &p_intf->change_lock );
101
102     return FALSE;
103 }
104
105
106 void
107 on_intf_window_drag_data_received      (GtkWidget       *widget,
108                                         GdkDragContext  *drag_context,
109                                         gint             x,
110                                         gint             y,
111                                         GtkSelectionData *data,
112                                         guint            info,
113                                         guint            time,
114                                         gpointer         user_data)
115 {
116 #if 0
117     char *psz_text = data->data;
118     int i_len      = strlen( psz_text );
119
120     switch( info )
121     {
122     case DROP_ACCEPT_TEXT_PLAIN: /* FIXME: handle multiple files */
123
124         if( i_len < 1 )
125         {
126             return;
127         }
128
129         /* get rid of ' ' at the end */
130         *( psz_text + i_len - 1 ) = 0;
131
132         intf_WarnMsg( 3, "intf: dropped text/uri-list data `%s'", psz_text );
133         intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
134
135         break;
136
137     case DROP_ACCEPT_TEXT_URI_LIST: /* FIXME: handle multiple files */
138
139         if( i_len < 2 )
140         {
141             return;
142         }
143
144         /* get rid of \r\n at the end */
145         *( psz_text + i_len - 2 ) = 0;
146
147         intf_WarnMsg( 3, "intf: dropped text/uri-list data `%s'", psz_text );
148         intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_text );
149         break;
150
151     default:
152
153         intf_ErrMsg( "intf error: unknown dropped type");
154         break;
155     }
156 #else
157     intf_thread_t * p_intf = GetIntf( GTK_WIDGET( widget ), "intf_window" );
158     int             i_end  = p_main->p_playlist->i_size;
159
160     GnomeDropDataReceived( p_intf, data, info, PLAYLIST_END );
161
162      if( p_intf->p_input != NULL )
163      {
164         /* FIXME: temporary hack */
165         p_intf->p_input->b_eof = 1;
166      }
167      
168     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
169
170 #endif
171 }
172
173
174 void
175 on_button_title_prev_clicked           (GtkButton       *button,
176                                         gpointer         user_data)
177 {
178     intf_thread_t * p_intf;
179     input_area_t *  p_area;
180     int             i_id;
181
182     p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
183     i_id = p_intf->p_input->stream.p_selected_area->i_id - 1;
184
185     if( i_id >= 0 )
186     {
187         p_area = p_intf->p_input->stream.pp_areas[i_id];
188         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
189
190         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
191
192         p_intf->p_sys->b_title_update = 1;
193     }
194 }
195
196
197 void
198 on_button_title_next_clicked           (GtkButton       *button,
199                                         gpointer         user_data)
200 {
201     intf_thread_t * p_intf;
202     input_area_t *  p_area;
203     int             i_id;
204
205     p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
206     i_id = p_intf->p_input->stream.p_selected_area->i_id + 1;
207
208     if( i_id < p_intf->p_input->stream.i_area_nb )
209     {
210         p_area = p_intf->p_input->stream.pp_areas[i_id];   
211         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
212
213         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
214
215         p_intf->p_sys->b_title_update = 1;
216     }
217 }
218
219
220 void
221 on_button_chapter_prev_clicked         (GtkButton       *button,
222                                         gpointer         user_data)
223 {
224     intf_thread_t * p_intf;
225     input_area_t *  p_area;
226
227     p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
228     p_area = p_intf->p_input->stream.p_selected_area;
229
230     if( p_area->i_part > 0 )
231     {
232         p_area->i_part--;
233         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
234
235         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
236
237         p_intf->p_sys->b_chapter_update = 1;
238     }
239 }
240
241
242 void
243 on_button_chapter_next_clicked         (GtkButton       *button,
244                                         gpointer         user_data)
245 {
246     intf_thread_t * p_intf;
247     input_area_t *  p_area;
248
249     p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
250     p_area = p_intf->p_input->stream.p_selected_area;
251
252     if( p_area->i_part < p_area->i_part_nb )
253     {
254         p_area->i_part++;
255         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
256
257         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
258
259         p_intf->p_sys->b_chapter_update = 1;
260     }
261 }
262
263
264 /*****************************************************************************
265  * Menubar callbacks
266  *****************************************************************************
267  * The following callbacks are related to the menubar of the main
268  * interface window.
269  *****************************************************************************/
270 void
271 on_menubar_open_activate               (GtkMenuItem     *menuitem,
272                                         gpointer         user_data)
273 {
274     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
275
276     /* If we have never used the file selector, open it */
277     if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
278     {
279         p_intf->p_sys->p_fileopen = create_intf_fileopen();
280         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
281                              "p_intf", p_intf );
282
283             gtk_file_selection_set_filename ( GTK_FILE_SELECTION(
284                 p_intf->p_sys->p_fileopen ),
285                 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
286     }
287
288     gtk_widget_show( p_intf->p_sys->p_fileopen );
289     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
290 }
291
292
293 void
294 on_menubar_disc_activate               (GtkMenuItem     *menuitem,
295                                         gpointer         user_data)
296 {
297     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
298
299     /* If we have never used the file selector, open it */
300     if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
301     {
302         p_intf->p_sys->p_disc = create_intf_disc();
303         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
304                              "p_intf", p_intf );
305     }
306
307     gtk_widget_show( p_intf->p_sys->p_disc );
308     gdk_window_raise( p_intf->p_sys->p_disc->window );
309 }
310
311
312 void
313 on_menubar_network_activate            (GtkMenuItem     *menuitem,
314                                         gpointer         user_data)
315 {
316     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
317
318     /* If we have never used the file selector, open it */
319     if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
320     {
321         p_intf->p_sys->p_network = create_intf_network();
322         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
323                              "p_intf", p_intf );
324     }
325
326     gtk_widget_show( p_intf->p_sys->p_network );
327     gdk_window_raise( p_intf->p_sys->p_network->window );
328 }
329
330
331 void
332 on_menubar_exit_activate               (GtkMenuItem     *menuitem,
333                                         gpointer         user_data)
334 {
335     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
336
337     vlc_mutex_lock( &p_intf->change_lock );
338     p_intf->b_die = 1;
339     vlc_mutex_unlock( &p_intf->change_lock );
340 }
341
342
343 void
344 on_menubar_playlist_activate           (GtkMenuItem     *menuitem,
345                                         gpointer         user_data)
346 {
347     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
348     playlist_t *    p_playlist ;
349     GtkCList *      p_list;
350
351     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
352     {
353         p_intf->p_sys->p_playlist = create_intf_playlist();
354         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
355                              "p_intf", p_intf );
356     }
357
358     vlc_mutex_lock( &p_main->p_playlist->change_lock );
359     if( p_main->p_playlist->i_size > 0 )
360     {
361         p_playlist = p_main->p_playlist;
362         p_list = GTK_CLIST( lookup_widget( p_intf->p_sys->p_playlist,
363                                            "playlist_clist" ) );
364         GnomeRebuildCList( p_list, p_playlist );
365     }
366     vlc_mutex_unlock( &p_main->p_playlist->change_lock );
367
368     gtk_widget_show( p_intf->p_sys->p_playlist );
369     gdk_window_raise( p_intf->p_sys->p_playlist->window );
370 }
371
372
373 void
374 on_menubar_audio_toggle                (GtkCheckMenuItem     *menuitem,
375                                         gpointer              user_data)
376 {
377     intf_thread_t *         p_intf;
378     es_descriptor_t *       p_es;
379
380     p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
381
382     if( !p_intf->p_sys->b_audio_update )
383     {
384         p_es = (es_descriptor_t*)user_data;
385
386         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
387
388         p_intf->p_sys->b_audio_update = menuitem->active;
389     }
390 }
391
392
393 void
394 on_menubar_subtitle_toggle             (GtkCheckMenuItem     *menuitem,
395                                         gpointer              user_data)
396 {
397     intf_thread_t *         p_intf;
398     es_descriptor_t *       p_es;
399
400     p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
401
402     if( !p_intf->p_sys->b_spu_update )
403     {
404         p_es = (es_descriptor_t*)user_data;
405
406         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
407
408         p_intf->p_sys->b_spu_update = menuitem->active;
409     }
410 }
411
412
413 void
414 on_menubar_fullscreen_activate         (GtkMenuItem     *menuitem,
415                                         gpointer         user_data)
416 {
417     if( p_vout_bank->i_count )
418     {
419         vlc_mutex_lock( &p_vout_bank->pp_vout[0]->change_lock );
420         if( p_vout_bank->pp_vout[0]->b_fullscreen ==
421                 !GTK_CHECK_MENU_ITEM( menuitem )->active )
422             p_vout_bank->pp_vout[0]->i_changes |= VOUT_FULLSCREEN_CHANGE;
423         vlc_mutex_unlock( &p_vout_bank->pp_vout[0]->change_lock );
424     }
425 }
426
427
428
429 void
430 on_menubar_title_toggle                (GtkCheckMenuItem     *menuitem,
431                                         gpointer              user_data)
432 {
433     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
434
435     if( menuitem->active && !p_intf->p_sys->b_title_update )
436     {
437         gint i_title = (gint)user_data;
438         p_intf->p_input->pf_set_area( p_intf->p_input,
439             p_intf->p_input->stream.pp_areas[i_title] );
440
441         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
442
443         p_intf->p_sys->b_title_update = 1;
444     }
445 }
446
447
448 void
449 on_menubar_chapter_toggle              (GtkCheckMenuItem     *menuitem,
450                                         gpointer              user_data)
451 {
452     intf_thread_t * p_intf    = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
453     input_area_t *  p_area    = p_intf->p_input->stream.p_selected_area;
454     gint            i_chapter = (gint)user_data;
455     char            psz_chapter[5];
456
457     if( menuitem->active && !p_intf->p_sys->b_chapter_update )
458     {
459         p_area->i_part = i_chapter;
460         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
461
462         snprintf( psz_chapter, 3, "%02d", p_area->i_part );
463         gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
464
465         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
466
467         p_intf->p_sys->b_chapter_update = 1;
468     }
469
470 }
471
472
473 void
474 on_menubar_angle_toggle                (GtkCheckMenuItem     *menuitem,
475                                         gpointer             user_data)
476 {
477     intf_thread_t * p_intf    = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
478     input_area_t *  p_area    = p_intf->p_input->stream.p_selected_area;
479     gint            i_angle   = (gint)user_data;
480
481     if( menuitem->active && !p_intf->p_sys->b_angle_update )
482     {
483         p_area->i_angle = i_angle;
484         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
485
486         p_intf->p_sys->b_angle_update = 1;
487     }
488 }
489
490
491 void
492 on_menubar_modules_activate            (GtkMenuItem     *menuitem,
493                                         gpointer         user_data)
494 {
495     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
496
497     if( !GTK_IS_WIDGET( p_intf->p_sys->p_modules ) )
498     {
499         p_intf->p_sys->p_modules = create_intf_modules();
500         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_modules ),
501                              "p_intf", p_intf );
502     }
503     gtk_widget_show( p_intf->p_sys->p_modules );
504     gdk_window_raise( p_intf->p_sys->p_modules->window );
505 }
506
507
508 void
509 on_menubar_preferences_activate        (GtkMenuItem     *menuitem,
510                                         gpointer         user_data)
511 {
512     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
513
514     /* If we have never used the file selector, open it */
515     if( !GTK_IS_WIDGET( p_intf->p_sys->p_preferences ) )
516     {
517         p_intf->p_sys->p_preferences = create_intf_preferences();
518         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_preferences ),
519                              "p_intf", p_intf );
520 #if 1
521 #define ASSIGN_PSZ_ENTRY( var, default, name )                               \
522     gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data( GTK_OBJECT(          \
523         p_intf->p_sys->p_preferences ), name ) ),                            \
524                         main_GetPszVariable( var, default ) )
525
526 #define ASSIGN_INT_VALUE( var, default, name )                                        \
527     gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(         \
528         GTK_OBJECT( p_intf->p_sys->p_preferences ), name ) ),                \
529                                main_GetIntVariable( var, default ) )
530
531 #define ASSIGN_INT_TOGGLE( var, default, name )                                       \
532     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( gtk_object_get_data(    \
533         GTK_OBJECT( p_intf->p_sys->p_preferences ), name ) ),                \
534                                main_GetIntVariable( var, default ) )
535
536         /* Default path */
537         ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, INTF_PATH_DEFAULT,
538                           "preferences_file_entry" );
539     
540         /* Default DVD */
541         ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR,INPUT_DVD_DEVICE_DEFAULT,
542                           "preferences_disc_dvd_entry" );
543     
544         /* Default VCD */
545         ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT,
546                           "preferences_disc_vcd_entry" );
547     
548         /* Default server */
549         ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, INPUT_SERVER_DEFAULT,
550                           "preferences_network_server_entry" );
551     
552         /* Default port */
553         ASSIGN_INT_VALUE( INPUT_PORT_VAR, INPUT_PORT_DEFAULT,
554                           "preferences_network_port_spinbutton" );
555     
556         /* Broadcast address */
557         ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADRR_VAR, INPUT_BCAST_ADDR_DEFAULT,
558                           "preferences_network_broadcast_entry" );
559     
560         /* Broadcast stream by default ? */
561         ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR, INPUT_BROADCAST_DEFAULT,
562                            "preferences_network_broadcast_checkbutton" );
563     
564         /* XXX Protocol */
565     
566         /* Default interface */
567         ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, INTF_METHOD_DEFAULT,
568                           "preferences_interface_entry" );
569     
570         /* Default video output */
571         ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, VOUT_METHOD_DEFAULT,
572                           "preferences_video_output_entry" );
573     
574         /* Default output width */
575         ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, VOUT_WIDTH_DEFAULT,
576                           "preferences_video_width_spinbutton" );
577     
578         /* Default output height */
579         ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, VOUT_HEIGHT_DEFAULT,
580                           "preferences_video_height_spinbutton" );
581     
582         /* XXX Default screen depth */
583     
584         /* XXX Default fullscreen depth */
585     
586         /* XXX Default gamma */
587         
588         /* Fullscreen on play */
589         ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR, VOUT_FULLSCREEN_DEFAULT,
590                            "preferences_video_fullscreen_checkbutton" );
591     
592         /* Grayscale display */
593         ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR, VOUT_GRAYSCALE_DEFAULT,
594                            "preferences_video_grayscale_checkbutton" );
595     
596         /* Default audio output */
597         ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, AOUT_METHOD_DEFAULT,
598                           "preferences_audio_output_entry" );
599     
600         /* Default audio device */
601         ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, AOUT_DSP_DEFAULT,
602                           "preferences_audio_device_entry" );
603     
604         /* XXX Default frequency */
605     
606         /* XXX Default quality */
607     
608         /* XXX Default number of channels */
609     
610         /* Use spdif output ? */
611         ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, AOUT_SPDIF_DEFAULT,
612                            "preferences_audio_spdif_checkbutton" );
613     
614         /* Launch playlist on startup */
615         ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR, PLAYLIST_STARTUP_DEFAULT,
616                         "preferences_playlist_launch_on_startup_checkbutton" );
617     
618         /* Enqueue drag'n dropped item as default */
619         ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR, PLAYLIST_ENQUEUE_DEFAULT,
620                            "preferences_playlist_enqueue_as_default_checkbutton" );
621     
622         /* Loop on playlist end */
623         ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR, PLAYLIST_LOOP_DEFAULT,
624                            "preferences_playlist_loop_checkbutton" );
625     
626         /* Verbosity of warning messages */
627         ASSIGN_INT_VALUE( INTF_WARNING_VAR, INTF_WARNING_DEFAULT,
628                           "preferences_misc_messages_spinbutton" );
629 #undef ASSIGN_PSZ_ENTRY
630 #undef ASSIGN_INT_VALUE
631 #undef ASSIGN_INT_TOGGLE
632 #endif
633     }
634
635     gtk_widget_show( p_intf->p_sys->p_preferences );
636     gdk_window_raise( p_intf->p_sys->p_preferences->window );
637 }
638
639
640 void
641 on_menubar_about_activate              (GtkMenuItem     *menuitem,
642                                         gpointer         user_data)
643 {
644     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
645
646     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
647     {
648         p_intf->p_sys->p_about = create_intf_about();
649         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
650                              "p_intf", p_intf );
651     }
652     gtk_widget_show( p_intf->p_sys->p_about );
653     gdk_window_raise( p_intf->p_sys->p_about->window );
654 }
655
656
657 /*****************************************************************************
658  * Toolbar callbacks
659  *****************************************************************************
660  * The following callbacks are related to the toolbar of the main
661  * interface window.
662  *****************************************************************************/
663 void
664 on_toolbar_open_clicked                (GtkButton       *button,
665                                         gpointer         user_data)
666 {
667     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
668
669     /* If we have never used the file selector, open it */
670     if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
671     {
672         p_intf->p_sys->p_fileopen = create_intf_fileopen();
673         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
674                              "p_intf", p_intf );
675
676         if( main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) != NULL )
677         {
678             gtk_file_selection_set_filename( GTK_FILE_SELECTION(
679                 p_intf->p_sys->p_fileopen ),
680                 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
681         }
682     }
683
684     gtk_widget_show( p_intf->p_sys->p_fileopen );
685     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
686 }
687
688
689 void
690 on_toolbar_disc_clicked                (GtkButton       *button,
691                                         gpointer         user_data)
692 {
693     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
694
695     /* If we have never used the file selector, open it */
696     if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
697     {
698         p_intf->p_sys->p_disc = create_intf_disc();
699         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
700                              "p_intf", p_intf );
701     }
702
703     gtk_widget_show( p_intf->p_sys->p_disc );
704     gdk_window_raise( p_intf->p_sys->p_disc->window );
705 }
706
707
708 void
709 on_toolbar_network_clicked             (GtkButton       *button,
710                                         gpointer         user_data)
711 {
712     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
713
714     /* If we have never used the file selector, open it */
715     if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
716     {
717         p_intf->p_sys->p_network = create_intf_network();
718         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
719                              "p_intf", p_intf );
720     }
721
722     gtk_widget_show( p_intf->p_sys->p_network );
723     gdk_window_raise( p_intf->p_sys->p_network->window );
724 }
725
726
727 void
728 on_toolbar_back_clicked                (GtkButton       *button,
729                                         gpointer         user_data)
730 {
731
732 }
733
734
735 void
736 on_toolbar_stop_clicked                (GtkButton       *button,
737                                         gpointer         user_data)
738 {
739     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
740
741     if( p_intf->p_input != NULL )
742     {
743         p_vout_bank->pp_vout[0]->b_die = 1;
744         p_aout_bank->pp_aout[0]->b_die = 1;
745         p_intf->p_input->b_die = 1;
746     }
747 }
748
749
750 void
751 on_toolbar_play_clicked                (GtkButton       *button,
752                                         gpointer         user_data)
753 {
754     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
755
756     if( p_intf->p_input != NULL )
757     {
758         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
759     }
760 }
761
762
763 void
764 on_toolbar_pause_clicked               (GtkButton       *button,
765                                         gpointer         user_data)
766 {
767     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
768
769     if( p_intf->p_input != NULL )
770     {
771         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
772     }
773 }
774
775
776 void
777 on_toolbar_slow_clicked                (GtkButton       *button,
778                                         gpointer         user_data)
779 {
780     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
781
782     if( p_intf->p_input != NULL )
783     {
784         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
785     }
786 }
787
788
789 void
790 on_toolbar_fast_clicked                (GtkButton       *button,
791                                         gpointer         user_data)
792 {
793     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
794
795     if( p_intf->p_input != NULL )
796     {
797         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
798     }
799 }
800
801
802 void
803 on_toolbar_playlist_clicked            (GtkButton       *button,
804                                         gpointer         user_data)
805 {
806     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
807
808     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
809     {
810         p_intf->p_sys->p_playlist = create_intf_playlist();
811         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
812                              "p_intf", p_intf );
813     }
814
815     if( GTK_WIDGET_VISIBLE( p_intf->p_sys->p_playlist ) )
816     {
817         gtk_widget_hide( p_intf->p_sys->p_playlist );
818     } 
819     else 
820     {        
821         GtkCList * p_clist;
822
823         p_clist = GTK_CLIST( gtk_object_get_data(
824             GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
825         GnomeRebuildCList( p_clist , p_main->p_playlist );
826         gtk_widget_show( p_intf->p_sys->p_playlist );
827         gdk_window_raise( p_intf->p_sys->p_playlist->window );
828     }
829 }
830
831
832 void
833 on_toolbar_prev_clicked                (GtkButton       *button,
834                                         gpointer         user_data)
835 {
836     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
837
838     if( p_intf->p_input != NULL )
839     {
840         /* FIXME: temporary hack */
841         intf_PlaylistPrev( p_main->p_playlist );
842         intf_PlaylistPrev( p_main->p_playlist );
843         p_intf->p_input->b_eof = 1;
844     }
845
846     p_intf->p_sys->b_mode_changed = 1;
847 }
848
849
850 void
851 on_toolbar_next_clicked                (GtkButton       *button,
852                                         gpointer         user_data)
853 {
854     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_window" );
855
856     if( p_intf->p_input != NULL )
857     {
858         /* FIXME: temporary hack */
859         p_intf->p_input->b_eof = 1;
860     }
861
862     p_intf->p_sys->b_mode_changed = 1;
863 }
864
865
866 /*****************************************************************************
867  * Popup callbacks
868  *****************************************************************************
869  * The following callbacks are related to the popup menu. The popup
870  * menu is activated when right-clicking on the video output window.
871  *****************************************************************************/
872 void
873 on_popup_play_activate                 (GtkMenuItem     *menuitem,
874                                         gpointer         user_data)
875 {
876     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
877
878     if( p_intf->p_input != NULL )
879     {
880         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
881     }
882 }
883
884
885 void
886 on_popup_back_activate                 (GtkMenuItem     *menuitem,
887                                         gpointer         user_data)
888 {
889
890 }
891
892
893 void
894 on_popup_pause_activate                (GtkMenuItem     *menuitem,
895                                         gpointer         user_data)
896 {
897     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
898
899     if( p_intf->p_input != NULL )
900     {
901         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
902     }
903 }
904
905
906 void
907 on_popup_slow_activate                 (GtkMenuItem     *menuitem,
908                                         gpointer         user_data)
909 {
910     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
911
912     if( p_intf->p_input != NULL )
913     {
914         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
915     }
916 }
917
918
919 void
920 on_popup_fast_activate                 (GtkMenuItem     *menuitem,
921                                         gpointer         user_data)
922 {
923     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
924
925     if( p_intf->p_input != NULL )
926     {
927         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
928     }
929 }
930
931
932 void
933 on_popup_fullscreen_activate           (GtkMenuItem     *menuitem,
934                                         gpointer         user_data)
935 {
936     if( p_vout_bank->i_count )
937     {
938         vlc_mutex_lock( &p_vout_bank->pp_vout[0]->change_lock );
939         if( p_vout_bank->pp_vout[0]->b_fullscreen ==
940                 !GTK_CHECK_MENU_ITEM( menuitem )->active )
941             p_vout_bank->pp_vout[0]->i_changes |= VOUT_FULLSCREEN_CHANGE;
942         vlc_mutex_unlock( &p_vout_bank->pp_vout[0]->change_lock );
943     }
944 }
945
946
947 void
948 on_popup_audio_toggle                  (GtkCheckMenuItem     *menuitem,
949                                         gpointer              user_data)
950 {
951     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
952     es_descriptor_t *       p_es;
953
954     p_es = (es_descriptor_t*)user_data;
955
956     if( !p_intf->p_sys->b_audio_update )
957     {
958         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
959
960         p_intf->p_sys->b_audio_update = menuitem->active;
961     }
962 }
963
964
965 void
966 on_popup_subtitle_toggle            (GtkCheckMenuItem     *menuitem,
967                                      gpointer              user_data)
968 {
969     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
970     es_descriptor_t *       p_es;
971
972     p_es = (es_descriptor_t*)user_data;
973
974     if( !p_intf->p_sys->b_spu_update )
975     {
976         input_ToggleES( p_intf->p_input, p_es, menuitem->active );
977
978         p_intf->p_sys->b_spu_update = menuitem->active;
979     }
980 }
981
982
983 void
984 on_popup_navigation_toggle             (GtkCheckMenuItem     *menuitem,
985                                         gpointer             user_data)
986 {
987     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
988
989     if( menuitem->active &&
990         !p_intf->p_sys->b_title_update &&
991         !p_intf->p_sys->b_chapter_update )
992     {
993         input_area_t *  p_area;
994         gint            i_title;
995         gint            i_chapter;
996
997         i_title   = (gint)(user_data) / 100;
998         i_chapter = (gint)(user_data) - ( 100 * i_title );
999         p_area = p_intf->p_input->stream.p_selected_area;
1000
1001
1002         if( p_area != p_intf->p_input->stream.pp_areas[i_title] )
1003         {
1004             p_area = p_intf->p_input->stream.pp_areas[i_title];
1005             p_intf->p_sys->b_title_update = 1;
1006         }
1007
1008         p_area->i_part = i_chapter;
1009         p_intf->p_sys->b_chapter_update = 1;
1010
1011         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
1012
1013         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
1014     }
1015 }
1016
1017
1018 void
1019 on_popup_angle_toggle                  (GtkCheckMenuItem     *menuitem,
1020                                         gpointer             user_data)
1021 {
1022     intf_thread_t * p_intf    = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
1023     input_area_t *  p_area    = p_intf->p_input->stream.p_selected_area;
1024     gint            i_angle   = (gint)user_data;
1025
1026     if( menuitem->active && !p_intf->p_sys->b_angle_update )
1027     {
1028         p_area->i_angle = i_angle;
1029         p_intf->p_input->pf_set_area( p_intf->p_input, (input_area_t*)p_area );
1030
1031         p_intf->p_sys->b_angle_update = 1;
1032     }
1033 }
1034
1035
1036 void
1037 on_popup_open_activate                 (GtkMenuItem     *menuitem,
1038                                         gpointer         user_data)
1039 {
1040     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
1041
1042     /* If we have never used the file selector, open it */
1043     if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
1044     {
1045         p_intf->p_sys->p_fileopen = create_intf_fileopen();
1046         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
1047                              "p_intf", p_intf );
1048
1049         if( main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) != NULL )
1050         {
1051             gtk_file_selection_set_filename( GTK_FILE_SELECTION(
1052                 p_intf->p_sys->p_fileopen ),
1053                 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
1054         }
1055     }
1056
1057     gtk_widget_show( p_intf->p_sys->p_fileopen );
1058     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
1059 }
1060
1061
1062 void
1063 on_popup_disc_activate                 (GtkMenuItem     *menuitem,
1064                                         gpointer         user_data)
1065 {
1066     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
1067
1068     gtk_widget_show( p_intf->p_sys->p_disc );
1069     gdk_window_raise( p_intf->p_sys->p_disc->window );
1070 }
1071
1072
1073 void
1074 on_popup_network_activate              (GtkMenuItem     *menuitem,
1075                                         gpointer         user_data)
1076 {
1077     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
1078
1079     gtk_widget_show( p_intf->p_sys->p_network );
1080     gdk_window_raise( p_intf->p_sys->p_network->window );
1081 }
1082
1083
1084 void
1085 on_popup_about_activate                (GtkMenuItem     *menuitem,
1086                                         gpointer         user_data)
1087 {
1088     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
1089
1090     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
1091     {
1092         p_intf->p_sys->p_about = create_intf_about();
1093         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
1094                              "p_intf", p_intf );
1095     }
1096     gtk_widget_show( p_intf->p_sys->p_about );
1097     gdk_window_raise( p_intf->p_sys->p_about->window );
1098 }
1099
1100
1101 void
1102 on_popup_exit_activate                 (GtkMenuItem     *menuitem,
1103                                         gpointer         user_data)
1104 {
1105     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
1106
1107     vlc_mutex_lock( &p_intf->change_lock );
1108     p_intf->b_die = 1;
1109     vlc_mutex_unlock( &p_intf->change_lock );
1110 }
1111
1112
1113 void
1114 on_popup_stop_activate                 (GtkMenuItem     *menuitem,
1115                                         gpointer         user_data)
1116 {
1117     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
1118
1119     if( p_intf->p_input != NULL )
1120     {
1121         p_intf->p_input->b_die = 1;
1122     }
1123 }
1124
1125
1126 void
1127 on_popup_playlist_activate             (GtkMenuItem     *menuitem,
1128                                         gpointer         user_data)
1129 {
1130     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
1131
1132     if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
1133     {
1134         p_intf->p_sys->p_playlist = create_intf_playlist();
1135         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
1136                              "p_intf", p_intf );
1137     }
1138     gtk_widget_show( p_intf->p_sys->p_playlist );
1139     gdk_window_raise( p_intf->p_sys->p_playlist->window );
1140 }
1141
1142
1143 void
1144 on_popup_jump_activate                 (GtkMenuItem     *menuitem,
1145                                         gpointer         user_data)
1146 {
1147     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
1148
1149     if( !GTK_IS_WIDGET( p_intf->p_sys->p_jump ) )
1150     {
1151         p_intf->p_sys->p_jump = create_intf_jump();
1152         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_jump ),
1153                              "p_intf", p_intf );
1154     }
1155
1156     gtk_widget_show( p_intf->p_sys->p_jump );
1157     gdk_window_raise( p_intf->p_sys->p_jump->window );
1158 }
1159
1160
1161 void
1162 on_popup_preferences_activate          (GtkMenuItem     *menuitem,
1163                                         gpointer         user_data)
1164 {
1165     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
1166
1167     gtk_widget_show( p_intf->p_sys->p_preferences );
1168     gdk_window_raise( p_intf->p_sys->p_preferences->window );
1169
1170 }
1171
1172
1173 /*****************************************************************************
1174  * Fileopen callbacks
1175  *****************************************************************************
1176  * The following callbacks are related to the file requester.
1177  *****************************************************************************/
1178 void
1179 on_intf_fileopen_destroy               (GtkObject       *object,
1180                                         gpointer         user_data)
1181 {
1182     gtk_widget_hide( GTK_WIDGET( object ) );
1183 }
1184
1185
1186 void
1187 on_fileopen_ok_clicked                 (GtkButton       *button,
1188                                         gpointer         user_data)
1189 {
1190     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
1191     GtkCList *      p_playlist_clist;
1192     GtkWidget *     p_filesel;
1193     gchar *         psz_filename;
1194     int             i_end = p_main->p_playlist->i_size;
1195
1196     p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
1197     gtk_widget_hide( p_filesel );
1198     psz_filename =
1199         gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
1200
1201     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
1202
1203     /* catch the GTK CList */
1204     p_playlist_clist = GTK_CLIST( gtk_object_get_data(
1205         GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
1206     /* update the display */
1207     GnomeRebuildCList( p_playlist_clist, p_main->p_playlist );
1208
1209     /* Select added item and switch to file interface */
1210     if( p_intf->p_input != NULL )
1211     {
1212         p_intf->p_input->b_eof = 1;
1213     }
1214
1215     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
1216 }
1217
1218
1219 void
1220 on_fileopen_cancel_clicked             (GtkButton       *button,
1221                                         gpointer         user_data)
1222 {
1223     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1224 }
1225
1226
1227 /*****************************************************************************
1228  * Module manager callbacks
1229  *****************************************************************************
1230  * The following callbacks are related to the module manager.
1231  *****************************************************************************/
1232 void
1233 on_intf_modules_destroy                (GtkObject       *object,
1234                                         gpointer         user_data)
1235 {
1236
1237 }
1238
1239
1240 void
1241 on_modules_ok_clicked                  (GtkButton       *button,
1242                                         gpointer         user_data)
1243 {
1244     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), "intf_modules" );
1245
1246     gtk_widget_hide( p_intf->p_sys->p_modules );
1247 }
1248
1249
1250 void
1251 on_modules_apply_clicked               (GtkButton       *button,
1252                                         gpointer         user_data)
1253 {
1254
1255 }
1256
1257
1258 void
1259 on_modules_cancel_clicked              (GtkButton       *button,
1260                                         gpointer         user_data)
1261 {
1262     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1263 }
1264
1265
1266 /*****************************************************************************
1267  * Open disc callbacks
1268  *****************************************************************************
1269  * The following callbacks are related to the disc manager.
1270  *****************************************************************************/
1271 void
1272 on_disc_dvd_toggled                    (GtkToggleButton *togglebutton,
1273                                         gpointer         user_data)
1274 {
1275     if( togglebutton->active )
1276     {
1277         gtk_entry_set_text( GTK_ENTRY( lookup_widget(
1278             GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/dvd" );
1279     }
1280 }
1281
1282
1283 void
1284 on_disc_vcd_toggled                    (GtkToggleButton *togglebutton,
1285                                         gpointer         user_data)
1286 {
1287     if( togglebutton->active )
1288     {
1289         gtk_entry_set_text( GTK_ENTRY( lookup_widget(
1290             GTK_WIDGET(togglebutton), "disc_name" ) ), "/dev/cdrom" );
1291     }
1292 }
1293
1294
1295 void
1296 on_disc_ok_clicked                     (GtkButton       *button,
1297                                         gpointer         user_data)
1298 {
1299     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
1300     GtkCList *      p_playlist_clist;
1301     char *          psz_device, *psz_source, *psz_method;
1302     int             i_end = p_main->p_playlist->i_size;
1303
1304     gtk_widget_hide( p_intf->p_sys->p_disc );
1305     psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
1306                                          GTK_WIDGET(button), "disc_name" ) ) );
1307
1308     /* "dvd:foo" has size 5 + strlen(foo) */
1309     psz_source = malloc( 3 /* "dvd" */ + 1 /* ":" */
1310                            + strlen( psz_device ) + 1 /* "\0" */ );
1311     if( psz_source == NULL )
1312     {
1313         return;
1314     }
1315
1316     /* Check which method was activated */
1317     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
1318                                           "disc_dvd" ) )->active )
1319     {
1320         psz_method = "dvd";
1321         p_intf->p_sys->i_intf_mode = DVD_MODE;
1322     }
1323     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
1324                                                "disc_vcd" ) )->active )
1325     {
1326         psz_method = "vcd";
1327     }
1328     else
1329     {
1330         intf_ErrMsg( "intf error: unknown disc type toggle button position" );
1331         free( psz_source );
1332         return;
1333     }
1334     
1335     /* Select title and chapter */
1336     main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
1337                               GTK_SPIN_BUTTON( lookup_widget(
1338                                   GTK_WIDGET(button), "disc_title" ) ) ) );
1339
1340     main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
1341                               GTK_SPIN_BUTTON( lookup_widget(
1342                                   GTK_WIDGET(button), "disc_chapter" ) ) ) );
1343
1344     /* Build source name and add it to playlist */
1345     sprintf( psz_source, "%s:%s", psz_method, psz_device );
1346     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
1347     free( psz_source );
1348
1349     /* catch the GTK CList */
1350     p_playlist_clist = GTK_CLIST( gtk_object_get_data(
1351         GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
1352     /* update the display */
1353     GnomeRebuildCList( p_playlist_clist, p_main->p_playlist );
1354
1355     /* Select added item and switch to DVD interface */
1356     if( p_intf->p_input != NULL )
1357     {
1358         p_intf->p_input->b_eof = 1;
1359     }
1360
1361     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
1362 }
1363
1364
1365 void
1366 on_disc_cancel_clicked                 (GtkButton       *button,
1367                                         gpointer         user_data)
1368 {
1369     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1370 }
1371
1372
1373 /*****************************************************************************
1374  * Network stream callbacks
1375  *****************************************************************************
1376  * The following callbacks are related to the network stream manager.
1377  *****************************************************************************/
1378 void
1379 on_network_ok_clicked                  (GtkButton       *button,
1380                                         gpointer         user_data)
1381 {
1382     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
1383     GtkCList *      p_playlist_clist;
1384     char *          psz_source, *psz_server, *psz_protocol;
1385     unsigned int    i_port;
1386     boolean_t       b_broadcast;
1387     int             i_end = p_main->p_playlist->i_size;
1388
1389     gtk_widget_hide( p_intf->p_sys->p_network );
1390     psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
1391                                  GTK_WIDGET(button), "network_server" ) ) );
1392
1393     /* Check which protocol was activated */
1394     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
1395                                           "network_ts" ) )->active )
1396     {
1397         psz_protocol = "ts";
1398     }
1399     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
1400                                                "network_rtp" ) )->active )
1401     {
1402         psz_protocol = "rtp";
1403     }
1404     else
1405     {
1406         intf_ErrMsg( "intf error: unknown protocol toggle button position" );
1407         return;
1408     }
1409
1410     /* Get the port number and make sure it will not overflow 5 characters */
1411     i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
1412                  lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
1413     if( i_port > 65535 )
1414     {
1415         intf_ErrMsg( "intf error: invalid port %i", i_port );
1416     }
1417
1418     /* do we have a broadcast address */
1419     b_broadcast = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
1420         lookup_widget( GTK_WIDGET(button), "broadcast_check" ) ) );
1421     if( b_broadcast )
1422     {
1423         char *  psz_broadcast;
1424         psz_broadcast = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
1425                                  GTK_WIDGET(button), "network_broadcast" ) ) );
1426         /* Allocate room for "protocol://server:port" */
1427         psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
1428                                + strlen( psz_server ) + 1 /* ":" */
1429                                + 5 /* 0-65535 */
1430                                + strlen( psz_broadcast ) + 2 /* "::" */ 
1431                                + 1 /* "\0" */ );
1432         if( psz_source == NULL )
1433         {
1434             return;
1435         }
1436
1437         /* Build source name and add it to playlist */
1438         sprintf( psz_source, "%s://%s:%i::%s", psz_protocol,
1439                                                psz_server,
1440                                                i_port,
1441                                                psz_broadcast );
1442     }
1443     else
1444     {
1445         /* Allocate room for "protocol://server:port" */
1446         psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
1447                                + strlen( psz_server ) + 1 /* ":" */
1448                                + 5 /* 0-65535 */ + 1 /* "\0" */ );
1449         if( psz_source == NULL )
1450         {
1451             return;
1452         }
1453        
1454         /* Build source name and add it to playlist */
1455         sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
1456     }
1457
1458     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
1459     free( psz_source );
1460
1461     /* catch the GTK CList */
1462     p_playlist_clist = GTK_CLIST( gtk_object_get_data(
1463         GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
1464     /* update the display */
1465     GnomeRebuildCList( p_playlist_clist, p_main->p_playlist );
1466
1467     /* Select added item and switch to network interface */
1468     if( p_intf->p_input != NULL )
1469     {
1470         p_intf->p_input->b_eof = 1;
1471     }
1472
1473     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
1474 }
1475
1476
1477 void
1478 on_network_cancel_clicked              (GtkButton       *button,
1479                                         gpointer         user_data)
1480 {
1481     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1482 }
1483
1484
1485 void
1486 on_broadcast_check_toggled             (GtkToggleButton *togglebutton,
1487                                         gpointer         user_data)
1488 {
1489     GtkWidget *     p_network;
1490
1491     p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
1492     gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
1493             "network_broadcast_combo" ),
1494             gtk_toggle_button_get_active( togglebutton ) );
1495     gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
1496             "network_broadcast" ),
1497             gtk_toggle_button_get_active( togglebutton ) );
1498 }
1499
1500
1501 /****************************************************************************
1502  * Jump window
1503  ****************************************************************************
1504  * Those callback are received from the jump window that allow to select
1505  * an arbitrary position of the stream.
1506  ****************************************************************************/
1507 void
1508 on_jump_ok_clicked                     (GtkButton       *button,
1509                                         gpointer         user_data)
1510 {
1511     on_jump_apply_clicked( button, user_data );
1512     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1513 }
1514
1515
1516 void
1517 on_jump_apply_clicked                  (GtkButton       *button,
1518                                         gpointer         user_data)
1519 {
1520 #if 1
1521     intf_thread_t * p_intf;
1522     off_t           i_seek;
1523     off_t           i_size;
1524     int             i_hours;
1525     int             i_minutes;
1526     int             i_seconds;
1527
1528     p_intf = GetIntf( GTK_WIDGET( button ), "intf_jump" );
1529
1530 #define GET_VALUE( name )                                                   \
1531     gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gtk_object_get_data( \
1532         GTK_OBJECT( p_intf->p_sys->p_jump ), name ) ) )
1533
1534     i_hours   = GET_VALUE( "jump_hour_spinbutton" );
1535     i_minutes = GET_VALUE( "jump_minute_spinbutton" );
1536     i_seconds = GET_VALUE( "jump_second_spinbutton" );
1537
1538 #undef GET_VALUE
1539
1540     i_seconds += 60 *i_minutes + 3600* i_hours;
1541
1542     vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
1543     i_seek = i_seconds * 50 * p_intf->p_input->stream.i_mux_rate;
1544     i_size = p_intf->p_input->stream.p_selected_area->i_size;
1545     vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
1546
1547     if( i_seek < i_size )
1548     {
1549         input_Seek( p_intf->p_input, i_seek );
1550     }
1551 #endif
1552 }
1553
1554
1555 void
1556 on_jump_cancel_clicked                 (GtkButton       *button,
1557                                         gpointer         user_data)
1558 {
1559     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1560 }
1561
1562
1563 /****************************************************************************
1564  * Preferences window callbacks
1565  ****************************************************************************/
1566 void
1567 on_preferences_ok_clicked              (GtkButton       *button,
1568                                         gpointer         user_data)
1569 {
1570     on_preferences_apply_clicked( button, user_data );
1571     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1572 }
1573
1574
1575 void
1576 on_preferences_apply_clicked           (GtkButton       *button,
1577                                         gpointer         user_data)
1578 {
1579 #if 1
1580     GtkWidget *     p_preferences;
1581
1582     /* get preferences window */
1583     p_preferences = gtk_widget_get_toplevel( GTK_WIDGET( button ) );
1584
1585 #define ASSIGN_PSZ_ENTRY( var, name )                                        \
1586     main_PutPszVariable( var, gtk_entry_get_text(                            \
1587     GTK_ENTRY( gtk_object_get_data( GTK_OBJECT( p_preferences ), name ) ) ) )
1588
1589 #define ASSIGN_INT_VALUE( var, name )                                        \
1590     main_PutIntVariable( var, gtk_spin_button_get_value_as_int(              \
1591         GTK_SPIN_BUTTON( gtk_object_get_data( GTK_OBJECT( p_preferences ),   \
1592         name ) ) ) )
1593
1594 #define ASSIGN_INT_TOGGLE( var, name )                                       \
1595     main_PutIntVariable( var, gtk_toggle_button_get_active(                  \
1596         GTK_TOGGLE_BUTTON( gtk_object_get_data( GTK_OBJECT( p_preferences ), \
1597         name ) ) ) )
1598
1599     /* Default path */
1600     ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, "preferences_file_entry" );
1601
1602     /* Default DVD */
1603     ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR, "preferences_disc_dvd_entry" );
1604
1605     /* Default VCD */
1606     ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, "preferences_disc_vcd_entry" );
1607
1608     /* Default server */
1609     ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, "preferences_network_server_entry" );
1610
1611     /* Default port */
1612     ASSIGN_INT_VALUE( INPUT_PORT_VAR, "preferences_network_port_spinbutton" );
1613
1614     /* Broadcast address */
1615     ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADRR_VAR,
1616                       "preferences_network_broadcast_entry" );
1617
1618     /* Broadcast stream by default ? */
1619     ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR,
1620                        "preferences_network_broadcast_checkbutton" );
1621
1622     /* XXX Protocol */
1623
1624     /* Default interface */
1625     ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, "preferences_interface_entry" );
1626
1627     /* Default video output */
1628     ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, "preferences_video_output_entry" );
1629
1630     /* Default output width */
1631     ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, "preferences_video_width_spinbutton" );
1632
1633     /* Default output height */
1634     ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, "preferences_video_height_spinbutton" );
1635
1636     /* XXX Default screen depth */
1637
1638     /* XXX Default fullscreen depth */
1639
1640     /* XXX Default gamma */
1641     
1642     /* Fullscreen on play */
1643     ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR,
1644                        "preferences_video_fullscreen_checkbutton" );
1645
1646     /* Grayscale display */
1647     ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR,
1648                        "preferences_video_grayscale_checkbutton" );
1649
1650     /* Default audio output */
1651     ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, "preferences_audio_output_entry" );
1652
1653     /* Default audio device */
1654     ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, "preferences_audio_device_entry" );
1655
1656     /* XXX Default frequency */
1657
1658     /* XXX Default quality */
1659
1660     /* XXX Default number of channels */
1661
1662     /* Use spdif output ? */
1663     ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, "preferences_audio_spdif_checkbutton" );
1664
1665     /* Launch playlist on startup */
1666     ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR,
1667                        "preferences_playlist_launch_on_startup_checkbutton" );
1668
1669     /* Enqueue drag'n dropped item as default */
1670     ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR,
1671                        "preferences_playlist_enqueue_as_default_checkbutton" );
1672
1673     /* Loop on playlist end */
1674     ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR,
1675                        "preferences_playlist_loop_checkbutton" );
1676
1677     /* Verbosity of warning messages */
1678     ASSIGN_INT_VALUE( INTF_WARNING_VAR,
1679                       "preferences_misc_messages_spinbutton" );
1680 #undef ASSIGN_PSZ_ENTRY
1681 #undef ASSIGN_INT_VALUE
1682 #undef ASSIGN_INT_TOGGLE
1683 #endif
1684 }
1685
1686
1687 void
1688 on_preferences_cancel_clicked          (GtkButton       *button,
1689                                         gpointer         user_data)
1690 {
1691     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
1692 }
1693