]> git.sesse.net Git - vlc/blobdiff - src/misc/beos_specific.cpp
* modules/gui/macosx/controls.m:
[vlc] / src / misc / beos_specific.cpp
index 6eb5a57a9bd1c973cd6b43e0d538ed75c743f070..f547af7cfee5d0a2aa20e36b04ecad057377bf6a 100644 (file)
@@ -2,7 +2,7 @@
  * beos_init.cpp: Initialization for BeOS specific features 
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: beos_specific.cpp,v 1.21 2002/06/01 14:31:32 sam Exp $
+ * $Id: beos_specific.cpp,v 1.29 2003/01/19 03:16:24 sam Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *
@@ -24,6 +24,9 @@
 #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() */
@@ -46,12 +49,20 @@ public:
 
     virtual void ReadyToRun();
     virtual void AboutRequested();
+    virtual void RefsReceived(BMessage* message);
+    virtual void MessageReceived(BMessage* message);
+    
+private:
+    BWindow*     fInterfaceWindow;
+    BMessage*    fRefsMessage;
 };
 
 /*****************************************************************************
  * Static vars
  *****************************************************************************/
-static char *         psz_program_path;
+
+//const uint32 INTERFACE_CREATED = 'ifcr';  /* message sent from interface */
+#include "../../modules/gui/beos/MsgVals.h"
 
 extern "C"
 {
@@ -64,19 +75,20 @@ static void AppThread( vlc_object_t *p_appthread );
 /*****************************************************************************
  * system_Init: create a BApplication object and fill in program path.
  *****************************************************************************/
-void system_Init( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[] )
+void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
 {
-    p_this->p_vlc->p_appthread =
+    p_this->p_libvlc->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_this->p_vlc->p_appthread, "app thread", AppThread, 1 );
+    vlc_thread_create( p_this->p_libvlc->p_appthread, "app thread", AppThread,
+                       VLC_THREAD_PRIORITY_LOW, VLC_TRUE );
 }
 
 /*****************************************************************************
  * system_Configure: check for system specific configuration options.
  *****************************************************************************/
-void system_Configure( vlc_object_t * )
+void system_Configure( vlc_t * )
 {
 
 }
@@ -84,23 +96,15 @@ void system_Configure( vlc_object_t * )
 /*****************************************************************************
  * system_End: destroy the BApplication object.
  *****************************************************************************/
-void system_End( vlc_object_t *p_this )
+void system_End( vlc_t *p_this )
 {
     /* Tell the BApplication to die */
     be_app->PostMessage( B_QUIT_REQUESTED );
 
-    vlc_thread_join( p_this->p_vlc->p_appthread );
-    vlc_object_destroy( p_this->p_vlc->p_appthread );
-
-    free( psz_program_path );
-}
+    vlc_thread_join( p_this->p_libvlc->p_appthread );
+    vlc_object_destroy( p_this->p_libvlc->p_appthread );
 
-/*****************************************************************************
- * system_GetProgramPath: get the full path to the program.
- *****************************************************************************/
-char * system_GetProgramPath( void )
-{
-    return( psz_program_path );
+    free( p_this->p_libvlc->psz_vlcpath );
 }
 
 /* following functions are local */
@@ -110,11 +114,11 @@ char * system_GetProgramPath( void )
  *****************************************************************************/
 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_vlc );
     BeApp->p_this = p_this;
     BeApp->Run();
-    vlc_object_unlink_all( p_this );
+    vlc_object_detach( p_this );
     delete BeApp;
 }
 
@@ -124,7 +128,9 @@ static void AppThread( vlc_object_t * p_this )
  * VlcApplication: application constructor
  *****************************************************************************/
 VlcApplication::VlcApplication( char * psz_mimetype )
-               :BApplication( psz_mimetype )
+               :BApplication( psz_mimetype ),
+                fInterfaceWindow( NULL ),
+                fRefsMessage( NULL )
 {
     /* Nothing to do, we use the default constructor */
 }
@@ -135,6 +141,7 @@ VlcApplication::VlcApplication( char * psz_mimetype )
 VlcApplication::~VlcApplication( )
 {
     /* Nothing to do, we use the default destructor */
+    delete fRefsMessage;
 }
 
 /*****************************************************************************
@@ -162,9 +169,53 @@ void VlcApplication::ReadyToRun( )
     BEntry entry( &info.ref ); 
     entry.GetPath( &path ); 
     path.GetParent( &path );
-    psz_program_path = strdup( path.Path() );
+    p_this->p_libvlc->psz_vlcpath = strdup( path.Path() );
 
     /* Tell the main thread we are finished initializing the BApplication */
     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;
+               }
+               default:
+                       BApplication::MessageReceived(message);
+       }
+}