1 /*****************************************************************************
2 * beos_init.cpp: Initialization for BeOS specific features
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: beos_specific.cpp,v 1.31 2003/05/08 01:05:14 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
);
54 virtual bool QuitRequested();
57 BWindow
* fInterfaceWindow
;
58 BMessage
* fRefsMessage
;
61 /*****************************************************************************
63 *****************************************************************************/
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_libvlc
->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_libvlc
->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_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
= new VlcApplication("application/x-vnd.videolan-vlc");
119 vlc_object_attach( p_this
, p_this
->p_vlc
);
120 BeApp
->p_this
= p_this
;
122 vlc_object_detach( p_this
);
128 /*****************************************************************************
129 * VlcApplication: application constructor
130 *****************************************************************************/
131 VlcApplication::VlcApplication( char * psz_mimetype
)
132 :BApplication( psz_mimetype
),
133 fInterfaceWindow( NULL
),
136 /* Nothing to do, we use the default constructor */
139 /*****************************************************************************
140 * ~VlcApplication: application destructor
141 *****************************************************************************/
142 VlcApplication::~VlcApplication( )
144 /* Nothing to do, we use the default destructor */
148 /*****************************************************************************
149 * AboutRequested: called by the system on B_ABOUT_REQUESTED
150 *****************************************************************************/
151 void VlcApplication::AboutRequested( )
154 alert
= new BAlert( "VLC " PACKAGE_VERSION
,
155 "VLC " PACKAGE_VERSION
" for BeOS\n\n"
156 "<www.videolan.org>", "OK");
160 /*****************************************************************************
161 * ReadyToRun: called when the BApplication is initialized
162 *****************************************************************************/
163 void VlcApplication::ReadyToRun( )
168 /* Get the program path */
169 be_app
->GetAppInfo( &info
);
170 BEntry
entry( &info
.ref
);
171 entry
.GetPath( &path
);
172 path
.GetParent( &path
);
173 p_this
->p_libvlc
->psz_vlcpath
= strdup( path
.Path() );
175 /* Tell the main thread we are finished initializing the BApplication */
176 vlc_thread_ready( p_this
);
179 /*****************************************************************************
180 * RefsReceived: called when files are sent to our application
181 * (for example when the user drops fils onto our icon)
182 *****************************************************************************/
183 void VlcApplication::RefsReceived(BMessage
* message
)
185 if (fInterfaceWindow
)
186 fInterfaceWindow
->PostMessage(message
);
189 fRefsMessage
= new BMessage(*message
);
193 /*****************************************************************************
194 * MessageReceived: a BeOS applications main message loop
195 * Since VlcApplication and interface are separated
196 * in the vlc binary and the interface plugin,
197 * we use this method to "stick" them together.
198 * The interface will post a message to the global
199 * "be_app" pointer when the interface is created
200 * containing a pointer to the interface window.
201 * In this way, we can keep a B_REFS_RECEIVED message
202 * in store for the interface window to handle later.
203 *****************************************************************************/
204 void VlcApplication::MessageReceived(BMessage
* message
)
206 switch (message
->what
) {
207 case INTERFACE_CREATED
: {
208 BWindow
* interfaceWindow
;
209 if (message
->FindPointer("window", (void**)&interfaceWindow
) == B_OK
) {
210 fInterfaceWindow
= interfaceWindow
;
212 fInterfaceWindow
->PostMessage(fRefsMessage
);
221 BApplication::MessageReceived(message
);
225 bool VlcApplication::QuitRequested()
227 if( CurrentMessage() && CurrentMessage()->FindBool( "shortcut" ) )
229 /* The user hit Alt+Q, don't let the be_app exit without cleaning.
230 Let the interface do the job */
231 if( fInterfaceWindow
)
232 fInterfaceWindow
->PostMessage( B_QUIT_REQUESTED
);
236 BApplication::QuitRequested();