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() */
37 #include "../libvlc.h"
40 /*****************************************************************************
41 * The VlcApplication class
42 *****************************************************************************/
43 class VlcApplication : public BApplication
48 VlcApplication(char* );
51 virtual void ReadyToRun();
52 virtual void AboutRequested();
53 virtual void RefsReceived(BMessage* message);
54 virtual void MessageReceived(BMessage* message);
55 virtual bool QuitRequested();
58 BWindow* fInterfaceWindow;
59 BMessage* fRefsMessage;
63 /*****************************************************************************
65 *****************************************************************************/
67 #include "../../modules/gui/beos/MsgVals.h"
68 #define REALLY_QUIT 'requ'
73 /*****************************************************************************
75 *****************************************************************************/
76 static void AppThread( vlc_object_t *p_appthread );
78 /*****************************************************************************
79 * system_Init: create a BApplication object and fill in program path.
80 *****************************************************************************/
81 void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] )
83 vlc_global()->p_appthread =
84 (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
86 /* Create the BApplication thread and wait for initialization */
87 vlc_thread_create( vlc_global()->p_appthread, "app thread", AppThread,
88 VLC_THREAD_PRIORITY_LOW, VLC_TRUE );
91 /*****************************************************************************
92 * system_Configure: check for system specific configuration options.
93 *****************************************************************************/
94 void system_Configure( libvlc_int_t *, int *pi_argc, char *ppsz_argv[] )
98 /*****************************************************************************
99 * system_End: destroy the BApplication object.
100 *****************************************************************************/
101 void system_End( libvlc_int_t *p_this )
103 /* Tell the BApplication to die */
104 be_app->PostMessage( REALLY_QUIT );
106 vlc_thread_join( vlc_global()->p_appthread );
107 vlc_object_destroy( vlc_global()->p_appthread );
109 free( vlc_global()->psz_vlcpath );
112 /* following functions are local */
114 /*****************************************************************************
115 * AppThread: the BApplication thread.
116 *****************************************************************************/
117 static void AppThread( vlc_object_t * p_this )
119 VlcApplication * BeApp =
120 new VlcApplication("application/x-vnd.videolan-vlc");
121 vlc_object_attach( p_this, p_this->p_libvlc );
122 BeApp->p_this = p_this;
124 vlc_object_detach( p_this );
130 /*****************************************************************************
131 * VlcApplication: application constructor
132 *****************************************************************************/
133 VlcApplication::VlcApplication( char * psz_mimetype )
134 :BApplication( psz_mimetype ),
135 fInterfaceWindow( NULL ),
136 fRefsMessage( NULL ),
137 fReadyToQuit( false )
139 /* Nothing to do, we use the default constructor */
142 /*****************************************************************************
143 * ~VlcApplication: application destructor
144 *****************************************************************************/
145 VlcApplication::~VlcApplication( )
147 /* Nothing to do, we use the default destructor */
151 /*****************************************************************************
152 * AboutRequested: called by the system on B_ABOUT_REQUESTED
153 *****************************************************************************/
154 void VlcApplication::AboutRequested( )
157 alert = new BAlert( "VLC " PACKAGE_VERSION,
158 "VLC " PACKAGE_VERSION " for BeOS\n\n"
159 "<www.videolan.org>", "OK");
163 /*****************************************************************************
164 * ReadyToRun: called when the BApplication is initialized
165 *****************************************************************************/
166 void VlcApplication::ReadyToRun( )
171 /* Get the program path */
172 be_app->GetAppInfo( &info );
173 BEntry entry( &info.ref );
174 entry.GetPath( &path );
175 path.GetParent( &path );
176 vlc_global()->psz_vlcpath = strdup( path.Path() );
178 /* Tell the main thread we are finished initializing the BApplication */
179 vlc_thread_ready( p_this );
182 /*****************************************************************************
183 * RefsReceived: called when files are sent to our application
184 * (for example when the user drops fils onto our icon)
185 *****************************************************************************/
186 void VlcApplication::RefsReceived(BMessage* message)
188 if (fInterfaceWindow)
189 fInterfaceWindow->PostMessage(message);
192 fRefsMessage = new BMessage(*message);
196 /*****************************************************************************
197 * MessageReceived: a BeOS applications main message loop
198 * Since VlcApplication and interface are separated
199 * in the vlc binary and the interface plugin,
200 * we use this method to "stick" them together.
201 * The interface will post a message to the global
202 * "be_app" pointer when the interface is created
203 * containing a pointer to the interface window.
204 * In this way, we can keep a B_REFS_RECEIVED message
205 * in store for the interface window to handle later.
206 *****************************************************************************/
207 void VlcApplication::MessageReceived(BMessage* message)
209 switch (message->what) {
210 case INTERFACE_CREATED: {
211 BWindow* interfaceWindow;
212 if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
213 fInterfaceWindow = interfaceWindow;
215 fInterfaceWindow->PostMessage(fRefsMessage);
225 PostMessage( B_QUIT_REQUESTED );
229 BApplication::MessageReceived(message);
233 bool VlcApplication::QuitRequested()
237 vlc_object_kill( p_this->p_libvlc );
241 BApplication::QuitRequested();