Пример #1
0
/*

{
    "topFace" : "~/burp/faceZ/.png",
    "bottomFace" : "~/burp/faceZ-/.png",
    "leftFace" : "~/burp/faceY/.png",
    "rightFace" : "~/burp/faceY-/.png",
    "frontFace" : "~/burp/faceX/.png",
    "backFace" : "~/burp/faceX-/.png",
    "frameStart" : 1,
    "frameStop" : 499,
    "outputWidth" : 4094,
    "antialiasing" : 1,
    "aaPattern" : "grid",
    "frames": [
          {"cubemap": 1, "fov": 180, "pitch" : 0, "yaw" : 0, "roll" : 0, "zoom" : 0},
          {"cubemap": 1, "fov": 180, "pitch" : 1, "yaw" : 2, "roll" : 3, "zoom" : 4},
          {"cubemap": 1, "fov": 180, "pitch" : 2, "yaw" : 3, "roll" : 4, "zoom" : 1},
          {"cubemap": 1, "fov": 180, "pitch" : 3, "yaw" : 4, "roll" : 1, "zoom" : 2},
          {"cubemap": 1, "fov": 180, "pitch" : 4, "yaw" : 1, "roll" : 2, "zoom" : 3}
        ]
}

  */
void JSonIO::saveJSon(QString filePath){
    QFile jsonFile(filePath);
    if (!jsonFile.open(QIODevice::WriteOnly | QIODevice::Text)){
        parserState = 1;
        return;
    }

    QVariantMap root;
    root.insert("outputFile", getOutputFile());
    root.insert("topFace", getTopFace());
    root.insert("bottomFace", getBottomFace());
    root.insert("leftFace", getLeftFace());
    root.insert("rightFace", getRightFace());
    root.insert("frontFace", getFrontFace());
    root.insert("backFace", getBackFace());
    root.insert("frameStart", getFrameStart());
    root.insert("frameStop", getFrameStop());
    root.insert("outputWidth", getOutputWidth());
    root.insert("antialiasing", getAntialiasing());
    root.insert("aaPattern", getAaPattern());
    root.insert("frames", frames);

    QJson::Serializer serializer;
    QByteArray json = serializer.serialize(root);
    QTextStream out(&jsonFile);
    out.setCodec("UTF-8");
    out << json;
    jsonFile.close();
    qDebug() << "Saved to " << filePath;
}
void LYGithubManager::closeIssue(int issueNumber){
	if(!isAuthenticated() || repository_.isEmpty() || closeIssueReply_)
		return;

	LYGithubProductBacklogStatusLog::statusLog()->appendStatusMessage("Starting closeIssue request");

	QNetworkRequest request;

	QString commentURL = QString("https://api.github.com/repos/%1/issues/%2").arg(repository_).arg(issueNumber);
	request.setUrl(QUrl(commentURL));

	QString userInfo = userName_+":"+password_;
	QByteArray userData = userInfo.toLocal8Bit().toBase64();
	QString headerData = "Basic " + userData;
	request.setRawHeader("Authorization", headerData.toLocal8Bit());

	QVariantMap jdata;
	jdata["state"] = "closed";
	QJson::Serializer jserializer;
	QByteArray jsonData = jserializer.serialize(jdata);

	QBuffer *buffer = new QBuffer;
	buffer->setData(jsonData);
	buffer->open(QIODevice::ReadOnly);
	closeIssueReply_ = manager_->sendCustomRequest(request, "PATCH", buffer);
	buffer->setParent(closeIssueReply_);

	connect(closeIssueReply_, SIGNAL(readyRead()), this, SLOT(onCloseIssueReturned()));
}
Пример #3
0
	void DriveManager::RequestSharingEntry (const QString& id,
			const QString& key)
	{
		QString str = QString ("https://www.googleapis.com/drive/v2/files/%1/permissions?access_token=%2")
				.arg (id, key);
		QNetworkRequest request (str);
		request.setHeader (QNetworkRequest::ContentTypeHeader, "application/json");

		QVariantMap map;
		map.insert ("kind", "drive#permission");
		map.insert ("id", "anyoneWithLink");
		map.insert ("role", "reader");
		map.insert ("type", "anyone");
		map.insert ("withLink", true);

		QJson::Serializer serializer;

		QNetworkReply *reply = Core::Instance ().GetProxy ()->
				GetNetworkAccessManager ()->post (request, serializer.serialize (map));
		Reply2Id_ [reply] = id;

		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (handleRequestFileSharing ()));
	}
