~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/contacts/qcontactactiondescriptor.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 "qcontactactiondescriptor.h"
 
43
#include "qcontactactiondescriptor_p.h"
 
44
#include "qcontactactionfactory.h"
 
45
#include "qcontact.h"
 
46
#include "qcontactinvalidfilter.h"
 
47
 
 
48
#include <QHash>
 
49
 
 
50
/*
 
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".
 
55
 
 
56
    Fall back to the less-performant QLatin1String in this case.
 
57
*/
 
58
#if defined(QStringLiteral) && defined(QT_UNICODE_LITERAL_II) && defined(Q_CC_GNU) && !defined(Q_COMPILER_LAMBDA)
 
59
# undef QStringLiteral
 
60
# define QStringLiteral QLatin1String
 
61
#endif
 
62
 
 
63
QT_BEGIN_NAMESPACE_CONTACTS
 
64
 
 
65
/*!
 
66
  \class QContactActionDescriptor
 
67
  \brief The QContactActionDescriptor class provides information that
 
68
  uniquely identifies a specific implementation of an action
 
69
  \ingroup contacts-actions
 
70
  \inmodule QtContacts
 
71
*/
 
72
 
 
73
/*!
 
74
 * Constructs a new, invalid action descriptor
 
75
 */
 
76
QContactActionDescriptor::QContactActionDescriptor()
 
77
        : d(new QContactActionDescriptorPrivate())
 
78
{
 
79
}
 
80
 
 
81
/*!
 
82
 * Constructs a copy of the \a other action descriptor
 
83
 */
 
84
QContactActionDescriptor::QContactActionDescriptor(const QContactActionDescriptor& other)
 
85
        : d(other.d)
 
86
{
 
87
}
 
88
 
 
89
/*!
 
90
 * Assigns this action descriptor to be equal to \a other
 
91
 */
 
92
QContactActionDescriptor& QContactActionDescriptor::operator=(const QContactActionDescriptor& other)
 
93
{
 
94
    d = other.d;
 
95
    return *this;
 
96
}
 
97
 
 
98
/*!
 
99
 * Cleans up any memory in use by the action descriptor
 
100
 */
 
101
QContactActionDescriptor::~QContactActionDescriptor()
 
102
{
 
103
}
 
104
 
 
105
/*!
 
106
 * Returns the name of the action which is identified by the action descriptor
 
107
 */
 
108
QString QContactActionDescriptor::actionName() const
 
109
{
 
110
    return d.constData()->m_actionName;
 
111
}
 
112
 
 
113
 
 
114
/*!
 
115
 * Returns the name of the service of the action implementation which is identified by the action descriptor
 
116
 */
 
117
QString QContactActionDescriptor::serviceName() const
 
118
{
 
119
    return d.constData()->m_serviceName;
 
120
}
 
121
 
 
122
/*!
 
123
 * Returns the identifier of the action, within the service.
 
124
 */
 
125
QString QContactActionDescriptor::actionIdentifier() const
 
126
{
 
127
    return d.constData()->m_identifier;
 
128
}
 
129
 
 
130
/*!
 
131
  Returns the service-specified version of the action implementation which is identified by the action descriptor
 
132
 */
 
133
int QContactActionDescriptor::implementationVersion() const
 
134
{
 
135
    return d.constData()->m_implementationVersion;
 
136
}
 
137
 
 
138
/*!
 
139
  Returns the set of action targets which are supported by this action for the given contact \a contact
 
140
 */
 
141
QSet<QContactActionTarget> QContactActionDescriptor::supportedTargets(const QContact& contact) const
 
142
{
 
143
    if (d.constData()->m_factory) {
 
144
        return d.constData()->m_factory->supportedTargets(contact, *this);
 
145
    }
 
146
 
 
147
    return QSet<QContactActionTarget>();
 
148
}
 
149
 
 
150
/*!
 
151
  Returns a filter which will match contacts for which this action has at least one supported action target
 
152
 */
 
153
QContactFilter QContactActionDescriptor::contactFilter() const
 
154
{
 
155
    if (d.constData()->m_factory) {
 
156
        return d.constData()->m_factory->contactFilter(*this);
 
157
    }
 
158
 
 
159
    return QContactInvalidFilter();
 
160
}
 
161
 
 
162
 
 
163
/*!
 
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
 
167
   action.
 
168
   \sa metaData()
 
169
 */
 
170
const QString QContactActionDescriptor::MetaDataIcon(QStringLiteral("Icon"));
 
171
 
 
172
/*!
 
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.
 
176
   \sa metaData()
 
177
 */
 
178
const QString QContactActionDescriptor::MetaDataLabel(QStringLiteral("Label"));
 
179
 
 
180
/*!
 
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
 
184
   action.
 
185
   \sa metaData()
 
186
 */
 
