QXmpp  Version:1.1.0
QXmppDataForm.h
1 /*
2  * Copyright (C) 2008-2019 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 
46 
47 class QXMPP_EXPORT QXmppDataForm
48 {
49 public:
55 
56  class QXMPP_EXPORT MediaSource
57  {
58  public:
59  MediaSource();
60  MediaSource(const QUrl &uri, const QMimeType &contentType);
62  ~MediaSource();
63 
64  MediaSource &operator=(const MediaSource &);
65 
66  QUrl uri() const;
67  void setUri(const QUrl &uri);
68 
69  QMimeType contentType() const;
70  void setContentType(const QMimeType &contentType);
71 
72  bool operator==(const MediaSource &other) const;
73 
74  private:
75  QSharedDataPointer<QXmppDataFormMediaSourcePrivate> d;
76  };
77 
78 #if QXMPP_DEPRECATED_SINCE(1, 1)
79 
84  class QXMPP_EXPORT Media
85  {
86  public:
87  QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
88  Media();
89  QT_DEPRECATED_X("Use QXmppDataForm::Field() instead")
90  Media(const QXmppDataForm::Media &other);
91  ~Media();
92 
93  QXmppDataForm::Media& operator=(const QXmppDataForm::Media &other);
94 
95  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().height() instead")
96  int height() const;
97  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setHeight() instead")
98  void setHeight(int height);
99 
100  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().width() instead")
101  int width() const;
102  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSize().setWidth() instead")
103  void setWidth(int width);
104 
105  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() instead")
106  QList<QPair<QString, QString> > uris() const;
107  QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() instead")
108  void setUris(const QList<QPair<QString, QString> > &uris);
109 
110  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources().isEmpty() instead")
111  bool isNull() const;
112 
113  private:
114  QSharedDataPointer<QXmppDataFormMediaPrivate> d;
115  };
116 #endif
117 
120 
121  class QXMPP_EXPORT Field
122  {
123  public:
125  enum Type
126  {
127  BooleanField,
128  FixedField,
129  HiddenField,
130  JidMultiField,
131  JidSingleField,
132  ListMultiField,
133  ListSingleField,
134  TextMultiField,
135  TextPrivateField,
136  TextSingleField
137  };
138 
139  Field(QXmppDataForm::Field::Type type = QXmppDataForm::Field::TextSingleField);
140  Field(const QXmppDataForm::Field &other);
141  ~Field();
142 
143  QXmppDataForm::Field& operator=(const QXmppDataForm::Field &other);
144 
145  QString description() const;
146  void setDescription(const QString &description);
147 
148  QString key() const;
149  void setKey(const QString &key);
150 
151  QString label() const;
152  void setLabel(const QString &label);
153 
154 #if QXMPP_DEPRECATED_SINCE(1, 1)
155  QT_DEPRECATED_X("Use QXmppDataForm::Field::mediaSources() or QXmppDataForm::Field::mediaSize() instead")
156  Media media() const;
157 
158  QT_DEPRECATED_X("Use QXmppDataForm::Field::setMediaSources() or QXmppDataForm::Field::setMediaSize() instead")
159  void setMedia(const Media &media);
160 #endif
161 
162  QList<QPair<QString, QString> > options() const;
163  void setOptions(const QList<QPair<QString, QString> > &options);
164 
165  bool isRequired() const;
166  void setRequired(bool required);
167 
168  QXmppDataForm::Field::Type type() const;
169  void setType(QXmppDataForm::Field::Type type);
170 
171  QVariant value() const;
172  void setValue(const QVariant &value);
173 
174  QVector<QXmppDataForm::MediaSource> &mediaSources();
175  QVector<QXmppDataForm::MediaSource> mediaSources() const;
176  void setMediaSources(const QVector<QXmppDataForm::MediaSource> &mediaSources);
177 
178  QSize mediaSize() const;
179  QSize &mediaSize();
180  void setMediaSize(const QSize &size);
181 
182  bool operator==(const Field &other) const;
183 
184  private:
185  QSharedDataPointer<QXmppDataFormFieldPrivate> d;
186  };
187 
189  enum Type
190  {
192  Form,
193  Submit,
195  Cancel,
197  Result
199  };
202 
204  QXmppDataForm(const QXmppDataForm &other);
205  ~QXmppDataForm();
206 
207  QXmppDataForm& operator=(const QXmppDataForm &other);
208 
209  QString instructions() const;
210  void setInstructions(const QString &instructions);
211 
212  QList<Field> fields() const;
213  QList<Field> &fields();
214  void setFields(const QList<QXmppDataForm::Field> &fields);
215 
216  QString title() const;
217  void setTitle(const QString &title);
218 
219  QXmppDataForm::Type type() const;
220  void setType(QXmppDataForm::Type type);
221 
222  bool isNull() const;
223 
225  void parse(const QDomElement &element);
226  void toXml(QXmlStreamWriter *writer) const;
228 
229 private:
230  QSharedDataPointer<QXmppDataFormPrivate> d;
231 };
232 
233 #endif
Type
This enum is used to describe a form&#39;s type.
Definition: QXmppDataForm.h:189
Unknown form type.
Definition: QXmppDataForm.h:191
Type
This enum is used to describe a field&#39;s type.
Definition: QXmppDataForm.h:125
The QXmppDataForm::MediaSource class represents a link to one of possibly multiple sources for a medi...
Definition: QXmppDataForm.h:56
The QXmppDataForm class represents a data form as defined by XEP-0004: Data Forms.
Definition: QXmppDataForm.h:47
The QXmppDataForm::Field class represents a data form field as defined by XEP-0004: Data Forms...
Definition: QXmppDataForm.h:121
The QXmppDataForm::Media class represents a media field as defined by XEP-0221: Data Forms Media Elem...
Definition: QXmppDataForm.h:84