1 /*****************************************************************************
2 * intf_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: intf_beos.cpp,v 1.10 2001/02/20 07:49:12 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 #define MODULE_NAME beos
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
34 #include <stdlib.h> /* malloc(), free() */
36 #include <kernel/OS.h>
37 #include <storage/Path.h>
39 #include <Application.h>
43 #include <DirectWindow.h>
58 #include "intf_plst.h"
59 #include "interface.h"
64 #include "beos_window.h"
66 /*****************************************************************************
67 * intf_sys_t: description and status of FB interface
68 *****************************************************************************/
69 typedef struct intf_sys_s
71 InterfaceWindow * p_window;
75 /*****************************************************************************
77 *****************************************************************************/
79 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t *p_interface )
80 : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE)
83 SetName( "interface" );
87 p_view = new BView( Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW );
93 InterfaceWindow::~InterfaceWindow()
97 /*****************************************************************************
98 * InterfaceWindow::MessageReceived
99 *****************************************************************************/
101 void InterfaceWindow::MessageReceived( BMessage * p_message )
105 switch( p_message->what )
108 p_message->FindString( "bytes", (const char **)&psz_key );
109 p_intf->p_sys->i_key = psz_key[0];
115 if( p_message->FindRef( "refs", &ref ) == B_OK )
118 char * psz_name = strdup(path.Path());
119 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'",
121 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_name );
128 BWindow::MessageReceived( p_message );
133 /*****************************************************************************
134 * InterfaceWindow::QuitRequested
135 *****************************************************************************/
137 bool InterfaceWindow::QuitRequested()
147 /*****************************************************************************
149 *****************************************************************************/
150 static int intf_Probe ( probedata_t *p_data );
151 static int intf_Open ( intf_thread_t *p_intf );
152 static void intf_Close ( intf_thread_t *p_intf );
153 static void intf_Run ( intf_thread_t *p_intf );
155 /*****************************************************************************
156 * Functions exported as capabilities. They are declared as static so that
157 * we don't pollute the namespace too much.
158 *****************************************************************************/
159 void _M( intf_getfunctions )( function_list_t * p_function_list )
161 p_function_list->pf_probe = intf_Probe;
162 p_function_list->functions.intf.pf_open = intf_Open;
163 p_function_list->functions.intf.pf_close = intf_Close;
164 p_function_list->functions.intf.pf_run = intf_Run;
167 /*****************************************************************************
168 * intf_Probe: probe the interface and return a score
169 *****************************************************************************
170 * This function tries to initialize Gnome and returns a score to the
171 * plugin manager so that it can select the best plugin.
172 *****************************************************************************/
173 static int intf_Probe( probedata_t *p_data )
175 if( TestMethod( INTF_METHOD_VAR, "beos" ) )
183 /*****************************************************************************
184 * intf_Open: initialize dummy interface
185 *****************************************************************************/
186 static int intf_Open( intf_thread_t *p_intf )
188 /* Allocate instance and initialize some members */
189 p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
190 if( p_intf->p_sys == NULL )
192 intf_ErrMsg("error: %s", strerror(ENOMEM));
195 p_intf->p_sys->i_key = -1;
197 /* Create the interface window */
198 p_intf->p_sys->p_window =
199 new InterfaceWindow( BRect( 50, 50, 400, 100 ),
200 VOUT_TITLE " (BeOS interface)", p_intf );
201 if( p_intf->p_sys->p_window == 0 )
203 free( p_intf->p_sys );
204 intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
208 /* Bind normal keys. */
209 intf_AssignNormalKeys( p_intf );
214 /*****************************************************************************
215 * intf_Close: destroy dummy interface
216 *****************************************************************************/
217 static void intf_Close( intf_thread_t *p_intf )
219 /* Destroy the interface window */
220 p_intf->p_sys->p_window->Lock();
221 p_intf->p_sys->p_window->Quit();
223 /* Destroy structure */
224 free( p_intf->p_sys );
228 /*****************************************************************************
229 * intf_Run: event loop
230 *****************************************************************************/
231 static void intf_Run( intf_thread_t *p_intf )
233 while( !p_intf->b_die )
235 /* Manage core vlc functions through the callback */
236 p_intf->pf_manage( p_intf );
239 if( p_intf->p_sys->i_key != -1 )
241 intf_ProcessKey( p_intf, p_intf->p_sys->i_key );
242 p_intf->p_sys->i_key = -1;
246 msleep( INTF_IDLE_SLEEP );