XDataField_TextMulti(XData::Field f, QGridLayout *grid, int row, QWidget *parent)
        : XDataField(f)
    {
        QLabel *label = new QLabel(labelText(), parent);
        grid->addWidget(label, row, 0);

        edit = new QTextEdit(parent);
        grid->addWidget(edit, row, 1);

        QString text;
        QStringList val = f.value();
        QStringList::Iterator it = val.begin();
        for ( ; it != val.end(); ++it) {
            if ( !text.isEmpty() )
                text += "\n";
            text += *it;
        }
        edit->setText(text);

        QLabel *req = new QLabel(reqText(), parent);
        grid->addWidget(req, row, 2);

        if ( !f.desc().isEmpty() ) {
            label->setToolTip(f.desc());
            edit->setToolTip(f.desc());
            req->setToolTip(f.desc());
        }
    }
    XDataField_Boolean(XData::Field f, QGridLayout *grid, int row, QWidget *parent)
        : XDataField(f)
    {
        bool checked = false;
        if ( f.value().count() ) {
            QString s = f.value().first();
            if ( s == "1" || s == "true" || s == "yes" )
                checked = true;
        }

        QLabel *label = new QLabel(labelText(), parent);
        grid->addWidget(label, row, 0);

        check = new QCheckBox(parent);
        check->setChecked(checked);
        grid->addWidget(check, row, 1);

        QLabel *req = new QLabel(reqText(), parent);
        grid->addWidget(req, row, 2);

        if ( !f.desc().isEmpty() ) {
            label->setToolTip(f.desc());
            check->setToolTip(f.desc());
            req->setToolTip(f.desc());
        }
    }
 XData::Field field() const
 {
     XData::Field f = XDataField::field();
     QStringList val;
     val << edit->text();
     f.setValue(val);
     return f;
 }
 XData::Field field() const
 {
     XData::Field f = XDataField::field();
     QStringList val;
     val << QString( check->isChecked() ? "1" : "0" );
     f.setValue(val);
     return f;
 }
Exemple #5
0
XData Util::parseXData(const XmlElement& el)
{
    xmpp_stanza_t* elPtr {el.getStanzaPtr()};
    xmpp_stanza_t* field {xmpp_stanza_get_children(elPtr)};  

    std::string type {makeString(xmpp_stanza_get_type(elPtr))};
     
    XData ret {type};

    while(field)
    {
        if(makeString(xmpp_stanza_get_name(field)) == "field")
        {
            std::string fieldType {makeString(xmpp_stanza_get_type(field))};
            std::string var {makeString(xmpp_stanza_get_attribute(field, "var"))};

            std::vector<std::string> values;

            xmpp_stanza_t* value {xmpp_stanza_get_children(field)};

            while(value)
            {
                if(makeString(xmpp_stanza_get_name(value)) == "value")
                {
                    char* text {xmpp_stanza_get_text(value)};
                    values.emplace_back(makeString(text));
                    xmpp_free(value->ctx, text);
                }

                value = xmpp_stanza_get_next(value);
            }

            XData::Field newField {fieldType, var, values};

            if(not newField.isValid())
            {
                throw std::runtime_error {""};
            }

            ret.addField(newField);
        }

        field = xmpp_stanza_get_next(field);
    }

    return ret;
}
    XData::Field field() const
    {
        QString lbl = combo->currentText();

        XData::Field f = XDataField::field();
        QStringList val;

        XData::Field::OptionList opts = f.options();
        XData::Field::OptionList::Iterator it = opts.begin();
        for ( ; it != opts.end(); ++it) {
            if ( (*it).label == lbl || (*it).value == lbl ) {
                val << (*it).value;
                break;
            }
        }

        f.setValue(val);
        return f;
    }
    XDataField_Fixed(XData::Field f, QGridLayout *grid, int row, QWidget *parent)
        : XDataField(f)
    {
        QString text;
        QStringList val = f.value();
        QStringList::Iterator it = val.begin();
        for ( ; it != val.end(); ++it) {
            if ( !text.isEmpty() )
                text += "<br>";
            text += *it;
        }

        QLabel *fixed = new QLabel("<qt>" + text + "</qt>", parent);
        grid->addMultiCellWidget(fixed, row, row, 0, 2);

        if ( !f.desc().isEmpty() ) {
            fixed->setToolTip(f.desc());
        }
    }
    XDataField_ListMulti(XData::Field f, QGridLayout *grid, int row, QWidget *parent)
        : XDataField(f)
    {
        QLabel *label = new QLabel(labelText(), parent);
        grid->addWidget(label, row, 0);

        list = new QListWidget(parent);
        grid->addWidget(list, row, 1);
        list->setSelectionMode(QAbstractItemView::MultiSelection);

        XData::Field::OptionList opts = f.options();
        XData::Field::OptionList::Iterator it = opts.begin();
        for ( ; it != opts.end(); ++it) {
            QString lbl = (*it).label;
            if ( lbl.isEmpty() )
                lbl = (*it).value;

            QListWidgetItem* item = new QListWidgetItem(lbl,list);

            QStringList val = f.value();
            QStringList::Iterator sit = val.begin();
            for ( ; sit != val.end(); ++sit)
                if ( (*it).label == *sit || (*it).value == *sit )
                    list->setItemSelected(item, true);
        }

        QLabel *req = new QLabel(reqText(), parent);
        grid->addWidget(req, row, 2);

        if ( !f.desc().isEmpty() ) {
            label->setToolTip(f.desc());
            list->setToolTip(f.desc());
            req->setToolTip(f.desc());
        }
    }
    XDataField_ListSingle(XData::Field f, QGridLayout *grid, int row, QWidget *parent)
        : XDataField(f)
    {
        QLabel *label = new QLabel(labelText(), parent);
        grid->addWidget(label, row, 0);

        combo = new QComboBox(parent);
        grid->addWidget(combo, row, 1);
        combo->setInsertionPolicy(QComboBox::NoInsertion);

        QString sel;
        if ( !f.value().isEmpty() )
            sel = f.value().first();

        XData::Field::OptionList opts = f.options();
        XData::Field::OptionList::Iterator it = opts.begin();
        for ( ; it != opts.end(); ++it) {
            QString lbl = (*it).label;
            if ( lbl.isEmpty() )
                lbl = (*it).value;

            combo->insertItem(lbl);
            if ( (*it).value == sel )
                combo->setCurrentText( lbl );
        }

        QLabel *req = new QLabel(reqText(), parent);
        grid->addWidget(req, row, 2);

        if ( !f.desc().isEmpty() ) {
            label->setToolTip(f.desc());
            combo->setToolTip(f.desc());
            req->setToolTip(f.desc());
        }
    }
    XData::Field field() const
    {
        XData::Field f = XDataField::field();
        QStringList val;

        for (int i = 0; i < list->count(); i++) {
            QListWidgetItem* item = list->item(i);
            if ( list->isItemSelected(item) ) {
                QString lbl = item->text();
                XData::Field::OptionList opts = f.options();
                XData::Field::OptionList::Iterator it = opts.begin();
                for ( ; it != opts.end(); ++it) {
                    if ( (*it).label == lbl || (*it).value == lbl ) {
                        val << (*it).value;
                        break;
                    }
                }
            }
        }

        f.setValue(val);
        return f;
    }
    XDataField_TextSingle(XData::Field f, QGridLayout *grid, int row, QWidget *parent)
        : XDataField(f)
    {
        QString text;
        if ( f.value().count() )
            text = f.value().first();

        QLabel *label = new QLabel(labelText(), parent);
        grid->addWidget(label, row, 0);

        edit = new QLineEdit(parent);
        edit->setText(text);
        grid->addWidget(edit, row, 1);

        QLabel *req = new QLabel(reqText(), parent);
        grid->addWidget(req, row, 2);

        if ( !f.desc().isEmpty() ) {
            label->setToolTip(f.desc());
            edit->setToolTip(f.desc());
            req->setToolTip(f.desc());
        }
    }
