File indexing completed on 2024-06-23 04:03:44

0001 /*
0002  * xmpp_xdata.h - a class for jabber:x:data forms
0003  * Copyright (C) 2003-2004  Michail Pishchagin
0004  *
0005  * This program is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU General Public License
0007  * as published by the Free Software Foundation; either version 2
0008  * of the License, or (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this library; if not, write to the Free Software
0017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0018  *
0019  */
0020 
0021 #ifndef XMPPXDATA_H
0022 #define XMPPXDATA_H
0023 
0024 #include <QString>
0025 #include <QMap>
0026 #include <QList>
0027 #include <QSharedDataPointer>
0028 #include <QStringList>
0029 
0030 class QDomElement;
0031 class QDomDocument;
0032 
0033 namespace XMPP {
0034 
0035     class XData
0036     {
0037     public:
0038         XData();
0039 
0040         QString title() const;
0041         void setTitle(const QString &);
0042 
0043         QString instructions() const;
0044         void setInstructions(const QString &);
0045 
0046         enum Type {
0047             Data_Form,
0048             Data_Result,
0049             Data_Submit,
0050             Data_Cancel
0051         };
0052 
0053         Type type() const;
0054         void setType(Type);
0055 
0056         struct ReportField {
0057             ReportField() { }
0058             ReportField( QString _label, QString _name ) { label = _label; name = _name; }
0059             QString label;
0060             QString name;
0061         };
0062         const QList<ReportField> &report() const;
0063 
0064         typedef QMap<QString, QString> ReportItem;
0065         const QList<ReportItem> &reportItems() const;
0066 
0067         void fromXml(const QDomElement &);
0068         QDomElement toXml(QDomDocument *, bool submitForm = true) const;
0069         bool isValid() const;
0070 
0071     public:
0072         class Field {
0073         public:
0074             Field();
0075             ~Field();
0076 
0077             QString desc() const;
0078             void setDesc(const QString &);
0079 
0080             struct Option {
0081                 QString label;
0082                 QString value;
0083             };
0084 
0085             typedef QList<Option> OptionList;
0086             OptionList options() const;
0087             void setOptions(OptionList);
0088 
0089             bool required() const;
0090             void setRequired(bool);
0091 
0092             QString label() const;
0093             void setLabel(const QString &);
0094 
0095             QString var() const;
0096             void setVar(const QString &);
0097 
0098             // generic value variable, because every possible Type
0099             // can be converted to QStringList. Field_Single will
0100             // use just one string in QStringList. Field_Boolean will
0101             // use just one string, and that string will equal 0 or 1.
0102             // and so on...
0103             QStringList value() const;
0104             void setValue(const QStringList &);
0105 
0106             enum Type {
0107                 Field_Boolean,
0108                 Field_Fixed,
0109                 Field_Hidden,
0110                 Field_JidMulti,
0111                 Field_JidSingle,
0112                 Field_ListMulti,
0113                 Field_ListSingle,
0114                 Field_TextMulti,
0115                 Field_TextPrivate,
0116                 Field_TextSingle
0117             };
0118 
0119             Type type() const;
0120             void setType(Type);
0121 
0122             bool isValid() const;
0123 
0124             void fromXml(const QDomElement &);
0125             QDomElement toXml(QDomDocument *, bool submitForm = true) const;
0126 
0127         private:
0128             QString _desc, _label, _var;
0129             QList<Option> _options;
0130             bool _required;
0131             Type _type;
0132             QStringList _value;
0133         };
0134 
0135         typedef QList<Field> FieldList;
0136 
0137         FieldList fields() const;
0138         void setFields(const FieldList &);
0139 
0140     private:
0141         class Private : public QSharedData {
0142         public:
0143             QString title, instructions;
0144             XData::Type type;
0145             FieldList fields;
0146             QList<ReportField> report;
0147             QList<ReportItem>  reportItems;
0148         };
0149         QSharedDataPointer<Private> d;
0150     };
0151 
0152 }
0153 
0154 #endif