]> git.sesse.net Git - vlc/blob - plugins/beos/intf_beos.cpp
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / plugins / beos / intf_beos.cpp
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 $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *
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.
14  * 
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.
19  *
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  *****************************************************************************/
24
25 #define MODULE_NAME beos
26 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32
33 #include <stdio.h>
34 #include <stdlib.h>                                      /* malloc(), free() */
35
36 #include <kernel/OS.h>
37 #include <storage/Path.h>
38 #include <View.h>
39 #include <Application.h>
40 #include <Message.h>
41 #include <NodeInfo.h>
42 #include <Locker.h>
43 #include <DirectWindow.h>
44
45 #include <malloc.h>
46 #include <string.h>
47
48 extern "C"
49 {
50 #include "config.h"
51 #include "common.h"
52 #include "threads.h"
53 #include "mtime.h"
54 #include "tests.h"
55 #include "modules.h"
56
57 #include "intf_msg.h"
58 #include "intf_plst.h"
59 #include "interface.h"
60
61 #include "main.h"
62 }
63
64 #include "beos_window.h"
65
66 /*****************************************************************************
67  * intf_sys_t: description and status of FB interface
68  *****************************************************************************/
69 typedef struct intf_sys_s
70 {
71     InterfaceWindow * p_window;
72     char              i_key;
73 } intf_sys_t;
74
75 /*****************************************************************************
76  * InterfaceWindow
77  *****************************************************************************/
78  
79 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t  *p_interface )
80     : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_ZOOMABLE)
81 {
82     p_intf = p_interface;
83     SetName( "interface" );
84     
85     BView * p_view;
86     
87     p_view = new BView( Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW );
88     AddChild( p_view );
89     
90     Show();
91 }
92
93 InterfaceWindow::~InterfaceWindow()
94 {
95 }
96
97 /*****************************************************************************
98  * InterfaceWindow::MessageReceived
99  *****************************************************************************/
100
101 void InterfaceWindow::MessageReceived( BMessage * p_message )
102 {
103     char * psz_key;
104     
105     switch( p_message->what )
106     {
107     case B_KEY_DOWN:
108         p_message->FindString( "bytes", (const char **)&psz_key );
109         p_intf->p_sys->i_key = psz_key[0];
110         break;
111         
112     case B_SIMPLE_DATA:
113         {
114             entry_ref ref;
115             if( p_message->FindRef( "refs", &ref ) == B_OK )
116             {
117                 BPath path( &ref );
118                 char * psz_name = strdup(path.Path());
119                 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'",
120                               psz_name );
121                 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_name );
122             }
123
124         }
125         break;
126
127     default:
128         BWindow::MessageReceived( p_message );
129         break;
130     }
131 }
132
133 /*****************************************************************************
134  * InterfaceWindow::QuitRequested
135  *****************************************************************************/
136
137 bool InterfaceWindow::QuitRequested()
138 {
139     p_intf->b_die = 1;
140
141     return( false );
142 }
143
144 extern "C"
145 {
146
147 /*****************************************************************************
148  * Local prototypes.
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 );
154
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 )
160 {
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;
165 }
166
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 )
174 {
175     if( TestMethod( INTF_METHOD_VAR, "beos" ) )
176     {
177         return( 999 );
178     }
179
180     return( 100 );
181 }
182
183 /*****************************************************************************
184  * intf_Open: initialize dummy interface
185  *****************************************************************************/
186 static int intf_Open( intf_thread_t *p_intf )
187 {
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 )
191     {
192         intf_ErrMsg("error: %s", strerror(ENOMEM));
193         return( 1 );
194     }
195     p_intf->p_sys->i_key = -1;
196     
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 )
202     {
203         free( p_intf->p_sys );
204         intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
205         return( 1 );
206     }
207     
208     /* Bind normal keys. */
209     intf_AssignNormalKeys( p_intf );
210
211     return( 0 );
212 }
213
214 /*****************************************************************************
215  * intf_Close: destroy dummy interface
216  *****************************************************************************/
217 static void intf_Close( intf_thread_t *p_intf )
218 {
219     /* Destroy the interface window */
220     p_intf->p_sys->p_window->Lock();
221     p_intf->p_sys->p_window->Quit();    
222
223     /* Destroy structure */
224     free( p_intf->p_sys );
225 }
226
227
228 /*****************************************************************************
229  * intf_Run: event loop
230  *****************************************************************************/
231 static void intf_Run( intf_thread_t *p_intf )
232 {
233     while( !p_intf->b_die )
234     {
235         /* Manage core vlc functions through the callback */
236         p_intf->pf_manage( p_intf );
237
238         /* Manage keys */
239         if( p_intf->p_sys->i_key != -1 )
240         {
241             intf_ProcessKey( p_intf, p_intf->p_sys->i_key );
242             p_intf->p_sys->i_key = -1;
243         }
244
245         /* Wait a bit */
246         msleep( INTF_IDLE_SLEEP );
247     }
248 }
249
250 } /* extern "C" */