]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/skin_main.cpp
skins2: fix forgotten initialization in copy constructor
[vlc] / modules / gui / skins2 / src / skin_main.cpp
index 4d9ea1cb8055a1ab09c334c23896fb3ea3412665..095bf498ea1d1701344e5593c434d2d059f6e57b 100644 (file)
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_input.h>
-#include <vlc_demux.h>
 #include <vlc_playlist.h>
 #include <vlc_threads.h>
 #include <vlc_vout_window.h>
+#include <vlc_vout_display.h>
 
 #include "dialogs.hpp"
 #include "os_factory.hpp"
 #include "theme_repository.hpp"
 #include "vout_window.hpp"
 #include "vout_manager.hpp"
+#include "art_manager.hpp"
 #include "../parser/interpreter.hpp"
 #include "../commands/async_queue.hpp"
 #include "../commands/cmd_quit.hpp"
 #include "../commands/cmd_dialogs.hpp"
 #include "../commands/cmd_minimize.hpp"
 #include "../commands/cmd_playlist.hpp"
-
-//---------------------------------------------------------------------------
-// Exported interface functions.
-//---------------------------------------------------------------------------
-#ifdef WIN32_SKINS
-extern "C" __declspec( dllexport )
-    int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
-#endif
-
+#include "../commands/cmd_callbacks.hpp"
+#include "../commands/cmd_show_window.hpp"
+#include "../commands/cmd_resize.hpp"
+#include "../commands/cmd_on_top.hpp"
 
 //---------------------------------------------------------------------------
 // Local prototypes
@@ -67,20 +63,6 @@ static int  Open  ( vlc_object_t * );
 static void Close ( vlc_object_t * );
 static void *Run  ( void * );
 
-static int DemuxOpen( vlc_object_t * );
-static int Demux( demux_t * );
-static int DemuxControl( demux_t *, int, va_list );
-
-//---------------------------------------------------------------------------
-// Prototypes for configuration callbacks
-//---------------------------------------------------------------------------
-static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
-                            vlc_value_t oldVal, vlc_value_t newVal,
-                            void *pParam );
-static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
-                            vlc_value_t oldVal, vlc_value_t newVal,
-                            void *pParam );
-
 static struct
 {
     intf_thread_t *intf;
@@ -101,7 +83,7 @@ static int Open( vlc_object_t *p_this )
 
     // Suscribe to messages bank
 #if 0
-    p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
+    p_intf->p_sys->p_sub = vlc_Subscribe( p_intf );
 #endif
 
     p_intf->p_sys->p_input = NULL;
@@ -122,16 +104,11 @@ static int Open( vlc_object_t *p_this )
     // No theme yet
     p_intf->p_sys->p_theme = NULL;
 
-    // Create a variable to be notified of skins to be loaded
-    var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
-
-    vlc_mutex_init( &p_intf->p_sys->vout_lock );
-    vlc_cond_init( &p_intf->p_sys->vout_wait );
-
     vlc_mutex_init( &p_intf->p_sys->init_lock );
     vlc_cond_init( &p_intf->p_sys->init_wait );
 
     vlc_mutex_lock( &p_intf->p_sys->init_lock );
+    p_intf->p_sys->b_error = false;
     p_intf->p_sys->b_ready = false;
 
     if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
@@ -141,8 +118,6 @@ static int Open( vlc_object_t *p_this )
 
         vlc_cond_destroy( &p_intf->p_sys->init_wait );
         vlc_mutex_destroy( &p_intf->p_sys->init_lock );
-        vlc_cond_destroy( &p_intf->p_sys->vout_wait );
-        vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
         free( p_intf->p_sys );
         return VLC_EGENERIC;
     }
@@ -151,6 +126,17 @@ static int Open( vlc_object_t *p_this )
         vlc_cond_wait( &p_intf->p_sys->init_wait, &p_intf->p_sys->init_lock );
     vlc_mutex_unlock( &p_intf->p_sys->init_lock );
 
