1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.3 2001/09/12 01:30:07 tcastley Exp $
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>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
29 #include <kernel/OS.h>
30 #include <InterfaceKit.h>
32 #include <StorageKit.h>
35 #include <scsiprobe_driver.h>
46 #include "stream_control.h"
47 #include "input_ext-intf.h"
48 #include "interface.h"
50 #include "intf_playlist.h"
51 #include "audio_output.h"
54 /* BeOS interface headers */
56 #include "MediaControlView.h"
57 #include "InterfaceWindow.h"
58 #include "PlayListWindow.h"
60 /*****************************************************************************
62 *****************************************************************************/
64 InterfaceWindow::InterfaceWindow( BRect frame, const char *name,
65 intf_thread_t *p_interface )
66 : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
67 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK
68 | B_ASYNCHRONOUS_CONTROLS )
72 BRect controlRect(0,0,0,0);
73 b_empty_playlist = (p_main->p_playlist->i_size < 0);
75 /* set the title bar */
76 SetName( "interface" );
79 /* set up the main menu */
81 menu_bar = new BMenuBar(controlRect, "main menu");
88 /* Add the file Menu */
90 menu_bar->AddItem( mFile = new BMenu( "File" ) );
91 menu_bar->ResizeToPreferred();
92 mFile->AddItem( mItem = new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
93 new BMessage(OPEN_FILE), 'O') );
95 cd_menu = new CDMenu( "Open Disc" );
96 mFile->AddItem( cd_menu );
98 mFile->AddSeparatorItem();
99 mFile->AddItem( mItem = new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
100 new BMessage(OPEN_PLAYLIST), 'P') );
102 mFile->AddSeparatorItem();
103 mFile->AddItem( mItem = new BMenuItem( "About" B_UTF8_ELLIPSIS,
104 new BMessage(B_ABOUT_REQUESTED), 'A') );
105 mItem->SetTarget( be_app );
106 mFile->AddItem(mItem = new BMenuItem( "Quit",
107 new BMessage(B_QUIT_REQUESTED), 'Q') );
109 /* Add the Audio menu */
110 menu_bar->AddItem ( mAudio = new BMenu( "Audio" ) );
111 menu_bar->ResizeToPreferred();
112 mAudio->AddItem( new LanguageMenu( "Language", AUDIO_ES, p_intf ) );
113 mAudio->AddItem( new LanguageMenu( "Subtitles", SPU_ES, p_intf ) );
115 ResizeTo(260,50 + menu_bar->Bounds().IntegerHeight()+1);
116 controlRect = Bounds();
117 controlRect.top += menu_bar->Bounds().IntegerHeight() + 1;
119 p_mediaControl = new MediaControlView( controlRect );
120 p_mediaControl->SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
123 AddChild( p_mediaControl );
128 InterfaceWindow::~InterfaceWindow()
132 /*****************************************************************************
133 * InterfaceWindow::MessageReceived
134 *****************************************************************************/
135 void InterfaceWindow::MessageReceived( BMessage * p_message )
137 int vol_val = p_mediaControl->GetVolume(); // remember the current volume
138 int playback_status; // remember playback state
145 playback_status = p_intf->p_input->stream.control.i_status;
149 playback_status = UNDEF_S;
152 switch( p_message->what )
154 case B_ABOUT_REQUESTED:
155 alert = new BAlert(VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
165 file_panel = new BFilePanel();
166 file_panel->SetTarget( this );
172 BRect rect(20,20,320,420);
173 PlayListWindow* playlist_window = new PlayListWindow(rect,
174 "Playlist", (playlist_t *)p_main->p_playlist);
175 playlist_window->Show();
179 const char *psz_device;
180 char psz_source[ B_FILE_NAME_LENGTH + 4 ];
181 if( p_message->FindString("device", &psz_device) != B_ERROR )
183 snprintf( psz_source, B_FILE_NAME_LENGTH + 4,
184 "dvd:%s", psz_device );
185 psz_source[ strlen(psz_source) ] = '\0';
186 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_source );
187 if( p_intf->p_input != NULL )
189 p_intf->p_input->b_eof = 1;
191 intf_PlaylistJumpto( p_main->p_playlist,
192 p_main->p_playlist->i_size - 1 );
197 // this currently stops playback not nicely
198 if( p_intf->p_input != NULL )
200 // silence the sound, otherwise very horrible
201 vlc_mutex_lock( &p_aout_bank->lock );
202 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
204 p_aout_bank->pp_aout[i_index]->i_savedvolume = p_aout_bank->pp_aout[i_index]->i_volume;
205 p_aout_bank->pp_aout[i_index]->i_volume = 0;
207 vlc_mutex_unlock( &p_aout_bank->lock );
210 /* end playing item */
211 p_intf->p_input->b_eof = 1;
213 /* update playlist */
214 vlc_mutex_lock( &p_main->p_playlist->change_lock );
215 p_main->p_playlist->i_index--;
216 p_main->p_playlist->b_stopped = 1;
217 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
219 p_mediaControl->SetStatus(NOT_STARTED_S,DEFAULT_RATE);
223 /* starts playing in normal mode */
226 /* toggle between pause and play */
227 if( p_intf->p_input != NULL )
229 /* pause if currently playing */
230 if( playback_status == PLAYING_S )
233 vlc_mutex_lock( &p_aout_bank->lock );
234 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
236 p_aout_bank->pp_aout[i_index]->i_savedvolume =
237 p_aout_bank->pp_aout[i_index]->i_volume;
238 p_aout_bank->pp_aout[i_index]->i_volume = 0;
240 vlc_mutex_unlock( &p_aout_bank->lock );
243 /* pause the movie */
244 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
245 vlc_mutex_lock( &p_main->p_playlist->change_lock );
246 p_main->p_playlist->b_stopped = 0;
247 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
251 /* Play after pausing */
252 /* Restore the volume */
253 vlc_mutex_lock( &p_aout_bank->lock );
254 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
256 p_aout_bank->pp_aout[i_index]->i_volume =
257 p_aout_bank->pp_aout[i_index]->i_savedvolume;
258 p_aout_bank->pp_aout[i_index]->i_savedvolume = 0;
260 vlc_mutex_unlock( &p_aout_bank->lock );
264 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
265 p_main->p_playlist->b_stopped = 0;
270 /* Play a new file */
271 vlc_mutex_lock( &p_main->p_playlist->change_lock );
272 if( p_main->p_playlist->b_stopped )
274 if( p_main->p_playlist->i_size )
276 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
277 intf_PlaylistJumpto( p_main->p_playlist,
278 p_main->p_playlist->i_index );
279 p_main->p_playlist->b_stopped = 0;
283 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
290 /* cycle the fast playback modes */
291 if( p_intf->p_input != NULL )
294 vlc_mutex_lock( &p_aout_bank->lock );
295 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
297 p_aout_bank->pp_aout[i_index]->i_savedvolume =
298 p_aout_bank->pp_aout[i_index]->i_volume;
299 p_aout_bank->pp_aout[i_index]->i_volume = 0;
301 vlc_mutex_unlock( &p_aout_bank->lock );
304 /* change the fast play mode */
305 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
306 vlc_mutex_lock( &p_main->p_playlist->change_lock );
307 p_main->p_playlist->b_stopped = 0;
308 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
313 /* cycle the slow playback modes */
314 if (p_intf->p_input != NULL )
317 vlc_mutex_lock( &p_aout_bank->lock );
318 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
320 p_aout_bank->pp_aout[i_index]->i_savedvolume =
321 p_aout_bank->pp_aout[i_index]->i_volume;
322 p_aout_bank->pp_aout[i_index]->i_volume = 0;
324 vlc_mutex_unlock( &p_aout_bank->lock );
327 /* change the slower play */
328 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
329 vlc_mutex_lock( &p_main->p_playlist->change_lock );
330 p_main->p_playlist->b_stopped = 0;
331 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
336 /* handled by semaphores */
340 /* adjust the volume */
341 vlc_mutex_lock( &p_aout_bank->lock );
342 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
344 if( p_aout_bank->pp_aout[i_index]->i_savedvolume )
346 p_aout_bank->pp_aout[i_index]->i_savedvolume = vol_val;
350 p_aout_bank->pp_aout[i_index]->i_volume = vol_val;
353 vlc_mutex_unlock( &p_aout_bank->lock );
358 vlc_mutex_lock( &p_aout_bank->lock );
359 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
361 if( p_aout_bank->pp_aout[i_index]->i_savedvolume )
363 p_aout_bank->pp_aout[i_index]->i_volume =
364 p_aout_bank->pp_aout[i_index]->i_savedvolume;
365 p_aout_bank->pp_aout[i_index]->i_savedvolume = 0;
369 p_aout_bank->pp_aout[i_index]->i_savedvolume =
370 p_aout_bank->pp_aout[i_index]->i_volume;
371 p_aout_bank->pp_aout[i_index]->i_volume = 0;
374 vlc_mutex_unlock( &p_aout_bank->lock );
379 int32 i = p_message->FindInt32( "channel" );
382 input_ChangeES( p_intf->p_input, NULL, AUDIO_ES );
386 input_ChangeES( p_intf->p_input,
387 p_intf->p_input->stream.pp_es[i], AUDIO_ES );
392 case SELECT_SUBTITLE:
394 int32 i = p_message->FindInt32( "subtitle" );
397 input_ChangeES( p_intf->p_input, NULL, SPU_ES);
401 input_ChangeES( p_intf->p_input,
402 p_intf->p_input->stream.pp_es[i], SPU_ES );
407 case B_REFS_RECEIVED:
411 if( p_message->FindRef( "refs", &ref ) == B_OK )
414 intf_PlaylistAdd( p_main->p_playlist,
415 PLAYLIST_END, (char*)path.Path() );
416 if( p_intf->p_input != NULL )
418 p_intf->p_input->b_eof = 1;
420 intf_PlaylistJumpto( p_main->p_playlist,
421 p_main->p_playlist->i_size - 1 );
428 BWindow::MessageReceived( p_message );
434 /*****************************************************************************
435 * InterfaceWindow::updateInterface
436 *****************************************************************************/
437 void InterfaceWindow::updateInterface()
439 if ( p_intf->p_input )
441 if ( acquire_sem(p_mediaControl->fScrubSem) == B_OK )
443 uint64 seekTo = (p_mediaControl->GetSeekTo() *
444 p_intf->p_input->stream.p_selected_area->i_size) / 100;
445 intf_Msg("Move to: %u", seekTo);
446 input_Seek( p_intf->p_input, seekTo);
450 p_mediaControl->SetStatus(p_intf->p_input->stream.control.i_status,
451 p_intf->p_input->stream.control.i_rate);
452 p_mediaControl->SetProgress(p_intf->p_input->stream.p_selected_area->i_tell,
453 p_intf->p_input->stream.p_selected_area->i_size);
457 if ( b_empty_playlist != (p_main->p_playlist->i_size < 1) )
461 b_empty_playlist = !b_empty_playlist;
462 p_mediaControl->SetEnabled( !b_empty_playlist );
468 /*****************************************************************************
469 * InterfaceWindow::QuitRequested
470 *****************************************************************************/
471 bool InterfaceWindow::QuitRequested()
478 /*****************************************************************************
480 *****************************************************************************/
481 CDMenu::CDMenu(const char *name)
486 /*****************************************************************************
488 *****************************************************************************/
493 /*****************************************************************************
494 * CDMenu::AttachedToWindow
495 *****************************************************************************/
496 void CDMenu::AttachedToWindow(void)
498 while (RemoveItem((long int)0) != NULL); // remove all items
500 BMenu::AttachedToWindow();
503 /*****************************************************************************
505 *****************************************************************************/
506 int CDMenu::GetCD( const char *directory )
510 dir.SetTo( directory );
512 if( dir.InitCheck() != B_NO_ERROR )
520 while( dir.GetNextEntry(&entry) >= 0 )
526 if( entry.GetPath(&path) != B_NO_ERROR )
533 if( entry.GetRef(&e) != B_NO_ERROR )
538 if( entry.IsDirectory() )
540 if( strcmp(e.name, "floppy") == 0 )
542 continue; // ignore floppy (it is not silent)
545 i_dev = GetCD( name );
557 if( strcmp(e.name, "raw") != 0 )
559 continue; // ignore partitions
562 i_dev = open( name, O_RDONLY );
569 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
571 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
573 if( ioctl(i_dev, B_GET_MEDIA_STATUS, &m, sizeof(m)) >= 0 )
575 if( m == B_NO_ERROR ) //ensure media is present
578 msg = new BMessage( OPEN_DVD );
579 msg->AddString( "device", name );
580 BMenuItem *menu_item;
581 menu_item = new BMenuItem( name, msg );
582 AddItem( menu_item );
594 /*****************************************************************************
595 * LanguageMenu::LanguageMenu
596 *****************************************************************************/
597 LanguageMenu::LanguageMenu(const char *name, int menu_kind,
598 intf_thread_t *p_interface)
602 p_intf = p_interface;
605 /*****************************************************************************
606 * LanguageMenu::~LanguageMenu
607 *****************************************************************************/
608 LanguageMenu::~LanguageMenu()
612 /*****************************************************************************
613 * LanguageMenu::AttachedToWindow
614 *****************************************************************************/
615 void LanguageMenu::AttachedToWindow(void)
617 while( RemoveItem((long int)0) != NULL )
619 ; // remove all items
624 BMenu::AttachedToWindow();
627 /*****************************************************************************
628 * LanguageMenu::GetChannels
629 *****************************************************************************/
630 int LanguageMenu::GetChannels()
636 es_descriptor_t *p_es = NULL;
638 /* Insert the null */
639 if( kind == AUDIO_ES ) //audio
641 msg = new BMessage(SELECT_CHANNEL);
642 msg->AddInt32("channel", -1);
646 msg = new BMessage(SELECT_SUBTITLE);
647 msg->AddInt32("subtitle", -1);
649 BMenuItem *menu_item;
650 menu_item = new BMenuItem("None", msg);
652 menu_item->SetMarked(TRUE);
654 if( p_intf->p_input == NULL )
660 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
661 for( i = 0; i < p_intf->p_input->stream.i_selected_es_number; i++ )
663 if( kind == p_intf->p_input->stream.pp_selected_es[i]->i_cat )
665 p_es = p_intf->p_input->stream.pp_selected_es[i];
669 for( i = 0; i < p_intf->p_input->stream.i_es_number; i++ )
671 if( kind == p_intf->p_input->stream.pp_es[i]->i_cat )
673 psz_name = p_intf->p_input->stream.pp_es[i]->psz_desc;
674 if( kind == AUDIO_ES ) //audio
676 msg = new BMessage(SELECT_CHANNEL);
677 msg->AddInt32("channel", i);
681 msg = new BMessage(SELECT_SUBTITLE);
682 msg->AddInt32("subtitle", i);
684 BMenuItem *menu_item;
685 menu_item = new BMenuItem(psz_name, msg);
687 b_active = (p_es == p_intf->p_input->stream.pp_es[i]);
688 menu_item->SetMarked(b_active);
691 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );