Example #1
0
static JSValueRef pixmapToDataUrl(JSContextRef context, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    QVariant& data = *static_cast<QVariant*>(JSObjectGetPrivate(object));
    QByteArray byteArray;
    QBuffer buffer(&byteArray);
    toImage(data).save(&buffer, "PNG");
    QByteArray encoded = QByteArray("data:image/png;base64,") + byteArray.toBase64();
    JSRetainPtr<JSStringRef> str(Adopt, JSStringCreateWithUTF8CString(encoded.constData()));
    JSValueRef value = JSValueMakeString(context, str.get());

    return value;
}
Example #2
0
QString QgsRenderChecker::imageToHash( QString theImageFile )
{
  QImage myImage;
  myImage.load( theImageFile );
  QByteArray myByteArray;
  QBuffer myBuffer( &myByteArray );
  myImage.save( &myBuffer, "PNG" );
  QString myImageString = QString::fromUtf8( myByteArray.toBase64().data() );
  QCryptographicHash myHash( QCryptographicHash::Md5 );
  myHash.addData( myImageString.toUtf8() );
  return myHash.result().toHex().constData();
}
Example #3
0
QByteArray IconFactory::toByteArray(const QIcon &icon) {
  QByteArray array;
  QBuffer buffer(&array);
  buffer.open(QIODevice::WriteOnly);

  QDataStream out(&buffer);
  out.setVersion(QDataStream::Qt_4_7);
  out << icon;

  buffer.close();
  return array.toBase64();
}
Example #4
0
/*!
	\internal
 */
