]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/skin_main.cpp
Skins: missing include, makes skins2 on Windows fail to build.
[vlc] / modules / gui / skins2 / src / skin_main.cpp
index 6cae2ea2f42eb390268ebe1a8622b3ed1f62b092..b287be74e5667ded5115efaff1e0490f5090c89a 100644 (file)
@@ -31,6 +31,7 @@
 #include <vlc_input.h>
 #include <vlc_demux.h>
 #include <vlc_playlist.h>
+#include <vlc_thread.h>
 #include <vlc_window.h>
 
 #include "dialogs.hpp"
@@ -78,6 +79,12 @@ static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
                             void *pParam );
 
 
+static struct
+{
+    intf_thread_t *intf;
+    vlc_mutex_t mutex;
+} skin_load = { NULL, VLC_STATIC_MUTEX };
+
 //---------------------------------------------------------------------------
 // Open: initialize interface
 //---------------------------------------------------------------------------
@@ -88,10 +95,7 @@ static int Open( vlc_object_t *p_this )
     // Allocate instance and initialize some members
     p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
     if( p_intf->p_sys == NULL )
-    {
-        msg_Err( p_intf, "out of memory" );
         return( VLC_ENOMEM );
-    };
 
     p_intf->pf_run = Run;
 
@@ -166,9 +170,59 @@ static int Open( vlc_object_t *p_this )
 #endif
         return VLC_EGENERIC;
     }
+    vlc_mutex_lock( &skin_load.mutex );
+    skin_load.intf = p_intf;
+    vlc_mutex_unlock( &skin_load.mutex );
+
     Dialogs::instance( p_intf );
     ThemeRepository::instance( p_intf );
 
+    // Load a theme
+    char *skin_last = config_GetPsz( p_intf, "skins2-last" );
+
+    ThemeLoader *pLoader = new ThemeLoader( p_intf );
+
+    if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
+    {
+        // Get the resource path and try to load the default skin
+        OSFactory *pOSFactory = OSFactory::instance( p_intf );
+        const list<string> &resPath = pOSFactory->getResourcePath();
+        const string &sep = pOSFactory->getDirSeparator();
+
+        list<string>::const_iterator it;
+        for( it = resPath.begin(); it != resPath.end(); it++ )
+        {
+            string path = (*it) + sep + "default.vlt";
+            if( pLoader->load( path ) )
+            {
+                // Theme loaded successfully
+                break;
+            }
+        }
+        if( it == resPath.end() )
+        {
+            // Last chance: the user can select a new theme file
+            if( Dialogs::instance( p_intf ) )
+            {
+                CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
+                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
+                pQueue->push( CmdGenericPtr( pCmd ) );
+            }
+            else
+            {
+                // No dialogs provider, just quit...
+                CmdQuit *pCmd = new CmdQuit( p_intf );
+                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
+                pQueue->push( CmdGenericPtr( pCmd ) );
+                msg_Err( p_intf,
+                         "cannot show the \"open skin\" dialog: exiting...");
+            }
+        }
+    }
+    delete pLoader;
+
+    free( skin_last );
+
 #ifdef WIN32
     p_intf->b_should_run_on_first_thread = true;
 #endif
