~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/auto/contacts/qcontactactions/multiaction/multiaction.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 Qt Mobility Components.
 
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
#ifndef ACTIONFACTORYPLUGINTARGET
 
43
#define ACTIONFACTORYPLUGINTARGET contacts_multiactionfactory
 
44
#endif
 
45
#ifndef ACTIONFACTORYPLUGINNAME
 
46
#define ACTIONFACTORYPLUGINNAME MultiActionFactory
 
47
#endif
 
48
 
 
49
#include "multiaction_p.h"
 
50
 
 
51
#include "qcontactphonenumber.h"
 
52
#include "qcontactemailaddress.h"
 
53
#include "qcontactfilters.h"
 
54
 
 
55
#include <QMessageBox>
 
56
#include <QTimer>
 
57
 
 
58
//! [Example Contact Action Plugin Implementation]
 
59
 
 
60
QObject* QContactMultiActionPlugin::createInstance(const QServiceInterfaceDescriptor& descriptor,
 
61
                        QServiceContext* context,
 
62
                        QAbstractSecuritySession* session)
 
63
{
 
64
    Q_UNUSED(context);
 
65
    Q_UNUSED(session);
 
66
 
 
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;
 
73
    } else {
 
74
        return 0;
 
75
    }
 
76
}
 
77
 
 
78
Q_EXPORT_PLUGIN2(contacts_multiaction, QContactMultiActionPlugin);
 
79
 
 
80
 
 
81
QContactMultiActionFactory::QContactMultiActionFactory()
 
82
    : QContactActionFactory()
 
83
{
 
84
    m_actionOneDescriptor = createDescriptor("call", "tst_qcontactactions:multiaction", "sip", 1);
 
85
    m_actionTwoDescriptor = createDescriptor("call", "tst_qcontactactions:multiaction", "prop", 1);
 
86
}
 
87
 
 
88
QContactMultiActionFactory::~QContactMultiActionFactory()
 
89
{
 
90
}
 
91
 
 
92
QList<QContactActionDescriptor> QContactMultiActionFactory::actionDescriptors() const
 
93
{
 
94
    QList<QContactActionDescriptor> retn;
 
95
    retn << m_actionOneDescriptor << m_actionTwoDescriptor;
 
96
    return retn;
 
97
}
 
98
 
 
99
QContactAction* QContactMultiActionFactory::create(const QContactActionDescriptor& which) const
 
100
{
 
101
    if (which == m_actionOneDescriptor)
 
102
        return new QContactActionOne;
 
103
    else if (which == m_actionTwoDescriptor)
 
104
        return new QContactActionTwo;
 
105
    else
 
106
        return 0;
 
107
}
 
108
 
 
109
QSet<QContactActionTarget> QContactMultiActionFactory::supportedTargets(const QContact& contact, const QContactActionDescriptor& which) const
 
110
{
 
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));
 
119
            retn << curr;
 
120
        }
 
121
    }
 
122
 
 
123
    return retn;
 
124
}
 
125
 
 
126
QContactFilter QContactMultiActionFactory::contactFilter(const QContactActionDescriptor& which) const
 
127
{
 
128
    if (which == m_actionOneDescriptor || which == m_actionTwoDescriptor) {
 
129
        QContactDetailFilter retn;
 
130
        retn.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber);
 
131
        return retn;
 
132
    }
 
133
 
 
134
    return QContactFilter();
 
135
}
 
136
 
 
137
QVariant QContactMultiActionFactory::metaData(const QString& key, const QList<QContactActionTarget>& targets, const QVariantMap& parameters, const QContactActionDescriptor& which) const
 
138
{
 
139
    Q_UNUSED(targets)
 
140
    Q_UNUSED(parameters)
 
141
 
 
142
    if (key == QContactActionDescriptor::MetaDataLabel)
 
143
        return QString("Call with VoIP");
 
144
    // Label etc
 
145
 
 
146
    if (key == QLatin1String("Provider")) {// our custom metadata - just return which.actionIdentifier
 
147
        return which.actionIdentifier();
 
148
    }
 
149
 
 
150
    return QVariant();
 
151
}
 
