Exemplo n.º 1
0
 QByteArray SimpleCrypt::encryptToByteArray(QByteArray plaintext)
 {
     if (m_keyParts.isEmpty()) {
         qWarning() << "No key set.";
         m_lastError = ErrorNoKeySet;
         return QByteArray();
     }
  
  
     QByteArray ba = plaintext;
  
     CryptoFlags flags = CryptoFlagNone;
     if (m_compressionMode == CompressionAlways) {
         ba = qCompress(ba, 9); //maximum compression
         flags |= CryptoFlagCompression;
     } else if (m_compressionMode == CompressionAuto) {
         QByteArray compressed = qCompress(ba, 9);
         if (compressed.count() < ba.count()) {
             ba = compressed;
             flags |= CryptoFlagCompression;
         }
     }
  
     QByteArray integrityProtection;
     if (m_protectionMode == ProtectionChecksum) {
         flags |= CryptoFlagChecksum;
         QDataStream s(&integrityProtection, QIODevice::WriteOnly);
         s << qChecksum(ba.constData(), ba.length());
     } else if (m_protectionMode == ProtectionHash) {
         flags |= CryptoFlagHash;
         QCryptographicHash hash(QCryptographicHash::Sha1);
         hash.addData(ba);
  
         integrityProtection += hash.result();
     }
  
     //prepend a random char to the string
     char randomChar = char(qrand() & 0xFF);
     ba = randomChar + integrityProtection + ba;
  
     int pos(0);
     char lastChar(0);
  
     int cnt = ba.count();
  
     while (pos < cnt) {
         ba[pos] = ba.at(pos) ^ m_keyParts.at(pos % 8) ^ lastChar;
         lastChar = ba.at(pos);
         ++pos;
     }
  
     QByteArray resultArray;
     resultArray.append(char(0x03));  //version for future updates to algorithm
     resultArray.append(char(flags)); //encryption flags
     resultArray.append(ba);
  
     m_lastError = ErrorNoError;
     return resultArray;
 }
