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>
44 #include <vlc_common.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 = pl_Yield( p_intf );
208 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
209 var_AddCallback( p_playlist, "item-change", PlaylistChanged, this );
210 var_AddCallback( p_playlist, "item-append", PlaylistChanged, this );
211 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, this );
212 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, this );
215 #define ADD_ELLIPSIS( a ) \
216 memset( psz_tmp, 0, 1024 ); \
217 snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );
220 BRect screen_rect = screen.Frame();
222 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
223 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
224 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
225 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
226 fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
227 window_rect.Set( screen_rect.right - 500,
228 screen_rect.top + 50,
229 screen_rect.right - 150,
230 screen_rect.top + 250 );
232 fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
233 window_rect.Set( screen_rect.right - 550,
234 screen_rect.top + 300,
235 screen_rect.right - 150,
236 screen_rect.top + 500 );
238 fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
240 // the media control view
241 p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );
242 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
245 p_mediaControl->GetPreferredSize( &width, &height );
247 // set up the main menu
248 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
249 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
251 // make menu bar resize to correct height
252 float menuWidth, menuHeight;
253 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
254 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
255 // take care of proper size for ourself
256 height += fMenuBar->Bounds().Height();
257 ResizeTo( width, height );
259 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
260 AddChild( fMenuBar );
264 BMenu* fileMenu = new BMenu( _("File") );
265 fMenuBar->AddItem( fileMenu );
266 ADD_ELLIPSIS( _("Open File") );
267 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );
268 fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
269 ADD_ELLIPSIS( _("Open Subtitles") );
270 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );
272 fileMenu->AddSeparatorItem();
273 ADD_ELLIPSIS( _("About") );
274 BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');
275 item->SetTarget( be_app );
276 fileMenu->AddItem( item );
277 fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
279 fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );
280 fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );
282 /* Add the Audio menu */
283 fAudioMenu = new BMenu( _("Audio") );
284 fMenuBar->AddItem ( fAudioMenu );
285 fAudioMenu->AddItem( fLanguageMenu );
286 fAudioMenu->AddItem( fSubtitlesMenu );
288 fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
289 fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
290 fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );
291 fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );
293 /* Add the Navigation menu */
294 fNavigationMenu = new BMenu( _("Navigation") );
295 fMenuBar->AddItem( fNavigationMenu );
296 fNavigationMenu->AddItem( fPrevTitleMI );
297 fNavigationMenu->AddItem( fNextTitleMI );
298 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
299 fNavigationMenu->AddSeparatorItem();
300 fNavigationMenu->AddItem( fPrevChapterMI );
301 fNavigationMenu->AddItem( fNextChapterMI );
302 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
304 /* Add the Speed menu */
305 fSpeedMenu = new BMenu( _("Speed") );
306 fSpeedMenu->SetRadioMode( true );
308 fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
310 fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
312 fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
314 fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
316 fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
318 fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
320 fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
321 fMenuBar->AddItem( fSpeedMenu );
323 /* Add the Show menu */
324 fShowMenu = new BMenu( _("Window") );
326 ADD_ELLIPSIS( _("Playlist") );
327 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );
329 ADD_ELLIPSIS( _("Messages") );
330 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );
331 ADD_ELLIPSIS( _("Preferences") );
332 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );
333 fMenuBar->AddItem( fShowMenu );
335 // add the media control view after the menubar is complete
336 // because it will set the window size limits in AttachedToWindow()
337 // and the menubar needs to report the correct PreferredSize()
338 AddChild( p_mediaControl );
340 /* Prepare fow showing */
341 _SetMenusEnabled( false );
342 p_mediaControl->SetEnabled( false );
349 InterfaceWindow::~InterfaceWindow()
353 vlc_object_release( p_input );
357 vlc_object_release( p_playlist );
360 if( fPlaylistWindow )
362 fPlaylistWindow->ReallyQuit();
365 if( fMessagesWindow )
367 fMessagesWindow->ReallyQuit();
369 if( fPreferencesWindow )
371 fPreferencesWindow->ReallyQuit();
377 /*****************************************************************************
378 * InterfaceWindow::FrameResized
379 *****************************************************************************/
381 InterfaceWindow::FrameResized(float width, float height)
384 fMenuBar->MoveTo(r.LeftTop());
385 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
386 r.top += fMenuBar->Bounds().Height() + 1.0;
387 p_mediaControl->MoveTo(r.LeftTop());
388 p_mediaControl->ResizeTo(r.Width(), r.Height());
391 /*****************************************************************************
392 * InterfaceWindow::MessageReceived
393 *****************************************************************************/
394 void InterfaceWindow::MessageReceived( BMessage * p_message )
396 switch( p_message->what )
398 case B_ABOUT_REQUESTED:
402 alert = new BAlert( "VLC media player" VERSION,
403 "VLC media player" VERSION " (BeOS interface)\n\n"
404 "The VideoLAN team <videolan@videolan.org>\n"
405 "http://www.videolan.org/", _("OK") );
413 _ShowFilePanel( B_REFS_RECEIVED, _("VLC media player: Open Media Files") );
417 _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
421 if (fPlaylistWindow->Lock())
423 if (fPlaylistWindow->IsHidden())
424 fPlaylistWindow->Show();
426 fPlaylistWindow->Activate();
427 fPlaylistWindow->Unlock();
433 const char * psz_device;
435 p_message->FindString( "device", &psz_device ) == B_OK )
438 memset( psz_uri, 0, 1024 );
439 snprintf( psz_uri, 1024, "dvdnav:%s", psz_device );
440 playlist_Add( p_playlist, psz_uri, psz_device,
441 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true );
447 case SUBFILE_RECEIVED:
450 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
453 if ( path.InitCheck() == B_OK )
454 config_PutPsz( p_intf, "sub-file", path.Path() );
462 playlist_Stop( p_playlist );
464 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
471 val.i_int = PLAYING_S;
474 var_Get( p_input, "state", &val );
476 if( p_input && val.i_int != PAUSE_S )
479 var_Set( p_input, "state", val );
483 playlist_Play( p_playlist );
490 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
497 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
504 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
511 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
518 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
525 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
532 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
537 /* handled by semaphores */
541 aout_VolumeSet( p_intf, p_mediaControl->GetVolume() );
545 aout_VolumeMute( p_intf, NULL );
553 if( p_message->FindInt32( "audio-es", &channel ) == B_OK )
555 var_SetInteger( p_input, "audio-es", channel );
557 else if( p_message->FindInt32( "spu-es", &channel ) == B_OK )
559 var_SetInteger( p_input, "spu-es", channel );
568 var_SetVoid( p_input, "prev-title" );
575 var_SetVoid( p_input, "next-title" );
583 p_message->FindInt32( "index", &index ) == B_OK )
585 var_SetInteger( p_input, "title", index );
593 var_SetVoid( p_input, "prev-chapter" );
600 var_SetVoid( p_input, "next-chapter" );
608 p_message->FindInt32( "index", &index ) == B_OK )
610 var_SetInteger( p_input, "chapter", index );
618 playlist_Prev( p_playlist );
625 playlist_Next( p_playlist );
634 /* First try to go to previous chapter */
635 if( !var_Get( p_input, "chapter", &val ) )
639 var_SetVoid( p_input, "prev-chapter" );
644 /* Try to go to previous title */
645 if( !var_Get( p_input, "title", &val ) )
649 var_SetVoid( p_input, "prev-title" );
654 /* Try to go to previous file */
657 playlist_Prev( p_playlist );
665 vlc_value_t val, val_list;
667 /* First try to go to next chapter */
668 if( !var_Get( p_input, "chapter", &val ) )
670 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
672 if( val_list.p_list->i_count > val.i_int )
674 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
676 var_SetVoid( p_input, "next-chapter" );
679 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
683 /* Try to go to next title */
684 if( !var_Get( p_input, "title", &val ) )
686 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
688 if( val_list.p_list->i_count > val.i_int )
690 var_Change( p_input, "title", VLC_VAR_FREELIST,
692 var_SetVoid( p_input, "next-title" );
695 var_Change( p_input, "title", VLC_VAR_FREELIST,
699 /* Try to go to next file */
702 playlist_Next( p_playlist );
707 // drag'n'drop and system messages
709 // convert soundplay drag'n'drop message (containing paths)
710 // to normal message (containing refs)
713 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
716 if ( get_ref_for_path( path, &ref ) == B_OK )
717 p_message->AddRef( "refs", &ref );
721 case B_REFS_RECEIVED:
724 /* file(s) opened by the File menu -> append to the playlist;
725 file(s) opened by drag & drop -> replace playlist;
726 file(s) opened by 'shift' + drag & drop -> append */
730 if( p_message->GetInfo( "refs", &dummy, &count ) != B_OK ||
736 bool b_remove = ( p_message->WasDropped() &&
737 !( modifiers() & B_SHIFT_KEY ) );
739 if( b_remove && p_playlist )
741 playlist_Clear( p_playlist, true );
745 for( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
749 /* TODO: find out if this is a DVD icon */
753 playlist_Add( p_playlist, path.Path(), NULL,
754 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true );
762 case OPEN_PREFERENCES:
764 if( fPreferencesWindow->Lock() )
766 if (fPreferencesWindow->IsHidden())
767 fPreferencesWindow->Show();
769 fPreferencesWindow->Activate();
770 fPreferencesWindow->Unlock();
777 if( fMessagesWindow->Lock() )
779 if (fMessagesWindow->IsHidden())
780 fMessagesWindow->Show();
782 fMessagesWindow->Activate();
783 fMessagesWindow->Unlock();
791 BWindow::MessageReceived( p_message );
796 /*****************************************************************************
797 * InterfaceWindow::QuitRequested
798 *****************************************************************************/
799 bool InterfaceWindow::QuitRequested()
803 playlist_Stop( p_playlist );
805 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
809 vlc_object_kill( p_intf );
814 /*****************************************************************************
815 * InterfaceWindow::UpdateInterface
816 *****************************************************************************/
817 void InterfaceWindow::UpdateInterface()
821 p_input = (input_thread_t *)
822 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
824 else if( p_input->b_dead )
826 vlc_object_release( p_input );
830 /* Get ready to update the interface */
831 if( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) != B_OK )
836 if( b_playlist_update )
839 if( fPlaylistWindow->Lock() )
841 fPlaylistWindow->UpdatePlaylist( true );
842 fPlaylistWindow->Unlock();
843 b_playlist_update = false;
846 p_mediaControl->SetEnabled( !playlist_IsEmpty( p_playlist ) );
852 p_mediaControl->SetEnabled( true );
853 bool hasTitles = !var_Get( p_input, "title", &val );
854 bool hasChapters = !var_Get( p_input, "chapter", &val );
855 p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
856 var_GetInteger( p_input, "rate" ) );
857 var_Get( p_input, "position", &val );
858 p_mediaControl->SetProgress( val.f_float );
859 _SetMenusEnabled( true, hasChapters, hasTitles );
860 _UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
862 // enable/disable skip buttons
866 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
867 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
870 audio_volume_t i_volume;
871 aout_VolumeGet( p_intf, &i_volume );
872 p_mediaControl->SetAudioEnabled( true );
873 p_mediaControl->SetMuted( i_volume );
877 p_mediaControl->SetAudioEnabled( false );
879 _SetMenusEnabled( false );
881 if( !playlist_IsEmpty( p_playlist ) )
883 p_mediaControl->SetProgress( 0 );
886 // enable/disable skip buttons
889 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
890 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
895 p_mediaControl->SetEnabled( false );
900 fLastUpdateTime = system_time();
903 /*****************************************************************************
904 * InterfaceWindow::UpdatePlaylist
905 *****************************************************************************/
907 InterfaceWindow::UpdatePlaylist()
909 b_playlist_update = true;
912 /*****************************************************************************
913 * InterfaceWindow::IsStopped
914 *****************************************************************************/
916 InterfaceWindow::IsStopped() const
918 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
921 /*****************************************************************************
922 * InterfaceWindow::_SetMenusEnabled
923 *****************************************************************************/
925 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
932 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
934 if ( fNextChapterMI->IsEnabled() != hasChapters )
935 fNextChapterMI->SetEnabled( hasChapters );
936 if ( fPrevChapterMI->IsEnabled() != hasChapters )
937 fPrevChapterMI->SetEnabled( hasChapters );
938 if ( fChapterMenu->IsEnabled() != hasChapters )
939 fChapterMenu->SetEnabled( hasChapters );
940 if ( fNextTitleMI->IsEnabled() != hasTitles )
941 fNextTitleMI->SetEnabled( hasTitles );
942 if ( fPrevTitleMI->IsEnabled() != hasTitles )
943 fPrevTitleMI->SetEnabled( hasTitles );
944 if ( fTitleMenu->IsEnabled() != hasTitles )
945 fTitleMenu->SetEnabled( hasTitles );
946 if ( fAudioMenu->IsEnabled() != hasFile )
947 fAudioMenu->SetEnabled( hasFile );
948 if ( fNavigationMenu->IsEnabled() != hasFile )
949 fNavigationMenu->SetEnabled( hasFile );
950 if ( fLanguageMenu->IsEnabled() != hasFile )
951 fLanguageMenu->SetEnabled( hasFile );
952 if ( fSubtitlesMenu->IsEnabled() != hasFile )
953 fSubtitlesMenu->SetEnabled( hasFile );
954 if ( fSpeedMenu->IsEnabled() != hasFile )
955 fSpeedMenu->SetEnabled( hasFile );
960 /*****************************************************************************
961 * InterfaceWindow::_UpdateSpeedMenu
962 *****************************************************************************/
964 InterfaceWindow::_UpdateSpeedMenu( int rate )
966 BMenuItem * toMark = NULL;
970 case ( INPUT_RATE_DEFAULT * 8 ):
974 case ( INPUT_RATE_DEFAULT * 4 ):
978 case ( INPUT_RATE_DEFAULT * 2 ):
982 case ( INPUT_RATE_DEFAULT ):
986 case ( INPUT_RATE_DEFAULT / 2 ):
990 case ( INPUT_RATE_DEFAULT / 4 ):
994 case ( INPUT_RATE_DEFAULT / 8 ):
999 if ( toMark && !toMark->IsMarked() )
1001 toMark->SetMarked( true );
1005 /*****************************************************************************
1006 * InterfaceWindow::_ShowFilePanel
1007 *****************************************************************************/
1009 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
1013 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
1014 B_FILE_NODE | B_DIRECTORY_NODE );
1015 fFilePanel->SetTarget( this );
1017 fFilePanel->Window()->SetTitle( windowTitle );
1018 BMessage message( command );
1019 fFilePanel->SetMessage( &message );
1020 if ( !fFilePanel->IsShowing() )
1022 fFilePanel->Refresh();
1029 set_window_pos( BWindow* window, BRect frame )
1031 // sanity checks: make sure window is not too big/small
1032 // and that it's not off-screen
1033 float minWidth, maxWidth, minHeight, maxHeight;
1034 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1036 make_sure_frame_is_within_limits( frame,
1037 minWidth, minHeight, maxWidth, maxHeight );
1038 if ( make_sure_frame_is_on_screen( frame ) )
1040 window->MoveTo( frame.LeftTop() );
1041 window->ResizeTo( frame.Width(), frame.Height() );
1047 launch_window( BWindow* window, bool showing )
1049 if ( window->Lock() )
1053 if ( window->IsHidden() )
1058 if ( !window->IsHidden() )
1065 /*****************************************************************************
1066 * InterfaceWindow::_RestoreSettings
1067 *****************************************************************************/
1069 InterfaceWindow::_RestoreSettings()
1071 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1074 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1075 set_window_pos( this, frame );
1077 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1078 set_window_pos( fPlaylistWindow, frame );
1080 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1081 set_window_pos( fMessagesWindow, frame );
1082 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1084 /* FIXME: Preferences resizing doesn't work correctly yet */
1085 frame.right = frame.left + fPreferencesWindow->Frame().Width();
1086 frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
1087 set_window_pos( fPreferencesWindow, frame );
1092 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1093 launch_window( fPlaylistWindow, showing );
1095 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1096 launch_window( fMessagesWindow, showing );
1097 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1098 launch_window( fPreferencesWindow, showing );
1101 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1102 fPlaylistWindow->SetDisplayMode( displayMode );
1107 /*****************************************************************************
1108 * InterfaceWindow::_StoreSettings
1109 *****************************************************************************/
1111 InterfaceWindow::_StoreSettings()
1113 /* Save the volume */
1114 config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
1115 config_SaveConfigFile( p_intf, "main" );
1117 /* Save the windows positions */
1118 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1119 fSettings->AddRect( "main frame", Frame() );
1121 if ( fPlaylistWindow->Lock() )
1123 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1124 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1125 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1126 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1127 fPlaylistWindow->Unlock();
1130 if ( fMessagesWindow->Lock() )
1132 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1133 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1134 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1135 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1136 fMessagesWindow->Unlock();
1138 if ( fPreferencesWindow->Lock() )
1140 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1141 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1142 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1143 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1144 fPreferencesWindow->Unlock();
1147 uint32 displayMode = fPlaylistWindow->DisplayMode();
1148 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1149 fSettings->AddInt32( "playlist display mode", displayMode );
1151 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1155 /*****************************************************************************
1157 *****************************************************************************/
1158 CDMenu::CDMenu(const char *name)
1163 /*****************************************************************************
1165 *****************************************************************************/
1170 /*****************************************************************************
1171 * CDMenu::AttachedToWindow
1172 *****************************************************************************/
1173 void CDMenu::AttachedToWindow(void)
1176 while ( BMenuItem* item = RemoveItem( 0L ) )
1178 GetCD( "/dev/disk" );
1179 BMenu::AttachedToWindow();
1182 /*****************************************************************************
1184 *****************************************************************************/
1185 int CDMenu::GetCD( const char *directory )
1187 BVolumeRoster volRoster;
1190 status_t status = volRoster.GetNextVolume( &vol );
1191 while ( status == B_NO_ERROR )
1196 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1199 BMessage* msg = new BMessage( OPEN_DVD );
1200 msg->AddString( "device", deviceName.String() );
1201 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1205 status = volRoster.GetNextVolume( &vol );
1210 /*****************************************************************************
1211 * LanguageMenu::LanguageMenu
1212 *****************************************************************************/
1213 LanguageMenu::LanguageMenu( intf_thread_t * _p_intf, const char * psz_name,
1214 char * _psz_variable )
1218 psz_variable = strdup( _psz_variable );
1221 /*****************************************************************************
1222 * LanguageMenu::~LanguageMenu
1223 *****************************************************************************/
1224 LanguageMenu::~LanguageMenu()
1226 free( psz_variable );
1229 /*****************************************************************************
1230 * LanguageMenu::AttachedToWindow
1231 *****************************************************************************/
1232 void LanguageMenu::AttachedToWindow()
1237 while( ( item = RemoveItem( 0L ) ) )
1242 SetRadioMode( true );
1244 input_thread_t * p_input = (input_thread_t *)
1245 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1251 vlc_value_t val_list, text_list;
1255 i_current = var_GetInteger( p_input, psz_variable );
1256 var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list );
1257 for( int i = 0; i < val_list.p_list->i_count; i++ )
1259 message = new BMessage( SELECT_CHANNEL );
1260 message->AddInt32( psz_variable, val_list.p_list->p_values[i].i_int );
1261 item = new BMenuItem( text_list.p_list->p_values[i].psz_string, message );
1262 if( val_list.p_list->p_values[i].i_int == i_current )
1264 item->SetMarked( true );
1268 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
1270 vlc_object_release( p_input );
1272 BMenu::AttachedToWindow();
1275 /*****************************************************************************
1276 * TitleMenu::TitleMenu
1277 *****************************************************************************/
1278 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1280 p_intf( p_interface )
1284 /*****************************************************************************
1285 * TitleMenu::~TitleMenu
1286 *****************************************************************************/
1287 TitleMenu::~TitleMenu()
1291 /*****************************************************************************
1292 * TitleMenu::AttachedToWindow
1293 *****************************************************************************/
1294 void TitleMenu::AttachedToWindow()
1297 while( ( item = RemoveItem( 0L ) ) )
1302 input_thread_t * p_input;
1303 p_input = (input_thread_t *)
1304 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1312 if( !var_Get( p_input, "title", &val ) )
1314 vlc_value_t val_list, text_list;
1315 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1316 &val_list, &text_list );
1318 for( int i = 0; i < val_list.p_list->i_count; i++ )
1320 message = new BMessage( TOGGLE_TITLE );
1321 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1322 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1324 if( val_list.p_list->p_values[i].i_int == val.i_int )
1326 item->SetMarked( true );
1331 var_Change( p_input, "title", VLC_VAR_FREELIST,
1332 &val_list, &text_list );
1334 vlc_object_release( p_input );
1335 BMenu::AttachedToWindow();
1339 /*****************************************************************************
1340 * ChapterMenu::ChapterMenu
1341 *****************************************************************************/
1342 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1344 p_intf( p_interface )
1348 /*****************************************************************************
1349 * ChapterMenu::~ChapterMenu
1350 *****************************************************************************/
1351 ChapterMenu::~ChapterMenu()
1355 /*****************************************************************************
1356 * ChapterMenu::AttachedToWindow
1357 *****************************************************************************/
1358 void ChapterMenu::AttachedToWindow()
1361 while( ( item = RemoveItem( 0L ) ) )
1366 input_thread_t * p_input;
1367 p_input = (input_thread_t *)
1368 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1376 if( !var_Get( p_input, "chapter", &val ) )
1378 vlc_value_t val_list, text_list;
1379 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1380 &val_list, &text_list );
1382 for( int i = 0; i < val_list.p_list->i_count; i++ )
1384 message = new BMessage( TOGGLE_CHAPTER );
1385 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1386 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1388 if( val_list.p_list->p_values[i].i_int == val.i_int )
1390 item->SetMarked( true );
1395 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
1396 &val_list, &text_list );
1398 vlc_object_release( p_input );
1399 BMenu::AttachedToWindow();
1403 /*****************************************************************************
1405 *****************************************************************************/
1407 load_settings( BMessage* message, const char* fileName, const char* folder )
1409 status_t ret = B_BAD_VALUE;
1413 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1415 // passing folder is optional
1417 ret = path.Append( folder );
1418 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1420 BFile file( path.Path(), B_READ_ONLY );
1421 if ( ( ret = file.InitCheck() ) == B_OK )
1423 ret = message->Unflatten( &file );
1432 /*****************************************************************************
1434 *****************************************************************************/
1436 save_settings( BMessage* message, const char* fileName, const char* folder )
1438 status_t ret = B_BAD_VALUE;
1442 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1444 // passing folder is optional
1445 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1446 ret = create_directory( path.Path(), 0777 );
1447 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1449 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1450 if ( ( ret = file.InitCheck() ) == B_OK )
1452 ret = message->Flatten( &file );