1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.15 2003/01/12 02:08:38 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 );
182 p_mediaControl->SetEnabled( false );
189 InterfaceWindow::~InterfaceWindow()
192 fPlaylistWindow->ReallyQuit();
196 /*****************************************************************************
197 * InterfaceWindow::FrameResized
198 *****************************************************************************/
200 InterfaceWindow::FrameResized(float width, float height)
203 fMenuBar->MoveTo(r.LeftTop());
204 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
205 r.top += fMenuBar->Bounds().Height() + 1.0;
206 p_mediaControl->MoveTo(r.LeftTop());
207 p_mediaControl->ResizeTo(r.Width(), r.Height());
210 /*****************************************************************************
211 * InterfaceWindow::MessageReceived
212 *****************************************************************************/
213 void InterfaceWindow::MessageReceived( BMessage * p_message )
215 int playback_status; // remember playback state
216 playback_status = p_wrapper->InputStatus();
218 switch( p_message->what )
220 case B_ABOUT_REQUESTED:
222 BAlert* alert = new BAlert( VOUT_TITLE,
223 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
236 fFilePanel = new BFilePanel();
237 fFilePanel->SetTarget( this );
242 if (fPlaylistWindow->Lock())
244 if (fPlaylistWindow->IsHidden())
245 fPlaylistWindow->Show();
247 fPlaylistWindow->Activate();
248 fPlaylistWindow->Unlock();
253 const char *psz_device;
254 BString type( "dvd" );
255 if( p_message->FindString( "device", &psz_device ) == B_OK )
257 BString device( psz_device );
258 p_wrapper->openDisc( type, device, 0, 0 );
265 // this currently stops playback not nicely
266 if (playback_status > UNDEF_S)
269 p_wrapper->PlaylistStop();
270 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
275 /* starts playing in normal mode */
278 /* toggle between pause and play */
279 if (playback_status > UNDEF_S)
281 /* pause if currently playing */
282 if ( playback_status == PLAYING_S )
284 p_wrapper->PlaylistPause();
288 p_wrapper->PlaylistPlay();
293 /* Play a new file */
294 p_wrapper->PlaylistPlay();
299 /* cycle the fast playback modes */
300 if (playback_status > UNDEF_S)
302 p_wrapper->InputFaster();
307 /* cycle the slow playback modes */
308 if (playback_status > UNDEF_S)
310 p_wrapper->InputSlower();
315 /* restore speed to normal if already playing */
316 if (playback_status > UNDEF_S)
318 p_wrapper->PlaylistPlay();
323 /* handled by semaphores */
325 // volume related messages
327 /* adjust the volume */
328 if (playback_status > UNDEF_S)
330 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
331 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
337 if( p_wrapper->IsMuted() )
338 p_wrapper->VolumeRestore();
340 p_wrapper->VolumeMute();
341 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
345 if ( playback_status > UNDEF_S )
348 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
350 p_wrapper->ToggleLanguage( channel );
355 case SELECT_SUBTITLE:
356 if ( playback_status > UNDEF_S )
359 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
360 p_wrapper->ToggleSubtitle( subtitle );
364 // specific navigation messages
367 p_wrapper->PrevTitle();
372 p_wrapper->NextTitle();
376 if ( playback_status > UNDEF_S )
379 if ( p_message->FindInt32( "index", &index ) == B_OK )
380 p_wrapper->toggleTitle( index );
385 p_wrapper->PrevChapter();
390 p_wrapper->NextChapter();
394 if ( playback_status > UNDEF_S )
397 if ( p_message->FindInt32( "index", &index ) == B_OK )
398 p_wrapper->toggleChapter( index );
402 p_wrapper->PlaylistPrev();
405 p_wrapper->PlaylistNext();
407 // general next/prev functionality (skips to whatever makes most sense)
409 p_wrapper->navigatePrev();
412 p_wrapper->navigateNext();
414 // drag'n'drop and system messages
415 case B_REFS_RECEIVED:
418 // figure out if user wants files replaced or added
419 bool replace = false;
420 if ( p_message->WasDropped() )
421 replace = !( modifiers() & B_SHIFT_KEY );
422 // build list of files to be played from message contents
425 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
428 if ( path.InitCheck() == B_OK )
429 // the BString objects will be deleted
430 // by the wrapper function further down
431 files.AddItem( new BString( (char*)path.Path() ) );
433 // give the list to VLC
434 p_wrapper->openFiles(&files, replace);
439 case OPEN_PREFERENCES:
440 if( fPreferencesWindow->Lock() )
442 if (fPreferencesWindow->IsHidden())
443 fPreferencesWindow->Show();
445 fPreferencesWindow->Activate();
446 fPreferencesWindow->Unlock();
451 BWindow::MessageReceived( p_message );
457 /*****************************************************************************
458 * InterfaceWindow::QuitRequested
459 *****************************************************************************/
460 bool InterfaceWindow::QuitRequested()
462 p_wrapper->PlaylistStop();
463 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
472 /*****************************************************************************
473 * InterfaceWindow::updateInterface
474 *****************************************************************************/
475 void InterfaceWindow::updateInterface()
477 if( p_wrapper->HasInput() )
479 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
481 p_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
485 // p_mediaControl->SetEnabled( true );
486 bool hasTitles = p_wrapper->HasTitles();
487 bool hasChapters = p_wrapper->HasChapters();
488 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
489 p_wrapper->InputRate() );
490 p_mediaControl->SetProgress( p_wrapper->getTimeAsFloat() );
491 _SetMenusEnabled( true, hasChapters, hasTitles );
493 _UpdateSpeedMenu( p_wrapper->InputRate() );
495 // enable/disable skip buttons
498 p_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
499 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
501 if ( p_wrapper->HasAudio() )
503 p_mediaControl->SetAudioEnabled( true );
504 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
506 p_mediaControl->SetAudioEnabled( false );
510 // update playlist as well
511 if ( fPlaylistWindow->Lock() )
513 fPlaylistWindow->UpdatePlaylist();
514 fPlaylistWindow->Unlock();
519 _SetMenusEnabled( false );
520 // p_mediaControl->SetEnabled( false );
523 /* always force the user-specified volume */
524 /* FIXME : I'm quite sure there is a cleaner way to do this */
525 if( p_wrapper->GetVolume() != p_mediaControl->GetVolume() )
527 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
530 fLastUpdateTime = system_time();
533 /*****************************************************************************
534 * InterfaceWindow::IsStopped
535 *****************************************************************************/
537 InterfaceWindow::IsStopped() const
539 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
542 /*****************************************************************************
543 * InterfaceWindow::_UpdatePlaylist
544 *****************************************************************************/
546 InterfaceWindow::_UpdatePlaylist()
548 if ( fPlaylistWindow->Lock() )
550 fPlaylistWindow->UpdatePlaylist( true );
551 fPlaylistWindow->Unlock();
552 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
556 /*****************************************************************************
557 * InterfaceWindow::_SetMenusEnabled
558 *****************************************************************************/
560 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
569 if (fNextChapterMI->IsEnabled() != hasChapters)
570 fNextChapterMI->SetEnabled(hasChapters);
571 if (fPrevChapterMI->IsEnabled() != hasChapters)
572 fPrevChapterMI->SetEnabled(hasChapters);
573 if (fChapterMenu->IsEnabled() != hasChapters)
574 fChapterMenu->SetEnabled(hasChapters);
575 if (fNextTitleMI->IsEnabled() != hasTitles)
576 fNextTitleMI->SetEnabled(hasTitles);
577 if (fPrevTitleMI->IsEnabled() != hasTitles)
578 fPrevTitleMI->SetEnabled(hasTitles);
579 if (fTitleMenu->IsEnabled() != hasTitles)
580 fTitleMenu->SetEnabled(hasTitles);
581 if (fAudioMenu->IsEnabled() != hasFile)
582 fAudioMenu->SetEnabled(hasFile);
583 if (fNavigationMenu->IsEnabled() != hasFile)
584 fNavigationMenu->SetEnabled(hasFile);
585 if (fLanguageMenu->IsEnabled() != hasFile)
586 fLanguageMenu->SetEnabled(hasFile);
587 if (fSubtitlesMenu->IsEnabled() != hasFile)
588 fSubtitlesMenu->SetEnabled(hasFile);
589 if (fSpeedMenu->IsEnabled() != hasFile)
590 fSpeedMenu->SetEnabled(hasFile);
595 /*****************************************************************************
596 * InterfaceWindow::_UpdateSpeedMenu
597 *****************************************************************************/
599 InterfaceWindow::_UpdateSpeedMenu( int rate )
601 if ( rate == DEFAULT_RATE )
603 if ( !fNormalMI->IsMarked() )
604 fNormalMI->SetMarked( true );
606 else if ( rate < DEFAULT_RATE )
608 if ( !fFasterMI->IsMarked() )
609 fFasterMI->SetMarked( true );
613 if ( !fSlowerMI->IsMarked() )
614 fSlowerMI->SetMarked( true );
618 /*****************************************************************************
619 * InterfaceWindow::_InputStreamChanged
620 *****************************************************************************/
622 InterfaceWindow::_InputStreamChanged()
624 //printf("InterfaceWindow::_InputStreamChanged()\n");
625 // TODO: move more stuff from updateInterface() here!
627 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
630 /*****************************************************************************
631 * InterfaceWindow::_LoadSettings
632 *****************************************************************************/
634 InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
636 status_t ret = B_BAD_VALUE;
640 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
642 // passing folder is optional
644 ret = path.Append( folder );
645 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
647 BFile file( path.Path(), B_READ_ONLY );
648 if ( ( ret = file.InitCheck() ) == B_OK )
650 ret = message->Unflatten( &file );
659 /*****************************************************************************
660 * InterfaceWindow::_SaveSettings
661 *****************************************************************************/
663 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
665 status_t ret = B_BAD_VALUE;
669 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
671 // passing folder is optional
672 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
673 ret = create_directory( path.Path(), 0777 );
674 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
676 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
677 if ( ( ret = file.InitCheck() ) == B_OK )
679 ret = message->Flatten( &file );
688 /*****************************************************************************
689 * InterfaceWindow::_RestoreSettings
690 *****************************************************************************/
692 make_sure_frame_is_on_screen( BRect& frame )
694 BScreen screen( B_MAIN_SCREEN_ID );
695 if (frame.IsValid() && screen.IsValid()) {
696 if (!screen.Frame().Contains(frame)) {
697 // make sure frame fits in the screen
698 if (frame.Width() > screen.Frame().Width())
699 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
700 if (frame.Height() > screen.Frame().Height())
701 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
702 // frame is now at the most the size of the screen
703 if (frame.right > screen.Frame().right)
704 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
705 if (frame.bottom > screen.Frame().bottom)
706 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
707 if (frame.left < screen.Frame().left)
708 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
709 if (frame.top < screen.Frame().top)
710 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
718 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
719 float maxWidth, float maxHeight )
721 if ( frame.Width() < minWidth )
722 frame.right = frame.left + minWidth;
723 if ( frame.Height() < minHeight )
724 frame.bottom = frame.top + minHeight;
725 if ( frame.Width() > maxWidth )
726 frame.right = frame.left + maxWidth;
727 if ( frame.Height() > maxHeight )
728 frame.bottom = frame.top + maxHeight;
731 /*****************************************************************************
732 * InterfaceWindow::_RestoreSettings
733 *****************************************************************************/
735 InterfaceWindow::_RestoreSettings()
737 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
740 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
742 // sanity checks: make sure window is not too big/small
743 // and that it's not off-screen
744 float minWidth, maxWidth, minHeight, maxHeight;
745 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
747 make_sure_frame_is_within_limits( mainFrame,
748 minWidth, minHeight, maxWidth, maxHeight );
749 make_sure_frame_is_on_screen( mainFrame );
752 MoveTo( mainFrame.LeftTop() );
753 ResizeTo( mainFrame.Width(), mainFrame.Height() );
755 if ( fPlaylistWindow->Lock() )
758 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
760 // sanity checks: make sure window is not too big/small
761 // and that it's not off-screen
762 float minWidth, maxWidth, minHeight, maxHeight;
763 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
765 make_sure_frame_is_within_limits( playlistFrame,
766 minWidth, minHeight, maxWidth, maxHeight );
767 make_sure_frame_is_on_screen( playlistFrame );
769 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
770 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
774 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
778 if ( fPlaylistWindow->IsHidden() )
779 fPlaylistWindow->Show();
783 if ( !fPlaylistWindow->IsHidden() )
784 fPlaylistWindow->Hide();
788 fPlaylistWindow->Unlock();
793 /*****************************************************************************
794 * InterfaceWindow::_StoreSettings
795 *****************************************************************************/
797 InterfaceWindow::_StoreSettings()
799 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
800 fSettings->AddRect( "main frame", Frame() );
801 if ( fPlaylistWindow->Lock() )
803 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
804 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
805 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
806 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
807 fPlaylistWindow->Unlock();
809 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
812 /*****************************************************************************
814 *****************************************************************************/
815 CDMenu::CDMenu(const char *name)
820 /*****************************************************************************
822 *****************************************************************************/
827 /*****************************************************************************
828 * CDMenu::AttachedToWindow
829 *****************************************************************************/
830 void CDMenu::AttachedToWindow(void)
833 while (BMenuItem* item = RemoveItem(0L))
836 BMenu::AttachedToWindow();
839 /*****************************************************************************
841 *****************************************************************************/
842 int CDMenu::GetCD( const char *directory )
844 BVolumeRoster *volRoster;
849 char name[B_FILE_NAME_LENGTH];
853 volRoster = new BVolumeRoster();
855 dir = new BDirectory();
856 status = volRoster->GetNextVolume(vol);
857 status = vol->GetRootDirectory(dir);
858 while (status == B_NO_ERROR)
860 mounted = vol->GetName(name);
861 if ((mounted == B_OK) && /* Disk is currently Mounted */
862 (vol->IsReadOnly()) ) /* Disk is read-only */
865 fs_stat_dev(dev, &info);
869 i_dev = open( info.device_name, O_RDONLY );
873 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
875 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
878 msg = new BMessage( OPEN_DVD );
879 msg->AddString( "device", info.device_name );
880 BMenuItem *menu_item;
881 menu_item = new BMenuItem( name, msg );
882 AddItem( menu_item );
889 status = volRoster->GetNextVolume(vol);
894 /*****************************************************************************
895 * LanguageMenu::LanguageMenu
896 *****************************************************************************/
897 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
898 VlcWrapper *p_wrapper )
902 this->p_wrapper = p_wrapper;
905 /*****************************************************************************
906 * LanguageMenu::~LanguageMenu
907 *****************************************************************************/
908 LanguageMenu::~LanguageMenu()
912 /*****************************************************************************
913 * LanguageMenu::AttachedToWindow
914 *****************************************************************************/
915 void LanguageMenu::AttachedToWindow()
918 while ( BMenuItem* item = RemoveItem( 0L ) )
921 SetRadioMode( true );
923 BMenu::AttachedToWindow();
926 /*****************************************************************************
927 * LanguageMenu::_GetChannels
928 *****************************************************************************/
929 void LanguageMenu::_GetChannels()
934 if( ( list = p_wrapper->InputGetChannels( kind ) ) == NULL )
937 for( int i = 0; i < list->CountItems(); i++ )
939 item = (BMenuItem*)list->ItemAt( i );
943 if( list->CountItems() > 1 )
944 AddItem( new BSeparatorItem(), 1 );
948 /*****************************************************************************
949 * TitleMenu::TitleMenu
950 *****************************************************************************/
951 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
953 p_intf( p_interface )
957 /*****************************************************************************
958 * TitleMenu::~TitleMenu
959 *****************************************************************************/
960 TitleMenu::~TitleMenu()
964 /*****************************************************************************
965 * TitleMenu::AttachedToWindow
966 *****************************************************************************/
967 void TitleMenu::AttachedToWindow()
969 // make title menu empty
970 while ( BMenuItem* item = RemoveItem( 0L ) )
974 input_thread_t* input = p_intf->p_sys->p_input;
977 // lock stream access
978 vlc_mutex_lock( &input->stream.stream_lock );
979 // populate menu according to current stream
980 int32 numTitles = input->stream.i_area_nb;
984 for ( int32 i = 1; i < numTitles; i++ )
986 BMessage* message = new BMessage( TOGGLE_TITLE );
987 message->AddInt32( "index", i );
988 BString helper( "" );
990 BMenuItem* item = new BMenuItem( helper.String(), message );
991 item->SetMarked( input->stream.p_selected_area->i_id == i );
995 // done messing with stream
996 vlc_mutex_unlock( &input->stream.stream_lock );
999 BMenu::AttachedToWindow();
1003 /*****************************************************************************
1004 * ChapterMenu::ChapterMenu
1005 *****************************************************************************/
1006 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1008 p_intf( p_interface )
1012 /*****************************************************************************
1013 * ChapterMenu::~ChapterMenu
1014 *****************************************************************************/
1015 ChapterMenu::~ChapterMenu()
1019 /*****************************************************************************
1020 * ChapterMenu::AttachedToWindow
1021 *****************************************************************************/
1022 void ChapterMenu::AttachedToWindow()
1024 // make title menu empty
1025 while ( BMenuItem* item = RemoveItem( 0L ) )
1029 input_thread_t* input = p_intf->p_sys->p_input;
1032 // lock stream access
1033 vlc_mutex_lock( &input->stream.stream_lock );
1034 // populate menu according to current stream
1035 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1036 if ( numChapters > 1 )
1038 for ( int32 i = 0; i < numChapters; i++ )
1040 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1041 message->AddInt32( "index", i );
1042 BString helper( "" );
1044 BMenuItem* item = new BMenuItem( helper.String(), message );
1045 item->SetMarked( input->stream.p_selected_area->i_part == i );
1049 // done messing with stream
1050 vlc_mutex_unlock( &input->stream.stream_lock );
1052 BMenu::AttachedToWindow();