summaryrefslogtreecommitdiff
path: root/TelepathyQt4/contact.h
blob: fa9097cfce5149e466eee53fe6d707a5d98426cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * This file is part of TelepathyQt4
 *
 * Copyright (C) 2008-2010 Collabora Ltd. <http://www.collabora.co.uk/>
 * Copyright (C) 2008-2010 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef _TelepathyQt4_contact_h_HEADER_GUARD_
#define _TelepathyQt4_contact_h_HEADER_GUARD_

#ifndef IN_TELEPATHY_QT4_HEADER
#error IN_TELEPATHY_QT4_HEADER
#endif

#include <TelepathyQt4/Channel>
#include <TelepathyQt4/Feature>
#include <TelepathyQt4/Object>
#include <TelepathyQt4/Types>

#include <QSet>
#include <QVariantMap>

namespace Tp
{

struct AvatarData;
class ContactCapabilities;
class LocationInfo;
class ContactManager;
class PendingContactInfo;
class PendingOperation;
class Presence;
class ReferencedHandles;

class TELEPATHY_QT4_EXPORT Contact : public Object
{
    Q_OBJECT
    Q_DISABLE_COPY(Contact)

public:
    static const Feature FeatureAlias;
    static const Feature FeatureAvatarData;
    static const Feature FeatureAvatarToken;
    static const Feature FeatureCapabilities;
    static const Feature FeatureInfo;
    static const Feature FeatureLocation;
    static const Feature FeatureSimplePresence;

    enum PresenceState {
         PresenceStateNo,
         PresenceStateAsk,
         PresenceStateYes
    };

    class InfoFields
    {
    public:
        InfoFields();
        InfoFields(const ContactInfoFieldList &fields);
        InfoFields(const InfoFields &other);
        ~InfoFields();

        bool isValid() const { return mPriv.constData() != 0; }

        InfoFields &operator=(const InfoFields &other);

        ContactInfoFieldList fields(const QString &name) const;

        ContactInfoFieldList allFields() const;

    private:
        struct Private;
        friend struct Private;
        QSharedDataPointer<Private> mPriv;
    };

    ~Contact();

    ContactManagerPtr manager() const;

    ReferencedHandles handle() const;

    // TODO filter: exact, prefix, substring match
    QString id() const;

    Features requestedFeatures() const;
    Features actualFeatures() const;

    // TODO filter: exact, prefix, substring match
    QString alias() const;

    bool isAvatarTokenKnown() const;
    QString avatarToken() const;
    AvatarData avatarData() const;

    /*
     * TODO filter:
     *  - exact match of presence().type(), presence().status()
     *  - ANY 1 of a number of presence types/statuses
     *  - presence().type() greater or less than a set value
     *  - have/don't have presence().message() AND exact/prefix/substring
     */
    Presence presence() const;

    // TODO filter: the same as Account filtering by caps
    ContactCapabilities capabilities() const;

    // TODO filter: is it available, how accurate, are they near me
    LocationInfo location() const;

    // TODO filter: having a specific field, having ANY field,
    // (field: exact, contents: exact/prefix/substring)
    InfoFields infoFields() const;
    PendingOperation *refreshInfo();
    PendingContactInfo *requestInfo();

    /*
     * Filters on exact values of these, but also the "in your contact list at all or not" usecase
     */
    PresenceState subscriptionState() const;
    PresenceState publishState() const;

    PendingOperation *requestPresenceSubscription(const QString &message = QString());
    PendingOperation *removePresenceSubscription(const QString &message = QString());
    PendingOperation *authorizePresencePublication(const QString &message = QString());
    PendingOperation *removePresencePublication(const QString &message = QString());

    /*
     * Filter on being blocked or not
     */
    bool isBlocked() const;
    PendingOperation *block(bool value = true);

    /*
     * Filter on the groups they're in - to show a specific group only
     *
     * Also prefix/substring match on ANY of the groups of the contact
     */
    QStringList groups() const;
    PendingOperation *addToGroup(const QString &group);
    PendingOperation *removeFromGroup(const QString &group);

Q_SIGNALS:
    void aliasChanged(const QString &alias);

    void avatarTokenChanged(const QString &avatarToken);
    void avatarDataChanged(const Tp::AvatarData &avatarData);

    void presenceChanged(const Tp::Presence &presence);

    void capabilitiesChanged(const Tp::ContactCapabilities &caps);

    void locationUpdated(const Tp::LocationInfo &location);

    void infoFieldsChanged(const Tp::Contact::InfoFields &infoFields);

    void subscriptionStateChanged(Tp::Contact::PresenceState state,
            const Tp::Channel::GroupMemberChangeDetails &details);
    void publishStateChanged(Tp::Contact::PresenceState state,
            const Tp::Channel::GroupMemberChangeDetails &details);
    void blockStatusChanged(bool blocked, const Tp::Channel::GroupMemberChangeDetails &details);

    void addedToGroup(const QString &group);
    void removedFromGroup(const QString &group);

    // TODO: consider how the Renaming interface should work and map to Contacts
    // I guess it would be something like:
    // void renamedTo(Tp::ContactPtr)
    // with that contact getting the same features requested as the current one. Or would we rather
    // want to signal that change right away with a handle?

private:
    Contact(ContactManager *manager, const ReferencedHandles &handle,
            const Features &requestedFeatures, const QVariantMap &attributes);

    void augment(const Features &requestedFeatures, const QVariantMap &attributes);

    void receiveAlias(const QString &alias);
    void receiveAvatarToken(const QString &avatarToken);
    void setAvatarToken(const QString &token);
    void receiveAvatarData(const AvatarData &);
    void receiveSimplePresence(const SimplePresence &presence);
    void receiveCapabilities(const RequestableChannelClassList &caps);
    void receiveLocation(const QVariantMap &location);
    void receiveInfo(const ContactInfoFieldList &info);

    void setSubscriptionState(PresenceState state, const Channel::GroupMemberChangeDetails &details =
            Channel::GroupMemberChangeDetails());
    void setPublishState(PresenceState state, const Channel::GroupMemberChangeDetails &details =
            Channel::GroupMemberChangeDetails());
    void setBlocked(bool value, const Channel::GroupMemberChangeDetails &details =
            Channel::GroupMemberChangeDetails());

    void setAddedToGroup(const QString &group);
    void setRemovedFromGroup(const QString &group);

    struct Private;
    friend class ContactManager;
    friend struct Private;
    Private *mPriv;
};

} // Tp

Q_DECLARE_METATYPE(Tp::Contact::InfoFields);

#endif