1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.11 2002/12/04 02:16:23 titer Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tony@castley.net>
10 * Richard Shepherd <richard@rshepherd.demon.co.uk>
11 * Stephan Aßmus <stippi@yellowbites.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
29 #include <kernel/OS.h>
30 #include <InterfaceKit.h>
32 #include <StorageKit.h>
33 #include <SupportKit.h>
36 #include <scsiprobe_driver.h>
45 /* BeOS interface headers */
46 #include "VlcWrapper.h"
48 #include "MediaControlView.h"
49 #include "PlayListWindow.h"
50 #include "PreferencesWindow.h"
51 #include "InterfaceWindow.h"
53 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
56 /*****************************************************************************
58 *****************************************************************************/
60 InterfaceWindow::InterfaceWindow( BRect frame, const char *name,
61 intf_thread_t *p_interface )
62 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
63 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
64 p_intf( p_interface ),
66 fLastUpdateTime( system_time() ),
67 fSettings( new BMessage( 'sett' ) )
70 p_wrapper = p_intf->p_sys->p_wrapper;
72 fPlaylistIsEmpty = ( p_wrapper->PlaylistSize() < 0 );
74 fPlaylistWindow = new PlayListWindow( BRect( 100.0, 100.0, 400.0, 350.0 ),
78 BScreen *p_screen = new BScreen();
79 BRect screen_rect = p_screen->Frame();
82 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
83 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
84 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
85 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
86 fPreferencesWindow = new PreferencesWindow( window_rect,
91 SetName( "interface" );
92 SetTitle( VOUT_TITLE );
94 // the media control view
95 p_mediaControl = new MediaControlView( BRect( 0.0, 0.0, 250.0, 50.0 ),
97 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
98 p_mediaControl->SetEnabled( !fPlaylistIsEmpty );
101 p_mediaControl->GetPreferredSize( &width, &height );
103 // set up the main menu
104 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
105 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
107 // make menu bar resize to correct height
108 float menuWidth, menuHeight;
109 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
110 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
111 // take care of proper size for ourself
112 height += fMenuBar->Bounds().Height();
113 ResizeTo( width, height );
115 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
116 AddChild( fMenuBar );
117 AddChild( p_mediaControl );
120 BMenu* fileMenu = new BMenu( "File" );
121 fMenuBar->AddItem( fileMenu );
122 fileMenu->AddItem( new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
123 new BMessage( OPEN_FILE ), 'O') );
125 fileMenu->AddItem( new CDMenu( "Open Disc" ) );
127 fileMenu->AddSeparatorItem();
128 fileMenu->AddItem( new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
129 new BMessage( OPEN_PLAYLIST ), 'P') );
131 fileMenu->AddSeparatorItem();
132 BMenuItem* item = new BMenuItem( "About" B_UTF8_ELLIPSIS,
133 new BMessage( B_ABOUT_REQUESTED ), 'A');
134 item->SetTarget( be_app );
135 fileMenu->AddItem( item );
136 fileMenu->AddItem( new BMenuItem( "Quit", new BMessage( B_QUIT_REQUESTED ), 'Q') );
138 fLanguageMenu = new LanguageMenu("Language", AUDIO_ES, p_intf);
139 fSubtitlesMenu = new LanguageMenu("Subtitles", SPU_ES, p_intf);
141 /* Add the Audio menu */
142 fAudioMenu = new BMenu( "Audio" );
143 fMenuBar->AddItem ( fAudioMenu );
144 fAudioMenu->AddItem( fLanguageMenu );
145 fAudioMenu->AddItem( fSubtitlesMenu );
147 fPrevTitleMI = new BMenuItem( "Prev Title", new BMessage( PREV_TITLE ) );
148 fNextTitleMI = new BMenuItem( "Next Title", new BMessage( NEXT_TITLE ) );
149 fPrevChapterMI = new BMenuItem( "Prev Chapter", new BMessage( PREV_CHAPTER ) );
150 fNextChapterMI = new BMenuItem( "Next Chapter", new BMessage( NEXT_CHAPTER ) );
152 /* Add the Navigation menu */
153 fNavigationMenu = new BMenu( "Navigation" );
154 fMenuBar->AddItem( fNavigationMenu );
155 fNavigationMenu->AddItem( fPrevTitleMI );
156 fNavigationMenu->AddItem( fNextTitleMI );
157 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( "Go to Title", p_intf ) );
158 fNavigationMenu->AddSeparatorItem();
159 fNavigationMenu->AddItem( fPrevChapterMI );
160 fNavigationMenu->AddItem( fNextChapterMI );
161 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( "Go to Chapter", p_intf ) );
163 /* Add the Speed menu */
164 fSpeedMenu = new BMenu( "Speed" );
165 fSpeedMenu->SetRadioMode( true );
166 fSpeedMenu->AddItem( fSlowerMI = new BMenuItem( "Slower", new BMessage( SLOWER_PLAY ) ) );
167 fNormalMI = new BMenuItem( "Normal", new BMessage( NORMAL_PLAY ) );
168 fNormalMI->SetMarked(true); // default to normal speed
169 fSpeedMenu->AddItem( fNormalMI );
170 fSpeedMenu->AddItem( fFasterMI = new BMenuItem( "Faster", new BMessage( FASTER_PLAY) ) );
171 fSpeedMenu->SetTargetForItems( this );
172 fMenuBar->AddItem( fSpeedMenu );
174 /* Add the Settings menu */
175 fSettingsMenu = new BMenu( "Settings" );
176 fSettingsMenu->AddItem( fPreferencesMI =
177 new BMenuItem( "Preferences", new BMessage( OPEN_PREFERENCES ) ) );
178 fMenuBar->AddItem( fSettingsMenu );
180 // prepare fow showing
181 _SetMenusEnabled(false);
188 InterfaceWindow::~InterfaceWindow()
191 fPlaylistWindow->ReallyQuit();
195 /*****************************************************************************
196 * InterfaceWindow::FrameResized
197 *****************************************************************************/
199 InterfaceWindow::FrameResized(float width, float height)
202 fMenuBar->MoveTo(r.LeftTop());
203 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
204 r.top += fMenuBar->Bounds().Height() + 1.0;
205 p_mediaControl->MoveTo(r.LeftTop());
206 p_mediaControl->ResizeTo(r.Width(), r.Height());
209 /*****************************************************************************
210 * InterfaceWindow::MessageReceived
211 *****************************************************************************/
212 void InterfaceWindow::MessageReceived( BMessage * p_message )
214 int playback_status; // remember playback state
215 playback_status = p_wrapper->InputStatus();
217 switch( p_message->what )
219 case B_ABOUT_REQUESTED:
221 BAlert* alert = new BAlert( VOUT_TITLE,
222 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
235 fFilePanel = new BFilePanel();
236 fFilePanel->SetTarget( this );
241 if (fPlaylistWindow->Lock())
243 if (fPlaylistWindow->IsHidden())
244 fPlaylistWindow->Show();
246 fPlaylistWindow->Activate();
247 fPlaylistWindow->Unlock();
252 const char *psz_device;
253 BString type( "dvd" );
254 if( p_message->FindString( "device", &psz_device ) == B_OK )
256 BString device( psz_device );
257 p_wrapper->openDisc( type, device, 0, 0 );
264 // this currently stops playback not nicely
265 if (playback_status > UNDEF_S)
267 p_wrapper->volume_mute();
269 p_wrapper->PlaylistStop();
270 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
275 /* starts playing in normal mode */
278 /* toggle between pause and play */
279 if (playback_status > UNDEF_S)
281 /* pause if currently playing */
282 if ( playback_status == PLAYING_S )
284 p_wrapper->volume_mute();
286 p_wrapper->PlaylistPause();
290 p_wrapper->volume_restore();
291 p_wrapper->PlaylistPlay();
296 /* Play a new file */
297 p_wrapper->PlaylistPlay();
302 /* cycle the fast playback modes */
303 if (playback_status > UNDEF_S)
305 p_wrapper->volume_mute();
307 p_wrapper->InputFaster();
312 /* cycle the slow playback modes */
313 if (playback_status > UNDEF_S)
315 p_wrapper->volume_mute();
317 p_wrapper->InputSlower();
322 /* restore speed to normal if already playing */
323 if (playback_status > UNDEF_S)
325 p_wrapper->volume_restore();
326 p_wrapper->PlaylistPlay();
331 /* handled by semaphores */
333 // volume related messages
335 /* adjust the volume */
336 if (playback_status > UNDEF_S)
338 p_wrapper->set_volume( p_mediaControl->GetVolume() );
339 p_mediaControl->SetMuted( p_wrapper->is_muted() );
345 p_wrapper->toggle_mute();
346 p_mediaControl->SetMuted( p_wrapper->is_muted() );
350 if ( playback_status > UNDEF_S )
353 if ( p_message->FindInt32( "channel", &channel ) == B_OK )
355 p_wrapper->toggleLanguage( channel );
356 // vlc seems to remember the volume for every channel,
357 // but I would assume that to be somewhat annoying to the user
358 // the next call will also unmute the volume, which is probably
359 // desired as well, because if the user selects another language,
360 // he probably wants to hear the change as well
361 snooze( 400000 ); // we have to wait a bit, or the change will be reverted
362 p_wrapper->set_volume( p_mediaControl->GetVolume() );
367 case SELECT_SUBTITLE:
368 if ( playback_status > UNDEF_S )
371 if ( p_message->FindInt32( "subtitle", &subtitle ) == B_OK )
372 p_wrapper->toggleSubtitle( subtitle );
376 // specific navigation messages
379 p_wrapper->PrevTitle();
384 p_wrapper->NextTitle();
388 if ( playback_status > UNDEF_S )
391 if ( p_message->FindInt32( "index", &index ) == B_OK )
392 p_wrapper->toggleTitle( index );
397 p_wrapper->PrevChapter();
402 p_wrapper->NextChapter();
406 if ( playback_status > UNDEF_S )
409 if ( p_message->FindInt32( "index", &index ) == B_OK )
410 p_wrapper->toggleChapter( index );
414 p_wrapper->PlaylistPrev();
417 p_wrapper->PlaylistNext();
419 // general next/prev functionality (skips to whatever makes most sense)
421 p_wrapper->navigatePrev();
424 p_wrapper->navigateNext();
426 // drag'n'drop and system messages
427 case B_REFS_RECEIVED:
430 // figure out if user wants files replaced or added
431 bool replace = false;
432 if ( p_message->WasDropped() )
433 replace = !( modifiers() & B_SHIFT_KEY );
434 // build list of files to be played from message contents
437 for ( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
440 if ( path.InitCheck() == B_OK )
441 // the BString objects will be deleted
442 // by the wrapper function further down
443 files.AddItem( new BString( (char*)path.Path() ) );
445 // give the list to VLC
446 p_wrapper->openFiles(&files, replace);
451 case OPEN_PREFERENCES:
452 if( fPreferencesWindow->Lock() )
454 if (fPreferencesWindow->IsHidden())
455 fPreferencesWindow->Show();
457 fPreferencesWindow->Activate();
458 fPreferencesWindow->Unlock();
463 BWindow::MessageReceived( p_message );
469 /*****************************************************************************
470 * InterfaceWindow::QuitRequested
471 *****************************************************************************/
472 bool InterfaceWindow::QuitRequested()
474 p_wrapper->PlaylistStop();
475 p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
484 /*****************************************************************************
485 * InterfaceWindow::updateInterface
486 *****************************************************************************/
487 void InterfaceWindow::updateInterface()
489 if( /* has_input */ true )
491 if ( acquire_sem( p_mediaControl->fScrubSem ) == B_OK )
493 p_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
497 bool hasTitles = p_wrapper->HasTitles();
498 bool hasChapters = p_wrapper->HasChapters();
499 p_mediaControl->SetStatus( p_wrapper->InputStatus(),
500 p_wrapper->InputRate() );
501 p_mediaControl->SetProgress( p_wrapper->InputTell(),
502 p_wrapper->InputSize() );
503 _SetMenusEnabled( true, hasChapters, hasTitles );
505 _UpdateSpeedMenu( p_wrapper->InputRate() );
507 // enable/disable skip buttons
510 p_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
511 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
513 if ( p_wrapper->has_audio() )
515 p_mediaControl->SetAudioEnabled( true );
516 p_mediaControl->SetMuted( p_wrapper->is_muted() );
518 p_mediaControl->SetAudioEnabled( false );
522 // update playlist as well
523 if ( fPlaylistWindow->Lock() )
525 fPlaylistWindow->UpdatePlaylist();
526 fPlaylistWindow->Unlock();
531 _SetMenusEnabled(false);
535 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
539 fLastUpdateTime = system_time();
542 /*****************************************************************************
543 * InterfaceWindow::IsStopped
544 *****************************************************************************/
546 InterfaceWindow::IsStopped() const
548 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
551 /*****************************************************************************
552 * InterfaceWindow::_UpdatePlaylist
553 *****************************************************************************/
555 InterfaceWindow::_UpdatePlaylist()
557 if ( fPlaylistWindow->Lock() )
559 fPlaylistWindow->UpdatePlaylist( true );
560 fPlaylistWindow->Unlock();
561 p_mediaControl->SetEnabled( p_wrapper->PlaylistSize() );
565 /*****************************************************************************
566 * InterfaceWindow::_SetMenusEnabled
567 *****************************************************************************/
569 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
578 if (fNextChapterMI->IsEnabled() != hasChapters)
579 fNextChapterMI->SetEnabled(hasChapters);
580 if (fPrevChapterMI->IsEnabled() != hasChapters)
581 fPrevChapterMI->SetEnabled(hasChapters);
582 if (fChapterMenu->IsEnabled() != hasChapters)
583 fChapterMenu->SetEnabled(hasChapters);
584 if (fNextTitleMI->IsEnabled() != hasTitles)
585 fNextTitleMI->SetEnabled(hasTitles);
586 if (fPrevTitleMI->IsEnabled() != hasTitles)
587 fPrevTitleMI->SetEnabled(hasTitles);
588 if (fTitleMenu->IsEnabled() != hasTitles)
589 fTitleMenu->SetEnabled(hasTitles);
590 if (fAudioMenu->IsEnabled() != hasFile)
591 fAudioMenu->SetEnabled(hasFile);
592 if (fNavigationMenu->IsEnabled() != hasFile)
593 fNavigationMenu->SetEnabled(hasFile);
594 if (fLanguageMenu->IsEnabled() != hasFile)
595 fLanguageMenu->SetEnabled(hasFile);
596 if (fSubtitlesMenu->IsEnabled() != hasFile)
597 fSubtitlesMenu->SetEnabled(hasFile);
598 if (fSpeedMenu->IsEnabled() != hasFile)
599 fSpeedMenu->SetEnabled(hasFile);
604 /*****************************************************************************
605 * InterfaceWindow::_UpdateSpeedMenu
606 *****************************************************************************/
608 InterfaceWindow::_UpdateSpeedMenu( int rate )
610 if ( rate == DEFAULT_RATE )
612 if ( !fNormalMI->IsMarked() )
613 fNormalMI->SetMarked( true );
615 else if ( rate < DEFAULT_RATE )
617 if ( !fFasterMI->IsMarked() )
618 fFasterMI->SetMarked( true );
622 if ( !fSlowerMI->IsMarked() )
623 fSlowerMI->SetMarked( true );
627 /*****************************************************************************
628 * InterfaceWindow::_InputStreamChanged
629 *****************************************************************************/
631 InterfaceWindow::_InputStreamChanged()
633 //printf("InterfaceWindow::_InputStreamChanged()\n");
634 // TODO: move more stuff from updateInterface() here!
636 p_wrapper->set_volume( p_mediaControl->GetVolume() );
639 /*****************************************************************************
640 * InterfaceWindow::_LoadSettings
641 *****************************************************************************/
643 InterfaceWindow::_LoadSettings( BMessage* message, const char* fileName, const char* folder )
645 status_t ret = B_BAD_VALUE;
649 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
651 // passing folder is optional
653 ret = path.Append( folder );
654 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
656 BFile file( path.Path(), B_READ_ONLY );
657 if ( ( ret = file.InitCheck() ) == B_OK )
659 ret = message->Unflatten( &file );
668 /*****************************************************************************
669 * InterfaceWindow::_SaveSettings
670 *****************************************************************************/
672 InterfaceWindow::_SaveSettings( BMessage* message, const char* fileName, const char* folder )
674 status_t ret = B_BAD_VALUE;
678 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
680 // passing folder is optional
681 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
682 ret = create_directory( path.Path(), 0777 );
683 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
685 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
686 if ( ( ret = file.InitCheck() ) == B_OK )
688 ret = message->Flatten( &file );
697 /*****************************************************************************
698 * InterfaceWindow::_RestoreSettings
699 *****************************************************************************/
701 make_sure_frame_is_on_screen( BRect& frame )
703 BScreen screen( B_MAIN_SCREEN_ID );
704 if (frame.IsValid() && screen.IsValid()) {
705 if (!screen.Frame().Contains(frame)) {
706 // make sure frame fits in the screen
707 if (frame.Width() > screen.Frame().Width())
708 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
709 if (frame.Height() > screen.Frame().Height())
710 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
711 // frame is now at the most the size of the screen
712 if (frame.right > screen.Frame().right)
713 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
714 if (frame.bottom > screen.Frame().bottom)
715 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
716 if (frame.left < screen.Frame().left)
717 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
718 if (frame.top < screen.Frame().top)
719 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
727 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
728 float maxWidth, float maxHeight )
730 if ( frame.Width() < minWidth )
731 frame.right = frame.left + minWidth;
732 if ( frame.Height() < minHeight )
733 frame.bottom = frame.top + minHeight;
734 if ( frame.Width() > maxWidth )
735 frame.right = frame.left + maxWidth;
736 if ( frame.Height() > maxHeight )
737 frame.bottom = frame.top + maxHeight;
740 /*****************************************************************************
741 * InterfaceWindow::_RestoreSettings
742 *****************************************************************************/
744 InterfaceWindow::_RestoreSettings()
746 if ( _LoadSettings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
749 if ( fSettings->FindRect( "main frame", &mainFrame ) == B_OK )
751 // sanity checks: make sure window is not too big/small
752 // and that it's not off-screen
753 float minWidth, maxWidth, minHeight, maxHeight;
754 GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
756 make_sure_frame_is_within_limits( mainFrame,
757 minWidth, minHeight, maxWidth, maxHeight );
758 make_sure_frame_is_on_screen( mainFrame );
761 MoveTo( mainFrame.LeftTop() );
762 ResizeTo( mainFrame.Width(), mainFrame.Height() );
764 if ( fPlaylistWindow->Lock() )
767 if (fSettings->FindRect( "playlist frame", &playlistFrame ) == B_OK )
769 // sanity checks: make sure window is not too big/small
770 // and that it's not off-screen
771 float minWidth, maxWidth, minHeight, maxHeight;
772 fPlaylistWindow->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
774 make_sure_frame_is_within_limits( playlistFrame,
775 minWidth, minHeight, maxWidth, maxHeight );
776 make_sure_frame_is_on_screen( playlistFrame );
778 fPlaylistWindow->MoveTo( playlistFrame.LeftTop() );
779 fPlaylistWindow->ResizeTo( playlistFrame.Width(), playlistFrame.Height() );
783 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
787 if ( fPlaylistWindow->IsHidden() )
788 fPlaylistWindow->Show();
792 if ( !fPlaylistWindow->IsHidden() )
793 fPlaylistWindow->Hide();
797 fPlaylistWindow->Unlock();
802 /*****************************************************************************
803 * InterfaceWindow::_StoreSettings
804 *****************************************************************************/
806 InterfaceWindow::_StoreSettings()
808 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
809 fSettings->AddRect( "main frame", Frame() );
810 if ( fPlaylistWindow->Lock() )
812 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
813 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
814 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
815 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
816 fPlaylistWindow->Unlock();
818 _SaveSettings( fSettings, "interface_settings", "VideoLAN Client" );
821 /*****************************************************************************
823 *****************************************************************************/
824 CDMenu::CDMenu(const char *name)
829 /*****************************************************************************
831 *****************************************************************************/
836 /*****************************************************************************
837 * CDMenu::AttachedToWindow
838 *****************************************************************************/
839 void CDMenu::AttachedToWindow(void)
842 while (BMenuItem* item = RemoveItem(0L))
845 BMenu::AttachedToWindow();
848 /*****************************************************************************
850 *****************************************************************************/
851 int CDMenu::GetCD( const char *directory )
853 BVolumeRoster *volRoster;
858 char name[B_FILE_NAME_LENGTH];
862 volRoster = new BVolumeRoster();
864 dir = new BDirectory();
865 status = volRoster->GetNextVolume(vol);
866 status = vol->GetRootDirectory(dir);
867 while (status == B_NO_ERROR)
869 mounted = vol->GetName(name);
870 if ((mounted == B_OK) && /* Disk is currently Mounted */
871 (vol->IsReadOnly()) ) /* Disk is read-only */
874 fs_stat_dev(dev, &info);
878 i_dev = open( info.device_name, O_RDONLY );
882 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
884 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
887 msg = new BMessage( OPEN_DVD );
888 msg->AddString( "device", info.device_name );
889 BMenuItem *menu_item;
890 menu_item = new BMenuItem( name, msg );
891 AddItem( menu_item );
898 status = volRoster->GetNextVolume(vol);
903 /*****************************************************************************
904 * LanguageMenu::LanguageMenu
905 *****************************************************************************/
906 LanguageMenu::LanguageMenu(const char *name, int menu_kind,
907 intf_thread_t *p_interface)
911 p_intf = p_interface;
914 /*****************************************************************************
915 * LanguageMenu::~LanguageMenu
916 *****************************************************************************/
917 LanguageMenu::~LanguageMenu()
921 /*****************************************************************************
922 * LanguageMenu::AttachedToWindow
923 *****************************************************************************/
924 void LanguageMenu::AttachedToWindow()
927 while ( BMenuItem* item = RemoveItem( 0L ) )
930 SetRadioMode( true );
932 BMenu::AttachedToWindow();
935 /*****************************************************************************
936 * LanguageMenu::_GetChannels
937 *****************************************************************************/
938 void LanguageMenu::_GetChannels()
940 #if 0 // must be ported to 0.5.0
944 BMenuItem *menu_item;
946 es_descriptor_t *p_es = NULL;
948 // Insert the "None" item if in subtitle mode
949 if( kind != AUDIO_ES ) //subtitle
951 msg = new BMessage( SELECT_SUBTITLE );
952 msg->AddInt32( "subtitle", -1 );
953 menu_item = new BMenuItem( "None", msg );
954 AddItem( menu_item );
955 menu_item->SetMarked( true );
958 input_thread_t* input = p_intf->p_sys->p_input;
961 vlc_mutex_lock( &input->stream.stream_lock );
962 for( i = 0; i < input->stream.i_selected_es_number; i++ )
964 if( kind == input->stream.pp_selected_es[i]->i_cat )
965 p_es = input->stream.pp_selected_es[i];
968 int32 addedItems = 0;
969 bool emptyItemAdded = false;
970 uint32 what = kind == AUDIO_ES ? SELECT_CHANNEL : SELECT_SUBTITLE;
971 const char* fieldName = kind == AUDIO_ES ? "channel" : "subtitle";
973 for ( i = 0; i < input->stream.i_es_number; i++ )
975 if ( kind == input->stream.pp_es[i]->i_cat )
978 psz_name = input->stream.pp_es[i]->psz_desc;
979 // workarround for irritating empty strings
980 if ( strcmp(psz_name, "") == 0 )
982 // if ( kind != AUDIO_ES ) // don't add empty subtitle items, they don't work anyways
988 psz_name = "<default>";
989 emptyItemAdded = true;
992 psz_name = "<unkown>";
998 msg = new BMessage( what );
999 msg->AddInt32( fieldName, i );
1000 menu_item = new BMenuItem( psz_name, msg );
1001 AddItem( menu_item );
1002 b_active = ( p_es == input->stream.pp_es[i] );
1003 menu_item->SetMarked( b_active );
1007 vlc_mutex_unlock( &input->stream.stream_lock );
1009 // enhance readability and separate first item from rest
1010 if ( ( emptyItemAdded || kind != AUDIO_ES ) && addedItems > 1 )
1011 AddItem( new BSeparatorItem(), 1 );
1018 /*****************************************************************************
1019 * TitleMenu::TitleMenu
1020 *****************************************************************************/
1021 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1023 p_intf( p_interface )
1027 /*****************************************************************************
1028 * TitleMenu::~TitleMenu
1029 *****************************************************************************/
1030 TitleMenu::~TitleMenu()
1034 /*****************************************************************************
1035 * TitleMenu::AttachedToWindow
1036 *****************************************************************************/
1037 void TitleMenu::AttachedToWindow()
1039 // make title menu empty
1040 while ( BMenuItem* item = RemoveItem( 0L ) )
1044 input_thread_t* input = p_intf->p_sys->p_input;
1047 // lock stream access
1048 vlc_mutex_lock( &input->stream.stream_lock );
1049 // populate menu according to current stream
1050 int32 numTitles = input->stream.i_area_nb;
1051 if ( numTitles > 1 )
1053 // disallow title 0!
1054 for ( int32 i = 1; i < numTitles; i++ )
1056 BMessage* message = new BMessage( TOGGLE_TITLE );
1057 message->AddInt32( "index", i );
1058 BString helper( "" );
1060 BMenuItem* item = new BMenuItem( helper.String(), message );
1061 item->SetMarked( input->stream.p_selected_area->i_id == i );
1065 // done messing with stream
1066 vlc_mutex_unlock( &input->stream.stream_lock );
1069 BMenu::AttachedToWindow();
1073 /*****************************************************************************
1074 * ChapterMenu::ChapterMenu
1075 *****************************************************************************/
1076 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1078 p_intf( p_interface )
1082 /*****************************************************************************
1083 * ChapterMenu::~ChapterMenu
1084 *****************************************************************************/
1085 ChapterMenu::~ChapterMenu()
1089 /*****************************************************************************
1090 * ChapterMenu::AttachedToWindow
1091 *****************************************************************************/
1092 void ChapterMenu::AttachedToWindow()
1094 // make title menu empty
1095 while ( BMenuItem* item = RemoveItem( 0L ) )
1099 input_thread_t* input = p_intf->p_sys->p_input;
1102 // lock stream access
1103 vlc_mutex_lock( &input->stream.stream_lock );
1104 // populate menu according to current stream
1105 int32 numChapters = input->stream.p_selected_area->i_part_nb;
1106 if ( numChapters > 1 )
1108 for ( int32 i = 0; i < numChapters; i++ )
1110 BMessage* message = new BMessage( TOGGLE_CHAPTER );
1111 message->AddInt32( "index", i );
1112 BString helper( "" );
1114 BMenuItem* item = new BMenuItem( helper.String(), message );
1115 item->SetMarked( input->stream.p_selected_area->i_part == i );
1119 // done messing with stream
1120 vlc_mutex_unlock( &input->stream.stream_lock );
1122 BMenu::AttachedToWindow();