]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/parser/interpreter.cpp
cosmetic: remove nullity test on free() and delete
[vlc] / modules / gui / skins2 / parser / interpreter.cpp
index 3b4c6c47646ead028c0162aaeffd7032e62d5d66..56c9f11a85eac6da4b17f7f3ba69ffe4af1eeea5 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -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 "interpreter.hpp"
@@ -30,6 +30,7 @@
 #include "../commands/cmd_playtree.hpp"
 #include "../commands/cmd_dialogs.hpp"
 #include "../commands/cmd_dummy.hpp"
+#include "../commands/cmd_dvd.hpp"
 #include "../commands/cmd_layout.hpp"
 #include "../commands/cmd_quit.hpp"
 #include "../commands/cmd_minimize.hpp"
@@ -37,6 +38,7 @@
 #include "../commands/cmd_fullscreen.hpp"
 #include "../commands/cmd_on_top.hpp"
 #include "../commands/cmd_show_window.hpp"
+#include "../commands/cmd_snapshot.hpp"
 #include "../src/theme.hpp"
 #include "../src/var_manager.hpp"
 #include "../src/vlcproc.hpp"
@@ -55,20 +57,27 @@ Interpreter::Interpreter( intf_thread_t *pIntf ): SkinObject( pIntf )
     REGISTER_CMD( "dialogs.directory()", CmdDlgDirectory )
     REGISTER_CMD( "dialogs.disc()", CmdDlgDisc )
     REGISTER_CMD( "dialogs.net()", CmdDlgNet )
+    REGISTER_CMD( "dialogs.playlist()", CmdDlgPlaylist )
     REGISTER_CMD( "dialogs.messages()", CmdDlgMessages )
     REGISTER_CMD( "dialogs.prefs()", CmdDlgPrefs )
     REGISTER_CMD( "dialogs.fileInfo()", CmdDlgFileInfo )
     REGISTER_CMD( "dialogs.streamingWizard()", CmdDlgStreamingWizard )
+
     REGISTER_CMD( "dialogs.popup()", CmdDlgShowPopupMenu )
+    REGISTER_CMD( "dialogs.audioPopup()", CmdDlgShowAudioPopupMenu )
+    REGISTER_CMD( "dialogs.videoPopup()", CmdDlgShowVideoPopupMenu )
+    REGISTER_CMD( "dialogs.miscPopup()", CmdDlgShowMiscPopupMenu )
+
+    REGISTER_CMD( "dvd.nextTitle()", CmdDvdNextTitle )
+    REGISTER_CMD( "dvd.previousTitle()", CmdDvdPreviousTitle )
+    REGISTER_CMD( "dvd.nextChapter()", CmdDvdNextChapter )
+    REGISTER_CMD( "dvd.previousChapter()", CmdDvdPreviousChapter )
+    REGISTER_CMD( "dvd.rootMenu()", CmdDvdRootMenu )
     REGISTER_CMD( "playlist.load()", CmdDlgPlaylistLoad )
     REGISTER_CMD( "playlist.save()", CmdDlgPlaylistSave )
     REGISTER_CMD( "playlist.add()", CmdDlgAdd )
-    VarList &rVar = VlcProc::instance( getIntf() )->getPlaylistVar();
-    m_commandMap["playlist.del()"] =
-        CmdGenericPtr( new CmdPlaylistDel( getIntf(), rVar ) );
     REGISTER_CMD( "playlist.next()", CmdPlaylistNext )
     REGISTER_CMD( "playlist.previous()", CmdPlaylistPrevious )
-    REGISTER_CMD( "playlist.sort()", CmdPlaylistSort )
     m_commandMap["playlist.setRandom(true)"] =
         CmdGenericPtr( new CmdPlaylistRandom( getIntf(), true ) );
     m_commandMap["playlist.setRandom(false)"] =
@@ -82,8 +91,11 @@ Interpreter::Interpreter( intf_thread_t *pIntf ): SkinObject( pIntf )
     m_commandMap["playlist.setRepeat(false)"] =
         CmdGenericPtr( new CmdPlaylistRepeat( getIntf(), false ) );
     VarTree &rVarTree = VlcProc::instance( getIntf() )->getPlaytreeVar();
+    m_commandMap["playlist.del()"] =
+        CmdGenericPtr( new CmdPlaytreeDel( getIntf(), rVarTree ) );
     m_commandMap["playtree.del()"] =
         CmdGenericPtr( new CmdPlaytreeDel( getIntf(), rVarTree ) );
