1 /*****************************************************************************
2 * beos_init.cpp: Initialization for BeOS specific features
3 *****************************************************************************
4 * Copyright (C) 1999-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23 #include <Application.h>
31 #include <string.h> /* strdup() */
32 #include <malloc.h> /* free() */
41 #include "../libvlc.h"
44 /*****************************************************************************
45 * The VlcApplication class
46 *****************************************************************************/
47 class VlcApplication : public BApplication
52 VlcApplication(char* );
55 virtual void ReadyToRun();
56 virtual void AboutRequested();
57 virtual void RefsReceived(BMessage* message);
58 virtual void MessageReceived(BMessage* message);
59 virtual bool QuitRequested();
62 BWindow* fInterfaceWindow;
63 BMessage* fRefsMessage;
67 /*****************************************************************************
69 *****************************************************************************/
71 #include "../../modules/gui/beos/MsgVals.h"
72 #define REALLY_QUIT 'requ'
77 /*****************************************************************************
79 *****************************************************************************/
80 static void AppThread( vlc_object_t *p_appthread );
82 /*****************************************************************************
83 * system_Init: create a BApplication object and fill in program path.
84 *****************************************************************************/
85 void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
87 vlc_global()->p_appthread =
88 (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
90 /* Create the BApplication thread and wait for initialization */
91 vlc_thread_create( vlc_global()->p_appthread, "app thread", AppThread,
92 VLC_THREAD_PRIORITY_LOW, VLC_TRUE );
95 /*****************************************************************************
96 * system_Configure: check for system specific configuration options.
97 *****************************************************************************/
98 void system_Configure( libvlc_int_t *, int *pi_argc, const char *ppsz_argv[] )
102 /*****************************************************************************
103 * system_End: destroy the BApplication object.
104 *****************************************************************************/
105 void system_End( libvlc_int_t *p_this )
107 /* Tell the BApplication to die */
108 be_app->PostMessage( REALLY_QUIT );
110 vlc_thread_join( vlc_global()->p_appthread );
111 vlc_object_destroy( vlc_global()->p_appthread );
113 free( vlc_global()->psz_vlcpath );
116 /* following functions are local */
118 /*****************************************************************************
119 * AppThread: the BApplication thread.
120 *****************************************************************************/
121 static void AppThread( vlc_object_t * p_this )
123 VlcApplication * BeApp =
124 new VlcApplication("application/x-vnd.videolan-vlc");
125 vlc_object_attach( p_this, p_this->p_libvlc );
126 BeApp->p_this = p_this;
128 vlc_object_detach( p_this );
134 /*****************************************************************************
135 * VlcApplication: application constructor
136 *****************************************************************************/
137 VlcApplication::VlcApplication( char * psz_mimetype )
138 :BApplication( psz_mimetype ),
139 fInterfaceWindow( NULL ),
140 fRefsMessage( NULL ),
141 fReadyToQuit( false )
143 /* Nothing to do, we use the default constructor */
146 /*****************************************************************************
147 * ~VlcApplication: application destructor
148 *****************************************************************************/
149 VlcApplication::~VlcApplication( )
151 /* Nothing to do, we use the default destructor */
155 /*****************************************************************************
156 * AboutRequested: called by the system on B_ABOUT_REQUESTED
157 *****************************************************************************/
158 void VlcApplication::AboutRequested( )
161 alert = new BAlert( "VLC " PACKAGE_VERSION,
162 "VLC " PACKAGE_VERSION " for BeOS\n\n"
163 "<www.videolan.org>", "OK");
167 /*****************************************************************************
168 * ReadyToRun: called when the BApplication is initialized
169 *****************************************************************************/
170 void VlcApplication::ReadyToRun( )
175 /* Get the program path */
176 be_app->GetAppInfo( &info );
177 BEntry entry( &info.ref );
178 entry.GetPath( &path );
179 path.GetParent( &path );
180 vlc_global()->psz_vlcpath = strdup( path.Path() );
182 /* Tell the main thread we are finished initializing the BApplication */
183 vlc_thread_ready( p_this );
186 /*****************************************************************************
187 * RefsReceived: called when files are sent to our application
188 * (for example when the user drops fils onto our icon)
189 *****************************************************************************/
190 void VlcApplication::RefsReceived(BMessage* message)
192 if (fInterfaceWindow)
193 fInterfaceWindow->PostMessage(message);
196 fRefsMessage = new BMessage(*message);
200 /*****************************************************************************
201 * MessageReceived: a BeOS applications main message loop
202 * Since VlcApplication and interface are separated
203 * in the vlc binary and the interface plugin,
204 * we use this method to "stick" them together.
205 * The interface will post a message to the global
206 * "be_app" pointer when the interface is created
207 * containing a pointer to the interface window.
208 * In this way, we can keep a B_REFS_RECEIVED message
209 * in store for the interface window to handle later.
210 *****************************************************************************/
211 void VlcApplication::MessageReceived(BMessage* message)
213 switch (message->what) {
214 case INTERFACE_CREATED: {
215 BWindow* interfaceWindow;
216 if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
217 fInterfaceWindow = interfaceWindow;
219 fInterfaceWindow->PostMessage(fRefsMessage);
229 PostMessage( B_QUIT_REQUESTED );
233 BApplication::MessageReceived(message);
237 bool VlcApplication::QuitRequested()
241 vlc_object_kill( p_this->p_libvlc );
245 BApplication::QuitRequested();