static QString qjsValueToString(const QJSValue &v)
{
  if (v.isArray()) {
    return QStringLiteral("<array>");
  } else if (v.isBool()) {
    return v.toBool() ? QStringLiteral("true") : QStringLiteral("false");
  } else if (v.isCallable()) {
    return QStringLiteral("<callable>");
  } else if (v.isDate()) {
    return v.toDateTime().toString();
  } else if (v.isError()) {
    return QStringLiteral("<error>");
  } else if (v.isNull()) {
    return QStringLiteral("<null>");
  } else if (v.isNumber()) {
    return QString::number(v.toNumber());
  } else if (v.isObject()) {
    return QStringLiteral("<object>");
  } else if (v.isQObject()) {
    return Util::displayString(v.toQObject());
  } else if (v.isRegExp()) {
    return QStringLiteral("<regexp>");
  } else if (v.isString()) {
    return v.toString();
  } else if (v.isUndefined()) {
    return QStringLiteral("<undefined>");
  } else if (v.isVariant()) {
    return VariantHandler::displayString(v.toVariant());
  }
  return QStringLiteral("<unknown QJSValue>");
}
void TelegramMembersListModel::setDateConvertorMethod(const QJSValue &method)
{
    if(p->dateConvertorMethod.isNull() && method.isNull())
        return;

    p->dateConvertorMethod = method;
    Q_EMIT dateConvertorMethodChanged();
}
Ejemplo n.º 3
0
void TelegramCache::setDecryptMethod(const QJSValue &method)
{
    if(p->decryptMethod.isNull() && method.isNull())
        return;

    p->decryptMethod = method;
    Q_EMIT decryptMethodChanged();
}
Ejemplo n.º 4
0
void JSKitXMLHttpRequest::send(const QJSValue &data)
{
    QByteArray byteData;

    if (data.isUndefined() || data.isNull()) {
        // Do nothing, byteData is empty.
    } else if (data.isString()) {
        byteData == data.toString().toUtf8();
    } else if (data.isObject()) {
        if (data.hasProperty("byteLength")) {
            // Looks like an ArrayView or an ArrayBufferView!
            QJSValue buffer = data.property("buffer");
            if (buffer.isUndefined()) {
                // We must assume we've been passed an ArrayBuffer directly
                buffer = data;
            }

            QJSValue array = data.property("_bytes");
            int byteLength = data.property("byteLength").toInt();

            if (array.isArray()) {
                byteData.reserve(byteLength);

                for (int i = 0; i < byteLength; i++) {
                    byteData.append(array.property(i).toInt());
                }

                qCDebug(l) << "passed an ArrayBufferView of" << byteData.length() << "bytes";
            } else {
                qCWarning(l) << "passed an unknown/invalid ArrayBuffer" << data.toString();
            }
        } else {
            qCWarning(l) << "passed an unknown object" << data.toString();
        }

    }

    QBuffer *buffer;
    if (!byteData.isEmpty()) {
        buffer = new QBuffer;
        buffer->setData(byteData);
    } else {
        buffer = 0;
    }

    qCDebug(l) << "sending" << _verb << "to" << _request.url() << "with" << QString::fromUtf8(byteData);
    _reply = _net->sendCustomRequest(_request, _verb.toLatin1(), buffer);

    connect(_reply, &QNetworkReply::finished,
            this, &JSKitXMLHttpRequest::handleReplyFinished);
    connect(_reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
            this, &JSKitXMLHttpRequest::handleReplyError);

    if (buffer) {
        // So that it gets deleted alongside the reply object.
        buffer->setParent(_reply);
    }
}
Ejemplo n.º 5
0
void
QPython::call(QVariant func, QVariant args, QJSValue callback)
{
    QJSValue *cb = 0;
    if (!callback.isNull() && !callback.isUndefined() && callback.isCallable()) {
        cb = new QJSValue(callback);
    }
    emit process(func, args, cb);
}
Ejemplo n.º 6
0
void
QPython::setHandler(QString event, QJSValue callback)
{
    if (!callback.isCallable() || callback.isNull() || callback.isUndefined()) {
        handlers.remove(event);
    } else {
        handlers[event] = callback;
    }
}
Ejemplo n.º 7
0
void
QPython::importModule(QString name, QJSValue callback)
{
    QJSValue *cb = 0;
    if (!callback.isNull() && !callback.isUndefined() && callback.isCallable()) {
        cb = new QJSValue(callback);
    }
    emit import(name, cb);
}
Ejemplo n.º 8
0
Option<Error> jsToJson(QJSValue value, JsonValue::Builder builder) {
    if (value.isArray()) {
        std::vector<QJSValue> arr;
        QJSValueIterator iter(value);
        while (iter.hasNext()) {
            iter.next();
            // dafuq!? why is this required
            if (!iter.hasNext()) {
                break;
            }
            arr.push_back(iter.value());
        }
        auto lst = builder.initArray(static_cast<unsigned int>(arr.size()));
        for (auto k = 0; k < arr.size(); ++k) {
            auto subvalue = lst[k];
            auto opt_err = jsToJson(arr[k], subvalue);
            if (opt_err.has()) {
                return opt_err;
            }
        }
        return Option<Error>();
    } if (value.isObject()) {
        std::vector<std::tuple<QString, QJSValue>> arr;
        QJSValueIterator iter(value);
        while (iter.hasNext()) {
            iter.next();
            arr.push_back(std::make_tuple(iter.name(), iter.value()));
        }
        auto lst = builder.initObject(static_cast<unsigned int>(arr.size()));
        for (auto k = 0; k < arr.size(); ++k) {
            auto value_builder = lst[k].initValue();
            const char *name = std::get<0>(arr[k]).toUtf8().constData();
            lst[k].setName(name);
            auto opt_err = jsToJson(std::get<1>(arr[k]), value_builder);
            if (opt_err.has()) {
                return opt_err;
            }
        }
        return Option<Error>();
    } if (value.isBool()) {
        builder.setBoolean(value.toBool());
        return Option<Error>();
    } if (value.isNumber()) {
        builder.setNumber(value.toNumber());
        return Option<Error>();
    } if (value.isString()) {
        const char *str = value.toString().toUtf8().constData();
        builder.setString(str);
        return Option<Error>();
    } if (value.isNull()) {
        builder.setNone();
        return Option<Error>();
    }
    auto tpname = toStdString(value.toVariant().typeName());
    Error err(Error::Kind::ClientSideError, "Invalid type: " + tpname);
    return err;
}
Ejemplo n.º 9
0
void SortFilterModel::setFilterCallback(const QJSValue& callback)
{
    if (m_filterCallback.strictlyEquals(callback)) {
        return;
    }

    if (!callback.isNull() && !callback.isCallable()) {
        return;
    }

    m_filterCallback = callback;
    invalidateFilter();

    emit filterCallbackChanged(callback);
}