* Now the MacOS mozilla plugin is an independant bundle ( searchs no more
[vlc.git] / src / misc / beos_specific.cpp
blobd1740e0ca22c03a91193408c40cf18936ab158ee
1 /*****************************************************************************
2 * beos_init.cpp: Initialization for BeOS specific features
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: beos_specific.cpp,v 1.31 2003/05/08 01:05:14 titer Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
23 #include <Application.h>
24 #include <Roster.h>
25 #include <Path.h>
26 #include <Alert.h>
27 #include <Message.h>
28 #include <Window.h>
30 #include <stdio.h>
31 #include <string.h> /* strdup() */
32 #include <malloc.h> /* free() */
34 extern "C"
36 #include <vlc/vlc.h>
39 /*****************************************************************************
40 * The VlcApplication class
41 *****************************************************************************/
42 class VlcApplication : public BApplication
44 public:
45 vlc_object_t *p_this;
47 VlcApplication(char* );
48 ~VlcApplication();
50 virtual void ReadyToRun();
51 virtual void AboutRequested();
52 virtual void RefsReceived(BMessage* message);
53 virtual void MessageReceived(BMessage* message);
54 virtual bool QuitRequested();
56 private:
57 BWindow* fInterfaceWindow;
58 BMessage* fRefsMessage;
61 /*****************************************************************************
62 * Static vars
63 *****************************************************************************/
65 //const uint32 INTERFACE_CREATED = 'ifcr'; /* message sent from interface */
66 #include "../../modules/gui/beos/MsgVals.h"
68 extern "C"
71 /*****************************************************************************
72 * Local prototypes.
73 *****************************************************************************/
74 static void AppThread( vlc_object_t *p_appthread );
76 /*****************************************************************************
77 * system_Init: create a BApplication object and fill in program path.
78 *****************************************************************************/
79 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
81 p_this->p_libvlc->p_appthread =
82 (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
84 /* Create the BApplication thread and wait for initialization */
85 vlc_thread_create( p_this->p_libvlc->p_appthread, "app thread", AppThread,
86 VLC_THREAD_PRIORITY_LOW, VLC_TRUE );
89 /*****************************************************************************
90 * system_Configure: check for system specific configuration options.
91 *****************************************************************************/
92 void system_Configure( vlc_t * )
97 /*****************************************************************************
98 * system_End: destroy the BApplication object.
99 *****************************************************************************/
100 void system_End( vlc_t *p_this )
102 /* Tell the BApplication to die */
103 be_app->PostMessage( B_QUIT_REQUESTED );
105 vlc_thread_join( p_this->p_libvlc->p_appthread );
106 vlc_object_destroy( p_this->p_libvlc->p_appthread );
108 free( p_this->p_libvlc->psz_vlcpath );
111 /* following functions are local */
113 /*****************************************************************************
114 * AppThread: the BApplication thread.
115 *****************************************************************************/
116 static void AppThread( vlc_object_t * p_this )
118 VlcApplication *BeApp = new VlcApplication("application/x-vnd.videolan-vlc");
119 vlc_object_attach( p_this, p_this->p_vlc );
120 BeApp->p_this = p_this;
121 BeApp->Run();
122 vlc_object_detach( p_this );
123 delete BeApp;
126 } /* extern "C" */
128 /*****************************************************************************
129 * VlcApplication: application constructor
130 *****************************************************************************/
131 VlcApplication::VlcApplication( char * psz_mimetype )
132 :BApplication( psz_mimetype ),
133 fInterfaceWindow( NULL ),
134 fRefsMessage( NULL )
136 /* Nothing to do, we use the default constructor */
139 /*****************************************************************************
140 * ~VlcApplication: application destructor
141 *****************************************************************************/
142 VlcApplication::~VlcApplication( )
144 /* Nothing to do, we use the default destructor */
145 delete fRefsMessage;
148 /*****************************************************************************
149 * AboutRequested: called by the system on B_ABOUT_REQUESTED
150 *****************************************************************************/
151 void VlcApplication::AboutRequested( )
153 BAlert *alert;
154 alert = new BAlert( "VLC " PACKAGE_VERSION,
155 "VLC " PACKAGE_VERSION " for BeOS\n\n"
156 "<www.videolan.org>", "OK");
157 alert->Go( NULL );
160 /*****************************************************************************
161 * ReadyToRun: called when the BApplication is initialized
162 *****************************************************************************/
163 void VlcApplication::ReadyToRun( )
165 BPath path;
166 app_info info;
168 /* Get the program path */
169 be_app->GetAppInfo( &info );
170 BEntry entry( &info.ref );
171 entry.GetPath( &path );
172 path.GetParent( &path );
173 p_this->p_libvlc->psz_vlcpath = strdup( path.Path() );
175 /* Tell the main thread we are finished initializing the BApplication */
176 vlc_thread_ready( p_this );
179 /*****************************************************************************
180 * RefsReceived: called when files are sent to our application
181 * (for example when the user drops fils onto our icon)
182 *****************************************************************************/
183 void VlcApplication::RefsReceived(BMessage* message)
185 if (fInterfaceWindow)
186 fInterfaceWindow->PostMessage(message);
187 else {
188 delete fRefsMessage;
189 fRefsMessage = new BMessage(*message);
193 /*****************************************************************************
194 * MessageReceived: a BeOS applications main message loop
195 * Since VlcApplication and interface are separated
196 * in the vlc binary and the interface plugin,
197 * we use this method to "stick" them together.
198 * The interface will post a message to the global
199 * "be_app" pointer when the interface is created
200 * containing a pointer to the interface window.
201 * In this way, we can keep a B_REFS_RECEIVED message
202 * in store for the interface window to handle later.
203 *****************************************************************************/
204 void VlcApplication::MessageReceived(BMessage* message)
206 switch (message->what) {
207 case INTERFACE_CREATED: {
208 BWindow* interfaceWindow;
209 if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
210 fInterfaceWindow = interfaceWindow;
211 if (fRefsMessage) {
212 fInterfaceWindow->PostMessage(fRefsMessage);
213 delete fRefsMessage;
214 fRefsMessage = NULL;
217 break;
220 default:
221 BApplication::MessageReceived(message);
225 bool VlcApplication::QuitRequested()
227 if( CurrentMessage() && CurrentMessage()->FindBool( "shortcut" ) )
229 /* The user hit Alt+Q, don't let the be_app exit without cleaning.
230 Let the interface do the job */
231 if( fInterfaceWindow )
232 fInterfaceWindow->PostMessage( B_QUIT_REQUESTED );
233 return false;
236 BApplication::QuitRequested();
237 return true;