+    if( p_intf->p_sys->b_error )
+    {
+        vlc_join( p_intf->p_sys->thread, NULL );
+
+        vlc_mutex_destroy( &p_intf->p_sys->init_lock );
+        vlc_cond_destroy( &p_intf->p_sys->init_wait );
+
+        free( p_intf->p_sys );
+        return VLC_EGENERIC;
+    }
+
     vlc_mutex_lock( &skin_load.mutex );
     skin_load.intf = p_intf;
     vlc_mutex_unlock( &skin_load.mutex );
@@ -178,12 +164,9 @@ static void Close( vlc_object_t *p_this )
 
     // Unsubscribe from messages bank
 #if 0
-    msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+    vlc_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
 #endif
 
-    vlc_cond_destroy( &p_intf->p_sys->vout_wait );
-    vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
-
     // Destroy structure
     free( p_intf->p_sys );
 }
@@ -220,13 +203,13 @@ static void *Run( void * p_obj )
     }
     if( Interpreter::instance( p_intf ) == NULL )
     {
-        msg_Err( p_intf, "cannot instanciate Interpreter" );
+        msg_Err( p_intf, "cannot instantiate Interpreter" );
         b_error = true;
         goto end;
     }
     if( VarManager::instance( p_intf ) == NULL )
     {
-        msg_Err( p_intf, "cannot instanciate VarManager" );
+        msg_Err( p_intf, "cannot instantiate VarManager" );
         b_error = true;
         goto end;
     }
@@ -238,19 +221,25 @@ static void *Run( void * p_obj )
     }
     if( VoutManager::instance( p_intf ) == NULL )
     {
-        msg_Err( p_intf, "cannot instanciate VoutManager" );
+        msg_Err( p_intf, "cannot instantiate VoutManager" );
+        b_error = true;
+        goto end;
+    }
+    if( ArtManager::instance( p_intf ) == NULL )
+    {
+        msg_Err( p_intf, "cannot instantiate ArtManager" );
         b_error = true;
         goto end;
     }
     if( ThemeRepository::instance( p_intf ) == NULL )
     {
-        msg_Err( p_intf, "cannot instanciate ThemeRepository" );
+        msg_Err( p_intf, "cannot instantiate ThemeRepository" );
         b_error = true;
         goto end;
     }
     if( Dialogs::instance( p_intf ) == NULL )
     {
-        msg_Err( p_intf, "cannot instanciate qt4 dialogs provider" );
+        msg_Err( p_intf, "cannot instantiate qt4 dialogs provider" );
         b_error = true;
         goto end;
     }
@@ -275,6 +264,7 @@ static void *Run( void * p_obj )
     loop = OSFactory::instance( p_intf )->getOSLoop();
 
     // Signal the main thread this thread is now ready
+    p_intf->p_sys->b_error = false;
     p_intf->p_sys->b_ready = true;
     vlc_cond_signal( &p_intf->p_sys->init_wait );
     vlc_mutex_unlock( &p_intf->p_sys->init_lock );
@@ -297,12 +287,13 @@ static void *Run( void * p_obj )
     }
 
     // save config file
-    config_SaveConfigFile( p_intf, NULL );
+    config_SaveConfigFile( p_intf );
 
 end:
     // Destroy "singleton" objects
     Dialogs::destroy( p_intf );
     ThemeRepository::destroy( p_intf );
+    ArtManager::destroy( p_intf );
     VoutManager::destroy( p_intf );
     VlcProc::destroy( p_intf );
     VarManager::destroy( p_intf );
@@ -312,23 +303,43 @@ end:
 
     if( b_error )
     {
+        p_intf->p_sys->b_error = true;
         p_intf->p_sys->b_ready = true;
         vlc_cond_signal( &p_intf->p_sys->init_wait );
         vlc_mutex_unlock( &p_intf->p_sys->init_lock );
-
-        libvlc_Quit( p_intf->p_libvlc );
     }
 
     vlc_restorecancel(canc);
     return NULL;
 }
 
