1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 the VideoLAN team
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tony@castley.net>
10 * Richard Shepherd <richard@rshepherd.demon.co.uk>
11 * Stephan Aßmus <superstippi@gmx.de>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
29 #include <kernel/OS.h>
30 #include <InterfaceKit.h>
32 #include <StorageKit.h>
33 #include <SupportKit.h>
36 #include <scsiprobe_driver.h>
46 #include <vlc_interface.h>
48 /* BeOS interface headers */
50 #include "MediaControlView.h"
51 #include "PlayListWindow.h"
52 #include "PreferencesWindow.h"
53 #include "MessagesWindow.h"
54 #include "InterfaceWindow.h"
56 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
57 #define INTERFACE_LOCKING_TIMEOUT 5000
59 // make_sure_frame_is_on_screen
61 make_sure_frame_is_on_screen( BRect& frame )
63 BScreen screen( B_MAIN_SCREEN_ID );
64 if (frame.IsValid() && screen.IsValid()) {
65 if (!screen.Frame().Contains(frame)) {
66 // make sure frame fits in the screen
67 if (frame.Width() > screen.Frame().Width())
68 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
69 if (frame.Height() > screen.Frame().Height())
70 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
71 // frame is now at the most the size of the screen
72 if (frame.right > screen.Frame().right)
73 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
74 if (frame.bottom > screen.Frame().bottom)
75 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
76 if (frame.left < screen.Frame().left)
77 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
78 if (frame.top < screen.Frame().top)
79 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
86 // make_sure_frame_is_within_limits
88 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
89 float maxWidth, float maxHeight )
91 if ( frame.Width() < minWidth )
92 frame.right = frame.left + minWidth;
93 if ( frame.Height() < minHeight )
94 frame.bottom = frame.top + minHeight;
95 if ( frame.Width() > maxWidth )
96 frame.right = frame.left + maxWidth;
97 if ( frame.Height() > maxHeight )
98 frame.bottom = frame.top + maxHeight;
103 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
105 bool success = false;
109 char name[B_FILE_NAME_LENGTH];
110 if ( volume.GetName( name ) >= B_OK ) // disk is currently mounted
113 dev_t dev = volume.Device();
115 if ( fs_stat_dev( dev, &info ) == B_OK )
118 deviceName = info.device_name;
119 if ( volume.IsReadOnly() )
121 int i_dev = open( info.device_name, O_RDONLY );
125 if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
126 isCDROM = ( g.device_type == B_CD );
135 // collect_folder_contents
137 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
139 while ( dir.GetNextEntry( &entry, true ) == B_OK )
141 if ( !entry.IsDirectory() )
144 // since the directory will give us the entries in reverse order,
145 // we put them each at the same index, effectively reversing the
146 // items while adding them
147 if ( entry.GetPath( &path ) == B_OK )
149 BString* string = new BString( path.Path() );
150 if ( !list.AddItem( string, 0 ) )
151 delete string; // at least don't leak
158 // ask user if we should parse sub-folders as well
159 BAlert* alert = new BAlert( "sub-folders?",
160 _("Open files from all sub-folders as well?"),
161 _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL,
163 int32 buttonIndex = alert->Go();
164 deep = buttonIndex == 1;
166 // never delete BAlerts!!
170 BDirectory subDir( &entry );
171 if ( subDir.InitCheck() == B_OK )
172 collect_folder_contents( subDir, list,
173 deep, asked, entry );
179 static int PlaylistChanged( vlc_object_t *p_this, const char * psz_variable,
180 vlc_value_t old_val, vlc_value_t new_val,
183 InterfaceWindow * w = (InterfaceWindow *) param;
188 /*****************************************************************************
190 *****************************************************************************/
192 InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
194 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
195 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
197 /* Initializations */
203 fLastUpdateTime( system_time() ),
204 fSettings( new BMessage( 'sett' ) )
206 p_playlist = (playlist_t *)
207 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
209 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
210 var_AddCallback( p_playlist, "item-change", PlaylistChanged, this );
211 var_AddCallback( p_playlist, "item-append", PlaylistChanged, this );
212 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, this );
213 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, this );
216 #define ADD_ELLIPSIS( a ) \
217 memset( psz_tmp, 0, 1024 ); \
218 snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );
221 BRect screen_rect = screen.Frame();
223 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
224 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
225 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
226 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
227 fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
228 window_rect.Set( screen_rect.right - 500,
229 screen_rect.top + 50,
230 screen_rect.right - 150,
231 screen_rect.top + 250 );
233 fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
234 window_rect.Set( screen_rect.right - 550,
235 screen_rect.top + 300,
236 screen_rect.right - 150,
237 screen_rect.top + 500 );
239 fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
241 // the media control view
242 p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );
243 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
246 p_mediaControl->GetPreferredSize( &width, &height );
248 // set up the main menu
249 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
250 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
252 // make menu bar resize to correct height
253 float menuWidth, menuHeight;
254 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
255 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
256 // take care of proper size for ourself
257 height += fMenuBar->Bounds().Height();
258 ResizeTo( width, height );
260 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
261 AddChild( fMenuBar );
265 BMenu* fileMenu = new BMenu( _("File") );
266 fMenuBar->AddItem( fileMenu );
267 ADD_ELLIPSIS( _("Open File") );
268 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );
269 fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
270 ADD_ELLIPSIS( _("Open Subtitles") );
271 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );
273 fileMenu->AddSeparatorItem();
274 ADD_ELLIPSIS( _("About") );
275 BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');
276 item->SetTarget( be_app );
277 fileMenu->AddItem( item );
278 fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
280 fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );
281 fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );
283 /* Add the Audio menu */
284 fAudioMenu = new BMenu( _("Audio") );
285 fMenuBar->AddItem ( fAudioMenu );
286 fAudioMenu->AddItem( fLanguageMenu );
287 fAudioMenu->AddItem( fSubtitlesMenu );
289 fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
290 fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
291 fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );
292 fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );
294 /* Add the Navigation menu */
295 fNavigationMenu = new BMenu( _("Navigation") );
296 fMenuBar->AddItem( fNavigationMenu );
297 fNavigationMenu->AddItem( fPrevTitleMI );
298 fNavigationMenu->AddItem( fNextTitleMI );
299 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
300 fNavigationMenu->AddSeparatorItem();
301 fNavigationMenu->AddItem( fPrevChapterMI );
302 fNavigationMenu->AddItem( fNextChapterMI );
303 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
305 /* Add the Speed menu */
306 fSpeedMenu = new BMenu( _("Speed") );
307 fSpeedMenu->SetRadioMode( true );
309 fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
311 fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
313 fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
315 fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
317 fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
319 fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
321 fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
322 fMenuBar->AddItem( fSpeedMenu );
324 /* Add the Show menu */
325 fShowMenu = new BMenu( _("Window") );
327 ADD_ELLIPSIS( _("Playlist") );
328 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );
330 ADD_ELLIPSIS( _("Messages") );
331 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );
332 ADD_ELLIPSIS( _("Preferences") );
333 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );
334 fMenuBar->AddItem( fShowMenu );
336 // add the media control view after the menubar is complete
337 // because it will set the window size limits in AttachedToWindow()
338 // and the menubar needs to report the correct PreferredSize()
339 AddChild( p_mediaControl );
341 /* Prepare fow showing */
342 _SetMenusEnabled( false );
343 p_mediaControl->SetEnabled( false );
350 InterfaceWindow::~InterfaceWindow()
354 vlc_object_release( p_input );
358 vlc_object_release( p_playlist );
361 if( fPlaylistWindow )
363 fPlaylistWindow->ReallyQuit();
366 if( fMessagesWindow )
368 fMessagesWindow->ReallyQuit();
370 if( fPreferencesWindow )
372 fPreferencesWindow->ReallyQuit();
378 /*****************************************************************************
379 * InterfaceWindow::FrameResized
380 *****************************************************************************/
382 InterfaceWindow::FrameResized(float width, float height)
385 fMenuBar->MoveTo(r.LeftTop());
386 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
387 r.top += fMenuBar->Bounds().Height() + 1.0;
388 p_mediaControl->MoveTo(r.LeftTop());
389 p_mediaControl->ResizeTo(r.Width(), r.Height());
392 /*****************************************************************************
393 * InterfaceWindow::MessageReceived
394 *****************************************************************************/
395 void InterfaceWindow::MessageReceived( BMessage * p_message )
397 switch( p_message->what )
399 case B_ABOUT_REQUESTED:
403 alert = new BAlert( "VLC media player" VERSION,
404 "VLC media player" VERSION " (BeOS interface)\n\n"
405 "The VideoLAN team <videolan@videolan.org>\n"
406 "http://www.videolan.org/", _("OK") );
414 _ShowFilePanel( B_REFS_RECEIVED, _("VLC media player: Open Media Files") );
418 _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
422 if (fPlaylistWindow->Lock())
424 if (fPlaylistWindow->IsHidden())
425 fPlaylistWindow->Show();
427 fPlaylistWindow->Activate();
428 fPlaylistWindow->Unlock();
434 const char * psz_device;
436 p_message->FindString( "device", &psz_device ) == B_OK )
439 memset( psz_uri, 0, 1024 );
440 snprintf( psz_uri, 1024, "dvdnav:%s", psz_device );
441 playlist_Add( p_playlist, psz_uri, psz_device,
442 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true );
448 case SUBFILE_RECEIVED:
451 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
454 if ( path.InitCheck() == B_OK )
455 config_PutPsz( p_intf, "sub-file", path.Path() );
463 playlist_Stop( p_playlist );
465 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
472 val.i_int = PLAYING_S;
475 var_Get( p_input, "state", &val );
477 if( p_input && val.i_int != PAUSE_S )
480 var_Set( p_input, "state", val );
484 playlist_Play( p_playlist );
491 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
498 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
505 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
512 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
519 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
526 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
533 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
538 /* handled by semaphores */
542 aout_VolumeSet( p_intf, p_mediaControl->GetVolume() );
546 aout_VolumeMute( p_intf, NULL );
554 if( p_message->FindInt32( "audio-es", &channel ) == B_OK )
556 var_SetInteger( p_input, "audio-es", channel );
558 else if( p_message->FindInt32( "spu-es", &channel ) == B_OK )
560 var_SetInteger( p_input, "spu-es", channel );
569 var_SetVoid( p_input, "prev-title" );
576 var_SetVoid( p_input, "next-title" );
584 p_message->FindInt32( "index", &index ) == B_OK )
586 var_SetInteger( p_input, "title", index );
594 var_SetVoid( p_input, "prev-chapter" );
601 var_SetVoid( p_input, "next-chapter" );
609 p_message->FindInt32( "index", &index ) == B_OK )
611 var_SetInteger( p_input, "chapter", index );
619 playlist_Prev( p_playlist );
626 playlist_Next( p_playlist );
635 /* First try to go to previous chapter */
636 if( !var_Get( p_input, "chapter", &val ) )
640 var_SetVoid( p_input, "prev-chapter" );
645 /* Try to go to previous title */
646 if( !var_Get( p_input, "title", &val ) )
650 var_SetVoid( p_input, "prev-title" );
655 /* Try to go to previous file */
658 playlist_Prev( p_playlist );
666 vlc_value_t val, val_list;
668 /* First try to go to next chapter */
669 if( !var_Get( p_input, "chapter", &val ) )
671 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
673 if( val_list.p_list->i_count > val.i_int )
675 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
677 var_SetVoid( p_input, "next-chapter" );
680 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
684 /* Try to go to next title */
685 if( !var_Get( p_input, "title", &val ) )
687 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
689 if( val_list.p_list->i_count > val.i_int )
691 var_Change( p_input, "title", VLC_VAR_FREELIST,
693 var_SetVoid( p_input, "next-title" );
696 var_Change( p_input, "title", VLC_VAR_FREELIST,
700 /* Try to go to next file */
703 playlist_Next( p_playlist );
708 // drag'n'drop and system messages
710 // convert soundplay drag'n'drop message (containing paths)
711 // to normal message (containing refs)
714 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
717 if ( get_ref_for_path( path, &ref ) == B_OK )
718 p_message->AddRef( "refs", &ref );
722 case B_REFS_RECEIVED:
725 /* file(s) opened by the File menu -> append to the playlist;
726 file(s) opened by drag & drop -> replace playlist;
727 file(s) opened by 'shift' + drag & drop -> append */
731 if( p_message->GetInfo( "refs", &dummy, &count ) != B_OK ||
737 bool b_remove = ( p_message->WasDropped() &&
738 !( modifiers() & B_SHIFT_KEY ) );
740 if( b_remove && p_playlist )
742 playlist_Clear( p_playlist, true );
746 for( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
750 /* TODO: find out if this is a DVD icon */
754 playlist_Add( p_playlist, path.Path(), NULL,
755 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true );
763 case OPEN_PREFERENCES:
765 if( fPreferencesWindow->Lock() )
767 if (fPreferencesWindow->IsHidden())
768 fPreferencesWindow->Show();
770 fPreferencesWindow->Activate();
771 fPreferencesWindow->Unlock();
778 if( fMessagesWindow->Lock() )
780 if (fMessagesWindow->IsHidden())
781 fMessagesWindow->Show();
783 fMessagesWindow->Activate();
784 fMessagesWindow->Unlock();
792 BWindow::MessageReceived( p_message );
797 /*****************************************************************************
798 * InterfaceWindow::QuitRequested
799 *****************************************************************************/
800 bool InterfaceWindow::QuitRequested()
804 playlist_Stop( p_playlist );
806 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
810 vlc_object_kill( p_intf );
815 /*****************************************************************************
816 * InterfaceWindow::UpdateInterface
817 *****************************************************************************/
818 void InterfaceWindow::UpdateInterface()
822 p_input = (input_thread_t *)
823 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
825 else if( p_input->b_dead )
827 vlc_object_release( p_input );
831 /* Get ready to update the interface */
832 if( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) != B_OK )
837 if( b_playlist_update )
840 if( fPlaylistWindow->Lock() )
842 fPlaylistWindow->UpdatePlaylist( true );
843 fPlaylistWindow->Unlock();
844 b_playlist_update = false;
847 p_mediaControl->SetEnabled( !playlist_IsEmpty( p_playlist ) );
853 p_mediaControl->SetEnabled( true );
854 bool hasTitles = !var_Get( p_input, "title", &val );
855 bool hasChapters = !var_Get( p_input, "chapter", &val );
856 p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
857 var_GetInteger( p_input, "rate" ) );
858 var_Get( p_input, "position", &val );
859 p_mediaControl->SetProgress( val.f_float );
860 _SetMenusEnabled( true, hasChapters, hasTitles );
861 _UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
863 // enable/disable skip buttons
867 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
868 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
871 audio_volume_t i_volume;
872 aout_VolumeGet( p_intf, &i_volume );
873 p_mediaControl->SetAudioEnabled( true );
874 p_mediaControl->SetMuted( i_volume );
878 p_mediaControl->SetAudioEnabled( false );
880 _SetMenusEnabled( false );
882 if( !playlist_IsEmpty( p_playlist ) )
884 p_mediaControl->SetProgress( 0 );
887 // enable/disable skip buttons
890 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
891 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
896 p_mediaControl->SetEnabled( false );
901 fLastUpdateTime = system_time();
904 /*****************************************************************************
905 * InterfaceWindow::UpdatePlaylist
906 *****************************************************************************/
908 InterfaceWindow::UpdatePlaylist()
910 b_playlist_update = true;
913 /*****************************************************************************
914 * InterfaceWindow::IsStopped
915 *****************************************************************************/
917 InterfaceWindow::IsStopped() const
919 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
922 /*****************************************************************************
923 * InterfaceWindow::_SetMenusEnabled
924 *****************************************************************************/
926 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
933 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
935 if ( fNextChapterMI->IsEnabled() != hasChapters )
936 fNextChapterMI->SetEnabled( hasChapters );
937 if ( fPrevChapterMI->IsEnabled() != hasChapters )
938 fPrevChapterMI->SetEnabled( hasChapters );
939 if ( fChapterMenu->IsEnabled() != hasChapters )
940 fChapterMenu->SetEnabled( hasChapters );
941 if ( fNextTitleMI->IsEnabled() != hasTitles )
942 fNextTitleMI->SetEnabled( hasTitles );
943 if ( fPrevTitleMI->IsEnabled() != hasTitles )
944 fPrevTitleMI->SetEnabled( hasTitles );
945 if ( fTitleMenu->IsEnabled() != hasTitles )
946 fTitleMenu->SetEnabled( hasTitles );
947 if ( fAudioMenu->IsEnabled() != hasFile )
948 fAudioMenu->SetEnabled( hasFile );
949 if ( fNavigationMenu->IsEnabled() != hasFile )
950 fNavigationMenu->SetEnabled( hasFile );
951 if ( fLanguageMenu->IsEnabled() != hasFile )
952 fLanguageMenu->SetEnabled( hasFile );
953 if ( fSubtitlesMenu->IsEnabled() != hasFile )
954 fSubtitlesMenu->SetEnabled( hasFile );
955 if ( fSpeedMenu->IsEnabled() != hasFile )
956 fSpeedMenu->SetEnabled( hasFile );
961 /*****************************************************************************
962 * InterfaceWindow::_UpdateSpeedMenu
963 *****************************************************************************/
965 InterfaceWindow::_UpdateSpeedMenu( int rate )
967 BMenuItem * toMark = NULL;
971 case ( INPUT_RATE_DEFAULT * 8 ):
975 case ( INPUT_RATE_DEFAULT * 4 ):
979 case ( INPUT_RATE_DEFAULT * 2 ):
983 case ( INPUT_RATE_DEFAULT ):
987 case ( INPUT_RATE_DEFAULT / 2 ):
991 case ( INPUT_RATE_DEFAULT / 4 ):
995 case ( INPUT_RATE_DEFAULT / 8 ):
1000 if ( toMark && !toMark->IsMarked() )
1002 toMark->SetMarked( true );
1006 /*****************************************************************************
1007 * InterfaceWindow::_ShowFilePanel
1008 *****************************************************************************/
1010 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
1014 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
1015 B_FILE_NODE | B_DIRECTORY_NODE );
1016 fFilePanel->SetTarget( this );
1018 fFilePanel->Window()->SetTitle( windowTitle );
1019 BMessage message( command );
1020 fFilePanel->SetMessage( &message );
1021 if ( !fFilePanel->IsShowing() )
1023 fFilePanel->Refresh();
1030 set_window_pos( BWindow* window, BRect frame )
1032 // sanity checks: make sure window is not too big/small
1033 // and that it's not off-screen
1034 float minWidth, maxWidth, minHeight, maxHeight;
1035 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1037 make_sure_frame_is_within_limits( frame,
1038 minWidth, minHeight, maxWidth, maxHeight );
1039 if ( make_sure_frame_is_on_screen( frame ) )
1041 window->MoveTo( frame.LeftTop() );
1042 window->ResizeTo( frame.Width(), frame.Height() );
1048 launch_window( BWindow* window, bool showing )
1050 if ( window->Lock() )
1054 if ( window->IsHidden() )
1059 if ( !window->IsHidden() )
1066 /*****************************************************************************
1067 * InterfaceWindow::_RestoreSettings
1068 *****************************************************************************/
1070 InterfaceWindow::_RestoreSettings()
1072 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1075 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1076 set_window_pos( this, frame );
1078 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1079 set_window_pos( fPlaylistWindow, frame );
1081 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1082 set_window_pos( fMessagesWindow, frame );
1083 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1085 /* FIXME: Preferences resizing doesn't work correctly yet */
1086 frame.right = frame.left + fPreferencesWindow->Frame().Width();
1087 frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
1088 set_window_pos( fPreferencesWindow, frame );
1093 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1094 launch_window( fPlaylistWindow, showing );
1096 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1097 launch_window( fMessagesWindow, showing );
1098 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1099 launch_window( fPreferencesWindow, showing );
1102 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1103 fPlaylistWindow->SetDisplayMode( displayMode );
1108 /*****************************************************************************
1109 * InterfaceWindow::_StoreSettings
1110 *****************************************************************************/
1112 InterfaceWindow::_StoreSettings()
1114 /* Save the volume */
1115 config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
1116 config_SaveConfigFile( p_intf, "main" );
1118 /* Save the windows positions */
1119 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1120 fSettings->AddRect( "main frame", Frame() );
1122 if ( fPlaylistWindow->Lock() )
1124 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1125 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1126 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1127 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1128 fPlaylistWindow->Unlock();
1131 if ( fMessagesWindow->Lock() )
1133 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1134 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1135 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1136 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1137 fMessagesWindow->Unlock();
1139 if ( fPreferencesWindow->Lock() )
1141 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1142 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1143 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1144 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1145 fPreferencesWindow->Unlock();
1148 uint32 displayMode = fPlaylistWindow->DisplayMode();
1149 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1150 fSettings->AddInt32( "playlist display mode", displayMode );
1152 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1156 /*****************************************************************************
1158 *****************************************************************************/
1159 CDMenu::CDMenu(const char *name)
1164 /*****************************************************************************
1166 *****************************************************************************/
1171 /*****************************************************************************
1172 * CDMenu::AttachedToWindow
1173 *****************************************************************************/
1174 void CDMenu::AttachedToWindow(void)
1177 while ( BMenuItem* item = RemoveItem( 0L ) )
1179 GetCD( "/dev/disk" );
1180 BMenu::AttachedToWindow();
1183 /*****************************************************************************
1185 *****************************************************************************/
1186 int CDMenu::GetCD( const char *directory )
1188 BVolumeRoster volRoster;
1191 status_t status = volRoster.GetNextVolume( &vol );
1192 while ( status == B_NO_ERROR )
1197 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1200 BMessage* msg = new BMessage( OPEN_DVD );
1201 msg->AddString( "device", deviceName.String() );
1202 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1206 status = volRoster.GetNextVolume( &vol );
1211 /*****************************************************************************
1212 * LanguageMenu::LanguageMenu
1213 *****************************************************************************/
1214 LanguageMenu::LanguageMenu( intf_thread_t * _p_intf, const char * psz_name,
1215 char * _psz_variable )
1219 psz_variable = strdup( _psz_variable );
1222 /*****************************************************************************
1223 * LanguageMenu::~LanguageMenu
1224 *****************************************************************************/
1225 LanguageMenu::~LanguageMenu()
1227 free( psz_variable );
1230 /*****************************************************************************
1231 * LanguageMenu::AttachedToWindow
1232 *****************************************************************************/
1233 void LanguageMenu::AttachedToWindow()
1238 while( ( item = RemoveItem( 0L ) ) )
1243 SetRadioMode( true );
1245 input_thread_t * p_input = (input_thread_t *)
1246 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1252 vlc_value_t val_list, text_list;
1256 i_current = var_GetInteger( p_input, psz_variable );
1257 var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list );
1258 for( int i = 0; i < val_list.p_list->i_count; i++ )
1260 message = new BMessage( SELECT_CHANNEL );
1261 message->AddInt32( psz_variable, val_list.p_list->p_values[i].i_int );
1262 item = new BMenuItem( text_list.p_list->p_values[i].psz_string, message );
1263 if( val_list.p_list->p_values[i].i_int == i_current )
1265 item->SetMarked( true );
1269 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
1271 vlc_object_release( p_input );
1273 BMenu::AttachedToWindow();
1276 /*****************************************************************************
1277 * TitleMenu::TitleMenu
1278 *****************************************************************************/
1279 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1281 p_intf( p_interface )
1285 /*****************************************************************************
1286 * TitleMenu::~TitleMenu
1287 *****************************************************************************/
1288 TitleMenu::~TitleMenu()
1292 /*****************************************************************************
1293 * TitleMenu::AttachedToWindow
1294 *****************************************************************************/
1295 void TitleMenu::AttachedToWindow()
1298 while( ( item = RemoveItem( 0L ) ) )
1303 input_thread_t * p_input;
1304 p_input = (input_thread_t *)
1305 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1313 if( !var_Get( p_input, "title", &val ) )
1315 vlc_value_t val_list, text_list;
1316 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1317 &val_list, &text_list );
1319 for( int i = 0; i < val_list.p_list->i_count; i++ )
1321 message = new BMessage( TOGGLE_TITLE );
1322 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1323 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1325 if( val_list.p_list->p_values[i].i_int == val.i_int )
1327 item->SetMarked( true );
1332 var_Change( p_input, "title", VLC_VAR_FREELIST,
1333 &val_list, &text_list );
1335 vlc_object_release( p_input );
1336 BMenu::AttachedToWindow();
1340 /*****************************************************************************
1341 * ChapterMenu::ChapterMenu
1342 *****************************************************************************/
1343 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1345 p_intf( p_interface )
1349 /*****************************************************************************
1350 * ChapterMenu::~ChapterMenu
1351 *****************************************************************************/
1352 ChapterMenu::~ChapterMenu()
1356 /*****************************************************************************
1357 * ChapterMenu::AttachedToWindow
1358 *****************************************************************************/
1359 void ChapterMenu::AttachedToWindow()
1362 while( ( item = RemoveItem( 0L ) ) )
1367 input_thread_t * p_input;
1368 p_input = (input_thread_t *)
1369 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1377 if( !var_Get( p_input, "chapter", &val ) )
1379 vlc_value_t val_list, text_list;
1380 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1381 &val_list, &text_list );
1383 for( int i = 0; i < val_list.p_list->i_count; i++ )
1385 message = new BMessage( TOGGLE_CHAPTER );
1386 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1387 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1389 if( val_list.p_list->p_values[i].i_int == val.i_int )
1391 item->SetMarked( true );
1396 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
1397 &val_list, &text_list );
1399 vlc_object_release( p_input );
1400 BMenu::AttachedToWindow();
1404 /*****************************************************************************
1406 *****************************************************************************/
1408 load_settings( BMessage* message, const char* fileName, const char* folder )
1410 status_t ret = B_BAD_VALUE;
1414 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1416 // passing folder is optional
1418 ret = path.Append( folder );
1419 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1421 BFile file( path.Path(), B_READ_ONLY );
1422 if ( ( ret = file.InitCheck() ) == B_OK )
1424 ret = message->Unflatten( &file );
1433 /*****************************************************************************
1435 *****************************************************************************/
1437 save_settings( BMessage* message, const char* fileName, const char* folder )
1439 status_t ret = B_BAD_VALUE;
1443 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1445 // passing folder is optional
1446 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1447 ret = create_directory( path.Path(), 0777 );
1448 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1450 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1451 if ( ( ret = file.InitCheck() ) == B_OK )
1453 ret = message->Flatten( &file );