]> git.sesse.net Git - vlc/blob - modules/gui/beos/InterfaceWindow.cpp
beos/*: update the playlist properly
[vlc] / modules / gui / beos / InterfaceWindow.cpp
1 /*****************************************************************************
2  * InterfaceWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Tony Castley <tony@castley.net>
10  *          Richard Shepherd <richard@rshepherd.demon.co.uk>
11  *          Stephan Aßmus <superstippi@gmx.de>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
26  *****************************************************************************/
27
28 /* System headers */
29 #include <kernel/OS.h>
30 #include <InterfaceKit.h>
31 #include <AppKit.h>
32 #include <StorageKit.h>
33 #include <SupportKit.h>
34 #include <malloc.h>
35 #include <scsi.h>
36 #include <scsiprobe_driver.h>
37 #include <fs_info.h>
38 #include <string.h>
39
40 /* VLC headers */
41 #include <vlc/vlc.h>
42 #include <vlc/aout.h>
43 #include <vlc/intf.h>
44 #include <vlc/input.h>
45
46 /* BeOS interface headers */
47 #include "MsgVals.h"
48 #include "MediaControlView.h"
49 #include "PlayListWindow.h"
50 #include "PreferencesWindow.h"
51 #include "MessagesWindow.h"
52 #include "InterfaceWindow.h"
53
54 #define INTERFACE_UPDATE_TIMEOUT  80000 // 2 frames if at 25 fps
55 #define INTERFACE_LOCKING_TIMEOUT 5000
56
57 // make_sure_frame_is_on_screen
58 bool
59 make_sure_frame_is_on_screen( BRect& frame )
60 {
61     BScreen screen( B_MAIN_SCREEN_ID );
62     if (frame.IsValid() && screen.IsValid()) {
63         if (!screen.Frame().Contains(frame)) {
64             // make sure frame fits in the screen
65             if (frame.Width() > screen.Frame().Width())
66                 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
67             if (frame.Height() > screen.Frame().Height())
68                 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
69             // frame is now at the most the size of the screen
70             if (frame.right > screen.Frame().right)
71                 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
72             if (frame.bottom > screen.Frame().bottom)
73                 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
74             if (frame.left < screen.Frame().left)
75                 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
76             if (frame.top < screen.Frame().top)
77                 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
78         }
79         return true;
80     }
81     return false;
82 }
83
84 // make_sure_frame_is_within_limits
85 void
86 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
87                                   float maxWidth, float maxHeight )
88 {
89     if ( frame.Width() < minWidth )
90         frame.right = frame.left + minWidth;
91     if ( frame.Height() < minHeight )
92         frame.bottom = frame.top + minHeight;
93     if ( frame.Width() > maxWidth )
94         frame.right = frame.left + maxWidth;
95     if ( frame.Height() > maxHeight )
96         frame.bottom = frame.top + maxHeight;
97 }
98
99 // get_volume_info
100 bool
101 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
102 {
103     bool success = false;
104     isCDROM = false;
105     deviceName = "";
106     volumeName = "";
107     char name[B_FILE_NAME_LENGTH];
108     if ( volume.GetName( name ) >= B_OK )    // disk is currently mounted
109     {
110         volumeName = name;
111         dev_t dev = volume.Device();
112         fs_info info;
113         if ( fs_stat_dev( dev, &info ) == B_OK )
114         {
115             success = true;
116             deviceName = info.device_name;
117             if ( volume.IsReadOnly() )
118             {
119                 int i_dev = open( info.device_name, O_RDONLY );
120                 if ( i_dev >= 0 )
121                 {
122                     device_geometry g;
123                     if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
124                         isCDROM = ( g.device_type == B_CD );
125                     close( i_dev );
126                 }
127             }
128         }
129      }
130      return success;
131 }
132
133 // collect_folder_contents
134 void
135 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
136 {
137     while ( dir.GetNextEntry( &entry, true ) == B_OK )
138     {
139         if ( !entry.IsDirectory() )
140         {
141             BPath path;
142             // since the directory will give us the entries in reverse order,
143             // we put them each at the same index, effectively reversing the
144             // items while adding them
145             if ( entry.GetPath( &path ) == B_OK )
146             {
147                 BString* string = new BString( path.Path() );
148                 if ( !list.AddItem( string, 0 ) )
149                     delete string;    // at least don't leak
150             }
151         }
152         else
153         {
154             if ( !asked )
155             {
156                 // ask user if we should parse sub-folders as well
157                 BAlert* alert = new BAlert( "sub-folders?",
158                                             _("Open files from all sub-folders as well?"),
159                                             _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL,
160                                             B_IDEA_ALERT );
161                 int32 buttonIndex = alert->Go();
162                 deep = buttonIndex == 1;
163                 asked = true;
164                 // never delete BAlerts!!
165             }
166             if ( deep )
167             {
168                 BDirectory subDir( &entry );
169                 if ( subDir.InitCheck() == B_OK )
170                     collect_folder_contents( subDir, list,
171                                              deep, asked, entry );
172             }
173         }
174     }
175 }
176
177 static int PlaylistChanged( vlc_object_t *p_this, const char * psz_variable,
178                             vlc_value_t old_val, vlc_value_t new_val,
179                             void * param )
180 {
181     InterfaceWindow * w = (InterfaceWindow *) param;
182     w->UpdatePlaylist();
183     return VLC_SUCCESS;
184 }
185
186 /*****************************************************************************
187  * InterfaceWindow
188  *****************************************************************************/
189
190 InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
191                                   const char * name )
192     : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
193                B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
194
195       /* Initializations */
196       p_intf( _p_intf ),
197       p_input( NULL ),
198       p_playlist( NULL ),
199
200       fFilePanel( NULL ),
201       fLastUpdateTime( system_time() ),
202       fSettings( new BMessage( 'sett' ) )
203 {
204     p_playlist = (playlist_t *)
205         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
206
207     var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
208     var_AddCallback( p_playlist, "item-change", PlaylistChanged, this );
209     var_AddCallback( p_playlist, "item-append", PlaylistChanged, this );
210     var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, this );
211     var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, this );
212
213     char psz_tmp[1024];
214 #define ADD_ELLIPSIS( a ) \
215     memset( psz_tmp, 0, 1024 ); \
216     snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );
217
218     BScreen screen;
219     BRect screen_rect = screen.Frame();
220     BRect window_rect;
221     window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
222                      ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
223                      ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
224                      ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
225     fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
226     window_rect.Set( screen_rect.right - 500,
227                      screen_rect.top + 50,
228                      screen_rect.right - 150,
229                      screen_rect.top + 250 );
230     fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
231     window_rect.Set( screen_rect.right - 550,
232                      screen_rect.top + 300,
233                      screen_rect.right - 150,
234                      screen_rect.top + 500 );
235     fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
236
237     // the media control view
238     p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );
239     p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
240
241     float width, height;
242     p_mediaControl->GetPreferredSize( &width, &height );
243
244     // set up the main menu
245     fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
246                              B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
247
248     // make menu bar resize to correct height
249     float menuWidth, menuHeight;
250     fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
251     fMenuBar->ResizeTo( width, menuHeight );    // don't change! it's a workarround!
252     // take care of proper size for ourself
253     height += fMenuBar->Bounds().Height();
254     ResizeTo( width, height );
255
256     p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
257     AddChild( fMenuBar );
258
259
260     // Add the file Menu
261     BMenu* fileMenu = new BMenu( _("File") );
262     fMenuBar->AddItem( fileMenu );
263     ADD_ELLIPSIS( _("Open File") );
264     fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );
265     fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
266     ADD_ELLIPSIS( _("Open Subtitles") );
267     fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );
268
269     fileMenu->AddSeparatorItem();
270     ADD_ELLIPSIS( _("About") );
271     BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');
272     item->SetTarget( be_app );
273     fileMenu->AddItem( item );
274     fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
275
276     fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );
277     fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );
278
279     /* Add the Audio menu */
280     fAudioMenu = new BMenu( _("Audio") );
281     fMenuBar->AddItem ( fAudioMenu );
282     fAudioMenu->AddItem( fLanguageMenu );
283     fAudioMenu->AddItem( fSubtitlesMenu );
284
285     fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
286     fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
287     fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );
288     fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );
289
290     /* Add the Navigation menu */
291     fNavigationMenu = new BMenu( _("Navigation") );
292     fMenuBar->AddItem( fNavigationMenu );
293     fNavigationMenu->AddItem( fPrevTitleMI );
294     fNavigationMenu->AddItem( fNextTitleMI );
295     fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
296     fNavigationMenu->AddSeparatorItem();
297     fNavigationMenu->AddItem( fPrevChapterMI );
298     fNavigationMenu->AddItem( fNextChapterMI );
299     fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
300
301     /* Add the Speed menu */
302     fSpeedMenu = new BMenu( _("Speed") );
303     fSpeedMenu->SetRadioMode( true );
304     fSpeedMenu->AddItem(
305         fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
306     fSpeedMenu->AddItem(
307         fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
308     fSpeedMenu->AddItem(
309         fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
310     fSpeedMenu->AddItem(
311         fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
312     fSpeedMenu->AddItem(
313         fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
314     fSpeedMenu->AddItem(
315         fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
316     fSpeedMenu->AddItem(
317         fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
318     fMenuBar->AddItem( fSpeedMenu );
319
320     /* Add the Show menu */
321     fShowMenu = new BMenu( _("Window") );
322     ADD_ELLIPSIS( _("Playlist") );
323     fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );
324     ADD_ELLIPSIS( _("Messages") );
325     fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );
326     ADD_ELLIPSIS( _("Preferences") );
327     fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );
328     fMenuBar->AddItem( fShowMenu );
329
330     // add the media control view after the menubar is complete
331     // because it will set the window size limits in AttachedToWindow()
332     // and the menubar needs to report the correct PreferredSize()
333     AddChild( p_mediaControl );
334
335     /* Prepare fow showing */
336     _SetMenusEnabled( false );
337     p_mediaControl->SetEnabled( false );
338
339     _RestoreSettings();
340
341     Show();
342 }
343
344 InterfaceWindow::~InterfaceWindow()
345 {
346     if( p_input )
347     {
348         vlc_object_release( p_input );
349     }
350     if( p_playlist )
351     {
352         vlc_object_release( p_playlist );
353     }
354     if( fPlaylistWindow )
355     {
356         fPlaylistWindow->ReallyQuit();
357     }
358     if( fMessagesWindow )
359     {
360         fMessagesWindow->ReallyQuit();
361     }
362     if( fPreferencesWindow )
363     {
364         fPreferencesWindow->ReallyQuit();
365     }
366     delete fFilePanel;
367     delete fSettings;
368 }
369
370 /*****************************************************************************
371  * InterfaceWindow::FrameResized
372  *****************************************************************************/
373 void
374 InterfaceWindow::FrameResized(float width, float height)
375 {
376     BRect r(Bounds());
377     fMenuBar->MoveTo(r.LeftTop());
378     fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
379     r.top += fMenuBar->Bounds().Height() + 1.0;
380     p_mediaControl->MoveTo(r.LeftTop());
381     p_mediaControl->ResizeTo(r.Width(), r.Height());
382 }
383
384 /*****************************************************************************
385  * InterfaceWindow::MessageReceived
386  *****************************************************************************/
387 void InterfaceWindow::MessageReceived( BMessage * p_message )
388 {
389     switch( p_message->what )
390     {
391         case B_ABOUT_REQUESTED:
392         {
393             BAlert * alert;
394
395             alert = new BAlert( "VLC media player" VERSION,
396                                 "VLC media player" VERSION " (BeOS interface)\n\n"
397                                 "The VideoLAN team <videolan@videolan.org>\n"
398                                 "http://www.videolan.org/", _("OK") );
399             alert->Go();
400             break;
401         }
402         case TOGGLE_ON_TOP:
403             break;
404
405         case OPEN_FILE:
406             _ShowFilePanel( B_REFS_RECEIVED, _("VLC media player: Open Media Files") );
407             break;
408
409         case LOAD_SUBFILE:
410             _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
411             break;
412
413         case OPEN_PLAYLIST:
414             if (fPlaylistWindow->Lock())
415             {
416                 if (fPlaylistWindow->IsHidden())
417                     fPlaylistWindow->Show();
418                 else
419                     fPlaylistWindow->Activate();
420                 fPlaylistWindow->Unlock();
421             }
422             break;
423
424         case OPEN_DVD:
425             {
426                 const char * psz_device;
427                 if( p_playlist &&
428                     p_message->FindString( "device", &psz_device ) == B_OK )
429                 {
430                     char psz_uri[1024];
431                     memset( psz_uri, 0, 1024 );
432                     snprintf( psz_uri, 1024, "dvdnav:%s", psz_device );
433                     playlist_Add( p_playlist, psz_uri, psz_device,
434                                   PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
435                 }
436                 UpdatePlaylist();
437             }
438             break;
439
440         case SUBFILE_RECEIVED:
441         {
442             entry_ref ref;
443             if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
444             {
445                 BPath path( &ref );
446                 if ( path.InitCheck() == B_OK )
447                     config_PutPsz( p_intf, "sub-file", path.Path() );
448             }
449             break;
450         }
451
452         case STOP_PLAYBACK:
453             if( p_playlist )
454             {
455                 playlist_Stop( p_playlist );
456             }
457             p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
458             break;
459
460         case START_PLAYBACK:
461         case PAUSE_PLAYBACK:
462         {
463             vlc_value_t val;
464             val.i_int = PLAYING_S;
465             if( p_input )
466             {
467                 var_Get( p_input, "state", &val );
468             }
469             if( p_input && val.i_int != PAUSE_S )
470             {
471                 val.i_int = PAUSE_S;
472                 var_Set( p_input, "state", val );
473             }
474             else
475             {
476                 playlist_Play( p_playlist );
477             }
478             break;
479         }
480         case HEIGHTH_PLAY:
481             if( p_input )
482             {
483                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
484             }
485             break;
486
487         case QUARTER_PLAY:
488             if( p_input )
489             {
490                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
491             }
492             break;
493
494         case HALF_PLAY:
495             if( p_input )
496             {
497                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
498             }
499             break;
500
501         case NORMAL_PLAY:
502             if( p_input )
503             {
504                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
505             }
506             break;
507
508         case TWICE_PLAY:
509             if( p_input )
510             {
511                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
512             }
513             break;
514
515         case FOUR_PLAY:
516             if( p_input )
517             {
518                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
519             }
520             break;
521
522         case HEIGHT_PLAY:
523             if( p_input )
524             {
525                 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
526             }
527             break;
528
529         case SEEK_PLAYBACK:
530             /* handled by semaphores */
531             break;
532
533         case VOLUME_CHG:
534             aout_VolumeSet( p_intf, p_mediaControl->GetVolume() );
535             break;
536
537         case VOLUME_MUTE:
538             aout_VolumeMute( p_intf, NULL );
539             break;
540
541         case SELECT_CHANNEL:
542         {
543             int32 channel;
544             if( p_input )
545             {
546                 if( p_message->FindInt32( "audio-es", &channel ) == B_OK )
547                 {
548                     var_SetInteger( p_input, "audio-es", channel );
549                 }
550                 else if( p_message->FindInt32( "spu-es", &channel ) == B_OK )
551                 {
552                     var_SetInteger( p_input, "spu-es", channel );
553                 }
554             }
555             break;
556         }
557
558         case PREV_TITLE:
559             if( p_input )
560             {
561                 var_SetVoid( p_input, "prev-title" );
562             }
563             break;
564
565         case NEXT_TITLE:
566             if( p_input )
567             {
568                 var_SetVoid( p_input, "next-title" );
569             }
570             break;
571
572         case TOGGLE_TITLE:
573         {
574             int32 index;
575             if( p_input &&
576                 p_message->FindInt32( "index", &index ) == B_OK )
577             {
578                 var_SetInteger( p_input, "title", index );
579             }
580             break;
581         }
582
583         case PREV_CHAPTER:
584             if( p_input )
585             {
586                 var_SetVoid( p_input, "prev-chapter" );
587             }
588             break;
589
590         case NEXT_CHAPTER:
591             if( p_input )
592             {
593                 var_SetVoid( p_input, "next-chapter" );
594             }
595             break;
596
597         case TOGGLE_CHAPTER:
598         {
599             int32 index;
600             if( p_input &&
601                 p_message->FindInt32( "index", &index ) == B_OK )
602             {
603                 var_SetInteger( p_input, "chapter", index );
604             }
605             break;
606         }
607
608         case PREV_FILE:
609             if( p_playlist )
610             {
611                 playlist_Prev( p_playlist );
612             }
613             break;
614
615         case NEXT_FILE:
616             if( p_playlist )
617             {
618                 playlist_Next( p_playlist );
619             }
620             break;
621
622         case NAVIGATE_PREV:
623             if( p_input )
624             {
625                 vlc_value_t val;
626
627                 /* First try to go to previous chapter */
628                 if( !var_Get( p_input, "chapter", &val ) )
629                 {
630                     if( val.i_int > 1 )
631                     {
632                         var_SetVoid( p_input, "prev-chapter" );
633                         break;
634                     }
635                 }
636
637                 /* Try to go to previous title */
638                 if( !var_Get( p_input, "title", &val ) )
639                 {
640                     if( val.i_int > 1 )
641                     {
642                         var_SetVoid( p_input, "prev-title" );
643                         break;
644                     }
645                 }
646
647                 /* Try to go to previous file */
648                 if( p_playlist )
649                 {
650                     playlist_Prev( p_playlist );
651                 }
652             }
653             break;
654
655         case NAVIGATE_NEXT:
656             if( p_input )
657             {
658                 vlc_value_t val, val_list;
659
660                 /* First try to go to next chapter */
661                 if( !var_Get( p_input, "chapter", &val ) )
662                 {
663                     var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
664                                 &val_list, NULL );
665                     if( val_list.p_list->i_count > val.i_int )
666                     {
667                         var_Change( p_input, "chapter", VLC_VAR_FREELIST,
668                                     &val_list, NULL );
669                         var_SetVoid( p_input, "next-chapter" );
670                         break;
671                     }
672                     var_Change( p_input, "chapter", VLC_VAR_FREELIST,
673                                 &val_list, NULL );
674                 }
675
676                 /* Try to go to next title */
677                 if( !var_Get( p_input, "title", &val ) )
678                 {
679                     var_Change( p_input, "title", VLC_VAR_GETCHOICES,
680                                 &val_list, NULL );
681                     if( val_list.p_list->i_count > val.i_int )
682                     {
683                         var_Change( p_input, "title", VLC_VAR_FREELIST,
684                                     &val_list, NULL );
685                         var_SetVoid( p_input, "next-title" );
686                         break;
687                     }
688                     var_Change( p_input, "title", VLC_VAR_FREELIST,
689                                 &val_list, NULL );
690                 }
691
692                 /* Try to go to next file */
693                 if( p_playlist )
694                 {
695                     playlist_Next( p_playlist );
696                 }
697             }
698             break;
699
700         // drag'n'drop and system messages
701         case MSG_SOUNDPLAY:
702             // convert soundplay drag'n'drop message (containing paths)
703             // to normal message (containing refs)
704             {
705                 const char* path;
706                 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
707                 {
708                     entry_ref ref;
709                     if ( get_ref_for_path( path, &ref ) == B_OK )
710                         p_message->AddRef( "refs", &ref );
711                 }
712             }
713             // fall through
714         case B_REFS_RECEIVED:
715         case B_SIMPLE_DATA:
716         {
717             /* file(s) opened by the File menu -> append to the playlist;
718                file(s) opened by drag & drop -> replace playlist;
719                file(s) opened by 'shift' + drag & drop -> append */
720
721             int32 count;
722             type_code dummy;
723             if( p_message->GetInfo( "refs", &dummy, &count ) != B_OK ||
724                 count < 1 )
725             {
726                 break;
727             }
728
729             vlc_bool_t b_remove = ( p_message->WasDropped() &&
730                                     !( modifiers() & B_SHIFT_KEY ) );
731
732             if( b_remove && p_playlist )
733             {
734                 playlist_Clear( p_playlist );
735             }
736
737             entry_ref ref;
738             for( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
739             {
740                 BPath path( &ref );
741
742                 /* TODO: find out if this is a DVD icon */
743
744                 if( p_playlist )
745                 {
746                     playlist_Add( p_playlist, path.Path(), path.Path(),
747                                   PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
748                 }
749             }
750
751             UpdatePlaylist();
752             break;
753         }
754
755         case OPEN_PREFERENCES:
756         {
757             if( fPreferencesWindow->Lock() )
758             {
759                 if (fPreferencesWindow->IsHidden())
760                     fPreferencesWindow->Show();
761                 else
762                     fPreferencesWindow->Activate();
763                 fPreferencesWindow->Unlock();
764             }
765             break;
766         }
767
768         case OPEN_MESSAGES:
769         {
770             if( fMessagesWindow->Lock() )
771             {
772                 if (fMessagesWindow->IsHidden())
773                     fMessagesWindow->Show();
774                 else
775                     fMessagesWindow->Activate();
776                 fMessagesWindow->Unlock();
777             }
778             break;
779         }
780         case MSG_UPDATE:
781             UpdateInterface();
782             break;
783         default:
784             BWindow::MessageReceived( p_message );
785             break;
786     }
787 }
788
789 /*****************************************************************************
790  * InterfaceWindow::QuitRequested
791  *****************************************************************************/
792 bool InterfaceWindow::QuitRequested()
793 {
794     if( p_playlist )
795     {
796         playlist_Stop( p_playlist );
797     }
798     p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
799
800      _StoreSettings();
801
802     p_intf->b_die = 1;
803
804     return( true );
805 }
806
807 /*****************************************************************************
808  * InterfaceWindow::UpdateInterface
809  *****************************************************************************/
810 void InterfaceWindow::UpdateInterface()
811 {
812     if( !p_input )
813     {
814         p_input = (input_thread_t *)
815             vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
816     }
817     else if( p_input->b_dead )
818     {
819         vlc_object_release( p_input );
820         p_input = NULL;
821     }
822
823     /* Get ready to update the interface */
824     if( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) != B_OK )
825     {
826         return;
827     }
828
829     if( b_playlist_update )
830     {
831         if( fPlaylistWindow->Lock() )
832         {
833             fPlaylistWindow->UpdatePlaylist( true );
834             fPlaylistWindow->Unlock();
835             b_playlist_update = false;
836         }
837         p_mediaControl->SetEnabled( p_playlist->i_size );
838     }
839
840     if( p_input )
841     {
842         vlc_value_t val;
843         p_mediaControl->SetEnabled( true );
844         bool hasTitles   = !var_Get( p_input, "title", &val );
845         bool hasChapters = !var_Get( p_input, "chapter", &val );
846         p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
847                                    var_GetInteger( p_input, "rate" ) );
848         var_Get( p_input, "position", &val );
849         p_mediaControl->SetProgress( val.f_float );
850         _SetMenusEnabled( true, hasChapters, hasTitles );
851         _UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
852
853         // enable/disable skip buttons
854 #if 0
855         bool canSkipPrev;
856         bool canSkipNext;
857         p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
858         p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
859 #endif
860
861         audio_volume_t i_volume;
862         aout_VolumeGet( p_intf, &i_volume );
863         p_mediaControl->SetAudioEnabled( true );
864         p_mediaControl->SetMuted( i_volume );
865     }
866     else
867     {
868         p_mediaControl->SetAudioEnabled( false );
869
870         _SetMenusEnabled( false );
871
872         if( !playlist_IsEmpty( p_playlist ) )
873         {
874             p_mediaControl->SetProgress( 0 );
875
876 #if 0
877             // enable/disable skip buttons
878             bool canSkipPrev;
879             bool canSkipNext;
880             p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
881             p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
882 #endif
883         }
884         else
885         {
886             p_mediaControl->SetEnabled( false );
887         }
888     }
889
890     Unlock();
891     fLastUpdateTime = system_time();
892 }
893
894 /*****************************************************************************
895  * InterfaceWindow::UpdatePlaylist
896  *****************************************************************************/
897 void
898 InterfaceWindow::UpdatePlaylist()
899 {
900     b_playlist_update = true;
901 }
902
903 /*****************************************************************************
904  * InterfaceWindow::IsStopped
905  *****************************************************************************/
906 bool
907 InterfaceWindow::IsStopped() const
908 {
909     return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
910 }
911
912 /*****************************************************************************
913  * InterfaceWindow::_SetMenusEnabled
914  *****************************************************************************/
915 void
916 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
917 {
918     if (!hasFile)
919     {
920         hasChapters = false;
921         hasTitles = false;
922     }
923     if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
924     {
925         if ( fNextChapterMI->IsEnabled() != hasChapters )
926              fNextChapterMI->SetEnabled( hasChapters );
927         if ( fPrevChapterMI->IsEnabled() != hasChapters )
928              fPrevChapterMI->SetEnabled( hasChapters );
929         if ( fChapterMenu->IsEnabled() != hasChapters )
930              fChapterMenu->SetEnabled( hasChapters );
931         if ( fNextTitleMI->IsEnabled() != hasTitles )
932              fNextTitleMI->SetEnabled( hasTitles );
933         if ( fPrevTitleMI->IsEnabled() != hasTitles )
934              fPrevTitleMI->SetEnabled( hasTitles );
935         if ( fTitleMenu->IsEnabled() != hasTitles )
936              fTitleMenu->SetEnabled( hasTitles );
937         if ( fAudioMenu->IsEnabled() != hasFile )
938              fAudioMenu->SetEnabled( hasFile );
939         if ( fNavigationMenu->IsEnabled() != hasFile )
940              fNavigationMenu->SetEnabled( hasFile );
941         if ( fLanguageMenu->IsEnabled() != hasFile )
942              fLanguageMenu->SetEnabled( hasFile );
943         if ( fSubtitlesMenu->IsEnabled() != hasFile )
944              fSubtitlesMenu->SetEnabled( hasFile );
945         if ( fSpeedMenu->IsEnabled() != hasFile )
946              fSpeedMenu->SetEnabled( hasFile );
947         Unlock();
948     }
949 }
950
951 /*****************************************************************************
952  * InterfaceWindow::_UpdateSpeedMenu
953  *****************************************************************************/
954 void
955 InterfaceWindow::_UpdateSpeedMenu( int rate )
956 {
957     BMenuItem * toMark = NULL;
958
959     switch( rate )
960     {
961         case ( INPUT_RATE_DEFAULT * 8 ):
962             toMark = fHeighthMI;
963             break;
964
965         case ( INPUT_RATE_DEFAULT * 4 ):
966             toMark = fQuarterMI;
967             break;
968
969         case ( INPUT_RATE_DEFAULT * 2 ):
970             toMark = fHalfMI;
971             break;
972
973         case ( INPUT_RATE_DEFAULT ):
974             toMark = fNormalMI;
975             break;
976
977         case ( INPUT_RATE_DEFAULT / 2 ):
978             toMark = fTwiceMI;
979             break;
980
981         case ( INPUT_RATE_DEFAULT / 4 ):
982             toMark = fFourMI;
983             break;
984
985         case ( INPUT_RATE_DEFAULT / 8 ):
986             toMark = fHeightMI;
987             break;
988     }
989
990     if ( toMark && !toMark->IsMarked() )
991     {
992         toMark->SetMarked( true );
993     }
994 }
995
996 /*****************************************************************************
997  * InterfaceWindow::_ShowFilePanel
998  *****************************************************************************/
999 void
1000 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
1001 {
1002     if( !fFilePanel )
1003     {
1004         fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
1005                                      B_FILE_NODE | B_DIRECTORY_NODE );
1006         fFilePanel->SetTarget( this );
1007     }
1008     fFilePanel->Window()->SetTitle( windowTitle );
1009     BMessage message( command );
1010     fFilePanel->SetMessage( &message );
1011     if ( !fFilePanel->IsShowing() )
1012     {
1013         fFilePanel->Refresh();
1014         fFilePanel->Show();
1015     }
1016 }
1017
1018 // set_window_pos
1019 void
1020 set_window_pos( BWindow* window, BRect frame )
1021 {
1022     // sanity checks: make sure window is not too big/small
1023     // and that it's not off-screen
1024     float minWidth, maxWidth, minHeight, maxHeight;
1025     window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1026
1027     make_sure_frame_is_within_limits( frame,
1028                                       minWidth, minHeight, maxWidth, maxHeight );
1029     if ( make_sure_frame_is_on_screen( frame ) )
1030     {
1031         window->MoveTo( frame.LeftTop() );
1032         window->ResizeTo( frame.Width(), frame.Height() );
1033     }
1034 }
1035
1036 // set_window_pos
1037 void
1038 launch_window( BWindow* window, bool showing )
1039 {
1040     if ( window->Lock() )
1041     {
1042         if ( showing )
1043         {
1044             if ( window->IsHidden() )
1045                 window->Show();
1046         }
1047         else
1048         {
1049             if ( !window->IsHidden() )
1050                 window->Hide();
1051         }
1052         window->Unlock();
1053     }
1054 }
1055
1056 /*****************************************************************************
1057  * InterfaceWindow::_RestoreSettings
1058  *****************************************************************************/
1059 void
1060 InterfaceWindow::_RestoreSettings()
1061 {
1062     if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1063     {
1064         BRect frame;
1065         if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1066             set_window_pos( this, frame );
1067         if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1068             set_window_pos( fPlaylistWindow, frame );
1069         if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1070             set_window_pos( fMessagesWindow, frame );
1071         if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1072         {
1073             /* FIXME: Preferences resizing doesn't work correctly yet */
1074             frame.right = frame.left + fPreferencesWindow->Frame().Width();
1075             frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
1076             set_window_pos( fPreferencesWindow, frame );
1077         }
1078
1079         bool showing;
1080         if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1081             launch_window( fPlaylistWindow, showing );
1082         if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1083             launch_window( fMessagesWindow, showing );
1084         if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1085             launch_window( fPreferencesWindow, showing );
1086
1087         uint32 displayMode;
1088         if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1089             fPlaylistWindow->SetDisplayMode( displayMode );
1090     }
1091 }
1092
1093 /*****************************************************************************
1094  * InterfaceWindow::_StoreSettings
1095  *****************************************************************************/
1096 void
1097 InterfaceWindow::_StoreSettings()
1098 {
1099     /* Save the volume */
1100     config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
1101     config_SaveConfigFile( p_intf, "main" );
1102
1103     /* Save the windows positions */
1104     if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1105         fSettings->AddRect( "main frame", Frame() );
1106     if ( fPlaylistWindow->Lock() )
1107     {
1108         if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1109             fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1110         if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1111             fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1112         fPlaylistWindow->Unlock();
1113     }
1114     if ( fMessagesWindow->Lock() )
1115     {
1116         if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1117             fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1118         if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1119             fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1120         fMessagesWindow->Unlock();
1121     }
1122     if ( fPreferencesWindow->Lock() )
1123     {
1124         if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1125             fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1126         if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1127             fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1128         fPreferencesWindow->Unlock();
1129     }
1130     uint32 displayMode = fPlaylistWindow->DisplayMode();
1131     if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1132         fSettings->AddInt32( "playlist display mode", displayMode );
1133
1134     save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1135 }
1136
1137
1138 /*****************************************************************************
1139  * CDMenu::CDMenu
1140  *****************************************************************************/
1141 CDMenu::CDMenu(const char *name)
1142       : BMenu(name)
1143 {
1144 }
1145
1146 /*****************************************************************************
1147  * CDMenu::~CDMenu
1148  *****************************************************************************/
1149 CDMenu::~CDMenu()
1150 {
1151 }
1152
1153 /*****************************************************************************
1154  * CDMenu::AttachedToWindow
1155  *****************************************************************************/
1156 void CDMenu::AttachedToWindow(void)
1157 {
1158     // remove all items
1159     while ( BMenuItem* item = RemoveItem( 0L ) )
1160         delete item;
1161     GetCD( "/dev/disk" );
1162     BMenu::AttachedToWindow();
1163 }
1164
1165 /*****************************************************************************
1166  * CDMenu::GetCD
1167  *****************************************************************************/
1168 int CDMenu::GetCD( const char *directory )
1169 {
1170     BVolumeRoster volRoster;
1171     BVolume vol;
1172     BDirectory dir;
1173     status_t status = volRoster.GetNextVolume( &vol );
1174     while ( status ==  B_NO_ERROR )
1175     {
1176         BString deviceName;
1177         BString volumeName;
1178         bool isCDROM;
1179         if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1180              && isCDROM )
1181         {
1182             BMessage* msg = new BMessage( OPEN_DVD );
1183             msg->AddString( "device", deviceName.String() );
1184             BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1185             AddItem( item );
1186         }
1187          vol.Unset();
1188         status = volRoster.GetNextVolume( &vol );
1189     }
1190     return 0;
1191 }
1192
1193 /*****************************************************************************
1194  * LanguageMenu::LanguageMenu
1195  *****************************************************************************/
1196 LanguageMenu::LanguageMenu( intf_thread_t * _p_intf, const char * psz_name,
1197                             char * _psz_variable )
1198     : BMenu( psz_name )
1199 {
1200     p_intf       = _p_intf;
1201     psz_variable = strdup( _psz_variable );
1202 }
1203
1204 /*****************************************************************************
1205  * LanguageMenu::~LanguageMenu
1206  *****************************************************************************/
1207 LanguageMenu::~LanguageMenu()
1208 {
1209     free( psz_variable );
1210 }
1211
1212 /*****************************************************************************
1213  * LanguageMenu::AttachedToWindow
1214  *****************************************************************************/
1215 void LanguageMenu::AttachedToWindow()
1216 {
1217     BMenuItem * item;
1218
1219     // remove all items
1220     while( ( item = RemoveItem( 0L ) ) )
1221     {
1222         delete item;
1223     }
1224
1225     SetRadioMode( true );
1226
1227     input_thread_t * p_input = (input_thread_t *)
1228             vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1229     if( !p_input )
1230     {
1231         return;
1232     }
1233
1234     vlc_value_t val_list, text_list;
1235     BMessage * message;
1236     int i_current;
1237
1238     i_current = var_GetInteger( p_input, psz_variable );
1239     var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list );
1240     for( int i = 0; i < val_list.p_list->i_count; i++ )
1241     {
1242         message = new BMessage( SELECT_CHANNEL );
1243         message->AddInt32( psz_variable, val_list.p_list->p_values[i].i_int );
1244         item = new BMenuItem( text_list.p_list->p_values[i].psz_string, message );
1245         if( val_list.p_list->p_values[i].i_int == i_current )
1246         {
1247             item->SetMarked( true );
1248         }
1249         AddItem( item );
1250     }
1251     var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
1252
1253     vlc_object_release( p_input );
1254
1255     BMenu::AttachedToWindow();
1256 }
1257
1258 /*****************************************************************************
1259  * TitleMenu::TitleMenu
1260  *****************************************************************************/
1261 TitleMenu::TitleMenu( const char *name, intf_thread_t  *p_interface )
1262     : BMenu(name),
1263     p_intf( p_interface )
1264 {
1265 }
1266
1267 /*****************************************************************************
1268  * TitleMenu::~TitleMenu
1269  *****************************************************************************/
1270 TitleMenu::~TitleMenu()
1271 {
1272 }
1273
1274 /*****************************************************************************
1275  * TitleMenu::AttachedToWindow
1276  *****************************************************************************/
1277 void TitleMenu::AttachedToWindow()
1278 {
1279     BMenuItem * item;
1280     while( ( item = RemoveItem( 0L ) ) )
1281     {
1282         delete item;
1283     }
1284
1285     input_thread_t * p_input;
1286     p_input = (input_thread_t *)
1287         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1288     if( !p_input )
1289     {
1290         return;
1291     }
1292
1293     vlc_value_t val;
1294     BMessage * message;
1295     if( !var_Get( p_input, "title", &val ) )
1296     {
1297         vlc_value_t val_list, text_list;
1298         var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1299                     &val_list, &text_list );
1300
1301         for( int i = 0; i < val_list.p_list->i_count; i++ )
1302         {
1303             message = new BMessage( TOGGLE_TITLE );
1304             message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1305             item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1306                                   message );
1307             if( val_list.p_list->p_values[i].i_int == val.i_int )
1308             {
1309                 item->SetMarked( true );
1310             }
1311             AddItem( item );
1312         }
1313
1314         var_Change( p_input, "title", VLC_VAR_FREELIST,
1315                     &val_list, &text_list );
1316     }
1317     vlc_object_release( p_input );
1318     BMenu::AttachedToWindow();
1319 }
1320
1321
1322 /*****************************************************************************
1323  * ChapterMenu::ChapterMenu
1324  *****************************************************************************/
1325 ChapterMenu::ChapterMenu( const char *name, intf_thread_t  *p_interface )
1326     : BMenu(name),
1327     p_intf( p_interface )
1328 {
1329 }
1330
1331 /*****************************************************************************
1332  * ChapterMenu::~ChapterMenu
1333  *****************************************************************************/
1334 ChapterMenu::~ChapterMenu()
1335 {
1336 }
1337
1338 /*****************************************************************************
1339  * ChapterMenu::AttachedToWindow
1340  *****************************************************************************/
1341 void ChapterMenu::AttachedToWindow()
1342 {
1343     BMenuItem * item;
1344     while( ( item = RemoveItem( 0L ) ) )
1345     {
1346         delete item;
1347     }
1348
1349     input_thread_t * p_input;
1350     p_input = (input_thread_t *)
1351         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1352     if( !p_input )
1353     {
1354         return;
1355     }
1356
1357     vlc_value_t val;
1358     BMessage * message;
1359     if( !var_Get( p_input, "chapter", &val ) )
1360     {
1361         vlc_value_t val_list, text_list;
1362         var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1363                     &val_list, &text_list );
1364
1365         for( int i = 0; i < val_list.p_list->i_count; i++ )
1366         {
1367             message = new BMessage( TOGGLE_CHAPTER );
1368             message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1369             item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1370                                   message );
1371             if( val_list.p_list->p_values[i].i_int == val.i_int )
1372             {
1373                 item->SetMarked( true );
1374             }
1375             AddItem( item );
1376         }
1377
1378         var_Change( p_input, "chapter", VLC_VAR_FREELIST,
1379                     &val_list, &text_list );
1380     }
1381     vlc_object_release( p_input );
1382     BMenu::AttachedToWindow();
1383 }
1384
1385
1386 /*****************************************************************************
1387  * load_settings
1388  *****************************************************************************/
1389 status_t
1390 load_settings( BMessage* message, const char* fileName, const char* folder )
1391 {
1392     status_t ret = B_BAD_VALUE;
1393     if ( message )
1394     {
1395         BPath path;
1396         if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1397         {
1398             // passing folder is optional
1399             if ( folder )
1400                 ret = path.Append( folder );
1401             if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1402             {
1403                 BFile file( path.Path(), B_READ_ONLY );
1404                 if ( ( ret = file.InitCheck() ) == B_OK )
1405                 {
1406                     ret = message->Unflatten( &file );
1407                     file.Unset();
1408                 }
1409             }
1410         }
1411     }
1412     return ret;
1413 }
1414
1415 /*****************************************************************************
1416  * save_settings
1417  *****************************************************************************/
1418 status_t
1419 save_settings( BMessage* message, const char* fileName, const char* folder )
1420 {
1421     status_t ret = B_BAD_VALUE;
1422     if ( message )
1423     {
1424         BPath path;
1425         if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1426         {
1427             // passing folder is optional
1428             if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1429                 ret = create_directory( path.Path(), 0777 );
1430             if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1431             {
1432                 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1433                 if ( ( ret = file.InitCheck() ) == B_OK )
1434                 {
1435                     ret = message->Flatten( &file );
1436                     file.Unset();
1437                 }
1438             }
1439         }
1440     }
1441     return ret;
1442 }