-static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
+static int  WindowOpen( vout_window_t *, const vout_window_cfg_t * );
+static void WindowClose( vout_window_t * );
+static int  WindowControl( vout_window_t *, int, va_list );
+
+struct vout_window_sys_t
+{
+    intf_thread_t*     pIntf;
+    vout_window_cfg_t  cfg;
+};
+
+static void WindowOpenLocal( intf_thread_t* pIntf, vlc_object_t *pObj )
+{
+    vout_window_t* pWnd = (vout_window_t*)pObj;
+    int width = (int)pWnd->sys->cfg.width;
+    int height = (int)pWnd->sys->cfg.height;
+    VoutManager::instance( pIntf )->acceptWnd( pWnd, width, height );
+}
+
+static void WindowCloseLocal( intf_thread_t* pIntf, vlc_object_t *pObj )
+{
+    vout_window_t* pWnd = (vout_window_t*)pObj;
+    VoutManager::instance( pIntf )->releaseWnd( pWnd );
+}
 
-// Callbacks for vout requests
-static int WindowOpen( vlc_object_t *p_this )
+static int WindowOpen( vout_window_t *pWnd, const vout_window_cfg_t *cfg )
 {
-    vout_window_t *pWnd = (vout_window_t *)p_this;
+    vout_window_sys_t* sys;
 
     vlc_mutex_lock( &skin_load.mutex );
     intf_thread_t *pIntf = skin_load.intf;
@@ -341,194 +352,110 @@ static int WindowOpen( vlc_object_t *p_this )
 
     if( !vlc_object_alive( pIntf ) ||
         !var_InheritBool( pIntf, "skinned-video") ||
-        pWnd->cfg->is_standalone )
+        cfg->is_standalone )
     {
         vlc_object_release( pIntf );
         return VLC_EGENERIC;
     }
 
-    vlc_mutex_lock( &serializer );
-
-    pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
-
-    if( pWnd->handle.hwnd )
-    {
-        pWnd->control = &VoutManager::controlWindow;
-        pWnd->sys = (vout_window_sys_t*)pIntf;
-
-        vlc_mutex_unlock( &serializer );
-        return VLC_SUCCESS;
-    }
-    else
+    sys = (vout_window_sys_t*)calloc( 1, sizeof( *sys ) );
+    if( !sys )
     {
         vlc_object_release( pIntf );
-        vlc_mutex_unlock( &serializer );
-        return VLC_EGENERIC;
+        return VLC_ENOMEM;
     }
-}
-
-static void WindowClose( vlc_object_t *p_this )
-{
-    vout_window_t *pWnd = (vout_window_t *)p_this;
-    intf_thread_t *pIntf = (intf_thread_t *)pWnd->sys;
 
-    VoutManager::releaseWindow( pIntf, pWnd );
+    pWnd->sys = sys;
+    pWnd->sys->cfg = *cfg;
+    pWnd->sys->pIntf = pIntf;
+    pWnd->control = WindowControl;
 
-    vlc_object_release( pIntf );
-}
+    // force execution in the skins2 thread context
+    CmdExecuteBlock* cmd = new CmdExecuteBlock( pIntf, VLC_OBJECT( pWnd ),
+                                                WindowOpenLocal );
+    CmdExecuteBlock::executeWait( CmdGenericPtr( cmd ) );
 
