| 1 | /*
|
|---|
| 2 | * xmpp_xdata.h - a class for jabber:x:data forms
|
|---|
| 3 | * Copyright (C) 2003-2004 Michail Pishchagin
|
|---|
| 4 | *
|
|---|
| 5 | * This program is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU General Public License
|
|---|
| 7 | * as published by the Free Software Foundation; either version 2
|
|---|
| 8 | * of the License, or (at your option) any later version.
|
|---|
| 9 | *
|
|---|
| 10 | * This program is distributed in the hope that it will be useful,
|
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | * GNU General Public License for more details.
|
|---|
| 14 | *
|
|---|
| 15 | * You should have received a copy of the GNU General Public License
|
|---|
| 16 | * along with this library; if not, write to the Free Software
|
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 18 | *
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #ifndef XMPPXDATA_H
|
|---|
| 22 | #define XMPPXDATA_H
|
|---|
| 23 |
|
|---|
| 24 | #include <qvaluelist.h>
|
|---|
| 25 |
|
|---|
| 26 | #include "xmpp_tasks.h"
|
|---|
| 27 |
|
|---|
| 28 | namespace XMPP {
|
|---|
| 29 |
|
|---|
| 30 | class XData
|
|---|
| 31 | {
|
|---|
| 32 | public:
|
|---|
| 33 | XData();
|
|---|
| 34 | XData(const XData &);
|
|---|
| 35 | ~XData();
|
|---|
| 36 |
|
|---|
| 37 | QString title() const;
|
|---|
| 38 | void setTitle(const QString &);
|
|---|
| 39 |
|
|---|
| 40 | QString instructions() const;
|
|---|
| 41 | void setInstructions(const QString &);
|
|---|
| 42 |
|
|---|
| 43 | enum Type {
|
|---|
| 44 | Data_Form,
|
|---|
| 45 | Data_Result,
|
|---|
| 46 | Data_Submit,
|
|---|
| 47 | Data_Cancel
|
|---|
| 48 | };
|
|---|
| 49 |
|
|---|
| 50 | Type type() const;
|
|---|
| 51 | void setType(Type);
|
|---|
| 52 |
|
|---|
| 53 | struct ReportField {
|
|---|
| 54 | ReportField() { }
|
|---|
| 55 | ReportField( QString _label, QString _name ) { label = _label; name = _name; }
|
|---|
| 56 | QString label;
|
|---|
| 57 | QString name;
|
|---|
| 58 | };
|
|---|
| 59 | const QValueList<ReportField> &report() const;
|
|---|
| 60 |
|
|---|
| 61 | typedef QMap<QString, QString> ReportItem;
|
|---|
| 62 | const QValueList<ReportItem> &reportItems() const;
|
|---|
| 63 |
|
|---|
| 64 | void fromXml(const QDomElement &);
|
|---|
| 65 | QDomElement toXml(QDomDocument *, bool submitForm = true) const;
|
|---|
| 66 |
|
|---|
| 67 | public:
|
|---|
| 68 | class Field {
|
|---|
| 69 | public:
|
|---|
| 70 | Field();
|
|---|
| 71 | ~Field();
|
|---|
| 72 |
|
|---|
| 73 | QString desc() const;
|
|---|
| 74 | void setDesc(const QString &);
|
|---|
| 75 |
|
|---|
| 76 | struct Option {
|
|---|
| 77 | QString label;
|
|---|
| 78 | QString value;
|
|---|
| 79 | };
|
|---|
| 80 |
|
|---|
| 81 | typedef QValueList<Option> OptionList;
|
|---|
| 82 | OptionList options() const;
|
|---|
| 83 | void setOptions(OptionList);
|
|---|
| 84 |
|
|---|
| 85 | bool required() const;
|
|---|
| 86 | void setRequired(bool);
|
|---|
| 87 |
|
|---|
| 88 | QString label() const;
|
|---|
| 89 | void setLabel(const QString &);
|
|---|
| 90 |
|
|---|
| 91 | QString var() const;
|
|---|
| 92 | void setVar(const QString &);
|
|---|
| 93 |
|
|---|
| 94 | // generic value variable, because every possible Type
|
|---|
| 95 | // can be converted to QStringList. Field_Single will
|
|---|
| 96 | // use just one string in QStringList. Field_Boolean will
|
|---|
| 97 | // use just one string, and that string will equal 0 or 1.
|
|---|
| 98 | // and so on...
|
|---|
| 99 | QStringList value() const;
|
|---|
| 100 | void setValue(const QStringList &);
|
|---|
| 101 |
|
|---|
| 102 | enum Type {
|
|---|
| 103 | Field_Boolean,
|
|---|
| 104 | Field_Fixed,
|
|---|
| 105 | Field_Hidden,
|
|---|
| 106 | Field_JidMulti,
|
|---|
| 107 | Field_JidSingle,
|
|---|
| 108 | Field_ListMulti,
|
|---|
| 109 | Field_ListSingle,
|
|---|
| 110 | Field_TextMulti,
|
|---|
| 111 | Field_TextPrivate,
|
|---|
| 112 | Field_TextSingle
|
|---|
| 113 | };
|
|---|
| 114 |
|
|---|
| 115 | Type type() const;
|
|---|
| 116 | void setType(Type);
|
|---|
| 117 |
|
|---|
| 118 | bool isValid() const;
|
|---|
| 119 |
|
|---|
| 120 | void fromXml(const QDomElement &);
|
|---|
| 121 | QDomElement toXml(QDomDocument *, bool submitForm = true) const;
|
|---|
| 122 |
|
|---|
| 123 | private:
|
|---|
| 124 | QString _desc, _label, _var;
|
|---|
| 125 | QValueList<Option> _options;
|
|---|
| 126 | bool _required;
|
|---|
| 127 | Type _type;
|
|---|
| 128 | QStringList _value;
|
|---|
| 129 | };
|
|---|
| 130 |
|
|---|
| 131 | typedef QValueList<Field> FieldList;
|
|---|
| 132 |
|
|---|
| 133 | FieldList fields() const;
|
|---|
| 134 | void setFields(const FieldList &);
|
|---|
| 135 | XData &operator= (const XData &);
|
|---|
| 136 | XData copy() const;
|
|---|
| 137 | void detach();
|
|---|
| 138 |
|
|---|
| 139 | private:
|
|---|
| 140 | class Private;
|
|---|
| 141 | Private *d;
|
|---|
| 142 | };
|
|---|
| 143 |
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| 146 | #endif
|
|---|