1 /*
2  * pubsubsubscription.cpp
3  * Copyright (C) 2006  Remko Troncon
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  */
20 
21 #include <QDomDocument>
22 #include <QDomElement>
23 #include <QString>
24 
25 #include "pubsubsubscription.h"
26 
27 
PubSubSubscription()28 PubSubSubscription::PubSubSubscription()
29 {
30 }
31 
PubSubSubscription(const QDomElement & e)32 PubSubSubscription::PubSubSubscription(const QDomElement& e)
33 {
34 	fromXml(e);
35 }
36 
jid() const37 const QString& PubSubSubscription::jid() const
38 {
39 	return jid_;
40 }
41 
node() const42 const QString& PubSubSubscription::node() const
43 {
44 	return node_;
45 }
46 
state() const47 PubSubSubscription::State PubSubSubscription::state() const
48 {
49 	return state_;
50 }
51 
isNull() const52 bool PubSubSubscription::isNull() const
53 {
54 	return jid_.isEmpty() && node_.isEmpty();
55 }
56 
fromXml(const QDomElement & e)57 void PubSubSubscription::fromXml(const QDomElement& e)
58 {
59 	if (e.tagName() != "subscription")
60 		return;
61 
62 	node_ = e.attribute("node");
63 	jid_ = e.attribute("jid");
64 
65 	QString sub = e.attribute("subscription");
66 	if (sub == "none")
67 		state_ = None;
68 	else if (sub == "pending")
69 		state_ = Pending;
70 	else if (sub == "unconfigured")
71 		state_ = Unconfigured;
72 	else if (sub == "subscribed")
73 		state_ = Subscribed;
74 }
75 
toXml(QDomDocument & doc) const76 QDomElement PubSubSubscription::toXml(QDomDocument& doc) const
77 {
78 	QDomElement s = doc.createElement("subscription");
79 	s.setAttribute("node",node_);
80 	if (state_ == None)
81 		s.setAttribute("subscription","none");
82 	else if (state_ == Pending)
83 		s.setAttribute("subscription","pending");
84 	else if (state_ == Unconfigured)
85 		s.setAttribute("subscription","unconfigured");
86 	else if (state_ == Subscribed)
87 		s.setAttribute("subscription","subscribed");
88 
89 	return s;
90 }
91 
operator ==(const PubSubSubscription & s) const92 bool PubSubSubscription::operator==(const PubSubSubscription& s) const
93 {
94 	return jid() == s.jid() && node() == s.node() && state() == s.state();
95 }
96 
operator !=(const PubSubSubscription & s) const97 bool PubSubSubscription::operator!=(const PubSubSubscription& s) const
98 {
99 	return !((*this) == s);
100 }
101