1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.16 2002/05/16 11:38:42 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 "InterfaceWindow.h"
57 #include "PlayListWindow.h"
59 /*****************************************************************************
61 *****************************************************************************/
63 InterfaceWindow::InterfaceWindow( BRect frame, const char *name,
64 intf_thread_t *p_interface )
65 : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
66 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK
67 | B_ASYNCHRONOUS_CONTROLS )
71 BRect controlRect(0,0,0,0);
72 b_empty_playlist = (p_main->p_playlist->i_size < 0);
74 /* set the title bar */
75 SetName( "interface" );
78 /* set up the main menu */
80 menu_bar = new BMenuBar(controlRect, "main menu");
89 /* Add the file Menu */
91 menu_bar->AddItem( mFile = new BMenu( "File" ) );
92 menu_bar->ResizeToPreferred();
93 mFile->AddItem( mItem = new BMenuItem( "Open File" B_UTF8_ELLIPSIS,
94 new BMessage(OPEN_FILE), 'O') );
96 cd_menu = new CDMenu( "Open Disc" );
97 mFile->AddItem( cd_menu );
99 mFile->AddSeparatorItem();
100 mFile->AddItem( mItem = new BMenuItem( "Play List" B_UTF8_ELLIPSIS,
101 new BMessage(OPEN_PLAYLIST), 'P') );
103 mFile->AddSeparatorItem();
104 mFile->AddItem( mItem = new BMenuItem( "About" B_UTF8_ELLIPSIS,
105 new BMessage(B_ABOUT_REQUESTED), 'A') );
106 mItem->SetTarget( be_app );
107 mFile->AddItem(mItem = new BMenuItem( "Quit",
108 new BMessage(B_QUIT_REQUESTED), 'Q') );
110 /* Add the Audio menu */
111 menu_bar->AddItem ( mAudio = new BMenu( "Audio" ) );
112 menu_bar->ResizeToPreferred();
113 mAudio->AddItem( new LanguageMenu( "Language", AUDIO_ES, p_intf ) );
114 mAudio->AddItem( new LanguageMenu( "Subtitles", SPU_ES, p_intf ) );
116 /* Add the Navigation menu */
117 menu_bar->AddItem( mNavigation = new BMenu( "Navigation" ) );
118 menu_bar->ResizeToPreferred();
119 mNavigation->AddItem( new BMenuItem( "Prev Title",
120 new BMessage(PREV_TITLE)) );
121 mNavigation->AddItem( new BMenuItem( "Next Title",
122 new BMessage(NEXT_TITLE)) );
123 mNavigation->AddItem( new BMenuItem( "Prev Chapter",
124 new BMessage(PREV_CHAPTER)) );
125 mNavigation->AddItem( new BMenuItem( "Next Chapter",
126 new BMessage(NEXT_CHAPTER)) );
128 /* Add the Config menu */
129 menu_bar->AddItem( mConfig = new BMenu( "Config" ) );
130 menu_bar->ResizeToPreferred();
131 mConfig->AddItem( miOnTop = new BMenuItem( "Always on Top",
132 new BMessage(TOGGLE_ON_TOP)) );
133 miOnTop->SetMarked(false);
135 ResizeTo(260,50 + menu_bar->Bounds().IntegerHeight()+1);
136 controlRect = Bounds();
137 controlRect.top += menu_bar->Bounds().IntegerHeight() + 1;
139 p_mediaControl = new MediaControlView( controlRect );
140 p_mediaControl->SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
141 b_empty_playlist = true;
142 p_mediaControl->SetEnabled( !b_empty_playlist );
145 AddChild( p_mediaControl );
150 InterfaceWindow::~InterfaceWindow()
154 /*****************************************************************************
155 * InterfaceWindow::MessageReceived
156 *****************************************************************************/
157 void InterfaceWindow::MessageReceived( BMessage * p_message )
159 int vol_val = p_mediaControl->GetVolume(); // remember the current volume
160 int playback_status; // remember playback state
165 if (p_input_bank->pp_input[0])
167 playback_status = p_input_bank->pp_input[0]->stream.control.i_status;
171 playback_status = UNDEF_S;
174 switch( p_message->what )
176 case B_ABOUT_REQUESTED:
177 alert = new BAlert(VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
182 miOnTop->SetMarked(! miOnTop->IsMarked() );
183 if ( miOnTop->IsMarked() )
185 SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
186 SetWorkspaces(B_CURRENT_WORKSPACE);
190 SetFeel(B_NORMAL_WINDOW_FEEL);
191 SetWorkspaces(B_CURRENT_WORKSPACE);
201 file_panel = new BFilePanel();
202 file_panel->SetTarget( this );
204 b_empty_playlist = false;
205 p_mediaControl->SetEnabled( !b_empty_playlist );
210 BRect rect(20,20,320,420);
211 PlayListWindow* playlist_window = new PlayListWindow(rect,
212 "Playlist", (playlist_t *)p_main->p_playlist);
213 playlist_window->Show();
217 const char *psz_device;
218 char psz_source[ B_FILE_NAME_LENGTH + 4 ];
219 if( p_message->FindString("device", &psz_device) != B_ERROR )
221 snprintf( psz_source, B_FILE_NAME_LENGTH + 4,
222 "dvd:%s", psz_device );
223 psz_source[ strlen(psz_source) ] = '\0';
224 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_source );
225 if( p_input_bank->pp_input[0] != NULL )
227 p_input_bank->pp_input[0]->b_eof = 1;
229 intf_PlaylistJumpto( p_main->p_playlist,
230 p_main->p_playlist->i_size - 1 );
231 b_empty_playlist = false;
232 p_mediaControl->SetEnabled( !b_empty_playlist );
237 // this currently stops playback not nicely
238 if( p_input_bank->pp_input[0] != NULL )
240 // silence the sound, otherwise very horrible
241 vlc_mutex_lock( &p_aout_bank->lock );
242 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
244 p_aout_bank->pp_aout[i_index]->i_savedvolume = p_aout_bank->pp_aout[i_index]->i_volume;
245 p_aout_bank->pp_aout[i_index]->i_volume = 0;
247 vlc_mutex_unlock( &p_aout_bank->lock );
250 /* end playing item */
251 p_input_bank->pp_input[0]->b_eof = 1;
253 /* update playlist */
254 vlc_mutex_lock( &p_main->p_playlist->change_lock );
255 p_main->p_playlist->i_index--;
256 p_main->p_playlist->b_stopped = 1;
257 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
259 p_mediaControl->SetStatus(NOT_STARTED_S,DEFAULT_RATE);
263 /* starts playing in normal mode */
266 /* toggle between pause and play */
267 if( p_input_bank->pp_input[0] != NULL )
269 /* pause if currently playing */
270 if( playback_status == PLAYING_S )
273 vlc_mutex_lock( &p_aout_bank->lock );
274 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
276 p_aout_bank->pp_aout[i_index]->i_savedvolume =
277 p_aout_bank->pp_aout[i_index]->i_volume;
278 p_aout_bank->pp_aout[i_index]->i_volume = 0;
280 vlc_mutex_unlock( &p_aout_bank->lock );
283 /* pause the movie */
284 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PAUSE );
285 vlc_mutex_lock( &p_main->p_playlist->change_lock );
286 p_main->p_playlist->b_stopped = 0;
287 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
291 /* Play after pausing */
292 /* Restore the volume */
293 vlc_mutex_lock( &p_aout_bank->lock );
294 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
296 p_aout_bank->pp_aout[i_index]->i_volume =
297 p_aout_bank->pp_aout[i_index]->i_savedvolume;
298 p_aout_bank->pp_aout[i_index]->i_savedvolume = 0;
300 vlc_mutex_unlock( &p_aout_bank->lock );
304 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
305 p_main->p_playlist->b_stopped = 0;
310 /* Play a new file */
311 vlc_mutex_lock( &p_main->p_playlist->change_lock );
312 if( p_main->p_playlist->b_stopped )
314 if( p_main->p_playlist->i_size )
316 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
317 intf_PlaylistJumpto( p_main->p_playlist,
318 p_main->p_playlist->i_index );
319 p_main->p_playlist->b_stopped = 0;
323 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
330 /* cycle the fast playback modes */
331 if( p_input_bank->pp_input[0] != NULL )
334 vlc_mutex_lock( &p_aout_bank->lock );
335 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
337 p_aout_bank->pp_aout[i_index]->i_savedvolume =
338 p_aout_bank->pp_aout[i_index]->i_volume;
339 p_aout_bank->pp_aout[i_index]->i_volume = 0;
341 vlc_mutex_unlock( &p_aout_bank->lock );
344 /* change the fast play mode */
345 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_FASTER );
346 vlc_mutex_lock( &p_main->p_playlist->change_lock );
347 p_main->p_playlist->b_stopped = 0;
348 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
353 /* cycle the slow playback modes */
354 if (p_input_bank->pp_input[0] != NULL )
357 vlc_mutex_lock( &p_aout_bank->lock );
358 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
360 p_aout_bank->pp_aout[i_index]->i_savedvolume =
361 p_aout_bank->pp_aout[i_index]->i_volume;
362 p_aout_bank->pp_aout[i_index]->i_volume = 0;
364 vlc_mutex_unlock( &p_aout_bank->lock );
367 /* change the slower play */
368 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_SLOWER );
369 vlc_mutex_lock( &p_main->p_playlist->change_lock );
370 p_main->p_playlist->b_stopped = 0;
371 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
376 /* handled by semaphores */
380 /* adjust the volume */
381 vlc_mutex_lock( &p_aout_bank->lock );
382 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
384 if( p_aout_bank->pp_aout[i_index]->i_savedvolume )
386 p_aout_bank->pp_aout[i_index]->i_savedvolume = vol_val;
390 p_aout_bank->pp_aout[i_index]->i_volume = vol_val;
393 vlc_mutex_unlock( &p_aout_bank->lock );
398 vlc_mutex_lock( &p_aout_bank->lock );
399 for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
401 if( p_aout_bank->pp_aout[i_index]->i_savedvolume )
403 p_aout_bank->pp_aout[i_index]->i_volume =
404 p_aout_bank->pp_aout[i_index]->i_savedvolume;
405 p_aout_bank->pp_aout[i_index]->i_savedvolume = 0;
409 p_aout_bank->pp_aout[i_index]->i_savedvolume =
410 p_aout_bank->pp_aout[i_index]->i_volume;
411 p_aout_bank->pp_aout[i_index]->i_volume = 0;
414 vlc_mutex_unlock( &p_aout_bank->lock );
419 int32 i = p_message->FindInt32( "channel" );
422 input_ChangeES( p_input_bank->pp_input[0], NULL, AUDIO_ES );
426 input_ChangeES( p_input_bank->pp_input[0],
427 p_input_bank->pp_input[0]->stream.pp_es[i], AUDIO_ES );
432 case SELECT_SUBTITLE:
434 int32 i = p_message->FindInt32( "subtitle" );
437 input_ChangeES( p_input_bank->pp_input[0], NULL, SPU_ES);
441 input_ChangeES( p_input_bank->pp_input[0],
442 p_input_bank->pp_input[0]->stream.pp_es[i], SPU_ES );
448 input_area_t * p_area;
451 i_id = p_input_bank->pp_input[0]->stream.p_selected_area->i_id - 1;
453 /* Disallow area 0 since it is used for video_ts.vob */
456 p_area = p_input_bank->pp_input[0]->stream.pp_areas[i_id];
457 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
458 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
464 input_area_t * p_area;
467 i_id = p_input_bank->pp_input[0]->stream.p_selected_area->i_id + 1;
469 if( i_id < p_input_bank->pp_input[0]->stream.i_area_nb )
471 p_area = p_input_bank->pp_input[0]->stream.pp_areas[i_id];
472 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
473 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
479 input_area_t * p_area;
481 p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
483 if( p_area->i_part > 0 )
486 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
487 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
493 input_area_t * p_area;
495 p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
497 if( p_area->i_part > 0 )
500 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
501 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
505 case B_REFS_RECEIVED:
509 if( p_message->FindRef( "refs", &ref ) == B_OK )
512 intf_PlaylistAdd( p_main->p_playlist,
513 PLAYLIST_END, (char*)path.Path() );
514 if( p_input_bank->pp_input[0] != NULL )
516 p_input_bank->pp_input[0]->b_eof = 1;
518 intf_PlaylistJumpto( p_main->p_playlist,
519 p_main->p_playlist->i_size - 1 );
526 BWindow::MessageReceived( p_message );
532 /*****************************************************************************
533 * InterfaceWindow::updateInterface
534 *****************************************************************************/
535 void InterfaceWindow::updateInterface()
537 if ( p_input_bank->pp_input[0] )
539 if ( acquire_sem(p_mediaControl->fScrubSem) == B_OK )
541 uint64 seekTo = (p_mediaControl->GetSeekTo() *
542 p_input_bank->pp_input[0]->stream.p_selected_area->i_size) / 100;
543 input_Seek( p_input_bank->pp_input[0], seekTo);
547 p_mediaControl->SetStatus(p_input_bank->pp_input[0]->stream.control.i_status,
548 p_input_bank->pp_input[0]->stream.control.i_rate);
549 p_mediaControl->SetProgress(p_input_bank->pp_input[0]->stream.p_selected_area->i_tell,
550 p_input_bank->pp_input[0]->stream.p_selected_area->i_size);
554 if ( b_empty_playlist != (p_main->p_playlist->i_size < 1) )
558 b_empty_playlist = !b_empty_playlist;
559 p_mediaControl->SetEnabled( !b_empty_playlist );
565 /*****************************************************************************
566 * InterfaceWindow::QuitRequested
567 *****************************************************************************/
568 bool InterfaceWindow::QuitRequested()
575 /*****************************************************************************
577 *****************************************************************************/
578 CDMenu::CDMenu(const char *name)
583 /*****************************************************************************
585 *****************************************************************************/
590 /*****************************************************************************
591 * CDMenu::AttachedToWindow
592 *****************************************************************************/
593 void CDMenu::AttachedToWindow(void)
595 while (RemoveItem((long int)0) != NULL); // remove all items
597 BMenu::AttachedToWindow();
600 /*****************************************************************************
602 *****************************************************************************/
603 int CDMenu::GetCD( const char *directory )
605 BVolumeRoster *volRoster;
610 char name[B_FILE_NAME_LENGTH];
614 volRoster = new BVolumeRoster();
616 dir = new BDirectory();
617 status = volRoster->GetNextVolume(vol);
618 status = vol->GetRootDirectory(dir);
619 while (status == B_NO_ERROR)
621 mounted = vol->GetName(name);
622 if ((mounted == B_OK) && /* Disk is currently Mounted */
623 (vol->IsReadOnly()) ) /* Disk is read-only */
626 fs_stat_dev(dev, &info);
630 i_dev = open( info.device_name, O_RDONLY );
634 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
636 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
639 msg = new BMessage( OPEN_DVD );
640 msg->AddString( "device", info.device_name );
641 BMenuItem *menu_item;
642 menu_item = new BMenuItem( name, msg );
643 AddItem( menu_item );
650 status = volRoster->GetNextVolume(vol);
654 /*****************************************************************************
655 * LanguageMenu::LanguageMenu
656 *****************************************************************************/
657 LanguageMenu::LanguageMenu(const char *name, int menu_kind,
658 intf_thread_t *p_interface)
662 p_intf = p_interface;
665 /*****************************************************************************
666 * LanguageMenu::~LanguageMenu
667 *****************************************************************************/
668 LanguageMenu::~LanguageMenu()
672 /*****************************************************************************
673 * LanguageMenu::AttachedToWindow
674 *****************************************************************************/
675 void LanguageMenu::AttachedToWindow(void)
677 while( RemoveItem((long int)0) != NULL )
679 ; // remove all items
684 BMenu::AttachedToWindow();
687 /*****************************************************************************
688 * LanguageMenu::GetChannels
689 *****************************************************************************/
690 int LanguageMenu::GetChannels()
696 es_descriptor_t *p_es = NULL;
698 /* Insert the null */
699 if( kind == AUDIO_ES ) //audio
701 msg = new BMessage(SELECT_CHANNEL);
702 msg->AddInt32("channel", -1);
706 msg = new BMessage(SELECT_SUBTITLE);
707 msg->AddInt32("subtitle", -1);
709 BMenuItem *menu_item;
710 menu_item = new BMenuItem("None", msg);
712 menu_item->SetMarked(TRUE);
714 if( p_input_bank->pp_input[0] == NULL )
720 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
721 for( i = 0; i < p_input_bank->pp_input[0]->stream.i_selected_es_number; i++ )
723 if( kind == p_input_bank->pp_input[0]->stream.pp_selected_es[i]->i_cat )
725 p_es = p_input_bank->pp_input[0]->stream.pp_selected_es[i];
729 for( i = 0; i < p_input_bank->pp_input[0]->stream.i_es_number; i++ )
731 if( kind == p_input_bank->pp_input[0]->stream.pp_es[i]->i_cat )
733 psz_name = p_input_bank->pp_input[0]->stream.pp_es[i]->psz_desc;
734 if( kind == AUDIO_ES ) //audio
736 msg = new BMessage(SELECT_CHANNEL);
737 msg->AddInt32("channel", i);
741 msg = new BMessage(SELECT_SUBTITLE);
742 msg->AddInt32("subtitle", i);
744 BMenuItem *menu_item;
745 menu_item = new BMenuItem(psz_name, msg);
747 b_active = (p_es == p_input_bank->pp_input[0]->stream.pp_es[i]);
748 menu_item->SetMarked(b_active);
751 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );