]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/vlcproc.cpp
* all: added a new skin text variable "$S" to get the audio sample rate
[vlc] / modules / gui / skins2 / src / vlcproc.cpp
index 73bd8b81586fd5f05d86125f2d63c1c51a6df5dc..e67f3c7da444821bedff56ab5b7fac5643d17293 100644 (file)
@@ -19,7 +19,7 @@
  *
  * 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 <vlc/aout.h>
@@ -38,6 +38,7 @@
 #include "../commands/cmd_quit.hpp"
 #include "../commands/cmd_resize.hpp"
 #include "../commands/cmd_vars.hpp"
+#include "../commands/cmd_dialogs.hpp"
 #include "../utils/var_bool.hpp"
 #include <sstream>
 
@@ -99,11 +100,18 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
     REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
     REGISTER_VAR( m_cVarEqualizer, VarBoolImpl, "equalizer.isEnabled" )
     REGISTER_VAR( m_cVarEqPreamp, EqualizerPreamp, "equalizer.preamp" )
+    REGISTER_VAR( m_cVarDvdActive, VarBoolImpl, "dvd.isActive" )
+    REGISTER_VAR( m_cVarFullscreen, VarBoolImpl, "vlc.isFullscreen" )
+    REGISTER_VAR( m_cVarHasVout, VarBoolImpl, "vlc.hasVout" )
 #undef REGISTER_VAR
     m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
     pVarManager->registerVar( m_cVarStreamName, "streamName" );
     m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
     pVarManager->registerVar( m_cVarStreamURI, "streamURI" );
+    m_cVarStreamBitRate = VariablePtr( new VarText( getIntf(), false ) );
+    pVarManager->registerVar( m_cVarStreamBitRate, "bitrate" );
+    m_cVarStreamSampleRate = VariablePtr( new VarText( getIntf(), false ) );
+    pVarManager->registerVar( m_cVarStreamSampleRate, "samplerate" );
 
     // Register the equalizer bands
     for( int i = 0; i < EqualizerBands::kNbBands; i++)
@@ -122,13 +130,12 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
     var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
                      onIntfChange, this );
     // Called when a playlist item is added
-    // TODO: properly handle item-append
     var_AddCallback( pIntf->p_sys->p_playlist, "item-append",
-                     onIntfChange, this );
+                     onItemAppend, this );
     // Called when a playlist item is deleted
     // TODO: properly handle item-deleted
     var_AddCallback( pIntf->p_sys->p_playlist, "item-deleted",
-                     onIntfChange, this );
+                     onItemDelete, this );
     // Called when the "interface shower" wants us to show the skin
     var_AddCallback( pIntf->p_sys->p_playlist, "intf-show",
                      onIntfShow, this );
@@ -141,6 +148,11 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
     // Called when our skins2 demux wants us to load a new skin
     var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
 
+    // Called when we have an interaction dialog to display
+    var_Create( pIntf, "interaction", VLC_VAR_ADDRESS );
+    var_AddCallback( pIntf, "interaction", onInteraction, this );
+    pIntf->b_interaction = VLC_TRUE;
+
     // Callbacks for vout requests
     getIntf()->pf_request_window = &getWindow;
     getIntf()->pf_release_window = &releaseWindow;
@@ -167,9 +179,9 @@ VlcProc::~VlcProc()
     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
                      onIntfChange, this );
     var_DelCallback( getIntf()->p_sys->p_playlist, "item-append",
-                     onIntfChange, this );
+                     onItemAppend, this );
     var_DelCallback( getIntf()->p_sys->p_playlist, "item-deleted",
-                     onIntfChange, this );
+                     onItemDelete, this );
     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-show",
                      onIntfShow, this );
     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
@@ -228,15 +240,21 @@ void VlcProc::manage()
     VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
     VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
     VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
+    VarBoolImpl *pVarDvdActive = (VarBoolImpl*)m_cVarDvdActive.get();
+    VarBoolImpl *pVarFullscreen = (VarBoolImpl*)m_cVarFullscreen.get();
+    VarBoolImpl *pVarHasVout = (VarBoolImpl*)m_cVarHasVout.get();
+    VarText *pBitrate = (VarText*)m_cVarStreamBitRate.get();
+    VarText *pSampleRate = (VarText*)m_cVarStreamSampleRate.get();
 
     // Refresh audio variables
     refreshAudio();
 
-   // Update the input
+    // Update the input
     if( getIntf()->p_sys->p_input == NULL )
     {
-        getIntf()->p_sys->p_input = (input_thread_t *)vlc_object_find(
-            getIntf(), VLC_OBJECT_INPUT, FIND_ANYWHERE );
+        getIntf()->p_sys->p_input = getIntf()->p_sys->p_playlist->p_input;
+        if( getIntf()->p_sys->p_input )
+            vlc_object_yield( getIntf()->p_sys->p_input );
     }
     else if( getIntf()->p_sys->p_input->b_dead )
     {
@@ -262,6 +280,30 @@ void VlcProc::manage()
         pVarPaused->set( status == PLAYLIST_PAUSED );
 
         pVarSeekable->set( pos.f_float != 0.0 );
+
+        // Refresh DVD detection
+        vlc_value_t chapters_count;
+        var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
+                    &chapters_count, NULL );
+        pVarDvdActive->set( chapters_count.i_int > 0 );
+
+        // Refresh fullscreen status
+        vout_thread_t *pVout = (vout_thread_t *)vlc_object_find( pInput,
+                VLC_OBJECT_VOUT, FIND_CHILD );
+        pVarHasVout->set( pVout != NULL );
+        if( pVout )
+        {
+            pVarFullscreen->set( pVout->b_fullscreen );
+            vlc_object_release( pVout );
+        }
+
+        // Get the input bitrate
+        int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
+        pBitrate->set( UString::fromInt( getIntf(), bitrate ) );
+
+        // Get the audio sample rate
+        int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
+        pSampleRate->set( UString::fromInt( getIntf(), sampleRate ) );
     }
     else
     {
@@ -269,7 +311,10 @@ void VlcProc::manage()
         pVarPaused->set( false );
         pVarStopped->set( true );
         pVarSeekable->set( false );
+        pVarDvdActive->set( false );
         pTime->set( 0, false );
+        pVarFullscreen->set( false );
+        pVarHasVout->set( false );
     }
 
     // Refresh the random variable
