|
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 |
|
18 #include "cntmessageaction.h" |
|
19 |
|
20 #include <xqservicerequest.h> |
|
21 #include <qcontactphonenumber.h> |
|
22 #include <qcontactfilters.h> |
|
23 |
|
24 //Action class |
|
25 CntMessageAction::CntMessageAction() : |
|
26 CntAction("message") |
|
27 { |
|
28 } |
|
29 |
|
30 CntMessageAction::~CntMessageAction() |
|
31 { |
|
32 } |
|
33 |
|
34 CntMessageAction* CntMessageAction::clone() const |
|
35 { |
|
36 return new CntMessageAction(); |
|
37 } |
|
38 |
|
39 bool CntMessageAction::isDetailSupported(const QContactDetail &detail, const QContact &/*contact*/) const |
|
40 { |
|
41 if (detail.definitionName() == QContactPhoneNumber::DefinitionName |
|
42 && !static_cast<QContactPhoneNumber>(detail).subTypes().isEmpty()) |
|
43 { |
|
44 return (static_cast<QContactPhoneNumber>(detail).subTypes().first() == QContactPhoneNumber::SubTypeMobile); |
|
45 } |
|
46 else |
|
47 { |
|
48 return false; |
|
49 } |
|
50 } |
|
51 |
|
52 QList<QContactDetail> CntMessageAction::supportedDetails(const QContact& contact) const |
|
53 { |
|
54 QList<QContactDetail> details = contact.details(QContactPhoneNumber::DefinitionName); |
|
55 QList<QContactDetail> supportedDetails; |
|
56 for (int i = 0; i < details.count(); i++) |
|
57 { |
|
58 if (!static_cast<QContactPhoneNumber>(details[i]).subTypes().isEmpty() |
|
59 && static_cast<QContactPhoneNumber>(details[i]).subTypes().first() == QContactPhoneNumber::SubTypeMobile) |
|
60 { |
|
61 supportedDetails.append(details[i]); |
|
62 } |
|
63 } |
|
64 return supportedDetails; |
|
65 } |
|
66 |
|
67 void CntMessageAction::performAction() |
|
68 { |
|
69 QList<QVariant> data; |
|
70 QVariant retValue; |
|
71 |
|
72 delete m_request; |
|
73 m_request = NULL; |
|
74 |
|
75 //QContactType == TypeGroup |
|
76 if (QContactType::TypeGroup == m_contact.type()) { |
|
77 QString interface("com.nokia.symbian.IMessageSend"); |
|
78 QString operation("send(QVariantMap,QString)"); |
|
79 m_request = m_AppManager.create(interface, operation, false); // not embedded |
|
80 if (m_request==NULL) { |
|
81 emitResult(GeneralError, retValue); |
|
82 return; |
|
83 } |
|
84 |
|
85 QVariantMap recipientMap; |
|
86 QVariant value = m_data.value("message"); |
|
87 if (value.canConvert<QVariantMap>()) { |
|
88 recipientMap = value.toMap(); |
|
89 } |
|
90 if (!recipientMap.isEmpty()) { |
|
91 data.append(recipientMap); //recipients |
|
92 data.append(QString()); //body text |
|
93 |
|
94 m_request->setArguments(data); |
|
95 m_request->send(retValue); |
|
96 emitResult(m_request->lastError(), retValue); |
|
97 } |
|
98 else { |
|
99 emitResult(GeneralError, retValue); |
|
100 } |
|
101 } |
|
102 //QContactType == TypeContact |
|
103 //detail exist use it |
|
104 else if (m_detail.definitionName() == QContactPhoneNumber::DefinitionName) { |
|
105 QString interface("com.nokia.symbian.IMessageSend"); |
|
106 QString operation("send(QString,qint32,QString)"); |
|
107 m_request = m_AppManager.create(interface, operation, false); // not embedded |
|
108 if (m_request==NULL) { |
|
109 emitResult(GeneralError, retValue); |
|
110 return; |
|
111 } |
|
112 |
|
113 const QContactPhoneNumber &phoneNumber = static_cast<const QContactPhoneNumber &>(m_detail); |
|
114 data << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel(); |
|
115 |
|
116 m_request->setArguments(data); |
|
117 m_request->send(retValue); |
|
118 emitResult(m_request->lastError(), retValue); |
|
119 } |
|
120 else { |
|
121 emitResult(GeneralError, retValue); |
|
122 } |
|
123 } |
|
124 |
|
125 |
|
126 |