1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.17 2003/01/14 22:03: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 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 )
460 files.AddItem( new BString( (char*)path.Path() ) );
462 // give the list to VLC
463 p_wrapper->openFiles(&files, replace);
468 case OPEN_PREFERENCES:
469 if( fPreferencesWindow->Lock() )
471 if (fPreferencesWindow->IsHidden())
472 fPreferencesWindow->Show();
474 fPreferencesWindow->Activate();
475 fPreferencesWindow->Unlock();
480 BWindow::MessageReceived( p_message );
486 /*****************************************************************************
487 * InterfaceWindow::QuitRequested
488 *****************************************************************************/
489 bool InterfaceWindow::QuitRequested()
491 p_wrapper->PlaylistStop();
492 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
501 /*****************************************************************************
502 * InterfaceWindow::updateInterface
503 *****************************************************************************/
504 void InterfaceWindow::updateInterface()
506 if( p_wrapper->HasInput() )
508 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
510 p_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
514 // p_mediaControl->SetEnabled( true );
515 bool hasTitles = p_wrapper->HasTitles();
516 bool hasChapters = p_wrapper->HasChapters();
517 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
518 p_wrapper->InputRate() );
519 p_mediaControl->SetProgress( p_wrapper->getTimeAsFloat() );
520 _SetMenusEnabled( true, hasChapters, hasTitles );
522 _UpdateSpeedMenu( p_wrapper->InputRate() );
524 // enable/disable skip buttons
527 p_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
528 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
530 if ( p_wrapper->HasAudio() )
532 p_mediaControl->SetAudioEnabled( true );
533 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
535 p_mediaControl->SetAudioEnabled( false );
539 // update playlist as well
540 if ( fPlaylistWindow->Lock() )
542 fPlaylistWindow->UpdatePlaylist();
543 fPlaylistWindow->Unlock();
548 _SetMenusEnabled( false );
549 // p_mediaControl->SetEnabled( false );
552 /* always force the user-specified volume */
553 /* FIXME : I'm quite sure there is a cleaner way to do this */
554 if( p_wrapper->GetVolume() != p_mediaControl->GetVolume() )
556 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
559 fLastUpdateTime = system_time();
562 /*****************************************************************************
563 * InterfaceWindow::IsStopped
564 *****************************************************************************/
566 InterfaceWindow::IsStopped() const
568 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
571 /*****************************************************************************
572 * InterfaceWindow::_UpdatePlaylist
573 *****************************************************************************/
575 InterfaceWindow::_UpdatePlaylist()
577 if ( fPlaylistWindow->Lock() )
579 fPlaylistWindow->UpdatePlaylist( true );
580 fPlaylistWindow->Unlock();
581 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
585 /*****************************************************************************
586 * InterfaceWindow::_SetMenusEnabled
587 *****************************************************************************/
589 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
598 if (fNextChapterMI->IsEnabled() != hasChapters)
599 fNextChapterMI->SetEnabled(hasChapters);
600 if (fPrevChapterMI->IsEnabled() != hasChapters)
601 fPrevChapterMI->SetEnabled(hasChapters);
602 if (fChapterMenu->IsEnabled() != hasChapters)
603 fChapterMenu->SetEnabled(hasChapters);
604 if (fNextTitleMI->IsEnabled() != hasTitles)
605 fNextTitleMI->SetEnabled(hasTitles);
606 if (fPrevTitleMI->IsEnabled() != hasTitles)
607 fPrevTitleMI->SetEnabled(hasTitles);
608 if (fTitleMenu->IsEnabled() != hasTitles)
609 fTitleMenu->SetEnabled(hasTitles);
610 if (fAudioMenu->IsEnabled() != hasFile)
611 fAudioMenu->SetEnabled(hasFile);
612 if (fNavigationMenu->IsEnabled() != hasFile)
613 fNavigationMenu->SetEnabled(hasFile);
614 if (fLanguageMenu->IsEnabled() != hasFile)
615 fLanguageMenu->SetEnabled(hasFile);
616 if (fSubtitlesMenu->IsEnabled() != hasFile)
617 fSubtitlesMenu->SetEnabled(hasFile);
618 if (fSpeedMenu->IsEnabled() != hasFile)
619 fSpeedMenu->SetEnabled(hasFile);
624 /*****************************************************************************
625 * InterfaceWindow::_UpdateSpeedMenu
626 *****************************************************************************/
628 InterfaceWindow::_UpdateSpeedMenu( int rate )
630 if ( rate == DEFAULT_RATE )
632 if ( !fNormalMI->IsMarked() )
633 fNormalMI->SetMarked( true );
635 else if ( rate < DEFAULT_RATE )
637 if ( !fFasterMI->IsMarked() )
638 fFasterMI->SetMarked( true );
642 if ( !fSlowerMI->IsMarked() )
643 fSlowerMI->SetMarked( true );
647 /*****************************************************************************
648 * InterfaceWindow::_InputStreamChanged
649 *****************************************************************************/
651 InterfaceWindow::_InputStreamChanged()
653 //printf("InterfaceWindow::_InputStreamChanged()\n");
654 // TODO: move more stuff from updateInterface() here!
656 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
659 /*****************************************************************************
660 * InterfaceWindow::_LoadSettings
661 *****************************************************************************/
663 InterfaceWindow::_LoadSettings( 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
673 ret = path.Append( folder );
674 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
676 BFile file( path.Path(), B_READ_ONLY );
677 if ( ( ret = file.InitCheck() ) == B_OK )
679 ret = message->Unflatten( &file );
688 /*****************************************************************************
689 * InterfaceWindow::_SaveSettings
690 *****************************************************************************/
692 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
694 status_t ret = B_BAD_VALUE;
698 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
700 // passing folder is optional
701 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
702 ret = create_directory( path.Path(), 0777 );
703 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
705 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
706 if ( ( ret = file.InitCheck() ) == B_OK )
708 ret = message->Flatten( &file );
717 /*****************************************************************************
718 * InterfaceWindow::_RestoreSettings
719 *****************************************************************************/
721 make_sure_frame_is_on_screen( BRect& frame )
723 BScreen screen( B_MAIN_SCREEN_ID );
724 if (frame.IsValid() && screen.IsValid()) {
725 if (!screen.Frame().Contains(frame)) {
726 // make sure frame fits in the screen
727 if (frame.Width() > screen.Frame().Width())
728 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
729 if (frame.Height() > screen.Frame().Height())
730 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
731 // frame is now at the most the size of the screen
732 if (frame.right > screen.Frame().right)
733 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
734 if (frame.bottom > screen.Frame().bottom)
735 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
736 if (frame.left < screen.Frame().left)
737 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
738 if (frame.top < screen.Frame().top)
739 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
747 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
748 float maxWidth, float maxHeight )
750 if ( frame.Width() < minWidth )
751 frame.right = frame.left + minWidth;
752 if ( frame.Height() < minHeight )
753 frame.bottom = frame.top + minHeight;
754 if ( frame.Width() > maxWidth )
755 frame.right = frame.left + maxWidth;
756 if ( frame.Height() > maxHeight )
757 frame.bottom = frame.top + maxHeight;
760 /*****************************************************************************
761 * InterfaceWindow::_RestoreSettings
762 *****************************************************************************/
764 InterfaceWindow::_RestoreSettings()
766 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
769 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
771 // sanity checks: make sure window is not too big/small
772 // and that it's not off-screen
773 float minWidth, maxWidth, minHeight, maxHeight;
774 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
776 make_sure_frame_is_within_limits( mainFrame,
777 minWidth, minHeight, maxWidth, maxHeight );
778 make_sure_frame_is_on_screen( mainFrame );
781 MoveTo( mainFrame.LeftTop() );
782 ResizeTo( mainFrame.Width(), mainFrame.Height() );
784 if ( fPlaylistWindow->Lock() )
787 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
789 // sanity checks: make sure window is not too big/small
790 // and that it's not off-screen
791 float minWidth, maxWidth, minHeight, maxHeight;
792 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
794 make_sure_frame_is_within_limits( playlistFrame,
795 minWidth, minHeight, maxWidth, maxHeight );
796 make_sure_frame_is_on_screen( playlistFrame );
798 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
799 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
803 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
807 if ( fPlaylistWindow->IsHidden() )
808 fPlaylistWindow->Show();
812 if ( !fPlaylistWindow->IsHidden() )
813 fPlaylistWindow->Hide();
817 fPlaylistWindow->Unlock();
822 /*****************************************************************************
823 * InterfaceWindow::_StoreSettings
824 *****************************************************************************/
826 InterfaceWindow::_StoreSettings()
828 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
829 fSettings->AddRect( "main frame", Frame() );
830 if ( fPlaylistWindow->Lock() )
832 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
833 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
834 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
835 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
836 fPlaylistWindow->Unlock();
838 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
841 /*****************************************************************************
843 *****************************************************************************/
844 CDMenu::CDMenu(const char *name)
849 /*****************************************************************************
851 *****************************************************************************/
856 /*****************************************************************************
857 * CDMenu::AttachedToWindow
858 *****************************************************************************/
859 void CDMenu::AttachedToWindow(void)
862 while (BMenuItem* item = RemoveItem(0L))
865 BMenu::AttachedToWindow();
868 /*****************************************************************************
870 *****************************************************************************/
871 int CDMenu::GetCD( const char *directory )
873 BVolumeRoster *volRoster;
878 char name[B_FILE_NAME_LENGTH];
882 volRoster = new BVolumeRoster();
884 dir = new BDirectory();
885 status = volRoster->GetNextVolume(vol);
886 status = vol->GetRootDirectory(dir);
887 while (status == B_NO_ERROR)
889 mounted = vol->GetName(name);
890 if ((mounted == B_OK) && /* Disk is currently Mounted */
891 (vol->IsReadOnly()) ) /* Disk is read-only */
894 fs_stat_dev(dev, &info);
898 i_dev = open( info.device_name, O_RDONLY );
902 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
904 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
907 msg = new BMessage( OPEN_DVD );
908 msg->AddString( "device", info.device_name );
909 BMenuItem *menu_item;
910 menu_item = new BMenuItem( name, msg );
911 AddItem( menu_item );
918 status = volRoster->GetNextVolume(vol);
923 /*****************************************************************************
924 * LanguageMenu::LanguageMenu
925 *****************************************************************************/
926 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
927 VlcWrapper *p_wrapper )
931 this->p_wrapper = p_wrapper;
934 /*****************************************************************************
935 * LanguageMenu::~LanguageMenu
936 *****************************************************************************/
937 LanguageMenu::~LanguageMenu()
941 /*****************************************************************************
942 * LanguageMenu::AttachedToWindow
943 *****************************************************************************/
944 void LanguageMenu::AttachedToWindow()
947 while ( BMenuItem* item = RemoveItem( 0L ) )
950 SetRadioMode( true );
952 BMenu::AttachedToWindow();
955 /*****************************************************************************
956 * LanguageMenu::_GetChannels
957 *****************************************************************************/
958 void LanguageMenu::_GetChannels()
963 if( ( list = p_wrapper->InputGetChannels( kind ) ) == NULL )
966 for( int i = 0; i < list->CountItems(); i++ )
968 item = (BMenuItem*)list->ItemAt( i );
972 if( list->CountItems() > 1 )
973 AddItem( new BSeparatorItem(), 1 );
977 /*****************************************************************************
978 * TitleMenu::TitleMenu
979 *****************************************************************************/
980 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
982 p_intf( p_interface )
986 /*****************************************************************************
987 * TitleMenu::~TitleMenu
988 *****************************************************************************/
989 TitleMenu::~TitleMenu()
993 /*****************************************************************************
994 * TitleMenu::AttachedToWindow
995 *****************************************************************************/
996 void TitleMenu::AttachedToWindow()
998 // make title menu empty
999 while ( BMenuItem* item = RemoveItem( 0L ) )
1003 input_thread_t* input = p_intf->p_sys->p_input;
1006 // lock stream access
1007 vlc_mutex_lock( &input->stream.stream_lock );
1008 // populate menu according to current stream
1009 int32 numTitles = input->stream.i_area_nb;
1010 if ( numTitles > 1 )
1012 // disallow title 0!
1013 for ( int32 i = 1; i < numTitles; i++ )
1015 BMessage* message = new BMessage( TOGGLE_TITLE );
1016 message->AddInt32( "index", i );
1017 BString helper( "" );
1019 BMenuItem* item = new BMenuItem( helper.String(), message );
1020 item->SetMarked( input->stream.p_selected_area->i_id == i );
1024 // done messing with stream
1025 vlc_mutex_unlock( &input->stream.stream_lock );
1028 BMenu::AttachedToWindow();
1032 /*****************************************************************************
1033 * ChapterMenu::ChapterMenu
1034 *****************************************************************************/
1035 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1037 p_intf( p_interface )
1041 /*****************************************************************************
1042 * ChapterMenu::~ChapterMenu
1043 *****************************************************************************/
1044 ChapterMenu::~ChapterMenu()
1048 /*****************************************************************************
1049 * ChapterMenu::AttachedToWindow
1050 *****************************************************************************/
1051 void ChapterMenu::AttachedToWindow()
1053 // make title menu empty
1054 while ( BMenuItem* item = RemoveItem( 0L ) )
1058 input_thread_t* input = p_intf->p_sys->p_input;
1061 // lock stream access
1062 vlc_mutex_lock( &input->stream.stream_lock );
1063 // populate menu according to current stream
1064 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1065 if ( numChapters > 1 )
1067 for ( int32 i = 0; i < numChapters; i++ )
1069 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1070 message->AddInt32( "index", i );
1071 BString helper( "" );
1073 BMenuItem* item = new BMenuItem( helper.String(), message );
1074 item->SetMarked( input->stream.p_selected_area->i_part == i );
1078 // done messing with stream
1079 vlc_mutex_unlock( &input->stream.stream_lock );
1081 BMenu::AttachedToWindow();