1
//=============================================================================
3
// File : KviKvsRunTimeContext.cpp
4
// Creation date : Tue 07 Oct 2003 01:49:40 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 "KviKvsRunTimeContext.h"
26
#include "KviKvsScript.h"
27
#include "KviKvsKernel.h"
28
#include "KviKvsReport.h"
29
#include "KviConsoleWindow.h"
30
#include "KviKvsTreeNodeBase.h"
31
#include "KviLocale.h"
32
#include "KviApplication.h"
33
#include "KviKvsObject.h"
35
KviKvsExtendedRunTimeData::~KviKvsExtendedRunTimeData()
39
if(m_pExtendedScopeVariables) delete m_pExtendedScopeVariables;
40
if(m_pAliasSwitchList) delete m_pAliasSwitchList;
41
if(m_pThisObject) delete m_pThisObject;
42
if(m_pScriptFilePath) delete m_pScriptFilePath;
43
// don't delete m_pPopupId;
47
void KviKvsExtendedRunTimeData::setPopupId(QString * pPopupId)
54
KviKvsRunTimeContext::KviKvsRunTimeContext(KviKvsScript * pScript,KviWindow * pWnd,KviKvsVariantList * pParams,KviKvsVariant * pRetVal,KviKvsExtendedRunTimeData * pExtData)
58
m_pParameterList = pParams;
60
m_pLocalVariables = new KviKvsHash();
61
m_pReturnValue = pRetVal;
63
m_pExtendedData = pExtData;
64
m_pDefaultReportLocation = 0;
67
KviKvsRunTimeContext::~KviKvsRunTimeContext()
69
delete m_pLocalVariables;
72
KviKvsHash * KviKvsRunTimeContext::globalVariables()
74
return KviKvsKernel::instance()->globalVariables();
77
void KviKvsRunTimeContext::enterBlockingSection()
82
bool KviKvsRunTimeContext::leaveBlockingSection()
84
if(g_pApp->kviClosingDown())return false; // application quitting
85
if(!g_pApp->windowExists(m_pWindow))return false; // window lost
89
KviKvsVariant * KviKvsRunTimeContext::swapReturnValuePointer(KviKvsVariant * pNewPointer)
91
KviKvsVariant * pAux = m_pReturnValue;
92
m_pReturnValue = pNewPointer;
96
void KviKvsRunTimeContext::report(bool bError,KviKvsTreeNode * pNode,const QString &szMsgFmt,kvi_va_list va)
99
KviQString::vsprintf(szMsg,szMsgFmt,va);
101
KviPointerList<QString> * pCodeListing = 0;
102
KviPointerList<QString> * pCallStack = 0;
107
if(pNode->location() && m_pScript)
109
pCodeListing = new KviPointerList<QString>;
110
pCodeListing->setAutoDelete(true);
114
KviKvsReport::findLineColAndListing(m_pScript->buffer(),pNode->location(),iLine,iCol,pCodeListing);
116
szLocation = QString(__tr2qs_ctx("line %1, near character %2","kvs")).arg(iLine).arg(iCol);
119
// create the call stack
122
pCallStack = new KviPointerList<QString>;
123
pCallStack->setAutoDelete(true);
125
while(pNode && (iFrame < 12))
127
QString * pString = new QString();
129
pNode->contextDescription(szTmp);
130
*pString = QString("#%1 %2").arg(iFrame).arg(szTmp);
131
if(pNode->location())
134
KviKvsReport::findLineAndCol(m_pScript->buffer(),pNode->location(),iLine,iCol);
135
QString tmpi = QString(" [line %1, near character %2]").arg(iLine).arg(iCol);
138
pCallStack->append(pString);
140
pNode = pNode->parent();
143
pCallStack->append(new QString("#12 ..."));
146
QString szContext = m_pScript ? m_pScript->name() : "kvirc core code";
147
KviKvsReport rep(bError ? KviKvsReport::RunTimeError : KviKvsReport::RunTimeWarning,szContext,szMsg,szLocation,m_pWindow);
149
rep.setCodeListing(pCodeListing);
151
rep.setCallStack(pCallStack);
153
KviKvsReport::report(&rep,m_pWindow);
156
void KviKvsRunTimeContext::error(KviKvsTreeNode * pNode,const QString &szMsgFmt,...)
161
kvi_va_start_by_reference(va,szMsgFmt);
162
report(true,pNode,szMsgFmt,va);
166
void KviKvsRunTimeContext::warning(KviKvsTreeNode * pNode,const QString &szMsgFmt,...)
169
kvi_va_start_by_reference(va,szMsgFmt);
170
report(false,pNode,szMsgFmt,va);
174
void KviKvsRunTimeContext::error(const QString &szMsgFmt,...)
179
kvi_va_start_by_reference(va,szMsgFmt);
180
report(true,m_pDefaultReportLocation,szMsgFmt,va);
184
void KviKvsRunTimeContext::warning(const QString &szMsgFmt,...)
187
kvi_va_start_by_reference(va,szMsgFmt);
188
report(false,m_pDefaultReportLocation,szMsgFmt,va);
192
bool KviKvsRunTimeContext::errorNoIrcContext()
194
error(m_pDefaultReportLocation,__tr2qs_ctx("This command can be used only in windows bound to an IRC context","kvs"));
198
bool KviKvsRunTimeContext::warningNoIrcConnection()
200
warning(m_pDefaultReportLocation,__tr2qs_ctx("You're not connected to an IRC server","kvs"));
204
bool KviKvsRunTimeContext::warningMissingParameter()
206
warning(m_pDefaultReportLocation,__tr2qs_ctx("Missing parameter","kvs"));
210
void KviKvsRunTimeContext::setDefaultReportLocation(KviKvsTreeNode * pNode)
212
m_pDefaultReportLocation = pNode;