QXmppStanza.h

    00001 /*
    00002  * Copyright (C) 2008-2011 The QXmpp developers
    00003  *
    00004  * Author:
    00005  *  Manjeet Dahiya
    00006  *
    00007  * Source:
    00008  *  http://code.google.com/p/qxmpp
    00009  *
    00010  * This file is a part of QXmpp library.
    00011  *
    00012  * This library is free software; you can redistribute it and/or
    00013  * modify it under the terms of the GNU Lesser General Public
    00014  * License as published by the Free Software Foundation; either
    00015  * version 2.1 of the License, or (at your option) any later version.
    00016  *
    00017  * This library is distributed in the hope that it will be useful,
    00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00020  * Lesser General Public License for more details.
    00021  *
    00022  */
    00023
    00024
    00025 #ifndef QXMPPSTANZA_H
    00026 #define QXMPPSTANZA_H
    00027
    00028 #include "QXmppElement.h"
    00029 #include "QXmppPacket.h"
    00030 #include <QString>
    00031
    00032 // forward declarations of QXmlStream* classes will not work on Mac, we need to
    00033 // include the whole header.
    00034 // See http://lists.trolltech.com/qt-interest/2008-07/thread00798-0.html
    00035 // for an explanation.
    00036 #include <QXmlStreamWriter>
    00037
    00039
    00043
    00044 class QXmppStanza : public QXmppPacket
    00045 {
    00046 public:
    00047     class Error
    00048     {
    00049     public:
    00050         enum Type
    00051         {
    00052             Cancel,
    00053             Continue,
    00054             Modify,
    00055             Auth,
    00056             Wait
    00057         };
    00058
    00059         enum Condition
    00060         {
    00061             BadRequest,
    00062             Conflict,
    00063             FeatureNotImplemented,
    00064             Forbidden,
    00065             Gone,
    00066             InternalServerError,
    00067             ItemNotFound,
    00068             JidMalformed,
    00069             NotAcceptable,
    00070             NotAllowed,
    00071             NotAuthorized,
    00072             PaymentRequired,
    00073             RecipientUnavailable,
    00074             Redirect,
    00075             RegistrationRequired,
    00076             RemoteServerNotFound,
    00077             RemoteServerTimeout,
    00078             ResourceConstraint,
    00079             ServiceUnavailable,
    00080             SubscriptionRequired,
    00081             UndefinedCondition,
    00082             UnexpectedRequest
    00083         };
    00084
    00085         Error();
    00086         Error(Type type, Condition cond, const QString& text="");
    00087         Error(const QString& type, const QString& cond, const QString& text="");
    00088
    00089         int code() const;
    00090         void setCode(int code);
    00091
    00092         QString text() const;
    00093         void setText(const QString& text);
    00094
    00095         Condition condition() const;
    00096         void setCondition(Condition cond);
    00097
    00098         void setType(Type type);
    00099         Type type() const;
    00100
    00101         // FIXME : remove this once is gone
    00102         bool isValid();
    00103
    00105         void parse(const QDomElement &element);
    00106         void toXml(QXmlStreamWriter *writer) const;
    00108
    00109     private:
    00110         QString getConditionStr() const;
    00111         void setConditionFromStr(const QString& cond);
    00112
    00113         QString getTypeStr() const;
    00114         void setTypeFromStr(const QString& type);
    00115
    00116         int m_code;
    00117         Type m_type;
    00118         Condition m_condition;
    00119         QString m_text;
    00120     };
    00121
    00122     QXmppStanza(const QString& from = QString(), const QString& to = QString());
    00123     ~QXmppStanza();
    00124
    00125     QString to() const;
    00126     void setTo(const QString&);
    00127
    00128     QString from() const;
    00129     void setFrom(const QString&);
    00130
    00131     QString id() const;
    00132     void setId(const QString&);
    00133
    00134     QString lang() const;
    00135     void setLang(const QString&);
    00136
    00137     QXmppStanza::Error error() const;
    00138     void setError(const QXmppStanza::Error& error);
    00139
    00140     QXmppElementList extensions() const;
    00141     void setExtensions(const QXmppElementList &elements);
    00142
    00144     // FIXME : why is this needed?
    00145     bool isErrorStanza();
    00146
    00147 protected:
    00148     void generateAndSetNextId();
    00149     void parse(const QDomElement &element);
    00151
    00152 private:
    00153     static uint s_uniqeIdNo;
    00154     QString m_to;
    00155     QString m_from;
    00156     QString m_id;
    00157     QString m_lang;
    00158     QXmppStanza::Error m_error;
    00159     QXmppElementList m_extensions;
    00160 };
    00161
    00162 #endif // QXMPPSTANZA_H

All Classes Functions Enumerations Enumerator Properties