1 /*****************************************************************************
2 * intf_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: intf_beos.cpp,v 1.19 2001/03/07 16:32:59 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 );
126 menu_bar->AddItem( m = new BMenu("File") );
127 menu_bar->ResizeToPreferred();
128 m->AddItem( new BMenuItem("Open File...", new BMessage(OPEN_FILE), 'O'));
129 cd_menu = new CDMenu("Open DVD");
130 //GetCD("/dev/disk", cd_menu);
132 m->AddSeparatorItem();
133 m->AddItem( new BMenuItem("About...", new BMessage(B_ABOUT_REQUESTED), 'A'));
134 m->AddItem( new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
138 rect.top += menu_bar->Bounds().IntegerHeight()+1;
141 p_view = new BBox( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER );
142 p_view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
146 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
147 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
148 xStart += kRewindBitmapWidth;
149 TransportButton* p_slow = new TransportButton(ButtonRect, B_EMPTY_STRING,
151 kPressedSkipBackBitmapBits,
152 kDisabledSkipBackBitmapBits,
153 new BMessage(SLOWER_PLAY));
154 p_view->AddChild( p_slow );
157 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
158 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kPlayButtonSize);
159 xStart += kPlayPauseBitmapWidth + 1.0;
160 PlayPauseButton* p_play = new PlayPauseButton(ButtonRect, B_EMPTY_STRING,
161 kPlayButtonBitmapBits,
162 kPressedPlayButtonBitmapBits,
163 kDisabledPlayButtonBitmapBits,
164 kPlayingPlayButtonBitmapBits,
165 kPressedPlayingPlayButtonBitmapBits,
166 kPausedPlayButtonBitmapBits,
167 kPressedPausedPlayButtonBitmapBits,
168 new BMessage(START_PLAYBACK));
170 p_view->AddChild( p_play );
171 p_play->SetPlaying();
174 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
175 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
176 xStart += kRewindBitmapWidth;
177 TransportButton* p_fast = new TransportButton(ButtonRect, B_EMPTY_STRING,
178 kSkipForwardBitmapBits,
179 kPressedSkipForwardBitmapBits,
180 kDisabledSkipForwardBitmapBits,
181 new BMessage(FASTER_PLAY));
182 p_view->AddChild( p_fast );
185 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
186 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kStopButtonSize);
187 xStart += kStopBitmapWidth;
188 TransportButton* p_stop = new TransportButton(ButtonRect, B_EMPTY_STRING,
189 kStopButtonBitmapBits,
190 kPressedStopButtonBitmapBits,
191 kDisabledStopButtonBitmapBits,
192 new BMessage(STOP_PLAYBACK));
193 p_view->AddChild( p_stop );
195 ButtonRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
196 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSpeakerButtonSize);
197 xStart += kSpeakerIconBitmapWidth;
199 TransportButton* p_mute = new TransportButton(ButtonRect, B_EMPTY_STRING,
201 kPressedSpeakerIconBits,
203 new BMessage(VOLUME_MUTE));
205 p_view->AddChild( p_mute );
208 rgb_color fill_color = {0,255,0};
209 p_seek = new SeekSlider(BRect(5,2,255,15), this, 0, 100,
212 p_seek->UseFillColor(true, &fill_color);
213 p_view->AddChild( p_seek );
216 p_vol = new MediaSlider(BRect(xStart,20,255,30), new BMessage(VOLUME_CHG),
218 p_vol->SetValue(VOLUME_DEFAULT);
219 p_vol->UseFillColor(true, &fill_color);
220 p_view->AddChild( p_vol );
222 /* Set size and Show */
224 ResizeTo(260,50 + menu_bar->Bounds().IntegerHeight()+1);
228 InterfaceWindow::~InterfaceWindow()
232 /*****************************************************************************
233 * InterfaceWindow::MessageReceived
234 *****************************************************************************/
235 void InterfaceWindow::MessageReceived( BMessage * p_message )
237 int vol_val = p_vol->Value(); // remember the current volume
238 static int playback_status; // remember playback state
242 switch( p_message->what )
244 case B_ABOUT_REQUESTED:
245 alert = new BAlert(VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
255 file_panel = new BFilePanel();
256 file_panel->SetTarget(this);
262 char device_method_and_name[B_FILE_NAME_LENGTH + 4];
263 if(p_message->FindString("device", device) != B_ERROR)
265 sprintf(device_method_and_name, "dvd:%s", *device);
266 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, device_method_and_name );
271 // this currently stops playback not nicely
272 if (p_intf->p_input != NULL )
274 // silence the sound, otherwise very horrible
275 if (p_main->p_aout != NULL)
277 p_main->p_aout->vol = 0;
280 input_SetStatus(p_intf->p_input, INPUT_STATUS_END);
284 // starts playing in normal mode
285 // if (p_intf->p_input != NULL )
287 // if (p_main->p_aout != NULL)
289 // p_main->p_aout->vol = vol_val;
292 // input_SetStatus(p_intf->p_input, INPUT_STATUS_PLAY);
293 // playback_status = PLAYING;
297 // pause the playback
298 if (p_intf->p_input != NULL )
300 // mute the volume if currently playing
301 if (playback_status == PLAYING)
303 if (p_main->p_aout != NULL)
305 p_main->p_aout->vol = 0;
307 playback_status = PAUSED;
310 // restore the volume
312 if (p_main->p_aout != NULL)
314 p_main->p_aout->vol = vol_val;
316 playback_status = PLAYING;
319 input_SetStatus(p_intf->p_input, INPUT_STATUS_PAUSE);
323 // cycle the fast playback modes
324 if (p_intf->p_input != NULL )
326 if (p_main->p_aout != NULL)
328 p_main->p_aout->vol = 0;
331 input_SetStatus(p_intf->p_input, INPUT_STATUS_FASTER);
335 // cycle the slow playback modes
336 if (p_intf->p_input != NULL )
338 if (p_main->p_aout != NULL)
340 p_main->p_aout->vol = 0;
343 input_SetStatus(p_intf->p_input, INPUT_STATUS_SLOWER);
347 // handled by semaphores;
348 /* if( p_intf->p_input != NULL )
351 if (p_message->FindFloat("be:value", &new_position) == B_OK)
353 printf("%e\n", new_position);
354 input_Seek( p_intf->p_input, new_position * 100 );
360 if (p_main->p_aout != NULL)
362 p_main->p_aout->vol = vol_val;
367 if (p_main->p_aout != NULL)
369 if (p_main->p_aout->vol == 0)
371 p_vol->SetEnabled(true);
372 p_main->p_aout->vol = vol_val;
376 p_vol->SetEnabled(false);
377 p_main->p_aout->vol = 0;
383 case B_REFS_RECEIVED:
387 if( p_message->FindRef( "refs", &ref ) == B_OK )
390 char * psz_name = strdup(path.Path());
391 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_name );
397 BWindow::MessageReceived( p_message );
402 /*****************************************************************************
403 * InterfaceWindow::QuitRequested
404 *****************************************************************************/
406 bool InterfaceWindow::QuitRequested()
413 /*****************************************************************************
415 *****************************************************************************/
417 CDMenu::CDMenu(const char *name)
422 /*****************************************************************************
424 *****************************************************************************/
431 /*****************************************************************************
432 * CDMenu::AttachedToWindow
433 *****************************************************************************/
435 void CDMenu::AttachedToWindow(void)
437 int32 items = CountItems();
438 for(int32 i = 0; i < items; i++)
441 BMenu::AttachedToWindow();
444 /*****************************************************************************
446 *****************************************************************************/
448 int CDMenu::GetCD(const char *directory)
451 dir.SetTo(directory);
452 if(dir.InitCheck() != B_NO_ERROR) {
457 while(dir.GetNextEntry(&entry) >= 0) {
462 if(entry.GetPath(&path) != B_NO_ERROR)
467 if(entry.GetRef(&e) != B_NO_ERROR)
470 if(entry.IsDirectory()) {
471 if(strcmp(e.name, "floppy") == 0)
472 continue; // ignore floppy (it is not silent)
473 int devfd = GetCD(name);
484 if(strcmp(e.name, "raw") != 0)
485 continue; // ignore partitions
487 devfd = open(name, O_RDONLY);
491 if(ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) {
492 if(g.device_type == B_CD) //ensure the drive is a CD-ROM
494 if(ioctl(devfd, B_GET_MEDIA_STATUS, &m, sizeof(m)) >= 0 )
495 if(m == B_NO_ERROR) //ensure media is present
498 msg = new BMessage(OPEN_DVD);
499 msg->AddString("device", name);
500 BMenuItem *menu_item;
501 menu_item = new BMenuItem(name, msg);
514 /*****************************************************************************
516 *****************************************************************************/
517 MediaSlider::MediaSlider(BRect frame,
521 :BSlider(frame, NULL, NULL, message, minValue, maxValue)
526 MediaSlider::~MediaSlider()
531 void MediaSlider::DrawThumb(void)
536 rgb_color black = {0,0,0};
540 v->SetHighColor(black);
542 v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
543 r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/6);
546 v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
548 v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
553 /*****************************************************************************
555 *****************************************************************************/
556 SeekSlider::SeekSlider(BRect frame,
557 InterfaceWindow *owner,
560 thumb_style thumbType = B_TRIANGLE_THUMB)
561 :MediaSlider(frame, NULL, minValue, maxValue)
567 SeekSlider::~SeekSlider()
571 /*****************************************************************************
572 * SeekSlider::MouseDown
573 *****************************************************************************/
574 void SeekSlider::MouseDown(BPoint where)
576 BSlider::MouseDown(where);
577 fOwner->fScrubSem = create_sem(1, "Vlc::fScrubSem");
581 /*****************************************************************************
582 * SeekSlider::MouseUp
583 *****************************************************************************/
584 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
586 BSlider::MouseMoved(where, code, message);
589 release_sem(fOwner->fScrubSem);
592 /*****************************************************************************
593 * SeekSlider::MouseUp
594 *****************************************************************************/
595 void SeekSlider::MouseUp(BPoint where)
597 BSlider::MouseUp(where);
598 delete_sem(fOwner->fScrubSem);
599 fOwner->fScrubSem = B_ERROR;
607 /*****************************************************************************
609 *****************************************************************************/
610 static int intf_Probe ( probedata_t *p_data );
611 static int intf_Open ( intf_thread_t *p_intf );
612 static void intf_Close ( intf_thread_t *p_intf );
613 static void intf_Run ( intf_thread_t *p_intf );
615 /*****************************************************************************
616 * Functions exported as capabilities. They are declared as static so that
617 * we don't pollute the namespace too much.
618 *****************************************************************************/
619 void _M( intf_getfunctions )( function_list_t * p_function_list )
621 p_function_list->pf_probe = intf_Probe;
622 p_function_list->functions.intf.pf_open = intf_Open;
623 p_function_list->functions.intf.pf_close = intf_Close;
624 p_function_list->functions.intf.pf_run = intf_Run;
627 /*****************************************************************************
628 * intf_Probe: probe the interface and return a score
629 *****************************************************************************
630 * This function tries to initialize Gnome and returns a score to the
631 * plugin manager so that it can select the best plugin.
632 *****************************************************************************/
633 static int intf_Probe( probedata_t *p_data )
635 if( TestMethod( INTF_METHOD_VAR, "beos" ) )
643 /*****************************************************************************
644 * intf_Open: initialize interface
645 *****************************************************************************/
646 static int intf_Open( intf_thread_t *p_intf )
649 screen = new BScreen();
650 BRect rect = screen->Frame();
651 rect.top = rect.bottom-100;
654 rect.right = rect.left + 350;
657 /* Allocate instance and initialize some members */
658 p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
659 if( p_intf->p_sys == NULL )
661 intf_ErrMsg("error: %s", strerror(ENOMEM));
664 p_intf->p_sys->i_key = -1;
666 /* Create the interface window */
667 p_intf->p_sys->p_window =
668 new InterfaceWindow( rect,
669 VOUT_TITLE " (BeOS interface)", p_intf );
670 if( p_intf->p_sys->p_window == 0 )
672 free( p_intf->p_sys );
673 intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
680 /*****************************************************************************
681 * intf_Close: destroy dummy interface
682 *****************************************************************************/
683 static void intf_Close( intf_thread_t *p_intf )
685 /* Destroy the interface window */
686 p_intf->p_sys->p_window->Lock();
687 p_intf->p_sys->p_window->Quit();
689 /* Destroy structure */
690 free( p_intf->p_sys );
694 /*****************************************************************************
695 * intf_Run: event loop
696 *****************************************************************************/
697 static void intf_Run( intf_thread_t *p_intf )
701 bool seekNeeded = false;
703 while( !p_intf->b_die )
706 /* Manage core vlc functions through the callback */
707 p_intf->pf_manage( p_intf );
709 /* Manage the slider */
710 if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL)
712 if (acquire_sem(p_intf->p_sys->p_window->fScrubSem) == B_OK)
719 uint32 seekTo = (p_intf->p_sys->p_window->p_seek->Value() *
720 p_intf->p_input->stream.p_selected_area->i_size) / 100;
721 input_Seek( p_intf->p_input, seekTo );
724 else if (p_intf->p_sys->p_window->Lock())
726 progress = (100. * p_intf->p_input->stream.p_selected_area->i_tell) /
727 p_intf->p_input->stream.p_selected_area->i_size;
728 p_intf->p_sys->p_window->p_seek->SetValue(progress);
729 p_intf->p_sys->p_window->Unlock();
734 msleep( INTF_IDLE_SLEEP );