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