Bonjour nick name is in Latin1 encoding
[kdenetwork.git] / kopete / protocols / jabber / jabbercapabilitiesmanager.h
blob6eaff9ea25b6c7873af76b42ea7ece00899cff9f
1 /*
2 jabbercapabilitiesmanager.h - Manage entity capabilities(JEP-0115) pool.
4 Copyright (c) 2006 by Michaël Larouche <larouche@kde.org>
5 Copyright 2006 by Tommi Rantala <tommi.rantala@cs.helsinki.fi>
7 Kopete (c) 2001-2006 by the Kopete developers <kopete-devel@kde.org>
9 Imported from caps.cpp from Psi:
10 Copyright (C) 2005 Remko Troncon
12 *************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 *************************************************************************
21 #ifndef JABBERCAPABILITIESMANAGER_H
22 #define JABBERCAPABILITIESMANAGER_H
24 #include <QPair>
25 #include <QList>
26 #include <QDate>
28 #include <QStringList>
29 #include <QDomElement>
31 #include <im.h>
32 #include <xmpp.h>
34 using namespace XMPP;
36 class JabberAccount;
38 /**
39 * @brief Manage Jabber entity capabilities (JEP-0115)
40 * @author Michaël Larouche <larouche@kde.org>
41 * @author Remko Troncon
43 class JabberCapabilitiesManager : public QObject
45 Q_OBJECT
46 public:
47 /**
48 * Construct
50 JabberCapabilitiesManager();
51 ~JabberCapabilitiesManager();
53 /**
54 * Load cached information from local file.
56 void loadCachedInformation();
58 /**
59 * Check if the jid support Entity capabitilies.
60 * @param jid JID to check.
61 * @return true if the jid support entity capabitilies.
63 bool capabilitiesEnabled(const Jid& jid) const;
65 /**
66 * Remove account from manager.
68 void removeAccount(JabberAccount *account);
70 /**
71 * Return the features supported for the JID.
73 XMPP::Features features(const Jid& jid) const;
74 /**
75 * Return the client name for the current JID.
77 QString clientName(const Jid& jid) const;
78 /**
79 * Return the client version for the current JID.
81 QString clientVersion(const Jid& jid) const;
83 signals:
84 void capabilitiesChanged(const XMPP::Jid &jid);
86 public slots:
87 /**
88 * Update if necessary the capabities for the JID passed in args.
89 * Caps are received in Presence messages so that's why we are
90 * passing a XMPP::Status object.
92 * @param jid JID that capabilities was updated.
93 * @param status The XMPP::Status that contain the caps.
95 void updateCapabilities(JabberAccount *account, const XMPP::Jid &jid, const XMPP::Status &status);
97 private slots:
98 /**
99 * @brief Called when a reply to disco#info request was received.
100 * If the result was successful, the resulting features are recorded in the
101 * features database for the requested node, and all the affected jids are
102 * put in the queue for update notification.
103 * If the result was unsuccessful, another jid with the same capabilities is
104 * selected and sent a disco#info query.
106 void discoRequestFinished();
108 private:
110 * @brief Sends a disco#info request to a given node of a jid through an account.
111 * When the request is finished, the discoRequestFinished() slot is called.
113 * @param account The account through which to send the disco request.
114 * @param jid The target entity's JID
115 * @param node The target disco#info node
117 void requestDiscoInfo(JabberAccount *account, const Jid& jid, const QString& node);
120 * Save capabilities information to disk.
122 void saveInformation();
124 class Capabilities;
125 typedef QList<Capabilities> CapabilitiesList;
127 * @brief A class representing an entity capability specification.
128 * An entity capability is a combination of a node, a version, and a set of
129 * extensions.
131 class Capabilities
133 public:
135 * Default constructor.
137 Capabilities();
139 * Define capabilities.
140 * @param node the node
141 * @param version the version
142 * @param extensions the list of extensions (separated by spaces)
144 Capabilities(const QString &node, const QString &version, const QString &extensions);
146 * Returns the node of the capabilities specification.
148 const QString& node() const;
150 * @brief Returns the version of the capabilities specification.
152 const QString& version() const;
154 * @brief Returns the extensions of the capabilities specification.
156 const QString& extensions() const;
158 * \brief Flattens the caps specification into the set of 'simple' specifications.
159 * A 'simple' specification is a specification with exactly one extension,
160 * or with the version number as the extension.
162 * Example: A caps specification with node=http://psi-im.org, version=0.10,
163 * and ext='achat vchat' would be expanded into the following list of specs:
164 * node=http://psi-im.org, ver=0.10, ext=0.10
165 * node=http://psi-im.org, ver=0.10, ext=achat
166 * node=http://psi-im.org, ver=0.10, ext=vchat
168 CapabilitiesList flatten() const;
170 bool operator==(const Capabilities&) const;
171 bool operator!=(const Capabilities&) const;
172 bool operator<(const Capabilities&) const;
174 private:
175 QString m_node, m_version, m_extensions;
178 class CapabilitiesInformation
180 public:
181 CapabilitiesInformation();
182 const QStringList& features() const;
183 const DiscoItem::Identities& identities() const;
184 QStringList jids() const;
185 bool discovered() const;
186 int pendingRequests() const;
188 void reset();
189 void removeAccount(JabberAccount* acc);
190 void removeJid(const Jid&);
191 void addJid(const Jid&, JabberAccount*);
192 QPair<Jid,JabberAccount*> nextJid(const Jid&, const Task*);
194 void setDiscovered(bool);
195 void setPendingRequests(int);
196 void setIdentities(const DiscoItem::Identities&);
197 void setFeatures(const QStringList&);
199 QDomElement toXml(QDomDocument *) const;
200 void fromXml(const QDomElement&);
202 protected:
203 void updateLastSeen();
205 private:
206 bool m_discovered;
207 int m_pendingRequests;
208 QStringList m_features;
209 DiscoItem::Identities m_identities;
211 typedef QList<QPair<QString, JabberAccount*> > JidList;
212 JidList m_jids;
214 QDate m_lastSeen;
217 class Private;
218 Private * const d;
221 #endif