19 #include "cntthumbnailmanager.h" |
19 #include "cntthumbnailmanager.h" |
20 #include "cntimageutility.h" |
20 #include "cntimageutility.h" |
21 #include "cntsavemanager.h" |
21 #include "cntsavemanager.h" |
22 #include "cntimagelabel.h" |
22 #include "cntimagelabel.h" |
23 |
23 |
24 #include <hblabel.h> |
|
25 #include <xqaiwrequest.h> |
|
26 #include <xqaiwdecl.h> |
|
27 |
|
28 #include "cntdebug.h" |
24 #include "cntdebug.h" |
29 #include "cntglobal.h" |
25 #include "cntglobal.h" |
30 |
26 |
31 #include <hbaction.h> |
27 #include <hbaction.h> |
32 #include <hbview.h> |
28 #include <hbview.h> |
35 #include <hblistviewitem.h> |
31 #include <hblistviewitem.h> |
36 #include <hbframebackground.h> |
32 #include <hbframebackground.h> |
37 #include <hbdevicenotificationdialog.h> |
33 #include <hbdevicenotificationdialog.h> |
38 #include <hbparameterlengthlimiter.h> |
34 #include <hbparameterlengthlimiter.h> |
39 |
35 |
|
36 #include <xqaiwrequest.h> |
|
37 #include <xqaiwdecl.h> |
|
38 |
40 #include <QStandardItemModel> |
39 #include <QStandardItemModel> |
41 #include <QApplication> |
40 #include <QApplication> |
42 |
41 |
43 const char *CNT_IMAGE_XML = ":/xml/contacts_if.docml"; |
42 const char *CNT_IMAGE_XML = ":/xml/contacts_if.docml"; |
44 |
43 |
134 if ( mArgs.contains(ESelectedGroupContact) && !mContact ) |
125 if ( mArgs.contains(ESelectedGroupContact) && !mContact ) |
135 { |
126 { |
136 mContact = new QContact(mArgs.value(ESelectedGroupContact).value<QContact>()); |
127 mContact = new QContact(mArgs.value(ESelectedGroupContact).value<QContact>()); |
137 } |
128 } |
138 |
129 |
139 QString myCard = mArgs.value( EMyCard ).toString(); |
|
140 QContactLocalId localId = mContact->localId(); |
|
141 QContactLocalId selfContactId = mEngine->contactManager(SYMBIAN_BACKEND).selfContactId(); |
|
142 bool isMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty(); |
|
143 |
|
144 if (isMyCard) |
|
145 { |
|
146 mSaveManager = new CntSaveManager(CntSaveManager::EMyCard); |
|
147 } |
|
148 else if (mContact->type() == QContactType::TypeGroup) |
|
149 { |
|
150 mSaveManager = new CntSaveManager(CntSaveManager::EGroup); |
|
151 } |
|
152 else |
|
153 { |
|
154 mSaveManager = new CntSaveManager(); |
|
155 } |
|
156 |
|
157 // set the correct image if the contact already has an image set |
130 // set the correct image if the contact already has an image set |
158 mImageLabel = static_cast<CntImageLabel*>(mDocumentLoader.findWidget(QString("cnt_image_label"))); |
131 mImageLabel = static_cast<CntImageLabel*>(mDocumentLoader.findWidget(QString("cnt_image_label"))); |
159 mImageLabel->ungrabGesture(Qt::TapGesture); |
132 mImageLabel->ungrabGesture(Qt::TapGesture); |
160 QList<QContactAvatar> details = mContact->details<QContactAvatar>(); |
133 QList<QContactAvatar> details = mContact->details<QContactAvatar>(); |
161 if (details.count() > 0) |
134 if (details.count() > 0) |
162 { |
135 { |
163 for (int i = 0;i < details.count();i++) |
136 for (int i = 0;i < details.count();i++) |
|
137 { |
|
138 if (details.at(i).imageUrl().isValid()) |
164 { |
139 { |
165 if (details.at(i).imageUrl().isValid()) |
140 mAvatar = new QContactAvatar(details.at(i)); |
166 { |
141 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString()); |
167 mAvatar = new QContactAvatar(details.at(i)); |
142 break; |
168 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString()); |
|
169 break; |
|
170 } |
|
171 } |
143 } |
172 } |
144 } |
|
145 } |
173 else |
146 else |
174 { |
147 { |
175 mAvatar = new QContactAvatar(); |
148 mAvatar = new QContactAvatar(); |
176 mRemoveImage->setEnabled(false); |
149 mRemoveImage->setEnabled(false); |
177 if (mContact->type() == QContactType::TypeGroup) |
150 if (mContact->type() == QContactType::TypeGroup) |
178 { |
151 { |
179 mImageLabel->setAvatarIcon(HbIcon("qtg_large_add_group_picture")); |
152 mImageLabel->setAvatarIcon(HbIcon("qtg_large_add_group_picture")); |
180 } |
153 } |
181 } |
154 } |
182 |
155 |
183 // set up the list |
156 // set up the list |
184 mListView = static_cast<HbListView*>(mDocumentLoader.findWidget(QString("cnt_listview"))); |
157 mListView = static_cast<HbListView*>(mDocumentLoader.findWidget(QString("cnt_listview"))); |
185 |
158 |
186 connect(mListView, SIGNAL(activated(const QModelIndex&)), this, |
159 connect(mListView, SIGNAL(activated(const QModelIndex&)), this, |
202 void CntImageEditorView::deactivate() |
175 void CntImageEditorView::deactivate() |
203 { |
176 { |
204 |
177 |
205 } |
178 } |
206 |
179 |
|
180 /*! |
|
181 Populate the list model |
|
182 */ |
207 void CntImageEditorView::populateModel(QStandardItemModel *model) |
183 void CntImageEditorView::populateModel(QStandardItemModel *model) |
208 { |
184 { |
209 QStandardItem *newPhoto = new QStandardItem(); |
185 QStandardItem *newPhoto = new QStandardItem(); |
210 newPhoto->setText(hbTrId("txt_phob_list_take_a_new_photo")); |
186 newPhoto->setText(hbTrId("txt_phob_list_take_a_new_photo")); |
211 newPhoto->setData(HbIcon("qtg_large_camera"), Qt::DecorationRole); |
187 newPhoto->setData(HbIcon("qtg_large_camera"), Qt::DecorationRole); |
245 // Set function parameters |
222 // Set function parameters |
246 QList<QVariant> args; |
223 QList<QVariant> args; |
247 args << mode; |
224 args << mode; |
248 args << map; |
225 args << map; |
249 mRequest->setArguments(args); |
226 mRequest->setArguments(args); |
|
227 mRequest->setSynchronous(false); // this must be an Asynchronus request, If symchronous it crashes |
250 |
228 |
251 connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleImageChange(const QVariant&))); |
229 connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleImageChange(const QVariant&))); |
252 connect(mRequest, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&))); |
230 |
253 |
|
254 mRequest->send(); |
231 mRequest->send(); |
255 } |
232 } |
256 |
233 |
257 CNT_EXIT |
234 CNT_EXIT |
258 } |
235 } |
305 |
283 |
306 mArgs.insert(ECustomParam, viewId()); |
284 mArgs.insert(ECustomParam, viewId()); |
307 mViewManager->back( mArgs ); |
285 mViewManager->back( mArgs ); |
308 } |
286 } |
309 |
287 |
|
288 /*! |
|
289 Called when user selects to remove the image |
|
290 */ |
310 void CntImageEditorView::removeImage() |
291 void CntImageEditorView::removeImage() |
311 { |
292 { |
312 QString filePath=mAvatar->imageUrl().toString(); |
293 QString filePath = mAvatar->imageUrl().toString(); |
313 if(!filePath.isEmpty()) |
294 if(!filePath.isEmpty()) |
314 { |
295 { |
315 // Check if image removable. |
296 // Check if image removable. |
316 CntImageUtility imageUtility; |
297 CntImageUtility imageUtility; |
317 if(imageUtility.isImageRemovable(filePath)) |
298 if(imageUtility.isImageRemovable(filePath)) |
423 break; |
410 break; |
424 } |
411 } |
425 } |
412 } |
426 } |
413 } |
427 |
414 |
428 void CntImageEditorView::handleError(int errorCode, const QString& errorMessage) |
415 /*! |
429 { |
416 Saves the whole contact, called when user exits phonebook (via task switcher or end key) |
430 Q_UNUSED(errorCode); |
417 */ |
431 Q_UNUSED(errorMessage); |
|
432 CNT_LOG_ARGS("error code = " << errorCode << "errorMessage=" << errorMessage) |
|
433 } |
|
434 |
|
435 void CntImageEditorView::saveContact() |
418 void CntImageEditorView::saveContact() |
436 { |
419 { |
437 mContact->saveDetail(mAvatar); |
420 mContact->saveDetail(mAvatar); |
438 |
421 |
439 if ( mAvatar->imageUrl().isEmpty()) |
422 if ( mAvatar->imageUrl().isEmpty()) |
440 { |
423 { |
441 mContact->removeDetail(mAvatar); |
424 mContact->removeDetail(mAvatar); |
442 } |
425 } |
443 |
426 |
444 QString name = mEngine->contactManager(SYMBIAN_BACKEND).synthesizedContactDisplayLabel(*mContact); |
427 QContactManager& mgr = mEngine->contactManager( SYMBIAN_BACKEND ); |
|
428 QString name = mgr.synthesizedContactDisplayLabel(*mContact); |
445 |
429 |
446 if (name.isEmpty()) |
430 if (name.isEmpty()) |
447 { |
431 { |
448 name = hbTrId("txt_phob_list_unnamed"); |
432 name = hbTrId("txt_phob_list_unnamed"); |
449 } |
433 } |
450 |
434 |
451 CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, &mEngine->contactManager(SYMBIAN_BACKEND)); |
435 QString myCard = mArgs.value( EMyCard ).toString(); |
452 |
436 QContactLocalId localId = mContact->localId(); |
|
437 QContactLocalId selfContactId = mgr.selfContactId(); |
|
438 bool isMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty(); |
|
439 |
|
440 CntSaveManager::CntSaveResult result; |
|
441 CntSaveManager& save = mEngine->saveManager(); |
|
442 |
|
443 if (isMyCard) |
|
444 { |
|
445 result = save.saveMyCard( mContact, &mgr ); |
|
446 } |
|
447 else if (mContact->type() == QContactType::TypeGroup) |
|
448 { |
|
449 result = save.saveGroup( mContact, &mgr ); |
|
450 } |
|
451 else |
|
452 { |
|
453 result = save.saveContact( mContact, &mgr ); |
|
454 } |
|
455 |
453 if (mContact->type() != QContactType::TypeGroup) |
456 if (mContact->type() != QContactType::TypeGroup) |
454 { |
457 { |
455 switch (result) |
458 switch (result) |
456 { |
459 { |
457 case CntSaveManager::ESaved: |
460 case CntSaveManager::ESaved: |
458 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name)); |
461 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter("txt_phob_dpophead_contact_1_saved").arg(name)); |
459 break; |
462 break; |
460 case CntSaveManager::EUpdated: |
463 case CntSaveManager::EUpdated: |
461 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contacts_1_updated")).arg(name)); |
464 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter("txt_phob_dpophead_contacts_1_updated").arg(name)); |
462 break; |
465 break; |
463 case CntSaveManager::EFailed: |
466 case CntSaveManager::EFailed: |
464 HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!")); |
467 HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!")); |
465 break; |
468 break; |
466 case CntSaveManager::EDeleted: |
469 case CntSaveManager::EDeleted: |