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