Loading...
Searching...
No Matches
QXmppDataForm.h
// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
// SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef QXMPPDATAFORM_H
#define QXMPPDATAFORM_H
#include "QXmppConstants_p.h"
#include "QXmppStanza.h"
#if QXMPP_DEPRECATED_SINCE(1, 1)
#include <QPair>
#endif
#include <QVariant>
#include <QVector>
class QMimeType;
class QUrl;
class QXmppDataFormBase;
class QXmppDataFormPrivate;
class QXmppDataFormFieldPrivate;
class QXmppDataFormMediaPrivate;
class QXmppDataFormMediaSourcePrivate;
class QXMPP_EXPORT QXmppDataForm
{
public:
class QXMPP_EXPORT MediaSource
{
public:
MediaSource();
MediaSource(const QUrl &uri, const QMimeType &contentType);
MediaSource(const QXmppDataForm::MediaSource &);
MediaSource(QXmppDataForm::MediaSource &&);
~MediaSource();
MediaSource &operator=(const MediaSource &);
MediaSource &operator=(MediaSource &&);
QUrl uri() const;
void setUri(const QUrl &uri);
QMimeType contentType() const;
void setContentType(const QMimeType &contentType);
bool operator==(const MediaSource &other) const;
static constexpr std::tuple XmlTag = { u"uri", QXmpp::Private::ns_media_element };
private:
QSharedDataPointer<QXmppDataFormMediaSourcePrivate> d;
};
#if QXMPP_DEPRECATED_SINCE(1, 1)
class QXMPP_EXPORT Media
{
public:
QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
Media();
QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
Media(const QXmppDataForm::Media &other);
~Media();
QXmppDataForm::Media &operator=(const QXmppDataForm::Media &other);
QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().height() instead")
int height() const;
QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setHeight() instead")
void setHeight(int height);
QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().width() instead")
int width() const;
QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setWidth() instead")
void setWidth(int width);
QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() instead")
QList<QPair<QString, QString>> uris() const;
QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() instead")
void setUris(const QList<QPair<QString, QString>> &uris);
QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources().isEmpty() instead")
bool isNull() const;
private:
QSharedDataPointer<QXmppDataFormMediaPrivate> d;
};
#endif
class QXMPP_EXPORT Field
{
public:
enum Type {
BooleanField,
FixedField,
HiddenField,
JidMultiField,
JidSingleField,
ListMultiField,
ListSingleField,
TextMultiField,
TextPrivateField,
TextSingleField
};
Field(Type type = TextSingleField,
const QString &key = {},
const QVariant &value = {},
bool isRequired = false,
const QString &label = {},
const QString &description = {},
const QList<QPair<QString, QString>> &options = {});
Field(const QXmppDataForm::Field &other);
Field(QXmppDataForm::Field &&);
~Field();
QXmppDataForm::Field &operator=(const QXmppDataForm::Field &other);
QXmppDataForm::Field &operator=(QXmppDataForm::Field &&);
QString description() const;
void setDescription(const QString &description);
QString key() const;
void setKey(const QString &key);
QString label() const;
void setLabel(const QString &label);
QList<QPair<QString, QString>> options() const;
void setOptions(const QList<QPair<QString, QString>> &options);
bool isRequired() const;
void setRequired(bool required);
QXmppDataForm::Field::Type type() const;
void setType(QXmppDataForm::Field::Type type);
QVariant value() const;
void setValue(const QVariant &value);
QVector<QXmppDataForm::MediaSource> mediaSources() const;
void setMediaSources(const QVector<QXmppDataForm::MediaSource> &mediaSources);
QSize mediaSize() const;
void setMediaSize(const QSize &size);
bool operator==(const Field &other) const;
static constexpr std::tuple XmlTag = { u"field", QXmpp::Private::ns_data };
static std::optional<Field> fromDom(const QDomElement &el);
void toXml(QXmlStreamWriter *writer) const;
#if QXMPP_DEPRECATED_SINCE(1, 1)
[[deprecated("Use mediaSources() and mediaSize()")]]
Media media() const;
[[deprecated("Use setMediaSources() and setMediaSize()")]]
void setMedia(const Media &media);
#endif
#if QXMPP_DEPRECATED_SINCE(1, 12)
[[deprecated("Use const-getter or setter")]]
QVector<QXmppDataForm::MediaSource> &mediaSources();
[[deprecated("Use const-getter or setter")]]
QSize &mediaSize();
#endif
private:
QSharedDataPointer<QXmppDataFormFieldPrivate> d;
};
enum Type {
None,
Form,
Submit,
Cancel,
Result
};
QXmppDataForm(Type type = None,
const QList<Field> &fields = {},
const QString &title = {},
const QString &instructions = {});
QXmppDataForm(const QXmppDataFormBase &based);
QXmppDataForm(const QXmppDataForm &other);
QXmppDataForm(QXmppDataForm &&);
~QXmppDataForm();
QXmppDataForm &operator=(const QXmppDataForm &other);
QXmppDataForm &operator=(QXmppDataForm &&);
QString instructions() const;
void setInstructions(const QString &instructions);
QList<Field> fields() const;
const QList<Field> &constFields() const;
void setFields(const QList<QXmppDataForm::Field> &fields);
void appendField(QXmppDataForm::Field &&field);
// lookup by key
std::optional<QXmppDataForm::Field> field(QStringView fieldName) const;
std::optional<QVariant> fieldValue(QStringView fieldName) const;
QString title() const;
void setTitle(const QString &title);
QXmppDataForm::Type type() const;
void setType(QXmppDataForm::Type type);
QString formType() const;
bool isNull() const;
static constexpr std::tuple XmlTag = { u"x", QXmpp::Private::ns_data };
void parse(const QDomElement &element);
void toXml(QXmlStreamWriter *writer) const;
#if QXMPP_DEPRECATED_SINCE(1, 12)
[[deprecated("Use const-getter or setter")]]
QList<Field> &fields();
#endif
private:
QSharedDataPointer<QXmppDataFormPrivate> d;
};
Q_DECLARE_METATYPE(QXmppDataForm)
#endif
QXmppDataFormBase
Definition QXmppDataFormBase.h:15
QXmppDataForm::Field
Definition QXmppDataForm.h:93
QXmppDataForm::Field::setOptions
void setOptions(const QList< QPair< QString, QString > > &options)
Definition QXmppDataForm.cpp:409
QXmppDataForm::Field::key
QString key() const
Definition QXmppDataForm.cpp:361
QXmppDataForm::Field::mediaSize
QSize mediaSize() const
Definition QXmppDataForm.cpp:476
QXmppDataForm::Field::description
QString description() const
Definition QXmppDataForm.cpp:343
QXmppDataForm::Field::Field
Field(QXmppDataForm::Field &&)
Default move constructor.
QXmppDataForm::Field::Type
Type
This enum is used to describe a field's type.
Definition QXmppDataForm.h:96
QXmppDataForm::Field::label
QString label() const
Definition QXmppDataForm.cpp:379
QXmppDataForm::Field::mediaSources
QVector< QXmppDataForm::MediaSource > mediaSources() const
Definition QXmppDataForm.cpp:498
QXmppDataForm::Field::setKey
void setKey(const QString &key)
Definition QXmppDataForm.cpp:371
QXmppDataForm::Field::Field
Field(const QXmppDataForm::Field &other)
Constructs a copy of other.
QXmppDataForm::Field::operator=
QXmppDataForm::Field & operator=(const QXmppDataForm::Field &other)
Assigns other to this field.
QXmppDataForm::Field::~Field
~Field()
Destroys the form field.
QXmppDataForm::Field::isRequired
bool isRequired() const
Definition QXmppDataForm.cpp:419
QXmppDataForm::Field::setValue
void setValue(const QVariant &value)
Definition QXmppDataForm.cpp:465
QXmppDataForm::Field::operator=
QXmppDataForm::Field & operator=(QXmppDataForm::Field &&)
Default move-assignment operator.
QXmppDataForm::Field::setMediaSize
void setMediaSize(const QSize &size)
Definition QXmppDataForm.cpp:487
QXmppDataForm::Field::setRequired
void setRequired(bool required)
Definition QXmppDataForm.cpp:429
QXmppDataForm::Field::value
QVariant value() const
Definition QXmppDataForm.cpp:455
QXmppDataForm::Field::type
QXmppDataForm::Field::Type type() const
Definition QXmppDataForm.cpp:437
QXmppDataForm::Field::operator==
bool operator==(const Field &other) const
Definition QXmppDataForm.cpp:519
QXmppDataForm::Field::setDescription
void setDescription(const QString &description)
Definition QXmppDataForm.cpp:353
QXmppDataForm::Field::setType
void setType(QXmppDataForm::Field::Type type)
Definition QXmppDataForm.cpp:447
QXmppDataForm::Field::Field
Field(Type type=TextSingleField, const QString &key={}, const QVariant &value={}, bool isRequired=false, const QString &label={}, const QString &description={}, const QList< QPair< QString, QString > > &options={})
Definition QXmppDataForm.cpp:311
QXmppDataForm::Field::setLabel
void setLabel(const QString &label)
Definition QXmppDataForm.cpp:389
QXmppDataForm::Field::setMediaSources
void setMediaSources(const QVector< QXmppDataForm::MediaSource > &mediaSources)
Definition QXmppDataForm.cpp:509
QXmppDataForm::Field::options
QList< QPair< QString, QString > > options() const
Definition QXmppDataForm.cpp:397
QXmppDataForm::MediaSource
Definition QXmppDataForm.h:31
QXmppDataForm::MediaSource::setContentType
void setContentType(const QMimeType &contentType)
Definition QXmppDataForm.cpp:132
QXmppDataForm::MediaSource::operator=
MediaSource & operator=(MediaSource &&)
Default move-assignment operator.
QXmppDataForm::MediaSource::operator=
MediaSource & operator=(const MediaSource &)
Default assignment operator.
QXmppDataForm::MediaSource::MediaSource
MediaSource(const QXmppDataForm::MediaSource &)
Default copy-constructor.
QXmppDataForm::MediaSource::MediaSource
MediaSource()
Definition QXmppDataForm.cpp:76
QXmppDataForm::MediaSource::contentType
QMimeType contentType() const
Definition QXmppDataForm.cpp:124
QXmppDataForm::MediaSource::operator==
bool operator==(const MediaSource &other) const
Definition QXmppDataForm.cpp:140
QXmppDataForm::MediaSource::uri
QUrl uri() const
Definition QXmppDataForm.cpp:108
QXmppDataForm::MediaSource::setUri
void setUri(const QUrl &uri)
Definition QXmppDataForm.cpp:116
QXmppDataForm::MediaSource::MediaSource
MediaSource(QXmppDataForm::MediaSource &&)
Default move-constructor.
QXmppDataForm::Media
Definition QXmppDataForm.h:59
QXmppDataForm::Media::setUris
void setUris(const QList< QPair< QString, QString > > &uris)
Definition QXmppDataForm.cpp:253
QXmppDataForm::Media::Media
Media()
Definition QXmppDataForm.cpp:166
QXmppDataForm::Media::uris
QList< QPair< QString, QString > > uris() const
Definition QXmppDataForm.cpp:242
QXmppDataForm::Media::setHeight
void setHeight(int height)
Definition QXmppDataForm.cpp:209
QXmppDataForm::Media::width
int width() const
Definition QXmppDataForm.cpp:220
QXmppDataForm::Media::setWidth
void setWidth(int width)
Definition QXmppDataForm.cpp:231
QXmppDataForm::Media::height
int height() const
Definition QXmppDataForm.cpp:198
QXmppDataForm::Media::isNull
bool isNull() const
Definition QXmppDataForm.cpp:261
QXmppDataForm
Definition QXmppDataForm.h:28
QXmppDataForm::appendField
void appendField(QXmppDataForm::Field &&field)
Definition QXmppDataForm.cpp:779
QXmppDataForm::fields
QList< Field > fields() const
Returns all fields.
Definition QXmppDataForm.cpp:759
QXmppDataForm::QXmppDataForm
QXmppDataForm(QXmppDataForm &&)
Default move constructor.
QXmppDataForm::constFields
const QList< Field > & constFields() const
Definition QXmppDataForm.cpp:766
QXmppDataForm::type
QXmppDataForm::Type type() const
Definition QXmppDataForm.cpp:851
QXmppDataForm::operator=
QXmppDataForm & operator=(QXmppDataForm &&)
Default move-assignment operator.
QXmppDataForm::setType
void setType(QXmppDataForm::Type type)
Definition QXmppDataForm.cpp:861
QXmppDataForm::field
std::optional< QXmppDataForm::Field > field(QStringView fieldName) const
Definition QXmppDataForm.cpp:789
QXmppDataForm::setInstructions
void setInstructions(const QString &instructions)
Definition QXmppDataForm.cpp:825
QXmppDataForm::QXmppDataForm
QXmppDataForm(const QXmppDataForm &other)
Constructs a copy of other.
QXmppDataForm::operator=
QXmppDataForm & operator=(const QXmppDataForm &other)
Assigns other to this form.
QXmppDataForm::isNull
bool isNull() const
Definition QXmppDataForm.cpp:890
QXmppDataForm::formType
QString formType() const
Definition QXmppDataForm.cpp:874
QXmppDataForm::fieldValue
std::optional< QVariant > fieldValue(QStringView fieldName) const
Definition QXmppDataForm.cpp:803
QXmppDataForm::title
QString title() const
Definition QXmppDataForm.cpp:833
QXmppDataForm::setFields
void setFields(const QList< QXmppDataForm::Field > &fields)
Sets the form's fields.
Definition QXmppDataForm.cpp:772
QXmppDataForm::instructions
QString instructions() const
Definition QXmppDataForm.cpp:815
QXmppDataForm::~QXmppDataForm
~QXmppDataForm()
Destroys the form.
QXmppDataForm::Type
Type
This enum is used to describe a form's type.
Definition QXmppDataForm.h:176
QXmppDataForm::None
@ None
Unknown form type.
Definition QXmppDataForm.h:177
QXmppDataForm::Form
@ Form
Definition QXmppDataForm.h:178
QXmppDataForm::Cancel
@ Cancel
Definition QXmppDataForm.h:182
QXmppDataForm::Result
@ Result
Definition QXmppDataForm.h:184
QXmppDataForm::Submit
@ Submit
Definition QXmppDataForm.h:180
QXmppDataForm::QXmppDataForm
QXmppDataForm(Type type=None, const QList< Field > &fields={}, const QString &title={}, const QString &instructions={})
Definition QXmppDataForm.cpp:725
QXmppDataForm::setTitle
void setTitle(const QString &title)
Definition QXmppDataForm.cpp:843