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>
43 #include <vlc_interface.h>
45 /* BeOS interface headers */
47 #include "MediaControlView.h"
48 #include "PlayListWindow.h"
49 #include "PreferencesWindow.h"
50 #include "MessagesWindow.h"
51 #include "InterfaceWindow.h"
53 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
54 #define INTERFACE_LOCKING_TIMEOUT 5000
56 // make_sure_frame_is_on_screen
58 make_sure_frame_is_on_screen( BRect& frame )
60 BScreen screen( B_MAIN_SCREEN_ID );
61 if (frame.IsValid() && screen.IsValid()) {
62 if (!screen.Frame().Contains(frame)) {
63 // make sure frame fits in the screen
64 if (frame.Width() > screen.Frame().Width())
65 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
66 if (frame.Height() > screen.Frame().Height())
67 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
68 // frame is now at the most the size of the screen
69 if (frame.right > screen.Frame().right)
70 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
71 if (frame.bottom > screen.Frame().bottom)
72 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
73 if (frame.left < screen.Frame().left)
74 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
75 if (frame.top < screen.Frame().top)
76 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
83 // make_sure_frame_is_within_limits
85 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
86 float maxWidth, float maxHeight )
88 if ( frame.Width() < minWidth )
89 frame.right = frame.left + minWidth;
90 if ( frame.Height() < minHeight )
91 frame.bottom = frame.top + minHeight;
92 if ( frame.Width() > maxWidth )
93 frame.right = frame.left + maxWidth;
94 if ( frame.Height() > maxHeight )
95 frame.bottom = frame.top + maxHeight;
100 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
102 bool success = false;
106 char name[B_FILE_NAME_LENGTH];
107 if ( volume.GetName( name ) >= B_OK ) // disk is currently mounted
110 dev_t dev = volume.Device();
112 if ( fs_stat_dev( dev, &info ) == B_OK )
115 deviceName = info.device_name;
116 if ( volume.IsReadOnly() )
118 int i_dev = open( info.device_name, O_RDONLY );
122 if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
123 isCDROM = ( g.device_type == B_CD );
132 // collect_folder_contents
134 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
136 while ( dir.GetNextEntry( &entry, true ) == B_OK )
138 if ( !entry.IsDirectory() )
141 // since the directory will give us the entries in reverse order,
142 // we put them each at the same index, effectively reversing the
143 // items while adding them
144 if ( entry.GetPath( &path ) == B_OK )
146 BString* string = new BString( path.Path() );
147 if ( !list.AddItem( string, 0 ) )
148 delete string; // at least don't leak
155 // ask user if we should parse sub-folders as well
156 BAlert* alert = new BAlert( "sub-folders?",
157 _("Open files from all sub-folders as well?"),
158 _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL,
160 int32 buttonIndex = alert->Go();
161 deep = buttonIndex == 1;
163 // never delete BAlerts!!
167 BDirectory subDir( &entry );
168 if ( subDir.InitCheck() == B_OK )
169 collect_folder_contents( subDir, list,
170 deep, asked, entry );
176 static int PlaylistChanged( vlc_object_t *p_this, const char * psz_variable,
177 vlc_value_t old_val, vlc_value_t new_val,
180 InterfaceWindow * w = (InterfaceWindow *) param;
185 /*****************************************************************************
187 *****************************************************************************/
189 InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
191 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
192 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
194 /* Initializations */
200 fLastUpdateTime( system_time() ),
201 fSettings( new BMessage( 'sett' ) )
203 p_playlist = (playlist_t *)
204 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
206 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
207 var_AddCallback( p_playlist, "item-change", PlaylistChanged, this );
208 var_AddCallback( p_playlist, "item-append", PlaylistChanged, this );
209 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, this );
210 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, this );
213 #define ADD_ELLIPSIS( a ) \
214 memset( psz_tmp, 0, 1024 ); \
215 snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );
218 BRect screen_rect = screen.Frame();
220 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
221 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
222 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
223 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
224 fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
225 window_rect.Set( screen_rect.right - 500,
226 screen_rect.top + 50,
227 screen_rect.right - 150,
228 screen_rect.top + 250 );
230 fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
231 window_rect.Set( screen_rect.right - 550,
232 screen_rect.top + 300,
233 screen_rect.right - 150,
234 screen_rect.top + 500 );
236 fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
238 // the media control view
239 p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );
240 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
243 p_mediaControl->GetPreferredSize( &width, &height );
245 // set up the main menu
246 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
247 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
249 // make menu bar resize to correct height
250 float menuWidth, menuHeight;
251 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
252 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
253 // take care of proper size for ourself
254 height += fMenuBar->Bounds().Height();
255 ResizeTo( width, height );
257 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
258 AddChild( fMenuBar );
262 BMenu* fileMenu = new BMenu( _("File") );
263 fMenuBar->AddItem( fileMenu );
264 ADD_ELLIPSIS( _("Open File") );
265 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );
266 fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
267 ADD_ELLIPSIS( _("Open Subtitles") );
268 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );
270 fileMenu->AddSeparatorItem();
271 ADD_ELLIPSIS( _("About") );
272 BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');
273 item->SetTarget( be_app );
274 fileMenu->AddItem( item );
275 fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
277 fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );
278 fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );
280 /* Add the Audio menu */
281 fAudioMenu = new BMenu( _("Audio") );
282 fMenuBar->AddItem ( fAudioMenu );
283 fAudioMenu->AddItem( fLanguageMenu );
284 fAudioMenu->AddItem( fSubtitlesMenu );
286 fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
287 fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
288 fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );
289 fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );
291 /* Add the Navigation menu */
292 fNavigationMenu = new BMenu( _("Navigation") );
293 fMenuBar->AddItem( fNavigationMenu );
294 fNavigationMenu->AddItem( fPrevTitleMI );
295 fNavigationMenu->AddItem( fNextTitleMI );
296 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
297 fNavigationMenu->AddSeparatorItem();
298 fNavigationMenu->AddItem( fPrevChapterMI );
299 fNavigationMenu->AddItem( fNextChapterMI );
300 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
302 /* Add the Speed menu */
303 fSpeedMenu = new BMenu( _("Speed") );
304 fSpeedMenu->SetRadioMode( true );
306 fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
308 fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
310 fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
312 fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
314 fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
316 fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
318 fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
319 fMenuBar->AddItem( fSpeedMenu );
321 /* Add the Show menu */
322 fShowMenu = new BMenu( _("Window") );
324 ADD_ELLIPSIS( _("Playlist") );
325 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );
327 ADD_ELLIPSIS( _("Messages") );
328 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );
329 ADD_ELLIPSIS( _("Preferences") );
330 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );
331 fMenuBar->AddItem( fShowMenu );
333 // add the media control view after the menubar is complete
334 // because it will set the window size limits in AttachedToWindow()
335 // and the menubar needs to report the correct PreferredSize()
336 AddChild( p_mediaControl );
338 /* Prepare fow showing */
339 _SetMenusEnabled( false );
340 p_mediaControl->SetEnabled( false );
347 InterfaceWindow::~InterfaceWindow()
351 vlc_object_release( p_input );
355 vlc_object_release( p_playlist );
358 if( fPlaylistWindow )
360 fPlaylistWindow->ReallyQuit();
363 if( fMessagesWindow )
365 fMessagesWindow->ReallyQuit();
367 if( fPreferencesWindow )
369 fPreferencesWindow->ReallyQuit();
375 /*****************************************************************************
376 * InterfaceWindow::FrameResized
377 *****************************************************************************/
379 InterfaceWindow::FrameResized(float width, float height)
382 fMenuBar->MoveTo(r.LeftTop());
383 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
384 r.top += fMenuBar->Bounds().Height() + 1.0;
385 p_mediaControl->MoveTo(r.LeftTop());
386 p_mediaControl->ResizeTo(r.Width(), r.Height());
389 /*****************************************************************************
390 * InterfaceWindow::MessageReceived
391 *****************************************************************************/
392 void InterfaceWindow::MessageReceived( BMessage * p_message )
394 switch( p_message->what )
396 case B_ABOUT_REQUESTED:
400 alert = new BAlert( "VLC media player" VERSION,
401 "VLC media player" VERSION " (BeOS interface)\n\n"
402 "The VideoLAN team <videolan@videolan.org>\n"
403 "http://www.videolan.org/", _("OK") );
411 _ShowFilePanel( B_REFS_RECEIVED, _("VLC media player: Open Media Files") );
415 _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
419 if (fPlaylistWindow->Lock())
421 if (fPlaylistWindow->IsHidden())
422 fPlaylistWindow->Show();
424 fPlaylistWindow->Activate();
425 fPlaylistWindow->Unlock();
431 const char * psz_device;
433 p_message->FindString( "device", &psz_device ) == B_OK )
436 memset( psz_uri, 0, 1024 );
437 snprintf( psz_uri, 1024, "dvdnav:%s", psz_device );
438 playlist_Add( p_playlist, psz_uri, psz_device,
439 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE );
445 case SUBFILE_RECEIVED:
448 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
451 if ( path.InitCheck() == B_OK )
452 config_PutPsz( p_intf, "sub-file", path.Path() );
460 playlist_Stop( p_playlist );
462 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
469 val.i_int = PLAYING_S;
472 var_Get( p_input, "state", &val );
474 if( p_input && val.i_int != PAUSE_S )
477 var_Set( p_input, "state", val );
481 playlist_Play( p_playlist );
488 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
495 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
502 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
509 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
516 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
523 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
530 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
535 /* handled by semaphores */
539 aout_VolumeSet( p_intf, p_mediaControl->GetVolume() );
543 aout_VolumeMute( p_intf, NULL );
551 if( p_message->FindInt32( "audio-es", &channel ) == B_OK )
553 var_SetInteger( p_input, "audio-es", channel );
555 else if( p_message->FindInt32( "spu-es", &channel ) == B_OK )
557 var_SetInteger( p_input, "spu-es", channel );
566 var_SetVoid( p_input, "prev-title" );
573 var_SetVoid( p_input, "next-title" );
581 p_message->FindInt32( "index", &index ) == B_OK )
583 var_SetInteger( p_input, "title", index );
591 var_SetVoid( p_input, "prev-chapter" );
598 var_SetVoid( p_input, "next-chapter" );
606 p_message->FindInt32( "index", &index ) == B_OK )
608 var_SetInteger( p_input, "chapter", index );
616 playlist_Prev( p_playlist );
623 playlist_Next( p_playlist );
632 /* First try to go to previous chapter */
633 if( !var_Get( p_input, "chapter", &val ) )
637 var_SetVoid( p_input, "prev-chapter" );
642 /* Try to go to previous title */
643 if( !var_Get( p_input, "title", &val ) )
647 var_SetVoid( p_input, "prev-title" );
652 /* Try to go to previous file */
655 playlist_Prev( p_playlist );
663 vlc_value_t val, val_list;
665 /* First try to go to next chapter */
666 if( !var_Get( p_input, "chapter", &val ) )
668 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
670 if( val_list.p_list->i_count > val.i_int )
672 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
674 var_SetVoid( p_input, "next-chapter" );
677 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
681 /* Try to go to next title */
682 if( !var_Get( p_input, "title", &val ) )
684 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
686 if( val_list.p_list->i_count > val.i_int )
688 var_Change( p_input, "title", VLC_VAR_FREELIST,
690 var_SetVoid( p_input, "next-title" );
693 var_Change( p_input, "title", VLC_VAR_FREELIST,
697 /* Try to go to next file */
700 playlist_Next( p_playlist );
705 // drag'n'drop and system messages
707 // convert soundplay drag'n'drop message (containing paths)
708 // to normal message (containing refs)
711 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
714 if ( get_ref_for_path( path, &ref ) == B_OK )
715 p_message->AddRef( "refs", &ref );
719 case B_REFS_RECEIVED:
722 /* file(s) opened by the File menu -> append to the playlist;
723 file(s) opened by drag & drop -> replace playlist;
724 file(s) opened by 'shift' + drag & drop -> append */
728 if( p_message->GetInfo( "refs", &dummy, &count ) != B_OK ||
734 vlc_bool_t b_remove = ( p_message->WasDropped() &&
735 !( modifiers() & B_SHIFT_KEY ) );
737 if( b_remove && p_playlist )
739 playlist_Clear( p_playlist, VLC_TRUE );
743 for( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
747 /* TODO: find out if this is a DVD icon */
751 playlist_Add( p_playlist, path.Path(), NULL,
752 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE );
760 case OPEN_PREFERENCES:
762 if( fPreferencesWindow->Lock() )
764 if (fPreferencesWindow->IsHidden())
765 fPreferencesWindow->Show();
767 fPreferencesWindow->Activate();
768 fPreferencesWindow->Unlock();
775 if( fMessagesWindow->Lock() )
777 if (fMessagesWindow->IsHidden())
778 fMessagesWindow->Show();
780 fMessagesWindow->Activate();
781 fMessagesWindow->Unlock();
789 BWindow::MessageReceived( p_message );
794 /*****************************************************************************
795 * InterfaceWindow::QuitRequested
796 *****************************************************************************/
797 bool InterfaceWindow::QuitRequested()
801 playlist_Stop( p_playlist );
803 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
812 /*****************************************************************************
813 * InterfaceWindow::UpdateInterface
814 *****************************************************************************/
815 void InterfaceWindow::UpdateInterface()
819 p_input = (input_thread_t *)
820 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
822 else if( p_input->b_dead )
824 vlc_object_release( p_input );
828 /* Get ready to update the interface */
829 if( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) != B_OK )
834 if( b_playlist_update )
837 if( fPlaylistWindow->Lock() )
839 fPlaylistWindow->UpdatePlaylist( true );
840 fPlaylistWindow->Unlock();
841 b_playlist_update = false;
844 p_mediaControl->SetEnabled( !playlist_IsEmpty( p_playlist ) );
850 p_mediaControl->SetEnabled( true );
851 bool hasTitles = !var_Get( p_input, "title", &val );
852 bool hasChapters = !var_Get( p_input, "chapter", &val );
853 p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
854 var_GetInteger( p_input, "rate" ) );
855 var_Get( p_input, "position", &val );
856 p_mediaControl->SetProgress( val.f_float );
857 _SetMenusEnabled( true, hasChapters, hasTitles );
858 _UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
860 // enable/disable skip buttons
864 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
865 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
868 audio_volume_t i_volume;
869 aout_VolumeGet( p_intf, &i_volume );
870 p_mediaControl->SetAudioEnabled( true );
871 p_mediaControl->SetMuted( i_volume );
875 p_mediaControl->SetAudioEnabled( false );
877 _SetMenusEnabled( false );
879 if( !playlist_IsEmpty( p_playlist ) )
881 p_mediaControl->SetProgress( 0 );
884 // enable/disable skip buttons
887 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
888 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
893 p_mediaControl->SetEnabled( false );
898 fLastUpdateTime = system_time();
901 /*****************************************************************************
902 * InterfaceWindow::UpdatePlaylist
903 *****************************************************************************/
905 InterfaceWindow::UpdatePlaylist()
907 b_playlist_update = true;
910 /*****************************************************************************
911 * InterfaceWindow::IsStopped
912 *****************************************************************************/
914 InterfaceWindow::IsStopped() const
916 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
919 /*****************************************************************************
920 * InterfaceWindow::_SetMenusEnabled
921 *****************************************************************************/
923 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
930 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
932 if ( fNextChapterMI->IsEnabled() != hasChapters )
933 fNextChapterMI->SetEnabled( hasChapters );
934 if ( fPrevChapterMI->IsEnabled() != hasChapters )
935 fPrevChapterMI->SetEnabled( hasChapters );
936 if ( fChapterMenu->IsEnabled() != hasChapters )
937 fChapterMenu->SetEnabled( hasChapters );
938 if ( fNextTitleMI->IsEnabled() != hasTitles )
939 fNextTitleMI->SetEnabled( hasTitles );
940 if ( fPrevTitleMI->IsEnabled() != hasTitles )
941 fPrevTitleMI->SetEnabled( hasTitles );
942 if ( fTitleMenu->IsEnabled() != hasTitles )
943 fTitleMenu->SetEnabled( hasTitles );
944 if ( fAudioMenu->IsEnabled() != hasFile )
945 fAudioMenu->SetEnabled( hasFile );
946 if ( fNavigationMenu->IsEnabled() != hasFile )
947 fNavigationMenu->SetEnabled( hasFile );
948 if ( fLanguageMenu->IsEnabled() != hasFile )
949 fLanguageMenu->SetEnabled( hasFile );
950 if ( fSubtitlesMenu->IsEnabled() != hasFile )
951 fSubtitlesMenu->SetEnabled( hasFile );
952 if ( fSpeedMenu->IsEnabled() != hasFile )
953 fSpeedMenu->SetEnabled( hasFile );
958 /*****************************************************************************
959 * InterfaceWindow::_UpdateSpeedMenu
960 *****************************************************************************/
962 InterfaceWindow::_UpdateSpeedMenu( int rate )
964 BMenuItem * toMark = NULL;
968 case ( INPUT_RATE_DEFAULT * 8 ):
972 case ( INPUT_RATE_DEFAULT * 4 ):
976 case ( INPUT_RATE_DEFAULT * 2 ):
980 case ( INPUT_RATE_DEFAULT ):
984 case ( INPUT_RATE_DEFAULT / 2 ):
988 case ( INPUT_RATE_DEFAULT / 4 ):
992 case ( INPUT_RATE_DEFAULT / 8 ):
997 if ( toMark && !toMark->IsMarked() )
999 toMark->SetMarked( true );
1003 /*****************************************************************************
1004 * InterfaceWindow::_ShowFilePanel
1005 *****************************************************************************/
1007 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
1011 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
1012 B_FILE_NODE | B_DIRECTORY_NODE );
1013 fFilePanel->SetTarget( this );
1015 fFilePanel->Window()->SetTitle( windowTitle );
1016 BMessage message( command );
1017 fFilePanel->SetMessage( &message );
1018 if ( !fFilePanel->IsShowing() )
1020 fFilePanel->Refresh();
1027 set_window_pos( BWindow* window, BRect frame )
1029 // sanity checks: make sure window is not too big/small
1030 // and that it's not off-screen
1031 float minWidth, maxWidth, minHeight, maxHeight;
1032 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1034 make_sure_frame_is_within_limits( frame,
1035 minWidth, minHeight, maxWidth, maxHeight );
1036 if ( make_sure_frame_is_on_screen( frame ) )
1038 window->MoveTo( frame.LeftTop() );
1039 window->ResizeTo( frame.Width(), frame.Height() );
1045 launch_window( BWindow* window, bool showing )
1047 if ( window->Lock() )
1051 if ( window->IsHidden() )
1056 if ( !window->IsHidden() )
1063 /*****************************************************************************
1064 * InterfaceWindow::_RestoreSettings
1065 *****************************************************************************/
1067 InterfaceWindow::_RestoreSettings()
1069 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1072 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1073 set_window_pos( this, frame );
1075 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1076 set_window_pos( fPlaylistWindow, frame );
1078 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1079 set_window_pos( fMessagesWindow, frame );
1080 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1082 /* FIXME: Preferences resizing doesn't work correctly yet */
1083 frame.right = frame.left + fPreferencesWindow->Frame().Width();
1084 frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
1085 set_window_pos( fPreferencesWindow, frame );
1090 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1091 launch_window( fPlaylistWindow, showing );
1093 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1094 launch_window( fMessagesWindow, showing );
1095 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1096 launch_window( fPreferencesWindow, showing );
1099 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1100 fPlaylistWindow->SetDisplayMode( displayMode );
1105 /*****************************************************************************
1106 * InterfaceWindow::_StoreSettings
1107 *****************************************************************************/
1109 InterfaceWindow::_StoreSettings()
1111 /* Save the volume */
1112 config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
1113 config_SaveConfigFile( p_intf, "main" );
1115 /* Save the windows positions */
1116 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1117 fSettings->AddRect( "main frame", Frame() );
1119 if ( fPlaylistWindow->Lock() )
1121 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1122 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1123 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1124 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1125 fPlaylistWindow->Unlock();
1128 if ( fMessagesWindow->Lock() )
1130 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1131 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1132 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1133 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1134 fMessagesWindow->Unlock();
1136 if ( fPreferencesWindow->Lock() )
1138 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1139 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1140 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1141 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1142 fPreferencesWindow->Unlock();
1145 uint32 displayMode = fPlaylistWindow->DisplayMode();
1146 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1147 fSettings->AddInt32( "playlist display mode", displayMode );
1149 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1153 /*****************************************************************************
1155 *****************************************************************************/
1156 CDMenu::CDMenu(const char *name)
1161 /*****************************************************************************
1163 *****************************************************************************/
1168 /*****************************************************************************
1169 * CDMenu::AttachedToWindow
1170 *****************************************************************************/
1171 void CDMenu::AttachedToWindow(void)
1174 while ( BMenuItem* item = RemoveItem( 0L ) )
1176 GetCD( "/dev/disk" );
1177 BMenu::AttachedToWindow();
1180 /*****************************************************************************
1182 *****************************************************************************/
1183 int CDMenu::GetCD( const char *directory )
1185 BVolumeRoster volRoster;
1188 status_t status = volRoster.GetNextVolume( &vol );
1189 while ( status == B_NO_ERROR )
1194 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1197 BMessage* msg = new BMessage( OPEN_DVD );
1198 msg->AddString( "device", deviceName.String() );
1199 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1203 status = volRoster.GetNextVolume( &vol );
1208 /*****************************************************************************
1209 * LanguageMenu::LanguageMenu
1210 *****************************************************************************/
1211 LanguageMenu::LanguageMenu( intf_thread_t * _p_intf, const char * psz_name,
1212 char * _psz_variable )
1216 psz_variable = strdup( _psz_variable );
1219 /*****************************************************************************
1220 * LanguageMenu::~LanguageMenu
1221 *****************************************************************************/
1222 LanguageMenu::~LanguageMenu()
1224 free( psz_variable );
1227 /*****************************************************************************
1228 * LanguageMenu::AttachedToWindow
1229 *****************************************************************************/
1230 void LanguageMenu::AttachedToWindow()
1235 while( ( item = RemoveItem( 0L ) ) )
1240 SetRadioMode( true );
1242 input_thread_t * p_input = (input_thread_t *)
1243 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1249 vlc_value_t val_list, text_list;
1253 i_current = var_GetInteger( p_input, psz_variable );
1254 var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list );
1255 for( int i = 0; i < val_list.p_list->i_count; i++ )
1257 message = new BMessage( SELECT_CHANNEL );
1258 message->AddInt32( psz_variable, val_list.p_list->p_values[i].i_int );
1259 item = new BMenuItem( text_list.p_list->p_values[i].psz_string, message );
1260 if( val_list.p_list->p_values[i].i_int == i_current )
1262 item->SetMarked( true );
1266 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
1268 vlc_object_release( p_input );
1270 BMenu::AttachedToWindow();
1273 /*****************************************************************************
1274 * TitleMenu::TitleMenu
1275 *****************************************************************************/
1276 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1278 p_intf( p_interface )
1282 /*****************************************************************************
1283 * TitleMenu::~TitleMenu
1284 *****************************************************************************/
1285 TitleMenu::~TitleMenu()
1289 /*****************************************************************************
1290 * TitleMenu::AttachedToWindow
1291 *****************************************************************************/
1292 void TitleMenu::AttachedToWindow()
1295 while( ( item = RemoveItem( 0L ) ) )
1300 input_thread_t * p_input;
1301 p_input = (input_thread_t *)
1302 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1310 if( !var_Get( p_input, "title", &val ) )
1312 vlc_value_t val_list, text_list;
1313 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1314 &val_list, &text_list );
1316 for( int i = 0; i < val_list.p_list->i_count; i++ )
1318 message = new BMessage( TOGGLE_TITLE );
1319 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1320 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1322 if( val_list.p_list->p_values[i].i_int == val.i_int )
1324 item->SetMarked( true );
1329 var_Change( p_input, "title", VLC_VAR_FREELIST,
1330 &val_list, &text_list );
1332 vlc_object_release( p_input );
1333 BMenu::AttachedToWindow();
1337 /*****************************************************************************
1338 * ChapterMenu::ChapterMenu
1339 *****************************************************************************/
1340 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1342 p_intf( p_interface )
1346 /*****************************************************************************
1347 * ChapterMenu::~ChapterMenu
1348 *****************************************************************************/
1349 ChapterMenu::~ChapterMenu()
1353 /*****************************************************************************
1354 * ChapterMenu::AttachedToWindow
1355 *****************************************************************************/
1356 void ChapterMenu::AttachedToWindow()
1359 while( ( item = RemoveItem( 0L ) ) )
1364 input_thread_t * p_input;
1365 p_input = (input_thread_t *)
1366 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1374 if( !var_Get( p_input, "chapter", &val ) )
1376 vlc_value_t val_list, text_list;
1377 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1378 &val_list, &text_list );
1380 for( int i = 0; i < val_list.p_list->i_count; i++ )
1382 message = new BMessage( TOGGLE_CHAPTER );
1383 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1384 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1386 if( val_list.p_list->p_values[i].i_int == val.i_int )
1388 item->SetMarked( true );
1393 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
1394 &val_list, &text_list );
1396 vlc_object_release( p_input );
1397 BMenu::AttachedToWindow();
1401 /*****************************************************************************
1403 *****************************************************************************/
1405 load_settings( BMessage* message, const char* fileName, const char* folder )
1407 status_t ret = B_BAD_VALUE;
1411 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1413 // passing folder is optional
1415 ret = path.Append( folder );
1416 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1418 BFile file( path.Path(), B_READ_ONLY );
1419 if ( ( ret = file.InitCheck() ) == B_OK )
1421 ret = message->Unflatten( &file );
1430 /*****************************************************************************
1432 *****************************************************************************/
1434 save_settings( BMessage* message, const char* fileName, const char* folder )
1436 status_t ret = B_BAD_VALUE;
1440 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1442 // passing folder is optional
1443 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1444 ret = create_directory( path.Path(), 0777 );
1445 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1447 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1448 if ( ( ret = file.InitCheck() ) == B_OK )
1450 ret = message->Flatten( &file );