1 /*****************************************************************************
2 * InterfaceWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: InterfaceWindow.cpp,v 1.1 2002/08/04 17:23:43 sam 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>
32 #include <SupportKit.h>
35 #include <scsiprobe_driver.h>
45 /* BeOS interface headers */
47 #include "MediaControlView.h"
48 #include "PlayListWindow.h"
49 #include "VlcWrapper.h"
50 #include "InterfaceWindow.h"
53 /*****************************************************************************
55 *****************************************************************************/
57 InterfaceWindow::InterfaceWindow( BRect frame, const char *name,
58 intf_thread_t *p_interface )
59 : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
60 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK
61 | B_ASYNCHRONOUS_CONTROLS )
64 playlist_window = NULL;
66 p_vlc_wrapper = Intf_VLCWrapper::getVLCWrapper(p_intf);
67 BRect controlRect(0,0,0,0);
69 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
71 b_empty_playlist = (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");
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 /* Add the Navigation menu */
116 menu_bar->AddItem( mNavigation = new BMenu( "Navigation" ) );
117 menu_bar->ResizeToPreferred();
118 mNavigation->AddItem( new BMenuItem( "Prev Title",
119 new BMessage(PREV_TITLE)) );
120 mNavigation->AddItem( new BMenuItem( "Next Title",
121 new BMessage(NEXT_TITLE)) );
122 mNavigation->AddItem( new BMenuItem( "Prev Chapter",
123 new BMessage(PREV_CHAPTER)) );
124 mNavigation->AddItem( new BMenuItem( "Next Chapter",
125 new BMessage(NEXT_CHAPTER)) );
127 ResizeTo(260,50 + menu_bar->Bounds().IntegerHeight()+1);
128 controlRect = Bounds();
129 controlRect.top += menu_bar->Bounds().IntegerHeight() + 1;
131 p_mediaControl = new MediaControlView( controlRect );
132 p_mediaControl->SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
133 b_empty_playlist = true;
134 p_mediaControl->SetEnabled( !b_empty_playlist );
137 AddChild( p_mediaControl );
142 InterfaceWindow::~InterfaceWindow()
144 if (playlist_window) playlist_window->ReallyQuit();
147 /*****************************************************************************
148 * InterfaceWindow::MessageReceived
149 *****************************************************************************/
150 void InterfaceWindow::MessageReceived( BMessage * p_message )
152 int vol_val = p_mediaControl->GetVolume(); // remember the current volume
153 int playback_status; // remember playback state
158 playback_status = p_vlc_wrapper->inputGetStatus();
160 switch( p_message->what )
162 case B_ABOUT_REQUESTED:
163 alert = new BAlert(VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
176 file_panel = new BFilePanel();
177 file_panel->SetTarget( this );
179 b_empty_playlist = false;
180 p_mediaControl->SetEnabled( !b_empty_playlist );
185 BRect rect(20,20,320,420);
186 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
189 playlist_window = PlayListWindow::getPlayList(rect,
190 "Playlist", p_playlist);
191 playlist_window->Show();
196 const char *psz_device;
198 if( p_message->FindString("device", &psz_device) != B_ERROR )
200 BString device(psz_device);
201 p_vlc_wrapper->openDisc(type, device, 0,0);
207 // this currently stops playback not nicely
208 //p_vlc_wrapper->volume_mute();
210 p_vlc_wrapper->playlistStop();
211 p_mediaControl->SetStatus(NOT_STARTED_S,DEFAULT_RATE);
215 /* starts playing in normal mode */
218 /* toggle between pause and play */
219 if( p_intf->p_sys->p_input != NULL )
221 /* pause if currently playing */
222 if ( playback_status == PLAYING_S )
224 //p_vlc_wrapper->volume_mute();
226 p_vlc_wrapper->playlistPause();
230 //p_vlc_wrapper->volume_restore();
231 p_vlc_wrapper->playlistPlay();
236 /* Play a new file */
237 p_vlc_wrapper->playlistPlay();
242 /* cycle the fast playback modes */
243 //p_vlc_wrapper->volume_mute();
245 p_vlc_wrapper->playFaster();
249 /* cycle the slow playback modes */
250 //p_vlc_wrapper->volume_mute();
252 p_vlc_wrapper->playSlower();
256 /* handled by semaphores */
260 /* adjust the volume */
261 // vlc_mutex_lock( &p_intf->p_sys->p_input->lock );
262 // for( i_index = 0 ; i_index < p_aout_bank->i_count ; i_index++ )
264 // if( p_aout_bank->pp_aout[i_index]->i_savedvolume )
266 // p_aout_bank->pp_aout[i_index]->i_savedvolume = vol_val;
270 // p_aout_bank->pp_aout[i_index]->i_volume = vol_val;
273 // vlc_mutex_unlock( &p_aout_bank->lock );
278 p_vlc_wrapper->toggleMute( );
283 int32 i = p_message->FindInt32( "audio" );
284 p_vlc_wrapper->toggleLanguage( i );
288 case SELECT_SUBTITLE:
290 int32 i = p_message->FindInt32( "subtitle" );
291 p_vlc_wrapper->toggleSubtitle( i );
297 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id - 1;
299 /* Disallow area 0 since it is used for video_ts.vob */
302 p_vlc_wrapper->toggleTitle(i_id);
310 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_id + 1;
312 if( i_id < p_intf->p_sys->p_input->stream.i_area_nb )
314 p_vlc_wrapper->toggleTitle(i_id);
322 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part - 1;
326 p_vlc_wrapper->toggleChapter(i_id);
334 i_id = p_intf->p_sys->p_input->stream.p_selected_area->i_part + 1;
338 p_vlc_wrapper->toggleChapter(i_id);
342 case B_REFS_RECEIVED:
346 BList* files = new BList();
349 while( p_message->FindRef( "refs", i, &ref ) == B_OK )
353 files->AddItem(new BString((char*)path.Path()) );
356 p_vlc_wrapper->openFiles(files);
362 BWindow::MessageReceived( p_message );
368 /*****************************************************************************
369 * InterfaceWindow::updateInterface
370 *****************************************************************************/
371 void InterfaceWindow::updateInterface()
374 if ( p_intf->p_sys->p_input != NULL )
376 if ( acquire_sem(p_mediaControl->fScrubSem) == B_OK )
378 p_vlc_wrapper->setTimeAsFloat(p_mediaControl->GetSeekTo());
382 p_mediaControl->SetStatus(p_intf->p_sys->p_input->stream.control.i_status,
383 p_intf->p_sys->p_input->stream.control.i_rate);
384 p_mediaControl->SetProgress(p_intf->p_sys->p_input->stream.p_selected_area->i_tell,
385 p_intf->p_sys->p_input->stream.p_selected_area->i_size);
390 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
393 if ( b_empty_playlist != (p_playlist->i_size < 1) )
397 b_empty_playlist = !b_empty_playlist;
398 p_mediaControl->SetEnabled( !b_empty_playlist );
404 /*****************************************************************************
405 * InterfaceWindow::QuitRequested
406 *****************************************************************************/
407 bool InterfaceWindow::QuitRequested()
409 p_intf->p_vlc->b_die = VLC_TRUE;
414 /*****************************************************************************
416 *****************************************************************************/
417 CDMenu::CDMenu(const char *name)
422 /*****************************************************************************
424 *****************************************************************************/
429 /*****************************************************************************
430 * CDMenu::AttachedToWindow
431 *****************************************************************************/
432 void CDMenu::AttachedToWindow(void)
434 while (RemoveItem((long int)0) != NULL); // remove all items
436 BMenu::AttachedToWindow();
439 /*****************************************************************************
441 *****************************************************************************/
442 int CDMenu::GetCD( const char *directory )
444 BVolumeRoster *volRoster;
449 char name[B_FILE_NAME_LENGTH];
453 volRoster = new BVolumeRoster();
455 dir = new BDirectory();
456 status = volRoster->GetNextVolume(vol);
457 status = vol->GetRootDirectory(dir);
458 while (status == B_NO_ERROR)
460 mounted = vol->GetName(name);
461 if ((mounted == B_OK) && /* Disk is currently Mounted */
462 (vol->IsReadOnly()) ) /* Disk is read-only */
465 fs_stat_dev(dev, &info);
469 i_dev = open( info.device_name, O_RDONLY );
473 if( ioctl(i_dev, B_GET_GEOMETRY, &g, sizeof(g)) >= 0 )
475 if( g.device_type == B_CD ) //ensure the drive is a CD-ROM
478 msg = new BMessage( OPEN_DVD );
479 msg->AddString( "device", info.device_name );
480 BMenuItem *menu_item;
481 menu_item = new BMenuItem( name, msg );
482 AddItem( menu_item );
489 status = volRoster->GetNextVolume(vol);
493 /*****************************************************************************
494 * LanguageMenu::LanguageMenu
495 *****************************************************************************/
496 LanguageMenu::LanguageMenu(const char *name, int menu_kind,
497 intf_thread_t *p_interface)
501 p_intf = p_interface;
504 /*****************************************************************************
505 * LanguageMenu::~LanguageMenu
506 *****************************************************************************/
507 LanguageMenu::~LanguageMenu()
511 /*****************************************************************************
512 * LanguageMenu::AttachedToWindow
513 *****************************************************************************/
514 void LanguageMenu::AttachedToWindow(void)
516 while( RemoveItem((long int)0) != NULL )
518 ; // remove all items
523 BMenu::AttachedToWindow();
526 /*****************************************************************************
527 * LanguageMenu::GetChannels
528 *****************************************************************************/
529 int LanguageMenu::GetChannels()
535 es_descriptor_t *p_es = NULL;
537 /* Insert the null */
538 if( kind == SPU_ES ) //audio
540 msg = new BMessage(SELECT_SUBTITLE);
541 msg->AddInt32("subtitle", -1);
542 BMenuItem *menu_item;
543 menu_item = new BMenuItem("None", msg);
545 menu_item->SetMarked(TRUE);
549 if( p_intf->p_sys->p_input == NULL )
555 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
556 for( i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number; i++ )
558 if( kind == p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat )
560 p_es = p_intf->p_sys->p_input->stream.pp_selected_es[i];
564 for( i = 0; i < p_intf->p_sys->p_input->stream.i_es_number; i++ )
566 if( kind == p_intf->p_sys->p_input->stream.pp_es[i]->i_cat )
568 psz_name = p_intf->p_sys->p_input->stream.pp_es[i]->psz_desc;
569 if( kind == AUDIO_ES ) //audio
571 msg = new BMessage(SELECT_AUDIO);
572 msg->AddInt32("audio", i);
576 msg = new BMessage(SELECT_SUBTITLE);
577 msg->AddInt32("subtitle", i);
579 BMenuItem *menu_item;
580 menu_item = new BMenuItem(psz_name, msg);
582 b_active = (p_es == p_intf->p_sys->p_input->stream.pp_es[i]);
583 menu_item->SetMarked(b_active);
586 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );