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() */
40 #include <vlc_common.h>
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'
74 static vlc_object_t *p_appthread;
79 /*****************************************************************************
81 *****************************************************************************/
82 static void* AppThread( vlc_object_t *p_appthread );
84 /*****************************************************************************
85 * system_Init: create a BApplication object and fill in program path.
86 *****************************************************************************/
87 void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
90 (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
92 /* Create the BApplication thread and wait for initialization */
93 vlc_thread_create( p_appthread, "app thread", AppThread,
94 VLC_THREAD_PRIORITY_LOW, true );
97 /*****************************************************************************
98 * system_Configure: check for system specific configuration options.
99 *****************************************************************************/
100 void system_Configure( libvlc_int_t *, int *pi_argc, const char *ppsz_argv[] )
104 /*****************************************************************************
105 * system_End: destroy the BApplication object.
106 *****************************************************************************/
107 void system_End( libvlc_int_t *p_this )
109 /* Tell the BApplication to die */
110 be_app->PostMessage( REALLY_QUIT );
112 vlc_thread_join( p_appthread );
113 vlc_object_release( p_appthread );
115 free( vlc_global()->psz_vlcpath );
118 /* following functions are local */
120 /*****************************************************************************
121 * AppThread: the BApplication thread.
122 *****************************************************************************/
123 static void* AppThread( vlc_object_t * p_this )
125 VlcApplication * BeApp =
126 new VlcApplication("application/x-vnd.videolan-vlc");
127 vlc_object_attach( p_this, p_this->p_libvlc );
128 BeApp->p_this = p_this;
130 vlc_object_detach( p_this );
137 /*****************************************************************************
138 * VlcApplication: application constructor
139 *****************************************************************************/
140 VlcApplication::VlcApplication( char * psz_mimetype )
141 :BApplication( psz_mimetype ),
142 fInterfaceWindow( NULL ),
143 fRefsMessage( NULL ),
144 fReadyToQuit( false )
146 /* Nothing to do, we use the default constructor */
149 /*****************************************************************************
150 * ~VlcApplication: application destructor
151 *****************************************************************************/
152 VlcApplication::~VlcApplication( )
154 /* Nothing to do, we use the default destructor */
158 /*****************************************************************************
159 * AboutRequested: called by the system on B_ABOUT_REQUESTED
160 *****************************************************************************/
161 void VlcApplication::AboutRequested( )
164 alert = new BAlert( "VLC " PACKAGE_VERSION,
165 "VLC " PACKAGE_VERSION " for BeOS\n\n"
166 "<www.videolan.org>", "OK");
170 /*****************************************************************************
171 * ReadyToRun: called when the BApplication is initialized
172 *****************************************************************************/
173 void VlcApplication::ReadyToRun( )
178 /* Get the program path */
179 be_app->GetAppInfo( &info );
180 BEntry entry( &info.ref );
181 entry.GetPath( &path );
182 path.GetParent( &path );
183 vlc_global()->psz_vlcpath = strdup( path.Path() );
185 /* Tell the main thread we are finished initializing the BApplication */
186 vlc_thread_ready( p_this );
189 /*****************************************************************************
190 * RefsReceived: called when files are sent to our application
191 * (for example when the user drops fils onto our icon)
192 *****************************************************************************/
193 void VlcApplication::RefsReceived(BMessage* message)
195 if (fInterfaceWindow)
196 fInterfaceWindow->PostMessage(message);
199 fRefsMessage = new BMessage(*message);
203 /*****************************************************************************
204 * MessageReceived: a BeOS applications main message loop
205 * Since VlcApplication and interface are separated
206 * in the vlc binary and the interface plugin,
207 * we use this method to "stick" them together.
208 * The interface will post a message to the global
209 * "be_app" pointer when the interface is created
210 * containing a pointer to the interface window.
211 * In this way, we can keep a B_REFS_RECEIVED message
212 * in store for the interface window to handle later.
213 *****************************************************************************/
214 void VlcApplication::MessageReceived(BMessage* message)
216 switch (message->what) {
217 case INTERFACE_CREATED: {
218 BWindow* interfaceWindow;
219 if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
220 fInterfaceWindow = interfaceWindow;
222 fInterfaceWindow->PostMessage(fRefsMessage);
232 PostMessage( B_QUIT_REQUESTED );
236 BApplication::MessageReceived(message);
240 bool VlcApplication::QuitRequested()
244 vlc_object_kill( p_this->p_libvlc );
248 BApplication::QuitRequested();