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