virtual QIODevice *data(const QUrl &/*url*/) { if (cachedData.isEmpty()) return 0; QBuffer *buffer = new QBuffer; buffer->setData(cachedData); buffer->open(QIODevice::ReadOnly); return buffer; }
QByteArray CommandlineOptions::Serialize() const { QBuffer buf; buf.open(QIODevice::WriteOnly); QDataStream s(&buf); s << *this; buf.close(); return buf.data(); }
void testSendWithoutSerializer() { QBuffer dev; dev.open(QIODevice::ReadWrite); mManager->setSerializer(0); mManager->addDevice(&dev); // Sending message to dev QVERIFY( dev.data().isEmpty() ); mService->boolSignal(false); QVERIFY( dev.data().isEmpty() ); }
/*! \overload Sends the contents of the \a data byte array to the destination specified by \a request. */ QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, const QByteArray &data) { QBuffer *buffer = new QBuffer; buffer->setData(data); buffer->open(QIODevice::ReadOnly); QNetworkReply *reply = put(request, buffer); buffer->setParent(reply); return reply; }
void QLCFixtureHead_Test::save() { QLCFixtureHead head; head.addChannel(0); head.addChannel(1); head.addChannel(2); head.addChannel(3); QBuffer buffer; buffer.open(QIODevice::WriteOnly | QIODevice::Text); QXmlStreamWriter xmlWriter(&buffer); QVERIFY(head.saveXML(&xmlWriter)); xmlWriter.setDevice(NULL); buffer.close(); buffer.open(QIODevice::ReadOnly | QIODevice::Text); QXmlStreamReader xmlReader(&buffer); xmlReader.readNextStartElement(); QCOMPARE(xmlReader.name().toString(), QString("Head")); int ch = 0; while (xmlReader.readNextStartElement()) { if (xmlReader.name() == "Channel") { QString chNum = xmlReader.readElementText(); QVERIFY(chNum.toInt() == 0 || chNum.toInt() == 1 || chNum.toInt() == 2 || chNum.toInt() == 3); ch++; } else { QFAIL(QString("Unexpected tag: %1").arg(xmlReader.name().toString()).toUtf8().constData()); xmlReader.skipCurrentElement(); } } QCOMPARE(ch, 4); }
void DBFile::setImage(QImage &image) { QBuffer buffer; buffer.open(QIODevice::WriteOnly); if (image.height() > IMAGE_MAX_SIZE || image.width() > IMAGE_MAX_SIZE) image = image.scaled(QSize(IMAGE_MAX_SIZE, IMAGE_MAX_SIZE), Qt::KeepAspectRatio, Qt::SmoothTransformation); image.save(&buffer, "JPG", JPEG_QUALITY); buffer.close(); setData(buffer.data()); }
void imageview::sSave() { XSqlQuery newImage; if (_mode == cNew) { if (!__imageview.isNull()) { XSqlQuery imageid("SELECT NEXTVAL('image_image_id_seq') AS _image_id"); if (imageid.first()) _imageviewid = imageid.value("_image_id").toInt(); // ToDo QImageWriter imageIo; QBuffer imageBuffer; QString imageString; imageBuffer.open(QIODevice::ReadWrite); imageIo.setDevice(&imageBuffer); imageIo.setFormat("PNG"); if (!imageIo.write(__imageview)) { // ToDo - should issue an error here reject(); return; } imageBuffer.close(); imageString = QUUEncode(imageBuffer); newImage.prepare( "INSERT INTO image " "(image_id, image_name, image_descrip, image_data) " "VALUES " "(:image_id, :image_name, :image_descrip, :image_data);" ); newImage.bindValue(":image_id", _imageviewid); newImage.bindValue(":image_name", _name->text()); newImage.bindValue(":image_descrip", _descrip->toPlainText()); newImage.bindValue(":image_data", imageString); } } else if (_mode == cEdit) { newImage.prepare( "UPDATE image " "SET image_name=:image_name, image_descrip=:image_descrip " "WHERE (image_id=:image_id);" ); newImage.bindValue(":image_id", _imageviewid); newImage.bindValue(":image_name", _name->text()); newImage.bindValue(":image_descrip", _descrip->toPlainText()); } newImage.exec(); done(_imageviewid); }
void TSoundOutputDeviceImp::play(const TSoundTrackP &st, TINT32 s0, TINT32 s1, bool loop, bool scrubbing) { if (!doSetStreamFormat(st->getFormat())) return; MyData *myData = new MyData(); myData->imp = shared_from_this(); myData->totalPacketCount = s1 - s0; myData->fileByteCount = (s1 - s0) * st->getSampleSize(); myData->entireFileBuffer = new char[myData->fileByteCount]; memcpy(myData->entireFileBuffer, st->getRawData() + s0 * st->getSampleSize(), myData->fileByteCount); m_isPlaying = true; myData->isLooping = loop; QAudioFormat format; QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); format.setSampleSize(st->getBitPerSample()); format.setCodec("audio/pcm"); format.setChannelCount(st->getChannelCount()); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(st->getFormat().m_signedSample ? QAudioFormat::SignedInt : QAudioFormat::UnSignedInt); format.setSampleRate(st->getSampleRate()); QList<QAudioFormat::Endian> sbos = info.supportedByteOrders(); QList<int> sccs = info.supportedChannelCounts(); QList<int> ssrs = info.supportedSampleRates(); QList<QAudioFormat::SampleType> sstypes = info.supportedSampleTypes(); QList<int> ssss = info.supportedSampleSizes(); QStringList supCodes = info.supportedCodecs(); if (!info.isFormatSupported((format))) { format = info.nearestFormat(format); int newChannels = format.channelCount(); int newBitsPerSample = format.sampleSize(); int newSampleRate = format.sampleRate(); QAudioFormat::SampleType newSampleType = format.sampleType(); QAudioFormat::Endian newBo = format.byteOrder(); } int test = st->getSampleCount() / st->getSampleRate(); QByteArray *data = new QByteArray(myData->entireFileBuffer, myData->fileByteCount); QBuffer *newBuffer = new QBuffer; newBuffer->setBuffer(data); newBuffer->open(QIODevice::ReadOnly); newBuffer->seek(0); if (m_audioOutput == NULL) { m_audioOutput = new QAudioOutput(format, NULL); } m_audioOutput->start(newBuffer); m_audioOutput->setVolume(m_volume); }
qint64 Request::writeData(const char* data, qint64 maxSize) { if(m_responseState == WaitingForResponseHeaders) { m_headerBuffer.append(data, maxSize); // We need to buffer the headers, so we can use the STATUS header appropriately QBuffer buffer; buffer.setData(m_headerBuffer); buffer.open(QIODevice::ReadOnly); buffer.seek(m_headerBufferPosition); while(buffer.canReadLine()) { const QByteArray line = buffer.readLine().trimmed(); if(line.isEmpty()) { Q_ASSERT(m_responseHeaders.contains("STATUS")); Q_ASSERT(m_requestHeaders.contains("SERVER_PROTOCOL")); m_responseState = WaitingForResponseBody; const QByteArray status = m_responseHeaders.take("STATUS"); m_socket->write(m_requestHeaders.value("SERVER_PROTOCOL")); m_socket->write(" ", 1); m_socket->write(status); m_socket->write("\r\n", 2); //qDebug() << Q_FUNC_INFO << m_requestHeaders << m_responseHeaders; for( HeaderMap::ConstIterator it = m_responseHeaders.constBegin(); it != m_responseHeaders.constEnd(); ++it ) { m_socket->write(it.key()); m_socket->write(": "); m_socket->write(it.value()); m_socket->write("\r\n"); } m_socket->write("\r\n"); m_socket->write(buffer.readAll()); buffer.close(); m_headerBuffer.clear(); return maxSize; } const int lengthOfName = line.indexOf(':'); const QByteArray name = line.left(lengthOfName); const QByteArray value = line.mid(lengthOfName + 2); // ": " after the name == 2 chars m_responseHeaders.insertMulti(name, value); } m_headerBufferPosition = buffer.pos(); buffer.close(); return maxSize; } Q_ASSERT(m_responseState == WaitingForResponseBody); return m_socket->write(data, maxSize); }
void merge( const QString& newname, const QString& oldname, const QString& resname ) { QFile f1(newname); if ( !f1.open( IO_ReadOnly) ) return; QFile f2(oldname); if ( !f2.open( IO_ReadOnly) ) return; QBuffer fout; fout.open(IO_WriteOnly); QTextStream in1( &f1 ); QTextStream in2( &f2 ); QTextStream out( &fout ); QString buf1 = in1.readLine().stripWhiteSpace(); QString buf2 = in2.readLine().stripWhiteSpace(); Item i1 = getItem( in1, buf1 ); Item i2 = getItem( in2, buf2 ); while ( !i1.isNull() || !i2.isNull() ) { Status s = compare( i1, i2 ); if ( s == Equal ) { writemerge(out,i1,i2); i1 = getItem( in1, buf1 ); i2 = getItem( in2, buf2 ); } else if ( s == First ) { writenew( out, i1 ); i1 = getItem( in1, buf1 ); } else if ( s == FirstJunk ) { //solitary comment writejunk( out, i1 ); i1 = getItem( in1, buf1 ); } else if ( s == Second ) { writeold( out, i2 ); i2 = getItem( in2, buf2 ); } else if ( s == SecondJunk ) { //solitary comment writejunk( out, i2 ); i2 = getItem( in2, buf2 ); } } f1.close(); f2.close(); fout.close(); QFile fileout(resname); if ( !fileout.open( IO_WriteOnly | IO_Translate ) ) return; fileout.writeBlock(fout.buffer()); fileout.close(); }
bool sendData(const T & output) { QBuffer buffer; buffer.open(QBuffer::ReadWrite); QDataStream serializer(&buffer); serializer << output; writeArray = buffer.data(); emit pulseSendSerialized(); return true; }
void KMessageClient::sendForward (const QByteArray &msg, const QList <quint32> &clients) { QByteArray sendBuffer; QBuffer buffer (&sendBuffer); buffer.open (QIODevice::WriteOnly); QDataStream stream (&buffer); stream << static_cast<quint32>( KMessageServer::REQ_FORWARD ) << clients; buffer.QIODevice::write (msg); sendServerMessage (sendBuffer); }
void KMessageClient::sendBroadcast (const QByteArray &msg) { QByteArray sendBuffer; QBuffer buffer (&sendBuffer); buffer.open (QIODevice::WriteOnly); QDataStream stream (&buffer); stream << static_cast<quint32> ( KMessageServer::REQ_BROADCAST ); buffer.QIODevice::write (msg); sendServerMessage (sendBuffer); }
const KeyboardTranslator* KeyboardTranslatorManager::defaultTranslator() { qDebug() << "Loading default translator from text"; QBuffer textBuffer; textBuffer.setData( defaultTranslatorText, strlen( defaultTranslatorText ) ); if ( !textBuffer.open( QIODevice::ReadOnly ) ) return 0; return loadTranslator( &textBuffer, "fallback" ); }
QBuffer* KDSoapClientInterfacePrivate::prepareRequestBuffer(const QString& method, const KDSoapMessage& message, const KDSoapHeaders& headers) { KDSoapMessageWriter msgWriter; msgWriter.setMessageNamespace(m_messageNamespace); msgWriter.setVersion(m_version); const QByteArray data = msgWriter.messageToXml(message, (m_style == KDSoapClientInterface::RPCStyle) ? method : QString(), headers, m_persistentHeaders, m_version); QBuffer* buffer = new QBuffer; buffer->setData(data); buffer->open(QIODevice::ReadOnly); return buffer; }
cmsHPROFILE loadFromPngData(const QByteArray& data) { QBuffer buffer; buffer.setBuffer(const_cast<QByteArray*>(&data)); buffer.open(QIODevice::ReadOnly); // Initialize the internal structures png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); GV_RETURN_VALUE_IF_FAIL(png_ptr, 0); png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); kWarning() << "Could not create info_struct"; return 0; } png_infop end_info = png_create_info_struct(png_ptr); if (!end_info) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); kWarning() << "Could not create info_struct2"; return 0; } // Catch errors if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); kWarning() << "Error decoding png file"; return 0; } // Initialize the special png_set_read_fn(png_ptr, &buffer, readPngChunk); // read all PNG info up to image data png_read_info(png_ptr, info_ptr); // Get profile png_charp profile_name; #if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 5 png_bytep profile_data; #else png_charp profile_data; #endif int compression_type; png_uint_32 proflen; cmsHPROFILE profile = 0; if (png_get_iCCP(png_ptr, info_ptr, &profile_name, &compression_type, &profile_data, &proflen)) { profile = cmsOpenProfileFromMem(profile_data, proflen); } png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); return profile; }
QWidget * FLManagerModules::createUI( const QString & n, QObject * connector, QWidget * parent, const char *name ) { QBuffer b; b.open( IO_ReadWrite ); QTextStream t( &b ); t.setEncoding( QTextStream::Latin1 ); t << contentCached( n ); b.reset(); QWidget * w = QWidgetFactory::create( &b, connector, parent, name ); return w; }
QByteArray CopyHelper::contentsAsByteArray() const { QBuffer result; result.open(QIODevice::WriteOnly); QDataStream os(&result); os << m_locations.size(); foreach (const TextLocation &location, m_locations) { os << location.position(); os << location.length(); }
void ManaChatServer::addConnection() { qDebug() <<"new connect"; QTcpSocket* connection = nextPendingConnection(); connections.append(connection); QBuffer* buffer = new QBuffer(this); buffer->open(QIODevice::ReadWrite); buffers.insert(connection, buffer); connect(connection, SIGNAL(disconnected()), SLOT(removeConnection())); connect(connection, SIGNAL(readyRead()), SLOT(receiveMessage())); }
const QByteArray QtZip::loadData(QString filename) { if( !filename.isEmpty() && isZipOpen ) { QBuffer cbuf; cbuf.open(QIODevice::WriteOnly); ec_uz = uz.extractFile(filename, &cbuf); return cbuf.data(); } else return QByteArray(""); }
// A tool for comparing XML documents and outputting something useful if they differ bool KDSoapUnitTestHelpers::xmlBufferCompare(const QByteArray& source, const QByteArray& dest) { QBuffer sourceFile; sourceFile.setData(source); if (!sourceFile.open(QIODevice::ReadOnly)) { qDebug() << "ERROR opening QIODevice"; return false; } QBuffer destFile; destFile.setData(dest); if (!destFile.open(QIODevice::ReadOnly)) { qDebug() << "ERROR opening QIODevice"; return false; } // Use QDomDocument to reformat the XML with newlines QDomDocument sourceDoc; if (!sourceDoc.setContent(&sourceFile)) { qDebug() << "ERROR parsing XML:" << source; return false; } QDomDocument destDoc; if (!destDoc.setContent(&destFile)) { qDebug() << "ERROR parsing XML:" << dest; return false; } const QByteArray sourceXml = sourceDoc.toByteArray(); const QByteArray destXml = destDoc.toByteArray(); sourceFile.close(); destFile.close(); QBuffer sourceBuffer; sourceBuffer.setData(sourceXml); sourceBuffer.open(QIODevice::ReadOnly); QBuffer destBuffer; destBuffer.setData(destXml); destBuffer.open(QIODevice::ReadOnly); return textBufferCompare(source, dest, sourceBuffer, destBuffer); }
void Fixture_Test::loader() { QBuffer buffer; buffer.open(QIODevice::WriteOnly | QIODevice::Text); QXmlStreamWriter xmlWriter(&buffer); xmlWriter.writeStartElement("Fixture"); xmlWriter.writeTextElement("Channels", "18"); xmlWriter.writeTextElement("Name", "Foobar"); xmlWriter.writeTextElement("Universe", "3"); xmlWriter.writeTextElement("Model", "Foobar"); xmlWriter.writeTextElement("Mode", "Foobar"); xmlWriter.writeTextElement("Manufacturer", "Foobar"); xmlWriter.writeTextElement("ID", "42"); xmlWriter.writeTextElement("Address", "21"); xmlWriter.writeEndDocument(); xmlWriter.setDevice(NULL); buffer.close(); buffer.open(QIODevice::ReadOnly | QIODevice::Text); QXmlStreamReader xmlReader(&buffer); xmlReader.readNextStartElement(); QVERIFY(m_doc != NULL); QVERIFY(m_doc->fixtures().size() == 0); QVERIFY(Fixture::loader(xmlReader, m_doc) == true); QVERIFY(m_doc->fixtures().size() == 1); QVERIFY(m_doc->fixture(0) == NULL); // No ID auto-assignment Fixture* fxi = m_doc->fixture(42); QVERIFY(fxi != NULL); QVERIFY(fxi->name() == "Foobar"); QVERIFY(fxi->channels() == 18); QVERIFY(fxi->address() == 21); QVERIFY(fxi->universe() == 3); QVERIFY(fxi->fixtureDef() != NULL); QVERIFY(fxi->fixtureMode() != NULL); }
QIODevice* GpsdMasterDevice::createSlave() { if(!_slaves.size() && !gpsdConnect()) return 0; QBuffer* slave = new QBuffer(this); slave->open(QIODevice::ReadWrite); _slaves.append(qMakePair(slave,false)); #ifndef QT_NO_DEBUG qDebug() << "Created slave" << slave; #endif return slave; }
void PSDUtilsTest::test_psdwrite_qstring() { QBuffer buf; buf.open(QBuffer::ReadWrite); QString s = "8BPS"; QVERIFY(psdwrite(&buf, s)); QCOMPARE(buf.buffer().size(), 4); QCOMPARE(buf.buffer().at(0), '8'); QCOMPARE(buf.buffer().at(1), 'B'); QCOMPARE(buf.buffer().at(2), 'P'); QCOMPARE(buf.buffer().at(3), 'S'); }
void PSDUtilsTest::test_psdwrite_quint32() { QBuffer buf; buf.open(QBuffer::ReadWrite); quint32 i = 100; QVERIFY(psdwrite(&buf, i)); QCOMPARE(buf.buffer().size(), 4); QCOMPARE(buf.buffer().at(0), '\0'); QCOMPARE(buf.buffer().at(1), '\0'); QCOMPARE(buf.buffer().at(2), '\0'); QCOMPARE(buf.buffer().at(3), 'd'); }
void Plugin::shoot () { ShotAction_->setEnabled (true); qDebug () << Q_FUNC_INFO << Dialog_->isVisible (); auto mw = Proxy_->GetMainWindow (); const QPixmap& pm = GetPixmap (); int quality = Dialog_->GetQuality (); switch (Dialog_->GetAction ()) { case ShooterDialog::Action::Save: { QString path = Proxy_->GetSettingsManager ()-> Property ("PluginsStorage/Auscrie/SavePath", QDir::currentPath () + "01." + Dialog_->GetFormat ()) .toString (); QString filename = QFileDialog::getSaveFileName (mw, tr ("Save as"), path, tr ("%1 files (*.%1);;All files (*.*)") .arg (Dialog_->GetFormat ())); if (!filename.isEmpty ()) { pm.save (filename, qPrintable (Dialog_->GetFormat ()), quality); Proxy_->GetSettingsManager ()-> setProperty ("PluginsStorage/Auscrie/SavePath", filename); } } break; case ShooterDialog::Action::Upload: { QByteArray bytes; QBuffer buf (&bytes); buf.open (QIODevice::ReadWrite); if (!pm.save (&buf, qPrintable (Dialog_->GetFormat ()), quality)) qWarning () << Q_FUNC_INFO << "save failed" << qPrintable (Dialog_->GetFormat ()) << quality; Post (bytes); break; } } }
void IndexBuilder::writeSnapshots(Reader &reader, KZip &zip) { static const qint64 SNAPSHOT_INTERVAL_MS = 1000; // snapshot interval in milliseconds static const int SNAPSHOT_MIN_ACTIONS = 200; // minimum number of actions between snapshots paintcore::LayerStack image; net::LayerListModel layermodel; canvas::StateTracker statetracker(&image, &layermodel, 1); MessageRecord msg; int snapshotCounter = 0; QElapsedTimer timer; timer.start(); while(true) { if(_abortflag.load()) return; msg = reader.readNext(); if(msg.status == MessageRecord::END_OF_RECORDING) break; else if(msg.status == MessageRecord::INVALID) continue; protocol::MessagePtr m(msg.message); if(m->isCommand()) { statetracker.receiveCommand(m); ++snapshotCounter; } // Save a snapshot every SNAPSHOT_INTERVAL or at every marker. (But no more often than SNAPSHOT_MIN_ACTIONS) // Note. We use the actual elapsed rendering time to decide when to snapshot. This means that (ideally), // the time it takes to jump to a snapshot is at most SNAPSHOT_INTERVAL milliseconds (+ the time it takes to load the snapshot) if(m_index.snapshots().isEmpty() || ((timer.hasExpired(SNAPSHOT_INTERVAL_MS) || m->type() == protocol::MSG_MARKER) && snapshotCounter>=SNAPSHOT_MIN_ACTIONS)) { qint64 streampos = reader.filePosition(); emit progress(streampos); canvas::StateSavepoint sp = statetracker.createSavepoint(-1); QBuffer buf; buf.open(QBuffer::ReadWrite); { QDataStream ds(&buf); sp.toDatastream(ds); } int snapshotIdx = m_index.m_snapshots.size(); zip.writeFile(QString("snapshot-%1").arg(snapshotIdx), buf.data()); m_index.m_snapshots.append(SnapshotEntry(streampos, reader.currentIndex())); snapshotCounter = 0; timer.restart(); } } }
void conflict_core::updateAida(){ QBuffer buffer; QDataStream in(&buffer); QString text; if(conflict.aidaOpen){ aida.lock(); buffer.setData((char*)aida.constData(), aida.size()); buffer.open(QBuffer::ReadOnly); in >> text; ui->debugOutputOut->append(text); aida.unlock(); }
bool MdlFileFormat::write(const chemkit::MoleculeFile *file, std::ostream &output) { QBuffer buffer; buffer.open(QBuffer::WriteOnly); bool ok = write(file, &buffer); if(!ok){ return false; } output.write(buffer.data().constData(), buffer.size()); return true; }
/*! Serializes all the arguments from the service request. \param action Defines the request having arguments to be serialized. \return Serialized arguments in byte array. */ QByteArray XQServiceRequest::serializeArguments(const XQServiceRequest &action) { XQSERVICE_DEBUG_PRINT("XQServiceRequest::serializeArguments"); QByteArray ret; QBuffer *buffer = new QBuffer(&ret); buffer->open(QIODevice::WriteOnly); QDataStream stream(buffer); stream << action.mData->mArguments; delete buffer; return ret; }