Home · All Classes · All Namespaces · Modules · Functions · Files

contact.h

00001 /*
00002  * This file is part of TelepathyQt4
00003  *
00004  * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
00005  * Copyright (C) 2008 Nokia Corporation
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _TelepathyQt4_contact_h_HEADER_GUARD_
00023 #define _TelepathyQt4_contact_h_HEADER_GUARD_
00024 
00025 #ifndef IN_TELEPATHY_QT4_HEADER
00026 #error IN_TELEPATHY_QT4_HEADER
00027 #endif
00028 
00029 #include <QObject>
00030 #include <QSet>
00031 #include <QSharedPointer>
00032 #include <QVariantMap>
00033 
00034 #include <TelepathyQt4/Types>
00035 
00036 namespace Tp
00037 {
00038 
00039 class ContactCapabilities;
00040 class ContactLocation;
00041 class ContactManager;
00042 class PendingContactInfo;
00043 class PendingOperation;
00044 class ReferencedHandles;
00045 
00046 class TELEPATHY_QT4_EXPORT Contact : public QObject
00047 {
00048     Q_OBJECT
00049     Q_DISABLE_COPY(Contact);
00050 
00051 public:
00052     enum Feature {
00053         FeatureAlias,
00054         FeatureAvatarToken,
00055         FeatureSimplePresence,
00056         FeatureCapabilities,
00057         FeatureLocation,
00058         FeatureInfo,
00059         FeatureAvatarData,
00060         _Padding = 0xFFFFFFFF
00061     };
00062 
00063     enum PresenceState {
00064          PresenceStateNo,
00065          PresenceStateAsk,
00066          PresenceStateYes
00067     };
00068 
00069     class InfoFields
00070     {
00071     public:
00072         InfoFields();
00073         InfoFields(const ContactInfoFieldList &fields);
00074         InfoFields(const InfoFields &other);
00075         ~InfoFields();
00076 
00077         bool isValid() const { return mPriv.constData() != 0; }
00078 
00079         InfoFields &operator=(const InfoFields &other);
00080 
00081         ContactInfoFieldList fields(const QString &name) const;
00082 
00083         ContactInfoFieldList allFields() const;
00084 
00085     private:
00086         struct Private;
00087         friend struct Private;
00088         QSharedDataPointer<Private> mPriv;
00089     };
00090 
00091     ContactManager *manager() const;
00092 
00093     ReferencedHandles handle() const;
00094     QString id() const; // TODO filter: exact, prefix, substring match
00095 
00096     QSet<Feature> requestedFeatures() const;
00097     QSet<Feature> actualFeatures() const;
00098 
00099     QString alias() const; // TODO filter: exact, prefix, substring match
00100 
00101     bool isAvatarTokenKnown() const;
00102     QString avatarToken() const;
00103     AvatarData avatarData() const;
00104 
00105     /*
00106      * TODO filter:
00107      *  - exact match of presenceType, presenceStatus
00108      *  - ANY 1 of a number of presenceTypes/Statuses
00109      *  - presenceType greater or less than a set value
00110      */
00111     QString presenceStatus() const;
00112     uint presenceType() const;
00113 
00114     // TODO filter: have/don't have message AND exact/prefix/substring
00115     QString presenceMessage() const; 
00116 
00117     // TODO filter: the same as Account filtering by caps
00118     ContactCapabilities *capabilities() const;
00119 
00120     // TODO filter: is it available, how accurate, are they near me
00121     ContactLocation *location() const;
00122 
00123     // TODO filter: having a specific field, having ANY field,
00124     // (field: exact, contents: exact/prefix/substring)
00125     TELEPATHY_QT4_DEPRECATED ContactInfoFieldList info() const;
00126     InfoFields infoFields() const;
00127     PendingOperation *refreshInfo();
00128     PendingContactInfo *requestInfo();
00129 
00130     /*
00131      * Filters on exact values of these, but also the "in your contact list at all or not" usecase
00132      */
00133     PresenceState subscriptionState() const;
00134     PresenceState publishState() const;
00135 
00136     PendingOperation *requestPresenceSubscription(const QString &message = QString());
00137     PendingOperation *removePresenceSubscription(const QString &message = QString());
00138     PendingOperation *authorizePresencePublication(const QString &message = QString());
00139     PendingOperation *removePresencePublication(const QString &message = QString());
00140 
00141     /*
00142      * Filter on being blocked or not
00143      */
00144     bool isBlocked() const;
00145     PendingOperation *block(bool value = true);
00146 
00147     /*
00148      * Filter on the groups they're in - to show a specific group only
00149      *
00150      * Also prefix/substring match on ANY of the groups of the contact
00151      */
00152     QStringList groups() const;
00153     PendingOperation *addToGroup(const QString &group);
00154     PendingOperation *removeFromGroup(const QString &group);
00155 
00156     ~Contact();
00157 
00158 Q_SIGNALS:
00159     void aliasChanged(const QString &alias);
00160     void avatarTokenChanged(const QString &avatarToken);
00161     void avatarDataChanged(const Tp::AvatarData &);
00162     void simplePresenceChanged(const QString &status, uint type, const QString &presenceMessage);
00163     void capabilitiesChanged(Tp::ContactCapabilities *caps);
00164     void locationUpdated(Tp::ContactLocation *location);
00165     void infoChanged(const Tp::ContactInfoFieldList &info);
00166     void infoFieldsChanged(const Tp::Contact::InfoFields &infoFields);
00167 
00168     void subscriptionStateChanged(Tp::Contact::PresenceState state);
00169     void publishStateChanged(Tp::Contact::PresenceState state);
00170     void blockStatusChanged(bool blocked);
00171 
00172     void addedToGroup(const QString &group);
00173     void removedFromGroup(const QString &group);
00174 
00175     // TODO: consider how the Renaming interface should work and map to Contacts
00176     // I guess it would be something like:
00177     // void renamedTo(Tp::ContactPtr)
00178     // with that contact getting the same features requested as the current one. Or would we rather
00179     // want to signal that change right away with a handle?
00180 
00181 private:
00182     Contact(ContactManager *manager, const ReferencedHandles &handle,
00183             const QSet<Feature> &requestedFeatures, const QVariantMap &attributes);
00184 
00185     void augment(const QSet<Feature> &requestedFeatures, const QVariantMap &attributes);
00186 
00187     void receiveAlias(const QString &alias);
00188     void receiveAvatarToken(const QString &avatarToken);
00189     void setAvatarToken(const QString &token);
00190     void receiveAvatarData(const AvatarData &);
00191     void receiveSimplePresence(const SimplePresence &presence);
00192     void receiveCapabilities(const RequestableChannelClassList &caps);
00193     void receiveLocation(const QVariantMap &location);
00194     void receiveInfo(const ContactInfoFieldList &info);
00195 
00196     void setSubscriptionState(PresenceState state);
00197     void setPublishState(PresenceState state);
00198     void setBlocked(bool value);
00199 
00200     void setAddedToGroup(const QString &group);
00201     void setRemovedFromGroup(const QString &group);
00202 
00203     struct Private;
00204     friend class ContactManager;
00205     friend struct Private;
00206     Private *mPriv;
00207 };
00208 
00209 typedef QSet<ContactPtr> Contacts;
00210 
00211 inline uint qHash(const ContactPtr &contact)
00212 {
00213     return qHash(contact.data());
00214 }
00215 
00216 } // Tp
00217 
00218 #endif


Copyright © 2008-2010 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.3.13