Exemplo n.º 1
1
    void EtherIPC::sendTransaction(const QString& from, const QString& to, const QString& valStr, const QString& gas) {
        QJsonArray params;
        const QString valHex = Helpers::toHexWeiStr(valStr);
        EtherLog::logMsg(QString("Trans Value: ") + valStr + QString(" HexValue: ") + valHex);

        QJsonObject p;
        p["from"] = from;
        p["to"] = to;
        p["value"] = valHex;
        if ( !gas.isEmpty() ) {
            const QString gasHex = Helpers::decStrToHexStr(gas);
            p["gas"] = gasHex;
        }

        params.append(p);

        if ( !queueRequest(RequestIPC(SendTransaction, "eth_sendTransaction", params)) ) {
            return bail(true); // softbail
        }
    }
QString BlockList::getSearchResult(QString query) const {
	QString queryLow = query.toLower();
	QJsonArray result;
    for (const BlockInfo& info: m_orderedBlockList) {
        if (!blockIsVisible(info)) continue;
		// check for query:
		if (blockMatchesQuery(info, queryLow)) {
			// block matches query -> add it to result:
			QJsonObject jsonInfo;
			jsonInfo["name"] = info.typeName;
			jsonInfo["nameInUi"] = info.nameInUi;
			jsonInfo["category"] = QJsonArray::fromStringList(info.category);
			result.append(jsonInfo);
		}
	}
	return QJsonDocument(result).toJson();
}
Exemplo n.º 3
0
QJsonValue PageZoneModel::toJson() const
{
    QJsonObject object;

    //
    object["type"] = QJsonValue(mZoneType);

    // Points
    QJsonArray pointsArray;
    foreach(QPoint point, mPolygon)
    {
        QJsonObject pointObject;
        pointObject["x"] = QJsonValue(point.x());
        pointObject["y"] = QJsonValue(point.y());

        pointsArray.append(QJsonValue(pointObject));
    }
Exemplo n.º 4
0
void Client::onPlayerUseCard(const Card *card, const QList<const Player *> &targets){

	if(card == NULL){
		replyToServer(BP::AskForUseCard, QJsonValue());
	}else{
		QJsonArray targetNames;
		foreach(const Player *target, targets)
		targetNames.append(target->objectName());

		replyToServer(BP::AskForUseCard, BP::toJsonArray(card->toString(), targetNames));

		if(status == Responsing)
			card_pattern.clear();
	}

	setStatus(NotActive);
}
Exemplo n.º 5
0
void Ingridients::saveItems(QJsonObject& json) {
    QJsonArray itemsList;

    PRINT_DEBUG("Saving all items");

    for ( auto& entry: avaliableItems ) {
        QJsonObject itemObj;

        if ( !dynamic_cast<Food*>(entry) ) {
            writeItem(itemObj, *entry);

            itemsList.append(itemObj);
        }
    }

    json["itemList"] = itemsList;
}
Exemplo n.º 6
0
bool indexDirectory(const QString& dir, const QString& dest)
{
    QVariantMap vm;
    QVariantMap pluginsVm;
    vm[QStringLiteral("Version")] = QStringLiteral("1.0");
    vm[QStringLiteral("Timestamp")] = QDateTime::currentMSecsSinceEpoch();

    QJsonArray plugins;

    QDirIterator it(dir, *metaDataFiles, QDir::Files, QDirIterator::Subdirectories);
    while (it.hasNext()) {
        it.next();
        const QString path = it.fileInfo().absoluteFilePath();
        QJsonObject obj = KPluginMetaData(path).rawData();
        obj.insert(QStringLiteral("FileName"), path);

        plugins.append(obj);
    }

    // Less than two plugin means it's not worth indexing
    if (plugins.count() < 2) {
        removeIndex(dir);
        return true;
    }

    QString destfile = dest;
    if (!QDir::isAbsolutePath(dest)) {
        destfile = dir + '/' + dest;
    }

    QDir().mkpath(QFileInfo(destfile).dir().absolutePath());
    QFile file(destfile);
    if (!file.open(QIODevice::WriteOnly)) {
        qWarning() << "Failed to open " << destfile;
        return false;
    }

    QJsonDocument jdoc;
    jdoc.setArray(plugins);
//     file.write(jdoc.toJson());
    file.write(jdoc.toBinaryData());
    qWarning() << "Generated " << destfile << " (" << plugins.count() << " plugins)";

    return true;
}
QString BlockList::getJsonBlockModel() const {
	// available blocks do not change at runtime
    // -> create model only if it doesn't already exist:
    if (m_jsonBlockModel.isEmpty() || m_jsonBlockModelDeveloperMode != m_controller->getDeveloperMode()) {
		QJsonArray model;
        for (const BlockInfo& info: m_orderedBlockList) {
            if (!blockIsVisible(info)) continue;
			QJsonObject jsonInfo;
			jsonInfo["name"] = info.typeName;
			jsonInfo["nameInUi"] = info.nameInUi;
			jsonInfo["category"] = QJsonArray::fromStringList(info.category);
			model.append(jsonInfo);
		}
		m_jsonBlockModel = QJsonDocument(model).toJson();
        m_jsonBlockModelDeveloperMode = m_controller->getDeveloperMode();
	}
	return m_jsonBlockModel;
}
Exemplo n.º 8
0
QNetworkReply::NetworkError OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status,
                                                                     const QStringList &custom_ids) {
  QJsonObject json;
  QJsonArray ids;
  QByteArray raw_output;

  QString final_url;

  if (status == RootItem::Read) {
    final_url = m_fixedUrl + API_PATH + "items/read/multiple";
  }
  else {
    final_url = m_fixedUrl + API_PATH + "items/unread/multiple";
  }

  foreach (const QString &id, custom_ids) {
    ids.append(QJsonValue(id.toInt()));
  }
Exemplo n.º 9
0
QJsonObject Blink1Input::toJson3()
{
    QJsonObject obj;
    obj.insert("arg1",arg1());
    obj.insert("iname", name());
    obj.insert("lastTime",date());
    if(mtype!="IFTTT.COM")
        obj.insert("lastVal",arg2());
    else{
        QJsonArray ja;
        ja.append(QJsonValue(arg2()));
        obj.insert("possibleVals",ja);
    }

    obj.insert("pname",patternName());
    obj.insert("type",type());
    return obj;
}
Exemplo n.º 10
0
QJsonObject
q2d::json::fromCategoryEntry(q2d::metamodel::Category* category) {
    Q_CHECK_PTR(category);

    QJsonObject result = QJsonObject();
    QJsonArray children = QJsonArray();
    result.insert(JSON_HIERARCHY_CATEGORY_NAME, QJsonValue(category->text()));
    // child recursion
    for (int rIndex = 0; rIndex < category->rowCount(); ++rIndex) {
        for (int cIndex = 0; cIndex < category->columnCount(); ++cIndex) {
            children.append(QJsonValue(
                                json::fromHierarchyEntry(category->child(rIndex, cIndex))
                            ));
        }
    }
    result.insert(JSON_HIERARCHY_CHILD, children);
    return result;
}
Exemplo n.º 11
0
void Reporter::reportMessages()
{
	if (!mMessagesFile) {
		return;
	}

	QJsonArray messages;
	for (const QPair<Level, QString> &message : mMessages) {
		messages.append(QJsonObject::fromVariantMap({
			{ "level", message.first == Level::information ? "info" : "error" }
			, { "message", message.second }
		}));
	}

	QJsonDocument document;
	document.setArray(messages);
	report(document.toJson(), mMessagesFile);
}
Exemplo n.º 12
0
void initWindow::write(QJsonObject &json)
{


       QJsonArray boardArray;

       boards->iteradorReset();

       while(!boards->iteradorEnd())
       {
           QJsonObject boardObject;
           boards->valorIterador()->write(boardObject);
           boardArray.append(boardObject);
           boards->Siguiente();
       }

        json["trello"] = boardArray;
}
Exemplo n.º 13
0
extern "C" PM_WIDGET_EXPORT void PluginInfo(QJsonObject &json)
{

    QJsonObject argument;
    argument["type"] = "cbox";
    argument["name"] = "mode";
    argument["count"] = "3";
    argument["var0"] = "RETINEX_UNIFORM";
    argument["var1"] = "RETINEX_LOW";
    argument["var2"] = "RETINEX_HIGH";
    QJsonArray argumentList;
    argumentList.append(argument);

    json["arguments"] = argumentList;
    json["pluginName"] = "Retinex";
    json["authorInfo"] = "Author: Ovsyannikov A.K. (drew.dru)";
    json["version"] = PLUGIN_VERSION;
}
Exemplo n.º 14
0
QJsonArray PlaylistHelper::getPlayingPlaylist()
{
    QSharedPointer<Core::IPlaylist> playlist = Core::ICore::playbackController()->getPlaylist();
    if(!playlist.isNull())
    {
        currentPlaylist = playlist;
        QJsonArray array;
        for(int i = 0; i < playlist->getSize(); i++)
        {
            array.append(JSONSerializer::getMedia(playlist->getMediaAt(i)));
        }
        return array;
    }
    else
    {
        return QJsonArray();
    }
}
Exemplo n.º 15
0
bool KNMusicPlaylistManager::writeModelToFile(KNMusicPlaylistModel *model,
                                              const QString &filePath)
{
    //Check te model first, then check out the model folder path.
    if(!model ||
            (KNUtil::ensurePathValid(
                 QFileInfo(filePath).absolutePath()).isEmpty()))
    {
        return false;
    }
    //Get the playlist file.
    QFile playlistFile(filePath);
    //Try to open the file as write mode.
    if(!playlistFile.open(QIODevice::WriteOnly))
    {
        return false;
    }
    //Create the playlist content.
    QJsonArray songs;
    //Write all the data to the content.
    for(int row=0; row<model->rowCount(); ++row)
    {
        //Translate the detail info from the model to a QJsonObject, and add it
        //to the playlist content.
        songs.append(
                    KNMusicUtil::detailInfoToObject(model->rowDetailInfo(row)));
    }
    //Create the playlist object.
    QJsonObject playlistObject;
    //Set the data of the playlist.
    playlistObject["Version"]=PlaylistListVersion;
    playlistObject["Name"]=model->title();
    playlistObject["Songs"]=songs;
    //Create playlist document
    QJsonDocument playlistDocument;
    //Set the playlist object to document object.
    playlistDocument.setObject(playlistObject);
    //Write document data to the file.
    playlistFile.write(playlistDocument.toJson(QJsonDocument::Indented));
    //Close the file.
    playlistFile.close();
    //Export complete.
    return true;
}
Exemplo n.º 16
0
QTreeWidgetItem* LOCACC::addMessage(QStringList msgData, bool isAccTextSame, QTreeWidgetItem *parent)
{
    QString eleId = parent->text(0);
    QJsonArray jArray = m_jsonMasterObj["locAccData"].toArray();
    QString parentScreen = parent->parent()->text(0);
    QJsonObject tempObj ;
    QTreeWidgetItem *newMsg;
    for(int i = 0 ; i < jArray.count() ; i++ )
    {
        tempObj = jArray.at(i).toObject();
        if(tempObj["id"] == parentScreen)
        {
            QJsonArray eleJArray = tempObj["elements"].toArray();
            QJsonObject tempEleObj;
            for(int j = 0 ; j < eleJArray.count(); j++)
            {
                tempEleObj = eleJArray.at(j).toObject();
                if(tempEleObj["id"] == eleId)
                {
                    QJsonArray msgsArray = tempEleObj["messages"].toArray();
                    if(messageExistance(msgData,msgsArray))
                    {
                        return false;
                    }
                    QJsonObject newMsgJson = getMessageJson(msgData,isAccTextSame);
                    msgsArray.append(newMsgJson);
                    QStringList msgList;
                    msgList << msgData.at(0);
                    newMsg  = new QTreeWidgetItem(msgList);
                    setMessageTooltip(newMsg,newMsgJson);
                    parent->addChild(newMsg);
                    tempEleObj["messages"] = msgsArray;
                    eleJArray.replace(j,tempEleObj);
                    tempObj["elements"] = eleJArray;
                    jArray.replace(i,tempObj);
                    break;
                }
            }
        }
    }
    m_jsonMasterObj["locAccData"] = jArray;
    writeFile();
    return newMsg;
}
Exemplo n.º 17
0
void PanelMenu::showMenu(int x, int y)
{
    if (m_menuManager && m_menuManager->isValid()){
        QDBusPendingReply<QDBusObjectPath> pr = m_menuManager->RegisterMenu();
        if (pr.count() == 1)
        {
            QDBusObjectPath op = pr.argumentAt(0).value<QDBusObjectPath>();
            m_menuInterfacePath = op.path();
            DBusMenu *m_menu = new DBusMenu(m_menuInterfacePath,this);
            connect(m_menu,&DBusMenu::MenuUnregistered,m_menu,&DBusMenu::deleteLater);
            connect(m_menu,&DBusMenu::ItemInvoked,this,&PanelMenu::onItemInvoked);

            QJsonObject targetObj;
            targetObj.insert("x",QJsonValue(x));
            targetObj.insert("y",QJsonValue(y));
            targetObj.insert("isDockMenu",QJsonValue(false));

            QJsonArray contentArry;
            contentArry.append(createRadioItemObj(tr("Fashion mode"),ToFashionMode,DockModeGroup,m_dockModeData->getDockMode() == Dock::FashionMode));
            contentArry.append(createRadioItemObj(tr("Efficient mode"),ToEfficientMode,DockModeGroup,m_dockModeData->getDockMode() == Dock::EfficientMode));
            contentArry.append(createRadioItemObj(tr("Classic mode"),ToClassicMode,DockModeGroup,m_dockModeData->getDockMode() == Dock::ClassicMode));
            contentArry.append(createItemObj("",OperationType(-1)));
            contentArry.append(createRadioItemObj(tr("Keep showing"),ToKeepShowing,HideModeGroup,m_dockModeData->getHideMode() == Dock::KeepShowing));
            contentArry.append(createRadioItemObj(tr("Keep hidden"),ToKeepHidden,HideModeGroup,m_dockModeData->getHideMode() == Dock::KeepHidden));
            contentArry.append(createRadioItemObj(tr("Smart hide"),ToSmartHide,HideModeGroup,m_dockModeData->getHideMode() == Dock::SmartHide));
            contentArry.append(createItemObj("",OperationType(-1)));
            contentArry.append(createItemObj(tr("Notification area settings"),ToPluginSetting));

            QJsonObject contentObj;
            contentObj.insert("items",contentArry);
            targetObj.insert("menuJsonContent",QString(QJsonDocument(contentObj).toJson()));

            m_menu->ShowMenu(QString(QJsonDocument(targetObj).toJson()));
        }
    }
}
Exemplo n.º 18
0
QJsonObject MCMCSettings::toJson() const
{
    QJsonObject mcmc;
    mcmc[STATE_MCMC_NUM_CHAINS] = QJsonValue::fromVariant(mNumChains);
    mcmc[STATE_MCMC_NUM_RUN_ITER] = QJsonValue::fromVariant(mNumRunIter);
    mcmc[STATE_MCMC_NUM_BURN_ITER] = QJsonValue::fromVariant(mNumBurnIter);
    mcmc[STATE_MCMC_MAX_ADAPT_BATCHES] = QJsonValue::fromVariant(mMaxBatches);
    mcmc[STATE_MCMC_ITER_PER_BATCH] = QJsonValue::fromVariant(mNumBatchIter);
    mcmc[STATE_MCMC_THINNING_INTERVAL] = QJsonValue::fromVariant(mThinningInterval);
    
    mcmc[STATE_MCMC_MIXING] = QJsonValue::fromVariant(mMixingLevel);
    
    QJsonArray seeds;
    for(int i=0; i<mSeeds.size(); ++i)
        seeds.append(QJsonValue::fromVariant(mSeeds[i]));
    mcmc[STATE_MCMC_SEEDS] = seeds;
    
    return mcmc;
}
Exemplo n.º 19
0
void ContactDetails::writeDetailsToDocument()
{
    QJsonArray detailGroupArray;

    foreach(ContactDetailGroupBox* detailGroup, contactDetailList)
    {
        if(!detailGroup->toJsonObject().isEmpty())
            detailGroupArray.append(detailGroup->toJsonObject());
    }

    QJsonObject contactObject;
    contactObject.insert("name", ui->nameLineEdit->text());
    contactObject.insert("detailGroups", detailGroupArray);

    QJsonArray currentArray = document->array();
    currentArray.replace(rowIndex, contactObject);

    document->setArray(currentArray);
}
Exemplo n.º 20
0
QJsonObject AnimationToJson::toJsonObject(const Animation &animation)
{
    QJsonObject animationObject;
    animationObject.insert("frameCount", animation.frameCount());
    animationObject.insert("fps", animation.fps());
//    animationObject.insert("origin", toJsonObject(animation.origin()));

    QJsonArray keyFramesArray;
    const auto keyFrames = animation.keyFrames();
    for(auto it = keyFrames.begin(); it != keyFrames.end(); ++it) {
        QJsonObject keyFrameObject;
        keyFrameObject.insert("frame", it.key());
        keyFrameObject.insert("data", toJsonObject(*it.value()));
        keyFramesArray.append(keyFrameObject);
    }
    animationObject.insert("keyFrames", keyFramesArray);

    return animationObject;
}
Exemplo n.º 21
0
void
CutyCapt::saveSnapshot() {
    QWebFrame *mainFrame = mPage->mainFrame();
    
    // TODO: sometimes contents/viewport can have size 0x0
    // in which case saving them will fail. This is likely
    // the result of the method being called too early. So
    // far I've been unable to find a workaround, except
    // using --delay with some substantial wait time. I've
    // tried to resize multiple time, make a fake render,
    // check for other events... This is primarily a problem
    // under my Ubuntu virtual machine.

    mPage->setViewportSize( mainFrame->contentsSize() );
    
    if (mPage->fixedWidth != 0 && mPage->fixedHeight != 0) {
      mPage->setViewportSize(QSize(mPage->fixedWidth, mPage->fixedHeight));
    }

    if (this-mPage->mSelector.count() > 0) {
        QWebElementCollection collection = mainFrame->findAllElements(this->mPage->mSelector);

        QJsonObject obj;
        QJsonArray elements;

        foreach(QWebElement elem, collection) {
            QJsonObject e;
            e["id"] = elem.attribute("id");

            if (this->mPage->mRetina) {
                e["x"] = elem.geometry().x() * 2;
                e["y"] = elem.geometry().y() * 2;
                e["width"] = elem.geometry().width() * 2;
                e["height"] = elem.geometry().height() * 2;
            }else{
                e["x"] = elem.geometry().x();
                e["y"] = elem.geometry().y();
                e["width"] = elem.geometry().width();
                e["height"] = elem.geometry().height();
            }

            elements.append(e);
        }
Exemplo n.º 22
0
const QJsonArray MediaSource::mediaArray(const mmTypes::MediaType &mediaType) const
{
    // TODO: We are still creating a copy of the data here as we are creating
    // JSonObjects from VariantMaps. Because the data is stored in QStrings
    // this still does not matter too much.
    // Once we refine the implementation of the Playlist this can probably be
    // further simplified.
    QJsonArray mediaPlaylist;
    const QList<QVariantMap> * mediaFiles=0;
    if (mediaType==mmTypes::AudioFile) mediaFiles=&m_playlist.audioFiles;
    else if (mediaType==mmTypes::VideoFile) mediaFiles=&m_playlist.videoFiles;
    // TODO: Add code for additional MediaTypes here
    if (mediaFiles) {
        foreach (const QVariantMap & file, *mediaFiles) {
            mediaPlaylist.append(QJsonObject::fromVariantMap(file));
        }
    }
    return mediaPlaylist;
}
Exemplo n.º 23
0
void MainWindow::on_pushButton_clicked()
{
    QString url = "http://preapi.kjt.com/open.api";     //接口测试地址
    QString secretkey = "kjt@345";              // 由接口提供方分配给接口调用方的验签密钥

    QMap<QString, QString> paramsMap;
    paramsMap["appid"] = "seller345";           // 由接口提供方分配给接口调用方的身份标识符
    paramsMap["method"] = "Product.ProudctInfoBatchGet";    // 由接口提供方指定的接口标识符
    paramsMap["version"] = "1.0";               // 由接口提供方指定的接口版本
    paramsMap["format"] = "json";               // 接口返回结果类型:json
    paramsMap["timestamp"] = QDateTime::currentDateTime().toString("yyyyMMddhhmmss");       // 调用方时间戳,格式为“4 位年+2 位月+2 位日+2 位小时(24 小时制)+2 位分+2 位秒”
//    qsrand(time(NULL));
    paramsMap["nonce"] = QString::number(100000 + qrand() % (999999 - 100000)); // QString::number(100000 + qrand() % (999999 - 100000));

    QJsonObject json;
    QJsonArray jsonArray;
    jsonArray.append(QJsonValue("345JPA018400002"));
    json["ProductIDs"] = jsonArray;
    json["SaleChannelSysNo"] = g_config.kjtSaleschannelsysno();
    QJsonDocument jsonDoc(json);
    qDebug() << jsonDoc.toJson(QJsonDocument::Compact);

    paramsMap["data"] = jsonDoc.toJson(QJsonDocument::Compact);
    qDebug() << paramsMap;

    QString params;
    QMapIterator<QString, QString> i(paramsMap);
    while (i.hasNext())
    {
        i.next();
        params.append(i.key()).append("=").append(i.value().toLatin1().toPercentEncoding()).append("&");
    }

    params.append(secretkey);
    qDebug() << params;
    QString sign = QCryptographicHash::hash(params.toLatin1(), QCryptographicHash::Md5).toHex();

    url.append("?").append(params).append("&sign=").append(sign);

    qDebug() << url;
    _manager->get(QNetworkRequest(QUrl(url)));
}
Exemplo n.º 24
0
bool Serializer::write(
        const std::vector<std::shared_ptr<Section>>& sections,
        const std::map<string, double>& shading,
        const QString& file)
{
    QFile jsonFile(file);
    if(!jsonFile.open(QFile::WriteOnly))
        return false;

    QJsonDocument doc;

    QJsonObject mainObj;

    QJsonArray array;
    for(shared_ptr<Section> s : sections)
    {
        QJsonObject obj;
        obj["Name"] = s->name;
        obj["File"] = s->file;
        obj["begining"] = s->beginingTime;
        obj["fade-in"] = s->fadeInTime;
        obj["duration"] = s->durationTime;
        obj["fade-out"] = s->fadeOutTime;
        obj["in-color"] = toArray(s->inColor);
        obj["out-color"] = toArray(s->outColor);

        array.append(obj);
    }

    mainObj["Sections"] = array;

    QJsonObject shadingObj;
    for(auto sh : shading)
        shadingObj[sh.first.c_str()] = sh.second;

    mainObj["Shading"] = shadingObj;

    doc.setObject(mainObj);
    jsonFile.write(doc.toJson());

    return true;
}
Exemplo n.º 25
0
QJsonArray Utils::serializeType(const QMetaObject& meta, qlonglong timestamp)
{
    QString className = meta.className();
    QStringList properties;
    properties << "_id" << "modified" << "deleted";
    properties << propertyNames(meta);
    
    QSqlQuery query;
    query.prepare(QString("SELECT %1 FROM %2 WHERE modified>:timestamp OR deleted>:timestamp").arg(properties.join(",")).arg(className));
    query.bindValue(":timestamp", timestamp);
    query.exec();
    
    QJsonArray array;
    while (query.next())
    {
        array.append(serializeObject(properties, query));
    }
    
    return array;
}
Exemplo n.º 26
0
bool VersionBuilder::writeOverrideOrders(OneSixInstance *instance, const PatchOrder &order)
{
	QJsonObject obj;
	obj.insert("version", currentOrderFileVersion);
	QJsonArray orderArray;
	for(auto str: order)
	{
		orderArray.append(str);
	}
	obj.insert("order", orderArray);
	QFile orderFile(instance->instanceRoot() + "/order.json");
	if (!orderFile.open(QFile::WriteOnly))
	{
		QLOG_ERROR() << "Couldn't open" << orderFile.fileName()
					 << "for writing:" << orderFile.errorString();
		return false;
	}
	orderFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented));
	return true;
}
Exemplo n.º 27
0
void Configuration::save()
{
    QJsonArray newConfArray;
    for (QList<SSProfile>::iterator it = profileList.begin(); it != profileList.end(); ++it) {
        QJsonObject json;
        json["backend"] = QJsonValue(it->backend);
        json["type"] = QJsonValue(it->type);
        json["profile"] = QJsonValue(it->profileName);
        json["server"] = QJsonValue(it->server);
        json["server_port"] = QJsonValue(it->server_port);
        json["password"] = QJsonValue(it->password);
        json["local_address"] = QJsonValue(it->local_addr);
        json["local_port"] = QJsonValue(it->local_port);
        json["method"] = QJsonValue(it->method.isEmpty() ? QString("table") : it->method.toLower());//lower-case in config
        json["timeout"] = QJsonValue(it->timeout);
        if (tfo_available) {
            json["fast_open"] = QJsonValue(it->fast_open);
        }
        newConfArray.append(QJsonValue(json));
    }

    QJsonObject JSONObj;
    JSONObj["index"] = QJsonValue(m_index);
    JSONObj["debug"] = QJsonValue(debugLog);
    JSONObj["autoHide"] = QJsonValue(autoHide);
    JSONObj["autoStart"] = QJsonValue(autoStart);
    JSONObj["translucent"] = QJsonValue(translucent);
    JSONObj["configs"] = QJsonValue(newConfArray);

    QJsonDocument JSONDoc(JSONObj);

    QFile JSONFile(m_file);
    JSONFile.open(QIODevice::WriteOnly | QIODevice::Text);
    if (JSONFile.isWritable()) {
        JSONFile.write(JSONDoc.toJson());
    }
    else {
        qWarning() << "Warning: file is not writable!";
    }
    JSONFile.close();
}
Exemplo n.º 28
0
void DataJSON::writeDrawing(vector<ObjectInterface *> shapes, QJsonObject &json)
{
    for (ObjectInterface *obj : shapes)
    {
        QString type = QString::fromLatin1(obj->metaObject()->className());
        QJsonObject shapeJSON;

        //cout<<obj->metaObject()->className()<<endl;

        shapeJSON["color"] = QString::fromStdString(obj->getColor());
        QJsonArray pointsArray;
        for(Point point : obj->getPoints())
        {
           QJsonObject pointObjJSON;
           pointObjJSON["x"] = point.get_x();
           pointObjJSON["y"] = point.get_y();
           pointsArray.append(pointObjJSON);
        }
        shapeJSON["points"] = pointsArray;
        shapeJSON["perimeter"] = obj->getPerimeter();
        shapeJSON["area"] = obj->getArea();

        if (type == "Circle")
        {
            Circle* circle = (Circle*)obj;
            shapeJSON["rayon"] = circle->getRayon();
        }
        else if (type == "Ellipse")
        {
            Ellipse* ellipse =(Ellipse*)obj;
            shapeJSON["rlar"] = ellipse->getRlar();
            shapeJSON["rlong"] = ellipse->getRlon();

        }
        /*else if (type == "Fresque") {
            Fresque *fresque = (Fresque*)obj;
        }*/

        json.insert(type, QJsonValue(shapeJSON));
    }
}
Exemplo n.º 29
0
void Configuration::write(QJsonObject &json) const
{
    QJsonObject positionObj;
    positionObj[KEY_X] = positionX;
    positionObj[KEY_Y] = positionY;
    json[KEY_POSITION] = positionObj;

    json[KEY_SCALE] = scale;
    json[KEY_FILL] = fill;
    json[KEY_OUTLINE] = outline;

    QJsonObject figureObj;
    figure->write(figureObj);
    QJsonArray glyphsArray;
    glyphsArray.append(figureObj);
    json[KEY_GLYPHS] = glyphsArray;

    QJsonObject panelObj;
    panel->write(panelObj);
    json[KEY_PANEL] = panelObj;
}
Exemplo n.º 30
0
/**
 * @brief PvrManager::GetTasksByIDs
 * Get task list by identifier list.
 * See pvrManager.TaskInfo, pvrManager.CreateTask, pvrManager.GetTaskByID.
 * @param ids list of task identifiers in JSON format
 * signature: number[]
 *
 * @return list of all matched recording tasks in JSON format
 */
QString PvrManager::GetTasksByIDs(const QString &ids)
{
    STUB() << ids;
    QJsonArray items = QJsonDocument::fromJson(ids.toUtf8()).array();

    QJsonArray result;

    for(const QVariant& item: items.toVariantList())
    {
        const QString id = item.toString();
        if(m_tasks.contains(id))
            result.append(m_tasks.value(id)->toJson());
        else
            WARN() << "Task" << id << "not found! Skipping...";
    }

    const QString str = QString(QJsonDocument(result).toJson(QJsonDocument::Compact));
    DEBUG() << "result:" << str;

    return str;
}