68 #include "cntvcarddetailhandler.h" |
68 #include "cntvcarddetailhandler.h" |
69 #include "cntsavemanager.h" |
69 #include "cntsavemanager.h" |
70 #include <cntabstractengine.h> |
70 #include <cntabstractengine.h> |
71 #include <cntuicontactcardextension.h> |
71 #include <cntuicontactcardextension.h> |
72 |
72 |
73 #define CNT_MAPTILE_PROGRESS_TIMER 100 //100 msec |
73 #define CNT_MAPTILE_PROGRESS_TIMER 100 // 100 msec |
74 #define CNT_UNKNOWN_MAPTILE_STATUS -1 |
74 #define CNT_UNKNOWN_MAPTILE_STATUS -1 |
|
75 |
|
76 // A few list items (CntInitialPopulation) will be populated before the first view; |
|
77 // if there are more list items, they will be fetched and added one by one after the |
|
78 // first view has been shown to the user |
|
79 static const int CntListPopulationNotInProgress = -1; |
|
80 static const QEvent::Type ProcessPopulateListEvent = QEvent::User; |
|
81 static const int CntInitialPopulation = 8; |
75 |
82 |
76 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml"; |
83 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml"; |
77 const char *CNT_MAPTILE_INPROGRESS_ICON = "qtg_anim_small_loading_1"; |
84 const char *CNT_MAPTILE_INPROGRESS_ICON = "qtg_anim_small_loading_1"; |
78 const char *CNT_MAPTILE_SEARCH_STOP_ICON = "qtg_mono_search_stop"; |
85 const char *CNT_MAPTILE_SEARCH_STOP_ICON = "qtg_mono_search_stop"; |
79 /*! |
86 /*! |
205 /*! |
215 /*! |
206 Activates a previous view |
216 Activates a previous view |
207 */ |
217 */ |
208 void CntContactCardViewPrivate::showPreviousView() |
218 void CntContactCardViewPrivate::showPreviousView() |
209 { |
219 { |
|
220 // stop list population, if it is still in progress |
|
221 mStopListPopulation = true; |
|
222 |
210 int returnValue = KCntServicesReturnValueContactNotModified; |
223 int returnValue = KCntServicesReturnValueContactNotModified; |
|
224 |
211 //save the contact if avatar has been changed. |
225 //save the contact if avatar has been changed. |
212 QContact contact = contactManager()->contact(mContact->localId()); |
226 QContact contact = contactManager()->contact(mContact->localId()); |
213 if ( contact != *mContact && contactManager()->error() == QContactManager::NoError) |
227 if ( contact != *mContact && contactManager()->error() == QContactManager::NoError) |
214 { |
228 { |
215 disconnect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
229 disconnect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), |
230 /*! |
244 /*! |
231 Activates the root view |
245 Activates the root view |
232 */ |
246 */ |
233 void CntContactCardViewPrivate::showRootView() |
247 void CntContactCardViewPrivate::showRootView() |
234 { |
248 { |
|
249 // stop list population, if it is still in progress |
|
250 mStopListPopulation = true; |
|
251 |
235 mViewManager->back( mArgs, true ); |
252 mViewManager->back( mArgs, true ); |
236 } |
253 } |
237 |
254 |
238 /* |
255 /* |
239 Activates a default view and setup name label texts |
256 Activates a default view and setup name label texts |
240 */ |
257 */ |
241 void CntContactCardViewPrivate::activate(const CntViewParameters aArgs) |
258 void CntContactCardViewPrivate::activate(const CntViewParameters aArgs) |
242 { |
259 { |
243 CNT_ENTRY |
260 CNT_ENTRY |
244 mArgs = aArgs; |
261 mArgs = aArgs; |
245 |
262 |
246 mViewManager = &mEngine->viewManager(); |
263 mViewManager = &mEngine->viewManager(); |
247 mThumbnailManager = &mEngine->thumbnailManager(); |
264 mThumbnailManager = &mEngine->thumbnailManager(); |
248 connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), |
265 connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), |
249 this, SLOT(thumbnailReady(QPixmap, void*, int, int))); |
266 this, SLOT(thumbnailReady(QPixmap, void*, int, int))); |
250 |
267 |
251 |
|
252 HbMainWindow* window = mView->mainWindow(); |
268 HbMainWindow* window = mView->mainWindow(); |
253 if (window) |
269 if (window) |
254 { |
270 { |
255 connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation))); |
271 connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation))); |
256 window->installEventFilter(this); |
272 window->installEventFilter(this); |
257 |
273 |
258 setOrientation(window->orientation()); |
274 setOrientation(window->orientation()); |
259 } |
275 } |
260 |
276 |
261 qApp->installEventFilter(this); |
277 qApp->installEventFilter(this); |
262 |
278 |
263 QContact contact = aArgs.value(ESelectedContact).value<QContact>(); |
279 QContact contact = aArgs.value(ESelectedContact).value<QContact>(); |
264 mContact = new QContact( contact ); |
280 mContact = new QContact( contact ); |
265 |
281 |
266 //my card |
282 //my card |
267 mMyCardId = contactManager()->selfContactId(); |
283 mMyCardId = contactManager()->selfContactId(); |
268 |
284 |
269 populateHeadingItem(); |
285 populateHeadingItem(); |
|
286 |
270 populateListItems(); |
287 populateListItems(); |
271 |
288 |
272 bool myCard = mContact->localId() == mMyCardId; |
289 bool myCard = mContact->localId() == mMyCardId; |
273 if (myCard) |
290 if (myCard) |
274 { |
291 { |
331 { |
350 { |
332 mHeadingItem->ungrabGesture(Qt::TapGesture); |
351 mHeadingItem->ungrabGesture(Qt::TapGesture); |
333 mImageLabel->ungrabGesture(Qt::TapGesture); |
352 mImageLabel->ungrabGesture(Qt::TapGesture); |
334 } |
353 } |
335 |
354 |
336 |
|
337 bool online; |
355 bool online; |
338 mInitiialPrecenceData = mPresenceListener->initialPresences(*mContact, online); |
356 mInitiialPrecenceData = mPresenceListener->initialPresences(*mContact, online); |
339 mHeadingItem->setOnlineStatus(online); |
357 mHeadingItem->setOnlineStatus(online); |
340 |
358 |
341 if (!myCard) |
359 if (!myCard) { |
342 { |
360 bool setAsFavorite = CntFavourite::isMemberOfFavouriteGroup(contactManager(), mContact); |
343 bool setAsFavorite( false ); |
361 mHeadingItem->setFavoriteStatus(setAsFavorite); // if contact is part of favourites group |
344 setAsFavorite = CntFavourite::isMemberOfFavouriteGroup( contactManager(), mContact ); |
|
345 mHeadingItem->setFavoriteStatus( setAsFavorite ); // if contact is part of favourites group |
|
346 static_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite ); |
362 static_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite ); |
347 static_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite ); |
363 static_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite ); |
348 } |
364 } |
349 |
365 |
350 // avatar |
366 // avatar |
365 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString()); |
381 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString()); |
366 } |
382 } |
367 break; |
383 break; |
368 } |
384 } |
369 } |
385 } |
370 |
386 |
|
387 CNT_EXIT |
371 } |
388 } |
372 |
389 |
373 void CntContactCardViewPrivate::populateListItems() |
390 void CntContactCardViewPrivate::populateListItems() |
374 { |
391 { |
|
392 CNT_ENTRY |
|
393 |
375 Q_ASSERT(mContact != NULL && mScrollArea != NULL); |
394 Q_ASSERT(mContact != NULL && mScrollArea != NULL); |
376 |
395 |
377 // data container |
396 if (mListPopulationProgress == CntListPopulationNotInProgress) { |
378 if (!mDataContainer) { |
397 mListPopulationProgress = 0; |
379 mDataContainer = new CntContactCardDataContainer( |
398 |
380 mMaptile, |
399 if (!mDataContainer) { |
381 mEngine->extensionManager(), |
400 mDataContainer = new CntContactCardDataContainer( |
382 mView->mainWindow()->orientation() ); |
401 mMaptile, |
383 } |
402 mEngine->extensionManager(), |
384 |
403 mView->mainWindow()->orientation()); |
385 // fill the data container with contact details |
404 } |
386 mDataContainer->setContactData(mContact); |
405 |
387 |
406 // fill the data container with contact details |
388 // scroll area + container widget |
407 mDataContainer->setContactData(mContact); |
389 QGraphicsWidget* containerWidget = mScrollArea->contentWidget(); |
408 |
390 if (!containerWidget) |
409 // scroll area + container widget |
391 { |
410 mContainerWidget = mScrollArea->contentWidget(); |
392 // initialize |
411 if (!mContainerWidget) { |
393 mScrollArea->setScrollDirections(Qt::Vertical); |
412 // initialize |
394 |
413 mScrollArea->setScrollDirections(Qt::Vertical); |
395 containerWidget = new QGraphicsWidget(); |
|
396 mScrollArea->setContentWidget(containerWidget); // takes ownership. |
|
397 |
414 |
398 mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical); |
415 mContainerWidget = new QGraphicsWidget(); |
399 mContainerLayout->setContentsMargins(0, 0, 0, 0); |
416 mScrollArea->setContentWidget(mContainerWidget); // takes ownership. Old widget is deleted |
400 mContainerLayout->setSpacing(0); |
417 |
401 mContainerLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
418 mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical); |
402 |
419 mContainerLayout->setContentsMargins(0, 0, 0, 0); |
403 containerWidget->setLayout(mContainerLayout); // takes ownership. |
420 mContainerLayout->setSpacing(0); |
404 } else { |
421 mContainerLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
405 // Already initialized |
422 |
406 Q_ASSERT(mContainerLayout != NULL); |
423 mContainerWidget->setLayout(mContainerLayout); // takes ownership. Old layout is deleted |
407 |
424 } else { |
408 // Clear the container |
425 // Already initialized |
409 int count = mContainerLayout->count(); |
426 Q_ASSERT(mContainerLayout != NULL); |
410 for (int i=0; i<count; i++) |
427 |
411 { |
428 // Clear the container |
412 // do not delete items. They will be deleted automatically |
429 int count = mContainerLayout->count(); |
413 mContainerLayout->removeAt(i); |
430 for (int i = 0; i < count; i++) { |
414 } |
431 // do not delete items. They will be deleted automatically |
415 } |
432 mContainerLayout->removeAt(i); |
416 |
433 } |
417 // Delete all the detail pointers if any |
434 } |
418 qDeleteAll(mDetailPtrs); |
435 |
419 mDetailPtrs.clear(); |
436 // Delete all the detail pointers if any |
420 for(int index = 0; index < mDataContainer->itemCount(); index++) |
437 qDeleteAll(mDetailPtrs); |
421 { |
438 mDetailPtrs.clear(); |
422 CntContactCardDataItem* dataItem = mDataContainer->dataItem(index); |
439 } |
|
440 |
|
441 |
|
442 do { |
|
443 if (mListPopulationProgress == mDataContainer->itemCount() || mStopListPopulation) { |
|
444 // population of the list has completed |
|
445 mListPopulationProgress = CntListPopulationNotInProgress; |
|
446 mStopListPopulation = false; |
|
447 return; |
|
448 } |
|
449 |
|
450 CntContactCardDataItem* dataItem = mDataContainer->dataItem(mListPopulationProgress); |
423 int pos = dataItem->position(); |
451 int pos = dataItem->position(); |
424 |
452 |
425 // communication methods |
453 // communication methods |
426 if (pos < CntContactCardDataItem::ESeparator && dataItem->isFocusable()) |
454 if (pos < CntContactCardDataItem::ESeparator && dataItem->isFocusable()) |
427 { |
455 { |
428 CntContactCardDetailItem* item = new CntContactCardDetailItem(index, containerWidget); |
456 CntContactCardDetailItem* item = new CntContactCardDetailItem(mListPopulationProgress, mContainerWidget); |
429 mDetailPtrs.append(item); |
457 mDetailPtrs.append(item); |
430 |
458 |
431 connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated())); |
459 connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated())); |
432 |
460 |
433 if (!mIsTemporary) |
461 if (!mIsTemporary) |
862 void CntContactCardViewPrivate::setAsFavorite() |
900 void CntContactCardViewPrivate::setAsFavorite() |
863 { |
901 { |
864 QContactId id = mContact->id(); |
902 QContactId id = mContact->id(); |
865 CntFavourite::addContactToFavouriteGroup( contactManager(), id ); |
903 CntFavourite::addContactToFavouriteGroup( contactManager(), id ); |
866 |
904 |
|
905 QContact c = contactManager()->contact(mContact->localId()); |
|
906 |
|
907 delete mContact; |
|
908 mContact = NULL; |
|
909 |
|
910 mContact = new QContact(c); |
|
911 |
867 qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(true); |
912 qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(true); |
868 qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(false); |
913 qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(false); |
869 mHeadingItem->setFavoriteStatus(true); |
914 mHeadingItem->setFavoriteStatus(true); |
870 } |
915 } |
871 |
916 |
872 void CntContactCardViewPrivate::removeFromFavorite() |
917 void CntContactCardViewPrivate::removeFromFavorite() |
873 { |
918 { |
874 QContactId id = mContact->id(); |
919 QContactId id = mContact->id(); |
875 CntFavourite::removeContactFromFavouriteGroup( contactManager(), id ); |
920 CntFavourite::removeContactFromFavouriteGroup( contactManager(), id ); |
|
921 |
|
922 QContact c = contactManager()->contact(mContact->localId()); |
|
923 |
|
924 delete mContact; |
|
925 mContact = NULL; |
|
926 |
|
927 mContact = new QContact(c); |
876 |
928 |
877 qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(false); |
929 qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(false); |
878 qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(true); |
930 qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(true); |
879 mHeadingItem->setFavoriteStatus(false); |
931 mHeadingItem->setFavoriteStatus(false); |
880 } |
932 } |
1293 QContact tmpContact( *mContact ); |
1345 QContact tmpContact( *mContact ); |
1294 foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() ) |
1346 foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() ) |
1295 { |
1347 { |
1296 tmpContact.removeDetail( &a ); |
1348 tmpContact.removeDetail( &a ); |
1297 } |
1349 } |
|
1350 |
|
1351 //temproral solution for a contact without name - add an empty name, |
|
1352 //so vcard construction doesn't fail |
|
1353 //TODO: use custom handler again when new QVersitContactExporterDetailHandlerV2 |
|
1354 //(part of QtVersit) is available in the platform |
|
1355 QList<QContactName> names = tmpContact.details<QContactName>(); |
|
1356 if (names.count() > 0) |
|
1357 { |
|
1358 QContactName name = names.at(0); |
|
1359 if (name.firstName().isEmpty() && name.lastName().isEmpty()) |
|
1360 { |
|
1361 //empty first and last names - update with empty string |
|
1362 name.setFirstName(QString("")); |
|
1363 tmpContact.saveDetail(&name); |
|
1364 } |
|
1365 } |
|
1366 else |
|
1367 { |
|
1368 //no name detail - create one |
|
1369 QContactName name; |
|
1370 name.setFirstName(QString("")); |
|
1371 tmpContact.saveDetail(&name); |
|
1372 } //temproral solution for a contact without name - add an empty name, |
|
1373 //so vcard construction doesn't fail - end |
|
1374 |
1298 list.append( tmpContact ); |
1375 list.append( tmpContact ); |
1299 |
1376 |
1300 QString tempDir = QDir::tempPath().append("/tempcntvcard"); |
1377 QString tempDir = QDir::tempPath().append("/tempcntvcard"); |
1301 QDir dir(tempDir); |
1378 QDir dir(tempDir); |
1302 |
1379 |
1331 QString vCardPath = dir.absolutePath().append(QDir::separator()); |
1408 QString vCardPath = dir.absolutePath().append(QDir::separator()); |
1332 vCardPath.append(vCardName); |
1409 vCardPath.append(vCardName); |
1333 vCardPath = QDir::toNativeSeparators(vCardPath); |
1410 vCardPath = QDir::toNativeSeparators(vCardPath); |
1334 |
1411 |
1335 QVersitContactExporter exporter; |
1412 QVersitContactExporter exporter; |
1336 CntVCardDetailHandler hanlder; |
1413 //TODO: use custom handler again when new QVersitContactExporterDetailHandlerV2 |
1337 exporter.setDetailHandler(&hanlder); |
1414 //(part of QtVersit) is available in the platform |
|
1415 //CntVCardDetailHandler hanlder; |
|
1416 //exporter.setDetailHandler(&hanlder); |
1338 // The vCard version needs to be 2.1 due to backward compatiblity when sending |
1417 // The vCard version needs to be 2.1 due to backward compatiblity when sending |
1339 if (exporter.exportContacts(list, QVersitDocument::VCard21Type)) |
1418 if (exporter.exportContacts(list, QVersitDocument::VCard21Type)) |
1340 { |
1419 { |
1341 CNT_LOG_ARGS("VCard21Type"); |
1420 CNT_LOG_ARGS("VCard21Type"); |
1342 QList<QVersitDocument> docs = exporter.documents(); |
1421 QList<QVersitDocument> docs = exporter.documents(); |