+    REGISTER_CMD( "playlist.sort()", CmdPlaytreeSort )
     REGISTER_CMD( "playtree.sort()", CmdPlaytreeSort )
     REGISTER_CMD( "vlc.fullscreen()", CmdFullscreen )
     REGISTER_CMD( "vlc.play()", CmdPlay )
@@ -96,6 +108,7 @@ Interpreter::Interpreter( intf_thread_t *pIntf ): SkinObject( pIntf )
     REGISTER_CMD( "vlc.volumeDown()", CmdVolumeDown )
     REGISTER_CMD( "vlc.minimize()", CmdMinimize )
     REGISTER_CMD( "vlc.onTop()", CmdOnTop )
+    REGISTER_CMD( "vlc.snapshot()", CmdSnapshot )
     REGISTER_CMD( "vlc.quit()", CmdQuit )
     m_commandMap["equalizer.enable()"] =
         CmdGenericPtr( new CmdSetEqualizer( getIntf(), true ) );
@@ -128,11 +141,8 @@ Interpreter *Interpreter::instance( intf_thread_t *pIntf )
 
 void Interpreter::destroy( intf_thread_t *pIntf )
 {
-    if( pIntf->p_sys->p_interpreter )
-    {
-        delete pIntf->p_sys->p_interpreter;
-        pIntf->p_sys->p_interpreter = NULL;
-    }
+    delete pIntf->p_sys->p_interpreter;
+    pIntf->p_sys->p_interpreter = NULL;
 }
 
 
@@ -162,6 +172,14 @@ CmdGeneric *Interpreter::parseAction( const string &rAction, Theme *pTheme )
             // Now remove any whitespace at the beginning of the right part,
             // and go on checking for further actions in it...
             rightPart = rightPart.substr( pos, rightPart.size() );
+            if ( rightPart.find_first_not_of( " \t;" ) == string::npos )
+            {
+                // The right part is completely buggy, it's time to leave the
+                // loop...
+                rightPart = "";
+                break;
+            }
+
             rightPart =
                 rightPart.substr( rightPart.find_first_not_of( " \t;" ),
                                   rightPart.size() );
@@ -187,16 +205,16 @@ CmdGeneric *Interpreter::parseAction( const string &rAction, Theme *pTheme )
         GenericLayout *pLayout = pTheme->getLayoutById( layoutId );
         if( !pWin )
         {
-            msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
+            msg_Err( getIntf(), "unknown window (%s)", windowId.c_str() );
         }
         else if( !pLayout )
         {
-            msg_Err( getIntf(), "Unknown layout (%s)", layoutId.c_str() );
+            msg_Err( getIntf(), "unknown layout (%s)", layoutId.c_str() );
         }
         // Check that the layout doesn't correspond to another window
         else if( pWin != pLayout->getWindow() )
         {
-            msg_Err( getIntf(), "Layout %s is not associated to window %s",
+            msg_Err( getIntf(), "layout %s is not associated to window %s",
                      layoutId.c_str(), windowId.c_str() );
         }
         else
@@ -204,34 +222,111 @@ CmdGeneric *Interpreter::parseAction( const string &rAction, Theme *pTheme )
             pCommand = new CmdLayout( getIntf(), *pWin, *pLayout );
         }
     }
