1 /*****************************************************************************
2 * beos_init.cpp: Initialization for BeOS specific features
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VideoLAN (Centrale Réseaux) and its contributors
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);
54 virtual bool QuitRequested();
57 BWindow* fInterfaceWindow;
58 BMessage* fRefsMessage;
62 /*****************************************************************************
64 *****************************************************************************/
66 #include "../../modules/gui/beos/MsgVals.h"
67 #define REALLY_QUIT 'requ'
72 /*****************************************************************************
74 *****************************************************************************/
75 static void AppThread( vlc_object_t *p_appthread );
77 /*****************************************************************************
78 * system_Init: create a BApplication object and fill in program path.
79 *****************************************************************************/
80 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
82 p_this->p_libvlc->p_appthread =
83 (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
85 /* Create the BApplication thread and wait for initialization */
86 vlc_thread_create( p_this->p_libvlc->p_appthread, "app thread", AppThread,
87 VLC_THREAD_PRIORITY_LOW, VLC_TRUE );
90 /*****************************************************************************
91 * system_Configure: check for system specific configuration options.
92 *****************************************************************************/
93 void system_Configure( vlc_t *, int *pi_argc, char *ppsz_argv[] )
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( REALLY_QUIT );
105 vlc_thread_join( p_this->p_libvlc->p_appthread );
106 vlc_object_destroy( p_this->p_libvlc->p_appthread );
108 free( p_this->p_libvlc->psz_vlcpath );
111 /* following functions are local */
113 /*****************************************************************************
114 * AppThread: the BApplication thread.
115 *****************************************************************************/
116 static void AppThread( vlc_object_t * p_this )
118 VlcApplication * BeApp =
119 new VlcApplication("application/x-vnd.videolan-vlc");
120 vlc_object_attach( p_this, p_this->p_vlc );
121 BeApp->p_this = p_this;
123 vlc_object_detach( p_this );
129 /*****************************************************************************
130 * VlcApplication: application constructor
131 *****************************************************************************/
132 VlcApplication::VlcApplication( char * psz_mimetype )
133 :BApplication( psz_mimetype ),
134 fInterfaceWindow( NULL ),
135 fRefsMessage( NULL ),
136 fReadyToQuit( false )
138 /* Nothing to do, we use the default constructor */
141 /*****************************************************************************
142 * ~VlcApplication: application destructor
143 *****************************************************************************/
144 VlcApplication::~VlcApplication( )
146 /* Nothing to do, we use the default destructor */
150 /*****************************************************************************
151 * AboutRequested: called by the system on B_ABOUT_REQUESTED
152 *****************************************************************************/
153 void VlcApplication::AboutRequested( )
156 alert = new BAlert( "VLC " PACKAGE_VERSION,
157 "VLC " PACKAGE_VERSION " for BeOS\n\n"
158 "<www.videolan.org>", "OK");
162 /*****************************************************************************
163 * ReadyToRun: called when the BApplication is initialized
164 *****************************************************************************/
165 void VlcApplication::ReadyToRun( )
170 /* Get the program path */
171 be_app->GetAppInfo( &info );
172 BEntry entry( &info.ref );
173 entry.GetPath( &path );
174 path.GetParent( &path );
175 p_this->p_libvlc->psz_vlcpath = strdup( path.Path() );
177 /* Tell the main thread we are finished initializing the BApplication */
178 vlc_thread_ready( p_this );
181 /*****************************************************************************
182 * RefsReceived: called when files are sent to our application
183 * (for example when the user drops fils onto our icon)
184 *****************************************************************************/
185 void VlcApplication::RefsReceived(BMessage* message)
187 if (fInterfaceWindow)
188 fInterfaceWindow->PostMessage(message);
191 fRefsMessage = new BMessage(*message);
195 /*****************************************************************************
196 * MessageReceived: a BeOS applications main message loop
197 * Since VlcApplication and interface are separated
198 * in the vlc binary and the interface plugin,
199 * we use this method to "stick" them together.
200 * The interface will post a message to the global
201 * "be_app" pointer when the interface is created
202 * containing a pointer to the interface window.
203 * In this way, we can keep a B_REFS_RECEIVED message
204 * in store for the interface window to handle later.
205 *****************************************************************************/
206 void VlcApplication::MessageReceived(BMessage* message)
208 switch (message->what) {
209 case INTERFACE_CREATED: {
210 BWindow* interfaceWindow;
211 if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
212 fInterfaceWindow = interfaceWindow;
214 fInterfaceWindow->PostMessage(fRefsMessage);
224 PostMessage( B_QUIT_REQUESTED );
228 BApplication::MessageReceived(message);
232 bool VlcApplication::QuitRequested()
236 p_this->p_vlc->b_die = 1;
240 BApplication::QuitRequested();