1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.2 2002/09/30 18:30:27 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 */
47 #include "MediaControlView.h"
48 #include "PlayListWindow.h"
49 #include "VlcWrapper.h"
50 #include "InterfaceWindow.h"
52 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
55 /*****************************************************************************
57 *****************************************************************************/
59 InterfaceWindow::InterfaceWindow( BRect frame, const char *name,
60 intf_thread_t *p_interface )
61 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
62 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
63 p_intf( p_interface ),
66 fLastUpdateTime( system_time() ),
67 fSettings( new BMessage( 'sett' ) )
70 p_vlc_wrapper = p_vlc_wrapper->getVLCWrapper(p_intf);
71 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
73 fPlaylistIsEmpty = (p_playlist->i_size < 0);
76 SetName( "interface" );
77 SetTitle( VOUT_TITLE );
79 // the media control view
80 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ) );
81 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
82 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
85 p_mediaControl->GetPreferredSize( &width, &height );
87 // set up the main menu
88 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
89 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
91 // make menu bar resize to correct height
92 float menuWidth, menuHeight;
93 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
94 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
95 // take care of proper size for ourself
96 height += fMenuBar->Bounds().Height();
97 ResizeTo( width, height );
99 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
100 AddChild( fMenuBar );
101 AddChild( p_mediaControl );
104 BMenu* fileMenu = new BMenu( "File" );
105 fMenuBar->AddItem( fileMenu );
106 fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
107 new BMessage( OPEN_FILE ), 'O') );
109 fileMenu->AddItem( new CDMenu( "Open Disc" ) );
111 fileMenu->AddSeparatorItem();
112 fileMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
113 new BMessage( OPEN_PLAYLIST ), 'P') );
115 fileMenu->AddSeparatorItem();
116 BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
117 new BMessage( B_ABOUT_REQUESTED ), 'A');
118 item->SetTarget( be_app );
119 fileMenu->AddItem( item );
120 fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
122 fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_intf);
123 fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_intf);
125 /* Add the Audio menu */
126 fAudioMenu = new BMenu( "Audio" );
127 fMenuBar->AddItem ( fAudioMenu );
128 fAudioMenu->AddItem( fLanguageMenu );
129 fAudioMenu->AddItem( fSubtitlesMenu );
131 fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
132 fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
133 fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
134 fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
136 /* Add the Navigation menu */
137 fNavigationMenu = new BMenu( "Navigation" );
138 fMenuBar->AddItem( fNavigationMenu );
139 fNavigationMenu->AddItem( fPrevTitleMI );
140 fNavigationMenu->AddItem( fNextTitleMI );
141 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
142 fNavigationMenu->AddSeparatorItem();
143 fNavigationMenu->AddItem( fPrevChapterMI );
144 fNavigationMenu->AddItem( fNextChapterMI );
145 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
147 /* Add the Speed menu */
148 fSpeedMenu = new BMenu( "Speed" );
149 fSpeedMenu->SetRadioMode( true );
150 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
151 fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
152 fNormalMI->SetMarked(true); // default to normal speed
153 fSpeedMenu->AddItem( fNormalMI );
154 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
155 fSpeedMenu->SetTargetForItems( this );
156 fMenuBar->AddItem( fSpeedMenu );
159 /* Add the Config menu */
160 // BMenu* configMenu = new BMenu( "Config" );
161 // menu_bar->AddItem( configMenu );
162 // fOnTopMI = new BMenuItem( "Always on Top",
163 // new BMessage( TOGGLE_ON_TOP ) )
164 // configMenu->AddItem( );
165 // fOnTopMI->SetMarked(false);
167 // prepare fow showing
168 _SetMenusEnabled(false);
175 InterfaceWindow::~InterfaceWindow()
178 fPlaylistWindow->ReallyQuit();
182 /*****************************************************************************
183 * InterfaceWindow::FrameResized
184 *****************************************************************************/
186 InterfaceWindow::FrameResized(float width, float height)
189 fMenuBar->MoveTo(r.LeftTop());
190 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
191 r.top += fMenuBar->Bounds().Height() + 1.0;
192 p_mediaControl->MoveTo(r.LeftTop());
193 p_mediaControl->ResizeTo(r.Width(), r.Height());
196 /*****************************************************************************
197 * InterfaceWindow::MessageReceived
198 *****************************************************************************/
199 void InterfaceWindow::MessageReceived( BMessage * p_message )
201 int playback_status; // remember playback state
202 playback_status = p_vlc_wrapper->inputGetStatus();
204 switch( p_message->what )
206 case B_ABOUT_REQUESTED:
208 BAlert* alert = new BAlert( VOUT_TITLE,
209 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
222 fFilePanel = new BFilePanel();
223 fFilePanel->SetTarget( this );
228 if (fPlaylistWindow->Lock())
230 if (fPlaylistWindow->IsHidden())
231 fPlaylistWindow->Show();
233 fPlaylistWindow->Activate();
234 fPlaylistWindow->Unlock();
239 const char *psz_device;
240 BString type( "dvd" );
241 if( p_message->FindString( "device", &psz_device ) == B_OK )
243 BString device( psz_device );
244 p_vlc_wrapper->openDisc( type, device, 0, 0 );
251 // this currently stops playback not nicely
252 if (playback_status > UNDEF_S)
254 p_vlc_wrapper->volume_mute();
256 p_vlc_wrapper->playlistStop();
257 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
262 /* starts playing in normal mode */
265 /* toggle between pause and play */
266 if (playback_status > UNDEF_S)
268 /* pause if currently playing */
269 if ( playback_status == PLAYING_S )
271 p_vlc_wrapper->volume_mute();
273 p_vlc_wrapper->playlistPause();
277 p_vlc_wrapper->volume_restore();
278 p_vlc_wrapper->playlistPlay();
283 /* Play a new file */
284 p_vlc_wrapper->playlistPlay();
289 /* cycle the fast playback modes */
290 if (playback_status > UNDEF_S)
292 p_vlc_wrapper->volume_mute();
294 p_vlc_wrapper->playFaster();
299 /* cycle the slow playback modes */
300 if (playback_status > UNDEF_S)
302 p_vlc_wrapper->volume_mute();
304 p_vlc_wrapper->playSlower();
309 /* restore speed to normal if already playing */
310 if (playback_status > UNDEF_S)
312 p_vlc_wrapper->volume_restore();
313 p_vlc_wrapper->playlistPlay();
318 /* handled by semaphores */
320 // volume related messages
322 /* adjust the volume */
323 if (playback_status > UNDEF_S)
325 p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
326 p_mediaControl->SetMuted( p_vlc_wrapper->is_muted() );
332 p_vlc_wrapper->toggle_mute();
333 p_mediaControl->SetMuted( p_vlc_wrapper->is_muted() );
337 if ( playback_status > UNDEF_S )
340 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
342 p_vlc_wrapper->toggleLanguage( channel );
343 // vlc seems to remember the volume for every channel,
344 // but I would assume that to be somewhat annoying to the user
345 // the next call will also unmute the volume, which is probably
346 // desired as well, because if the user selects another language,
347 // he probably wants to hear the change as well
348 snooze( 400000 ); // we have to wait a bit, or the change will be reverted
349 p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
354 case SELECT_SUBTITLE:
355 if ( playback_status > UNDEF_S )
358 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
359 p_vlc_wrapper->toggleSubtitle( subtitle );
363 // specific navigation messages
367 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id - 1;
369 /* Disallow area 0 since it is used for video_ts.vob */
372 p_vlc_wrapper->toggleTitle(i_id);
380 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id + 1;
382 if( i_id < p_intf->p_sys->p_input->stream.i_area_nb )
384 p_vlc_wrapper->toggleTitle(i_id);
389 if ( playback_status > UNDEF_S )
392 if ( p_message->FindInt32( "index", &index ) == B_OK )
393 p_vlc_wrapper->toggleTitle( index );
400 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part - 1;
404 p_vlc_wrapper->toggleChapter(i_id);
412 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part + 1;
416 p_vlc_wrapper->toggleChapter(i_id);
421 if ( playback_status > UNDEF_S )
424 if ( p_message->FindInt32( "index", &index ) == B_OK )
425 p_vlc_wrapper->toggleChapter( index );
429 p_vlc_wrapper->playlistPrev();
432 p_vlc_wrapper->playlistNext();
434 // general next/prev functionality (skips to whatever makes most sense)
436 p_vlc_wrapper->navigatePrev();
439 p_vlc_wrapper->navigateNext();
441 // drag'n'drop and system messages
442 case B_REFS_RECEIVED:
445 // figure out if user wants files replaced or added
446 bool replace = false;
447 if ( p_message->WasDropped() )
448 replace = !( modifiers() & B_SHIFT_KEY );
449 // build list of files to be played from message contents
452 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
455 if ( path.InitCheck() == B_OK )
456 // the BString objects will be deleted
457 // by the wrapper function further down
458 files.AddItem( new BString( (char*)path.Path() ) );
460 // give the list to VLC
461 p_vlc_wrapper->openFiles(&files, replace);
467 BWindow::MessageReceived( p_message );
473 /*****************************************************************************
474 * InterfaceWindow::QuitRequested
475 *****************************************************************************/
476 bool InterfaceWindow::QuitRequested()
478 if (p_intf->p_sys->p_input)
480 p_vlc_wrapper->volume_mute();
482 p_vlc_wrapper->playlistStop();
483 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
493 /*****************************************************************************
494 * InterfaceWindow::updateInterface
495 *****************************************************************************/
496 void InterfaceWindow::updateInterface()
498 input_thread_t* input = p_intf->p_sys->p_input;
501 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
503 p_vlc_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
507 bool hasTitles = input->stream.i_area_nb > 1;
508 bool hasChapters = input->stream.p_selected_area->i_part_nb > 1;
509 p_mediaControl->SetStatus( input->stream.control.i_status,
510 input->stream.control.i_rate );
511 p_mediaControl->SetProgress( input->stream.p_selected_area->i_tell,
512 input->stream.p_selected_area->i_size );
513 _SetMenusEnabled( true, hasChapters, hasTitles );
515 _UpdateSpeedMenu( input->stream.control.i_rate );
517 // enable/disable skip buttons
520 p_vlc_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
521 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
523 if ( p_vlc_wrapper->has_audio() )
525 p_mediaControl->SetAudioEnabled( true );
526 p_mediaControl->SetMuted( p_vlc_wrapper->is_muted() );
528 p_mediaControl->SetAudioEnabled( false );
530 if ( input != fInputThread )
532 fInputThread = input;
533 _InputStreamChanged();
538 // update playlist as well
539 if ( fPlaylistWindow->Lock() )
541 fPlaylistWindow->UpdatePlaylist();
542 fPlaylistWindow->Unlock();
546 _SetMenusEnabled(false);
548 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
550 if ( fPlaylistIsEmpty != ( p_playlist->i_size < 0) )
554 fPlaylistIsEmpty = !fPlaylistIsEmpty;
555 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
559 if ( input != fInputThread )
560 fInputThread = input;
562 fLastUpdateTime = system_time();
565 /*****************************************************************************
566 * InterfaceWindow::IsStopped
567 *****************************************************************************/
569 InterfaceWindow::IsStopped() const
571 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
574 /*****************************************************************************
575 * InterfaceWindow::_UpdatePlaylist
576 *****************************************************************************/
578 InterfaceWindow::_UpdatePlaylist()
580 if ( fPlaylistWindow->Lock() )
582 fPlaylistWindow->UpdatePlaylist( true );
583 fPlaylistWindow->Unlock();
584 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
586 fPlaylistIsEmpty = p_playlist->i_size < 1;
587 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
591 /*****************************************************************************
592 * InterfaceWindow::_SetMenusEnabled
593 *****************************************************************************/
595 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
604 if (fNextChapterMI->IsEnabled() != hasChapters)
605 fNextChapterMI->SetEnabled(hasChapters);
606 if (fPrevChapterMI->IsEnabled() != hasChapters)
607 fPrevChapterMI->SetEnabled(hasChapters);
608 if (fChapterMenu->IsEnabled() != hasChapters)
609 fChapterMenu->SetEnabled(hasChapters);
610 if (fNextTitleMI->IsEnabled() != hasTitles)
611 fNextTitleMI->SetEnabled(hasTitles);
612 if (fPrevTitleMI->IsEnabled() != hasTitles)
613 fPrevTitleMI->SetEnabled(hasTitles);
614 if (fTitleMenu->IsEnabled() != hasTitles)
615 fTitleMenu->SetEnabled(hasTitles);
616 if (fAudioMenu->IsEnabled() != hasFile)
617 fAudioMenu->SetEnabled(hasFile);
618 if (fNavigationMenu->IsEnabled() != hasFile)
619 fNavigationMenu->SetEnabled(hasFile);
620 if (fLanguageMenu->IsEnabled() != hasFile)
621 fLanguageMenu->SetEnabled(hasFile);
622 if (fSubtitlesMenu->IsEnabled() != hasFile)
623 fSubtitlesMenu->SetEnabled(hasFile);
624 if (fSpeedMenu->IsEnabled() != hasFile)
625 fSpeedMenu->SetEnabled(hasFile);
630 /*****************************************************************************
631 * InterfaceWindow::_UpdateSpeedMenu
632 *****************************************************************************/
634 InterfaceWindow::_UpdateSpeedMenu( int rate )
636 if ( rate == DEFAULT_RATE )
638 if ( !fNormalMI->IsMarked() )
639 fNormalMI->SetMarked( true );
641 else if ( rate < DEFAULT_RATE )
643 if ( !fFasterMI->IsMarked() )
644 fFasterMI->SetMarked( true );
648 if ( !fSlowerMI->IsMarked() )
649 fSlowerMI->SetMarked( true );
653 /*****************************************************************************
654 * InterfaceWindow::_InputStreamChanged
655 *****************************************************************************/
657 InterfaceWindow::_InputStreamChanged()
659 //printf("InterfaceWindow::_InputStreamChanged()\n");
660 // TODO: move more stuff from updateInterface() here!
662 p_vlc_wrapper->set_volume( p_mediaControl->GetVolume() );
665 /*****************************************************************************
666 * InterfaceWindow::_LoadSettings
667 *****************************************************************************/
669 InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
671 status_t ret = B_BAD_VALUE;
675 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
677 // passing folder is optional
679 ret = path.Append( folder );
680 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
682 BFile file( path.Path(), B_READ_ONLY );
683 if ( ( ret = file.InitCheck() ) == B_OK )
685 ret = message->Unflatten( &file );
694 /*****************************************************************************
695 * InterfaceWindow::_SaveSettings
696 *****************************************************************************/
698 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
700 status_t ret = B_BAD_VALUE;
704 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
706 // passing folder is optional
707 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
708 ret = create_directory( path.Path(), 0777 );
709 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
711 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
712 if ( ( ret = file.InitCheck() ) == B_OK )
714 ret = message->Flatten( &file );
723 /*****************************************************************************
724 * InterfaceWindow::_RestoreSettings
725 *****************************************************************************/
727 make_sure_frame_is_on_screen( BRect& frame )
729 BScreen screen( B_MAIN_SCREEN_ID );
730 if (frame.IsValid() && screen.IsValid()) {
731 if (!screen.Frame().Contains(frame)) {
732 // make sure frame fits in the screen
733 if (frame.Width() > screen.Frame().Width())
734 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
735 if (frame.Height() > screen.Frame().Height())
736 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
737 // frame is now at the most the size of the screen
738 if (frame.right > screen.Frame().right)
739 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
740 if (frame.bottom > screen.Frame().bottom)
741 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
742 if (frame.left < screen.Frame().left)
743 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
744 if (frame.top < screen.Frame().top)
745 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
753 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
754 float maxWidth, float maxHeight )
756 if ( frame.Width() < minWidth )
757 frame.right = frame.left + minWidth;
758 if ( frame.Height() < minHeight )
759 frame.bottom = frame.top + minHeight;
760 if ( frame.Width() > maxWidth )
761 frame.right = frame.left + maxWidth;
762 if ( frame.Height() > maxHeight )
763 frame.bottom = frame.top + maxHeight;
766 /*****************************************************************************
767 * InterfaceWindow::_RestoreSettings
768 *****************************************************************************/
770 InterfaceWindow::_RestoreSettings()
772 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
775 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
777 // sanity checks: make sure window is not too big/small
778 // and that it's not off-screen
779 float minWidth, maxWidth, minHeight, maxHeight;
780 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
782 make_sure_frame_is_within_limits( mainFrame,
783 minWidth, minHeight, maxWidth, maxHeight );
784 make_sure_frame_is_on_screen( mainFrame );
787 MoveTo( mainFrame.LeftTop() );
788 ResizeTo( mainFrame.Width(), mainFrame.Height() );
790 if ( fPlaylistWindow->Lock() )
793 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
795 // sanity checks: make sure window is not too big/small
796 // and that it's not off-screen
797 float minWidth, maxWidth, minHeight, maxHeight;
798 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
800 make_sure_frame_is_within_limits( playlistFrame,
801 minWidth, minHeight, maxWidth, maxHeight );
802 make_sure_frame_is_on_screen( playlistFrame );
804 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
805 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
809 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
813 if ( fPlaylistWindow->IsHidden() )
814 fPlaylistWindow->Show();
818 if ( !fPlaylistWindow->IsHidden() )
819 fPlaylistWindow->Hide();
823 fPlaylistWindow->Unlock();
828 /*****************************************************************************
829 * InterfaceWindow::_StoreSettings
830 *****************************************************************************/
832 InterfaceWindow::_StoreSettings()
834 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
835 fSettings->AddRect( "main frame", Frame() );
836 if ( fPlaylistWindow->Lock() )
838 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
839 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
840 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
841 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
842 fPlaylistWindow->Unlock();
844 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
847 /*****************************************************************************
849 *****************************************************************************/
850 CDMenu::CDMenu(const char *name)
855 /*****************************************************************************
857 *****************************************************************************/
862 /*****************************************************************************
863 * CDMenu::AttachedToWindow
864 *****************************************************************************/
865 void CDMenu::AttachedToWindow(void)
868 while (BMenuItem* item = RemoveItem(0L))
871 BMenu::AttachedToWindow();
874 /*****************************************************************************
876 *****************************************************************************/
877 int CDMenu::GetCD( const char *directory )
879 BVolumeRoster *volRoster;
884 char name[B_FILE_NAME_LENGTH];
888 volRoster = new BVolumeRoster();
890 dir = new BDirectory();
891 status = volRoster->GetNextVolume(vol);
892 status = vol->GetRootDirectory(dir);
893 while (status == B_NO_ERROR)
895 mounted = vol->GetName(name);
896 if ((mounted == B_OK) && /* Disk is currently Mounted */
897 (vol->IsReadOnly()) ) /* Disk is read-only */
900 fs_stat_dev(dev, &info);
904 i_dev = open( info.device_name, O_RDONLY );
908 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
910 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
913 msg = new BMessage( OPEN_DVD );
914 msg->AddString( "device", info.device_name );
915 BMenuItem *menu_item;
916 menu_item = new BMenuItem( name, msg );
917 AddItem( menu_item );
924 status = volRoster->GetNextVolume(vol);
929 /*****************************************************************************
930 * LanguageMenu::LanguageMenu
931 *****************************************************************************/
932 LanguageMenu::LanguageMenu(const char *name, int menu_kind,
933 intf_thread_t *p_interface)
937 p_intf = p_interface;
940 /*****************************************************************************
941 * LanguageMenu::~LanguageMenu
942 *****************************************************************************/
943 LanguageMenu::~LanguageMenu()
947 /*****************************************************************************
948 * LanguageMenu::AttachedToWindow
949 *****************************************************************************/
950 void LanguageMenu::AttachedToWindow()
953 while ( BMenuItem* item = RemoveItem( 0L ) )
956 SetRadioMode( true );
958 BMenu::AttachedToWindow();
961 /*****************************************************************************
962 * LanguageMenu::_GetChannels
963 *****************************************************************************/
964 void LanguageMenu::_GetChannels()
969 BMenuItem *menu_item;
971 es_descriptor_t *p_es = NULL;
973 // Insert the "None" item if in subtitle mode
974 if( kind != AUDIO_ES ) //subtitle
976 msg = new BMessage( SELECT_SUBTITLE );
977 msg->AddInt32( "subtitle", -1 );
978 menu_item = new BMenuItem( "None", msg );
979 AddItem( menu_item );
980 menu_item->SetMarked( true );
983 input_thread_t* input = p_intf->p_sys->p_input;
986 vlc_mutex_lock( &input->stream.stream_lock );
987 for( i = 0; i < input->stream.i_selected_es_number; i++ )
989 if( kind == input->stream.pp_selected_es[i]->i_cat )
990 p_es = input->stream.pp_selected_es[i];
993 int32 addedItems = 0;
994 bool emptyItemAdded = false;
995 uint32 what = kind == AUDIO_ES ? SELECT_CHANNEL : SELECT_SUBTITLE;
996 const char* fieldName = kind == AUDIO_ES ? "channel" : "subtitle";
998 for ( i = 0; i < input->stream.i_es_number; i++ )
1000 if ( kind == input->stream.pp_es[i]->i_cat )
1002 bool addItem = true;
1003 psz_name = input->stream.pp_es[i]->psz_desc;
1004 // workarround for irritating empty strings
1005 if ( strcmp(psz_name, "") == 0 )
1007 // if ( kind != AUDIO_ES ) // don't add empty subtitle items, they don't work anyways
1011 if (!emptyItemAdded)
1013 psz_name = "<default>";
1014 emptyItemAdded = true;
1017 psz_name = "<unkown>";
1023 msg = new BMessage( what );
1024 msg->AddInt32( fieldName, i );
1025 menu_item = new BMenuItem( psz_name, msg );
1026 AddItem( menu_item );
1027 b_active = ( p_es == input->stream.pp_es[i] );
1028 menu_item->SetMarked( b_active );
1032 vlc_mutex_unlock( &input->stream.stream_lock );
1034 // enhance readability and separate first item from rest
1035 if ( ( emptyItemAdded || kind != AUDIO_ES ) && addedItems > 1 )
1036 AddItem( new BSeparatorItem(), 1 );
1042 /*****************************************************************************
1043 * TitleMenu::TitleMenu
1044 *****************************************************************************/
1045 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1047 p_intf( p_interface )
1051 /*****************************************************************************
1052 * TitleMenu::~TitleMenu
1053 *****************************************************************************/
1054 TitleMenu::~TitleMenu()
1058 /*****************************************************************************
1059 * TitleMenu::AttachedToWindow
1060 *****************************************************************************/
1061 void TitleMenu::AttachedToWindow()
1063 // make title menu empty
1064 while ( BMenuItem* item = RemoveItem( 0L ) )
1067 input_thread_t* input = p_intf->p_sys->p_input;
1070 // lock stream access
1071 vlc_mutex_lock( &input->stream.stream_lock );
1072 // populate menu according to current stream
1073 int32 numTitles = input->stream.i_area_nb;
1074 if ( numTitles > 1 )
1076 // disallow title 0!
1077 for ( int32 i = 1; i < numTitles; i++ )
1079 BMessage* message = new BMessage( TOGGLE_TITLE );
1080 message->AddInt32( "index", i );
1081 BString helper( "" );
1083 BMenuItem* item = new BMenuItem( helper.String(), message );
1084 item->SetMarked( input->stream.p_selected_area->i_id == i );
1088 // done messing with stream
1089 vlc_mutex_unlock( &input->stream.stream_lock );
1091 BMenu::AttachedToWindow();
1095 /*****************************************************************************
1096 * ChapterMenu::ChapterMenu
1097 *****************************************************************************/
1098 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1100 p_intf( p_interface )
1104 /*****************************************************************************
1105 * ChapterMenu::~ChapterMenu
1106 *****************************************************************************/
1107 ChapterMenu::~ChapterMenu()
1111 /*****************************************************************************
1112 * ChapterMenu::AttachedToWindow
1113 *****************************************************************************/
1114 void ChapterMenu::AttachedToWindow()
1116 // make title menu empty
1117 while ( BMenuItem* item = RemoveItem( 0L ) )
1120 input_thread_t* input = p_intf->p_sys->p_input;
1123 // lock stream access
1124 vlc_mutex_lock( &input->stream.stream_lock );
1125 // populate menu according to current stream
1126 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1127 if ( numChapters > 1 )
1129 for ( int32 i = 0; i < numChapters; i++ )
1131 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1132 message->AddInt32( "index", i );
1133 BString helper( "" );
1135 BMenuItem* item = new BMenuItem( helper.String(), message );
1136 item->SetMarked( input->stream.p_selected_area->i_part == i );
1140 // done messing with stream
1141 vlc_mutex_unlock( &input->stream.stream_lock );
1143 BMenu::AttachedToWindow();