1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN (Centrale Réseaux) and its contributors
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tony@castley.net>
10 * Richard Shepherd <richard@rshepherd.demon.co.uk>
11 * Stephan Aßmus <superstippi@gmx.de>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
29 #include <kernel/OS.h>
30 #include <InterfaceKit.h>
32 #include <StorageKit.h>
33 #include <SupportKit.h>
36 #include <scsiprobe_driver.h>
44 #include <vlc/input.h>
46 /* BeOS interface headers */
48 #include "MediaControlView.h"
49 #include "PlayListWindow.h"
50 #include "PreferencesWindow.h"
51 #include "MessagesWindow.h"
52 #include "InterfaceWindow.h"
54 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
55 #define INTERFACE_LOCKING_TIMEOUT 5000
57 // make_sure_frame_is_on_screen
59 make_sure_frame_is_on_screen( BRect& frame )
61 BScreen screen( B_MAIN_SCREEN_ID );
62 if (frame.IsValid() && screen.IsValid()) {
63 if (!screen.Frame().Contains(frame)) {
64 // make sure frame fits in the screen
65 if (frame.Width() > screen.Frame().Width())
66 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
67 if (frame.Height() > screen.Frame().Height())
68 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
69 // frame is now at the most the size of the screen
70 if (frame.right > screen.Frame().right)
71 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
72 if (frame.bottom > screen.Frame().bottom)
73 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
74 if (frame.left < screen.Frame().left)
75 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
76 if (frame.top < screen.Frame().top)
77 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
84 // make_sure_frame_is_within_limits
86 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
87 float maxWidth, float maxHeight )
89 if ( frame.Width() < minWidth )
90 frame.right = frame.left + minWidth;
91 if ( frame.Height() < minHeight )
92 frame.bottom = frame.top + minHeight;
93 if ( frame.Width() > maxWidth )
94 frame.right = frame.left + maxWidth;
95 if ( frame.Height() > maxHeight )
96 frame.bottom = frame.top + maxHeight;
101 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
103 bool success = false;
107 char name[B_FILE_NAME_LENGTH];
108 if ( volume.GetName( name ) >= B_OK ) // disk is currently mounted
111 dev_t dev = volume.Device();
113 if ( fs_stat_dev( dev, &info ) == B_OK )
116 deviceName = info.device_name;
117 if ( volume.IsReadOnly() )
119 int i_dev = open( info.device_name, O_RDONLY );
123 if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
124 isCDROM = ( g.device_type == B_CD );
133 // collect_folder_contents
135 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
137 while ( dir.GetNextEntry( &entry, true ) == B_OK )
139 if ( !entry.IsDirectory() )
142 // since the directory will give us the entries in reverse order,
143 // we put them each at the same index, effectively reversing the
144 // items while adding them
145 if ( entry.GetPath( &path ) == B_OK )
147 BString* string = new BString( path.Path() );
148 if ( !list.AddItem( string, 0 ) )
149 delete string; // at least don't leak
156 // ask user if we should parse sub-folders as well
157 BAlert* alert = new BAlert( "sub-folders?",
158 _("Open files from all sub-folders as well?"),
159 _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL,
161 int32 buttonIndex = alert->Go();
162 deep = buttonIndex == 1;
164 // never delete BAlerts!!
168 BDirectory subDir( &entry );
169 if ( subDir.InitCheck() == B_OK )
170 collect_folder_contents( subDir, list,
171 deep, asked, entry );
178 /*****************************************************************************
180 *****************************************************************************/
182 InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
184 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
185 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
187 /* Initializations */
193 fLastUpdateTime( system_time() ),
194 fSettings( new BMessage( 'sett' ) )
197 #define ADD_ELLIPSIS( a ) \
198 memset( psz_tmp, 0, 1024 ); \
199 snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );
202 BRect screen_rect = screen.Frame();
204 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
205 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
206 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
207 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
208 fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
209 window_rect.Set( screen_rect.right - 500,
210 screen_rect.top + 50,
211 screen_rect.right - 150,
212 screen_rect.top + 250 );
213 fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
214 window_rect.Set( screen_rect.right - 550,
215 screen_rect.top + 300,
216 screen_rect.right - 150,
217 screen_rect.top + 500 );
218 fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
220 // the media control view
221 p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );
222 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
225 p_mediaControl->GetPreferredSize( &width, &height );
227 // set up the main menu
228 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
229 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
231 // make menu bar resize to correct height
232 float menuWidth, menuHeight;
233 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
234 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
235 // take care of proper size for ourself
236 height += fMenuBar->Bounds().Height();
237 ResizeTo( width, height );
239 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
240 AddChild( fMenuBar );
244 BMenu* fileMenu = new BMenu( _("File") );
245 fMenuBar->AddItem( fileMenu );
246 ADD_ELLIPSIS( _("Open File") );
247 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );
248 fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
249 ADD_ELLIPSIS( _("Open Subtitles") );
250 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );
252 fileMenu->AddSeparatorItem();
253 ADD_ELLIPSIS( _("About") );
254 BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');
255 item->SetTarget( be_app );
256 fileMenu->AddItem( item );
257 fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
259 fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );
260 fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );
262 /* Add the Audio menu */
263 fAudioMenu = new BMenu( _("Audio") );
264 fMenuBar->AddItem ( fAudioMenu );
265 fAudioMenu->AddItem( fLanguageMenu );
266 fAudioMenu->AddItem( fSubtitlesMenu );
268 fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
269 fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
270 fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );
271 fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );
273 /* Add the Navigation menu */
274 fNavigationMenu = new BMenu( _("Navigation") );
275 fMenuBar->AddItem( fNavigationMenu );
276 fNavigationMenu->AddItem( fPrevTitleMI );
277 fNavigationMenu->AddItem( fNextTitleMI );
278 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
279 fNavigationMenu->AddSeparatorItem();
280 fNavigationMenu->AddItem( fPrevChapterMI );
281 fNavigationMenu->AddItem( fNextChapterMI );
282 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
284 /* Add the Speed menu */
285 fSpeedMenu = new BMenu( _("Speed") );
286 fSpeedMenu->SetRadioMode( true );
288 fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
290 fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
292 fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
294 fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
296 fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
298 fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
300 fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
301 fMenuBar->AddItem( fSpeedMenu );
303 /* Add the Show menu */
304 fShowMenu = new BMenu( _("Window") );
305 ADD_ELLIPSIS( _("Playlist") );
306 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );
307 ADD_ELLIPSIS( _("Messages") );
308 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );
309 ADD_ELLIPSIS( _("Preferences") );
310 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );
311 fMenuBar->AddItem( fShowMenu );
313 // add the media control view after the menubar is complete
314 // because it will set the window size limits in AttachedToWindow()
315 // and the menubar needs to report the correct PreferredSize()
316 AddChild( p_mediaControl );
318 /* Prepare fow showing */
319 _SetMenusEnabled( false );
320 p_mediaControl->SetEnabled( false );
327 InterfaceWindow::~InterfaceWindow()
331 vlc_object_release( p_input );
335 vlc_object_release( p_playlist );
337 if( fPlaylistWindow )
339 fPlaylistWindow->ReallyQuit();
341 if( fMessagesWindow )
343 fMessagesWindow->ReallyQuit();
345 if( fPreferencesWindow )
347 fPreferencesWindow->ReallyQuit();
353 /*****************************************************************************
354 * InterfaceWindow::FrameResized
355 *****************************************************************************/
357 InterfaceWindow::FrameResized(float width, float height)
360 fMenuBar->MoveTo(r.LeftTop());
361 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
362 r.top += fMenuBar->Bounds().Height() + 1.0;
363 p_mediaControl->MoveTo(r.LeftTop());
364 p_mediaControl->ResizeTo(r.Width(), r.Height());
367 /*****************************************************************************
368 * InterfaceWindow::MessageReceived
369 *****************************************************************************/
370 void InterfaceWindow::MessageReceived( BMessage * p_message )
372 switch( p_message->what )
374 case B_ABOUT_REQUESTED:
378 alert = new BAlert( "VLC media player" VERSION,
379 "VLC media player" VERSION " (BeOS interface)\n\n"
380 "The VideoLAN team <videolan@videolan.org>\n"
381 "http://www.videolan.org/", _("OK") );
389 _ShowFilePanel( B_REFS_RECEIVED, _("VLC media player: Open Media Files") );
393 _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
397 if (fPlaylistWindow->Lock())
399 if (fPlaylistWindow->IsHidden())
400 fPlaylistWindow->Show();
402 fPlaylistWindow->Activate();
403 fPlaylistWindow->Unlock();
409 const char * psz_device;
411 p_message->FindString( "device", &psz_device ) == B_OK )
414 memset( psz_uri, 0, 1024 );
415 snprintf( psz_uri, 1024, "dvdnav:%s", psz_device );
416 playlist_Add( p_playlist, psz_uri, psz_device,
417 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
423 case SUBFILE_RECEIVED:
426 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
429 if ( path.InitCheck() == B_OK )
430 config_PutPsz( p_intf, "sub-file", path.Path() );
438 playlist_Stop( p_playlist );
440 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
447 val.i_int = PLAYING_S;
450 var_Get( p_input, "state", &val );
452 if( p_input && val.i_int != PAUSE_S )
455 var_Set( p_input, "state", val );
459 playlist_Play( p_playlist );
466 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
473 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
480 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
487 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
494 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
501 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
508 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
513 /* handled by semaphores */
517 aout_VolumeSet( p_intf, p_mediaControl->GetVolume() );
521 aout_VolumeMute( p_intf, NULL );
529 if( p_message->FindInt32( "audio-es", &channel ) == B_OK )
531 var_SetInteger( p_input, "audio-es", channel );
533 else if( p_message->FindInt32( "spu-es", &channel ) == B_OK )
535 var_SetInteger( p_input, "spu-es", channel );
544 var_SetVoid( p_input, "prev-title" );
551 var_SetVoid( p_input, "next-title" );
559 p_message->FindInt32( "index", &index ) == B_OK )
561 var_SetInteger( p_input, "title", index );
569 var_SetVoid( p_input, "prev-chapter" );
576 var_SetVoid( p_input, "next-chapter" );
584 p_message->FindInt32( "index", &index ) == B_OK )
586 var_SetInteger( p_input, "chapter", index );
594 playlist_Prev( p_playlist );
601 playlist_Next( p_playlist );
610 /* First try to go to previous chapter */
611 if( !var_Get( p_input, "chapter", &val ) )
615 var_SetVoid( p_input, "prev-chapter" );
620 /* Try to go to previous title */
621 if( !var_Get( p_input, "title", &val ) )
625 var_SetVoid( p_input, "prev-title" );
630 /* Try to go to previous file */
633 playlist_Prev( p_playlist );
641 vlc_value_t val, val_list;
643 /* First try to go to next chapter */
644 if( !var_Get( p_input, "chapter", &val ) )
646 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
648 if( val_list.p_list->i_count > val.i_int )
650 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
652 var_SetVoid( p_input, "next-chapter" );
655 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
659 /* Try to go to next title */
660 if( !var_Get( p_input, "title", &val ) )
662 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
664 if( val_list.p_list->i_count > val.i_int )
666 var_Change( p_input, "title", VLC_VAR_FREELIST,
668 var_SetVoid( p_input, "next-title" );
671 var_Change( p_input, "title", VLC_VAR_FREELIST,
675 /* Try to go to next file */
678 playlist_Next( p_playlist );
683 // drag'n'drop and system messages
685 // convert soundplay drag'n'drop message (containing paths)
686 // to normal message (containing refs)
689 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
692 if ( get_ref_for_path( path, &ref ) == B_OK )
693 p_message->AddRef( "refs", &ref );
697 case B_REFS_RECEIVED:
700 /* file(s) opened by the File menu -> append to the playlist;
701 file(s) opened by drag & drop -> replace playlist;
702 file(s) opened by 'shift' + drag & drop -> append */
706 if( p_message->GetInfo( "refs", &dummy, &count ) != B_OK ||
712 vlc_bool_t b_remove = ( p_message->WasDropped() &&
713 !( modifiers() & B_SHIFT_KEY ) );
715 if( b_remove && p_playlist )
717 playlist_Clear( p_playlist );
721 for( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
725 /* TODO: find out if this is a DVD icon */
729 playlist_Add( p_playlist, path.Path(), path.Path(),
730 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
738 case OPEN_PREFERENCES:
740 if( fPreferencesWindow->Lock() )
742 if (fPreferencesWindow->IsHidden())
743 fPreferencesWindow->Show();
745 fPreferencesWindow->Activate();
746 fPreferencesWindow->Unlock();
753 if( fMessagesWindow->Lock() )
755 if (fMessagesWindow->IsHidden())
756 fMessagesWindow->Show();
758 fMessagesWindow->Activate();
759 fMessagesWindow->Unlock();
767 BWindow::MessageReceived( p_message );
772 /*****************************************************************************
773 * InterfaceWindow::QuitRequested
774 *****************************************************************************/
775 bool InterfaceWindow::QuitRequested()
779 playlist_Stop( p_playlist );
781 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
790 /*****************************************************************************
791 * InterfaceWindow::UpdateInterface
792 *****************************************************************************/
793 void InterfaceWindow::UpdateInterface()
795 /* Manage the input part */
798 p_playlist = (playlist_t *)
799 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
803 p_input = (input_thread_t *)
804 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
806 else if( p_input->b_dead )
808 vlc_object_release( p_input );
812 /* Get ready to update the interface */
813 if( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) != B_OK )
821 p_mediaControl->SetEnabled( true );
822 bool hasTitles = !var_Get( p_input, "title", &val );
823 bool hasChapters = !var_Get( p_input, "chapter", &val );
824 p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
825 var_GetInteger( p_input, "rate" ) );
826 var_Get( p_input, "position", &val );
827 p_mediaControl->SetProgress( val.f_float );
828 _SetMenusEnabled( true, hasChapters, hasTitles );
829 _UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
831 // enable/disable skip buttons
835 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
836 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
839 audio_volume_t i_volume;
840 aout_VolumeGet( p_intf, &i_volume );
841 p_mediaControl->SetAudioEnabled( true );
842 p_mediaControl->SetMuted( i_volume );
844 // update playlist as well
845 if( fPlaylistWindow->LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK )
847 fPlaylistWindow->UpdatePlaylist();
848 fPlaylistWindow->Unlock();
853 p_mediaControl->SetAudioEnabled( false );
855 _SetMenusEnabled( false );
857 if( !playlist_IsEmpty( p_playlist ) )
859 p_mediaControl->SetProgress( 0 );
862 // enable/disable skip buttons
865 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
866 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
871 p_mediaControl->SetEnabled( false );
876 fLastUpdateTime = system_time();
879 /*****************************************************************************
880 * InterfaceWindow::IsStopped
881 *****************************************************************************/
883 InterfaceWindow::IsStopped() const
885 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
888 /*****************************************************************************
889 * InterfaceWindow::_UpdatePlaylist
890 *****************************************************************************/
892 InterfaceWindow::_UpdatePlaylist()
894 if( fPlaylistWindow->Lock() )
896 fPlaylistWindow->UpdatePlaylist( true );
897 fPlaylistWindow->Unlock();
899 p_mediaControl->SetEnabled( p_playlist->i_size );
902 /*****************************************************************************
903 * InterfaceWindow::_SetMenusEnabled
904 *****************************************************************************/
906 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
913 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
915 if ( fNextChapterMI->IsEnabled() != hasChapters )
916 fNextChapterMI->SetEnabled( hasChapters );
917 if ( fPrevChapterMI->IsEnabled() != hasChapters )
918 fPrevChapterMI->SetEnabled( hasChapters );
919 if ( fChapterMenu->IsEnabled() != hasChapters )
920 fChapterMenu->SetEnabled( hasChapters );
921 if ( fNextTitleMI->IsEnabled() != hasTitles )
922 fNextTitleMI->SetEnabled( hasTitles );
923 if ( fPrevTitleMI->IsEnabled() != hasTitles )
924 fPrevTitleMI->SetEnabled( hasTitles );
925 if ( fTitleMenu->IsEnabled() != hasTitles )
926 fTitleMenu->SetEnabled( hasTitles );
927 if ( fAudioMenu->IsEnabled() != hasFile )
928 fAudioMenu->SetEnabled( hasFile );
929 if ( fNavigationMenu->IsEnabled() != hasFile )
930 fNavigationMenu->SetEnabled( hasFile );
931 if ( fLanguageMenu->IsEnabled() != hasFile )
932 fLanguageMenu->SetEnabled( hasFile );
933 if ( fSubtitlesMenu->IsEnabled() != hasFile )
934 fSubtitlesMenu->SetEnabled( hasFile );
935 if ( fSpeedMenu->IsEnabled() != hasFile )
936 fSpeedMenu->SetEnabled( hasFile );
941 /*****************************************************************************
942 * InterfaceWindow::_UpdateSpeedMenu
943 *****************************************************************************/
945 InterfaceWindow::_UpdateSpeedMenu( int rate )
947 BMenuItem * toMark = NULL;
951 case ( INPUT_RATE_DEFAULT * 8 ):
955 case ( INPUT_RATE_DEFAULT * 4 ):
959 case ( INPUT_RATE_DEFAULT * 2 ):
963 case ( INPUT_RATE_DEFAULT ):
967 case ( INPUT_RATE_DEFAULT / 2 ):
971 case ( INPUT_RATE_DEFAULT / 4 ):
975 case ( INPUT_RATE_DEFAULT / 8 ):
980 if ( toMark && !toMark->IsMarked() )
982 toMark->SetMarked( true );
986 /*****************************************************************************
987 * InterfaceWindow::_ShowFilePanel
988 *****************************************************************************/
990 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
994 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
995 B_FILE_NODE | B_DIRECTORY_NODE );
996 fFilePanel->SetTarget( this );
998 fFilePanel->Window()->SetTitle( windowTitle );
999 BMessage message( command );
1000 fFilePanel->SetMessage( &message );
1001 if ( !fFilePanel->IsShowing() )
1003 fFilePanel->Refresh();
1010 set_window_pos( BWindow* window, BRect frame )
1012 // sanity checks: make sure window is not too big/small
1013 // and that it's not off-screen
1014 float minWidth, maxWidth, minHeight, maxHeight;
1015 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1017 make_sure_frame_is_within_limits( frame,
1018 minWidth, minHeight, maxWidth, maxHeight );
1019 if ( make_sure_frame_is_on_screen( frame ) )
1021 window->MoveTo( frame.LeftTop() );
1022 window->ResizeTo( frame.Width(), frame.Height() );
1028 launch_window( BWindow* window, bool showing )
1030 if ( window->Lock() )
1034 if ( window->IsHidden() )
1039 if ( !window->IsHidden() )
1046 /*****************************************************************************
1047 * InterfaceWindow::_RestoreSettings
1048 *****************************************************************************/
1050 InterfaceWindow::_RestoreSettings()
1052 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1055 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1056 set_window_pos( this, frame );
1057 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1058 set_window_pos( fPlaylistWindow, frame );
1059 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1060 set_window_pos( fMessagesWindow, frame );
1061 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1063 /* FIXME: Preferences resizing doesn't work correctly yet */
1064 frame.right = frame.left + fPreferencesWindow->Frame().Width();
1065 frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
1066 set_window_pos( fPreferencesWindow, frame );
1070 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1071 launch_window( fPlaylistWindow, showing );
1072 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1073 launch_window( fMessagesWindow, showing );
1074 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1075 launch_window( fPreferencesWindow, showing );
1078 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1079 fPlaylistWindow->SetDisplayMode( displayMode );
1083 /*****************************************************************************
1084 * InterfaceWindow::_StoreSettings
1085 *****************************************************************************/
1087 InterfaceWindow::_StoreSettings()
1089 /* Save the volume */
1090 config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
1091 config_SaveConfigFile( p_intf, "main" );
1093 /* Save the windows positions */
1094 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1095 fSettings->AddRect( "main frame", Frame() );
1096 if ( fPlaylistWindow->Lock() )
1098 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1099 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1100 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1101 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1102 fPlaylistWindow->Unlock();
1104 if ( fMessagesWindow->Lock() )
1106 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1107 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1108 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1109 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1110 fMessagesWindow->Unlock();
1112 if ( fPreferencesWindow->Lock() )
1114 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1115 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1116 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1117 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1118 fPreferencesWindow->Unlock();
1120 uint32 displayMode = fPlaylistWindow->DisplayMode();
1121 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1122 fSettings->AddInt32( "playlist display mode", displayMode );
1124 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1128 /*****************************************************************************
1130 *****************************************************************************/
1131 CDMenu::CDMenu(const char *name)
1136 /*****************************************************************************
1138 *****************************************************************************/
1143 /*****************************************************************************
1144 * CDMenu::AttachedToWindow
1145 *****************************************************************************/
1146 void CDMenu::AttachedToWindow(void)
1149 while ( BMenuItem* item = RemoveItem( 0L ) )
1151 GetCD( "/dev/disk" );
1152 BMenu::AttachedToWindow();
1155 /*****************************************************************************
1157 *****************************************************************************/
1158 int CDMenu::GetCD( const char *directory )
1160 BVolumeRoster volRoster;
1163 status_t status = volRoster.GetNextVolume( &vol );
1164 while ( status == B_NO_ERROR )
1169 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1172 BMessage* msg = new BMessage( OPEN_DVD );
1173 msg->AddString( "device", deviceName.String() );
1174 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1178 status = volRoster.GetNextVolume( &vol );
1183 /*****************************************************************************
1184 * LanguageMenu::LanguageMenu
1185 *****************************************************************************/
1186 LanguageMenu::LanguageMenu( intf_thread_t * _p_intf, const char * psz_name,
1187 char * _psz_variable )
1191 psz_variable = strdup( _psz_variable );
1194 /*****************************************************************************
1195 * LanguageMenu::~LanguageMenu
1196 *****************************************************************************/
1197 LanguageMenu::~LanguageMenu()
1199 free( psz_variable );
1202 /*****************************************************************************
1203 * LanguageMenu::AttachedToWindow
1204 *****************************************************************************/
1205 void LanguageMenu::AttachedToWindow()
1210 while( ( item = RemoveItem( 0L ) ) )
1215 SetRadioMode( true );
1217 input_thread_t * p_input = (input_thread_t *)
1218 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1224 vlc_value_t val_list, text_list;
1228 i_current = var_GetInteger( p_input, psz_variable );
1229 var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list );
1230 for( int i = 0; i < val_list.p_list->i_count; i++ )
1232 message = new BMessage( SELECT_CHANNEL );
1233 message->AddInt32( psz_variable, val_list.p_list->p_values[i].i_int );
1234 item = new BMenuItem( text_list.p_list->p_values[i].psz_string, message );
1235 if( val_list.p_list->p_values[i].i_int == i_current )
1237 item->SetMarked( true );
1241 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
1243 vlc_object_release( p_input );
1245 BMenu::AttachedToWindow();
1248 /*****************************************************************************
1249 * TitleMenu::TitleMenu
1250 *****************************************************************************/
1251 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1253 p_intf( p_interface )
1257 /*****************************************************************************
1258 * TitleMenu::~TitleMenu
1259 *****************************************************************************/
1260 TitleMenu::~TitleMenu()
1264 /*****************************************************************************
1265 * TitleMenu::AttachedToWindow
1266 *****************************************************************************/
1267 void TitleMenu::AttachedToWindow()
1270 while( ( item = RemoveItem( 0L ) ) )
1275 input_thread_t * p_input;
1276 p_input = (input_thread_t *)
1277 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1285 if( !var_Get( p_input, "title", &val ) )
1287 vlc_value_t val_list, text_list;
1288 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1289 &val_list, &text_list );
1291 for( int i = 0; i < val_list.p_list->i_count; i++ )
1293 message = new BMessage( TOGGLE_TITLE );
1294 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1295 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1297 if( val_list.p_list->p_values[i].i_int == val.i_int )
1299 item->SetMarked( true );
1304 var_Change( p_input, "title", VLC_VAR_FREELIST,
1305 &val_list, &text_list );
1307 vlc_object_release( p_input );
1308 BMenu::AttachedToWindow();
1312 /*****************************************************************************
1313 * ChapterMenu::ChapterMenu
1314 *****************************************************************************/
1315 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1317 p_intf( p_interface )
1321 /*****************************************************************************
1322 * ChapterMenu::~ChapterMenu
1323 *****************************************************************************/
1324 ChapterMenu::~ChapterMenu()
1328 /*****************************************************************************
1329 * ChapterMenu::AttachedToWindow
1330 *****************************************************************************/
1331 void ChapterMenu::AttachedToWindow()
1334 while( ( item = RemoveItem( 0L ) ) )
1339 input_thread_t * p_input;
1340 p_input = (input_thread_t *)
1341 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1349 if( !var_Get( p_input, "chapter", &val ) )
1351 vlc_value_t val_list, text_list;
1352 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1353 &val_list, &text_list );
1355 for( int i = 0; i < val_list.p_list->i_count; i++ )
1357 message = new BMessage( TOGGLE_CHAPTER );
1358 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1359 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1361 if( val_list.p_list->p_values[i].i_int == val.i_int )
1363 item->SetMarked( true );
1368 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
1369 &val_list, &text_list );
1371 vlc_object_release( p_input );
1372 BMenu::AttachedToWindow();
1376 /*****************************************************************************
1378 *****************************************************************************/
1380 load_settings( BMessage* message, const char* fileName, const char* folder )
1382 status_t ret = B_BAD_VALUE;
1386 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1388 // passing folder is optional
1390 ret = path.Append( folder );
1391 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1393 BFile file( path.Path(), B_READ_ONLY );
1394 if ( ( ret = file.InitCheck() ) == B_OK )
1396 ret = message->Unflatten( &file );
1405 /*****************************************************************************
1407 *****************************************************************************/
1409 save_settings( BMessage* message, const char* fileName, const char* folder )
1411 status_t ret = B_BAD_VALUE;
1415 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1417 // passing folder is optional
1418 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1419 ret = create_directory( path.Path(), 0777 );
1420 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1422 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1423 if ( ( ret = file.InitCheck() ) == B_OK )
1425 ret = message->Flatten( &file );