1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.17 2002/06/01 09:21:59 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 *****************************************************************************/
28 #include <kernel/OS.h>
29 #include <InterfaceKit.h>
31 #include <StorageKit.h>
34 #include <scsiprobe_driver.h>
42 #include <videolan/vlc.h>
44 #include "stream_control.h"
45 #include "input_ext-intf.h"
47 #include "interface.h"
48 #include "intf_playlist.h"
50 #include "audio_output.h"
53 /* BeOS interface headers */
55 #include "MediaControlView.h"
56 #include "PlayListWindow.h"
57 #include "InterfaceWindow.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 )
71 playlist_window = NULL;
73 BRect controlRect(0,0,0,0);
74 b_empty_playlist = (p_main->p_playlist->i_size < 0);
76 /* set the title bar */
77 SetName( "interface" );
80 /* set up the main menu */
82 menu_bar = new BMenuBar(controlRect, "main menu");
91 /* Add the file Menu */
93 menu_bar->AddItem( mFile = new BMenu( "File" ) );
94 menu_bar->ResizeToPreferred();
95 mFile->AddItem( mItem = new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
96 new BMessage(OPEN_FILE), 'O') );
98 cd_menu = new CDMenu( "Open Disc" );
99 mFile->AddItem( cd_menu );
101 mFile->AddSeparatorItem();
102 mFile->AddItem( mItem = new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
103 new BMessage(OPEN_PLAYLIST), 'P') );
105 mFile->AddSeparatorItem();
106 mFile->AddItem( mItem = new BMenuItem( "About" B_UTF8_ELLIPSIS,
107 new BMessage(B_ABOUT_REQUESTED), 'A') );
108 mItem->SetTarget( be_app );
109 mFile->AddItem(mItem = new BMenuItem( "Quit",
110 new BMessage(B_QUIT_REQUESTED), 'Q') );
112 /* Add the Audio menu */
113 menu_bar->AddItem ( mAudio = new BMenu( "Audio" ) );
114 menu_bar->ResizeToPreferred();
115 mAudio->AddItem( new LanguageMenu( "Language", AUDIO_ES, p_intf ) );
116 mAudio->AddItem( new LanguageMenu( "Subtitles", SPU_ES, p_intf ) );
118 /* Add the Navigation menu */
119 menu_bar->AddItem( mNavigation = new BMenu( "Navigation" ) );
120 menu_bar->ResizeToPreferred();
121 mNavigation->AddItem( new BMenuItem( "Prev Title",
122 new BMessage(PREV_TITLE)) );
123 mNavigation->AddItem( new BMenuItem( "Next Title",
124 new BMessage(NEXT_TITLE)) );
125 mNavigation->AddItem( new BMenuItem( "Prev Chapter",
126 new BMessage(PREV_CHAPTER)) );
127 mNavigation->AddItem( new BMenuItem( "Next Chapter",
128 new BMessage(NEXT_CHAPTER)) );
130 /* Add the Config menu */
131 menu_bar->AddItem( mConfig = new BMenu( "Config" ) );
132 menu_bar->ResizeToPreferred();
133 mConfig->AddItem( miOnTop = new BMenuItem( "Always on Top",
134 new BMessage(TOGGLE_ON_TOP)) );
135 miOnTop->SetMarked(false);
137 ResizeTo(260,50 + menu_bar->Bounds().IntegerHeight()+1);
138 controlRect = Bounds();
139 controlRect.top += menu_bar->Bounds().IntegerHeight() + 1;
141 p_mediaControl = new MediaControlView( controlRect );
142 p_mediaControl->SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
143 b_empty_playlist = true;
144 p_mediaControl->SetEnabled( !b_empty_playlist );
147 AddChild( p_mediaControl );
152 InterfaceWindow::~InterfaceWindow()
154 if (playlist_window) playlist_window->ReallyQuit();
157 /*****************************************************************************
158 * InterfaceWindow::MessageReceived
159 *****************************************************************************/
160 void InterfaceWindow::MessageReceived( BMessage * p_message )
162 int vol_val = p_mediaControl->GetVolume(); // remember the current volume
163 int playback_status; // remember playback state
168 if (p_input_bank->pp_input[0])
170 playback_status = p_input_bank->pp_input[0]->stream.control.i_status;
174 playback_status = UNDEF_S;
177 switch( p_message->what )
179 case B_ABOUT_REQUESTED:
180 alert = new BAlert(VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
185 miOnTop->SetMarked(! miOnTop->IsMarked() );
186 if ( miOnTop->IsMarked() )
188 SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
189 SetWorkspaces(B_CURRENT_WORKSPACE);
193 SetFeel(B_NORMAL_WINDOW_FEEL);
194 SetWorkspaces(B_CURRENT_WORKSPACE);
204 file_panel = new BFilePanel();
205 file_panel->SetTarget( this );
207 b_empty_playlist = false;
208 p_mediaControl->SetEnabled( !b_empty_playlist );
213 BRect rect(20,20,320,420);
214 playlist_window = PlayListWindow::getPlayList(rect,
215 "Playlist", (playlist_t *)p_main->p_playlist);
216 playlist_window->Show();
220 const char *psz_device;
221 char psz_source[ B_FILE_NAME_LENGTH + 4 ];
222 if( p_message->FindString("device", &psz_device) != B_ERROR )
224 snprintf( psz_source, B_FILE_NAME_LENGTH + 4,
225 "dvd:%s", psz_device );
226 psz_source[ strlen(psz_source) ] = '\0';
227 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_source );
228 if( p_input_bank->pp_input[0] != NULL )
230 p_input_bank->pp_input[0]->b_eof = 1;
232 intf_PlaylistJumpto( p_main->p_playlist,
233 p_main->p_playlist->i_size - 1 );
234 b_empty_playlist = false;
235 p_mediaControl->SetEnabled( !b_empty_playlist );
240 // this currently stops playback not nicely
241 if( p_input_bank->pp_input[0] != NULL )
243 // silence the sound, otherwise very horrible
244 vlc_mutex_lock( &p_aout_bank->lock );
245 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
247 p_aout_bank->pp_aout[i_index]->i_savedvolume = p_aout_bank->pp_aout[i_index]->i_volume;
248 p_aout_bank->pp_aout[i_index]->i_volume = 0;
250 vlc_mutex_unlock( &p_aout_bank->lock );
253 /* end playing item */
254 p_input_bank->pp_input[0]->b_eof = 1;
256 /* update playlist */
257 vlc_mutex_lock( &p_main->p_playlist->change_lock );
258 p_main->p_playlist->i_index--;
259 p_main->p_playlist->b_stopped = 1;
260 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
262 p_mediaControl->SetStatus(NOT_STARTED_S,DEFAULT_RATE);
266 /* starts playing in normal mode */
269 /* toggle between pause and play */
270 if( p_input_bank->pp_input[0] != NULL )
272 /* pause if currently playing */
273 if( playback_status == PLAYING_S )
276 vlc_mutex_lock( &p_aout_bank->lock );
277 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
279 p_aout_bank->pp_aout[i_index]->i_savedvolume =
280 p_aout_bank->pp_aout[i_index]->i_volume;
281 p_aout_bank->pp_aout[i_index]->i_volume = 0;
283 vlc_mutex_unlock( &p_aout_bank->lock );
286 /* pause the movie */
287 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PAUSE );
288 vlc_mutex_lock( &p_main->p_playlist->change_lock );
289 p_main->p_playlist->b_stopped = 0;
290 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
294 /* Play after pausing */
295 /* Restore the volume */
296 vlc_mutex_lock( &p_aout_bank->lock );
297 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
299 p_aout_bank->pp_aout[i_index]->i_volume =
300 p_aout_bank->pp_aout[i_index]->i_savedvolume;
301 p_aout_bank->pp_aout[i_index]->i_savedvolume = 0;
303 vlc_mutex_unlock( &p_aout_bank->lock );
307 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
308 p_main->p_playlist->b_stopped = 0;
313 /* Play a new file */
314 vlc_mutex_lock( &p_main->p_playlist->change_lock );
315 if( p_main->p_playlist->b_stopped )
317 if( p_main->p_playlist->i_size )
319 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
320 intf_PlaylistJumpto( p_main->p_playlist,
321 p_main->p_playlist->i_index );
322 p_main->p_playlist->b_stopped = 0;
326 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
333 /* cycle the fast playback modes */
334 if( p_input_bank->pp_input[0] != NULL )
337 vlc_mutex_lock( &p_aout_bank->lock );
338 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
340 p_aout_bank->pp_aout[i_index]->i_savedvolume =
341 p_aout_bank->pp_aout[i_index]->i_volume;
342 p_aout_bank->pp_aout[i_index]->i_volume = 0;
344 vlc_mutex_unlock( &p_aout_bank->lock );
347 /* change the fast play mode */
348 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_FASTER );
349 vlc_mutex_lock( &p_main->p_playlist->change_lock );
350 p_main->p_playlist->b_stopped = 0;
351 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
356 /* cycle the slow playback modes */
357 if (p_input_bank->pp_input[0] != NULL )
360 vlc_mutex_lock( &p_aout_bank->lock );
361 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
363 p_aout_bank->pp_aout[i_index]->i_savedvolume =
364 p_aout_bank->pp_aout[i_index]->i_volume;
365 p_aout_bank->pp_aout[i_index]->i_volume = 0;
367 vlc_mutex_unlock( &p_aout_bank->lock );
370 /* change the slower play */
371 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_SLOWER );
372 vlc_mutex_lock( &p_main->p_playlist->change_lock );
373 p_main->p_playlist->b_stopped = 0;
374 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
379 /* handled by semaphores */
383 /* adjust the volume */
384 vlc_mutex_lock( &p_aout_bank->lock );
385 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
387 if( p_aout_bank->pp_aout[i_index]->i_savedvolume )
389 p_aout_bank->pp_aout[i_index]->i_savedvolume = vol_val;
393 p_aout_bank->pp_aout[i_index]->i_volume = vol_val;
396 vlc_mutex_unlock( &p_aout_bank->lock );
401 vlc_mutex_lock( &p_aout_bank->lock );
402 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
404 if( p_aout_bank->pp_aout[i_index]->i_savedvolume )
406 p_aout_bank->pp_aout[i_index]->i_volume =
407 p_aout_bank->pp_aout[i_index]->i_savedvolume;
408 p_aout_bank->pp_aout[i_index]->i_savedvolume = 0;
412 p_aout_bank->pp_aout[i_index]->i_savedvolume =
413 p_aout_bank->pp_aout[i_index]->i_volume;
414 p_aout_bank->pp_aout[i_index]->i_volume = 0;
417 vlc_mutex_unlock( &p_aout_bank->lock );
422 int32 i = p_message->FindInt32( "channel" );
425 input_ChangeES( p_input_bank->pp_input[0], NULL, AUDIO_ES );
429 input_ChangeES( p_input_bank->pp_input[0],
430 p_input_bank->pp_input[0]->stream.pp_es[i], AUDIO_ES );
435 case SELECT_SUBTITLE:
437 int32 i = p_message->FindInt32( "subtitle" );
440 input_ChangeES( p_input_bank->pp_input[0], NULL, SPU_ES);
444 input_ChangeES( p_input_bank->pp_input[0],
445 p_input_bank->pp_input[0]->stream.pp_es[i], SPU_ES );
451 input_area_t * p_area;
454 i_id = p_input_bank->pp_input[0]->stream.p_selected_area->i_id - 1;
456 /* Disallow area 0 since it is used for video_ts.vob */
459 p_area = p_input_bank->pp_input[0]->stream.pp_areas[i_id];
460 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
461 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
467 input_area_t * p_area;
470 i_id = p_input_bank->pp_input[0]->stream.p_selected_area->i_id + 1;
472 if( i_id < p_input_bank->pp_input[0]->stream.i_area_nb )
474 p_area = p_input_bank->pp_input[0]->stream.pp_areas[i_id];
475 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
476 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
482 input_area_t * p_area;
484 p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
486 if( p_area->i_part > 0 )
489 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
490 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
496 input_area_t * p_area;
498 p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
500 if( p_area->i_part > 0 )
503 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
504 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
508 case B_REFS_RECEIVED:
512 if( p_message->FindRef( "refs", &ref ) == B_OK )
515 intf_PlaylistAdd( p_main->p_playlist,
516 PLAYLIST_END, (char*)path.Path() );
517 if( p_input_bank->pp_input[0] != NULL )
519 p_input_bank->pp_input[0]->b_eof = 1;
521 intf_PlaylistJumpto( p_main->p_playlist,
522 p_main->p_playlist->i_size - 1 );
529 BWindow::MessageReceived( p_message );
535 /*****************************************************************************
536 * InterfaceWindow::updateInterface
537 *****************************************************************************/
538 void InterfaceWindow::updateInterface()
540 if ( p_input_bank->pp_input[0] )
542 if ( acquire_sem(p_mediaControl->fScrubSem) == B_OK )
544 uint64 seekTo = (p_mediaControl->GetSeekTo() *
545 p_input_bank->pp_input[0]->stream.p_selected_area->i_size) / 100;
546 input_Seek( p_input_bank->pp_input[0], seekTo);
550 p_mediaControl->SetStatus(p_input_bank->pp_input[0]->stream.control.i_status,
551 p_input_bank->pp_input[0]->stream.control.i_rate);
552 p_mediaControl->SetProgress(p_input_bank->pp_input[0]->stream.p_selected_area->i_tell,
553 p_input_bank->pp_input[0]->stream.p_selected_area->i_size);
557 if ( b_empty_playlist != (p_main->p_playlist->i_size < 1) )
561 b_empty_playlist = !b_empty_playlist;
562 p_mediaControl->SetEnabled( !b_empty_playlist );
568 /*****************************************************************************
569 * InterfaceWindow::QuitRequested
570 *****************************************************************************/
571 bool InterfaceWindow::QuitRequested()
578 /*****************************************************************************
580 *****************************************************************************/
581 CDMenu::CDMenu(const char *name)
586 /*****************************************************************************
588 *****************************************************************************/
593 /*****************************************************************************
594 * CDMenu::AttachedToWindow
595 *****************************************************************************/
596 void CDMenu::AttachedToWindow(void)
598 while (RemoveItem((long int)0) != NULL); // remove all items
600 BMenu::AttachedToWindow();
603 /*****************************************************************************
605 *****************************************************************************/
606 int CDMenu::GetCD( const char *directory )
608 BVolumeRoster *volRoster;
613 char name[B_FILE_NAME_LENGTH];
617 volRoster = new BVolumeRoster();
619 dir = new BDirectory();
620 status = volRoster->GetNextVolume(vol);
621 status = vol->GetRootDirectory(dir);
622 while (status == B_NO_ERROR)
624 mounted = vol->GetName(name);
625 if ((mounted == B_OK) && /* Disk is currently Mounted */
626 (vol->IsReadOnly()) ) /* Disk is read-only */
629 fs_stat_dev(dev, &info);
633 i_dev = open( info.device_name, O_RDONLY );
637 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
639 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
642 msg = new BMessage( OPEN_DVD );
643 msg->AddString( "device", info.device_name );
644 BMenuItem *menu_item;
645 menu_item = new BMenuItem( name, msg );
646 AddItem( menu_item );
653 status = volRoster->GetNextVolume(vol);
657 /*****************************************************************************
658 * LanguageMenu::LanguageMenu
659 *****************************************************************************/
660 LanguageMenu::LanguageMenu(const char *name, int menu_kind,
661 intf_thread_t *p_interface)
665 p_intf = p_interface;
668 /*****************************************************************************
669 * LanguageMenu::~LanguageMenu
670 *****************************************************************************/
671 LanguageMenu::~LanguageMenu()
675 /*****************************************************************************
676 * LanguageMenu::AttachedToWindow
677 *****************************************************************************/
678 void LanguageMenu::AttachedToWindow(void)
680 while( RemoveItem((long int)0) != NULL )
682 ; // remove all items
687 BMenu::AttachedToWindow();
690 /*****************************************************************************
691 * LanguageMenu::GetChannels
692 *****************************************************************************/
693 int LanguageMenu::GetChannels()
699 es_descriptor_t *p_es = NULL;
701 /* Insert the null */
702 if( kind == AUDIO_ES ) //audio
704 msg = new BMessage(SELECT_CHANNEL);
705 msg->AddInt32("channel", -1);
709 msg = new BMessage(SELECT_SUBTITLE);
710 msg->AddInt32("subtitle", -1);
712 BMenuItem *menu_item;
713 menu_item = new BMenuItem("None", msg);
715 menu_item->SetMarked(TRUE);
717 if( p_input_bank->pp_input[0] == NULL )
723 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
724 for( i = 0; i < p_input_bank->pp_input[0]->stream.i_selected_es_number; i++ )
726 if( kind == p_input_bank->pp_input[0]->stream.pp_selected_es[i]->i_cat )
728 p_es = p_input_bank->pp_input[0]->stream.pp_selected_es[i];
732 for( i = 0; i < p_input_bank->pp_input[0]->stream.i_es_number; i++ )
734 if( kind == p_input_bank->pp_input[0]->stream.pp_es[i]->i_cat )
736 psz_name = p_input_bank->pp_input[0]->stream.pp_es[i]->psz_desc;
737 if( kind == AUDIO_ES ) //audio
739 msg = new BMessage(SELECT_CHANNEL);
740 msg->AddInt32("channel", i);
744 msg = new BMessage(SELECT_SUBTITLE);
745 msg->AddInt32("subtitle", i);
747 BMenuItem *menu_item;
748 menu_item = new BMenuItem(psz_name, msg);
750 b_active = (p_es == p_input_bank->pp_input[0]->stream.pp_es[i]);
751 menu_item->SetMarked(b_active);
754 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );