1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.19 2003/01/17 18:19:43 titer Exp $
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>
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.
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.
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 *****************************************************************************/
29 #include <kernel/OS.h>
30 #include <InterfaceKit.h>
32 #include <StorageKit.h>
33 #include <SupportKit.h>
36 #include <scsiprobe_driver.h>
45 /* BeOS interface headers */
46 #include "VlcWrapper.h"
48 #include "MediaControlView.h"
49 #include "PlayListWindow.h"
50 #include "PreferencesWindow.h"
51 #include "InterfaceWindow.h"
53 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
56 /*****************************************************************************
58 *****************************************************************************/
60 InterfaceWindow::InterfaceWindow( BRect frame, const char *name,
61 intf_thread_t *p_interface )
62 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
63 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
64 p_intf( p_interface ),
66 fSubtitlesPanel( NULL ),
67 fLastUpdateTime( system_time() ),
68 fSettings( new BMessage( 'sett' ) )
71 p_wrapper = p_intf->p_sys->p_wrapper;
72 p_intf->p_sys->b_dvdold = false;
74 fPlaylistIsEmpty = ( p_wrapper->PlaylistSize() < 0 );
76 fPlaylistWindow = new PlayListWindow( BRect( 100.0, 100.0, 400.0, 350.0 ),
80 BScreen *p_screen = new BScreen();
81 BRect screen_rect = p_screen->Frame();
84 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
85 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
86 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
87 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
88 fPreferencesWindow = new PreferencesWindow( window_rect,
93 SetName( "interface" );
94 SetTitle( VOUT_TITLE );
96 // the media control view
97 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
99 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
100 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
103 p_mediaControl->GetPreferredSize( &width, &height );
105 // set up the main menu
106 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
107 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
109 // make menu bar resize to correct height
110 float menuWidth, menuHeight;
111 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
112 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
113 // take care of proper size for ourself
114 height += fMenuBar->Bounds().Height();
115 ResizeTo( width, height );
117 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
118 AddChild( fMenuBar );
119 AddChild( p_mediaControl );
122 BMenu* fileMenu = new BMenu( "File" );
123 fMenuBar->AddItem( fileMenu );
124 fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
125 new BMessage( OPEN_FILE ), 'O') );
127 fileMenu->AddItem( new CDMenu( "Open Disc" ) );
129 fileMenu->AddItem( new BMenuItem( "Load a subtitle file" B_UTF8_ELLIPSIS,
130 new BMessage( LOAD_SUBFILE ) ) );
132 fileMenu->AddSeparatorItem();
133 fileMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
134 new BMessage( OPEN_PLAYLIST ), 'P') );
136 fileMenu->AddSeparatorItem();
137 BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
138 new BMessage( B_ABOUT_REQUESTED ), 'A');
139 item->SetTarget( be_app );
140 fileMenu->AddItem( item );
141 fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
143 fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_wrapper);
144 fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_wrapper);
146 /* Add the Audio menu */
147 fAudioMenu = new BMenu( "Audio" );
148 fMenuBar->AddItem ( fAudioMenu );
149 fAudioMenu->AddItem( fLanguageMenu );
150 fAudioMenu->AddItem( fSubtitlesMenu );
152 fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
153 fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
154 fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
155 fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
157 /* Add the Navigation menu */
158 fNavigationMenu = new BMenu( "Navigation" );
159 fMenuBar->AddItem( fNavigationMenu );
160 fNavigationMenu->AddItem( fPrevTitleMI );
161 fNavigationMenu->AddItem( fNextTitleMI );
162 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
163 fNavigationMenu->AddSeparatorItem();
164 fNavigationMenu->AddItem( fPrevChapterMI );
165 fNavigationMenu->AddItem( fNextChapterMI );
166 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
168 /* Add the Speed menu */
169 fSpeedMenu = new BMenu( "Speed" );
170 fSpeedMenu->SetRadioMode( true );
171 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
172 fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
173 fNormalMI->SetMarked(true); // default to normal speed
174 fSpeedMenu->AddItem( fNormalMI );
175 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
176 fSpeedMenu->SetTargetForItems( this );
177 fMenuBar->AddItem( fSpeedMenu );
179 /* Add the Settings menu */
180 fSettingsMenu = new BMenu( "Settings" );
181 fSettingsMenu->AddItem( fPreferencesMI =
182 new BMenuItem( "Preferences", new BMessage( OPEN_PREFERENCES ) ) );
183 fMenuBar->AddItem( fSettingsMenu );
185 // prepare fow showing
186 _SetMenusEnabled( false );
187 p_mediaControl->SetEnabled( false );
194 InterfaceWindow::~InterfaceWindow()
197 fPlaylistWindow->ReallyQuit();
201 /*****************************************************************************
202 * InterfaceWindow::FrameResized
203 *****************************************************************************/
205 InterfaceWindow::FrameResized(float width, float height)
208 fMenuBar->MoveTo(r.LeftTop());
209 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
210 r.top += fMenuBar->Bounds().Height() + 1.0;
211 p_mediaControl->MoveTo(r.LeftTop());
212 p_mediaControl->ResizeTo(r.Width(), r.Height());
215 /*****************************************************************************
216 * InterfaceWindow::MessageReceived
217 *****************************************************************************/
218 void InterfaceWindow::MessageReceived( BMessage * p_message )
220 int playback_status; // remember playback state
221 playback_status = p_wrapper->InputStatus();
223 switch( p_message->what )
225 case B_ABOUT_REQUESTED:
227 BAlert* alert = new BAlert( VOUT_TITLE,
228 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
241 fFilePanel = new BFilePanel();
242 fFilePanel->SetTarget( this );
247 if (fPlaylistWindow->Lock())
249 if (fPlaylistWindow->IsHidden())
250 fPlaylistWindow->Show();
252 fPlaylistWindow->Activate();
253 fPlaylistWindow->Unlock();
258 const char *psz_device;
259 BString type( "dvd" );
260 if( p_message->FindString( "device", &psz_device ) == B_OK )
262 BString device( psz_device );
263 p_wrapper->openDisc( type, device, 0, 0 );
270 if( fSubtitlesPanel )
272 fSubtitlesPanel->Show();
275 fSubtitlesPanel = new BFilePanel();
276 fSubtitlesPanel->SetTarget( this );
277 fSubtitlesPanel->SetMessage( new BMessage( SUBFILE_RECEIVED ) );
278 fSubtitlesPanel->Show();
281 case SUBFILE_RECEIVED:
284 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
287 if ( path.InitCheck() == B_OK )
288 p_wrapper->LoadSubFile( (char*)path.Path() );
294 // this currently stops playback not nicely
295 if (playback_status > UNDEF_S)
298 p_wrapper->PlaylistStop();
299 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
304 /* starts playing in normal mode */
307 /* toggle between pause and play */
308 if (playback_status > UNDEF_S)
310 /* pause if currently playing */
311 if ( playback_status == PLAYING_S )
313 p_wrapper->PlaylistPause();
317 p_wrapper->PlaylistPlay();
322 /* Play a new file */
323 p_wrapper->PlaylistPlay();
328 /* cycle the fast playback modes */
329 if (playback_status > UNDEF_S)
331 p_wrapper->InputFaster();
336 /* cycle the slow playback modes */
337 if (playback_status > UNDEF_S)
339 p_wrapper->InputSlower();
344 /* restore speed to normal if already playing */
345 if (playback_status > UNDEF_S)
347 p_wrapper->PlaylistPlay();
352 /* handled by semaphores */
354 // volume related messages
356 /* adjust the volume */
357 if (playback_status > UNDEF_S)
359 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
360 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
366 if( p_wrapper->IsMuted() )
367 p_wrapper->VolumeRestore();
369 p_wrapper->VolumeMute();
370 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
374 if ( playback_status > UNDEF_S )
377 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
379 p_wrapper->ToggleLanguage( channel );
384 case SELECT_SUBTITLE:
385 if ( playback_status > UNDEF_S )
388 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
389 p_wrapper->ToggleSubtitle( subtitle );
393 // specific navigation messages
396 p_wrapper->PrevTitle();
401 p_wrapper->NextTitle();
405 if ( playback_status > UNDEF_S )
408 if ( p_message->FindInt32( "index", &index ) == B_OK )
409 p_wrapper->toggleTitle( index );
414 p_wrapper->PrevChapter();
419 p_wrapper->NextChapter();
423 if ( playback_status > UNDEF_S )
426 if ( p_message->FindInt32( "index", &index ) == B_OK )
427 p_wrapper->toggleChapter( index );
431 p_wrapper->PlaylistPrev();
434 p_wrapper->PlaylistNext();
436 // general next/prev functionality (skips to whatever makes most sense)
438 p_wrapper->navigatePrev();
441 p_wrapper->navigateNext();
443 // drag'n'drop and system messages
444 case B_REFS_RECEIVED:
447 /* file(s) opened by the File menu -> append to the playlist;
448 * file(s) opened by drag & drop -> replace playlist;
449 * file(s) opened by 'shift' + drag & drop -> append */
450 bool replace = false;
451 if ( p_message->WasDropped() )
452 replace = !( modifiers() & B_SHIFT_KEY );
454 // build list of files to be played from message contents
457 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
460 if ( path.InitCheck() == B_OK )
463 // has the user dropped a dvd disk icon?
464 BDirectory dir( &ref );
465 if ( dir.InitCheck() == B_OK && dir.IsRootDirectory() )
467 BVolumeRoster volRoster;
469 BDirectory volumeRoot;
470 status_t status = volRoster.GetNextVolume( &vol );
471 while( status == B_NO_ERROR )
473 if( vol.GetRootDirectory( &volumeRoot ) == B_OK
474 && dir == volumeRoot )
478 bool isCDROM = false;
479 bool success = false;
482 char name[B_FILE_NAME_LENGTH];
483 if ( vol.GetName( name ) >= B_OK ) // disk is currently mounted
486 dev_t dev = vol.Device();
488 if ( fs_stat_dev( dev, &info ) == B_OK )
491 deviceName = info.device_name;
492 if ( vol.IsReadOnly() )
494 int i_dev = open( info.device_name, O_RDONLY );
498 if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
499 isCDROM = ( g.device_type == B_CD );
506 if( success && isCDROM )
508 BMessage msg( OPEN_DVD );
509 msg.AddString( "device", deviceName.String() );
518 status = volRoster.GetNextVolume( &vol );
524 files.AddItem( new BString( (char*)path.Path() ) );
528 // give the list to VLC
529 p_wrapper->openFiles(&files, replace);
534 case OPEN_PREFERENCES:
535 if( fPreferencesWindow->Lock() )
537 if (fPreferencesWindow->IsHidden())
538 fPreferencesWindow->Show();
540 fPreferencesWindow->Activate();
541 fPreferencesWindow->Unlock();
546 BWindow::MessageReceived( p_message );
552 /*****************************************************************************
553 * InterfaceWindow::QuitRequested
554 *****************************************************************************/
555 bool InterfaceWindow::QuitRequested()
557 p_wrapper->PlaylistStop();
558 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
567 /*****************************************************************************
568 * InterfaceWindow::updateInterface
569 *****************************************************************************/
570 void InterfaceWindow::updateInterface()
572 if( p_wrapper->HasInput() )
574 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
576 p_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
580 // p_mediaControl->SetEnabled( true );
581 bool hasTitles = p_wrapper->HasTitles();
582 bool hasChapters = p_wrapper->HasChapters();
583 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
584 p_wrapper->InputRate() );
585 p_mediaControl->SetProgress( p_wrapper->getTimeAsFloat() );
586 _SetMenusEnabled( true, hasChapters, hasTitles );
588 _UpdateSpeedMenu( p_wrapper->InputRate() );
590 // enable/disable skip buttons
593 p_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
594 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
596 if ( p_wrapper->HasAudio() )
598 p_mediaControl->SetAudioEnabled( true );
599 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
601 p_mediaControl->SetAudioEnabled( false );
605 // update playlist as well
606 if ( fPlaylistWindow->Lock() )
608 fPlaylistWindow->UpdatePlaylist();
609 fPlaylistWindow->Unlock();
614 _SetMenusEnabled( false );
615 // p_mediaControl->SetEnabled( false );
618 /* always force the user-specified volume */
619 /* FIXME : I'm quite sure there is a cleaner way to do this */
620 if( p_wrapper->GetVolume() != p_mediaControl->GetVolume() )
622 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
625 fLastUpdateTime = system_time();
628 /*****************************************************************************
629 * InterfaceWindow::IsStopped
630 *****************************************************************************/
632 InterfaceWindow::IsStopped() const
634 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
637 /*****************************************************************************
638 * InterfaceWindow::_UpdatePlaylist
639 *****************************************************************************/
641 InterfaceWindow::_UpdatePlaylist()
643 if ( fPlaylistWindow->Lock() )
645 fPlaylistWindow->UpdatePlaylist( true );
646 fPlaylistWindow->Unlock();
647 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
651 /*****************************************************************************
652 * InterfaceWindow::_SetMenusEnabled
653 *****************************************************************************/
655 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
664 if (fNextChapterMI->IsEnabled() != hasChapters)
665 fNextChapterMI->SetEnabled(hasChapters);
666 if (fPrevChapterMI->IsEnabled() != hasChapters)
667 fPrevChapterMI->SetEnabled(hasChapters);
668 if (fChapterMenu->IsEnabled() != hasChapters)
669 fChapterMenu->SetEnabled(hasChapters);
670 if (fNextTitleMI->IsEnabled() != hasTitles)
671 fNextTitleMI->SetEnabled(hasTitles);
672 if (fPrevTitleMI->IsEnabled() != hasTitles)
673 fPrevTitleMI->SetEnabled(hasTitles);
674 if (fTitleMenu->IsEnabled() != hasTitles)
675 fTitleMenu->SetEnabled(hasTitles);
676 if (fAudioMenu->IsEnabled() != hasFile)
677 fAudioMenu->SetEnabled(hasFile);
678 if (fNavigationMenu->IsEnabled() != hasFile)
679 fNavigationMenu->SetEnabled(hasFile);
680 if (fLanguageMenu->IsEnabled() != hasFile)
681 fLanguageMenu->SetEnabled(hasFile);
682 if (fSubtitlesMenu->IsEnabled() != hasFile)
683 fSubtitlesMenu->SetEnabled(hasFile);
684 if (fSpeedMenu->IsEnabled() != hasFile)
685 fSpeedMenu->SetEnabled(hasFile);
690 /*****************************************************************************
691 * InterfaceWindow::_UpdateSpeedMenu
692 *****************************************************************************/
694 InterfaceWindow::_UpdateSpeedMenu( int rate )
696 if ( rate == DEFAULT_RATE )
698 if ( !fNormalMI->IsMarked() )
699 fNormalMI->SetMarked( true );
701 else if ( rate < DEFAULT_RATE )
703 if ( !fFasterMI->IsMarked() )
704 fFasterMI->SetMarked( true );
708 if ( !fSlowerMI->IsMarked() )
709 fSlowerMI->SetMarked( true );
713 /*****************************************************************************
714 * InterfaceWindow::_InputStreamChanged
715 *****************************************************************************/
717 InterfaceWindow::_InputStreamChanged()
719 //printf("InterfaceWindow::_InputStreamChanged()\n");
720 // TODO: move more stuff from updateInterface() here!
722 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
725 /*****************************************************************************
726 * InterfaceWindow::_LoadSettings
727 *****************************************************************************/
729 InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
731 status_t ret = B_BAD_VALUE;
735 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
737 // passing folder is optional
739 ret = path.Append( folder );
740 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
742 BFile file( path.Path(), B_READ_ONLY );
743 if ( ( ret = file.InitCheck() ) == B_OK )
745 ret = message->Unflatten( &file );
754 /*****************************************************************************
755 * InterfaceWindow::_SaveSettings
756 *****************************************************************************/
758 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
760 status_t ret = B_BAD_VALUE;
764 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
766 // passing folder is optional
767 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
768 ret = create_directory( path.Path(), 0777 );
769 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
771 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
772 if ( ( ret = file.InitCheck() ) == B_OK )
774 ret = message->Flatten( &file );
783 /*****************************************************************************
784 * InterfaceWindow::_RestoreSettings
785 *****************************************************************************/
787 make_sure_frame_is_on_screen( BRect& frame )
789 BScreen screen( B_MAIN_SCREEN_ID );
790 if (frame.IsValid() && screen.IsValid()) {
791 if (!screen.Frame().Contains(frame)) {
792 // make sure frame fits in the screen
793 if (frame.Width() > screen.Frame().Width())
794 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
795 if (frame.Height() > screen.Frame().Height())
796 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
797 // frame is now at the most the size of the screen
798 if (frame.right > screen.Frame().right)
799 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
800 if (frame.bottom > screen.Frame().bottom)
801 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
802 if (frame.left < screen.Frame().left)
803 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
804 if (frame.top < screen.Frame().top)
805 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
813 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
814 float maxWidth, float maxHeight )
816 if ( frame.Width() < minWidth )
817 frame.right = frame.left + minWidth;
818 if ( frame.Height() < minHeight )
819 frame.bottom = frame.top + minHeight;
820 if ( frame.Width() > maxWidth )
821 frame.right = frame.left + maxWidth;
822 if ( frame.Height() > maxHeight )
823 frame.bottom = frame.top + maxHeight;
826 /*****************************************************************************
827 * InterfaceWindow::_RestoreSettings
828 *****************************************************************************/
830 InterfaceWindow::_RestoreSettings()
832 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
835 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
837 // sanity checks: make sure window is not too big/small
838 // and that it's not off-screen
839 float minWidth, maxWidth, minHeight, maxHeight;
840 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
842 make_sure_frame_is_within_limits( mainFrame,
843 minWidth, minHeight, maxWidth, maxHeight );
844 make_sure_frame_is_on_screen( mainFrame );
847 MoveTo( mainFrame.LeftTop() );
848 ResizeTo( mainFrame.Width(), mainFrame.Height() );
850 if ( fPlaylistWindow->Lock() )
853 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
855 // sanity checks: make sure window is not too big/small
856 // and that it's not off-screen
857 float minWidth, maxWidth, minHeight, maxHeight;
858 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
860 make_sure_frame_is_within_limits( playlistFrame,
861 minWidth, minHeight, maxWidth, maxHeight );
862 make_sure_frame_is_on_screen( playlistFrame );
864 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
865 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
869 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
873 if ( fPlaylistWindow->IsHidden() )
874 fPlaylistWindow->Show();
878 if ( !fPlaylistWindow->IsHidden() )
879 fPlaylistWindow->Hide();
883 fPlaylistWindow->Unlock();
888 /*****************************************************************************
889 * InterfaceWindow::_StoreSettings
890 *****************************************************************************/
892 InterfaceWindow::_StoreSettings()
894 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
895 fSettings->AddRect( "main frame", Frame() );
896 if ( fPlaylistWindow->Lock() )
898 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
899 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
900 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
901 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
902 fPlaylistWindow->Unlock();
904 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
907 /*****************************************************************************
909 *****************************************************************************/
910 CDMenu::CDMenu(const char *name)
915 /*****************************************************************************
917 *****************************************************************************/
922 /*****************************************************************************
923 * CDMenu::AttachedToWindow
924 *****************************************************************************/
925 void CDMenu::AttachedToWindow(void)
928 while (BMenuItem* item = RemoveItem(0L))
931 BMenu::AttachedToWindow();
934 /*****************************************************************************
936 *****************************************************************************/
937 int CDMenu::GetCD( const char *directory )
939 BVolumeRoster *volRoster;
944 char name[B_FILE_NAME_LENGTH];
948 volRoster = new BVolumeRoster();
950 dir = new BDirectory();
951 status = volRoster->GetNextVolume(vol);
952 status = vol->GetRootDirectory(dir);
953 while (status == B_NO_ERROR)
955 mounted = vol->GetName(name);
956 if ((mounted == B_OK) && /* Disk is currently Mounted */
957 (vol->IsReadOnly()) ) /* Disk is read-only */
960 fs_stat_dev(dev, &info);
964 i_dev = open( info.device_name, O_RDONLY );
968 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
970 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
973 msg = new BMessage( OPEN_DVD );
974 msg->AddString( "device", info.device_name );
975 BMenuItem *menu_item;
976 menu_item = new BMenuItem( name, msg );
977 AddItem( menu_item );
984 status = volRoster->GetNextVolume(vol);
989 /*****************************************************************************
990 * LanguageMenu::LanguageMenu
991 *****************************************************************************/
992 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
993 VlcWrapper *p_wrapper )
997 this->p_wrapper = p_wrapper;
1000 /*****************************************************************************
1001 * LanguageMenu::~LanguageMenu
1002 *****************************************************************************/
1003 LanguageMenu::~LanguageMenu()
1007 /*****************************************************************************
1008 * LanguageMenu::AttachedToWindow
1009 *****************************************************************************/
1010 void LanguageMenu::AttachedToWindow()
1013 while ( BMenuItem* item = RemoveItem( 0L ) )
1016 SetRadioMode( true );
1018 BMenu::AttachedToWindow();
1021 /*****************************************************************************
1022 * LanguageMenu::_GetChannels
1023 *****************************************************************************/
1024 void LanguageMenu::_GetChannels()
1029 if( ( list = p_wrapper->InputGetChannels( kind ) ) == NULL )
1032 for( int i = 0; i < list->CountItems(); i++ )
1034 item = (BMenuItem*)list->ItemAt( i );
1038 if( list->CountItems() > 1 )
1039 AddItem( new BSeparatorItem(), 1 );
1043 /*****************************************************************************
1044 * TitleMenu::TitleMenu
1045 *****************************************************************************/
1046 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1048 p_intf( p_interface )
1052 /*****************************************************************************
1053 * TitleMenu::~TitleMenu
1054 *****************************************************************************/
1055 TitleMenu::~TitleMenu()
1059 /*****************************************************************************
1060 * TitleMenu::AttachedToWindow
1061 *****************************************************************************/
1062 void TitleMenu::AttachedToWindow()
1064 // make title menu empty
1065 while ( BMenuItem* item = RemoveItem( 0L ) )
1069 input_thread_t* input = p_intf->p_sys->p_input;
1072 // lock stream access
1073 vlc_mutex_lock( &input->stream.stream_lock );
1074 // populate menu according to current stream
1075 int32 numTitles = input->stream.i_area_nb;
1076 if ( numTitles > 1 )
1078 // disallow title 0!
1079 for ( int32 i = 1; i < numTitles; i++ )
1081 BMessage* message = new BMessage( TOGGLE_TITLE );
1082 message->AddInt32( "index", i );
1083 BString helper( "" );
1085 BMenuItem* item = new BMenuItem( helper.String(), message );
1086 item->SetMarked( input->stream.p_selected_area->i_id == i );
1090 // done messing with stream
1091 vlc_mutex_unlock( &input->stream.stream_lock );
1094 BMenu::AttachedToWindow();
1098 /*****************************************************************************
1099 * ChapterMenu::ChapterMenu
1100 *****************************************************************************/
1101 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1103 p_intf( p_interface )
1107 /*****************************************************************************
1108 * ChapterMenu::~ChapterMenu
1109 *****************************************************************************/
1110 ChapterMenu::~ChapterMenu()
1114 /*****************************************************************************
1115 * ChapterMenu::AttachedToWindow
1116 *****************************************************************************/
1117 void ChapterMenu::AttachedToWindow()
1119 // make title menu empty
1120 while ( BMenuItem* item = RemoveItem( 0L ) )
1124 input_thread_t* input = p_intf->p_sys->p_input;
1127 // lock stream access
1128 vlc_mutex_lock( &input->stream.stream_lock );
1129 // populate menu according to current stream
1130 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1131 if ( numChapters > 1 )
1133 for ( int32 i = 0; i < numChapters; i++ )
1135 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1136 message->AddInt32( "index", i );
1137 BString helper( "" );
1139 BMenuItem* item = new BMenuItem( helper.String(), message );
1140 item->SetMarked( input->stream.p_selected_area->i_part == i );
1144 // done messing with stream
1145 vlc_mutex_unlock( &input->stream.stream_lock );
1147 BMenu::AttachedToWindow();