File indexing completed on 2024-04-14 04:01:43
0001 0002 /*************************************************************************** 0003 jabberaccount.h - core Jabber account class 0004 ------------------- 0005 begin : Sat Mar 8 2003 0006 copyright : (C) 2003 by Till Gerken <till@tantalo.net> 0007 Based on JabberProtocol by Daniel Stone <dstone@kde.org> 0008 and Till Gerken <till@tantalo.net>. 0009 copyright : (C) 2006 by Olivier Goffart <ogoffart at kde.org> 0010 0011 Copyright 2006 by Tommi Rantala <tommi.rantala@cs.helsinki.fi> 0012 0013 Kopete (C) 2001-2006 Kopete developers <kopete-devel@kde.org>. 0014 ***************************************************************************/ 0015 0016 /*************************************************************************** 0017 * * 0018 * This program is free software; you can redistribute it and/or modify * 0019 * it under the terms of the GNU General Public License as published by * 0020 * the Free Software Foundation; either either version 2 0021 of the License, or (at your option) any later version.of the License, or * 0022 * (at your option) any later version. * 0023 * * 0024 ***************************************************************************/ 0025 0026 #ifndef JABBERACCOUNT_H 0027 #define JABBERACCOUNT_H 0028 0029 // we need these for type reasons 0030 #include <im.h> 0031 #include "jabberclient.h" 0032 #include "jabberprotocol.h" 0033 0034 #include <QObject> 0035 #include <QMap> 0036 #include <QtCrypto> 0037 0038 class QString; 0039 class JabberResourcePool; 0040 class JabberContact; 0041 class JabberContactPool; 0042 class JabberProtocol; 0043 // class JabberTransport; 0044 class JabberBookmarks; 0045 0046 #ifdef SUPPORT_JINGLE 0047 //class JingleSessionManager; 0048 //class JingleSession; 0049 class VoiceCaller; 0050 #endif 0051 0052 0053 /* @author Daniel Stone, Till Gerken */ 0054 0055 class JabberAccount: public JabberProtocol 0056 { 0057 Q_OBJECT 0058 0059 public: 0060 JabberAccount (JabberProtocol* parent, const QString & accountID); 0061 ~JabberAccount (); 0062 0063 const QString& contactId(); 0064 0065 /* Return the resource of the client */ 0066 const QString resource () const; 0067 const QString server () const; 0068 const int port () const; 0069 0070 JabberResourcePool *resourcePool (); 0071 JabberContactPool *contactPool (); 0072 0073 /* to get the protocol from the account */ 0074 JabberProtocol *protocol () const 0075 { 0076 return m_protocol; 0077 } 0078 0079 JabberClient *client () const 0080 { 0081 return m_jabberClient; 0082 } 0083 0084 PrivacyManager *privacyManager () const 0085 { 0086 return m_privacyManager; 0087 } 0088 0089 // #ifdef SUPPORT_JINGLE 0090 // VoiceCaller *voiceCaller() const 0091 // { 0092 // return m_voiceCaller; 0093 // } 0094 // 0095 // // JingleSessionManager *sessionManager() const 0096 // // { 0097 // // return m_jingleSessionManager; 0098 // // } 0099 // #endif 0100 0101 // change the default S5B server port 0102 // void setS5BServerPort ( int port ); 0103 0104 /* Tells the user to connect first before they can do whatever it is 0105 * that they want to do. */ 0106 void errorConnectFirst (); 0107 0108 /* Tells the user that the connection was lost while we waited for 0109 * an answer of him. */ 0110 void errorConnectionLost (); 0111 0112 /** 0113 * Handle a TLS warning. Displays a dialog and returns if the 0114 * stream can be continued or not. 0115 * 0116 * @param client JabberClient instance 0117 * @param identityResult Peer identity checking result from QCA::TLS 0118 * @param validityResult Certificate validity checking result from QCA::TLS 0119 * @return True if stream can be resumed. 0120 */ 0121 static bool handleTLSWarning ( JabberClient *client, QCA::TLS::IdentityResult identityResult, QCA::Validity validityResult ); 0122 0123 /* 0124 * Handle stream errors. Displays a dialog and returns. 0125 */ 0126 static void handleStreamError (int streamError, int streamCondition, int connectorCode, const QString &server, int &errorClass, QString additionalErrMsg); 0127 0128 // const QMap<QString, JabberTransport *> &transports() 0129 // { return m_transports; } 0130 0131 0132 /** 0133 * called when the account is removed in the config ui 0134 */ 0135 // virtual bool removeAccount(); 0136 0137 public slots: 0138 /* Connects to the server. */ 0139 void connectWithPassword ( const QString &password ); 0140 0141 /* Disconnects from the server. */ 0142 void disconnect (); 0143 0144 /* Disconnect with a reason */ 0145 void disconnect ( int reason ); 0146 0147 /* Disconnect with a reason, and status */ 0148 void disconnect( int reason, XMPP::Status &status ); 0149 /* Reimplemented from Kopete::Account */ 0150 void setOnlineStatus( const JabberProtocol::OnlineStatus& status, const QString &reason = QString()); 0151 void setStatusMessage( const QString &statusMessage ); 0152 0153 // void addTransport( JabberTransport *tr , const QString &jid); 0154 // void removeTransport( const QString &jid ); 0155 0156 0157 protected: 0158 /** 0159 * Create a new contact in the specified metacontact 0160 * 0161 * You shouldn't ever call this method yourself, For adding contacts see @ref addContact() 0162 * 0163 * This method is called by @ref Kopete::Account::addContact() in this method, you should 0164 * simply create the new custom @ref Kopete::Contact in the given metacontact. You should 0165 * NOT add the contact to the server here as this method gets only called when synchronizing 0166 * the contact list on disk with the one in memory. As such, all created contacts from this 0167 * method should have the "dirty" flag set. 0168 * 0169 * This method should simply be used to intantiate the new contact, everything else 0170 * (updating the GUI, parenting to meta contact, etc.) is being taken care of. 0171 * 0172 * @param contactId The unique ID for this protocol 0173 * @param parentContact The metacontact to add this contact to 0174 */ 0175 // virtual bool createContact (const QString & contactID, Kopete::MetaContact * parentContact); 0176 0177 0178 0179 private: 0180 JabberProtocol *m_protocol; 0181 0182 // backend for this account 0183 JabberClient *m_jabberClient; 0184 0185 PrivacyManager *m_privacyManager; 0186 0187 JabberResourcePool *m_resourcePool; 0188 JabberContactPool *m_contactPool; 0189 0190 // #ifdef SUPPORT_JINGLE 0191 // VoiceCaller *m_voiceCaller; 0192 // //JingleSessionManager *m_jingleSessionManager; 0193 // #endif 0194 0195 // JabberBookmarks *m_bookmarks; 0196 0197 /* Set up our actions for the status menu. */ 0198 // void initActions (); 0199 0200 void cleanup (); 0201 0202 /* Initial presence to set after connecting. */ 0203 XMPP::Status m_initialPresence; 0204 0205 /** 0206 * Sets our own presence. Updates our resource in the 0207 * resource pool and sends a presence packet to the server. 0208 */ 0209 void setPresence ( const XMPP::Status &status ); 0210 0211 /** 0212 * Returns if a connection attempt is currently in progress. 0213 */ 0214 bool isConnecting (); 0215 bool isConnected(); 0216 0217 const QString& accountId (); 0218 // QMap<QString, JabberTransport*> m_transports; 0219 0220 /* used in removeAccount() */ 0221 bool m_removing; 0222 /* keep track if we told the user we were not able to bind the 0223 jabber transfer port, to avoid popup insanity */ 0224 bool m_notifiedUserCannotBindTransferPort; 0225 private slots: 0226 /* Connects to the server. */ 0227 void slotConnect (); 0228 0229 /* Disconnects from the server. */ 0230 void slotDisconnect (); 0231 0232 // handle a TLS warning 0233 void slotHandleTLSWarning ( QCA::TLS::IdentityResult identityResult, QCA::Validity validityResult ); 0234 0235 // handle client errors 0236 void slotClientError ( JabberClient::ErrorCode errorCode ); 0237 0238 // we are connected to the server 0239 void slotConnected (); 0240 0241 /* Called from Psi: tells us when we've been disconnected from the server. */ 0242 void slotCSDisconnected (); 0243 0244 /* Called from Psi: alerts us to a protocol error. */ 0245 void slotCSError (int); 0246 0247 /* Called from Psi: roster request finished */ 0248 void slotRosterRequestFinished ( bool success ); 0249 0250 /* Called from Psi: incoming file transfer */ 0251 void slotIncomingFileTransfer (); 0252 0253 /* Called from Psi: debug messages from the backend. */ 0254 void slotClientDebugMessage (const QString &msg); 0255 0256 /* XMPP console dialog */ 0257 void slotXMPPConsole (); 0258 0259 /* Slots for handling groupchats. */ 0260 void slotJoinNewChat (); 0261 void slotGroupChatJoined ( const XMPP::Jid &jid ); 0262 void slotGroupChatLeft ( const XMPP::Jid &jid ); 0263 void slotGroupChatPresence ( const XMPP::Jid &jid, const XMPP::Status &status ); 0264 void slotGroupChatError ( const XMPP::Jid &jid, int error, const QString &reason ); 0265 0266 /* Incoming subscription request. */ 0267 void slotSubscription ( const XMPP::Jid &jid, const QString &type ); 0268 0269 /* the dialog that asked to add the contact was closed (that dialog is shown in slotSubscription) */ 0270 void slotAddedInfoEventActionActivated ( uint actionId ); 0271 0272 /** 0273 * A new item appeared in our roster, synch it with the 0274 * contact list. 0275 * (or the contact has been updated 0276 */ 0277 void slotContactUpdated ( const XMPP::RosterItem & ); 0278 0279 /** 0280 * An item has been deleted from our roster, 0281 * delete it from our contact pool. 0282 */ 0283 void slotContactDeleted ( const XMPP::RosterItem & ); 0284 0285 0286 /* Someone on our contact list had (another) resource come online. */ 0287 void slotResourceAvailable ( const XMPP::Jid &, const XMPP::Resource & ); 0288 0289 /* Someone on our contact list had (another) resource go offline. */ 0290 void slotResourceUnavailable ( const XMPP::Jid &, const XMPP::Resource & ); 0291 0292 /* Displays a new message. */ 0293 void slotReceivedMessage ( const XMPP::Message & ); 0294 0295 /* Gets the user's vCard from the server for editing. */ 0296 void slotEditVCard (); 0297 0298 /* Get the services list from the server for management. */ 0299 void slotGetServices (); 0300 0301 /* we received a voice invitation */ 0302 // void slotIncomingVoiceCall(const Jid&); 0303 0304 /* the unregister task finished */ 0305 void slotUnregisterFinished(); 0306 0307 //void slotIncomingJingleSession(const QString &sessionType, JingleSession *session); 0308 }; 0309 0310 #endif