phonebookui/pbkcommonui/src/cntcontactcardview_p.cpp
changeset 65 ae724a111993
parent 59 a642906a277a
child 71 7cc7d74059f9
equal deleted inserted replaced
59:a642906a277a 65:ae724a111993
    13 * Description:
    13 * Description:
    14 *
    14 *
    15 */
    15 */
    16 
    16 
    17 #include "cntcontactcardview_p.h"
    17 #include "cntcontactcardview_p.h"
       
    18 #include "cntthumbnailmanager.h"
    18 
    19 
    19 #include <QGraphicsLinearLayout>
    20 #include <QGraphicsLinearLayout>
    20 #include <QGraphicsSceneResizeEvent>
    21 #include <QGraphicsSceneResizeEvent>
    21 #include <QStringList>
    22 #include <QStringList>
    22 #include <QStandardItemModel>
    23 #include <QStandardItemModel>
    23 #include <QDebug>
    24 #include <QDebug>
    24 #include <QKeyEvent>
    25 #include <QKeyEvent>
    25 #include <QDir>
    26 #include <QDir>
    26 
    27 
       
    28 #include <cntservicescontact.h>
    27 #include <qtcontacts.h>
    29 #include <qtcontacts.h>
    28 #include <hbscrollarea.h>
    30 #include <hbscrollarea.h>
    29 #include <hblabel.h>
    31 #include <hblabel.h>
    30 #include <hbmenu.h>
    32 #include <hbmenu.h>
    31 #include <hbview.h>
    33 #include <hbview.h>
    39 #include <hbframedrawer.h>
    41 #include <hbframedrawer.h>
    40 #include <hbselectiondialog.h>
    42 #include <hbselectiondialog.h>
    41 #include <hblistview.h>
    43 #include <hblistview.h>
    42 #include <hblistviewitem.h>
    44 #include <hblistviewitem.h>
    43 #include <shareui.h>
    45 #include <shareui.h>
    44 #include <thumbnailmanager_qt.h>
    46 #include <maptileservice.h>  //For maptile processing
    45 #include <cntmaptileservice.h>  //For maptile processing
       
    46 #include <qversitcontactexporter.h>
    47 #include <qversitcontactexporter.h>
    47 #include <qversitwriter.h>
    48 #include <qversitwriter.h>
    48 #include <xqservicerequest.h>
    49 #include <xqservicerequest.h>
    49 #include <QTimer>  //Progress indication icon
    50 #include <QTimer>  //Progress indication icon
       
    51 #include <QApplication>
    50 
    52 
    51 #include <cntdebug.h>
    53 #include <cntdebug.h>
    52 #include "cntcontactcarddatacontainer.h"
    54 #include "cntcontactcarddatacontainer.h"
    53 #include "cntcontactcarddetailitem.h"
       
    54 #include "cntcontactcardheadingitem.h"
    55 #include "cntcontactcardheadingitem.h"
    55 #include "cntcontactcarddataitem.h"
    56 #include "cntcontactcarddataitem.h"
       
    57 #include "cntcontactcarddetailitem.h"
    56 #include "cntcontactcardcontextmenu.h"
    58 #include "cntcontactcardcontextmenu.h"
    57 #include "cntmainwindow.h"
    59 #include "cntmainwindow.h"
    58 #include "cntstringmapper.h"
    60 #include "cntstringmapper.h"
    59 #include "cntdocumentloader.h"
    61 #include "cntdocumentloader.h"
    60 #include "cntimagelabel.h"
    62 #include "cntimagelabel.h"
    62 #include "cntfavourite.h"
    64 #include "cntfavourite.h"
    63 #include "cntactionlauncher.h"
    65 #include "cntactionlauncher.h"
    64 #include "cntpresencelistener.h"
    66 #include "cntpresencelistener.h"
    65 #include "cntactionpopup.h"
    67 #include "cntactionpopup.h"
    66 #include "cntvcarddetailhandler.h"
    68 #include "cntvcarddetailhandler.h"
       
    69 #include "cntsavemanager.h"
       
    70 #include <cntabstractengine.h>
       
    71 #include <cntuicontactcardextension.h>
    67 
    72 
    68 #define CNT_MAPTILE_PROGRESS_TIMER  100 //100 msec
    73 #define CNT_MAPTILE_PROGRESS_TIMER  100 //100 msec
    69 #define CNT_UNKNOWN_MAPTILE_STATUS  -1
    74 #define CNT_UNKNOWN_MAPTILE_STATUS  -1
    70 
    75 
    71 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
    76 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
    74 /*!
    79 /*!
    75 Constructor, initialize member variables.
    80 Constructor, initialize member variables.
    76 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
    81 \a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
    77 */
    82 */
    78 CntContactCardViewPrivate::CntContactCardViewPrivate(bool isTemporary) :
    83 CntContactCardViewPrivate::CntContactCardViewPrivate(bool isTemporary) :
    79     QObject(), 
    84     QObject(),
    80     mScrollArea(NULL),
       
    81     mContainerWidget(NULL),
       
    82     mContainerLayout(NULL),
    85     mContainerLayout(NULL),
    83     mContact(NULL),
    86     mContact(NULL),
    84     mDetailsWidget(NULL),
       
    85     mDataContainer(NULL),
    87     mDataContainer(NULL),
    86     mHeadingItem(NULL),
       
    87     mThumbnailManager(NULL),
       
    88     mAvatar(NULL),
    88     mAvatar(NULL),
    89     mFavoriteGroupId(-1),
       
    90     mLoader(NULL),
    89     mLoader(NULL),
    91     mContactAction(NULL),
       
    92     mBackKey(NULL),
       
    93     mImageLabel(NULL),
       
    94     mVCardIcon(NULL),
    90     mVCardIcon(NULL),
    95     mShareUi(NULL),
    91     mShareUi(NULL),
    96     mAcceptSendKey(true),
    92     mAcceptSendKey(true),
    97     mSendKeyListModel(NULL),
       
    98     mPresenceListener(NULL),
    93     mPresenceListener(NULL),
    99     mMaptile(NULL),
       
   100 	mProgressTimer(NULL),
       
   101 	mIsTemporary(isTemporary),
    94 	mIsTemporary(isTemporary),
   102 	mIsExecutingAction(false)
    95 	mIsExecutingAction(false),
       
    96     mMyCardId(0),
       
    97     mSaveManager(NULL)
   103 {
    98 {
   104     bool ok;
    99     bool ok;
   105     document()->load(CNT_CONTACTCARDVIEW_XML, &ok);
   100     document()->load(CNT_CONTACTCARDVIEW_XML, &ok);
   106     if (!ok) 
   101     if (!ok) 
   107     {
   102     {
   108         qFatal("Unable to read :/xml/contacts_contactcard.docml");
   103         qFatal("Unable to read :/xml/contacts_contactcard.docml");
   109     }
   104     }
   110     
   105     
   111     mView = static_cast<HbView*>(document()->findWidget("view"));
   106     mView = static_cast<HbView*>(document()->findWidget("view"));
   112 
   107 
   113     mThumbnailManager = new ThumbnailManager(this);
       
   114     mThumbnailManager->setMode(ThumbnailManager::Default);
       
   115     mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality);
       
   116     mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
       
   117     
       
   118     connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)),
       
   119         this, SLOT(thumbnailReady(QPixmap, void*, int, int)));
       
   120     
       
   121     //back button
   108     //back button
   122     mBackKey = new HbAction(Hb::BackNaviAction, mView);
   109     mBackKey = new HbAction(Hb::BackNaviAction, mView);
   123     mView->setNavigationAction(mBackKey);  
   110     mView->setNavigationAction(mBackKey);  
   124     connect(mBackKey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
   111     connect(mBackKey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
   125     
   112     
   126     mProgressTimer = new QTimer(this);
   113     mProgressTimer = new QTimer(this);
   127     mProgressTimer->setSingleShot(true);
   114     mProgressTimer->setSingleShot(true);
   128     connect(mProgressTimer, SIGNAL(timeout()),this, SLOT(updateSpinningIndicator())); 
   115     connect(mProgressTimer, SIGNAL(timeout()),this, SLOT(updateSpinningIndicator()));
   129 
   116 
   130     mMaptile = new CntMapTileService;
   117     mMaptile = new MapTileService;
   131     if( mMaptile->isLocationFeatureEnabled() )
   118     if( mMaptile->isLocationFeatureEnabled(MapTileService::AppTypeContacts) )
   132     {
   119     {
   133         //Connect for maptile status evenet
   120         //Connect for maptile status evenet
   134         QObject::connect( mMaptile, SIGNAL(maptileFetchingStatusUpdate(int, 
   121         QObject::connect( mMaptile, SIGNAL(maptileFetchingStatusUpdate(int, 
   135             int,int)),this,SLOT(mapTileStatusReceived(int,int,int)));
   122             int,int)),this,SLOT(mapTileStatusReceived(int,int,int)));
   136     }
   123     }
       
   124     
       
   125     mScrollArea = static_cast<HbScrollArea*>(document()->findWidget(QString("scrollArea")));
       
   126     mHeadingItem = static_cast<CntContactCardHeadingItem*>(document()->findWidget(QString("cnt_contactcard_heading")));
       
   127     mImageLabel = static_cast<CntImageLabel*>(document()->findWidget("cnt_contactcard_image"));
       
   128     
       
   129     // presence listener
       
   130     mPresenceListener = new CntPresenceListener();
       
   131     connect(mPresenceListener, SIGNAL(fullPresenceUpdated(bool)), mHeadingItem, SLOT(setOnlineStatus(bool)));
       
   132     connect(mPresenceListener, SIGNAL(accountPresenceUpdated(const QString&, bool)), 
       
   133             this, SLOT(updateItemPresence(const QString&, bool)));
       
   134     
       
   135     
       
   136     mSaveManager = new CntSaveManager();
   137 }
   137 }
   138 
   138 
   139 /*!
   139 /*!
   140 Destructor
   140 Destructor
   141 */
   141 */
   142 CntContactCardViewPrivate::~CntContactCardViewPrivate()
   142 CntContactCardViewPrivate::~CntContactCardViewPrivate()
   143 {
   143 {
       
   144     // Clear the container to avoid double deletion
       
   145     if (mContainerLayout != NULL)
       
   146     {
       
   147         int count = mContainerLayout->count();
       
   148         for (int i=0; i<count; i++) 
       
   149         {
       
   150             // do not delete items. They will be deleted automatically
       
   151             mContainerLayout->removeAt(i);
       
   152         }
       
   153     }
       
   154     
       
   155     // Delete all the detail pointers if any
       
   156     qDeleteAll(mDetailPtrs);
       
   157     mDetailPtrs.clear();
       
   158     
   144     mView->deleteLater();
   159     mView->deleteLater();
   145     
   160     
   146     delete mContact;
   161     delete mContact;
   147     mContact = 0;
   162     mContact = NULL;
   148     
   163     
   149     delete mDataContainer;
   164     delete mDataContainer;
   150     mDataContainer = NULL;
   165     mDataContainer = NULL;
   151     
   166     
   152     delete mAvatar;
   167     delete mAvatar;
   165     {
   180     {
   166         delete mShareUi;
   181         delete mShareUi;
   167         mShareUi = NULL;
   182         mShareUi = NULL;
   168     }
   183     }
   169     
   184     
   170     delete mSendKeyListModel;
       
   171     mSendKeyListModel = NULL;
       
   172     
       
   173     delete mPresenceListener;
   185     delete mPresenceListener;
   174     mPresenceListener = NULL;
   186     mPresenceListener = NULL;
   175     
   187     
   176     delete mMaptile;
   188     delete mMaptile;
   177     mMaptile = NULL;
   189     mMaptile = NULL;
   178     
   190         
   179     delete mProgressTimer;
       
   180     mProgressTimer = NULL;
       
   181     
       
   182     //delete maptile label memory
   191     //delete maptile label memory
   183     for ( int index = 0; index < mMaptileLabelList.count(); index++ )
   192     for ( int index = 0; index < mMaptileLabelList.count(); index++ )
   184     {
   193     {
   185         if( mMaptileLabelList[index] )
   194         if( mMaptileLabelList[index] )
   186         {
   195         {
   187            delete mMaptileLabelList[index];
   196            delete mMaptileLabelList[index];
   188            mMaptileLabelList[index] = NULL ;
   197            mMaptileLabelList[index] = NULL ;
   189         }
   198         }
   190     }
   199     }
       
   200     
       
   201     delete mSaveManager;
       
   202     mSaveManager = NULL;
   191 }
   203 }
   192 
   204 
   193 /*!
   205 /*!
   194 Activates a previous view
   206 Activates a previous view
   195 */
   207 */
   196 void CntContactCardViewPrivate::showPreviousView()
   208 void CntContactCardViewPrivate::showPreviousView()
   197 {
   209 {
   198     emit backPressed();
   210     int returnValue = KCntServicesReturnValueContactNotModified;
   199     
       
   200     //save the contact if avatar has been changed.
   211     //save the contact if avatar has been changed.
   201     QContact contact = contactManager()->contact(mContact->localId());
   212     QContact contact = contactManager()->contact(mContact->localId());
   202     if ( contact != *mContact && contactManager()->error() == QContactManager::NoError)
   213     if ( contact != *mContact && contactManager()->error() == QContactManager::NoError)
   203     {
   214     {
   204         contactManager()->saveContact(mContact);
   215         disconnect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
   205     }
   216                     this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
       
   217         CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, contactManager());
       
   218         
       
   219         if (result != CntSaveManager::ENothingDone)
       
   220             returnValue = KCntServicesReturnValueContactSaved;
       
   221         else
       
   222             returnValue = KCntServicesReturnValueContactNotModified;
       
   223     }
       
   224     
       
   225     emit backPressed(returnValue);
   206     
   226     
   207     mViewManager->back( mArgs );
   227     mViewManager->back( mArgs );
   208 }
   228 }
   209 
   229 
   210 /*!
   230 /*!
   216 }
   236 }
   217 
   237 
   218 /*
   238 /*
   219 Activates a default view and setup name label texts
   239 Activates a default view and setup name label texts
   220 */
   240 */
   221 void CntContactCardViewPrivate::activate(CntAbstractViewManager* aMgr, const CntViewParameters aArgs)
   241 void CntContactCardViewPrivate::activate(const CntViewParameters aArgs)
   222 {   
   242 {   
   223     CNT_ENTRY
   243     CNT_ENTRY
   224     
       
   225     mViewManager = aMgr;
       
   226     mArgs = aArgs;
   244     mArgs = aArgs;
       
   245             
       
   246     mViewManager = &mEngine->viewManager();
       
   247     mThumbnailManager = &mEngine->thumbnailManager();
       
   248     connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)),
       
   249             this, SLOT(thumbnailReady(QPixmap, void*, int, int)));
       
   250        
   227     
   251     
   228     HbMainWindow* window = mView->mainWindow();
   252     HbMainWindow* window = mView->mainWindow();
   229     if (window)
   253     if (window)
   230     {
   254     {
   231         connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
   255         connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
   232         window->installEventFilter(this);
   256         window->installEventFilter(this);
   233         
   257         
   234         setOrientation(window->orientation());
   258         setOrientation(window->orientation());
   235     }
   259     }
       
   260     
       
   261     qApp->installEventFilter(this);
   236         
   262         
   237     QContact contact = aArgs.value(ESelectedContact).value<QContact>();
   263     QContact contact = aArgs.value(ESelectedContact).value<QContact>();
   238     mContact = new QContact( contact );
   264     mContact = new QContact( contact );
       
   265     
   239     //my card
   266     //my card
   240     bool myCard = mContact->localId() == contactManager()->selfContactId();
   267     mMyCardId = contactManager()->selfContactId();
       
   268     
       
   269     populateHeadingItem();
       
   270     populateListItems();
       
   271     
       
   272     bool myCard = mContact->localId() == mMyCardId;
   241     if (myCard)
   273     if (myCard)
   242     {
   274     {
   243         mView->menu()->clearActions();
   275         mView->menu()->clearActions();
   244         mView->toolBar()->removeAction(static_cast<HbAction*>(document()->findObject(QString("cnt:history"))));
   276         mView->toolBar()->removeAction(static_cast<HbAction*>(document()->findObject(QString("cnt:history"))));
   245     }
   277     }
   251     {
   283     {
   252         mView->menu()->clearActions();
   284         mView->menu()->clearActions();
   253         mView->toolBar()->clearActions();
   285         mView->toolBar()->clearActions();
   254         mView->toolBar()->addAction(static_cast<HbAction*>(document()->findObject(QString("cnt:addtocontact"))));
   286         mView->toolBar()->addAction(static_cast<HbAction*>(document()->findObject(QString("cnt:addtocontact"))));
   255     }
   287     }
   256     
   288 
   257     // add heading widget to the content
   289     document()->findWidget("viewToolbar")->setParent(mView);
   258     QGraphicsWidget *c = document()->findWidget(QString("content"));
   290     document()->findWidget("viewMenu")->setParent(mView);
   259     QGraphicsLinearLayout* l = static_cast<QGraphicsLinearLayout*>(c->layout());
   291     
   260 
   292     // Menu items
   261     mHeadingItem = static_cast<CntContactCardHeadingItem*>(document()->findWidget(QString("cnt_contactcard_heading")));
   293     connectAction("cnt:sendbusinesscard", SLOT(sendBusinessCard()));
       
   294     connectAction("cnt:deletecontact", SLOT(deleteContact()));
       
   295     connectAction("cnt:setasfavorite", SLOT(setAsFavorite()));
       
   296     connectAction("cnt:removefromfavorite", SLOT(removeFromFavorite()));
       
   297     connectAction("cnt:placecontacttohs", SLOT(sendToHs()));
       
   298     connectAction("cnt:edit", SLOT(editContact()));
       
   299     connectAction("cnt:history", SLOT(viewHistory()));
       
   300     connectAction("cnt:sendMyCard", SLOT(sendBusinessCard()));
       
   301     connectAction("cnt:addtocontact", SLOT(onAddedToContacts()));
       
   302     connectAction("cnt:activityStream", NULL);      // placeholder until this action is implemented (needed to avoid memory leak)
       
   303     
       
   304     // disabled until this action is implemented 
       
   305     static_cast<HbAction *>(document()->findObject("cnt:activityStream"))->setEnabled(false);
       
   306         
       
   307     connect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), 
       
   308         this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
       
   309     
       
   310     emit viewActivated( mViewManager, aArgs );
       
   311 
       
   312     CNT_EXIT
       
   313 }
       
   314 
       
   315 void CntContactCardViewPrivate::populateHeadingItem()
       
   316 {
       
   317     Q_ASSERT(mHeadingItem != NULL && mContact != NULL);
       
   318     
   262     mHeadingItem->setDetails(mContact);
   319     mHeadingItem->setDetails(mContact);
   263     
   320     
   264     mImageLabel = static_cast<CntImageLabel*>(document()->findWidget("cnt_contactcard_image"));
   321     bool myCard = mContact->localId() == mMyCardId;
   265          
   322     
   266     if (!mIsTemporary)
   323     if (!mIsTemporary)
   267     {
   324     {
   268         connect(mHeadingItem, SIGNAL(passLongPressed(const QPointF&)), this, SLOT(drawMenu(const QPointF&)));
   325         connect(mHeadingItem, SIGNAL(passLongPressed(const QPointF&)), this, SLOT(drawMenu(const QPointF&)), Qt::UniqueConnection);
   269         connect(mHeadingItem, SIGNAL(passShortPressed(const QPointF&)), this, SLOT(doChangeImage())); 
   326         connect(mHeadingItem, SIGNAL(passShortPressed(const QPointF&)), this, SLOT(doChangeImage()), Qt::UniqueConnection); 
   270         connect(mImageLabel, SIGNAL(iconClicked()), this, SLOT(doChangeImage()));
   327         connect(mImageLabel, SIGNAL(iconClicked()), this, SLOT(doChangeImage()), Qt::UniqueConnection);
   271         connect(mImageLabel, SIGNAL(iconLongPressed(const QPointF&)), this, SLOT(drawMenu(const QPointF&)));
   328         connect(mImageLabel, SIGNAL(iconLongPressed(const QPointF&)), this, SLOT(drawMenu(const QPointF&)), Qt::UniqueConnection);
   272     }
   329     }
   273     else
   330     else
   274     {
   331     {
   275         mHeadingItem->ungrabGesture(Qt::TapGesture);
   332         mHeadingItem->ungrabGesture(Qt::TapGesture);
   276         mImageLabel->ungrabGesture(Qt::TapGesture);
   333         mImageLabel->ungrabGesture(Qt::TapGesture);
   277     }
   334     }
   278     
   335     
   279     // presence listener
   336 
   280     mPresenceListener = new CntPresenceListener(*mContact);
       
   281     connect(mPresenceListener, SIGNAL(fullPresenceUpdated(bool)), mHeadingItem, SLOT(setOnlineStatus(bool)));
       
   282     connect(mPresenceListener, SIGNAL(accountPresenceUpdated(const QString&, bool)), 
       
   283             this, SLOT(updateItemPresence(const QString&, bool)));
       
   284     bool online;
   337     bool online;
   285     QMap<QString, bool> presences = mPresenceListener->initialPresences(online);
   338     mInitiialPrecenceData = mPresenceListener->initialPresences(*mContact, online);
   286     mHeadingItem->setOnlineStatus(online);
   339     mHeadingItem->setOnlineStatus(online);
   287 
   340     
   288    
   341     if (!myCard)
       
   342     {
       
   343         bool setAsFavorite( false );
       
   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 );
       
   347         static_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
       
   348     }
   289     
   349     
   290     // avatar
   350     // avatar
   291     QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   351     QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   292     for (int i = 0;i < details.count();i++)
   352     for (int i = 0;i < details.count();i++)
   293     {
   353     {
   294         if (details.at(i).imageUrl().isValid())
   354         if (details.at(i).imageUrl().isValid())
   295         {
   355         {
   296             mAvatar = new QContactAvatar(details.at(i));
   356             if (!mAvatar)
   297             mThumbnailManager->getThumbnail(mAvatar->imageUrl().toString());
   357             {
       
   358                 mAvatar = new QContactAvatar(details.at(i));
       
   359                 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
       
   360             }
       
   361             else if (*mAvatar != details.at(i))
       
   362             {
       
   363                 delete mAvatar;
       
   364                 mAvatar = new QContactAvatar(details.at(i));
       
   365                 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
       
   366             }
   298             break;
   367             break;
   299         }
   368         }
   300     }
   369     }
   301     
   370     
   302     // data
   371 }
   303     mDataContainer = new CntContactCardDataContainer( 
   372 
   304             mContact, NULL, myCard, mMaptile, mView->mainWindow()->orientation() );
   373 void CntContactCardViewPrivate::populateListItems()
   305 
   374 {
       
   375     Q_ASSERT(mContact != NULL && mScrollArea != NULL);
       
   376 
       
   377     // data container
       
   378     if (!mDataContainer) {
       
   379         mDataContainer = new CntContactCardDataContainer(
       
   380             mMaptile,
       
   381             mEngine->extensionManager(),
       
   382             mView->mainWindow()->orientation() );
       
   383     }
       
   384     
       
   385     // fill the data container with contact details
       
   386     mDataContainer->setContactData(mContact);
       
   387     
   306     // scroll area + container widget
   388     // scroll area + container widget
   307     mScrollArea = static_cast<HbScrollArea*>(document()->findWidget(QString("scrollArea")));
   389     QGraphicsWidget* containerWidget = mScrollArea->contentWidget();
   308     mScrollArea->setScrollDirections(Qt::Vertical);
   390     if (!containerWidget)
   309     mContainerWidget = new QGraphicsWidget(mScrollArea);
   391     {
   310     mScrollArea->setContentWidget(mContainerWidget);
   392         // initialize
   311         
   393         mScrollArea->setScrollDirections(Qt::Vertical);
   312     mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical);
   394         
   313     mContainerLayout->setContentsMargins(0, 0, 0, 0);
   395         containerWidget = new QGraphicsWidget();
   314     mContainerLayout->setSpacing(0);
   396         mScrollArea->setContentWidget(containerWidget); // takes ownership.
   315     mContainerLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
   397             
   316     
   398         mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical);
   317     mContainerWidget->setLayout(mContainerLayout);
   399         mContainerLayout->setContentsMargins(0, 0, 0, 0);
   318  
   400         mContainerLayout->setSpacing(0);
   319     for (int index = 0; index < mDataContainer->itemCount(); index++)
   401         mContainerLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
       
   402         
       
   403         containerWidget->setLayout(mContainerLayout);   // takes ownership.
       
   404     } else {
       
   405         // Already initialized
       
   406         Q_ASSERT(mContainerLayout != NULL);
       
   407         
       
   408         // Clear the container
       
   409         int count = mContainerLayout->count();
       
   410         for (int i=0; i<count; i++) 
       
   411         {
       
   412             // do not delete items. They will be deleted automatically
       
   413             mContainerLayout->removeAt(i);
       
   414         }
       
   415     }
       
   416     
       
   417     // Delete all the detail pointers if any
       
   418     qDeleteAll(mDetailPtrs);
       
   419     mDetailPtrs.clear();
       
   420     for(int index = 0; index < mDataContainer->itemCount(); index++)
   320     {
   421     {
   321         CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
   422         CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
   322         int pos = dataItem->position();
   423         int pos = dataItem->position();
   323         
   424         
   324         // communication methods
   425         // communication methods
   325         if (pos < CntContactCardDataItem::ESeparator && dataItem->isFocusable())
   426         if (pos < CntContactCardDataItem::ESeparator && dataItem->isFocusable())
   326         { 
   427         { 
   327             CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget);
   428             CntContactCardDetailItem* item = new CntContactCardDetailItem(index, containerWidget);
       
   429             mDetailPtrs.append(item);
   328 
   430 
   329             connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated()));
   431             connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated()));
   330             
   432             
   331             if (!mIsTemporary)
   433             if (!mIsTemporary)
   332             {
   434             {
   339                 mPreferredItems.insert(dataItem->action(), item);
   441                 mPreferredItems.insert(dataItem->action(), item);
   340             }
   442             }
   341             
   443             
   342             if (dataItem->detail().definitionName() == QContactOnlineAccount::DefinitionName)
   444             if (dataItem->detail().definitionName() == QContactOnlineAccount::DefinitionName)
   343             {
   445             {
   344                 for (int i = 0;i < presences.keys().count();i++)
   446                 for (int i = 0;i < mInitiialPrecenceData.keys().count();i++)
   345                 {
   447                 {
   346                     QString fullAccount = presences.keys().at(i);
   448                     QString fullAccount = mInitiialPrecenceData.keys().at(i);
   347                     QContactOnlineAccount account = dataItem->detail();
   449                     QContactOnlineAccount account = dataItem->detail();
   348                     QString currentFullAccount = account.serviceProvider() + ':' + account.accountUri();
   450                     QString currentFullAccount = account.serviceProvider() + ':' + account.accountUri();
   349                     if (fullAccount == currentFullAccount)
   451                     if (fullAccount == currentFullAccount)
   350                     {
   452                     {
   351                         if (presences.values().at(i))
   453                         if (mInitiialPrecenceData.values().at(i))
   352                         {
   454                         {
   353                             dataItem->setSecondaryIcon(HbIcon("qtg_small_online"));
   455                             dataItem->setSecondaryIcon(HbIcon("qtg_small_online"));
   354                         }
   456                         }
   355                         mPresenceItems.insert(fullAccount, item);
   457                         mPresenceItems.insert(fullAccount, item);
   356                         break;
   458                         break;
   366         else if (pos == CntContactCardDataItem::ESeparator)
   468         else if (pos == CntContactCardDataItem::ESeparator)
   367         {      
   469         {      
   368             HbFrameItem* frameItem = new HbFrameItem(QString("qtg_fr_list_separator"), HbFrameDrawer::NinePieces);
   470             HbFrameItem* frameItem = new HbFrameItem(QString("qtg_fr_list_separator"), HbFrameDrawer::NinePieces);
   369             HbLabel* label = static_cast<HbLabel*>(document()->findWidget(QString("separator")));
   471             HbLabel* label = static_cast<HbLabel*>(document()->findWidget(QString("separator")));
   370             label->setPlainText(dataItem->titleText());
   472             label->setPlainText(dataItem->titleText());
   371             label->setBackgroundItem(frameItem);
   473             label->setBackgroundItem(frameItem); // takes ownership
   372             mContainerLayout->addItem(label);
   474             mContainerLayout->addItem(label);
   373         }
   475         }
   374 
   476 
   375         // details
   477         // details
   376         else
   478         else
   377         {
   479         {
   378             //map support (image only)
   480             //map support (image only)
   379             if (pos >= CntContactCardDataItem::EAddress && pos <= CntContactCardDataItem::EAddressWork && !dataItem->icon().isNull())
   481             if (pos >= CntContactCardDataItem::EAddress && pos <= CntContactCardDataItem::EAddressWork && !dataItem->icon().isNull())
   380             {        
   482             {        
   381                 int addressType = CntMapTileService::AddressPreference;
   483                 int addressType = MapTileService::AddressPreference;
   382                 
   484                 
   383                 if( pos == CntContactCardDataItem::EAddressHome  )
   485                 if( pos == CntContactCardDataItem::EAddressHome  )
   384                 {
   486                 {
   385                     addressType  = CntMapTileService::AddressHome;
   487                     addressType  = MapTileService::AddressHome;
   386                 }
   488                 }
   387                 else if( pos == CntContactCardDataItem::EAddressWork )
   489                 else if( pos == CntContactCardDataItem::EAddressWork )
   388                 {
   490                 {
   389                     addressType  = CntMapTileService::AddressWork;
   491                     addressType  = MapTileService::AddressWork;
   390                 }
   492                 }
   391                   
   493                   
   392                 HbLabel* maptileLabel = loadMaptileLabel( addressType );
   494                 HbLabel* maptileLabel = loadMaptileLabel( addressType );
   393                 setMaptileLabel( maptileLabel, dataItem->icon() );
   495                 setMaptileLabel( maptileLabel, dataItem->icon() );
   394                 mContainerLayout->addItem(  maptileLabel );
   496                 mContainerLayout->addItem(  maptileLabel );
   395                 mMaptileLabelList.insert( addressType, maptileLabel );
   497                 mMaptileLabelList.insert( addressType, maptileLabel );
   396             } 
   498             } 
   397             //other details
   499             //other details
   398             else
   500             else
   399             {    
   501             {
   400                 CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget, false);
   502                 CntContactCardDetailItem* item = new CntContactCardDetailItem(index, containerWidget, false);
   401 				//To check whether maptile status  icon is set with the address 
   503                 mDetailPtrs.append(item);
       
   504                 
       
   505                 //To check whether maptile status  icon is set with the address 
   402                 if( ( dataItem->titleText() == hbTrId("txt_phob_formlabel_address") ||
   506                 if( ( dataItem->titleText() == hbTrId("txt_phob_formlabel_address") ||
   403                       dataItem->titleText() == hbTrId("txt_phob_formlabel_address_home")||  
   507                       dataItem->titleText() == hbTrId("txt_phob_formlabel_address_home")||  
   404                       dataItem->titleText() == hbTrId("txt_phob_formlabel_address_work") ) &&
   508                       dataItem->titleText() == hbTrId("txt_phob_formlabel_address_work") ) &&
   405                       dataItem->secondaryIcon().iconName() == QString(CNT_MAPTILE_INPROGRESS_ICON) )
   509                       dataItem->secondaryIcon().iconName() == QString(CNT_MAPTILE_INPROGRESS_ICON) )
   406                     
   510                     
   407                 {
   511                 {
   408                     //Information for displaying maptile fetching progress bar.
   512                     //Information for displaying maptile fetching progress bar.
   409                     //Memory will be deleted from the queue.
   513                     //Memory will be deleted from the queue.
   410                     CntContactCardMapTileDetail* detail = new CntContactCardMapTileDetail;
   514                     CntContactCardMapTileDetail* detail = new CntContactCardMapTileDetail;
   411                     if( detail )
   515                     detail->mContactId = mContact->localId();
       
   516                         
       
   517                     if( dataItem->titleText() == hbTrId("txt_phob_formlabel_address") )
   412                     {
   518                     {
   413                         detail->mContactId = mContact->localId();
   519                                detail->mAddressType = MapTileService::AddressPreference;
   414                             
   520                     }
   415                         if( dataItem->titleText() == hbTrId("txt_phob_formlabel_address") )
   521                     else if ( dataItem->titleText() ==  hbTrId("txt_phob_formlabel_address_home") )
       
   522                     {
       
   523                                detail->mAddressType = MapTileService::AddressHome;
       
   524                     }
       
   525                     else if( dataItem->titleText() ==  hbTrId("txt_phob_formlabel_address_work") )
   416                         {
   526                         {
   417                                detail->mAddressType = CntMapTileService::AddressPreference;
   527                                detail->mAddressType = MapTileService::AddressWork;
   418                         }
       
   419                         else if ( dataItem->titleText() ==  hbTrId("txt_phob_formlabel_address_home") )
       
   420                         {
       
   421                                detail->mAddressType = CntMapTileService::AddressHome;
       
   422                         }
       
   423                         else if( dataItem->titleText() ==  hbTrId("txt_phob_formlabel_address_work") )
       
   424                         {
       
   425                                detail->mAddressType = CntMapTileService::AddressWork;
       
   426                         }
       
   427                         
       
   428                         detail->mProgressCount = 0;
       
   429                         detail->mDetailItem =  item;
       
   430                         detail->maptileStatus = CNT_UNKNOWN_MAPTILE_STATUS;
       
   431                         mAddressList.append( detail );  
       
   432                     }
   528                     }
       
   529                     
       
   530                     detail->mProgressCount = 0;
       
   531                     detail->mDetailItem =  item;
       
   532                     detail->maptileStatus = CNT_UNKNOWN_MAPTILE_STATUS;
       
   533                     mAddressList.append( detail );  
   433                     
   534                     
   434                     //Update the spinning indicator
   535                     //Update the spinning indicator
   435                     updateSpinningIndicator();
   536                     updateSpinningIndicator();
   436                     
   537                     
   437                 }
   538                 }
   438                 item->setDetails(dataItem);
   539                 item->setDetails(dataItem);
   439                 mContainerLayout->addItem(item);
   540                 mContainerLayout->addItem(item);
   440             }
   541             }
   441         }
   542         }
   442     }
   543     }
   443     
       
   444     if (!myCard)
       
   445     {   
       
   446         bool setAsFavorite( false );
       
   447         QContactLocalId favouriteGroupId = CntFavourite::favouriteGroupId( contactManager() );
       
   448         if( favouriteGroupId != 0 )
       
   449         {
       
   450             setAsFavorite = CntFavourite::isMemberOfFavouriteGroup( contactManager(), mContact );
       
   451             mHeadingItem->setFavoriteStatus( setAsFavorite ); // if contact is part of favourites group
       
   452         }
       
   453         static_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite );
       
   454         static_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
       
   455     }
       
   456     document()->findWidget("viewToolbar")->setParent(mView);
       
   457     document()->findWidget("viewMenu")->setParent(mView);
       
   458     
       
   459     // Menu items
       
   460     connectAction("cnt:sendbusinesscard", SLOT(sendBusinessCard()));
       
   461     connectAction("cnt:deletecontact", SLOT(deleteContact()));
       
   462     connectAction("cnt:setasfavorite", SLOT(setAsFavorite()));
       
   463     connectAction("cnt:removefromfavorite", SLOT(removeFromFavorite()));
       
   464     connectAction("cnt:placecontacttohs", SLOT(sendToHs()));
       
   465     connectAction("cnt:edit", SLOT(editContact()));
       
   466     connectAction("cnt:history", SLOT(viewHistory()));
       
   467     connectAction("cnt:sendMyCard", SLOT(sendBusinessCard()));
       
   468     connectAction("cnt:addtocontact", SLOT(onAddedToContacts()));
       
   469     connectAction("cnt:activityStream", NULL);      // placeholder until this action is implemented (needed to avoid memory leak)
       
   470     
       
   471     // disabled until this action is implemented 
       
   472     static_cast<HbAction *>(document()->findObject("cnt:activityStream"))->setEnabled(false);
       
   473         
       
   474     connect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)), 
       
   475         this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
       
   476     
       
   477     emit viewActivated( mViewManager, aArgs );
       
   478 
       
   479     CNT_EXIT
       
   480 }
   544 }
   481 
   545 
   482 /*
   546 /*
   483     Connects the action with a slot and also sets the view as the parent for the action.
   547     Connects the action with a slot and also sets the view as the parent for the action.
   484  */
   548  */
   509              iconName.append(QVariant(mAddressList[index]->mProgressCount).toString());
   573              iconName.append(QVariant(mAddressList[index]->mProgressCount).toString());
   510              
   574              
   511              HbIcon icon(iconName);
   575              HbIcon icon(iconName);
   512              mAddressList[index]->mDetailItem->setSecondaryIconItem( icon );
   576              mAddressList[index]->mDetailItem->setSecondaryIconItem( icon );
   513              mAddressList[index]->mDetailItem->update();   
   577              mAddressList[index]->mDetailItem->update();   
   514              mProgressTimer->start(CNT_MAPTILE_PROGRESS_TIMER); 
   578              mProgressTimer->start(CNT_MAPTILE_PROGRESS_TIMER);
   515              index++;
   579              index++;
   516         }
   580         }
   517         else
   581         else
   518         {
   582         {
   519             //Maptile status received. Show the maptile image if available
   583             //Maptile status received. Show the maptile image if available
   520             CntMapTileService::ContactAddressType sourceAddressType =
   584             MapTileService::AddressType sourceAddressType =
   521                     static_cast <CntMapTileService::ContactAddressType>( mAddressList[index]->mAddressType );
   585                     static_cast <MapTileService::AddressType>( mAddressList[index]->mAddressType );
   522              
   586              
   523             QContactLocalId contactId = mContact->localId();
   587             QContactLocalId contactId = mContact->localId();
   524              
   588              
   525             if( mAddressList[index]->mDetailItem != NULL )
   589             if( mAddressList[index] != NULL )
   526             {
   590             {
   527                  if( mAddressList[index]->maptileStatus == CntMapTileService::MapTileFetchingCompleted )
   591                  if( mAddressList[index]->maptileStatus == MapTileService::MapTileFetchingCompleted )
   528                  {
   592                  {
   529  
   593  
   530                      //Read the maptile path and update the image
   594                      //Read the maptile path and update the image
   531                      QString imagePath;
   595                      QString imagePath;
   532                      mMaptile->getMapTileImage( 
   596                      mMaptile->getMapTileImage( 
   624         QList<QContactAddress> addressDetails = mContact->details<QContactAddress>();
   688         QList<QContactAddress> addressDetails = mContact->details<QContactAddress>();
   625         
   689         
   626         //address
   690         //address
   627         QString contextHome(QContactAddress::ContextHome.operator QString());
   691         QString contextHome(QContactAddress::ContextHome.operator QString());
   628         QString contextWork(QContactAddress::ContextWork.operator QString());
   692         QString contextWork(QContactAddress::ContextWork.operator QString());
   629         CntMapTileService::ContactAddressType sourceAddressType 
   693         MapTileService::AddressType sourceAddressType 
   630                                              = CntMapTileService::AddressPreference;
   694                                              = MapTileService::AddressPreference;
   631         
   695         
   632         QString imagePath;
   696         QString imagePath;
   633         
   697         
   634         for ( int i = 0; i < addressDetails.count(); i++ )
   698         for ( int i = 0; i < addressDetails.count(); i++ )
   635         {
   699         {
   636             if ( !addressDetails[i].contexts().isEmpty() && 
   700             if ( !addressDetails[i].contexts().isEmpty() && 
   637                    addressDetails[i].contexts().at(0) == contextHome )
   701                    addressDetails[i].contexts().at(0) == contextHome )
   638             {
   702             {
   639                 sourceAddressType = CntMapTileService::AddressHome;
   703                 sourceAddressType = MapTileService::AddressHome;
   640             }
   704             }
   641             else if ( !addressDetails[i].contexts().isEmpty() && 
   705             else if ( !addressDetails[i].contexts().isEmpty() && 
   642                          addressDetails[i].contexts().at(0) == contextWork )
   706                          addressDetails[i].contexts().at(0) == contextWork )
   643             {
   707             {
   644                 sourceAddressType = CntMapTileService::AddressWork;
   708                 sourceAddressType = MapTileService::AddressWork;
   645             }
   709             }
   646             
   710             
   647             int status = mMaptile->getMapTileImage( 
   711             int status = mMaptile->getMapTileImage( 
   648                                              contactId, 
   712                                              contactId, 
   649                                              sourceAddressType, 
   713                                              sourceAddressType, 
   669 void CntContactCardViewPrivate::setMaptileLabel( HbLabel*& mapLabel, const HbIcon& icon )
   733 void CntContactCardViewPrivate::setMaptileLabel( HbLabel*& mapLabel, const HbIcon& icon )
   670 {
   734 {
   671     mapLabel->clear();
   735     mapLabel->clear();
   672     mapLabel->setIcon( icon );
   736     mapLabel->setIcon( icon );
   673     
   737     
   674     int width = icon.width();
   738 	qreal leftMarginSize;
   675     int height = icon.height();    
   739 	mapLabel->getContentsMargins( &leftMarginSize, 0 , 0 , 0 );
   676                     
   740     mapLabel->setPreferredSize( 
   677     //HbLabel setPreferredSize is not working properly,
   741           QSizeF(icon.width() + leftMarginSize, icon.height()));
   678     //so added minimum , maximum size to fix the issue
   742    
   679     mapLabel->setPreferredSize(QSizeF(width,height));
       
   680     mapLabel->setMinimumSize(QSizeF(width, height));
       
   681     mapLabel->setMaximumSize(QSizeF(width, height));
       
   682     mapLabel->setSizePolicy(QSizePolicy( QSizePolicy::Fixed,
       
   683                         QSizePolicy::Fixed));            
       
   684 }
   743 }
   685 
   744 
   686 /*
   745 /*
   687 * Load the maptile label based on the address type
   746 * Load the maptile label based on the address type
   688 */
   747 */
   689 HbLabel* CntContactCardViewPrivate::loadMaptileLabel( int addressType )
   748 HbLabel* CntContactCardViewPrivate::loadMaptileLabel( int addressType )
   690 {
   749 {
   691     HbLabel* maptileLabel = NULL ;
   750     HbLabel* maptileLabel = NULL;
   692     
   751     
   693     if( addressType == CntMapTileService::AddressPreference )
   752     if( addressType == MapTileService::AddressPreference )
   694     {
   753     {
   695         maptileLabel = static_cast<HbLabel*>(document()->findWidget(QString("maptilePreferenceWidget")));
   754         maptileLabel = static_cast<HbLabel*>(document()->findWidget(QString("maptilePreferenceWidget")));
   696     }
   755     }
   697     else if( addressType == CntMapTileService::AddressHome  )
   756     else if( addressType == MapTileService::AddressHome  )
   698     {
   757     {
   699         maptileLabel  = static_cast<HbLabel*>(document()->findWidget(QString("maptileHomeWidget")));
   758         maptileLabel  = static_cast<HbLabel*>(document()->findWidget(QString("maptileHomeWidget")));
   700     }
   759     }
   701     else if( addressType == CntMapTileService::AddressWork )
   760     else if( addressType == MapTileService::AddressWork )
   702     {
   761     {
   703         maptileLabel  = static_cast<HbLabel*>(document()->findWidget(QString("maptileWorkWidget")));
   762         maptileLabel  = static_cast<HbLabel*>(document()->findWidget(QString("maptileWorkWidget")));
   704     }
   763     }
   705                             
   764                             
   706     return maptileLabel;
   765     return maptileLabel;
   843     if (action == HbMessageBox::Delete)
   902     if (action == HbMessageBox::Delete)
   844     {
   903     {
   845         disconnect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
   904         disconnect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
   846                 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
   905                 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
   847         
   906         
   848         contactManager()->removeContact(mContact->localId());  
   907         bool success = contactManager()->removeContact(mContact->localId());
   849         emit backPressed();  
   908         
       
   909         int returnValue = success ? KCntServicesReturnValueContactDeleted : KCntServicesReturnValueContactNotModified;
       
   910         
       
   911         emit backPressed(returnValue);  
       
   912         
   850         mViewManager->back( mArgs, true );
   913         mViewManager->back( mArgs, true );
   851     }
   914     }
   852 }
   915 }
   853 
   916 
   854 /*!
   917 /*!
   855 Launch history view 
   918 Launch history view 
   856 */
   919 */
   857 void CntContactCardViewPrivate::viewHistory()
   920 void CntContactCardViewPrivate::viewHistory()
   858 {
   921 {
       
   922     // stop the progress timer
       
   923     if ( mProgressTimer && mProgressTimer->isActive())
       
   924     {
       
   925         mProgressTimer->stop();
       
   926     }
       
   927     
   859     QVariant var;
   928     QVariant var;
   860     var.setValue(*mContact);
   929     var.setValue(*mContact);
   861     mArgs.insert(ESelectedContact, var);
   930     mArgs.insert(ESelectedContact, var);
   862     mArgs.insert(EViewId, historyView);
   931     mArgs.insert(EViewId, historyView);
   863         
   932     
   864     mViewManager->changeView( mArgs );
   933     mViewManager->changeView( mArgs );
   865 }
   934 }
   866 
   935 
   867 /*!
   936 /*!
   868 Deactivate the view
   937 Deactivate the view
   869 */
   938 */
   870 void CntContactCardViewPrivate::deactivate()
   939 void CntContactCardViewPrivate::deactivate()
   871 {
   940 {
   872     
       
   873 }
   941 }
   874 
   942 
   875 /*!
   943 /*!
   876 Send the business card / my card 
   944 Send the business card / my card 
   877 */
   945 */
   942 */
  1010 */
   943 void CntContactCardViewPrivate::onItemActivated()
  1011 void CntContactCardViewPrivate::onItemActivated()
   944 {
  1012 {
   945     CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender());
  1013     CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender());
   946     int index = item->index();
  1014     int index = item->index();
       
  1015     CntContactCardDataItem& dataItem = *mDataContainer->dataItem(index);
   947     QString action = mDataContainer->dataItem(index)->action();
  1016     QString action = mDataContainer->dataItem(index)->action();
   948     // Check if action is internal
  1017     CntUiContactCardExtension* extension = dataItem.contactCardExtension();
   949     QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(action, "symbian", 1);
  1018     if (!extension)
   950     if (0 < actionDescriptors.count())
  1019     {
   951     {
  1020         //It's not an extension action.
   952         // These actions are considered internal(vendor=symbian and version=1)
  1021         // Check if action is internal
   953         executeAction(*mContact, mDataContainer->dataItem(index)->detail(), action, item);
  1022         QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(action, "symbian", 1);
   954     }
  1023         if (0 < actionDescriptors.count())
   955     else
  1024         {
   956     {
  1025             // These actions are considered internal(vendor=symbian and version=1)
   957         //Handle dynamic actions differently
  1026             executeAction(*mContact, dataItem.detail(), action, item);
   958         executeDynamicAction(*mContact, mDataContainer->dataItem(index)->detail(), mDataContainer->dataItem(index)->actionDescriptor());
  1027         }
       
  1028         else
       
  1029         {
       
  1030             //Handle dynamic actions differently
       
  1031             executeDynamicAction(*mContact, dataItem.detail(), dataItem.actionDescriptor());
       
  1032         }
       
  1033     } else {
       
  1034         // The action is from an extension
       
  1035         int indexWithinPlugin = dataItem.contactCardExtensionActionIndex();
       
  1036         extension->handleShortPress(indexWithinPlugin);
   959     }
  1037     }
   960 }
  1038 }
   961 
  1039 
   962 /*!
  1040 /*!
   963 Execute the call / message / email action
  1041 Execute the call / message / email action
  1105     else if (action.compare("email", Qt::CaseInsensitive) == 0)
  1183     else if (action.compare("email", Qt::CaseInsensitive) == 0)
  1106     {
  1184     {
  1107         preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_email"));
  1185         preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_email"));
  1108     }
  1186     }
  1109       
  1187       
  1110     if (mContact->isPreferredDetail(action, detail))
  1188     if (mContact->isPreferredDetail(action, detail) && preferredAction)
  1111     {
  1189     {
  1112         preferredAction->setEnabled(false);
  1190         preferredAction->setEnabled(false);
  1113     }
  1191     }
  1114    
  1192    
  1115     if ( communicationAction )
  1193     if ( communicationAction )
  1327             }
  1405             }
  1328             mAvatar->setImageUrl(QUrl());
  1406             mAvatar->setImageUrl(QUrl());
  1329             mImageLabel->clear();
  1407             mImageLabel->clear();
  1330             mImageLabel->setAvatarIcon(HbIcon("qtg_large_add_contact_picture"));
  1408             mImageLabel->setAvatarIcon(HbIcon("qtg_large_add_contact_picture"));
  1331             mHeadingItem->setIcon(HbIcon("qtg_large_add_contact_picture"));
  1409             mHeadingItem->setIcon(HbIcon("qtg_large_add_contact_picture"));
  1332             contactManager()->saveContact(mContact);
  1410             
       
  1411             disconnect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
       
  1412                                 this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
       
  1413             CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, contactManager());
  1333         }
  1414         }
  1334     }
  1415     }
  1335 }
  1416 }
  1336 
  1417 
  1337 /*!
  1418 /*!
  1365 /*!
  1446 /*!
  1366 Return pointer to the contact manager
  1447 Return pointer to the contact manager
  1367 */
  1448 */
  1368 QContactManager* CntContactCardViewPrivate::contactManager()
  1449 QContactManager* CntContactCardViewPrivate::contactManager()
  1369 {
  1450 {
  1370     return mViewManager->contactManager(SYMBIAN_BACKEND);
  1451     return &mEngine->contactManager(SYMBIAN_BACKEND);
  1371 }
  1452 }
  1372 
  1453 
  1373 bool CntContactCardViewPrivate::eventFilter(QObject *obj, QEvent *event)
  1454 bool CntContactCardViewPrivate::eventFilter(QObject *obj, QEvent *event)
  1374 {
  1455 {
  1375     if (event->type() == QEvent::KeyPress && obj == mView->mainWindow())
  1456     if (event->type() == QEvent::KeyPress && obj == mView->mainWindow())
  1378         if (keyEvent->key() == Qt::Key_Yes)
  1459         if (keyEvent->key() == Qt::Key_Yes)
  1379         {
  1460         {
  1380             return sendKeyPressed();
  1461             return sendKeyPressed();
  1381         }
  1462         }
  1382     }
  1463     }
       
  1464     
       
  1465     // Update the contact only when the application is in the backgound
       
  1466     // This avoids flickering when the contact card is in focus
       
  1467     if ( event->type() == QEvent::ApplicationActivate ) 
       
  1468     {
       
  1469         CNT_LOG_ARGS("app activated")
       
  1470 
       
  1471         disconnect(contactManager(), SIGNAL(contactsChanged(const QList<QContactLocalId>&)),
       
  1472                 this, SLOT(contactUpdatedFromOtherSource(const QList<QContactLocalId>&)));
       
  1473         
       
  1474         QContact c = contactManager()->contact(mContact->localId());
       
  1475         
       
  1476         QContactTimestamp latestTimeStamp = c.detail<QContactTimestamp>();
       
  1477         QContactTimestamp localTimeStamp = mContact->detail<QContactTimestamp>();
       
  1478         
       
  1479         // Once we regain focus check if the contact was modified in the background
       
  1480         if (contactManager()->error() == QContactManager::NoError 
       
  1481             && latestTimeStamp.lastModified() > localTimeStamp.lastModified())
       
  1482         {
       
  1483             if (mContact)
       
  1484                 delete mContact;
       
  1485             mContact = new QContact(c);
       
  1486                 
       
  1487             populateHeadingItem();
       
  1488             populateListItems();
       
  1489         }
       
  1490     }
       
  1491     
       
  1492     if ( event->type() == QEvent::ApplicationDeactivate )
       
  1493     {
       
  1494         CNT_LOG_ARGS("app deactivated")
       
  1495 
       
  1496         connect(contactManager(), SIGNAL(contactsChanged(const QList<QContactLocalId>&)), 
       
  1497             this, SLOT(contactUpdatedFromOtherSource(const QList<QContactLocalId>&)), Qt::UniqueConnection);
       
  1498     }
       
  1499     
  1383     return false;
  1500     return false;
  1384 }
  1501 }
  1385 
  1502 
  1386 bool CntContactCardViewPrivate::sendKeyPressed()
  1503 bool CntContactCardViewPrivate::sendKeyPressed()
  1387 {   
  1504 {   
  1448         // not updated properly if this is not done in the event loop
  1565         // not updated properly if this is not done in the event loop
  1449         QTimer::singleShot(0, this, SLOT(showRootView()));
  1566         QTimer::singleShot(0, this, SLOT(showRootView()));
  1450     }
  1567     }
  1451 }
  1568 }
  1452 
  1569 
       
  1570 void CntContactCardViewPrivate::contactUpdatedFromOtherSource(const QList<QContactLocalId>& contactIds)
       
  1571 {
       
  1572     if ( contactIds.contains(mContact->localId()) )
       
  1573     {
       
  1574         QContact c = contactManager()->contact(mContact->localId());
       
  1575         if (contactManager()->error() == QContactManager::NoError)
       
  1576         {
       
  1577             if (mContact)
       
  1578                 delete mContact;
       
  1579             mContact = new QContact(c);
       
  1580             
       
  1581             populateHeadingItem();
       
  1582             populateListItems();
       
  1583         }
       
  1584     }
       
  1585 }
       
  1586 
  1453 // end of file
  1587 // end of file