1 /*****************************************************************************
2 * intf_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: intf_beos.cpp,v 1.18 2001/03/06 19:52:03 richards Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tcastley@mail.powerup.com.au>
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 *****************************************************************************/
27 #define MODULE_NAME beos
28 #include "modules_inner.h"
30 /*****************************************************************************
32 *****************************************************************************/
36 #include <stdlib.h> /* malloc(), free() */
38 #include <kernel/OS.h>
39 #include <storage/Path.h>
45 #include <StatusBar.h>
46 #include <Application.h>
50 #include <DirectWindow.h>
55 #include <FilePanel.h>
59 #include <Directory.h>
62 #include <StorageDefs.h>
64 #include <scsiprobe_driver.h>
75 #include "stream_control.h"
76 #include "input_ext-intf.h"
78 #include "interface.h"
79 #include "intf_plst.h"
81 #include "audio_output.h"
88 #include "InterfaceWindow.h"
90 #include "TransportButton.h"
92 /*****************************************************************************
93 * intf_sys_t: description and status of FB interface
94 *****************************************************************************/
95 typedef struct intf_sys_s
97 InterfaceWindow * p_window;
101 /*****************************************************************************
103 *****************************************************************************/
105 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t *p_interface )
106 : BWindow(frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
107 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK |B_ASYNCHRONOUS_CONTROLS)
110 p_intf = p_interface;
115 SetName( "interface" );
116 SetTitle(VOUT_TITLE " (BeOS interface)");
117 BRect rect(0, 0, 0, 0);
120 menu_bar = new BMenuBar(rect, "main menu");
121 AddChild( menu_bar );
125 menu_bar->AddItem( m = new BMenu("File") );
126 menu_bar->ResizeToPreferred();
127 m->AddItem( new BMenuItem("Open File...", new BMessage(OPEN_FILE), 'O'));
128 cd_menu = new BMenu("Open DVD");
129 GetCD("/dev/disk", cd_menu);
131 m->AddSeparatorItem();
132 m->AddItem( new BMenuItem("About...", new BMessage(B_ABOUT_REQUESTED), 'A'));
133 m->AddItem( new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
137 rect.top += menu_bar->Bounds().IntegerHeight()+1;
140 p_view = new BBox( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER );
141 p_view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
145 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
146 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
147 xStart += kRewindBitmapWidth;
148 TransportButton* p_slow = new TransportButton(ButtonRect, B_EMPTY_STRING,
150 kPressedSkipBackBitmapBits,
151 kDisabledSkipBackBitmapBits,
152 new BMessage(SLOWER_PLAY));
153 p_view->AddChild( p_slow );
156 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
157 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kPlayButtonSize);
158 xStart += kPlayPauseBitmapWidth + 1.0;
159 PlayPauseButton* p_play = new PlayPauseButton(ButtonRect, B_EMPTY_STRING,
160 kPlayButtonBitmapBits,
161 kPressedPlayButtonBitmapBits,
162 kDisabledPlayButtonBitmapBits,
163 kPlayingPlayButtonBitmapBits,
164 kPressedPlayingPlayButtonBitmapBits,
165 kPausedPlayButtonBitmapBits,
166 kPressedPausedPlayButtonBitmapBits,
167 new BMessage(START_PLAYBACK));
169 p_view->AddChild( p_play );
170 p_play->SetPlaying();
173 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
174 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
175 xStart += kRewindBitmapWidth;
176 TransportButton* p_fast = new TransportButton(ButtonRect, B_EMPTY_STRING,
177 kSkipForwardBitmapBits,
178 kPressedSkipForwardBitmapBits,
179 kDisabledSkipForwardBitmapBits,
180 new BMessage(FASTER_PLAY));
181 p_view->AddChild( p_fast );
184 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
185 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kStopButtonSize);
186 xStart += kStopBitmapWidth;
187 TransportButton* p_stop = new TransportButton(ButtonRect, B_EMPTY_STRING,
188 kStopButtonBitmapBits,
189 kPressedStopButtonBitmapBits,
190 kDisabledStopButtonBitmapBits,
191 new BMessage(STOP_PLAYBACK));
192 p_view->AddChild( p_stop );
194 ButtonRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
195 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSpeakerButtonSize);
196 xStart += kSpeakerIconBitmapWidth;
198 TransportButton* p_mute = new TransportButton(ButtonRect, B_EMPTY_STRING,
200 kPressedSpeakerIconBits,
202 new BMessage(VOLUME_MUTE));
204 p_view->AddChild( p_mute );
207 rgb_color fill_color = {0,255,0};
208 p_seek = new SeekSlider(BRect(5,2,255,15), this, 0, 100,
211 p_seek->UseFillColor(true, &fill_color);
212 p_view->AddChild( p_seek );
215 p_vol = new MediaSlider(BRect(xStart,20,255,30), new BMessage(VOLUME_CHG),
217 p_vol->SetValue(VOLUME_DEFAULT);
218 p_vol->UseFillColor(true, &fill_color);
219 p_view->AddChild( p_vol );
221 /* Set size and Show */
223 ResizeTo(260,50 + menu_bar->Bounds().IntegerHeight()+1);
227 InterfaceWindow::~InterfaceWindow()
231 /*****************************************************************************
232 * InterfaceWindow::MessageReceived
233 *****************************************************************************/
234 void InterfaceWindow::MessageReceived( BMessage * p_message )
236 int vol_val = p_vol->Value(); // remember the current volume
237 static int playback_status; // remember playback state
241 switch( p_message->what )
243 case B_ABOUT_REQUESTED:
244 alert = new BAlert(VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
254 file_panel = new BFilePanel();
255 file_panel->SetTarget(this);
261 char device_method_and_name[B_FILE_NAME_LENGTH + 4];
262 if(p_message->FindString("device", device) != B_ERROR)
264 sprintf(device_method_and_name, "dvd:%s", *device);
265 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, device_method_and_name );
270 // this currently stops playback not nicely
271 if (p_intf->p_input != NULL )
273 // silence the sound, otherwise very horrible
274 if (p_main->p_aout != NULL)
276 p_main->p_aout->vol = 0;
279 input_SetStatus(p_intf->p_input, INPUT_STATUS_END);
283 // starts playing in normal mode
284 // if (p_intf->p_input != NULL )
286 // if (p_main->p_aout != NULL)
288 // p_main->p_aout->vol = vol_val;
291 // input_SetStatus(p_intf->p_input, INPUT_STATUS_PLAY);
292 // playback_status = PLAYING;
296 // pause the playback
297 if (p_intf->p_input != NULL )
299 // mute the volume if currently playing
300 if (playback_status == PLAYING)
302 if (p_main->p_aout != NULL)
304 p_main->p_aout->vol = 0;
306 playback_status = PAUSED;
309 // restore the volume
311 if (p_main->p_aout != NULL)
313 p_main->p_aout->vol = vol_val;
315 playback_status = PLAYING;
318 input_SetStatus(p_intf->p_input, INPUT_STATUS_PAUSE);
322 // cycle the fast playback modes
323 if (p_intf->p_input != NULL )
325 if (p_main->p_aout != NULL)
327 p_main->p_aout->vol = 0;
330 input_SetStatus(p_intf->p_input, INPUT_STATUS_FASTER);
334 // cycle the slow playback modes
335 if (p_intf->p_input != NULL )
337 if (p_main->p_aout != NULL)
339 p_main->p_aout->vol = 0;
342 input_SetStatus(p_intf->p_input, INPUT_STATUS_SLOWER);
346 // handled by semaphores;
347 /* if( p_intf->p_input != NULL )
350 if (p_message->FindFloat("be:value", &new_position) == B_OK)
352 printf("%e\n", new_position);
353 input_Seek( p_intf->p_input, new_position * 100 );
359 if (p_main->p_aout != NULL)
361 p_main->p_aout->vol = vol_val;
366 if (p_main->p_aout != NULL)
368 if (p_main->p_aout->vol == 0)
370 p_vol->SetEnabled(true);
371 p_main->p_aout->vol = vol_val;
375 p_vol->SetEnabled(false);
376 p_main->p_aout->vol = 0;
382 case B_REFS_RECEIVED:
386 if( p_message->FindRef( "refs", &ref ) == B_OK )
389 char * psz_name = strdup(path.Path());
390 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_name );
396 BWindow::MessageReceived( p_message );
401 /*****************************************************************************
402 * InterfaceWindow::QuitRequested
403 *****************************************************************************/
405 bool InterfaceWindow::QuitRequested()
413 int InterfaceWindow::GetCD(const char *directory, BMenu *cd_menu)
416 dir.SetTo(directory);
417 if(dir.InitCheck() != B_NO_ERROR) {
422 while(dir.GetNextEntry(&entry) >= 0) {
427 if(entry.GetPath(&path) != B_NO_ERROR)
432 if(entry.GetRef(&e) != B_NO_ERROR)
435 if(entry.IsDirectory()) {
436 if(strcmp(e.name, "floppy") == 0)
437 continue; // ignore floppy (it is not silent)
438 int devfd = GetCD(name, cd_menu);
449 if(strcmp(e.name, "raw") != 0)
450 continue; // ignore partitions
452 devfd = open(name, O_RDONLY);
456 if(ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) {
457 if(g.device_type == B_CD) //ensure the drive is a CD-ROM
459 if(ioctl(devfd, B_GET_MEDIA_STATUS, &m, sizeof(m)) >= 0 )
460 if(m == B_NO_ERROR) //ensure media is present
463 msg = new BMessage(OPEN_DVD);
464 msg->AddString("device", name);
465 BMenuItem *menu_item;
466 menu_item = new BMenuItem(name, msg);
467 cd_menu->AddItem(menu_item);
479 /*****************************************************************************
481 *****************************************************************************/
482 MediaSlider::MediaSlider(BRect frame,
486 :BSlider(frame, NULL, NULL, message, minValue, maxValue)
491 MediaSlider::~MediaSlider()
496 void MediaSlider::DrawThumb(void)
501 rgb_color black = {0,0,0};
505 v->SetHighColor(black);
507 v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
508 r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/6);
511 v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
513 v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
518 /*****************************************************************************
520 *****************************************************************************/
521 SeekSlider::SeekSlider(BRect frame,
522 InterfaceWindow *owner,
525 thumb_style thumbType = B_TRIANGLE_THUMB)
526 :MediaSlider(frame, NULL, minValue, maxValue)
532 SeekSlider::~SeekSlider()
536 /*****************************************************************************
537 * SeekSlider::MouseDown
538 *****************************************************************************/
539 void SeekSlider::MouseDown(BPoint where)
541 BSlider::MouseDown(where);
542 fOwner->fScrubSem = create_sem(1, "Vlc::fScrubSem");
546 /*****************************************************************************
547 * SeekSlider::MouseUp
548 *****************************************************************************/
549 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
551 BSlider::MouseMoved(where, code, message);
554 release_sem(fOwner->fScrubSem);
557 /*****************************************************************************
558 * SeekSlider::MouseUp
559 *****************************************************************************/
560 void SeekSlider::MouseUp(BPoint where)
562 BSlider::MouseUp(where);
563 delete_sem(fOwner->fScrubSem);
564 fOwner->fScrubSem = B_ERROR;
572 /*****************************************************************************
574 *****************************************************************************/
575 static int intf_Probe ( probedata_t *p_data );
576 static int intf_Open ( intf_thread_t *p_intf );
577 static void intf_Close ( intf_thread_t *p_intf );
578 static void intf_Run ( intf_thread_t *p_intf );
580 /*****************************************************************************
581 * Functions exported as capabilities. They are declared as static so that
582 * we don't pollute the namespace too much.
583 *****************************************************************************/
584 void _M( intf_getfunctions )( function_list_t * p_function_list )
586 p_function_list->pf_probe = intf_Probe;
587 p_function_list->functions.intf.pf_open = intf_Open;
588 p_function_list->functions.intf.pf_close = intf_Close;
589 p_function_list->functions.intf.pf_run = intf_Run;
592 /*****************************************************************************
593 * intf_Probe: probe the interface and return a score
594 *****************************************************************************
595 * This function tries to initialize Gnome and returns a score to the
596 * plugin manager so that it can select the best plugin.
597 *****************************************************************************/
598 static int intf_Probe( probedata_t *p_data )
600 if( TestMethod( INTF_METHOD_VAR, "beos" ) )
608 /*****************************************************************************
609 * intf_Open: initialize interface
610 *****************************************************************************/
611 static int intf_Open( intf_thread_t *p_intf )
614 screen = new BScreen();
615 BRect rect = screen->Frame();
616 rect.top = rect.bottom-100;
619 rect.right = rect.left + 350;
622 /* Allocate instance and initialize some members */
623 p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
624 if( p_intf->p_sys == NULL )
626 intf_ErrMsg("error: %s", strerror(ENOMEM));
629 p_intf->p_sys->i_key = -1;
631 /* Create the interface window */
632 p_intf->p_sys->p_window =
633 new InterfaceWindow( rect,
634 VOUT_TITLE " (BeOS interface)", p_intf );
635 if( p_intf->p_sys->p_window == 0 )
637 free( p_intf->p_sys );
638 intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
645 /*****************************************************************************
646 * intf_Close: destroy dummy interface
647 *****************************************************************************/
648 static void intf_Close( intf_thread_t *p_intf )
650 /* Destroy the interface window */
651 p_intf->p_sys->p_window->Lock();
652 p_intf->p_sys->p_window->Quit();
654 /* Destroy structure */
655 free( p_intf->p_sys );
659 /*****************************************************************************
660 * intf_Run: event loop
661 *****************************************************************************/
662 static void intf_Run( intf_thread_t *p_intf )
666 bool seekNeeded = false;
668 while( !p_intf->b_die )
671 /* Manage core vlc functions through the callback */
672 p_intf->pf_manage( p_intf );
674 /* Manage the slider */
675 if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL)
677 if (acquire_sem(p_intf->p_sys->p_window->fScrubSem) == B_OK)
684 uint32 seekTo = (p_intf->p_sys->p_window->p_seek->Value() *
685 p_intf->p_input->stream.p_selected_area->i_size) / 100;
686 input_Seek( p_intf->p_input, seekTo );
689 else if (p_intf->p_sys->p_window->Lock())
691 progress = (100. * p_intf->p_input->stream.p_selected_area->i_tell) /
692 p_intf->p_input->stream.p_selected_area->i_size;
693 p_intf->p_sys->p_window->p_seek->SetValue(progress);
694 p_intf->p_sys->p_window->Unlock();
699 msleep( INTF_IDLE_SLEEP );