1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.34 2003/04/22 16:36:16 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") );
217 // the media control view
218 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
220 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
223 p_mediaControl->GetPreferredSize( &width, &height );
225 // set up the main menu
226 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
227 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
229 // make menu bar resize to correct height
230 float menuWidth, menuHeight;
231 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
232 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
233 // take care of proper size for ourself
234 height += fMenuBar->Bounds().Height();
235 ResizeTo( width, height );
237 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
238 AddChild( fMenuBar );
239 AddChild( p_mediaControl );
242 BMenu* fileMenu = new BMenu( _("File") );
243 fMenuBar->AddItem( fileMenu );
244 fileMenu->AddItem( new BMenuItem( _AddEllipsis(_("Open Subtitles")),
245 new BMessage( OPEN_FILE ), 'O') );
247 fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
249 fileMenu->AddItem( new BMenuItem( _AddEllipsis(_("Open Subtitles")),
250 new BMessage( LOAD_SUBFILE ) ) );
252 fileMenu->AddSeparatorItem();
253 BMenuItem* item = new BMenuItem( _AddEllipsis(_("About")),
254 new BMessage( B_ABOUT_REQUESTED ), 'A');
255 item->SetTarget( be_app );
256 fileMenu->AddItem( item );
257 fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
259 fLanguageMenu = new LanguageMenu( _("Language"), AUDIO_ES, p_wrapper);
260 fSubtitlesMenu = new LanguageMenu( _("Subtitles"), SPU_ES, p_wrapper);
262 /* Add the Audio menu */
263 fAudioMenu = new BMenu( _("Audio") );
264 fMenuBar->AddItem ( fAudioMenu );
265 fAudioMenu->AddItem( fLanguageMenu );
266 fAudioMenu->AddItem( fSubtitlesMenu );
268 fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
269 fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
270 fPrevChapterMI = new BMenuItem( _("Prev Chapter"), new BMessage( PREV_CHAPTER ) );
271 fNextChapterMI = new BMenuItem( _("Next Chapter"), new BMessage( NEXT_CHAPTER ) );
272 fGotoMenuMI = new BMenuItem( _("Goto Menu"), new BMessage( NAVIGATE_MENU ) );
274 /* Add the Navigation menu */
275 fNavigationMenu = new BMenu( _("Navigation") );
276 fMenuBar->AddItem( fNavigationMenu );
277 fNavigationMenu->AddItem( fGotoMenuMI );
278 fNavigationMenu->AddSeparatorItem();
279 fNavigationMenu->AddItem( fPrevTitleMI );
280 fNavigationMenu->AddItem( fNextTitleMI );
281 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
282 fNavigationMenu->AddSeparatorItem();
283 fNavigationMenu->AddItem( fPrevChapterMI );
284 fNavigationMenu->AddItem( fNextChapterMI );
285 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
287 /* Add the Speed menu */
288 fSpeedMenu = new BMenu( _("Speed") );
289 fSpeedMenu->SetRadioMode( true );
290 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( _("Slower"), new BMessage( SLOWER_PLAY ) ) );
291 fNormalMI = new BMenuItem( _("Normal"), new BMessage( NORMAL_PLAY ) );
292 fNormalMI->SetMarked(true); // default to normal speed
293 fSpeedMenu->AddItem( fNormalMI );
294 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( _("Faster"), new BMessage( FASTER_PLAY) ) );
295 fSpeedMenu->SetTargetForItems( this );
296 fMenuBar->AddItem( fSpeedMenu );
298 /* Add the Show menu */
299 fShowMenu = new BMenu( _("Window") );
300 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Play List")),
301 new BMessage( OPEN_PLAYLIST ), 'P') );
302 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Messages")),
303 new BMessage( OPEN_MESSAGES ), 'M' ) );
304 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Settings")),
305 new BMessage( OPEN_PREFERENCES ), 'S' ) );
306 fMenuBar->AddItem( fShowMenu );
308 /* Prepare fow showing */
309 _SetMenusEnabled( false );
310 p_mediaControl->SetEnabled( false );
317 InterfaceWindow::~InterfaceWindow()
319 if( fPlaylistWindow )
320 fPlaylistWindow->ReallyQuit();
321 fPlaylistWindow = NULL;
322 if( fMessagesWindow )
323 fMessagesWindow->ReallyQuit();
324 fMessagesWindow = NULL;
325 if( fPreferencesWindow )
326 fPreferencesWindow->ReallyQuit();
327 fPreferencesWindow = NULL;
332 /*****************************************************************************
333 * InterfaceWindow::FrameResized
334 *****************************************************************************/
336 InterfaceWindow::FrameResized(float width, float height)
339 fMenuBar->MoveTo(r.LeftTop());
340 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
341 r.top += fMenuBar->Bounds().Height() + 1.0;
342 p_mediaControl->MoveTo(r.LeftTop());
343 p_mediaControl->ResizeTo(r.Width(), r.Height());
346 /*****************************************************************************
347 * InterfaceWindow::MessageReceived
348 *****************************************************************************/
349 void InterfaceWindow::MessageReceived( BMessage * p_message )
351 int playback_status; // remember playback state
352 playback_status = p_wrapper->InputStatus();
354 switch( p_message->what )
356 case B_ABOUT_REQUESTED:
358 BAlert* alert = new BAlert( "VLC " PACKAGE_VERSION,
359 "VLC " PACKAGE_VERSION " for BeOS"
360 "\n\n<www.videolan.org>", _("OK"));
368 _ShowFilePanel( B_REFS_RECEIVED, _("VideoLAN Client: Open Media Files") );
372 _ShowFilePanel( SUBFILE_RECEIVED, _("VideoLAN Client: Open Subtitle File") );
376 if (fPlaylistWindow->Lock())
378 if (fPlaylistWindow->IsHidden())
379 fPlaylistWindow->Show();
381 fPlaylistWindow->Activate();
382 fPlaylistWindow->Unlock();
387 const char *psz_device;
388 BString type( "dvd" );
389 if( p_message->FindString( "device", &psz_device ) == B_OK )
391 BString device( psz_device );
392 p_wrapper->OpenDisc( type, device, 0, 0 );
398 case SUBFILE_RECEIVED:
401 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
404 if ( path.InitCheck() == B_OK )
405 p_wrapper->LoadSubFile( path.Path() );
411 // this currently stops playback not nicely
412 if (playback_status > UNDEF_S)
414 p_wrapper->PlaylistStop();
415 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
420 /* starts playing in normal mode */
423 /* toggle between pause and play */
424 if (playback_status > UNDEF_S)
426 /* pause if currently playing */
427 if ( playback_status == PLAYING_S )
429 p_wrapper->PlaylistPause();
433 p_wrapper->PlaylistPlay();
438 /* Play a new file */
439 p_wrapper->PlaylistPlay();
444 /* cycle the fast playback modes */
445 if (playback_status > UNDEF_S)
447 p_wrapper->InputFaster();
452 /* cycle the slow playback modes */
453 if (playback_status > UNDEF_S)
455 p_wrapper->InputSlower();
460 /* restore speed to normal if already playing */
461 if (playback_status > UNDEF_S)
463 p_wrapper->PlaylistPlay();
468 /* handled by semaphores */
470 // volume related messages
472 /* adjust the volume */
473 if (playback_status > UNDEF_S)
475 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
476 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
482 if( p_wrapper->IsMuted() )
483 p_wrapper->VolumeRestore();
485 p_wrapper->VolumeMute();
486 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
490 if ( playback_status > UNDEF_S )
493 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
495 p_wrapper->ToggleLanguage( channel );
500 case SELECT_SUBTITLE:
501 if ( playback_status > UNDEF_S )
504 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
505 p_wrapper->ToggleSubtitle( subtitle );
509 // specific navigation messages
512 p_wrapper->PrevTitle();
517 p_wrapper->NextTitle();
521 p_wrapper->ToggleTitle( 0 );
524 if ( playback_status > UNDEF_S )
527 if( p_message->FindInt32( "index", &index ) == B_OK )
528 p_wrapper->ToggleTitle( index );
533 p_wrapper->PrevChapter();
538 p_wrapper->NextChapter();
542 if ( playback_status > UNDEF_S )
545 if( p_message->FindInt32( "index", &index ) == B_OK )
546 p_wrapper->ToggleChapter( index );
550 p_wrapper->PlaylistPrev();
553 p_wrapper->PlaylistNext();
555 // general next/prev functionality (skips to whatever makes most sense)
557 p_wrapper->NavigatePrev();
560 p_wrapper->NavigateNext();
562 // drag'n'drop and system messages
564 // convert soundplay drag'n'drop message (containing paths)
565 // to normal message (containing refs)
568 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
571 if ( get_ref_for_path( path, &ref ) == B_OK )
572 p_message->AddRef( "refs", &ref );
576 case B_REFS_RECEIVED:
579 /* file(s) opened by the File menu -> append to the playlist;
580 * file(s) opened by drag & drop -> replace playlist;
581 * file(s) opened by 'shift' + drag & drop -> append */
582 bool replace = false;
583 bool reverse = false;
584 if ( p_message->WasDropped() )
586 replace = !( modifiers() & B_SHIFT_KEY );
590 // build list of files to be played from message contents
594 // if we should parse sub-folders as well
595 bool askedAlready = false;
596 bool parseSubFolders = askedAlready;
597 // traverse refs in reverse order
600 if ( p_message->GetInfo( "refs", &dummy, &count ) == B_OK && count > 0 )
602 int32 i = reverse ? count - 1 : 0;
603 int32 increment = reverse ? -1 : 1;
604 for ( ; p_message->FindRef( "refs", i, &ref ) == B_OK; i += increment )
607 if ( path.InitCheck() == B_OK )
610 // has the user dropped a folder?
611 BDirectory dir( &ref );
612 if ( dir.InitCheck() == B_OK)
614 // has the user dropped a dvd disk icon?
615 if ( dir.IsRootDirectory() )
617 BVolumeRoster volRoster;
619 BDirectory volumeRoot;
620 status_t status = volRoster.GetNextVolume( &vol );
621 while ( status == B_NO_ERROR )
623 if ( vol.GetRootDirectory( &volumeRoot ) == B_OK
624 && dir == volumeRoot )
629 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
632 BMessage msg( OPEN_DVD );
633 msg.AddString( "device", deviceName.String() );
642 status = volRoster.GetNextVolume( &vol );
649 dir.Rewind(); // defensive programming
651 collect_folder_contents( dir, files,
659 BString* string = new BString( path.Path() );
660 if ( !files.AddItem( string, 0 ) )
661 delete string; // at least don't leak
665 // give the list to VLC
666 // BString objects allocated here will be deleted there
668 if ( p_message->FindInt32("drop index", &index) != B_OK )
670 p_wrapper->OpenFiles( &files, replace, index );
676 case OPEN_PREFERENCES:
678 if( fPreferencesWindow->Lock() )
680 if (fPreferencesWindow->IsHidden())
681 fPreferencesWindow->Show();
683 fPreferencesWindow->Activate();
684 fPreferencesWindow->Unlock();
691 if( fMessagesWindow->Lock() )
693 if (fMessagesWindow->IsHidden())
694 fMessagesWindow->Show();
696 fMessagesWindow->Activate();
697 fMessagesWindow->Unlock();
705 BWindow::MessageReceived( p_message );
711 /*****************************************************************************
712 * InterfaceWindow::QuitRequested
713 *****************************************************************************/
714 bool InterfaceWindow::QuitRequested()
716 p_wrapper->PlaylistStop();
717 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
726 /*****************************************************************************
727 * InterfaceWindow::UpdateInterface
728 *****************************************************************************/
729 void InterfaceWindow::UpdateInterface()
731 if( p_wrapper->HasInput() )
733 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
735 p_wrapper->SetTimeAsFloat( p_mediaControl->GetSeekTo() );
737 else if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
739 p_mediaControl->SetEnabled( true );
740 bool hasTitles = p_wrapper->HasTitles();
741 bool hasChapters = p_wrapper->HasChapters();
742 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
743 p_wrapper->InputRate() );
744 p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
745 _SetMenusEnabled( true, hasChapters, hasTitles );
747 _UpdateSpeedMenu( p_wrapper->InputRate() );
749 // enable/disable skip buttons
752 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
753 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
755 if ( p_wrapper->HasInput() )
757 p_mediaControl->SetAudioEnabled( true );
758 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
760 p_mediaControl->SetAudioEnabled( false );
764 // update playlist as well
765 if ( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
767 fPlaylistWindow->UpdatePlaylist();
768 fPlaylistWindow->Unlock();
773 if ( LockWithTimeout(INTERFACE_LOCKING_TIMEOUT) == B_OK )
775 _SetMenusEnabled( false );
776 if( !( p_wrapper->PlaylistSize() > 0 ) )
777 p_mediaControl->SetEnabled( false );
780 p_mediaControl->SetProgress( 0 );
781 // enable/disable skip buttons
784 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
785 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
791 fLastUpdateTime = system_time();
794 /*****************************************************************************
795 * InterfaceWindow::IsStopped
796 *****************************************************************************/
798 InterfaceWindow::IsStopped() const
800 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
803 /*****************************************************************************
804 * InterfaceWindow::_UpdatePlaylist
805 *****************************************************************************/
807 InterfaceWindow::_UpdatePlaylist()
809 if ( fPlaylistWindow->Lock() )
811 fPlaylistWindow->UpdatePlaylist( true );
812 fPlaylistWindow->Unlock();
813 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
817 /*****************************************************************************
818 * InterfaceWindow::_SetMenusEnabled
819 *****************************************************************************/
821 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
828 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
830 if ( fNextChapterMI->IsEnabled() != hasChapters )
831 fNextChapterMI->SetEnabled( hasChapters );
832 if ( fPrevChapterMI->IsEnabled() != hasChapters )
833 fPrevChapterMI->SetEnabled( hasChapters );
834 if ( fChapterMenu->IsEnabled() != hasChapters )
835 fChapterMenu->SetEnabled( hasChapters );
836 if ( fNextTitleMI->IsEnabled() != hasTitles )
837 fNextTitleMI->SetEnabled( hasTitles );
838 if ( fPrevTitleMI->IsEnabled() != hasTitles )
839 fPrevTitleMI->SetEnabled( hasTitles );
840 if ( fTitleMenu->IsEnabled() != hasTitles )
841 fTitleMenu->SetEnabled( hasTitles );
842 if ( fAudioMenu->IsEnabled() != hasFile )
843 fAudioMenu->SetEnabled( hasFile );
844 if ( fNavigationMenu->IsEnabled() != hasFile )
845 fNavigationMenu->SetEnabled( hasFile );
846 if ( fLanguageMenu->IsEnabled() != hasFile )
847 fLanguageMenu->SetEnabled( hasFile );
848 if ( fSubtitlesMenu->IsEnabled() != hasFile )
849 fSubtitlesMenu->SetEnabled( hasFile );
850 if ( fSpeedMenu->IsEnabled() != hasFile )
851 fSpeedMenu->SetEnabled( hasFile );
852 // "goto menu" menu item
853 bool hasMenu = p_intf->p_sys->b_dvdmenus ? hasTitles : false;
854 if ( fGotoMenuMI->IsEnabled() != hasMenu )
855 fGotoMenuMI->SetEnabled( hasMenu );
860 /*****************************************************************************
861 * InterfaceWindow::_UpdateSpeedMenu
862 *****************************************************************************/
864 InterfaceWindow::_UpdateSpeedMenu( int rate )
866 if ( rate == DEFAULT_RATE )
868 if ( !fNormalMI->IsMarked() )
869 fNormalMI->SetMarked( true );
871 else if ( rate < DEFAULT_RATE )
873 if ( !fFasterMI->IsMarked() )
874 fFasterMI->SetMarked( true );
878 if ( !fSlowerMI->IsMarked() )
879 fSlowerMI->SetMarked( true );
883 /*****************************************************************************
884 * InterfaceWindow::_InputStreamChanged
885 *****************************************************************************/
887 InterfaceWindow::_InputStreamChanged()
889 // TODO: move more stuff from updateInterface() here!
891 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
894 /*****************************************************************************
895 * InterfaceWindow::_ShowFilePanel
896 *****************************************************************************/
898 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
902 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
903 B_FILE_NODE | B_DIRECTORY_NODE );
904 fFilePanel->SetTarget( this );
906 fFilePanel->Window()->SetTitle( windowTitle );
907 BMessage message( command );
908 fFilePanel->SetMessage( &message );
909 if ( !fFilePanel->IsShowing() )
911 fFilePanel->Refresh();
918 set_window_pos( BWindow* window, BRect frame )
920 // sanity checks: make sure window is not too big/small
921 // and that it's not off-screen
922 float minWidth, maxWidth, minHeight, maxHeight;
923 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
925 make_sure_frame_is_within_limits( frame,
926 minWidth, minHeight, maxWidth, maxHeight );
927 if ( make_sure_frame_is_on_screen( frame ) )
929 window->MoveTo( frame.LeftTop() );
930 window->ResizeTo( frame.Width(), frame.Height() );
936 launch_window( BWindow* window, bool showing )
938 if ( window->Lock() )
942 if ( window->IsHidden() )
947 if ( !window->IsHidden() )
954 /*****************************************************************************
955 * InterfaceWindow::_RestoreSettings
956 *****************************************************************************/
958 InterfaceWindow::_RestoreSettings()
960 if ( USE_VLC_CONFIG_FILE )
962 // main window size and position
963 int i_width = config_GetInt( p_intf, "beos-intf-width" ),
964 i_height = config_GetInt( p_intf, "beos-intf-height" ),
965 i_xpos = config_GetInt( p_intf, "beos-intf-xpos" ),
966 i_ypos = config_GetInt( p_intf, "beos-intf-ypos" );
967 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
969 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
970 set_window_pos( this, r );
972 // playlist window size and position
973 i_width = config_GetInt( p_intf, "beos-playlist-width" ),
974 i_height = config_GetInt( p_intf, "beos-playlist-height" ),
975 i_xpos = config_GetInt( p_intf, "beos-playlist-xpos" ),
976 i_ypos = config_GetInt( p_intf, "beos-playlist-ypos" );
977 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
979 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
980 set_window_pos( fPlaylistWindow, r );
983 launch_window( fPlaylistWindow, config_GetInt( p_intf, "beos-playlist-show" ) );
984 // messages window size and position
985 i_width = config_GetInt( p_intf, "beos-messages-width" ),
986 i_height = config_GetInt( p_intf, "beos-messages-height" ),
987 i_xpos = config_GetInt( p_intf, "beos-messages-xpos" ),
988 i_ypos = config_GetInt( p_intf, "beos-messages-ypos" );
989 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
991 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
992 set_window_pos( fMessagesWindow, r );
995 launch_window( fMessagesWindow, config_GetInt( p_intf, "beos-messages-show" ) );
997 // messages window size and position
998 i_width = config_GetInt( p_intf, "beos-settings-width" ),
999 i_height = config_GetInt( p_intf, "beos-settings-height" ),
1000 i_xpos = config_GetInt( p_intf, "beos-settings-xpos" ),
1001 i_ypos = config_GetInt( p_intf, "beos-settings-ypos" );
1002 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
1004 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
1005 set_window_pos( fPreferencesWindow, r );
1008 launch_window( fPreferencesWindow, config_GetInt( p_intf, "beos-settings-show" ) );
1012 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1015 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1016 set_window_pos( this, frame );
1017 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1018 set_window_pos( fPlaylistWindow, frame );
1019 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1020 set_window_pos( fMessagesWindow, frame );
1021 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1022 set_window_pos( fPreferencesWindow, frame );
1025 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1026 launch_window( fPlaylistWindow, showing );
1027 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1028 launch_window( fMessagesWindow, showing );
1029 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1030 launch_window( fPreferencesWindow, showing );
1033 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1034 fPlaylistWindow->SetDisplayMode( displayMode );
1039 /*****************************************************************************
1040 * InterfaceWindow::_StoreSettings
1041 *****************************************************************************/
1043 InterfaceWindow::_StoreSettings()
1045 if ( USE_VLC_CONFIG_FILE )
1047 // save interface settings in vlc config file
1048 BRect frame = Frame();
1049 config_PutInt( p_intf, "beos-intf-width", (int)frame.Width() );
1050 config_PutInt( p_intf, "beos-intf-height", (int)frame.Height() );
1051 config_PutInt( p_intf, "beos-intf-xpos", (int)frame.left );
1052 config_PutInt( p_intf, "beos-intf-ypos", (int)frame.top );
1053 if( fPlaylistWindow->Lock() )
1055 frame = fPlaylistWindow->Frame();
1056 config_PutInt( p_intf, "beos-playlist-width", (int)frame.Width() );
1057 config_PutInt( p_intf, "beos-playlist-height", (int)frame.Height() );
1058 config_PutInt( p_intf, "beos-playlist-xpos", (int)frame.left );
1059 config_PutInt( p_intf, "beos-playlist-ypos", (int)frame.top );
1060 config_PutInt( p_intf, "beos-playlist-show", !fPlaylistWindow->IsHidden() );
1061 fPlaylistWindow->Unlock();
1063 if( fMessagesWindow->Lock() )
1065 frame = fMessagesWindow->Frame();
1066 config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
1067 config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
1068 config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
1069 config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
1070 config_PutInt( p_intf, "beos-messages-show", !fMessagesWindow->IsHidden() );
1071 fMessagesWindow->Unlock();
1073 if( fPreferencesWindow->Lock() )
1075 frame = fPreferencesWindow->Frame();
1076 config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
1077 config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
1078 config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
1079 config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
1080 config_PutInt( p_intf, "beos-messages-show", !fPreferencesWindow->IsHidden() );
1081 fPreferencesWindow->Unlock();
1086 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1087 fSettings->AddRect( "main frame", Frame() );
1088 if ( fPlaylistWindow->Lock() )
1090 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1091 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1092 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1093 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1094 fPlaylistWindow->Unlock();
1096 if ( fMessagesWindow->Lock() )
1098 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1099 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1100 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1101 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1102 fMessagesWindow->Unlock();
1104 if ( fPreferencesWindow->Lock() )
1106 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1107 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1108 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1109 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1110 fPreferencesWindow->Unlock();
1112 uint32 displayMode = fPlaylistWindow->DisplayMode();
1113 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1114 fSettings->AddInt32( "playlist display mode", displayMode );
1116 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1119 // save VLC internal settings
1120 config_SaveConfigFile( p_intf, "beos" );
1121 config_SaveConfigFile( p_intf, "main" );
1122 config_SaveConfigFile( p_intf, "adjust" );
1123 config_SaveConfigFile( p_intf, "ffmpeg" );
1131 /*****************************************************************************
1133 *****************************************************************************/
1134 CDMenu::CDMenu(const char *name)
1139 /*****************************************************************************
1141 *****************************************************************************/
1146 /*****************************************************************************
1147 * CDMenu::AttachedToWindow
1148 *****************************************************************************/
1149 void CDMenu::AttachedToWindow(void)
1152 while ( BMenuItem* item = RemoveItem( 0L ) )
1154 GetCD( "/dev/disk" );
1155 BMenu::AttachedToWindow();
1158 /*****************************************************************************
1160 *****************************************************************************/
1161 int CDMenu::GetCD( const char *directory )
1163 BVolumeRoster volRoster;
1166 status_t status = volRoster.GetNextVolume( &vol );
1167 while ( status == B_NO_ERROR )
1172 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1175 BMessage* msg = new BMessage( OPEN_DVD );
1176 msg->AddString( "device", deviceName.String() );
1177 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1181 status = volRoster.GetNextVolume( &vol );
1186 /*****************************************************************************
1187 * LanguageMenu::LanguageMenu
1188 *****************************************************************************/
1189 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
1190 VlcWrapper *p_wrapper )
1194 this->p_wrapper = p_wrapper;
1197 /*****************************************************************************
1198 * LanguageMenu::~LanguageMenu
1199 *****************************************************************************/
1200 LanguageMenu::~LanguageMenu()
1204 /*****************************************************************************
1205 * LanguageMenu::AttachedToWindow
1206 *****************************************************************************/
1207 void LanguageMenu::AttachedToWindow()
1210 while ( BMenuItem* item = RemoveItem( 0L ) )
1213 SetRadioMode( true );
1214 if ( BList *list = p_wrapper->GetChannels( kind ) )
1216 for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1219 if ( list->CountItems() > 1 )
1220 AddItem( new BSeparatorItem(), 1 );
1222 BMenu::AttachedToWindow();
1225 /*****************************************************************************
1226 * TitleMenu::TitleMenu
1227 *****************************************************************************/
1228 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1230 p_intf( p_interface )
1234 /*****************************************************************************
1235 * TitleMenu::~TitleMenu
1236 *****************************************************************************/
1237 TitleMenu::~TitleMenu()
1241 /*****************************************************************************
1242 * TitleMenu::AttachedToWindow
1243 *****************************************************************************/
1244 void TitleMenu::AttachedToWindow()
1246 while( BMenuItem* item = RemoveItem( 0L ) )
1249 if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1251 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1254 BMenu::AttachedToWindow();
1258 /*****************************************************************************
1259 * ChapterMenu::ChapterMenu
1260 *****************************************************************************/
1261 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1263 p_intf( p_interface )
1267 /*****************************************************************************
1268 * ChapterMenu::~ChapterMenu
1269 *****************************************************************************/
1270 ChapterMenu::~ChapterMenu()
1274 /*****************************************************************************
1275 * ChapterMenu::AttachedToWindow
1276 *****************************************************************************/
1277 void ChapterMenu::AttachedToWindow()
1279 while( BMenuItem* item = RemoveItem( 0L ) )
1282 if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1284 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1288 BMenu::AttachedToWindow();
1299 /*****************************************************************************
1301 *****************************************************************************/
1303 load_settings( BMessage* message, const char* fileName, const char* folder )
1305 status_t ret = B_BAD_VALUE;
1309 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1311 // passing folder is optional
1313 ret = path.Append( folder );
1314 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1316 BFile file( path.Path(), B_READ_ONLY );
1317 if ( ( ret = file.InitCheck() ) == B_OK )
1319 ret = message->Unflatten( &file );
1328 /*****************************************************************************
1330 *****************************************************************************/
1332 save_settings( BMessage* message, const char* fileName, const char* folder )
1334 status_t ret = B_BAD_VALUE;
1338 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1340 // passing folder is optional
1341 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1342 ret = create_directory( path.Path(), 0777 );
1343 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1345 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1346 if ( ( ret = file.InitCheck() ) == B_OK )
1348 ret = message->Flatten( &file );