]> git.sesse.net Git - vlc/blob - src/misc/beos_specific.cpp
* beos/* : fixed a bug in the progress bar with big files
[vlc] / src / misc / beos_specific.cpp
1 /*****************************************************************************
2  * beos_init.cpp: Initialization for BeOS specific features 
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: beos_specific.cpp,v 1.28 2003/01/12 02:08:39 titer Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *
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.
13  * 
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.
18  *
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>
24 #include <Roster.h>
25 #include <Path.h>
26 #include <Alert.h>
27 #include <Message.h>
28 #include <Window.h>
29
30 #include <stdio.h>
31 #include <string.h> /* strdup() */
32 #include <malloc.h>   /* free() */
33
34 extern "C"
35 {
36 #include <vlc/vlc.h>
37 }
38
39 /*****************************************************************************
40  * The VlcApplication class
41  *****************************************************************************/
42 class VlcApplication : public BApplication
43 {
44 public:
45     vlc_object_t *p_this;
46
47     VlcApplication(char* );
48     ~VlcApplication();
49
50     virtual void ReadyToRun();
51     virtual void AboutRequested();
52     virtual void RefsReceived(BMessage* message);
53     virtual void MessageReceived(BMessage* message);
54     
55 private:
56     BWindow*     fInterfaceWindow;
57     BMessage*    fRefsMessage;
58 };
59
60 /*****************************************************************************
61  * Static vars
62  *****************************************************************************/
63 static char *         psz_program_path;
64
65 //const uint32 INTERFACE_CREATED = 'ifcr';  /* message sent from interface */
66 #include "../../modules/gui/beos/MsgVals.h"
67
68 extern "C"
69 {
70
71 /*****************************************************************************
72  * Local prototypes.
73  *****************************************************************************/
74 static void AppThread( vlc_object_t *p_appthread );
75
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[] )
80 {
81     p_this->p_libvlc->p_appthread =
82             (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
83
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 );
87 }
88
89 /*****************************************************************************
90  * system_Configure: check for system specific configuration options.
91  *****************************************************************************/
92 void system_Configure( vlc_t * )
93 {
94
95 }
96
97 /*****************************************************************************
98  * system_End: destroy the BApplication object.
99  *****************************************************************************/
100 void system_End( vlc_t *p_this )
101 {
102     /* Tell the BApplication to die */
103     be_app->PostMessage( B_QUIT_REQUESTED );
104
105     vlc_thread_join( p_this->p_libvlc->p_appthread );
106     vlc_object_destroy( p_this->p_libvlc->p_appthread );
107
108     free( psz_program_path );
109 }
110
111 /*****************************************************************************
112  * system_GetProgramPath: get the full path to the program.
113  *****************************************************************************/
114 char * system_GetProgramPath( void )
115 {
116     return( psz_program_path );
117 }
118
119 /* following functions are local */
120
121 /*****************************************************************************
122  * AppThread: the BApplication thread.
123  *****************************************************************************/
124 static void AppThread( vlc_object_t * p_this )
125 {
126     VlcApplication *BeApp = new VlcApplication("application/x-vnd.videolan-vlc");
127     vlc_object_attach( p_this, p_this->p_vlc );
128     BeApp->p_this = p_this;
129     BeApp->Run();
130     vlc_object_detach( p_this );
131     delete BeApp;
132 }
133
134 } /* extern "C" */
135
136 /*****************************************************************************
137  * VlcApplication: application constructor
138  *****************************************************************************/
139 VlcApplication::VlcApplication( char * psz_mimetype )
140                :BApplication( psz_mimetype ),
141                 fInterfaceWindow( NULL ),
142                 fRefsMessage( NULL )
143 {
144     /* Nothing to do, we use the default constructor */
145 }
146
147 /*****************************************************************************
148  * ~VlcApplication: application destructor
149  *****************************************************************************/
150 VlcApplication::~VlcApplication( )
151 {
152     /* Nothing to do, we use the default destructor */
153     delete fRefsMessage;
154 }
155
156 /*****************************************************************************
157  * AboutRequested: called by the system on B_ABOUT_REQUESTED
158  *****************************************************************************/
159 void VlcApplication::AboutRequested( )
160 {
161     BAlert *alert;
162     alert = new BAlert( VOUT_TITLE,
163                         "BeOS " VOUT_TITLE "\n\n<www.videolan.org>",
164                         "Ok" );
165     alert->Go( NULL );
166 }
167
168 /*****************************************************************************
169  * ReadyToRun: called when the BApplication is initialized
170  *****************************************************************************/
171 void VlcApplication::ReadyToRun( )
172 {
173     BPath path;
174     app_info info; 
175
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() );
182
183     /* Tell the main thread we are finished initializing the BApplication */
184     vlc_thread_ready( p_this );
185 }
186
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)
192 {
193         if (fInterfaceWindow)
194                 fInterfaceWindow->PostMessage(message);
195         else {
196                 delete fRefsMessage;
197                 fRefsMessage = new BMessage(*message);
198         }
199 }
200
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)
213 {
214         switch (message->what) {
215                 case INTERFACE_CREATED: {
216                         BWindow* interfaceWindow;
217                         if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
218                                 fInterfaceWindow = interfaceWindow;
219                                 if (fRefsMessage) {
220                                         fInterfaceWindow->PostMessage(fRefsMessage);
221                                         delete fRefsMessage;
222                                         fRefsMessage = NULL;
223                                 }
224                         }
225                         break;
226                 }
227                 default:
228                         BApplication::MessageReceived(message);
229         }
230 }