messagingapp/msgui/conversationview/src/msgcontactcardwidget.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 41 25fe1fe642e3
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    19 
    19 
    20 // SYSTEM INCLUDES
    20 // SYSTEM INCLUDES
    21 #include <HbStyle>
    21 #include <HbStyle>
    22 #include <HbIconItem>
    22 #include <HbIconItem>
    23 #include <HbTextItem>
    23 #include <HbTextItem>
    24 #include <HbFrameDrawer>
    24 #include <HbTapGesture>
    25 #include <HbGesture>
    25 #include <HbInstantFeedback>
    26 #include <HbGestureSceneFilter>
       
    27 #include <HbWidgetFeedback>
       
    28 #include <HbFrameItem>
    26 #include <HbFrameItem>
    29 #include <qmobilityglobal.h>
       
    30 #include <qcontactphonenumber.h>
    27 #include <qcontactphonenumber.h>
    31 #include <qcontactfilter.h>
    28 #include <qcontactavatar.h>
    32 #include <qcontactmanager.h>
       
    33 #include <qcontactdetailfilter.h>
       
    34 #include <xqaiwrequest.h>
    29 #include <xqaiwrequest.h>
    35 #include <xqappmgr.h>
    30 #include <xqappmgr.h>
    36 #include <XQServiceRequest.h>
    31 #include <xqservicerequest.h>
    37 #include <cntservicescontact.h>
    32 #include <cntservicescontact.h>
    38 #include <QGraphicsSceneMouseEvent>
    33 #include <QGraphicsSceneMouseEvent>
    39 #include <HbMenu>
    34 #include <HbMenu>
    40 #include <HbMainWindow>
    35 #include <thumbnailmanager_qt.h>
       
    36 #include <QTimer>
    41 
    37 
    42 #include <ccsdefs.h>
    38 #include <ccsdefs.h>
    43 
    39 
    44 // USER INCLUDES
    40 // USER INCLUDES
    45 #include "conversationsenginedefines.h"
    41 #include "conversationsenginedefines.h"
    46 #include "debugtraces.h"
       
    47 #include "conversationsengine.h"
    42 #include "conversationsengine.h"
    48 #include "convergedmessage.h"
    43 #include "convergedmessage.h"
    49 
    44 #include "msgcontacthandler.h"
    50 QTM_USE_NAMESPACE
       
    51 
    45 
    52 // LOCAL CONSTANTS
    46 // LOCAL CONSTANTS
    53 const QString DEFAULT_AVATAR_ICON("qtg_large_avatar");
    47 const QString DEFAULT_AVATAR_ICON("qtg_large_avatar");
    54 const QString BT_ICON("qtg_large_bluetooth");
    48 const QString BT_ICON("qtg_large_bluetooth");
    55 const QString BACKGROUND_FRAME_NORMAL("qtg_fr_groupbox");
    49 const QString BG_FRAME_NORMAL("qtg_fr_groupbox_normal");
    56 const QString GROUPBOX_BG_FRAME_PRESSED("qtg_fr_groupbox_pressed");
    50 const QString BG_FRAME_PRESSED("qtg_fr_groupbox_pressed");
    57 
       
    58 const QString PLUGINPATH("conversationviewplugin.dll");
       
    59 
    51 
    60 // LOCALIZATION CONSTANTS
    52 // LOCALIZATION CONSTANTS
    61 #define LOC_RECEIVED_FILES hbTrId("txt_messaging_title_received_files")
    53 #define LOC_RECEIVED_FILES hbTrId("txt_messaging_title_received_files")
    62 #define LOC_MENU_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info")
    54 #define LOC_MENU_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info")
    63 #define LOC_COMMON_MENU_CALL hbTrId("txt_common_menu_call_verb")
    55 #define LOC_COMMON_MENU_CALL hbTrId("txt_common_menu_call_verb")
    64 #define LOC_SAVETO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts")
    56 #define LOC_SAVETO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts")
    65 
    57 
       
    58 // LOCAL FUNCTIONS
       
    59 
    66 //---------------------------------------------------------------
    60 //---------------------------------------------------------------
    67 // MsgContactCardWidget::MsgContactCardWidget
    61 // MsgContactCardWidget::MsgContactCardWidget
    68 // @see header
    62 // @see header
    69 //---------------------------------------------------------------
    63 //---------------------------------------------------------------
    70 MsgContactCardWidget::MsgContactCardWidget(QGraphicsItem *parent) :
    64 MsgContactCardWidget::MsgContactCardWidget(QGraphicsItem *parent) :
    71 HbWidget(parent), 
    65     HbWidget(parent), mIgnoreEvents(false), mAvatarIconItem(NULL), mPresenceIconItem(NULL),
    72 mMenuShown(false),
    66         mAddressTextItem(NULL), mThumbnailManager(NULL)
    73 mAvatarIconItem(NULL),
    67 {
    74 mPresenceIconItem(NULL),
    68     init();
    75 mAddressTextItem(NULL),
       
    76 mGestureFilter(NULL)
       
    77 
       
    78 {
       
    79     int baseId = style()->registerPlugin(PLUGINPATH);
       
    80     QDEBUG_WRITE_FORMAT("MsgContactCardWidget BASE ID --->", baseId);
       
    81     setPluginBaseId(baseId);
       
    82 
       
    83     init();  
       
    84     setBackGround(BACKGROUND_FRAME_NORMAL);
       
    85     connectSignals(true);
       
    86     
       
    87     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(initGesture()));   
       
    88 }
    69 }
    89 
    70 
    90 //---------------------------------------------------------------
    71 //---------------------------------------------------------------
    91 // MsgContactCardWidget::~MsgContactCardWidget
    72 // MsgContactCardWidget::~MsgContactCardWidget
    92 // @see header
    73 // @see header
    93 //---------------------------------------------------------------
    74 //---------------------------------------------------------------
    94 MsgContactCardWidget::~MsgContactCardWidget()
    75 MsgContactCardWidget::~MsgContactCardWidget()
    95 {
    76 {
    96     style()->unregisterPlugin(PLUGINPATH);
       
    97     
       
    98     if(mGestureFilter)
       
    99         {
       
   100         removeSceneEventFilter(mGestureFilter);
       
   101         }
       
   102 }
    77 }
   103 
    78 
   104 //---------------------------------------------------------------
    79 //---------------------------------------------------------------
   105 // MsgContactCardWidget::init
    80 // MsgContactCardWidget::init
   106 // @see header
    81 // @see header
   107 //---------------------------------------------------------------
    82 //---------------------------------------------------------------
   108 void MsgContactCardWidget::init()
    83 void MsgContactCardWidget::init()
   109 {
    84 {
       
    85     this->setProperty("state", "normal");
       
    86     this->grabGesture(Qt::TapGesture);
       
    87 
       
    88     HbFrameItem *frameItem = new HbFrameItem(BG_FRAME_NORMAL, HbFrameDrawer::NinePieces, this);
       
    89     this->setBackgroundItem(frameItem);
       
    90 
   110     mAvatarIconItem = new HbIconItem(this);
    91     mAvatarIconItem = new HbIconItem(this);
   111     HbStyle::setItemName(mAvatarIconItem, "avatar");
    92     HbStyle::setItemName(mAvatarIconItem, "avatar");
   112 
    93 
   113     mPresenceIconItem = new HbIconItem(this);
    94     mPresenceIconItem = new HbIconItem(this);
   114     HbStyle::setItemName(mPresenceIconItem, "presence");
    95     HbStyle::setItemName(mPresenceIconItem, "presence");
   115 
    96 
   116     mAddressTextItem = new HbTextItem(this);
    97     mAddressTextItem = new HbTextItem(this);
   117     HbStyle::setItemName(mAddressTextItem, "addressText");
    98     HbStyle::setItemName(mAddressTextItem, "addressText");
   118 
    99 
       
   100     mThumbnailManager = new ThumbnailManager(this);
       
   101     mThumbnailManager->setMode(ThumbnailManager::Default);
       
   102     mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality);
       
   103     mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
       
   104 
       
   105     connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), this,
       
   106         SLOT(thumbnailReady(QPixmap, void*, int, int)));
   119 }
   107 }
   120 
   108 
   121 //---------------------------------------------------------------
   109 //---------------------------------------------------------------
   122 // MsgContactCardWidget::setAvatar
   110 // MsgContactCardWidget::setAvatar
   123 // @see header
   111 // @see header
   151 // @see header
   139 // @see header
   152 //---------------------------------------------------------------
   140 //---------------------------------------------------------------
   153 ConvergedMessageAddressList MsgContactCardWidget::address()
   141 ConvergedMessageAddressList MsgContactCardWidget::address()
   154 {
   142 {
   155     ConvergedMessageAddressList addresses;
   143     ConvergedMessageAddressList addresses;
   156     QModelIndex index = ConversationsEngine::instance()->getConversationsModel()->index(0, 0);
   144     QStandardItemModel* msgModel = ConversationsEngine::instance()->getConversationsModel();
       
   145     const int rowCnt = msgModel->rowCount();
       
   146     QModelIndex index = msgModel->index(rowCnt-1, 0);
   157     ConvergedMessageAddress* address = new ConvergedMessageAddress(
   147     ConvergedMessageAddress* address = new ConvergedMessageAddress(
   158         index.data(ConversationAddress).toString());
   148         index.data(ConversationAddress).toString());
   159     address->setAlias(mAddress);
   149     QString displayname;
       
   150     QString addr;
       
   151     ConversationsEngine::instance()->getContactDetails(
       
   152             ConversationsEngine::instance()->getCurrentConversationId(),
       
   153             displayname,
       
   154             addr);
       
   155     address->setAlias(displayname);
   160     addresses.append(address);
   156     addresses.append(address);
   161     return addresses;
   157     return addresses;
   162 }
   158 }
   163 
   159 
   164 //---------------------------------------------------------------
   160 //---------------------------------------------------------------
   185         //Set the Contact Name/Number
   181         //Set the Contact Name/Number
   186         qint64 convId;
   182         qint64 convId;
   187         QString displayName;
   183         QString displayName;
   188         QString contactAddress;
   184         QString contactAddress;
   189         convId = ConversationsEngine::instance()->getCurrentConversationId();
   185         convId = ConversationsEngine::instance()->getCurrentConversationId();
   190         ConversationsEngine::instance()->getContactDetails(convId, displayName,
   186         ConversationsEngine::instance()->getContactDetails(convId, displayName, contactAddress);
   191             contactAddress);
   187 
   192         
       
   193         mContactNumber = contactAddress;
   188         mContactNumber = contactAddress;
   194         QString contactName;
   189         QString contactName;
   195         if (displayName.isEmpty()) {
   190         if (displayName.isEmpty()) {
   196             contactName.append(contactAddress);
   191             contactName.append(contactAddress);
   197         }
   192         }
   198         else {
   193         else {
   199             contactName.append(displayName);
   194             contactName.append(displayName);
   200         }
   195         }
   201         
   196 
   202         setAddress(contactName);
   197         setAddress(contactName);
   203 
   198 
   204         // Set Avatar
   199         // Set Avatar
   205         HbIcon avatar;
   200         QList<QContact> contactList = MsgContactHandler::findContactList(mContactNumber);
   206         QByteArray avatarByteArray = index.data(Avatar).toByteArray();
   201 
   207         if (avatarByteArray.isEmpty()) {
   202         if (!contactList.isEmpty()) {
   208             avatar = HbIcon(DEFAULT_AVATAR_ICON);
   203             QList<QContactAvatar> avatarDetails = contactList.at(0).details<QContactAvatar> ();
   209         }
   204 
   210         else {
   205             if (!avatarDetails.isEmpty()) {
   211             QPixmap pixmap;
   206                 mThumbnailManager->getThumbnail(avatarDetails.at(0).imageUrl().toString());
   212             pixmap.loadFromData(avatarByteArray);
   207             }
   213             avatar = HbIcon(QIcon(pixmap));
   208         }
   214         }
   209 
   215         setAvatar(avatar);
   210         // Set default avatar till actual is set.
       
   211         setAvatar(HbIcon(DEFAULT_AVATAR_ICON));
   216     }
   212     }
   217 }
   213 }
   218 
   214 
   219 //---------------------------------------------------------------
   215 //---------------------------------------------------------------
   220 // MsgContactCardWidget::clearContent
   216 // MsgContactCardWidget::clearContent
   225     setAddress("");
   221     setAddress("");
   226     setAvatar(HbIcon());
   222     setAvatar(HbIcon());
   227 }
   223 }
   228 
   224 
   229 //---------------------------------------------------------------
   225 //---------------------------------------------------------------
   230 // MsgContactCardWidget::initGesture
   226 // MsgContactCardWidget::gestureEvent
   231 // @see header file
   227 // @see header file
   232 //---------------------------------------------------------------
   228 //---------------------------------------------------------------
   233 void MsgContactCardWidget::initGesture()
   229 void MsgContactCardWidget::gestureEvent(QGestureEvent *event)
   234 {
   230 {
   235     // Create gesture filter
   231     HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture));
   236     QGraphicsScene* sc = this->scene();
   232     if (tapGesture) {
   237     mGestureFilter = new HbGestureSceneFilter( Qt::LeftButton, this );
   233         switch (tapGesture->state()) {
   238     
   234         case Qt::GestureStarted:
   239     // Add gestures for longpress
   235         {
   240     HbGesture* gestureLongpressed = new HbGesture( HbGesture::longpress,5 );
   236             // Trigger haptic feedback.
   241     
   237             HbInstantFeedback::play(HbFeedback::Basic);
   242     mGestureFilter->addGesture( gestureLongpressed );
   238             setPressed(true);
   243     
   239             break;
   244     connect( gestureLongpressed, SIGNAL(longPress(QPointF)),
   240         }
   245              this, SLOT(handleLongPress(QPointF)));
   241         case Qt::GestureUpdated:
   246 
   242         {
   247     //install gesture filter.
   243             if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) {
   248     this->installSceneEventFilter(mGestureFilter);
   244                 // Handle longtap.
   249     
   245                 setPressed(false);
   250     disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(initGesture()));   
   246                 handleLongTap(tapGesture->scenePosition());
   251 }
   247             }
   252 
   248             break;
   253 //---------------------------------------------------------------
   249         }
   254 // MsgContactCardWidget::mousePressEvent
   250         case Qt::GestureFinished:
       
   251         {
       
   252             HbInstantFeedback::play(HbFeedback::Basic);
       
   253             if (HbTapGesture::Tap == tapGesture->tapStyleHint()) {
       
   254                 // Handle short tap.
       
   255                 setPressed(false);
       
   256                 handleShortTap(tapGesture->scenePosition());
       
   257             }
       
   258             break;
       
   259         }
       
   260         case Qt::GestureCanceled:
       
   261         {
       
   262             HbInstantFeedback::play(HbFeedback::Basic);
       
   263             setPressed(false);
       
   264             break;
       
   265         }
       
   266         }
       
   267     }
       
   268     else {
       
   269         HbWidget::gestureEvent(event);
       
   270     }
       
   271 }
       
   272 
       
   273 //---------------------------------------------------------------
       
   274 // MsgContactCardWidget::setPressed
   255 // @see header file
   275 // @see header file
   256 //---------------------------------------------------------------
   276 //---------------------------------------------------------------
   257 void MsgContactCardWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
   277 void MsgContactCardWidget::setPressed(bool pressed)
   258 {    
   278 {
   259     mMenuShown = false;
   279     HbFrameItem *frameItem = static_cast<HbFrameItem *> (this->backgroundItem());
   260     
   280     if (pressed) {
   261     HbWidgetFeedback::triggered(this, Hb::InstantPressed);
   281         this->setProperty("state", "pressed");
   262     
   282         frameItem->frameDrawer().setFrameGraphicsName(BG_FRAME_PRESSED);
   263     setBackGround(GROUPBOX_BG_FRAME_PRESSED);
   283     }
   264     
   284     else {
   265     event->accept();
   285         this->setProperty("state", "normal");
   266 }
   286         frameItem->frameDrawer().setFrameGraphicsName(BG_FRAME_NORMAL);
   267 
   287     }
   268 
   288 }
   269 //---------------------------------------------------------------
   289 
   270 // MsgContactCardWidget::mouseReleaseEvent
   290 //---------------------------------------------------------------
       
   291 // MsgContactCardWidget::handleLongTap
   271 // @see header file
   292 // @see header file
   272 //---------------------------------------------------------------
   293 //---------------------------------------------------------------
   273 void MsgContactCardWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   294 void MsgContactCardWidget::handleLongTap(const QPointF &position)
   274 {
   295 {
   275     setBackGround(BACKGROUND_FRAME_NORMAL);
   296     // Check if events need to be ignored/accepted
   276     
   297     if (mIgnoreEvents) {
   277     if(this->rect().contains(event->pos())&& !mMenuShown)
   298         return;
   278         {
   299     }
   279         HbWidgetFeedback::triggered(this, Hb::InstantClicked);
   300 
   280 		emit clicked();
   301     if (KBluetoothMsgsConversationId != ConversationsEngine::instance()->getCurrentConversationId()) {
   281         }
       
   282     
       
   283     event->accept();    
       
   284 }
       
   285 
       
   286 //---------------------------------------------------------------
       
   287 // MsgContactCardWidget::setBackGround
       
   288 // @see header file
       
   289 //---------------------------------------------------------------
       
   290 void MsgContactCardWidget::setBackGround(const QString& bg)
       
   291     {
       
   292     HbFrameItem* backGround = new HbFrameItem(this);
       
   293     backGround->frameDrawer().setFrameGraphicsName(bg);
       
   294     backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
   295     this->setBackgroundItem(backGround); 
       
   296     this->repolish();
       
   297     }
       
   298 
       
   299 //---------------------------------------------------------------
       
   300 // MsgContactCardWidget::handleLongPress
       
   301 // @see header file
       
   302 //---------------------------------------------------------------
       
   303 void MsgContactCardWidget::handleLongPress(QPointF position)
       
   304 {
       
   305     if(KBluetoothMsgsConversationId 
       
   306         != ConversationsEngine::instance()->getCurrentConversationId())    
       
   307         {
       
   308         HbMenu* contextMenu = new HbMenu();
   302         HbMenu* contextMenu = new HbMenu();
   309         contextMenu->setDismissPolicy(HbPopup::TapAnywhere);
   303         contextMenu->setDismissPolicy(HbPopup::TapAnywhere);
   310         contextMenu->setAttribute(Qt::WA_DeleteOnClose, true);
   304         contextMenu->setAttribute(Qt::WA_DeleteOnClose, true);
   311         contextMenu->setPreferredPos(position);
   305         contextMenu->setPreferredPos(position);   
   312         
   306 
   313         contextMenu->addAction(LOC_MENU_CONTACT_INFO,this, SLOT(openContactInfo()));    
       
   314         contextMenu->addAction(LOC_COMMON_MENU_CALL, this, SLOT(call()));
       
   315         
       
   316         //If contact doesn't exist in phonebook then add another menu item "Save to Contacts"
   307         //If contact doesn't exist in phonebook then add another menu item "Save to Contacts"
   317         int contactId = resolveContactId(mContactNumber);
   308         int contactId = resolveContactId(mContactNumber);
   318         if(contactId < 0)
   309         if (contactId < 0) {
   319         {
       
   320             contextMenu->addAction(LOC_SAVETO_CONTACTS, this, SLOT(addToContacts()));
   310             contextMenu->addAction(LOC_SAVETO_CONTACTS, this, SLOT(addToContacts()));
   321         }
   311         }
   322         
   312         else{
       
   313             contextMenu->addAction(LOC_MENU_CONTACT_INFO, this, SLOT(openContactInfo()));
       
   314         }
       
   315         contextMenu->addAction(LOC_COMMON_MENU_CALL, this, SLOT(call()));
       
   316 
   323         contextMenu->show();
   317         contextMenu->show();
   324         
   318     }
   325         mMenuShown = true;
   319 }
   326         }
   320 
   327 }
   321 //---------------------------------------------------------------
   328 
   322 // MsgContactCardWidget::handleShortTap
   329 //---------------------------------------------------------------
   323 // @see header
   330 // MsgContactCardWidget::overrideFeedback
   324 //---------------------------------------------------------------
   331 // @see header file
   325 void MsgContactCardWidget::handleShortTap(const QPointF &position)
   332 //---------------------------------------------------------------
   326 {
   333 HbFeedback::InstantEffect MsgContactCardWidget::overrideFeedback(Hb::InstantInteraction interaction) const
   327     this->ungrabGesture(Qt::TapGesture);
   334         {
   328     
   335         switch(interaction)
   329     // Check if events need to be ignored/accepted
   336             {
   330     if (mIgnoreEvents) {
   337             case Hb::InstantPressed:
   331         return;
   338             case Hb::InstantClicked:
   332     }
   339                 return HbFeedback::Basic;
   333     
   340             default:
   334     int contactId = resolveContactId(mContactNumber);
   341                 return HbFeedback::NoOverride;
   335     if(contactId > 0)
   342             }
   336     {
   343         }
   337         //resolved contact open contact card.
   344 		
   338         openContactInfo();
       
   339     }
       
   340     else
       
   341     {
       
   342         //unresolved contact show longpress options menu.
       
   343         handleLongTap(position);
       
   344     }
       
   345     
       
   346     //fire timer to regrab gesture after some delay.
       
   347     QTimer::singleShot(300,this,SLOT(regrabGesture()));    
       
   348 }
       
   349 
   345 //---------------------------------------------------------------
   350 //---------------------------------------------------------------
   346 // MsgContactCardWidget::openContactInfo
   351 // MsgContactCardWidget::openContactInfo
   347 // @see header
   352 // @see header
   348 //---------------------------------------------------------------
   353 //---------------------------------------------------------------
   349 void MsgContactCardWidget::openContactInfo()
   354 void MsgContactCardWidget::openContactInfo()
   350 {
   355 {
   351     QString operation;
   356     QString operation;
   352     QList<QVariant> args;
   357     QList<QVariant> args;
   353     if(KBluetoothMsgsConversationId 
   358     if (KBluetoothMsgsConversationId != ConversationsEngine::instance()->getCurrentConversationId()) {
   354             != ConversationsEngine::instance()->getCurrentConversationId())
   359         int contactId = resolveContactId(mContactNumber);
   355     {
   360         if (contactId > 0) {
   356         int contactId = resolveContactId(mContactNumber);                
       
   357         if(contactId > 0)
       
   358         {
       
   359             //open existing contact card
   361             //open existing contact card
   360             operation = QString("open(int)");
   362             operation = QString("open(int)");
   361             args << contactId;
   363             args << contactId;
   362         }
   364         }
   363         else
   365         else {
   364         {
       
   365             //populate data and open unknown contact template
   366             //populate data and open unknown contact template
   366             operation = QString("editCreateNew(QString,QString)");
   367             operation = QString("editCreateNew(QString,QString)");
   367             QString type = QContactPhoneNumber::DefinitionName;
   368             QString type = QContactPhoneNumber::DefinitionName;
   368     
   369 
   369             args << type;
   370             args << type;
   370             args << mAddress;
   371             args << mAddress;
   371         }
   372         }
   372         //service stuff.
   373         //service stuff.
   373         QString serviceName("com.nokia.services.phonebookservices");
   374         QString serviceName("com.nokia.services.phonebookservices");
   374      
   375 
   375         XQAiwRequest* request;
   376         XQAiwRequest* request;
   376         XQApplicationManager appManager;
   377         XQApplicationManager appManager;
   377         request = appManager.create(serviceName, "Fetch", operation, true); // embedded
   378         request = appManager.create(serviceName, "Fetch", operation, true); // embedded
   378         if ( request == NULL )
   379         if (request == NULL) {
   379         {
   380             return;
   380         	return;       
   381         }
   381         }
   382 
   382         
       
   383         // Result handlers
   383         // Result handlers
   384         connect (request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
   384         connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
   385         connect (request, SIGNAL(requestError(const QVariant&)), this, SLOT(handleError(const QVariant&)));
   385         connect(request, SIGNAL(requestError(const QVariant&)), this,
   386         
   386             SLOT(handleError(const QVariant&)));
       
   387 
       
   388         //disbale subscritption for the CV events
       
   389         ConversationsEngine::instance()->disableRegisterationForCVEvents();
       
   390                 
   387         request->setArguments(args);
   391         request->setArguments(args);
   388         request->send();
   392         request->send();
   389         delete request;
   393         delete request;
   390     }
   394     }
   391 }
   395 }
   394 // MsgContactCardWidget::resolveContactId
   398 // MsgContactCardWidget::resolveContactId
   395 // @see header
   399 // @see header
   396 //---------------------------------------------------------------
   400 //---------------------------------------------------------------
   397 int MsgContactCardWidget::resolveContactId(const QString& value)
   401 int MsgContactCardWidget::resolveContactId(const QString& value)
   398 {
   402 {
   399     int contactId = -1;
   403     QString displayLabel;
   400     
   404 
   401     QContactManager phonebookManager("symbian");
   405     int count;
   402     
   406     return MsgContactHandler::resolveContactDisplayName(value, displayLabel, count);
   403     QContactDetailFilter phoneFilter;
       
   404     phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName,
       
   405                                         QContactPhoneNumber::FieldNumber);
       
   406     phoneFilter.setValue(value);
       
   407     phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
       
   408 
       
   409     QList<QContactSortOrder> sortOrder;
       
   410     QList<QContact> matchingContacts = phonebookManager.contacts(
       
   411             phoneFilter,
       
   412             sortOrder,
       
   413             QStringList());
       
   414 
       
   415     if ( matchingContacts.count() > 0 ) 
       
   416         {       
       
   417         contactId = matchingContacts.at(0).localId();   
       
   418         }
       
   419     
       
   420     return contactId;
       
   421 }
   407 }
   422 
   408 
   423 //---------------------------------------------------------------
   409 //---------------------------------------------------------------
   424 // MsgContactCardWidget::call
   410 // MsgContactCardWidget::call
   425 // @see header
   411 // @see header
   426 //---------------------------------------------------------------
   412 //---------------------------------------------------------------
   427 void MsgContactCardWidget::call()
   413 void MsgContactCardWidget::call()
   428 {
   414 {
   429     //Launch dialer service     
   415     //Launch dialer service     
   430     QString serviceName("com.nokia.services.telephony");
   416     QString serviceName("com.nokia.symbian.ICallDial");
   431     QString operation("dial(QString)");
   417     QString operation("dial(QString)");
   432     
   418 
   433     XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName,operation,false);
   419     XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName, operation, false);
   434     
   420 
   435     connect(serviceRequest, SIGNAL(requestCompleted(QVariant)),
   421     connect(serviceRequest, SIGNAL(requestCompleted(QVariant)), this,
   436             this, SLOT(onServiceRequestCompleted()));
   422         SLOT(onServiceRequestCompleted()));
   437     
   423 
   438     connect(serviceRequest, SIGNAL(requestError(int)),
   424     connect(serviceRequest, SIGNAL(requestError(int)), this, SLOT(onServiceRequestCompleted()));
   439             this, SLOT(onServiceRequestCompleted()));
   425 
   440     
       
   441     *serviceRequest << mContactNumber;
   426     *serviceRequest << mContactNumber;
   442     serviceRequest->send();
   427     serviceRequest->send();
   443 }
   428 }
   444 
   429 
   445 //---------------------------------------------------------------
   430 //---------------------------------------------------------------
   446 // MsgContactCardWidget::addToContacts
   431 // MsgContactCardWidget::addToContacts
   447 // @see header
   432 // @see header
   448 //---------------------------------------------------------------
   433 //---------------------------------------------------------------
   449 void MsgContactCardWidget::addToContacts()
   434 void MsgContactCardWidget::addToContacts()
   450 {
   435 {
       
   436     openContactInfo();
   451 }
   437 }
   452 
   438 
   453 //---------------------------------------------------------------
   439 //---------------------------------------------------------------
   454 // MsgContactCardWidget::handleOk
   440 // MsgContactCardWidget::handleOk
   455 // @see header
   441 // @see header
   456 //---------------------------------------------------------------
   442 //---------------------------------------------------------------
   457 void MsgContactCardWidget::handleOk(const QVariant& result)
   443 void MsgContactCardWidget::handleOk(const QVariant& result)
   458 {
   444 {
   459     Q_UNUSED(result)
   445     Q_UNUSED(result)
       
   446 
       
   447     QList<QContact> matchingContacts = MsgContactHandler::findContactList(mContactNumber);
       
   448 
       
   449     if (!matchingContacts.isEmpty()) {
       
   450         setAddress(matchingContacts.at(0).displayLabel());
       
   451 
       
   452         QList<QContactAvatar> avatarDetails = matchingContacts.at(0).details<QContactAvatar> ();
       
   453 
       
   454         if (!avatarDetails.isEmpty()) {
       
   455             mThumbnailManager->getThumbnail(avatarDetails.at(0).imageUrl().toString());
       
   456         }
       
   457 	}
       
   458 	
       
   459 	// Get the new conversation id.
       
   460     qint64 convId = ConversationsEngine::instance()->getConversationIdFromAddress(
       
   461                 mContactNumber);
       
   462     emit conversationIdChanged(convId);
       
   463             
       
   464     ConversationsEngine::instance(
       
   465                     )->emitOpenConversationViewIdUpdate(convId);
   460     
   466     
   461     QContactManager phonebookManager("symbian");
   467 }
   462         
   468 
   463     QContactDetailFilter phoneFilter;
   469 //---------------------------------------------------------------
   464     phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, 
   470 // MsgContactCardWidget::handleError
   465                                             QContactPhoneNumber::FieldNumber);
   471 // @see header
   466     phoneFilter.setValue(mContactNumber);
   472 //---------------------------------------------------------------
   467     phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
   473 void MsgContactCardWidget::handleError(int errorCode, const QString& errorMessage)
   468 
   474 {
   469     QList<QContactSortOrder> sortOrder;
   475     Q_UNUSED(errorMessage)
   470     QList<QContact> matchingContacts = phonebookManager.contacts(phoneFilter,
   476     Q_UNUSED(errorCode)    
   471                                        sortOrder, QStringList());
       
   472     
   477     
   473     if(matchingContacts.count())
   478     //unblock the cv events in case of contacts save error
   474     {
   479     ConversationsEngine::instance(
   475         setAddress(matchingContacts.at(0).displayLabel());
   480                         )->emitOpenConversationViewIdUpdate(
   476     }
   481                                 ConversationsEngine::instance(
   477 }
   482                                         )->getCurrentConversationId(
   478 
   483                                                 ));
   479 //---------------------------------------------------------------
   484 }
   480 // MsgContactCardWidget::handleError
   485 
   481 // @see header
       
   482 //---------------------------------------------------------------
       
   483 void MsgContactCardWidget::handleError(int errorCode, const QString& errorMessage)
       
   484     {
       
   485     Q_UNUSED(errorMessage)
       
   486     Q_UNUSED(errorCode)
       
   487     }
       
   488 	
       
   489 //---------------------------------------------------------------
   486 //---------------------------------------------------------------
   490 // MsgContactCardWidget::onServiceRequestCompleted
   487 // MsgContactCardWidget::onServiceRequestCompleted
   491 // @see header
   488 // @see header
   492 //---------------------------------------------------------------
   489 //---------------------------------------------------------------
   493 void MsgContactCardWidget::onServiceRequestCompleted()
   490 void MsgContactCardWidget::onServiceRequestCompleted()
   494 {
   491 {
   495     //service request is now complete. delete it.
   492     //service request is now complete. delete it.
   496     XQServiceRequest* request = qobject_cast<XQServiceRequest*>(sender());
   493     XQServiceRequest* request = qobject_cast<XQServiceRequest*> (sender());
   497     if(request)
   494     if (request) {
   498     {
       
   499         delete request;
   495         delete request;
   500     }
   496     }
   501 }
   497 }
   502 
   498 
   503 //---------------------------------------------------------------
   499 //---------------------------------------------------------------
   504 // MsgContactCardWidget::connectSignals
   500 // MsgContactCardWidget::thumbnailReady
   505 // @see header
   501 // @see header
   506 //---------------------------------------------------------------
   502 //---------------------------------------------------------------
   507 void MsgContactCardWidget::connectSignals(bool yes)
   503 void MsgContactCardWidget::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
   508 {
   504 {
   509     if(yes)
   505     Q_UNUSED(data)
   510     {
   506     Q_UNUSED(id)
   511         connect(this,SIGNAL(clicked()),this,SLOT(openContactInfo()));
   507 
   512     }
   508     if (!error) {
   513     else
   509         QIcon icon(pixmap);
   514     {
   510         setAvatar(HbIcon(icon));
   515         disconnect(this,SIGNAL(clicked()),this,SLOT(openContactInfo()));
   511     }
   516     }
   512     else {
       
   513         setAvatar(HbIcon(DEFAULT_AVATAR_ICON));
       
   514     }
       
   515 }
       
   516 
       
   517 //---------------------------------------------------------------
       
   518 // MsgContactCardWidget::ignoreSignals
       
   519 // @see header
       
   520 //---------------------------------------------------------------
       
   521 void MsgContactCardWidget::ignoreSignals(bool yes)
       
   522 {
       
   523     mIgnoreEvents = yes;
       
   524 }
       
   525 
       
   526 //---------------------------------------------------------------
       
   527 // MsgContactCardWidget::regrabGesture
       
   528 // @see header file
       
   529 //---------------------------------------------------------------
       
   530 void MsgContactCardWidget::regrabGesture()
       
   531 {
       
   532     this->grabGesture(Qt::TapGesture);
   517 }
   533 }
   518 // EOF
   534 // EOF