1 /*****************************************************************************
2 * beos_init.cpp: Initialization for BeOS specific features
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: beos_specific.cpp,v 1.29 2003/01/19 03:16:24 sam 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 *****************************************************************************/
64 //const uint32 INTERFACE_CREATED = 'ifcr'; /* message sent from interface */
65 #include "../../modules/gui/beos/MsgVals.h"
70 /*****************************************************************************
72 *****************************************************************************/
73 static void AppThread( vlc_object_t *p_appthread );
75 /*****************************************************************************
76 * system_Init: create a BApplication object and fill in program path.
77 *****************************************************************************/
78 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
80 p_this->p_libvlc->p_appthread =
81 (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
83 /* Create the BApplication thread and wait for initialization */
84 vlc_thread_create( p_this->p_libvlc->p_appthread, "app thread", AppThread,
85 VLC_THREAD_PRIORITY_LOW, VLC_TRUE );
88 /*****************************************************************************
89 * system_Configure: check for system specific configuration options.
90 *****************************************************************************/
91 void system_Configure( vlc_t * )
96 /*****************************************************************************
97 * system_End: destroy the BApplication object.
98 *****************************************************************************/
99 void system_End( vlc_t *p_this )
101 /* Tell the BApplication to die */
102 be_app->PostMessage( B_QUIT_REQUESTED );
104 vlc_thread_join( p_this->p_libvlc->p_appthread );
105 vlc_object_destroy( p_this->p_libvlc->p_appthread );
107 free( p_this->p_libvlc->psz_vlcpath );
110 /* following functions are local */
112 /*****************************************************************************
113 * AppThread: the BApplication thread.
114 *****************************************************************************/
115 static void AppThread( vlc_object_t * p_this )
117 VlcApplication *BeApp = new VlcApplication("application/x-vnd.videolan-vlc");
118 vlc_object_attach( p_this, p_this->p_vlc );
119 BeApp->p_this = p_this;
121 vlc_object_detach( p_this );
127 /*****************************************************************************
128 * VlcApplication: application constructor
129 *****************************************************************************/
130 VlcApplication::VlcApplication( char * psz_mimetype )
131 :BApplication( psz_mimetype ),
132 fInterfaceWindow( NULL ),
135 /* Nothing to do, we use the default constructor */
138 /*****************************************************************************
139 * ~VlcApplication: application destructor
140 *****************************************************************************/
141 VlcApplication::~VlcApplication( )
143 /* Nothing to do, we use the default destructor */
147 /*****************************************************************************
148 * AboutRequested: called by the system on B_ABOUT_REQUESTED
149 *****************************************************************************/
150 void VlcApplication::AboutRequested( )
153 alert = new BAlert( VOUT_TITLE,
154 "BeOS " VOUT_TITLE "\n\n<www.videolan.org>",
159 /*****************************************************************************
160 * ReadyToRun: called when the BApplication is initialized
161 *****************************************************************************/
162 void VlcApplication::ReadyToRun( )
167 /* Get the program path */
168 be_app->GetAppInfo( &info );
169 BEntry entry( &info.ref );
170 entry.GetPath( &path );
171 path.GetParent( &path );
172 p_this->p_libvlc->psz_vlcpath = strdup( path.Path() );
174 /* Tell the main thread we are finished initializing the BApplication */
175 vlc_thread_ready( p_this );
178 /*****************************************************************************
179 * RefsReceived: called when files are sent to our application
180 * (for example when the user drops fils onto our icon)
181 *****************************************************************************/
182 void VlcApplication::RefsReceived(BMessage* message)
184 if (fInterfaceWindow)
185 fInterfaceWindow->PostMessage(message);
188 fRefsMessage = new BMessage(*message);
192 /*****************************************************************************
193 * MessageReceived: a BeOS applications main message loop
194 * Since VlcApplication and interface are separated
195 * in the vlc binary and the interface plugin,
196 * we use this method to "stick" them together.
197 * The interface will post a message to the global
198 * "be_app" pointer when the interface is created
199 * containing a pointer to the interface window.
200 * In this way, we can keep a B_REFS_RECEIVED message
201 * in store for the interface window to handle later.
202 *****************************************************************************/
203 void VlcApplication::MessageReceived(BMessage* message)
205 switch (message->what) {
206 case INTERFACE_CREATED: {
207 BWindow* interfaceWindow;
208 if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
209 fInterfaceWindow = interfaceWindow;
211 fInterfaceWindow->PostMessage(fRefsMessage);
219 BApplication::MessageReceived(message);