-//---------------------------------------------------------------------------
-// DemuxOpen: initialize demux
-//---------------------------------------------------------------------------
-static int DemuxOpen( vlc_object_t *p_this )
-{
-    demux_t *p_demux = (demux_t*)p_this;
-    intf_thread_t *p_intf;
-    char *ext;
-
-    // Needed callbacks
-    p_demux->pf_demux   = Demux;
-    p_demux->pf_control = DemuxControl;
-
-    // Test that we have a valid .vlt or .wsz file, based on the extension
-    if( ( ext = strrchr( p_demux->psz_path, '.' ) ) == NULL ||
-        ( strcasecmp( ext, ".vlt" ) && strcasecmp( ext, ".wsz" ) ) )
+#ifdef X11_SKINS
+    if( !pWnd->handle.xid )
+#else
+    if( !pWnd->handle.hwnd )
+#endif
     {
+        free( sys );
+        vlc_object_release( pIntf );
         return VLC_EGENERIC;
     }
 
-    vlc_mutex_lock( &skin_load.mutex );
-    p_intf = skin_load.intf;
-    if( p_intf )
-        vlc_object_hold( p_intf );
-    vlc_mutex_unlock( &skin_load.mutex );
-
-    if( p_intf != NULL )
-    {
-        playlist_t *p_playlist = pl_Get( p_this );
-
-        PL_LOCK;
-        // Make sure the item is deleted afterwards
-        /// \bug does not always work
-        playlist_CurrentPlayingItem( p_playlist )->i_flags |= PLAYLIST_REMOVE_FLAG;
-        PL_UNLOCK;
-
-        var_SetString( p_intf, "skin-to-load", p_demux->psz_path );
-        vlc_object_release( p_intf );
-    }
-    else
-    {
-        msg_Warn( p_this,
-                  "skin could not be loaded (not using skins2 intf)" );
-    }
-
     return VLC_SUCCESS;
 }
 
-
-//---------------------------------------------------------------------------
-// Demux: return EOF
-//---------------------------------------------------------------------------
-static int Demux( demux_t *p_demux )
+static void WindowClose( vout_window_t *pWnd )
 {
-    return 0;
-}
-
+    vout_window_sys_t* sys = pWnd->sys;
+    intf_thread_t *pIntf = sys->pIntf;
 
-//---------------------------------------------------------------------------
-// DemuxControl
-//---------------------------------------------------------------------------
-static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
-{
-    switch( i_query )
-    {
-    case DEMUX_GET_PTS_DELAY:
-    {
-        int64_t *pi_pts_delay = va_arg( args, int64_t * );
-        *pi_pts_delay = 10;
-        return VLC_SUCCESS;
-    }
-    default:
-        return VLC_EGENERIC;
-    }
+    // force execution in the skins2 thread context
+    CmdExecuteBlock* cmd = new CmdExecuteBlock( pIntf, VLC_OBJECT( pWnd ),
+                                                WindowCloseLocal );
+    CmdExecuteBlock::executeWait( CmdGenericPtr( cmd ) );
 
+    vlc_object_release( sys->pIntf );
+    free( sys );
 }
 
