1 /*****************************************************************************
2 * intf_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: intf_beos.cpp,v 1.9 2001/02/19 03:46:27 sam Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
31 #include <stdlib.h> /* malloc(), free() */
33 #include <kernel/OS.h>
34 #include <storage/Path.h>
36 #include <Application.h>
40 #include <DirectWindow.h>
55 #include "intf_plst.h"
56 #include "interface.h"
61 #include "beos_window.h"
63 /*****************************************************************************
64 * intf_sys_t: description and status of FB interface
65 *****************************************************************************/
66 typedef struct intf_sys_s
68 InterfaceWindow * p_window;
72 /*****************************************************************************
74 *****************************************************************************/
76 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t *p_interface )
77 : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE)
80 SetName( "interface" );
84 p_view = new BView( Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW );
90 InterfaceWindow::~InterfaceWindow()
94 /*****************************************************************************
95 * InterfaceWindow::MessageReceived
96 *****************************************************************************/
98 void InterfaceWindow::MessageReceived( BMessage * p_message )
102 switch( p_message->what )
105 p_message->FindString( "bytes", (const char **)&psz_key );
106 p_intf->p_sys->i_key = psz_key[0];
112 if( p_message->FindRef( "refs", &ref ) == B_OK )
115 char * psz_name = strdup(path.Path());
116 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'",
118 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_name );
125 BWindow::MessageReceived( p_message );
130 /*****************************************************************************
131 * InterfaceWindow::QuitRequested
132 *****************************************************************************/
134 bool InterfaceWindow::QuitRequested()
144 /*****************************************************************************
146 *****************************************************************************/
147 static int intf_Probe ( probedata_t *p_data );
148 static int intf_Open ( intf_thread_t *p_intf );
149 static void intf_Close ( intf_thread_t *p_intf );
150 static void intf_Run ( intf_thread_t *p_intf );
152 /*****************************************************************************
153 * Functions exported as capabilities. They are declared as static so that
154 * we don't pollute the namespace too much.
155 *****************************************************************************/
156 void intf_getfunctions( function_list_t * p_function_list )
158 p_function_list->pf_probe = intf_Probe;
159 p_function_list->functions.intf.pf_open = intf_Open;
160 p_function_list->functions.intf.pf_close = intf_Close;
161 p_function_list->functions.intf.pf_run = intf_Run;
164 /*****************************************************************************
165 * intf_Probe: probe the interface and return a score
166 *****************************************************************************
167 * This function tries to initialize Gnome and returns a score to the
168 * plugin manager so that it can select the best plugin.
169 *****************************************************************************/
170 static int intf_Probe( probedata_t *p_data )
172 if( TestMethod( INTF_METHOD_VAR, "beos" ) )
180 /*****************************************************************************
181 * intf_Open: initialize dummy interface
182 *****************************************************************************/
183 static int intf_Open( intf_thread_t *p_intf )
185 /* Allocate instance and initialize some members */
186 p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
187 if( p_intf->p_sys == NULL )
189 intf_ErrMsg("error: %s", strerror(ENOMEM));
192 p_intf->p_sys->i_key = -1;
194 /* Create the interface window */
195 p_intf->p_sys->p_window =
196 new InterfaceWindow( BRect( 50, 50, 400, 100 ),
197 VOUT_TITLE " (BeOS interface)", p_intf );
198 if( p_intf->p_sys->p_window == 0 )
200 free( p_intf->p_sys );
201 intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
205 /* Bind normal keys. */
206 intf_AssignNormalKeys( p_intf );
211 /*****************************************************************************
212 * intf_Close: destroy dummy interface
213 *****************************************************************************/
214 static void intf_Close( intf_thread_t *p_intf )
216 /* Destroy the interface window */
217 p_intf->p_sys->p_window->Lock();
218 p_intf->p_sys->p_window->Quit();
220 /* Destroy structure */
221 free( p_intf->p_sys );
225 /*****************************************************************************
226 * intf_Run: event loop
227 *****************************************************************************/
228 static void intf_Run( intf_thread_t *p_intf )
230 while( !p_intf->b_die )
232 /* Manage core vlc functions through the callback */
233 p_intf->pf_manage( p_intf );
236 if( p_intf->p_sys->i_key != -1 )
238 intf_ProcessKey( p_intf, p_intf->p_sys->i_key );
239 p_intf->p_sys->i_key = -1;
243 msleep( INTF_IDLE_SLEEP );