void LYGithubManager::updateFileContents(const QString &path, const QString &commitMessage, const QString &contents, const QString &sha){
	if(!isAuthenticated() || repository_.isEmpty() || updateFileContentsReply_)
		return;

	LYGithubProductBacklogStatusLog::statusLog()->appendStatusMessage("Starting updateFileContents request");

	QNetworkRequest request;

	QString updateFileContentsURL = QString("https://api.github.com/repos/%1/contents/%2").arg(repository_).arg(path);
	request.setUrl(QUrl(updateFileContentsURL));

	QString userInfo = userName_+":"+password_;
	QByteArray userData = userInfo.toLocal8Bit().toBase64();
	QString headerData = "Basic " + userData;
	request.setRawHeader("Authorization", headerData.toLocal8Bit());

	QVariantMap jdata;
	jdata["message"] = commitMessage;
	QByteArray encodedContent = contents.toLocal8Bit().toBase64();
	jdata["content"] = encodedContent;
	jdata["sha"] = sha;
	QJson::Serializer jserializer;
	QByteArray jsonData = jserializer.serialize(jdata);

	QBuffer *buffer = new QBuffer;
	buffer->setData(jsonData);
	buffer->open(QIODevice::ReadOnly);
	updateFileContentsReply_ = manager_->sendCustomRequest(request, "PUT", buffer);
	buffer->setParent(updateFileContentsReply_);

	connect(updateFileContentsReply_, SIGNAL(readyRead()), this, SLOT(onUpdateFileContentsReturned()));
}
Пример #5
0
QByteArray encode(const QVariant &claim, const QByteArray &key)
{
	if(!QCA::isSupported("hmac(sha256)"))
		return QByteArray();

	QJson::Serializer serializer;

	QVariantMap header;
	header["typ"] = "JWT";
	header["alg"] = "HS256";
	QByteArray headerJson = serializer.serialize(header);
	if(headerJson.isNull())
		return QByteArray();

	QByteArray claimJson = serializer.serialize(claim);
	if(claimJson.isNull())
		return QByteArray();

	QByteArray headerPart = base64url(headerJson);
	QByteArray claimPart = base64url(claimJson);

	QByteArray sig = jws_sign(headerPart, claimPart, key);

	return headerPart + '.' + claimPart + '.' + sig;
}
Пример #6
0
bool Peer::call(const QString &method, const QVariant &params, const QVariant &id)
{
    if (method.startsWith("rpc.")
            || (params.type() != QVariant::List
                && params.type() != QVariant::Map
                && !params.isNull())
            || (id.type() != QVariant::String
                && id.type() != QVariant::Int
                && id.type() != QVariant::ULongLong
                && id.type() != QVariant::LongLong
                && id.type() != QVariant::Double
                && !id.isNull()))
        return false;

    QVariantMap object;

    object.insert("jsonrpc", "2.0");

    object.insert("method", method);

    if (!params.isNull())
        object.insert("params", params);

    object.insert("id", id);

    QJson::Serializer serializer;
    emit readyRequestMessage(serializer.serialize(object));
    return true;
}
Пример #7
0
QByteArray
toJson( const QVariant &variant, bool* ok )
{
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
    QVariant _variant = variant;
    if ( variant.type() == QVariant::Hash )
    {
        // QJsonDocument cannot deal with QVariantHash, so convert.
        const QVariantHash hash = variant.toHash();
        QVariantMap map;
        QHashIterator<QString, QVariant> it(hash);
        while ( it.hasNext() )
        {
            it.next();
            map.insert( it.key(), it.value() );
        }
        _variant = map;
    }

    QJsonDocument doc = QJsonDocument::fromVariant( _variant );
    if ( ok != NULL )
    {
        *ok = !doc.isNull();
    }
    return doc.toJson( QJsonDocument::Compact );
#else
    QJson::Serializer serializer;
    return serializer.serialize( variant, ok );
#endif
}
Пример #8
0
QByteArray QuitSessionRequestJSON::getJson() const
{
  QJson::Serializer serializer;
  QVariantMap obj;
  obj.insert("auth_token", m_sessionToken);
  return serializer.serialize(obj);
}
Пример #9
0
int HueBridgeConnection::put(const QString &path, const QVariantMap &params, QObject *sender, const QString &slot)
{
    if (m_baseApiUrl.isEmpty()) {
        qWarning() << "Not authenticated to bridge, cannot put" << path;
        return -1;
    }

    QUrl url(m_baseApiUrl + path);
    QNetworkRequest request;
    request.setUrl(url);

#if QT_VERSION >= 0x050000
    QJsonDocument jsonDoc = QJsonDocument::fromVariant(params);
    QByteArray data = jsonDoc.toJson();
#else
    QJson::Serializer serializer;
    QByteArray data = serializer.serialize(params);
#endif
//    qDebug() << "putting" << url << data;

    QNetworkReply *reply = m_nam->put(request, data);
    connect(reply, SIGNAL(finished()), this, SLOT(slotOpFinished()));
    m_requestIdMap.insert(reply, m_requestCounter);
    m_writeOperationList.append(reply);
    CallbackObject co(sender, slot);
    m_requestSenderMap.insert(m_requestCounter, co);
    return m_requestCounter++;
}
Пример #10
0
void AMGithubManager::createNewIssue(const QString &title, const QString &body, const QString &assignee){
	if(!isAuthenticated() || repository_.isEmpty() || createNewIssueReply_)
		return;
	QNetworkRequest request;

	QString issuesURL = "https://api.github.com/repos/"+repository_+"/issues";
	request.setUrl(QUrl(issuesURL));

	QString userInfo = userName_+":"+password_;
	QByteArray userData = userInfo.toLocal8Bit().toBase64();
	QString headerData = "Basic " + userData;
	request.setRawHeader("Authorization", headerData.toLocal8Bit());

	QVariantMap jdata;
	jdata["title"] = title;
	jdata["body"] = body;
	if(!assignee.isEmpty())
		jdata["assignee"] = assignee;
	QJson::Serializer jserializer;
	QByteArray jsonData = jserializer.serialize(jdata);
	//qdebug() << jsonData;

	createNewIssueReply_ = manager_->post(request, jsonData);
	createNewIssueReply_->ignoreSslErrors();
	connect(createNewIssueReply_, SIGNAL(readyRead()), this, SLOT(onCreateNewIssueReturned()));
}
Пример #11
0
Cache::~Cache() {
	QString error;
	write_file(directory() + "/cache-info", &error, recent().join("\n").toAscii());
	if (!error.isEmpty()) {
		qFatal("Unable to save cache: %s", qPrintable(error));
	}
	
	foreach (QString name, recent()) {
		if (!data().contains(name)) continue;
		
		qDebug() << "Saving cached data:" << name;
		
		QVariantMap map = data()[name].toMap();
		
		QString error; bool ok; QJson::Serializer serializer;
		write_file(directory() + '/' + name.replace('/', '-'), &error, serializer.serialize(map, &ok));
		if (!error.isEmpty()) {
			qWarning() << "Error while saving cache: " + error;;
			continue;
		}
		
		if (!ok) {
			error = INVALID_JSON + serializer.errorMessage();
			qWarning() << "Error while saving cache: " + error;
			continue;
		}
	}
}
Пример #12
0
	void respondOk(ZhttpRequest *req, const QVariant &data, const QByteArray &prefix = QByteArray(), const QByteArray &jsonpCallback = QByteArray())
	{
		HttpHeaders headers;
		if(!jsonpCallback.isEmpty())
			headers += HttpHeader("Content-Type", "application/javascript");
		else
			headers += HttpHeader("Content-Type", "text/plain");

		QJson::Serializer serializer;
		QByteArray body;
		if(data.isValid())
			body = serializer.serialize(data);
		if(!prefix.isEmpty())
			body.prepend(prefix);

		if(!jsonpCallback.isEmpty())
		{
			QByteArray encBody = serializer.serialize(QString::fromUtf8(body));
			body = "/**/" + jsonpCallback + '(' + encBody + ");\n";
		}
		else if(!body.isEmpty())
			body += "\n"; // newline is required

		respond(req, 200, "OK", headers, body);
	}
