1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.37 2003/05/07 14:49:19 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
57 // make_sure_frame_is_on_screen
59 make_sure_frame_is_on_screen( BRect& frame )
61 BScreen screen( B_MAIN_SCREEN_ID );
62 if (frame.IsValid() && screen.IsValid()) {
63 if (!screen.Frame().Contains(frame)) {
64 // make sure frame fits in the screen
65 if (frame.Width() > screen.Frame().Width())
66 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
67 if (frame.Height() > screen.Frame().Height())
68 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
69 // frame is now at the most the size of the screen
70 if (frame.right > screen.Frame().right)
71 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
72 if (frame.bottom > screen.Frame().bottom)
73 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
74 if (frame.left < screen.Frame().left)
75 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
76 if (frame.top < screen.Frame().top)
77 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
84 // make_sure_frame_is_within_limits
86 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
87 float maxWidth, float maxHeight )
89 if ( frame.Width() < minWidth )
90 frame.right = frame.left + minWidth;
91 if ( frame.Height() < minHeight )
92 frame.bottom = frame.top + minHeight;
93 if ( frame.Width() > maxWidth )
94 frame.right = frame.left + maxWidth;
95 if ( frame.Height() > maxHeight )
96 frame.bottom = frame.top + maxHeight;
101 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
103 bool success = false;
107 char name[B_FILE_NAME_LENGTH];
108 if ( volume.GetName( name ) >= B_OK ) // disk is currently mounted
111 dev_t dev = volume.Device();
113 if ( fs_stat_dev( dev, &info ) == B_OK )
116 deviceName = info.device_name;
117 if ( volume.IsReadOnly() )
119 int i_dev = open( info.device_name, O_RDONLY );
123 if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
124 isCDROM = ( g.device_type == B_CD );
133 // collect_folder_contents
135 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
137 while ( dir.GetNextEntry( &entry, true ) == B_OK )
139 if ( !entry.IsDirectory() )
142 // since the directory will give us the entries in reverse order,
143 // we put them each at the same index, effectively reversing the
144 // items while adding them
145 if ( entry.GetPath( &path ) == B_OK )
147 BString* string = new BString( path.Path() );
148 if ( !list.AddItem( string, 0 ) )
149 delete string; // at least don't leak
156 // ask user if we should parse sub-folders as well
157 BAlert* alert = new BAlert( "sub-folders?",
158 _("Open files from all sub-folders as well?"),
159 _("No"), _("Yes"), NULL, B_WIDTH_AS_USUAL,
161 int32 buttonIndex = alert->Go();
162 deep = buttonIndex == 1;
164 // never delete BAlerts!!
168 BDirectory subDir( &entry );
169 if ( subDir.InitCheck() == B_OK )
170 collect_folder_contents( subDir, list,
171 deep, asked, entry );
178 /*****************************************************************************
180 *****************************************************************************/
182 InterfaceWindow::InterfaceWindow( BRect frame, const char* name,
183 intf_thread_t* p_interface )
184 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
185 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
186 p_intf( p_interface ),
188 fLastUpdateTime( system_time() ),
189 fSettings( new BMessage( 'sett' ) ),
190 p_wrapper( p_intf->p_sys->p_wrapper )
192 fPlaylistIsEmpty = !( p_wrapper->PlaylistSize() > 0 );
195 BRect screen_rect = screen.Frame();
197 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
198 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
199 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
200 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
201 fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
202 window_rect.Set( screen_rect.right - 500,
203 screen_rect.top + 50,
204 screen_rect.right - 150,
205 screen_rect.top + 250 );
206 fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
207 window_rect.Set( screen_rect.right - 500,
208 screen_rect.top + 300,
209 screen_rect.right - 150,
210 screen_rect.top + 600 );
211 fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
213 // the media control view
214 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
216 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
219 p_mediaControl->GetPreferredSize( &width, &height );
221 // set up the main menu
222 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
223 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
225 // make menu bar resize to correct height
226 float menuWidth, menuHeight;
227 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
228 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
229 // take care of proper size for ourself
230 height += fMenuBar->Bounds().Height();
231 ResizeTo( width, height );
233 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
234 AddChild( fMenuBar );
235 AddChild( p_mediaControl );
238 BMenu* fileMenu = new BMenu( _("File") );
239 fMenuBar->AddItem( fileMenu );
240 fileMenu->AddItem( new BMenuItem( _AddEllipsis(_("Open File")),
241 new BMessage( OPEN_FILE ), 'O') );
243 fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
245 fileMenu->AddItem( new BMenuItem( _AddEllipsis(_("Open Subtitles")),
246 new BMessage( LOAD_SUBFILE ) ) );
248 fileMenu->AddSeparatorItem();
249 BMenuItem* item = new BMenuItem( _AddEllipsis(_("About")),
250 new BMessage( B_ABOUT_REQUESTED ), 'A');
251 item->SetTarget( be_app );
252 fileMenu->AddItem( item );
253 fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
255 fLanguageMenu = new LanguageMenu( _("Language"), AUDIO_ES, p_wrapper);
256 fSubtitlesMenu = new LanguageMenu( _("Subtitles"), SPU_ES, p_wrapper);
258 /* Add the Audio menu */
259 fAudioMenu = new BMenu( _("Audio") );
260 fMenuBar->AddItem ( fAudioMenu );
261 fAudioMenu->AddItem( fLanguageMenu );
262 fAudioMenu->AddItem( fSubtitlesMenu );
264 fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
265 fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
266 fPrevChapterMI = new BMenuItem( _("Prev Chapter"), new BMessage( PREV_CHAPTER ) );
267 fNextChapterMI = new BMenuItem( _("Next Chapter"), new BMessage( NEXT_CHAPTER ) );
268 fGotoMenuMI = new BMenuItem( _("Goto Menu"), new BMessage( NAVIGATE_MENU ) );
270 /* Add the Navigation menu */
271 fNavigationMenu = new BMenu( _("Navigation") );
272 fMenuBar->AddItem( fNavigationMenu );
273 fNavigationMenu->AddItem( fGotoMenuMI );
274 fNavigationMenu->AddSeparatorItem();
275 fNavigationMenu->AddItem( fPrevTitleMI );
276 fNavigationMenu->AddItem( fNextTitleMI );
277 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
278 fNavigationMenu->AddSeparatorItem();
279 fNavigationMenu->AddItem( fPrevChapterMI );
280 fNavigationMenu->AddItem( fNextChapterMI );
281 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
283 /* Add the Speed menu */
284 fSpeedMenu = new BMenu( _("Speed") );
285 fSpeedMenu->SetRadioMode( true );
286 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( _("Slower"), new BMessage( SLOWER_PLAY ) ) );
287 fNormalMI = new BMenuItem( _("Normal"), new BMessage( NORMAL_PLAY ) );
288 fNormalMI->SetMarked(true); // default to normal speed
289 fSpeedMenu->AddItem( fNormalMI );
290 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( _("Faster"), new BMessage( FASTER_PLAY) ) );
291 fSpeedMenu->SetTargetForItems( this );
292 fMenuBar->AddItem( fSpeedMenu );
294 /* Add the Show menu */
295 fShowMenu = new BMenu( _("Window") );
296 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Play List")),
297 new BMessage( OPEN_PLAYLIST ), 'P') );
298 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Messages")),
299 new BMessage( OPEN_MESSAGES ), 'M' ) );
300 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Preferences")),
301 new BMessage( OPEN_PREFERENCES ), 'S' ) );
302 fMenuBar->AddItem( fShowMenu );
304 /* Prepare fow showing */
305 _SetMenusEnabled( false );
306 p_mediaControl->SetEnabled( false );
313 InterfaceWindow::~InterfaceWindow()
315 if( fPlaylistWindow )
316 fPlaylistWindow->ReallyQuit();
317 fPlaylistWindow = NULL;
318 if( fMessagesWindow )
319 fMessagesWindow->ReallyQuit();
320 fMessagesWindow = NULL;
321 if( fPreferencesWindow )
322 fPreferencesWindow->ReallyQuit();
323 fPreferencesWindow = NULL;
328 /*****************************************************************************
329 * InterfaceWindow::FrameResized
330 *****************************************************************************/
332 InterfaceWindow::FrameResized(float width, float height)
335 fMenuBar->MoveTo(r.LeftTop());
336 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
337 r.top += fMenuBar->Bounds().Height() + 1.0;
338 p_mediaControl->MoveTo(r.LeftTop());
339 p_mediaControl->ResizeTo(r.Width(), r.Height());
342 /*****************************************************************************
343 * InterfaceWindow::MessageReceived
344 *****************************************************************************/
345 void InterfaceWindow::MessageReceived( BMessage * p_message )
347 int playback_status; // remember playback state
348 playback_status = p_wrapper->InputStatus();
350 switch( p_message->what )
352 case B_ABOUT_REQUESTED:
354 BAlert* alert = new BAlert( "VLC " PACKAGE_VERSION,
355 "VLC " PACKAGE_VERSION " for BeOS"
356 "\n\n<www.videolan.org>", _("OK"));
364 _ShowFilePanel( B_REFS_RECEIVED, _("VideoLAN Client: Open Media Files") );
368 _ShowFilePanel( SUBFILE_RECEIVED, _("VideoLAN Client: Open Subtitle File") );
372 if (fPlaylistWindow->Lock())
374 if (fPlaylistWindow->IsHidden())
375 fPlaylistWindow->Show();
377 fPlaylistWindow->Activate();
378 fPlaylistWindow->Unlock();
383 const char *psz_device;
384 BString type( "dvd" );
385 if( p_message->FindString( "device", &psz_device ) == B_OK )
387 BString device( psz_device );
388 p_wrapper->OpenDisc( type, device, 0, 0 );
394 case SUBFILE_RECEIVED:
397 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
400 if ( path.InitCheck() == B_OK )
401 p_wrapper->LoadSubFile( path.Path() );
407 // this currently stops playback not nicely
408 if (playback_status > UNDEF_S)
410 p_wrapper->PlaylistStop();
411 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
416 /* starts playing in normal mode */
419 /* toggle between pause and play */
420 if (playback_status > UNDEF_S)
422 /* pause if currently playing */
423 if ( playback_status == PLAYING_S )
425 p_wrapper->PlaylistPause();
429 p_wrapper->PlaylistPlay();
434 /* Play a new file */
435 p_wrapper->PlaylistPlay();
440 /* cycle the fast playback modes */
441 if (playback_status > UNDEF_S)
443 p_wrapper->InputFaster();
448 /* cycle the slow playback modes */
449 if (playback_status > UNDEF_S)
451 p_wrapper->InputSlower();
456 /* restore speed to normal if already playing */
457 if (playback_status > UNDEF_S)
459 p_wrapper->PlaylistPlay();
464 /* handled by semaphores */
466 // volume related messages
468 /* adjust the volume */
469 if (playback_status > UNDEF_S)
471 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
472 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
478 if( p_wrapper->IsMuted() )
479 p_wrapper->VolumeRestore();
481 p_wrapper->VolumeMute();
482 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
486 if ( playback_status > UNDEF_S )
489 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
491 p_wrapper->ToggleLanguage( channel );
496 case SELECT_SUBTITLE:
497 if ( playback_status > UNDEF_S )
500 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
501 p_wrapper->ToggleSubtitle( subtitle );
505 // specific navigation messages
508 p_wrapper->PrevTitle();
513 p_wrapper->NextTitle();
517 p_wrapper->ToggleTitle( 0 );
520 if ( playback_status > UNDEF_S )
523 if( p_message->FindInt32( "index", &index ) == B_OK )
524 p_wrapper->ToggleTitle( index );
529 p_wrapper->PrevChapter();
534 p_wrapper->NextChapter();
538 if ( playback_status > UNDEF_S )
541 if( p_message->FindInt32( "index", &index ) == B_OK )
542 p_wrapper->ToggleChapter( index );
546 p_wrapper->PlaylistPrev();
549 p_wrapper->PlaylistNext();
551 // general next/prev functionality (skips to whatever makes most sense)
553 p_wrapper->NavigatePrev();
556 p_wrapper->NavigateNext();
558 // drag'n'drop and system messages
560 // convert soundplay drag'n'drop message (containing paths)
561 // to normal message (containing refs)
564 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
567 if ( get_ref_for_path( path, &ref ) == B_OK )
568 p_message->AddRef( "refs", &ref );
572 case B_REFS_RECEIVED:
575 /* file(s) opened by the File menu -> append to the playlist;
576 * file(s) opened by drag & drop -> replace playlist;
577 * file(s) opened by 'shift' + drag & drop -> append */
578 bool replace = false;
579 bool reverse = false;
580 if ( p_message->WasDropped() )
582 replace = !( modifiers() & B_SHIFT_KEY );
586 // build list of files to be played from message contents
590 // if we should parse sub-folders as well
591 bool askedAlready = false;
592 bool parseSubFolders = askedAlready;
593 // traverse refs in reverse order
596 if ( p_message->GetInfo( "refs", &dummy, &count ) == B_OK && count > 0 )
598 int32 i = reverse ? count - 1 : 0;
599 int32 increment = reverse ? -1 : 1;
600 for ( ; p_message->FindRef( "refs", i, &ref ) == B_OK; i += increment )
603 if ( path.InitCheck() == B_OK )
606 // has the user dropped a folder?
607 BDirectory dir( &ref );
608 if ( dir.InitCheck() == B_OK)
610 // has the user dropped a dvd disk icon?
611 if ( dir.IsRootDirectory() )
613 BVolumeRoster volRoster;
615 BDirectory volumeRoot;
616 status_t status = volRoster.GetNextVolume( &vol );
617 while ( status == B_NO_ERROR )
619 if ( vol.GetRootDirectory( &volumeRoot ) == B_OK
620 && dir == volumeRoot )
625 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
628 BMessage msg( OPEN_DVD );
629 msg.AddString( "device", deviceName.String() );
638 status = volRoster.GetNextVolume( &vol );
645 dir.Rewind(); // defensive programming
647 collect_folder_contents( dir, files,
655 BString* string = new BString( path.Path() );
656 if ( !files.AddItem( string, 0 ) )
657 delete string; // at least don't leak
661 // give the list to VLC
662 // BString objects allocated here will be deleted there
664 if ( p_message->FindInt32("drop index", &index) != B_OK )
666 p_wrapper->OpenFiles( &files, replace, index );
672 case OPEN_PREFERENCES:
674 if( fPreferencesWindow->Lock() )
676 if (fPreferencesWindow->IsHidden())
677 fPreferencesWindow->Show();
679 fPreferencesWindow->Activate();
680 fPreferencesWindow->Unlock();
687 if( fMessagesWindow->Lock() )
689 if (fMessagesWindow->IsHidden())
690 fMessagesWindow->Show();
692 fMessagesWindow->Activate();
693 fMessagesWindow->Unlock();
701 BWindow::MessageReceived( p_message );
707 /*****************************************************************************
708 * InterfaceWindow::QuitRequested
709 *****************************************************************************/
710 bool InterfaceWindow::QuitRequested()
712 p_wrapper->PlaylistStop();
713 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
722 /*****************************************************************************
723 * InterfaceWindow::UpdateInterface
724 *****************************************************************************/
725 void InterfaceWindow::UpdateInterface()
727 if( p_wrapper->HasInput() )
729 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
731 p_wrapper->SetTimeAsFloat( p_mediaControl->GetSeekTo() );
733 else if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
735 p_mediaControl->SetEnabled( true );
736 bool hasTitles = p_wrapper->HasTitles();
737 bool hasChapters = p_wrapper->HasChapters();
738 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
739 p_wrapper->InputRate() );
740 p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
741 _SetMenusEnabled( true, hasChapters, hasTitles );
743 _UpdateSpeedMenu( p_wrapper->InputRate() );
745 // enable/disable skip buttons
748 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
749 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
751 if ( p_wrapper->HasInput() )
753 p_mediaControl->SetAudioEnabled( true );
754 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
756 p_mediaControl->SetAudioEnabled( false );
760 // update playlist as well
761 if ( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
763 fPlaylistWindow->UpdatePlaylist();
764 fPlaylistWindow->Unlock();
769 if ( LockWithTimeout(INTERFACE_LOCKING_TIMEOUT) == B_OK )
771 _SetMenusEnabled( false );
772 if( !( p_wrapper->PlaylistSize() > 0 ) )
773 p_mediaControl->SetEnabled( false );
776 p_mediaControl->SetProgress( 0 );
777 // enable/disable skip buttons
780 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
781 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
787 fLastUpdateTime = system_time();
790 /*****************************************************************************
791 * InterfaceWindow::IsStopped
792 *****************************************************************************/
794 InterfaceWindow::IsStopped() const
796 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
799 /*****************************************************************************
800 * InterfaceWindow::_UpdatePlaylist
801 *****************************************************************************/
803 InterfaceWindow::_UpdatePlaylist()
805 if ( fPlaylistWindow->Lock() )
807 fPlaylistWindow->UpdatePlaylist( true );
808 fPlaylistWindow->Unlock();
809 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
813 /*****************************************************************************
814 * InterfaceWindow::_SetMenusEnabled
815 *****************************************************************************/
817 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
824 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
826 if ( fNextChapterMI->IsEnabled() != hasChapters )
827 fNextChapterMI->SetEnabled( hasChapters );
828 if ( fPrevChapterMI->IsEnabled() != hasChapters )
829 fPrevChapterMI->SetEnabled( hasChapters );
830 if ( fChapterMenu->IsEnabled() != hasChapters )
831 fChapterMenu->SetEnabled( hasChapters );
832 if ( fNextTitleMI->IsEnabled() != hasTitles )
833 fNextTitleMI->SetEnabled( hasTitles );
834 if ( fPrevTitleMI->IsEnabled() != hasTitles )
835 fPrevTitleMI->SetEnabled( hasTitles );
836 if ( fTitleMenu->IsEnabled() != hasTitles )
837 fTitleMenu->SetEnabled( hasTitles );
838 if ( fAudioMenu->IsEnabled() != hasFile )
839 fAudioMenu->SetEnabled( hasFile );
840 if ( fNavigationMenu->IsEnabled() != hasFile )
841 fNavigationMenu->SetEnabled( hasFile );
842 if ( fLanguageMenu->IsEnabled() != hasFile )
843 fLanguageMenu->SetEnabled( hasFile );
844 if ( fSubtitlesMenu->IsEnabled() != hasFile )
845 fSubtitlesMenu->SetEnabled( hasFile );
846 if ( fSpeedMenu->IsEnabled() != hasFile )
847 fSpeedMenu->SetEnabled( hasFile );
848 // "goto menu" menu item
849 bool hasMenu = config_GetInt( p_intf, "beos-dvdmenus" ) ?
851 if ( fGotoMenuMI->IsEnabled() != hasMenu )
852 fGotoMenuMI->SetEnabled( hasMenu );
857 /*****************************************************************************
858 * InterfaceWindow::_UpdateSpeedMenu
859 *****************************************************************************/
861 InterfaceWindow::_UpdateSpeedMenu( int rate )
863 if ( rate == DEFAULT_RATE )
865 if ( !fNormalMI->IsMarked() )
866 fNormalMI->SetMarked( true );
868 else if ( rate < DEFAULT_RATE )
870 if ( !fFasterMI->IsMarked() )
871 fFasterMI->SetMarked( true );
875 if ( !fSlowerMI->IsMarked() )
876 fSlowerMI->SetMarked( true );
880 /*****************************************************************************
881 * InterfaceWindow::_InputStreamChanged
882 *****************************************************************************/
884 InterfaceWindow::_InputStreamChanged()
886 // TODO: move more stuff from updateInterface() here!
888 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
891 /*****************************************************************************
892 * InterfaceWindow::_ShowFilePanel
893 *****************************************************************************/
895 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
899 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
900 B_FILE_NODE | B_DIRECTORY_NODE );
901 fFilePanel->SetTarget( this );
903 fFilePanel->Window()->SetTitle( windowTitle );
904 BMessage message( command );
905 fFilePanel->SetMessage( &message );
906 if ( !fFilePanel->IsShowing() )
908 fFilePanel->Refresh();
915 set_window_pos( BWindow* window, BRect frame )
917 // sanity checks: make sure window is not too big/small
918 // and that it's not off-screen
919 float minWidth, maxWidth, minHeight, maxHeight;
920 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
922 make_sure_frame_is_within_limits( frame,
923 minWidth, minHeight, maxWidth, maxHeight );
924 if ( make_sure_frame_is_on_screen( frame ) )
926 window->MoveTo( frame.LeftTop() );
927 window->ResizeTo( frame.Width(), frame.Height() );
933 launch_window( BWindow* window, bool showing )
935 if ( window->Lock() )
939 if ( window->IsHidden() )
944 if ( !window->IsHidden() )
951 /*****************************************************************************
952 * InterfaceWindow::_RestoreSettings
953 *****************************************************************************/
955 InterfaceWindow::_RestoreSettings()
957 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
960 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
961 set_window_pos( this, frame );
962 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
963 set_window_pos( fPlaylistWindow, frame );
964 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
965 set_window_pos( fMessagesWindow, frame );
966 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
968 /* FIXME: Preferences horizontal resizing doesn't work
970 frame.right = frame.left + fPreferencesWindow->Frame().Width();
971 set_window_pos( fPreferencesWindow, frame );
975 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
976 launch_window( fPlaylistWindow, showing );
977 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
978 launch_window( fMessagesWindow, showing );
979 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
980 launch_window( fPreferencesWindow, showing );
983 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
984 fPlaylistWindow->SetDisplayMode( displayMode );
988 /*****************************************************************************
989 * InterfaceWindow::_StoreSettings
990 *****************************************************************************/
992 InterfaceWindow::_StoreSettings()
994 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
995 fSettings->AddRect( "main frame", Frame() );
996 if ( fPlaylistWindow->Lock() )
998 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
999 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1000 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1001 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1002 fPlaylistWindow->Unlock();
1004 if ( fMessagesWindow->Lock() )
1006 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1007 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1008 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1009 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1010 fMessagesWindow->Unlock();
1012 if ( fPreferencesWindow->Lock() )
1014 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1015 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1016 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1017 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1018 fPreferencesWindow->Unlock();
1020 uint32 displayMode = fPlaylistWindow->DisplayMode();
1021 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1022 fSettings->AddInt32( "playlist display mode", displayMode );
1024 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1028 /*****************************************************************************
1030 *****************************************************************************/
1031 CDMenu::CDMenu(const char *name)
1036 /*****************************************************************************
1038 *****************************************************************************/
1043 /*****************************************************************************
1044 * CDMenu::AttachedToWindow
1045 *****************************************************************************/
1046 void CDMenu::AttachedToWindow(void)
1049 while ( BMenuItem* item = RemoveItem( 0L ) )
1051 GetCD( "/dev/disk" );
1052 BMenu::AttachedToWindow();
1055 /*****************************************************************************
1057 *****************************************************************************/
1058 int CDMenu::GetCD( const char *directory )
1060 BVolumeRoster volRoster;
1063 status_t status = volRoster.GetNextVolume( &vol );
1064 while ( status == B_NO_ERROR )
1069 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1072 BMessage* msg = new BMessage( OPEN_DVD );
1073 msg->AddString( "device", deviceName.String() );
1074 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1078 status = volRoster.GetNextVolume( &vol );
1083 /*****************************************************************************
1084 * LanguageMenu::LanguageMenu
1085 *****************************************************************************/
1086 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
1087 VlcWrapper *p_wrapper )
1091 this->p_wrapper = p_wrapper;
1094 /*****************************************************************************
1095 * LanguageMenu::~LanguageMenu
1096 *****************************************************************************/
1097 LanguageMenu::~LanguageMenu()
1101 /*****************************************************************************
1102 * LanguageMenu::AttachedToWindow
1103 *****************************************************************************/
1104 void LanguageMenu::AttachedToWindow()
1107 while ( BMenuItem* item = RemoveItem( 0L ) )
1110 SetRadioMode( true );
1111 if ( BList *list = p_wrapper->GetChannels( kind ) )
1113 for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1116 if ( list->CountItems() > 1 )
1117 AddItem( new BSeparatorItem(), 1 );
1119 BMenu::AttachedToWindow();
1122 /*****************************************************************************
1123 * TitleMenu::TitleMenu
1124 *****************************************************************************/
1125 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1127 p_intf( p_interface )
1131 /*****************************************************************************
1132 * TitleMenu::~TitleMenu
1133 *****************************************************************************/
1134 TitleMenu::~TitleMenu()
1138 /*****************************************************************************
1139 * TitleMenu::AttachedToWindow
1140 *****************************************************************************/
1141 void TitleMenu::AttachedToWindow()
1143 while( BMenuItem* item = RemoveItem( 0L ) )
1146 if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1148 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1151 BMenu::AttachedToWindow();
1155 /*****************************************************************************
1156 * ChapterMenu::ChapterMenu
1157 *****************************************************************************/
1158 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1160 p_intf( p_interface )
1164 /*****************************************************************************
1165 * ChapterMenu::~ChapterMenu
1166 *****************************************************************************/
1167 ChapterMenu::~ChapterMenu()
1171 /*****************************************************************************
1172 * ChapterMenu::AttachedToWindow
1173 *****************************************************************************/
1174 void ChapterMenu::AttachedToWindow()
1176 while( BMenuItem* item = RemoveItem( 0L ) )
1179 if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1181 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1185 BMenu::AttachedToWindow();
1196 /*****************************************************************************
1198 *****************************************************************************/
1200 load_settings( BMessage* message, const char* fileName, const char* folder )
1202 status_t ret = B_BAD_VALUE;
1206 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1208 // passing folder is optional
1210 ret = path.Append( folder );
1211 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1213 BFile file( path.Path(), B_READ_ONLY );
1214 if ( ( ret = file.InitCheck() ) == B_OK )
1216 ret = message->Unflatten( &file );
1225 /*****************************************************************************
1227 *****************************************************************************/
1229 save_settings( BMessage* message, const char* fileName, const char* folder )
1231 status_t ret = B_BAD_VALUE;
1235 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1237 // passing folder is optional
1238 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1239 ret = create_directory( path.Path(), 0777 );
1240 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1242 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1243 if ( ( ret = file.InitCheck() ) == B_OK )
1245 ret = message->Flatten( &file );