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 "qcontactactiondescriptor.h"
43
#include "qcontactactiondescriptor_p.h"
44
#include "qcontactactionfactory.h"
46
#include "qcontactinvalidfilter.h"
51
When these conditions are satisfied, QStringLiteral is implemented by
52
gcc's statement-expression extension. However, in this file it will
53
not work, because "statement-expressions are not allowed outside functions
54
nor in template-argument lists".
56
Fall back to the less-performant QLatin1String in this case.
58
#if defined(QStringLiteral) && defined(QT_UNICODE_LITERAL_II) && defined(Q_CC_GNU) && !defined(Q_COMPILER_LAMBDA)
59
# undef QStringLiteral
60
# define QStringLiteral QLatin1String
63
QT_BEGIN_NAMESPACE_CONTACTS
66
\class QContactActionDescriptor
67
\brief The QContactActionDescriptor class provides information that
68
uniquely identifies a specific implementation of an action
69
\ingroup contacts-actions
74
* Constructs a new, invalid action descriptor
76
QContactActionDescriptor::QContactActionDescriptor()
77
: d(new QContactActionDescriptorPrivate())
82
* Constructs a copy of the \a other action descriptor
84
QContactActionDescriptor::QContactActionDescriptor(const QContactActionDescriptor& other)
90
* Assigns this action descriptor to be equal to \a other
92
QContactActionDescriptor& QContactActionDescriptor::operator=(const QContactActionDescriptor& other)
99
* Cleans up any memory in use by the action descriptor
101
QContactActionDescriptor::~QContactActionDescriptor()
106
* Returns the name of the action which is identified by the action descriptor
108
QString QContactActionDescriptor::actionName() const
110
return d.constData()->m_actionName;
115
* Returns the name of the service of the action implementation which is identified by the action descriptor
117
QString QContactActionDescriptor::serviceName() const
119
return d.constData()->m_serviceName;
123
* Returns the identifier of the action, within the service.
125
QString QContactActionDescriptor::actionIdentifier() const
127
return d.constData()->m_identifier;
131
Returns the service-specified version of the action implementation which is identified by the action descriptor
133
int QContactActionDescriptor::implementationVersion() const
135
return d.constData()->m_implementationVersion;
139
Returns the set of action targets which are supported by this action for the given contact \a contact
141
QSet<QContactActionTarget> QContactActionDescriptor::supportedTargets(const QContact& contact) const
143
if (d.constData()->m_factory) {
144
return d.constData()->m_factory->supportedTargets(contact, *this);
147
return QSet<QContactActionTarget>();
151
Returns a filter which will match contacts for which this action has at least one supported action target
153
QContactFilter QContactActionDescriptor::contactFilter() const
155
if (d.constData()->m_factory) {
156
return d.constData()->m_factory->contactFilter(*this);
159
return QContactInvalidFilter();
164
\variable QContactActionDescriptor::MetaDataIcon
165
The meta data key which corresponds to the meta data value
166
which contains the icon which should be displayed for this
170
const QString QContactActionDescriptor::MetaDataIcon(QStringLiteral("Icon"));
173
\variable QContactActionDescriptor::MetaDataLabel
174
The meta data key which corresponds to the meta data value
175
which contains the display label for this action.
178
const QString QContactActionDescriptor::MetaDataLabel(QStringLiteral("Label"));
181
\variable QContactActionDescriptor::MetaDataSecondLabel
182
The meta data key which corresponds to the meta data value
183
which contains the second or additional display label for this
187
const QString QContactActionDescriptor::MetaDataSecondLabel(QStringLiteral("SecondLabel"));
190
\variable QContactActionDescriptor::MetaDataOptionalParameterKeys
191
The meta data key which corresponds to the meta data value which
192
contains the list of keys of parameters which the client may provide
193
at invocation time which may affect the action.
195
An example of an optional parameter might be an "attachment"
196
parameter to a "send email" action.
200
const QString QContactActionDescriptor::MetaDataOptionalParameterKeys(QStringLiteral("OptionalParameterKeys"));
203
\variable QContactActionDescriptor::MetaDataMandatoryParameterKeys
204
The meta data key which corresponds to the meta data value which
205
contains the list of keys of parameters which the client must provide
206
at invocation for the action to succeed.
208
An example of a mandatory parameter might be a "recipient"
209
parameter to a "send email" action.
213
const QString QContactActionDescriptor::MetaDataMandatoryParameterKeys(QStringLiteral("MandatoryParameterKeys"));
216
Returns the meta data for the given meta data key \a key for the the given action targets \a targets with the given invocation parameters \a parameters.
218
QVariant QContactActionDescriptor::metaData(const QString& key, const QList<QContactActionTarget>& targets, const QVariantMap& parameters) const
220
if (d.constData()->m_factory) {
221
return d.constData()->m_factory->metaData(key, targets, parameters, *this);
228
Returns the meta data for the given meta data key \a key with the given invocation parameters \a parameters.
230
QVariant QContactActionDescriptor::metaData(const QString& key, const QVariantMap& parameters) const
232
return metaData(key, QList<QContactActionTarget>(), parameters);
236
Returns the meta data for the given meta data key \a key for the \a target, with the given invocation parameters \a parameters.
238
QVariant QContactActionDescriptor::metaData(const QString& key, const QContactActionTarget& target, const QVariantMap& parameters) const
240
return metaData(key, QList<QContactActionTarget>() << target, parameters);
244
Returns the meta data for the given meta data key \a key for a target identified by \a contact and \a detail, with the given invocation parameters \a parameters.
246
QVariant QContactActionDescriptor::metaData(const QString& key, const QContact& contact, const QContactDetail& detail, const QVariantMap& parameters) const
248
return metaData(key, QList<QContactActionTarget>() << QContactActionTarget(contact, detail), parameters);
252
Returns true if the action which this descriptor describes supports at least one action target for the given \a contact
254
bool QContactActionDescriptor::supportsContact(const QContact& contact) const
256
if (d.constData()->m_factory) {
257
return d.constData()->m_factory->supportsContact(contact, *this);
264
* Returns false if either the name, service and version of the descriptor are missing from the descriptor,
265
* or if the descriptor is not associated with a valid action factory which can create instances of an action.
266
* An empty descriptor cannot uniquely identify an action.
268
bool QContactActionDescriptor::isValid() const
270
if (d.constData()->m_actionName.isEmpty())
272
if (d.constData()->m_serviceName.isEmpty())
274
if (d.constData()->m_identifier.isEmpty())
276
if (d.constData()->m_implementationVersion <= 0)
278
if (d.constData()->m_factory == 0)
284
* Returns true if the action identified by this descriptor is the same as the action
285
* identified by the \a other descriptor. Note that two actions with the same
286
* action name, service name and implementation version may in fact be different (for example,
287
* they may have different metaData), so using this function is the only way for clients
288
* to tell whether or not the action descriptors identify different actions.
290
bool QContactActionDescriptor::operator==(const QContactActionDescriptor& other) const
292
return (d.constData()->m_factory == other.d.constData()->m_factory && d.constData()->m_identifier == other.d.constData()->m_identifier);
296
* Returns true if the action name, service name or service-specified implementation version
297
* specified by this action descriptor are different to that specified by \a other
299
bool QContactActionDescriptor::operator!=(const QContactActionDescriptor& other) const
301
return !(*this == other);
304
/*! Returns the hash value for \a key. */
305
uint qHash(const QContactActionDescriptor& key)
309
ret += QT_PREPEND_NAMESPACE(qHash)(key.serviceName())
310
+ QT_PREPEND_NAMESPACE(qHash)(key.actionName())
311
+ QT_PREPEND_NAMESPACE(qHash)(key.d.constData()->m_identifier)
312
+ QT_PREPEND_NAMESPACE(qHash)(key.implementationVersion())
313
+ QT_PREPEND_NAMESPACE(qHash)(key.d.constData()->m_factory);
318
#ifndef QT_NO_DEBUG_STREAM
319
QDebug& operator<<(QDebug dbg, const QContactActionDescriptor& descriptor)
321
dbg.nospace() << "QContactActionDescriptor("
322
<< descriptor.serviceName() << ","
323
<< descriptor.actionName() << ","
324
<< descriptor.d.constData()->m_identifier << ","
325
<< descriptor.implementationVersion() << ","
326
<< descriptor.d.constData()->m_factory
328
return dbg.maybeSpace();
332
QT_END_NAMESPACE_CONTACTS