1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.27 2003/02/03 17:18:48 stippi 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" );
217 SetName( "interface" );
218 SetTitle( VOUT_TITLE );
220 // the media control view
221 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
223 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
226 p_mediaControl->GetPreferredSize( &width, &height );
228 // set up the main menu
229 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
230 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
232 // make menu bar resize to correct height
233 float menuWidth, menuHeight;
234 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
235 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
236 // take care of proper size for ourself
237 height += fMenuBar->Bounds().Height();
238 ResizeTo( width, height );
240 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
241 AddChild( fMenuBar );
242 AddChild( p_mediaControl );
245 BMenu* fileMenu = new BMenu( "File" );
246 fMenuBar->AddItem( fileMenu );
247 fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
248 new BMessage( OPEN_FILE ), 'O') );
250 fileMenu->AddItem( new CDMenu( "Open Disc" ) );
252 fileMenu->AddItem( new BMenuItem( "Open Subtitles" B_UTF8_ELLIPSIS,
253 new BMessage( LOAD_SUBFILE ) ) );
255 fileMenu->AddSeparatorItem();
256 BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
257 new BMessage( B_ABOUT_REQUESTED ), 'A');
258 item->SetTarget( be_app );
259 fileMenu->AddItem( item );
260 fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
262 fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_wrapper);
263 fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_wrapper);
265 /* Add the Audio menu */
266 fAudioMenu = new BMenu( "Audio" );
267 fMenuBar->AddItem ( fAudioMenu );
268 fAudioMenu->AddItem( fLanguageMenu );
269 fAudioMenu->AddItem( fSubtitlesMenu );
271 fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
272 fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
273 fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
274 fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
276 /* Add the Navigation menu */
277 fNavigationMenu = new BMenu( "Navigation" );
278 fMenuBar->AddItem( fNavigationMenu );
279 fNavigationMenu->AddItem( fPrevTitleMI );
280 fNavigationMenu->AddItem( fNextTitleMI );
281 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
282 fNavigationMenu->AddSeparatorItem();
283 fNavigationMenu->AddItem( fPrevChapterMI );
284 fNavigationMenu->AddItem( fNextChapterMI );
285 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
287 /* Add the Speed menu */
288 fSpeedMenu = new BMenu( "Speed" );
289 fSpeedMenu->SetRadioMode( true );
290 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
291 fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
292 fNormalMI->SetMarked(true); // default to normal speed
293 fSpeedMenu->AddItem( fNormalMI );
294 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
295 fSpeedMenu->SetTargetForItems( this );
296 fMenuBar->AddItem( fSpeedMenu );
298 /* Add the Show menu */
299 fShowMenu = new BMenu( "Window" );
300 fShowMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
301 new BMessage( OPEN_PLAYLIST ), 'P') );
302 fShowMenu->AddItem( new BMenuItem( "Messages" B_UTF8_ELLIPSIS,
303 new BMessage( OPEN_MESSAGES ), 'M' ) );
304 fShowMenu->AddItem( new BMenuItem( "Settings" B_UTF8_ELLIPSIS,
305 new BMessage( OPEN_PREFERENCES ), 'S' ) );
306 fMenuBar->AddItem( fShowMenu );
308 /* Prepare fow showing */
309 _SetMenusEnabled( false );
310 p_mediaControl->SetEnabled( false );
314 /* // Restore interface settings
315 // main window size and position
316 int i_width = config_GetInt( p_intf, "beos-intf-width" ),
317 i_height = config_GetInt( p_intf, "beos-intf-height" ),
318 i_xpos = config_GetInt( p_intf, "beos-intf-xpos" ),
319 i_ypos = config_GetInt( p_intf, "beos-intf-ypos" );
320 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
322 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
324 float minWidth, maxWidth, minHeight, maxHeight;
325 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
327 make_sure_frame_is_within_limits( r, minWidth, minHeight, maxWidth, maxHeight );
328 if ( make_sure_frame_is_on_screen( r ) )
330 ResizeTo( r.Width(), r.Height() );
331 MoveTo( r.LeftTop() );
334 // playlist window size and position
335 i_width = config_GetInt( p_intf, "beos-playlist-width" ),
336 i_height = config_GetInt( p_intf, "beos-playlist-height" ),
337 i_xpos = config_GetInt( p_intf, "beos-playlist-xpos" ),
338 i_ypos = config_GetInt( p_intf, "beos-playlist-ypos" );
339 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
341 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
343 float minWidth, maxWidth, minHeight, maxHeight;
344 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
346 make_sure_frame_is_within_limits( r, minWidth, minHeight, maxWidth, maxHeight );
347 if ( make_sure_frame_is_on_screen( r ) )
349 fPlaylistWindow->ResizeTo( r.Width(), r.Height() );
350 fPlaylistWindow->MoveTo( r.LeftTop() );
353 // child windows are not running yet, that's why we aint locking them
355 // messages window size and position
356 i_width = config_GetInt( p_intf, "beos-messages-width" ),
357 i_height = config_GetInt( p_intf, "beos-messages-height" ),
358 i_xpos = config_GetInt( p_intf, "beos-messages-xpos" ),
359 i_ypos = config_GetInt( p_intf, "beos-messages-ypos" );
360 if( i_width && i_height && i_xpos && i_ypos )
362 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
364 float minWidth, maxWidth, minHeight, maxHeight;
365 fMessagesWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
367 make_sure_frame_is_within_limits( r, minWidth, minHeight, maxWidth, maxHeight );
368 if ( make_sure_frame_is_on_screen( r ) )
370 fMessagesWindow->ResizeTo( r.Width(), r.Height() );
371 fMessagesWindow->MoveTo( r.LeftTop() );
374 if( config_GetInt( p_intf, "beos-playlist-show" ) )
376 fPlaylistWindow->Show();
380 fPlaylistWindow->Hide();
381 fPlaylistWindow->Show();
383 // messages window size and position
384 i_width = config_GetInt( p_intf, "beos-messages-width" ),
385 i_height = config_GetInt( p_intf, "beos-messages-height" ),
386 i_xpos = config_GetInt( p_intf, "beos-messages-xpos" ),
387 i_ypos = config_GetInt( p_intf, "beos-messages-ypos" );
388 if( i_width > 20 && i_height > 20 && i_xpos >= 0 && i_ypos >= 0 )
390 BRect r( i_xpos, i_ypos, i_xpos + i_width, i_ypos + i_height );
391 float minWidth, maxWidth, minHeight, maxHeight;
392 fMessagesWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
394 make_sure_frame_is_within_limits( r, minWidth, minHeight, maxWidth, maxHeight );
395 if ( make_sure_frame_is_on_screen( r ) )
397 fMessagesWindow->ResizeTo( r.Width(), r.Height() );
398 fMessagesWindow->MoveTo( r.LeftTop() );
402 if( config_GetInt( p_intf, "beos-messages-show" ) )
404 fMessagesWindow->Show();
408 fMessagesWindow->Hide();
409 fMessagesWindow->Show();
415 InterfaceWindow::~InterfaceWindow()
417 if( fPlaylistWindow )
418 fPlaylistWindow->ReallyQuit();
419 fPlaylistWindow = NULL;
420 if( fMessagesWindow )
421 fMessagesWindow->ReallyQuit();
422 fMessagesWindow = NULL;
427 /*****************************************************************************
428 * InterfaceWindow::FrameResized
429 *****************************************************************************/
431 InterfaceWindow::FrameResized(float width, float height)
434 fMenuBar->MoveTo(r.LeftTop());
435 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
436 r.top += fMenuBar->Bounds().Height() + 1.0;
437 p_mediaControl->MoveTo(r.LeftTop());
438 p_mediaControl->ResizeTo(r.Width(), r.Height());
441 /*****************************************************************************
442 * InterfaceWindow::MessageReceived
443 *****************************************************************************/
444 void InterfaceWindow::MessageReceived( BMessage * p_message )
446 int playback_status; // remember playback state
447 playback_status = p_wrapper->InputStatus();
449 switch( p_message->what )
451 case B_ABOUT_REQUESTED:
453 BAlert* alert = new BAlert( VOUT_TITLE,
454 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
462 _ShowFilePanel( B_REFS_RECEIVED, "VideoLAN Client: Open Media Files" );
466 _ShowFilePanel( SUBFILE_RECEIVED, "VideoLAN Client: Open Subtitle File" );
470 if (fPlaylistWindow->Lock())
472 if (fPlaylistWindow->IsHidden())
473 fPlaylistWindow->Show();
475 fPlaylistWindow->Activate();
476 fPlaylistWindow->Unlock();
481 const char *psz_device;
482 BString type( "dvd" );
483 if( p_message->FindString( "device", &psz_device ) == B_OK )
485 BString device( psz_device );
486 p_wrapper->OpenDisc( type, device, 0, 0 );
492 case SUBFILE_RECEIVED:
495 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
498 if ( path.InitCheck() == B_OK )
499 p_wrapper->LoadSubFile( path.Path() );
505 // this currently stops playback not nicely
506 if (playback_status > UNDEF_S)
508 p_wrapper->PlaylistStop();
509 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
514 /* starts playing in normal mode */
517 /* toggle between pause and play */
518 if (playback_status > UNDEF_S)
520 /* pause if currently playing */
521 if ( playback_status == PLAYING_S )
523 p_wrapper->PlaylistPause();
527 p_wrapper->PlaylistPlay();
532 /* Play a new file */
533 p_wrapper->PlaylistPlay();
538 /* cycle the fast playback modes */
539 if (playback_status > UNDEF_S)
541 p_wrapper->InputFaster();
546 /* cycle the slow playback modes */
547 if (playback_status > UNDEF_S)
549 p_wrapper->InputSlower();
554 /* restore speed to normal if already playing */
555 if (playback_status > UNDEF_S)
557 p_wrapper->PlaylistPlay();
562 /* handled by semaphores */
564 // volume related messages
566 /* adjust the volume */
567 if (playback_status > UNDEF_S)
569 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
570 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
576 if( p_wrapper->IsMuted() )
577 p_wrapper->VolumeRestore();
579 p_wrapper->VolumeMute();
580 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
584 if ( playback_status > UNDEF_S )
587 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
589 p_wrapper->ToggleLanguage( channel );
594 case SELECT_SUBTITLE:
595 if ( playback_status > UNDEF_S )
598 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
599 p_wrapper->ToggleSubtitle( subtitle );
603 // specific navigation messages
606 p_wrapper->PrevTitle();
611 p_wrapper->NextTitle();
615 if ( playback_status > UNDEF_S )
618 if( p_message->FindInt32( "index", &index ) == B_OK )
619 p_wrapper->ToggleTitle( index );
624 p_wrapper->PrevChapter();
629 p_wrapper->NextChapter();
633 if ( playback_status > UNDEF_S )
636 if( p_message->FindInt32( "index", &index ) == B_OK )
637 p_wrapper->ToggleChapter( index );
641 p_wrapper->PlaylistPrev();
644 p_wrapper->PlaylistNext();
646 // general next/prev functionality (skips to whatever makes most sense)
648 p_wrapper->NavigatePrev();
651 p_wrapper->NavigateNext();
653 // drag'n'drop and system messages
655 // convert soundplay drag'n'drop message (containing paths)
656 // to normal message (containing refs)
659 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
662 if ( get_ref_for_path( path, &ref ) == B_OK )
663 p_message->AddRef( "refs", &ref );
667 case B_REFS_RECEIVED:
670 /* file(s) opened by the File menu -> append to the playlist;
671 * file(s) opened by drag & drop -> replace playlist;
672 * file(s) opened by 'shift' + drag & drop -> append */
673 bool replace = false;
674 bool reverse = false;
675 if ( p_message->WasDropped() )
677 replace = !( modifiers() & B_SHIFT_KEY );
681 // build list of files to be played from message contents
685 // if we should parse sub-folders as well
686 bool askedAlready = false;
687 bool parseSubFolders = askedAlready;
688 // traverse refs in reverse order
691 if ( p_message->GetInfo( "refs", &dummy, &count ) == B_OK && count > 0 )
693 int32 i = reverse ? count - 1 : 0;
694 int32 increment = reverse ? -1 : 1;
695 for ( ; p_message->FindRef( "refs", i, &ref ) == B_OK; i += increment )
698 if ( path.InitCheck() == B_OK )
701 // has the user dropped a folder?
702 BDirectory dir( &ref );
703 if ( dir.InitCheck() == B_OK)
705 // has the user dropped a dvd disk icon?
706 if ( dir.IsRootDirectory() )
708 BVolumeRoster volRoster;
710 BDirectory volumeRoot;
711 status_t status = volRoster.GetNextVolume( &vol );
712 while ( status == B_NO_ERROR )
714 if ( vol.GetRootDirectory( &volumeRoot ) == B_OK
715 && dir == volumeRoot )
720 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
723 BMessage msg( OPEN_DVD );
724 msg.AddString( "device", deviceName.String() );
733 status = volRoster.GetNextVolume( &vol );
740 dir.Rewind(); // defensive programming
742 collect_folder_contents( dir, files,
750 BString* string = new BString( path.Path() );
751 if ( !files.AddItem( string, 0 ) )
752 delete string; // at least don't leak
756 // give the list to VLC
757 // BString objects allocated here will be deleted there
759 if ( p_message->FindInt32("drop index", &index) != B_OK )
761 p_wrapper->OpenFiles( &files, replace, index );
767 case OPEN_PREFERENCES:
769 if( fPreferencesWindow->Lock() )
771 if (fPreferencesWindow->IsHidden())
772 fPreferencesWindow->Show();
774 fPreferencesWindow->Activate();
775 fPreferencesWindow->Unlock();
782 if( fMessagesWindow->Lock() )
784 if (fMessagesWindow->IsHidden())
785 fMessagesWindow->Show();
787 fMessagesWindow->Activate();
788 fMessagesWindow->Unlock();
796 BWindow::MessageReceived( p_message );
802 /*****************************************************************************
803 * InterfaceWindow::QuitRequested
804 *****************************************************************************/
805 bool InterfaceWindow::QuitRequested()
807 p_wrapper->PlaylistStop();
808 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
810 /* Save interface settings */
811 /* BRect frame = Frame();
812 config_PutInt( p_intf, "beos-intf-width", (int)frame.Width() );
813 config_PutInt( p_intf, "beos-intf-height", (int)frame.Height() );
814 config_PutInt( p_intf, "beos-intf-xpos", (int)frame.left );
815 config_PutInt( p_intf, "beos-intf-ypos", (int)frame.top );
816 if( fPlaylistWindow->Lock() )
818 frame = fPlaylistWindow->Frame();
819 config_PutInt( p_intf, "beos-playlist-width", (int)frame.Width() );
820 config_PutInt( p_intf, "beos-playlist-height", (int)frame.Height() );
821 config_PutInt( p_intf, "beos-playlist-xpos", (int)frame.left );
822 config_PutInt( p_intf, "beos-playlist-ypos", (int)frame.top );
823 config_PutInt( p_intf, "beos-playlist-show", !fPlaylistWindow->IsHidden() );
824 fPlaylistWindow->Unlock();
826 if( fMessagesWindow->Lock() )
828 frame = fMessagesWindow->Frame();
829 config_PutInt( p_intf, "beos-messages-width", (int)frame.Width() );
830 config_PutInt( p_intf, "beos-messages-height", (int)frame.Height() );
831 config_PutInt( p_intf, "beos-messages-xpos", (int)frame.left );
832 config_PutInt( p_intf, "beos-messages-ypos", (int)frame.top );
833 config_PutInt( p_intf, "beos-messages-show", !fMessagesWindow->IsHidden() );
834 fMessagesWindow->Unlock();
836 config_SaveConfigFile( p_intf, "beos" );
844 /*****************************************************************************
845 * InterfaceWindow::UpdateInterface
846 *****************************************************************************/
847 void InterfaceWindow::UpdateInterface()
849 if( p_wrapper->HasInput() )
851 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
853 p_wrapper->SetTimeAsFloat( p_mediaControl->GetSeekTo() );
855 else if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
857 p_mediaControl->SetEnabled( true );
858 bool hasTitles = p_wrapper->HasTitles();
859 bool hasChapters = p_wrapper->HasChapters();
860 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
861 p_wrapper->InputRate() );
862 p_mediaControl->SetProgress( p_wrapper->GetTimeAsFloat() );
863 _SetMenusEnabled( true, hasChapters, hasTitles );
865 _UpdateSpeedMenu( p_wrapper->InputRate() );
867 // enable/disable skip buttons
870 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
871 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
873 if ( p_wrapper->HasAudio() )
875 p_mediaControl->SetAudioEnabled( true );
876 p_mediaControl->SetMuted( p_wrapper->IsMuted() );
878 p_mediaControl->SetAudioEnabled( false );
882 // update playlist as well
883 if ( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
885 fPlaylistWindow->UpdatePlaylist();
886 fPlaylistWindow->Unlock();
891 if ( LockWithTimeout(INTERFACE_LOCKING_TIMEOUT) == B_OK )
893 _SetMenusEnabled( false );
894 if( !( p_wrapper->PlaylistSize() > 0 ) )
895 p_mediaControl->SetEnabled( false );
898 p_mediaControl->SetProgress( 0 );
899 // enable/disable skip buttons
902 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
903 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
909 /* always force the user-specified volume */
910 /* FIXME : I'm quite sure there is a cleaner way to do this */
911 int i_volume = p_mediaControl->GetVolume();
912 if( p_wrapper->GetVolume() != i_volume )
914 p_wrapper->SetVolume( i_volume );
917 // strangly, someone is calling this function even after the object has been destructed!
918 // even more strangly, this workarround seems to work
920 fMessagesWindow->UpdateMessages();
922 fLastUpdateTime = system_time();
925 /*****************************************************************************
926 * InterfaceWindow::IsStopped
927 *****************************************************************************/
929 InterfaceWindow::IsStopped() const
931 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
934 /*****************************************************************************
935 * InterfaceWindow::_UpdatePlaylist
936 *****************************************************************************/
938 InterfaceWindow::_UpdatePlaylist()
940 if ( fPlaylistWindow->Lock() )
942 fPlaylistWindow->UpdatePlaylist( true );
943 fPlaylistWindow->Unlock();
944 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
948 /*****************************************************************************
949 * InterfaceWindow::_SetMenusEnabled
950 *****************************************************************************/
952 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
959 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
961 if ( fNextChapterMI->IsEnabled() != hasChapters )
962 fNextChapterMI->SetEnabled( hasChapters );
963 if ( fPrevChapterMI->IsEnabled() != hasChapters )
964 fPrevChapterMI->SetEnabled( hasChapters );
965 if ( fChapterMenu->IsEnabled() != hasChapters )
966 fChapterMenu->SetEnabled( hasChapters );
967 if ( fNextTitleMI->IsEnabled() != hasTitles )
968 fNextTitleMI->SetEnabled( hasTitles );
969 if ( fPrevTitleMI->IsEnabled() != hasTitles )
970 fPrevTitleMI->SetEnabled( hasTitles );
971 if ( fTitleMenu->IsEnabled() != hasTitles )
972 fTitleMenu->SetEnabled( hasTitles );
973 if ( fAudioMenu->IsEnabled() != hasFile )
974 fAudioMenu->SetEnabled( hasFile );
975 if ( fNavigationMenu->IsEnabled() != hasFile )
976 fNavigationMenu->SetEnabled( hasFile );
977 if ( fLanguageMenu->IsEnabled() != hasFile )
978 fLanguageMenu->SetEnabled( hasFile );
979 if ( fSubtitlesMenu->IsEnabled() != hasFile )
980 fSubtitlesMenu->SetEnabled( hasFile );
981 if ( fSpeedMenu->IsEnabled() != hasFile )
982 fSpeedMenu->SetEnabled( hasFile );
987 /*****************************************************************************
988 * InterfaceWindow::_UpdateSpeedMenu
989 *****************************************************************************/
991 InterfaceWindow::_UpdateSpeedMenu( int rate )
993 if ( rate == DEFAULT_RATE )
995 if ( !fNormalMI->IsMarked() )
996 fNormalMI->SetMarked( true );
998 else if ( rate < DEFAULT_RATE )
1000 if ( !fFasterMI->IsMarked() )
1001 fFasterMI->SetMarked( true );
1005 if ( !fSlowerMI->IsMarked() )
1006 fSlowerMI->SetMarked( true );
1010 /*****************************************************************************
1011 * InterfaceWindow::_InputStreamChanged
1012 *****************************************************************************/
1014 InterfaceWindow::_InputStreamChanged()
1016 // TODO: move more stuff from updateInterface() here!
1018 p_wrapper->SetVolume( p_mediaControl->GetVolume() );
1021 /*****************************************************************************
1022 * InterfaceWindow::_ShowFilePanel
1023 *****************************************************************************/
1025 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
1029 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
1030 B_FILE_NODE | B_DIRECTORY_NODE );
1031 fFilePanel->SetTarget( this );
1033 fFilePanel->Window()->SetTitle( windowTitle );
1034 BMessage message( command );
1035 fFilePanel->SetMessage( &message );
1036 if ( !fFilePanel->IsShowing() )
1038 fFilePanel->Refresh();
1045 set_window_pos( BWindow* window, BRect frame )
1047 // sanity checks: make sure window is not too big/small
1048 // and that it's not off-screen
1049 float minWidth, maxWidth, minHeight, maxHeight;
1050 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1052 make_sure_frame_is_within_limits( frame,
1053 minWidth, minHeight, maxWidth, maxHeight );
1054 if ( make_sure_frame_is_on_screen( frame ) )
1056 window->MoveTo( frame.LeftTop() );
1057 window->ResizeTo( frame.Width(), frame.Height() );
1063 launch_window( BWindow* window, bool showing )
1065 if ( window->Lock() )
1069 if ( window->IsHidden() )
1074 if ( !window->IsHidden() )
1081 /*****************************************************************************
1082 * InterfaceWindow::_RestoreSettings
1083 *****************************************************************************/
1085 InterfaceWindow::_RestoreSettings()
1087 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1090 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1091 set_window_pos( this, frame );
1092 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1093 set_window_pos( fPlaylistWindow, frame );
1094 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1095 set_window_pos( fMessagesWindow, frame );
1096 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1097 set_window_pos( fPreferencesWindow, frame );
1100 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1101 launch_window( fPlaylistWindow, showing );
1102 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1103 launch_window( fMessagesWindow, showing );
1104 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1105 launch_window( fPreferencesWindow, showing );
1108 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1109 fPlaylistWindow->SetDisplayMode( displayMode );
1113 /*****************************************************************************
1114 * InterfaceWindow::_StoreSettings
1115 *****************************************************************************/
1117 InterfaceWindow::_StoreSettings()
1119 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1120 fSettings->AddRect( "main frame", Frame() );
1121 if ( fPlaylistWindow->Lock() )
1123 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1124 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1125 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1126 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1127 fPlaylistWindow->Unlock();
1129 if ( fMessagesWindow->Lock() )
1131 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1132 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1133 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1134 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1135 fMessagesWindow->Unlock();
1137 if ( fPreferencesWindow->Lock() )
1139 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1140 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1141 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1142 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1143 fPreferencesWindow->Unlock();
1146 uint32 displayMode = fPlaylistWindow->DisplayMode();
1147 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1148 fSettings->AddInt32( "playlist display mode", displayMode );
1150 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1158 /*****************************************************************************
1160 *****************************************************************************/
1161 CDMenu::CDMenu(const char *name)
1166 /*****************************************************************************
1168 *****************************************************************************/
1173 /*****************************************************************************
1174 * CDMenu::AttachedToWindow
1175 *****************************************************************************/
1176 void CDMenu::AttachedToWindow(void)
1179 while ( BMenuItem* item = RemoveItem( 0L ) )
1181 GetCD( "/dev/disk" );
1182 BMenu::AttachedToWindow();
1185 /*****************************************************************************
1187 *****************************************************************************/
1188 int CDMenu::GetCD( const char *directory )
1190 BVolumeRoster volRoster;
1193 status_t status = volRoster.GetNextVolume( &vol );
1194 while ( status == B_NO_ERROR )
1199 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1202 BMessage* msg = new BMessage( OPEN_DVD );
1203 msg->AddString( "device", deviceName.String() );
1204 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1208 status = volRoster.GetNextVolume( &vol );
1212 /*****************************************************************************
1213 * LanguageMenu::LanguageMenu
1214 *****************************************************************************/
1215 LanguageMenu::LanguageMenu( const char *name, int menu_kind,
1216 VlcWrapper *p_wrapper )
1220 this->p_wrapper = p_wrapper;
1223 /*****************************************************************************
1224 * LanguageMenu::~LanguageMenu
1225 *****************************************************************************/
1226 LanguageMenu::~LanguageMenu()
1230 /*****************************************************************************
1231 * LanguageMenu::AttachedToWindow
1232 *****************************************************************************/
1233 void LanguageMenu::AttachedToWindow()
1236 while ( BMenuItem* item = RemoveItem( 0L ) )
1239 SetRadioMode( true );
1240 if ( BList *list = p_wrapper->GetChannels( kind ) )
1242 for ( int32 i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1245 if ( list->CountItems() > 1 )
1246 AddItem( new BSeparatorItem(), 1 );
1248 BMenu::AttachedToWindow();
1251 /*****************************************************************************
1252 * TitleMenu::TitleMenu
1253 *****************************************************************************/
1254 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1256 p_intf( p_interface )
1260 /*****************************************************************************
1261 * TitleMenu::~TitleMenu
1262 *****************************************************************************/
1263 TitleMenu::~TitleMenu()
1267 /*****************************************************************************
1268 * TitleMenu::AttachedToWindow
1269 *****************************************************************************/
1270 void TitleMenu::AttachedToWindow()
1272 while( BMenuItem* item = RemoveItem( 0L ) )
1275 if ( BList *list = p_intf->p_sys->p_wrapper->GetTitles() )
1277 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1280 BMenu::AttachedToWindow();
1284 /*****************************************************************************
1285 * ChapterMenu::ChapterMenu
1286 *****************************************************************************/
1287 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1289 p_intf( p_interface )
1293 /*****************************************************************************
1294 * ChapterMenu::~ChapterMenu
1295 *****************************************************************************/
1296 ChapterMenu::~ChapterMenu()
1300 /*****************************************************************************
1301 * ChapterMenu::AttachedToWindow
1302 *****************************************************************************/
1303 void ChapterMenu::AttachedToWindow()
1305 while( BMenuItem* item = RemoveItem( 0L ) )
1308 if ( BList* list = p_intf->p_sys->p_wrapper->GetChapters() )
1310 for( int i = 0; BMenuItem* item = (BMenuItem*)list->ItemAt( i ); i++ )
1314 BMenu::AttachedToWindow();
1325 /*****************************************************************************
1327 *****************************************************************************/
1329 load_settings( BMessage* message, const char* fileName, const char* folder )
1331 status_t ret = B_BAD_VALUE;
1335 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1337 // passing folder is optional
1339 ret = path.Append( folder );
1340 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1342 BFile file( path.Path(), B_READ_ONLY );
1343 if ( ( ret = file.InitCheck() ) == B_OK )
1345 ret = message->Unflatten( &file );
1354 /*****************************************************************************
1356 *****************************************************************************/
1358 save_settings( BMessage* message, const char* fileName, const char* folder )
1360 status_t ret = B_BAD_VALUE;
1364 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1366 // passing folder is optional
1367 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1368 ret = create_directory( path.Path(), 0777 );
1369 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1371 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1372 if ( ( ret = file.InitCheck() ) == B_OK )
1374 ret = message->Flatten( &file );