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