1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtContacts module of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
42
#include "qcontactactiontarget.h"
43
#include "qcontactactiontarget_p.h"
49
QT_BEGIN_NAMESPACE_CONTACTS
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
62
\enum QContactActionTarget::Type
63
This enumerator defines the type of a QContactActionTarget.
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.
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).
77
QContactActionTarget::QContactActionTarget(const QContact& contact, const QList<QContactDetail>& details)
78
: d(new QContactActionTargetPrivate(contact, details))
83
* Constructs a new action target from the given \a contact and a specific \a detail of that contact
85
QContactActionTarget::QContactActionTarget(const QContact& contact, const QContactDetail& detail)
86
: d(new QContactActionTargetPrivate(contact, QList<QContactDetail>() << detail))
91
* Constructs a copy of the \a other action target
93
QContactActionTarget::QContactActionTarget(const QContactActionTarget& other)
99
* Assigns this action target to be equal to \a other
101
QContactActionTarget& QContactActionTarget::operator=(const QContactActionTarget& other)
108
* Cleans up any memory in use by the action target
110
QContactActionTarget::~QContactActionTarget()
115
* Returns the contact that this action target will operate on.
118
QContact QContactActionTarget::contact() const
120
return d.constData()->m_contact;
124
* Returns the details that this action target will operate on.
127
QList<QContactDetail> QContactActionTarget::details() const
129
return d.constData()->m_details;
133
* Sets the contact that this action target will operate on to \a contact.
136
void QContactActionTarget::setContact(const QContact& contact)
138
d->m_contact = contact;
142
* Sets the details that this action target will operate on to \a details.
145
void QContactActionTarget::setDetails(const QList<QContactDetail>& details)
147
d->m_details = details;
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.
154
bool QContactActionTarget::isValid() const
156
return (d.constData()->m_contact != QContact());
160
* Returns true if the contacts and details specified by this action target are equal to those specified by \a other
162
bool QContactActionTarget::operator==(const QContactActionTarget& other) const
164
return d.constData()->m_contact == other.d.constData()->m_contact
165
&& d.constData()->m_details == other.d.constData()->m_details;
169
* Returns true if the contacts or details specified by this action target are different to that specified by \a other
171
bool QContactActionTarget::operator!=(const QContactActionTarget& other) const
173
return !(*this == other);
177
Returns the type of this action target.
179
The type is determined by the properties that have been set on this target.
181
QContactActionTarget::Type QContactActionTarget::type() const
183
if (d.constData()->m_contact.isEmpty())
184
return QContactActionTarget::Invalid;
185
switch (d.constData()->m_details.count()) {
187
return QContactActionTarget::WholeContact;
189
return QContactActionTarget::SingleDetail;
191
return QContactActionTarget::MultipleDetails;
195
/*! Returns the hash value for \a key. */
196
uint qHash(const QContactActionTarget& key)
198
uint ret = qHash(key.contact());
199
foreach (const QContactDetail& det, key.details()) {
205
#ifndef QT_NO_DATASTREAM
206
/*! Streams the given \a target to the datastream \a out */
207
QDataStream& operator<<(QDataStream& out, const QContactActionTarget& target)
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;
216
/*! Streams \a target in from the datastream \a in */
217
QDataStream& operator>>(QDataStream& in, QContactActionTarget& target)
219
QContactActionTarget retn;
220
quint8 formatVersion;
222
if (formatVersion == 1) {
223
in >> retn.d->m_contact;
224
in >> retn.d->m_details;
226
in.setStatus(QDataStream::ReadCorruptData);
233
#ifndef QT_NO_DEBUG_STREAM
234
QDebug& operator<<(QDebug dbg, const QContactActionTarget& target)
236
dbg.nospace() << "QContactActionTarget(" << target.contact() << target.details() << ')';
237
return dbg.maybeSpace();
241
QT_END_NAMESPACE_CONTACTS