/*****************************************************************************
- * beos_init.cpp: Initialization for BeOS specific features
+ * beos_init.cpp: Initialization for BeOS specific features
*****************************************************************************
- * Copyright (C) 1999, 2000 VideoLAN
- * $Id: beos_specific.cpp,v 1.9 2001/04/14 07:41:20 sam Exp $
+ * Copyright (C) 1999-2004 the VideoLAN team
+ * $Id$
*
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-#include "defs.h"
-
#include <Application.h>
#include <Roster.h>
#include <Path.h>
+#include <Alert.h>
+#include <Message.h>
+#include <Window.h>
+
#include <stdio.h>
#include <string.h> /* strdup() */
-#include <malloc.h> /* free() */
+#include <malloc.h> /* free() */
extern "C"
{
-#include "common.h"
-#include "threads.h"
-#include "mtime.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include "../libvlc.h"
}
-#include "beos_specific.h"
/*****************************************************************************
* The VlcApplication class
class VlcApplication : public BApplication
{
public:
+ vlc_object_t *p_this;
+
VlcApplication(char* );
~VlcApplication();
- void ReadyToRun();
+ virtual void ReadyToRun();
+ virtual void AboutRequested();
+ virtual void RefsReceived(BMessage* message);
+ virtual void MessageReceived(BMessage* message);
+ virtual bool QuitRequested();
+
+private:
+ BWindow* fInterfaceWindow;
+ BMessage* fRefsMessage;
+ bool fReadyToQuit;
};
/*****************************************************************************
* Static vars
*****************************************************************************/
-static vlc_thread_t app_thread;
-static vlc_mutex_t app_lock;
-static vlc_cond_t app_wait;
-static char *psz_program_path;
+
+#include "../../modules/gui/beos/MsgVals.h"
+#define REALLY_QUIT 'requ'
+
+static vlc_object_t *p_appthread;
extern "C"
{
/*****************************************************************************
* Local prototypes.
*****************************************************************************/
-static void system_AppThread( void * args );
+static void AppThread( vlc_object_t *p_appthread );
/*****************************************************************************
- * system_Create: create a BApplication object and fill in program path.
+ * system_Init: create a BApplication object and fill in program path.
*****************************************************************************/
-void system_Create( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
+void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
{
- /* Prepare the lock/wait before launching the BApplication thread */
- vlc_mutex_init( &app_lock );
- vlc_cond_init( &app_wait );
- vlc_mutex_lock( &app_lock );
-
- /* Create the BApplication thread */
- vlc_thread_create( &app_thread, "app thread",
- (vlc_thread_func_t)system_AppThread, 0 );
-
- /* Wait for the application to be initialized */
- vlc_cond_wait( &app_wait, &app_lock );
- vlc_mutex_unlock( &app_lock );
-
- /* Destroy the locks */
- vlc_mutex_destroy( &app_lock );
- vlc_cond_destroy( &app_wait );
+ p_appthread =
+ (vlc_object_t *)vlc_object_create( p_this, sizeof(vlc_object_t) );
+
+ /* Create the BApplication thread and wait for initialization */
+ vlc_thread_create( p_appthread, "app thread", AppThread,
+ VLC_THREAD_PRIORITY_LOW, true );
}
/*****************************************************************************
- * system_Destroy: destroy the BApplication object.
+ * system_Configure: check for system specific configuration options.
*****************************************************************************/
-void system_Destroy( void )
+void system_Configure( libvlc_int_t *, int *pi_argc, const char *ppsz_argv[] )
{
- free( psz_program_path );
-
- /* Tell the BApplication to die */
- be_app->PostMessage( B_QUIT_REQUESTED );
- vlc_thread_join( app_thread );
}
/*****************************************************************************
- * system_GetProgramPath: get the full path to the program.
+ * system_End: destroy the BApplication object.
*****************************************************************************/
-char * system_GetProgramPath( void )
+void system_End( libvlc_int_t *p_this )
{
- return( psz_program_path );
+ /* Tell the BApplication to die */
+ be_app->PostMessage( REALLY_QUIT );
+
+ vlc_thread_join( p_appthread );
+ vlc_object_release( p_appthread );
+
+ free( vlc_global()->psz_vlcpath );
}
/* following functions are local */
/*****************************************************************************
- * system_AppThread: the BApplication thread.
+ * AppThread: the BApplication thread.
*****************************************************************************/
-static void system_AppThread( void * args )
+static void AppThread( vlc_object_t * p_this )
{
- VlcApplication *BeApp = new VlcApplication("application/x-vnd.Ink-vlc");
+ VlcApplication * BeApp =
+ new VlcApplication("application/x-vnd.videolan-vlc");
+ vlc_object_attach( p_this, p_this->p_libvlc );
+ BeApp->p_this = p_this;
BeApp->Run();
+ vlc_object_detach( p_this );
delete BeApp;
}
* VlcApplication: application constructor
*****************************************************************************/
VlcApplication::VlcApplication( char * psz_mimetype )
- :BApplication( psz_mimetype )
+ :BApplication( psz_mimetype ),
+ fInterfaceWindow( NULL ),
+ fRefsMessage( NULL ),
+ fReadyToQuit( false )
{
/* Nothing to do, we use the default constructor */
}
VlcApplication::~VlcApplication( )
{
/* Nothing to do, we use the default destructor */
+ delete fRefsMessage;
}
/*****************************************************************************
- * ~ReadyToRun: called when the BApplication is initialized
+ * AboutRequested: called by the system on B_ABOUT_REQUESTED
+ *****************************************************************************/
+void VlcApplication::AboutRequested( )
+{
+ BAlert *alert;
+ alert = new BAlert( "VLC " PACKAGE_VERSION,
+ "VLC " PACKAGE_VERSION " for BeOS\n\n"
+ "<www.videolan.org>", "OK");
+ alert->Go( NULL );
+}
+
+/*****************************************************************************
+ * ReadyToRun: called when the BApplication is initialized
*****************************************************************************/
void VlcApplication::ReadyToRun( )
{
BPath path;
- app_info info;
+ app_info info;
/* Get the program path */
- be_app->GetAppInfo( &info );
- BEntry entry( &info.ref );
- entry.GetPath( &path );
+ be_app->GetAppInfo( &info );
+ BEntry entry( &info.ref );
+ entry.GetPath( &path );
path.GetParent( &path );
- psz_program_path = strdup( path.Path() );
+ vlc_global()->psz_vlcpath = strdup( path.Path() );
/* Tell the main thread we are finished initializing the BApplication */
- vlc_mutex_lock( &app_lock );
- vlc_cond_signal( &app_wait );
- vlc_mutex_unlock( &app_lock );
+ vlc_thread_ready( p_this );
+}
+
+/*****************************************************************************
+ * RefsReceived: called when files are sent to our application
+ * (for example when the user drops fils onto our icon)
+ *****************************************************************************/
+void VlcApplication::RefsReceived(BMessage* message)
+{
+ if (fInterfaceWindow)
+ fInterfaceWindow->PostMessage(message);
+ else {
+ delete fRefsMessage;
+ fRefsMessage = new BMessage(*message);
+ }
}
+/*****************************************************************************
+ * MessageReceived: a BeOS applications main message loop
+ * Since VlcApplication and interface are separated
+ * in the vlc binary and the interface plugin,
+ * we use this method to "stick" them together.
+ * The interface will post a message to the global
+ * "be_app" pointer when the interface is created
+ * containing a pointer to the interface window.
+ * In this way, we can keep a B_REFS_RECEIVED message
+ * in store for the interface window to handle later.
+ *****************************************************************************/
+void VlcApplication::MessageReceived(BMessage* message)
+{
+ switch (message->what) {
+ case INTERFACE_CREATED: {
+ BWindow* interfaceWindow;
+ if (message->FindPointer("window", (void**)&interfaceWindow) == B_OK) {
+ fInterfaceWindow = interfaceWindow;
+ if (fRefsMessage) {
+ fInterfaceWindow->PostMessage(fRefsMessage);
+ delete fRefsMessage;
+ fRefsMessage = NULL;
+ }
+ }
+ break;
+ }
+
+ case REALLY_QUIT:
+ fReadyToQuit = true;
+ PostMessage( B_QUIT_REQUESTED );
+ break;
+
+ default:
+ BApplication::MessageReceived(message);
+ }
+}
+
+bool VlcApplication::QuitRequested()
+{
+ if( !fReadyToQuit )
+ {
+ vlc_object_kill( p_this->p_libvlc );
+ return false;
+ }
+
+ BApplication::QuitRequested();
+ return true;
+}