1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
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 <superstippi@gmx.de>
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>
44 #include <vlc/input.h>
46 /* BeOS interface headers */
47 #include "VlcWrapper.h"
49 #include "MediaControlView.h"
50 #include "PlayListWindow.h"
51 #include "PreferencesWindow.h"
52 #include "MessagesWindow.h"
53 #include "InterfaceWindow.h"
55 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
56 #define INTERFACE_LOCKING_TIMEOUT 5000
58 // make_sure_frame_is_on_screen
60 make_sure_frame_is_on_screen( BRect& frame )
62 BScreen screen( B_MAIN_SCREEN_ID );
63 if (frame.IsValid() && screen.IsValid()) {
64 if (!screen.Frame().Contains(frame)) {
65 // make sure frame fits in the screen
66 if (frame.Width() > screen.Frame().Width())
67 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
68 if (frame.Height() > screen.Frame().Height())
69 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
70 // frame is now at the most the size of the screen
71 if (frame.right > screen.Frame().right)
72 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
73 if (frame.bottom > screen.Frame().bottom)
74 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
75 if (frame.left < screen.Frame().left)
76 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
77 if (frame.top < screen.Frame().top)
78 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
85 // make_sure_frame_is_within_limits
87 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
88 float maxWidth, float maxHeight )
90 if ( frame.Width() < minWidth )
91 frame.right = frame.left + minWidth;
92 if ( frame.Height() < minHeight )
93 frame.bottom = frame.top + minHeight;
94 if ( frame.Width() > maxWidth )
95 frame.right = frame.left + maxWidth;
96 if ( frame.Height() > maxHeight )
97 frame.bottom = frame.top + maxHeight;
102 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
104 bool success = false;
108 char name[B_FILE_NAME_LENGTH];
109 if ( volume.GetName( name ) >= B_OK ) // disk is currently mounted
112 dev_t dev = volume.Device();
114 if ( fs_stat_dev( dev, &info ) == B_OK )
117 deviceName = info.device_name;
118 if ( volume.IsReadOnly() )
120 int i_dev = open( info.device_name, O_RDONLY );
124 if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
125 isCDROM = ( g.device_type == B_CD );
134 // collect_folder_contents
136 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
138 while ( dir.GetNextEntry( &entry, true ) == B_OK )
140 if ( !entry.IsDirectory() )
143 // since the directory will give us the entries in reverse order,
144 // we put them each at the same index, effectively reversing the
145 // items while adding them
146 if ( entry.GetPath( &path ) == B_OK )
148 BString* string = new BString( path.Path() );
149 if ( !list.AddItem( string, 0 ) )
150 delete string; // at least don't leak
157 // ask user if we should parse sub-folders as well
158 BAlert* alert = new BAlert( "sub-folders?",
159 _("Open files from all sub-folders as well?"),
160 _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL,
162 int32 buttonIndex = alert->Go();
163 deep = buttonIndex == 1;
165 // never delete BAlerts!!
169 BDirectory subDir( &entry );
170 if ( subDir.InitCheck() == B_OK )
171 collect_folder_contents( subDir, list,
172 deep, asked, entry );
179 /*****************************************************************************
181 *****************************************************************************/
183 InterfaceWindow::InterfaceWindow( BRect frame, const char* name,
184 intf_thread_t* p_interface )
185 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
186 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
187 p_intf( p_interface ),
189 fLastUpdateTime( system_time() ),
190 fSettings( new BMessage( 'sett' ) ),
191 p_wrapper( p_intf->p_sys->p_wrapper )
193 fPlaylistIsEmpty = !( p_wrapper->PlaylistSize() > 0 );
196 BRect screen_rect = screen.Frame();
198 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
199 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
200 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
201 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
202 fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
203 window_rect.Set( screen_rect.right - 500,
204 screen_rect.top + 50,
205 screen_rect.right - 150,
206 screen_rect.top + 250 );
207 fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
208 window_rect.Set( screen_rect.right - 550,
209 screen_rect.top + 300,
210 screen_rect.right - 150,
211 screen_rect.top + 500 );
212 fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
214 // the media control view
215 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
217 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
220 p_mediaControl->GetPreferredSize( &width, &height );
222 // set up the main menu
223 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
224 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
226 // make menu bar resize to correct height
227 float menuWidth, menuHeight;
228 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
229 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
230 // take care of proper size for ourself
231 height += fMenuBar->Bounds().Height();
232 ResizeTo( width, height );
234 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
235 AddChild( fMenuBar );
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( _("Previous 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(_("Playlist")),
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 // add the media control view after the menubar is complete
313 // because it will set the window size limits in AttachedToWindow()
314 // and the menubar needs to report the correct PreferredSize()
315 AddChild( p_mediaControl );
317 /* Prepare fow showing */
318 _SetMenusEnabled( false );
319 p_mediaControl->SetEnabled( false );
326 InterfaceWindow::~InterfaceWindow()
328 if( fPlaylistWindow )
329 fPlaylistWindow->ReallyQuit();
330 fPlaylistWindow = NULL;
331 if( fMessagesWindow )
332 fMessagesWindow->ReallyQuit();
333 fMessagesWindow = NULL;
334 if( fPreferencesWindow )
335 fPreferencesWindow->ReallyQuit();
336 fPreferencesWindow = NULL;
341 /*****************************************************************************
342 * InterfaceWindow::FrameResized
343 *****************************************************************************/
345 InterfaceWindow::FrameResized(float width, float height)
348 fMenuBar->MoveTo(r.LeftTop());
349 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
350 r.top += fMenuBar->Bounds().Height() + 1.0;
351 p_mediaControl->MoveTo(r.LeftTop());
352 p_mediaControl->ResizeTo(r.Width(), r.Height());
355 /*****************************************************************************
356 * InterfaceWindow::MessageReceived
357 *****************************************************************************/
358 void InterfaceWindow::MessageReceived( BMessage * p_message )
360 int playback_status; // remember playback state
361 playback_status = p_wrapper->InputStatus();
363 switch( p_message->what )
365 case B_ABOUT_REQUESTED:
367 BAlert* alert = new BAlert( "VLC " PACKAGE_VERSION,
368 "VLC " PACKAGE_VERSION " for BeOS"
369 "\n\n<www.videolan.org>", _("OK"));
377 _ShowFilePanel( B_REFS_RECEIVED, _("VLC media player: Open Media Files") );
381 _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
385 if (fPlaylistWindow->Lock())
387 if (fPlaylistWindow->IsHidden())
388 fPlaylistWindow->Show();
390 fPlaylistWindow->Activate();
391 fPlaylistWindow->Unlock();
396 const char *psz_device;
397 BString type( "dvd" );
398 if( p_message->FindString( "device", &psz_device ) == B_OK )
400 BString device( psz_device );
401 p_wrapper->OpenDisc( type, device, 0, 0 );
407 case SUBFILE_RECEIVED:
410 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
413 if ( path.InitCheck() == B_OK )
414 p_wrapper->LoadSubFile( path.Path() );
420 // this currently stops playback not nicely
421 if (playback_status != -1)
423 p_wrapper->PlaylistStop();
424 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
429 /* starts playing in normal mode */
432 /* toggle between pause and play */
433 if (playback_status > -1)
435 /* pause if currently playing */
436 if ( playback_status == PLAYING_S )
438 p_wrapper->PlaylistPause();
442 p_wrapper->PlaylistPlay();
447 /* Play a new file */
448 p_wrapper->PlaylistPlay();
453 p_wrapper->InputSetRate( INPUT_RATE_DEFAULT * 8 );
457 p_wrapper->InputSetRate( INPUT_RATE_DEFAULT * 4 );
461 p_wrapper->InputSetRate( INPUT_RATE_DEFAULT * 2 );
465 p_wrapper->InputSetRate( INPUT_RATE_DEFAULT );
469 p_wrapper->InputSetRate( INPUT_RATE_DEFAULT / 2 );
473 p_wrapper->InputSetRate( INPUT_RATE_DEFAULT / 4 );
477 p_wrapper->InputSetRate( INPUT_RATE_DEFAULT / 8 );
481 /* handled by semaphores */
483 // volume related messages
485 /* adjust the volume */
486 if (playback_status > -1)
488 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
489 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
495 if( p_wrapper->IsMuted() )
496 p_wrapper->VolumeRestore();
498 p_wrapper->VolumeMute();
499 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
503 if ( playback_status > -1 )
506 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
508 p_wrapper->ToggleLanguage( channel );
513 case SELECT_SUBTITLE:
514 if ( playback_status > -1 )
517 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
518 p_wrapper->ToggleSubtitle( subtitle );
522 // specific navigation messages
525 p_wrapper->PrevTitle();
530 p_wrapper->NextTitle();
534 p_wrapper->ToggleTitle( 0 );
537 if ( playback_status > -1 )
540 if( p_message->FindInt32( "index", &index ) == B_OK )
541 p_wrapper->ToggleTitle( index );
546 p_wrapper->PrevChapter();
551 p_wrapper->NextChapter();
555 if ( playback_status > -1 )
558 if( p_message->FindInt32( "index", &index ) == B_OK )
559 p_wrapper->ToggleChapter( index );
563 p_wrapper->PlaylistPrev();
566 p_wrapper->PlaylistNext();
568 // general next/prev functionality (skips to whatever makes most sense)
570 p_wrapper->NavigatePrev();
573 p_wrapper->NavigateNext();
575 // drag'n'drop and system messages
577 // convert soundplay drag'n'drop message (containing paths)
578 // to normal message (containing refs)
581 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
584 if ( get_ref_for_path( path, &ref ) == B_OK )
585 p_message->AddRef( "refs", &ref );
589 case B_REFS_RECEIVED:
592 /* file(s) opened by the File menu -> append to the playlist;
593 * file(s) opened by drag & drop -> replace playlist;
594 * file(s) opened by 'shift' + drag & drop -> append */
595 bool replace = false;
596 bool reverse = false;
597 if ( p_message->WasDropped() )
599 replace = !( modifiers() & B_SHIFT_KEY );
603 // build list of files to be played from message contents
607 // if we should parse sub-folders as well
608 bool askedAlready = false;
609 bool parseSubFolders = askedAlready;
610 // traverse refs in reverse order
613 if ( p_message->GetInfo( "refs", &dummy, &count ) == B_OK && count > 0 )
615 int32 i = reverse ? count - 1 : 0;
616 int32 increment = reverse ? -1 : 1;
617 for ( ; p_message->FindRef( "refs", i, &ref ) == B_OK; i += increment )
620 if ( path.InitCheck() == B_OK )
623 // has the user dropped a folder?
624 BDirectory dir( &ref );
625 if ( dir.InitCheck() == B_OK)
627 // has the user dropped a dvd disk icon?
628 if ( dir.IsRootDirectory() )
630 BVolumeRoster volRoster;
632 BDirectory volumeRoot;
633 status_t status = volRoster.GetNextVolume( &vol );
634 while ( status == B_NO_ERROR )
636 if ( vol.GetRootDirectory( &volumeRoot ) == B_OK
637 && dir == volumeRoot )
642 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
645 BMessage msg( OPEN_DVD );
646 msg.AddString( "device", deviceName.String() );
655 status = volRoster.GetNextVolume( &vol );
662 dir.Rewind(); // defensive programming
664 collect_folder_contents( dir, files,
672 BString* string = new BString( path.Path() );
673 if ( !files.AddItem( string, 0 ) )
674 delete string; // at least don't leak
678 // give the list to VLC
679 // BString objects allocated here will be deleted there
681 if ( p_message->FindInt32("drop index", &index) != B_OK )
683 p_wrapper->OpenFiles( &files, replace, index );
689 case OPEN_PREFERENCES:
691 if( fPreferencesWindow->Lock() )
693 if (fPreferencesWindow->IsHidden())
694 fPreferencesWindow->Show();
696 fPreferencesWindow->Activate();
697 fPreferencesWindow->Unlock();
704 if( fMessagesWindow->Lock() )
706 if (fMessagesWindow->IsHidden())
707 fMessagesWindow->Show();
709 fMessagesWindow->Activate();
710 fMessagesWindow->Unlock();
718 BWindow::MessageReceived( p_message );
724 /*****************************************************************************
725 * InterfaceWindow::QuitRequested
726 *****************************************************************************/
727 bool InterfaceWindow::QuitRequested()
729 p_wrapper->PlaylistStop();
730 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
739 /*****************************************************************************
740 * InterfaceWindow::UpdateInterface
741 *****************************************************************************/
742 void InterfaceWindow::UpdateInterface()
744 if( p_wrapper->HasInput() )
746 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
748 p_wrapper->SetTimeAsFloat( p_mediaControl->GetSeekTo() );
750 else if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
752 p_mediaControl->SetEnabled( true );
753 bool hasTitles = p_wrapper->HasTitles();
754 bool hasChapters = p_wrapper->HasChapters();
755 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
756 p_wrapper->InputRate() );
757 p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
758 _SetMenusEnabled( true, hasChapters, hasTitles );
760 _UpdateSpeedMenu( p_wrapper->InputRate() );
762 // enable/disable skip buttons
765 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
766 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
768 if ( p_wrapper->HasInput() )
770 p_mediaControl->SetAudioEnabled( true );
771 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
773 p_mediaControl->SetAudioEnabled( false );
777 // update playlist as well
778 if ( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
780 fPlaylistWindow->UpdatePlaylist();
781 fPlaylistWindow->Unlock();
786 if ( LockWithTimeout(INTERFACE_LOCKING_TIMEOUT) == B_OK )
788 _SetMenusEnabled( false );
789 if( !( p_wrapper->PlaylistSize() > 0 ) )
790 p_mediaControl->SetEnabled( false );
793 p_mediaControl->SetProgress( 0 );
794 // enable/disable skip buttons
797 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
798 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
804 fLastUpdateTime = system_time();
807 /*****************************************************************************
808 * InterfaceWindow::IsStopped
809 *****************************************************************************/
811 InterfaceWindow::IsStopped() const
813 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
816 /*****************************************************************************
817 * InterfaceWindow::_UpdatePlaylist
818 *****************************************************************************/
820 InterfaceWindow::_UpdatePlaylist()
822 if ( fPlaylistWindow->Lock() )
824 fPlaylistWindow->UpdatePlaylist( true );
825 fPlaylistWindow->Unlock();
826 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
830 /*****************************************************************************
831 * InterfaceWindow::_SetMenusEnabled
832 *****************************************************************************/
834 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
841 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
843 if ( fNextChapterMI->IsEnabled() != hasChapters )
844 fNextChapterMI->SetEnabled( hasChapters );
845 if ( fPrevChapterMI->IsEnabled() != hasChapters )
846 fPrevChapterMI->SetEnabled( hasChapters );
847 if ( fChapterMenu->IsEnabled() != hasChapters )
848 fChapterMenu->SetEnabled( hasChapters );
849 if ( fNextTitleMI->IsEnabled() != hasTitles )
850 fNextTitleMI->SetEnabled( hasTitles );
851 if ( fPrevTitleMI->IsEnabled() != hasTitles )
852 fPrevTitleMI->SetEnabled( hasTitles );
853 if ( fTitleMenu->IsEnabled() != hasTitles )
854 fTitleMenu->SetEnabled( hasTitles );
855 if ( fAudioMenu->IsEnabled() != hasFile )
856 fAudioMenu->SetEnabled( hasFile );
857 if ( fNavigationMenu->IsEnabled() != hasFile )
858 fNavigationMenu->SetEnabled( hasFile );
859 if ( fLanguageMenu->IsEnabled() != hasFile )
860 fLanguageMenu->SetEnabled( hasFile );
861 if ( fSubtitlesMenu->IsEnabled() != hasFile )
862 fSubtitlesMenu->SetEnabled( hasFile );
863 if ( fSpeedMenu->IsEnabled() != hasFile )
864 fSpeedMenu->SetEnabled( hasFile );
865 // "goto menu" menu item
866 bool hasMenu = p_wrapper->IsUsingMenus();
867 if ( fGotoMenuMI->IsEnabled() != hasMenu )
868 fGotoMenuMI->SetEnabled( hasMenu );
873 /*****************************************************************************
874 * InterfaceWindow::_UpdateSpeedMenu
875 *****************************************************************************/
877 InterfaceWindow::_UpdateSpeedMenu( int rate )
879 BMenuItem * toMark = NULL;
883 case ( INPUT_RATE_DEFAULT * 8 ):
887 case ( INPUT_RATE_DEFAULT * 4 ):
891 case ( INPUT_RATE_DEFAULT * 2 ):
895 case ( INPUT_RATE_DEFAULT ):
899 case ( INPUT_RATE_DEFAULT / 2 ):
903 case ( INPUT_RATE_DEFAULT / 4 ):
907 case ( INPUT_RATE_DEFAULT / 8 ):
912 if ( !toMark->IsMarked() )
913 toMark->SetMarked( true );
916 /*****************************************************************************
917 * InterfaceWindow::_ShowFilePanel
918 *****************************************************************************/
920 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
924 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
925 B_FILE_NODE | B_DIRECTORY_NODE );
926 fFilePanel->SetTarget( this );
928 fFilePanel->Window()->SetTitle( windowTitle );
929 BMessage message( command );
930 fFilePanel->SetMessage( &message );
931 if ( !fFilePanel->IsShowing() )
933 fFilePanel->Refresh();
940 set_window_pos( BWindow* window, BRect frame )
942 // sanity checks: make sure window is not too big/small
943 // and that it's not off-screen
944 float minWidth, maxWidth, minHeight, maxHeight;
945 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
947 make_sure_frame_is_within_limits( frame,
948 minWidth, minHeight, maxWidth, maxHeight );
949 if ( make_sure_frame_is_on_screen( frame ) )
951 window->MoveTo( frame.LeftTop() );
952 window->ResizeTo( frame.Width(), frame.Height() );
958 launch_window( BWindow* window, bool showing )
960 if ( window->Lock() )
964 if ( window->IsHidden() )
969 if ( !window->IsHidden() )
976 /*****************************************************************************
977 * InterfaceWindow::_RestoreSettings
978 *****************************************************************************/
980 InterfaceWindow::_RestoreSettings()
982 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
985 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
986 set_window_pos( this, frame );
987 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
988 set_window_pos( fPlaylistWindow, frame );
989 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
990 set_window_pos( fMessagesWindow, frame );
991 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
993 /* FIXME: Preferences resizing doesn't work correctly yet */
994 frame.right = frame.left + fPreferencesWindow->Frame().Width();
995 frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
996 set_window_pos( fPreferencesWindow, frame );
1000 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1001 launch_window( fPlaylistWindow, showing );
1002 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1003 launch_window( fMessagesWindow, showing );
1004 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1005 launch_window( fPreferencesWindow, showing );
1008 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1009 fPlaylistWindow->SetDisplayMode( displayMode );
1013 /*****************************************************************************
1014 * InterfaceWindow::_StoreSettings
1015 *****************************************************************************/
1017 InterfaceWindow::_StoreSettings()
1019 /* Save the volume */
1020 config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
1021 config_SaveConfigFile( p_intf, "main" );
1023 /* Save the windows positions */
1024 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1025 fSettings->AddRect( "main frame", Frame() );
1026 if ( fPlaylistWindow->Lock() )
1028 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1029 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1030 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1031 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1032 fPlaylistWindow->Unlock();
1034 if ( fMessagesWindow->Lock() )
1036 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1037 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1038 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1039 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1040 fMessagesWindow->Unlock();
1042 if ( fPreferencesWindow->Lock() )
1044 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1045 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1046 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1047 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1048 fPreferencesWindow->Unlock();
1050 uint32 displayMode = fPlaylistWindow->DisplayMode();
1051 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1052 fSettings->AddInt32( "playlist display mode", displayMode );
1054 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1058 /*****************************************************************************
1060 *****************************************************************************/
1061 CDMenu::CDMenu(const char *name)
1066 /*****************************************************************************
1068 *****************************************************************************/
1073 /*****************************************************************************
1074 * CDMenu::AttachedToWindow
1075 *****************************************************************************/
1076 void CDMenu::AttachedToWindow(void)
1079 while ( BMenuItem* item = RemoveItem( 0L ) )
1081 GetCD( "/dev/disk" );
1082 BMenu::AttachedToWindow();
1085 /*****************************************************************************
1087 *****************************************************************************/
1088 int CDMenu::GetCD( const char *directory )
1090 BVolumeRoster volRoster;
1093 status_t status = volRoster.GetNextVolume( &vol );
1094 while ( status == B_NO_ERROR )
1099 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1102 BMessage* msg = new BMessage( OPEN_DVD );
1103 msg->AddString( "device", deviceName.String() );
1104 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1108 status = volRoster.GetNextVolume( &vol );
1113 /*****************************************************************************
1114 * LanguageMenu::LanguageMenu
1115 *****************************************************************************/
1116 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
1117 VlcWrapper *p_wrapper )
1121 this->p_wrapper = p_wrapper;
1124 /*****************************************************************************
1125 * LanguageMenu::~LanguageMenu
1126 *****************************************************************************/
1127 LanguageMenu::~LanguageMenu()
1131 /*****************************************************************************
1132 * LanguageMenu::AttachedToWindow
1133 *****************************************************************************/
1134 void LanguageMenu::AttachedToWindow()
1137 while ( BMenuItem* item = RemoveItem( 0L ) )
1140 SetRadioMode( true );
1141 if ( BList *list = p_wrapper->GetChannels( kind ) )
1143 for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1146 if ( list->CountItems() > 1 )
1147 AddItem( new BSeparatorItem(), 1 );
1149 BMenu::AttachedToWindow();
1152 /*****************************************************************************
1153 * TitleMenu::TitleMenu
1154 *****************************************************************************/
1155 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1157 p_intf( p_interface )
1161 /*****************************************************************************
1162 * TitleMenu::~TitleMenu
1163 *****************************************************************************/
1164 TitleMenu::~TitleMenu()
1168 /*****************************************************************************
1169 * TitleMenu::AttachedToWindow
1170 *****************************************************************************/
1171 void TitleMenu::AttachedToWindow()
1173 while( BMenuItem* item = RemoveItem( 0L ) )
1176 if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1178 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1181 BMenu::AttachedToWindow();
1185 /*****************************************************************************
1186 * ChapterMenu::ChapterMenu
1187 *****************************************************************************/
1188 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1190 p_intf( p_interface )
1194 /*****************************************************************************
1195 * ChapterMenu::~ChapterMenu
1196 *****************************************************************************/
1197 ChapterMenu::~ChapterMenu()
1201 /*****************************************************************************
1202 * ChapterMenu::AttachedToWindow
1203 *****************************************************************************/
1204 void ChapterMenu::AttachedToWindow()
1206 while( BMenuItem* item = RemoveItem( 0L ) )
1209 if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1211 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1215 BMenu::AttachedToWindow();
1226 /*****************************************************************************
1228 *****************************************************************************/
1230 load_settings( BMessage* message, const char* fileName, const char* folder )
1232 status_t ret = B_BAD_VALUE;
1236 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1238 // passing folder is optional
1240 ret = path.Append( folder );
1241 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1243 BFile file( path.Path(), B_READ_ONLY );
1244 if ( ( ret = file.InitCheck() ) == B_OK )
1246 ret = message->Unflatten( &file );
1255 /*****************************************************************************
1257 *****************************************************************************/
1259 save_settings( BMessage* message, const char* fileName, const char* folder )
1261 status_t ret = B_BAD_VALUE;
1265 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1267 // passing folder is optional
1268 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1269 ret = create_directory( path.Path(), 0777 );
1270 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1272 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1273 if ( ( ret = file.InitCheck() ) == B_OK )
1275 ret = message->Flatten( &file );