QByteArray WebSocket::generateKey() const
{
	QByteArray key;

	for (int i = 0; i < 4; ++i)
	{
		quint32 tmp = generateRandomNumber();
		key.append(static_cast<const char *>(static_cast<const void *>(&tmp)), sizeof(quint32));
	}

	return key.toBase64();
}
Example #5
0
void Server::messageFromClient(QByteArray message,QString client){
    qDebug()<<ENCAPS(tr("[server] incoming"))<<message.toBase64()<<ENCAPS(tr("from"))<<client;
    QString header;
    QDataStream stream(message);
    stream >> header;
    qDebug()<<header;
    if(0==header.compare("SET_VELOCITY")){
        qDebug()<<ENCAPS(tr("Got velocity data!"));
        int i;
        stream >> i;
        stream >> spaceObjects[client][i].velocity;
    }
Example #6
0
// Only used for audio files, so we don't bother with compression.
const char *DISK_file_to_base64(const wchar_t *wfilename){
  disk_t *disk = DISK_open_binary_for_reading(wfilename);

  if (disk==NULL)
    return NULL;

  QByteArray data = disk->file()->readAll();

  DISK_close_and_delete(disk);

  return talloc_strdup(data.toBase64().constData());
}
Example #7
0
bool LoginJobPrivate::startAuthentication()
{
  //SASL authentication
  if ( !initSASL() ) {
    q->setError( LoginJob::UserDefinedError );
    q->setErrorText( i18n( "Login failed, client cannot initialize the SASL library." ) );
    return false;
  }

  authState = LoginJobPrivate::Authenticate;
  const char *out = 0;
  uint outlen = 0;
  const char *mechusing = 0;

  int result = sasl_client_new( "imap", m_session->hostName().toLatin1(), 0, 0, callbacks, 0, &conn );
  if ( result != SASL_OK ) {
    kDebug() << "sasl_client_new failed with:" << result;
    q->setError( LoginJob::UserDefinedError );
    q->setErrorText( QString::fromUtf8( sasl_errdetail( conn ) ) );
    return false;
  }

  do {
    result = sasl_client_start( conn, authMode.toLatin1(), &client_interact, capabilities.contains( "SASL-IR" ) ? &out : 0, &outlen, &mechusing );

    if ( result == SASL_INTERACT ) {
      if ( !sasl_interact() ) {
        sasl_dispose( &conn );
        q->setError( LoginJob::UserDefinedError ); //TODO: check up the actual error
        return false;
      }
    }
  } while ( result == SASL_INTERACT );

  if ( result != SASL_CONTINUE && result != SASL_OK ) {
    kDebug() << "sasl_client_start failed with:" << result;
    q->setError( LoginJob::UserDefinedError );
    q->setErrorText( QString::fromUtf8( sasl_errdetail( conn ) ) );
    sasl_dispose( &conn );
    return false;
  }

  QByteArray tmp = QByteArray::fromRawData( out, outlen );
  QByteArray challenge = tmp.toBase64();

  if ( challenge.isEmpty() ) {
    tags << sessionInternal()->sendCommand( "AUTHENTICATE", authMode.toLatin1() );
  } else {
    tags << sessionInternal()->sendCommand( "AUTHENTICATE", authMode.toLatin1() + ' ' + challenge );
  }

  return true;
}
Example #8
0
QVariant SettingsManager::variantEncode(const QVariant &v) const
{
    if (v.type() == QVariant::ByteArray) {
        QByteArray data = v.toByteArray();
        data = data.toBase64();

        return data;
    }
    else {
        return v;
    }
}
Example #9
0
//=============================================================================
//=============================================================================
QString Crypt::encrypt(QString str)
{
  FUNC_DEBUG;  
  if (_key.isEmpty() || str.isEmpty()) { return QString(); }
  
  QByteArray baEncrypt = str.toLatin1();
  for (int i = 0; i < baEncrypt.count(); i++) {
    baEncrypt[i] = baEncrypt.at(i) ^ _key.at(i % _key.size());
  }
  baEncrypt = qCompress(baEncrypt,9);
  return QString(baEncrypt.toBase64());
}
Example #10
0
DraggableElement::DraggableElement(
		MainWindow &mainWindow
		, const PaletteElement &data
		, bool iconsOnly
		, const EditorManagerInterface &editorManagerProxy
		, QWidget *parent
		)
	: QWidget(parent)
	, mData(data)
	, mEditorManagerProxy(editorManagerProxy)
	, mMainWindow(mainWindow)
{
	QHBoxLayout *layout = new QHBoxLayout(this);
	layout->setContentsMargins(0, 4, 0, 4);

	const int size = iconsOnly ? 50 : 30;
	mLabel = new QLabel(this);
	mLabel->setPixmap(mData.icon().pixmap(size - 2, size - 2));
	layout->addWidget(mLabel);

	if (!iconsOnly) {
		QLabel *text = new QLabel(this);
		text->setText(mData.name());
		layout->addWidget(text);
		layout->addStretch();
	}

	setLayout(layout);

	QString description = mData.description();
	if (!description.isEmpty()) {
		const QString rawGesture = mEditorManagerProxy.mouseGesture(data.id());
		if (!rawGesture.isEmpty() && qReal::SettingsManager::value("gesturesEnabled").toBool()) {
			const QSize size(gestureTipSize, gestureTipSize);
			gestures::GesturePainter painter(rawGesture, Qt::white, Qt::blue, gestureTipSize);
			const QPixmap gesture = painter.pixmap(size, QIcon::Mode::Normal, QIcon::State::Off);
			QByteArray byteArray;
			QBuffer buffer(&byteArray);
			gesture.save(&buffer, "PNG");
			const QString gestureDescription = tr("Mouse gesture");
			description += QString("<br><table><tr><td valign='middle'>%1:&nbsp;&nbsp;&nbsp;</td>"\
					"<td><img src=\"data:image/png;base64,%2\"/></td></tr></table>")
							.arg(gestureDescription, QString(byteArray.toBase64()));
		}

		setToolTip(QString("<body>%1</body>").arg(description));
	}

	setCursor(Qt::OpenHandCursor);
	setAttribute(Qt::WA_AcceptTouchEvents);
	setObjectName(mData.name());
}
Example #11
0
QByteArray QAuthenticatorPrivate::calculateResponse(const QByteArray &requestMethod, const QByteArray &path)
{
    QByteArray response;
    const char *methodString = 0;
    switch(method) {
    case QAuthenticatorPrivate::None:
        methodString = "";
        phase = Done;
        break;
    case QAuthenticatorPrivate::Plain:
        response = '\0' + user.toUtf8() + '\0' + password.toUtf8();
        phase = Done;
        break;
    case QAuthenticatorPrivate::Basic:
        methodString = "Basic ";
        response = user.toLatin1() + ':' + password.toLatin1();
        response = response.toBase64();
        phase = Done;
        break;
    case QAuthenticatorPrivate::Login:
        if (challenge.contains("VXNlciBOYW1lAA==")) {
            response = user.toUtf8().toBase64();
            phase = Phase2;
        } else if (challenge.contains("UGFzc3dvcmQA")) {
            response = password.toUtf8().toBase64();
            phase = Done;
        }
        break;
    case QAuthenticatorPrivate::CramMd5:
        break;
    case QAuthenticatorPrivate::DigestMd5:
        methodString = "Digest ";
        response = digestMd5Response(challenge, requestMethod, path);
        phase = Done;
        break;
    case QAuthenticatorPrivate::Ntlm:
        methodString = "NTLM ";
        if (challenge.isEmpty()) {
            response = qNtlmPhase1().toBase64();
            if (user.isEmpty())
                phase = Done;
            else
                phase = Phase2;
        } else {
            response = qNtlmPhase3(this, QByteArray::fromBase64(challenge)).toBase64();
            phase = Done;
        }

        break;
    }
    return QByteArray(methodString) + response;
}
Example #12
0
// static
bool Sandbox::createSecurityToken(const QString& canonicalPath,
                                  bool isDirectory) {
    if (sDebug) {
        qDebug() << "createSecurityToken" << canonicalPath << isDirectory;
    }
    if (!enabled()) {
        return false;
    }
    QMutexLocker locker(&s_mutex);
    if (s_pSandboxPermissions == NULL) {
        return false;
    }

#ifdef Q_OS_MAC
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
    CFURLRef url = CFURLCreateWithFileSystemPath(
            kCFAllocatorDefault, QStringToCFString(canonicalPath),
            kCFURLPOSIXPathStyle, isDirectory);
    if (url) {
        CFErrorRef error = NULL;
        CFDataRef bookmark = CFURLCreateBookmarkData(
                kCFAllocatorDefault, url,
                kCFURLBookmarkCreationWithSecurityScope, nil, nil, &error);
        CFRelease(url);
        if (bookmark) {
            QByteArray bookmarkBA = QByteArray(
                    reinterpret_cast<const char*>(CFDataGetBytePtr(bookmark)),
                    CFDataGetLength(bookmark));

            QString bookmarkBase64 = QString(bookmarkBA.toBase64());

            s_pSandboxPermissions->set(keyForCanonicalPath(canonicalPath),
                                       bookmarkBase64);
            CFRelease(bookmark);
            return true;
        } else {
            if (sDebug) {
                qDebug() << "Failed to create security-scoped bookmark for" << canonicalPath;
                if (error != NULL) {
                    qDebug() << "Error:" << CFStringToQString(CFErrorCopyDescription(error));
                }
            }
        }
    } else {
        if (sDebug) {
            qDebug() << "Failed to create security-scoped bookmark URL for" << canonicalPath;
        }
    }
#endif
#endif
    return false;
}
Example #13
0
void ClientWidget::messageFromServer(QByteArray message){
    qDebug()<<ENCAPS(tr("incoming"))<<message.toBase64();
    QString header;
    QDataStream stream(message);
    stream >> header;
    qDebug()<<header;
    if(0==header.compare("SIMULATION_UPDATE_DATA")){
        qDebug()<<ENCAPS(tr("Got simulation data!"));
        int size,i;
        stream >> size;
        stream >> i;
        stream >> me;
    }
Example #14
0
QString BaseStateAbstract::write(QString val, bool compress)
{
    QString ret;
    QByteArray data = val.toUtf8();

    if (compress)
        data = qCompress(data,9).toBase64().prepend(COMPRESSED_MARKER); // prepending # to signify the string is compressed
    else
        data = data.toBase64();

    ret = QString::fromUtf8(data.constData(), data.size());
    return ret;
}
Example #15
0
void unitFaceModel::serialiseLeaves(const QList<QList<QList<int> > >& allLeaves)
{
    QByteArray byteArray;
    QBuffer writeBuffer(&byteArray);
    writeBuffer.open(QIODevice::WriteOnly);
    QDataStream out(&writeBuffer);

    out << allLeaves;

    writeBuffer.close();

    serialisedLeaves = QString(byteArray.toBase64());
}
Example #16
0
 QString RecentItemsModel::serializeItems() {
     // historical reasons to have QQueue here
     // now only thing left is to be backward compatible
     QQueue<QString> items;
     for (auto &kv: m_LRUcache.data()) {
         items.enqueue(kv.first);
     }
     Q_ASSERT(m_LRUcache.size() <= m_MaxRecentItems);
     QByteArray raw;
     QDataStream ds(&raw, QIODevice::WriteOnly);
     ds << items;
     return QString::fromLatin1(raw.toBase64());
 }
Example #17
0
QByteArray AuthHelper::encodeBasicB64Auth( const QString& aUsername, const QString& aPassword ) const
{
    FUNCTION_CALL_TRACE;

    QByteArray in;

    in.append( aUsername );
    in.append( ':' );
    in.append( aPassword );

    return in.toBase64();

}
Example #18
0
    void TorrentActivity::saveState(KSharedConfigPtr cfg)
    {
        search_bar->saveState(cfg);
        group_view->saveState(cfg);
        group_switcher->saveState(cfg);
        qm->saveState(cfg);
        tool_views->saveState(cfg, "TorrentActivityBottomTabBar");
        magnet_view->saveState(cfg);

        KConfigGroup g = cfg->group("TorrentActivitySplitters");
        if (vsplit)
        {
            QByteArray data = vsplit->saveState();
            g.writeEntry("vsplit", data.toBase64());
        }

        if (hsplit)
        {
            QByteArray data = hsplit->saveState();
            g.writeEntry("hsplit", data.toBase64());
        }
    }
Example #19
0
void Connector::sendTextMess(QString msg)
{
    if(useAes){
        QJsonObject obj;
        QByteArray iv = QACrypt::genAesKey(128);
        obj["type"] = messType::data;
        obj["data"] = QString::fromLatin1(QACrypt::encrypt2(msg.toUtf8(), aesKey, iv).toBase64());
        obj["iv"] = QString::fromLatin1(iv.toBase64());
        QJsonDocument doc(obj);
        cliSocket.sendTextMessage(doc.toJson(QJsonDocument::Compact));
    } else
        cliSocket.sendTextMessage(msg);
}
void QgsLayerTreeModelLegendNode::exportSymbolToJson( const QgsLegendSettings &settings, const QgsRenderContext &, QJsonObject &json ) const
{
  const QIcon icon = data( Qt::DecorationRole ).value<QIcon>();
  if ( icon.isNull() )
    return;

  const QImage image( icon.pixmap( settings.symbolSize().width(), settings.symbolSize().height() ).toImage() );
  QByteArray byteArray;
  QBuffer buffer( &byteArray );
  image.save( &buffer, "PNG" );
  const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
  json[ "icon" ] = base64;
}
Example #21
0
bool
OsdCipher::_cipher(const QByteArray &byIn, QByteArray &byOut, bool bEncrypt)
{
    // Do I reeealy need to encrypt anything when the app is entirely sandboxed?

    if (bEncrypt) {
        byOut = byIn.toBase64();
    } else {
        byOut = QByteArray::fromBase64(byIn);
    }

    return (true);
}//OsdCipher::cipher
void UBAbstractPublisher::processAuthenticationTokenResponse(bool success, const QByteArray& payload)
{
    if (mTokenRequest)
        mTokenRequest->deleteLater();

    if (success)
    {
        /*
          <publishing-token>
            ...
            <token>iFzZIXhPxHTLhJeHWFF9BDVblMDWU546rpzoEEfxMSLrftMq444w4BuoisnNtRAjm6ht3hKUIHmMKA3xGN2Hlaof8tbYNLHmzf2R1dO439vnXFiHMPLBi7nFpSEPtBNJ</token>
            <uuid>26fea4c0-1319-012d-d0fc-001f5b3d920c</uuid>
            ...
          </publishing-token>
        */

        QDomDocument doc("publishing-token");
        doc.setContent(payload, false);

        QDomElement root = doc.documentElement();

        const QString token = root.firstChildElement("token").text();
        const QString uuid = root.firstChildElement("uuid").text();

        if (token.length() > 0 && uuid.length() > 0)
        {
            const QByteArray encrypted = encrypt(token);
            QString encryptedBase64 = QString::fromAscii(encrypted.toBase64());

            UBApplication::showMessage(tr("Found %1").arg(UBSettings::settings()->uniboardWebUrl->get().toString()), false);

            emit authenticated(QUuid(uuid), encryptedBase64);
        }
        else
        {
            qWarning() << "Authentication failed" << QString::fromUtf8(payload);

            emit authenticationFailure();

            UBApplication::showMessage(tr("Cannot Authenticate with %1").arg(UBSettings::settings()->uniboardWebUrl->get().toString()));
        }
    }
    else
    {
        qWarning() << "Authentication failed" << QString::fromUtf8(payload);

        emit authenticationFailure();

        UBApplication::showMessage(tr("Cannot Authenticate with %1").arg(UBSettings::settings()->uniboardWebUrl->get().toString()));
    }
}
Example #23
0
void HttpProxyPost::sock_connected()
{
#ifdef PROX_DEBUG
	fprintf(stderr, "HttpProxyPost: Connected\n");
#endif
	if(d->useSsl) {
		d->tls = new QCA::TLS(this);
		connect(d->tls, SIGNAL(readyRead()), SLOT(tls_readyRead()));
		connect(d->tls, SIGNAL(readyReadOutgoing()), SLOT(tls_readyReadOutgoing()));
		connect(d->tls, SIGNAL(error()), SLOT(tls_error()));
		d->tls->startClient();
	}

	d->lastAddress = d->sock.peerAddress();
	d->inHeader = true;
	d->headerLines.clear();

	QUrl u = d->url;

	// connected, now send the request
	QByteArray s;
	s += QByteArray("POST ") + d->url.toEncoded() + " HTTP/1.1\r\n";
	if(d->asProxy) {
		if(!d->user.isEmpty()) {
			QByteArray str = d->user.toUtf8() + ':' + d->pass.toUtf8();
			s += QByteArray("Proxy-Authorization: Basic ") + str.toBase64() + "\r\n";
		}
		s += "Pragma: no-cache\r\n";
		s += QByteArray("Host: ") + u.host().toUtf8() + "\r\n";
	}
	else {
		s += QByteArray("Host: ") + d->host.toUtf8() + "\r\n";
	}
	s += "Content-Type: application/x-www-form-urlencoded\r\n";
	s += QByteArray("Content-Length: ") + QByteArray::number(d->postdata.size()) + "\r\n";
	s += "\r\n";

	if(d->useSsl) {
		// write request
		d->tls->write(s);

		// write postdata
		d->tls->write(d->postdata);
	} else {
		// write request
		d->sock.write(s);

		// write postdata
		d->sock.write(d->postdata);
	}
}
Example #24
0
void Processor::writeBlock(const QByteArray &data)
{

    statsLock.lock();
    stats.incrInBlocks();
    statsLock.unlock();
    QByteArray temp = data;
    QByteArray temp2;
    QByteArray * outputval = nullptr;
    int i = 0;

    if (decode)
        temp = QByteArray::fromBase64(temp);

    for (i = 0; i < tlist.size(); i++) {
        if (i % 2 == 0)
            tlist.at(i)->transform(temp,temp2);
        else
            tlist.at(i)->transform(temp2,temp);
    }
    if (i % 2 == 0)
        outputval = &temp;
    else
        outputval = &temp2;

    if (!outputval->isEmpty()) {
        if (encode)
            *outputval = outputval->toBase64();
        outputval->append(separator);
        if (outputLock != 0)
            outputLock->lock();

        while (outputval->size() > 0) {
            int whatHasBeenDone = out->write(*outputval);
            if (whatHasBeenDone < 0) {
                logError(out->errorString(), this->metaObject()->className());
                break;
            }

            *outputval = outputval->remove(0,whatHasBeenDone);

        }

        if (outputLock != 0)
            outputLock->unlock();
        statsLock.lock();
        stats.incrOutBlocks();
        statsLock.unlock();
    }
}
Example #25
0
/*
 * This function generate first server challenge according to the digest mechanism for sasl authentification
 */
QByteArray StreamNegotiation::generateSecondChallengeReply()
{
    QByteArray secondChallenge = "rspauth=" + Sasl::generateResponseValue(m_map);

    QDomDocument replyDocument;

    QDomElement challenge = replyDocument.createElement("challenge");
    challenge.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl");
    challenge.appendChild(replyDocument.createTextNode(secondChallenge.toBase64()));

    replyDocument.appendChild(challenge);

    return replyDocument.toByteArray();
}
Example #26
0
void XmlWriter::writeVariant( QXmlStreamWriter &stream, const QVariant &value )
{
    ASSERT_LIMITED_VARIANT( value );

    if( value.isNull() || value.type() == QVariant::Invalid ) {
        stream.writeEmptyElement( "nil" );
    } else if( value.type() == QVariant::Bool ) {
        stream.writeTextElement( "boolean", value.toBool() ? "true" : "false" );
    } else if( value.type() == QVariant::ByteArray ) {
        stream.writeTextElement( "base64", value.toByteArray().toBase64() );
    } else if( value.type() == QVariant::Color ) {
        writeColor( stream, value.value<QColor>() );
    } else if( value.type() == QVariant::Date ) {
        stream.writeTextElement( "date", value.toDate().toString( Qt::ISODate ) );
    } else if( value.type() == QVariant::DateTime ) {
        stream.writeTextElement( "datetime", value.toDateTime().toString( Qt::ISODate ) );
    } else if( value.type() == QVariant::Double ) {
        stream.writeTextElement( "double", QString::number( value.toDouble() ) );
    } else if( value.type() == QVariant::Hash ) {
        QHash<QString, QVariant> hash = value.toHash();
        QHashIterator<QString, QVariant> it( hash );

        stream.writeStartElement( "map" );
        stream.writeAttribute( "type", "hash" );
        while( it.hasNext() ) {
            it.next();
            stream.writeStartElement( "item" );
            stream.writeTextElement( "key", it.key() );
            stream.writeStartElement( "value" );
            writeVariant( stream, it.value() );
            stream.writeEndElement(); // value
            stream.writeEndElement(); // item
        }
        stream.writeEndElement();
    } else if( value.type() == QVariant::Image ) {
        QByteArray ba;
        QBuffer buffer( &ba );
        buffer.open( QIODevice::WriteOnly );
        value.value<QImage>().save( &buffer, "PNG" );
        buffer.close();

        stream.writeTextElement( "image", ba.toBase64() );
    } else if( value.type() == QVariant::Int ) {
        stream.writeTextElement( "int", QString::number( value.toInt() ) );
    } else if( value.type() == QVariant::List ) {
        stream.writeStartElement( "list" );
        const QVariantList list = value.toList();
        foreach( const QVariant & var, list ) {
            writeVariant( stream, var );
        }
Example #27
0
QUrl QgsComposerLabel::createStylesheetUrl() const
{
  QString stylesheet;
  stylesheet += QStringLiteral( "body { margin: %1 %2;" ).arg( qMax( mMarginY * mHtmlUnitsToMM, 0.0 ) ).arg( qMax( mMarginX * mHtmlUnitsToMM, 0.0 ) );
  stylesheet += QgsFontUtils::asCSS( mFont, 0.352778 * mHtmlUnitsToMM );
  stylesheet += QStringLiteral( "color: %1;" ).arg( mFontColor.name() );
  stylesheet += QStringLiteral( "text-align: %1; }" ).arg( mHAlignment == Qt::AlignLeft ? "left" : mHAlignment == Qt::AlignRight ? "right" : "center" );

  QByteArray ba;
  ba.append( stylesheet.toUtf8() );
  QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );

  return cssFileURL;
}
Example #28
0
String ImageBuffer::toDataURL(const String& mimeType, const double* quality, CoordinateSystem) const
{
    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));

    // QImageWriter does not support mimetypes. It does support Qt image formats (png,
    // gif, jpeg..., xpm) so skip the image/ to get the Qt image format used to encode
    // the m_pixmap image.

    QByteArray data;
    if (!encodeImage(m_data.m_pixmap, mimeType.substring(sizeof "image"), quality, data))
        return "data:,";

    return "data:" + mimeType + ";base64," + data.toBase64().data();
}
QString Transform::pixmapToBase64(const QPixmap& pixmap)
{
    if (pixmap.isNull())
        return QString();

    QByteArray array;
    QDataStream stream(&array, QIODevice::WriteOnly);
    stream << pixmap;

    if (array.isEmpty())
        return QString();

    return QString::fromAscii(array.toBase64());
}
void XmlQStringSerializator::save(const QVariant &value, QString name)
{
    QDomElement _node = doc()->createElement(name);
    _node.setAttribute("Type","QString");
    if (name.compare("password")==0){
        Chipper chipper;
        QByteArray ba = chipper.cryptString(value.toString());
        //ba.append();
        _node.setAttribute("Value",QString(ba.toBase64()));
    } else {
        _node.appendChild(doc()->createTextNode(value.toString()));
    }
    node()->appendChild(_node);
}