root/src/misc/beos_specific.cpp
| Revision 974a5e403890f924980be2add6983913c520c94f, 8.5 kB (checked in by Rémi Denis-Courmont <rdenis@simphalempin.com>, 2 months ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /***************************************************************************** |
| 2 | * beos_init.cpp: Initialization for BeOS specific features |
| 3 | ***************************************************************************** |
| 4 | * Copyright (C) 1999-2004 the VideoLAN team |
| 5 | * $Id$ |
| 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 | #ifdef HAVE_CONFIG_H |
| 37 | # include "config.h" |
| 38 | #endif |
| 39 | |
| 40 | #include <vlc_common.h> |
| 41 | #include "../libvlc.h" |
| 42 | } |
| 43 | |
| 44 | /***************************************************************************** |
| 45 | * The VlcApplication class |
| 46 | *****************************************************************************/ |
| 47 | class VlcApplication : public BApplication |
| 48 | { |
| 49 | public: |
| 50 | vlc_object_t *p_this; |
| 51 | |
| 52 | VlcApplication(char* ); |
| 53 | ~VlcApplication(); |
| 54 | |
| 55 | virtual void ReadyToRun(); |
| 56 | virtual void AboutRequested(); |
| 57 | virtual void RefsReceived(BMessage* message); |
| 58 | virtual void MessageReceived(BMessage* message); |
| 59 | virtual bool QuitRequested(); |
| 60 | |
| 61 | private: |
| 62 | BWindow* fInterfaceWindow; |
| 63 | BMessage* fRefsMessage; |
| 64 | bool fReadyToQuit; |
| 65 | }; |
| 66 | |
| 67 | /***************************************************************************** |
| 68 | * Static vars |
| 69 | *****************************************************************************/ |
| 70 | |
| 71 | #include "../../modules/gui/beos/MsgVals.h" |
| 72 | #define REALLY_QUIT 'requ' |
| 73 | |
| 74 | static vlc_object_t *p_appthread; |
| 75 | |
| 76 | extern "C" |
| 77 | { |
| 78 | |
| 79 | /***************************************************************************** |
| 80 | * Local prototypes. |
| 81 | *****************************************************************************/ |
| 82 | static void* AppThread( vlc_object_t *p_appthread ); |
| 83 | |
| 84 | /***************************************************************************** |
| 85 | * system_Init: create a BApplication object and fill in program path. |
| 86 | *****************************************************************************/ |
| 87 | void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] ) |
| 88 | { |
| 89 | p_appthread = |
| 90 | (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) ); |
| 91 | |
| 92 | /* Create the BApplication thread and wait for initialization */ |
| 93 | vlc_thread_create( p_appthread, "app thread", AppThread, |
| 94 | VLC_THREAD_PRIORITY_LOW, true ); |
| 95 | } |
| 96 | |
| 97 | /***************************************************************************** |
| 98 | * system_Configure: check for system specific configuration options. |
| 99 | *****************************************************************************/ |
| 100 | void system_Configure( libvlc_int_t *, int *pi_argc, const char *ppsz_argv[] ) |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | /***************************************************************************** |
| 105 | * system_End: destroy the BApplication object. |
| 106 | *****************************************************************************/ |
| 107 | void system_End( libvlc_int_t *p_this ) |
| 108 | { |
| 109 | /* Tell the BApplication to die */ |
| 110 | be_app->PostMessage( REALLY_QUIT ); |
| 111 | |
| 112 | vlc_thread_join( p_appthread ); |
| 113 | vlc_object_release( p_appthread ); |
| 114 | |
| 115 | free( vlc_global()->psz_vlcpath ); |
| 116 | } |
| 117 | |
| 118 | /* following functions are local */ |
| 119 | |
| 120 | /***************************************************************************** |
| 121 | * AppThread: the BApplication thread. |
| 122 | *****************************************************************************/ |
| 123 | static void* AppThread( vlc_object_t * p_this ) |
| 124 | { |
| 125 | int canc = vlc_savecancel (); |
| 126 | VlcApplication * BeApp = |
| 127 | new VlcApplication("application/x-vnd.videolan-vlc"); |
| 128 | vlc_object_attach( p_this, p_this->p_libvlc ); |
| 129 | BeApp->p_this = p_this; |
| 130 | BeApp->Run(); |
| 131 | vlc_object_detach( p_this ); |
| 132 | delete BeApp; |
| 133 | vlc_restorecancel (canc); |
| 134 | return NULL; |
| 135 | } |
| 136 | |
| 137 | } /* extern "C" */ |
| 138 | |
| 139 | /***************************************************************************** |
| 140 | * VlcApplication: application constructor |
| 141 | *****************************************************************************/ |
| 142 | VlcApplication::VlcApplication( char * psz_mimetype ) |
| 143 | :BApplication( psz_mimetype ), |
| 144 | fInterfaceWindow( NULL ), |
| 145 | fRefsMessage( NULL ), |
| 146 | fReadyToQuit( false ) |
| 147 | { |
| 148 | /* Nothing to do, we use the default constructor */ |
| 149 | } |
| 150 | |
| 151 | /***************************************************************************** |
| 152 | * ~VlcApplication: application destructor |
| 153 | *****************************************************************************/ |
| 154 | VlcApplication::~VlcApplication( ) |
| 155 | { |
| 156 | /* Nothing to do, we use the default destructor */ |
| 157 | delete fRefsMessage; |
| 158 | } |
| 159 | |
| 160 | /***************************************************************************** |
| 161 | * AboutRequested: called by the system on B_ABOUT_REQUESTED |
| 162 | *****************************************************************************/ |
| 163 | void VlcApplication::AboutRequested( ) |
| 164 | { |
| 165 | BAlert *alert; |
| 166 | alert = new BAlert( "VLC " PACKAGE_VERSION, |
| 167 | "VLC " PACKAGE_VERSION " for BeOS\n\n" |
| 168 | "<www.videolan.org>", "OK"); |
| 169 | alert->Go( NULL ); |
| 170 | } |
| 171 | |
| 172 | /***************************************************************************** |
| 173 | * ReadyToRun: called when the BApplication is initialized |
| 174 | *****************************************************************************/ |
| 175 | void VlcApplication::ReadyToRun( ) |
| 176 | { |
| 177 | BPath path; |
| 178 | app_info info; |
| 179 | |
| 180 | /* Get the program path */ |
| 181 | be_app->GetAppInfo( &info ); |
| 182 | BEntry entry( &info.ref ); |
| 183 | entry.GetPath( &path ); |
| 184 | path.GetParent( &path ); |
| 185 | vlc_global()->psz_vlcpath = strdup( path.Path() ); |
| 186 | |
| 187 | /* Tell the main thread we are finished initializing the BApplication */ |
| 188 | vlc_thread_ready( p_this ); |
| 189 | } |
| 190 | |
| 191 | /***************************************************************************** |
| 192 | * RefsReceived: called when files are sent to our application |
| 193 | * (for example when the user drops fils onto our icon) |
| 194 | *****************************************************************************/ |
| 195 | void VlcApplication::RefsReceived(BMessage* message) |
| 196 | { |
| 197 | if (fInterfaceWindow) |
| 198 | fInterfaceWindow->PostMessage(message); |
| 199 | else { |
| 200 | delete fRefsMessage; |
| 201 | fRefsMessage = new BMessage(*message); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /***************************************************************************** |
| 206 | * MessageReceived: a BeOS applications main message loop |
| 207 | * Since VlcApplication and interface are separated |
| 208 | * in the vlc binary and the interface plugin, |
| 209 | * we use this method to "stick" them together. |
| 210 | * The interface will post a message to the global |
| 211 | * "be_app" pointer when the interface is created |
| 212 | * containing a pointer to the interface window. |
| 213 | * In this way, we can keep a B_REFS_RECEIVED message |
| 214 | * in store for the interface window to handle later. |
| 215 | *****************************************************************************/ |
| 216 | void VlcApplication::MessageReceived(BMessage* message) |
| 217 | { |
| 218 | switch (message->what) { |
| 219 | case INTERFACE_CREATED: { |
| 220 | BWindow* interfaceWindow; |
| 221 | if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) { |
| 222 | fInterfaceWindow = interfaceWindow; |
| 223 | if (fRefsMessage) { |
| 224 | fInterfaceWindow->PostMessage(fRefsMessage); |
| 225 | delete fRefsMessage; |
| 226 | fRefsMessage = NULL; |
| 227 | } |
| 228 | } |
| 229 | break; |
| 230 | } |
| 231 | |
| 232 | case REALLY_QUIT: |
| 233 | fReadyToQuit = true; |
| 234 | PostMessage( B_QUIT_REQUESTED ); |
| 235 | break; |
| 236 | |
| 237 | default: |
| 238 | BApplication::MessageReceived(message); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | bool VlcApplication::QuitRequested() |
| 243 | { |
| 244 | if( !fReadyToQuit ) |
| 245 | { |
| 246 | vlc_object_kill( p_this->p_libvlc ); |
| 247 | return false; |
| 248 | } |
| 249 | |
| 250 | BApplication::QuitRequested(); |
| 251 | return true; |
| 252 | } |
Note: See TracBrowser for help on using the browser.
