1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.16 2003/01/14 14:48:55 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 // figure out if user wants files replaced or added
447 bool replace = false;
448 if ( p_message->WasDropped() )
449 replace = !( modifiers() & B_SHIFT_KEY );
450 // build list of files to be played from message contents
453 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
456 if ( path.InitCheck() == B_OK )
457 // the BString objects will be deleted
458 // by the wrapper function further down
459 files.AddItem( new BString( (char*)path.Path() ) );
461 // give the list to VLC
462 p_wrapper->openFiles(&files, replace);
467 case OPEN_PREFERENCES:
468 if( fPreferencesWindow->Lock() )
470 if (fPreferencesWindow->IsHidden())
471 fPreferencesWindow->Show();
473 fPreferencesWindow->Activate();
474 fPreferencesWindow->Unlock();
479 BWindow::MessageReceived( p_message );
485 /*****************************************************************************
486 * InterfaceWindow::QuitRequested
487 *****************************************************************************/
488 bool InterfaceWindow::QuitRequested()
490 p_wrapper->PlaylistStop();
491 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
500 /*****************************************************************************
501 * InterfaceWindow::updateInterface
502 *****************************************************************************/
503 void InterfaceWindow::updateInterface()
505 if( p_wrapper->HasInput() )
507 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
509 p_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
513 // p_mediaControl->SetEnabled( true );
514 bool hasTitles = p_wrapper->HasTitles();
515 bool hasChapters = p_wrapper->HasChapters();
516 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
517 p_wrapper->InputRate() );
518 p_mediaControl->SetProgress( p_wrapper->getTimeAsFloat() );
519 _SetMenusEnabled( true, hasChapters, hasTitles );
521 _UpdateSpeedMenu( p_wrapper->InputRate() );
523 // enable/disable skip buttons
526 p_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
527 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
529 if ( p_wrapper->HasAudio() )
531 p_mediaControl->SetAudioEnabled( true );
532 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
534 p_mediaControl->SetAudioEnabled( false );
538 // update playlist as well
539 if ( fPlaylistWindow->Lock() )
541 fPlaylistWindow->UpdatePlaylist();
542 fPlaylistWindow->Unlock();
547 _SetMenusEnabled( false );
548 // p_mediaControl->SetEnabled( false );
551 /* always force the user-specified volume */
552 /* FIXME : I'm quite sure there is a cleaner way to do this */
553 if( p_wrapper->GetVolume() != p_mediaControl->GetVolume() )
555 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
558 fLastUpdateTime = system_time();
561 /*****************************************************************************
562 * InterfaceWindow::IsStopped
563 *****************************************************************************/
565 InterfaceWindow::IsStopped() const
567 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
570 /*****************************************************************************
571 * InterfaceWindow::_UpdatePlaylist
572 *****************************************************************************/
574 InterfaceWindow::_UpdatePlaylist()
576 if ( fPlaylistWindow->Lock() )
578 fPlaylistWindow->UpdatePlaylist( true );
579 fPlaylistWindow->Unlock();
580 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
584 /*****************************************************************************
585 * InterfaceWindow::_SetMenusEnabled
586 *****************************************************************************/
588 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
597 if (fNextChapterMI->IsEnabled() != hasChapters)
598 fNextChapterMI->SetEnabled(hasChapters);
599 if (fPrevChapterMI->IsEnabled() != hasChapters)
600 fPrevChapterMI->SetEnabled(hasChapters);
601 if (fChapterMenu->IsEnabled() != hasChapters)
602 fChapterMenu->SetEnabled(hasChapters);
603 if (fNextTitleMI->IsEnabled() != hasTitles)
604 fNextTitleMI->SetEnabled(hasTitles);
605 if (fPrevTitleMI->IsEnabled() != hasTitles)
606 fPrevTitleMI->SetEnabled(hasTitles);
607 if (fTitleMenu->IsEnabled() != hasTitles)
608 fTitleMenu->SetEnabled(hasTitles);
609 if (fAudioMenu->IsEnabled() != hasFile)
610 fAudioMenu->SetEnabled(hasFile);
611 if (fNavigationMenu->IsEnabled() != hasFile)
612 fNavigationMenu->SetEnabled(hasFile);
613 if (fLanguageMenu->IsEnabled() != hasFile)
614 fLanguageMenu->SetEnabled(hasFile);
615 if (fSubtitlesMenu->IsEnabled() != hasFile)
616 fSubtitlesMenu->SetEnabled(hasFile);
617 if (fSpeedMenu->IsEnabled() != hasFile)
618 fSpeedMenu->SetEnabled(hasFile);
623 /*****************************************************************************
624 * InterfaceWindow::_UpdateSpeedMenu
625 *****************************************************************************/
627 InterfaceWindow::_UpdateSpeedMenu( int rate )
629 if ( rate == DEFAULT_RATE )
631 if ( !fNormalMI->IsMarked() )
632 fNormalMI->SetMarked( true );
634 else if ( rate < DEFAULT_RATE )
636 if ( !fFasterMI->IsMarked() )
637 fFasterMI->SetMarked( true );
641 if ( !fSlowerMI->IsMarked() )
642 fSlowerMI->SetMarked( true );
646 /*****************************************************************************
647 * InterfaceWindow::_InputStreamChanged
648 *****************************************************************************/
650 InterfaceWindow::_InputStreamChanged()
652 //printf("InterfaceWindow::_InputStreamChanged()\n");
653 // TODO: move more stuff from updateInterface() here!
655 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
658 /*****************************************************************************
659 * InterfaceWindow::_LoadSettings
660 *****************************************************************************/
662 InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
664 status_t ret = B_BAD_VALUE;
668 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
670 // passing folder is optional
672 ret = path.Append( folder );
673 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
675 BFile file( path.Path(), B_READ_ONLY );
676 if ( ( ret = file.InitCheck() ) == B_OK )
678 ret = message->Unflatten( &file );
687 /*****************************************************************************
688 * InterfaceWindow::_SaveSettings
689 *****************************************************************************/
691 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
693 status_t ret = B_BAD_VALUE;
697 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
699 // passing folder is optional
700 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
701 ret = create_directory( path.Path(), 0777 );
702 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
704 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
705 if ( ( ret = file.InitCheck() ) == B_OK )
707 ret = message->Flatten( &file );
716 /*****************************************************************************
717 * InterfaceWindow::_RestoreSettings
718 *****************************************************************************/
720 make_sure_frame_is_on_screen( BRect& frame )
722 BScreen screen( B_MAIN_SCREEN_ID );
723 if (frame.IsValid() && screen.IsValid()) {
724 if (!screen.Frame().Contains(frame)) {
725 // make sure frame fits in the screen
726 if (frame.Width() > screen.Frame().Width())
727 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
728 if (frame.Height() > screen.Frame().Height())
729 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
730 // frame is now at the most the size of the screen
731 if (frame.right > screen.Frame().right)
732 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
733 if (frame.bottom > screen.Frame().bottom)
734 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
735 if (frame.left < screen.Frame().left)
736 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
737 if (frame.top < screen.Frame().top)
738 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
746 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
747 float maxWidth, float maxHeight )
749 if ( frame.Width() < minWidth )
750 frame.right = frame.left + minWidth;
751 if ( frame.Height() < minHeight )
752 frame.bottom = frame.top + minHeight;
753 if ( frame.Width() > maxWidth )
754 frame.right = frame.left + maxWidth;
755 if ( frame.Height() > maxHeight )
756 frame.bottom = frame.top + maxHeight;
759 /*****************************************************************************
760 * InterfaceWindow::_RestoreSettings
761 *****************************************************************************/
763 InterfaceWindow::_RestoreSettings()
765 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
768 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
770 // sanity checks: make sure window is not too big/small
771 // and that it's not off-screen
772 float minWidth, maxWidth, minHeight, maxHeight;
773 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
775 make_sure_frame_is_within_limits( mainFrame,
776 minWidth, minHeight, maxWidth, maxHeight );
777 make_sure_frame_is_on_screen( mainFrame );
780 MoveTo( mainFrame.LeftTop() );
781 ResizeTo( mainFrame.Width(), mainFrame.Height() );
783 if ( fPlaylistWindow->Lock() )
786 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
788 // sanity checks: make sure window is not too big/small
789 // and that it's not off-screen
790 float minWidth, maxWidth, minHeight, maxHeight;
791 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
793 make_sure_frame_is_within_limits( playlistFrame,
794 minWidth, minHeight, maxWidth, maxHeight );
795 make_sure_frame_is_on_screen( playlistFrame );
797 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
798 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
802 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
806 if ( fPlaylistWindow->IsHidden() )
807 fPlaylistWindow->Show();
811 if ( !fPlaylistWindow->IsHidden() )
812 fPlaylistWindow->Hide();
816 fPlaylistWindow->Unlock();
821 /*****************************************************************************
822 * InterfaceWindow::_StoreSettings
823 *****************************************************************************/
825 InterfaceWindow::_StoreSettings()
827 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
828 fSettings->AddRect( "main frame", Frame() );
829 if ( fPlaylistWindow->Lock() )
831 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
832 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
833 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
834 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
835 fPlaylistWindow->Unlock();
837 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
840 /*****************************************************************************
842 *****************************************************************************/
843 CDMenu::CDMenu(const char *name)
848 /*****************************************************************************
850 *****************************************************************************/
855 /*****************************************************************************
856 * CDMenu::AttachedToWindow
857 *****************************************************************************/
858 void CDMenu::AttachedToWindow(void)
861 while (BMenuItem* item = RemoveItem(0L))
864 BMenu::AttachedToWindow();
867 /*****************************************************************************
869 *****************************************************************************/
870 int CDMenu::GetCD( const char *directory )
872 BVolumeRoster *volRoster;
877 char name[B_FILE_NAME_LENGTH];
881 volRoster = new BVolumeRoster();
883 dir = new BDirectory();
884 status = volRoster->GetNextVolume(vol);
885 status = vol->GetRootDirectory(dir);
886 while (status == B_NO_ERROR)
888 mounted = vol->GetName(name);
889 if ((mounted == B_OK) && /* Disk is currently Mounted */
890 (vol->IsReadOnly()) ) /* Disk is read-only */
893 fs_stat_dev(dev, &info);
897 i_dev = open( info.device_name, O_RDONLY );
901 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
903 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
906 msg = new BMessage( OPEN_DVD );
907 msg->AddString( "device", info.device_name );
908 BMenuItem *menu_item;
909 menu_item = new BMenuItem( name, msg );
910 AddItem( menu_item );
917 status = volRoster->GetNextVolume(vol);
922 /*****************************************************************************
923 * LanguageMenu::LanguageMenu
924 *****************************************************************************/
925 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
926 VlcWrapper *p_wrapper )
930 this->p_wrapper = p_wrapper;
933 /*****************************************************************************
934 * LanguageMenu::~LanguageMenu
935 *****************************************************************************/
936 LanguageMenu::~LanguageMenu()
940 /*****************************************************************************
941 * LanguageMenu::AttachedToWindow
942 *****************************************************************************/
943 void LanguageMenu::AttachedToWindow()
946 while ( BMenuItem* item = RemoveItem( 0L ) )
949 SetRadioMode( true );
951 BMenu::AttachedToWindow();
954 /*****************************************************************************
955 * LanguageMenu::_GetChannels
956 *****************************************************************************/
957 void LanguageMenu::_GetChannels()
962 if( ( list = p_wrapper->InputGetChannels( kind ) ) == NULL )
965 for( int i = 0; i < list->CountItems(); i++ )
967 item = (BMenuItem*)list->ItemAt( i );
971 if( list->CountItems() > 1 )
972 AddItem( new BSeparatorItem(), 1 );
976 /*****************************************************************************
977 * TitleMenu::TitleMenu
978 *****************************************************************************/
979 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
981 p_intf( p_interface )
985 /*****************************************************************************
986 * TitleMenu::~TitleMenu
987 *****************************************************************************/
988 TitleMenu::~TitleMenu()
992 /*****************************************************************************
993 * TitleMenu::AttachedToWindow
994 *****************************************************************************/
995 void TitleMenu::AttachedToWindow()
997 // make title menu empty
998 while ( BMenuItem* item = RemoveItem( 0L ) )
1002 input_thread_t* input = p_intf->p_sys->p_input;
1005 // lock stream access
1006 vlc_mutex_lock( &input->stream.stream_lock );
1007 // populate menu according to current stream
1008 int32 numTitles = input->stream.i_area_nb;
1009 if ( numTitles > 1 )
1011 // disallow title 0!
1012 for ( int32 i = 1; i < numTitles; i++ )
1014 BMessage* message = new BMessage( TOGGLE_TITLE );
1015 message->AddInt32( "index", i );
1016 BString helper( "" );
1018 BMenuItem* item = new BMenuItem( helper.String(), message );
1019 item->SetMarked( input->stream.p_selected_area->i_id == i );
1023 // done messing with stream
1024 vlc_mutex_unlock( &input->stream.stream_lock );
1027 BMenu::AttachedToWindow();
1031 /*****************************************************************************
1032 * ChapterMenu::ChapterMenu
1033 *****************************************************************************/
1034 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1036 p_intf( p_interface )
1040 /*****************************************************************************
1041 * ChapterMenu::~ChapterMenu
1042 *****************************************************************************/
1043 ChapterMenu::~ChapterMenu()
1047 /*****************************************************************************
1048 * ChapterMenu::AttachedToWindow
1049 *****************************************************************************/
1050 void ChapterMenu::AttachedToWindow()
1052 // make title menu empty
1053 while ( BMenuItem* item = RemoveItem( 0L ) )
1057 input_thread_t* input = p_intf->p_sys->p_input;
1060 // lock stream access
1061 vlc_mutex_lock( &input->stream.stream_lock );
1062 // populate menu according to current stream
1063 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1064 if ( numChapters > 1 )
1066 for ( int32 i = 0; i < numChapters; i++ )
1068 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1069 message->AddInt32( "index", i );
1070 BString helper( "" );
1072 BMenuItem* item = new BMenuItem( helper.String(), message );
1073 item->SetMarked( input->stream.p_selected_area->i_part == i );
1077 // done messing with stream
1078 vlc_mutex_unlock( &input->stream.stream_lock );
1080 BMenu::AttachedToWindow();