Exemplo n.º 1
0
void KviKvsEventManager::removeAllModuleAppHandlers(KviKvsModuleInterface *pIface)
{
	KviKvsEventHandler * h;
	for(unsigned int i =0;i< KVI_KVS_NUM_APP_EVENTS;i++)
	{
		if(!m_appEventTable[i].handlers())continue;

		KviPointerList<KviKvsEventHandler> l;
		l.setAutoDelete(false);
		for(h = m_appEventTable[i].handlers()->first();h;h = m_appEventTable[i].handlers()->next())
		{
			if(h->type() == KviKvsEventHandler::Module)
			{
				if(((KviKvsModuleEventHandler *)h)->moduleInterface() == pIface)
				{
					l.append(h);
				}
			}
			// COMPAT
			/*
			} else if(h->type() == KviKvsEventHandler::OldModule)
			{
				if(((KviKvsOldModuleEventHandler *)h)->module() == pIface)
				{
					l.append(h);
				}
			}
			*/
			// END COMPAT

		}
		for(h = l.first();h;h = l.next())m_appEventTable[i].removeHandler(h);
	}
}
Exemplo n.º 2
0
void RawEditorWidget::oneTimeSetup()
{
	if(m_bOneTimeSetupDone)return;
	m_bOneTimeSetupDone = true;

	RawTreeWidgetItem * it;

	for(unsigned int i = 0;i < 999;i++)
	{
		KviPointerList<KviKvsEventHandler> * l = KviKvsEventManager::instance()->rawHandlers(i);
		if(l)
		{
			it = new RawTreeWidgetItem(m_pTreeWidget,i,true);
			for(KviKvsEventHandler * s = l->first();s;s = l->next())
			{
				if(s->type() == KviKvsEventHandler::Script)
				{
					new RawHandlerTreeWidgetItem(it,((KviKvsScriptEventHandler *)s)->name(),
					((KviKvsScriptEventHandler *)s)->code(),((KviKvsScriptEventHandler *)s)->isEnabled());
				}
			}
			it->setExpanded(true);
		}
	}
}
Exemplo n.º 3
0
bool KviKvsEventManager::removeModuleAppHandler(unsigned int uEvIdx,KviKvsModuleInterface *i)
{
	if(uEvIdx >= KVI_KVS_NUM_APP_EVENTS)return false;
	KviKvsEventHandler * h;
	if(!(m_appEventTable[uEvIdx].handlers()))return false;
	for(h = m_appEventTable[uEvIdx].handlers()->first();h;h = m_appEventTable[uEvIdx].handlers()->next())
	{
		if(h->type() == KviKvsEventHandler::Module)
		{
			if(((KviKvsModuleEventHandler *)h)->moduleInterface() == i)
			{
				m_appEventTable[uEvIdx].removeHandler(h);
				return true;
			}
		}
		// COMPAT
		/*
		} else if(h->type() == KviKvsEventHandler::OldModule)
		{
			if(((KviKvsOldModuleEventHandler *)h)->module() == i)
			{
				m_appEventTable[uEvIdx].removeHandler(h);
				return true;
			}
		}
		*/
		// END COMPAT
	}
	return false;
}
Exemplo n.º 4
0
void KviKvsEventManager::saveRawEvents(const QString & szFileName)
{
	KviConfigurationFile cfg(szFileName,KviConfigurationFile::Write);
	cfg.clear();
	int i;

	for(i=0; i < KVI_KVS_NUM_RAW_EVENTS; i++)
	{
		if(m_rawEventTable[i])
		{
			QString szTmp = QString("RAW%1").arg(i);
			cfg.setGroup(szTmp);

			int iIdx = 0;
			for(KviKvsEventHandler * pEvent = m_rawEventTable[i]->first(); pEvent; pEvent = m_rawEventTable[i]->next())
			{
				if(pEvent->type() == KviKvsEventHandler::Script)
				{
					szTmp = QString("Name%1").arg(iIdx);
					cfg.writeEntry(szTmp,((KviKvsScriptEventHandler *)pEvent)->name());
					szTmp = QString("Buffer%1").arg(iIdx);
					cfg.writeEntry(szTmp,((KviKvsScriptEventHandler *)pEvent)->code());
					szTmp = QString("Enabled%1").arg(iIdx);
					cfg.writeEntry(szTmp,((KviKvsScriptEventHandler *)pEvent)->isEnabled());
					iIdx++;
				}
			}
			cfg.writeEntry("NHandlers",iIdx);
		}
	}

}
Exemplo n.º 5
0
void KviKvsEventManager::removeAllScriptRawHandlers()
{
	for(auto & i : m_rawEventTable)
	{
		if(i)
		{
			KviPointerList<KviKvsEventHandler> dl;
			dl.setAutoDelete(false);
			KviKvsEventHandler * e;
			for(e = i->first(); e; e = i->next())
			{
				if(e->type() == KviKvsEventHandler::Script)
					dl.append(e);
			}

			for(e = dl.first(); e; e = dl.next())
			{
				i->removeRef(e);
			}

			if(i->isEmpty())
			{
				delete i;
				i = nullptr;
			}
		}
	}
}
Exemplo n.º 6
0
bool KviKvsEventManager::removeModuleRawHandler(unsigned int uRawIdx, KviKvsModuleInterface * i)
{
	if(uRawIdx >= KVI_KVS_NUM_RAW_EVENTS)
		return false;
	if(!m_rawEventTable[uRawIdx])
		return false;
	KviKvsEventHandler * h;
	for(h = m_rawEventTable[uRawIdx]->first(); h; h = m_rawEventTable[uRawIdx]->next())
	{
		if(h->type() == KviKvsEventHandler::Module)
		{
			if(((KviKvsModuleEventHandler *)h)->moduleInterface() == i)
			{
				m_rawEventTable[uRawIdx]->removeRef(h);
				if(m_rawEventTable[uRawIdx]->isEmpty())
				{
					delete m_rawEventTable[uRawIdx];
					m_rawEventTable[uRawIdx] = nullptr;
				}
				return true;
			}
		}
	}
	return false;
}
Exemplo n.º 7
0
bool KviKvsEventManager::removeScriptRawHandler(unsigned int uEvIdx, const QString & szName)
{
	if(uEvIdx >= KVI_KVS_NUM_RAW_EVENTS)
		return false;
	if(!m_rawEventTable[uEvIdx])
		return false;
	KviKvsEventHandler * h;
	for(h = m_rawEventTable[uEvIdx]->first(); h; h = m_rawEventTable[uEvIdx]->next())
	{
		if(h->type() == KviKvsEventHandler::Script)
		{
			if(KviQString::equalCI(((KviKvsScriptEventHandler *)h)->name(), szName))
			{
				m_rawEventTable[uEvIdx]->removeRef(h);
				if(m_rawEventTable[uEvIdx]->isEmpty())
				{
					delete m_rawEventTable[uEvIdx];
					m_rawEventTable[uEvIdx] = nullptr;
				}
				return true;
			}
		}
	}
	return false;
}
Exemplo n.º 8
0
void KviKvsEventManager::removeAllModuleRawHandlers(KviKvsModuleInterface * pIface)
{
	KviKvsEventHandler * h;
	for(auto & i : m_rawEventTable)
	{
		if(!i)
			continue;

		KviPointerList<KviKvsEventHandler> l;
		l.setAutoDelete(false);
		for(h = i->first(); h; h = i->next())
		{
			if(h->type() == KviKvsEventHandler::Module)
			{
				if(((KviKvsModuleEventHandler *)h)->moduleInterface() == pIface)
				{
					l.append(h);
				}
			}
		}
		for(h = l.first(); h; h = l.next())
			i->removeRef(h);
		if(i->isEmpty())
		{
			delete i;
			i = nullptr;
		}
	}
}
Exemplo n.º 9
0
void KviKvsEventManager::removeAllScriptRawHandlers()
{
	for(int i=0;i< KVI_KVS_NUM_RAW_EVENTS;i++)
	{
		if(m_rawEventTable[i])
		{
			KviPointerList<KviKvsEventHandler> dl;
			dl.setAutoDelete(false);
			KviKvsEventHandler * e;
			for(e = m_rawEventTable[i]->first();e;e = m_rawEventTable[i]->next())
			{
				if(e->type() == KviKvsEventHandler::Script)dl.append(e);
			}

			for(e = dl.first();e;e = dl.next())
			{
				m_rawEventTable[i]->removeRef(e);
			}

			if(m_rawEventTable[i]->isEmpty())
			{
				delete m_rawEventTable[i];
				m_rawEventTable[i] = 0;
			}
		}
	}
}
Exemplo n.º 10
0
void EventEditor::oneTimeSetup()
{
	if(m_bOneTimeSetupDone)return;
	m_bOneTimeSetupDone = true;

	EventEditorEventTreeWidgetItem * it;

	for(unsigned int i = 0;i < KVI_KVS_NUM_APP_EVENTS;i++)
	{
		KviKvsEvent * e = KviKvsEventManager::instance()->appEvent(i);

		it = new EventEditorEventTreeWidgetItem(m_pTreeWidget,i,e->name(),e->parameterDescription());
		if(KviPointerList<KviKvsEventHandler> * l = e->handlers())
		{
			for(KviKvsEventHandler * s = l->first();s;s = l->next())
			{
				if(s->type() == KviKvsEventHandler::Script)
				{
					new EventEditorHandlerTreeWidgetItem(it,((KviKvsScriptEventHandler *)s)->name(),
					((KviKvsScriptEventHandler *)s)->code(),((KviKvsScriptEventHandler *)s)->isEnabled());
				}
			}
		}
		it->setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(it->childCount() ? KviIconManager::Event : KviIconManager::EventNoHandlers))));
	}

	connect(m_pTreeWidget,SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),this,SLOT(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)));
	connect(m_pTreeWidget,SIGNAL(rightButtonPressed(QTreeWidgetItem *,QPoint)),
		this,SLOT(itemPressed(QTreeWidgetItem *,QPoint)));
        connect(KviKvsEventManager::instance(),SIGNAL(eventHandlerDisabled(const QString &)),this,SLOT(eventHandlerDisabled(const QString &)));
	m_pContextPopup = new QMenu(this);
	m_pTreeWidget->sortItems(0,Qt::AscendingOrder);
}
Exemplo n.º 11
0
bool KviKvsEventManager::triggerHandlers(KviPointerList<KviKvsEventHandler> * pHandlers, KviWindow * pWnd, KviKvsVariantList * pParams)
{
	if(!pHandlers)
		return false;

	bool bGotHalt = false;
	for(KviKvsEventHandler * h = pHandlers->first(); h; h = pHandlers->next())
	{
		switch(h->type())
		{
			case KviKvsEventHandler::Script:
			{
				if(((KviKvsScriptEventHandler *)h)->isEnabled())
				{
					KviKvsScript * s = ((KviKvsScriptEventHandler *)h)->script();
					KviKvsScript copy(*s);
					KviKvsVariant retVal;
					int iRet = copy.run(pWnd, pParams, &retVal, KviKvsScript::PreserveParams);
					if(!iRet)
					{
						// error! disable the handler if it's broken
						if(KVI_OPTION_BOOL(KviOption_boolDisableBrokenEventHandlers))
						{
							((KviKvsScriptEventHandler *)h)->setEnabled(false);
							pWnd->output(KVI_OUT_PARSERERROR, __tr2qs_ctx("Event handler %Q is broken: disabling", "kvs"), &(s->name()));
							emit eventHandlerDisabled(s->name());
						}
					}
					if(!bGotHalt)
						bGotHalt = (iRet & KviKvsScript::HaltEncountered);
				}
			}
			break;
			case KviKvsEventHandler::Module:
			{
				KviModule * m = (KviModule *)((KviKvsModuleEventHandler *)h)->moduleInterface();
				KviKvsModuleEventHandlerRoutine * proc = ((KviKvsModuleEventHandler *)h)->handlerRoutine();
				KviKvsVariant retVal;
				KviKvsRunTimeContext ctx(nullptr, pWnd, pParams, &retVal);
				KviKvsModuleEventCall call(m, &ctx, pParams);
				if(!(*proc)(&call))
					bGotHalt = true;
			}
			break;
		}
	}
	return bGotHalt;
}
Exemplo n.º 12
0
KviKvsScriptEventHandler * KviKvsEventManager::findScriptAppHandler(unsigned int uEvIdx,const QString &szName)
{
	if(uEvIdx >= KVI_KVS_NUM_APP_EVENTS)return 0;
	KviKvsEventHandler * h;
	if(!(m_appEventTable[uEvIdx].handlers()))return 0;
	for(h = m_appEventTable[uEvIdx].handlers()->first();h;h = m_appEventTable[uEvIdx].handlers()->next())
	{
		if(h->type() == KviKvsEventHandler::Script)
		{
			if(KviQString::equalCI(((KviKvsScriptEventHandler *)h)->name(),szName))
			{
				return (KviKvsScriptEventHandler *)h;
			}
		}
	}
	return 0;
}
Exemplo n.º 13
0
KviKvsScriptEventHandler * KviKvsEventManager::findScriptRawHandler(unsigned int uEvIdx, const QString & szName)
{
	if(uEvIdx >= KVI_KVS_NUM_RAW_EVENTS)
		return nullptr;
	if(!m_rawEventTable[uEvIdx])
		return nullptr;
	KviKvsEventHandler * h;
	for(h = m_rawEventTable[uEvIdx]->first(); h; h = m_rawEventTable[uEvIdx]->next())
	{
		if(h->type() == KviKvsEventHandler::Script)
		{
			if(KviQString::equalCI(((KviKvsScriptEventHandler *)h)->name(), szName))
			{
				return (KviKvsScriptEventHandler *)h;
			}
		}
	}
	return nullptr;
}
Exemplo n.º 14
0
void KviKvsEvent::clearScriptHandlers()
{
    if(!m_pHandlers)return;
    KviPointerList<KviKvsEventHandler> dl;
    dl.setAutoDelete(false);
    KviKvsEventHandler * e;
    for(e = m_pHandlers->first(); e; e = m_pHandlers->next())
    {
        if(e->type() == KviKvsEventHandler::Script)dl.append(e);
    }
    for(e = dl.first(); e; e = dl.next())
    {
        m_pHandlers->removeRef(e);
    }
    if(m_pHandlers->isEmpty())
    {
        delete m_pHandlers;
        m_pHandlers = 0;
    }
}
Exemplo n.º 15
0
void KviKvsEventManager::saveAppEvents(const QString & szFileName)
{
	KviConfigurationFile cfg(szFileName,KviConfigurationFile::Write);
	cfg.clear();
	int i;
	bool bCompat = false;

	for(i=0; i < KVI_KVS_NUM_APP_EVENTS; i++)
	{
		if(m_appEventTable[i].hasHandlers())
		{
			QString szEventName(m_appEventTable[i].name());
			// Backwards compatibility >_<
			if((i == 4) && cfg.hasGroup(szEventName))
			{
				szEventName = "OnIRCConnectionEstabilished";
				bCompat = true;
			}
			cfg.setGroup(szEventName);
			int iIdx = 0;
			for(KviKvsEventHandler * pEvent = m_appEventTable[i].handlers()->first(); pEvent; pEvent = m_appEventTable[i].handlers()->next())
			{
				if(pEvent->type() == KviKvsEventHandler::Script)
				{
					QString szTmp = QString("Name%1").arg(iIdx);
					cfg.writeEntry(szTmp,((KviKvsScriptEventHandler *)pEvent)->name());
					szTmp = QString("Buffer%1").arg(iIdx);
					cfg.writeEntry(szTmp,((KviKvsScriptEventHandler *)pEvent)->code());
					szTmp = QString("Enabled%1").arg(iIdx);
					cfg.writeEntry(szTmp,((KviKvsScriptEventHandler *)pEvent)->isEnabled());
					iIdx++;
				}
			}
			cfg.writeEntry("NHandlers",iIdx);

			// Backwards compatibility >_<
			if((i == 4) && !bCompat)
				i--;
		}
	}
}
Exemplo n.º 16
0
void KviKvsEventManager::removeAllModuleRawHandlers(KviKvsModuleInterface *pIface)
{
	KviKvsEventHandler * h;
	for(unsigned int i =0;i< KVI_KVS_NUM_RAW_EVENTS;i++)
	{
		if(!m_rawEventTable[i])continue;

		KviPointerList<KviKvsEventHandler> l;
		l.setAutoDelete(false);
		for(h = m_rawEventTable[i]->first();h;h = m_rawEventTable[i]->next())
		{
			if(h->type() == KviKvsEventHandler::Module)
			{
				if(((KviKvsModuleEventHandler *)h)->moduleInterface() == pIface)
				{
					l.append(h);
				}
			}
			// COMPAT
			/*
			} else if(h->type() == KviKvsEventHandler::OldModule)
			{
				if(((KviKvsOldModuleEventHandler *)h)->module() == pIface)
				{
					l.append(h);
				}
			}
			*/
			// END COMPAT

		}
		for(h = l.first();h;h = l.next())m_rawEventTable[i]->removeRef(h);
		if(m_rawEventTable[i]->isEmpty())
		{
			delete m_rawEventTable[i];
			m_rawEventTable[i] = 0;
		}
	}
}
Exemplo n.º 17
0
void KviKvsEventManager::removeAllModuleAppHandlers(KviKvsModuleInterface * pIface)
{
	KviKvsEventHandler * h;
	for(auto & i : m_appEventTable)
	{
		if(!i.handlers())
			continue;

		KviPointerList<KviKvsEventHandler> l;
		l.setAutoDelete(false);
		for(h = i.handlers()->first(); h; h = i.handlers()->next())
		{
			if(h->type() == KviKvsEventHandler::Module)
			{
				if(((KviKvsModuleEventHandler *)h)->moduleInterface() == pIface)
				{
					l.append(h);
				}
			}
		}
		for(h = l.first(); h; h = l.next())
			i.removeHandler(h);
	}
}