|
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 "cntservicecontactfetchview.h" |
|
19 |
|
20 #include <cntservicescontact.h> |
|
21 #include <cntlistmodel.h> |
|
22 #include "cntserviceviewparams.h" |
|
23 |
|
24 #include <hbmenu.h> |
|
25 #include <hbview.h> |
|
26 #include <hblistview.h> |
|
27 #include <hbdocumentloader.h> |
|
28 #include <hbaction.h> |
|
29 #include "cntactionpopup.h" |
|
30 |
|
31 #include <QCoreApplication> |
|
32 |
|
33 CntServiceContactFetchView::CntServiceContactFetchView( CntAbstractServiceProvider& aServiceProvider ): |
|
34 CntBaseSelectionView(), |
|
35 mProvider( aServiceProvider ) |
|
36 { |
|
37 HbAction* cancel = static_cast<HbAction*>( mDocument->findObject( "cnt:cancel" ) ); |
|
38 mView->menu()->addAction( cancel ); |
|
39 connect(cancel, SIGNAL(triggered()), this, SLOT(cancelFetch()) ); |
|
40 connect( this, SIGNAL(viewClosed()), this, SLOT(closeFetchView()) ); |
|
41 connect( this, SIGNAL(viewOpened(CntAbstractViewManager*, const CntViewParameters)), this, SLOT(aboutToOpenView(CntAbstractViewManager*, const CntViewParameters)) ); |
|
42 } |
|
43 |
|
44 CntServiceContactFetchView::~CntServiceContactFetchView() |
|
45 { |
|
46 } |
|
47 |
|
48 |
|
49 void CntServiceContactFetchView::cancelFetch() |
|
50 { |
|
51 CntServicesContactList serviceList; |
|
52 QVariant variant; |
|
53 variant.setValue(serviceList); |
|
54 mProvider.CompleteServiceAndCloseApp(variant); |
|
55 } |
|
56 |
|
57 |
|
58 |
|
59 void CntServiceContactFetchView::closeFetchView() |
|
60 { |
|
61 QModelIndexList temp = mListView->selectionModel()->selection().indexes(); |
|
62 mIndex = 0; |
|
63 for(int i = 0; i < temp.count(); i++ ) |
|
64 { |
|
65 QContact contact = mListModel->contact(temp.at(i)); |
|
66 if (mAction == KCntActionCall) |
|
67 { |
|
68 serviceCallMessageAction(contact, KCntActionCall); |
|
69 } |
|
70 else if (mAction == KCntActionSms ) |
|
71 { |
|
72 serviceCallMessageAction(contact, "message"); |
|
73 } |
|
74 else if (mAction == KCntActionEmail) |
|
75 { |
|
76 serviceEmailAction(contact); |
|
77 } |
|
78 else |
|
79 { |
|
80 serviceAllAction(contact); |
|
81 } |
|
82 } |
|
83 showPreviousView(); |
|
84 } |
|
85 |
|
86 void CntServiceContactFetchView::serviceCallMessageAction(QContact& aContact, QString aAction) |
|
87 { |
|
88 CntServicesContact servicesContact; |
|
89 //get the phonenumber |
|
90 QList<QContactPhoneNumber> phonenumbers = aContact.details<QContactPhoneNumber>(); |
|
91 |
|
92 Q_ASSERT_X( phonenumbers.count() > 0, "serviceCallMessageAction", "Number count is zero"); |
|
93 |
|
94 QContactDetail detail = aContact.preferredDetail(aAction); |
|
95 if (!detail.isEmpty()) |
|
96 { |
|
97 //Set preferred detail for services |
|
98 QContactPhoneNumber number = detail; |
|
99 servicesContact.mDisplayName = aContact.displayLabel(); |
|
100 servicesContact.mPhoneNumber = number.number(); |
|
101 servicesContact.mEmailAddress = ""; |
|
102 servicesContact.mContactId = aContact.localId(); |
|
103 mServiceList.append(servicesContact); |
|
104 } |
|
105 else |
|
106 { |
|
107 // show popup for call numbers |
|
108 CntActionPopup *actionPopup = new CntActionPopup(&aContact); |
|
109 bool popup = actionPopup->showActionPopup(aAction); |
|
110 if(popup) |
|
111 { |
|
112 //if call numbers are present wait for signals |
|
113 mIndex++; |
|
114 connect( actionPopup, SIGNAL(executeContactAction(QContact&,QContactDetail, QString)), this, |
|
115 SLOT(popupContactAction(QContact&, QContactDetail, QString))); |
|
116 connect( actionPopup, SIGNAL(actionPopupCancelPressed()), this, |
|
117 SLOT(actionPopupCancelSlot())); |
|
118 } |
|
119 else |
|
120 { |
|
121 //else delete popup if no call number present |
|
122 delete actionPopup; |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 void CntServiceContactFetchView::serviceEmailAction(QContact& aContact) |
|
128 { |
|
129 CntServicesContact servicesContact; |
|
130 //get the email address |
|
131 QList<QContactEmailAddress> emailAddresses = aContact.details<QContactEmailAddress>(); |
|
132 |
|
133 Q_ASSERT_X( emailAddresses.count() > 0, "serviceEmailAction", "email address count is zero"); |
|
134 |
|
135 QContactDetail detail = aContact.preferredDetail("email"); |
|
136 if (!detail.isEmpty()) |
|
137 { |
|
138 //Set preferred detail for services |
|
139 QContactEmailAddress email = detail; |
|
140 servicesContact.mDisplayName = aContact.displayLabel(); |
|
141 servicesContact.mPhoneNumber = ""; |
|
142 servicesContact.mEmailAddress = email.emailAddress(); |
|
143 servicesContact.mContactId = aContact.localId(); |
|
144 mServiceList.append(servicesContact); |
|
145 |
|
146 } |
|
147 else |
|
148 { |
|
149 // show popup for email id's |
|
150 CntActionPopup *actionPopup = new CntActionPopup(&aContact); |
|
151 bool popup = actionPopup->showActionPopup("email"); |
|
152 if(popup) |
|
153 { |
|
154 //if email id's are present wait for signals |
|
155 mIndex++; |
|
156 connect( actionPopup, SIGNAL(executeContactAction(QContact&,QContactDetail, QString)), this, |
|
157 SLOT(popupContactAction(QContact&, QContactDetail, QString))); |
|
158 connect( actionPopup, SIGNAL(actionPopupCancelPressed()), this, |
|
159 SLOT(actionPopupCancelSlot())); |
|
160 } |
|
161 else |
|
162 { |
|
163 //else delete popup if no email present |
|
164 delete actionPopup; |
|
165 } |
|
166 } |
|
167 } |
|
168 |
|
169 void CntServiceContactFetchView::serviceAllAction(QContact& aContact) |
|
170 { |
|
171 CntServicesContact servicesContact; |
|
172 servicesContact.mDisplayName = aContact.displayLabel(); |
|
173 QContactDetail callDetail = aContact.preferredDetail("call"); |
|
174 //Check for preferredDetail from call |
|
175 // if not present check for preferredDetail for message |
|
176 // if not present pick first phone number |
|
177 if (!callDetail.isEmpty()) |
|
178 { |
|
179 QContactPhoneNumber number = callDetail; |
|
180 servicesContact.mPhoneNumber = number.number(); |
|
181 } |
|
182 else |
|
183 { |
|
184 QContactDetail smsDetail = aContact.preferredDetail("message"); |
|
185 if (!callDetail.isEmpty()) |
|
186 { |
|
187 QContactPhoneNumber number = smsDetail; |
|
188 servicesContact.mPhoneNumber = number.number(); |
|
189 } |
|
190 else |
|
191 { |
|
192 QList<QContactPhoneNumber> phonenumbers = aContact.details<QContactPhoneNumber>(); |
|
193 if(phonenumbers.count() > 0) |
|
194 { |
|
195 servicesContact.mPhoneNumber = phonenumbers.first().number(); |
|
196 } |
|
197 else |
|
198 { |
|
199 servicesContact.mPhoneNumber = ""; |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 QContactDetail emailDetail = aContact.preferredDetail("email"); |
|
205 if (!emailDetail.isEmpty()) |
|
206 { |
|
207 QContactEmailAddress email = emailDetail; |
|
208 servicesContact.mEmailAddress = email.emailAddress(); |
|
209 } |
|
210 else |
|
211 { |
|
212 //get first email address |
|
213 QList<QContactEmailAddress> emailAddresses = aContact.details<QContactEmailAddress>(); |
|
214 if(emailAddresses.count() > 0) |
|
215 { |
|
216 servicesContact.mEmailAddress = emailAddresses.first().emailAddress(); |
|
217 } |
|
218 else |
|
219 { |
|
220 servicesContact.mEmailAddress = ""; |
|
221 } |
|
222 } |
|
223 servicesContact.mContactId = aContact.localId(); |
|
224 mServiceList.append(servicesContact); |
|
225 } |
|
226 |
|
227 void CntServiceContactFetchView::aboutToOpenView(CntAbstractViewManager* aMgr, const CntViewParameters aArgs) |
|
228 { |
|
229 mMgr = aMgr; |
|
230 |
|
231 // Set title of the view. |
|
232 QString title = aArgs.value(KCntServiceViewParamTitle).toString(); |
|
233 mView->setTitle(title); |
|
234 |
|
235 // Set action filter |
|
236 mAction = aArgs.value(ESelectedAction).toString(); |
|
237 // ESelectedAction is defined in cntviewparams.h |
|
238 |
|
239 // Has never been implemented. |
|
240 //QString filterStr = aArgs.value(KCntServiceViewParamFilter).toString(); |
|
241 // KCntServiceViewParamFilter is defined in cntserviceviewparams.h |
|
242 |
|
243 if (mAction == KCntActionSms) |
|
244 { |
|
245 QContactActionFilter actionFilter; |
|
246 actionFilter.setActionName("message"); |
|
247 mListModel->setFilter(actionFilter); |
|
248 } |
|
249 else if (mAction == KCntActionCall) |
|
250 { |
|
251 QContactActionFilter actionFilter; |
|
252 actionFilter.setActionName("call"); |
|
253 mListModel->setFilter(actionFilter); |
|
254 } |
|
255 else if (mAction == KCntActionEmail) |
|
256 { |
|
257 QContactActionFilter actionFilter; |
|
258 actionFilter.setActionName("email"); |
|
259 mListModel->setFilter(actionFilter); |
|
260 } |
|
261 else |
|
262 { |
|
263 QContactDetailFilter filter; |
|
264 filter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType); |
|
265 QString typeContact = QContactType::TypeContact; |
|
266 filter.setValue(typeContact); |
|
267 mListModel->setFilter(filter); |
|
268 } |
|
269 |
|
270 // hide my card if it's not set |
|
271 if ( mListModel->myCardId() == 0 ) |
|
272 { |
|
273 mListModel->showMyCard( false ); |
|
274 } |
|
275 } |
|
276 |
|
277 void CntServiceContactFetchView::popupContactAction(QContact& aContact,QContactDetail contactDetail, QString aAction) |
|
278 { |
|
279 if (aAction.compare("call", Qt::CaseInsensitive) == 0 |
|
280 || aAction.compare("message", Qt::CaseInsensitive) == 0 ) |
|
281 { |
|
282 CntServicesContact servicesContact; |
|
283 QContactPhoneNumber number = static_cast<QContactPhoneNumber>(contactDetail); |
|
284 QString name = aContact.displayLabel(); |
|
285 servicesContact.mDisplayName = aContact.displayLabel(); |
|
286 servicesContact.mPhoneNumber = number.number(); |
|
287 servicesContact.mEmailAddress = ""; |
|
288 servicesContact.mContactId = aContact.localId(); |
|
289 mServiceList.append(servicesContact); |
|
290 mIndex--; |
|
291 } |
|
292 else if (aAction.compare("email", Qt::CaseInsensitive) == 0 ) |
|
293 { |
|
294 CntServicesContact servicesContact; |
|
295 QContactEmailAddress email = static_cast<QContactEmailAddress>(contactDetail); |
|
296 servicesContact.mDisplayName = aContact.displayLabel(); |
|
297 servicesContact.mPhoneNumber = ""; |
|
298 servicesContact.mEmailAddress = email.emailAddress(); |
|
299 servicesContact.mContactId = aContact.localId(); |
|
300 mServiceList.append(servicesContact); |
|
301 mIndex--; |
|
302 } |
|
303 |
|
304 if (aContact.preferredDetail(aAction).isEmpty() && (aAction == "call" || aAction == "message" || aAction == "email")) |
|
305 { |
|
306 aContact.setPreferredDetail(aAction, contactDetail); |
|
307 //return value will be ignored because we cannot do anything if it fails. |
|
308 mEngine->contactManager(SYMBIAN_BACKEND).saveContact(&aContact); |
|
309 } |
|
310 |
|
311 showPreviousView(); |
|
312 } |
|
313 |
|
314 void CntServiceContactFetchView::actionPopupCancelSlot() |
|
315 { |
|
316 mIndex--; |
|
317 showPreviousView(); |
|
318 } |
|
319 |
|
320 void CntServiceContactFetchView::showPreviousView() |
|
321 { |
|
322 if(mIndex==0) |
|
323 { |
|
324 QVariant variant; |
|
325 variant.setValue(mServiceList); |
|
326 mProvider.CompleteServiceAndCloseApp(variant); |
|
327 |
|
328 CntViewParameters args; |
|
329 mMgr->back( args ); |
|
330 } |
|
331 } |
|
332 // EOF |