1
//=============================================================================
3
// File : KviKvsTreeNodeModuleSimpleCommand.cpp
4
// Creation date : Thu 09 Oct 2003 02:18:27 by Szymon Stefanek
6
// This file is part of the KVIrc IRC client distribution
7
// Copyright (C) 2003-2010 Szymon Stefanek <pragma at kvirc dot net>
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) any later version.
14
// This program is distributed in the HOPE that it will be USEFUL,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program. If not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//=============================================================================
25
#include "KviKvsTreeNodeModuleSimpleCommand.h"
26
#include "KviKvsTreeNodeDataList.h"
27
#include "KviKvsTreeNodeSwitchList.h"
29
#include "KviModuleManager.h"
30
#include "KviLocale.h"
31
#include "KviKvsModuleInterface.h"
32
#include "KviKvsRunTimeContext.h"
34
KviKvsTreeNodeModuleSimpleCommand::KviKvsTreeNodeModuleSimpleCommand(const QChar * pLocation,const QString &szModuleName,const QString &szCmdName,KviKvsTreeNodeDataList * params)
35
: KviKvsTreeNodeSimpleCommand(pLocation,szCmdName,params)
37
m_szModuleName = szModuleName;
41
KviKvsTreeNodeModuleSimpleCommand::~KviKvsTreeNodeModuleSimpleCommand()
45
void KviKvsTreeNodeModuleSimpleCommand::contextDescription(QString &szBuffer)
47
szBuffer = "Module Callback Command \"";
48
szBuffer += m_szModuleName;
50
szBuffer += m_szCmdName;
54
void KviKvsTreeNodeModuleSimpleCommand::dump(const char * prefix)
56
qDebug("%s ModuleSimpleCommand(%s.%s)",prefix,m_szModuleName.toUtf8().data(),m_szCmdName.toUtf8().data());
57
dumpSwitchList(prefix);
58
dumpParameterList(prefix);
61
bool KviKvsTreeNodeModuleSimpleCommand::execute(KviKvsRunTimeContext * c)
63
KviModule * m = g_pModuleManager->getModule(m_szModuleName);
66
QString szErr = g_pModuleManager->lastError();
67
c->error(this,__tr2qs_ctx("Module command call failed: can't load the module '%Q': %Q","kvs"),&m_szModuleName,&szErr);
71
KviKvsModuleSimpleCommandExecRoutine * proc = m->kvsFindSimpleCommand(m_szCmdName);
74
c->error(this,__tr2qs_ctx("Module command call failed: the module '%Q' doesn't export a command named '%Q'","kvs"),&m_szModuleName,&m_szCmdName);
79
l.setAutoDelete(true);
81
if(!(m_pParams->evaluate(c,&l)))return false;
85
if(!(m_pSwitches->evaluate(c,&swl)))return false;
88
c->setDefaultReportLocation(this);
90
KviKvsModuleCommandCall call(m,c,&l,&swl);
92
return (*proc)(&call);