Пример #13
0
QByteArray RestorePasswordRequestJSON::getJson() const
{
    QJson::Serializer serializer;
    QVariantMap obj;
    obj.insert("email", m_usersContainer->at(0)->getEmail());
    return serializer.serialize(obj);
}
Пример #14
0
void GrooveRequest::post()
{
    QString cacheKey = generateCacheKey();

    if (cacheKey.length()) {
        qDebug() << Q_FUNC_INFO << "Possibly cached request";
        QString cachePath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation) + "/libgroove/cache/api/" + cacheKey;
        QFile cacheFile(cachePath);
        if (cacheFile.open(QIODevice::ReadOnly)) {
            qDebug() << Q_FUNC_INFO << "Definitely cached request";
            QByteArray response = cacheFile.readAll();
            processData(response);
            return;
        }
    }

    m_request.setHeader(m_request.ContentTypeHeader, "application/json");

    QJson::Serializer serializer;

    qDebug() << Q_FUNC_INFO << "Posting to: " << m_request.url();
    qDebug() << Q_FUNC_INFO << serializer.serialize(buildRequest());

    QNetworkReply *reply = m_client->networkManager()->post(m_request, serializer.serialize(buildRequest()));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SIGNAL(error(QNetworkReply::NetworkError)));
    connect(reply, SIGNAL(finished()), SLOT(onFinished()));
}
Пример #15
0
QByteArray DefaultResponseJSON::getJson() const
{
    QJson::Serializer serializer;
    QVariantMap obj;
    obj.insert("errno", m_errno);
    return serializer.serialize(obj);
}
Пример #16
0
/**
 * To JSON
 */