-
-//---------------------------------------------------------------------------
-// Callbacks
-//---------------------------------------------------------------------------
-
-/// Callback for the systray configuration option
-static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
-                            vlc_value_t oldVal, vlc_value_t newVal,
-                            void *pParam )
+static int WindowControl( vout_window_t *pWnd, int query, va_list args )
 {
-    intf_thread_t *pIntf;
-
-    vlc_mutex_lock( &skin_load.mutex );
-    pIntf = skin_load.intf;
-    if( pIntf )
-        vlc_object_hold( pIntf );
-    vlc_mutex_unlock( &skin_load.mutex );
-
-    if( pIntf == NULL )
-    {
-        return VLC_EGENERIC;
-    }
-
+    vout_window_sys_t* sys = pWnd->sys;
+    intf_thread_t *pIntf = sys->pIntf;
     AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
-    if( newVal.b_bool )
-    {
-        CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
-        pQueue->push( CmdGenericPtr( pCmd ) );
-    }
-    else
-    {
-        CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
-        pQueue->push( CmdGenericPtr( pCmd ) );
-    }
-
-    vlc_object_release( pIntf );
-    return VLC_SUCCESS;
-}
-
-
-/// Callback for the systray configuration option
-static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
-                            vlc_value_t oldVal, vlc_value_t newVal,
-                            void *pParam )
-{
-    intf_thread_t *pIntf;
-
-    vlc_mutex_lock( &skin_load.mutex );
-    pIntf = skin_load.intf;
-    if( pIntf )
-        vlc_object_hold( pIntf );
-    vlc_mutex_unlock( &skin_load.mutex );
 
-    if( pIntf == NULL )
-    {
-        return VLC_EGENERIC;
-    }
-
-    AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
-    if( newVal.b_bool )
+    switch( query )
     {
-        CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
-        pQueue->push( CmdGenericPtr( pCmd ) );
+        case VOUT_WINDOW_SET_SIZE:
+        {
+            unsigned int i_width  = va_arg( args, unsigned int );
+            unsigned int i_height = va_arg( args, unsigned int );
+
+            if( i_width && i_height )
+            {
+                // Post a vout resize command
+                CmdResizeVout *pCmd =
+                    new CmdResizeVout( pIntf, pWnd,
+                                       (int)i_width, (int)i_height );
+                pQueue->push( CmdGenericPtr( pCmd ) );
+            }
+            return VLC_EGENERIC;
+        }
+
+        case VOUT_WINDOW_SET_FULLSCREEN:
+        {
+            bool b_fullscreen = va_arg( args, int );
+
+            // Post a set fullscreen command
+            CmdSetFullscreen* pCmd =
+                new CmdSetFullscreen( pIntf, pWnd, b_fullscreen );
+            pQueue->push( CmdGenericPtr( pCmd ) );
+            return VLC_SUCCESS;
+        }
+
+        case VOUT_WINDOW_SET_STATE:
+        {
+            unsigned i_arg = va_arg( args, unsigned );
+            unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
+
+            // Post a SetOnTop command
+            CmdSetOnTop* pCmd =
+                new CmdSetOnTop( pIntf, on_top );
+            pQueue->push( CmdGenericPtr( pCmd ) );
+            return VLC_SUCCESS;
+        }
+
+        default:
+            msg_Dbg( pIntf, "control query not supported" );
+            return VLC_EGENERIC;
     }
-    else
-    {
-        CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
-        pQueue->push( CmdGenericPtr( pCmd ) );
-    }
-
-    vlc_object_release( pIntf );
-    return VLC_SUCCESS;
 }
 
-
 //---------------------------------------------------------------------------
 // Module descriptor
 //---------------------------------------------------------------------------
@@ -555,25 +482,23 @@ static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
 vlc_module_begin ()
     set_category( CAT_INTERFACE )
     set_subcategory( SUBCAT_INTERFACE_MAIN )
-    add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
-              true )
-        change_autosave ()
-    add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
+    add_loadfile( "skins2-last", "", SKINS2_LAST, SKINS2_LAST_LONG,
+                  true )
+    add_string( "skins2-config", "", SKINS2_CONFIG, SKINS2_CONFIG_LONG,
                 true )
-        change_autosave ()
         change_private ()
 #ifdef WIN32
-    add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
+    add_bool( "skins2-systray", true, SKINS2_SYSTRAY,
               SKINS2_SYSTRAY_LONG, false );
-    add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
+    add_bool( "skins2-taskbar", true, SKINS2_TASKBAR,
               SKINS2_TASKBAR_LONG, false );
 #endif
-    add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
+    add_bool( "skins2-transparency", false, SKINS2_TRANSPARENCY,
               SKINS2_TRANSPARENCY_LONG, false );
 
-    add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
+    add_bool( "skinned-playlist", true, SKINS2_PLAYLIST,
               SKINS2_PLAYLIST_LONG, false );
-    add_bool( "skinned-video", true, NULL, SKINS2_VIDEO,
+    add_bool( "skinned-video", true, SKINS2_VIDEO,
               SKINS2_VIDEO_LONG, false );
     set_shortname( N_("Skins"))
     set_description( N_("Skinnable Interface") )
@@ -589,10 +514,4 @@ vlc_module_begin ()
 #endif
         set_callbacks( WindowOpen, WindowClose )
 
-    add_submodule ()
-        set_description( N_("Skins loader demux") )
-        set_capability( "access_demux", 5 )
-        set_callbacks( DemuxOpen, NULL )
-        add_shortcut( "skins" )
-
 vlc_module_end ()