phonebookui/cntcommonui/contactcard/cntcontactcardview_p.cpp
changeset 81 640d30f4fb64
parent 72 6abfb1094884
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
    82 static const int CntListPopulationNotInProgress = -1;
    82 static const int CntListPopulationNotInProgress = -1;
    83 static const QEvent::Type ProcessPopulateListEvent = QEvent::User;
    83 static const QEvent::Type ProcessPopulateListEvent = QEvent::User;
    84 static const int CntInitialPopulation = 8;
    84 static const int CntInitialPopulation = 8;
    85 
    85 
    86 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
    86 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
       
    87 const QString CNT_ACTIVITY_CONTACTCARD  = "ContactsCardView";
    87 const char *CNT_MAPTILE_INPROGRESS_ICON = "qtg_anim_small_loading_1";
    88 const char *CNT_MAPTILE_INPROGRESS_ICON = "qtg_anim_small_loading_1";
    88 const char *CNT_MAPTILE_SEARCH_STOP_ICON = "qtg_mono_search_stop";
    89 const char *CNT_MAPTILE_SEARCH_STOP_ICON = "qtg_mono_search_stop";
    89 /*!
    90 /*!
    90 Constructor, initialize member variables.
    91 Constructor, initialize member variables.
    91 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
    92 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
   105 	mIsTemporary(isTemporary),
   106 	mIsTemporary(isTemporary),
   106 	mIsExecutingAction(false),
   107 	mIsExecutingAction(false),
   107     mMyCardId(0),
   108     mMyCardId(0),
   108     mSaveManager(NULL),
   109     mSaveManager(NULL),
   109     mListPopulationProgress(CntListPopulationNotInProgress),
   110     mListPopulationProgress(CntListPopulationNotInProgress),
   110     mStopListPopulation(false)
   111     mStopListPopulation(false),
       
   112     mFetchAvatar(false),
       
   113     mSeparatorlabel(NULL)
   111 {
   114 {
   112     bool ok;
   115     bool ok;
   113     document()->load(CNT_CONTACTCARDVIEW_XML, &ok);
   116     document()->load(CNT_CONTACTCARDVIEW_XML, &ok);
   114     if (!ok) 
   117     if (!ok) 
   115     {
   118     {
   158     if ( mProgressTimer && mProgressTimer->isActive())
   161     if ( mProgressTimer && mProgressTimer->isActive())
   159     {
   162     {
   160         mProgressTimer->stop();
   163         mProgressTimer->stop();
   161     }
   164     }
   162     
   165     
   163     // Clear the container to avoid double deletion
   166     if (mContainerLayout)
   164     if (mContainerLayout != NULL)
   167     {
   165     {
   168         // Remove the separator obj from layout
   166         int count = mContainerLayout->count();
   169         mContainerLayout->removeItem(mSeparatorlabel);
   167         for (int i=0; i<count; i++) 
   170     }
   168         {
   171     delete mSeparatorlabel;
   169             // do not delete items. They will be deleted automatically
       
   170             mContainerLayout->removeAt(i);
       
   171         }
       
   172     }
       
   173     
       
   174     // Delete all the detail pointers if any
       
   175     qDeleteAll(mDetailPtrs);
       
   176     mDetailPtrs.clear();
       
   177     
   172     
   178     mView->deleteLater();
   173     mView->deleteLater();
   179     
   174     
   180     delete mContact;
   175     delete mContact;
   181     mContact = NULL;
   176     mContact = NULL;
   295 Activates a default view and setup name label texts
   290 Activates a default view and setup name label texts
   296 */
   291 */
   297 void CntContactCardViewPrivate::activate(const CntViewParameters aArgs)
   292 void CntContactCardViewPrivate::activate(const CntViewParameters aArgs)
   298 {   
   293 {   
   299     CNT_ENTRY
   294     CNT_ENTRY
       
   295 
   300     mArgs = aArgs;
   296     mArgs = aArgs;
   301 
   297 
   302     mViewManager = &mEngine->viewManager();
   298     mViewManager = &mEngine->viewManager();
   303     mThumbnailManager = &mEngine->thumbnailManager();
   299     mThumbnailManager = &mEngine->thumbnailManager();
   304     connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)),
   300     connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)),
   386     emit viewActivated( mViewManager, aArgs );
   382     emit viewActivated( mViewManager, aArgs );
   387 
   383 
   388     CNT_EXIT
   384     CNT_EXIT
   389 }
   385 }
   390 
   386 
       
   387 QString CntContactCardViewPrivate::externalize(QDataStream &stream)
       
   388 {   
       
   389     // set activity parameters 
       
   390     CntViewParameters viewParameters;
       
   391     viewParameters.insert(EViewId, mArgs.value(EViewId).toInt());
       
   392  
       
   393     if (mArgs.value(ESelectedContact).isValid())
       
   394     {
       
   395         QContact contact = mArgs.value(ESelectedContact).value<QContact>();
       
   396         viewParameters.insert(ESelectedContactId, contact.localId()); 
       
   397     }
       
   398     if (mArgs.value(ESelectedGroupContact).isValid())
       
   399     {
       
   400         QContact contact = mArgs.value(ESelectedGroupContact).value<QContact>();
       
   401         viewParameters.insert(ESelectedGroupContactId, QVariant(contact.localId()));
       
   402     }
       
   403     if (mArgs.value(EMyCard).isValid())
       
   404     {
       
   405         viewParameters.insert(EMyCard, mArgs.value(EMyCard));
       
   406     }
       
   407     if (mArgs.value(EExtraAction).isValid())
       
   408     {
       
   409         viewParameters.insert(EExtraAction, mArgs.value(EExtraAction));
       
   410     }
       
   411     
       
   412     stream << viewParameters;
       
   413     
       
   414     return CNT_ACTIVITY_CONTACTCARD;
       
   415 }
       
   416 
       
   417 bool CntContactCardViewPrivate::internalize(QDataStream &stream, CntViewParameters &viewParameters)
       
   418 {
       
   419     CntViewParameters tempViewParameters;
       
   420     stream >> tempViewParameters;
       
   421         
       
   422     viewParameters.insert(EViewId, tempViewParameters.value(EViewId));
       
   423     
       
   424     if (tempViewParameters.value(ESelectedContactId).isValid())
       
   425     {
       
   426         QContact contact = contactManager()->contact(tempViewParameters.value(ESelectedContactId).toInt());
       
   427         if (contact.isEmpty())
       
   428         {
       
   429             // a contact has been deleted.
       
   430             return false;
       
   431         }
       
   432         else
       
   433         {
       
   434             QVariant var;
       
   435             var.setValue(contact);      
       
   436             viewParameters.insert(ESelectedContact, var);
       
   437         }
       
   438     }
       
   439     if (tempViewParameters.value(ESelectedGroupContactId).isValid())
       
   440     {
       
   441         QVariant var;
       
   442         var.setValue(contactManager()->contact(tempViewParameters.value(ESelectedGroupContactId).toInt()));      
       
   443         viewParameters.insert(ESelectedGroupContact, var);
       
   444     }
       
   445     if (tempViewParameters.value(EMyCard).isValid())
       
   446     {
       
   447         viewParameters.insert(EMyCard, tempViewParameters.value(EMyCard));
       
   448     }
       
   449     if (tempViewParameters.value(EMyCard).isValid())
       
   450     {
       
   451         viewParameters.insert(EExtraAction, tempViewParameters.value(EExtraAction));
       
   452     }
       
   453      
       
   454     return true;
       
   455 }
       
   456 
   391 void CntContactCardViewPrivate::populateHeadingItem()
   457 void CntContactCardViewPrivate::populateHeadingItem()
   392 {
   458 {
   393     CNT_ENTRY
   459     CNT_ENTRY
   394 
   460 
   395     Q_ASSERT(mHeadingItem != NULL && mContact != NULL);
   461     Q_ASSERT(mHeadingItem != NULL && mContact != NULL);
   408     else
   474     else
   409     {
   475     {
   410         mHeadingItem->ungrabGesture(Qt::TapGesture);
   476         mHeadingItem->ungrabGesture(Qt::TapGesture);
   411         mImageLabel->ungrabGesture(Qt::TapGesture);
   477         mImageLabel->ungrabGesture(Qt::TapGesture);
   412     }
   478     }
   413     
   479 
   414     bool online;
   480     bool online;
   415     mInitiialPrecenceData = mPresenceListener->initialPresences(*mContact, online);
   481     mInitiialPrecenceData = mPresenceListener->initialPresences(*mContact, online);
   416     mHeadingItem->setOnlineStatus(online);
   482     mHeadingItem->setOnlineStatus(online);
   417 
   483 
   418     if (!myCard) {
   484     if (!myCard)
       
   485     {
   419         bool setAsFavorite = CntFavourite::isMemberOfFavouriteGroup(contactManager(), mContact);
   486         bool setAsFavorite = CntFavourite::isMemberOfFavouriteGroup(contactManager(), mContact);
   420         mHeadingItem->setFavoriteStatus(setAsFavorite); // if contact is part of favourites group
   487         mHeadingItem->setFavoriteStatus(setAsFavorite); // if contact is part of favourites group
   421         static_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite );
   488         static_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite );
   422         static_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
   489         static_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
   423     }
   490     }
   426     QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   493     QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   427     for (int i = 0;i < details.count();i++)
   494     for (int i = 0;i < details.count();i++)
   428     {
   495     {
   429         if (details.at(i).imageUrl().isValid())
   496         if (details.at(i).imageUrl().isValid())
   430         {
   497         {
   431             if (!mAvatar)
   498             if (!mAvatar || *mAvatar != details.at(i))
   432             {
       
   433                 mAvatar = new QContactAvatar(details.at(i));
       
   434                 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
       
   435             }
       
   436             else if (*mAvatar != details.at(i))
       
   437             {
   499             {
   438                 delete mAvatar;
   500                 delete mAvatar;
   439                 mAvatar = new QContactAvatar(details.at(i));
   501                 mAvatar = new QContactAvatar(details.at(i));
   440                 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
   502                 mFetchAvatar = true;
   441             }
   503             }
   442             break;
   504             break;
   443         }
   505         }
   444     }
   506     }
   445 
   507 
   450 {
   512 {
   451     CNT_ENTRY
   513     CNT_ENTRY
   452 
   514 
   453     Q_ASSERT(mContact != NULL && mScrollArea != NULL);
   515     Q_ASSERT(mContact != NULL && mScrollArea != NULL);
   454 
   516 
   455     if (mListPopulationProgress == CntListPopulationNotInProgress) {
   517     if (mListPopulationProgress == CntListPopulationNotInProgress)
       
   518     {
   456         mListPopulationProgress = 0;
   519         mListPopulationProgress = 0;
   457 
   520 
   458         if (!mDataContainer) {
   521         if (!mDataContainer)
       
   522         {
   459             mDataContainer = new CntContactCardDataContainer(
   523             mDataContainer = new CntContactCardDataContainer(
   460                 mMaptile,
   524                 mMaptile,
   461                 mEngine->extensionManager(),
   525                 mEngine->extensionManager(),
   462                 mView->mainWindow()->orientation());
   526                 mView->mainWindow()->orientation());
   463         }
   527         }
   464 
   528 
   465         // fill the data container with contact details
   529         // fill the data container with contact details
   466         mDataContainer->setContactData(mContact);
   530         mDataContainer->setContactData(mContact);
   467         
   531         
   468         // scroll area + container widget
   532         if (mContainerLayout)
   469         mContainerWidget = mScrollArea->contentWidget();
   533         {
   470         if (!mContainerWidget) {
   534             // Remove the separator obj from previous layout
   471             // initialize
   535             // It needs to be reused
   472             mScrollArea->setScrollDirections(Qt::Vertical);
   536             mContainerLayout->removeItem(mSeparatorlabel);
   473             
   537         }
   474             mContainerWidget = new QGraphicsWidget();
   538         // initialize
   475             mScrollArea->setContentWidget(mContainerWidget); // takes ownership. Old widget is deleted
   539         mScrollArea->setScrollDirections(Qt::Vertical);
   476                 
   540         
   477             mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical);
   541         mContainerWidget = new QGraphicsWidget();
   478             mContainerLayout->setContentsMargins(0, 0, 0, 0);
   542         mScrollArea->setContentWidget(mContainerWidget); // takes ownership.
   479             mContainerLayout->setSpacing(0);
   543         
   480             mContainerLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
   544         mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical);
   481             
   545         mContainerLayout->setContentsMargins(0, 0, 0, 0);
   482             mContainerWidget->setLayout(mContainerLayout);   // takes ownership. Old layout is deleted
   546         mContainerLayout->setSpacing(0);
   483         } else {
   547         mContainerLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
   484             // Already initialized
   548         
   485             Q_ASSERT(mContainerLayout != NULL);
   549         mContainerWidget->setLayout(mContainerLayout);   // takes ownership.
   486             
   550     }
   487             // Clear the container
   551 
   488             int count = mContainerLayout->count();
   552 
   489             for (int i = 0; i < count; i++) {
   553     do {
   490                 // do not delete items. They will be deleted automatically
   554         if (mListPopulationProgress == mDataContainer->itemCount() || mStopListPopulation)
   491                 mContainerLayout->removeAt(i);
   555         {
       
   556             if (!mStopListPopulation && mFetchAvatar)
       
   557             {
       
   558                 // fetch the avatar if it has not yet been fetched
       
   559                 mFetchAvatar = false;
       
   560                 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
   492             }
   561             }
   493         }
       
   494     
       
   495         // Delete all the detail pointers if any
       
   496         qDeleteAll(mDetailPtrs);
       
   497         mDetailPtrs.clear();
       
   498     }
       
   499 
       
   500 
       
   501     do {
       
   502         if (mListPopulationProgress == mDataContainer->itemCount() || mStopListPopulation) {
       
   503             // population of the list has completed
   562             // population of the list has completed
   504             mListPopulationProgress = CntListPopulationNotInProgress;
   563             mListPopulationProgress = CntListPopulationNotInProgress;
   505             mStopListPopulation = false;
   564             mStopListPopulation = false;
   506             disconnect(mView->mainWindow(), SIGNAL(viewReady()), this, SLOT(populateListItems()));
   565             disconnect(mView->mainWindow(), SIGNAL(viewReady()), this, SLOT(populateListItems()));
       
   566             CNT_EXIT_ARGS("population completed")
   507             return;
   567             return;
   508         }
   568         }
   509 
   569 
   510         CntContactCardDataItem* dataItem = mDataContainer->dataItem(mListPopulationProgress);
   570         CntContactCardDataItem* dataItem = mDataContainer->dataItem(mListPopulationProgress);
   511         int pos = dataItem->position();
   571         int pos = dataItem->position();
   512 
   572 
   513         // communication methods
   573         // communication methods
   514         if (pos < CntContactCardDataItem::ESeparator && dataItem->isFocusable())
   574         if (pos < CntContactCardDataItem::ESeparator && dataItem->isFocusable())
   515         { 
   575         { 
   516             CntContactCardDetailItem* item = new CntContactCardDetailItem(mListPopulationProgress, mContainerWidget);
   576             CntContactCardDetailItem* item = new CntContactCardDetailItem(mListPopulationProgress, mContainerWidget);
   517             mDetailPtrs.append(item);
       
   518 
   577 
   519             connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated()));
   578             connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated()));
   520             
   579             
   521             if (!mIsTemporary)
   580             if (!mIsTemporary)
   522             {
   581             {
   552             mContainerLayout->addItem(item);
   611             mContainerLayout->addItem(item);
   553         }
   612         }
   554 
   613 
   555         // separator
   614         // separator
   556         else if (pos == CntContactCardDataItem::ESeparator)
   615         else if (pos == CntContactCardDataItem::ESeparator)
   557         {      
   616         {
   558             HbFrameItem* frameItem = new HbFrameItem(QString("qtg_fr_list_separator"), HbFrameDrawer::NinePieces);
   617             if (!mSeparatorlabel)
   559             HbLabel* label = static_cast<HbLabel*>(document()->findWidget(QString("separator")));
   618             {
   560             label->setPlainText(dataItem->titleText());
   619                 HbFrameItem* frameItem = new HbFrameItem(QString("qtg_fr_list_separator"), HbFrameDrawer::NinePieces);
   561             label->setBackgroundItem(frameItem); // takes ownership
   620                 mSeparatorlabel = static_cast<HbLabel*>(document()->findWidget(QString("separator")));
   562             mContainerLayout->addItem(label);
   621                 mSeparatorlabel->setPlainText(dataItem->titleText());
       
   622                 mSeparatorlabel->setBackgroundItem(frameItem); // takes ownership
       
   623                 mSeparatorlabel->setParent(this);
       
   624             }
       
   625             mContainerLayout->addItem(mSeparatorlabel);
   563         }
   626         }
   564 
   627 
   565         // details
   628         // details
   566         else
   629         else
   567         {
   630         {
   586             } 
   649             } 
   587             //other details
   650             //other details
   588             else
   651             else
   589             {
   652             {
   590                 CntContactCardDetailItem* item = new CntContactCardDetailItem(mListPopulationProgress, mContainerWidget, false);
   653                 CntContactCardDetailItem* item = new CntContactCardDetailItem(mListPopulationProgress, mContainerWidget, false);
   591                 mDetailPtrs.append(item);
       
   592                 
   654                 
   593                 //To check whether maptile status  icon is set with the address 
   655                 //To check whether maptile status  icon is set with the address 
   594                 if( ( dataItem->titleText() == hbTrId("txt_phob_formlabel_address") ||
   656                 if( ( dataItem->titleText() == hbTrId("txt_phob_formlabel_address") ||
   595                       dataItem->titleText() == hbTrId("txt_phob_formlabel_address_home")||  
   657                       dataItem->titleText() == hbTrId("txt_phob_formlabel_address_home")||  
   596                       dataItem->titleText() == hbTrId("txt_phob_formlabel_address_work") ) &&
   658                       dataItem->titleText() == hbTrId("txt_phob_formlabel_address_work") ) &&
   630         }
   692         }
   631     
   693     
   632         ++mListPopulationProgress;
   694         ++mListPopulationProgress;
   633     } while (mListPopulationProgress < CntInitialPopulation);
   695     } while (mListPopulationProgress < CntInitialPopulation);
   634 
   696 
   635     if (mListPopulationProgress <= CntInitialPopulation) {
   697     if (mListPopulationProgress <= CntInitialPopulation)
       
   698     {
   636         connect(mView->mainWindow(), SIGNAL(viewReady()), this, SLOT(populateListItems()));
   699         connect(mView->mainWindow(), SIGNAL(viewReady()), this, SLOT(populateListItems()));
   637     } else {
   700     }
       
   701     else
       
   702     {
   638         disconnect(mView->mainWindow(), SIGNAL(viewReady()), this, SLOT(populateListItems()));
   703         disconnect(mView->mainWindow(), SIGNAL(viewReady()), this, SLOT(populateListItems()));
   639         HbApplication::instance()->postEvent(this, new QEvent(ProcessPopulateListEvent));
   704         HbApplication::instance()->postEvent(this, new QEvent(ProcessPopulateListEvent));
       
   705 
       
   706         if (mFetchAvatar)
       
   707         {
       
   708             // initial view has been shown, so starting fetching the avatar
       
   709             mFetchAvatar = false;
       
   710             mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
       
   711         }
   640     }
   712     }
   641 
   713 
   642     CNT_EXIT
   714     CNT_EXIT
   643 }
   715 }
   644 
   716 
   646     Connects the action with a slot and also sets the view as the parent for the action.
   718     Connects the action with a slot and also sets the view as the parent for the action.
   647  */
   719  */
   648 void CntContactCardViewPrivate::connectAction(QString actionName, const char* slot)
   720 void CntContactCardViewPrivate::connectAction(QString actionName, const char* slot)
   649 {
   721 {
   650     HbAction *action = qobject_cast<HbAction *>(document()->findObject(actionName));
   722     HbAction *action = qobject_cast<HbAction *>(document()->findObject(actionName));
   651     if (action) {
   723     if (action)
       
   724     {
   652         action->setParent(mView);
   725         action->setParent(mView);
   653         if (slot != NULL) {
   726         if (slot != NULL)
       
   727         {
   654             connect(action, SIGNAL(triggered()), this, slot);
   728             connect(action, SIGNAL(triggered()), this, slot);
   655         }
   729         }
   656     }
   730     }
   657 }
   731 }
   658 
   732 
   659 /*
   733 /*
   660     Updates the maptile fetching spinning indicator icon
   734     Updates the maptile fetching spinning indicator icon
   661  */
   735  */
   662 void CntContactCardViewPrivate::updateSpinningIndicator()
   736 void CntContactCardViewPrivate::updateSpinningIndicator()
   663 {
   737 {
   664     //Check all address details( Preferred, Home, Work )
   738     CNT_ENTRY
   665     for( int index = 0 ; index < mAddressList.count(); )
   739     
   666     {
   740     // Check all address details( Preferred, Home, Work )
   667         //Maptile status not received update the rotating icon
   741     for (int index = 0 ; index < mAddressList.count();)
   668         if( mAddressList[index]->maptileStatus == CNT_UNKNOWN_MAPTILE_STATUS )
   742     {
   669         {
   743         // Maptile status not received update the rotating icon
   670              QString iconName("qtg_anim_small_loading_");
   744         if (mAddressList[index]->maptileStatus == CNT_UNKNOWN_MAPTILE_STATUS)
   671              mAddressList[index]->mProgressCount = mAddressList[index]->mProgressCount % 10 + 1;
   745         {
   672              iconName.append(QVariant(mAddressList[index]->mProgressCount).toString());
   746             QString iconName("qtg_anim_small_loading_");
       
   747             mAddressList[index]->mProgressCount = mAddressList[index]->mProgressCount % 10 + 1;
       
   748             iconName.append(QVariant(mAddressList[index]->mProgressCount).toString());
   673              
   749              
   674              HbIcon icon(iconName);
   750             HbIcon icon(iconName);
   675              mAddressList[index]->mDetailItem->setSecondaryIconItem( icon );
   751             mAddressList[index]->mDetailItem->setSecondaryIconItem(icon);
   676              mAddressList[index]->mDetailItem->update();   
   752             mAddressList[index]->mDetailItem->update();   
   677              mProgressTimer->start(CNT_MAPTILE_PROGRESS_TIMER);
   753             mProgressTimer->start(CNT_MAPTILE_PROGRESS_TIMER);
   678              index++;
   754             index++;
   679         }
   755         }
   680         else
   756         else
   681         {
   757         {
   682             //Maptile status received. Show the maptile image if available
   758             // Maptile status received. Show the maptile image if available
   683             MapTileService::AddressType sourceAddressType =
   759             MapTileService::AddressType sourceAddressType =
   684                     static_cast <MapTileService::AddressType>( mAddressList[index]->mAddressType );
   760                     static_cast <MapTileService::AddressType>(mAddressList[index]->mAddressType);
   685              
   761              
   686             QContactLocalId contactId = mContact->localId();
   762             QContactLocalId contactId = mContact->localId();
   687              
   763              
   688             if( mAddressList[index] != NULL )
   764             if (mAddressList[index] != NULL)
   689             {
   765             {
   690                  if( mAddressList[index]->maptileStatus == MapTileService::MapTileFetchingCompleted )
   766                 if (mAddressList[index]->maptileStatus == MapTileService::MapTileFetchingCompleted)
   691                  {
   767                 {
   692  
   768                     // Read the maptile path and update the image
   693                      //Read the maptile path and update the image
   769                     QString imagePath;
   694                      QString imagePath;
   770                     mMaptile->getMapTileImage( 
   695                      mMaptile->getMapTileImage( 
   771                                contactId, sourceAddressType, imagePath, mView->mainWindow()->orientation());
   696                                 contactId, sourceAddressType, imagePath, mView->mainWindow()->orientation() );
       
   697 					 
   772 					 
   698                      if( !imagePath.isEmpty() )
   773                     if (!imagePath.isEmpty())
   699                      {
   774                     {
   700                          //Empty icon. Clear the inprogress  icon
   775                         //Empty icon. Clear the inprogress  icon
   701                          HbIcon emptyIcon;
   776                         HbIcon emptyIcon;
   702                          mAddressList[index]->mDetailItem->setSecondaryIconItem( emptyIcon );
   777                         mAddressList[index]->mDetailItem->setSecondaryIconItem(emptyIcon);
   703                          
   778                          
   704                          HbIcon icon( imagePath );
   779                         HbIcon icon(imagePath);
   705                          
   780                          
   706                          HbLabel* maptileLabel = loadMaptileLabel( sourceAddressType );
   781                         HbLabel* maptileLabel = loadMaptileLabel(sourceAddressType);
   707                          setMaptileLabel( maptileLabel, icon );
   782                         setMaptileLabel(maptileLabel, icon);
   708                          mMaptileLabelList.insert( sourceAddressType, maptileLabel );
   783                         mMaptileLabelList.insert(sourceAddressType, maptileLabel);
   709                         
   784 
   710                          //find the index of the item and insert maptile in the next index 
   785                         //find the index of the item and insert maptile in the next index 
   711                          for( int itemIndex = 0 ; itemIndex < mContainerLayout->count(); itemIndex++ )
   786                         for (int itemIndex = 0 ; itemIndex < mContainerLayout->count(); itemIndex++)
   712                          {
   787                         {
   713                              if( mContainerLayout->itemAt(itemIndex) == mAddressList[index]->mDetailItem )
   788                             if (mContainerLayout->itemAt(itemIndex) == mAddressList[index]->mDetailItem)
   714                              {
   789                             {
   715                                  mContainerLayout->insertItem( itemIndex+1, maptileLabel );
   790                                 mContainerLayout->insertItem(itemIndex + 1, maptileLabel);
   716                                  break;
   791                                 break;
   717                              }
   792                             }
   718                          }
   793                         }
   719                          
   794                     }
   720                      }
   795                     else
   721                      else
   796                     {
   722                      {
   797                         //Maptile image not available. Show the search stop icon
   723                          //Maptile image not available. Show the search stop icon
   798                         setMaptileSearchStopIcon(index);
   724                          setMaptileSearchStopIcon( index );
   799                     }
   725                      }
   800                 }
   726                  }
   801                 else
   727                  else
   802                 {
   728                  {
   803                     //Maptile fetching failed. Show the search stop icon
   729                      //Maptile fetching failed. Show the search stop icon
   804                     setMaptileSearchStopIcon(index);
   730                      setMaptileSearchStopIcon( index );
   805                 }
   731                  }
       
   732                  
   806                  
   733                  delete mAddressList[index];
   807                 delete mAddressList[index];
   734                  mAddressList.removeAt(index);
   808                 mAddressList.removeAt(index);
   735             }
   809             }
   736             else
   810             else
   737             {
   811             {
   738                  //increment the index now
   812                 //increment the index now
   739                  index++;
   813                 index++;
   740             }
   814             }
   741         }
   815         }
   742     }
   816     }
   743 }
   817 }
   744 
   818 
   745 /*
   819 /*
   746 * Sets the search stop icon to secondary icon item
   820 * Sets the search stop icon to secondary icon item
   747 */
   821 */
   748 void CntContactCardViewPrivate::setMaptileSearchStopIcon( int index )
   822 void CntContactCardViewPrivate::setMaptileSearchStopIcon(int index)
   749 {
   823 {
   750     if( index < mAddressList.count() )
   824     if (index < mAddressList.count())
   751     {
   825     {
   752         QString iconName(CNT_MAPTILE_SEARCH_STOP_ICON);
   826         QString iconName(CNT_MAPTILE_SEARCH_STOP_ICON);
   753         HbIcon icon(iconName);
   827         HbIcon icon(iconName);
   754         mAddressList[index]->mDetailItem->setSecondaryIconItem( icon );
   828         mAddressList[index]->mDetailItem->setSecondaryIconItem(icon);
   755         mAddressList[index]->mDetailItem->update();  
   829         mAddressList[index]->mDetailItem->update();  
   756     }
   830     }
   757 }
   831 }
   758 
   832 
   759 /*
   833 /*!
   760 * Slot to receive the maptile status information
   834     Slot to receive the maptile status information.
   761 */
   835  */
   762 void CntContactCardViewPrivate::mapTileStatusReceived( int contactid, int addressType, int status)
   836 void CntContactCardViewPrivate::mapTileStatusReceived(int contactid, int addressType, int status)
   763 {
   837 {
   764     //Update the maptile status information for all 3( Preferred, Work, Home ) address
   838     // Update the maptile status information for all 3( Preferred, Work, Home ) address
   765     for( int index = 0 ; index < mAddressList.count(); index++  )
   839     for (int index = 0; index < mAddressList.count(); index++)
   766     {
   840     {
   767         if( mAddressList[index]->mContactId == contactid &&  
   841         if (mAddressList[index]->mContactId == contactid &&  
   768                  mAddressList[index]->mAddressType == addressType )
   842                 mAddressList[index]->mAddressType == addressType)
   769         {
   843         {
   770             mAddressList[index]->maptileStatus = status;
   844             mAddressList[index]->maptileStatus = status;
   771         }
   845         }
   772     }
   846     }
   773     
   847 
   774     updateSpinningIndicator();
   848     updateSpinningIndicator();
   775 }
   849 }
   776 
   850 
   777 /*
   851 /*!
   778 * Updates correct maptile image when screen orientation changes.
   852     Updates correct maptile image when screen orientation changes.
   779 */
   853  */
   780 void CntContactCardViewPrivate::updateMaptileImage()
   854 void CntContactCardViewPrivate::updateMaptileImage()
   781 {
   855 {
   782     //If there is no maptile displayed, return immediately
   856     // If there is no maptile displayed, return immediately
   783     if( mMaptileLabelList.count() > 0 )
   857     if (mMaptileLabelList.count() > 0)
   784     {
   858     {
   785         QContactLocalId contactId = mContact->localId();
   859         QContactLocalId contactId = mContact->localId();
   786         
   860         
   787         QList<QContactAddress> addressDetails = mContact->details<QContactAddress>();
   861         QList<QContactAddress> addressDetails = mContact->details<QContactAddress>();
   788         
   862         
   789         //address
   863         //address
   790         QString contextHome(QContactAddress::ContextHome.operator QString());
   864         QString contextHome(QContactAddress::ContextHome.operator QString());
   791         QString contextWork(QContactAddress::ContextWork.operator QString());
   865         QString contextWork(QContactAddress::ContextWork.operator QString());
   792         MapTileService::AddressType sourceAddressType 
   866         MapTileService::AddressType sourceAddressType 
   793                                              = MapTileService::AddressPreference;
   867             = MapTileService::AddressPreference;
   794         
   868         
   795         QString imagePath;
   869         QString imagePath;
   796         
   870         
   797         for ( int i = 0; i < addressDetails.count(); i++ )
   871         for (int i = 0; i < addressDetails.count(); i++)
   798         {
   872         {
   799             if ( !addressDetails[i].contexts().isEmpty() && 
   873             if (!addressDetails[i].contexts().isEmpty() &&
   800                    addressDetails[i].contexts().at(0) == contextHome )
   874                    addressDetails[i].contexts().at(0) == contextHome)
   801             {
   875             {
   802                 sourceAddressType = MapTileService::AddressHome;
   876                 sourceAddressType = MapTileService::AddressHome;
   803             }
   877             }
   804             else if ( !addressDetails[i].contexts().isEmpty() && 
   878             else if (!addressDetails[i].contexts().isEmpty() && 
   805                          addressDetails[i].contexts().at(0) == contextWork )
   879                         addressDetails[i].contexts().at(0) == contextWork)
   806             {
   880             {
   807                 sourceAddressType = MapTileService::AddressWork;
   881                 sourceAddressType = MapTileService::AddressWork;
   808             }
   882             }
   809             
   883 
   810             int status = mMaptile->getMapTileImage( 
   884             int status = mMaptile->getMapTileImage( 
   811                                              contactId, 
   885                                              contactId, 
   812                                              sourceAddressType, 
   886                                              sourceAddressType, 
   813                                              imagePath, 
   887                                              imagePath, 
   814                                              mView->mainWindow()->orientation() );
   888                                              mView->mainWindow()->orientation());
   815             if( !imagePath.isEmpty() )
   889             if (!imagePath.isEmpty())
   816             {
   890             {
   817                 HbIcon icon( imagePath );
   891                 HbIcon icon(imagePath);
   818                 HbLabel* label = mMaptileLabelList.value( sourceAddressType );
   892                 HbLabel* label = mMaptileLabelList.value(sourceAddressType);
   819                 if( label )
   893                 if (label)
   820                 {
   894                 {
   821                     setMaptileLabel( label, icon );
   895                     setMaptileLabel(label, icon);
   822                 }
   896                 }
   823             }
   897             }
   824         }
   898         }
   825     }
   899     }
   826 }
   900 }
   827 
   901 
   828 
   902 
   829 /*
   903 /*!
   830 * Asscoiate the maptile label widget with maptile image
   904     Asscoiate the maptile label widget with maptile image.
   831 */
   905  */
   832 void CntContactCardViewPrivate::setMaptileLabel( HbLabel*& mapLabel, const HbIcon& icon )
   906 void CntContactCardViewPrivate::setMaptileLabel(HbLabel*& mapLabel, const HbIcon& icon)
   833 {
   907 {
   834     mapLabel->clear();
   908     mapLabel->clear();
   835     mapLabel->setIcon( icon );
   909     mapLabel->setIcon(icon);
   836     
   910 
   837 	qreal leftMarginSize;
   911     qreal leftMarginSize;
   838 	mapLabel->getContentsMargins( &leftMarginSize, 0 , 0 , 0 );
   912     mapLabel->getContentsMargins(&leftMarginSize, 0, 0, 0);
   839     mapLabel->setPreferredSize( 
   913     mapLabel->setPreferredSize(QSizeF(icon.width() + leftMarginSize, icon.height()));
   840           QSizeF(icon.width() + leftMarginSize, icon.height()));
   914 }
   841    
   915 
   842 }
   916 /*!
   843 
   917     Load the maptile label based on the address type.
   844 /*
   918  */
   845 * Load the maptile label based on the address type
   919 HbLabel* CntContactCardViewPrivate::loadMaptileLabel(int addressType)
   846 */
       
   847 HbLabel* CntContactCardViewPrivate::loadMaptileLabel( int addressType )
       
   848 {
   920 {
   849     HbLabel* maptileLabel = NULL;
   921     HbLabel* maptileLabel = NULL;
   850     
   922     
   851     if( addressType == MapTileService::AddressPreference )
   923     if (addressType == MapTileService::AddressPreference)
   852     {
   924     {
   853         maptileLabel = static_cast<HbLabel*>(document()->findWidget(QString("maptilePreferenceWidget")));
   925         maptileLabel = static_cast<HbLabel*>(document()->findWidget(QString("maptilePreferenceWidget")));
   854     }
   926     }
   855     else if( addressType == MapTileService::AddressHome  )
   927     else if (addressType == MapTileService::AddressHome)
   856     {
   928     {
   857         maptileLabel  = static_cast<HbLabel*>(document()->findWidget(QString("maptileHomeWidget")));
   929         maptileLabel = static_cast<HbLabel*>(document()->findWidget(QString("maptileHomeWidget")));
   858     }
   930     }
   859     else if( addressType == MapTileService::AddressWork )
   931     else if (addressType == MapTileService::AddressWork)
   860     {
   932     {
   861         maptileLabel  = static_cast<HbLabel*>(document()->findWidget(QString("maptileWorkWidget")));
   933         maptileLabel = static_cast<HbLabel*>(document()->findWidget(QString("maptileWorkWidget")));
   862     }
   934     }
   863                             
   935                             
   864     return maptileLabel;
   936     return maptileLabel;
   865 }
   937 }
   866 
   938 
  1001     if (name.isEmpty())
  1073     if (name.isEmpty())
  1002     {
  1074     {
  1003         name = hbTrId("txt_phob_list_unnamed");
  1075         name = hbTrId("txt_phob_list_unnamed");
  1004     }
  1076     }
  1005     
  1077     
  1006     HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_delete_1")).arg(name), this, SLOT(handleDeleteContact(int)),
  1078     HbMessageBox::question(HbParameterLengthLimiter("txt_phob_info_delete_1").arg(name), this, SLOT(handleDeleteContact(int)),
  1007             HbMessageBox::Delete | HbMessageBox::Cancel);
  1079             HbMessageBox::Delete | HbMessageBox::Cancel);
  1008 }
  1080 }
  1009 
  1081 
  1010 /*!
  1082 /*!
  1011 Handle action for deleting a contact
  1083 Handle action for deleting a contact
  1637         
  1709         
  1638         // Once we regain focus check if the contact was modified in the background
  1710         // Once we regain focus check if the contact was modified in the background
  1639         if (contactManager()->error() == QContactManager::NoError 
  1711         if (contactManager()->error() == QContactManager::NoError 
  1640             && latestTimeStamp.lastModified() > localTimeStamp.lastModified())
  1712             && latestTimeStamp.lastModified() > localTimeStamp.lastModified())
  1641         {
  1713         {
       
  1714             mListPopulationProgress = CntListPopulationNotInProgress;
       
  1715             
  1642             if (mContact)
  1716             if (mContact)
  1643                 delete mContact;
  1717                 delete mContact;
  1644             mContact = new QContact(c);
  1718             mContact = new QContact(c);
  1645                 
  1719                 
  1646             populateHeadingItem();
  1720             populateHeadingItem();
  1731     if ( contactIds.contains(mContact->localId()) )
  1805     if ( contactIds.contains(mContact->localId()) )
  1732     {
  1806     {
  1733         QContact c = contactManager()->contact(mContact->localId());
  1807         QContact c = contactManager()->contact(mContact->localId());
  1734         if (contactManager()->error() == QContactManager::NoError)
  1808         if (contactManager()->error() == QContactManager::NoError)
  1735         {
  1809         {
       
  1810             mListPopulationProgress = CntListPopulationNotInProgress;
       
  1811             
  1736             if (mContact)
  1812             if (mContact)
  1737                 delete mContact;
  1813                 delete mContact;
  1738             mContact = new QContact(c);
  1814             mContact = new QContact(c);
  1739             
  1815             
  1740             populateHeadingItem();
  1816             populateHeadingItem();