QString *WorkModel::toJSON() {
	QVariantMap variantMap = QJson::QObjectHelper::qobject2qvariant(this);
	QJson::Serializer serializer;
	QByteArray serializedArray = serializer.serialize(variantMap);
	QString *jsonString = new QString(QString::fromUtf8(serializedArray));
	return jsonString;
}
Пример #17
0
QByteArray GetBlobResponseJSON::getJson() const
{
  QJson::Serializer serializer;
  QVariantMap obj;
  obj["errno"] = getErrno();
  obj.insert("blob", m_blob);
  return serializer.serialize(obj);
}
Пример #18
0
 /* -------------------------------------------------------------------------------------------
  *
  * ------------------------------------------------------------------------------------------- */
 QByteArray Message::encode(QString from, QString type, QVariantMap message) {
     QJson::Serializer serializer;
     QVariantMap msg;
     msg.insert("type",type);
     msg.insert("data",message);
     msg.insert("from",from);
     return serializer.serialize(msg);
 }
Пример #19
0
QByteArray LoginRequestJSON::getJson() const
{
    QJson::Serializer serializer;
    QVariantMap obj;
    obj.insert("login", m_usersContainer->at(0)->getLogin());
    obj.insert("password", m_usersContainer->at(0)->getPassword());
    return serializer.serialize(obj);
}
Пример #20
0
// convenience:
void
Connection::setFirstMessage( const QVariant& m )
{
    QJson::Serializer ser;
    const QByteArray ba = ser.serialize( m );
    //qDebug() << "first msg json len:" << ba.length();
    setFirstMessage( Msg::factory( ba, Msg::JSON ) );
}
Пример #21
0
QByteArray FilterPolygonRequestJSON::getJson() const
{
  // TODO it's necessary for symbian client
  QJson::Serializer serializer;
  QVariantMap obj;
  obj.insert("auth_token", m_sessionsContainer->at(0)->getSessionToken());
  return serializer.serialize(obj);
}
Пример #22
0
QString Response::toJson()
{
    QVariant result = QJson::QObjectHelper::qobject2qvariant(this, QJson::QObjectHelper::Flag_None);

    QJson::Serializer s;
    s.setIndentMode(QJson::IndentCompact);
    return s.serialize(result);
}
Пример #23
0
QByteArray VersionResponseJSON::getJson() const
{
  QJson::Serializer serializer;
  QVariantMap obj;

  obj.insert("errno", m_errno);
  if (getErrno()== SUCCESS) obj.insert("version", m_version);
  return serializer.serialize(obj);
}
Пример #24
0
 QByteArray Serialize(const QVariant &variant, IndentMode indentMode, bool *ok)
 {
     QJson::Serializer serializer;
     serializer.setIndentMode(static_cast<QJson::IndentMode>(indentMode));
     QByteArray data = serializer.serialize(variant, ok);
     if (ok != 0 && *ok == false)
         LogError(QString("TundraJson::Serialize: %1").arg(serializer.errorMessage()));
     return data;
 }
Пример #25
0
QByteArray SubscribedChannelsRequestJSON::getJson() const
{
  QJson::Serializer serializer;
  QVariantMap request;

  request.insert("auth_token", m_token);

  return serializer.serialize(request);
}
Пример #26
0
QNetworkReply* Synchronizer::registerSelf()
{
   QVariantMap peer;
   peer["url"] = m_selfUrl;
   QVariantMap data;
   data["peer"] = peer;
   QJson::Serializer serializer;
   return post(m_trackerUrl, "peers", serializer.serialize(data));
}
Пример #27
0
QByteArray Akonadi::SocialNetworkAttributes::serialized() const
{
  QJson::Serializer serializer;
#if !defined( USE_QJSON_0_8 )
  return serializer.serialize( d->attributes );
#else
  return serializer.serialize( d->attributes, 0 );
#endif
}
Пример #28
0
QByteArray WriteTagResponseJSON::getJson() const
{
  QJson::Serializer serializer;
  QVariantMap obj;
  if (m_tagsContainer->size() > 0)
    obj.insert("mark_id", m_tagsContainer->at(0)->getId());
  obj.insert("errno", m_errno);
  return serializer.serialize(obj);
}
Пример #29
0
void JSONProtocol::printJSON(QVariantMap json) {
    QJson::Serializer serializer;
    serializer.setIndentMode(QJson::IndentCompact);

    QByteArray jsonText = serializer.serialize(json);

    io->write(jsonText);
    io->write("\n");//Print a newline to finish it

}
QByteArray SetDefaultTimeSlotMarkRequestJSON::getJson() const
{
  QJson::Serializer serializer;
  QVariantMap request;

  request.insert("auth_token", m_usersContainer->at(0)->getToken());
  request.insert("mark_id", m_tagsContainer->at(0)->getId());

  return serializer.serialize(request);
}