QXmpp  Version:1.3.1
QXmppDataForm.h
1 /*
2  * Copyright (C) 2008-2020 The QXmpp developers
3  *
4  * Author:
5  * Jeremy LainĂ©
6  * Linus Jahn
7  *
8  * Source:
9  * https://github.com/qxmpp-project/qxmpp
10  *
11  * This file is a part of QXmpp library.
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  */
24 
25 #ifndef QXMPPDATAFORM_H
26 #define QXMPPDATAFORM_H
27 
28 #include "QXmppStanza.h"
29 
30 #if QXMPP_DEPRECATED_SINCE(1, 1)
31 #include <QPair>
32 #endif
33 #include <QVariant>
34 #include <QVector>
35 
36 class QMimeType;
37 class QUrl;
38 
39 class QXmppDataFormPrivate;
40 class QXmppDataFormFieldPrivate;
41 class QXmppDataFormMediaPrivate;
42 class QXmppDataFormMediaSourcePrivate;
43 
48 class QXMPP_EXPORT QXmppDataForm
49 {
50 public:
58  class QXMPP_EXPORT MediaSource
59  {
60  public:
61  MediaSource();
62  MediaSource(const QUrl &uri, const QMimeType &contentType);
64  ~MediaSource();
65 
66  MediaSource &operator=(const MediaSource &);
67 
68  QUrl uri() const;
69  void setUri(const QUrl &uri);
70 
71  QMimeType contentType() const;
72  void setContentType(const QMimeType &contentType);
73 
74  bool operator==(const MediaSource &other) const;
75 
76  private:
77  QSharedDataPointer<QXmppDataFormMediaSourcePrivate> d;
78  };
79 
80 #if QXMPP_DEPRECATED_SINCE(1, 1)
81  class QXMPP_EXPORT Media
88  {
89  public:
90  QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
91  Media();
92  QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
93  Media(const QXmppDataForm::Media &other);
94  ~Media();
95 
96  QXmppDataForm::Media &operator=(const QXmppDataForm::Media &other);
97 
98  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().height() instead")
99  int height() const;
100  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setHeight() instead")
101  void setHeight(int height);
102 
103  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().width() instead")
104  int width() const;
105  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setWidth() instead")
106  void setWidth(int width);
107 
108  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() instead")
109  QList<QPair<QString, QString>> uris() const;
110  QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() instead")
111  void setUris(const QList<QPair<QString, QString>> &uris);
112 
113  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources().isEmpty() instead")
114  bool isNull() const;
115 
116  private:
117  QSharedDataPointer<QXmppDataFormMediaPrivate> d;
118  };
119 #endif
120 
125  class QXMPP_EXPORT Field
126  {
127  public:
129  enum Type {
130  BooleanField,
131  FixedField,
132  HiddenField,
133  JidMultiField,
134  JidSingleField,
135  ListMultiField,
136  ListSingleField,
137  TextMultiField,
138  TextPrivateField,
139  TextSingleField
140  };
141 
142  // ### QXmpp2: merge ctors
143  Field(QXmppDataForm::Field::Type type = QXmppDataForm::Field::TextSingleField);
145  const QString &key,
146  const QVariant &value = {},
147  bool isRequired = false,
148  const QString &label = {},
149  const QString &description = {},
150  const QList<QPair<QString, QString>> &options = {});
151  Field(const QXmppDataForm::Field &other);
152  ~Field();
153 
154  QXmppDataForm::Field &operator=(const QXmppDataForm::Field &other);
155 
156  QString description() const;
157  void setDescription(const QString &description);
158 
159  QString key() const;
160  void setKey(const QString &key);
161 
162  QString label() const;
163  void setLabel(const QString &label);
164 
165 #if QXMPP_DEPRECATED_SINCE(1, 1)
166  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() or QXmppDataForm::Field::mediaSize() instead")
167  Media media() const;
168 
169  QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() or QXmppDataForm::Field::setMediaSize() instead")
170  void setMedia(const Media &media);
171 #endif
172 
173  QList<QPair<QString, QString>> options() const;
174  void setOptions(const QList<QPair<QString, QString>> &options);
175 
176  bool isRequired() const;
177  void setRequired(bool required);
178 
179  QXmppDataForm::Field::Type type() const;
180  void setType(QXmppDataForm::Field::Type type);
181 
182  QVariant value() const;
183  void setValue(const QVariant &value);
184 
185  QVector<QXmppDataForm::MediaSource> &mediaSources();
186  QVector<QXmppDataForm::MediaSource> mediaSources() const;
187  void setMediaSources(const QVector<QXmppDataForm::MediaSource> &mediaSources);
188 
189  QSize mediaSize() const;
190  QSize &mediaSize();
191  void setMediaSize(const QSize &size);
192 
193  bool operator==(const Field &other) const;
194 
195  private:
196  QSharedDataPointer<QXmppDataFormFieldPrivate> d;
197  };
198 
200  enum Type {
202  Form,
203  Submit,
205  Cancel,
207  Result
209  };
212 
213  // ### QXmpp2: merge ctors
216  const QList<Field> &fields,
217  const QString &title = {},
218  const QString &instructions = {});
219  QXmppDataForm(const QXmppDataForm &other);
220  ~QXmppDataForm();
221 
222  QXmppDataForm &operator=(const QXmppDataForm &other);
223 
224  QString instructions() const;
225  void setInstructions(const QString &instructions);
226 
227  QList<Field> fields() const;
228  QList<Field> &fields();
229  void setFields(const QList<QXmppDataForm::Field> &fields);
230 
231  QString title() const;
232  void setTitle(const QString &title);
233 
234  QXmppDataForm::Type type() const;
235  void setType(QXmppDataForm::Type type);
236 
237  bool isNull() const;
238 
240  void parse(const QDomElement &element);
241  void toXml(QXmlStreamWriter *writer) const;
243 
244 private:
245  QSharedDataPointer<QXmppDataFormPrivate> d;
246 };
247 
248 #endif
QXmppDataForm::Field::Type
Type
This enum is used to describe a field's type.
Definition: QXmppDataForm.h:129
QXmppDataForm::Field
The QXmppDataForm::Field class represents a data form field as defined by XEP-0004: Data Forms.
Definition: QXmppDataForm.h:125
QXmppDataForm
The QXmppDataForm class represents a data form as defined by XEP-0004: Data Forms.
Definition: QXmppDataForm.h:48
QXmppDataForm::None
@ None
Unknown form type.
Definition: QXmppDataForm.h:201
QXmppDataForm::Media
The QXmppDataForm::Media class represents a media field as defined by XEP-0221: Data Forms Media Elem...
Definition: QXmppDataForm.h:87
QXmppDataForm::MediaSource
The QXmppDataForm::MediaSource class represents a link to one of possibly multiple sources for a medi...
Definition: QXmppDataForm.h:58
QXmppDataForm::Type
Type
This enum is used to describe a form's type.
Definition: QXmppDataForm.h:200