1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.29 2003/02/09 17:10:52 stippi 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 "MessagesWindow.h"
52 #include "InterfaceWindow.h"
54 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
55 #define INTERFACE_LOCKING_TIMEOUT 5000
56 #define USE_VLC_CONFIG_FILE 0
58 // make_sure_frame_is_on_screen
60 make_sure_frame_is_on_screen( BRect& frame )
62 BScreen screen( B_MAIN_SCREEN_ID );
63 if (frame.IsValid() && screen.IsValid()) {
64 if (!screen.Frame().Contains(frame)) {
65 // make sure frame fits in the screen
66 if (frame.Width() > screen.Frame().Width())
67 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
68 if (frame.Height() > screen.Frame().Height())
69 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
70 // frame is now at the most the size of the screen
71 if (frame.right > screen.Frame().right)
72 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
73 if (frame.bottom > screen.Frame().bottom)
74 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
75 if (frame.left < screen.Frame().left)
76 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
77 if (frame.top < screen.Frame().top)
78 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
85 // make_sure_frame_is_within_limits
87 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
88 float maxWidth, float maxHeight )
90 if ( frame.Width() < minWidth )
91 frame.right = frame.left + minWidth;
92 if ( frame.Height() < minHeight )
93 frame.bottom = frame.top + minHeight;
94 if ( frame.Width() > maxWidth )
95 frame.right = frame.left + maxWidth;
96 if ( frame.Height() > maxHeight )
97 frame.bottom = frame.top + maxHeight;
102 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
104 bool success = false;
108 char name[B_FILE_NAME_LENGTH];
109 if ( volume.GetName( name ) >= B_OK ) // disk is currently mounted
112 dev_t dev = volume.Device();
114 if ( fs_stat_dev( dev, &info ) == B_OK )
117 deviceName = info.device_name;
118 if ( volume.IsReadOnly() )
120 int i_dev = open( info.device_name, O_RDONLY );
124 if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
125 isCDROM = ( g.device_type == B_CD );
134 // collect_folder_contents
136 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
138 while ( dir.GetNextEntry( &entry, true ) == B_OK )
140 if ( !entry.IsDirectory() )
143 // since the directory will give us the entries in reverse order,
144 // we put them each at the same index, effectively reversing the
145 // items while adding them
146 if ( entry.GetPath( &path ) == B_OK )
148 BString* string = new BString( path.Path() );
149 if ( !list.AddItem( string, 0 ) )
150 delete string; // at least don't leak
157 // ask user if we should parse sub-folders as well
158 BAlert* alert = new BAlert( "sub-folders?",
159 "Open files from all sub-folders as well?",
160 "No", "Yes", NULL, B_WIDTH_AS_USUAL,
162 int32 buttonIndex = alert->Go();
163 deep = buttonIndex == 1;
165 // never delete BAlerts!!
169 BDirectory subDir( &entry );
170 if ( subDir.InitCheck() == B_OK )
171 collect_folder_contents( subDir, list,
172 deep, asked, entry );
179 /*****************************************************************************
181 *****************************************************************************/
183 InterfaceWindow::InterfaceWindow( BRect frame, const char* name,
184 intf_thread_t* p_interface )
185 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
186 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
187 p_intf( p_interface ),
189 fLastUpdateTime( system_time() ),
190 fSettings( new BMessage( 'sett' ) ),
191 p_wrapper( p_intf->p_sys->p_wrapper )
193 // TODO: ?!? what about user settings?
194 p_intf->p_sys->b_dvdmenus = false;
196 fPlaylistIsEmpty = !( p_wrapper->PlaylistSize() > 0 );
199 BRect screen_rect = screen.Frame();
201 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
202 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
203 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
204 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
205 fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, "Settings" );
206 window_rect.Set( screen_rect.right - 500,
207 screen_rect.top + 50,
208 screen_rect.right - 150,
209 screen_rect.top + 250 );
210 fPlaylistWindow = new PlayListWindow( window_rect, "Playlist", this, p_intf );
211 window_rect.Set( screen_rect.right - 500,
212 screen_rect.top + 300,
213 screen_rect.right - 150,
214 screen_rect.top + 600 );
215 fMessagesWindow = new MessagesWindow( p_intf, window_rect, "Messages" );
218 SetName( "interface" );
219 SetTitle( VOUT_TITLE );
221 // the media control view
222 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
224 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
227 p_mediaControl->GetPreferredSize( &width, &height );
229 // set up the main menu
230 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
231 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
233 // make menu bar resize to correct height
234 float menuWidth, menuHeight;
235 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
236 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
237 // take care of proper size for ourself
238 height += fMenuBar->Bounds().Height();
239 ResizeTo( width, height );
241 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
242 AddChild( fMenuBar );
243 AddChild( p_mediaControl );
246 BMenu* fileMenu = new BMenu( "File" );
247 fMenuBar->AddItem( fileMenu );
248 fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
249 new BMessage( OPEN_FILE ), 'O') );
251 fileMenu->AddItem( new CDMenu( "Open Disc" ) );
253 fileMenu->AddItem( new BMenuItem( "Open Subtitles" B_UTF8_ELLIPSIS,
254 new BMessage( LOAD_SUBFILE ) ) );
256 fileMenu->AddSeparatorItem();
257 BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
258 new BMessage( B_ABOUT_REQUESTED ), 'A');
259 item->SetTarget( be_app );
260 fileMenu->AddItem( item );
261 fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
263 fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_wrapper);
264 fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_wrapper);
266 /* Add the Audio menu */
267 fAudioMenu = new BMenu( "Audio" );
268 fMenuBar->AddItem ( fAudioMenu );
269 fAudioMenu->AddItem( fLanguageMenu );
270 fAudioMenu->AddItem( fSubtitlesMenu );
272 fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
273 fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
274 fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
275 fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
276 fGotoMenuMI = new BMenuItem( "Goto Menu", new BMessage( NAVIGATE_MENU ) );
278 /* Add the Navigation menu */
279 fNavigationMenu = new BMenu( "Navigation" );
280 fMenuBar->AddItem( fNavigationMenu );
281 fNavigationMenu->AddItem( fGotoMenuMI );
282 fNavigationMenu->AddSeparatorItem();
283 fNavigationMenu->AddItem( fPrevTitleMI );
284 fNavigationMenu->AddItem( fNextTitleMI );
285 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
286 fNavigationMenu->AddSeparatorItem();
287 fNavigationMenu->AddItem( fPrevChapterMI );
288 fNavigationMenu->AddItem( fNextChapterMI );
289 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
291 /* Add the Speed menu */
292 fSpeedMenu = new BMenu( "Speed" );
293 fSpeedMenu->SetRadioMode( true );
294 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
295 fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
296 fNormalMI->SetMarked(true); // default to normal speed
297 fSpeedMenu->AddItem( fNormalMI );
298 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
299 fSpeedMenu->SetTargetForItems( this );
300 fMenuBar->AddItem( fSpeedMenu );
302 /* Add the Show menu */
303 fShowMenu = new BMenu( "Window" );
304 fShowMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
305 new BMessage( OPEN_PLAYLIST ), 'P') );
306 fShowMenu->AddItem( new BMenuItem( "Messages" B_UTF8_ELLIPSIS,
307 new BMessage( OPEN_MESSAGES ), 'M' ) );
308 fShowMenu->AddItem( new BMenuItem( "Settings" B_UTF8_ELLIPSIS,
309 new BMessage( OPEN_PREFERENCES ), 'S' ) );
310 fMenuBar->AddItem( fShowMenu );
312 /* Prepare fow showing */
313 _SetMenusEnabled( false );
314 p_mediaControl->SetEnabled( false );
321 InterfaceWindow::~InterfaceWindow()
323 if( fPlaylistWindow )
324 fPlaylistWindow->ReallyQuit();
325 fPlaylistWindow = NULL;
326 if( fMessagesWindow )
327 fMessagesWindow->ReallyQuit();
328 fMessagesWindow = NULL;
329 if( fPreferencesWindow )
330 fPreferencesWindow->ReallyQuit();
331 fPreferencesWindow = NULL;
336 /*****************************************************************************
337 * InterfaceWindow::FrameResized
338 *****************************************************************************/
340 InterfaceWindow::FrameResized(float width, float height)
343 fMenuBar->MoveTo(r.LeftTop());
344 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
345 r.top += fMenuBar->Bounds().Height() + 1.0;
346 p_mediaControl->MoveTo(r.LeftTop());
347 p_mediaControl->ResizeTo(r.Width(), r.Height());
350 /*****************************************************************************
351 * InterfaceWindow::MessageReceived
352 *****************************************************************************/
353 void InterfaceWindow::MessageReceived( BMessage * p_message )
355 int playback_status; // remember playback state
356 playback_status = p_wrapper->InputStatus();
358 switch( p_message->what )
360 case B_ABOUT_REQUESTED:
362 BAlert* alert = new BAlert( VOUT_TITLE,
363 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
371 _ShowFilePanel( B_REFS_RECEIVED, "VideoLAN Client: Open Media Files" );
375 _ShowFilePanel( SUBFILE_RECEIVED, "VideoLAN Client: Open Subtitle File" );
379 if (fPlaylistWindow->Lock())
381 if (fPlaylistWindow->IsHidden())
382 fPlaylistWindow->Show();
384 fPlaylistWindow->Activate();
385 fPlaylistWindow->Unlock();
390 const char *psz_device;
391 BString type( "dvd" );
392 if( p_message->FindString( "device", &psz_device ) == B_OK )
394 BString device( psz_device );
395 p_wrapper->OpenDisc( type, device, 0, 0 );
401 case SUBFILE_RECEIVED:
404 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
407 if ( path.InitCheck() == B_OK )
408 p_wrapper->LoadSubFile( path.Path() );
414 // this currently stops playback not nicely
415 if (playback_status > UNDEF_S)
417 p_wrapper->PlaylistStop();
418 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
423 /* starts playing in normal mode */
426 /* toggle between pause and play */
427 if (playback_status > UNDEF_S)
429 /* pause if currently playing */
430 if ( playback_status == PLAYING_S )
432 p_wrapper->PlaylistPause();
436 p_wrapper->PlaylistPlay();
441 /* Play a new file */
442 p_wrapper->PlaylistPlay();
447 /* cycle the fast playback modes */
448 if (playback_status > UNDEF_S)
450 p_wrapper->InputFaster();
455 /* cycle the slow playback modes */
456 if (playback_status > UNDEF_S)
458 p_wrapper->InputSlower();
463 /* restore speed to normal if already playing */
464 if (playback_status > UNDEF_S)
466 p_wrapper->PlaylistPlay();
471 /* handled by semaphores */
473 // volume related messages
475 /* adjust the volume */
476 if (playback_status > UNDEF_S)
478 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
479 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
485 if( p_wrapper->IsMuted() )
486 p_wrapper->VolumeRestore();
488 p_wrapper->VolumeMute();
489 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
493 if ( playback_status > UNDEF_S )
496 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
498 p_wrapper->ToggleLanguage( channel );
503 case SELECT_SUBTITLE:
504 if ( playback_status > UNDEF_S )
507 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
508 p_wrapper->ToggleSubtitle( subtitle );
512 // specific navigation messages
515 p_wrapper->PrevTitle();
520 p_wrapper->NextTitle();
524 p_wrapper->ToggleTitle( 0 );
527 if ( playback_status > UNDEF_S )
530 if( p_message->FindInt32( "index", &index ) == B_OK )
531 p_wrapper->ToggleTitle( index );
536 p_wrapper->PrevChapter();
541 p_wrapper->NextChapter();
545 if ( playback_status > UNDEF_S )
548 if( p_message->FindInt32( "index", &index ) == B_OK )
549 p_wrapper->ToggleChapter( index );
553 p_wrapper->PlaylistPrev();
556 p_wrapper->PlaylistNext();
558 // general next/prev functionality (skips to whatever makes most sense)
560 p_wrapper->NavigatePrev();
563 p_wrapper->NavigateNext();
565 // drag'n'drop and system messages
567 // convert soundplay drag'n'drop message (containing paths)
568 // to normal message (containing refs)
571 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
574 if ( get_ref_for_path( path, &ref ) == B_OK )
575 p_message->AddRef( "refs", &ref );
579 case B_REFS_RECEIVED:
582 /* file(s) opened by the File menu -> append to the playlist;
583 * file(s) opened by drag & drop -> replace playlist;
584 * file(s) opened by 'shift' + drag & drop -> append */
585 bool replace = false;
586 bool reverse = false;
587 if ( p_message->WasDropped() )
589 replace = !( modifiers() & B_SHIFT_KEY );
593 // build list of files to be played from message contents
597 // if we should parse sub-folders as well
598 bool askedAlready = false;
599 bool parseSubFolders = askedAlready;
600 // traverse refs in reverse order
603 if ( p_message->GetInfo( "refs", &dummy, &count ) == B_OK && count > 0 )
605 int32 i = reverse ? count - 1 : 0;
606 int32 increment = reverse ? -1 : 1;
607 for ( ; p_message->FindRef( "refs", i, &ref ) == B_OK; i += increment )
610 if ( path.InitCheck() == B_OK )
613 // has the user dropped a folder?
614 BDirectory dir( &ref );
615 if ( dir.InitCheck() == B_OK)
617 // has the user dropped a dvd disk icon?
618 if ( dir.IsRootDirectory() )
620 BVolumeRoster volRoster;
622 BDirectory volumeRoot;
623 status_t status = volRoster.GetNextVolume( &vol );
624 while ( status == B_NO_ERROR )
626 if ( vol.GetRootDirectory( &volumeRoot ) == B_OK
627 && dir == volumeRoot )
632 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
635 BMessage msg( OPEN_DVD );
636 msg.AddString( "device", deviceName.String() );
645 status = volRoster.GetNextVolume( &vol );
652 dir.Rewind(); // defensive programming
654 collect_folder_contents( dir, files,
662 BString* string = new BString( path.Path() );
663 if ( !files.AddItem( string, 0 ) )
664 delete string; // at least don't leak
668 // give the list to VLC
669 // BString objects allocated here will be deleted there
671 if ( p_message->FindInt32("drop index", &index) != B_OK )
673 p_wrapper->OpenFiles( &files, replace, index );
679 case OPEN_PREFERENCES:
681 if( fPreferencesWindow->Lock() )
683 if (fPreferencesWindow->IsHidden())
684 fPreferencesWindow->Show();
686 fPreferencesWindow->Activate();
687 fPreferencesWindow->Unlock();
694 if( fMessagesWindow->Lock() )
696 if (fMessagesWindow->IsHidden())
697 fMessagesWindow->Show();
699 fMessagesWindow->Activate();
700 fMessagesWindow->Unlock();
708 BWindow::MessageReceived( p_message );
714 /*****************************************************************************
715 * InterfaceWindow::QuitRequested
716 *****************************************************************************/
717 bool InterfaceWindow::QuitRequested()
719 p_wrapper->PlaylistStop();
720 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
729 /*****************************************************************************
730 * InterfaceWindow::UpdateInterface
731 *****************************************************************************/
732 void InterfaceWindow::UpdateInterface()
734 if( p_wrapper->HasInput() )
736 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
738 p_wrapper->SetTimeAsFloat( p_mediaControl->GetSeekTo() );
740 else if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
742 p_mediaControl->SetEnabled( true );
743 bool hasTitles = p_wrapper->HasTitles();
744 bool hasChapters = p_wrapper->HasChapters();
745 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
746 p_wrapper->InputRate() );
747 p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
748 _SetMenusEnabled( true, hasChapters, hasTitles );
750 _UpdateSpeedMenu( p_wrapper->InputRate() );
752 // enable/disable skip buttons
755 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
756 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
758 if ( p_wrapper->HasInput() )
760 p_mediaControl->SetAudioEnabled( true );
761 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
763 p_mediaControl->SetAudioEnabled( false );
767 // update playlist as well
768 if ( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
770 fPlaylistWindow->UpdatePlaylist();
771 fPlaylistWindow->Unlock();
776 if ( LockWithTimeout(INTERFACE_LOCKING_TIMEOUT) == B_OK )
778 _SetMenusEnabled( false );
779 if( !( p_wrapper->PlaylistSize() > 0 ) )
780 p_mediaControl->SetEnabled( false );
783 p_mediaControl->SetProgress( 0 );
784 // enable/disable skip buttons
787 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
788 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
794 // strangly, someone is calling this function even after the object has been destructed!
795 // even more strangly, this workarround seems to work
797 fMessagesWindow->UpdateMessages();
799 fLastUpdateTime = system_time();
802 /*****************************************************************************
803 * InterfaceWindow::IsStopped
804 *****************************************************************************/
806 InterfaceWindow::IsStopped() const
808 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
811 /*****************************************************************************
812 * InterfaceWindow::_UpdatePlaylist
813 *****************************************************************************/
815 InterfaceWindow::_UpdatePlaylist()
817 if ( fPlaylistWindow->Lock() )
819 fPlaylistWindow->UpdatePlaylist( true );
820 fPlaylistWindow->Unlock();
821 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
825 /*****************************************************************************
826 * InterfaceWindow::_SetMenusEnabled
827 *****************************************************************************/
829 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
836 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
838 if ( fNextChapterMI->IsEnabled() != hasChapters )
839 fNextChapterMI->SetEnabled( hasChapters );
840 if ( fPrevChapterMI->IsEnabled() != hasChapters )
841 fPrevChapterMI->SetEnabled( hasChapters );
842 if ( fChapterMenu->IsEnabled() != hasChapters )
843 fChapterMenu->SetEnabled( hasChapters );
844 if ( fNextTitleMI->IsEnabled() != hasTitles )
845 fNextTitleMI->SetEnabled( hasTitles );
846 if ( fPrevTitleMI->IsEnabled() != hasTitles )
847 fPrevTitleMI->SetEnabled( hasTitles );
848 if ( fTitleMenu->IsEnabled() != hasTitles )
849 fTitleMenu->SetEnabled( hasTitles );
850 if ( fAudioMenu->IsEnabled() != hasFile )
851 fAudioMenu->SetEnabled( hasFile );
852 if ( fNavigationMenu->IsEnabled() != hasFile )
853 fNavigationMenu->SetEnabled( hasFile );
854 if ( fLanguageMenu->IsEnabled() != hasFile )
855 fLanguageMenu->SetEnabled( hasFile );
856 if ( fSubtitlesMenu->IsEnabled() != hasFile )
857 fSubtitlesMenu->SetEnabled( hasFile );
858 if ( fSpeedMenu->IsEnabled() != hasFile )
859 fSpeedMenu->SetEnabled( hasFile );
860 // "goto menu" menu item
861 bool hasMenu = p_intf->p_sys->b_dvdmenus ? hasTitles : false;
862 if ( fGotoMenuMI->IsEnabled() != hasMenu )
863 fGotoMenuMI->SetEnabled( hasMenu );
868 /*****************************************************************************
869 * InterfaceWindow::_UpdateSpeedMenu
870 *****************************************************************************/
872 InterfaceWindow::_UpdateSpeedMenu( int rate )
874 if ( rate == DEFAULT_RATE )
876 if ( !fNormalMI->IsMarked() )
877 fNormalMI->SetMarked( true );
879 else if ( rate < DEFAULT_RATE )
881 if ( !fFasterMI->IsMarked() )
882 fFasterMI->SetMarked( true );
886 if ( !fSlowerMI->IsMarked() )
887 fSlowerMI->SetMarked( true );
891 /*****************************************************************************
892 * InterfaceWindow::_InputStreamChanged
893 *****************************************************************************/
895 InterfaceWindow::_InputStreamChanged()
897 // TODO: move more stuff from updateInterface() here!
899 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
902 /*****************************************************************************
903 * InterfaceWindow::_ShowFilePanel
904 *****************************************************************************/
906 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
910 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
911 B_FILE_NODE | B_DIRECTORY_NODE );
912 fFilePanel->SetTarget( this );
914 fFilePanel->Window()->SetTitle( windowTitle );
915 BMessage message( command );
916 fFilePanel->SetMessage( &message );
917 if ( !fFilePanel->IsShowing() )
919 fFilePanel->Refresh();
926 set_window_pos( BWindow* window, BRect frame )
928 // sanity checks: make sure window is not too big/small
929 // and that it's not off-screen
930 float minWidth, maxWidth, minHeight, maxHeight;
931 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
933 make_sure_frame_is_within_limits( frame,
934 minWidth, minHeight, maxWidth, maxHeight );
935 if ( make_sure_frame_is_on_screen( frame ) )
937 window->MoveTo( frame.LeftTop() );
938 window->ResizeTo( frame.Width(), frame.Height() );
944 launch_window( BWindow* window, bool showing )
946 if ( window->Lock() )
950 if ( window->IsHidden() )
955 if ( !window->IsHidden() )
962 /*****************************************************************************
963 * InterfaceWindow::_RestoreSettings
964 *****************************************************************************/
966 InterfaceWindow::_RestoreSettings()
968 if ( USE_VLC_CONFIG_FILE )
970 // main window size and position
971 int i_width = config_GetInt( p_intf, "beos-intf-width" ),
972 i_height = config_GetInt( p_intf, "beos-intf-height" ),
973 i_xpos = config_GetInt( p_intf, "beos-intf-xpos" ),
974 i_ypos = config_GetInt( p_intf, "beos-intf-ypos" );
975 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
977 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
978 set_window_pos( this, r );
980 // playlist window size and position
981 i_width = config_GetInt( p_intf, "beos-playlist-width" ),
982 i_height = config_GetInt( p_intf, "beos-playlist-height" ),
983 i_xpos = config_GetInt( p_intf, "beos-playlist-xpos" ),
984 i_ypos = config_GetInt( p_intf, "beos-playlist-ypos" );
985 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
987 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
988 set_window_pos( fPlaylistWindow, r );
991 launch_window( fPlaylistWindow, config_GetInt( p_intf, "beos-playlist-show" ) );
992 // messages window size and position
993 i_width = config_GetInt( p_intf, "beos-messages-width" ),
994 i_height = config_GetInt( p_intf, "beos-messages-height" ),
995 i_xpos = config_GetInt( p_intf, "beos-messages-xpos" ),
996 i_ypos = config_GetInt( p_intf, "beos-messages-ypos" );
997 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
999 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
1000 set_window_pos( fMessagesWindow, r );
1003 launch_window( fMessagesWindow, config_GetInt( p_intf, "beos-messages-show" ) );
1005 // messages window size and position
1006 i_width = config_GetInt( p_intf, "beos-settings-width" ),
1007 i_height = config_GetInt( p_intf, "beos-settings-height" ),
1008 i_xpos = config_GetInt( p_intf, "beos-settings-xpos" ),
1009 i_ypos = config_GetInt( p_intf, "beos-settings-ypos" );
1010 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
1012 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
1013 set_window_pos( fPreferencesWindow, r );
1016 launch_window( fPreferencesWindow, config_GetInt( p_intf, "beos-settings-show" ) );
1020 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1023 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1024 set_window_pos( this, frame );
1025 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1026 set_window_pos( fPlaylistWindow, frame );
1027 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1028 set_window_pos( fMessagesWindow, frame );
1029 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1030 set_window_pos( fPreferencesWindow, frame );
1033 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1034 launch_window( fPlaylistWindow, showing );
1035 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1036 launch_window( fMessagesWindow, showing );
1037 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1038 launch_window( fPreferencesWindow, showing );
1041 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1042 fPlaylistWindow->SetDisplayMode( displayMode );
1047 /*****************************************************************************
1048 * InterfaceWindow::_StoreSettings
1049 *****************************************************************************/
1051 InterfaceWindow::_StoreSettings()
1053 if ( USE_VLC_CONFIG_FILE )
1055 // save interface settings in vlc config file
1056 BRect frame = Frame();
1057 config_PutInt( p_intf, "beos-intf-width", (int)frame.Width() );
1058 config_PutInt( p_intf, "beos-intf-height", (int)frame.Height() );
1059 config_PutInt( p_intf, "beos-intf-xpos", (int)frame.left );
1060 config_PutInt( p_intf, "beos-intf-ypos", (int)frame.top );
1061 if( fPlaylistWindow->Lock() )
1063 frame = fPlaylistWindow->Frame();
1064 config_PutInt( p_intf, "beos-playlist-width", (int)frame.Width() );
1065 config_PutInt( p_intf, "beos-playlist-height", (int)frame.Height() );
1066 config_PutInt( p_intf, "beos-playlist-xpos", (int)frame.left );
1067 config_PutInt( p_intf, "beos-playlist-ypos", (int)frame.top );
1068 config_PutInt( p_intf, "beos-playlist-show", !fPlaylistWindow->IsHidden() );
1069 fPlaylistWindow->Unlock();
1071 if( fMessagesWindow->Lock() )
1073 frame = fMessagesWindow->Frame();
1074 config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
1075 config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
1076 config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
1077 config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
1078 config_PutInt( p_intf, "beos-messages-show", !fMessagesWindow->IsHidden() );
1079 fMessagesWindow->Unlock();
1081 if( fPreferencesWindow->Lock() )
1083 frame = fPreferencesWindow->Frame();
1084 config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
1085 config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
1086 config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
1087 config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
1088 config_PutInt( p_intf, "beos-messages-show", !fPreferencesWindow->IsHidden() );
1089 fPreferencesWindow->Unlock();
1094 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1095 fSettings->AddRect( "main frame", Frame() );
1096 if ( fPlaylistWindow->Lock() )
1098 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1099 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1100 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1101 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1102 fPlaylistWindow->Unlock();
1104 if ( fMessagesWindow->Lock() )
1106 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1107 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1108 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1109 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1110 fMessagesWindow->Unlock();
1112 if ( fPreferencesWindow->Lock() )
1114 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1115 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1116 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1117 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1118 fPreferencesWindow->Unlock();
1120 uint32 displayMode = fPlaylistWindow->DisplayMode();
1121 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1122 fSettings->AddInt32( "playlist display mode", displayMode );
1124 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1127 // save VLC internal settings
1128 config_SaveConfigFile( p_intf, "beos" );
1129 config_SaveConfigFile( p_intf, "main" );
1130 config_SaveConfigFile( p_intf, "adjust" );
1131 config_SaveConfigFile( p_intf, "ffmpeg" );
1139 /*****************************************************************************
1141 *****************************************************************************/
1142 CDMenu::CDMenu(const char *name)
1147 /*****************************************************************************
1149 *****************************************************************************/
1154 /*****************************************************************************
1155 * CDMenu::AttachedToWindow
1156 *****************************************************************************/
1157 void CDMenu::AttachedToWindow(void)
1160 while ( BMenuItem* item = RemoveItem( 0L ) )
1162 GetCD( "/dev/disk" );
1163 BMenu::AttachedToWindow();
1166 /*****************************************************************************
1168 *****************************************************************************/
1169 int CDMenu::GetCD( const char *directory )
1171 BVolumeRoster volRoster;
1174 status_t status = volRoster.GetNextVolume( &vol );
1175 while ( status == B_NO_ERROR )
1180 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1183 BMessage* msg = new BMessage( OPEN_DVD );
1184 msg->AddString( "device", deviceName.String() );
1185 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1189 status = volRoster.GetNextVolume( &vol );
1193 /*****************************************************************************
1194 * LanguageMenu::LanguageMenu
1195 *****************************************************************************/
1196 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
1197 VlcWrapper *p_wrapper )
1201 this->p_wrapper = p_wrapper;
1204 /*****************************************************************************
1205 * LanguageMenu::~LanguageMenu
1206 *****************************************************************************/
1207 LanguageMenu::~LanguageMenu()
1211 /*****************************************************************************
1212 * LanguageMenu::AttachedToWindow
1213 *****************************************************************************/
1214 void LanguageMenu::AttachedToWindow()
1217 while ( BMenuItem* item = RemoveItem( 0L ) )
1220 SetRadioMode( true );
1221 if ( BList *list = p_wrapper->GetChannels( kind ) )
1223 for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1226 if ( list->CountItems() > 1 )
1227 AddItem( new BSeparatorItem(), 1 );
1229 BMenu::AttachedToWindow();
1232 /*****************************************************************************
1233 * TitleMenu::TitleMenu
1234 *****************************************************************************/
1235 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1237 p_intf( p_interface )
1241 /*****************************************************************************
1242 * TitleMenu::~TitleMenu
1243 *****************************************************************************/
1244 TitleMenu::~TitleMenu()
1248 /*****************************************************************************
1249 * TitleMenu::AttachedToWindow
1250 *****************************************************************************/
1251 void TitleMenu::AttachedToWindow()
1253 while( BMenuItem* item = RemoveItem( 0L ) )
1256 if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1258 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1261 BMenu::AttachedToWindow();
1265 /*****************************************************************************
1266 * ChapterMenu::ChapterMenu
1267 *****************************************************************************/
1268 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1270 p_intf( p_interface )
1274 /*****************************************************************************
1275 * ChapterMenu::~ChapterMenu
1276 *****************************************************************************/
1277 ChapterMenu::~ChapterMenu()
1281 /*****************************************************************************
1282 * ChapterMenu::AttachedToWindow
1283 *****************************************************************************/
1284 void ChapterMenu::AttachedToWindow()
1286 while( BMenuItem* item = RemoveItem( 0L ) )
1289 if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1291 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1295 BMenu::AttachedToWindow();
1306 /*****************************************************************************
1308 *****************************************************************************/
1310 load_settings( BMessage* message, const char* fileName, const char* folder )
1312 status_t ret = B_BAD_VALUE;
1316 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1318 // passing folder is optional
1320 ret = path.Append( folder );
1321 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1323 BFile file( path.Path(), B_READ_ONLY );
1324 if ( ( ret = file.InitCheck() ) == B_OK )
1326 ret = message->Unflatten( &file );
1335 /*****************************************************************************
1337 *****************************************************************************/
1339 save_settings( BMessage* message, const char* fileName, const char* folder )
1341 status_t ret = B_BAD_VALUE;
1345 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1347 // passing folder is optional
1348 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1349 ret = create_directory( path.Path(), 0777 );
1350 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1352 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1353 if ( ( ret = file.InitCheck() ) == B_OK )
1355 ret = message->Flatten( &file );