@@ -284,6 +329,8 @@ void VlcProc::manage()
     // Refresh the repeat variable
     var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
     pVarRepeat->set( val.b_bool != 0 );
+
+
 }
 
 
@@ -351,9 +398,9 @@ int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
     playlist_t *p_playlist = (playlist_t*)pObj;
     pThis->updateStreamName(p_playlist);
 
-    // Create a playlist notify command
+    // Create a playlist notify command (for old style playlist)
     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
-    // Create a playtree notify command
+    // Create a playtree notify command (for new style playtree)
     CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
 
     // Push the command in the asynchronous command queue
@@ -411,6 +458,59 @@ int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
     return VLC_SUCCESS;
 }
 
+int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
+                           vlc_value_t oldVal, vlc_value_t newVal,
+                           void *pParam )
+{
+    VlcProc *pThis = (VlcProc*)pParam;
+
+    playlist_add_t *p_add = (playlist_add_t*)malloc( sizeof(
+                                                playlist_add_t ) ) ;
+
+    memcpy( p_add, newVal.p_address, sizeof( playlist_add_t ) ) ;
+
+    CmdGenericPtr ptrTree;
+    CmdPlaytreeAppend *pCmdTree = new CmdPlaytreeAppend( pThis->getIntf(),
+                                                             p_add );
+    ptrTree = CmdGenericPtr( pCmdTree );
+
+    // Create a playlist notify command (for old style playlist)
+    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
+
+    // Push the command in the asynchronous command queue
+    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
+    pQueue->push( CmdGenericPtr( pCmd ) );
+    pQueue->push( ptrTree , false );
+
+    return VLC_SUCCESS;
+}
+
+int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
+                           vlc_value_t oldVal, vlc_value_t newVal,
+                           void *pParam )
+{
+    VlcProc *pThis = (VlcProc*)pParam;
+
+    int i_id = newVal.i_int;
+
+    CmdGenericPtr ptrTree;
+    CmdPlaytreeDelete *pCmdTree = new CmdPlaytreeDelete( pThis->getIntf(),
+                                                         i_id);
+    ptrTree = CmdGenericPtr( pCmdTree );
+
+    // Create a playlist notify command (for old style playlist)
+    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
+
+    // Push the command in the asynchronous command queue
+    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
+    pQueue->push( CmdGenericPtr( pCmd ) );
+    pQueue->push( ptrTree , false );
+
+    return VLC_SUCCESS;
+}
+
+
+
 
 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
                                vlc_value_t oldVal, vlc_value_t newVal,
@@ -424,15 +524,16 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
     playlist_t *p_playlist = (playlist_t*)pObj;
     pThis->updateStreamName(p_playlist);
 
-    // Create a playlist notify command
+    // Create a playlist notify command (old style playlist)
     // TODO: selective update
     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
-    // Create a playtree notify command
-    CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
-
-    // Push the command in the asynchronous command queue
     pQueue->push( CmdGenericPtr( pCmd ) );
-    pQueue->push( CmdGenericPtr( pCmdTree ) );
+    // Create two playtree notify commands: one for old item, one for new
+    CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
+                                                         oldVal.i_int );
+    pQueue->push( CmdGenericPtr( pCmdTree ) , true );
+    pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), newVal.i_int );
+    pQueue->push( CmdGenericPtr( pCmdTree ) , true );
 
     return VLC_SUCCESS;
 }
@@ -455,16 +556,32 @@ int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
     return VLC_SUCCESS;
 }
 
+int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
+                            vlc_value_t oldVal, vlc_value_t newVal,
+                            void *pParam )
+{
+    VlcProc *pThis = (VlcProc*)pParam;
+    interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
+
+    CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
+    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
+    pQueue->push( CmdGenericPtr( pCmd ) );
+    return VLC_SUCCESS;
+}
+
 
 void VlcProc::updateStreamName( playlist_t *p_playlist )
 {
-    if( p_playlist->p_input )
+    if( p_playlist && p_playlist->p_input )
     {
+        // Get playlist item information
+        input_item_t *pItem = p_playlist->p_input->input.p_item;
+
         VarText &rStreamName = getStreamNameVar();
         VarText &rStreamURI = getStreamURIVar();
         // XXX: we should not need to access p_input->psz_source directly, a
         // getter should be provided by VLC core
-        string name = p_playlist->p_input->input.p_item->psz_name;
+        string name = pItem->psz_name;
         // XXX: This should be done in VLC core, not here...
         // Remove path information if any
         OSFactory *pFactory = OSFactory::instance( getIntf() );
@@ -474,10 +591,9 @@ void VlcProc::updateStreamName( playlist_t *p_playlist )
             name = name.substr( pos + 1, name.size() - pos + 1 );
         }
         UString srcName( getIntf(), name.c_str() );
-        UString srcURI( getIntf(),
-                         p_playlist->p_input->input.p_item->psz_uri );
+        UString srcURI( getIntf(), pItem->psz_uri );
 
-        // Create commands to update the stream variables
+       // Create commands to update the stream variables
         CmdSetText *pCmd1 = new CmdSetText( getIntf(), rStreamName, srcName );
         CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI );
         // Push the commands in the asynchronous command queue