summaryrefslogtreecommitdiff
path: root/qt4/TelepathyQt4/contact-factory.cpp
blob: 9f71e381c25c6d34f5bd7893725fc757a7c3bf12 (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
/**
 * This file is part of TelepathyQt4
 *
 * @copyright Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
 * @copyright Copyright (C) 2010 Nokia Corporation
 * @license LGPL 2.1
 *
 * 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
 */

#include <TelepathyQt4/ContactFactory>

namespace Tp
{

struct TELEPATHY_QT4_NO_EXPORT ContactFactory::Private
{
    Features features;
};

/**
 * \class ContactFactory
 * \ingroup utils
 * \headerfile TelepathyQt4/contact-factory.h <TelepathyQt4/ContactFactory>
 *
 * \brief The ContactFactory class is responsible for constructing Contact
 * objects according to application-defined settings.
 */

/**
 * Creates a new ContactFactory.
 *
 * \param features The features to make ready on constructed contacts.
 * \returns A pointer to the created factory.
 */
ContactFactoryPtr ContactFactory::create(const Features &features)
{
    return ContactFactoryPtr(new ContactFactory(features));
}

/**
 * Class constructor.
 *
 * \param features The features to make ready on constructed contacts.
 */
ContactFactory::ContactFactory(const Features &features)
    : mPriv(new Private)
{
    addFeatures(features);
}

/**
 * Class destructor.
 */
ContactFactory::~ContactFactory()
{
    delete mPriv;
}

/**
 * Gets the features this factory will make ready on constructed contacts.
 *
 * \return The set of features.
 */
Features ContactFactory::features() const
{
    Features features = mPriv->features;
    // FeatureAvatarData depends on FeatureAvatarToken
    if (features.contains(Contact::FeatureAvatarData) &&
        !features.contains(Contact::FeatureAvatarToken)) {
        features.insert(Contact::FeatureAvatarToken);
    }

    return features;
}

/**
 * Adds a single feature this factory will make ready on further constructed contacts.
 *
 * No feature removal is provided, to guard against uncooperative modules removing features other
 * modules have set and depend on.
 *
 * \param feature The feature to add.
 */
void ContactFactory::addFeature(const Feature &feature)
{
    addFeatures(Features(feature));
}

/**
 * Adds a set of features this factory will make ready on further constructed contacts.
 *
 * No feature removal is provided, to guard against uncooperative modules removing features other
 * modules have set and depend on.
 *
 * \param features The features to add.
 */
void ContactFactory::addFeatures(const Features &features)
{
    mPriv->features.unite(features);
}

/**
 * Can be used by subclasses to override the Contact subclass constructed by the factory.
 *
 * The default implementation constructs Tp::Contact objects.
 *
 * \param manager The contact manager this contact belongs.
 * \param handle The contact handle.
 * \param features The desired contact features.
 * \param attributes The desired contact attributes.
 * \return A pointer to the constructed contact.
 */
ContactPtr ContactFactory::construct(Tp::ContactManager *manager, const ReferencedHandles &handle,
        const Features &features, const QVariantMap &attributes) const
{
    ContactPtr contact = ContactPtr(new Contact(manager, handle, features, attributes));
    return contact;
}

/**
 * Can be used by subclasses to do arbitrary manipulation on constructed Contact objects.
 *
 * The default implementation does nothing.
 *
 * \param contact The contact to be prepared.
 * \return A PendingOperation used to prepare the contact or NULL if there is nothing to prepare.
 */
PendingOperation *ContactFactory::prepare(const ContactPtr &contact) const
{
    return NULL;
}

}