72
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include "cntactionlauncher.h"
|
|
18 |
|
|
19 |
/*!
|
|
20 |
Action launcher. Caller should delete the instance.
|
|
21 |
*/
|
81
|
22 |
CntActionLauncher::CntActionLauncher( QContactManager& aContactManager, QString aAction ) :
|
|
23 |
QObject(),
|
|
24 |
mAction( aAction ),
|
|
25 |
mContactAction( NULL ),
|
|
26 |
mContactManager( &aContactManager )
|
|
27 |
{
|
|
28 |
|
|
29 |
}
|
|
30 |
|
|
31 |
CntActionLauncher::~CntActionLauncher()
|
|
32 |
{
|
|
33 |
delete mContactAction;
|
|
34 |
}
|
|
35 |
|
|
36 |
bool CntActionLauncher::execute( QContact aContact, QContactDetail aDetail )
|
|
37 |
{
|
|
38 |
bool executed = false;
|
|
39 |
QList<QContactActionDescriptor> all = QContactAction::actionDescriptors(mAction, "symbian");
|
|
40 |
if ( all.count() )
|
72
|
41 |
{
|
81
|
42 |
mContactAction = QContactAction::action( all.first() );
|
|
43 |
|
|
44 |
if (mContactAction)
|
|
45 |
{
|
|
46 |
if (aContact.preferredDetail(mAction).isEmpty() && (mAction == "call"))
|
|
47 |
{
|
|
48 |
aContact.setPreferredDetail(mAction, aDetail);
|
|
49 |
//return value will be ignored because we cannot do anything if it fails.
|
|
50 |
mContactManager->saveContact(&aContact);
|
|
51 |
}
|
|
52 |
|
|
53 |
connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
|
|
54 |
this, SLOT(progress(QContactAction::State)));
|
|
55 |
executed = mContactAction->invokeAction( aContact, aDetail );
|
|
56 |
}
|
|
57 |
else
|
|
58 |
{
|
|
59 |
progress(QContactAction::FinishedWithErrorState);
|
|
60 |
}
|
|
61 |
}
|
|
62 |
else
|
|
63 |
{
|
|
64 |
progress(QContactAction::FinishedWithErrorState);
|
72
|
65 |
}
|
|
66 |
|
81
|
67 |
return executed;
|
|
68 |
}
|
|
69 |
|
|
70 |
bool CntActionLauncher::execute( QContact aGrpContact, QContactDetail aDetail, QVariantMap aParameters )
|
|
71 |
{
|
72
|
72 |
bool executed = false;
|
|
73 |
QList<QContactActionDescriptor> all = QContactAction::actionDescriptors(mAction, "symbian");
|
|
74 |
mContactAction = QContactAction::action( all.first() );
|
|
75 |
if ( mContactAction )
|
|
76 |
{
|
|
77 |
connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
|
|
78 |
this, SLOT(progress(QContactAction::State)));
|
|
79 |
executed = mContactAction->invokeAction( aGrpContact, aDetail, aParameters );
|
81
|
80 |
}
|
72
|
81 |
else
|
81
|
82 |
{
|
72
|
83 |
progress(QContactAction::FinishedWithErrorState);
|
81
|
84 |
}
|
|
85 |
|
72
|
86 |
return executed;
|
81
|
87 |
}
|
|
88 |
|
72
|
89 |
/*!
|
|
90 |
Launch dynamic action
|
|
91 |
*/
|
|
92 |
bool CntActionLauncher::execute( QContact aContact, QContactDetail aDetail, QContactActionDescriptor aActionDescriptor )
|
|
93 |
{
|
|
94 |
bool executed = false;
|
|
95 |
// detail might be empty -> in that case engine uses the preferred detail for the selected action
|
|
96 |
mContactAction = QContactAction::action( aActionDescriptor );
|
|
97 |
if ( mContactAction )
|
|
98 |
{
|
|
99 |
connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
|
|
100 |
this, SLOT(progress(QContactAction::State)));
|
|
101 |
executed = mContactAction->invokeAction( aContact, aDetail );
|
|
102 |
}
|
|
103 |
else
|
|
104 |
{
|
|
105 |
progress(QContactAction::FinishedWithErrorState);
|
|
106 |
}
|
|
107 |
return executed;
|
|
108 |
}
|
|
109 |
|
|
110 |
void CntActionLauncher::progress( QContactAction::State status )
|
81
|
111 |
{
|
72
|
112 |
switch(status)
|
81
|
113 |
{
|
|
114 |
case QContactAction::FinishedState:
|
|
115 |
case QContactAction::FinishedWithErrorState:
|
|
116 |
emit actionExecuted( this );
|
|
117 |
break;
|
|
118 |
default:
|
|
119 |
break;
|
72
|
120 |
}
|
81
|
121 |
}
|
72
|
122 |
|
|
123 |
// End of File
|