1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.13 2003/01/08 02:09:15 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 fLastUpdateTime( system_time() ),
67 fSettings( new BMessage( 'sett' ) )
70 p_wrapper = p_intf->p_sys->p_wrapper;
72 fPlaylistIsEmpty = ( p_wrapper->PlaylistSize() < 0 );
74 fPlaylistWindow = new PlayListWindow( BRect( 100.0, 100.0, 400.0, 350.0 ),
78 BScreen *p_screen = new BScreen();
79 BRect screen_rect = p_screen->Frame();
82 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
83 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
84 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
85 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
86 fPreferencesWindow = new PreferencesWindow( window_rect,
91 SetName( "interface" );
92 SetTitle( VOUT_TITLE );
94 // the media control view
95 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
97 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
98 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
101 p_mediaControl->GetPreferredSize( &width, &height );
103 // set up the main menu
104 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
105 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
107 // make menu bar resize to correct height
108 float menuWidth, menuHeight;
109 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
110 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
111 // take care of proper size for ourself
112 height += fMenuBar->Bounds().Height();
113 ResizeTo( width, height );
115 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
116 AddChild( fMenuBar );
117 AddChild( p_mediaControl );
120 BMenu* fileMenu = new BMenu( "File" );
121 fMenuBar->AddItem( fileMenu );
122 fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
123 new BMessage( OPEN_FILE ), 'O') );
125 fileMenu->AddItem( new CDMenu( "Open Disc" ) );
127 fileMenu->AddSeparatorItem();
128 fileMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
129 new BMessage( OPEN_PLAYLIST ), 'P') );
131 fileMenu->AddSeparatorItem();
132 BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
133 new BMessage( B_ABOUT_REQUESTED ), 'A');
134 item->SetTarget( be_app );
135 fileMenu->AddItem( item );
136 fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
138 fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_wrapper);
139 fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_wrapper);
141 /* Add the Audio menu */
142 fAudioMenu = new BMenu( "Audio" );
143 fMenuBar->AddItem ( fAudioMenu );
144 fAudioMenu->AddItem( fLanguageMenu );
145 fAudioMenu->AddItem( fSubtitlesMenu );
147 fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
148 fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
149 fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
150 fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
152 /* Add the Navigation menu */
153 fNavigationMenu = new BMenu( "Navigation" );
154 fMenuBar->AddItem( fNavigationMenu );
155 fNavigationMenu->AddItem( fPrevTitleMI );
156 fNavigationMenu->AddItem( fNextTitleMI );
157 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
158 fNavigationMenu->AddSeparatorItem();
159 fNavigationMenu->AddItem( fPrevChapterMI );
160 fNavigationMenu->AddItem( fNextChapterMI );
161 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
163 /* Add the Speed menu */
164 fSpeedMenu = new BMenu( "Speed" );
165 fSpeedMenu->SetRadioMode( true );
166 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
167 fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
168 fNormalMI->SetMarked(true); // default to normal speed
169 fSpeedMenu->AddItem( fNormalMI );
170 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
171 fSpeedMenu->SetTargetForItems( this );
172 fMenuBar->AddItem( fSpeedMenu );
174 /* Add the Settings menu */
175 fSettingsMenu = new BMenu( "Settings" );
176 fSettingsMenu->AddItem( fPreferencesMI =
177 new BMenuItem( "Preferences", new BMessage( OPEN_PREFERENCES ) ) );
178 fMenuBar->AddItem( fSettingsMenu );
180 // prepare fow showing
181 _SetMenusEnabled(false);
188 InterfaceWindow::~InterfaceWindow()
191 fPlaylistWindow->ReallyQuit();
195 /*****************************************************************************
196 * InterfaceWindow::FrameResized
197 *****************************************************************************/
199 InterfaceWindow::FrameResized(float width, float height)
202 fMenuBar->MoveTo(r.LeftTop());
203 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
204 r.top += fMenuBar->Bounds().Height() + 1.0;
205 p_mediaControl->MoveTo(r.LeftTop());
206 p_mediaControl->ResizeTo(r.Width(), r.Height());
209 /*****************************************************************************
210 * InterfaceWindow::MessageReceived
211 *****************************************************************************/
212 void InterfaceWindow::MessageReceived( BMessage * p_message )
214 int playback_status; // remember playback state
215 playback_status = p_wrapper->InputStatus();
217 switch( p_message->what )
219 case B_ABOUT_REQUESTED:
221 BAlert* alert = new BAlert( VOUT_TITLE,
222 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
235 fFilePanel = new BFilePanel();
236 fFilePanel->SetTarget( this );
241 if (fPlaylistWindow->Lock())
243 if (fPlaylistWindow->IsHidden())
244 fPlaylistWindow->Show();
246 fPlaylistWindow->Activate();
247 fPlaylistWindow->Unlock();
252 const char *psz_device;
253 BString type( "dvd" );
254 if( p_message->FindString( "device", &psz_device ) == B_OK )
256 BString device( psz_device );
257 p_wrapper->openDisc( type, device, 0, 0 );
264 // this currently stops playback not nicely
265 if (playback_status > UNDEF_S)
268 p_wrapper->PlaylistStop();
269 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
274 /* starts playing in normal mode */
277 /* toggle between pause and play */
278 if (playback_status > UNDEF_S)
280 /* pause if currently playing */
281 if ( playback_status == PLAYING_S )
283 p_wrapper->PlaylistPause();
287 p_wrapper->PlaylistPlay();
292 /* Play a new file */
293 p_wrapper->PlaylistPlay();
298 /* cycle the fast playback modes */
299 if (playback_status > UNDEF_S)
301 p_wrapper->InputFaster();
306 /* cycle the slow playback modes */
307 if (playback_status > UNDEF_S)
309 p_wrapper->InputSlower();
314 /* restore speed to normal if already playing */
315 if (playback_status > UNDEF_S)
317 p_wrapper->PlaylistPlay();
322 /* handled by semaphores */
324 // volume related messages
326 /* adjust the volume */
327 if (playback_status > UNDEF_S)
329 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
330 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
336 if( p_wrapper->IsMuted() )
337 p_wrapper->VolumeRestore();
339 p_wrapper->VolumeMute();
340 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
344 if ( playback_status > UNDEF_S )
347 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
349 p_wrapper->ToggleLanguage( channel );
354 case SELECT_SUBTITLE:
355 if ( playback_status > UNDEF_S )
358 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
359 p_wrapper->ToggleSubtitle( subtitle );
363 // specific navigation messages
366 p_wrapper->PrevTitle();
371 p_wrapper->NextTitle();
375 if ( playback_status > UNDEF_S )
378 if ( p_message->FindInt32( "index", &index ) == B_OK )
379 p_wrapper->toggleTitle( index );
384 p_wrapper->PrevChapter();
389 p_wrapper->NextChapter();
393 if ( playback_status > UNDEF_S )
396 if ( p_message->FindInt32( "index", &index ) == B_OK )
397 p_wrapper->toggleChapter( index );
401 p_wrapper->PlaylistPrev();
404 p_wrapper->PlaylistNext();
406 // general next/prev functionality (skips to whatever makes most sense)
408 p_wrapper->navigatePrev();
411 p_wrapper->navigateNext();
413 // drag'n'drop and system messages
414 case B_REFS_RECEIVED:
417 // figure out if user wants files replaced or added
418 bool replace = false;
419 if ( p_message->WasDropped() )
420 replace = !( modifiers() & B_SHIFT_KEY );
421 // build list of files to be played from message contents
424 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
427 if ( path.InitCheck() == B_OK )
428 // the BString objects will be deleted
429 // by the wrapper function further down
430 files.AddItem( new BString( (char*)path.Path() ) );
432 // give the list to VLC
433 p_wrapper->openFiles(&files, replace);
438 case OPEN_PREFERENCES:
439 if( fPreferencesWindow->Lock() )
441 if (fPreferencesWindow->IsHidden())
442 fPreferencesWindow->Show();
444 fPreferencesWindow->Activate();
445 fPreferencesWindow->Unlock();
450 BWindow::MessageReceived( p_message );
456 /*****************************************************************************
457 * InterfaceWindow::QuitRequested
458 *****************************************************************************/
459 bool InterfaceWindow::QuitRequested()
461 p_wrapper->PlaylistStop();
462 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
471 /*****************************************************************************
472 * InterfaceWindow::updateInterface
473 *****************************************************************************/
474 void InterfaceWindow::updateInterface()
476 if( p_wrapper->HasInput() )
478 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
480 p_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
484 bool hasTitles = p_wrapper->HasTitles();
485 bool hasChapters = p_wrapper->HasChapters();
486 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
487 p_wrapper->InputRate() );
488 p_mediaControl->SetProgress( p_wrapper->InputTell(),
489 p_wrapper->InputSize() );
490 _SetMenusEnabled( true, hasChapters, hasTitles );
492 _UpdateSpeedMenu( p_wrapper->InputRate() );
494 // enable/disable skip buttons
497 p_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
498 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
500 if ( p_wrapper->HasAudio() )
502 p_mediaControl->SetAudioEnabled( true );
503 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
505 p_mediaControl->SetAudioEnabled( false );
509 // update playlist as well
510 if ( fPlaylistWindow->Lock() )
512 fPlaylistWindow->UpdatePlaylist();
513 fPlaylistWindow->Unlock();
518 _SetMenusEnabled(false);
522 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
526 /* always force the user-specified volume */
527 /* FIXME : I'm quite sure there is a cleaner way to do this */
528 if( p_wrapper->GetVolume() != p_mediaControl->GetVolume() )
530 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
533 fLastUpdateTime = system_time();
536 /*****************************************************************************
537 * InterfaceWindow::IsStopped
538 *****************************************************************************/
540 InterfaceWindow::IsStopped() const
542 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
545 /*****************************************************************************
546 * InterfaceWindow::_UpdatePlaylist
547 *****************************************************************************/
549 InterfaceWindow::_UpdatePlaylist()
551 if ( fPlaylistWindow->Lock() )
553 fPlaylistWindow->UpdatePlaylist( true );
554 fPlaylistWindow->Unlock();
555 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
559 /*****************************************************************************
560 * InterfaceWindow::_SetMenusEnabled
561 *****************************************************************************/
563 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
572 if (fNextChapterMI->IsEnabled() != hasChapters)
573 fNextChapterMI->SetEnabled(hasChapters);
574 if (fPrevChapterMI->IsEnabled() != hasChapters)
575 fPrevChapterMI->SetEnabled(hasChapters);
576 if (fChapterMenu->IsEnabled() != hasChapters)
577 fChapterMenu->SetEnabled(hasChapters);
578 if (fNextTitleMI->IsEnabled() != hasTitles)
579 fNextTitleMI->SetEnabled(hasTitles);
580 if (fPrevTitleMI->IsEnabled() != hasTitles)
581 fPrevTitleMI->SetEnabled(hasTitles);
582 if (fTitleMenu->IsEnabled() != hasTitles)
583 fTitleMenu->SetEnabled(hasTitles);
584 if (fAudioMenu->IsEnabled() != hasFile)
585 fAudioMenu->SetEnabled(hasFile);
586 if (fNavigationMenu->IsEnabled() != hasFile)
587 fNavigationMenu->SetEnabled(hasFile);
588 if (fLanguageMenu->IsEnabled() != hasFile)
589 fLanguageMenu->SetEnabled(hasFile);
590 if (fSubtitlesMenu->IsEnabled() != hasFile)
591 fSubtitlesMenu->SetEnabled(hasFile);
592 if (fSpeedMenu->IsEnabled() != hasFile)
593 fSpeedMenu->SetEnabled(hasFile);
598 /*****************************************************************************
599 * InterfaceWindow::_UpdateSpeedMenu
600 *****************************************************************************/
602 InterfaceWindow::_UpdateSpeedMenu( int rate )
604 if ( rate == DEFAULT_RATE )
606 if ( !fNormalMI->IsMarked() )
607 fNormalMI->SetMarked( true );
609 else if ( rate < DEFAULT_RATE )
611 if ( !fFasterMI->IsMarked() )
612 fFasterMI->SetMarked( true );
616 if ( !fSlowerMI->IsMarked() )
617 fSlowerMI->SetMarked( true );
621 /*****************************************************************************
622 * InterfaceWindow::_InputStreamChanged
623 *****************************************************************************/
625 InterfaceWindow::_InputStreamChanged()
627 //printf("InterfaceWindow::_InputStreamChanged()\n");
628 // TODO: move more stuff from updateInterface() here!
630 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
633 /*****************************************************************************
634 * InterfaceWindow::_LoadSettings
635 *****************************************************************************/
637 InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
639 status_t ret = B_BAD_VALUE;
643 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
645 // passing folder is optional
647 ret = path.Append( folder );
648 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
650 BFile file( path.Path(), B_READ_ONLY );
651 if ( ( ret = file.InitCheck() ) == B_OK )
653 ret = message->Unflatten( &file );
662 /*****************************************************************************
663 * InterfaceWindow::_SaveSettings
664 *****************************************************************************/
666 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
668 status_t ret = B_BAD_VALUE;
672 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
674 // passing folder is optional
675 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
676 ret = create_directory( path.Path(), 0777 );
677 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
679 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
680 if ( ( ret = file.InitCheck() ) == B_OK )
682 ret = message->Flatten( &file );
691 /*****************************************************************************
692 * InterfaceWindow::_RestoreSettings
693 *****************************************************************************/
695 make_sure_frame_is_on_screen( BRect& frame )
697 BScreen screen( B_MAIN_SCREEN_ID );
698 if (frame.IsValid() && screen.IsValid()) {
699 if (!screen.Frame().Contains(frame)) {
700 // make sure frame fits in the screen
701 if (frame.Width() > screen.Frame().Width())
702 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
703 if (frame.Height() > screen.Frame().Height())
704 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
705 // frame is now at the most the size of the screen
706 if (frame.right > screen.Frame().right)
707 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
708 if (frame.bottom > screen.Frame().bottom)
709 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
710 if (frame.left < screen.Frame().left)
711 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
712 if (frame.top < screen.Frame().top)
713 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
721 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
722 float maxWidth, float maxHeight )
724 if ( frame.Width() < minWidth )
725 frame.right = frame.left + minWidth;
726 if ( frame.Height() < minHeight )
727 frame.bottom = frame.top + minHeight;
728 if ( frame.Width() > maxWidth )
729 frame.right = frame.left + maxWidth;
730 if ( frame.Height() > maxHeight )
731 frame.bottom = frame.top + maxHeight;
734 /*****************************************************************************
735 * InterfaceWindow::_RestoreSettings
736 *****************************************************************************/
738 InterfaceWindow::_RestoreSettings()
740 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
743 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
745 // sanity checks: make sure window is not too big/small
746 // and that it's not off-screen
747 float minWidth, maxWidth, minHeight, maxHeight;
748 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
750 make_sure_frame_is_within_limits( mainFrame,
751 minWidth, minHeight, maxWidth, maxHeight );
752 make_sure_frame_is_on_screen( mainFrame );
755 MoveTo( mainFrame.LeftTop() );
756 ResizeTo( mainFrame.Width(), mainFrame.Height() );
758 if ( fPlaylistWindow->Lock() )
761 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
763 // sanity checks: make sure window is not too big/small
764 // and that it's not off-screen
765 float minWidth, maxWidth, minHeight, maxHeight;
766 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
768 make_sure_frame_is_within_limits( playlistFrame,
769 minWidth, minHeight, maxWidth, maxHeight );
770 make_sure_frame_is_on_screen( playlistFrame );
772 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
773 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
777 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
781 if ( fPlaylistWindow->IsHidden() )
782 fPlaylistWindow->Show();
786 if ( !fPlaylistWindow->IsHidden() )
787 fPlaylistWindow->Hide();
791 fPlaylistWindow->Unlock();
796 /*****************************************************************************
797 * InterfaceWindow::_StoreSettings
798 *****************************************************************************/
800 InterfaceWindow::_StoreSettings()
802 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
803 fSettings->AddRect( "main frame", Frame() );
804 if ( fPlaylistWindow->Lock() )
806 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
807 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
808 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
809 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
810 fPlaylistWindow->Unlock();
812 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
815 /*****************************************************************************
817 *****************************************************************************/
818 CDMenu::CDMenu(const char *name)
823 /*****************************************************************************
825 *****************************************************************************/
830 /*****************************************************************************
831 * CDMenu::AttachedToWindow
832 *****************************************************************************/
833 void CDMenu::AttachedToWindow(void)
836 while (BMenuItem* item = RemoveItem(0L))
839 BMenu::AttachedToWindow();
842 /*****************************************************************************
844 *****************************************************************************/
845 int CDMenu::GetCD( const char *directory )
847 BVolumeRoster *volRoster;
852 char name[B_FILE_NAME_LENGTH];
856 volRoster = new BVolumeRoster();
858 dir = new BDirectory();
859 status = volRoster->GetNextVolume(vol);
860 status = vol->GetRootDirectory(dir);
861 while (status == B_NO_ERROR)
863 mounted = vol->GetName(name);
864 if ((mounted == B_OK) && /* Disk is currently Mounted */
865 (vol->IsReadOnly()) ) /* Disk is read-only */
868 fs_stat_dev(dev, &info);
872 i_dev = open( info.device_name, O_RDONLY );
876 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
878 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
881 msg = new BMessage( OPEN_DVD );
882 msg->AddString( "device", info.device_name );
883 BMenuItem *menu_item;
884 menu_item = new BMenuItem( name, msg );
885 AddItem( menu_item );
892 status = volRoster->GetNextVolume(vol);
897 /*****************************************************************************
898 * LanguageMenu::LanguageMenu
899 *****************************************************************************/
900 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
901 VlcWrapper *p_wrapper )
905 this->p_wrapper = p_wrapper;
908 /*****************************************************************************
909 * LanguageMenu::~LanguageMenu
910 *****************************************************************************/
911 LanguageMenu::~LanguageMenu()
915 /*****************************************************************************
916 * LanguageMenu::AttachedToWindow
917 *****************************************************************************/
918 void LanguageMenu::AttachedToWindow()
921 while ( BMenuItem* item = RemoveItem( 0L ) )
924 SetRadioMode( true );
926 BMenu::AttachedToWindow();
929 /*****************************************************************************
930 * LanguageMenu::_GetChannels
931 *****************************************************************************/
932 void LanguageMenu::_GetChannels()
937 if( ( list = p_wrapper->InputGetChannels( kind ) ) == NULL )
940 for( int i = 0; i < list->CountItems(); i++ )
942 item = (BMenuItem*)list->ItemAt( i );
946 if( list->CountItems() > 1 )
947 AddItem( new BSeparatorItem(), 1 );
951 /*****************************************************************************
952 * TitleMenu::TitleMenu
953 *****************************************************************************/
954 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
956 p_intf( p_interface )
960 /*****************************************************************************
961 * TitleMenu::~TitleMenu
962 *****************************************************************************/
963 TitleMenu::~TitleMenu()
967 /*****************************************************************************
968 * TitleMenu::AttachedToWindow
969 *****************************************************************************/
970 void TitleMenu::AttachedToWindow()
972 // make title menu empty
973 while ( BMenuItem* item = RemoveItem( 0L ) )
977 input_thread_t* input = p_intf->p_sys->p_input;
980 // lock stream access
981 vlc_mutex_lock( &input->stream.stream_lock );
982 // populate menu according to current stream
983 int32 numTitles = input->stream.i_area_nb;
987 for ( int32 i = 1; i < numTitles; i++ )
989 BMessage* message = new BMessage( TOGGLE_TITLE );
990 message->AddInt32( "index", i );
991 BString helper( "" );
993 BMenuItem* item = new BMenuItem( helper.String(), message );
994 item->SetMarked( input->stream.p_selected_area->i_id == i );
998 // done messing with stream
999 vlc_mutex_unlock( &input->stream.stream_lock );
1002 BMenu::AttachedToWindow();
1006 /*****************************************************************************
1007 * ChapterMenu::ChapterMenu
1008 *****************************************************************************/
1009 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1011 p_intf( p_interface )
1015 /*****************************************************************************
1016 * ChapterMenu::~ChapterMenu
1017 *****************************************************************************/
1018 ChapterMenu::~ChapterMenu()
1022 /*****************************************************************************
1023 * ChapterMenu::AttachedToWindow
1024 *****************************************************************************/
1025 void ChapterMenu::AttachedToWindow()
1027 // make title menu empty
1028 while ( BMenuItem* item = RemoveItem( 0L ) )
1032 input_thread_t* input = p_intf->p_sys->p_input;
1035 // lock stream access
1036 vlc_mutex_lock( &input->stream.stream_lock );
1037 // populate menu according to current stream
1038 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1039 if ( numChapters > 1 )
1041 for ( int32 i = 0; i < numChapters; i++ )
1043 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1044 message->AddInt32( "index", i );
1045 BString helper( "" );
1047 BMenuItem* item = new BMenuItem( helper.String(), message );
1048 item->SetMarked( input->stream.p_selected_area->i_part == i );
1052 // done messing with stream
1053 vlc_mutex_unlock( &input->stream.stream_lock );
1055 BMenu::AttachedToWindow();