-    else if( rAction.find( ".show()" ) != string::npos )
+    else if( rAction.find( ".maximize()" ) != string::npos )
     {
-        int leftPos = rAction.find( ".show()" );
+        int leftPos = rAction.find( ".maximize()" );
         string windowId = rAction.substr( 0, leftPos );
+
         TopWindow *pWin = pTheme->getWindowById( windowId );
-        if( pWin )
+        if( !pWin )
+        {
+            msg_Err( getIntf(), "unknown window (%s)", windowId.c_str() );
+        }
+        else
         {
-            pCommand = new CmdShowWindow( getIntf(), pTheme->getWindowManager(),
+            pCommand = new CmdMaximize( getIntf(),
+                                        pTheme->getWindowManager(),
+                                        *pWin );
+        }
+    }
+    else if( rAction.find( ".unmaximize()" ) != string::npos )
+    {
+        int leftPos = rAction.find( ".unmaximize()" );
+        string windowId = rAction.substr( 0, leftPos );
+
+        TopWindow *pWin = pTheme->getWindowById( windowId );
+        if( !pWin )
+        {
+            msg_Err( getIntf(), "unknown window (%s)", windowId.c_str() );
+        }
+        else
+        {
+            pCommand = new CmdUnmaximize( getIntf(),
+                                          pTheme->getWindowManager(),
                                           *pWin );
         }
+    }
+    else if( rAction.find( ".show()" ) != string::npos )
+    {
+        int leftPos = rAction.find( ".show()" );
+        string windowId = rAction.substr( 0, leftPos );
+
+        if( windowId == "playlist_window" &&
+            !config_GetInt( getIntf(), "skinned-playlist") )
+        {
+            list<CmdGeneric *> list;
+            list.push_back( new CmdDlgPlaylist( getIntf() ) );
+            TopWindow *pWin = pTheme->getWindowById( windowId );
+            if( pWin )
+                list.push_back( new CmdHideWindow( getIntf(),
+                                                   pTheme->getWindowManager(),
+                                                   *pWin ) );
+            pCommand = new CmdMuxer( getIntf(), list );
+        }
         else
         {
-            msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
+            TopWindow *pWin = pTheme->getWindowById( windowId );
+            if( pWin )
+            {
+                pCommand = new CmdShowWindow( getIntf(),
+                                              pTheme->getWindowManager(),
+                                              *pWin );
+            }
+            else
+            {
+                // It was maybe the id of a popup
+                Popup *pPopup = pTheme->getPopupById( windowId );
+                if( pPopup )
+                {
+                    pCommand = new CmdShowPopup( getIntf(), *pPopup );
+                }
+                else
+                {
+                    msg_Err( getIntf(), "unknown window or popup (%s)",
+                             windowId.c_str() );
+                }
+            }
         }
     }
     else if( rAction.find( ".hide()" ) != string::npos )
     {
         int leftPos = rAction.find( ".hide()" );
         string windowId = rAction.substr( 0, leftPos );
-        TopWindow *pWin = pTheme->getWindowById( windowId );
-        if( pWin )
+        if( windowId == "playlist_window" &&
+           ! config_GetInt( getIntf(), "skinned-playlist") )
         {
-            pCommand = new CmdHideWindow( getIntf(), pTheme->getWindowManager(),
-                                          *pWin );
+            list<CmdGeneric *> list;
+            list.push_back( new CmdDlgPlaylist( getIntf() ) );
+            TopWindow *pWin = pTheme->getWindowById( windowId );
+            if( pWin )
+                list.push_back( new CmdHideWindow( getIntf(),
+                                                   pTheme->getWindowManager(),
+                                                   *pWin ) );
+            pCommand = new CmdMuxer( getIntf(), list );
         }
         else
         {
-            msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
+            TopWindow *pWin = pTheme->getWindowById( windowId );
+            if( pWin )
+            {
+                pCommand = new CmdHideWindow( getIntf(),
+                                              pTheme->getWindowManager(),
+                                              *pWin );
+            }
+            else
+            {
+                msg_Err( getIntf(), "unknown window (%s)", windowId.c_str() );
+            }
         }
     }
 
@@ -242,7 +337,7 @@ CmdGeneric *Interpreter::parseAction( const string &rAction, Theme *pTheme )
     }
     else
     {
-        msg_Warn( getIntf(), "Unknown action: %s", rAction.c_str() );
+        msg_Warn( getIntf(), "unknown action: %s", rAction.c_str() );
     }
 
     return pCommand;
@@ -268,7 +363,7 @@ VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme )
             // Get the 2 last variables on the stack
             if( varStack.empty() )
             {
-                msg_Err( getIntf(), "Invalid boolean expression: %s",
+                msg_Err( getIntf(), "invalid boolean expression: %s",
                          rName.c_str());
                 return NULL;
             }
@@ -276,7 +371,7 @@ VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme )
             varStack.pop_back();
             if( varStack.empty() )
             {
-                msg_Err( getIntf(), "Invalid boolean expression: %s",
+                msg_Err( getIntf(), "invalid boolean expression: %s",
                          rName.c_str());
                 return NULL;
             }
@@ -294,7 +389,7 @@ VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme )
             // Get the 2 last variables on the stack
             if( varStack.empty() )
             {
-                msg_Err( getIntf(), "Invalid boolean expression: %s",
+                msg_Err( getIntf(), "invalid boolean expression: %s",
                          rName.c_str());
                 return NULL;
             }
@@ -302,7 +397,7 @@ VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme )
             varStack.pop_back();
             if( varStack.empty() )
             {
-                msg_Err( getIntf(), "Invalid boolean expression: %s",
+                msg_Err( getIntf(), "invalid boolean expression: %s",
                          rName.c_str());
                 return NULL;
             }
@@ -320,7 +415,7 @@ VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme )
             // Get the last variable on the stack
             if( varStack.empty() )
             {
-                msg_Err( getIntf(), "Invalid boolean expression: %s",
+                msg_Err( getIntf(), "invalid boolean expression: %s",
                          rName.c_str());
                 return NULL;
             }
@@ -333,33 +428,74 @@ VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme )
             // Register this variable in the manager
             pVarManager->registerVar( VariablePtr( pNewVar ) );
         }