Exemplo n.º 2
0
void BugReportForm::generateReport(const QByteArray &buf)
{
	Messagebox msgbox;
	QFile output;
	QString filename=QFileInfo(QString(output_edt->text() +
									   GlobalAttributes::DIR_SEPARATOR +
									   GlobalAttributes::BUG_REPORT_FILE)
							   .arg(QDateTime::currentDateTime().toString(QString("_yyyyMMdd_hhmm")))).absoluteFilePath();

	//Opens the file for writting
	output.setFileName(filename);
	output.open(QFile::WriteOnly);

	if(!output.isOpen())
		msgbox.show(Exception::getErrorMessage(ERR_FILE_DIR_NOT_WRITTEN).arg(filename), Messagebox::ERROR_ICON);
	else
	{
		QByteArray comp_buf;

		//Compress the buffer (using zlib) in a compression rate at 8
		comp_buf=qCompress(buf, 8);

		//Saves the buffer
		output.write(comp_buf.data(), comp_buf.size());
		output.close();

		msgbox.show(trUtf8("Bug report successfuly generated! Please, send the file <strong>%1</strong> to <em>%2</em> in order be analyzed. Thank you for the collaboration!").arg(filename).arg(GlobalAttributes::BUG_REPORT_EMAIL),
					Messagebox::INFO_ICON);
	}
}
void KMoneyThingMainWidget::slotSave()
{
  KTempFile temp;
  QString fileName = mCurrentFile->kurl().path();
  
  if (fileName == "")
  {
    slotSaveAs();
    return;
  }
  
  if (!mCurrentFile->kurl().isLocalFile())
  {
    fileName = temp.name();
  }
  
  emit(setStatus(i18n("Saving file...")));
  QByteArray dump = qCompress(mCurrentFile->dump());
  QFile file(fileName);
  file.open(IO_WriteOnly);
  QDataStream stream(&file);
  stream << (QString) "KMoneyThingFile" << dump;
  file.close();
  
  if (!mCurrentFile->kurl().isLocalFile())
  {
    emit(setStatus(i18n("Uploading file...")));
    if (!KIO::NetAccess::upload(fileName, mCurrentFile->kurl(), this))
      KMessageBox::error(this, i18n("Failed to upload file."));
  }
  
  temp.unlink();
  
  emit(setStatus(i18n("Ready.")));
}
Exemplo n.º 4
0
bool JArchive::writeData(const QString &key,const QByteArray &data,bool compress,const QString &data_type) {
	QByteArray data2;
	if (compress) data2=qCompress(data);
	
	QString tmp=key;
	if (!d->m_group_prefix.isEmpty())
		tmp=d->m_group_prefix+"/"+key;
	QByteArray key2=tmp.toAscii();
	QByteArray data_type2=data_type.toAscii();
	qint32 length_of_header=4+4+4+4+4+key2.count()+4+4+data_type2.count();
	qint32 length_of_data=data.count();
	qint32 compressed_length_of_data=length_of_data;
	if (compress) {
		compressed_length_of_data=data2.count();
	}
	qint32 length_of_key=key2.count();
	qint32 is_compressed=0;
	if (compress) is_compressed=1;
	qint32 code=JARCHIVE_BEGIN_RECORD_CODE;
	qint32 length_of_data_type=data_type2.count();
	
	d->write_int32(code); //4
	d->write_int32(length_of_header); //4
	d->write_int32(compressed_length_of_data); //4
	d->write_int32(length_of_data); //4
	d->write_int32(length_of_key); //4
	d->write_bytes(key2); //length_of_key
	d->write_int32(is_compressed); //4
	d->write_int32(length_of_data_type); //4
	d->write_bytes(data_type2); //length_of_data_type
	if (compress) d->write_bytes(data2);
	else d->write_bytes(data);
	return true;
}
Exemplo n.º 5
0
void Socket::sendData(const QByteArray &content)
{
    if(socket->state() == QAbstractSocket::ConnectedState){
        QByteArray buffer;
        if(compressed_){
            buffer = qCompress(content);
        }else{
            buffer = content;
        }
        quint32 length = buffer.length()+1; // one more byte to
                                            // store extra information
        uchar c1, c2, c3, c4;
        c1 = length & 0xFF;
        length >>= 8;
        c2 = length & 0xFF;
        length >>= 8;
        c3 = length & 0xFF;
        length >>= 8;
        c4 = length & 0xFF;

        socket->putChar(c4);
        socket->putChar(c3);
        socket->putChar(c2);
        socket->putChar(c1);
        // lowest bit for compressed or not
        if(compressed_){
            socket->putChar(0x1);
        }else{
            socket->putChar(0);
        }
        socket->write(buffer);
    }
Exemplo n.º 6
0
// Save the prepared API information.
bool QsciAPIs::savePrepared(const QString &filename) const
{
    QString pname = prepName(filename, true);

    if (pname.isEmpty())
        return false;

    // Write the prepared data to a memory buffer.
    QByteArray pdata;
    QDataStream pds(&pdata, QIODevice::WriteOnly);

    // Use a serialisation format supported by Qt v3.0 and later.
    pds.setVersion(QDataStream::Qt_3_0);
    pds << PreparedDataFormatVersion;
    pds << lexer()->lexer();
    pds << prep->wdict;
    pds << prep->raw_apis;

    // Compress the data and write it.
    QFile pf(pname);

    if (!pf.open(QIODevice::WriteOnly|QIODevice::Truncate))
        return false;

    if (pf.write(qCompress(pdata)) < 0)
    {
        pf.close();
        return false;
    }

    pf.close();
    return true;
}
Exemplo n.º 7
0
bool Vocabulary::save( const QString& filename ) const {
    QByteArray data;

    QDataStream out( &data, QIODevice::WriteOnly );
    out.setVersion( QDataStream::Qt_2_1 );

    // 0x0010 means 0.10.x version.  
    out << qint32( Vocabulary::magicNumber ) << qint16( 0x0010 ) << *this;

    QByteArray compressedData( qCompress( data ) ); 

    QFile dataFile( filename );
    QFileInfo dataFileInfo( dataFile );
    QDir dataFileDir( dataFileInfo.absoluteDir() );

    if( !dataFileDir.mkpath( dataFileDir.path() ) )
        return( false );

    if( !dataFile.open( QIODevice::WriteOnly ) )
        return( false );

    int ret = dataFile.write( compressedData );
    dataFile.close();

    if( ret == -1 || dataFile.error() != QFile::NoError ) {
        dataFile.unsetError();
        return( false );
    }

    return( true );
}
Exemplo n.º 8
0
bool Emu::saveState(const QString &statePath)
{
	emsl.save = true;

	QByteArray data;
	data.reserve(10*1024*1024);

	QDataStream s(&data, QIODevice::WriteOnly);
	s.setByteOrder(QDataStream::LittleEndian);
	s.setFloatingPointPrecision(QDataStream::SinglePrecision);
	if (!saveInternal(&s))
		return false;

	QFile file(statePath);
	if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
		emsl.error = tr("Could not open file for writing.");
		return false;
	}

	s.setDevice(&file);
	s << frame().copy(videoSrcRect().toRect());
	QByteArray compressed = qCompress(data);
	bool ok = (file.write(compressed) == compressed.size());
	file.close();
	if (!ok)
		file.remove();
	return ok;
}
Exemplo n.º 9
0
QByteArray ourtrackserv::Serialize(const QVector<MainListItem> &items)
{
  // Результирующий буффер
  QByteArray buffer;
  QDataStream out(&buffer, QIODevice::WriteOnly);

  QMap<quint16, QVariant> m;  // Карта для записи элементов класса для последующей сериализации
  int counter = 0;            // Количество записей в карту (используется как ключ)

  // Добавляем количество элементов (потребуется для десериализации)
  m.insert(counter++, items.size());

  // Добавляем все элементы
  for (auto it = items.begin(); it != items.end(); ++it)
  {
    m.insert(counter++, it->id);
    m.insert(counter++, it->category);
    m.insert(counter++, it->name);
    m.insert(counter++, it->description);
    m.insert(counter++, it->size);
    m.insert(counter++, it->reg_time);
    m.insert(counter++, it->hash);
    m.insert(counter++, it->user_id);
    m.insert(counter++, it->download);
    m.insert(counter++, it->liked);
  }

  out << m;
  return  qCompress(buffer, 0);
}
Exemplo n.º 10
0
static ulong embedData( QTextStream& out, const uchar* input, int nbytes )
{
#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
    QByteArray bazip( qCompress( input, nbytes ) );
    ulong len = bazip.size();
#else
    ulong len = nbytes;
#endif
    static const char hexdigits[] = "0123456789abcdef";
    QString s;
    for ( int i=0; i<(int)len; i++ ) {
	if ( (i%14) == 0 ) {
	    s += "\n    ";
	    out << (const char*)s;
	    s.truncate( 0 );
	}
	uint v = (uchar)
#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
		 bazip
#else
		 input
#endif
		 [i];
	s += "0x";
	s += hexdigits[(v >> 4) & 15];
	s += hexdigits[v & 15];
	if ( i < (int)len-1 )
	    s += ',';
    }
    if ( s.length() )
	out << (const char*)s;
    return len;
}
Exemplo n.º 11
0
bool OctreePacketData::compressContent() { 
    PerformanceWarning warn(false, "OctreePacketData::compressContent()", false, &_compressContentTime, &_compressContentCalls);
    
    // without compression, we always pass...
    if (!_enableCompression) {
        return true;
    }

    _bytesInUseLastCheck = _bytesInUse;

    bool success = false;
    const int MAX_COMPRESSION = 9;

    // we only want to compress the data payload, not the message header
    const uchar* uncompressedData = &_uncompressed[0];
    int uncompressedSize = _bytesInUse;

    QByteArray compressedData = qCompress(uncompressedData, uncompressedSize, MAX_COMPRESSION);

    if (compressedData.size() < (int)MAX_OCTREE_PACKET_DATA_SIZE) {
        _compressedBytes = compressedData.size();
        for (int i = 0; i < _compressedBytes; i++) {
            _compressed[i] = compressedData[i];
        }
        _dirty = false;
        success = true;
    }
    return success;
}
Exemplo n.º 12
0
void Buddha::saveScreenshot ( QString fileName ) {
	QImage out( (uchar*) RGBImage, w, h, QImage::Format_RGB32 );
	out.save( fileName, "PNG" );

	QByteArray compress = qCompress( (const uchar*) RGBImage, w * h * sizeof(int), 9 );
	cout << "Compressed size vs Full: " << compress.size() << " " << w * h * sizeof(int) << endl;
}
bool TSessionRedisStore::store(TSession &session)
{
    QByteArray data;
    QDataStream ds(&data, QIODevice::WriteOnly);
    ds << *static_cast<const QVariantMap *>(&session);
    data = qCompress(data, 1).toBase64();

#ifndef TF_NO_DEBUG
    {
        QByteArray badummy;
        QDataStream dsdmy(&badummy, QIODevice::ReadWrite);
        dsdmy << *static_cast<const QVariantMap *>(&session);

        TSession dummy;
        dsdmy.device()->seek(0);
        dsdmy >> *static_cast<QVariantMap *>(&dummy);
        if (dsdmy.status() != QDataStream::Ok) {
            tSystemError("Failed to store a session into the cookie store. Must set objects that can be serialized.");
        }
    }
#endif

    TRedis redis;
    tSystemDebug("TSessionRedisStore::store  id:%s", session.id().data());
    return redis.setEx('_' + session.id(), data, lifeTimeSecs());
}
Exemplo n.º 14
0
void writeVector(QDataStream& out, char ch, QVector<T> vec) {
    // Minimum number of bytes to consider compressing
    const int ATTEMPT_COMPRESSION_THRESHOLD_BYTES = 2000;

    out.device()->write(&ch, 1);
    out << (int32_t)vec.length();

    auto data { QByteArray::fromRawData((const char*)vec.constData(), vec.length() * sizeof(T)) };

    if (data.size() >= ATTEMPT_COMPRESSION_THRESHOLD_BYTES) {
        auto compressedDataWithLength { qCompress(data) };

        // qCompress packs a length uint32 at the beginning of the buffer, but the FBX format
        // does not expect it. This removes it.
        auto compressedData = QByteArray::fromRawData(
            compressedDataWithLength.constData() + sizeof(uint32_t), compressedDataWithLength.size() - sizeof(uint32_t));

        if (compressedData.size() < data.size()) {
            out << FBX_PROPERTY_COMPRESSED_FLAG;
            out << (int32_t)compressedData.size();
            out.writeRawData(compressedData.constData(), compressedData.size());
            return;
        }
    }

    out << FBX_PROPERTY_UNCOMPRESSED_FLAG;
    out << (int32_t)0;
    out.writeRawData(data.constData(), data.size());
}
Exemplo n.º 15
0
	void MTcpSocket::sendPacketInternal(const Mara::MPacket *pPacket)
	{
		QByteArray data;
		bool compressed = pPacket->compressed();

		if(compressed)
		{
			QByteArray uncompressed(*(pPacket->serialize()));
			data = qCompress(uncompressed);
			qDebug("Compression Ratio: %d/%d", data.size(), uncompressed.size());
		}
		else
		{
			data = *(pPacket->serialize());
		}

		{
			QMutexLocker lock(&_mutex);

			write(_packetHeaderBytes);
			_socketStream << data.length();
			_socketStream << pPacket->type();

			write(data);

			_socketStream << qChecksum(data.constData(), data.length());
			_socketStream << compressed;
		}

		if(pPacket->deleteOnSend()) delete pPacket;
	}
