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 Qt Mobility Components.
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
#ifndef ACTIONFACTORYPLUGINTARGET
43
#define ACTIONFACTORYPLUGINTARGET contacts_multiactionfactory
45
#ifndef ACTIONFACTORYPLUGINNAME
46
#define ACTIONFACTORYPLUGINNAME MultiActionFactory
49
#include "multiaction_p.h"
51
#include "qcontactphonenumber.h"
52
#include "qcontactemailaddress.h"
53
#include "qcontactfilters.h"
55
#include <QMessageBox>
58
//! [Example Contact Action Plugin Implementation]
60
QObject* QContactMultiActionPlugin::createInstance(const QServiceInterfaceDescriptor& descriptor,
61
QServiceContext* context,
62
QAbstractSecuritySession* session)
67
if (descriptor.interfaceName() == QContactActionFactory::InterfaceName
68
&& descriptor.serviceName() == QString(QLatin1String("tst_qcontactactions:multiaction"))
69
&& descriptor.majorVersion() == 1
70
&& descriptor.minorVersion() == 1
71
&& descriptor.customAttribute("ActionName") == QString(QLatin1String("call"))) {
72
return new QContactMultiActionFactory;
78
Q_EXPORT_PLUGIN2(contacts_multiaction, QContactMultiActionPlugin);
81
QContactMultiActionFactory::QContactMultiActionFactory()
82
: QContactActionFactory()
84
m_actionOneDescriptor = createDescriptor("call", "tst_qcontactactions:multiaction", "sip", 1);
85
m_actionTwoDescriptor = createDescriptor("call", "tst_qcontactactions:multiaction", "prop", 1);
88
QContactMultiActionFactory::~QContactMultiActionFactory()
92
QList<QContactActionDescriptor> QContactMultiActionFactory::actionDescriptors() const
94
QList<QContactActionDescriptor> retn;
95
retn << m_actionOneDescriptor << m_actionTwoDescriptor;
99
QContactAction* QContactMultiActionFactory::create(const QContactActionDescriptor& which) const
101
if (which == m_actionOneDescriptor)
102
return new QContactActionOne;
103
else if (which == m_actionTwoDescriptor)
104
return new QContactActionTwo;
109
QSet<QContactActionTarget> QContactMultiActionFactory::supportedTargets(const QContact& contact, const QContactActionDescriptor& which) const
111
QSet<QContactActionTarget> retn;
112
if (which == m_actionOneDescriptor || which == m_actionTwoDescriptor) {
113
// in this example, they support the same targets.
114
QList<QContactPhoneNumber> pndets = contact.details<QContactPhoneNumber>();
115
for (int i = 0; i < pndets.size(); ++i) {
116
QContactActionTarget curr;
117
curr.setContact(contact);
118
curr.setDetails(QList<QContactDetail>() << pndets.at(i));
126
QContactFilter QContactMultiActionFactory::contactFilter(const QContactActionDescriptor& which) const
128
if (which == m_actionOneDescriptor || which == m_actionTwoDescriptor) {
129
QContactDetailFilter retn;
130
retn.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber);
134
return QContactFilter();
137
QVariant QContactMultiActionFactory::metaData(const QString& key, const QList<QContactActionTarget>& targets, const QVariantMap& parameters, const QContactActionDescriptor& which) const
142
if (key == QContactActionDescriptor::MetaDataLabel)
143
return QString("Call with VoIP");
146
if (key == QLatin1String("Provider")) {// our custom metadata - just return which.actionIdentifier
147
return which.actionIdentifier();
153
bool QContactMultiActionFactory::supportsContact(const QContact& contact, const QContactActionDescriptor& which) const
155
if (which == m_actionOneDescriptor || which == m_actionTwoDescriptor)
156
return !contact.details<QContactPhoneNumber>().isEmpty();
161
QContactActionOne::QContactActionOne()
166
QContactActionOne::~QContactActionOne()
171
bool QContactActionOne::invokeAction(const QContactActionTarget& target, const QVariantMap& params)
174
// this action only works on (contact + phone number) targets.
175
if (target.details().size() > 1 || target.details().at(0).definitionName() != QContactPhoneNumber::DefinitionName)
178
QTimer::singleShot(1, this, SLOT(performAction()));
182
bool QContactActionOne::invokeAction(const QList<QContactActionTarget>& targets, const QVariantMap& params)
185
foreach (const QContactActionTarget& target, targets) {
186
if (target.details().size() > 1 || target.details().at(0).definitionName() != QContactPhoneNumber::DefinitionName) {
191
QTimer::singleShot(1, this, SLOT(performAction()));
195
QVariantMap QContactActionOne::results() const
197
return QVariantMap();
200
QContactAction::State QContactActionOne::state() const
202
return QContactAction::FinishedState;
205
void QContactActionOne::performAction()
207
QMessageBox::information(0, "ActionOne", "This is action one!");
208
emit stateChanged(QContactAction::FinishedState);
211
QContactActionTwo::QContactActionTwo()
216
QContactActionTwo::~QContactActionTwo()
221
bool QContactActionTwo::invokeAction(const QContactActionTarget& target, const QVariantMap& params)
224
// this action only works on (contact + phone number) targets. Note that it doesn't
225
// have to be the same as QContactActionOne -- it could have an entirely different implementation!
226
if (target.details().size() > 1 || target.details().at(0).definitionName() != QContactPhoneNumber::DefinitionName)
229
QTimer::singleShot(1, this, SLOT(performAction()));
233
bool QContactActionTwo::invokeAction(const QList<QContactActionTarget>& targets, const QVariantMap& params)
236
foreach (const QContactActionTarget& target, targets) {
237
if (target.details().size() > 1 || target.details().at(0).definitionName() != QContactPhoneNumber::DefinitionName) {
242
QTimer::singleShot(1, this, SLOT(performAction()));
246
QVariantMap QContactActionTwo::results() const
248
return QVariantMap();
251
QContactAction::State QContactActionTwo::state() const
253
return QContactAction::FinishedState;
256
void QContactActionTwo::performAction()
258
QMessageBox::information(0, "ActionTwo", "This is action two!");
259
emit stateChanged(QContactAction::FinishedState);
262
//! [Example Contact Action Plugin Implementation]