Beispiel #1
0
void SerialServer::processTransfer(QByteArray& header)
{
    QDataStream headerStream(&header, QIODevice::ReadOnly);
    
    quint16 startWord;
    quint16 packetCount;
    
    headerStream >> startWord;
    headerStream >> packetCount;
    
    if(startWord != SERIAL_START)
        return;
    qWarning("Got start...");
    qWarning("packetcount=%d", packetCount);
    
    QByteArray compressedData;
    
    for(quint16 i = 0;i < packetCount;i++) {
        QByteArray data;
        if(!readPacket(&data))
            return;
        compressedData += data;
    }
    
    
    QByteArray data = qUncompress(compressedData);
    compressedData.clear();
    compressedData.squeeze();
    
    processData(data);
}
QByteArray QGitHubReleaseAPIPrivate::downloadFile(const QUrl &u, bool generic) const {

	QByteArray ba;
	QBuffer buf(&ba);

	if(!(buf.open(QIODevice::WriteOnly) && downloadFile(u, &buf, generic) != Q_INT64_C(-1))) {
		emit error(buf.errorString());
	}

	ba.squeeze();

	return ba;
}
Beispiel #3
0
void tst_QByteArray::constByteArray()
{
    const char *ptr = "abc";
    QByteArray cba = QByteArray::fromRawData(ptr, 3);
    QVERIFY(cba.constData() == ptr);
    cba.squeeze();
    QVERIFY(cba.constData() == ptr);
    cba.detach();
    QVERIFY(cba.size() == 3);
    QVERIFY(cba.capacity() == 3);
    QVERIFY(cba.constData() != ptr);
    QVERIFY(cba.constData()[0] == 'a');
    QVERIFY(cba.constData()[1] == 'b');
    QVERIFY(cba.constData()[2] == 'c');
    QVERIFY(cba.constData()[3] == '\0');
}
//////////////////////////////////////////////////////////////////////
// name Get Functions
//////////////////////////////////////////////////////////////////////
// Load the binary rep
GLC_3DRep GLC_BSRep::loadRep()
{
	GLC_3DRep loadedRep;

	if (open(QIODevice::ReadOnly))
	{
		if (headerIsOk())
		{
			timeStampOk(QDateTime());
			GLC_BoundingBox boundingBox;
			m_DataStream >> boundingBox;
			bool useCompression;
			m_DataStream >> useCompression;
			if (useCompression)
			{
				QByteArray CompresseBuffer;
				m_DataStream >> CompresseBuffer;
				QByteArray uncompressedBuffer= qUncompress(CompresseBuffer);
				uncompressedBuffer.squeeze();
				CompresseBuffer.clear();
				CompresseBuffer.squeeze();
				QDataStream bufferStream(uncompressedBuffer);
				bufferStream >> loadedRep;
			}
			else
			{
				m_DataStream >> loadedRep;
			}
			loadedRep.setFileName(m_FileInfo.filePath());

			if (!close())
			{
				QString message(QString("GLC_BSRep::loadRep An error occur when loading file ") + m_FileInfo.fileName());
				GLC_FileFormatException fileFormatException(message, m_FileInfo.fileName(), GLC_FileFormatException::WrongFileFormat);
				throw(fileFormatException);
			}
		}
		else
		{
Beispiel #5
0
bool SerialClient::sendFile(QString name, QStringList deps)
{
    m_serialPort.open();
    
    qWarning("MainFilePath=%s", qPrintable(name));
    
    QByteArray data;
    QDataStream dataStream(&data, QIODevice::WriteOnly);
    
    QFileInfo info(name);
    QFile fin(name);
    fin.open(QIODevice::ReadOnly);
    dataStream << info.fileName();
    dataStream << fin.readAll();
    fin.close();
    
    for(int i = 0;i < deps.size();i++) {
        info.setFile(deps[i]);
        fin.setFileName(deps[i]);
        if(fin.open(QIODevice::ReadOnly))
            qWarning("Opened file");
        else
            qWarning("failed to open file \"%s\"", qPrintable(deps[i]));
        dataStream << info.fileName();
        dataStream << fin.readAll();
        fin.close();
    }
    
    qWarning("data.size=%d", data.size());
    
    QByteArray compressedData = qCompress(data, 9);
    data.clear();
    data.squeeze();
    
    qWarning("compressedData.size()=%d", compressedData.size());
    
    QList<QByteArray> dataChunks;
    while(compressedData.size()) {
        dataChunks.push_front(compressedData.right(32));
        qWarning("dataChunks.count()=%d", dataChunks.count());
        compressedData.chop(32);
    }
    qWarning("dataChunks.count()=%d", dataChunks.count());
    compressedData.squeeze();
    
    QByteArray header;
    QDataStream stream(&header, QIODevice::WriteOnly);
    stream << SERIAL_START;
    stream << (quint16)dataChunks.size();
    
    qWarning("dataChunks.size()=%d", dataChunks.size());
    
    dataChunks.push_front(header);
    
    for(int i = 0;i < dataChunks.size();i++) {
        if(!writePacket(dataChunks[i]))
            return false;
    }
    
    m_serialPort.close();
    
    return true;
}
QString QGitHubReleaseAPIPrivate::embedImages(QString &b) const {
#if QT_VERSION >= QT_VERSION_CHECK(4, 5, 0)

	QRegExp emjRex(":([_a-zA-Z0-9]+):");
	QRegExp imgRex("<[^<]*img[^>]*src\\s*=\\s*\"([^\"]*)\"[^>]*>");

	Emoji *emoji = 0L;

	int idx = -1;

	while((idx = b.indexOf(emjRex, idx + 1)) != -1) {

		const QString emjKey(emjRex.cap(1));

		if(!emoji) {
			QEventLoop emjLoop;
			QObject::connect((emoji = new Emoji(eTag())), SIGNAL(available()),
							 &emjLoop, SLOT(quit()));
			if(!emoji->entries()) emjLoop.exec();
		}

		const QUrl &emjUrl(emoji->getUrl(emjKey));

		if(emjUrl.isValid()) {
			b.replace(idx, emjKey.length() + 2, "<img width=\"16\" height=\"16\" alt=\"" + emjKey +
					  "\" src=\"" + emjUrl.toString() + "\">");
		}

		idx += emjKey.length() + 1;
	}

	delete emoji;

	idx = -1;

	while((idx = b.indexOf(imgRex, idx + 1)) != -1) {

		const QUrl url = QUrl(imgRex.cap(1));

		if(url.isValid()) {

			const QImage img = QImage::fromData(downloadFile(url));

			if(!img.isNull()) {

				QByteArray ba;
				QBuffer buf(&ba);
				buf.open(QIODevice::WriteOnly);
				img.save(&buf, "PNG");
				ba.squeeze();

				b.replace(imgRex.pos(1), imgRex.cap(1).length(),
						  QString("data:image/png;base64,%1").
						  arg(ba.toBase64().constData()));
			}
		}
	}
#endif

	b.append("<hr /><p>Release information provided by " \
			 "<em>QGitHubReleaseAPI "
			 PROJECTVERSION
			 "</em> &copy; 2015 " \
			 "Heiko Sch&auml;fer &lt;<a href=\"mailto:[email protected]?" \
			 "subject=QGitHubReleaseAPI%20"
			 PROJECTVERSION
			 "\">[email protected]</a>&gt;");

#ifdef HAVE_MKDIO_H
	if(m_type == QGitHubReleaseAPI::RAW) {
		b.append(QString("<br />Markdown rendered with <em>libmarkdown %1</em>").
				 arg(markdown_version));
	}
#endif

	return b.append("</p>");
}