1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.8 2002/11/23 15:00:54 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 */
47 #include "MediaControlView.h"
48 #include "PlayListWindow.h"
49 #include "PreferencesWindow.h"
50 #include "VlcWrapper.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 ),
67 fLastUpdateTime( system_time() ),
68 fSettings( new BMessage( 'sett' ) )
71 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
73 fPlaylistIsEmpty = (p_playlist->i_size < 0);
75 fPlaylistWindow = new PlayListWindow( BRect( 100.0, 100.0, 400.0, 350.0 ),
80 BScreen *p_screen = new BScreen();
81 BRect screen_rect = p_screen->Frame();
84 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
85 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
86 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
87 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
88 fPreferencesWindow = new PreferencesWindow( window_rect,
93 SetName( "interface" );
94 SetTitle( VOUT_TITLE );
96 // the media control view
97 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
99 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
100 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
103 p_mediaControl->GetPreferredSize( &width, &height );
105 // set up the main menu
106 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
107 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
109 // make menu bar resize to correct height
110 float menuWidth, menuHeight;
111 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
112 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
113 // take care of proper size for ourself
114 height += fMenuBar->Bounds().Height();
115 ResizeTo( width, height );
117 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
118 AddChild( fMenuBar );
119 AddChild( p_mediaControl );
122 BMenu* fileMenu = new BMenu( "File" );
123 fMenuBar->AddItem( fileMenu );
124 fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
125 new BMessage( OPEN_FILE ), 'O') );
127 fileMenu->AddItem( new CDMenu( "Open Disc" ) );
129 fileMenu->AddSeparatorItem();
130 fileMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
131 new BMessage( OPEN_PLAYLIST ), 'P') );
133 fileMenu->AddSeparatorItem();
134 BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
135 new BMessage( B_ABOUT_REQUESTED ), 'A');
136 item->SetTarget( be_app );
137 fileMenu->AddItem( item );
138 fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
140 fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_intf);
141 fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_intf);
143 /* Add the Audio menu */
144 fAudioMenu = new BMenu( "Audio" );
145 fMenuBar->AddItem ( fAudioMenu );
146 fAudioMenu->AddItem( fLanguageMenu );
147 fAudioMenu->AddItem( fSubtitlesMenu );
149 fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
150 fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
151 fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
152 fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
154 /* Add the Navigation menu */
155 fNavigationMenu = new BMenu( "Navigation" );
156 fMenuBar->AddItem( fNavigationMenu );
157 fNavigationMenu->AddItem( fPrevTitleMI );
158 fNavigationMenu->AddItem( fNextTitleMI );
159 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
160 fNavigationMenu->AddSeparatorItem();
161 fNavigationMenu->AddItem( fPrevChapterMI );
162 fNavigationMenu->AddItem( fNextChapterMI );
163 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
165 /* Add the Speed menu */
166 fSpeedMenu = new BMenu( "Speed" );
167 fSpeedMenu->SetRadioMode( true );
168 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
169 fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
170 fNormalMI->SetMarked(true); // default to normal speed
171 fSpeedMenu->AddItem( fNormalMI );
172 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
173 fSpeedMenu->SetTargetForItems( this );
174 fMenuBar->AddItem( fSpeedMenu );
176 /* Add the Settings menu */
177 fSettingsMenu = new BMenu( "Settings" );
178 fSettingsMenu->AddItem( fPreferencesMI =
179 new BMenuItem( "Preferences", new BMessage( OPEN_PREFERENCES ) ) );
180 fMenuBar->AddItem( fSettingsMenu );
182 // prepare fow showing
183 _SetMenusEnabled(false);
190 InterfaceWindow::~InterfaceWindow()
193 fPlaylistWindow->ReallyQuit();
197 /*****************************************************************************
198 * InterfaceWindow::FrameResized
199 *****************************************************************************/
201 InterfaceWindow::FrameResized(float width, float height)
204 fMenuBar->MoveTo(r.LeftTop());
205 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
206 r.top += fMenuBar->Bounds().Height() + 1.0;
207 p_mediaControl->MoveTo(r.LeftTop());
208 p_mediaControl->ResizeTo(r.Width(), r.Height());
211 /*****************************************************************************
212 * InterfaceWindow::MessageReceived
213 *****************************************************************************/
214 void InterfaceWindow::MessageReceived( BMessage * p_message )
216 int playback_status; // remember playback state
217 playback_status = p_intf->p_sys->p_vlc_wrapper->inputGetStatus();
219 switch( p_message->what )
221 case B_ABOUT_REQUESTED:
223 BAlert* alert = new BAlert( VOUT_TITLE,
224 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
237 fFilePanel = new BFilePanel();
238 fFilePanel->SetTarget( this );
243 if (fPlaylistWindow->Lock())
245 if (fPlaylistWindow->IsHidden())
246 fPlaylistWindow->Show();
248 fPlaylistWindow->Activate();
249 fPlaylistWindow->Unlock();
254 const char *psz_device;
255 BString type( "dvd" );
256 if( p_message->FindString( "device", &psz_device ) == B_OK )
258 BString device( psz_device );
259 p_intf->p_sys->p_vlc_wrapper->openDisc( type, device, 0, 0 );
266 // this currently stops playback not nicely
267 if (playback_status > UNDEF_S)
269 p_intf->p_sys->p_vlc_wrapper->volume_mute();
271 p_intf->p_sys->p_vlc_wrapper->playlistStop();
272 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
277 /* starts playing in normal mode */
280 /* toggle between pause and play */
281 if (playback_status > UNDEF_S)
283 /* pause if currently playing */
284 if ( playback_status == PLAYING_S )
286 p_intf->p_sys->p_vlc_wrapper->volume_mute();
288 p_intf->p_sys->p_vlc_wrapper->playlistPause();
292 p_intf->p_sys->p_vlc_wrapper->volume_restore();
293 p_intf->p_sys->p_vlc_wrapper->playlistPlay();
298 /* Play a new file */
299 p_intf->p_sys->p_vlc_wrapper->playlistPlay();
304 /* cycle the fast playback modes */
305 if (playback_status > UNDEF_S)
307 p_intf->p_sys->p_vlc_wrapper->volume_mute();
309 p_intf->p_sys->p_vlc_wrapper->playFaster();
314 /* cycle the slow playback modes */
315 if (playback_status > UNDEF_S)
317 p_intf->p_sys->p_vlc_wrapper->volume_mute();
319 p_intf->p_sys->p_vlc_wrapper->playSlower();
324 /* restore speed to normal if already playing */
325 if (playback_status > UNDEF_S)
327 p_intf->p_sys->p_vlc_wrapper->volume_restore();
328 p_intf->p_sys->p_vlc_wrapper->playlistPlay();
333 /* handled by semaphores */
335 // volume related messages
337 /* adjust the volume */
338 if (playback_status > UNDEF_S)
340 p_intf->p_sys->p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
341 p_mediaControl->SetMuted( p_intf->p_sys->p_vlc_wrapper->is_muted() );
347 p_intf->p_sys->p_vlc_wrapper->toggle_mute();
348 p_mediaControl->SetMuted( p_intf->p_sys->p_vlc_wrapper->is_muted() );
352 if ( playback_status > UNDEF_S )
355 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
357 p_intf->p_sys->p_vlc_wrapper->toggleLanguage( channel );
358 // vlc seems to remember the volume for every channel,
359 // but I would assume that to be somewhat annoying to the user
360 // the next call will also unmute the volume, which is probably
361 // desired as well, because if the user selects another language,
362 // he probably wants to hear the change as well
363 snooze( 400000 ); // we have to wait a bit, or the change will be reverted
364 p_intf->p_sys->p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
369 case SELECT_SUBTITLE:
370 if ( playback_status > UNDEF_S )
373 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
374 p_intf->p_sys->p_vlc_wrapper->toggleSubtitle( subtitle );
378 // specific navigation messages
382 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id - 1;
384 /* Disallow area 0 since it is used for video_ts.vob */
387 p_intf->p_sys->p_vlc_wrapper->toggleTitle(i_id);
395 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id + 1;
397 if( i_id < p_intf->p_sys->p_input->stream.i_area_nb )
399 p_intf->p_sys->p_vlc_wrapper->toggleTitle(i_id);
404 if ( playback_status > UNDEF_S )
407 if ( p_message->FindInt32( "index", &index ) == B_OK )
408 p_intf->p_sys->p_vlc_wrapper->toggleTitle( index );
415 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part - 1;
419 p_intf->p_sys->p_vlc_wrapper->toggleChapter(i_id);
427 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part + 1;
431 p_intf->p_sys->p_vlc_wrapper->toggleChapter(i_id);
436 if ( playback_status > UNDEF_S )
439 if ( p_message->FindInt32( "index", &index ) == B_OK )
440 p_intf->p_sys->p_vlc_wrapper->toggleChapter( index );
444 p_intf->p_sys->p_vlc_wrapper->playlistPrev();
447 p_intf->p_sys->p_vlc_wrapper->playlistNext();
449 // general next/prev functionality (skips to whatever makes most sense)
451 p_intf->p_sys->p_vlc_wrapper->navigatePrev();
454 p_intf->p_sys->p_vlc_wrapper->navigateNext();
456 // drag'n'drop and system messages
457 case B_REFS_RECEIVED:
460 // figure out if user wants files replaced or added
461 bool replace = false;
462 if ( p_message->WasDropped() )
463 replace = !( modifiers() & B_SHIFT_KEY );
464 // build list of files to be played from message contents
467 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
470 if ( path.InitCheck() == B_OK )
471 // the BString objects will be deleted
472 // by the wrapper function further down
473 files.AddItem( new BString( (char*)path.Path() ) );
475 // give the list to VLC
476 p_intf->p_sys->p_vlc_wrapper->openFiles(&files, replace);
481 case OPEN_PREFERENCES:
482 if( fPreferencesWindow->Lock() )
484 if (fPreferencesWindow->IsHidden())
485 fPreferencesWindow->Show();
487 fPreferencesWindow->Activate();
488 fPreferencesWindow->Unlock();
493 BWindow::MessageReceived( p_message );
499 /*****************************************************************************
500 * InterfaceWindow::QuitRequested
501 *****************************************************************************/
502 bool InterfaceWindow::QuitRequested()
504 if (p_intf->p_sys->p_input)
506 p_intf->p_sys->p_vlc_wrapper->volume_mute();
508 p_intf->p_sys->p_vlc_wrapper->playlistStop();
509 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
519 /*****************************************************************************
520 * InterfaceWindow::updateInterface
521 *****************************************************************************/
522 void InterfaceWindow::updateInterface()
524 input_thread_t* input = p_intf->p_sys->p_input;
527 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
529 p_intf->p_sys->p_vlc_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
533 bool hasTitles = input->stream.i_area_nb > 1;
534 bool hasChapters = input->stream.p_selected_area->i_part_nb > 1;
535 p_mediaControl->SetStatus( input->stream.control.i_status,
536 input->stream.control.i_rate );
537 p_mediaControl->SetProgress( input->stream.p_selected_area->i_tell,
538 input->stream.p_selected_area->i_size );
539 _SetMenusEnabled( true, hasChapters, hasTitles );
541 _UpdateSpeedMenu( input->stream.control.i_rate );
543 // enable/disable skip buttons
546 p_intf->p_sys->p_vlc_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
547 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
549 if ( p_intf->p_sys->p_vlc_wrapper->has_audio() )
551 p_mediaControl->SetAudioEnabled( true );
552 p_mediaControl->SetMuted( p_intf->p_sys->p_vlc_wrapper->is_muted() );
554 p_mediaControl->SetAudioEnabled( false );
556 if ( input != fInputThread )
558 fInputThread = input;
559 _InputStreamChanged();
564 // update playlist as well
565 if ( fPlaylistWindow->Lock() )
567 fPlaylistWindow->UpdatePlaylist();
568 fPlaylistWindow->Unlock();
572 _SetMenusEnabled(false);
574 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
576 if ( fPlaylistIsEmpty != ( p_playlist->i_size < 0) )
580 fPlaylistIsEmpty = !fPlaylistIsEmpty;
581 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
585 if ( input != fInputThread )
586 fInputThread = input;
588 fLastUpdateTime = system_time();
591 /*****************************************************************************
592 * InterfaceWindow::IsStopped
593 *****************************************************************************/
595 InterfaceWindow::IsStopped() const
597 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
600 /*****************************************************************************
601 * InterfaceWindow::_UpdatePlaylist
602 *****************************************************************************/
604 InterfaceWindow::_UpdatePlaylist()
606 if ( fPlaylistWindow->Lock() )
608 fPlaylistWindow->UpdatePlaylist( true );
609 fPlaylistWindow->Unlock();
610 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
611 fPlaylistIsEmpty = p_playlist->i_size < 1;
612 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
616 /*****************************************************************************
617 * InterfaceWindow::_SetMenusEnabled
618 *****************************************************************************/
620 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
629 if (fNextChapterMI->IsEnabled() != hasChapters)
630 fNextChapterMI->SetEnabled(hasChapters);
631 if (fPrevChapterMI->IsEnabled() != hasChapters)
632 fPrevChapterMI->SetEnabled(hasChapters);
633 if (fChapterMenu->IsEnabled() != hasChapters)
634 fChapterMenu->SetEnabled(hasChapters);
635 if (fNextTitleMI->IsEnabled() != hasTitles)
636 fNextTitleMI->SetEnabled(hasTitles);
637 if (fPrevTitleMI->IsEnabled() != hasTitles)
638 fPrevTitleMI->SetEnabled(hasTitles);
639 if (fTitleMenu->IsEnabled() != hasTitles)
640 fTitleMenu->SetEnabled(hasTitles);
641 if (fAudioMenu->IsEnabled() != hasFile)
642 fAudioMenu->SetEnabled(hasFile);
643 if (fNavigationMenu->IsEnabled() != hasFile)
644 fNavigationMenu->SetEnabled(hasFile);
645 if (fLanguageMenu->IsEnabled() != hasFile)
646 fLanguageMenu->SetEnabled(hasFile);
647 if (fSubtitlesMenu->IsEnabled() != hasFile)
648 fSubtitlesMenu->SetEnabled(hasFile);
649 if (fSpeedMenu->IsEnabled() != hasFile)
650 fSpeedMenu->SetEnabled(hasFile);
655 /*****************************************************************************
656 * InterfaceWindow::_UpdateSpeedMenu
657 *****************************************************************************/
659 InterfaceWindow::_UpdateSpeedMenu( int rate )
661 if ( rate == DEFAULT_RATE )
663 if ( !fNormalMI->IsMarked() )
664 fNormalMI->SetMarked( true );
666 else if ( rate < DEFAULT_RATE )
668 if ( !fFasterMI->IsMarked() )
669 fFasterMI->SetMarked( true );
673 if ( !fSlowerMI->IsMarked() )
674 fSlowerMI->SetMarked( true );
678 /*****************************************************************************
679 * InterfaceWindow::_InputStreamChanged
680 *****************************************************************************/
682 InterfaceWindow::_InputStreamChanged()
684 //printf("InterfaceWindow::_InputStreamChanged()\n");
685 // TODO: move more stuff from updateInterface() here!
687 p_intf->p_sys->p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
690 /*****************************************************************************
691 * InterfaceWindow::_LoadSettings
692 *****************************************************************************/
694 InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
696 status_t ret = B_BAD_VALUE;
700 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
702 // passing folder is optional
704 ret = path.Append( folder );
705 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
707 BFile file( path.Path(), B_READ_ONLY );
708 if ( ( ret = file.InitCheck() ) == B_OK )
710 ret = message->Unflatten( &file );
719 /*****************************************************************************
720 * InterfaceWindow::_SaveSettings
721 *****************************************************************************/
723 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
725 status_t ret = B_BAD_VALUE;
729 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
731 // passing folder is optional
732 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
733 ret = create_directory( path.Path(), 0777 );
734 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
736 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
737 if ( ( ret = file.InitCheck() ) == B_OK )
739 ret = message->Flatten( &file );
748 /*****************************************************************************
749 * InterfaceWindow::_RestoreSettings
750 *****************************************************************************/
752 make_sure_frame_is_on_screen( BRect& frame )
754 BScreen screen( B_MAIN_SCREEN_ID );
755 if (frame.IsValid() && screen.IsValid()) {
756 if (!screen.Frame().Contains(frame)) {
757 // make sure frame fits in the screen
758 if (frame.Width() > screen.Frame().Width())
759 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
760 if (frame.Height() > screen.Frame().Height())
761 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
762 // frame is now at the most the size of the screen
763 if (frame.right > screen.Frame().right)
764 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
765 if (frame.bottom > screen.Frame().bottom)
766 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
767 if (frame.left < screen.Frame().left)
768 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
769 if (frame.top < screen.Frame().top)
770 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
778 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
779 float maxWidth, float maxHeight )
781 if ( frame.Width() < minWidth )
782 frame.right = frame.left + minWidth;
783 if ( frame.Height() < minHeight )
784 frame.bottom = frame.top + minHeight;
785 if ( frame.Width() > maxWidth )
786 frame.right = frame.left + maxWidth;
787 if ( frame.Height() > maxHeight )
788 frame.bottom = frame.top + maxHeight;
791 /*****************************************************************************
792 * InterfaceWindow::_RestoreSettings
793 *****************************************************************************/
795 InterfaceWindow::_RestoreSettings()
797 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
800 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
802 // sanity checks: make sure window is not too big/small
803 // and that it's not off-screen
804 float minWidth, maxWidth, minHeight, maxHeight;
805 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
807 make_sure_frame_is_within_limits( mainFrame,
808 minWidth, minHeight, maxWidth, maxHeight );
809 make_sure_frame_is_on_screen( mainFrame );
812 MoveTo( mainFrame.LeftTop() );
813 ResizeTo( mainFrame.Width(), mainFrame.Height() );
815 if ( fPlaylistWindow->Lock() )
818 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
820 // sanity checks: make sure window is not too big/small
821 // and that it's not off-screen
822 float minWidth, maxWidth, minHeight, maxHeight;
823 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
825 make_sure_frame_is_within_limits( playlistFrame,
826 minWidth, minHeight, maxWidth, maxHeight );
827 make_sure_frame_is_on_screen( playlistFrame );
829 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
830 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
834 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
838 if ( fPlaylistWindow->IsHidden() )
839 fPlaylistWindow->Show();
843 if ( !fPlaylistWindow->IsHidden() )
844 fPlaylistWindow->Hide();
848 fPlaylistWindow->Unlock();
853 /*****************************************************************************
854 * InterfaceWindow::_StoreSettings
855 *****************************************************************************/
857 InterfaceWindow::_StoreSettings()
859 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
860 fSettings->AddRect( "main frame", Frame() );
861 if ( fPlaylistWindow->Lock() )
863 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
864 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
865 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
866 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
867 fPlaylistWindow->Unlock();
869 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
872 /*****************************************************************************
874 *****************************************************************************/
875 CDMenu::CDMenu(const char *name)
880 /*****************************************************************************
882 *****************************************************************************/
887 /*****************************************************************************
888 * CDMenu::AttachedToWindow
889 *****************************************************************************/
890 void CDMenu::AttachedToWindow(void)
893 while (BMenuItem* item = RemoveItem(0L))
896 BMenu::AttachedToWindow();
899 /*****************************************************************************
901 *****************************************************************************/
902 int CDMenu::GetCD( const char *directory )
904 BVolumeRoster *volRoster;
909 char name[B_FILE_NAME_LENGTH];
913 volRoster = new BVolumeRoster();
915 dir = new BDirectory();
916 status = volRoster->GetNextVolume(vol);
917 status = vol->GetRootDirectory(dir);
918 while (status == B_NO_ERROR)
920 mounted = vol->GetName(name);
921 if ((mounted == B_OK) && /* Disk is currently Mounted */
922 (vol->IsReadOnly()) ) /* Disk is read-only */
925 fs_stat_dev(dev, &info);
929 i_dev = open( info.device_name, O_RDONLY );
933 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
935 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
938 msg = new BMessage( OPEN_DVD );
939 msg->AddString( "device", info.device_name );
940 BMenuItem *menu_item;
941 menu_item = new BMenuItem( name, msg );
942 AddItem( menu_item );
949 status = volRoster->GetNextVolume(vol);
954 /*****************************************************************************
955 * LanguageMenu::LanguageMenu
956 *****************************************************************************/
957 LanguageMenu::LanguageMenu(const char *name, int menu_kind,
958 intf_thread_t *p_interface)
962 p_intf = p_interface;
965 /*****************************************************************************
966 * LanguageMenu::~LanguageMenu
967 *****************************************************************************/
968 LanguageMenu::~LanguageMenu()
972 /*****************************************************************************
973 * LanguageMenu::AttachedToWindow
974 *****************************************************************************/
975 void LanguageMenu::AttachedToWindow()
978 while ( BMenuItem* item = RemoveItem( 0L ) )
981 SetRadioMode( true );
983 BMenu::AttachedToWindow();
986 /*****************************************************************************
987 * LanguageMenu::_GetChannels
988 *****************************************************************************/
989 void LanguageMenu::_GetChannels()
994 BMenuItem *menu_item;
996 es_descriptor_t *p_es = NULL;
998 // Insert the "None" item if in subtitle mode
999 if( kind != AUDIO_ES ) //subtitle
1001 msg = new BMessage( SELECT_SUBTITLE );
1002 msg->AddInt32( "subtitle", -1 );
1003 menu_item = new BMenuItem( "None", msg );
1004 AddItem( menu_item );
1005 menu_item->SetMarked( true );
1008 input_thread_t* input = p_intf->p_sys->p_input;
1011 vlc_mutex_lock( &input->stream.stream_lock );
1012 for( i = 0; i < input->stream.i_selected_es_number; i++ )
1014 if( kind == input->stream.pp_selected_es[i]->i_cat )
1015 p_es = input->stream.pp_selected_es[i];
1018 int32 addedItems = 0;
1019 bool emptyItemAdded = false;
1020 uint32 what = kind == AUDIO_ES ? SELECT_CHANNEL : SELECT_SUBTITLE;
1021 const char* fieldName = kind == AUDIO_ES ? "channel" : "subtitle";
1023 for ( i = 0; i < input->stream.i_es_number; i++ )
1025 if ( kind == input->stream.pp_es[i]->i_cat )
1027 bool addItem = true;
1028 psz_name = input->stream.pp_es[i]->psz_desc;
1029 // workarround for irritating empty strings
1030 if ( strcmp(psz_name, "") == 0 )
1032 // if ( kind != AUDIO_ES ) // don't add empty subtitle items, they don't work anyways
1036 if (!emptyItemAdded)
1038 psz_name = "<default>";
1039 emptyItemAdded = true;
1042 psz_name = "<unkown>";
1048 msg = new BMessage( what );
1049 msg->AddInt32( fieldName, i );
1050 menu_item = new BMenuItem( psz_name, msg );
1051 AddItem( menu_item );
1052 b_active = ( p_es == input->stream.pp_es[i] );
1053 menu_item->SetMarked( b_active );
1057 vlc_mutex_unlock( &input->stream.stream_lock );
1059 // enhance readability and separate first item from rest
1060 if ( ( emptyItemAdded || kind != AUDIO_ES ) && addedItems > 1 )
1061 AddItem( new BSeparatorItem(), 1 );
1067 /*****************************************************************************
1068 * TitleMenu::TitleMenu
1069 *****************************************************************************/
1070 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1072 p_intf( p_interface )
1076 /*****************************************************************************
1077 * TitleMenu::~TitleMenu
1078 *****************************************************************************/
1079 TitleMenu::~TitleMenu()
1083 /*****************************************************************************
1084 * TitleMenu::AttachedToWindow
1085 *****************************************************************************/
1086 void TitleMenu::AttachedToWindow()
1088 // make title menu empty
1089 while ( BMenuItem* item = RemoveItem( 0L ) )
1092 input_thread_t* input = p_intf->p_sys->p_input;
1095 // lock stream access
1096 vlc_mutex_lock( &input->stream.stream_lock );
1097 // populate menu according to current stream
1098 int32 numTitles = input->stream.i_area_nb;
1099 if ( numTitles > 1 )
1101 // disallow title 0!
1102 for ( int32 i = 1; i < numTitles; i++ )
1104 BMessage* message = new BMessage( TOGGLE_TITLE );
1105 message->AddInt32( "index", i );
1106 BString helper( "" );
1108 BMenuItem* item = new BMenuItem( helper.String(), message );
1109 item->SetMarked( input->stream.p_selected_area->i_id == i );
1113 // done messing with stream
1114 vlc_mutex_unlock( &input->stream.stream_lock );
1116 BMenu::AttachedToWindow();
1120 /*****************************************************************************
1121 * ChapterMenu::ChapterMenu
1122 *****************************************************************************/
1123 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1125 p_intf( p_interface )
1129 /*****************************************************************************
1130 * ChapterMenu::~ChapterMenu
1131 *****************************************************************************/
1132 ChapterMenu::~ChapterMenu()
1136 /*****************************************************************************
1137 * ChapterMenu::AttachedToWindow
1138 *****************************************************************************/
1139 void ChapterMenu::AttachedToWindow()
1141 // make title menu empty
1142 while ( BMenuItem* item = RemoveItem( 0L ) )
1145 input_thread_t* input = p_intf->p_sys->p_input;
1148 // lock stream access
1149 vlc_mutex_lock( &input->stream.stream_lock );
1150 // populate menu according to current stream
1151 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1152 if ( numChapters > 1 )
1154 for ( int32 i = 0; i < numChapters; i++ )
1156 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1157 message->AddInt32( "index", i );
1158 BString helper( "" );
1160 BMenuItem* item = new BMenuItem( helper.String(), message );
1161 item->SetMarked( input->stream.p_selected_area->i_part == i );
1165 // done messing with stream
1166 vlc_mutex_unlock( &input->stream.stream_lock );
1168 BMenu::AttachedToWindow();