48 #include <QFileInfo> |
48 #include <QFileInfo> |
49 #include <QApplication> |
49 #include <QApplication> |
50 #include <QTimer> |
50 #include <QTimer> |
51 |
51 |
52 const char *CNT_EDIT_XML = ":/xml/contacts_ev.docml"; |
52 const char *CNT_EDIT_XML = ":/xml/contacts_ev.docml"; |
|
53 const QString CNT_ACTIVITY_EDITOR = "ContactsCardEdit"; |
53 |
54 |
54 CntEditViewPrivate::CntEditViewPrivate() : |
55 CntEditViewPrivate::CntEditViewPrivate() : |
55 mModel( NULL ), |
56 mModel( NULL ), |
56 mImageLabel( NULL ), |
57 mImageLabel( NULL ), |
57 mThumbnailManager( NULL ), |
58 mThumbnailManager( NULL ), |
58 mContact( NULL ), |
59 mContact( NULL ), |
59 mReq(NULL), |
60 mReq(NULL), |
60 mMenu(NULL), |
61 mMenu(NULL) |
61 mSaveManager(NULL) |
|
62 { |
62 { |
63 mDocument = new CntDocumentLoader; |
63 mDocument = new CntDocumentLoader; |
64 |
64 |
65 bool ok; |
65 bool ok; |
66 mDocument->load( CNT_EDIT_XML, &ok ); |
66 mDocument->load( CNT_EDIT_XML, &ok ); |
95 add->setParent(mView); |
95 add->setParent(mView); |
96 |
96 |
97 connect( add, SIGNAL(triggered()), this, SLOT(addDetailItem()) ); |
97 connect( add, SIGNAL(triggered()), this, SLOT(addDetailItem()) ); |
98 connect( mDelete, SIGNAL(triggered()), this, SLOT(deleteContact()) ); |
98 connect( mDelete, SIGNAL(triggered()), this, SLOT(deleteContact()) ); |
99 connect( mDiscard, SIGNAL(triggered()), this, SLOT(discardChanges()) ); |
99 connect( mDiscard, SIGNAL(triggered()), this, SLOT(discardChanges()) ); |
100 connect( mSave, SIGNAL(triggered()), this, SLOT(saveChanges()) ); |
100 connect( mSave, SIGNAL(triggered()), this, SLOT(showPreviousView()) ); |
101 |
101 |
102 connect( mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()) ); |
102 connect( mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()) ); |
103 connect( mImageLabel, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
103 connect( mImageLabel, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
104 connect( mHeading, SIGNAL(textClicked()), this, SLOT(openNameEditor()) ); |
104 connect( mHeading, SIGNAL(textClicked()), this, SLOT(openNameEditor()) ); |
105 connect( mHeading, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
105 connect( mHeading, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) ); |
106 connect( mListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(activated(const QModelIndex&)) ); |
106 connect( mListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(activated(const QModelIndex&)) ); |
107 connect( mListView, SIGNAL(longPressed(HbAbstractViewItem*,const QPointF&)), this, SLOT(longPressed(HbAbstractViewItem*,const QPointF&)) ); |
107 connect( mListView, SIGNAL(longPressed(HbAbstractViewItem*,const QPointF&)), this, SLOT(longPressed(HbAbstractViewItem*,const QPointF&)) ); |
108 |
|
109 // closing the application from task swapper or end key will cause the contact to be saved |
|
110 connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(saveChanges())); |
|
111 } |
108 } |
112 |
109 |
113 CntEditViewPrivate::~CntEditViewPrivate() |
110 CntEditViewPrivate::~CntEditViewPrivate() |
114 { |
111 { |
115 mView->deleteLater(); |
112 mView->deleteLater(); |
157 } |
151 } |
158 HbMainWindow* window = mView->mainWindow(); |
152 HbMainWindow* window = mView->mainWindow(); |
159 if ( window ) |
153 if ( window ) |
160 { |
154 { |
161 connect(window, SIGNAL(viewReady()), this, SLOT(setScrollPosition()) ); |
155 connect(window, SIGNAL(viewReady()), this, SLOT(setScrollPosition()) ); |
|
156 connect(window, SIGNAL(viewReady()), this, SLOT(setObjectNames()) ); |
162 connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation))); |
157 connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation))); |
163 setOrientation(window->orientation()); |
158 setOrientation(window->orientation()); |
164 } |
159 } |
165 |
160 |
166 QString myCard = mArgs.value( EMyCard ).toString(); |
161 QString myCard = mArgs.value( EMyCard ).toString(); |
174 QContactLocalId localId = mContact->localId(); |
169 QContactLocalId localId = mContact->localId(); |
175 QContactManager& cm = mEngine->contactManager(SYMBIAN_BACKEND); |
170 QContactManager& cm = mEngine->contactManager(SYMBIAN_BACKEND); |
176 QContactLocalId selfContactId = cm.selfContactId(); |
171 QContactLocalId selfContactId = cm.selfContactId(); |
177 mIsMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty(); |
172 mIsMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty(); |
178 |
173 |
179 if (mIsMyCard) |
|
180 { |
|
181 mSaveManager = new CntSaveManager(CntSaveManager::EMyCard); |
|
182 } |
|
183 else |
|
184 { |
|
185 mSaveManager = new CntSaveManager(); |
|
186 } |
|
187 |
174 |
188 if ( mHeading ) |
175 if ( mHeading ) |
189 mHeading->setDetails( mContact, mIsMyCard ); |
176 mHeading->setDetails( mContact, mIsMyCard ); |
190 |
177 |
191 // if "MyCard", set slightly different heading and options menu |
178 // if "MyCard", set slightly different heading and options menu |
224 this, SLOT(thumbnailReady(QPixmap, void*, int, int)) ); |
211 this, SLOT(thumbnailReady(QPixmap, void*, int, int)) ); |
225 |
212 |
226 loadAvatar(); |
213 loadAvatar(); |
227 |
214 |
228 CNT_EXIT |
215 CNT_EXIT |
|
216 } |
|
217 |
|
218 QString CntEditViewPrivate::externalize(QDataStream &stream) |
|
219 { |
|
220 // closing the application from task swapper or end key will cause the contact to be saved |
|
221 saveChanges(); |
|
222 |
|
223 CntViewParameters viewParameters; |
|
224 viewParameters.insert(EViewId, mArgs.value(EViewId).toInt()); |
|
225 |
|
226 if (mArgs.value(ESelectedContact).isValid()) |
|
227 { |
|
228 QContact contact = mArgs.value(ESelectedContact).value<QContact>(); |
|
229 viewParameters.insert(ESelectedContactId, contact.localId()); |
|
230 } |
|
231 if (mArgs.value(ESelectedGroupContact).isValid()) |
|
232 { |
|
233 QContact contact = mArgs.value(ESelectedGroupContact).value<QContact>(); |
|
234 viewParameters.insert(ESelectedGroupContactId, contact.localId()); |
|
235 } |
|
236 if (mArgs.value(EMyCard).isValid()) |
|
237 { |
|
238 viewParameters.insert(EMyCard, mArgs.value(EMyCard)); |
|
239 } |
|
240 if (mArgs.value(EExtraAction).isValid()) |
|
241 { |
|
242 viewParameters.insert(EExtraAction, mArgs.value(EExtraAction)); |
|
243 } |
|
244 |
|
245 stream << viewParameters; |
|
246 |
|
247 return CNT_ACTIVITY_EDITOR; |
|
248 } |
|
249 |
|
250 bool CntEditViewPrivate::internalize(QDataStream &stream, CntViewParameters &viewParameters) |
|
251 { |
|
252 CntViewParameters tempViewParameters; |
|
253 stream >> tempViewParameters; |
|
254 |
|
255 viewParameters.insert(EViewId, tempViewParameters.value(EViewId)); |
|
256 |
|
257 if (tempViewParameters.value(ESelectedContactId).isValid()) |
|
258 { |
|
259 QContactManager &mgr = mEngine->contactManager(SYMBIAN_BACKEND); |
|
260 |
|
261 QContactLocalId localId = tempViewParameters.value(ESelectedContactId).toInt(); |
|
262 |
|
263 if (!mgr.contactIds().contains(localId) && localId != 0 && mgr.selfContactId() != localId) |
|
264 { |
|
265 // a contact has been deleted. |
|
266 return false; |
|
267 } |
|
268 else |
|
269 { |
|
270 QVariant var; |
|
271 var.setValue(mgr.contact(localId)); |
|
272 viewParameters.insert(ESelectedContact, var); |
|
273 } |
|
274 } |
|
275 if (tempViewParameters.value(ESelectedGroupContactId).isValid()) |
|
276 { |
|
277 QContactManager &mgr = mEngine->contactManager(SYMBIAN_BACKEND); |
|
278 QVariant var; |
|
279 var.setValue(mgr.contact(tempViewParameters.value(ESelectedGroupContactId).toInt())); |
|
280 viewParameters.insert(ESelectedGroupContact, var); |
|
281 } |
|
282 if (tempViewParameters.value(EMyCard).isValid()) |
|
283 { |
|
284 viewParameters.insert(EMyCard, tempViewParameters.value(EMyCard)); |
|
285 } |
|
286 if (tempViewParameters.value(EExtraAction).isValid()) |
|
287 { |
|
288 viewParameters.insert(EExtraAction, tempViewParameters.value(EExtraAction)); |
|
289 } |
|
290 |
|
291 return true; |
229 } |
292 } |
230 |
293 |
231 void CntEditViewPrivate::deactivate() |
294 void CntEditViewPrivate::deactivate() |
232 { |
295 { |
233 } |
296 } |
416 { |
479 { |
417 return; |
480 return; |
418 } |
481 } |
419 else |
482 else |
420 { |
483 { |
|
484 mReq->setSynchronous(false); |
421 connect(mReq, SIGNAL( requestOk( const QVariant&)), SLOT( ringToneFetchHandleOk(const QVariant&)) ); |
485 connect(mReq, SIGNAL( requestOk( const QVariant&)), SLOT( ringToneFetchHandleOk(const QVariant&)) ); |
422 connect(mReq, SIGNAL( requestError( int,const QString&)), SLOT(ringToneFetchHandleError(int,const QString&)) ); |
486 connect(mReq, SIGNAL( requestError( int,const QString&)), SLOT(ringToneFetchHandleError(int,const QString&)) ); |
423 } |
487 } |
424 |
488 |
425 // Make the request |
489 // Make the request |
426 mReq->send(); |
490 mReq->send(); |
427 } |
491 } |
428 |
492 |
429 void CntEditViewPrivate::ringToneFetchHandleOk(const QVariant &result) |
493 void CntEditViewPrivate::ringToneFetchHandleOk(const QVariant &result) |
430 { |
494 { |
431 |
|
432 QContactRingtone ringtone = mContact->detail<QContactRingtone>(); |
495 QContactRingtone ringtone = mContact->detail<QContactRingtone>(); |
433 QUrl ringtoneUrl = ringtone.audioRingtoneUrl(); |
496 // Contact can have only one ringtone at a time |
434 QFileInfo ringtoneFileInfo(ringtoneUrl.toString()); |
497 // remove existing ringtone detail if any |
435 QString ringtoneFileName = ringtoneFileInfo.fileName(); |
498 if(!(ringtone.isEmpty())) |
436 // Contact can have only one ringtone at a time |
499 { |
437 // remove existing ringtone detail if any |
500 mContact->removeDetail(&ringtone); |
|
501 } |
438 |
502 |
439 if(!(ringtone.isEmpty())) |
503 ringtone.setAudioRingtoneUrl( QUrl::fromLocalFile( result.value<QString>() ) ); |
440 { |
|
441 mContact->removeDetail(&ringtone); |
|
442 } |
|
443 |
|
444 ringtone.setAudioRingtoneUrl(result.value<QString>()); |
|
445 mContact->saveDetail( &ringtone ); |
504 mContact->saveDetail( &ringtone ); |
446 mModel->updateRingtone(); |
505 mModel->updateRingtone(); |
447 mSave->setEnabled( true ); |
506 mSave->setEnabled( true ); |
448 mDiscard->setEnabled( true ); |
507 mDiscard->setEnabled( true ); |
449 |
|
450 } |
508 } |
451 |
509 |
452 void CntEditViewPrivate::ringToneFetchHandleError(int errorCode, const QString& errorMessage) |
510 void CntEditViewPrivate::ringToneFetchHandleError(int errorCode, const QString& errorMessage) |
453 { |
511 { |
454 Q_UNUSED(errorCode); |
512 Q_UNUSED(errorCode); |
543 name = hbTrId("txt_phob_list_unnamed"); |
601 name = hbTrId("txt_phob_list_unnamed"); |
544 } |
602 } |
545 |
603 |
546 disconnect(&mgr, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
604 disconnect(&mgr, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
547 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
605 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&))); |
548 CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, &mgr); |
606 |
|
607 CntSaveManager& save = mEngine->saveManager(); |
|
608 CntSaveManager::CntSaveResult result; |
|
609 if ( mIsMyCard ) |
|
610 result = save.saveMyCard(mContact, &mgr); |
|
611 else |
|
612 result = save.saveContact( mContact, &mgr ); |
549 |
613 |
550 QVariant var; |
614 QVariant var; |
551 bool backToRoot(false); |
615 bool backToRoot(false); |
552 |
616 |
553 switch (result) |
617 switch (result) |
554 { |
618 { |
555 case CntSaveManager::ESaved: |
619 case CntSaveManager::ESaved: |
556 emit q->contactUpdated(KCntServicesReturnValueContactSaved); |
620 emit q->contactUpdated(KCntServicesReturnValueContactSaved); |
557 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name)); |
621 HbDeviceNotificationDialog::notification(QString(), HbParameterLengthLimiter("txt_phob_dpophead_contact_1_saved").arg(name)); |
558 var.setValue(*mContact); |
622 var.setValue(*mContact); |
559 mArgs.insert(ESelectedContact, var); |
623 mArgs.insert(ESelectedContact, var); |
560 mArgs.insert(ESelectedAction, CNT_CREATE_ACTION); |
624 mArgs.insert(ESelectedAction, CNT_CREATE_ACTION); |
561 break; |
625 break; |
562 case CntSaveManager::EUpdated: |
626 case CntSaveManager::EUpdated: |
563 emit q->contactUpdated(KCntServicesReturnValueContactSaved); |
627 emit q->contactUpdated(KCntServicesReturnValueContactSaved); |
564 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contacts_1_updated")).arg(name)); |
628 HbDeviceNotificationDialog::notification(QString(), HbParameterLengthLimiter("txt_phob_dpophead_contacts_1_updated").arg(name)); |
565 var.setValue(*mContact); |
629 var.setValue(*mContact); |
566 mArgs.insert(ESelectedContact, var); |
630 mArgs.insert(ESelectedContact, var); |
567 mArgs.insert(ESelectedAction, CNT_EDIT_ACTION); |
631 mArgs.insert(ESelectedAction, CNT_EDIT_ACTION); |
568 break; |
632 break; |
569 case CntSaveManager::EFailed: |
633 case CntSaveManager::EFailed: |