phonebookui/pbkcommonui/src/cntcontactcardview_p.cpp
changeset 40 b46a585f6909
parent 37 fd64c38c277d
child 46 efe85016a067
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
    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 <QStandardItemModel>
       
    23 #include <hblistview.h>
       
    24 #include <hblistviewitem.h>
    22 #include <QDebug>
    25 #include <QDebug>
       
    26 #include <QKeyEvent>
       
    27 #include <QDir>
    23 
    28 
    24 #include <qtcontacts.h>
    29 #include <qtcontacts.h>
    25 #include <hbscrollarea.h>
    30 #include <hbscrollarea.h>
    26 #include <hblabel.h>
    31 #include <hblabel.h>
    27 #include <hbmenu.h>
    32 #include <hbmenu.h>
    50 #include "cntstringmapper.h"
    55 #include "cntstringmapper.h"
    51 #include "cntdocumentloader.h"
    56 #include "cntdocumentloader.h"
    52 #include "cntimagelabel.h"
    57 #include "cntimagelabel.h"
    53 #include "cntimageutility.h"
    58 #include "cntimageutility.h"
    54 #include "cntfavourite.h"
    59 #include "cntfavourite.h"
       
    60 #include "cntactionlauncher.h"
       
    61 #include <hbselectiondialog.h>
       
    62 
    55 
    63 
    56 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
    64 const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
    57 
    65 
    58 /*!
    66 /*!
    59 Constructor, initialize member variables.
    67 Constructor, initialize member variables.
    74     mFavoriteGroupId(-1),
    82     mFavoriteGroupId(-1),
    75     mLoader(NULL),
    83     mLoader(NULL),
    76     mContactAction(NULL),
    84     mContactAction(NULL),
    77     mBackKey(NULL),
    85     mBackKey(NULL),
    78     mImageLabel(NULL),
    86     mImageLabel(NULL),
    79     mVCardIcon(NULL)
    87     mVCardIcon(NULL),
       
    88     mShareUi(NULL),
       
    89     mAcceptSendKey(true),
       
    90     mSendKeyListModel(NULL)
    80 {
    91 {
    81     bool ok;
    92     bool ok;
    82     document()->load(CNT_CONTACTCARDVIEW_XML, &ok);
    93     document()->load(CNT_CONTACTCARDVIEW_XML, &ok);
    83     if (!ok) 
    94     if (!ok) 
    84     {
    95     {
   104 /*!
   115 /*!
   105 Destructor
   116 Destructor
   106 */
   117 */
   107 CntContactCardViewPrivate::~CntContactCardViewPrivate()
   118 CntContactCardViewPrivate::~CntContactCardViewPrivate()
   108 {
   119 {
       
   120     mView->deleteLater();
       
   121     
   109     delete mContact;
   122     delete mContact;
   110     mContact = 0;
   123     mContact = 0;
   111     
   124     
   112     delete mDataContainer;
   125     delete mDataContainer;
   113     mDataContainer = NULL;
   126     mDataContainer = NULL;
   116     mAvatar = NULL;
   129     mAvatar = NULL;
   117     
   130     
   118     delete mLoader;
   131     delete mLoader;
   119     mLoader = NULL;
   132     mLoader = NULL;
   120     
   133     
   121     delete mVCardIcon;
   134     if (mVCardIcon) {
   122     mVCardIcon = NULL;
   135         delete mVCardIcon;
       
   136         mVCardIcon = NULL;
       
   137     }
       
   138     
       
   139     if (mShareUi) {
       
   140         delete mShareUi;
       
   141         mShareUi = NULL;
       
   142     }
       
   143     
       
   144     delete mSendKeyListModel;
       
   145     mSendKeyListModel = NULL;
   123 }
   146 }
   124 
   147 
   125 /*!
   148 /*!
   126 Activates a previous view
   149 Activates a previous view
   127 */
   150 */
   157     
   180     
   158     mView->installEventFilter(this);
   181     mView->installEventFilter(this);
   159     
   182     
   160     HbMainWindow* window = mView->mainWindow();
   183     HbMainWindow* window = mView->mainWindow();
   161     connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
   184     connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
       
   185     connect(window, SIGNAL(keyPressed(QKeyEvent*)), this, SLOT(keyPressed(QKeyEvent*)));
       
   186     
   162     setOrientation(window->orientation());
   187     setOrientation(window->orientation());
   163         
   188         
   164     QContact contact = aArgs.value(ESelectedContact).value<QContact>();
   189     QContact contact = aArgs.value(ESelectedContact).value<QContact>();
   165     mContact = new QContact( contact );
   190     mContact = new QContact( contact );
   166     //my card
   191     //my card
   216     
   241     
   217     mContainerWidget->setLayout(mContainerLayout);
   242     mContainerWidget->setLayout(mContainerLayout);
   218  
   243  
   219     for (int index = 0; index < mDataContainer->itemCount(); index++)
   244     for (int index = 0; index < mDataContainer->itemCount(); index++)
   220     {
   245     {
       
   246         CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
       
   247         int pos = dataItem->position();
       
   248         
   221         // communication methods
   249         // communication methods
   222         if (mDataContainer->separatorIndex() == -1 || index < mDataContainer->separatorIndex())
   250         if (pos < CntContactCardDataItem::ESeparator && dataItem->isFocusable())
   223         { 
   251         { 
   224             CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget);
   252             CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget);
   225 
   253 
   226             connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated()));
   254             connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated()));
   227             connect(item, SIGNAL(longPressed(const QPointF&)), this, SLOT(onLongPressed(const QPointF&)));
   255             connect(item, SIGNAL(longPressed(const QPointF&)), this, SLOT(onLongPressed(const QPointF&)));
   228 
   256    
   229             CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
       
   230             
       
   231             if (mContact->isPreferredDetail(dataItem->action(), dataItem->detail()))
   257             if (mContact->isPreferredDetail(dataItem->action(), dataItem->detail()))
   232             {
   258             {
   233                 dataItem->setSecondaryIcon(HbIcon("qtg_mono_favourites"));
   259                 dataItem->setSecondaryIcon(HbIcon("qtg_mono_favourites"));
   234                 mPreferredItems.insert(dataItem->action(), item);
   260                 mPreferredItems.insert(dataItem->action(), item);
   235             }
   261             }
   237             item->setDetails(dataItem);
   263             item->setDetails(dataItem);
   238             mContainerLayout->addItem(item);
   264             mContainerLayout->addItem(item);
   239         }
   265         }
   240 
   266 
   241         // separator
   267         // separator
   242         else if (index == mDataContainer->separatorIndex())
   268         else if (pos == CntContactCardDataItem::ESeparator)
   243         {      
   269         {      
   244             HbFrameItem* frameItem = new HbFrameItem(QString("qtg_fr_list_separator"), HbFrameDrawer::NinePieces);
   270             HbFrameItem* frameItem = new HbFrameItem(QString("qtg_fr_list_separator"), HbFrameDrawer::NinePieces);
   245             HbLabel* label = static_cast<HbLabel*>(document()->findWidget(QString("separator")));
   271             HbLabel* label = static_cast<HbLabel*>(document()->findWidget(QString("separator")));
   246             label->setPlainText(mDataContainer->dataItem(index)->titleText());
   272             label->setPlainText(dataItem->titleText());
   247             label->setBackgroundItem(frameItem);
   273             label->setBackgroundItem(frameItem);
   248             mContainerLayout->addItem(label);
   274             mContainerLayout->addItem(label);
   249         }
   275         }
   250 
   276 
   251         // details
   277         // details
   252         else
   278         else
   253         {
   279         {
   254             CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
   280             //map support (image only)
   255             if (!dataItem->icon().isNull())
   281             if (pos >= CntContactCardDataItem::EAddress && pos <= CntContactCardDataItem::EAddressWork && !dataItem->icon().isNull())
   256             { 
   282             {         
   257                 HbLabel* iconLabel = new HbLabel(mView);
   283                 HbLabel* iconLabel = new HbLabel(mView);
   258                 iconLabel->setIcon(dataItem->icon());
   284                 iconLabel->setIcon(dataItem->icon());
   259                 
   285                 
   260                 int width = dataItem->icon().width();
   286                 int width = dataItem->icon().width();
   261                 int height = dataItem->icon().height();    
   287                 int height = dataItem->icon().height();    
   267                 iconLabel->setMaximumSize(QSizeF(width, height));
   293                 iconLabel->setMaximumSize(QSizeF(width, height));
   268                 iconLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
   294                 iconLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
   269                                     QSizePolicy::Fixed));            
   295                                     QSizePolicy::Fixed));            
   270                 mContainerLayout->addItem(iconLabel);
   296                 mContainerLayout->addItem(iconLabel);
   271             } 
   297             } 
       
   298             //other details
   272             else
   299             else
   273             {    
   300             {    
   274                 CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget, false);
   301                 CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget, false);
   275                 item->setDetails(dataItem);
   302                 item->setDetails(dataItem);
   276                 mContainerLayout->addItem(item);
   303                 mContainerLayout->addItem(item);
   277             }
   304             }
   278         }
   305         }
   279     }
   306     }
   280     
   307     
   281     bool setAsFavorite( false );
   308     if (!myCard)
   282     QContactLocalId favouriteGroupId = CntFavourite::favouriteGroupId( contactManager() );
   309     {   
   283     if( favouriteGroupId != 0 )
   310         bool setAsFavorite( false );
   284     {
   311         QContactLocalId favouriteGroupId = CntFavourite::favouriteGroupId( contactManager() );
   285         setAsFavorite = CntFavourite::isMemberOfFavouriteGroup( contactManager(), mContact );
   312         if( favouriteGroupId != 0 )
   286         mHeadingItem->setSecondaryIcon( setAsFavorite ); // if contact is part of favourites group
   313         {
   287     }
   314             setAsFavorite = CntFavourite::isMemberOfFavouriteGroup( contactManager(), mContact );
   288     qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite );
   315             mHeadingItem->setSecondaryIcon( setAsFavorite ); // if contact is part of favourites group
   289     qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
   316         }
       
   317         qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite );
       
   318         qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
       
   319     }
   290         
   320         
   291     // Menu items
   321     // Menu items
   292     connect(qobject_cast<HbAction *>(document()->findObject("cnt:sendbusinesscard")), SIGNAL(triggered()),
   322     connect(qobject_cast<HbAction *>(document()->findObject("cnt:sendbusinesscard")), SIGNAL(triggered()),
   293                 this, SLOT (sendBusinessCard()));
   323                 this, SLOT (sendBusinessCard()));
   294     connect(qobject_cast<HbAction *>(document()->findObject("cnt:deletecontact")), SIGNAL(triggered()),
   324     connect(qobject_cast<HbAction *>(document()->findObject("cnt:deletecontact")), SIGNAL(triggered()),
   335     preferences["contactId"] = mContact->id().localId();
   365     preferences["contactId"] = mContact->id().localId();
   336     
   366     
   337     XQServiceRequest snd("com.nokia.services.hsapplication.IHomeScreenClient",
   367     XQServiceRequest snd("com.nokia.services.hsapplication.IHomeScreenClient",
   338                          "addWidget(QString,QVariantHash)"
   368                          "addWidget(QString,QVariantHash)"
   339                          ,false);
   369                          ,false);
   340     snd << QString("hscontactwidgetplugin");
   370     snd << QString("contactwidgethsplugin");
   341     snd << preferences;
   371     snd << preferences;
   342     snd.send();
   372     snd.send();
   343 }
   373 }
   344 
   374 
   345 /*!
   375 /*!
   434 {
   464 {
   435     qDebug() << "CntContactCardViewPrivate::sendBusinessCard - IN";
   465     qDebug() << "CntContactCardViewPrivate::sendBusinessCard - IN";
   436     // Check if the contact has an image.
   466     // Check if the contact has an image.
   437     QList<QContactAvatar> avatars = mContact->details<QContactAvatar>();
   467     QList<QContactAvatar> avatars = mContact->details<QContactAvatar>();
   438     bool imageExists( false );
   468     bool imageExists( false );
   439     foreach(QContactAvatar a, mContact->details<QContactAvatar>())
   469     /*foreach(QContactAvatar a, mContact->details<QContactAvatar>())
   440     {
   470     {
   441         if (!a.imageUrl().isEmpty())
   471         if (!a.imageUrl().isEmpty())
   442         {
   472         {
   443             imageExists = true;
   473             imageExists = true;
   444             HbMessageBox *note = new HbMessageBox(
   474             HbMessageBox *note = new HbMessageBox(
   445                     hbTrId("txt_phob_info_add_contact_card_image_to_business_c"),
   475                     hbTrId("txt_phob_info_add_contact_card_image_to_business_c"),
   446                     HbMessageBox::MessageTypeQuestion);
   476                     HbMessageBox::MessageTypeQuestion);
   447             note->setIcon(*mVCardIcon);
   477             note->setIcon(*mVCardIcon);
       
   478             note->clearActions();
   448             
   479             
   449             HbAction* ok = new HbAction(hbTrId("txt_common_button_ok"), note);
   480             HbAction* ok = new HbAction(hbTrId("txt_common_button_ok"), note);
   450             HbAction* cancel = new HbAction(hbTrId("txt_common_button_cancel"), note);
   481             HbAction* cancel = new HbAction(hbTrId("txt_common_button_cancel"), note);
   451             
   482             
   452             ok->setObjectName( "ok" );
   483             ok->setObjectName( "ok" );
   458             note->setModal( true );
   489             note->setModal( true );
   459             note->setAttribute(Qt::WA_DeleteOnClose, true );
   490             note->setAttribute(Qt::WA_DeleteOnClose, true );
   460             note->open( this, SLOT(handleSendBusinessCard(HbAction*)));
   491             note->open( this, SLOT(handleSendBusinessCard(HbAction*)));
   461             break;
   492             break;
   462         }
   493         }
   463     }
   494     }*/
   464     
   495     
   465     if ( !imageExists )
   496     if ( !imageExists )
   466     {
   497     {
   467         qDebug() << "CntContactCardViewPrivate::sendBusinessCard without image";
   498         qDebug() << "CntContactCardViewPrivate::sendBusinessCard without image";
   468         handleSendBusinessCard( NULL ); // no image
   499         handleSendBusinessCard( NULL ); // no image
   498     // Check if action is internal
   529     // Check if action is internal
   499     QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(action, "symbian", 1);
   530     QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(action, "symbian", 1);
   500     if(0 < actionDescriptors.count())
   531     if(0 < actionDescriptors.count())
   501     {
   532     {
   502         // These actions are considered internal(vendor=symbian and version=1)
   533         // These actions are considered internal(vendor=symbian and version=1)
   503         launchAction(*mContact, mDataContainer->dataItem(index)->detail(), action);
   534         executeAction(*mContact, mDataContainer->dataItem(index)->detail(), action);
   504     }
   535     }
   505     else
   536     else
   506     {
   537     {
   507         //Handle dynamic actions differently
   538         //Handle dynamic actions differently
   508         launchDynamicAction(*mContact, mDataContainer->dataItem(index)->detail(), mDataContainer->dataItem(index)->actionDescriptor());
   539         executeDynamicAction(*mContact, mDataContainer->dataItem(index)->detail(), mDataContainer->dataItem(index)->actionDescriptor());
   509     }
   540     }
   510 }
   541 }
   511 
   542 
   512 /*!
   543 /*!
   513 Launch the call / message / email action
   544 Execute the call / message / email action
   514 */
   545 */
   515 void CntContactCardViewPrivate::launchAction(QContact contact, QContactDetail detail, QString action)
   546 void CntContactCardViewPrivate::executeAction(QContact& aContact, QContactDetail aDetail, QString aAction)
   516 {
   547 {
   517     // detail might be empty -> in that case engine uses the preferred detail for the selected action
   548     CntActionLauncher* other = new CntActionLauncher( aAction );
   518     QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(action, "symbian");
   549     connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
   519     if (actionDescriptors.isEmpty())
   550     other->execute(aContact, aDetail);
   520     {
   551 }
   521         return;
   552 
   522     }
   553 /*!
   523     mContactAction = QContactAction::action(actionDescriptors.first());
   554 Execute dynamic action
   524     connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
   555 */
   525                 this, SLOT(progress(QContactAction::State)));
   556 void CntContactCardViewPrivate::executeDynamicAction(QContact& aContact, QContactDetail aDetail, QContactActionDescriptor aActionDescriptor)
   526     mContactAction->invokeAction(contact, detail);
   557 {
   527 }
   558     CntActionLauncher* other = new CntActionLauncher( );
   528 
   559     connect(other, SIGNAL(actionExecuted(CntAction*)), this, SLOT(actionExecuted(CntAction*)));
   529 /*!
   560     other->execute(aContact, aDetail, aActionDescriptor);
   530 Launch dynamic action
   561 }
   531 */
   562 
   532 void CntContactCardViewPrivate::launchDynamicAction(QContact contact, QContactDetail detail, QContactActionDescriptor actionDescriptor)
   563 void CntContactCardViewPrivate::actionExecuted(CntActionLauncher* aAction)
   533 {
   564 {
   534     // detail might be empty -> in that case engine uses the preferred detail for the selected action
   565     aAction->deleteLater();
   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 
       
   541 void CntContactCardViewPrivate::progress(QContactAction::State status)
       
   542 {
       
   543     switch(status)
       
   544     {
       
   545     case QContactAction::FinishedState:
       
   546     case QContactAction::FinishedWithErrorState:
       
   547         mContactAction->deleteLater();
       
   548         break;
       
   549     default:
       
   550         break;
       
   551     }
       
   552 }
   566 }
   553 
   567 
   554 /*!
   568 /*!
   555 Set selected detail as preferred for selected action
   569 Set selected detail as preferred for selected action
   556 */
   570 */
   586             QContactPhoneNumber number = static_cast<QContactPhoneNumber>(detail);
   600             QContactPhoneNumber number = static_cast<QContactPhoneNumber>(detail);
   587             QString context = number.contexts().isEmpty() ? QString() : number.contexts().first();
   601             QString context = number.contexts().isEmpty() ? QString() : number.contexts().first();
   588             QString subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first();
   602             QString subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first();
   589 
   603 
   590             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(subtype, context));
   604             communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(subtype, context));
   591    
   605             videoCommunicationAction = menu->addAction(hbTrId("txt_phob_menu_call_video_number"));
   592             // TODO : uncomment next line when videotelephony is released
       
   593             Q_UNUSED(videoCommunicationAction)
       
   594             //videoCommunicationAction = menu->addAction(QString("txt_phob_menu_call_video_number"));
       
   595         }        
   606         }        
   596     }
   607     }
   597     else if (action.compare("message", Qt::CaseInsensitive) == 0)
   608     else if (action.compare("message", Qt::CaseInsensitive) == 0)
   598     {
   609     {
   599         communicationAction = menu->addAction(hbTrId("txt_phob_menu_send_message"));
   610         communicationAction = menu->addAction(hbTrId("txt_phob_menu_send_message"));
   647     }
   658     }
   648    
   659    
   649     if ( communicationAction )
   660     if ( communicationAction )
   650     {
   661     {
   651         communicationAction->setObjectName( "communicationAction" );
   662         communicationAction->setObjectName( "communicationAction" );
       
   663     }
       
   664     if ( videoCommunicationAction )
       
   665     {
       
   666         videoCommunicationAction->setObjectName( "videoCommunicationAction" );
   652     }
   667     }
   653    
   668    
   654     if ( dynamicAction )
   669     if ( dynamicAction )
   655     {
   670     {
   656         dynamicAction->setObjectName( "dynamicAction" );
   671         dynamicAction->setObjectName( "dynamicAction" );
   678         
   693         
   679     QString name = aAction->objectName();
   694     QString name = aAction->objectName();
   680     
   695     
   681     if ( name == "communicationAction" )
   696     if ( name == "communicationAction" )
   682     {
   697     {
   683         launchAction( *mContact, detail, action );
   698         executeAction( *mContact, detail, action );
   684     }
   699     }
   685 
   700 
       
   701     if ( name == "videoCommunicationAction" )
       
   702     {
       
   703         //service name latter on should come from service table.
       
   704         executeAction( *mContact, detail, "videocall" );
       
   705     }
   686     if ( name == "dynamicAction" )
   706     if ( name == "dynamicAction" )
   687     {             
   707     {             
   688         launchDynamicAction(*mContact, detail, mDataContainer->dataItem(index)->actionDescriptor());
   708         executeDynamicAction(*mContact, detail, mDataContainer->dataItem(index)->actionDescriptor());
   689     }
   709     }
   690     
   710     
   691     if ( name == "preferredAction" )
   711     if ( name == "preferredAction" )
   692     {
   712     {
   693         setPreferredAction(action, detail);
   713         setPreferredAction(action, detail);
   708 
   728 
   709 void CntContactCardViewPrivate::handleSendBusinessCard( HbAction* aAction )
   729 void CntContactCardViewPrivate::handleSendBusinessCard( HbAction* aAction )
   710 {
   730 {
   711     qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard - IN";
   731     qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard - IN";
   712     QList<QContact> list;
   732     QList<QContact> list;
   713     if ( aAction && aAction->objectName() == "cancel" )
   733     /* if ( aAction && aAction->objectName() == "cancel" )
   714     {
   734     {
   715         QContact tmpContact( *mContact );
   735         QContact tmpContact( *mContact );
   716         foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() )
   736         foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() )
   717         {
   737         {
   718             tmpContact.removeDetail( &a );
   738             tmpContact.removeDetail( &a );
   720         list.append( tmpContact );
   740         list.append( tmpContact );
   721     }
   741     }
   722     else
   742     else
   723     {
   743     {
   724         list.append( *mContact );
   744         list.append( *mContact );
   725     }
   745     }*/
   726     
   746     
       
   747     QContact tmpContact( *mContact );
       
   748     foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() )
       
   749     {
       
   750         tmpContact.removeDetail( &a );
       
   751     }
       
   752     list.append( tmpContact );
       
   753       
   727     QString tempDir = QDir::tempPath().append("/tempcntvcard");
   754     QString tempDir = QDir::tempPath().append("/tempcntvcard");
   728     QDir dir(tempDir);
   755     QDir dir(tempDir);
   729            
   756            
   730     // Temporary directory to store the vCard file
   757     // Temporary directory to store the vCard file
   731     if (!dir.exists()) 
   758     if (!dir.exists()) 
   767         
   794         
   768             bool ret = writer.startWriting(docs);
   795             bool ret = writer.startWriting(docs);
   769             ret = writer.waitForFinished();
   796             ret = writer.waitForFinished();
   770         
   797         
   771             // Create the vCard and send it to messaging service
   798             // Create the vCard and send it to messaging service
   772             ShareUi s;
   799             if (!mShareUi) {
       
   800                 mShareUi = new ShareUi();
       
   801             }
   773             QStringList l;
   802             QStringList l;
   774             l << vCardPath;
   803             l << vCardPath;
   775             s.send(l,false);
   804             mShareUi->send(l,false);
   776         }
   805         }
   777     }
   806     }
   778     qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard - OUT";
   807     qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard - OUT";
   779 }
   808 }
   780 
   809 
   781 /*!
       
   782 Event filter for green key
       
   783 */
       
   784 bool CntContactCardViewPrivate::eventFilter(QObject *obj, QEvent *event)
       
   785 {
       
   786     if (event->type() == QEvent::KeyPress && static_cast<QKeyEvent*>(event)->key() == Qt::Key_Yes)
       
   787     {
       
   788         QList<QContactActionDescriptor> actionDescriptors = mContact->availableActions();
       
   789         QStringList availableActions;
       
   790         for (int i = 0; i < actionDescriptors.count();i++)
       
   791         {
       
   792             availableActions << actionDescriptors.at(i).actionName();
       
   793         }
       
   794         if (availableActions.contains("call", Qt::CaseInsensitive))
       
   795         {
       
   796             launchAction(*mContact, QContactDetail(), "call");
       
   797         }
       
   798         return true;
       
   799     }
       
   800     else
       
   801     {
       
   802         return QObject::eventFilter(obj,event);
       
   803     }
       
   804 }
       
   805 
   810 
   806 /*!
   811 /*!
   807 Called after the user clicked "Change Image" from popup menu after 
   812 Called after the user clicked "Change Image" from popup menu after 
   808 longpressing the image in this view.
   813 longpressing the image in this view.
   809 */
   814 */
   887 QContactManager* CntContactCardViewPrivate::contactManager()
   892 QContactManager* CntContactCardViewPrivate::contactManager()
   888 {
   893 {
   889     return mViewManager->contactManager(SYMBIAN_BACKEND);
   894     return mViewManager->contactManager(SYMBIAN_BACKEND);
   890 }
   895 }
   891 
   896 
       
   897 void CntContactCardViewPrivate::keyPressed(QKeyEvent *event)
       
   898 {
       
   899     if (event->key() == Qt::Key_Yes )
       
   900     {
       
   901         sendKeyPressed();
       
   902     }
       
   903 }
       
   904 
       
   905 void CntContactCardViewPrivate::sendKeyPressed()
       
   906 {   
       
   907     QContactDetail preferredDetail = mContact->preferredDetail("call");
       
   908     if (!preferredDetail.isEmpty())
       
   909     {
       
   910         executeAction(*mContact, preferredDetail, "call"); 
       
   911     }
       
   912     else 
       
   913     {   
       
   914         if(!mSendKeyListModel)
       
   915         {
       
   916             mSendKeyListModel = new QStandardItemModel();
       
   917         }
       
   918         mSendKeyListModel->clear();
       
   919         for (int index = 0; index < mDataContainer->itemCount(); index++)
       
   920         {
       
   921             CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
       
   922             if (dataItem->action().compare("call", Qt::CaseInsensitive) == 0)
       
   923             {
       
   924                 QStandardItem *labelItem = new QStandardItem();
       
   925                 QStringList textList;
       
   926                 textList << dataItem->titleText() << dataItem->valueText();
       
   927                 labelItem->setData(textList, Qt::DisplayRole);
       
   928                 labelItem->setData(dataItem->icon(), Qt::DecorationRole);
       
   929                 labelItem->setData(index, Qt::UserRole);
       
   930                 mSendKeyListModel->appendRow(labelItem);
       
   931             }
       
   932         }
       
   933   
       
   934         if (mSendKeyListModel->rowCount() == 0)
       
   935         {
       
   936             XQServiceRequest snd("com.nokia.services.logsservices.starter", "start(int,bool)", false);
       
   937             snd << 0; // all calls
       
   938             snd << true; // show dialpad
       
   939             snd.send();
       
   940         }
       
   941         else if (mSendKeyListModel->rowCount() ==1 )
       
   942         {
       
   943             QContactDetail detail = mDataContainer->dataItem(0)->detail();
       
   944             executeAction( *mContact, detail, "call" ); 
       
   945         }
       
   946         else if (mSendKeyListModel->rowCount() >= 2 && mAcceptSendKey)
       
   947         {
       
   948             mAcceptSendKey = false;
       
   949             
       
   950             // Instantiate a dialog        
       
   951             mSendKeyPopup = new HbSelectionDialog();
       
   952             mSendKeyPopup->clearActions(); 
       
   953             mSendKeyPopup->setAttribute(Qt::WA_DeleteOnClose, true);
       
   954             mSendKeyPopup->setDismissPolicy(HbPopup::NoDismiss);
       
   955             mSendKeyPopup->setTimeout(HbPopup::NoTimeout);
       
   956             mSendKeyPopup->setModal(true);
       
   957             
       
   958             HbListView* listView = new HbListView(mSendKeyPopup);
       
   959             listView->setModel(mSendKeyListModel);
       
   960             listView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
       
   961             listView->setFrictionEnabled(true);
       
   962             
       
   963             connect(listView, SIGNAL(activated (const QModelIndex&)), this,
       
   964                 SLOT(launchSendKeyAction(const QModelIndex&)));
       
   965             
       
   966             QString contactName = mContact->displayLabel();
       
   967         
       
   968             HbLabel *headingText = new HbLabel(mSendKeyPopup);
       
   969             headingText->setPlainText(contactName);
       
   970             
       
   971             mSendKeyPopup->setHeadingWidget(headingText);
       
   972             mSendKeyPopup->setContentWidget(listView);
       
   973             
       
   974             HbAction *cancelAction = new HbAction(hbTrId("txt_phob_button_cancel"), mSendKeyPopup);
       
   975             mSendKeyPopup->addAction(cancelAction);
       
   976             
       
   977             // Launch dialog asyncronously
       
   978             mSendKeyPopup->open(this, SLOT(sendKeyDialogSlot(HbAction*)));
       
   979         }
       
   980     }
       
   981 }
       
   982 
       
   983 void CntContactCardViewPrivate::sendKeyDialogSlot(HbAction* action)
       
   984 {
       
   985     Q_UNUSED(action);
       
   986     mAcceptSendKey = true;
       
   987 }
       
   988 
       
   989 void CntContactCardViewPrivate::launchSendKeyAction(const QModelIndex &index)
       
   990 {
       
   991     mAcceptSendKey = true;
       
   992     mSendKeyPopup->close();
       
   993     if (index.isValid())
       
   994     {
       
   995         int row = index.row();
       
   996         int selectedDetail = mSendKeyListModel->item(index.row())->data(Qt::UserRole).toInt();
       
   997         executeAction(*mContact, mDataContainer->dataItem(selectedDetail)->detail(), "call");
       
   998     }
       
   999 }
       
  1000 
       
  1001 
       
  1002 
   892 // end of file
  1003 // end of file