1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.35 2003/05/03 13:37:21 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 // TODO: ?!? what about user settings?
193 p_intf->p_sys->b_dvdmenus = false;
195 fPlaylistIsEmpty = !( p_wrapper->PlaylistSize() > 0 );
198 BRect screen_rect = screen.Frame();
200 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
201 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
202 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
203 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
204 fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
205 window_rect.Set( screen_rect.right - 500,
206 screen_rect.top + 50,
207 screen_rect.right - 150,
208 screen_rect.top + 250 );
209 fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
210 window_rect.Set( screen_rect.right - 500,
211 screen_rect.top + 300,
212 screen_rect.right - 150,
213 screen_rect.top + 600 );
214 fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
216 // the media control view
217 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
219 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
222 p_mediaControl->GetPreferredSize( &width, &height );
224 // set up the main menu
225 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
226 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
228 // make menu bar resize to correct height
229 float menuWidth, menuHeight;
230 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
231 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
232 // take care of proper size for ourself
233 height += fMenuBar->Bounds().Height();
234 ResizeTo( width, height );
236 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
237 AddChild( fMenuBar );
238 AddChild( p_mediaControl );
241 BMenu* fileMenu = new BMenu( _("File") );
242 fMenuBar->AddItem( fileMenu );
243 fileMenu->AddItem( new BMenuItem( _AddEllipsis(_("Open File")),
244 new BMessage( OPEN_FILE ), 'O') );
246 fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
248 fileMenu->AddItem( new BMenuItem( _AddEllipsis(_("Open Subtitles")),
249 new BMessage( LOAD_SUBFILE ) ) );
251 fileMenu->AddSeparatorItem();
252 BMenuItem* item = new BMenuItem( _AddEllipsis(_("About")),
253 new BMessage( B_ABOUT_REQUESTED ), 'A');
254 item->SetTarget( be_app );
255 fileMenu->AddItem( item );
256 fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
258 fLanguageMenu = new LanguageMenu( _("Language"), AUDIO_ES, p_wrapper);
259 fSubtitlesMenu = new LanguageMenu( _("Subtitles"), SPU_ES, p_wrapper);
261 /* Add the Audio menu */
262 fAudioMenu = new BMenu( _("Audio") );
263 fMenuBar->AddItem ( fAudioMenu );
264 fAudioMenu->AddItem( fLanguageMenu );
265 fAudioMenu->AddItem( fSubtitlesMenu );
267 fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
268 fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
269 fPrevChapterMI = new BMenuItem( _("Prev Chapter"), new BMessage( PREV_CHAPTER ) );
270 fNextChapterMI = new BMenuItem( _("Next Chapter"), new BMessage( NEXT_CHAPTER ) );
271 fGotoMenuMI = new BMenuItem( _("Goto Menu"), new BMessage( NAVIGATE_MENU ) );
273 /* Add the Navigation menu */
274 fNavigationMenu = new BMenu( _("Navigation") );
275 fMenuBar->AddItem( fNavigationMenu );
276 fNavigationMenu->AddItem( fGotoMenuMI );
277 fNavigationMenu->AddSeparatorItem();
278 fNavigationMenu->AddItem( fPrevTitleMI );
279 fNavigationMenu->AddItem( fNextTitleMI );
280 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
281 fNavigationMenu->AddSeparatorItem();
282 fNavigationMenu->AddItem( fPrevChapterMI );
283 fNavigationMenu->AddItem( fNextChapterMI );
284 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
286 /* Add the Speed menu */
287 fSpeedMenu = new BMenu( _("Speed") );
288 fSpeedMenu->SetRadioMode( true );
289 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( _("Slower"), new BMessage( SLOWER_PLAY ) ) );
290 fNormalMI = new BMenuItem( _("Normal"), new BMessage( NORMAL_PLAY ) );
291 fNormalMI->SetMarked(true); // default to normal speed
292 fSpeedMenu->AddItem( fNormalMI );
293 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( _("Faster"), new BMessage( FASTER_PLAY) ) );
294 fSpeedMenu->SetTargetForItems( this );
295 fMenuBar->AddItem( fSpeedMenu );
297 /* Add the Show menu */
298 fShowMenu = new BMenu( _("Window") );
299 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Play List")),
300 new BMessage( OPEN_PLAYLIST ), 'P') );
301 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Messages")),
302 new BMessage( OPEN_MESSAGES ), 'M' ) );
303 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Preferences")),
304 new BMessage( OPEN_PREFERENCES ), 'S' ) );
305 fMenuBar->AddItem( fShowMenu );
307 /* Prepare fow showing */
308 _SetMenusEnabled( false );
309 p_mediaControl->SetEnabled( false );
316 InterfaceWindow::~InterfaceWindow()
318 if( fPlaylistWindow )
319 fPlaylistWindow->ReallyQuit();
320 fPlaylistWindow = NULL;
321 if( fMessagesWindow )
322 fMessagesWindow->ReallyQuit();
323 fMessagesWindow = NULL;
324 if( fPreferencesWindow )
325 fPreferencesWindow->ReallyQuit();
326 fPreferencesWindow = NULL;
331 /*****************************************************************************
332 * InterfaceWindow::FrameResized
333 *****************************************************************************/
335 InterfaceWindow::FrameResized(float width, float height)
338 fMenuBar->MoveTo(r.LeftTop());
339 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
340 r.top += fMenuBar->Bounds().Height() + 1.0;
341 p_mediaControl->MoveTo(r.LeftTop());
342 p_mediaControl->ResizeTo(r.Width(), r.Height());
345 /*****************************************************************************
346 * InterfaceWindow::MessageReceived
347 *****************************************************************************/
348 void InterfaceWindow::MessageReceived( BMessage * p_message )
350 int playback_status; // remember playback state
351 playback_status = p_wrapper->InputStatus();
353 switch( p_message->what )
355 case B_ABOUT_REQUESTED:
357 BAlert* alert = new BAlert( "VLC " PACKAGE_VERSION,
358 "VLC " PACKAGE_VERSION " for BeOS"
359 "\n\n<www.videolan.org>", _("OK"));
367 _ShowFilePanel( B_REFS_RECEIVED, _("VideoLAN Client: Open Media Files") );
371 _ShowFilePanel( SUBFILE_RECEIVED, _("VideoLAN Client: Open Subtitle File") );
375 if (fPlaylistWindow->Lock())
377 if (fPlaylistWindow->IsHidden())
378 fPlaylistWindow->Show();
380 fPlaylistWindow->Activate();
381 fPlaylistWindow->Unlock();
386 const char *psz_device;
387 BString type( "dvd" );
388 if( p_message->FindString( "device", &psz_device ) == B_OK )
390 BString device( psz_device );
391 p_wrapper->OpenDisc( type, device, 0, 0 );
397 case SUBFILE_RECEIVED:
400 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
403 if ( path.InitCheck() == B_OK )
404 p_wrapper->LoadSubFile( path.Path() );
410 // this currently stops playback not nicely
411 if (playback_status > UNDEF_S)
413 p_wrapper->PlaylistStop();
414 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
419 /* starts playing in normal mode */
422 /* toggle between pause and play */
423 if (playback_status > UNDEF_S)
425 /* pause if currently playing */
426 if ( playback_status == PLAYING_S )
428 p_wrapper->PlaylistPause();
432 p_wrapper->PlaylistPlay();
437 /* Play a new file */
438 p_wrapper->PlaylistPlay();
443 /* cycle the fast playback modes */
444 if (playback_status > UNDEF_S)
446 p_wrapper->InputFaster();
451 /* cycle the slow playback modes */
452 if (playback_status > UNDEF_S)
454 p_wrapper->InputSlower();
459 /* restore speed to normal if already playing */
460 if (playback_status > UNDEF_S)
462 p_wrapper->PlaylistPlay();
467 /* handled by semaphores */
469 // volume related messages
471 /* adjust the volume */
472 if (playback_status > UNDEF_S)
474 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
475 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
481 if( p_wrapper->IsMuted() )
482 p_wrapper->VolumeRestore();
484 p_wrapper->VolumeMute();
485 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
489 if ( playback_status > UNDEF_S )
492 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
494 p_wrapper->ToggleLanguage( channel );
499 case SELECT_SUBTITLE:
500 if ( playback_status > UNDEF_S )
503 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
504 p_wrapper->ToggleSubtitle( subtitle );
508 // specific navigation messages
511 p_wrapper->PrevTitle();
516 p_wrapper->NextTitle();
520 p_wrapper->ToggleTitle( 0 );
523 if ( playback_status > UNDEF_S )
526 if( p_message->FindInt32( "index", &index ) == B_OK )
527 p_wrapper->ToggleTitle( index );
532 p_wrapper->PrevChapter();
537 p_wrapper->NextChapter();
541 if ( playback_status > UNDEF_S )
544 if( p_message->FindInt32( "index", &index ) == B_OK )
545 p_wrapper->ToggleChapter( index );
549 p_wrapper->PlaylistPrev();
552 p_wrapper->PlaylistNext();
554 // general next/prev functionality (skips to whatever makes most sense)
556 p_wrapper->NavigatePrev();
559 p_wrapper->NavigateNext();
561 // drag'n'drop and system messages
563 // convert soundplay drag'n'drop message (containing paths)
564 // to normal message (containing refs)
567 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
570 if ( get_ref_for_path( path, &ref ) == B_OK )
571 p_message->AddRef( "refs", &ref );
575 case B_REFS_RECEIVED:
578 /* file(s) opened by the File menu -> append to the playlist;
579 * file(s) opened by drag & drop -> replace playlist;
580 * file(s) opened by 'shift' + drag & drop -> append */
581 bool replace = false;
582 bool reverse = false;
583 if ( p_message->WasDropped() )
585 replace = !( modifiers() & B_SHIFT_KEY );
589 // build list of files to be played from message contents
593 // if we should parse sub-folders as well
594 bool askedAlready = false;
595 bool parseSubFolders = askedAlready;
596 // traverse refs in reverse order
599 if ( p_message->GetInfo( "refs", &dummy, &count ) == B_OK && count > 0 )
601 int32 i = reverse ? count - 1 : 0;
602 int32 increment = reverse ? -1 : 1;
603 for ( ; p_message->FindRef( "refs", i, &ref ) == B_OK; i += increment )
606 if ( path.InitCheck() == B_OK )
609 // has the user dropped a folder?
610 BDirectory dir( &ref );
611 if ( dir.InitCheck() == B_OK)
613 // has the user dropped a dvd disk icon?
614 if ( dir.IsRootDirectory() )
616 BVolumeRoster volRoster;
618 BDirectory volumeRoot;
619 status_t status = volRoster.GetNextVolume( &vol );
620 while ( status == B_NO_ERROR )
622 if ( vol.GetRootDirectory( &volumeRoot ) == B_OK
623 && dir == volumeRoot )
628 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
631 BMessage msg( OPEN_DVD );
632 msg.AddString( "device", deviceName.String() );
641 status = volRoster.GetNextVolume( &vol );
648 dir.Rewind(); // defensive programming
650 collect_folder_contents( dir, files,
658 BString* string = new BString( path.Path() );
659 if ( !files.AddItem( string, 0 ) )
660 delete string; // at least don't leak
664 // give the list to VLC
665 // BString objects allocated here will be deleted there
667 if ( p_message->FindInt32("drop index", &index) != B_OK )
669 p_wrapper->OpenFiles( &files, replace, index );
675 case OPEN_PREFERENCES:
677 if( fPreferencesWindow->Lock() )
679 if (fPreferencesWindow->IsHidden())
680 fPreferencesWindow->Show();
682 fPreferencesWindow->Activate();
683 fPreferencesWindow->Unlock();
690 if( fMessagesWindow->Lock() )
692 if (fMessagesWindow->IsHidden())
693 fMessagesWindow->Show();
695 fMessagesWindow->Activate();
696 fMessagesWindow->Unlock();
704 BWindow::MessageReceived( p_message );
710 /*****************************************************************************
711 * InterfaceWindow::QuitRequested
712 *****************************************************************************/
713 bool InterfaceWindow::QuitRequested()
715 p_wrapper->PlaylistStop();
716 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
725 /*****************************************************************************
726 * InterfaceWindow::UpdateInterface
727 *****************************************************************************/
728 void InterfaceWindow::UpdateInterface()
730 if( p_wrapper->HasInput() )
732 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
734 p_wrapper->SetTimeAsFloat( p_mediaControl->GetSeekTo() );
736 else if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
738 p_mediaControl->SetEnabled( true );
739 bool hasTitles = p_wrapper->HasTitles();
740 bool hasChapters = p_wrapper->HasChapters();
741 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
742 p_wrapper->InputRate() );
743 p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
744 _SetMenusEnabled( true, hasChapters, hasTitles );
746 _UpdateSpeedMenu( p_wrapper->InputRate() );
748 // enable/disable skip buttons
751 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
752 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
754 if ( p_wrapper->HasInput() )
756 p_mediaControl->SetAudioEnabled( true );
757 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
759 p_mediaControl->SetAudioEnabled( false );
763 // update playlist as well
764 if ( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
766 fPlaylistWindow->UpdatePlaylist();
767 fPlaylistWindow->Unlock();
772 if ( LockWithTimeout(INTERFACE_LOCKING_TIMEOUT) == B_OK )
774 _SetMenusEnabled( false );
775 if( !( p_wrapper->PlaylistSize() > 0 ) )
776 p_mediaControl->SetEnabled( false );
779 p_mediaControl->SetProgress( 0 );
780 // enable/disable skip buttons
783 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
784 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
790 fLastUpdateTime = system_time();
793 /*****************************************************************************
794 * InterfaceWindow::IsStopped
795 *****************************************************************************/
797 InterfaceWindow::IsStopped() const
799 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
802 /*****************************************************************************
803 * InterfaceWindow::_UpdatePlaylist
804 *****************************************************************************/
806 InterfaceWindow::_UpdatePlaylist()
808 if ( fPlaylistWindow->Lock() )
810 fPlaylistWindow->UpdatePlaylist( true );
811 fPlaylistWindow->Unlock();
812 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
816 /*****************************************************************************
817 * InterfaceWindow::_SetMenusEnabled
818 *****************************************************************************/
820 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
827 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
829 if ( fNextChapterMI->IsEnabled() != hasChapters )
830 fNextChapterMI->SetEnabled( hasChapters );
831 if ( fPrevChapterMI->IsEnabled() != hasChapters )
832 fPrevChapterMI->SetEnabled( hasChapters );
833 if ( fChapterMenu->IsEnabled() != hasChapters )
834 fChapterMenu->SetEnabled( hasChapters );
835 if ( fNextTitleMI->IsEnabled() != hasTitles )
836 fNextTitleMI->SetEnabled( hasTitles );
837 if ( fPrevTitleMI->IsEnabled() != hasTitles )
838 fPrevTitleMI->SetEnabled( hasTitles );
839 if ( fTitleMenu->IsEnabled() != hasTitles )
840 fTitleMenu->SetEnabled( hasTitles );
841 if ( fAudioMenu->IsEnabled() != hasFile )
842 fAudioMenu->SetEnabled( hasFile );
843 if ( fNavigationMenu->IsEnabled() != hasFile )
844 fNavigationMenu->SetEnabled( hasFile );
845 if ( fLanguageMenu->IsEnabled() != hasFile )
846 fLanguageMenu->SetEnabled( hasFile );
847 if ( fSubtitlesMenu->IsEnabled() != hasFile )
848 fSubtitlesMenu->SetEnabled( hasFile );
849 if ( fSpeedMenu->IsEnabled() != hasFile )
850 fSpeedMenu->SetEnabled( hasFile );
851 // "goto menu" menu item
852 bool hasMenu = p_intf->p_sys->b_dvdmenus ? hasTitles : false;
853 if ( fGotoMenuMI->IsEnabled() != hasMenu )
854 fGotoMenuMI->SetEnabled( hasMenu );
859 /*****************************************************************************
860 * InterfaceWindow::_UpdateSpeedMenu
861 *****************************************************************************/
863 InterfaceWindow::_UpdateSpeedMenu( int rate )
865 if ( rate == DEFAULT_RATE )
867 if ( !fNormalMI->IsMarked() )
868 fNormalMI->SetMarked( true );
870 else if ( rate < DEFAULT_RATE )
872 if ( !fFasterMI->IsMarked() )
873 fFasterMI->SetMarked( true );
877 if ( !fSlowerMI->IsMarked() )
878 fSlowerMI->SetMarked( true );
882 /*****************************************************************************
883 * InterfaceWindow::_InputStreamChanged
884 *****************************************************************************/
886 InterfaceWindow::_InputStreamChanged()
888 // TODO: move more stuff from updateInterface() here!
890 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
893 /*****************************************************************************
894 * InterfaceWindow::_ShowFilePanel
895 *****************************************************************************/
897 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
901 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
902 B_FILE_NODE | B_DIRECTORY_NODE );
903 fFilePanel->SetTarget( this );
905 fFilePanel->Window()->SetTitle( windowTitle );
906 BMessage message( command );
907 fFilePanel->SetMessage( &message );
908 if ( !fFilePanel->IsShowing() )
910 fFilePanel->Refresh();
917 set_window_pos( BWindow* window, BRect frame )
919 // sanity checks: make sure window is not too big/small
920 // and that it's not off-screen
921 float minWidth, maxWidth, minHeight, maxHeight;
922 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
924 make_sure_frame_is_within_limits( frame,
925 minWidth, minHeight, maxWidth, maxHeight );
926 if ( make_sure_frame_is_on_screen( frame ) )
928 window->MoveTo( frame.LeftTop() );
929 window->ResizeTo( frame.Width(), frame.Height() );
935 launch_window( BWindow* window, bool showing )
937 if ( window->Lock() )
941 if ( window->IsHidden() )
946 if ( !window->IsHidden() )
953 /*****************************************************************************
954 * InterfaceWindow::_RestoreSettings
955 *****************************************************************************/
957 InterfaceWindow::_RestoreSettings()
959 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
962 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
963 set_window_pos( this, frame );
964 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
965 set_window_pos( fPlaylistWindow, frame );
966 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
967 set_window_pos( fMessagesWindow, frame );
968 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
969 set_window_pos( fPreferencesWindow, frame );
972 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
973 launch_window( fPlaylistWindow, showing );
974 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
975 launch_window( fMessagesWindow, showing );
976 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
977 launch_window( fPreferencesWindow, showing );
980 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
981 fPlaylistWindow->SetDisplayMode( displayMode );
985 /*****************************************************************************
986 * InterfaceWindow::_StoreSettings
987 *****************************************************************************/
989 InterfaceWindow::_StoreSettings()
991 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
992 fSettings->AddRect( "main frame", Frame() );
993 if ( fPlaylistWindow->Lock() )
995 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
996 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
997 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
998 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
999 fPlaylistWindow->Unlock();
1001 if ( fMessagesWindow->Lock() )
1003 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1004 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1005 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1006 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1007 fMessagesWindow->Unlock();
1009 if ( fPreferencesWindow->Lock() )
1011 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1012 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1013 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1014 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1015 fPreferencesWindow->Unlock();
1017 uint32 displayMode = fPlaylistWindow->DisplayMode();
1018 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1019 fSettings->AddInt32( "playlist display mode", displayMode );
1021 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1025 /*****************************************************************************
1027 *****************************************************************************/
1028 CDMenu::CDMenu(const char *name)
1033 /*****************************************************************************
1035 *****************************************************************************/
1040 /*****************************************************************************
1041 * CDMenu::AttachedToWindow
1042 *****************************************************************************/
1043 void CDMenu::AttachedToWindow(void)
1046 while ( BMenuItem* item = RemoveItem( 0L ) )
1048 GetCD( "/dev/disk" );
1049 BMenu::AttachedToWindow();
1052 /*****************************************************************************
1054 *****************************************************************************/
1055 int CDMenu::GetCD( const char *directory )
1057 BVolumeRoster volRoster;
1060 status_t status = volRoster.GetNextVolume( &vol );
1061 while ( status == B_NO_ERROR )
1066 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1069 BMessage* msg = new BMessage( OPEN_DVD );
1070 msg->AddString( "device", deviceName.String() );
1071 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1075 status = volRoster.GetNextVolume( &vol );
1080 /*****************************************************************************
1081 * LanguageMenu::LanguageMenu
1082 *****************************************************************************/
1083 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
1084 VlcWrapper *p_wrapper )
1088 this->p_wrapper = p_wrapper;
1091 /*****************************************************************************
1092 * LanguageMenu::~LanguageMenu
1093 *****************************************************************************/
1094 LanguageMenu::~LanguageMenu()
1098 /*****************************************************************************
1099 * LanguageMenu::AttachedToWindow
1100 *****************************************************************************/
1101 void LanguageMenu::AttachedToWindow()
1104 while ( BMenuItem* item = RemoveItem( 0L ) )
1107 SetRadioMode( true );
1108 if ( BList *list = p_wrapper->GetChannels( kind ) )
1110 for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1113 if ( list->CountItems() > 1 )
1114 AddItem( new BSeparatorItem(), 1 );
1116 BMenu::AttachedToWindow();
1119 /*****************************************************************************
1120 * TitleMenu::TitleMenu
1121 *****************************************************************************/
1122 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1124 p_intf( p_interface )
1128 /*****************************************************************************
1129 * TitleMenu::~TitleMenu
1130 *****************************************************************************/
1131 TitleMenu::~TitleMenu()
1135 /*****************************************************************************
1136 * TitleMenu::AttachedToWindow
1137 *****************************************************************************/
1138 void TitleMenu::AttachedToWindow()
1140 while( BMenuItem* item = RemoveItem( 0L ) )
1143 if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1145 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1148 BMenu::AttachedToWindow();
1152 /*****************************************************************************
1153 * ChapterMenu::ChapterMenu
1154 *****************************************************************************/
1155 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1157 p_intf( p_interface )
1161 /*****************************************************************************
1162 * ChapterMenu::~ChapterMenu
1163 *****************************************************************************/
1164 ChapterMenu::~ChapterMenu()
1168 /*****************************************************************************
1169 * ChapterMenu::AttachedToWindow
1170 *****************************************************************************/
1171 void ChapterMenu::AttachedToWindow()
1173 while( BMenuItem* item = RemoveItem( 0L ) )
1176 if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1178 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1182 BMenu::AttachedToWindow();
1193 /*****************************************************************************
1195 *****************************************************************************/
1197 load_settings( BMessage* message, const char* fileName, const char* folder )
1199 status_t ret = B_BAD_VALUE;
1203 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1205 // passing folder is optional
1207 ret = path.Append( folder );
1208 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1210 BFile file( path.Path(), B_READ_ONLY );
1211 if ( ( ret = file.InitCheck() ) == B_OK )
1213 ret = message->Unflatten( &file );
1222 /*****************************************************************************
1224 *****************************************************************************/
1226 save_settings( BMessage* message, const char* fileName, const char* folder )
1228 status_t ret = B_BAD_VALUE;
1232 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1234 // passing folder is optional
1235 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1236 ret = create_directory( path.Path(), 0777 );
1237 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1239 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1240 if ( ( ret = file.InitCheck() ) == B_OK )
1242 ret = message->Flatten( &file );