1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.30 2003/02/10 15:23:46 titer Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tony@castley.net>
10 * Richard Shepherd <richard@rshepherd.demon.co.uk>
11 * Stephan Aßmus <stippi@yellowbites.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
29 #include <kernel/OS.h>
30 #include <InterfaceKit.h>
32 #include <StorageKit.h>
33 #include <SupportKit.h>
36 #include <scsiprobe_driver.h>
45 /* BeOS interface headers */
46 #include "VlcWrapper.h"
48 #include "MediaControlView.h"
49 #include "PlayListWindow.h"
50 #include "PreferencesWindow.h"
51 #include "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 fLastUpdateTime = system_time();
797 /*****************************************************************************
798 * InterfaceWindow::IsStopped
799 *****************************************************************************/
801 InterfaceWindow::IsStopped() const
803 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
806 /*****************************************************************************
807 * InterfaceWindow::_UpdatePlaylist
808 *****************************************************************************/
810 InterfaceWindow::_UpdatePlaylist()
812 if ( fPlaylistWindow->Lock() )
814 fPlaylistWindow->UpdatePlaylist( true );
815 fPlaylistWindow->Unlock();
816 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
820 /*****************************************************************************
821 * InterfaceWindow::_SetMenusEnabled
822 *****************************************************************************/
824 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
831 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
833 if ( fNextChapterMI->IsEnabled() != hasChapters )
834 fNextChapterMI->SetEnabled( hasChapters );
835 if ( fPrevChapterMI->IsEnabled() != hasChapters )
836 fPrevChapterMI->SetEnabled( hasChapters );
837 if ( fChapterMenu->IsEnabled() != hasChapters )
838 fChapterMenu->SetEnabled( hasChapters );
839 if ( fNextTitleMI->IsEnabled() != hasTitles )
840 fNextTitleMI->SetEnabled( hasTitles );
841 if ( fPrevTitleMI->IsEnabled() != hasTitles )
842 fPrevTitleMI->SetEnabled( hasTitles );
843 if ( fTitleMenu->IsEnabled() != hasTitles )
844 fTitleMenu->SetEnabled( hasTitles );
845 if ( fAudioMenu->IsEnabled() != hasFile )
846 fAudioMenu->SetEnabled( hasFile );
847 if ( fNavigationMenu->IsEnabled() != hasFile )
848 fNavigationMenu->SetEnabled( hasFile );
849 if ( fLanguageMenu->IsEnabled() != hasFile )
850 fLanguageMenu->SetEnabled( hasFile );
851 if ( fSubtitlesMenu->IsEnabled() != hasFile )
852 fSubtitlesMenu->SetEnabled( hasFile );
853 if ( fSpeedMenu->IsEnabled() != hasFile )
854 fSpeedMenu->SetEnabled( hasFile );
855 // "goto menu" menu item
856 bool hasMenu = p_intf->p_sys->b_dvdmenus ? hasTitles : false;
857 if ( fGotoMenuMI->IsEnabled() != hasMenu )
858 fGotoMenuMI->SetEnabled( hasMenu );
863 /*****************************************************************************
864 * InterfaceWindow::_UpdateSpeedMenu
865 *****************************************************************************/
867 InterfaceWindow::_UpdateSpeedMenu( int rate )
869 if ( rate == DEFAULT_RATE )
871 if ( !fNormalMI->IsMarked() )
872 fNormalMI->SetMarked( true );
874 else if ( rate < DEFAULT_RATE )
876 if ( !fFasterMI->IsMarked() )
877 fFasterMI->SetMarked( true );
881 if ( !fSlowerMI->IsMarked() )
882 fSlowerMI->SetMarked( true );
886 /*****************************************************************************
887 * InterfaceWindow::_InputStreamChanged
888 *****************************************************************************/
890 InterfaceWindow::_InputStreamChanged()
892 // TODO: move more stuff from updateInterface() here!
894 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
897 /*****************************************************************************
898 * InterfaceWindow::_ShowFilePanel
899 *****************************************************************************/
901 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
905 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
906 B_FILE_NODE | B_DIRECTORY_NODE );
907 fFilePanel->SetTarget( this );
909 fFilePanel->Window()->SetTitle( windowTitle );
910 BMessage message( command );
911 fFilePanel->SetMessage( &message );
912 if ( !fFilePanel->IsShowing() )
914 fFilePanel->Refresh();
921 set_window_pos( BWindow* window, BRect frame )
923 // sanity checks: make sure window is not too big/small
924 // and that it's not off-screen
925 float minWidth, maxWidth, minHeight, maxHeight;
926 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
928 make_sure_frame_is_within_limits( frame,
929 minWidth, minHeight, maxWidth, maxHeight );
930 if ( make_sure_frame_is_on_screen( frame ) )
932 window->MoveTo( frame.LeftTop() );
933 window->ResizeTo( frame.Width(), frame.Height() );
939 launch_window( BWindow* window, bool showing )
941 if ( window->Lock() )
945 if ( window->IsHidden() )
950 if ( !window->IsHidden() )
957 /*****************************************************************************
958 * InterfaceWindow::_RestoreSettings
959 *****************************************************************************/
961 InterfaceWindow::_RestoreSettings()
963 if ( USE_VLC_CONFIG_FILE )
965 // main window size and position
966 int i_width = config_GetInt( p_intf, "beos-intf-width" ),
967 i_height = config_GetInt( p_intf, "beos-intf-height" ),
968 i_xpos = config_GetInt( p_intf, "beos-intf-xpos" ),
969 i_ypos = config_GetInt( p_intf, "beos-intf-ypos" );
970 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
972 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
973 set_window_pos( this, r );
975 // playlist window size and position
976 i_width = config_GetInt( p_intf, "beos-playlist-width" ),
977 i_height = config_GetInt( p_intf, "beos-playlist-height" ),
978 i_xpos = config_GetInt( p_intf, "beos-playlist-xpos" ),
979 i_ypos = config_GetInt( p_intf, "beos-playlist-ypos" );
980 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
982 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
983 set_window_pos( fPlaylistWindow, r );
986 launch_window( fPlaylistWindow, config_GetInt( p_intf, "beos-playlist-show" ) );
987 // messages window size and position
988 i_width = config_GetInt( p_intf, "beos-messages-width" ),
989 i_height = config_GetInt( p_intf, "beos-messages-height" ),
990 i_xpos = config_GetInt( p_intf, "beos-messages-xpos" ),
991 i_ypos = config_GetInt( p_intf, "beos-messages-ypos" );
992 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
994 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
995 set_window_pos( fMessagesWindow, r );
998 launch_window( fMessagesWindow, config_GetInt( p_intf, "beos-messages-show" ) );
1000 // messages window size and position
1001 i_width = config_GetInt( p_intf, "beos-settings-width" ),
1002 i_height = config_GetInt( p_intf, "beos-settings-height" ),
1003 i_xpos = config_GetInt( p_intf, "beos-settings-xpos" ),
1004 i_ypos = config_GetInt( p_intf, "beos-settings-ypos" );
1005 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
1007 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
1008 set_window_pos( fPreferencesWindow, r );
1011 launch_window( fPreferencesWindow, config_GetInt( p_intf, "beos-settings-show" ) );
1015 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1018 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1019 set_window_pos( this, frame );
1020 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1021 set_window_pos( fPlaylistWindow, frame );
1022 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1023 set_window_pos( fMessagesWindow, frame );
1024 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1025 set_window_pos( fPreferencesWindow, frame );
1028 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1029 launch_window( fPlaylistWindow, showing );
1030 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1031 launch_window( fMessagesWindow, showing );
1032 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1033 launch_window( fPreferencesWindow, showing );
1036 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1037 fPlaylistWindow->SetDisplayMode( displayMode );
1042 /*****************************************************************************
1043 * InterfaceWindow::_StoreSettings
1044 *****************************************************************************/
1046 InterfaceWindow::_StoreSettings()
1048 if ( USE_VLC_CONFIG_FILE )
1050 // save interface settings in vlc config file
1051 BRect frame = Frame();
1052 config_PutInt( p_intf, "beos-intf-width", (int)frame.Width() );
1053 config_PutInt( p_intf, "beos-intf-height", (int)frame.Height() );
1054 config_PutInt( p_intf, "beos-intf-xpos", (int)frame.left );
1055 config_PutInt( p_intf, "beos-intf-ypos", (int)frame.top );
1056 if( fPlaylistWindow->Lock() )
1058 frame = fPlaylistWindow->Frame();
1059 config_PutInt( p_intf, "beos-playlist-width", (int)frame.Width() );
1060 config_PutInt( p_intf, "beos-playlist-height", (int)frame.Height() );
1061 config_PutInt( p_intf, "beos-playlist-xpos", (int)frame.left );
1062 config_PutInt( p_intf, "beos-playlist-ypos", (int)frame.top );
1063 config_PutInt( p_intf, "beos-playlist-show", !fPlaylistWindow->IsHidden() );
1064 fPlaylistWindow->Unlock();
1066 if( fMessagesWindow->Lock() )
1068 frame = fMessagesWindow->Frame();
1069 config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
1070 config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
1071 config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
1072 config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
1073 config_PutInt( p_intf, "beos-messages-show", !fMessagesWindow->IsHidden() );
1074 fMessagesWindow->Unlock();
1076 if( fPreferencesWindow->Lock() )
1078 frame = fPreferencesWindow->Frame();
1079 config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
1080 config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
1081 config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
1082 config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
1083 config_PutInt( p_intf, "beos-messages-show", !fPreferencesWindow->IsHidden() );
1084 fPreferencesWindow->Unlock();
1089 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1090 fSettings->AddRect( "main frame", Frame() );
1091 if ( fPlaylistWindow->Lock() )
1093 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1094 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1095 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1096 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1097 fPlaylistWindow->Unlock();
1099 if ( fMessagesWindow->Lock() )
1101 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1102 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1103 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1104 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1105 fMessagesWindow->Unlock();
1107 if ( fPreferencesWindow->Lock() )
1109 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1110 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1111 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1112 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1113 fPreferencesWindow->Unlock();
1115 uint32 displayMode = fPlaylistWindow->DisplayMode();
1116 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1117 fSettings->AddInt32( "playlist display mode", displayMode );
1119 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1122 // save VLC internal settings
1123 config_SaveConfigFile( p_intf, "beos" );
1124 config_SaveConfigFile( p_intf, "main" );
1125 config_SaveConfigFile( p_intf, "adjust" );
1126 config_SaveConfigFile( p_intf, "ffmpeg" );
1134 /*****************************************************************************
1136 *****************************************************************************/
1137 CDMenu::CDMenu(const char *name)
1142 /*****************************************************************************
1144 *****************************************************************************/
1149 /*****************************************************************************
1150 * CDMenu::AttachedToWindow
1151 *****************************************************************************/
1152 void CDMenu::AttachedToWindow(void)
1155 while ( BMenuItem* item = RemoveItem( 0L ) )
1157 GetCD( "/dev/disk" );
1158 BMenu::AttachedToWindow();
1161 /*****************************************************************************
1163 *****************************************************************************/
1164 int CDMenu::GetCD( const char *directory )
1166 BVolumeRoster volRoster;
1169 status_t status = volRoster.GetNextVolume( &vol );
1170 while ( status == B_NO_ERROR )
1175 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1178 BMessage* msg = new BMessage( OPEN_DVD );
1179 msg->AddString( "device", deviceName.String() );
1180 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1184 status = volRoster.GetNextVolume( &vol );
1188 /*****************************************************************************
1189 * LanguageMenu::LanguageMenu
1190 *****************************************************************************/
1191 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
1192 VlcWrapper *p_wrapper )
1196 this->p_wrapper = p_wrapper;
1199 /*****************************************************************************
1200 * LanguageMenu::~LanguageMenu
1201 *****************************************************************************/
1202 LanguageMenu::~LanguageMenu()
1206 /*****************************************************************************
1207 * LanguageMenu::AttachedToWindow
1208 *****************************************************************************/
1209 void LanguageMenu::AttachedToWindow()
1212 while ( BMenuItem* item = RemoveItem( 0L ) )
1215 SetRadioMode( true );
1216 if ( BList *list = p_wrapper->GetChannels( kind ) )
1218 for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1221 if ( list->CountItems() > 1 )
1222 AddItem( new BSeparatorItem(), 1 );
1224 BMenu::AttachedToWindow();
1227 /*****************************************************************************
1228 * TitleMenu::TitleMenu
1229 *****************************************************************************/
1230 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1232 p_intf( p_interface )
1236 /*****************************************************************************
1237 * TitleMenu::~TitleMenu
1238 *****************************************************************************/
1239 TitleMenu::~TitleMenu()
1243 /*****************************************************************************
1244 * TitleMenu::AttachedToWindow
1245 *****************************************************************************/
1246 void TitleMenu::AttachedToWindow()
1248 while( BMenuItem* item = RemoveItem( 0L ) )
1251 if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1253 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1256 BMenu::AttachedToWindow();
1260 /*****************************************************************************
1261 * ChapterMenu::ChapterMenu
1262 *****************************************************************************/
1263 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1265 p_intf( p_interface )
1269 /*****************************************************************************
1270 * ChapterMenu::~ChapterMenu
1271 *****************************************************************************/
1272 ChapterMenu::~ChapterMenu()
1276 /*****************************************************************************
1277 * ChapterMenu::AttachedToWindow
1278 *****************************************************************************/
1279 void ChapterMenu::AttachedToWindow()
1281 while( BMenuItem* item = RemoveItem( 0L ) )
1284 if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1286 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1290 BMenu::AttachedToWindow();
1301 /*****************************************************************************
1303 *****************************************************************************/
1305 load_settings( BMessage* message, const char* fileName, const char* folder )
1307 status_t ret = B_BAD_VALUE;
1311 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1313 // passing folder is optional
1315 ret = path.Append( folder );
1316 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1318 BFile file( path.Path(), B_READ_ONLY );
1319 if ( ( ret = file.InitCheck() ) == B_OK )
1321 ret = message->Unflatten( &file );
1330 /*****************************************************************************
1332 *****************************************************************************/
1334 save_settings( BMessage* message, const char* fileName, const char* folder )
1336 status_t ret = B_BAD_VALUE;
1340 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1342 // passing folder is optional
1343 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1344 ret = create_directory( path.Path(), 0777 );
1345 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1347 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1348 if ( ( ret = file.InitCheck() ) == B_OK )
1350 ret = message->Flatten( &file );