1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 #include "interpreter.hpp"
26 #include "../commands/cmd_playlist.hpp"
27 #include "../commands/cmd_dialogs.hpp"
28 #include "../commands/cmd_dummy.hpp"
29 #include "../commands/cmd_layout.hpp"
30 #include "../commands/cmd_quit.hpp"
31 #include "../commands/cmd_input.hpp"
32 #include "../commands/cmd_fullscreen.hpp"
33 #include "../commands/cmd_show_window.hpp"
34 #include "../src/theme.hpp"
35 #include "../src/var_manager.hpp"
36 #include "../src/vlcproc.hpp"
39 Interpreter::Interpreter( intf_thread_t *pIntf ): SkinObject( pIntf )
41 /// Create the generic commands
42 #define REGISTER_CMD( name, cmd ) \
43 m_commandMap[name] = CmdGenericPtr( new cmd( getIntf() ) );
45 REGISTER_CMD( "none", CmdDummy )
46 REGISTER_CMD( "dialogs.changeSkin()", CmdDlgChangeSkin )
47 REGISTER_CMD( "dialogs.fileSimple()", CmdDlgFileSimple )
48 REGISTER_CMD( "dialogs.file()", CmdDlgFile )
49 REGISTER_CMD( "dialogs.disc()", CmdDlgDisc )
50 REGISTER_CMD( "dialogs.net()", CmdDlgNet )
51 REGISTER_CMD( "dialogs.messages()", CmdDlgMessages )
52 REGISTER_CMD( "dialogs.prefs()", CmdDlgPrefs )
53 REGISTER_CMD( "dialogs.fileInfo()", CmdDlgFileInfo )
54 REGISTER_CMD( "dialogs.popup()", CmdDlgShowPopupMenu )
55 REGISTER_CMD( "playlist.add()", CmdDlgAdd )
56 VarList &rVar = VlcProc::instance( getIntf() )->getPlaylistVar();
57 m_commandMap["playlist.del()"] =
58 CmdGenericPtr( new CmdPlaylistDel( getIntf(), rVar ) );
59 REGISTER_CMD( "playlist.next()", CmdPlaylistNext )
60 REGISTER_CMD( "playlist.previous()", CmdPlaylistPrevious )
61 REGISTER_CMD( "playlist.sort()", CmdPlaylistSort )
62 m_commandMap["playlist.setRandom(true)"] =
63 CmdGenericPtr( new CmdPlaylistRandom( getIntf(), true ) );
64 m_commandMap["playlist.setRandom(false)"] =
65 CmdGenericPtr( new CmdPlaylistRandom( getIntf(), false ) );
66 m_commandMap["playlist.setLoop(true)"] =
67 CmdGenericPtr( new CmdPlaylistLoop( getIntf(), true ) );
68 m_commandMap["playlist.setLoop(false)"] =
69 CmdGenericPtr( new CmdPlaylistLoop( getIntf(), false ) );
70 REGISTER_CMD( "vlc.fullscreen()", CmdFullscreen )
71 REGISTER_CMD( "vlc.play()", CmdPlay )
72 REGISTER_CMD( "vlc.pause()", CmdPause )
73 REGISTER_CMD( "vlc.quit()", CmdQuit )
74 REGISTER_CMD( "vlc.faster()", CmdFaster )
75 REGISTER_CMD( "vlc.slower()", CmdSlower )
76 REGISTER_CMD( "vlc.stop()", CmdStop )
80 Interpreter *Interpreter::instance( intf_thread_t *pIntf )
82 if( ! pIntf->p_sys->p_interpreter )
84 Interpreter *pInterpreter;
85 pInterpreter = new Interpreter( pIntf );
88 pIntf->p_sys->p_interpreter = pInterpreter;
91 return pIntf->p_sys->p_interpreter;
95 void Interpreter::destroy( intf_thread_t *pIntf )
97 if( pIntf->p_sys->p_interpreter )
99 delete pIntf->p_sys->p_interpreter;
100 pIntf->p_sys->p_interpreter = NULL;
105 CmdGeneric *Interpreter::parseAction( const string &rAction, Theme *pTheme )
107 // Try to find the command in the global command map
108 if( m_commandMap.find( rAction ) != m_commandMap.end() )
110 return m_commandMap[rAction].get();
113 CmdGeneric *pCommand = NULL;
115 if( rAction.find( ".setLayout(" ) != string::npos )
117 int leftPos = rAction.find( ".setLayout(" );
118 string windowId = rAction.substr( 0, leftPos );
119 // 11 is the size of ".setLayout("
120 int rightPos = rAction.find( ")", windowId.size() + 11 );
121 string layoutId = rAction.substr( windowId.size() + 11,
122 rightPos - (windowId.size() + 11) );
123 pCommand = new CmdLayout( getIntf(), windowId, layoutId );
125 else if( rAction.find( ".show()" ) != string::npos )
127 int leftPos = rAction.find( ".show()" );
128 string windowId = rAction.substr( 0, leftPos );
129 TopWindow *pWin = pTheme->getWindowById( windowId );
132 pCommand = new CmdShowWindow( getIntf(), pTheme->getWindowManager(),
137 msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
140 else if( rAction.find( ".hide()" ) != string::npos )
142 int leftPos = rAction.find( ".hide()" );
143 string windowId = rAction.substr( 0, leftPos );
144 TopWindow *pWin = pTheme->getWindowById( windowId );
147 pCommand = new CmdHideWindow( getIntf(), pTheme->getWindowManager(),
152 msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
158 // Add the command in the pool
159 pTheme->m_commands.push_back( CmdGenericPtr( pCommand ) );
166 VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme )
168 // Try to get the variable from the variable manager
169 VarManager *pVarManager = VarManager::instance( getIntf() );
170 VarBool *pVar = (VarBool*)pVarManager->getVar( rName, "bool" );
176 else if( rName.find( " and " ) != string::npos )
178 int leftPos = rName.find( " and " );
179 string name1 = rName.substr( 0, leftPos );
180 int rightPos = leftPos + 5; // 5 is the size of " and "
181 string name2 = rName.substr( rightPos, rName.size() - rightPos );
182 // Retrive the two boolean variables
183 VarBool *pVar1 = getVarBool( name1, pTheme );
184 VarBool *pVar2 = getVarBool( name2, pTheme );
185 // Create a composite boolean variable
188 VarBool *pNewVar = new VarBoolAndBool( getIntf(), *pVar1, *pVar2 );
189 // Register this variable in the manager
190 pVarManager->registerVar( VariablePtr( pNewVar ), rName );
198 else if( rName.find( "not " ) != string::npos )
200 int rightPos = rName.find( "not " ) + 4;
201 string name = rName.substr( rightPos, rName.size() - rightPos );
202 // Retrive the boolean variable
203 VarBool *pVar = getVarBool( name, pTheme );
204 // Create a composite boolean variable
207 VarBool *pNewVar = new VarNotBool( getIntf(), *pVar );
208 // Register this variable in the manager
209 pVarManager->registerVar( VariablePtr( pNewVar ), rName );
217 else if( rName.find( ".isVisible" ) != string::npos )
219 int leftPos = rName.find( ".isVisible" );
220 string windowId = rName.substr( 0, leftPos );
221 TopWindow *pWin = pTheme->getWindowById( windowId );
224 return &pWin->getVisibleVar();
228 msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
239 VarPercent *Interpreter::getVarPercent( const string &rName, Theme *pTheme )
241 // Try to get the variable from the variable manager
242 VarManager *pVarManager = VarManager::instance( getIntf() );
243 VarPercent *pVar = (VarPercent*)pVarManager->getVar( rName, "percent" );
248 VarList *Interpreter::getVarList( const string &rName, Theme *pTheme )
250 // Try to get the variable from the variable manager
251 VarManager *pVarManager = VarManager::instance( getIntf() );
252 VarList *pVar = (VarList*)pVarManager->getVar( rName, "list" );