Exemple #12
0
void HttpFileUpload::start()
{
    if (d->state != State::None) // Attempt to start twice?
        return;

    setState(State::GettingSlot);

    d->result.statusCode = HttpFileUpload::ErrorCode::NoError;
    static QList<QSet<QString>> featureOptions;
    if (featureOptions.isEmpty()) {
        featureOptions << (QSet<QString>() << xmlns_v0_2_5) << (QSet<QString>() << xmlns_v0_3_1);
    }
    d->client->serverInfoManager()->queryServiceInfo(
                QLatin1String("store"), QLatin1String("file"),
                featureOptions, QRegExp("^(upload|http|stor|file|dis|drive).*"), ServerInfoManager::SQ_CheckAllOnNoMatch,
                [this](const QList<DiscoItem> &items)
    {
        d->httpHosts.clear();
        for (const auto &item: items) {
            const QStringList &l = item.features().list();
            XEP0363::version ver = XEP0363::vUnknown;
            QString xmlns;
            quint64 sizeLimit = 0;
            if (l.contains(xmlns_v0_3_1)) {
                ver = XEP0363::v0_3_1;
                xmlns = xmlns_v0_3_1;
            } else if (l.contains(xmlns_v0_2_5)) {
                ver = XEP0363::v0_2_5;
                xmlns = xmlns_v0_2_5;
            }
            if (ver != XEP0363::vUnknown) {
                QList<std::pair<HttpHost,int>> hosts;
                const XData::Field field = item.registeredExtension(xmlns).getField(QLatin1String("max-file-size"));
                if (field.isValid() && field.type() == XData::Field::Field_TextSingle)
                    sizeLimit = field.value().at(0).toULongLong();
                HttpHost host;
                host.ver = ver;
                host.jid = item.jid();
                host.sizeLimit = sizeLimit;
                QVariant metaProps(d->client->serverInfoManager()->serviceMeta(host.jid, "httpprops"));
                if (metaProps.isValid()) {
                    host.props = HostProps(metaProps.value<int>());
                } else {
                    host.props = SecureGet | SecurePut;
                    if (ver == XEP0363::v0_3_1)
                        host.props |= NewestVer;
                }
                int value = 0;
                if (host.props & SecureGet) value += 5;
                if (host.props & SecurePut) value += 5;
                if (host.props & NewestVer) value += 3;
                if (host.props & Failure) value -= 15;
                if (!sizeLimit || d->fileSize < sizeLimit)
                    hosts.append({host,value});

                // no sorting in preference order. most preferred go first
                std::sort(hosts.begin(), hosts.end(), [](const auto &a, const auto &b){
                    return a.second > b.second;
                });
                for (auto &hp: hosts) {
                    d->httpHosts.append(hp.first);
                }
            }
        }
        //d->currentHost = d->httpHosts.begin();
        if (d->httpHosts.isEmpty()) { // if empty as the last resort check all services
            d->result.statusCode   = HttpFileUpload::ErrorCode::NoUploadService;
            d->result.statusString = "No suitable http upload services were found";
            done(State::Error);
        } else {
            tryNextServer();
        }
    });
}
 XData::Field field() const
 {
     XData::Field f = XDataField::field();
     f.setValue( QStringList::split("\n", edit->text(), true) );
     return f;
 }
Exemple #14
0
	XData::Field field() const
	{
		XData::Field f = XDataField::field();
		f.setValue( edit->toPlainText().split("\n") );
		return f;
	}