187
const QString QContactActionDescriptor::MetaDataSecondLabel(QStringLiteral("SecondLabel"));
 
188
 
 
189
/*!
 
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.
 
194
 
 
195
   An example of an optional parameter might be an "attachment"
 
196
   parameter to a "send email" action.
 
197
 
 
198
   \sa metaData()
 
199
 */
 
200
const QString QContactActionDescriptor::MetaDataOptionalParameterKeys(QStringLiteral("OptionalParameterKeys"));
 
201
 
 
202
/*!
 
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.
 
207
 
 
208
   An example of a mandatory parameter might be a "recipient"
 
209
   parameter to a "send email" action.
 
210
 
 
211
   \sa metaData()
 
212
 */
 
213
const QString QContactActionDescriptor::MetaDataMandatoryParameterKeys(QStringLiteral("MandatoryParameterKeys"));
 
214
 
 
215
/*!
 
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.
 
217
 */
 
218
QVariant QContactActionDescriptor::metaData(const QString& key, const QList<QContactActionTarget>& targets, const QVariantMap& parameters) const
 
219
{
 
220
    if (d.constData()->m_factory) {
 
221
        return d.constData()->m_factory->metaData(key, targets, parameters, *this);
 
222
    }
 
223
 
 
224
    return QVariant();
 
225
}
 
226
 
 
227
/*!
 
228
  Returns the meta data for the given meta data key \a key with the given invocation parameters \a parameters.
 
229
 */
 
230
QVariant QContactActionDescriptor::metaData(const QString& key, const QVariantMap& parameters) const
 
231
{
 
232
    return metaData(key, QList<QContactActionTarget>(), parameters);
 
233
}
 
234
 
 
235
/*!
 
236
  Returns the meta data for the given meta data key \a key for the \a target, with the given invocation parameters \a parameters.
 
237
 */
 
238
QVariant QContactActionDescriptor::metaData(const QString& key, const QContactActionTarget& target, const QVariantMap& parameters) const
 
239
{
 
240
    return metaData(key, QList<QContactActionTarget>() << target, parameters);
 
241
}
 
242
 
 
243
/*!
 
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.
 
245
 */
 
246
QVariant QContactActionDescriptor::metaData(const QString& key, const QContact& contact, const QContactDetail& detail, const QVariantMap& parameters) const
 
247
{
 
248
    return metaData(key, QList<QContactActionTarget>() << QContactActionTarget(contact, detail), parameters);
 
249
}
 
250
 
 
251
/*!
 
252
  Returns true if the action which this descriptor describes supports at least one action target for the given \a contact
 
253
 */
 
254
bool QContactActionDescriptor::supportsContact(const QContact& contact) const
 
255
{
 
256
    if (d.constData()->m_factory) {
 
257
        return d.constData()->m_factory->supportsContact(contact, *this);
 
258
    }
 
259
 
 
260
    return false;
 
261
}
 
262
 
 
263
/*!
 
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.
 
267
 */
 
268
bool QContactActionDescriptor::isValid() const
 
269
{
 
270
    if (d.constData()->m_actionName.isEmpty())
 
271
        return false;
 
272
    if (d.constData()->m_serviceName.isEmpty())
 
273
        return false;
 
274
    if (d.constData()->m_identifier.isEmpty())
 
275
        return false;
 
276
    if (d.constData()->m_implementationVersion <= 0)
 
277
        return false;
 
278
    if (d.constData()->m_factory == 0)
 
279
        return false;
 
280
    return true;
 
281
}
 
282
 
 
283
/*!
 
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.
 
289
 */
 
290
bool QContactActionDescriptor::operator==(const QContactActionDescriptor& other) const
 
291
{
 
292
    return (d.constData()->m_factory == other.d.constData()->m_factory && d.constData()->m_identifier == other.d.constData()->m_identifier);
 
293
}
 
294
 
 
295
/*!
 
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
 
298
 */
 
299
bool QContactActionDescriptor::operator!=(const QContactActionDescriptor& other) const
 
300
{
 
301
    return !(*this == other);
 
302
}
 
303
 
 
304
/*! Returns the hash value for \a key. */
 
305
uint qHash(const QContactActionDescriptor& key)
 
306
{
 
307
    uint ret = 0;
 
308
 
 
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);
 
314
 
 
315
    return ret;
 
316
}
 
317
 
 
318
#ifndef QT_NO_DEBUG_STREAM
 
319
QDebug& operator<<(QDebug dbg, const QContactActionDescriptor& descriptor)
 
320
{
 
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
 
327
                  << ')';
 
328
    return dbg.maybeSpace();
 
329
}
 
330
#endif
 
331
 
 
332
QT_END_NAMESPACE_CONTACTS