1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.42 2003/06/22 00:40:18 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 - 550,
208 screen_rect.top + 300,
209 screen_rect.right - 150,
210 screen_rect.top + 500 );
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 );
287 fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
289 fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
291 fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
293 fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
295 fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
297 fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
299 fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
300 fMenuBar->AddItem( fSpeedMenu );
302 /* Add the Show menu */
303 fShowMenu = new BMenu( _("Window") );
304 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Play List")),
305 new BMessage( OPEN_PLAYLIST ), 'P') );
306 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Messages")),
307 new BMessage( OPEN_MESSAGES ), 'M' ) );
308 fShowMenu->AddItem( new BMenuItem( _AddEllipsis(_("Preferences")),
309 new BMessage( OPEN_PREFERENCES ), 'S' ) );
310 fMenuBar->AddItem( fShowMenu );
312 /* Prepare fow showing */
313 _SetMenusEnabled( false );
314 p_mediaControl->SetEnabled( false );
321 InterfaceWindow::~InterfaceWindow()
323 if( fPlaylistWindow )
324 fPlaylistWindow->ReallyQuit();
325 fPlaylistWindow = NULL;
326 if( fMessagesWindow )
327 fMessagesWindow->ReallyQuit();
328 fMessagesWindow = NULL;
329 if( fPreferencesWindow )
330 fPreferencesWindow->ReallyQuit();
331 fPreferencesWindow = NULL;
336 /*****************************************************************************
337 * InterfaceWindow::FrameResized
338 *****************************************************************************/
340 InterfaceWindow::FrameResized(float width, float height)
343 fMenuBar->MoveTo(r.LeftTop());
344 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
345 r.top += fMenuBar->Bounds().Height() + 1.0;
346 p_mediaControl->MoveTo(r.LeftTop());
347 p_mediaControl->ResizeTo(r.Width(), r.Height());
350 /*****************************************************************************
351 * InterfaceWindow::MessageReceived
352 *****************************************************************************/
353 void InterfaceWindow::MessageReceived( BMessage * p_message )
355 int playback_status; // remember playback state
356 playback_status = p_wrapper->InputStatus();
358 switch( p_message->what )
360 case B_ABOUT_REQUESTED:
362 BAlert* alert = new BAlert( "VLC " PACKAGE_VERSION,
363 "VLC " PACKAGE_VERSION " for BeOS"
364 "\n\n<www.videolan.org>", _("OK"));
372 _ShowFilePanel( B_REFS_RECEIVED, _("VideoLAN Client: Open Media Files") );
376 _ShowFilePanel( SUBFILE_RECEIVED, _("VideoLAN Client: Open Subtitle File") );
380 if (fPlaylistWindow->Lock())
382 if (fPlaylistWindow->IsHidden())
383 fPlaylistWindow->Show();
385 fPlaylistWindow->Activate();
386 fPlaylistWindow->Unlock();
391 const char *psz_device;
392 BString type( "dvd" );
393 if( p_message->FindString( "device", &psz_device ) == B_OK )
395 BString device( psz_device );
396 p_wrapper->OpenDisc( type, device, 0, 0 );
402 case SUBFILE_RECEIVED:
405 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
408 if ( path.InitCheck() == B_OK )
409 p_wrapper->LoadSubFile( path.Path() );
415 // this currently stops playback not nicely
416 if (playback_status > UNDEF_S)
418 p_wrapper->PlaylistStop();
419 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
424 /* starts playing in normal mode */
427 /* toggle between pause and play */
428 if (playback_status > UNDEF_S)
430 /* pause if currently playing */
431 if ( playback_status == PLAYING_S )
433 p_wrapper->PlaylistPause();
437 p_wrapper->PlaylistPlay();
442 /* Play a new file */
443 p_wrapper->PlaylistPlay();
448 p_wrapper->InputSetRate( DEFAULT_RATE * 8 );
452 p_wrapper->InputSetRate( DEFAULT_RATE * 4 );
456 p_wrapper->InputSetRate( DEFAULT_RATE * 2 );
460 p_wrapper->InputSetRate( DEFAULT_RATE );
464 p_wrapper->InputSetRate( DEFAULT_RATE / 2 );
468 p_wrapper->InputSetRate( DEFAULT_RATE / 4 );
472 p_wrapper->InputSetRate( DEFAULT_RATE / 8 );
476 /* handled by semaphores */
478 // volume related messages
480 /* adjust the volume */
481 if (playback_status > UNDEF_S)
483 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
484 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
490 if( p_wrapper->IsMuted() )
491 p_wrapper->VolumeRestore();
493 p_wrapper->VolumeMute();
494 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
498 if ( playback_status > UNDEF_S )
501 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
503 p_wrapper->ToggleLanguage( channel );
508 case SELECT_SUBTITLE:
509 if ( playback_status > UNDEF_S )
512 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
513 p_wrapper->ToggleSubtitle( subtitle );
517 // specific navigation messages
520 p_wrapper->PrevTitle();
525 p_wrapper->NextTitle();
529 p_wrapper->ToggleTitle( 0 );
532 if ( playback_status > UNDEF_S )
535 if( p_message->FindInt32( "index", &index ) == B_OK )
536 p_wrapper->ToggleTitle( index );
541 p_wrapper->PrevChapter();
546 p_wrapper->NextChapter();
550 if ( playback_status > UNDEF_S )
553 if( p_message->FindInt32( "index", &index ) == B_OK )
554 p_wrapper->ToggleChapter( index );
558 p_wrapper->PlaylistPrev();
561 p_wrapper->PlaylistNext();
563 // general next/prev functionality (skips to whatever makes most sense)
565 p_wrapper->NavigatePrev();
568 p_wrapper->NavigateNext();
570 // drag'n'drop and system messages
572 // convert soundplay drag'n'drop message (containing paths)
573 // to normal message (containing refs)
576 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
579 if ( get_ref_for_path( path, &ref ) == B_OK )
580 p_message->AddRef( "refs", &ref );
584 case B_REFS_RECEIVED:
587 /* file(s) opened by the File menu -> append to the playlist;
588 * file(s) opened by drag & drop -> replace playlist;
589 * file(s) opened by 'shift' + drag & drop -> append */
590 bool replace = false;
591 bool reverse = false;
592 if ( p_message->WasDropped() )
594 replace = !( modifiers() & B_SHIFT_KEY );
598 // build list of files to be played from message contents
602 // if we should parse sub-folders as well
603 bool askedAlready = false;
604 bool parseSubFolders = askedAlready;
605 // traverse refs in reverse order
608 if ( p_message->GetInfo( "refs", &dummy, &count ) == B_OK && count > 0 )
610 int32 i = reverse ? count - 1 : 0;
611 int32 increment = reverse ? -1 : 1;
612 for ( ; p_message->FindRef( "refs", i, &ref ) == B_OK; i += increment )
615 if ( path.InitCheck() == B_OK )
618 // has the user dropped a folder?
619 BDirectory dir( &ref );
620 if ( dir.InitCheck() == B_OK)
622 // has the user dropped a dvd disk icon?
623 if ( dir.IsRootDirectory() )
625 BVolumeRoster volRoster;
627 BDirectory volumeRoot;
628 status_t status = volRoster.GetNextVolume( &vol );
629 while ( status == B_NO_ERROR )
631 if ( vol.GetRootDirectory( &volumeRoot ) == B_OK
632 && dir == volumeRoot )
637 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
640 BMessage msg( OPEN_DVD );
641 msg.AddString( "device", deviceName.String() );
650 status = volRoster.GetNextVolume( &vol );
657 dir.Rewind(); // defensive programming
659 collect_folder_contents( dir, files,
667 BString* string = new BString( path.Path() );
668 if ( !files.AddItem( string, 0 ) )
669 delete string; // at least don't leak
673 // give the list to VLC
674 // BString objects allocated here will be deleted there
676 if ( p_message->FindInt32("drop index", &index) != B_OK )
678 p_wrapper->OpenFiles( &files, replace, index );
684 case OPEN_PREFERENCES:
686 if( fPreferencesWindow->Lock() )
688 if (fPreferencesWindow->IsHidden())
689 fPreferencesWindow->Show();
691 fPreferencesWindow->Activate();
692 fPreferencesWindow->Unlock();
699 if( fMessagesWindow->Lock() )
701 if (fMessagesWindow->IsHidden())
702 fMessagesWindow->Show();
704 fMessagesWindow->Activate();
705 fMessagesWindow->Unlock();
713 BWindow::MessageReceived( p_message );
719 /*****************************************************************************
720 * InterfaceWindow::QuitRequested
721 *****************************************************************************/
722 bool InterfaceWindow::QuitRequested()
724 p_wrapper->PlaylistStop();
725 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
734 /*****************************************************************************
735 * InterfaceWindow::UpdateInterface
736 *****************************************************************************/
737 void InterfaceWindow::UpdateInterface()
739 if( p_wrapper->HasInput() )
741 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
743 p_wrapper->SetTimeAsFloat( p_mediaControl->GetSeekTo() );
745 else if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
747 p_mediaControl->SetEnabled( true );
748 bool hasTitles = p_wrapper->HasTitles();
749 bool hasChapters = p_wrapper->HasChapters();
750 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
751 p_wrapper->InputRate() );
752 p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
753 _SetMenusEnabled( true, hasChapters, hasTitles );
755 _UpdateSpeedMenu( p_wrapper->InputRate() );
757 // enable/disable skip buttons
760 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
761 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
763 if ( p_wrapper->HasInput() )
765 p_mediaControl->SetAudioEnabled( true );
766 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
768 p_mediaControl->SetAudioEnabled( false );
772 // update playlist as well
773 if ( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
775 fPlaylistWindow->UpdatePlaylist();
776 fPlaylistWindow->Unlock();
781 if ( LockWithTimeout(INTERFACE_LOCKING_TIMEOUT) == B_OK )
783 _SetMenusEnabled( false );
784 if( !( p_wrapper->PlaylistSize() > 0 ) )
785 p_mediaControl->SetEnabled( false );
788 p_mediaControl->SetProgress( 0 );
789 // enable/disable skip buttons
792 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
793 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
799 fLastUpdateTime = system_time();
802 /*****************************************************************************
803 * InterfaceWindow::IsStopped
804 *****************************************************************************/
806 InterfaceWindow::IsStopped() const
808 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
811 /*****************************************************************************
812 * InterfaceWindow::_UpdatePlaylist
813 *****************************************************************************/
815 InterfaceWindow::_UpdatePlaylist()
817 if ( fPlaylistWindow->Lock() )
819 fPlaylistWindow->UpdatePlaylist( true );
820 fPlaylistWindow->Unlock();
821 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
825 /*****************************************************************************
826 * InterfaceWindow::_SetMenusEnabled
827 *****************************************************************************/
829 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
836 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
838 if ( fNextChapterMI->IsEnabled() != hasChapters )
839 fNextChapterMI->SetEnabled( hasChapters );
840 if ( fPrevChapterMI->IsEnabled() != hasChapters )
841 fPrevChapterMI->SetEnabled( hasChapters );
842 if ( fChapterMenu->IsEnabled() != hasChapters )
843 fChapterMenu->SetEnabled( hasChapters );
844 if ( fNextTitleMI->IsEnabled() != hasTitles )
845 fNextTitleMI->SetEnabled( hasTitles );
846 if ( fPrevTitleMI->IsEnabled() != hasTitles )
847 fPrevTitleMI->SetEnabled( hasTitles );
848 if ( fTitleMenu->IsEnabled() != hasTitles )
849 fTitleMenu->SetEnabled( hasTitles );
850 if ( fAudioMenu->IsEnabled() != hasFile )
851 fAudioMenu->SetEnabled( hasFile );
852 if ( fNavigationMenu->IsEnabled() != hasFile )
853 fNavigationMenu->SetEnabled( hasFile );
854 if ( fLanguageMenu->IsEnabled() != hasFile )
855 fLanguageMenu->SetEnabled( hasFile );
856 if ( fSubtitlesMenu->IsEnabled() != hasFile )
857 fSubtitlesMenu->SetEnabled( hasFile );
858 if ( fSpeedMenu->IsEnabled() != hasFile )
859 fSpeedMenu->SetEnabled( hasFile );
860 // "goto menu" menu item
861 bool hasMenu = p_wrapper->IsUsingMenus();
862 if ( fGotoMenuMI->IsEnabled() != hasMenu )
863 fGotoMenuMI->SetEnabled( hasMenu );
868 /*****************************************************************************
869 * InterfaceWindow::_UpdateSpeedMenu
870 *****************************************************************************/
872 InterfaceWindow::_UpdateSpeedMenu( int rate )
874 BMenuItem * toMark = NULL;
878 case ( DEFAULT_RATE * 8 ):
882 case ( DEFAULT_RATE * 4 ):
886 case ( DEFAULT_RATE * 2 ):
890 case ( DEFAULT_RATE ):
894 case ( DEFAULT_RATE / 2 ):
898 case ( DEFAULT_RATE / 4 ):
902 case ( DEFAULT_RATE / 8 ):
907 if ( !toMark->IsMarked() )
908 toMark->SetMarked( true );
911 /*****************************************************************************
912 * InterfaceWindow::_ShowFilePanel
913 *****************************************************************************/
915 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
919 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
920 B_FILE_NODE | B_DIRECTORY_NODE );
921 fFilePanel->SetTarget( this );
923 fFilePanel->Window()->SetTitle( windowTitle );
924 BMessage message( command );
925 fFilePanel->SetMessage( &message );
926 if ( !fFilePanel->IsShowing() )
928 fFilePanel->Refresh();
935 set_window_pos( BWindow* window, BRect frame )
937 // sanity checks: make sure window is not too big/small
938 // and that it's not off-screen
939 float minWidth, maxWidth, minHeight, maxHeight;
940 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
942 make_sure_frame_is_within_limits( frame,
943 minWidth, minHeight, maxWidth, maxHeight );
944 if ( make_sure_frame_is_on_screen( frame ) )
946 window->MoveTo( frame.LeftTop() );
947 window->ResizeTo( frame.Width(), frame.Height() );
953 launch_window( BWindow* window, bool showing )
955 if ( window->Lock() )
959 if ( window->IsHidden() )
964 if ( !window->IsHidden() )
971 /*****************************************************************************
972 * InterfaceWindow::_RestoreSettings
973 *****************************************************************************/
975 InterfaceWindow::_RestoreSettings()
977 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
980 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
981 set_window_pos( this, frame );
982 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
983 set_window_pos( fPlaylistWindow, frame );
984 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
985 set_window_pos( fMessagesWindow, frame );
986 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
988 /* FIXME: Preferences resizing doesn't work correctly yet */
989 frame.right = frame.left + fPreferencesWindow->Frame().Width();
990 frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
991 set_window_pos( fPreferencesWindow, frame );
995 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
996 launch_window( fPlaylistWindow, showing );
997 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
998 launch_window( fMessagesWindow, showing );
999 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1000 launch_window( fPreferencesWindow, showing );
1003 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1004 fPlaylistWindow->SetDisplayMode( displayMode );
1008 /*****************************************************************************
1009 * InterfaceWindow::_StoreSettings
1010 *****************************************************************************/
1012 InterfaceWindow::_StoreSettings()
1014 /* Save the volume */
1015 config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
1016 config_SaveConfigFile( p_intf, "main" );
1018 /* Save the windows positions */
1019 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1020 fSettings->AddRect( "main frame", Frame() );
1021 if ( fPlaylistWindow->Lock() )
1023 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1024 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1025 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1026 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1027 fPlaylistWindow->Unlock();
1029 if ( fMessagesWindow->Lock() )
1031 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1032 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1033 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1034 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1035 fMessagesWindow->Unlock();
1037 if ( fPreferencesWindow->Lock() )
1039 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1040 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1041 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1042 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1043 fPreferencesWindow->Unlock();
1045 uint32 displayMode = fPlaylistWindow->DisplayMode();
1046 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1047 fSettings->AddInt32( "playlist display mode", displayMode );
1049 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1053 /*****************************************************************************
1055 *****************************************************************************/
1056 CDMenu::CDMenu(const char *name)
1061 /*****************************************************************************
1063 *****************************************************************************/
1068 /*****************************************************************************
1069 * CDMenu::AttachedToWindow
1070 *****************************************************************************/
1071 void CDMenu::AttachedToWindow(void)
1074 while ( BMenuItem* item = RemoveItem( 0L ) )
1076 GetCD( "/dev/disk" );
1077 BMenu::AttachedToWindow();
1080 /*****************************************************************************
1082 *****************************************************************************/
1083 int CDMenu::GetCD( const char *directory )
1085 BVolumeRoster volRoster;
1088 status_t status = volRoster.GetNextVolume( &vol );
1089 while ( status == B_NO_ERROR )
1094 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1097 BMessage* msg = new BMessage( OPEN_DVD );
1098 msg->AddString( "device", deviceName.String() );
1099 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1103 status = volRoster.GetNextVolume( &vol );
1108 /*****************************************************************************
1109 * LanguageMenu::LanguageMenu
1110 *****************************************************************************/
1111 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
1112 VlcWrapper *p_wrapper )
1116 this->p_wrapper = p_wrapper;
1119 /*****************************************************************************
1120 * LanguageMenu::~LanguageMenu
1121 *****************************************************************************/
1122 LanguageMenu::~LanguageMenu()
1126 /*****************************************************************************
1127 * LanguageMenu::AttachedToWindow
1128 *****************************************************************************/
1129 void LanguageMenu::AttachedToWindow()
1132 while ( BMenuItem* item = RemoveItem( 0L ) )
1135 SetRadioMode( true );
1136 if ( BList *list = p_wrapper->GetChannels( kind ) )
1138 for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1141 if ( list->CountItems() > 1 )
1142 AddItem( new BSeparatorItem(), 1 );
1144 BMenu::AttachedToWindow();
1147 /*****************************************************************************
1148 * TitleMenu::TitleMenu
1149 *****************************************************************************/
1150 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1152 p_intf( p_interface )
1156 /*****************************************************************************
1157 * TitleMenu::~TitleMenu
1158 *****************************************************************************/
1159 TitleMenu::~TitleMenu()
1163 /*****************************************************************************
1164 * TitleMenu::AttachedToWindow
1165 *****************************************************************************/
1166 void TitleMenu::AttachedToWindow()
1168 while( BMenuItem* item = RemoveItem( 0L ) )
1171 if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1173 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1176 BMenu::AttachedToWindow();
1180 /*****************************************************************************
1181 * ChapterMenu::ChapterMenu
1182 *****************************************************************************/
1183 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1185 p_intf( p_interface )
1189 /*****************************************************************************
1190 * ChapterMenu::~ChapterMenu
1191 *****************************************************************************/
1192 ChapterMenu::~ChapterMenu()
1196 /*****************************************************************************
1197 * ChapterMenu::AttachedToWindow
1198 *****************************************************************************/
1199 void ChapterMenu::AttachedToWindow()
1201 while( BMenuItem* item = RemoveItem( 0L ) )
1204 if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1206 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1210 BMenu::AttachedToWindow();
1221 /*****************************************************************************
1223 *****************************************************************************/
1225 load_settings( BMessage* message, const char* fileName, const char* folder )
1227 status_t ret = B_BAD_VALUE;
1231 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1233 // passing folder is optional
1235 ret = path.Append( folder );
1236 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1238 BFile file( path.Path(), B_READ_ONLY );
1239 if ( ( ret = file.InitCheck() ) == B_OK )
1241 ret = message->Unflatten( &file );
1250 /*****************************************************************************
1252 *****************************************************************************/
1254 save_settings( BMessage* message, const char* fileName, const char* folder )
1256 status_t ret = B_BAD_VALUE;
1260 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1262 // passing folder is optional
1263 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1264 ret = create_directory( path.Path(), 0777 );
1265 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1267 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1268 if ( ( ret = file.InitCheck() ) == B_OK )
1270 ret = message->Flatten( &file );