@@ -183,6 +237,10 @@ static void Close( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
 
+    vlc_mutex_lock( &skin_load.mutex );
+    skin_load.intf = NULL;
+    vlc_mutex_unlock( &skin_load.mutex);
+
     // Destroy "singleton" objects
     OSFactory::instance( p_intf )->destroyOSLoop();
     ThemeRepository::destroy( p_intf );
@@ -214,50 +272,6 @@ static void Close( vlc_object_t *p_this )
 static void Run( intf_thread_t *p_intf )
 {
     int canc = vlc_savecancel();
-    // Load a theme
-    ThemeLoader *pLoader = new ThemeLoader( p_intf );
-    char *skin_last = config_GetPsz( p_intf, "skins2-last" );
-
-    if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
-    {
-        // Get the resource path and try to load the default skin
-        OSFactory *pOSFactory = OSFactory::instance( p_intf );
-        const list<string> &resPath = pOSFactory->getResourcePath();
-        const string &sep = pOSFactory->getDirSeparator();
-
-        list<string>::const_iterator it;
-        for( it = resPath.begin(); it != resPath.end(); it++ )
-        {
-            string path = (*it) + sep + "default.vlt";
-            if( pLoader->load( path ) )
-            {
-                // Theme loaded successfully
-                break;
-            }
-        }
-        if( it == resPath.end() )
-        {
-            // Last chance: the user can select a new theme file
-            if( Dialogs::instance( p_intf ) )
-            {
-                CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
-                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
-                pQueue->push( CmdGenericPtr( pCmd ) );
-            }
-            else
-            {
-                // No dialogs provider, just quit...
-                CmdQuit *pCmd = new CmdQuit( p_intf );
-                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
-                pQueue->push( CmdGenericPtr( pCmd ) );
-                msg_Err( p_intf,
-                         "cannot show the \"open skin\" dialog: exiting...");
-            }
-        }
-    }
-    delete pLoader;
-
-    free( skin_last );
 
     // Get the instance of OSLoop
     OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
@@ -326,31 +340,28 @@ static int DemuxOpen( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    p_intf = (intf_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INTF,
-                                               FIND_ANYWHERE );
+    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 )
     {
-        // Do nothing is skins2 is not the main interface
-        if( var_Type( p_intf, "skin-to-load" ) == VLC_VAR_STRING )
-        {
-            playlist_t *p_playlist = pl_Hold( p_this );
-            // Make sure the item is deleted afterwards
-            /// \bug does not always work
-            playlist_CurrentPlayingItem( p_playlist )->i_flags |= PLAYLIST_REMOVE_FLAG;
-            vlc_object_release( p_playlist );
-
-            vlc_value_t val;
-            val.psz_string = p_demux->psz_path;
-            var_Set( p_intf, "skin-to-load", val );
-        }
-        else
-        {
-            msg_Warn( p_this,
-                      "skin could not be loaded (not using skins2 intf)" );
-        }
+        playlist_t *p_playlist = pl_Hold( p_this );
+        // Make sure the item is deleted afterwards
+        /// \bug does not always work
+        playlist_CurrentPlayingItem( p_playlist )->i_flags |= PLAYLIST_REMOVE_FLAG;
+        vlc_object_release( p_playlist );
 
+        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;
 }
@@ -383,28 +394,29 @@ static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
                             vlc_value_t oldVal, vlc_value_t newVal,
                             void *pParam )
 {
-    intf_thread_t *pIntf =
-        (intf_thread_t*)vlc_object_find( pObj, VLC_OBJECT_INTF, FIND_ANYWHERE );
+    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;
     }
 
-    // Check that we found the correct interface (same check as for the demux)
-    if( var_Type( pIntf, "skin-to-load" ) == VLC_VAR_STRING )
+    AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
+    if( newVal.b_bool )
     {
-        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 ) );
-        }
+        CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
+        pQueue->push( CmdGenericPtr( pCmd ) );
+    }
+    else
+    {
+        CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
+        pQueue->push( CmdGenericPtr( pCmd ) );
     }
 
     vlc_object_release( pIntf );
@@ -417,28 +429,29 @@ static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
                             vlc_value_t oldVal, vlc_value_t newVal,
                             void *pParam )
 {
-    intf_thread_t *pIntf =
-        (intf_thread_t*)vlc_object_find( pObj, VLC_OBJECT_INTF, FIND_ANYWHERE );
+    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;
     }
 
-    // Check that we found the correct interface (same check as for the demux)
-    if( var_Type( pIntf, "skin-to-load" ) == VLC_VAR_STRING )
+    AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
+    if( newVal.b_bool )
     {
-        AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
-        if( newVal.b_bool )
-        {
-            CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
-            pQueue->push( CmdGenericPtr( pCmd ) );
-        }
-        else
-        {
-            CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
-            pQueue->push( CmdGenericPtr( pCmd ) );
-        }
+        CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
+        pQueue->push( CmdGenericPtr( pCmd ) );
+    }
+    else
+    {
+        CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
+        pQueue->push( CmdGenericPtr( pCmd ) );
     }
 
     vlc_object_release( pIntf );
@@ -465,16 +478,16 @@ static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
 
-vlc_module_begin();
-    set_category( CAT_INTERFACE );
-    set_subcategory( SUBCAT_INTERFACE_MAIN );
+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();
+        change_autosave ()
     add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
                 true );
-        change_autosave();
-        change_internal();
+        change_autosave ()
+        change_internal ()
 #ifdef WIN32
     add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
               SKINS2_SYSTRAY_LONG, false );
@@ -486,19 +499,19 @@ vlc_module_begin();
 
     add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
               SKINS2_PLAYLIST_LONG, false );
-    set_shortname( N_("Skins"));
-    set_description( N_("Skinnable Interface") );
-    set_capability( "interface", 30 );
-    set_callbacks( Open, Close );
-    add_shortcut( "skins" );
-
-    add_submodule();
-        set_capability( "vout window", 51 );
-        set_callbacks( WindowOpen, WindowClose );
-
-    add_submodule();
-        set_description( N_("Skins loader demux") );
-        set_capability( "demux", 5 );
-        set_callbacks( DemuxOpen, NULL );
-
-vlc_module_end();
+    set_shortname( N_("Skins"))
+    set_description( N_("Skinnable Interface") )
+    set_capability( "interface", 30 )
+    set_callbacks( Open, Close )
+    add_shortcut( "skins" )
+
+    add_submodule ()
+        set_capability( "vout_window", 51 )
+        set_callbacks( WindowOpen, WindowClose )
+
+    add_submodule ()
+        set_description( N_("Skins loader demux") )
+        set_capability( "demux", 5 )
+        set_callbacks( DemuxOpen, NULL )
+
+vlc_module_end ()