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>
42 #include <vlc_interface.h>
44 /* BeOS interface headers */
46 #include "MediaControlView.h"
47 #include "PlayListWindow.h"
48 #include "PreferencesWindow.h"
49 #include "MessagesWindow.h"
50 #include "InterfaceWindow.h"
52 #define INTERFACE_UPDATE_TIMEOUT 80000 // 2 frames if at 25 fps
53 #define INTERFACE_LOCKING_TIMEOUT 5000
55 // make_sure_frame_is_on_screen
57 make_sure_frame_is_on_screen( BRect& frame )
59 BScreen screen( B_MAIN_SCREEN_ID );
60 if (frame.IsValid() && screen.IsValid()) {
61 if (!screen.Frame().Contains(frame)) {
62 // make sure frame fits in the screen
63 if (frame.Width() > screen.Frame().Width())
64 frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
65 if (frame.Height() > screen.Frame().Height())
66 frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
67 // frame is now at the most the size of the screen
68 if (frame.right > screen.Frame().right)
69 frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
70 if (frame.bottom > screen.Frame().bottom)
71 frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
72 if (frame.left < screen.Frame().left)
73 frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
74 if (frame.top < screen.Frame().top)
75 frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
82 // make_sure_frame_is_within_limits
84 make_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,
85 float maxWidth, float maxHeight )
87 if ( frame.Width() < minWidth )
88 frame.right = frame.left + minWidth;
89 if ( frame.Height() < minHeight )
90 frame.bottom = frame.top + minHeight;
91 if ( frame.Width() > maxWidth )
92 frame.right = frame.left + maxWidth;
93 if ( frame.Height() > maxHeight )
94 frame.bottom = frame.top + maxHeight;
99 get_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName )
101 bool success = false;
105 char name[B_FILE_NAME_LENGTH];
106 if ( volume.GetName( name ) >= B_OK ) // disk is currently mounted
109 dev_t dev = volume.Device();
111 if ( fs_stat_dev( dev, &info ) == B_OK )
114 deviceName = info.device_name;
115 if ( volume.IsReadOnly() )
117 int i_dev = open( info.device_name, O_RDONLY );
121 if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )
122 isCDROM = ( g.device_type == B_CD );
131 // collect_folder_contents
133 collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry )
135 while ( dir.GetNextEntry( &entry, true ) == B_OK )
137 if ( !entry.IsDirectory() )
140 // since the directory will give us the entries in reverse order,
141 // we put them each at the same index, effectively reversing the
142 // items while adding them
143 if ( entry.GetPath( &path ) == B_OK )
145 BString* string = new BString( path.Path() );
146 if ( !list.AddItem( string, 0 ) )
147 delete string; // at least don't leak
154 // ask user if we should parse sub-folders as well
155 BAlert* alert = new BAlert( "sub-folders?",
156 _("Open files from all sub-folders as well?"),
157 _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL,
159 int32 buttonIndex = alert->Go();
160 deep = buttonIndex == 1;
162 // never delete BAlerts!!
166 BDirectory subDir( &entry );
167 if ( subDir.InitCheck() == B_OK )
168 collect_folder_contents( subDir, list,
169 deep, asked, entry );
175 static int PlaylistChanged( vlc_object_t *p_this, const char * psz_variable,
176 vlc_value_t old_val, vlc_value_t new_val,
179 InterfaceWindow * w = (InterfaceWindow *) param;
184 /*****************************************************************************
186 *****************************************************************************/
188 InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,
190 : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
191 B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),
193 /* Initializations */
199 fLastUpdateTime( system_time() ),
200 fSettings( new BMessage( 'sett' ) )
202 p_playlist = (playlist_t *)
203 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
205 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
206 var_AddCallback( p_playlist, "item-change", PlaylistChanged, this );
207 var_AddCallback( p_playlist, "item-append", PlaylistChanged, this );
208 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, this );
209 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, this );
212 #define ADD_ELLIPSIS( a ) \
213 memset( psz_tmp, 0, 1024 ); \
214 snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );
217 BRect screen_rect = screen.Frame();
219 window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,
220 ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,
221 ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,
222 ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );
223 fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );
224 window_rect.Set( screen_rect.right - 500,
225 screen_rect.top + 50,
226 screen_rect.right - 150,
227 screen_rect.top + 250 );
229 fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );
230 window_rect.Set( screen_rect.right - 550,
231 screen_rect.top + 300,
232 screen_rect.right - 150,
233 screen_rect.top + 500 );
235 fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );
237 // the media control view
238 p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );
239 p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
242 p_mediaControl->GetPreferredSize( &width, &height );
244 // set up the main menu
245 fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",
246 B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );
248 // make menu bar resize to correct height
249 float menuWidth, menuHeight;
250 fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );
251 fMenuBar->ResizeTo( width, menuHeight ); // don't change! it's a workarround!
252 // take care of proper size for ourself
253 height += fMenuBar->Bounds().Height();
254 ResizeTo( width, height );
256 p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );
257 AddChild( fMenuBar );
261 BMenu* fileMenu = new BMenu( _("File") );
262 fMenuBar->AddItem( fileMenu );
263 ADD_ELLIPSIS( _("Open File") );
264 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );
265 fileMenu->AddItem( new CDMenu( _("Open Disc") ) );
266 ADD_ELLIPSIS( _("Open Subtitles") );
267 fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );
269 fileMenu->AddSeparatorItem();
270 ADD_ELLIPSIS( _("About") );
271 BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');
272 item->SetTarget( be_app );
273 fileMenu->AddItem( item );
274 fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );
276 fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );
277 fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );
279 /* Add the Audio menu */
280 fAudioMenu = new BMenu( _("Audio") );
281 fMenuBar->AddItem ( fAudioMenu );
282 fAudioMenu->AddItem( fLanguageMenu );
283 fAudioMenu->AddItem( fSubtitlesMenu );
285 fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );
286 fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );
287 fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );
288 fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );
290 /* Add the Navigation menu */
291 fNavigationMenu = new BMenu( _("Navigation") );
292 fMenuBar->AddItem( fNavigationMenu );
293 fNavigationMenu->AddItem( fPrevTitleMI );
294 fNavigationMenu->AddItem( fNextTitleMI );
295 fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );
296 fNavigationMenu->AddSeparatorItem();
297 fNavigationMenu->AddItem( fPrevChapterMI );
298 fNavigationMenu->AddItem( fNextChapterMI );
299 fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );
301 /* Add the Speed menu */
302 fSpeedMenu = new BMenu( _("Speed") );
303 fSpeedMenu->SetRadioMode( true );
305 fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );
307 fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );
309 fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );
311 fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );
313 fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );
315 fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );
317 fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );
318 fMenuBar->AddItem( fSpeedMenu );
320 /* Add the Show menu */
321 fShowMenu = new BMenu( _("Window") );
323 ADD_ELLIPSIS( _("Playlist") );
324 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );
326 ADD_ELLIPSIS( _("Messages") );
327 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );
328 ADD_ELLIPSIS( _("Preferences") );
329 fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );
330 fMenuBar->AddItem( fShowMenu );
332 // add the media control view after the menubar is complete
333 // because it will set the window size limits in AttachedToWindow()
334 // and the menubar needs to report the correct PreferredSize()
335 AddChild( p_mediaControl );
337 /* Prepare fow showing */
338 _SetMenusEnabled( false );
339 p_mediaControl->SetEnabled( false );
346 InterfaceWindow::~InterfaceWindow()
350 vlc_object_release( p_input );
354 vlc_object_release( p_playlist );
357 if( fPlaylistWindow )
359 fPlaylistWindow->ReallyQuit();
362 if( fMessagesWindow )
364 fMessagesWindow->ReallyQuit();
366 if( fPreferencesWindow )
368 fPreferencesWindow->ReallyQuit();
374 /*****************************************************************************
375 * InterfaceWindow::FrameResized
376 *****************************************************************************/
378 InterfaceWindow::FrameResized(float width, float height)
381 fMenuBar->MoveTo(r.LeftTop());
382 fMenuBar->ResizeTo(r.Width(), fMenuBar->Bounds().Height());
383 r.top += fMenuBar->Bounds().Height() + 1.0;
384 p_mediaControl->MoveTo(r.LeftTop());
385 p_mediaControl->ResizeTo(r.Width(), r.Height());
388 /*****************************************************************************
389 * InterfaceWindow::MessageReceived
390 *****************************************************************************/
391 void InterfaceWindow::MessageReceived( BMessage * p_message )
393 switch( p_message->what )
395 case B_ABOUT_REQUESTED:
399 alert = new BAlert( "VLC media player" VERSION,
400 "VLC media player" VERSION " (BeOS interface)\n\n"
401 "The VideoLAN team <videolan@videolan.org>\n"
402 "http://www.videolan.org/", _("OK") );
410 _ShowFilePanel( B_REFS_RECEIVED, _("VLC media player: Open Media Files") );
414 _ShowFilePanel( SUBFILE_RECEIVED, _("VLC media player: Open Subtitle File") );
418 if (fPlaylistWindow->Lock())
420 if (fPlaylistWindow->IsHidden())
421 fPlaylistWindow->Show();
423 fPlaylistWindow->Activate();
424 fPlaylistWindow->Unlock();
430 const char * psz_device;
432 p_message->FindString( "device", &psz_device ) == B_OK )
435 memset( psz_uri, 0, 1024 );
436 snprintf( psz_uri, 1024, "dvdnav:%s", psz_device );
437 playlist_Add( p_playlist, psz_uri, psz_device,
438 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE );
444 case SUBFILE_RECEIVED:
447 if( p_message->FindRef( "refs", 0, &ref ) == B_OK )
450 if ( path.InitCheck() == B_OK )
451 config_PutPsz( p_intf, "sub-file", path.Path() );
459 playlist_Stop( p_playlist );
461 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
468 val.i_int = PLAYING_S;
471 var_Get( p_input, "state", &val );
473 if( p_input && val.i_int != PAUSE_S )
476 var_Set( p_input, "state", val );
480 playlist_Play( p_playlist );
487 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
494 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
501 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
508 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
515 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
522 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
529 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
534 /* handled by semaphores */
538 aout_VolumeSet( p_intf, p_mediaControl->GetVolume() );
542 aout_VolumeMute( p_intf, NULL );
550 if( p_message->FindInt32( "audio-es", &channel ) == B_OK )
552 var_SetInteger( p_input, "audio-es", channel );
554 else if( p_message->FindInt32( "spu-es", &channel ) == B_OK )
556 var_SetInteger( p_input, "spu-es", channel );
565 var_SetVoid( p_input, "prev-title" );
572 var_SetVoid( p_input, "next-title" );
580 p_message->FindInt32( "index", &index ) == B_OK )
582 var_SetInteger( p_input, "title", index );
590 var_SetVoid( p_input, "prev-chapter" );
597 var_SetVoid( p_input, "next-chapter" );
605 p_message->FindInt32( "index", &index ) == B_OK )
607 var_SetInteger( p_input, "chapter", index );
615 playlist_Prev( p_playlist );
622 playlist_Next( p_playlist );
631 /* First try to go to previous chapter */
632 if( !var_Get( p_input, "chapter", &val ) )
636 var_SetVoid( p_input, "prev-chapter" );
641 /* Try to go to previous title */
642 if( !var_Get( p_input, "title", &val ) )
646 var_SetVoid( p_input, "prev-title" );
651 /* Try to go to previous file */
654 playlist_Prev( p_playlist );
662 vlc_value_t val, val_list;
664 /* First try to go to next chapter */
665 if( !var_Get( p_input, "chapter", &val ) )
667 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
669 if( val_list.p_list->i_count > val.i_int )
671 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
673 var_SetVoid( p_input, "next-chapter" );
676 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
680 /* Try to go to next title */
681 if( !var_Get( p_input, "title", &val ) )
683 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
685 if( val_list.p_list->i_count > val.i_int )
687 var_Change( p_input, "title", VLC_VAR_FREELIST,
689 var_SetVoid( p_input, "next-title" );
692 var_Change( p_input, "title", VLC_VAR_FREELIST,
696 /* Try to go to next file */
699 playlist_Next( p_playlist );
704 // drag'n'drop and system messages
706 // convert soundplay drag'n'drop message (containing paths)
707 // to normal message (containing refs)
710 for ( int32 i = 0; p_message->FindString( "path", i, &path ) == B_OK; i++ )
713 if ( get_ref_for_path( path, &ref ) == B_OK )
714 p_message->AddRef( "refs", &ref );
718 case B_REFS_RECEIVED:
721 /* file(s) opened by the File menu -> append to the playlist;
722 file(s) opened by drag & drop -> replace playlist;
723 file(s) opened by 'shift' + drag & drop -> append */
727 if( p_message->GetInfo( "refs", &dummy, &count ) != B_OK ||
733 vlc_bool_t b_remove = ( p_message->WasDropped() &&
734 !( modifiers() & B_SHIFT_KEY ) );
736 if( b_remove && p_playlist )
738 playlist_Clear( p_playlist, VLC_TRUE );
742 for( int i = 0; p_message->FindRef( "refs", i, &ref ) == B_OK; i++ )
746 /* TODO: find out if this is a DVD icon */
750 playlist_Add( p_playlist, path.Path(), NULL,
751 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE );
759 case OPEN_PREFERENCES:
761 if( fPreferencesWindow->Lock() )
763 if (fPreferencesWindow->IsHidden())
764 fPreferencesWindow->Show();
766 fPreferencesWindow->Activate();
767 fPreferencesWindow->Unlock();
774 if( fMessagesWindow->Lock() )
776 if (fMessagesWindow->IsHidden())
777 fMessagesWindow->Show();
779 fMessagesWindow->Activate();
780 fMessagesWindow->Unlock();
788 BWindow::MessageReceived( p_message );
793 /*****************************************************************************
794 * InterfaceWindow::QuitRequested
795 *****************************************************************************/
796 bool InterfaceWindow::QuitRequested()
800 playlist_Stop( p_playlist );
802 p_mediaControl->SetStatus(-1, INPUT_RATE_DEFAULT);
806 vlc_object_kill( p_intf );
811 /*****************************************************************************
812 * InterfaceWindow::UpdateInterface
813 *****************************************************************************/
814 void InterfaceWindow::UpdateInterface()
818 p_input = (input_thread_t *)
819 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
821 else if( p_input->b_dead )
823 vlc_object_release( p_input );
827 /* Get ready to update the interface */
828 if( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) != B_OK )
833 if( b_playlist_update )
836 if( fPlaylistWindow->Lock() )
838 fPlaylistWindow->UpdatePlaylist( true );
839 fPlaylistWindow->Unlock();
840 b_playlist_update = false;
843 p_mediaControl->SetEnabled( !playlist_IsEmpty( p_playlist ) );
849 p_mediaControl->SetEnabled( true );
850 bool hasTitles = !var_Get( p_input, "title", &val );
851 bool hasChapters = !var_Get( p_input, "chapter", &val );
852 p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
853 var_GetInteger( p_input, "rate" ) );
854 var_Get( p_input, "position", &val );
855 p_mediaControl->SetProgress( val.f_float );
856 _SetMenusEnabled( true, hasChapters, hasTitles );
857 _UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
859 // enable/disable skip buttons
863 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
864 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
867 audio_volume_t i_volume;
868 aout_VolumeGet( p_intf, &i_volume );
869 p_mediaControl->SetAudioEnabled( true );
870 p_mediaControl->SetMuted( i_volume );
874 p_mediaControl->SetAudioEnabled( false );
876 _SetMenusEnabled( false );
878 if( !playlist_IsEmpty( p_playlist ) )
880 p_mediaControl->SetProgress( 0 );
883 // enable/disable skip buttons
886 p_wrapper->GetNavCapabilities( &canSkipPrev, &canSkipNext );
887 p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
892 p_mediaControl->SetEnabled( false );
897 fLastUpdateTime = system_time();
900 /*****************************************************************************
901 * InterfaceWindow::UpdatePlaylist
902 *****************************************************************************/
904 InterfaceWindow::UpdatePlaylist()
906 b_playlist_update = true;
909 /*****************************************************************************
910 * InterfaceWindow::IsStopped
911 *****************************************************************************/
913 InterfaceWindow::IsStopped() const
915 return (system_time() - fLastUpdateTime > INTERFACE_UPDATE_TIMEOUT);
918 /*****************************************************************************
919 * InterfaceWindow::_SetMenusEnabled
920 *****************************************************************************/
922 InterfaceWindow::_SetMenusEnabled(bool hasFile, bool hasChapters, bool hasTitles)
929 if ( LockWithTimeout( INTERFACE_LOCKING_TIMEOUT ) == B_OK)
931 if ( fNextChapterMI->IsEnabled() != hasChapters )
932 fNextChapterMI->SetEnabled( hasChapters );
933 if ( fPrevChapterMI->IsEnabled() != hasChapters )
934 fPrevChapterMI->SetEnabled( hasChapters );
935 if ( fChapterMenu->IsEnabled() != hasChapters )
936 fChapterMenu->SetEnabled( hasChapters );
937 if ( fNextTitleMI->IsEnabled() != hasTitles )
938 fNextTitleMI->SetEnabled( hasTitles );
939 if ( fPrevTitleMI->IsEnabled() != hasTitles )
940 fPrevTitleMI->SetEnabled( hasTitles );
941 if ( fTitleMenu->IsEnabled() != hasTitles )
942 fTitleMenu->SetEnabled( hasTitles );
943 if ( fAudioMenu->IsEnabled() != hasFile )
944 fAudioMenu->SetEnabled( hasFile );
945 if ( fNavigationMenu->IsEnabled() != hasFile )
946 fNavigationMenu->SetEnabled( hasFile );
947 if ( fLanguageMenu->IsEnabled() != hasFile )
948 fLanguageMenu->SetEnabled( hasFile );
949 if ( fSubtitlesMenu->IsEnabled() != hasFile )
950 fSubtitlesMenu->SetEnabled( hasFile );
951 if ( fSpeedMenu->IsEnabled() != hasFile )
952 fSpeedMenu->SetEnabled( hasFile );
957 /*****************************************************************************
958 * InterfaceWindow::_UpdateSpeedMenu
959 *****************************************************************************/
961 InterfaceWindow::_UpdateSpeedMenu( int rate )
963 BMenuItem * toMark = NULL;
967 case ( INPUT_RATE_DEFAULT * 8 ):
971 case ( INPUT_RATE_DEFAULT * 4 ):
975 case ( INPUT_RATE_DEFAULT * 2 ):
979 case ( INPUT_RATE_DEFAULT ):
983 case ( INPUT_RATE_DEFAULT / 2 ):
987 case ( INPUT_RATE_DEFAULT / 4 ):
991 case ( INPUT_RATE_DEFAULT / 8 ):
996 if ( toMark && !toMark->IsMarked() )
998 toMark->SetMarked( true );
1002 /*****************************************************************************
1003 * InterfaceWindow::_ShowFilePanel
1004 *****************************************************************************/
1006 InterfaceWindow::_ShowFilePanel( uint32 command, const char* windowTitle )
1010 fFilePanel = new BFilePanel( B_OPEN_PANEL, NULL, NULL,
1011 B_FILE_NODE | B_DIRECTORY_NODE );
1012 fFilePanel->SetTarget( this );
1014 fFilePanel->Window()->SetTitle( windowTitle );
1015 BMessage message( command );
1016 fFilePanel->SetMessage( &message );
1017 if ( !fFilePanel->IsShowing() )
1019 fFilePanel->Refresh();
1026 set_window_pos( BWindow* window, BRect frame )
1028 // sanity checks: make sure window is not too big/small
1029 // and that it's not off-screen
1030 float minWidth, maxWidth, minHeight, maxHeight;
1031 window->GetSizeLimits( &minWidth, &maxWidth, &minHeight, &maxHeight );
1033 make_sure_frame_is_within_limits( frame,
1034 minWidth, minHeight, maxWidth, maxHeight );
1035 if ( make_sure_frame_is_on_screen( frame ) )
1037 window->MoveTo( frame.LeftTop() );
1038 window->ResizeTo( frame.Width(), frame.Height() );
1044 launch_window( BWindow* window, bool showing )
1046 if ( window->Lock() )
1050 if ( window->IsHidden() )
1055 if ( !window->IsHidden() )
1062 /*****************************************************************************
1063 * InterfaceWindow::_RestoreSettings
1064 *****************************************************************************/
1066 InterfaceWindow::_RestoreSettings()
1068 if ( load_settings( fSettings, "interface_settings", "VideoLAN Client" ) == B_OK )
1071 if ( fSettings->FindRect( "main frame", &frame ) == B_OK )
1072 set_window_pos( this, frame );
1074 if (fSettings->FindRect( "playlist frame", &frame ) == B_OK )
1075 set_window_pos( fPlaylistWindow, frame );
1077 if (fSettings->FindRect( "messages frame", &frame ) == B_OK )
1078 set_window_pos( fMessagesWindow, frame );
1079 if (fSettings->FindRect( "settings frame", &frame ) == B_OK )
1081 /* FIXME: Preferences resizing doesn't work correctly yet */
1082 frame.right = frame.left + fPreferencesWindow->Frame().Width();
1083 frame.bottom = frame.top + fPreferencesWindow->Frame().Height();
1084 set_window_pos( fPreferencesWindow, frame );
1089 if ( fSettings->FindBool( "playlist showing", &showing ) == B_OK )
1090 launch_window( fPlaylistWindow, showing );
1092 if ( fSettings->FindBool( "messages showing", &showing ) == B_OK )
1093 launch_window( fMessagesWindow, showing );
1094 if ( fSettings->FindBool( "settings showing", &showing ) == B_OK )
1095 launch_window( fPreferencesWindow, showing );
1098 if ( fSettings->FindInt32( "playlist display mode", (int32*)&displayMode ) == B_OK )
1099 fPlaylistWindow->SetDisplayMode( displayMode );
1104 /*****************************************************************************
1105 * InterfaceWindow::_StoreSettings
1106 *****************************************************************************/
1108 InterfaceWindow::_StoreSettings()
1110 /* Save the volume */
1111 config_PutInt( p_intf, "volume", p_mediaControl->GetVolume() );
1112 config_SaveConfigFile( p_intf, "main" );
1114 /* Save the windows positions */
1115 if ( fSettings->ReplaceRect( "main frame", Frame() ) != B_OK )
1116 fSettings->AddRect( "main frame", Frame() );
1118 if ( fPlaylistWindow->Lock() )
1120 if (fSettings->ReplaceRect( "playlist frame", fPlaylistWindow->Frame() ) != B_OK)
1121 fSettings->AddRect( "playlist frame", fPlaylistWindow->Frame() );
1122 if (fSettings->ReplaceBool( "playlist showing", !fPlaylistWindow->IsHidden() ) != B_OK)
1123 fSettings->AddBool( "playlist showing", !fPlaylistWindow->IsHidden() );
1124 fPlaylistWindow->Unlock();
1127 if ( fMessagesWindow->Lock() )
1129 if (fSettings->ReplaceRect( "messages frame", fMessagesWindow->Frame() ) != B_OK)
1130 fSettings->AddRect( "messages frame", fMessagesWindow->Frame() );
1131 if (fSettings->ReplaceBool( "messages showing", !fMessagesWindow->IsHidden() ) != B_OK)
1132 fSettings->AddBool( "messages showing", !fMessagesWindow->IsHidden() );
1133 fMessagesWindow->Unlock();
1135 if ( fPreferencesWindow->Lock() )
1137 if (fSettings->ReplaceRect( "settings frame", fPreferencesWindow->Frame() ) != B_OK)
1138 fSettings->AddRect( "settings frame", fPreferencesWindow->Frame() );
1139 if (fSettings->ReplaceBool( "settings showing", !fPreferencesWindow->IsHidden() ) != B_OK)
1140 fSettings->AddBool( "settings showing", !fPreferencesWindow->IsHidden() );
1141 fPreferencesWindow->Unlock();
1144 uint32 displayMode = fPlaylistWindow->DisplayMode();
1145 if (fSettings->ReplaceInt32( "playlist display mode", displayMode ) != B_OK )
1146 fSettings->AddInt32( "playlist display mode", displayMode );
1148 save_settings( fSettings, "interface_settings", "VideoLAN Client" );
1152 /*****************************************************************************
1154 *****************************************************************************/
1155 CDMenu::CDMenu(const char *name)
1160 /*****************************************************************************
1162 *****************************************************************************/
1167 /*****************************************************************************
1168 * CDMenu::AttachedToWindow
1169 *****************************************************************************/
1170 void CDMenu::AttachedToWindow(void)
1173 while ( BMenuItem* item = RemoveItem( 0L ) )
1175 GetCD( "/dev/disk" );
1176 BMenu::AttachedToWindow();
1179 /*****************************************************************************
1181 *****************************************************************************/
1182 int CDMenu::GetCD( const char *directory )
1184 BVolumeRoster volRoster;
1187 status_t status = volRoster.GetNextVolume( &vol );
1188 while ( status == B_NO_ERROR )
1193 if ( get_volume_info( vol, volumeName, isCDROM, deviceName )
1196 BMessage* msg = new BMessage( OPEN_DVD );
1197 msg->AddString( "device", deviceName.String() );
1198 BMenuItem* item = new BMenuItem( volumeName.String(), msg );
1202 status = volRoster.GetNextVolume( &vol );
1207 /*****************************************************************************
1208 * LanguageMenu::LanguageMenu
1209 *****************************************************************************/
1210 LanguageMenu::LanguageMenu( intf_thread_t * _p_intf, const char * psz_name,
1211 char * _psz_variable )
1215 psz_variable = strdup( _psz_variable );
1218 /*****************************************************************************
1219 * LanguageMenu::~LanguageMenu
1220 *****************************************************************************/
1221 LanguageMenu::~LanguageMenu()
1223 free( psz_variable );
1226 /*****************************************************************************
1227 * LanguageMenu::AttachedToWindow
1228 *****************************************************************************/
1229 void LanguageMenu::AttachedToWindow()
1234 while( ( item = RemoveItem( 0L ) ) )
1239 SetRadioMode( true );
1241 input_thread_t * p_input = (input_thread_t *)
1242 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1248 vlc_value_t val_list, text_list;
1252 i_current = var_GetInteger( p_input, psz_variable );
1253 var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list );
1254 for( int i = 0; i < val_list.p_list->i_count; i++ )
1256 message = new BMessage( SELECT_CHANNEL );
1257 message->AddInt32( psz_variable, val_list.p_list->p_values[i].i_int );
1258 item = new BMenuItem( text_list.p_list->p_values[i].psz_string, message );
1259 if( val_list.p_list->p_values[i].i_int == i_current )
1261 item->SetMarked( true );
1265 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
1267 vlc_object_release( p_input );
1269 BMenu::AttachedToWindow();
1272 /*****************************************************************************
1273 * TitleMenu::TitleMenu
1274 *****************************************************************************/
1275 TitleMenu::TitleMenu( const char *name, intf_thread_t *p_interface )
1277 p_intf( p_interface )
1281 /*****************************************************************************
1282 * TitleMenu::~TitleMenu
1283 *****************************************************************************/
1284 TitleMenu::~TitleMenu()
1288 /*****************************************************************************
1289 * TitleMenu::AttachedToWindow
1290 *****************************************************************************/
1291 void TitleMenu::AttachedToWindow()
1294 while( ( item = RemoveItem( 0L ) ) )
1299 input_thread_t * p_input;
1300 p_input = (input_thread_t *)
1301 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1309 if( !var_Get( p_input, "title", &val ) )
1311 vlc_value_t val_list, text_list;
1312 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1313 &val_list, &text_list );
1315 for( int i = 0; i < val_list.p_list->i_count; i++ )
1317 message = new BMessage( TOGGLE_TITLE );
1318 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1319 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1321 if( val_list.p_list->p_values[i].i_int == val.i_int )
1323 item->SetMarked( true );
1328 var_Change( p_input, "title", VLC_VAR_FREELIST,
1329 &val_list, &text_list );
1331 vlc_object_release( p_input );
1332 BMenu::AttachedToWindow();
1336 /*****************************************************************************
1337 * ChapterMenu::ChapterMenu
1338 *****************************************************************************/
1339 ChapterMenu::ChapterMenu( const char *name, intf_thread_t *p_interface )
1341 p_intf( p_interface )
1345 /*****************************************************************************
1346 * ChapterMenu::~ChapterMenu
1347 *****************************************************************************/
1348 ChapterMenu::~ChapterMenu()
1352 /*****************************************************************************
1353 * ChapterMenu::AttachedToWindow
1354 *****************************************************************************/
1355 void ChapterMenu::AttachedToWindow()
1358 while( ( item = RemoveItem( 0L ) ) )
1363 input_thread_t * p_input;
1364 p_input = (input_thread_t *)
1365 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1373 if( !var_Get( p_input, "chapter", &val ) )
1375 vlc_value_t val_list, text_list;
1376 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1377 &val_list, &text_list );
1379 for( int i = 0; i < val_list.p_list->i_count; i++ )
1381 message = new BMessage( TOGGLE_CHAPTER );
1382 message->AddInt32( "index", val_list.p_list->p_values[i].i_int );
1383 item = new BMenuItem( text_list.p_list->p_values[i].psz_string,
1385 if( val_list.p_list->p_values[i].i_int == val.i_int )
1387 item->SetMarked( true );
1392 var_Change( p_input, "chapter", VLC_VAR_FREELIST,
1393 &val_list, &text_list );
1395 vlc_object_release( p_input );
1396 BMenu::AttachedToWindow();
1400 /*****************************************************************************
1402 *****************************************************************************/
1404 load_settings( BMessage* message, const char* fileName, const char* folder )
1406 status_t ret = B_BAD_VALUE;
1410 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1412 // passing folder is optional
1414 ret = path.Append( folder );
1415 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1417 BFile file( path.Path(), B_READ_ONLY );
1418 if ( ( ret = file.InitCheck() ) == B_OK )
1420 ret = message->Unflatten( &file );
1429 /*****************************************************************************
1431 *****************************************************************************/
1433 save_settings( BMessage* message, const char* fileName, const char* folder )
1435 status_t ret = B_BAD_VALUE;
1439 if ( ( ret = find_directory( B_USER_SETTINGS_DIRECTORY, &path ) ) == B_OK )
1441 // passing folder is optional
1442 if ( folder && ( ret = path.Append( folder ) ) == B_OK )
1443 ret = create_directory( path.Path(), 0777 );
1444 if ( ret == B_OK && ( ret = path.Append( fileName ) ) == B_OK )
1446 BFile file( path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
1447 if ( ( ret = file.InitCheck() ) == B_OK )
1449 ret = message->Flatten( &file );