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