KviHttpRequest::~KviHttpRequest() { resetInternalStatus(); KVI_ASSERT(!(m_p->pSocket)); KVI_ASSERT(!(m_p->pFile)); if(m_p->pBuffer) delete m_p->pBuffer; delete m_p; }
void PopupEditorWidget::getUniquePopupName(MenuTreeWidgetItem * item, QString & buffer) { KVI_ASSERT(m_bOneTimeSetupDone); if(buffer.isEmpty()) buffer = __tr2qs_ctx("unnamed", "editor"); QString newName = buffer; bool bFound = true; int idx = 1; int topcount = m_pTreeWidget->topLevelItemCount(); while(bFound) { bFound = false; for(int i = 0; i < topcount; i++) { MenuTreeWidgetItem * ch = (MenuTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); if(KviQString::equalCI(newName, ch->m_pPopup->popupName()) && (ch != item)) { bFound = true; newName = QString("%1.%2").arg(buffer).arg(idx); idx++; break; } } } buffer = newName; }
void RawEditorWidget::getUniqueHandlerName(RawTreeWidgetItem *it,QString &buffer) { KVI_ASSERT(m_bOneTimeSetupDone); QString newName = buffer; if(newName.isEmpty())newName = __tr2qs_ctx("unnamed","editor"); bool bFound = true; int idx = 1; while(bFound) { bFound = false; for (int i=0;i<it->childCount();i++) { RawHandlerTreeWidgetItem * ch =(RawHandlerTreeWidgetItem *) it->child(i); if(KviQString::equalCI(newName,ch->text(0))) { bFound = true; newName = QString("%1_%2").arg(buffer).arg(idx); idx++; break; } } } buffer = newName; }
void PopupEditorWidget::customContextMenuRequested(const QPoint & pos) { QTreeWidgetItem * it = m_pTreeWidget->itemAt(pos); KVI_ASSERT(m_bOneTimeSetupDone); if(it) { m_pContextPopup->clear(); m_pContextPopup->addAction(*(g_pIconManager->getSmallIcon(KviIconManager::Popup)), __tr2qs_ctx("&New Popup", "editor"), this, SLOT(newPopup())); m_pContextPopup->addAction(*(g_pIconManager->getSmallIcon(KviIconManager::Discard)), __tr2qs_ctx("Re&move Popup", "editor"), this, SLOT(removeCurrentPopup())) ->setEnabled(it); m_pContextPopup->addAction(*(g_pIconManager->getSmallIcon(KviIconManager::Save)), __tr2qs_ctx("&Export Popup to...", "editor"), this, SLOT(exportCurrentPopup())) ->setEnabled(it); m_pContextPopup->popup(QCursor::pos()); } else { m_pEmptyContextPopup->clear(); m_pEmptyContextPopup->addAction(*(g_pIconManager->getSmallIcon(KviIconManager::Popup)), __tr2qs_ctx("&New Popup", "editor"), this, SLOT(newPopup())); m_pEmptyContextPopup->popup(QCursor::pos()); } }
void EventEditor::getUniqueHandlerName(EventEditorEventTreeWidgetItem *it,QString &buffer) { KVI_ASSERT(m_bOneTimeSetupDone); QString newName = buffer; if(newName.isEmpty())newName = __tr2qs_ctx("unnamed","editor"); bool bFound = true; int idx = 1; while(bFound) { bFound = false; for(int i=0;i<it->childCount();i++) //for(EventEditorHandlerTreeWidgetItem * ch = (EventEditorHandlerTreeWidgetItem *)(it->firstChild());ch;ch = (EventEditorHandlerTreeWidgetItem *)ch->nextSibling()) { if(KviQString::equalCI(newName,((EventEditorHandlerTreeWidgetItem *)it->child(i))->m_szName)) { bFound = true; newName = QString("%1_%2").arg(buffer).arg(idx); idx++; break; } } } buffer = newName; }
void KviHttpRequest::slotSocketReadDataReady() { KVI_ASSERT(m_p->pSocket); int iBytes = m_p->pSocket->bytesAvailable(); if(iBytes <= 0) { // assume connection closed ? slotSocketDisconnected(); return; } // FIXME: Avoid double-buffering here! KviDataBuffer oBuffer(iBytes); int iRead = m_p->pSocket->read((char *)(oBuffer.data()),iBytes); if(iRead < iBytes) { // hum.... what here ? if(iRead < 1) { slotSocketDisconnected(); return; } // FIXME // well... otherwise just wait. // FIXME ? oBuffer.resize(iRead); } processData(&oBuffer); }
void EventEditor::currentItemChanged(QTreeWidgetItem * it,QTreeWidgetItem *) { KVI_ASSERT(m_bOneTimeSetupDone); saveLastEditedItem(); if(!it) { m_pNameEditor->setText(__tr2qs_ctx("No item selected","editor")); m_pEditor->setText(""); m_pEditor->setEnabled(false); return; } if(it->parent()) { m_pLastEditedItem = (EventEditorHandlerTreeWidgetItem *)it; m_pNameEditor->setEnabled(true); m_pNameEditor->setText(m_pLastEditedItem->name()); m_pEditor->setEnabled(true); m_pEditor->setFocus(); m_pEditor->setText(m_pLastEditedItem->m_szBuffer); m_pEditor->setCursorPosition(((EventEditorHandlerTreeWidgetItem *)it)->cursorPosition()); } else { m_pLastEditedItem = 0; m_pNameEditor->setEnabled(false); m_pNameEditor->setText(""); m_pEditor->setEnabled(false); QString parms = ((EventEditorEventTreeWidgetItem *)it)->m_szParams; if(parms.isEmpty())parms = __tr2qs_ctx("none","editor"); KviCommandFormatter::indent(parms); KviCommandFormatter::indent(parms); QString szTmp = QString(__tr2qs_ctx("\n\nEvent:\n%1\n\nParameters:\n%2","editor")).arg(((EventEditorEventTreeWidgetItem *)it)->m_szName,parms); m_pEditor->setText(szTmp); } }
void KviMdiChild::setClient(QWidget * w) { KVI_ASSERT(!m_pClient); KVI_ASSERT(w); m_pClient = w; setWidget(w); QString tmp1; if(w->inherits("KviWindow")) { KviIrcConnection * pConnection=((KviWindow*)w)->connection(); if(pConnection) tmp1.append(pConnection->target()->network()->name()+"_"); } KviCString tmp(KviCString::Format,"mdi_child_%s%s",tmp1.toUtf8().data(),w->objectName().toUtf8().data()); setObjectName(tmp.ptr()); }
void EventEditor::toggleCurrentHandlerEnabled() { KVI_ASSERT(m_bOneTimeSetupDone); if(m_pLastEditedItem) { m_pLastEditedItem->setEnabled(!(m_pLastEditedItem->m_bEnabled)); m_pTreeWidget->repaint(m_pTreeWidget->visualItemRect(m_pLastEditedItem)); currentItemChanged(m_pLastEditedItem,0); } }
void RawEditorWidget::toggleCurrentHandlerEnabled() { KVI_ASSERT(m_bOneTimeSetupDone); if(m_pLastEditedItem) { m_pLastEditedItem->m_bEnabled = !(m_pLastEditedItem->m_bEnabled); m_pLastEditedItem->setEnabled(m_pLastEditedItem->m_bEnabled); currentItemChanged(m_pLastEditedItem,m_pLastEditedItem); } }
KviQueryWindow * KviIrcContext::findDeadQuery(const QString & name) { for(auto & q : m_DeadQueries) { KVI_ASSERT(q->isDeadQuery()); if(KviQString::equalCI(name, q->windowName())) return q; } return nullptr; }
KviChannelWindow * KviIrcContext::findDeadChannel(const QString & name) { for(auto & c : m_DeadChannels) { KVI_ASSERT(c->isDeadChan()); if(KviQString::equalCI(name, c->windowName())) return c; } return nullptr; }
void KviMdiChild::unsetClient() { KVI_ASSERT(m_pClient); if(!m_pClient) return; setWidget(NULL); m_pClient = NULL; setObjectName("mdi_child"); }
static inline bool url_compare_helper(const kvi_wchar_t * pData1, const kvi_wchar_t * pData2, int iData2Len) { KVI_ASSERT(pData1); KVI_ASSERT(pData2); // pData1 is null-terminated and may be shorter than pData2 // pData2 is NOT null terminated and is lower case const kvi_wchar_t * pData2End = pData2 + iData2Len; while(pData2 < pData2End) { if(!*pData1) return false; // not equal if(QChar::toLower(*pData1) != *pData2) return false; // not equal pData1++; pData2++; } return true; // all equal up to iData2Len }
bool KviIrcView::event(QEvent *e) { if(e->type() == QEvent::User) { KVI_ASSERT(m_bPostedPaintEventPending); if(m_iUnprocessedPaintEventRequests) repaint(); // else we just had a pointEvent that did the job m_bPostedPaintEventPending = false; return true; } return QWidget::event(e); }
void KviHttpRequest::slotSocketError(QAbstractSocket::SocketError eError) { KVI_ASSERT(m_p->pSocket); if(eError == QAbstractSocket::RemoteHostClosedError) { slotSocketDisconnected(); return; } m_szLastError = m_p->pSocket->errorString(); resetInternalStatus(); emit terminated(false); }
void RawEditorWidget::removeCurrentHandler() { KVI_ASSERT(m_bOneTimeSetupDone); if(m_pLastEditedItem) { QTreeWidgetItem * it = m_pLastEditedItem; RawTreeWidgetItem * parent=(RawTreeWidgetItem *)it->parent(); m_pLastEditedItem = 0; delete it; m_pEditor->setEnabled(false); m_pNameEditor->setEnabled(false); if (!parent->childCount()) parent->setEnabled(false); } }
void KviKvsObjectController::deleteClass(KviKvsObjectClass * pClass) { KVI_ASSERT(pClass); pClass->clearDirtyFlag(); // don't flush it to disk QString szPath; QString szFileName = pClass->name().toLower(); szFileName += ".kvs"; szFileName.replace("::","--"); g_pApp->getLocalKvircDirectory(szPath,KviApplication::Classes,szFileName); KviFileUtils::removeFile(szPath); delete pClass; }
void KviRegisteredChannelDataBase::save(const QString &filename) { KviConfigurationFile cfg(filename,KviConfigurationFile::Write); cfg.clear(); cfg.preserveEmptyGroups(true); for(QHash<QString,KviRegisteredChannelList *>::Iterator it = m_pChannelDict->begin();it != m_pChannelDict->end();++it) { KviRegisteredChannelList * l = it.value(); KVI_ASSERT(l); for(KviRegisteredChannel * c = l->first();c;c = l->next()) { QString szGroup = QString::fromUtf8("%1@%2").arg(c->name(),c->netMask()); cfg.setGroup(szGroup); QHash<QString,QString> * pPropertyDict = c->propertyDict(); KVI_ASSERT(pPropertyDict); for(QHash<QString,QString>::Iterator it2 = pPropertyDict->begin();it2 != pPropertyDict->end();++it2) cfg.writeEntry(it2.key(),it2.value()); } } }
void kvi_appendWCharToQStringWithLength(QString * qstrptr, const kvi_wchar_t * ptr, kvi_wslen_t len) { KVI_ASSERT(qstrptr); kvi_wslen_t oldLen = qstrptr->length(); qstrptr->resize(oldLen + len); #ifdef WSTRINGCONFIG_SAFE_TO_MEMCPY_QCHAR KviMemory::copy((void *)(qstrptr->unicode() + oldLen), ptr, sizeof(kvi_wchar_t) * len); #else // !WSTRINGCONFIG_SAFE_TO_MEMCPY_QCHAR QChar * c = (QChar *)(qstrptr->unicode() + oldLen); while(*ptr) { c->unicode() = *ptr; ptr++; c++; } #endif // !WSTRINGCONFIG_SAFE_TO_MEMCPY_QCHAR }
void KviRegisteredChannelDataBase::add(KviRegisteredChannel * c) { KviRegisteredChannel * old = findExact(c->name(),c->netMask()); if(old) { // merge properties QHash<QString,QString> * pPropertyDict = old->propertyDict(); KVI_ASSERT(pPropertyDict); for(QHash<QString,QString>::Iterator it = pPropertyDict->begin();it != pPropertyDict->end();++it) { if(!c->property(it.key()).isEmpty()) c->setProperty(it.key(),it.value()); } remove(old); } KviRegisteredChannelList * l = m_pChannelDict->value(c->name()); if(!l) { l = new KviRegisteredChannelList(); l->setAutoDelete(true); m_pChannelDict->insert(c->name(),l); } // insert where there are less wildcards int o = c->netMask().count(QChar('*')); int idx = 0; for(KviRegisteredChannel * rc = l->first();rc;rc = l->next()) { if(rc->netMask().count(QChar('*')) > o) { // the existing has more wildcards, insert here! l->insert(idx,c); return; } idx++; } l->append(c); }
void RawEditorWidget::saveLastEditedItem() { KVI_ASSERT(m_bOneTimeSetupDone); if(!m_pLastEditedItem)return; QString buffer = m_pNameEditor->text(); qDebug("Check lineedit name %s and internal %s",buffer.toUtf8().data(),m_pLastEditedItem->text(0).toUtf8().data()); if(!KviQString::equalCI(buffer,m_pLastEditedItem->text(0))) { getUniqueHandlerName((RawTreeWidgetItem *)(m_pLastEditedItem->parent()),buffer); qDebug("Change name %s",buffer.toUtf8().data()); } m_pLastEditedItem->setName(buffer); QString tmp; m_pEditor->getText(tmp); m_pLastEditedItem->m_szBuffer = tmp; }
void EventEditor::saveLastEditedItem() { KVI_ASSERT(m_bOneTimeSetupDone); if(!m_pLastEditedItem)return; ((EventEditorHandlerTreeWidgetItem *)m_pLastEditedItem)->setCursorPosition(m_pEditor->getCursor()); QString buffer = m_pNameEditor->text(); //not-so elaborate fix for #218, we'd better rework this buffer.replace(QRegExp("[^A-Za-z0-9_]"), ""); if(!KviQString::equalCI(buffer,m_pLastEditedItem->m_szName)) { getUniqueHandlerName((EventEditorEventTreeWidgetItem *)(m_pLastEditedItem->parent()),buffer); } m_pLastEditedItem->setName(buffer); QString tmp; m_pEditor->getText(tmp); m_pLastEditedItem->m_szBuffer = tmp; }
void RawEditorWidget::customContextMenuRequested(const QPoint &pos) { QTreeWidgetItem *it; it=(QTreeWidgetItem *)m_pTreeWidget->itemAt(pos); KVI_ASSERT(m_bOneTimeSetupDone); m_pContextPopup->clear(); if(it) { if(it->parent()) { if(!(((RawHandlerTreeWidgetItem *)it)->m_bEnabled)) m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::Handler)), __tr2qs_ctx("&Enable Handler","editor"),this,SLOT(toggleCurrentHandlerEnabled())); else m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::HandlerDisabled)), __tr2qs_ctx("&Disable Handler","editor"),this,SLOT(toggleCurrentHandlerEnabled())); m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::Discard)), __tr2qs_ctx("Re&move Handler","editor"), this,SLOT(removeCurrentHandler())); m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::Save)), __tr2qs_ctx("&Export Handler to...","editor"), this,SLOT(exportCurrentHandler())); } else { m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::Handler)), __tr2qs_ctx("&New Handler","editor"), this,SLOT(addHandlerForCurrentRaw())); } } m_pContextPopup->addSeparator(); m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::RawEvent)), __tr2qs_ctx("&Add RAW Event...","editor"), this,SLOT(addRaw())); m_pContextPopup->popup(mapToGlobal(QPoint(pos.x()+15,pos.y()))); }
void RawEditorWidget::addHandlerForCurrentRaw() { KVI_ASSERT(m_bOneTimeSetupDone); RawTreeWidgetItem * it = (RawTreeWidgetItem *) m_pTreeWidget->currentItem(); if(it) { if(it->parent() == 0) { QString buffer = __tr2qs_ctx("default","editor"); getUniqueHandlerName((RawTreeWidgetItem *)it,buffer); QTreeWidgetItem * ch = new RawHandlerTreeWidgetItem(it,buffer,"",true); it->setEnabled(true); it->setExpanded(true); m_pTreeWidget->setCurrentItem(ch); m_pTreeWidget->clearSelection(); ch->setSelected(true); } } }
void RawEditorWidget::currentItemChanged(QTreeWidgetItem * it,QTreeWidgetItem *) { KVI_ASSERT(m_bOneTimeSetupDone); saveLastEditedItem(); if(it->parent()) { m_pLastEditedItem = (RawHandlerTreeWidgetItem *)it; m_pNameEditor->setEnabled(true); m_pNameEditor->setText(it->text(0)); m_pEditor->setEnabled(true); m_pEditor->setText(((RawHandlerTreeWidgetItem *)it)->m_szBuffer); } else { m_pLastEditedItem = 0; m_pNameEditor->setEnabled(false); m_pNameEditor->setText(""); m_pEditor->setEnabled(false); QString szTmp = QString(__tr2qs_ctx("\n\nRAW Event:\n%1","editor")).arg(((RawHandlerTreeWidgetItem *)it)->text(0)); m_pEditor->setText(szTmp); } }
void EventEditor::removeCurrentHandler() { KVI_ASSERT(m_bOneTimeSetupDone); if(m_pLastEditedItem) { QTreeWidgetItem * it = m_pLastEditedItem; QTreeWidgetItem * parent = m_pLastEditedItem->parent(); m_pLastEditedItem = 0; delete it; if(parent) { if(parent->childCount()==0) parent->setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KviIconManager::EventNoHandlers)))); } m_pEditor->setEnabled(false); m_pNameEditor->setEnabled(false); } }
void EventEditor::addHandlerForCurrentEvent() { KVI_ASSERT(m_bOneTimeSetupDone); if(!m_pTreeWidget->selectedItems().isEmpty()) { QTreeWidgetItem * it = m_pTreeWidget->selectedItems().first(); if(it->parent() == 0) { if(it->childCount()==0) it->setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Event)))); QString buffer = __tr2qs_ctx("default","editor"); getUniqueHandlerName((EventEditorEventTreeWidgetItem *)it,buffer); QTreeWidgetItem * ch = new EventEditorHandlerTreeWidgetItem(it,buffer,"",true); it->setExpanded(true); ch->setSelected(true); } } }
void EventEditor::itemPressed(QTreeWidgetItem * it, const QPoint & pnt) { KVI_ASSERT(m_bOneTimeSetupDone); if(it) { m_pContextPopup->clear(); if(it->parent()) { QString tmp; if(!(((EventEditorHandlerTreeWidgetItem *)it)->m_bEnabled)) m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::Handler)), __tr2qs_ctx("&Enable Handler", "editor"), this, SLOT(toggleCurrentHandlerEnabled())); else m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::HandlerDisabled)), __tr2qs_ctx("&Disable Handler", "editor"), this, SLOT(toggleCurrentHandlerEnabled())); m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::Discard)), __tr2qs_ctx("Re&move Handler", "editor"), this, SLOT(removeCurrentHandler())); m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::Save)), __tr2qs_ctx("&Export Handler to...", "editor"), this, SLOT(exportCurrentHandler())); } else { m_pContextPopup->addAction( *(g_pIconManager->getSmallIcon(KviIconManager::Handler)), __tr2qs_ctx("&New Handler", "editor"), this, SLOT(addHandlerForCurrentEvent())); } m_pContextPopup->popup(pnt); } }
void KviStupidNotifyListManager::sendIsOn() { m_szLastIsOnMsg = ""; QString * nick = m_pNickList->at(m_iNextNickToCheck); KVI_ASSERT(nick); int i = 0; while(nick && ((nick->length() + 5 + m_szLastIsOnMsg.length()) < 510)) { KviQString::appendFormatted(m_szLastIsOnMsg, " %Q", nick); nick = m_pNickList->next(); i++; } if(_OUTPUT_PARANOIC) m_pConsole->output(KVI_OUT_SYSTEMMESSAGE, __tr2qs("Notify list: Checking for: %Q"), &m_szLastIsOnMsg); QByteArray dat = m_pConnection->encodeText(m_szLastIsOnMsg); m_pConnection->sendFmtData("ISON%s", dat.data()); if(m_pConnection->lagMeter()) m_pConnection->lagMeter()->lagCheckRegister("@notify_naive", 20); m_iNextNickToCheck += i; }