void QXmppStream::_q_socketReadyRead() { d->dataBuffer.append(d->socket->readAll()); // handle whitespace pings if (!d->dataBuffer.isEmpty() && d->dataBuffer.trimmed().isEmpty()) { d->dataBuffer.clear(); handleStanza(QDomElement()); } // FIXME : maybe these QRegExps could be static? QRegExp startStreamRegex("^(<\\?xml.*\\?>)?\\s*<stream:stream.*>"); startStreamRegex.setMinimal(true); QRegExp endStreamRegex("</stream:stream>$"); endStreamRegex.setMinimal(true); // check whether we need to add stream start / end elements // // NOTE: as we may only have partial XML content, do not alter the stream's // state until we have a valid XML document! QByteArray completeXml = d->dataBuffer; const QString strData = QString::fromUtf8(d->dataBuffer); bool streamStart = false; if (d->streamStart.isEmpty() && strData.contains(startStreamRegex)) streamStart = true; else completeXml.prepend(d->streamStart); bool streamEnd = false; if (strData.contains(endStreamRegex)) streamEnd = true; else completeXml.append(streamRootElementEnd); // check whether we have a valid XML document QDomDocument doc; if (!doc.setContent(completeXml, true)) return; // remove data from buffer logReceived(strData); d->dataBuffer.clear(); // process stream start if (streamStart) { d->streamStart = startStreamRegex.cap(0).toUtf8(); handleStream(doc.documentElement()); } // process stanzas QDomElement nodeRecv = doc.documentElement().firstChildElement(); while (!nodeRecv.isNull()) { handleStanza(nodeRecv); nodeRecv = nodeRecv.nextSiblingElement(); } // process stream end if (streamEnd) disconnectFromHost(); }
void Messenger::onReadyRead() { while (_udp.hasPendingDatagrams()) { QByteArray datagram; datagram.resize(_udp.pendingDatagramSize()); QHostAddress sender; quint16 senderPort; _udp.readDatagram(datagram.data(), datagram.size(), &sender, &senderPort); bool flag = true; for(int i=0; i < _myips.count(); ++i) if(sender.toString() == _myips[i].toString()) flag = false; if (flag) { logReceived(datagram, sender); processTheDatagram(datagram, sender); } } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), tcore(new ThunderCore (this)), tpanel(new ThunderPanel (this)), vpanel(new VideoPanel (this)), lpanel(new LogView (this)), bpanel(new Browser (this)), transf0r(new Transf0r (this)), osd(new OSD (this)) { ui->setupUi(this); setWindowTitle (tr("%1 $VER %2").arg(QApplication::applicationName()) .arg(QApplication::applicationVersion())); vpanel->setStatusBar(ui->statusBar); ui->tabWidget->addTab(tpanel, "Cloud"); ui->tabWidget->addTab(vpanel, "Video"); ui->tabWidget->addTab(bpanel, "Browser"); ui->tabWidget->addTab(lpanel, "Log"); ui->tabWidget->addTab(transf0r, "Transf0r"); /// connect (tcore, SIGNAL(StatusChanged(ThunderCore::ChangeType)), SLOT(slotStatusChanged(ThunderCore::ChangeType))); connect (tcore, SIGNAL(error(QString,ThunderCore::ErrorCategory)), lpanel, SLOT(logReceived(QString,ThunderCore::ErrorCategory))); connect (tcore, SIGNAL(BTSubTaskReady(Thunder::BitorrentTask)), tpanel, SLOT(setBTSubTask(Thunder::BitorrentTask))); connect (tpanel, SIGNAL(doThisLink(Thunder::RemoteTask, ThunderPanel::RequestType,bool)), SLOT(slotRequestReceived(Thunder::RemoteTask, ThunderPanel::RequestType,bool))); connect (tpanel, SIGNAL(doIndirectRequest(ThunderPanel::IndirectRequestType)), SLOT(slotIndirectRequestReceived(ThunderPanel::IndirectRequestType))); connect (osd, SIGNAL(doubleClicked()), SLOT(slotShowOrHideWindow())); // WILL BE REMOVED LATER! connect (tcore, SIGNAL(error(QString,ThunderCore::ErrorCategory)), SLOT(slotError(QString,ThunderCore::ErrorCategory))); connect (bpanel, SIGNAL(browserLinksReady(QString)), SLOT(slotBrowserLinksReady(QString))); /// osd->osd_menu->addAction(ui->actionNewTask); osd->osd_menu->addSeparator(); osd->osd_menu->addAction(ui->actionQ_uit); /// { QSettings settings; settings.beginGroup("UI"); restoreState( settings.value("State").toByteArray()); restoreGeometry( settings.value("Geometry").toByteArray() ); } login (); }