1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: interpreter.cpp,v 1.5 2004/02/01 14:44:11 asmax Exp $
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 REGISTER_CMD( "vlc.fullscreen()", CmdFullscreen )
63 REGISTER_CMD( "vlc.play()", CmdPlay )
64 REGISTER_CMD( "vlc.pause()", CmdPause )
65 REGISTER_CMD( "vlc.quit()", CmdQuit )
66 REGISTER_CMD( "vlc.faster()", CmdFaster )
67 REGISTER_CMD( "vlc.slower()", CmdSlower )
68 REGISTER_CMD( "vlc.stop()", CmdStop )
72 Interpreter *Interpreter::instance( intf_thread_t *pIntf )
74 if( ! pIntf->p_sys->p_interpreter )
76 Interpreter *pInterpreter;
77 pInterpreter = new Interpreter( pIntf );
80 pIntf->p_sys->p_interpreter = pInterpreter;
83 return pIntf->p_sys->p_interpreter;
87 void Interpreter::destroy( intf_thread_t *pIntf )
89 if( pIntf->p_sys->p_interpreter )
91 delete pIntf->p_sys->p_interpreter;
92 pIntf->p_sys->p_interpreter = NULL;
97 CmdGeneric *Interpreter::parseAction( const string &rAction, Theme *pTheme )
99 // Try to find the command in the global command map
100 if( m_commandMap.find( rAction ) != m_commandMap.end() )
102 return m_commandMap[rAction].get();
105 CmdGeneric *pCommand = NULL;
107 if( rAction.find( ".setLayout(" ) != string::npos )
109 int leftPos = rAction.find( ".setLayout(" );
110 string windowId = rAction.substr( 0, leftPos );
111 // 11 is the size of ".setLayout("
112 int rightPos = rAction.find( ")", windowId.size() + 11 );
113 string layoutId = rAction.substr( windowId.size() + 11,
114 rightPos - (windowId.size() + 11) );
115 pCommand = new CmdLayout( getIntf(), windowId, layoutId );
117 else if( rAction.find( ".show()" ) != string::npos )
119 int leftPos = rAction.find( ".show()" );
120 string windowId = rAction.substr( 0, leftPos );
121 GenericWindow *pWin = pTheme->getWindowById( windowId );
124 pCommand = new CmdShowWindow( getIntf(), *pWin );
128 msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
131 else if( rAction.find( ".hide()" ) != string::npos )
133 int leftPos = rAction.find( ".hide()" );
134 string windowId = rAction.substr( 0, leftPos );
135 GenericWindow *pWin = pTheme->getWindowById( windowId );
138 pCommand = new CmdHideWindow( getIntf(), *pWin );
142 msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
148 // Add the command in the pool
149 pTheme->m_commands.push_back( CmdGenericPtr( pCommand ) );
156 VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme )
158 // Try to get the variable from the variable manager
159 VarManager *pVarManager = VarManager::instance( getIntf() );
160 VarBool *pVar = (VarBool*)pVarManager->getVar( rName, "bool" );
166 else if( rName.find( " and " ) != string::npos )
168 int leftPos = rName.find( " and " );
169 string name1 = rName.substr( 0, leftPos );
170 int rightPos = leftPos + 5; // 5 is the size of " and "
171 string name2 = rName.substr( rightPos, rName.size() - rightPos );
172 // Retrive the two boolean variables
173 VarBool *pVar1 = getVarBool( name1, pTheme );
174 VarBool *pVar2 = getVarBool( name2, pTheme );
175 // Create a composite boolean variable
178 VarBool *pNewVar = new VarBoolAndBool( getIntf(), *pVar1, *pVar2 );
179 // Register this variable in the manager
180 pVarManager->registerVar( VariablePtr( pNewVar ), rName );
188 else if( rName.find( "not " ) != string::npos )
190 int rightPos = rName.find( "not " ) + 4;
191 string name = rName.substr( rightPos, rName.size() - rightPos );
192 // Retrive the boolean variable
193 VarBool *pVar = getVarBool( name, pTheme );
194 // Create a composite boolean variable
197 VarBool *pNewVar = new VarNotBool( getIntf(), *pVar );
198 // Register this variable in the manager
199 pVarManager->registerVar( VariablePtr( pNewVar ), rName );
207 else if( rName.find( ".isVisible" ) != string::npos )
209 int leftPos = rName.find( ".isVisible" );
210 string windowId = rName.substr( 0, leftPos );
211 GenericWindow *pWin = pTheme->getWindowById( windowId );
214 return &pWin->getVisibleVar();
218 msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
229 VarPercent *Interpreter::getVarPercent( const string &rName, Theme *pTheme )
231 // Try to get the variable from the variable manager
232 VarManager *pVarManager = VarManager::instance( getIntf() );
233 VarPercent *pVar = (VarPercent*)pVarManager->getVar( rName, "percent" );
238 VarList *Interpreter::getVarList( const string &rName, Theme *pTheme )
240 // Try to get the variable from the variable manager
241 VarManager *pVarManager = VarManager::instance( getIntf() );
242 VarList *pVar = (VarList*)pVarManager->getVar( rName, "list" );