50
50
class SxeManager : public QObject
54
/*! \brief A simple struct used to keep track of the detected SXE sessions.*/
55
struct DetectedSession {
61
/*! \brief A simple class to keep track of the state of a session negotiation process.*/
64
enum Role {Participant, Joiner};
65
enum State {NotStarted, InvitationSent, ConnectionRequested, InvitationAccepted, DocumentBegan, /*DocumentEnded,*/ HistoryOffered, HistoryAccepted, Finished, Aborted};
67
/*! \brief Describes our role in the negotiation.*/
69
/*! \brief Describes the current state of the negotiation.*/
71
/*! \brief The identifier for the session.*/
73
/*! \brief The JID that will be used for delivering the sxe messages once session is established.*/
75
/*! \brief The JID where negotiation messages are sent.*/
77
/*! \brief The user's own JID used in the session.*/
79
/*! \brief Set if the target is a groupchat.*/
81
/*! \brief The document to be sent as the initial document during the negotiation.
82
* This is only relevant when Role == Participant.
84
QDomDocument initialDoc;
85
/*! \brief A list of features proposed for the session.*/
86
QList<QString> features;
87
/*! \brief The session created for this negotiation.*/
88
QPointer<SxeSession> session;
54
/*! \brief A simple struct used to keep track of the detected SXE sessions.*/
55
struct DetectedSession {
61
/*! \brief A simple class to keep track of the state of a session negotiation process.*/
64
enum Role {Participant, Joiner};
65
enum State {NotStarted, InvitationSent, ConnectionRequested, InvitationAccepted, DocumentBegan, /*DocumentEnded,*/ HistoryOffered, HistoryAccepted, Finished, Aborted};
67
/*! \brief Describes our role in the negotiation.*/
69
/*! \brief Describes the current state of the negotiation.*/
71
/*! \brief The identifier for the session.*/
73
/*! \brief The JID that will be used for delivering the sxe messages once session is established.*/
75
/*! \brief The JID where negotiation messages are sent.*/
77
/*! \brief The user's own JID used in the session.*/
79
/*! \brief Set if the target is a groupchat.*/
81
/*! \brief The document to be sent as the initial document during the negotiation.
82
* This is only relevant when Role == Participant.
84
QDomDocument initialDoc;
85
/*! \brief A list of features proposed for the session.*/
86
QList<QString> features;
87
/*! \brief The session created for this negotiation.*/
88
QPointer<SxeSession> session;
92
/*! \brief Constructor.
93
* Creates a new manager for the specified Client and PsiAccount
95
SxeManager(XMPP::Client* client, PsiAccount* pa);
96
/*! \brief Return a list of pointers to sessions to the specified contact.
97
* If no such session exits, returns 0.
99
QList< QPointer<SxeSession> > findSession(const Jid &target);
100
/*! \brief Return a pointer to the specified session.
101
* If such session doesn't exits, returns 0.
103
QPointer<SxeSession> findSession(const QString &session);
104
/*! \brief Add a callback for invitations.*/
105
void addInvitationCallback(bool (*callback)(const Jid &peer, const QList<QString> &features));
106
/*! \brief Starts a new session negotiation to the specified contact with given list of features.*/
107
void startNewSession(const Jid &target, const Jid &ownJid, bool groupChat, const QDomDocument &initialDoc, QList<QString> features = QList<QString>());
108
/*! \brief Join an existing session.*/
109
void joinSession(const Jid &target, const Jid &ownJid, bool groupChat, const QString &session);
110
/*! \brief Checks that \a jid supports SXE and \a features. */
111
bool checkSupport(const Jid &jid, const QList<QString> &features);
92
/*! \brief Constructor.
93
* Creates a new manager for the specified Client and PsiAccount
95
SxeManager(XMPP::Client* client, PsiAccount* pa);
96
/*! \brief Return a list of pointers to sessions to the specified contact.
97
* If no such session exits, returns 0.
99
QList< QPointer<SxeSession> > findSession(const Jid &target);
100
/*! \brief Return a pointer to the specified session.
101
* If such session doesn't exits, returns 0.
103
QPointer<SxeSession> findSession(const QString &session);
104
/*! \brief Add a callback for invitations.*/
105
void addInvitationCallback(bool (*callback)(const Jid &peer, const QList<QString> &features));
106
/*! \brief Starts a new session negotiation to the specified contact with given list of features.*/
107
void startNewSession(const Jid &target, const Jid &ownJid, bool groupChat, const QDomDocument &initialDoc, QList<QString> features = QList<QString>());
108
/*! \brief Join an existing session.*/
109
void joinSession(const Jid &target, const Jid &ownJid, bool groupChat, const QString &session);
110
/*! \brief Checks that \a jid supports SXE and \a features. */
111
bool checkSupport(const Jid &jid, const QList<QString> &features);
113
inline Client *client() { return client_; }
114
/*! \brief Emitted when \a session has been established.*/
115
void sessionNegotiated(SxeSession* session);
116
/*! \brief Emitted when \a an invitation to \a jid was declined and joining an alternative session \a session was suggested.*/
117
void alternativeSession(const Jid &jid, const QString &session);
116
/*! \brief Emitted when \a session has been established.*/
117
void sessionNegotiated(SxeSession* session);
118
/*! \brief Emitted when \a an invitation to \a jid was declined and joining an alternative session \a session was suggested.*/
119
void alternativeSession(const Jid &jid, const QString &session);
120
/*! \brief Process a message that contains a negotiation element.
121
* Returns a pointer to the new session if negotiation finished.
123
QPointer<SxeSession> processNegotiationMessage(const Message &message);
124
/*! \brief Process a negotiation element as a Participant.
125
Appends the appropriate responses to \a response.
126
Returns false iff the negotiation object was deleted. */
127
bool processNegotiationAsParticipant(const QDomNode &negotiationElement, SxeNegotiation* negotiation, QDomNode response);
128
/*! \brief Process a negotiation element as a Joiner.
129
Appends the appropriate responses to \a response.
130
Returns false iff the negotiation object was deleted. */
131
bool processNegotiationAsJoiner(const QDomNode &negotiationElement, SxeNegotiation* negotiation, QDomNode response, const Message &message);
132
/*! \brief Returns a pointer to a new session instance.*/
133
QPointer<SxeSession> createSxeSession(const Jid &target, QString session, const Jid &ownJid, bool groupChat, const QList<QString> &features);
134
/*! \brief Aborts the negotiation of \a session started with \a peer.*/
135
void abortNegotiation(QString session, const Jid &peer, bool groupChat);
136
/*! \brief Aborts the negotiation with the peer and deletes the session.*/
137
void abortNegotiation(SxeNegotiation* negotiation);
138
/*! \brief Records the session that the message refers to as a DetectedSession if no entry for the session exists yet.*/
139
void recordDetectedSession(const Message &message);
140
/*! \brief Returns a pointer to a new negotiation instance based on \a message.*/
141
SxeNegotiation* createNegotiation(const Message &message);
142
/*! \brief Returns a pointer to a new negotiation instance.*/
143
SxeNegotiation* createNegotiation(SxeNegotiation::Role role, SxeNegotiation::State state, const QString &sessionId, const Jid &target, const Jid &ownJid, bool groupChat);
144
/*! \brief Returns a pointer to an existing negotiation object of \a session with \a jid.*/
145
SxeNegotiation* findNegotiation(const Jid &jid, const QString &session);
146
/*! \brief Remove the negotiation object of \a session with \a jid.*/
147
void removeNegotiation(SxeNegotiation* negotiation);
150
/*! \brief A pointer to the Client to listen to.*/
151
XMPP::Client* client_;
152
/*! \brief A pointer to the PsiAccount to listen to.*/
154
/*! \brief A list of of established sessions.*/
155
QList< QPointer<SxeSession> > sessions_;
156
/*! \brief A list of negotiations in process.*/
157
QMultiHash<QString, SxeNegotiation* > negotiations_;
158
/*! \brief A timer used to remove unfinished negotiations after a timeout.*/
159
QTimer negotiationTimer_;
160
/*! \brief A list of of detected sessions.*/
161
QList<DetectedSession> DetectedSessions_;
162
/*! \brief A list of Jids corresponding to self.*/
163
QList<QString> ownJids_;
164
/*! \brief A list of callbacks used to determine whether an invitation should be accepted.*/
165
QList<bool (*)(const Jid &peer, const QList<QString> &features)> invitationCallbacks_;
166
/*! \brief A counter used for including a unique id in each sent sxe element.*/
168
/*! \brief A list of messages waiting to be sent out.*/
169
QList<Message> queuedMessages_;
122
/*! \brief Process a message that contains a negotiation element.
123
* Returns a pointer to the new session if negotiation finished.
125
QPointer<SxeSession> processNegotiationMessage(const Message &message);
126
/*! \brief Process a negotiation element as a Participant.
127
Appends the appropriate responses to \a response.
128
Returns false iff the negotiation object was deleted. */
129
bool processNegotiationAsParticipant(const QDomNode &negotiationElement, SxeNegotiation* negotiation, QDomNode response);
130
/*! \brief Process a negotiation element as a Joiner.
131
Appends the appropriate responses to \a response.
132
Returns false iff the negotiation object was deleted. */
133
bool processNegotiationAsJoiner(const QDomNode &negotiationElement, SxeNegotiation* negotiation, QDomNode response, const Message &message);
134
/*! \brief Returns a pointer to a new session instance.*/
135
QPointer<SxeSession> createSxeSession(const Jid &target, QString session, const Jid &ownJid, bool groupChat, const QList<QString> &features);
136
/*! \brief Aborts the negotiation of \a session started with \a peer.*/
137
void abortNegotiation(QString session, const Jid &peer, bool groupChat);
138
/*! \brief Aborts the negotiation with the peer and deletes the session.*/
139
void abortNegotiation(SxeNegotiation* negotiation);
140
/*! \brief Records the session that the message refers to as a DetectedSession if no entry for the session exists yet.*/
141
void recordDetectedSession(const Message &message);
142
/*! \brief Returns a pointer to a new negotiation instance based on \a message.*/
143
SxeNegotiation* createNegotiation(const Message &message);
144
/*! \brief Returns a pointer to a new negotiation instance.*/
145
SxeNegotiation* createNegotiation(SxeNegotiation::Role role, SxeNegotiation::State state, const QString &sessionId, const Jid &target, const Jid &ownJid, bool groupChat);
146
/*! \brief Returns a pointer to an existing negotiation object of \a session with \a jid.*/
147
SxeNegotiation* findNegotiation(const Jid &jid, const QString &session);
148
/*! \brief Remove the negotiation object of \a session with \a jid.*/
149
void removeNegotiation(SxeNegotiation* negotiation);
152
/*! \brief A pointer to the Client to listen to.*/
153
XMPP::Client* client_;
154
/*! \brief A pointer to the PsiAccount to listen to.*/
156
/*! \brief A list of of established sessions.*/
157
QList< QPointer<SxeSession> > sessions_;
158
/*! \brief A list of negotiations in process.*/
159
QMultiHash<QString, SxeNegotiation* > negotiations_;
160
/*! \brief A timer used to remove unfinished negotiations after a timeout.*/
161
QTimer negotiationTimer_;
162
/*! \brief A list of of detected sessions.*/
163
QList<DetectedSession> DetectedSessions_;
164
/*! \brief A list of Jids corresponding to self.*/
165
QList<QString> ownJids_;
166
/*! \brief A list of callbacks used to determine whether an invitation should be accepted.*/
167
QList<bool (*)(const Jid &peer, const QList<QString> &features)> invitationCallbacks_;
168
/*! \brief A counter used for including a unique id in each sent sxe element.*/
170
/*! \brief A list of messages waiting to be sent out.*/
171
QList<Message> queuedMessages_;
172
/*! \brief Receives incoming message and determines what to do with them.*/
173
void messageReceived(const Message &message);
174
/*! \brief Send given whiteboard element to receiver in a message.*/
175
void sendSxe(QDomElement sxe, const Jid & receiver, bool groupChat);
176
/*! \brief Removes and deletes the session.*/
177
void removeSession(SxeSession* session);
178
/*! \brief Removes the "detected session" record of the given session.*/
179
void removeDetectedSession(SxeSession* session);
180
/*! \brief Removes and deletes the possible sessions for the groupchat.*/
181
void groupChatLeft(const Jid &);
182
/*! \brief Keeps a record of groupchats.*/
183
void groupChatJoined(const Jid &, const Jid &ownJid);
184
/*! \brief Removes inactive and unfinished session negotiations.*/
185
void negotiationTimeout();
174
/*! \brief Receives incoming message and determines what to do with them.*/
175
void messageReceived(const Message &message);
176
/*! \brief Send given whiteboard element to receiver in a message.*/
177
void sendSxe(QDomElement sxe, const Jid & receiver, bool groupChat);
178
/*! \brief Removes and deletes the session.*/
179
void removeSession(SxeSession* session);
180
/*! \brief Removes the "detected session" record of the given session.*/
181
void removeDetectedSession(SxeSession* session);
182
/*! \brief Removes and deletes the possible sessions for the groupchat.*/
183
void groupChatLeft(const Jid &);
184
/*! \brief Keeps a record of groupchats.*/
185
void groupChatJoined(const Jid &, const Jid &ownJid);
186
/*! \brief Removes inactive and unfinished session negotiations.*/
187
void negotiationTimeout();