QXmpp  Version:0.6.2
 All Classes Functions Variables Enumerations Enumerator Properties Groups
QXmppStanza.h
1 /*
2  * Copyright (C) 2008-2012 The QXmpp developers
3  *
4  * Author:
5  * Manjeet Dahiya
6  *
7  * Source:
8  * http://code.google.com/p/qxmpp
9  *
10  * This file is a part of QXmpp library.
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  */
23 
24 
25 #ifndef QXMPPSTANZA_H
26 #define QXMPPSTANZA_H
27 
28 #include <QByteArray>
29 #include <QString>
30 #include <QSharedData>
31 
32 // forward declarations of QXmlStream* classes will not work on Mac, we need to
33 // include the whole header.
34 // See http://lists.trolltech.com/qt-interest/2008-07/thread00798-0.html
35 // for an explanation.
36 #include <QXmlStreamWriter>
37 
38 #include "QXmppElement.h"
39 
40 class QXmppStanzaPrivate;
41 
43 
47 
48 class QXMPP_EXPORT QXmppStanza
49 {
50 public:
51  class QXMPP_EXPORT Error
52  {
53  public:
54  enum Type
55  {
56  Cancel,
57  Continue,
58  Modify,
59  Auth,
60  Wait
61  };
62 
63  enum Condition
64  {
65  BadRequest,
66  Conflict,
67  FeatureNotImplemented,
68  Forbidden,
69  Gone,
70  InternalServerError,
71  ItemNotFound,
72  JidMalformed,
73  NotAcceptable,
74  NotAllowed,
75  NotAuthorized,
76  PaymentRequired,
77  RecipientUnavailable,
78  Redirect,
79  RegistrationRequired,
80  RemoteServerNotFound,
81  RemoteServerTimeout,
82  ResourceConstraint,
83  ServiceUnavailable,
84  SubscriptionRequired,
85  UndefinedCondition,
86  UnexpectedRequest
87  };
88 
89  Error();
90  Error(Type type, Condition cond, const QString& text="");
91  Error(const QString& type, const QString& cond, const QString& text="");
92 
93  int code() const;
94  void setCode(int code);
95 
96  QString text() const;
97  void setText(const QString& text);
98 
99  Condition condition() const;
100  void setCondition(Condition cond);
101 
102  void setType(Type type);
103  Type type() const;
104 
106  void parse(const QDomElement &element);
107  void toXml(QXmlStreamWriter *writer) const;
109 
110  private:
111  QString getConditionStr() const;
112  void setConditionFromStr(const QString& cond);
113 
114  QString getTypeStr() const;
115  void setTypeFromStr(const QString& type);
116 
117  int m_code;
118  Type m_type;
119  Condition m_condition;
120  QString m_text;
121  };
122 
123  QXmppStanza(const QString& from = QString(), const QString& to = QString());
124  QXmppStanza(const QXmppStanza &other);
125  virtual ~QXmppStanza();
126 
127  QXmppStanza& operator=(const QXmppStanza &other);
128 
129  QString to() const;
130  void setTo(const QString&);
131 
132  QString from() const;
133  void setFrom(const QString&);
134 
135  QString id() const;
136  void setId(const QString&);
137 
138  QString lang() const;
139  void setLang(const QString&);
140 
141  QXmppStanza::Error error() const;
142  void setError(const QXmppStanza::Error& error);
143 
144  QXmppElementList extensions() const;
145  void setExtensions(const QXmppElementList &elements);
146 
148  virtual void parse(const QDomElement &element);
149  virtual void toXml(QXmlStreamWriter *writer) const = 0;
150 
151 protected:
152  void generateAndSetNextId();
154 
155 private:
156  QSharedDataPointer<QXmppStanzaPrivate> d;
157  static uint s_uniqeIdNo;
158 };
159 
160 #endif // QXMPPSTANZA_H