1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.18 2003/01/16 15:26:23 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;
73 fPlaylistIsEmpty = ( p_wrapper->PlaylistSize() < 0 );
75 fPlaylistWindow = new PlayListWindow( BRect( 100.0, 100.0, 400.0, 350.0 ),
79 BScreen *p_screen = new BScreen();
80 BRect screen_rect = p_screen->Frame();
83 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
84 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
85 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
86 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
87 fPreferencesWindow = new PreferencesWindow( window_rect,
92 SetName( "interface" );
93 SetTitle( VOUT_TITLE );
95 // the media control view
96 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
98 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
99 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
102 p_mediaControl->GetPreferredSize( &width, &height );
104 // set up the main menu
105 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
106 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
108 // make menu bar resize to correct height
109 float menuWidth, menuHeight;
110 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
111 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
112 // take care of proper size for ourself
113 height += fMenuBar->Bounds().Height();
114 ResizeTo( width, height );
116 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
117 AddChild( fMenuBar );
118 AddChild( p_mediaControl );
121 BMenu* fileMenu = new BMenu( "File" );
122 fMenuBar->AddItem( fileMenu );
123 fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
124 new BMessage( OPEN_FILE ), 'O') );
126 fileMenu->AddItem( new CDMenu( "Open Disc" ) );
128 fileMenu->AddItem( new BMenuItem( "Load a subtitle file" B_UTF8_ELLIPSIS,
129 new BMessage( LOAD_SUBFILE ) ) );
131 fileMenu->AddSeparatorItem();
132 fileMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
133 new BMessage( OPEN_PLAYLIST ), 'P') );
135 fileMenu->AddSeparatorItem();
136 BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
137 new BMessage( B_ABOUT_REQUESTED ), 'A');
138 item->SetTarget( be_app );
139 fileMenu->AddItem( item );
140 fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
142 fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_wrapper);
143 fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_wrapper);
145 /* Add the Audio menu */
146 fAudioMenu = new BMenu( "Audio" );
147 fMenuBar->AddItem ( fAudioMenu );
148 fAudioMenu->AddItem( fLanguageMenu );
149 fAudioMenu->AddItem( fSubtitlesMenu );
151 fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
152 fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
153 fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
154 fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
156 /* Add the Navigation menu */
157 fNavigationMenu = new BMenu( "Navigation" );
158 fMenuBar->AddItem( fNavigationMenu );
159 fNavigationMenu->AddItem( fPrevTitleMI );
160 fNavigationMenu->AddItem( fNextTitleMI );
161 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
162 fNavigationMenu->AddSeparatorItem();
163 fNavigationMenu->AddItem( fPrevChapterMI );
164 fNavigationMenu->AddItem( fNextChapterMI );
165 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
167 /* Add the Speed menu */
168 fSpeedMenu = new BMenu( "Speed" );
169 fSpeedMenu->SetRadioMode( true );
170 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
171 fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
172 fNormalMI->SetMarked(true); // default to normal speed
173 fSpeedMenu->AddItem( fNormalMI );
174 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
175 fSpeedMenu->SetTargetForItems( this );
176 fMenuBar->AddItem( fSpeedMenu );
178 /* Add the Settings menu */
179 fSettingsMenu = new BMenu( "Settings" );
180 fSettingsMenu->AddItem( fPreferencesMI =
181 new BMenuItem( "Preferences", new BMessage( OPEN_PREFERENCES ) ) );
182 fMenuBar->AddItem( fSettingsMenu );
184 // prepare fow showing
185 _SetMenusEnabled( false );
186 p_mediaControl->SetEnabled( false );
193 InterfaceWindow::~InterfaceWindow()
196 fPlaylistWindow->ReallyQuit();
200 /*****************************************************************************
201 * InterfaceWindow::FrameResized
202 *****************************************************************************/
204 InterfaceWindow::FrameResized(float width, float height)
207 fMenuBar->MoveTo(r.LeftTop());
208 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
209 r.top += fMenuBar->Bounds().Height() + 1.0;
210 p_mediaControl->MoveTo(r.LeftTop());
211 p_mediaControl->ResizeTo(r.Width(), r.Height());
214 /*****************************************************************************
215 * InterfaceWindow::MessageReceived
216 *****************************************************************************/
217 void InterfaceWindow::MessageReceived( BMessage * p_message )
219 int playback_status; // remember playback state
220 playback_status = p_wrapper->InputStatus();
222 switch( p_message->what )
224 case B_ABOUT_REQUESTED:
226 BAlert* alert = new BAlert( VOUT_TITLE,
227 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
240 fFilePanel = new BFilePanel();
241 fFilePanel->SetTarget( this );
246 if (fPlaylistWindow->Lock())
248 if (fPlaylistWindow->IsHidden())
249 fPlaylistWindow->Show();
251 fPlaylistWindow->Activate();
252 fPlaylistWindow->Unlock();
257 const char *psz_device;
258 BString type( "dvd" );
259 if( p_message->FindString( "device", &psz_device ) == B_OK )
261 BString device( psz_device );
262 p_wrapper->openDisc( type, device, 0, 0 );
269 if( fSubtitlesPanel )
271 fSubtitlesPanel->Show();
274 fSubtitlesPanel = new BFilePanel();
275 fSubtitlesPanel->SetTarget( this );
276 fSubtitlesPanel->SetMessage( new BMessage( SUBFILE_RECEIVED ) );
277 fSubtitlesPanel->Show();
280 case SUBFILE_RECEIVED:
283 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
286 if ( path.InitCheck() == B_OK )
287 p_wrapper->LoadSubFile( (char*)path.Path() );
293 // this currently stops playback not nicely
294 if (playback_status > UNDEF_S)
297 p_wrapper->PlaylistStop();
298 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
303 /* starts playing in normal mode */
306 /* toggle between pause and play */
307 if (playback_status > UNDEF_S)
309 /* pause if currently playing */
310 if ( playback_status == PLAYING_S )
312 p_wrapper->PlaylistPause();
316 p_wrapper->PlaylistPlay();
321 /* Play a new file */
322 p_wrapper->PlaylistPlay();
327 /* cycle the fast playback modes */
328 if (playback_status > UNDEF_S)
330 p_wrapper->InputFaster();
335 /* cycle the slow playback modes */
336 if (playback_status > UNDEF_S)
338 p_wrapper->InputSlower();
343 /* restore speed to normal if already playing */
344 if (playback_status > UNDEF_S)
346 p_wrapper->PlaylistPlay();
351 /* handled by semaphores */
353 // volume related messages
355 /* adjust the volume */
356 if (playback_status > UNDEF_S)
358 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
359 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
365 if( p_wrapper->IsMuted() )
366 p_wrapper->VolumeRestore();
368 p_wrapper->VolumeMute();
369 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
373 if ( playback_status > UNDEF_S )
376 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
378 p_wrapper->ToggleLanguage( channel );
383 case SELECT_SUBTITLE:
384 if ( playback_status > UNDEF_S )
387 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
388 p_wrapper->ToggleSubtitle( subtitle );
392 // specific navigation messages
395 p_wrapper->PrevTitle();
400 p_wrapper->NextTitle();
404 if ( playback_status > UNDEF_S )
407 if ( p_message->FindInt32( "index", &index ) == B_OK )
408 p_wrapper->toggleTitle( index );
413 p_wrapper->PrevChapter();
418 p_wrapper->NextChapter();
422 if ( playback_status > UNDEF_S )
425 if ( p_message->FindInt32( "index", &index ) == B_OK )
426 p_wrapper->toggleChapter( index );
430 p_wrapper->PlaylistPrev();
433 p_wrapper->PlaylistNext();
435 // general next/prev functionality (skips to whatever makes most sense)
437 p_wrapper->navigatePrev();
440 p_wrapper->navigateNext();
442 // drag'n'drop and system messages
443 case B_REFS_RECEIVED:
446 /* file(s) opened by the File menu -> append to the playlist;
447 * file(s) opened by drag & drop -> replace playlist;
448 * file(s) opened by 'shift' + drag & drop -> append */
449 bool replace = false;
450 if ( p_message->WasDropped() )
451 replace = !( modifiers() & B_SHIFT_KEY );
453 // build list of files to be played from message contents
456 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
459 if ( path.InitCheck() == B_OK )
462 // has the user dropped a dvd disk icon?
463 BDirectory dir( &ref );
464 if ( dir.InitCheck() == B_OK && dir.IsRootDirectory() )
466 BVolumeRoster volRoster;
468 BDirectory volumeRoot;
469 status_t status = volRoster.GetNextVolume( &vol );
470 while( status == B_NO_ERROR )
472 if( vol.GetRootDirectory( &volumeRoot ) == B_OK
473 && dir == volumeRoot )
477 bool isCDROM = false;
478 bool success = false;
481 char name[B_FILE_NAME_LENGTH];
482 if ( vol.GetName( name ) >= B_OK ) // disk is currently mounted
485 dev_t dev = vol.Device();
487 if ( fs_stat_dev( dev, &info ) == B_OK )
490 deviceName = info.device_name;
491 if ( vol.IsReadOnly() )
493 int i_dev = open( info.device_name, O_RDONLY );
497 if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
498 isCDROM = ( g.device_type == B_CD );
505 if( success && isCDROM )
507 BMessage msg( OPEN_DVD );
508 msg.AddString( "device", deviceName.String() );
517 status = volRoster.GetNextVolume( &vol );
523 files.AddItem( new BString( (char*)path.Path() ) );
527 // give the list to VLC
528 p_wrapper->openFiles(&files, replace);
533 case OPEN_PREFERENCES:
534 if( fPreferencesWindow->Lock() )
536 if (fPreferencesWindow->IsHidden())
537 fPreferencesWindow->Show();
539 fPreferencesWindow->Activate();
540 fPreferencesWindow->Unlock();
545 BWindow::MessageReceived( p_message );
551 /*****************************************************************************
552 * InterfaceWindow::QuitRequested
553 *****************************************************************************/
554 bool InterfaceWindow::QuitRequested()
556 p_wrapper->PlaylistStop();
557 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
566 /*****************************************************************************
567 * InterfaceWindow::updateInterface
568 *****************************************************************************/
569 void InterfaceWindow::updateInterface()
571 if( p_wrapper->HasInput() )
573 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
575 p_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
579 // p_mediaControl->SetEnabled( true );
580 bool hasTitles = p_wrapper->HasTitles();
581 bool hasChapters = p_wrapper->HasChapters();
582 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
583 p_wrapper->InputRate() );
584 p_mediaControl->SetProgress( p_wrapper->getTimeAsFloat() );
585 _SetMenusEnabled( true, hasChapters, hasTitles );
587 _UpdateSpeedMenu( p_wrapper->InputRate() );
589 // enable/disable skip buttons
592 p_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
593 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
595 if ( p_wrapper->HasAudio() )
597 p_mediaControl->SetAudioEnabled( true );
598 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
600 p_mediaControl->SetAudioEnabled( false );
604 // update playlist as well
605 if ( fPlaylistWindow->Lock() )
607 fPlaylistWindow->UpdatePlaylist();
608 fPlaylistWindow->Unlock();
613 _SetMenusEnabled( false );
614 // p_mediaControl->SetEnabled( false );
617 /* always force the user-specified volume */
618 /* FIXME : I'm quite sure there is a cleaner way to do this */
619 if( p_wrapper->GetVolume() != p_mediaControl->GetVolume() )
621 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
624 fLastUpdateTime = system_time();
627 /*****************************************************************************
628 * InterfaceWindow::IsStopped
629 *****************************************************************************/
631 InterfaceWindow::IsStopped() const
633 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
636 /*****************************************************************************
637 * InterfaceWindow::_UpdatePlaylist
638 *****************************************************************************/
640 InterfaceWindow::_UpdatePlaylist()
642 if ( fPlaylistWindow->Lock() )
644 fPlaylistWindow->UpdatePlaylist( true );
645 fPlaylistWindow->Unlock();
646 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
650 /*****************************************************************************
651 * InterfaceWindow::_SetMenusEnabled
652 *****************************************************************************/
654 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
663 if (fNextChapterMI->IsEnabled() != hasChapters)
664 fNextChapterMI->SetEnabled(hasChapters);
665 if (fPrevChapterMI->IsEnabled() != hasChapters)
666 fPrevChapterMI->SetEnabled(hasChapters);
667 if (fChapterMenu->IsEnabled() != hasChapters)
668 fChapterMenu->SetEnabled(hasChapters);
669 if (fNextTitleMI->IsEnabled() != hasTitles)
670 fNextTitleMI->SetEnabled(hasTitles);
671 if (fPrevTitleMI->IsEnabled() != hasTitles)
672 fPrevTitleMI->SetEnabled(hasTitles);
673 if (fTitleMenu->IsEnabled() != hasTitles)
674 fTitleMenu->SetEnabled(hasTitles);
675 if (fAudioMenu->IsEnabled() != hasFile)
676 fAudioMenu->SetEnabled(hasFile);
677 if (fNavigationMenu->IsEnabled() != hasFile)
678 fNavigationMenu->SetEnabled(hasFile);
679 if (fLanguageMenu->IsEnabled() != hasFile)
680 fLanguageMenu->SetEnabled(hasFile);
681 if (fSubtitlesMenu->IsEnabled() != hasFile)
682 fSubtitlesMenu->SetEnabled(hasFile);
683 if (fSpeedMenu->IsEnabled() != hasFile)
684 fSpeedMenu->SetEnabled(hasFile);
689 /*****************************************************************************
690 * InterfaceWindow::_UpdateSpeedMenu
691 *****************************************************************************/
693 InterfaceWindow::_UpdateSpeedMenu( int rate )
695 if ( rate == DEFAULT_RATE )
697 if ( !fNormalMI->IsMarked() )
698 fNormalMI->SetMarked( true );
700 else if ( rate < DEFAULT_RATE )
702 if ( !fFasterMI->IsMarked() )
703 fFasterMI->SetMarked( true );
707 if ( !fSlowerMI->IsMarked() )
708 fSlowerMI->SetMarked( true );
712 /*****************************************************************************
713 * InterfaceWindow::_InputStreamChanged
714 *****************************************************************************/
716 InterfaceWindow::_InputStreamChanged()
718 //printf("InterfaceWindow::_InputStreamChanged()\n");
719 // TODO: move more stuff from updateInterface() here!
721 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
724 /*****************************************************************************
725 * InterfaceWindow::_LoadSettings
726 *****************************************************************************/
728 InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
730 status_t ret = B_BAD_VALUE;
734 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
736 // passing folder is optional
738 ret = path.Append( folder );
739 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
741 BFile file( path.Path(), B_READ_ONLY );
742 if ( ( ret = file.InitCheck() ) == B_OK )
744 ret = message->Unflatten( &file );
753 /*****************************************************************************
754 * InterfaceWindow::_SaveSettings
755 *****************************************************************************/
757 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
759 status_t ret = B_BAD_VALUE;
763 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
765 // passing folder is optional
766 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
767 ret = create_directory( path.Path(), 0777 );
768 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
770 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
771 if ( ( ret = file.InitCheck() ) == B_OK )
773 ret = message->Flatten( &file );
782 /*****************************************************************************
783 * InterfaceWindow::_RestoreSettings
784 *****************************************************************************/
786 make_sure_frame_is_on_screen( BRect& frame )
788 BScreen screen( B_MAIN_SCREEN_ID );
789 if (frame.IsValid() && screen.IsValid()) {
790 if (!screen.Frame().Contains(frame)) {
791 // make sure frame fits in the screen
792 if (frame.Width() > screen.Frame().Width())
793 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
794 if (frame.Height() > screen.Frame().Height())
795 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
796 // frame is now at the most the size of the screen
797 if (frame.right > screen.Frame().right)
798 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
799 if (frame.bottom > screen.Frame().bottom)
800 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
801 if (frame.left < screen.Frame().left)
802 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
803 if (frame.top < screen.Frame().top)
804 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
812 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
813 float maxWidth, float maxHeight )
815 if ( frame.Width() < minWidth )
816 frame.right = frame.left + minWidth;
817 if ( frame.Height() < minHeight )
818 frame.bottom = frame.top + minHeight;
819 if ( frame.Width() > maxWidth )
820 frame.right = frame.left + maxWidth;
821 if ( frame.Height() > maxHeight )
822 frame.bottom = frame.top + maxHeight;
825 /*****************************************************************************
826 * InterfaceWindow::_RestoreSettings
827 *****************************************************************************/
829 InterfaceWindow::_RestoreSettings()
831 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
834 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
836 // sanity checks: make sure window is not too big/small
837 // and that it's not off-screen
838 float minWidth, maxWidth, minHeight, maxHeight;
839 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
841 make_sure_frame_is_within_limits( mainFrame,
842 minWidth, minHeight, maxWidth, maxHeight );
843 make_sure_frame_is_on_screen( mainFrame );
846 MoveTo( mainFrame.LeftTop() );
847 ResizeTo( mainFrame.Width(), mainFrame.Height() );
849 if ( fPlaylistWindow->Lock() )
852 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
854 // sanity checks: make sure window is not too big/small
855 // and that it's not off-screen
856 float minWidth, maxWidth, minHeight, maxHeight;
857 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
859 make_sure_frame_is_within_limits( playlistFrame,
860 minWidth, minHeight, maxWidth, maxHeight );
861 make_sure_frame_is_on_screen( playlistFrame );
863 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
864 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
868 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
872 if ( fPlaylistWindow->IsHidden() )
873 fPlaylistWindow->Show();
877 if ( !fPlaylistWindow->IsHidden() )
878 fPlaylistWindow->Hide();
882 fPlaylistWindow->Unlock();
887 /*****************************************************************************
888 * InterfaceWindow::_StoreSettings
889 *****************************************************************************/
891 InterfaceWindow::_StoreSettings()
893 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
894 fSettings->AddRect( "main frame", Frame() );
895 if ( fPlaylistWindow->Lock() )
897 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
898 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
899 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
900 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
901 fPlaylistWindow->Unlock();
903 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
906 /*****************************************************************************
908 *****************************************************************************/
909 CDMenu::CDMenu(const char *name)
914 /*****************************************************************************
916 *****************************************************************************/
921 /*****************************************************************************
922 * CDMenu::AttachedToWindow
923 *****************************************************************************/
924 void CDMenu::AttachedToWindow(void)
927 while (BMenuItem* item = RemoveItem(0L))
930 BMenu::AttachedToWindow();
933 /*****************************************************************************
935 *****************************************************************************/
936 int CDMenu::GetCD( const char *directory )
938 BVolumeRoster *volRoster;
943 char name[B_FILE_NAME_LENGTH];
947 volRoster = new BVolumeRoster();
949 dir = new BDirectory();
950 status = volRoster->GetNextVolume(vol);
951 status = vol->GetRootDirectory(dir);
952 while (status == B_NO_ERROR)
954 mounted = vol->GetName(name);
955 if ((mounted == B_OK) && /* Disk is currently Mounted */
956 (vol->IsReadOnly()) ) /* Disk is read-only */
959 fs_stat_dev(dev, &info);
963 i_dev = open( info.device_name, O_RDONLY );
967 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
969 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
972 msg = new BMessage( OPEN_DVD );
973 msg->AddString( "device", info.device_name );
974 BMenuItem *menu_item;
975 menu_item = new BMenuItem( name, msg );
976 AddItem( menu_item );
983 status = volRoster->GetNextVolume(vol);
988 /*****************************************************************************
989 * LanguageMenu::LanguageMenu
990 *****************************************************************************/
991 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
992 VlcWrapper *p_wrapper )
996 this->p_wrapper = p_wrapper;
999 /*****************************************************************************
1000 * LanguageMenu::~LanguageMenu
1001 *****************************************************************************/
1002 LanguageMenu::~LanguageMenu()
1006 /*****************************************************************************
1007 * LanguageMenu::AttachedToWindow
1008 *****************************************************************************/
1009 void LanguageMenu::AttachedToWindow()
1012 while ( BMenuItem* item = RemoveItem( 0L ) )
1015 SetRadioMode( true );
1017 BMenu::AttachedToWindow();
1020 /*****************************************************************************
1021 * LanguageMenu::_GetChannels
1022 *****************************************************************************/
1023 void LanguageMenu::_GetChannels()
1028 if( ( list = p_wrapper->InputGetChannels( kind ) ) == NULL )
1031 for( int i = 0; i < list->CountItems(); i++ )
1033 item = (BMenuItem*)list->ItemAt( i );
1037 if( list->CountItems() > 1 )
1038 AddItem( new BSeparatorItem(), 1 );
1042 /*****************************************************************************
1043 * TitleMenu::TitleMenu
1044 *****************************************************************************/
1045 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1047 p_intf( p_interface )
1051 /*****************************************************************************
1052 * TitleMenu::~TitleMenu
1053 *****************************************************************************/
1054 TitleMenu::~TitleMenu()
1058 /*****************************************************************************
1059 * TitleMenu::AttachedToWindow
1060 *****************************************************************************/
1061 void TitleMenu::AttachedToWindow()
1063 // make title menu empty
1064 while ( BMenuItem* item = RemoveItem( 0L ) )
1068 input_thread_t* input = p_intf->p_sys->p_input;
1071 // lock stream access
1072 vlc_mutex_lock( &input->stream.stream_lock );
1073 // populate menu according to current stream
1074 int32 numTitles = input->stream.i_area_nb;
1075 if ( numTitles > 1 )
1077 // disallow title 0!
1078 for ( int32 i = 1; i < numTitles; i++ )
1080 BMessage* message = new BMessage( TOGGLE_TITLE );
1081 message->AddInt32( "index", i );
1082 BString helper( "" );
1084 BMenuItem* item = new BMenuItem( helper.String(), message );
1085 item->SetMarked( input->stream.p_selected_area->i_id == i );
1089 // done messing with stream
1090 vlc_mutex_unlock( &input->stream.stream_lock );
1093 BMenu::AttachedToWindow();
1097 /*****************************************************************************
1098 * ChapterMenu::ChapterMenu
1099 *****************************************************************************/
1100 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1102 p_intf( p_interface )
1106 /*****************************************************************************
1107 * ChapterMenu::~ChapterMenu
1108 *****************************************************************************/
1109 ChapterMenu::~ChapterMenu()
1113 /*****************************************************************************
1114 * ChapterMenu::AttachedToWindow
1115 *****************************************************************************/
1116 void ChapterMenu::AttachedToWindow()
1118 // make title menu empty
1119 while ( BMenuItem* item = RemoveItem( 0L ) )
1123 input_thread_t* input = p_intf->p_sys->p_input;
1126 // lock stream access
1127 vlc_mutex_lock( &input->stream.stream_lock );
1128 // populate menu according to current stream
1129 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1130 if ( numChapters > 1 )
1132 for ( int32 i = 0; i < numChapters; i++ )
1134 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1135 message->AddInt32( "index", i );
1136 BString helper( "" );
1138 BMenuItem* item = new BMenuItem( helper.String(), message );
1139 item->SetMarked( input->stream.p_selected_area->i_part == i );
1143 // done messing with stream
1144 vlc_mutex_unlock( &input->stream.stream_lock );
1146 BMenu::AttachedToWindow();