1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.4 2002/10/28 16:55:05 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 = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
73 fPlaylistIsEmpty = (p_playlist->i_size < 0);
75 fPlaylistWindow = new PlayListWindow( BRect( 100.0, 100.0, 400.0, 350.0 ),
80 fPreferencesWindow = new PreferencesWindow( BRect( 100, 400, 500, 595 ),
85 SetName( "interface" );
86 SetTitle( VOUT_TITLE );
88 // the media control view
89 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ) );
90 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
91 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
94 p_mediaControl->GetPreferredSize( &width, &height );
96 // set up the main menu
97 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
98 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
100 // make menu bar resize to correct height
101 float menuWidth, menuHeight;
102 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
103 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
104 // take care of proper size for ourself
105 height += fMenuBar->Bounds().Height();
106 ResizeTo( width, height );
108 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
109 AddChild( fMenuBar );
110 AddChild( p_mediaControl );
113 BMenu* fileMenu = new BMenu( "File" );
114 fMenuBar->AddItem( fileMenu );
115 fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
116 new BMessage( OPEN_FILE ), 'O') );
118 fileMenu->AddItem( new CDMenu( "Open Disc" ) );
120 fileMenu->AddSeparatorItem();
121 fileMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
122 new BMessage( OPEN_PLAYLIST ), 'P') );
124 fileMenu->AddSeparatorItem();
125 BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
126 new BMessage( B_ABOUT_REQUESTED ), 'A');
127 item->SetTarget( be_app );
128 fileMenu->AddItem( item );
129 fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
131 fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_intf);
132 fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_intf);
134 /* Add the Audio menu */
135 fAudioMenu = new BMenu( "Audio" );
136 fMenuBar->AddItem ( fAudioMenu );
137 fAudioMenu->AddItem( fLanguageMenu );
138 fAudioMenu->AddItem( fSubtitlesMenu );
140 fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
141 fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
142 fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
143 fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
145 /* Add the Navigation menu */
146 fNavigationMenu = new BMenu( "Navigation" );
147 fMenuBar->AddItem( fNavigationMenu );
148 fNavigationMenu->AddItem( fPrevTitleMI );
149 fNavigationMenu->AddItem( fNextTitleMI );
150 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
151 fNavigationMenu->AddSeparatorItem();
152 fNavigationMenu->AddItem( fPrevChapterMI );
153 fNavigationMenu->AddItem( fNextChapterMI );
154 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
156 /* Add the Speed menu */
157 fSpeedMenu = new BMenu( "Speed" );
158 fSpeedMenu->SetRadioMode( true );
159 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
160 fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
161 fNormalMI->SetMarked(true); // default to normal speed
162 fSpeedMenu->AddItem( fNormalMI );
163 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
164 fSpeedMenu->SetTargetForItems( this );
165 fMenuBar->AddItem( fSpeedMenu );
167 /* Add the Settings menu */
168 fSettingsMenu = new BMenu( "Settings" );
169 fSettingsMenu->AddItem( fPreferencesMI =
170 new BMenuItem( "Preferences", new BMessage( OPEN_PREFERENCES ) ) );
171 fMenuBar->AddItem( fSettingsMenu );
173 /* Add the Config menu */
174 // BMenu* configMenu = new BMenu( "Config" );
175 // menu_bar->AddItem( configMenu );
176 // fOnTopMI = new BMenuItem( "Always on Top",
177 // new BMessage( TOGGLE_ON_TOP ) )
178 // configMenu->AddItem( );
179 // fOnTopMI->SetMarked(false);
181 // prepare fow showing
182 _SetMenusEnabled(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_intf->p_sys->p_vlc_wrapper->inputGetStatus();
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_intf->p_sys->p_vlc_wrapper->openDisc( type, device, 0, 0 );
265 // this currently stops playback not nicely
266 if (playback_status > UNDEF_S)
268 p_intf->p_sys->p_vlc_wrapper->volume_mute();
270 p_intf->p_sys->p_vlc_wrapper->playlistStop();
271 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
276 /* starts playing in normal mode */
279 /* toggle between pause and play */
280 if (playback_status > UNDEF_S)
282 /* pause if currently playing */
283 if ( playback_status == PLAYING_S )
285 p_intf->p_sys->p_vlc_wrapper->volume_mute();
287 p_intf->p_sys->p_vlc_wrapper->playlistPause();
291 p_intf->p_sys->p_vlc_wrapper->volume_restore();
292 p_intf->p_sys->p_vlc_wrapper->playlistPlay();
297 /* Play a new file */
298 p_intf->p_sys->p_vlc_wrapper->playlistPlay();
303 /* cycle the fast playback modes */
304 if (playback_status > UNDEF_S)
306 p_intf->p_sys->p_vlc_wrapper->volume_mute();
308 p_intf->p_sys->p_vlc_wrapper->playFaster();
313 /* cycle the slow playback modes */
314 if (playback_status > UNDEF_S)
316 p_intf->p_sys->p_vlc_wrapper->volume_mute();
318 p_intf->p_sys->p_vlc_wrapper->playSlower();
323 /* restore speed to normal if already playing */
324 if (playback_status > UNDEF_S)
326 p_intf->p_sys->p_vlc_wrapper->volume_restore();
327 p_intf->p_sys->p_vlc_wrapper->playlistPlay();
332 /* handled by semaphores */
334 // volume related messages
336 /* adjust the volume */
337 if (playback_status > UNDEF_S)
339 p_intf->p_sys->p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
340 p_mediaControl->SetMuted( p_intf->p_sys->p_vlc_wrapper->is_muted() );
346 p_intf->p_sys->p_vlc_wrapper->toggle_mute();
347 p_mediaControl->SetMuted( p_intf->p_sys->p_vlc_wrapper->is_muted() );
351 if ( playback_status > UNDEF_S )
354 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
356 p_intf->p_sys->p_vlc_wrapper->toggleLanguage( channel );
357 // vlc seems to remember the volume for every channel,
358 // but I would assume that to be somewhat annoying to the user
359 // the next call will also unmute the volume, which is probably
360 // desired as well, because if the user selects another language,
361 // he probably wants to hear the change as well
362 snooze( 400000 ); // we have to wait a bit, or the change will be reverted
363 p_intf->p_sys->p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
368 case SELECT_SUBTITLE:
369 if ( playback_status > UNDEF_S )
372 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
373 p_intf->p_sys->p_vlc_wrapper->toggleSubtitle( subtitle );
377 // specific navigation messages
381 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id - 1;
383 /* Disallow area 0 since it is used for video_ts.vob */
386 p_intf->p_sys->p_vlc_wrapper->toggleTitle(i_id);
394 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id + 1;
396 if( i_id < p_intf->p_sys->p_input->stream.i_area_nb )
398 p_intf->p_sys->p_vlc_wrapper->toggleTitle(i_id);
403 if ( playback_status > UNDEF_S )
406 if ( p_message->FindInt32( "index", &index ) == B_OK )
407 p_intf->p_sys->p_vlc_wrapper->toggleTitle( index );
414 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part - 1;
418 p_intf->p_sys->p_vlc_wrapper->toggleChapter(i_id);
426 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part + 1;
430 p_intf->p_sys->p_vlc_wrapper->toggleChapter(i_id);
435 if ( playback_status > UNDEF_S )
438 if ( p_message->FindInt32( "index", &index ) == B_OK )
439 p_intf->p_sys->p_vlc_wrapper->toggleChapter( index );
443 p_intf->p_sys->p_vlc_wrapper->playlistPrev();
446 p_intf->p_sys->p_vlc_wrapper->playlistNext();
448 // general next/prev functionality (skips to whatever makes most sense)
450 p_intf->p_sys->p_vlc_wrapper->navigatePrev();
453 p_intf->p_sys->p_vlc_wrapper->navigateNext();
455 // drag'n'drop and system messages
456 case B_REFS_RECEIVED:
459 // figure out if user wants files replaced or added
460 bool replace = false;
461 if ( p_message->WasDropped() )
462 replace = !( modifiers() & B_SHIFT_KEY );
463 // build list of files to be played from message contents
466 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
469 if ( path.InitCheck() == B_OK )
470 // the BString objects will be deleted
471 // by the wrapper function further down
472 files.AddItem( new BString( (char*)path.Path() ) );
474 // give the list to VLC
475 p_intf->p_sys->p_vlc_wrapper->openFiles(&files, replace);
480 case OPEN_PREFERENCES:
481 if (fPreferencesWindow->IsHidden())
482 fPreferencesWindow->Show();
484 fPreferencesWindow->Activate();
488 BWindow::MessageReceived( p_message );
494 /*****************************************************************************
495 * InterfaceWindow::QuitRequested
496 *****************************************************************************/
497 bool InterfaceWindow::QuitRequested()
499 if (p_intf->p_sys->p_input)
501 p_intf->p_sys->p_vlc_wrapper->volume_mute();
503 p_intf->p_sys->p_vlc_wrapper->playlistStop();
504 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
514 /*****************************************************************************
515 * InterfaceWindow::updateInterface
516 *****************************************************************************/
517 void InterfaceWindow::updateInterface()
519 input_thread_t* input = p_intf->p_sys->p_input;
522 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
524 p_intf->p_sys->p_vlc_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
528 bool hasTitles = input->stream.i_area_nb > 1;
529 bool hasChapters = input->stream.p_selected_area->i_part_nb > 1;
530 p_mediaControl->SetStatus( input->stream.control.i_status,
531 input->stream.control.i_rate );
532 p_mediaControl->SetProgress( input->stream.p_selected_area->i_tell,
533 input->stream.p_selected_area->i_size );
534 _SetMenusEnabled( true, hasChapters, hasTitles );
536 _UpdateSpeedMenu( input->stream.control.i_rate );
538 // enable/disable skip buttons
541 p_intf->p_sys->p_vlc_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
542 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
544 if ( p_intf->p_sys->p_vlc_wrapper->has_audio() )
546 p_mediaControl->SetAudioEnabled( true );
547 p_mediaControl->SetMuted( p_intf->p_sys->p_vlc_wrapper->is_muted() );
549 p_mediaControl->SetAudioEnabled( false );
551 if ( input != fInputThread )
553 fInputThread = input;
554 _InputStreamChanged();
559 // update playlist as well
560 if ( fPlaylistWindow->Lock() )
562 fPlaylistWindow->UpdatePlaylist();
563 fPlaylistWindow->Unlock();
567 _SetMenusEnabled(false);
569 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
571 if ( fPlaylistIsEmpty != ( p_playlist->i_size < 0) )
575 fPlaylistIsEmpty = !fPlaylistIsEmpty;
576 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
580 if ( input != fInputThread )
581 fInputThread = input;
583 fLastUpdateTime = system_time();
586 /*****************************************************************************
587 * InterfaceWindow::IsStopped
588 *****************************************************************************/
590 InterfaceWindow::IsStopped() const
592 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
595 /*****************************************************************************
596 * InterfaceWindow::_UpdatePlaylist
597 *****************************************************************************/
599 InterfaceWindow::_UpdatePlaylist()
601 if ( fPlaylistWindow->Lock() )
603 fPlaylistWindow->UpdatePlaylist( true );
604 fPlaylistWindow->Unlock();
605 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
607 fPlaylistIsEmpty = p_playlist->i_size < 1;
608 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
612 /*****************************************************************************
613 * InterfaceWindow::_SetMenusEnabled
614 *****************************************************************************/
616 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
625 if (fNextChapterMI->IsEnabled() != hasChapters)
626 fNextChapterMI->SetEnabled(hasChapters);
627 if (fPrevChapterMI->IsEnabled() != hasChapters)
628 fPrevChapterMI->SetEnabled(hasChapters);
629 if (fChapterMenu->IsEnabled() != hasChapters)
630 fChapterMenu->SetEnabled(hasChapters);
631 if (fNextTitleMI->IsEnabled() != hasTitles)
632 fNextTitleMI->SetEnabled(hasTitles);
633 if (fPrevTitleMI->IsEnabled() != hasTitles)
634 fPrevTitleMI->SetEnabled(hasTitles);
635 if (fTitleMenu->IsEnabled() != hasTitles)
636 fTitleMenu->SetEnabled(hasTitles);
637 if (fAudioMenu->IsEnabled() != hasFile)
638 fAudioMenu->SetEnabled(hasFile);
639 if (fNavigationMenu->IsEnabled() != hasFile)
640 fNavigationMenu->SetEnabled(hasFile);
641 if (fLanguageMenu->IsEnabled() != hasFile)
642 fLanguageMenu->SetEnabled(hasFile);
643 if (fSubtitlesMenu->IsEnabled() != hasFile)
644 fSubtitlesMenu->SetEnabled(hasFile);
645 if (fSpeedMenu->IsEnabled() != hasFile)
646 fSpeedMenu->SetEnabled(hasFile);
651 /*****************************************************************************
652 * InterfaceWindow::_UpdateSpeedMenu
653 *****************************************************************************/
655 InterfaceWindow::_UpdateSpeedMenu( int rate )
657 if ( rate == DEFAULT_RATE )
659 if ( !fNormalMI->IsMarked() )
660 fNormalMI->SetMarked( true );
662 else if ( rate < DEFAULT_RATE )
664 if ( !fFasterMI->IsMarked() )
665 fFasterMI->SetMarked( true );
669 if ( !fSlowerMI->IsMarked() )
670 fSlowerMI->SetMarked( true );
674 /*****************************************************************************
675 * InterfaceWindow::_InputStreamChanged
676 *****************************************************************************/
678 InterfaceWindow::_InputStreamChanged()
680 //printf("InterfaceWindow::_InputStreamChanged()\n");
681 // TODO: move more stuff from updateInterface() here!
683 p_intf->p_sys->p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
686 /*****************************************************************************
687 * InterfaceWindow::_LoadSettings
688 *****************************************************************************/
690 InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
692 status_t ret = B_BAD_VALUE;
696 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
698 // passing folder is optional
700 ret = path.Append( folder );
701 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
703 BFile file( path.Path(), B_READ_ONLY );
704 if ( ( ret = file.InitCheck() ) == B_OK )
706 ret = message->Unflatten( &file );
715 /*****************************************************************************
716 * InterfaceWindow::_SaveSettings
717 *****************************************************************************/
719 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
721 status_t ret = B_BAD_VALUE;
725 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
727 // passing folder is optional
728 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
729 ret = create_directory( path.Path(), 0777 );
730 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
732 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
733 if ( ( ret = file.InitCheck() ) == B_OK )
735 ret = message->Flatten( &file );
744 /*****************************************************************************
745 * InterfaceWindow::_RestoreSettings
746 *****************************************************************************/
748 make_sure_frame_is_on_screen( BRect& frame )
750 BScreen screen( B_MAIN_SCREEN_ID );
751 if (frame.IsValid() && screen.IsValid()) {
752 if (!screen.Frame().Contains(frame)) {
753 // make sure frame fits in the screen
754 if (frame.Width() > screen.Frame().Width())
755 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
756 if (frame.Height() > screen.Frame().Height())
757 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
758 // frame is now at the most the size of the screen
759 if (frame.right > screen.Frame().right)
760 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
761 if (frame.bottom > screen.Frame().bottom)
762 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
763 if (frame.left < screen.Frame().left)
764 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
765 if (frame.top < screen.Frame().top)
766 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
774 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
775 float maxWidth, float maxHeight )
777 if ( frame.Width() < minWidth )
778 frame.right = frame.left + minWidth;
779 if ( frame.Height() < minHeight )
780 frame.bottom = frame.top + minHeight;
781 if ( frame.Width() > maxWidth )
782 frame.right = frame.left + maxWidth;
783 if ( frame.Height() > maxHeight )
784 frame.bottom = frame.top + maxHeight;
787 /*****************************************************************************
788 * InterfaceWindow::_RestoreSettings
789 *****************************************************************************/
791 InterfaceWindow::_RestoreSettings()
793 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
796 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
798 // sanity checks: make sure window is not too big/small
799 // and that it's not off-screen
800 float minWidth, maxWidth, minHeight, maxHeight;
801 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
803 make_sure_frame_is_within_limits( mainFrame,
804 minWidth, minHeight, maxWidth, maxHeight );
805 make_sure_frame_is_on_screen( mainFrame );
808 MoveTo( mainFrame.LeftTop() );
809 ResizeTo( mainFrame.Width(), mainFrame.Height() );
811 if ( fPlaylistWindow->Lock() )
814 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
816 // sanity checks: make sure window is not too big/small
817 // and that it's not off-screen
818 float minWidth, maxWidth, minHeight, maxHeight;
819 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
821 make_sure_frame_is_within_limits( playlistFrame,
822 minWidth, minHeight, maxWidth, maxHeight );
823 make_sure_frame_is_on_screen( playlistFrame );
825 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
826 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
830 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
834 if ( fPlaylistWindow->IsHidden() )
835 fPlaylistWindow->Show();
839 if ( !fPlaylistWindow->IsHidden() )
840 fPlaylistWindow->Hide();
844 fPlaylistWindow->Unlock();
849 /*****************************************************************************
850 * InterfaceWindow::_StoreSettings
851 *****************************************************************************/
853 InterfaceWindow::_StoreSettings()
855 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
856 fSettings->AddRect( "main frame", Frame() );
857 if ( fPlaylistWindow->Lock() )
859 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
860 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
861 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
862 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
863 fPlaylistWindow->Unlock();
865 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
868 /*****************************************************************************
870 *****************************************************************************/
871 CDMenu::CDMenu(const char *name)
876 /*****************************************************************************
878 *****************************************************************************/
883 /*****************************************************************************
884 * CDMenu::AttachedToWindow
885 *****************************************************************************/
886 void CDMenu::AttachedToWindow(void)
889 while (BMenuItem* item = RemoveItem(0L))
892 BMenu::AttachedToWindow();
895 /*****************************************************************************
897 *****************************************************************************/
898 int CDMenu::GetCD( const char *directory )
900 BVolumeRoster *volRoster;
905 char name[B_FILE_NAME_LENGTH];
909 volRoster = new BVolumeRoster();
911 dir = new BDirectory();
912 status = volRoster->GetNextVolume(vol);
913 status = vol->GetRootDirectory(dir);
914 while (status == B_NO_ERROR)
916 mounted = vol->GetName(name);
917 if ((mounted == B_OK) && /* Disk is currently Mounted */
918 (vol->IsReadOnly()) ) /* Disk is read-only */
921 fs_stat_dev(dev, &info);
925 i_dev = open( info.device_name, O_RDONLY );
929 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
931 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
934 msg = new BMessage( OPEN_DVD );
935 msg->AddString( "device", info.device_name );
936 BMenuItem *menu_item;
937 menu_item = new BMenuItem( name, msg );
938 AddItem( menu_item );
945 status = volRoster->GetNextVolume(vol);
950 /*****************************************************************************
951 * LanguageMenu::LanguageMenu
952 *****************************************************************************/
953 LanguageMenu::LanguageMenu(const char *name, int menu_kind,
954 intf_thread_t *p_interface)
958 p_intf = p_interface;
961 /*****************************************************************************
962 * LanguageMenu::~LanguageMenu
963 *****************************************************************************/
964 LanguageMenu::~LanguageMenu()
968 /*****************************************************************************
969 * LanguageMenu::AttachedToWindow
970 *****************************************************************************/
971 void LanguageMenu::AttachedToWindow()
974 while ( BMenuItem* item = RemoveItem( 0L ) )
977 SetRadioMode( true );
979 BMenu::AttachedToWindow();
982 /*****************************************************************************
983 * LanguageMenu::_GetChannels
984 *****************************************************************************/
985 void LanguageMenu::_GetChannels()
990 BMenuItem *menu_item;
992 es_descriptor_t *p_es = NULL;
994 // Insert the "None" item if in subtitle mode
995 if( kind != AUDIO_ES ) //subtitle
997 msg = new BMessage( SELECT_SUBTITLE );
998 msg->AddInt32( "subtitle", -1 );
999 menu_item = new BMenuItem( "None", msg );
1000 AddItem( menu_item );
1001 menu_item->SetMarked( true );
1004 input_thread_t* input = p_intf->p_sys->p_input;
1007 vlc_mutex_lock( &input->stream.stream_lock );
1008 for( i = 0; i < input->stream.i_selected_es_number; i++ )
1010 if( kind == input->stream.pp_selected_es[i]->i_cat )
1011 p_es = input->stream.pp_selected_es[i];
1014 int32 addedItems = 0;
1015 bool emptyItemAdded = false;
1016 uint32 what = kind == AUDIO_ES ? SELECT_CHANNEL : SELECT_SUBTITLE;
1017 const char* fieldName = kind == AUDIO_ES ? "channel" : "subtitle";
1019 for ( i = 0; i < input->stream.i_es_number; i++ )
1021 if ( kind == input->stream.pp_es[i]->i_cat )
1023 bool addItem = true;
1024 psz_name = input->stream.pp_es[i]->psz_desc;
1025 // workarround for irritating empty strings
1026 if ( strcmp(psz_name, "") == 0 )
1028 // if ( kind != AUDIO_ES ) // don't add empty subtitle items, they don't work anyways
1032 if (!emptyItemAdded)
1034 psz_name = "<default>";
1035 emptyItemAdded = true;
1038 psz_name = "<unkown>";
1044 msg = new BMessage( what );
1045 msg->AddInt32( fieldName, i );
1046 menu_item = new BMenuItem( psz_name, msg );
1047 AddItem( menu_item );
1048 b_active = ( p_es == input->stream.pp_es[i] );
1049 menu_item->SetMarked( b_active );
1053 vlc_mutex_unlock( &input->stream.stream_lock );
1055 // enhance readability and separate first item from rest
1056 if ( ( emptyItemAdded || kind != AUDIO_ES ) && addedItems > 1 )
1057 AddItem( new BSeparatorItem(), 1 );
1063 /*****************************************************************************
1064 * TitleMenu::TitleMenu
1065 *****************************************************************************/
1066 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1068 p_intf( p_interface )
1072 /*****************************************************************************
1073 * TitleMenu::~TitleMenu
1074 *****************************************************************************/
1075 TitleMenu::~TitleMenu()
1079 /*****************************************************************************
1080 * TitleMenu::AttachedToWindow
1081 *****************************************************************************/
1082 void TitleMenu::AttachedToWindow()
1084 // make title menu empty
1085 while ( BMenuItem* item = RemoveItem( 0L ) )
1088 input_thread_t* input = p_intf->p_sys->p_input;
1091 // lock stream access
1092 vlc_mutex_lock( &input->stream.stream_lock );
1093 // populate menu according to current stream
1094 int32 numTitles = input->stream.i_area_nb;
1095 if ( numTitles > 1 )
1097 // disallow title 0!
1098 for ( int32 i = 1; i < numTitles; i++ )
1100 BMessage* message = new BMessage( TOGGLE_TITLE );
1101 message->AddInt32( "index", i );
1102 BString helper( "" );
1104 BMenuItem* item = new BMenuItem( helper.String(), message );
1105 item->SetMarked( input->stream.p_selected_area->i_id == i );
1109 // done messing with stream
1110 vlc_mutex_unlock( &input->stream.stream_lock );
1112 BMenu::AttachedToWindow();
1116 /*****************************************************************************
1117 * ChapterMenu::ChapterMenu
1118 *****************************************************************************/
1119 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1121 p_intf( p_interface )
1125 /*****************************************************************************
1126 * ChapterMenu::~ChapterMenu
1127 *****************************************************************************/
1128 ChapterMenu::~ChapterMenu()
1132 /*****************************************************************************
1133 * ChapterMenu::AttachedToWindow
1134 *****************************************************************************/
1135 void ChapterMenu::AttachedToWindow()
1137 // make title menu empty
1138 while ( BMenuItem* item = RemoveItem( 0L ) )
1141 input_thread_t* input = p_intf->p_sys->p_input;
1144 // lock stream access
1145 vlc_mutex_lock( &input->stream.stream_lock );
1146 // populate menu according to current stream
1147 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1148 if ( numChapters > 1 )
1150 for ( int32 i = 0; i < numChapters; i++ )
1152 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1153 message->AddInt32( "index", i );
1154 BString helper( "" );
1156 BMenuItem* item = new BMenuItem( helper.String(), message );
1157 item->SetMarked( input->stream.p_selected_area->i_part == i );
1161 // done messing with stream
1162 vlc_mutex_unlock( &input->stream.stream_lock );
1164 BMenu::AttachedToWindow();