phonebookui/pbkcommonui/src/cntcontactcardview_p.cpp
changeset 37 fd64c38c277d
parent 31 2a11b5b00470
child 40 b46a585f6909
equal deleted inserted replaced
31:2a11b5b00470 37:fd64c38c277d
    17 #include "cntcontactcardview_p.h"
    17 #include "cntcontactcardview_p.h"
    18 
    18 
    19 #include <QGraphicsLinearLayout>
    19 #include <QGraphicsLinearLayout>
    20 #include <QGraphicsSceneResizeEvent>
    20 #include <QGraphicsSceneResizeEvent>
    21 #include <QStringList>
    21 #include <QStringList>
       
    22 #include <QDebug>
       
    23 
    22 #include <qtcontacts.h>
    24 #include <qtcontacts.h>
    23 #include <hbscrollarea.h>
    25 #include <hbscrollarea.h>
    24 #include <hblabel.h>
    26 #include <hblabel.h>
    25 #include <hbmenu.h>
    27 #include <hbmenu.h>
    26 #include <hbview.h>
    28 #include <hbview.h>
    36 #include <thumbnailmanager_qt.h>
    38 #include <thumbnailmanager_qt.h>
    37 #include <cntmaptileservice.h>  //For maptile processing
    39 #include <cntmaptileservice.h>  //For maptile processing
    38 #include <qversitcontactexporter.h>
    40 #include <qversitcontactexporter.h>
    39 #include <qversitwriter.h>
    41 #include <qversitwriter.h>
    40 #include <xqservicerequest.h>
    42 #include <xqservicerequest.h>
       
    43 
    41 #include "cntcontactcarddatacontainer.h"
    44 #include "cntcontactcarddatacontainer.h"
    42 #include "cntcontactcarddetailitem.h"
    45 #include "cntcontactcarddetailitem.h"
    43 #include "cntcontactcardheadingitem.h"
    46 #include "cntcontactcardheadingitem.h"
    44 #include "cntcontactcarddataitem.h"
    47 #include "cntcontactcarddataitem.h"
    45 #include "cntcontactcardcontextmenu.h"
    48 #include "cntcontactcardcontextmenu.h"
    46 #include "cntmainwindow.h"
    49 #include "cntmainwindow.h"
    47 #include "cntstringmapper.h"
    50 #include "cntstringmapper.h"
    48 #include "cntdocumentloader.h"
    51 #include "cntdocumentloader.h"
    49 #include "cntimagelabel.h"
    52 #include "cntimagelabel.h"
    50 #include "cntimageutility.h"
    53 #include "cntimageutility.h"
       
    54 #include "cntfavourite.h"
    51 
    55 
    52 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
    56 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
    53 
    57 
    54 /*!
    58 /*!
    55 Constructor, initialize member variables.
    59 Constructor, initialize member variables.
    63     mContact(NULL),
    67     mContact(NULL),
    64     mDetailsWidget(NULL),
    68     mDetailsWidget(NULL),
    65     mDataContainer(NULL),
    69     mDataContainer(NULL),
    66     mHeadingItem(NULL),
    70     mHeadingItem(NULL),
    67     mThumbnailManager(NULL),
    71     mThumbnailManager(NULL),
    68     mGroupContact(NULL),
       
    69     mAvatar(NULL),
    72     mAvatar(NULL),
    70     mIsGroupMember(false),
       
    71     mIsHandlingMenu(false),
    73     mIsHandlingMenu(false),
    72     mIsPreviousImageEditorView(false),
       
    73     mFavoriteGroupId(-1),
    74     mFavoriteGroupId(-1),
    74     mLoader(NULL),
    75     mLoader(NULL),
    75     mContactAction(NULL),
    76     mContactAction(NULL),
    76     mBackKey(NULL),
    77     mBackKey(NULL),
    77     mImageLabel(NULL),
    78     mImageLabel(NULL),
   109     mContact = 0;
   110     mContact = 0;
   110     
   111     
   111     delete mDataContainer;
   112     delete mDataContainer;
   112     mDataContainer = NULL;
   113     mDataContainer = NULL;
   113     
   114     
   114     delete mGroupContact;
       
   115     mGroupContact = NULL;
       
   116     
       
   117     delete mAvatar;
   115     delete mAvatar;
   118     mAvatar = NULL;
   116     mAvatar = NULL;
   119     
   117     
   120     delete mLoader;
   118     delete mLoader;
   121     mLoader = NULL;
   119     mLoader = NULL;
   129 */
   127 */
   130 void CntContactCardViewPrivate::showPreviousView()
   128 void CntContactCardViewPrivate::showPreviousView()
   131 {
   129 {
   132     emit backPressed();
   130     emit backPressed();
   133     
   131     
   134     //save an avatar
   132     //save the contact if avatar has been changed.
   135     if (mIsPreviousImageEditorView)
   133     QContact contact = contactManager()->contact(mContact->localId());
       
   134     if ( contact != *mContact )
   136     {
   135     {
   137         QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   136         QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   138         for (int i = 0; i < details.count(); i++)
   137         for (int i = 0; i < details.count(); i++)
   139         {
   138         {
   140             if (!details.at(i).imageUrl().isEmpty())
   139             if (!details.at(i).imageUrl().isEmpty())
   143                 break;
   142                 break;
   144             }
   143             }
   145         }
   144         }
   146     }
   145     }
   147        
   146        
   148     CntViewParameters viewParameters;
   147     mViewManager->back( mArgs );
   149     if (mIsGroupMember)
       
   150     {
       
   151         QVariant var;
       
   152         var.setValue(*mGroupContact);
       
   153         viewParameters.insert(ESelectedContact, var);
       
   154     }
       
   155     mViewManager->back(viewParameters);
       
   156 }
   148 }
   157 
   149 
   158 /*
   150 /*
   159 Activates a default view and setup name label texts
   151 Activates a default view and setup name label texts
   160 */
   152 */
   161 void CntContactCardViewPrivate::activate(CntAbstractViewManager* aMgr, const CntViewParameters aArgs)
   153 void CntContactCardViewPrivate::activate(CntAbstractViewManager* aMgr, const CntViewParameters aArgs)
   162 {   
   154 {   
       
   155     mViewManager = aMgr;
       
   156     mArgs = aArgs;
       
   157     
   163     mView->installEventFilter(this);
   158     mView->installEventFilter(this);
   164     
       
   165     mViewManager = aMgr;
       
   166     
   159     
   167     HbMainWindow* window = mView->mainWindow();
   160     HbMainWindow* window = mView->mainWindow();
   168     connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
   161     connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
   169     setOrientation(window->orientation());
   162     setOrientation(window->orientation());
   170         
   163         
   171     if (aArgs.value(ECustomParam).toInt() == imageEditorView)
       
   172     {    
       
   173         mIsPreviousImageEditorView = true;   
       
   174     }
       
   175     
       
   176     QContact contact = aArgs.value(ESelectedContact).value<QContact>();
   164     QContact contact = aArgs.value(ESelectedContact).value<QContact>();
   177     mContact = new QContact(contact);
   165     mContact = new QContact( contact );
   178 
       
   179     //my card
   166     //my card
   180     if (mContact->localId() == contactManager()->selfContactId())
   167     bool myCard = mContact->localId() == contactManager()->selfContactId();
       
   168     if (myCard)
   181     {
   169     {
   182         mView->menu()->clearActions();
   170         mView->menu()->clearActions();
   183         mView->toolBar()->removeAction(static_cast<HbAction*>(document()->findObject(QString("cnt:history"))));
   171         mView->toolBar()->removeAction(static_cast<HbAction*>(document()->findObject(QString("cnt:history"))));
   184     }
   172     }
   185     else
   173     else
   186     {
   174     {
   187         mView->toolBar()->removeAction(static_cast<HbAction*>(document()->findObject(QString("cnt:sendMyCard"))));
   175         mView->toolBar()->removeAction(static_cast<HbAction*>(document()->findObject(QString("cnt:sendMyCard"))));
   188     }
   176     }
   189     
   177     
   190     if (aArgs.value(ESelectedAction).toString() == "FromGroupMemberView")
       
   191     {
       
   192         mIsGroupMember = true;
       
   193         QContact groupContact = aArgs.value(ESelectedGroupContact).value<QContact>();
       
   194         mGroupContact = new QContact(groupContact);
       
   195     }
       
   196     // add heading widget to the content
   178     // add heading widget to the content
   197     QGraphicsWidget *c = document()->findWidget(QString("content"));
   179     QGraphicsWidget *c = document()->findWidget(QString("content"));
   198     QGraphicsLinearLayout* l = static_cast<QGraphicsLinearLayout*>(c->layout());
   180     QGraphicsLinearLayout* l = static_cast<QGraphicsLinearLayout*>(c->layout());
   199 
   181 
   200     mHeadingItem = static_cast<CntContactCardHeadingItem*>(document()->findWidget(QString("cnt_contactcard_heading")));
   182     mHeadingItem = static_cast<CntContactCardHeadingItem*>(document()->findWidget(QString("cnt_contactcard_heading")));
   201     mHeadingItem->setDetails(mContact);
   183     mHeadingItem->setDetails(mContact);
   202     mHeadingItem->setSecondaryIcon(isFavoriteGroupContact());
       
   203     
       
   204     connect(mHeadingItem, SIGNAL(passLongPressed(const QPointF&)), this, SLOT(drawMenu(const QPointF&)));
   184     connect(mHeadingItem, SIGNAL(passLongPressed(const QPointF&)), this, SLOT(drawMenu(const QPointF&)));
       
   185     connect(mHeadingItem, SIGNAL(passShortPressed(const QPointF&)), this, SLOT(doChangeImage()));
   205 
   186 
   206     mImageLabel = static_cast<CntImageLabel*>(document()->findWidget("cnt_contactcard_image"));
   187     mImageLabel = static_cast<CntImageLabel*>(document()->findWidget("cnt_contactcard_image"));
   207     connect(mImageLabel, SIGNAL(iconClicked()), this, SLOT(doChangeImage()));
   188     connect(mImageLabel, SIGNAL(iconClicked()), this, SLOT(doChangeImage()));
       
   189     connect(mImageLabel, SIGNAL(iconLongPressed(const QPointF&)), this, SLOT(drawMenu(const QPointF&)));
   208     
   190     
   209     // avatar
   191     // avatar
   210     QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   192     QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   211     for (int i = 0;i < details.count();i++)
   193     for (int i = 0;i < details.count();i++)
   212     {
   194     {
   217             break;
   199             break;
   218         }
   200         }
   219     }
   201     }
   220     
   202     
   221     // data
   203     // data
   222     mDataContainer = new CntContactCardDataContainer(mContact);
   204     mDataContainer = new CntContactCardDataContainer(mContact, NULL, myCard);
   223 
   205 
   224     // scroll area + container widget
   206     // scroll area + container widget
   225     mScrollArea = static_cast<HbScrollArea*>(document()->findWidget(QString("scrollArea")));
   207     mScrollArea = static_cast<HbScrollArea*>(document()->findWidget(QString("scrollArea")));
   226     mScrollArea->setScrollDirections(Qt::Vertical);
   208     mScrollArea->setScrollDirections(Qt::Vertical);
   227     mContainerWidget = new QGraphicsWidget(mScrollArea);
   209     mContainerWidget = new QGraphicsWidget(mScrollArea);
   294                 mContainerLayout->addItem(item);
   276                 mContainerLayout->addItem(item);
   295             }
   277             }
   296         }
   278         }
   297     }
   279     }
   298     
   280     
   299     bool setAsFavorite = false;
   281     bool setAsFavorite( false );
   300     if(isFavoriteGroupCreated())
   282     QContactLocalId favouriteGroupId = CntFavourite::favouriteGroupId( contactManager() );
   301     {
   283     if( favouriteGroupId != 0 )
   302         QContact favoriteGroup = contactManager()->contact(mFavoriteGroupId);
   284     {
   303         // Use relationship filter to get list of contacts in the relationship (if any)
   285         setAsFavorite = CntFavourite::isMemberOfFavouriteGroup( contactManager(), mContact );
   304         QContactRelationshipFilter filter;
   286         mHeadingItem->setSecondaryIcon( setAsFavorite ); // if contact is part of favourites group
   305         filter.setRelationshipType(QContactRelationship::HasMember);
   287     }
   306         filter.setRelatedContactRole(QContactRelationship::First); 
   288     qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite );
   307         filter.setRelatedContactId(favoriteGroup.id());
   289     qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
   308         
       
   309         QList<QContactLocalId> mContactsList = contactManager()->contactIds(filter);
       
   310         int count = mContactsList.count();
       
   311         if (count)
       
   312         {
       
   313             for (int i = 0 ; i < count ; i++)
       
   314             {
       
   315                 if (mContactsList.at(i) == mContact->localId())
       
   316                 {
       
   317                 setAsFavorite = true;
       
   318                 }
       
   319             }
       
   320         }
       
   321     }
       
   322     
       
   323     if (setAsFavorite)
       
   324     {
       
   325         qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(false);
       
   326     }
       
   327     else
       
   328     {
       
   329         qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(false);
       
   330     }
       
   331         
   290         
   332     // Menu items
   291     // Menu items
   333     connect(qobject_cast<HbAction *>(document()->findObject("cnt:sendbusinesscard")), SIGNAL(triggered()),
   292     connect(qobject_cast<HbAction *>(document()->findObject("cnt:sendbusinesscard")), SIGNAL(triggered()),
   334                 this, SLOT (sendBusinessCard()));
   293                 this, SLOT (sendBusinessCard()));
   335     connect(qobject_cast<HbAction *>(document()->findObject("cnt:deletecontact")), SIGNAL(triggered()),
   294     connect(qobject_cast<HbAction *>(document()->findObject("cnt:deletecontact")), SIGNAL(triggered()),
   347     connect(qobject_cast<HbAction *>(document()->findObject("cnt:history")), SIGNAL(triggered()),
   306     connect(qobject_cast<HbAction *>(document()->findObject("cnt:history")), SIGNAL(triggered()),
   348                 this, SLOT(viewHistory()));
   307                 this, SLOT(viewHistory()));
   349     connect(qobject_cast<HbAction *>(document()->findObject("cnt:sendMyCard")), SIGNAL(triggered()),
   308     connect(qobject_cast<HbAction *>(document()->findObject("cnt:sendMyCard")), SIGNAL(triggered()),
   350                 this, SLOT (sendBusinessCard()));
   309                 this, SLOT (sendBusinessCard()));
   351  
   310  
   352     emit viewActivated(*mContact, aArgs.value(ESelectedDetail).value<QContactDetail>());
   311     emit viewActivated( mViewManager, aArgs );
   353 }
   312 }
   354 
   313 
   355 void CntContactCardViewPrivate::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
   314 void CntContactCardViewPrivate::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
   356 {
   315 {
   357     Q_UNUSED(data);
   316     Q_UNUSED(data);
   386 /*!
   345 /*!
   387 Launch contact editor 
   346 Launch contact editor 
   388 */
   347 */
   389 void CntContactCardViewPrivate::editContact()
   348 void CntContactCardViewPrivate::editContact()
   390 {
   349 {
   391     CntViewParameters viewParameters;
       
   392     viewParameters.insert(EViewId, editView);
       
   393     QVariant var;
   350     QVariant var;
   394     var.setValue(*mContact);
   351     var.setValue(*mContact);
   395     viewParameters.insert(ESelectedContact, var);
   352     
   396     mViewManager->changeView(viewParameters);
   353     mArgs.insert(ESelectedContact, var);
       
   354     mArgs.insert(EViewId, editView);
       
   355     
       
   356     mViewManager->changeView( mArgs );
   397 }
   357 }
   398 
   358 
   399 void CntContactCardViewPrivate::addToGroup()
   359 void CntContactCardViewPrivate::addToGroup()
   400 {
   360 {
   401 }
   361 }
   402 
   362 
   403 void CntContactCardViewPrivate::setAsFavorite()
   363 void CntContactCardViewPrivate::setAsFavorite()
   404 {
   364 {
   405     QContact favoriteGroup;
   365     QContactId id = mContact->id();
   406     if (!isFavoriteGroupCreated() )
   366     CntFavourite::addContactToFavouriteGroup( contactManager(), id );
   407     {
   367     
   408         //Create Fav grp
   368     qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(true);
   409         favoriteGroup.setType(QContactType::TypeGroup);
       
   410         QContactName favoriteGroupName;
       
   411         favoriteGroupName.setCustomLabel("Favorites");
       
   412         favoriteGroup.saveDetail(&favoriteGroupName);
       
   413         contactManager()->saveContact(&favoriteGroup);
       
   414         mFavoriteGroupId = favoriteGroup.localId();
       
   415     }
       
   416     else
       
   417     {
       
   418         favoriteGroup = contactManager()->contact(mFavoriteGroupId);
       
   419     }
       
   420     
       
   421     // new contact added to the favorite group
       
   422     QContactRelationship relationship;
       
   423     relationship.setRelationshipType(QContactRelationship::HasMember);
       
   424     relationship.setFirst(favoriteGroup.id());
       
   425     relationship.setSecond(mContact->id());
       
   426     // save relationship
       
   427     contactManager()->saveRelationship(&relationship);
       
   428     
       
   429     qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(false);
   369     qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(false);
   430     qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(true);
       
   431     mHeadingItem->setSecondaryIcon(true);  
   370     mHeadingItem->setSecondaryIcon(true);  
   432 }
   371 }
   433 
   372 
   434 void CntContactCardViewPrivate::removeFromFavorite()
   373 void CntContactCardViewPrivate::removeFromFavorite()
   435 {
   374 {
   436     QContact favoriteGroup = contactManager()->contact(mFavoriteGroupId);
   375     QContactId id = mContact->id();   
   437     QContactRelationship relationship;
   376     CntFavourite::removeContactFromFavouriteGroup( contactManager(), id );
   438     relationship.setRelationshipType(QContactRelationship::HasMember);
       
   439     relationship.setFirst(favoriteGroup.id());
       
   440     relationship.setSecond(mContact->id());
       
   441     contactManager()->removeRelationship(relationship);
       
   442 
   377 
   443     qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(false);
   378     qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(false);
   444     qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(true);
   379     qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(true);
   445     mHeadingItem->setSecondaryIcon(false); 
   380     mHeadingItem->setSecondaryIcon(false); 
   446 }
   381 }
   464     HbMessageBox *note = static_cast<HbMessageBox*>(sender());
   399     HbMessageBox *note = static_cast<HbMessageBox*>(sender());
   465     
   400     
   466     if (note && action == note->actions().first())
   401     if (note && action == note->actions().first())
   467     {
   402     {
   468         contactManager()->removeContact(mContact->localId());
   403         contactManager()->removeContact(mContact->localId());
   469         CntViewParameters viewParameters;
   404         mArgs.insert(EViewId, namesView);
   470         viewParameters.insert(EViewId, namesView);
   405         mViewManager->changeView( mArgs );
   471         mViewManager->changeView(viewParameters);
       
   472     }
   406     }
   473 }
   407 }
   474 
   408 
   475 /*!
   409 /*!
   476 Launch history view 
   410 Launch history view 
   477 */
   411 */
   478 void CntContactCardViewPrivate::viewHistory()
   412 void CntContactCardViewPrivate::viewHistory()
   479 {
   413 {
   480     CntViewParameters viewParameters;
       
   481     viewParameters.insert(EViewId, historyView);
       
   482     QVariant var;
   414     QVariant var;
   483     var.setValue(*mContact);
   415     var.setValue(*mContact);
   484     viewParameters.insert(ESelectedContact, var);
   416     mArgs.insert(ESelectedContact, var);
   485     mViewManager->changeView(viewParameters);
   417     mArgs.insert(EViewId, historyView);
       
   418         
       
   419     mViewManager->changeView( mArgs );
   486 }
   420 }
   487 
   421 
   488 /*!
   422 /*!
   489 Deactivate the view
   423 Deactivate the view
   490 */
   424 */
   496 /*!
   430 /*!
   497 Send the business card / my card 
   431 Send the business card / my card 
   498 */
   432 */
   499 void CntContactCardViewPrivate::sendBusinessCard()
   433 void CntContactCardViewPrivate::sendBusinessCard()
   500 {
   434 {
       
   435     qDebug() << "CntContactCardViewPrivate::sendBusinessCard - IN";
   501     // Check if the contact has an image.
   436     // Check if the contact has an image.
   502     QList<QContactAvatar> avatars = mContact->details<QContactAvatar>();
   437     QList<QContactAvatar> avatars = mContact->details<QContactAvatar>();
   503     bool imageExists( false );
   438     bool imageExists( false );
   504     foreach(QContactAvatar a, mContact->details<QContactAvatar>())
   439     foreach(QContactAvatar a, mContact->details<QContactAvatar>())
   505     {
   440     {
   527         }
   462         }
   528     }
   463     }
   529     
   464     
   530     if ( !imageExists )
   465     if ( !imageExists )
   531     {
   466     {
       
   467         qDebug() << "CntContactCardViewPrivate::sendBusinessCard without image";
   532         handleSendBusinessCard( NULL ); // no image
   468         handleSendBusinessCard( NULL ); // no image
   533     }
   469     }
       
   470     qDebug() << "CntContactCardViewPrivate::sendBusinessCard - OUT";
   534 }
   471 }
   535 
   472 
   536 /*!
   473 /*!
   537 Set orientation of the view
   474 Set orientation of the view
   538 */
   475 */
   555 */
   492 */
   556 void CntContactCardViewPrivate::onItemActivated()
   493 void CntContactCardViewPrivate::onItemActivated()
   557 {
   494 {
   558     CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender());
   495     CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender());
   559     int index = item->index();
   496     int index = item->index();
   560     launchAction(*mContact, mDataContainer->dataItem(index)->detail(), mDataContainer->dataItem(index)->action());
   497     QString action = mDataContainer->dataItem(index)->action();
       
   498     // Check if action is internal
       
   499     QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(action, "symbian", 1);
       
   500     if(0 < actionDescriptors.count())
       
   501     {
       
   502         // These actions are considered internal(vendor=symbian and version=1)
       
   503         launchAction(*mContact, mDataContainer->dataItem(index)->detail(), action);
       
   504     }
       
   505     else
       
   506     {
       
   507         //Handle dynamic actions differently
       
   508         launchDynamicAction(*mContact, mDataContainer->dataItem(index)->detail(), mDataContainer->dataItem(index)->actionDescriptor());
       
   509     }
   561 }
   510 }
   562 
   511 
   563 /*!
   512 /*!
   564 Launch the call / message / email action
   513 Launch the call / message / email action
   565 */
   514 */
   575     connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
   524     connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
   576                 this, SLOT(progress(QContactAction::State)));
   525                 this, SLOT(progress(QContactAction::State)));
   577     mContactAction->invokeAction(contact, detail);
   526     mContactAction->invokeAction(contact, detail);
   578 }
   527 }
   579 
   528 
       
   529 /*!
       
   530 Launch dynamic action
       
   531 */
       
   532 void CntContactCardViewPrivate::launchDynamicAction(QContact contact, QContactDetail detail, QContactActionDescriptor actionDescriptor)
       
   533 {
       
   534     // detail might be empty -> in that case engine uses the preferred detail for the selected action
       
   535     mContactAction = QContactAction::action(actionDescriptor);
       
   536     connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
       
   537                 this, SLOT(progress(QContactAction::State)));
       
   538     mContactAction->invokeAction(contact, detail);
       
   539 }
       
   540 
   580 void CntContactCardViewPrivate::progress(QContactAction::State status)
   541 void CntContactCardViewPrivate::progress(QContactAction::State status)
   581 {
   542 {
   582     switch(status)
   543     switch(status)
   583     {
   544     {
   584     case QContactAction::FinishedState:
   545     case QContactAction::FinishedState:
   585     case QContactAction::FinishedWithErrorState:
   546     case QContactAction::FinishedWithErrorState:
   586         mContactAction->deleteLater();
   547         mContactAction->deleteLater();
   587         mContactAction = 0;
       
   588         break;
   548         break;
   589     default:
   549     default:
   590         break;
   550         break;
   591     }
   551     }
   592 }
   552 }
   608     CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender());
   568     CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender());
   609     int index = item->index();
   569     int index = item->index();
   610     
   570     
   611     CntContactCardContextMenu *menu = new CntContactCardContextMenu( item );
   571     CntContactCardContextMenu *menu = new CntContactCardContextMenu( item );
   612     HbAction *communicationAction = 0;
   572     HbAction *communicationAction = 0;
       
   573     HbAction *dynamicAction = 0;
   613     HbAction *videoCommunicationAction = 0;
   574     HbAction *videoCommunicationAction = 0;
   614     HbAction *preferredAction = 0;
   575     HbAction *preferredAction = 0;
   615     CntStringMapper stringMapper;
   576     CntStringMapper stringMapper;
   616     
   577     
   617     QString action = mDataContainer->dataItem(index)->action();
   578     QString action = mDataContainer->dataItem(index)->action();
   627             QString subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first();
   588             QString subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first();
   628 
   589 
   629             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(subtype, context));
   590             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(subtype, context));
   630    
   591    
   631             // TODO : uncomment next line when videotelephony is released
   592             // TODO : uncomment next line when videotelephony is released
   632             //videoCommunicationAction = menu->addAction(QString("VideoCall"));
   593             Q_UNUSED(videoCommunicationAction)
       
   594             //videoCommunicationAction = menu->addAction(QString("txt_phob_menu_call_video_number"));
   633         }        
   595         }        
   634     }
   596     }
   635     else if (action.compare("message", Qt::CaseInsensitive) == 0)
   597     else if (action.compare("message", Qt::CaseInsensitive) == 0)
   636     {
   598     {
   637         communicationAction = menu->addAction(hbTrId("txt_phob_menu_send_message"));
   599         communicationAction = menu->addAction(hbTrId("txt_phob_menu_send_message"));
   643             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), detail.contexts().first()));
   605             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), detail.contexts().first()));
   644         }
   606         }
   645         else
   607         else
   646         {
   608         {
   647             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), QString()));
   609             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), QString()));
   648         }        
   610         }
       
   611     }
       
   612     else if (action.compare("url", Qt::CaseInsensitive) == 0)
       
   613     {
       
   614         if (!detail.contexts().isEmpty())
       
   615         {
       
   616             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), detail.contexts().first()));
       
   617         }
       
   618         else
       
   619         {
       
   620             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), QString()));
       
   621         }
       
   622     }
       
   623     else if (1 > QContactAction::actionDescriptors(action, "symbian", 1).count())
       
   624     {
       
   625         // Do verification that action is not internal type(vendor=symbian and version=1)
       
   626         // If hard coded action is not found, fetch localization from dynamic action
       
   627         // and create dynamic action item.
       
   628         dynamicAction = menu->addAction(mDataContainer->dataItem(index)->longPressText());
   649     }
   629     }
   650     
   630     
   651     if (action.compare("call", Qt::CaseInsensitive) == 0)
   631     if (action.compare("call", Qt::CaseInsensitive) == 0)
   652     {
   632     {
   653         preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_number"));
   633         preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_number"));
   667     }
   647     }
   668    
   648    
   669     if ( communicationAction )
   649     if ( communicationAction )
   670     {
   650     {
   671         communicationAction->setObjectName( "communicationAction" );
   651         communicationAction->setObjectName( "communicationAction" );
       
   652     }
       
   653    
       
   654     if ( dynamicAction )
       
   655     {
       
   656         dynamicAction->setObjectName( "dynamicAction" );
   672     }
   657     }
   673     
   658     
   674     if ( preferredAction )
   659     if ( preferredAction )
   675     {
   660     {
   676         preferredAction->setObjectName( "preferredAction" );
   661         preferredAction->setObjectName( "preferredAction" );
   695     
   680     
   696     if ( name == "communicationAction" )
   681     if ( name == "communicationAction" )
   697     {
   682     {
   698         launchAction( *mContact, detail, action );
   683         launchAction( *mContact, detail, action );
   699     }
   684     }
       
   685 
       
   686     if ( name == "dynamicAction" )
       
   687     {             
       
   688         launchDynamicAction(*mContact, detail, mDataContainer->dataItem(index)->actionDescriptor());
       
   689     }
   700     
   690     
   701     if ( name == "preferredAction" )
   691     if ( name == "preferredAction" )
   702     {
   692     {
   703         setPreferredAction(action, detail);
   693         setPreferredAction(action, detail);
   704                     
   694                     
   716     }
   706     }
   717 }
   707 }
   718 
   708 
   719 void CntContactCardViewPrivate::handleSendBusinessCard( HbAction* aAction )
   709 void CntContactCardViewPrivate::handleSendBusinessCard( HbAction* aAction )
   720 {
   710 {
       
   711     qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard - IN";
   721     QList<QContact> list;
   712     QList<QContact> list;
   722     if ( aAction && aAction->objectName() == "cancel" )
   713     if ( aAction && aAction->objectName() == "cancel" )
   723     {
   714     {
   724         QContact tmpContact( *mContact );
   715         QContact tmpContact( *mContact );
   725         foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() )
   716         foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() )
   760     vCardPath.append(vCardName);
   751     vCardPath.append(vCardName);
   761     vCardPath = QDir::toNativeSeparators(vCardPath);
   752     vCardPath = QDir::toNativeSeparators(vCardPath);
   762         
   753         
   763     QVersitContactExporter exporter;
   754     QVersitContactExporter exporter;
   764     // The vCard version needs to be 2.1 due to backward compatiblity when sending 
   755     // The vCard version needs to be 2.1 due to backward compatiblity when sending 
   765     if (!exporter.exportContacts(list, QVersitDocument::VCard21Type))
   756     if (exporter.exportContacts(list, QVersitDocument::VCard21Type))
   766     {
   757     {
   767             
   758         qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard, VCard21Type";
   768         QList<QVersitDocument> docs = exporter.documents();
   759         QList<QVersitDocument> docs = exporter.documents();
   769         QFile f(vCardPath);
   760         QFile f(vCardPath);
   770         if ( f.open(QIODevice::WriteOnly) ) 
   761         if ( f.open(QIODevice::WriteOnly) ) 
   771         {
   762         {
       
   763             qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard write VCard";
   772             // Start creating the vCard
   764             // Start creating the vCard
   773             QVersitWriter writer;
   765             QVersitWriter writer;
   774             writer.setDevice(&f);
   766             writer.setDevice(&f);
   775         
   767         
   776             bool ret = writer.startWriting(docs);
   768             bool ret = writer.startWriting(docs);
   781             QStringList l;
   773             QStringList l;
   782             l << vCardPath;
   774             l << vCardPath;
   783             s.send(l,false);
   775             s.send(l,false);
   784         }
   776         }
   785     }
   777     }
       
   778     qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard - OUT";
   786 }
   779 }
   787 
   780 
   788 /*!
   781 /*!
   789 Event filter for green key
   782 Event filter for green key
   790 */
   783 */
   802         {
   795         {
   803             launchAction(*mContact, QContactDetail(), "call");
   796             launchAction(*mContact, QContactDetail(), "call");
   804         }
   797         }
   805         return true;
   798         return true;
   806     }
   799     }
   807     else if (event->type() == QEvent::LayoutRequest && mScrollArea)
       
   808     {
       
   809         mContainerWidget->resize(mScrollArea->size().width(), mScrollArea->size().height());
       
   810         return true;
       
   811     }
       
   812     else
   800     else
   813     {
   801     {
   814         return QObject::eventFilter(obj,event);
   802         return QObject::eventFilter(obj,event);
   815     }
   803     }
   816 }
   804 }
   819 Called after the user clicked "Change Image" from popup menu after 
   807 Called after the user clicked "Change Image" from popup menu after 
   820 longpressing the image in this view.
   808 longpressing the image in this view.
   821 */
   809 */
   822 void CntContactCardViewPrivate::doChangeImage()
   810 void CntContactCardViewPrivate::doChangeImage()
   823 {
   811 {
   824     CntViewParameters viewParameters;
       
   825     viewParameters.insert(EViewId, imageEditorView);
       
   826     QVariant var;
   812     QVariant var;
   827     var.setValue(*mContact);
   813     var.setValue(*mContact);
   828     viewParameters.insert(ESelectedContact, var);
   814     
   829     mViewManager->changeView(viewParameters);
   815     mArgs.insert(ESelectedContact, var);
       
   816     mArgs.insert(EViewId, imageEditorView);
       
   817         
       
   818     mViewManager->changeView( mArgs );
   830 }
   819 }
   831 
   820 
   832 /*!
   821 /*!
   833 Called after the user clicked "Remove Image" from popup menu after 
   822 Called after the user clicked "Remove Image" from popup menu after 
   834 longpressing the image in this view.
   823 longpressing the image in this view.
   869     // multiple emitted signals, set state that we are handling the signal
   858     // multiple emitted signals, set state that we are handling the signal
   870     mIsHandlingMenu = true;
   859     mIsHandlingMenu = true;
   871     
   860     
   872     HbMenu *menu = new HbMenu();
   861     HbMenu *menu = new HbMenu();
   873     menu->addAction(hbTrId("txt_phob_menu_change_picture"), this, SLOT(doChangeImage()) );
   862     menu->addAction(hbTrId("txt_phob_menu_change_picture"), this, SLOT(doChangeImage()) );
   874     menu->addAction(hbTrId("txt_phob_menu_remove_image"), this, SLOT(doRemoveImage()) );
   863     if (mAvatar)
   875  
   864     {
       
   865         menu->addAction(hbTrId("txt_phob_menu_remove_image"), this, SLOT(doRemoveImage()) );
       
   866     }
   876     menu->setAttribute( Qt::WA_DeleteOnClose );
   867     menu->setAttribute( Qt::WA_DeleteOnClose );
   877     menu->setPreferredPos( aCoords );
   868     menu->setPreferredPos( aCoords );
   878     menu->open();
   869     menu->open();
   879     }
   870     }
   880 
   871 
   881 /*!
   872 /*!
   882 Check if the favourite group created
       
   883 */
       
   884 bool CntContactCardViewPrivate::isFavoriteGroupCreated()
       
   885 {
       
   886     bool favoriteGroupCreated = false;
       
   887     QContactDetailFilter groupFilter;
       
   888     groupFilter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
       
   889     groupFilter.setValue(QString(QLatin1String(QContactType::TypeGroup)));
       
   890 
       
   891     QList<QContactLocalId> groupContactIds = contactManager()->contactIds(groupFilter);
       
   892     
       
   893     if (!groupContactIds.isEmpty())
       
   894     {
       
   895         for(int i = 0;i < groupContactIds.count();i++)
       
   896         {
       
   897             QContact contact = contactManager()->contact(groupContactIds.at(i));
       
   898             QContactName contactName = contact.detail<QContactName>();
       
   899             QString groupName = contactName.customLabel();
       
   900             if(groupName.compare("Favorites") == 0)
       
   901             {
       
   902                 favoriteGroupCreated = true;
       
   903                 mFavoriteGroupId = groupContactIds.at(i);
       
   904                 break;
       
   905             }
       
   906         }
       
   907     }
       
   908     return favoriteGroupCreated;
       
   909 }
       
   910 
       
   911 /*!
       
   912 Check if the contact is the favourite group
       
   913 */
       
   914 bool CntContactCardViewPrivate::isFavoriteGroupContact()
       
   915 {
       
   916     bool favoriteGroupContact = false;
       
   917     
       
   918     if (isFavoriteGroupCreated())
       
   919     {
       
   920         QContact favoriteGroup = contactManager()->contact(mFavoriteGroupId);
       
   921         QContactRelationshipFilter rFilter;
       
   922         rFilter.setRelationshipType(QContactRelationship::HasMember);
       
   923         rFilter.setRelatedContactRole(QContactRelationship::First);
       
   924         rFilter.setRelatedContactId(favoriteGroup.id());
       
   925     
       
   926         QList<QContactLocalId> contactsLocalIdList = contactManager()->contactIds(rFilter);
       
   927         if (!contactsLocalIdList.isEmpty())
       
   928         {
       
   929             for(int i = 0;i < contactsLocalIdList.count();i++)
       
   930             {
       
   931                 QContact favContact = contactManager()->contact(contactsLocalIdList.at(i));
       
   932                 if (favContact.localId() == mContact->localId())
       
   933                 {
       
   934                     favoriteGroupContact = true;
       
   935                 }  
       
   936              }
       
   937         }
       
   938     }
       
   939     return favoriteGroupContact;
       
   940 }
       
   941 
       
   942 /*!
       
   943 Return the pointer to the document loader
   873 Return the pointer to the document loader
   944 */
   874 */
   945 CntDocumentLoader* CntContactCardViewPrivate::document()
   875 CntDocumentLoader* CntContactCardViewPrivate::document()
   946 {
   876 {
   947     if (!mLoader) 
   877     if (!mLoader)