152
 
 
153
bool QContactMultiActionFactory::supportsContact(const QContact& contact, const QContactActionDescriptor& which) const
 
154
{
 
155
    if (which == m_actionOneDescriptor || which == m_actionTwoDescriptor)
 
156
        return !contact.details<QContactPhoneNumber>().isEmpty();
 
157
    return false;
 
158
}
 
159
 
 
160
 
 
161
QContactActionOne::QContactActionOne()
 
162
{
 
163
 
 
164
}
 
165
 
 
166
QContactActionOne::~QContactActionOne()
 
167
{
 
168
 
 
169
}
 
170
 
 
171
bool QContactActionOne::invokeAction(const QContactActionTarget& target, const QVariantMap& params)
 
172
{
 
173
    Q_UNUSED(params)
 
174
    // this action only works on (contact + phone number) targets.
 
175
    if (target.details().size() > 1 || target.details().at(0).definitionName() != QContactPhoneNumber::DefinitionName)
 
176
        return false;
 
177
 
 
178
    QTimer::singleShot(1, this, SLOT(performAction()));
 
179
    return true;
 
180
}
 
181
 
 
182
bool QContactActionOne::invokeAction(const QList<QContactActionTarget>& targets, const QVariantMap& params)
 
183
{
 
184
    Q_UNUSED(params)
 
185
    foreach (const QContactActionTarget& target, targets) {
 
186
        if (target.details().size() > 1 || target.details().at(0).definitionName() != QContactPhoneNumber::DefinitionName) {
 
187
            return false;
 
188
        }
 
189
    }
 
190
 
 
191
    QTimer::singleShot(1, this, SLOT(performAction()));
 
192
    return true;
 
193
}
 
194
 
 
195
QVariantMap QContactActionOne::results() const
 
196
{
 
197
    return QVariantMap();
 
198
}
 
199
 
 
200
QContactAction::State QContactActionOne::state() const
 
201
{
 
202
    return QContactAction::FinishedState;
 
203
}
 
204
 
 
205
void QContactActionOne::performAction()
 
206
{
 
207
    QMessageBox::information(0, "ActionOne", "This is action one!");
 
208
    emit stateChanged(QContactAction::FinishedState);
 
209
}
 
210
 
 
211
QContactActionTwo::QContactActionTwo()
 
212
{
 
213
 
 
214
}
 
215
 
 
216
QContactActionTwo::~QContactActionTwo()
 
217
{
 
218
 
 
219
}
 
220
 
 
221
bool QContactActionTwo::invokeAction(const QContactActionTarget& target, const QVariantMap& params)
 
222
{
 
223
    Q_UNUSED(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)
 
227
        return false;
 
228
 
 
229
    QTimer::singleShot(1, this, SLOT(performAction()));
 
230
    return true;
 
231
}
 
232
 
 
233
bool QContactActionTwo::invokeAction(const QList<QContactActionTarget>& targets, const QVariantMap& params)
 
234
{
 
235
    Q_UNUSED(params)
 
236
    foreach (const QContactActionTarget& target, targets) {
 
237
        if (target.details().size() > 1 || target.details().at(0).definitionName() != QContactPhoneNumber::DefinitionName) {
 
238
            return false;
 
239
        }
 
240
    }
 
241
 
 
242
    QTimer::singleShot(1, this, SLOT(performAction()));
 
243
    return true;
 
244
}
 
245
 
 
246
QVariantMap QContactActionTwo::results() const
 
247
{
 
248
    return QVariantMap();
 
249
}
 
250
 
 
251
QContactAction::State QContactActionTwo::state() const
 
252
{
 
253
    return QContactAction::FinishedState;
 
254
}
 
255
 
 
256
void QContactActionTwo::performAction()
 
257
{
 
258
    QMessageBox::information(0, "ActionTwo", "This is action two!");
 
259
    emit stateChanged(QContactAction::FinishedState);
 
260
}
 
261
 
 
262
//! [Example Contact Action Plugin Implementation]