messagingapp/msgui/unifiedviewer/src/univieweraddresswidget.cpp
changeset 52 12db4185673b
parent 44 36f374c67aa8
child 70 a15d9966050f
--- a/messagingapp/msgui/unifiedviewer/src/univieweraddresswidget.cpp	Tue Jul 06 14:12:40 2010 +0300
+++ b/messagingapp/msgui/unifiedviewer/src/univieweraddresswidget.cpp	Wed Aug 18 09:45:25 2010 +0300
@@ -43,7 +43,7 @@
 const QString SPACE(" ");
 
 //localization
-#define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info")
+#define LOC_CONTACT_INFO      hbTrId("txt_messaging_menu_contact_info")
 #define LOC_CALL              hbTrId("txt_common_menu_call_verb")
 #define LOC_SEND_MESSAGE      hbTrId("txt_common_menu_send_message")
 #define LOC_SAVE_TO_CONTACTS  hbTrId("txt_common_menu_save_to_contacts")
@@ -123,7 +123,7 @@
                     //do short tap action.
                     if (!anchor.isEmpty() && !this->textCursor().hasSelection())
                     {
-                        shortTapAction(anchor);
+                        shortTapAction(anchor,tap->scenePosition());
                     }
                 }
                 break;
@@ -349,34 +349,73 @@
 
     if(!anchor.isEmpty() && !this->textCursor().hasSelection())
     {
-
-        HbAction* action = NULL;
+        populateMenu(contextMenu,anchor);
+    }
+}
 
-        action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo()));
-        action->setData(anchor);
-
-        action = contextMenu->addAction(LOC_CALL, this, SLOT(call()));
-        action->setData(anchor);
+void UniViewerAddressWidget::populateMenu(HbMenu* contextMenu,const QString& data)
+{
+    HbAction* action = NULL;
 
-        action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage()));
-        action->setData(anchor);
-
+    int contactId = MsgContactHandler::resolveContactDisplayName(
+                                 data, 
+                                 QContactPhoneNumber::DefinitionName,
+                                 QContactPhoneNumber::FieldNumber); 
+    
+    if(contactId > 0)
+    {
+        action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo()));
+        action->setData(data);
+    }
+    else
+    {
         action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
-        action->setData(anchor);
-
-        action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
-        action->setData(anchor);
-
+        action->setData(data);  
     }
 
-    connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed()));    
+    action = contextMenu->addAction(LOC_CALL, this, SLOT(call()));
+    action->setData(data);
+
+    action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage()));
+    action->setData(data);
+
+    action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
+    action->setData(data);
+    
+    connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed())); 
 }
 
-void UniViewerAddressWidget::shortTapAction(QString anchor)
+void UniViewerAddressWidget::shortTapAction(QString anchor,const QPointF& pos)
 {
     HbAction action;
     action.setData(anchor);
-    connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo()));
+
+
+    int contactId = MsgContactHandler::resolveContactDisplayName(
+        anchor, 
+        QContactPhoneNumber::DefinitionName,
+        QContactPhoneNumber::FieldNumber);        
+
+    if(contactId > 0 )
+    {
+        //if resolved conatct open contact card 
+        connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo()));
+    }
+    else
+    {
+        //unresolved contact show popup.  
+        highlightText(true);
+
+        HbMenu* contextMenu = new HbMenu();
+        contextMenu->setDismissPolicy(HbPopup::TapAnywhere);
+        contextMenu->setAttribute(Qt::WA_DeleteOnClose, true);
+        contextMenu->setPreferredPos(pos); 
+
+        populateMenu(contextMenu,anchor);
+        
+        contextMenu->show();
+    }
+
     action.trigger();
 }
 
@@ -509,7 +548,7 @@
 
 void UniViewerAddressWidget::saveToContacts()
 {
-    //handler for save to contacts.
+    openContactInfo();
 }
 
 void UniViewerAddressWidget::sendMessage()