static PyObject *meth_QScriptValueIterator_hasNext(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QScriptValueIterator *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QScriptValueIterator, &sipCpp))
        {
            bool sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->hasNext();
            Py_END_ALLOW_THREADS

            return PyBool_FromLong(sipRes);
        }
    }
Пример #2
0
void UT::SetResultMapWithSets(QList<QMap<QString,QString > >& fql_result_set,
							  QScriptValueIterator& resultSetIter)
{
	int i = 1;
	while (resultSetIter.hasNext()) {
	    QMap<QString,QString> fql_result_set_map;
		resultSetIter.next();
		UT::getInstance()->LogToFile("# "+(i++));
	    QScriptValueIterator it3(resultSetIter.value());
		while (it3.hasNext()) {
			it3.next();
			UT::getInstance()->LogToFile(it3.name() +": " + it3.value().toString());
			fql_result_set_map.insert(it3.name(),it3.value().toString());
		}
		fql_result_set.append(fql_result_set_map);	
	}


}
Пример #3
0
int BTCTrader::gotReply ( QNetworkReply* reply )
{
 /*   if ( graph == NULL )
    {
//        timerOrders->start ( poolInterval );
        return 0;
    }*/
    QByteArray result;
    float bid = 0;
    float ask = 0;
    float trade = 0;
    result = reply->readAll ();

    QScriptValue sc;
    QScriptEngine engine;
    sc = engine.evaluate("(" + QString(result) + ")");
    if (sc.property("asks").isArray())
    {
            QStringList items;
            qScriptValueToSequence(sc.property("asks"), items);
            QMap<float,float> hash;
            for ( int i=0;i<items.count();i++ )
            {
                if ( hash[items.at ( i ).split ( ',') .at ( 0 ).toFloat()] > 0 )
                {
                    hash[items.at ( i ).split ( ',') .at ( 0 ).toFloat()] += items.at ( i ).split ( ',') .at ( 1 ).toFloat();
                } else {
                    hash.insert( items.at ( i ).split ( ',') .at ( 0 ).toFloat(), items.at ( i ).split ( ',') .at ( 1 ).toFloat() );
                }
            }
            QList<float> keys = hash.keys();
            qSort ( keys );
            ask = keys.at ( 0 );
            float balanceBs = 0;
            float count = balanceUSD;
            int counter = 0;
            while ( count > 0 )
            {
                if ( count >= hash[keys.at ( counter )]*keys.at ( counter ) )
                {
                    balanceBs += hash[keys.at ( counter )];
                    count -= hash[keys.at ( counter )]*keys.at ( counter );
                } else {
                    balanceBs += count/keys.at ( counter );
                    count = 0;
                }
                counter++;
            }
            balanceBs -= balanceBs/100*fee;
//            ui->USDLabel->setText( QString::number ( balanceUSD ) );
//            ui->USDtoBTCLabel->setText (QString::number ( balanceBs ) );


            if ( graph != NULL )
                graph->updateAsk( ask );
            if ( ordersGraph != NULL )
                ordersGraph->updateAsks( hash );
            if ( tradeList != NULL )
            {
                for ( int i=9; i>=0;i-- )
                {
                      QTableWidgetItem* item;
                      item = tradeList->takeItem ( i, 0 );
                      ask = (float)keys.at ( 9 - i );
                      item->setText( QString::number ( ask ) );
                      item->setForeground( Qt::red );
                      tradeList->setItem ( i, 0, item );

                      item = tradeList->takeItem ( i, 1 );
                      ask = (float)hash.value( keys.at ( 9 - i ) );
                      item->setText( QString::number ( ask ) );
                      tradeList->setItem ( i, 1, item );
                }
            }
    }
    if (sc.property("bids").isArray())
    {
            QStringList items;
            qScriptValueToSequence(sc.property("bids"), items);
            QMap<float,float> hash;
            for ( int i=0;i<items.count();i++ )
            {
                if ( hash[items.at ( i ).split ( ',') .at ( 0 ).toFloat()] > 0 )
                {
                    hash[items.at ( i ).split ( ',') .at ( 0 ).toFloat()] += items.at ( i ).split ( ',') .at ( 1 ).toFloat();
                } else {
                    hash.insert( items.at ( i ).split ( ',') .at ( 0 ).toFloat(), items.at ( i ).split ( ',') .at ( 1 ).toFloat() );
                }
            }
            QList<float> keys = hash.keys();
            qSort ( keys );
            bid = keys.at ( keys.count() - 1 );
            float balanceBs = 0;
            float count = balance;
            count -= count / 100 * fee;
            int counter = keys.count() - 1;
            while ( count > 0 )
            {
                if ( count >= hash[keys.at ( counter )] )
                {
                    balanceBs += hash[keys.at ( counter )] * keys.at ( counter );
                    count -= hash[keys.at ( counter ) ];
                } else {
                    balanceBs += count * keys.at ( counter );
                    count = 0;
                }
                counter--;
            }
//            ui->BTCLabel->setText( QString::number ( balance ) );
//            ui->BTCtoUSDLabel->setText (QString::number ( balanceBs ) );
            if ( graph != NULL )
                graph->updateBid( bid );
            if ( ordersGraph != NULL )
                ordersGraph->updateBids( hash );

            if ( tradeList != NULL )
            {
                for ( int i=11; i<=20;i++ )
                {
                    QTableWidgetItem* item;
                    item = tradeList->takeItem ( i, 0 );
                    bid = (float)keys.at ( keys.count() - i + 10 );
                    item->setText( QString::number ( bid ) );
                    item->setForeground( Qt::blue );
                    tradeList->setItem ( i, 0, item );

                    item = tradeList->takeItem ( i, 1 );
                    bid = (float)hash.value( keys.at ( keys.count() - i + 10 ) );
                    item->setText( QString::number ( bid ) );
                    tradeList->setItem ( i, 1, item );
                }

            }
            timerDepth->start ( poolInterval );
    }
    if ( sc.property ( "ticker" ).isObject() )
    {
        QString str = sc.property("ticker").property("last").toString();
        trade = str.toFloat ();
        graph->updateTrade( trade );
        if ( tradeList != NULL )
        {
            QTableWidgetItem* item;
            item = tradeList->takeItem ( 10, 0 );
            item->setText( str );
            item->setForeground( Qt::green );
            tradeList->setItem ( 10, 0, item );
        }
//        QTableWidgetItem* item;
//        item = ui->bidTableWidget->takeItem ( 0, 20 );
//        item->setText( str );
//        item->setForeground( Qt::green );
//        ui->bidTableWidget->setItem ( 0, 20, item );
        timerTicker->start ( poolInterval );

    }
    if ( sc.property ( "usds" ).isString() )
    {
        balanceUSD=sc.property ( "usds" ).toNumber();
    }
    if ( sc.property ( "btcs" ).isString() )
    {
        balance = sc.property ( "btcs" ).toNumber();
    }

    if ( sc.property ( "orders" ).isObject()/* && ! myOrderTableWidget->contextMenu->isVisible()*/ )
    {
        errorCount = 0;
//        myOrderTableWidget->clear();
//        myOrderTableWidget->setRowCount( 0 );
//        myOrderTableWidget->setColumnCount( 4 );
        QScriptValueIterator iterator ( sc.property( "orders" ) );
        while ( iterator.hasNext() )
        {
            iterator.next();
            QTableWidgetItem* item;
//            myOrderTableWidget->insertRow( 0 );
            item = new QTableWidgetItem ();
            item->setText( iterator.value().property( "oid" ).toString() );
            if ( iterator.value().property ( "status" ).toInteger() != 1 )
                item->setBackgroundColor( ( QColor ( Qt::gray ) ) );
//            myOrderTableWidget->setItem( 0, 0, item );
            item = new QTableWidgetItem ();
            if ( iterator.value().property( "type" ).toInteger() == 1 )
                item->setText( "S" );
            else
                item->setText( "B" );
            if ( iterator.value().property ( "status" ).toInteger() != 1 )
                item->setBackgroundColor( ( QColor ( Qt::gray ) ) );
//            myOrderTableWidget->setItem( 0, 1, item );
            item = new QTableWidgetItem ();
            item->setText( iterator.value().property( "amount" ).toString() );
            if ( iterator.value().property ( "status" ).toInteger() != 1 )
                item->setBackgroundColor( ( QColor ( Qt::gray ) ) );
//            myOrderTableWidget->setItem( 0, 2, item );
            item = new QTableWidgetItem ();
            item->setText( iterator.value().property( "price" ).toString() );
            if ( iterator.value().property ( "status" ).toInteger() != 1 )
                item->setBackgroundColor( ( QColor ( Qt::gray ) ) );
//            myOrderTableWidget->setItem( 0, 3, item );
//            myOrderTableWidget->setRowHeight(0, 15);
        }
/*        myOrderTableWidget->removeRow( 0 );*/

/*        myOrderTableWidget->setColumnWidth( 0, 0 );
        myOrderTableWidget->setColumnWidth( 1, 20 );
        myOrderTableWidget->setColumnWidth( 2, 110 );
        myOrderTableWidget->setColumnWidth( 3, 110 );*/
        timerOrders->start( poolInterval );
    }
    if ( sc.property( "error" ).toString().length() > 0 )
    {
        errorCount += 1;
        qDebug ( QString ( result ).toStdString().c_str() );
        if ( errorCount == 5 )
        {

            failedLogin = true;
            qDebug ( sc.property( "error" ).toString().toStdString().c_str() );
//            this->ui->statusBar->showMessage ( sc.property( "error" ).toString() );
//            this->setWindowTitle( "BTCTrade - failed login" );
        }
    }

    reply->deleteLater();

    return 0;
}
/*!
  Applies the given \a command to the given \a backend.
*/
QScriptDebuggerResponse QScriptDebuggerCommandExecutor::execute(
    QScriptDebuggerBackend *backend,
    const QScriptDebuggerCommand &command)
{
    QScriptDebuggerResponse response;
    switch (command.type()) {
    case QScriptDebuggerCommand::None:
        break;

    case QScriptDebuggerCommand::Interrupt:
        backend->interruptEvaluation();
        break;

    case QScriptDebuggerCommand::Continue:
        if (backend->engine()->isEvaluating()) {
            backend->continueEvalution();
            response.setAsync(true);
        }
        break;

    case QScriptDebuggerCommand::StepInto: {
        QVariant attr = command.attribute(QScriptDebuggerCommand::StepCount);
        int count = attr.isValid() ? attr.toInt() : 1;
        backend->stepInto(count);
        response.setAsync(true);
    }   break;

    case QScriptDebuggerCommand::StepOver: {
        QVariant attr = command.attribute(QScriptDebuggerCommand::StepCount);
        int count = attr.isValid() ? attr.toInt() : 1;
        backend->stepOver(count);
        response.setAsync(true);
    }   break;

    case QScriptDebuggerCommand::StepOut:
        backend->stepOut();
        response.setAsync(true);
        break;

    case QScriptDebuggerCommand::RunToLocation:
        backend->runToLocation(command.fileName(), command.lineNumber());
        response.setAsync(true);
        break;

    case QScriptDebuggerCommand::RunToLocationByID:
        backend->runToLocation(command.scriptId(), command.lineNumber());
        response.setAsync(true);
        break;

    case QScriptDebuggerCommand::ForceReturn: {
        int contextIndex = command.contextIndex();
        QScriptDebuggerValue value = command.scriptValue();
        QScriptEngine *engine = backend->engine();
        QScriptValue realValue = value.toScriptValue(engine);
        backend->returnToCaller(contextIndex, realValue);
        response.setAsync(true);
    }   break;

    case QScriptDebuggerCommand::Resume:
        backend->resume();
        response.setAsync(true);
        break;

    case QScriptDebuggerCommand::SetBreakpoint: {
        QScriptBreakpointData data = command.breakpointData();
        if (!data.isValid())
            data = QScriptBreakpointData(command.fileName(), command.lineNumber());
        int id = backend->setBreakpoint(data);
        response.setResult(id);
    }   break;

    case QScriptDebuggerCommand::DeleteBreakpoint: {
        int id = command.breakpointId();
        if (!backend->deleteBreakpoint(id))
            response.setError(QScriptDebuggerResponse::InvalidBreakpointID);
    }   break;

    case QScriptDebuggerCommand::DeleteAllBreakpoints:
        backend->deleteAllBreakpoints();
        break;

    case QScriptDebuggerCommand::GetBreakpoints: {
        QScriptBreakpointMap bps = backend->breakpoints();
        if (!bps.isEmpty())
            response.setResult(bps);
    }   break;

    case QScriptDebuggerCommand::GetBreakpointData: {
        int id = command.breakpointId();
        QScriptBreakpointData data = backend->breakpointData(id);
        if (data.isValid())
            response.setResult(data);
        else
            response.setError(QScriptDebuggerResponse::InvalidBreakpointID);
    }   break;

    case QScriptDebuggerCommand::SetBreakpointData: {
        int id = command.breakpointId();
        QScriptBreakpointData data = command.breakpointData();
        if (!backend->setBreakpointData(id, data))
            response.setError(QScriptDebuggerResponse::InvalidBreakpointID);
    }   break;

    case QScriptDebuggerCommand::GetScripts: {
        QScriptScriptMap scripts = backend->scripts();
        if (!scripts.isEmpty())
            response.setResult(scripts);
    }   break;

    case QScriptDebuggerCommand::GetScriptData: {
        qint64 id = command.scriptId();
        QScriptScriptData data = backend->scriptData(id);
        if (data.isValid())
            response.setResult(data);
        else
            response.setError(QScriptDebuggerResponse::InvalidScriptID);
    }   break;

    case QScriptDebuggerCommand::ScriptsCheckpoint:
        backend->scriptsCheckpoint();
        response.setResult(QVariant::fromValue(backend->scriptsDelta()));
        break;

    case QScriptDebuggerCommand::GetScriptsDelta:
        response.setResult(QVariant::fromValue(backend->scriptsDelta()));
        break;

    case QScriptDebuggerCommand::ResolveScript:
        response.setResult(backend->resolveScript(command.fileName()));
        break;

    case QScriptDebuggerCommand::GetBacktrace:
        response.setResult(backend->backtrace());
        break;

    case QScriptDebuggerCommand::GetContextCount:
        response.setResult(backend->contextCount());
        break;

    case QScriptDebuggerCommand::GetContextState: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(static_cast<int>(ctx->state()));
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetContextID: {
        int idx = command.contextIndex();
        if ((idx >= 0) && (idx < backend->contextCount()))
            response.setResult(backend->contextIds()[idx]);
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetContextInfo: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(QScriptContextInfo(ctx));
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetThisObject: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(ctx->thisObject());
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetActivationObject: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx)
            response.setResult(ctx->activationObject());
        else
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
    }   break;

    case QScriptDebuggerCommand::GetScopeChain: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        if (ctx) {
            QScriptDebuggerValueList dest;
            QScriptValueList src = ctx->scopeChain();
            for (int i = 0; i < src.size(); ++i)
                dest.append(src.at(i));
            response.setResult(dest);
        } else {
            response.setError(QScriptDebuggerResponse::InvalidContextIndex);
        }
    }   break;

    case QScriptDebuggerCommand::ContextsCheckpoint: {
        response.setResult(QVariant::fromValue(backend->contextsCheckpoint()));
    }   break;

    case QScriptDebuggerCommand::GetPropertyExpressionValue: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        int lineNumber = command.lineNumber();
        QVariant attr = command.attribute(QScriptDebuggerCommand::UserAttribute);
        QStringList path = attr.toStringList();
        if (!ctx || path.isEmpty())
            break;
        QScriptContextInfo ctxInfo(ctx);
        if (ctx->callee().isValid()
            && ((lineNumber < ctxInfo.functionStartLineNumber())
                || (lineNumber > ctxInfo.functionEndLineNumber()))) {
            break;
        }
        QScriptValueList objects;
        int pathIndex = 0;
        if (path.at(0) == QLatin1String("this")) {
            objects.append(ctx->thisObject());
            ++pathIndex;
        } else {
            objects << ctx->scopeChain();
        }
        for (int i = 0; i < objects.size(); ++i) {
            QScriptValue val = objects.at(i);
            for (int j = pathIndex; val.isValid() && (j < path.size()); ++j) {
                val = val.property(path.at(j));
            }
            if (val.isValid()) {
                bool hadException = (ctx->state() == QScriptContext::ExceptionState);
                QString str = val.toString();
                if (!hadException && backend->engine()->hasUncaughtException())
                    backend->engine()->clearExceptions();
                response.setResult(str);
                break;
            }
        }
    }   break;

    case QScriptDebuggerCommand::GetCompletions: {
        QScriptContext *ctx = backend->context(command.contextIndex());
        QVariant attr = command.attribute(QScriptDebuggerCommand::UserAttribute);
        QStringList path = attr.toStringList();
        if (!ctx || path.isEmpty())
            break;
        QScriptValueList objects;
        QString prefix = path.last();
        QSet<QString> matches;
        if (path.size() > 1) {
            const QString &topLevelIdent = path.at(0);
            QScriptValue obj;
            if (topLevelIdent == QLatin1String("this")) {
                obj = ctx->thisObject();
            } else {
                QScriptValueList scopeChain;
                scopeChain = ctx->scopeChain();
                for (int i = 0; i < scopeChain.size(); ++i) {
                    QScriptValue oo = scopeChain.at(i).property(topLevelIdent);
                    if (oo.isObject()) {
                        obj = oo;
                        break;
                    }
                }
            }
            for (int i = 1; obj.isObject() && (i < path.size()-1); ++i)
                obj = obj.property(path.at(i));
            if (obj.isValid())
                objects.append(obj);
        } else {
            objects << ctx->scopeChain();
            QStringList keywords;
            keywords.append(QString::fromLatin1("this"));
            keywords.append(QString::fromLatin1("true"));
            keywords.append(QString::fromLatin1("false"));
            keywords.append(QString::fromLatin1("null"));
            for (int i = 0; i < keywords.size(); ++i) {
                const QString &kwd = keywords.at(i);
                if (isPrefixOf(prefix, kwd))
                    matches.insert(kwd);
            }
        }

        for (int i = 0; i < objects.size(); ++i) {
            QScriptValue obj = objects.at(i);
            while (obj.isObject()) {
                QScriptValueIterator it(obj);
                while (it.hasNext()) {
                    it.next();
                    QString propertyName = it.name();
                    if (isPrefixOf(prefix, propertyName))
                        matches.insert(propertyName);
                }
                obj = obj.prototype();
            }
        }
        QStringList matchesList = matches.toList();
        qStableSort(matchesList);
        response.setResult(matchesList);
    }   break;

    case QScriptDebuggerCommand::NewScriptObjectSnapshot: {
        int id = backend->newScriptObjectSnapshot();
        response.setResult(id);
    }   break;

    case QScriptDebuggerCommand::ScriptObjectSnapshotCapture: {
        int id = command.snapshotId();
        QScriptObjectSnapshot *snap = backend->scriptObjectSnapshot(id);
        Q_ASSERT(snap != 0);
        QScriptDebuggerValue object = command.scriptValue();
        Q_ASSERT(object.type() == QScriptDebuggerValue::ObjectValue);
        QScriptEngine *engine = backend->engine();
        QScriptValue realObject = object.toScriptValue(engine);
        Q_ASSERT(realObject.isObject());
        QScriptObjectSnapshot::Delta delta = snap->capture(realObject);
        QScriptDebuggerObjectSnapshotDelta result;
        result.removedProperties = delta.removedProperties;
        bool didIgnoreExceptions = backend->ignoreExceptions();
        backend->setIgnoreExceptions(true);
        for (int i = 0; i < delta.changedProperties.size(); ++i) {
            const QScriptValueProperty &src = delta.changedProperties.at(i);
            bool hadException = engine->hasUncaughtException();
            QString str = src.value().toString();
            if (!hadException && engine->hasUncaughtException())
                engine->clearExceptions();
            QScriptDebuggerValueProperty dest(src.name(), src.value(), str, src.flags());
            result.changedProperties.append(dest);
        }
        for (int j = 0; j < delta.addedProperties.size(); ++j) {
            const QScriptValueProperty &src = delta.addedProperties.at(j);
            bool hadException = engine->hasUncaughtException();
            QString str = src.value().toString();
            if (!hadException && engine->hasUncaughtException())
                engine->clearExceptions();
            QScriptDebuggerValueProperty dest(src.name(), src.value(), str, src.flags());
            result.addedProperties.append(dest);
        }
        backend->setIgnoreExceptions(didIgnoreExceptions);
        response.setResult(QVariant::fromValue(result));
    }   break;

    case QScriptDebuggerCommand::DeleteScriptObjectSnapshot: {
        int id = command.snapshotId();
        backend->deleteScriptObjectSnapshot(id);
    }   break;

    case QScriptDebuggerCommand::NewScriptValueIterator: {
        QScriptDebuggerValue object = command.scriptValue();
        Q_ASSERT(object.type() == QScriptDebuggerValue::ObjectValue);
        QScriptEngine *engine = backend->engine();
        QScriptValue realObject = object.toScriptValue(engine);
        Q_ASSERT(realObject.isObject());
        int id = backend->newScriptValueIterator(realObject);
        response.setResult(id);
    }   break;

    case QScriptDebuggerCommand::GetPropertiesByIterator: {
        int id = command.iteratorId();
        int count = 1000;
        QScriptValueIterator *it = backend->scriptValueIterator(id);
        Q_ASSERT(it != 0);
        QScriptDebuggerValuePropertyList props;
        for (int i = 0; (i < count) && it->hasNext(); ++i) {
            it->next();
            QString name = it->name();
            QScriptValue value = it->value();
            QString valueAsString = value.toString();
            QScriptValue::PropertyFlags flags = it->flags();
            QScriptDebuggerValueProperty prp(name, value, valueAsString, flags);
            props.append(prp);
        }
        response.setResult(props);
    }   break;

    case QScriptDebuggerCommand::DeleteScriptValueIterator: {
        int id = command.iteratorId();
        backend->deleteScriptValueIterator(id);
    }   break;

    case QScriptDebuggerCommand::Evaluate: {
        int contextIndex = command.contextIndex();
        QString program = command.program();
        QString fileName = command.fileName();
        int lineNumber = command.lineNumber();
        backend->evaluate(contextIndex, program, fileName, lineNumber);
        response.setAsync(true);
    }   break;

    case QScriptDebuggerCommand::ScriptValueToString: {
        QScriptDebuggerValue value = command.scriptValue();
        QScriptEngine *engine = backend->engine();
        QScriptValue realValue = value.toScriptValue(engine);
        response.setResult(realValue.toString());
    }   break;

    case QScriptDebuggerCommand::SetScriptValueProperty: {
        QScriptDebuggerValue object = command.scriptValue();
        QScriptEngine *engine = backend->engine();
        QScriptValue realObject = object.toScriptValue(engine);
        QScriptDebuggerValue value = command.subordinateScriptValue();
        QScriptValue realValue = value.toScriptValue(engine);
        QString name = command.name();
        realObject.setProperty(name, realValue);
    }   break;

    case QScriptDebuggerCommand::ClearExceptions:
        backend->engine()->clearExceptions();
        break;

    case QScriptDebuggerCommand::UserCommand:
    case QScriptDebuggerCommand::MaxUserCommand:
        break;
    }
    return response;
}
Пример #5
0
bool JsonParser::read( QIODevice* device )
{
    // Assert previous document got released.
    delete m_document;
    m_document = new GeoDataDocument;
    Q_ASSERT( m_document );

    // Fixes for test parsing
    device->seek(21); // Strip off 'onKothicDataRespone('
    QString temp = QString::fromUtf8( device->readAll() );
    int midIndex = temp.size();
    int rightIndex = midIndex;
    for ( int i=0; i<4; ++i ) {
        rightIndex = midIndex;
        midIndex = temp.lastIndexOf( ',', midIndex-1 );
        if ( i==1 ) {
            QString name = temp.mid( midIndex-1 );
            name.remove( name.size()-2,2 );
            m_document->setName( "Kothic " + name );
        }
    }

    QString stream = temp.mid(0, midIndex);
    stream.prepend('(');
    stream.append("})");
    bool hasGranularity = false;
    int const granularity = temp.mid(midIndex+15, rightIndex-midIndex-16).toInt( &hasGranularity );
    if (!hasGranularity) {
        mDebug() << "Cannot parse json file (failed to parse granularity) " << temp;
        return false;
    }

    /** THIS IS A TEST PARSER FOR KOTHIK's JSON FORMAT **/

    m_data = m_engine.evaluate( stream );
    if (m_engine.hasUncaughtException()) {
        mDebug() << "Cannot parse json file: " << m_engine.uncaughtException().toString();
        return false;
    }

    // Start parsing
    GeoDataPlacemark *placemark;
    GeoDataFeature::GeoDataVisualCategory category;

    // Bounding box coordinates
    float east;
    float south;
    float west;
    float north;

    // Global data (even if it is at the end of the json response
    // it is possible to read it now)

    if ( m_data.property( "bbox" ).isArray() ){
        QStringList coors = m_data.property( "bbox" ).toString().split( QLatin1Char( ',' ) );

        // Load the bounding box coordinates
        west  = coors.at(0).toFloat();
        east  = coors.at(2).toFloat();
        south = coors.at(1).toFloat();
        north = coors.at(3).toFloat();
    }
    else{
        mDebug() << "Cannot parse bbox";
        return false;
    }

    //  All downloaded placemarks will be features, so we should iterate
    //  on features
    QScriptValue const features = m_data.property( "features" );
    if (features.isArray()){
        QScriptValueIterator iterator( features );

        // Add items to the list
        while ( iterator.hasNext() ) {
            iterator.next();

            GeoDataGeometry * geom;
            placemark = new GeoDataPlacemark();

            QString const typeProperty = iterator.value().property( "type" ).toString();
            if ( typeProperty == "Polygon" ){
                geom = new GeoDataPolygon( RespectLatitudeCircle | Tessellate );
            } else if ( typeProperty == "LineString" ){
                    geom = new GeoDataLineString( RespectLatitudeCircle | Tessellate );
            } else if ( typeProperty == "Point" ){
                geom = new GeoDataPoint();
            } else
                    geom = 0;

            QScriptValueIterator it (iterator.value().property( "properties" ));

            bool propertiesCorrect = false;

            // Parsing properties
            while ( it.hasNext() && geom != 0 ) {
                it.next();

                if ( it.name() == "name" ){
                    placemark->setName( it.value().toString() );
                }else if ( !propertiesCorrect ){
                    category = GeoDataFeature::OsmVisualCategory( it.name() + '=' + it.value().toString() );

                    if (category != 0){
                        placemark->setVisualCategory( category );
                        propertiesCorrect = true;
                    }
                }
            }

            // Parsing coordinates

            QScriptValue const coordinatesProperty = iterator.value().property( "coordinates" );
            if ( coordinatesProperty.isArray() ){

                QScriptValueIterator it ( coordinatesProperty );

                while ( it.hasNext() ) {
                    it.next();

                    QStringList coors = it.value().toString().split( QLatin1Char( ',' ) );
                    for (int x = 0; x < coors.size()-1 && coors.size()>1 ;){

                        float auxX = ( coors.at(x++).toFloat() / granularity)*(east-west)   + west;
                        float auxY = ( coors.at(x++).toFloat() / granularity)*(north-south) + south;


                        QString const typeProperty = iterator.value().property( "type" ).toString();
                            if (typeProperty == "Polygon"){

                                GeoDataLinearRing ring = ((GeoDataPolygon*)geom)->outerBoundary();
                                ring.append( GeoDataCoordinates(auxX, auxY,0, GeoDataCoordinates::Degree ) );

                                // FIXME appending to the ring could be done more efficiently

                                ((GeoDataPolygon*)geom)->setOuterBoundary(ring);
                            }
                            else
                                if (typeProperty == "LineString"){
                                    ((GeoDataLineString*) geom)->append( GeoDataCoordinates(auxX, auxY,0, GeoDataCoordinates::Degree ) );
                           } else if (typeProperty == "Point"){
                                    ((GeoDataPoint*) geom)->setCoordinates( GeoDataCoordinates(auxX,auxY,0, GeoDataCoordinates::Degree ) );
                           }

                    }
                }
            }

            if ( propertiesCorrect && geom != 0 ){
                placemark->setGeometry( geom );
                placemark->setVisible( true );
                m_document->append( placemark );
            }
        }
    }
    return true;
}