~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/contacts/qcontactactiontarget.cpp

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtContacts module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include "qcontactactiontarget.h"
 
43
#include "qcontactactiontarget_p.h"
 
44
 
 
45
#include "qcontact.h"
 
46
 
 
47
#include <QHash>
 
48
 
 
49
QT_BEGIN_NAMESPACE_CONTACTS
 
50
 
 
51
/*!
 
52
  \class QContactActionTarget
 
53
  \brief The QContactActionTarget class provides information about the
 
54
  target of an action.  It may be either a contact, a contact and a detail
 
55
  of that contact, or a contact and a list of the details of the contact,
 
56
  which together should be used by the action.
 
57
  \ingroup contacts-actions
 
58
  \inmodule QtContacts
 
59
*/
 
60
 
 
61
/*!
 
62
  \enum QContactActionTarget::Type
 
63
  This enumerator defines the type of a QContactActionTarget.
 
64
 
 
65
  \value Invalid The type is invalid.
 
66
  \value WholeContact The type is a complete contact.
 
67
  \value SingleDetail The type is only a single detail.
 
68
  \value MultipleDetails The type contains multiple details.
 
69
*/
 
70
 
 
71
/*!
 
72
 * Constructs a new action target from the given \a contact and the given list of that contact's \a details.
 
73
 * If no \a contact is specified, the target will be invalid.  If a \a contact but no \a details are specified,
 
74
 * the target will be valid, but the action which operates on the target may fail (for example, if it requires
 
75
 * a certain detail to be specified in order to perform the action).
 
76
 */
 
77
QContactActionTarget::QContactActionTarget(const QContact& contact, const QList<QContactDetail>& details)
 
78
        : d(new QContactActionTargetPrivate(contact, details))
 
79
{
 
80
}
 
81
 
 
82
/*!
 
83
 * Constructs a new action target from the given \a contact and a specific \a detail of that contact
 
84
 */
 
85
QContactActionTarget::QContactActionTarget(const QContact& contact, const QContactDetail& detail)
 
86
        : d(new QContactActionTargetPrivate(contact, QList<QContactDetail>() << detail))
 
87
{
 
88
}
 
89
 
 
90
/*!
 
91
 * Constructs a copy of the \a other action target
 
92
 */
 
93
QContactActionTarget::QContactActionTarget(const QContactActionTarget& other)
 
94
        : d(other.d)
 
95
{
 
96
}
 
97
 
 
98
/*!
 
99
 * Assigns this action target to be equal to \a other
 
100
 */
 
101
QContactActionTarget& QContactActionTarget::operator=(const QContactActionTarget& other)
 
102
{
 
103
    d = other.d;
 
104
    return *this;
 
105
}
 
106
 
 
107
/*!
 
108
 * Cleans up any memory in use by the action target
 
109
 */
 
110
QContactActionTarget::~QContactActionTarget()
 
111
{
 
112
}
 
113
 
 
114
/*!
 
115
 * Returns the contact that this action target will operate on.
 
116
 * \sa details()
 
117
 */
 
118
QContact QContactActionTarget::contact() const
 
119
{
 
120
    return d.constData()->m_contact;
 
121
}
 
122
 
 
123
/*!
 
124
 * Returns the details that this action target will operate on.
 
125
 * \sa contact()
 
126
 */
 
127
QList<QContactDetail> QContactActionTarget::details() const
 
128
{
 
129
    return d.constData()->m_details;
 
130
}
 
131
 
 
132
/*!
 
133
 * Sets the contact that this action target will operate on to \a contact.
 
134
 * \sa setDetails()
 
135
 */
 
136
void QContactActionTarget::setContact(const QContact& contact)
 
137
{
 
138
    d->m_contact = contact;
 
139
}
 
140
 
 
141
/*!
 
142
 * Sets the details that this action target will operate on to \a details.
 
143
 * \sa setContact()
 
144
 */
 
145
void QContactActionTarget::setDetails(const QList<QContactDetail>& details)
 
146
{
 
147
    d->m_details = details;
 
148
}
 
149
 
 
150
/*!
 
151
 * Returns true if the target contact is not the default constructed contact.
 
152
 * The validity of any specified details is not checked by this function.
 
153
 */
 
154
bool QContactActionTarget::isValid() const
 
155
{
 
156
    return (d.constData()->m_contact != QContact());
 
157
}
 
158
 
 
159
/*!
 
160
 * Returns true if the contacts and details specified by this action target are equal to those specified by \a other
 
161
 */
 
162
bool QContactActionTarget::operator==(const QContactActionTarget& other) const
 
163
{
 
164
    return d.constData()->m_contact == other.d.constData()->m_contact
 
165
            && d.constData()->m_details == other.d.constData()->m_details;
 
166
}
 
167
 
 
168
/*!
 
169
 * Returns true if the contacts or details specified by this action target are different to that specified by \a other
 
170
 */
 
171
bool QContactActionTarget::operator!=(const QContactActionTarget& other) const
 
172
{
 
173
    return !(*this == other);
 
174
}
 
175
 
 
176
/*!
 
177
  Returns the type of this action target.
 
178
 
 
179
  The type is determined by the properties that have been set on this target.
 
180
 */
 
181
QContactActionTarget::Type QContactActionTarget::type() const
 
182
{
 
183
    if (d.constData()->m_contact.isEmpty())
 
184
        return QContactActionTarget::Invalid;
 
185
    switch (d.constData()->m_details.count()) {
 
186
        case 0:
 
187
            return QContactActionTarget::WholeContact;
 
188
        case 1:
 
189
            return QContactActionTarget::SingleDetail;
 
190
        default:
 
191
            return QContactActionTarget::MultipleDetails;
 
192
    }
 
193
}
 
194
 
 
195
/*! Returns the hash value for \a key. */
 
196
uint qHash(const QContactActionTarget& key)
 
197
{
 
198
    uint ret = qHash(key.contact());
 
199
    foreach (const QContactDetail& det, key.details()) {
 
200
        ret += qHash(det);
 
201
    }
 
202
    return ret;
 
203
}
 
204
 
 
205
#ifndef QT_NO_DATASTREAM
 
206
/*! Streams the given \a target to the datastream \a out */
 
207
QDataStream& operator<<(QDataStream& out, const QContactActionTarget& target)
 
208
{
 
209
    quint8 formatVersion = 1; // Version of QDataStream format for QContactActionTarget
 
210
    out << formatVersion;
 
211
    out << target.d.constData()->m_contact;
 
212
    out << target.d.constData()->m_details;
 
213
    return out;
 
214
}
 
215
 
 
216
/*! Streams \a target in from the datastream \a in */
 
217
QDataStream& operator>>(QDataStream& in, QContactActionTarget& target)
 
218
{
 
219
    QContactActionTarget retn;
 
220
    quint8 formatVersion;
 
221
    in >> formatVersion;
 
222
    if (formatVersion == 1) {
 
223
        in >> retn.d->m_contact;
 
224
        in >> retn.d->m_details;
 
225
    } else {
 
226
        in.setStatus(QDataStream::ReadCorruptData);
 
227
    }
 
228
    target = retn;
 
229
    return in;
 
230
}
 
231
#endif
 
232
 
 
233
#ifndef QT_NO_DEBUG_STREAM
 
234
QDebug& operator<<(QDebug dbg, const QContactActionTarget& target)
 
235
{
 
236
    dbg.nospace() << "QContactActionTarget(" << target.contact() << target.details() << ')';
 
237
    return dbg.maybeSpace();
 
238
}
 
239
#endif
 
240
 
 
241
QT_END_NAMESPACE_CONTACTS