Exemplo n.º 16
0
bool FileManager::serialize(Serialize *serializable, const QString &path)
{
    this->setFilePath(path);

    if(!this->fileRemove())
    {
        qDebug("Could not remove the old found file");
        return false;
    }

    this->setFilePath(path);

    if(!this->fileOpen(QIODevice::WriteOnly))
    {
        qDebug("File could not be opened in write only mode.");
        return false;
    }

    QDataStream stream(this->refFile());

    QByteArray bytes;
    QBuffer buffer(&bytes);
    buffer.open(QBuffer::ReadWrite);
    serializable->serialize(&buffer);

    stream << qCompress(bytes,7);
    serializable->setFileInfo(path);

    return this->fileClose();
}
Exemplo n.º 17
0
bool DataFile::writeFile( const QString& filename )
{
	const QString fullName = nameWithExtension( filename );
	const QString fullNameTemp = fullName + ".new";
	const QString fullNameBak = fullName + ".bak";

	QFile outfile( fullNameTemp );

	if( !outfile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
	{
		if( Engine::hasGUI() )
		{
			QMessageBox::critical( NULL,
				SongEditor::tr( "Could not write file" ),
				SongEditor::tr( "Could not open %1 for writing. You probably are not permitted to "
								"write to this file. Please make sure you have write-access to "
								"the file and try again." ).arg( fullName ) );
		}

		return false;
	}

	if( fullName.section( '.', -1 ) == "mmpz" )
	{
		QString xml;
		QTextStream ts( &xml );
		write( ts );
		outfile.write( qCompress( xml.toUtf8() ) );
	}
	else
	{
		QTextStream ts( &outfile );
		write( ts );
	}

	outfile.close();

	// make sure the file has been written correctly
	if( QFileInfo( outfile.fileName() ).size() > 0 )
	{
		if( ConfigManager::inst()->value( "app", "disablebackup" ).toInt() )
		{
			// remove current file
			QFile::remove( fullName );
		}
		else
		{
			// remove old backup file
			QFile::remove( fullNameBak );
			// move current file to backup file
			QFile::rename( fullName, fullNameBak );
		}
		// move temporary file to current file
		QFile::rename( fullNameTemp, fullName );

		return true;
	}

	return false;
}
Exemplo n.º 18
0
// 返回压缩后的大小
static size_t enet_simple_compress(void * context, const ENetBuffer * inBuffers, size_t inBufferCount,
                                   size_t inLimit, enet_uint8 * outData, size_t outLimit)
{
    // return 0;
    if (inLimit < 200) return 0;
    
    qDebug()<<inBufferCount<<inLimit<<outLimit;
    size_t cpsz = 0;
    QByteArray inbuf;
    
    size_t inlen = 0;
    for (int i = 0; i < inBufferCount; i ++) {
        const ENetBuffer *buffer = &inBuffers[i];
        if (inlen + buffer->dataLength > inLimit) {
            break;
        }
        inlen += buffer->dataLength;
        inbuf.append((const char*)buffer->data, buffer->dataLength);
    }

    QByteArray outbuf = qCompress(inbuf, 7);
    memcpy(outData, outbuf.data(), outbuf.length());

    if (outbuf.length() > outLimit) {
        qDebug()<<"invlid compress:"<<outbuf.length()<<outLimit<<inlen;
        return 0;
    }
    return outbuf.length();
    return 0;
}
Exemplo n.º 19
0
void MainWindow::on_streamButton_clicked()
{
    if (QFile::exists(ui->fileEdit->text()) != true)
    {
        QMessageBox::critical(this, "Critical", QString(FILE_NOT_FOUND).arg(ui->fileEdit->text()));
        return;
    }

    QFile *file = new QFile(ui->fileEdit->text());
    if (!file->open(QIODevice::ReadOnly))
    {
        delete file;
        QMessageBox::critical(this, "Critical", QString(CANT_OPEN_TO_READ).arg(ui->fileEdit->text()));
        return;
    }

    if (file->size() == 0)
    {
        file->close();
        delete file;
        QMessageBox::critical(this, "Critical", QString(FILE_IS_EMPTY).arg(ui->fileEdit->text()));
    }

    QByteArray *data = new QByteArray();
    *data = file->readAll();
    file->close();
    delete file;

    QByteArray *data_compressed = new QByteArray();
    *data_compressed = qCompress(*data).remove(0, 4);

    int size = data->size();
    int size_compressed = data_compressed->size();
    if(size_compressed < size) {
        delete data;
        data = data_compressed;
    }
    else {
        delete data_compressed;
        size_compressed = size;
    }

    QByteArray *args = new QByteArray();
    //*args = ui->argEdit->text().toAscii(); //toAscii() has been depreciated in qt5
    *args = ui->argEdit->text().toLatin1(); //toAscii() has been replaced by toLatin1()
    int args_len = 0;
    if(!args->isEmpty())
        args_len = args->size() + 1;

    ui->progressBar->setMaximum(size_compressed);
    ui->progressBar->setEnabled(true);

    wiiStreamThread = new QWiiStreamThread(ui->hostEdit->text(), data, size, size_compressed, args, args_len);
    connect(wiiStreamThread, SIGNAL(transferFail(QString)), this, SLOT(transferFail(QString)));
    connect(wiiStreamThread, SIGNAL(transferDone()), this, SLOT(transferDone()));
    connect(wiiStreamThread, SIGNAL(progressBarPosition(int)), this, SLOT(progressBarPosition(int)));
    wiiStreamThread->start();
    ui->streamButton->setEnabled(false);
}
Exemplo n.º 20
0
int DatabaseManager::commitDetection(DetectionJob* job) {

	SDPASSERT(Logger::instancePtr());
	int newID = -1;

	if ( !__db.isOpen() ) {
		Logger::instancePtr()->addMessage(Logger::CRITICAL, __func__,
		    QString("Failed to store detection job %1. Database couldn't be opened.")
		        .arg(job->id()));
		return newID;
	}

	QByteArray buffer;
	QDataStream stream(&buffer, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(4, 8, 0))
	stream.setVersion(QDataStream::Qt_4_8);
#else
	stream.setVersion(QDataStream::Qt_4_6);
#endif
	job->toDataStream(stream);

	QSqlQuery query;

	if ( detectionExists(job->id()) ) {
		query.prepare("UPDATE main.Detection SET return_code=:jretcode, "
			"data=:jdata WHERE id = :jid");
		query.bindValue("jretcode", job->runExitCode());
		query.bindValue("jdata", qCompress(buffer));
		query.bindValue("jid", job->id());
	}
	else {
		query.prepare("INSERT INTO main.Detection (id, return_code, data) "
			"VALUES (:jid, :jretcode, :jdata)");
		query.bindValue("jid", job->id());
		query.bindValue("jretcode", job->runExitCode());
		query.bindValue("jdata", qCompress(buffer));
	}

	if ( query.exec() )
		newID = query.lastInsertId().toInt();
	else
		Logger::instancePtr()->addMessage(Logger::CRITICAL, __func__,
		    QString("Query failed: %1").arg(query.executedQuery()));

	return newID;
}
Exemplo n.º 21
0
ImageStream & ImageStream::operator<<(const sp_i3matrix * mask){
  QDataStream & s = *this;
  QByteArray compressedMask = qCompress((const uchar *)mask->data,
					 sp_i3matrix_size(mask)*sizeof(int),m_maskCompression);
  qDebug("Compressed i3matrix from %lld to %d bytes",sp_i3matrix_size(mask)*sizeof(int),compressedMask.size());
  s.writeBytes(compressedMask.constData(),compressedMask.size());
  return *this;
}
Exemplo n.º 22
0
QByteArray& TasMessage::dataCompressed()
{
    if(!mCompressed){
        mData = qCompress(mData, 9);
        mCompressed = true;
    }
    return mData;
}
Exemplo n.º 23
0
int DatabaseManager::commitTrigger(Trigger* trig) {

	SDPASSERT(Logger::instancePtr());
	int newID = -1;

	if ( !__db.isOpen() ) {
		Logger::instancePtr()->addMessage(Logger::CRITICAL, __func__,
		    QString("Failed to store trigger %1. Database couldn't be opened.")
		        .arg(trig->id()));
		return newID;
	}

	QByteArray buffer;
	QDataStream stream(&buffer, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(4, 8, 0))
	stream.setVersion(QDataStream::Qt_4_8);
#else
	stream.setVersion(QDataStream::Qt_4_6);
#endif
	trig->toDataStream(stream);

	QSqlQuery query;

	if ( triggerExists(trig->id()) ) {
		query.prepare("UPDATE main.Trigger SET status=:tstatus, data=:tdata WHERE id = :tid");
		query.bindValue("tstatus", static_cast<int>(trig->status()));
		query.bindValue("tdata", qCompress(buffer));
		query.bindValue("tid", trig->id());
	}
	else {
		query.prepare("INSERT INTO main.Trigger (id, status, data, detection_id) "
			"VALUES (:tid, :tstatus, :tdata, :jid)");
		query.bindValue("tid", trig->id());
		query.bindValue("tstatus", static_cast<int>(trig->status()));
		query.bindValue("tdata", qCompress(buffer));
		query.bindValue("jid", trig->jobID());
	}

	if ( query.exec() )
		newID = query.lastInsertId().toInt();
	else
		Logger::instancePtr()->addMessage(Logger::CRITICAL, __func__,
		    QString("Query failed: %1").arg(query.executedQuery()));

	return newID;
}
QByteArray SimpleTaskManager::STToBinary(SimpleTask *st)
{
#ifdef COMPRESS
    return qCompress(STToQString(st).toUtf8());
#else
    return STToQString(st).toUtf8();
#endif
}
Exemplo n.º 25
0
void SvgItem::save(QXmlStreamWriter &xml) {
  xml.writeStartElement("svg");
  ViewItem::save(xml);
  xml.writeStartElement("data");
  xml.writeCharacters(qCompress(_svgData).toBase64());
  xml.writeEndElement();
  xml.writeEndElement();
}
Exemplo n.º 26
0
QByteArray ArrayBufferPrototype::compress() const {
    // Compresses the ArrayBuffer data in Zlib format.
    QByteArray* ba = thisArrayBuffer();

    QByteArray buffer = qCompress(*ba);
    buffer.remove(QCOMPRESS_HEADER_POSITION, QCOMPRESS_HEADER_SIZE);  // Remove Qt's custom header to make it proper Zlib.

    return buffer;
}
Exemplo n.º 27
0
QString CMisc::Encrypt(const QString& src)
{
	QByteArray byteArray = src.toLatin1();
	QByteArray result = qCompress(byteArray);
	QString strEncryBuffer = result.toBase64();
	qDebug() << strEncryBuffer;

	return strEncryBuffer;
}
Exemplo n.º 28
0
QString BaseStateAbstract::byteArrayToString(QByteArray data, bool compress)
{
    QString ret;
    if (compress)
        data = qCompress(data,9).toBase64();
    else
        data = data.toBase64();
    ret = QString::fromUtf8(data.constData(), data.size());
    return ret;
}
void VIFrame::set_pics( QPixmap barcode )
{
      if (barcode.isNull()) {
        return;
      }
      QByteArray bytes;
      QBuffer buffer(&bytes);
      buffer.open(QIODevice::WriteOnly);
      barcode.save(&buffer,"PNG");
      dimg = qCompress(bytes,9);
} 
Exemplo n.º 30
0
	// 4- For each mFile in list: add mFile path and compressed binary data
	foreach (QFileInfo const &fileInfo, filesList) {
		QFile file(dir.absolutePath() + "/" + fileInfo.fileName());
		if (!file.open(QIODevice::ReadOnly)) { // couldn't open file
			return false;
		}

		dataStream << QString(prefix + "/" + fileInfo.fileName());
		dataStream << qCompress(file.readAll());

		file.close();
	}