File indexing completed on 2024-04-28 07:54:07

0001  /*
0002   * jabbercontact.h  -  Base class for the Kopete Jabber protocol contact
0003   *
0004   * Copyright (c) 2002-2004 by Till Gerken <till@tantalo.net>
0005   * Copyright (c) 2002 by Daniel Stone <dstone@kde.org>
0006   *
0007   * Kopete    (c) by the Kopete developers  <kopete-devel@kde.org>
0008   *
0009   * *************************************************************************
0010   * *                                                                       *
0011   * * This program is free software; you can redistribute it and/or modify  *
0012   * * it under the terms of the GNU General Public License as published by  *
0013   * * the Free Software Foundation; either either version 2
0014    of the License, or (at your option) any later version.of the License, or     *
0015   * * (at your option) any later version.                                   *
0016   * *                                                                       *
0017   * *************************************************************************
0018   */
0019 
0020 #ifndef JABBERBASECONTACT_H
0021 #define JABBERBASECONTACT_H
0022 
0023 #include <QObject>
0024 
0025 // #include "kopetecontact.h"
0026 #include "xmpp.h"
0027 #include "im.h"
0028 
0029 class JabberProtocol;
0030 class JabberAccount;
0031 class JabberTransport;
0032 // namespace Kopete { class MetaContact; }
0033 namespace XMPP { class VCard; }
0034 
0035 class JabberBaseContact : public QObject
0036 {
0037 
0038 Q_OBJECT
0039 friend class JabberAccount; /* Friends can touch each other's private parts. */
0040 
0041 public:
0042 
0043     /**
0044      * @param legacyId is the contactId of the contact if != Jid
0045      */
0046     JabberBaseContact (const XMPP::RosterItem &rosterItem,
0047                        JabberAccount *account/*, Kopete::MetaContact * mc*/,
0048                        const QString &legacyId=QString());
0049 
0050     /********************************************************************
0051      *
0052      * Kopete::Contact reimplementation start
0053      *
0054      ********************************************************************/
0055 
0056     /**
0057      * Return the protocol instance associated with this contact
0058      */
0059     JabberProtocol *protocol ();
0060 
0061     /**
0062      * Return the account instance associated with this contact
0063      */
0064     JabberAccount *account () const { return m_account; };
0065     
0066     /**
0067      * return the transport if any, or null
0068      */
0069     JabberTransport *transport();
0070             
0071     /**
0072      * Return if the contact is reachable (this is true if the account
0073      * is online)
0074      */
0075     virtual bool isReachable ();
0076 
0077     /**
0078      * Create custom context menu items for the contact
0079      * FIXME: implement manager version here?
0080      */
0081 //  virtual QList<QAction *> *customContextMenuActions () = 0;
0082 
0083     /**
0084      * Serialize contact
0085      */
0086     virtual void serialize (QMap < QString, QString > &serializedData, QMap < QString, QString > &addressBookData);
0087 
0088     /**
0089      * Update contact if a roster item has been
0090      * received for it. (used during login)
0091      */
0092     void updateContact ( const XMPP::RosterItem &item );
0093 
0094     /**
0095      * Deal with an incoming message for this contact.
0096      */
0097     virtual void handleIncomingMessage ( const XMPP::Message &message ) = 0;
0098 
0099     /**
0100      * Update the resource property of the
0101      * contact, listing all available resources.
0102      */
0103     void updateResourceList ();
0104 
0105     /**
0106      * Return current full address.
0107      * Uses bestResource() if no presubscribed
0108      * address exists.
0109      */
0110     QString fullAddress ();
0111 
0112     /**
0113      * Set the dontSync flag for this contact.
0114      * If this flag is set, calls to @ref sync will
0115      * be ignored. This is required if the contact
0116      * has been moved between groups on the server
0117      * after we logged in and we try to update our
0118      * local contact list. Since libkopete can only
0119      * handle one group update at a time, moving
0120      * between groups requires to operations which
0121      * each in turn would cause a call to sync(),
0122      * overwriting the change that is being carried
0123      * out. (besides causing unnecessary traffic)
0124      * This is avoided by setting the dontSync flag
0125      * while synchronizing the local copy.
0126      */
0127     void setDontSync ( bool flag );
0128 
0129     /**
0130      * Return the status of the dontSync flag.
0131      * See @ref setDontSync for a full description.
0132      */
0133     bool dontSync ();
0134     
0135     /**
0136      * return the roster item of the contact.
0137      * to get the jid, use  rosterItem().jid().full()  don't use contactId as it is not the same with transport
0138      */
0139     XMPP::RosterItem rosterItem() const { return mRosterItem; }
0140     
0141     /**
0142      * Reads a vCard object and updates the contact's
0143      * properties accordingly.
0144      */
0145     void setPropertiesFromVCard ( const XMPP::VCard &vCard );
0146 
0147 
0148 public slots:
0149 
0150     /**
0151      * Retrieve a vCard for the contact
0152      */
0153     virtual void slotUserInfo ();
0154     
0155     
0156     /**
0157      * Re-evaluate online status. Gets called
0158      * whenever a resource is added, removed, or
0159      * changed in the resource pool.
0160      */
0161     void reevaluateStatus ();
0162 
0163 protected:
0164     /**
0165      * Construct best address out of
0166      * eventually preselected resource
0167      * (due to subscription) and best
0168      * available resource.
0169      */
0170     XMPP::Jid bestAddress ();
0171 
0172     /**
0173      * This will simply cache all
0174      * relevant data for this contact.
0175      */
0176     XMPP::RosterItem mRosterItem;
0177 
0178 private:
0179     bool mDontSync;
0180     JabberAccount *m_account;
0181 
0182 };
0183 
0184 #endif
0185 
0186 // vim: set noet ts=4 sts=4 sw=4: