]> git.sesse.net Git - vlc/blob - modules/gui/beos/InterfaceWindow.cpp
modules/gui/beos/PreferenceWindow.h/.cpp
[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.29 2003/02/09 17:10:52 stippi 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     SetTitle( VOUT_TITLE );
220
221     // the media control view
222     p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
223                                            p_intf );
224     p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
225
226     float width, height;
227     p_mediaControl->GetPreferredSize( &width, &height );
228
229     // set up the main menu
230     fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
231                              B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
232
233     // make menu bar resize to correct height
234     float menuWidth, menuHeight;
235     fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
236     fMenuBar->ResizeTo( width, menuHeight );    // don't change! it's a workarround!
237     // take care of proper size for ourself
238     height += fMenuBar->Bounds().Height();
239     ResizeTo( width, height );
240
241     p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
242     AddChild( fMenuBar );
243     AddChild( p_mediaControl );
244
245     // Add the file Menu
246     BMenu* fileMenu = new BMenu( "File" );
247     fMenuBar->AddItem( fileMenu );
248     fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
249                                       new BMessage( OPEN_FILE ), 'O') );
250     
251     fileMenu->AddItem( new CDMenu( "Open Disc" ) );
252
253     fileMenu->AddItem( new BMenuItem( "Open Subtitles" B_UTF8_ELLIPSIS,
254                                       new BMessage( LOAD_SUBFILE ) ) );
255     
256     fileMenu->AddSeparatorItem();
257     BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
258                                      new BMessage( B_ABOUT_REQUESTED ), 'A');
259     item->SetTarget( be_app );
260     fileMenu->AddItem( item );
261     fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
262
263     fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_wrapper);
264     fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_wrapper);
265
266     /* Add the Audio menu */
267     fAudioMenu = new BMenu( "Audio" );
268     fMenuBar->AddItem ( fAudioMenu );
269     fAudioMenu->AddItem( fLanguageMenu );
270     fAudioMenu->AddItem( fSubtitlesMenu );
271
272     fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
273     fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
274     fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
275     fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
276     fGotoMenuMI = new BMenuItem( "Goto Menu", new BMessage( NAVIGATE_MENU ) );
277
278     /* Add the Navigation menu */
279     fNavigationMenu = new BMenu( "Navigation" );
280     fMenuBar->AddItem( fNavigationMenu );
281     fNavigationMenu->AddItem( fGotoMenuMI );
282     fNavigationMenu->AddSeparatorItem();
283     fNavigationMenu->AddItem( fPrevTitleMI );
284     fNavigationMenu->AddItem( fNextTitleMI );
285     fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
286     fNavigationMenu->AddSeparatorItem();
287     fNavigationMenu->AddItem( fPrevChapterMI );
288     fNavigationMenu->AddItem( fNextChapterMI );
289     fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
290
291     /* Add the Speed menu */
292     fSpeedMenu = new BMenu( "Speed" );
293     fSpeedMenu->SetRadioMode( true );
294     fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
295     fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
296     fNormalMI->SetMarked(true); // default to normal speed
297     fSpeedMenu->AddItem( fNormalMI );
298     fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
299     fSpeedMenu->SetTargetForItems( this );
300     fMenuBar->AddItem( fSpeedMenu );
301
302     /* Add the Show menu */
303     fShowMenu = new BMenu( "Window" );
304     fShowMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
305                                        new BMessage( OPEN_PLAYLIST ), 'P') );
306     fShowMenu->AddItem( new BMenuItem( "Messages" B_UTF8_ELLIPSIS,
307                                        new BMessage( OPEN_MESSAGES ), 'M' ) );
308     fShowMenu->AddItem( new BMenuItem( "Settings" B_UTF8_ELLIPSIS,
309                                        new BMessage( OPEN_PREFERENCES ), 'S' ) );
310     fMenuBar->AddItem( fShowMenu );                            
311
312     /* Prepare fow showing */
313     _SetMenusEnabled( false );
314     p_mediaControl->SetEnabled( false );
315
316         _RestoreSettings();    
317
318     Show();
319 }
320
321 InterfaceWindow::~InterfaceWindow()
322 {
323     if( fPlaylistWindow )
324         fPlaylistWindow->ReallyQuit();
325     fPlaylistWindow = NULL;
326     if( fMessagesWindow )
327         fMessagesWindow->ReallyQuit();
328     fMessagesWindow = NULL;
329     if( fPreferencesWindow )
330         fPreferencesWindow->ReallyQuit();
331     fPreferencesWindow = NULL;
332         delete fFilePanel;
333         delete fSettings;
334 }
335
336 /*****************************************************************************
337  * InterfaceWindow::FrameResized
338  *****************************************************************************/
339 void
340 InterfaceWindow::FrameResized(float width, float height)
341 {
342     BRect r(Bounds());
343     fMenuBar->MoveTo(r.LeftTop());
344     fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
345     r.top += fMenuBar->Bounds().Height() + 1.0;
346     p_mediaControl->MoveTo(r.LeftTop());
347     p_mediaControl->ResizeTo(r.Width(), r.Height());
348 }
349
350 /*****************************************************************************
351  * InterfaceWindow::MessageReceived
352  *****************************************************************************/
353 void InterfaceWindow::MessageReceived( BMessage * p_message )
354 {
355     int playback_status;      // remember playback state
356     playback_status = p_wrapper->InputStatus();
357
358     switch( p_message->what )
359     {
360         case B_ABOUT_REQUESTED:
361         {
362             BAlert* alert = new BAlert( VOUT_TITLE,
363                                         "BeOS " VOUT_TITLE "\n\n<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         // strangly, someone is calling this function even after the object has been destructed!
795         // even more strangly, this workarround seems to work
796         if (fMessagesWindow)
797             fMessagesWindow->UpdateMessages();
798
799     fLastUpdateTime = system_time();
800 }
801
802 /*****************************************************************************
803  * InterfaceWindow::IsStopped
804  *****************************************************************************/
805 bool
806 InterfaceWindow::IsStopped() const
807 {
808     return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
809 }
810
811 /*****************************************************************************
812  * InterfaceWindow::_UpdatePlaylist
813  *****************************************************************************/
814 void
815 InterfaceWindow::_UpdatePlaylist()
816 {
817     if ( fPlaylistWindow->Lock() )
818     {
819         fPlaylistWindow->UpdatePlaylist( true );
820         fPlaylistWindow->Unlock();
821         p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
822     }
823 }
824
825 /*****************************************************************************
826  * InterfaceWindow::_SetMenusEnabled
827  *****************************************************************************/
828 void
829 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
830 {
831     if (!hasFile)
832     {
833         hasChapters = false;
834         hasTitles = false;
835     }
836     if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
837     {
838         if ( fNextChapterMI->IsEnabled() != hasChapters )
839              fNextChapterMI->SetEnabled( hasChapters );
840         if ( fPrevChapterMI->IsEnabled() != hasChapters )
841              fPrevChapterMI->SetEnabled( hasChapters );
842         if ( fChapterMenu->IsEnabled() != hasChapters )
843              fChapterMenu->SetEnabled( hasChapters );
844         if ( fNextTitleMI->IsEnabled() != hasTitles )
845              fNextTitleMI->SetEnabled( hasTitles );
846         if ( fPrevTitleMI->IsEnabled() != hasTitles )
847              fPrevTitleMI->SetEnabled( hasTitles );
848         if ( fTitleMenu->IsEnabled() != hasTitles )
849              fTitleMenu->SetEnabled( hasTitles );
850         if ( fAudioMenu->IsEnabled() != hasFile )
851              fAudioMenu->SetEnabled( hasFile );
852         if ( fNavigationMenu->IsEnabled() != hasFile )
853              fNavigationMenu->SetEnabled( hasFile );
854         if ( fLanguageMenu->IsEnabled() != hasFile )
855              fLanguageMenu->SetEnabled( hasFile );
856         if ( fSubtitlesMenu->IsEnabled() != hasFile )
857              fSubtitlesMenu->SetEnabled( hasFile );
858         if ( fSpeedMenu->IsEnabled() != hasFile )
859              fSpeedMenu->SetEnabled( hasFile );
860         // "goto menu" menu item
861         bool hasMenu = p_intf->p_sys->b_dvdmenus ? hasTitles : false;
862         if ( fGotoMenuMI->IsEnabled() != hasMenu )
863              fGotoMenuMI->SetEnabled( hasMenu );
864         Unlock();
865     }
866 }
867
868 /*****************************************************************************
869  * InterfaceWindow::_UpdateSpeedMenu
870  *****************************************************************************/
871 void
872 InterfaceWindow::_UpdateSpeedMenu( int rate )
873 {
874     if ( rate == DEFAULT_RATE )
875     {
876         if ( !fNormalMI->IsMarked() )
877             fNormalMI->SetMarked( true );
878     }
879     else if ( rate < DEFAULT_RATE )
880     {
881         if ( !fFasterMI->IsMarked() )
882             fFasterMI->SetMarked( true );
883     }
884     else
885     {
886         if ( !fSlowerMI->IsMarked() )
887             fSlowerMI->SetMarked( true );
888     }
889 }
890
891 /*****************************************************************************
892  * InterfaceWindow::_InputStreamChanged
893  *****************************************************************************/
894 void
895 InterfaceWindow::_InputStreamChanged()
896 {
897     // TODO: move more stuff from updateInterface() here!
898     snooze( 400000 );
899     p_wrapper->SetVolume( p_mediaControl->GetVolume() );
900 }
901
902 /*****************************************************************************
903  * InterfaceWindow::_ShowFilePanel
904  *****************************************************************************/
905 void
906 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
907 {
908         if( !fFilePanel )
909         {
910                 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
911                                                                          B_FILE_NODE | B_DIRECTORY_NODE );
912                 fFilePanel->SetTarget( this );
913         }
914         fFilePanel->Window()->SetTitle( windowTitle );
915         BMessage message( command );
916         fFilePanel->SetMessage( &message );
917         if ( !fFilePanel->IsShowing() )
918         {
919                 fFilePanel->Refresh();
920                 fFilePanel->Show();
921         }
922 }
923
924 // set_window_pos
925 void
926 set_window_pos( BWindow* window, BRect frame )
927 {
928         // sanity checks: make sure window is not too big/small
929         // and that it's not off-screen
930         float minWidth, maxWidth, minHeight, maxHeight;
931         window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
932
933         make_sure_frame_is_within_limits( frame,
934                                                                           minWidth, minHeight, maxWidth, maxHeight );
935         if ( make_sure_frame_is_on_screen( frame ) )
936         {
937                 window->MoveTo( frame.LeftTop() );
938                 window->ResizeTo( frame.Width(), frame.Height() );
939         }
940 }
941
942 // set_window_pos
943 void
944 launch_window( BWindow* window, bool showing )
945 {
946         if ( window->Lock() )
947         {
948                 if ( showing )
949                 {
950                         if ( window->IsHidden() )
951                                 window->Show();
952                 }
953                 else
954                 {
955                         if ( !window->IsHidden() )
956                                 window->Hide();
957                 }
958                 window->Unlock();
959         }
960 }
961
962 /*****************************************************************************
963  * InterfaceWindow::_RestoreSettings
964  *****************************************************************************/
965 void
966 InterfaceWindow::_RestoreSettings()
967 {
968         if ( USE_VLC_CONFIG_FILE )
969         {
970                 // main window size and position
971             int i_width = config_GetInt( p_intf, "beos-intf-width" ),
972                 i_height = config_GetInt( p_intf, "beos-intf-height" ),
973                 i_xpos = config_GetInt( p_intf, "beos-intf-xpos" ),
974                 i_ypos = config_GetInt( p_intf, "beos-intf-ypos" );
975             if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
976             {
977                 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
978                 set_window_pos( this, r );
979             }
980                 // playlist window size and position
981             i_width = config_GetInt( p_intf, "beos-playlist-width" ),
982             i_height = config_GetInt( p_intf, "beos-playlist-height" ),
983             i_xpos = config_GetInt( p_intf, "beos-playlist-xpos" ),
984             i_ypos = config_GetInt( p_intf, "beos-playlist-ypos" );
985             if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
986             {
987                 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
988                 set_window_pos( fPlaylistWindow, r );
989             }
990             // playlist showing
991             launch_window( fPlaylistWindow, config_GetInt( p_intf, "beos-playlist-show" ) );
992             // messages window size and position
993             i_width = config_GetInt( p_intf, "beos-messages-width" ),
994             i_height = config_GetInt( p_intf, "beos-messages-height" ),
995             i_xpos = config_GetInt( p_intf, "beos-messages-xpos" ),
996             i_ypos = config_GetInt( p_intf, "beos-messages-ypos" );
997             if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
998             {
999                 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
1000                 set_window_pos( fMessagesWindow, r );
1001             }
1002             // messages showing
1003             launch_window( fMessagesWindow, config_GetInt( p_intf, "beos-messages-show" ) );
1004
1005                 // messages window size and position
1006             i_width = config_GetInt( p_intf, "beos-settings-width" ),
1007             i_height = config_GetInt( p_intf, "beos-settings-height" ),
1008             i_xpos = config_GetInt( p_intf, "beos-settings-xpos" ),
1009             i_ypos = config_GetInt( p_intf, "beos-settings-ypos" );
1010             if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
1011             {
1012                 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
1013                 set_window_pos( fPreferencesWindow, r );
1014             }
1015             // settings showing
1016             launch_window( fPreferencesWindow, config_GetInt( p_intf, "beos-settings-show" ) );
1017         }
1018         else
1019         {
1020                 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1021                 {
1022                         BRect frame;
1023                         if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1024                                 set_window_pos( this, frame );
1025                         if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1026                                 set_window_pos( fPlaylistWindow, frame );
1027                         if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1028                                 set_window_pos( fMessagesWindow, frame );
1029                         if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1030                                 set_window_pos( fPreferencesWindow, frame );
1031                         
1032                         bool showing;
1033                         if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1034                                 launch_window( fPlaylistWindow, showing );
1035                         if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1036                                 launch_window( fMessagesWindow, showing );
1037                         if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1038                                 launch_window( fPreferencesWindow, showing );
1039         
1040                         uint32 displayMode;
1041                         if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1042                                 fPlaylistWindow->SetDisplayMode( displayMode );
1043                 }
1044         }
1045 }
1046
1047 /*****************************************************************************
1048  * InterfaceWindow::_StoreSettings
1049  *****************************************************************************/
1050 void
1051 InterfaceWindow::_StoreSettings()
1052 {
1053         if ( USE_VLC_CONFIG_FILE )
1054         {
1055             // save interface settings in vlc config file
1056             BRect frame = Frame();
1057             config_PutInt( p_intf, "beos-intf-width", (int)frame.Width() );
1058             config_PutInt( p_intf, "beos-intf-height", (int)frame.Height() );
1059             config_PutInt( p_intf, "beos-intf-xpos", (int)frame.left );
1060             config_PutInt( p_intf, "beos-intf-ypos", (int)frame.top );
1061             if( fPlaylistWindow->Lock() )
1062             {
1063                 frame = fPlaylistWindow->Frame();
1064                 config_PutInt( p_intf, "beos-playlist-width", (int)frame.Width() );
1065                 config_PutInt( p_intf, "beos-playlist-height", (int)frame.Height() );
1066                 config_PutInt( p_intf, "beos-playlist-xpos", (int)frame.left );
1067                 config_PutInt( p_intf, "beos-playlist-ypos", (int)frame.top );
1068                 config_PutInt( p_intf, "beos-playlist-show", !fPlaylistWindow->IsHidden() );
1069                 fPlaylistWindow->Unlock();
1070             }
1071             if( fMessagesWindow->Lock() )
1072             {
1073                 frame = fMessagesWindow->Frame();
1074                 config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
1075                 config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
1076                 config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
1077                 config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
1078                 config_PutInt( p_intf, "beos-messages-show", !fMessagesWindow->IsHidden() );
1079                 fMessagesWindow->Unlock();
1080             }
1081             if( fPreferencesWindow->Lock() )
1082             {
1083                 frame = fPreferencesWindow->Frame();
1084                 config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
1085                 config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
1086                 config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
1087                 config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
1088                 config_PutInt( p_intf, "beos-messages-show", !fPreferencesWindow->IsHidden() );
1089                 fPreferencesWindow->Unlock();
1090             }
1091         }
1092     else
1093     {
1094                 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1095                         fSettings->AddRect( "main frame", Frame() );
1096                 if ( fPlaylistWindow->Lock() )
1097                 {
1098                         if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1099                                 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1100                         if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1101                                 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1102                         fPlaylistWindow->Unlock();
1103                 }
1104                 if ( fMessagesWindow->Lock() )
1105                 {
1106                         if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1107                                 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1108                         if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1109                                 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1110                         fMessagesWindow->Unlock();
1111                 }
1112                 if ( fPreferencesWindow->Lock() )
1113                 {
1114                         if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1115                                 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1116                         if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1117                                 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1118                         fPreferencesWindow->Unlock();
1119                 }
1120                 uint32 displayMode = fPlaylistWindow->DisplayMode();
1121                 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1122                         fSettings->AddInt32( "playlist display mode", displayMode );
1123         
1124                 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1125     }
1126
1127         // save VLC internal settings
1128         config_SaveConfigFile( p_intf, "beos" );
1129         config_SaveConfigFile( p_intf, "main" );
1130         config_SaveConfigFile( p_intf, "adjust" );
1131         config_SaveConfigFile( p_intf, "ffmpeg" );
1132 }
1133
1134
1135
1136
1137
1138
1139 /*****************************************************************************
1140  * CDMenu::CDMenu
1141  *****************************************************************************/
1142 CDMenu::CDMenu(const char *name)
1143       : BMenu(name)
1144 {
1145 }
1146
1147 /*****************************************************************************
1148  * CDMenu::~CDMenu
1149  *****************************************************************************/
1150 CDMenu::~CDMenu()
1151 {
1152 }
1153
1154 /*****************************************************************************
1155  * CDMenu::AttachedToWindow
1156  *****************************************************************************/
1157 void CDMenu::AttachedToWindow(void)
1158 {
1159     // remove all items
1160     while ( BMenuItem* item = RemoveItem( 0L ) )
1161         delete item;
1162     GetCD( "/dev/disk" );
1163     BMenu::AttachedToWindow();
1164 }
1165
1166 /*****************************************************************************
1167  * CDMenu::GetCD
1168  *****************************************************************************/
1169 int CDMenu::GetCD( const char *directory )
1170 {
1171         BVolumeRoster volRoster;
1172         BVolume vol;
1173         BDirectory dir;
1174         status_t status = volRoster.GetNextVolume( &vol );
1175         while ( status ==  B_NO_ERROR )
1176         {
1177                 BString deviceName;
1178                 BString volumeName;
1179                 bool isCDROM;
1180                 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1181                          && isCDROM )
1182                 {
1183                         BMessage* msg = new BMessage( OPEN_DVD );
1184                         msg->AddString( "device", deviceName.String() );
1185                         BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1186                         AddItem( item );
1187                 }
1188                 vol.Unset();
1189                 status = volRoster.GetNextVolume( &vol );
1190         }
1191 }
1192
1193 /*****************************************************************************
1194  * LanguageMenu::LanguageMenu
1195  *****************************************************************************/
1196 LanguageMenu::LanguageMenu( const char *name, int menu_kind, 
1197                             VlcWrapper *p_wrapper )
1198     :BMenu(name)
1199 {
1200     kind = menu_kind;
1201     this->p_wrapper = p_wrapper;
1202 }
1203
1204 /*****************************************************************************
1205  * LanguageMenu::~LanguageMenu
1206  *****************************************************************************/
1207 LanguageMenu::~LanguageMenu()
1208 {
1209 }
1210
1211 /*****************************************************************************
1212  * LanguageMenu::AttachedToWindow
1213  *****************************************************************************/
1214 void LanguageMenu::AttachedToWindow()
1215 {
1216     // remove all items
1217     while ( BMenuItem* item = RemoveItem( 0L ) )
1218         delete item;
1219
1220     SetRadioMode( true );
1221         if ( BList *list = p_wrapper->GetChannels( kind ) )
1222         {
1223             for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1224                 AddItem( item );
1225             
1226             if ( list->CountItems() > 1 )
1227                 AddItem( new BSeparatorItem(), 1 );
1228         }
1229     BMenu::AttachedToWindow();
1230 }
1231
1232 /*****************************************************************************
1233  * TitleMenu::TitleMenu
1234  *****************************************************************************/
1235 TitleMenu::TitleMenu( const char *name, intf_thread_t  *p_interface )
1236     : BMenu(name),
1237     p_intf( p_interface )
1238 {
1239 }
1240
1241 /*****************************************************************************
1242  * TitleMenu::~TitleMenu
1243  *****************************************************************************/
1244 TitleMenu::~TitleMenu()
1245 {
1246 }
1247
1248 /*****************************************************************************
1249  * TitleMenu::AttachedToWindow
1250  *****************************************************************************/
1251 void TitleMenu::AttachedToWindow()
1252 {
1253     while( BMenuItem* item = RemoveItem( 0L ) )
1254         delete item;
1255
1256     if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1257         {    
1258                 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1259                 AddItem( item );
1260         }
1261     BMenu::AttachedToWindow();
1262 }
1263
1264
1265 /*****************************************************************************
1266  * ChapterMenu::ChapterMenu
1267  *****************************************************************************/
1268 ChapterMenu::ChapterMenu( const char *name, intf_thread_t  *p_interface )
1269     : BMenu(name),
1270     p_intf( p_interface )
1271 {
1272 }
1273
1274 /*****************************************************************************
1275  * ChapterMenu::~ChapterMenu
1276  *****************************************************************************/
1277 ChapterMenu::~ChapterMenu()
1278 {
1279 }
1280
1281 /*****************************************************************************
1282  * ChapterMenu::AttachedToWindow
1283  *****************************************************************************/
1284 void ChapterMenu::AttachedToWindow()
1285 {
1286     while( BMenuItem* item = RemoveItem( 0L ) )
1287         delete item;
1288
1289     if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1290         {    
1291             for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1292                 AddItem( item );
1293         }
1294     
1295     BMenu::AttachedToWindow();
1296 }
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306 /*****************************************************************************
1307  * load_settings
1308  *****************************************************************************/
1309 status_t
1310 load_settings( BMessage* message, const char* fileName, const char* folder )
1311 {
1312         status_t ret = B_BAD_VALUE;
1313         if ( message )
1314         {
1315                 BPath path;
1316                 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1317                 {
1318                         // passing folder is optional
1319                         if ( folder )
1320                                 ret = path.Append( folder );
1321                         if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1322                         {
1323                                 BFile file( path.Path(), B_READ_ONLY );
1324                                 if ( ( ret = file.InitCheck() ) == B_OK )
1325                                 {
1326                                         ret = message->Unflatten( &file );
1327                                         file.Unset();
1328                                 }
1329                         }
1330                 }
1331         }
1332         return ret;
1333 }
1334
1335 /*****************************************************************************
1336  * save_settings
1337  *****************************************************************************/
1338 status_t
1339 save_settings( BMessage* message, const char* fileName, const char* folder )
1340 {
1341         status_t ret = B_BAD_VALUE;
1342         if ( message )
1343         {
1344                 BPath path;
1345                 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1346                 {
1347                         // passing folder is optional
1348                         if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1349                                 ret = create_directory( path.Path(), 0777 );
1350                         if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1351                         {
1352                                 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1353                                 if ( ( ret = file.InitCheck() ) == B_OK )
1354                                 {
1355                                         ret = message->Flatten( &file );
1356                                         file.Unset();
1357                                 }
1358                         }
1359                 }
1360         }
1361         return ret;
1362 }