void KviKvsAsyncDnsOperation::lookupTerminated(KviDnsResolver *) { KviWindow * pWnd = window(); if(!g_pApp->windowExists(pWnd)) pWnd = g_pActiveWindow; if(m_pCallback) { KviKvsVariantList params; params.setAutoDelete(true); if(m_pDns->state() == KviDnsResolver::Failure) { params.append(new KviKvsVariant(m_szQuery)); params.append(new KviKvsVariant((kvs_int_t)0)); params.append(new KviKvsVariant(m_pDns->errorString())); params.append(new KviKvsVariant()); params.append(new KviKvsVariant(*m_pMagic)); } else { QString szHostName = m_pDns->hostName(); const auto & strL = m_pDns->ipAddressList(); const QString & fi = strL.empty() ? QString("?.?.?.?") : strL.front(); params.append(new KviKvsVariant(m_szQuery)); params.append(new KviKvsVariant((kvs_int_t)1)); params.append(new KviKvsVariant(fi)); params.append(new KviKvsVariant(szHostName.isEmpty() ? QString("?.?") : szHostName)); params.append(new KviKvsVariant(*m_pMagic)); } m_pCallback->run(pWnd, ¶ms, nullptr, KviKvsScript::PreserveParams); delete this; return; } // we have no callback : output the results QString szQuery = m_pDns->query(); pWnd->output(KVI_OUT_HOSTLOOKUP, __tr2qs_ctx("DNS lookup result for query \"%Q\"", "kvs"), &szQuery); if(m_pDns->state() == KviDnsResolver::Failure) { QString strDescription(m_pDns->errorString()); pWnd->output(KVI_OUT_HOSTLOOKUP, __tr2qs_ctx("Error: %Q", "kvs"), &strDescription); } else { QString szHostName = m_pDns->hostName(); pWnd->output(KVI_OUT_HOSTLOOKUP, __tr2qs_ctx("Hostname: %Q", "kvs"), &szHostName); int idx = 1; for(const auto & a : m_pDns->ipAddressList()) { pWnd->output(KVI_OUT_HOSTLOOKUP, __tr2qs_ctx("IP address %d: %Q", "kvs"), idx, &a); idx++; } } delete this; }
void HttpFileTransfer::transferTerminated(bool bSuccess) { KviWindow * out = transferWindow(); m_tTransferEndTime = kvi_unixTime(); KviKvsVariantList vParams; vParams.append(bSuccess); vParams.append(new KviKvsVariant(m_pHttpRequest->url().url(), true)); vParams.append(new KviKvsVariant(m_pHttpRequest->fileName(), true)); vParams.append(new KviKvsVariant(m_vMagicIdentifier)); if(m_szCompletionCallback.isNull()) { KVS_TRIGGER_EVENT(KviEvent_OnHTTPGetTerminated,out ? out : (KviWindow *)(g_pApp->activeConsole()),&vParams) } else { KviKvsScript::run(m_szCompletionCallback,out ? out : (KviWindow *)(g_pApp->activeConsole()),&vParams); } if(bSuccess) { m_szStatusString = __tr2qs_ctx("Transfer completed","http"); m_eGeneralStatus = Success; displayUpdate(); if(out && (!m_bNoOutput))out->output(KVI_OUT_GENERICSUCCESS,__tr2qs_ctx("[HTTP %d]: Transfer completed","http"),id()); g_pApp->fileDownloadTerminated( true, m_pHttpRequest->url().url(), m_pHttpRequest->fileName(), QString(), QString(), !m_bNotifyCompletion ); } else { m_szStatusString = __tr2qs_ctx("Transfer failed","http"); m_szStatusString += ": "; m_szStatusString += m_pHttpRequest->lastError(); m_eGeneralStatus = Failure; displayUpdate(); if(out && (!m_bNoOutput))out->output(KVI_OUT_GENERICERROR,__tr2qs_ctx("[HTTP %d]: Transfer failed: %Q","http"),id(),&(m_pHttpRequest->lastError())); g_pApp->fileDownloadTerminated( false, m_pHttpRequest->url().url(), m_pHttpRequest->fileName(), QString(), m_pHttpRequest->lastError(), !m_bNotifyCompletion ); } if(m_bAutoClean) { if(m_pAutoCleanTimer)delete m_pAutoCleanTimer; m_pAutoCleanTimer = new QTimer(); connect(m_pAutoCleanTimer,SIGNAL(timeout()),this,SLOT(autoClean())); m_pAutoCleanTimer->start(100); m_TimerId=m_pAutoCleanTimer->timerId(); } }
// this is called just after the first startup // all the subsystems are up and running (we even have a nice console // to write on if needed). // all the options are loaded. KVIMODULEEXPORTFUNC void setup_finish() { if(bNeedToApplyDefaults) { KVI_OPTION_STRING(KviOption_stringIncomingPath) = g_szChoosenIncomingDirectory; // Reset the quit message and the real name... if they contain the KVIrc version // then probably the user hasn't even edited them. if(KVI_OPTION_STRING(KviOption_stringQuitMessage).indexOf("KVIrc",0,Qt::CaseInsensitive) != -1) KVI_OPTION_STRING(KviOption_stringQuitMessage) = KVI_DEFAULT_QUIT_MESSAGE; // We deserve to change the user's part message in something nice :) KVI_OPTION_STRING(KviOption_stringPartMessage) = KVI_DEFAULT_PART_MESSAGE; // FIXME: Should we also change these ? // #define KVI_DEFAULT_CTCP_USERINFO_REPLY "I'm too lazy to edit this field." // #define KVI_DEFAULT_AWAY_MESSAGE "I'm off to see the wizard." // Apply the chosen default theme KviThemeInfo out; switch(g_iThemeToApply) { case THEME_APPLY_HIRES: KviTheme::load("Aria-1.0.0",out,BUILTIN); break; case THEME_APPLY_LORES: KviTheme::load("MinimalDark-1.0.0",out,BUILTIN); break; // default: no theme } if(!szMircServers.isEmpty()) { g_pServerDataBase->importFromMircIni(szMircServers,szMircIni, KVI_OPTION_STRINGLIST(KviOption_stringlistRecentServers)); g_pApp->saveIrcServerDataBase(); } g_pApp->loadDefaultScript(); if(!szUrl.isEmpty()) { KviKvsVariantList * pParams = new KviKvsVariantList(); pParams->append(szUrl); KviKvsScript::run("openurl $0",g_pActiveWindow,pParams); delete pParams; KVI_OPTION_BOOL(KviOption_boolShowServersConnectDialogOnStart) = TRUE; } else if(!szHost.isEmpty()) { KviKvsVariantList * pParams = new KviKvsVariantList(); pParams->append(szHost); pParams->append((kvs_int_t)uPort); KviKvsScript::run("server $0 $1",g_pActiveWindow,pParams); delete pParams; KVI_OPTION_BOOL(KviOption_boolShowServersConnectDialogOnStart) = TRUE; } } }
bool endElement(const QString & szNamespaceUri, const QString & szLocalName, const QString & szQualifiedName) override { KviKvsVariant ret; KviKvsVariantList par; par.setAutoDelete(true); par.append(new KviKvsVariant(szQualifiedName)); par.append(new KviKvsVariant(szNamespaceUri)); par.append(new KviKvsVariant(szLocalName)); if(!m_pReader->callFunction(m_pReader, "onElementEnd", &ret, &par)) return kvsCodeFailure(); return handleKvsCallReturnValue(&ret); }
void KvsObject_xmlReader::fatalError(const QString & szError) { m_szLastError = szError; KviKvsVariantList vArgs; vArgs.append(new KviKvsVariant(m_szLastError)); callFunction(this, "onError", &vArgs); }
bool startElement(const QString & szNamespaceUri, const QString & szLocalName, const QString & szQualifiedName, const QXmlAttributes & attrs) override { KviKvsVariant ret; KviKvsVariantList par; par.setAutoDelete(true); par.append(new KviKvsVariant(szQualifiedName)); KviKvsHash * pHash = new KviKvsHash(); par.append(new KviKvsVariant(pHash)); par.append(new KviKvsVariant(szNamespaceUri)); par.append(new KviKvsVariant(szLocalName)); int c = attrs.count(); for(int i = 0; i < c; i++) pHash->set(attrs.qName(i), new KviKvsVariant(attrs.value(i))); if(!m_pReader->callFunction(m_pReader, "onElementStart", &ret, &par)) return kvsCodeFailure(); return handleKvsCallReturnValue(&ret); }
void SinglePopupEditor::testPopup() { if(m_pTestPopup) delete m_pTestPopup; m_pTestPopup = getMenu(); if(!m_pTestPopup) return; connect(m_pTestPopup, SIGNAL(testModeItemClicked(KviKvsPopupMenuItem *)), this, SLOT(testModeMenuItemClicked(KviKvsPopupMenuItem *))); QPoint pnt = m_pMenuButton->mapToGlobal(QPoint(0, m_pMenuButton->height())); KviKvsVariantList * parms = new KviKvsVariantList(); parms->append(new KviKvsVariant(QString("test1"))); parms->append(new KviKvsVariant(QString("test2"))); parms->append(new KviKvsVariant(QString("test3"))); parms->append(new KviKvsVariant(QString("test4"))); m_pTestPopup->doPopup(pnt, g_pActiveWindow, parms, true); }
bool characters(const QString & szChars) override { KviKvsVariant ret; KviKvsVariantList par; par.setAutoDelete(true); par.append(new KviKvsVariant(szChars)); if(!m_pReader->callFunction(m_pReader, "onText", &ret, &par)) return kvsCodeFailure(); return handleKvsCallReturnValue(&ret); }
void KviScriptUserButton::btnClicked() { KviWindow * pWnd = window(); if(!pWnd)return; // ops... QPoint pos = mapToGlobal(QPoint(0,height())); KviKvsVariantList vList; vList.append((kvs_int_t)pos.x()); vList.append((kvs_int_t)pos.y()); m_pScript->run(pWnd,&vList,0,KviKvsScript::PreserveParams); }
bool error(const QXmlParseException & exception) override { // recoverable QString szMsg; decodeException(szMsg, false, exception); KviKvsVariant ret; KviKvsVariantList par; par.setAutoDelete(true); par.append(new KviKvsVariant(szMsg)); if(!m_pReader->callFunction(m_pReader, "onWarning", &ret, &par)) return kvsCodeFailure(); return handleKvsCallReturnValue(&ret); }
void KvsObject_trayIcon::slotActivated(QSystemTrayIcon::ActivationReason reason) { QString szReason; if (reason==QSystemTrayIcon::Unknown) szReason="Unknown"; else if(reason==QSystemTrayIcon::Context) szReason="Context"; else if(reason==QSystemTrayIcon::DoubleClick) szReason="DoubleClick"; else if(reason==QSystemTrayIcon::Trigger) szReason="Trigger"; else szReason="MiddleClick"; KviKvsVariantList lParams; lParams.append(new KviKvsVariant(szReason)); callFunction(this,"activatedEvent",0,&lParams); }
KviKvsObject * KviKvsObjectClass::allocateInstance(KviKvsObject * pParent,const QString &szName,KviKvsRunTimeContext * pContext,KviKvsVariantList * pParams) { if(!m_allocProc) return 0; KviKvsObject * pObject = m_allocProc(this,pParent,szName); if(!pObject) return 0; if(!pObject->init(pContext,pParams)) { // internal init failure : abort pObject->dieNow(); return 0; } // copy params KviKvsVariantList copy; copy.setAutoDelete(false); KviKvsVariant * v = pParams->first(); while(v) { copy.append(v); v = pParams->next(); } KviKvsVariant ret; if(!pObject->callFunction(pObject,"constructor",QString(),pContext,&ret,©)) { // ops...constructor failed (script error!) pObject->dieNow(); return 0; } if(!ret.isEmpty()) pContext->warning(__tr2qs_ctx("It's not allowed to return values in the constructor","kvs")); return pObject; }
bool KviKvsProcessAsyncOperation::trigger(CallbackEvent e, const QString & szData) { if(m_bDeletePending) return false; if(!g_pApp->windowExists(m_pData->pWnd)) { if(m_pData->iFlags & KVI_KVS_PROCESSDESCRIPTOR_KILLIFNOWINDOW) { return true; } m_pData->pWnd = g_pApp->activeConsole(); } if(m_pData->pCallback) { KviKvsVariantList params; params.setAutoDelete(true); switch(e) { case EventStdout: params.append(new KviKvsVariant(QString("stdout"))); break; case EventStderr: params.append(new KviKvsVariant(QString("stderr"))); break; case EventTerminated: params.append(new KviKvsVariant(QString("terminated"))); break; case EventStarted: params.append(new KviKvsVariant(QString("started"))); break; case EventPing: params.append(new KviKvsVariant(QString("ping"))); break; default: qDebug("Oops! Unknown trigger() CallbackEvent parameter in QProcessDescriptor::trigger()"); return false; break; } params.append(new KviKvsVariant(szData)); if(m_pData->pMagic) { KviKvsVariant * pTmp = new KviKvsVariant(); pTmp->copyFrom(m_pData->pMagic); params.append(pTmp); } KviKvsVariant retVal; int iRet = m_pData->pCallback->run(m_pData->pWnd, ¶ms, &retVal, KviKvsScript::PreserveParams, m_pExtendedRunTimeData); if(!iRet) { m_pData->pWnd->output(KVI_OUT_PARSERERROR, __tr2qs_ctx("Error triggered from process callback handler: killing process", "kvs")); return true; } if(!retVal.isNothing()) { QString sz; retVal.asString(sz); m_pProcess->write(sz.toUtf8().data()); } if(iRet & KviKvsScript::HaltEncountered) { // halt encountered: kill the process return true; } } return false; }
void KviIrcView::triggerMouseRelatedKvsEvents(QMouseEvent *e) { QString linkCmd; QString linkText; getLinkUnderMouse(e->pos().x(),e->pos().y(),0,&linkCmd,&linkText); QString szCmd(linkCmd); szCmd.remove(0,1); KviKvsVariantList * pParams = new KviKvsVariantList(); if(!szCmd.isEmpty()) pParams->append(szCmd); // <-- FIXME: why we do this ? else pParams->append(linkText); // <-- FIXME: why we do this ? pParams->append(linkText); pParams->append(szCmd); if(!(e->modifiers() & Qt::ControlModifier))//(e->button() & Qt::RightButton) && ( { if(!linkCmd.isEmpty()) { switch(linkCmd[0].unicode()) { case 'n': { bool bTrigger = false; switch(m_pKviWindow->type()) { case KviWindow::Channel: if(((KviChannelWindow *)m_pKviWindow)->isOn(linkText)) { if(e->button() & Qt::RightButton) KVS_TRIGGER_EVENT(KviEvent_OnChannelNickPopupRequest,m_pKviWindow,pParams); if(e->button() & Qt::LeftButton) { KVS_TRIGGER_EVENT(KviEvent_OnChannelNickLinkClick,m_pKviWindow,pParams); } } else bTrigger = true; break; case KviWindow::Query: if(KviQString::equalCI(((KviQueryWindow *)m_pKviWindow)->windowName(),linkText)) { if(e->button() & Qt::RightButton) KVS_TRIGGER_EVENT(KviEvent_OnQueryNickPopupRequest,m_pKviWindow,pParams); if(e->button() & Qt::LeftButton) KVS_TRIGGER_EVENT(KviEvent_OnQueryNickLinkClick,m_pKviWindow,pParams); } else bTrigger = true; break; default: bTrigger = true; break; } if(bTrigger) { if(console()) { if(e->button() & Qt::RightButton) KVS_TRIGGER_EVENT(KviEvent_OnNickLinkPopupRequest,m_pKviWindow,pParams); if(e->button() & Qt::LeftButton) KVS_TRIGGER_EVENT(KviEvent_OnConsoleNickLinkClick,m_pKviWindow,pParams); } else emit rightClicked(); } } break; case 'h': if(e->button() & Qt::RightButton) KVS_TRIGGER_EVENT(KviEvent_OnHostLinkPopupRequest,m_pKviWindow,pParams); if(e->button() & Qt::LeftButton) KVS_TRIGGER_EVENT(KviEvent_OnHostLinkClick,m_pKviWindow,pParams); break; case 'u': if(e->button() & Qt::RightButton) KVS_TRIGGER_EVENT(KviEvent_OnURLLinkPopupRequest,m_pKviWindow,pParams); if(e->button() & Qt::LeftButton && KVI_OPTION_UINT(KviOption_uintUrlMouseClickNum) == 1) KVS_TRIGGER_EVENT(KviEvent_OnURLLinkClick,m_pKviWindow,pParams); break; case 'c': if(e->button() & Qt::RightButton) KVS_TRIGGER_EVENT(KviEvent_OnChannelLinkPopupRequest,m_pKviWindow,pParams); if(e->button() & Qt::LeftButton) KVS_TRIGGER_EVENT(KviEvent_OnChannelLinkClick,m_pKviWindow,pParams); break; case 's': if(e->button() & Qt::RightButton) KVS_TRIGGER_EVENT(KviEvent_OnServerLinkPopupRequest,m_pKviWindow,pParams); if(e->button() & Qt::LeftButton) KVS_TRIGGER_EVENT(KviEvent_OnServerLinkClick,m_pKviWindow,pParams); break; default: { if(e->button() & Qt::RightButton) { QString tmp; getLinkEscapeCommand(tmp,linkCmd,"[!rbt]"); if(!tmp.isEmpty()) { KviKvsScript::run(tmp,m_pKviWindow,pParams); } else emit rightClicked(); } } break; } } else if(e->button() & Qt::RightButton) emit rightClicked(); } else if((e->button() & Qt::MidButton) || ((e->button() & Qt::RightButton) && (e->modifiers() & Qt::ControlModifier))) { QString tmp; getLinkEscapeCommand(tmp,linkCmd,QString("[!mbt]")); if(!tmp.isEmpty()) { KviKvsScript::run(tmp,m_pKviWindow,pParams); } else { KVS_TRIGGER_EVENT_0(KviEvent_OnWindowPopupRequest,m_pKviWindow); } } delete pParams; }
//mouse events void KviIrcView::mouseDoubleClickEvent(QMouseEvent *e) { QString szKvsCommand; QString szLinkCommandPart; QString szLinkTextPart; if(m_iMouseTimer) { killTimer(m_iMouseTimer); m_iMouseTimer=0; delete m_pLastEvent; m_pLastEvent = 0; } getLinkUnderMouse(e->pos().x(),e->pos().y(),0,&szLinkCommandPart,&szLinkTextPart); if(szLinkCommandPart.isEmpty()) { KVS_TRIGGER_EVENT_0(KviEvent_OnTextViewDoubleClicked,m_pKviWindow); return; } KviKvsVariantList lParams; lParams.append(szLinkTextPart); switch(szLinkCommandPart[0].unicode()) { case 'n': { switch(m_pKviWindow->type()) { case KviWindow::Channel: if(((KviChannelWindow *)m_pKviWindow)->isOn(szLinkTextPart)) { KVS_TRIGGER_EVENT(KviEvent_OnChannelNickDefaultActionRequest,m_pKviWindow,&lParams); return; } break; case KviWindow::Query: if(KviQString::equalCI(((KviQueryWindow *)m_pKviWindow)->windowName(),szLinkTextPart)) { KVS_TRIGGER_EVENT(KviEvent_OnQueryNickDefaultActionRequest,m_pKviWindow,&lParams); return; } break; default: return; // unhandled window type (FIXME: Let it go anyway ?) break; } if(console()) KVS_TRIGGER_EVENT(KviEvent_OnNickLinkDefaultActionRequest,m_pKviWindow,&lParams); return; } break; case 'm': // m+X[ param] / m-X[ param] (used to quickly undo mode changes) { // Syntax is // m<plus_or_minus><mode_char>[ <parameter>] if(szLinkCommandPart.length() < 3) return; // malformed if(m_pKviWindow->type() != KviWindow::Channel) return; // must be on a channel to apply it if(!(((KviChannelWindow *)m_pKviWindow)->isMeOp())) return; // i'm not op, can't do mode changes QString szPart = szLinkCommandPart.mid(1); szKvsCommand = QString("mode $chan.name %1").arg(szPart); } break; case 'h': m_pKviWindow->output(KVI_OUT_HOSTLOOKUP,__tr2qs("Looking up host %Q..."),&szLinkTextPart); szKvsCommand = "host -a $0"; break; case 'u': if(KVI_OPTION_UINT(KviOption_uintUrlMouseClickNum) == 2) // <-- ?????????? { KVS_TRIGGER_EVENT(KviEvent_OnURLLinkClick,m_pKviWindow,&lParams); return; } break; case 'c': { if(!console()) return; if(!console()->connection()) return; // If there is a channel after the c flag, join that instead (as the text part may contain control codes) if(szLinkCommandPart.length() > 1) szLinkTextPart = szLinkCommandPart.mid(1); if(KviChannelWindow * c = console()->connection()->findChannel(szLinkTextPart)) { // already there g_pMainWindow->setActiveWindow(c); return; } szKvsCommand = "join $0"; } break; case 's': szKvsCommand = "motd $0"; break; default: { // extract the user-supplied double click command getLinkEscapeCommand(szKvsCommand,szLinkCommandPart,"[!dbl]"); if(szKvsCommand.isEmpty()) { KVS_TRIGGER_EVENT_0(KviEvent_OnTextViewDoubleClicked,m_pKviWindow); return; } } break; } if(!szKvsCommand.isEmpty()) KviKvsScript::run(szKvsCommand,m_pKviWindow,&lParams); }