1 /*****************************************************************************
2 * beos_init.cpp: Initialization for BeOS specific features
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: beos_specific.cpp,v 1.26 2002/09/30 18:30:28 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>
31 #include <string.h> /* strdup() */
32 #include <malloc.h> /* free() */
39 /*****************************************************************************
40 * The VlcApplication class
41 *****************************************************************************/
42 class VlcApplication : public BApplication
47 VlcApplication(char* );
50 virtual void ReadyToRun();
51 virtual void AboutRequested();
52 virtual void RefsReceived(BMessage* message);
53 virtual void MessageReceived(BMessage* message);
56 BWindow* fInterfaceWindow;
57 BMessage* fRefsMessage;
60 /*****************************************************************************
62 *****************************************************************************/
63 static char * psz_program_path;
65 //const uint32 INTERFACE_CREATED = 'ifcr'; /* message sent from interface */
66 #include "../../modules/gui/beos/MsgVals.h"
71 /*****************************************************************************
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_vlc->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_vlc->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_vlc->p_appthread );
106 vlc_object_destroy( p_this->p_vlc->p_appthread );
108 free( psz_program_path );
111 /*****************************************************************************
112 * system_GetProgramPath: get the full path to the program.
113 *****************************************************************************/
114 char * system_GetProgramPath( void )
116 return( psz_program_path );
119 /* following functions are local */
121 /*****************************************************************************
122 * AppThread: the BApplication thread.
123 *****************************************************************************/
124 static void AppThread( vlc_object_t * p_this )
126 VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
127 vlc_object_attach( p_this, p_this->p_vlc );
128 BeApp->p_this = p_this;
130 vlc_object_detach( p_this );
136 /*****************************************************************************
137 * VlcApplication: application constructor
138 *****************************************************************************/
139 VlcApplication::VlcApplication( char * psz_mimetype )
140 :BApplication( psz_mimetype ),
141 fInterfaceWindow( NULL ),
144 /* Nothing to do, we use the default constructor */
147 /*****************************************************************************
148 * ~VlcApplication: application destructor
149 *****************************************************************************/
150 VlcApplication::~VlcApplication( )
152 /* Nothing to do, we use the default destructor */
156 /*****************************************************************************
157 * AboutRequested: called by the system on B_ABOUT_REQUESTED
158 *****************************************************************************/
159 void VlcApplication::AboutRequested( )
162 alert = new BAlert( VOUT_TITLE,
163 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>",
168 /*****************************************************************************
169 * ReadyToRun: called when the BApplication is initialized
170 *****************************************************************************/
171 void VlcApplication::ReadyToRun( )
176 /* Get the program path */
177 be_app->GetAppInfo( &info );
178 BEntry entry( &info.ref );
179 entry.GetPath( &path );
180 path.GetParent( &path );
181 psz_program_path = strdup( path.Path() );
183 /* Tell the main thread we are finished initializing the BApplication */
184 vlc_thread_ready( p_this );
187 /*****************************************************************************
188 * RefsReceived: called when files are sent to our application
189 * (for example when the user drops fils onto our icon)
190 *****************************************************************************/
191 void VlcApplication::RefsReceived(BMessage* message)
193 if (fInterfaceWindow)
194 fInterfaceWindow->PostMessage(message);
197 fRefsMessage = new BMessage(*message);
201 /*****************************************************************************
202 * MessageReceived: a BeOS applications main message loop
203 * Since VlcApplication and interface are separated
204 * in the vlc binary and the interface plugin,
205 * we use this method to "stick" them together.
206 * The interface will post a message to the global
207 * "be_app" pointer when the interface is created
208 * containing a pointer to the interface window.
209 * In this way, we can keep a B_REFS_RECEIVED message
210 * in store for the interface window to handle later.
211 *****************************************************************************/
212 void VlcApplication::MessageReceived(BMessage* message)
214 switch (message->what) {
215 case INTERFACE_CREATED: {
216 BWindow* interfaceWindow;
217 if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
218 fInterfaceWindow = interfaceWindow;
220 fInterfaceWindow->PostMessage(fRefsMessage);
228 BApplication::MessageReceived(message);