-        else if( token.find( ".isVisible" ) != string::npos )
+        else
         {
-            int leftPos = token.find( ".isVisible" );
-            string windowId = token.substr( 0, leftPos );
-            TopWindow *pWin = pTheme->getWindowById( windowId );
-            if( pWin )
+            // Try first to get the variable from the variable manager
+            // Indeed, if the skin designer is stupid enough to call a layout
+            // "dvd", we want "dvd.isActive" to resolve as the built-in action
+            // and not as the "layoutId.isActive" one.
+            VarBool *pVar = (VarBool*)pVarManager->getVar( token, "bool" );
+            if( pVar )
             {
-                // Push the visibility variable on the stack
-                varStack.push_back( &pWin->getVisibleVar() );
+                varStack.push_back( pVar );
             }
-            else
+            else if( token.find( ".isVisible" ) != string::npos )
             {
-                msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
-                return NULL;
+                int leftPos = token.find( ".isVisible" );
+                string windowId = token.substr( 0, leftPos );
+                TopWindow *pWin = pTheme->getWindowById( windowId );
+                if( pWin )
+                {
+                    // Push the visibility variable onto the stack
+                    varStack.push_back( &pWin->getVisibleVar() );
+                }
+                else
+                {
+                    msg_Err( getIntf(), "unknown window (%s)",
+                             windowId.c_str() );
+                    return NULL;
+                }
             }
-        }
-        else
-        {
-            // Try to get the variable from the variable manager
-            VarBool *pVar = (VarBool*)pVarManager->getVar( token, "bool" );
-            if( !pVar )
+            else if( token.find( ".isMaximized" ) != string::npos )
+            {
+                int leftPos = token.find( ".isMaximized" );
+                string windowId = token.substr( 0, leftPos );
+                TopWindow *pWin = pTheme->getWindowById( windowId );
+                if( pWin )
+                {
+                    // Push the "maximized" variable onto the stack
+                    varStack.push_back( &pWin->getMaximizedVar() );
+                }
+                else
+                {
+                    msg_Err( getIntf(), "unknown window (%s)",
+                             windowId.c_str() );
+                    return NULL;
+                }
+            }
+            else if( token.find( ".isActive" ) != string::npos )
             {
-                msg_Err( getIntf(), "Cannot resolve boolean variable: %s",
+                int leftPos = token.find( ".isActive" );
+                string layoutId = token.substr( 0, leftPos );
+                GenericLayout *pLayout = pTheme->getLayoutById( layoutId );
+                if( pLayout )
+                {
+                    // Push the isActive variable onto the stack
+                    varStack.push_back( &pLayout->getActiveVar() );
+                }
+                else
+                {
+                    msg_Err( getIntf(), "unknown layout (%s)",
+                             layoutId.c_str() );
+                    return NULL;
+                }
+            }
+            else
+            {
+                msg_Err( getIntf(), "cannot resolve boolean variable: %s",
                          token.c_str());
                 return NULL;
             }
-            varStack.push_back( pVar );
         }
         // Get the first token from the RPN stack
         token = evaluator.getToken();
@@ -368,7 +504,7 @@ VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme )
     // The stack should contain a single variable
     if( varStack.size() != 1 )
     {
-        msg_Err( getIntf(), "Invalid boolean expression: %s", rName.c_str() );
+        msg_Err( getIntf(), "invalid boolean expression: %s", rName.c_str() );
         return NULL;
     }
     return varStack.back();
@@ -392,6 +528,7 @@ VarList *Interpreter::getVarList( const string &rName, Theme *pTheme )
     return pVar;
 }
 
+
 VarTree *Interpreter::getVarTree( const string &rName, Theme *pTheme )
 {
     // Try to get the variable from the variable manager
@@ -399,3 +536,17 @@ VarTree *Interpreter::getVarTree( const string &rName, Theme *pTheme )
     VarTree *pVar = (VarTree*)pVarManager->getVar( rName, "tree" );
     return pVar;
 }
+
+
+string Interpreter::getConstant( const string &rValue )
+{
+    // Check if the value is a registered constant
+    string val = VarManager::instance( getIntf() )->getConst( rValue );
+    if( val.empty() )
+    {
+        // if not, keep the value as is
+        val = rValue;
+    }
+    return val;
+}
+