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