messagingapp/msgui/unifiedviewer/src/univiewertextitem.cpp
changeset 44 36f374c67aa8
parent 43 35b64624a9e7
child 47 5b14749788d7
child 52 12db4185673b
--- a/messagingapp/msgui/unifiedviewer/src/univiewertextitem.cpp	Wed Jun 23 18:09:17 2010 +0300
+++ b/messagingapp/msgui/unifiedviewer/src/univiewertextitem.cpp	Tue Jul 06 14:12:40 2010 +0300
@@ -38,11 +38,11 @@
 //consts
 
 //regexp
-const QString NUMBER_PATTERN("(\\(|\\+|\\d)((?:\\d{2,})((?:[\\s-/.\\)\\()])*(?:(\\d+|\\))))*)|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))");
+const QString NUMBER_PATTERN("(\\(?(\\+|\\d))((?:\\d)((?:[\\s-/.\\)\\(])*(?:(\\d+|\\))))*(?:\\d?|\\)))|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))");
 
 const QString EMAIL_PATTERN("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?");
 
-const QString URL_PATTERN("(((ht|f|rt)(tp|sp)(s?)\\:\\/\\/)|(www|wap)(?:\\.))(([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*)(\\.)([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*))+");
+const QString URL_PATTERN("(((ht|f|rt)(tp|sp)(s?)\\:\\/\\/)|(www|wap)(?:\\.))(([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*)(\\.)([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*))+[a-zA-Z0-9/]");
 
 //rules
 const QString NUMBER_RULE("NUMBER_RULE");
@@ -50,7 +50,7 @@
 const QString URL_RULE("URL_RULE");
 
 //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")
@@ -67,7 +67,6 @@
 {
     this->setReadOnly(true);
     this->setScrollable(false);
-    this->setSmileysEnabled(true);
     this->setCursorVisibility(Hb::TextCursorHidden);
     this->setFlag(QGraphicsItem::ItemIsFocusable,false);
     this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
@@ -211,7 +210,7 @@
                     //do short tap action.
                     if (!anchor.isEmpty() && !this->textCursor().hasSelection())
                     {
-                        shortTapAction(anchor);
+                        handleShortTap(anchor,tap->scenePosition());
                     }
                 }
                 break;
@@ -244,8 +243,23 @@
 {
     HbAction* action = NULL;
 
-    action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo()));
-    action->setData(data);
+    QString number = data;
+    number.remove(NUMBER_RULE);
+    int contactId = MsgContactHandler::resolveContactDisplayName(
+                                 number, 
+                                 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(data);  
+    }
 
     action = contextMenu->addAction(LOC_CALL, this, SLOT(call()));
     action->setData(data);
@@ -253,9 +267,6 @@
     action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage()));
     action->setData(data);
 
-    action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
-    action->setData(data);
-
     action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard()));
     action->setData(data);
 }
@@ -267,7 +278,7 @@
     action = contextMenu->addAction(LOC_CREATE_EMAIL, this, SLOT(createEmail()));
     action->setData(data);
     
-    action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo()));
+    action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo()));
     action->setData(data);
 
     action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts()));
@@ -291,15 +302,40 @@
     action->setData(data);
 }
 
-void UniViewerTextItem::shortTapAction(QString anchor)
+void UniViewerTextItem::handleShortTap(QString anchor,const QPointF& pos)
 {
     HbAction action;
     action.setData(anchor);
 
     if(anchor.contains(NUMBER_RULE))
     {
-        //open vcard template.
-        connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo()));
+        QString data = anchor;
+        data.remove(NUMBER_RULE);
+        int contactId = MsgContactHandler::resolveContactDisplayName(
+                                     data, 
+                                     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); 
+            connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed()));
+            
+            addNumberMenu(contextMenu,anchor);
+            
+            contextMenu->show();
+        }
     }
     else if(anchor.contains(EMAIL_RULE))
     {
@@ -534,7 +570,7 @@
 
 void UniViewerTextItem::saveToContacts()
 {
-    //handler for save to contacts.
+     openContactInfo();
 }
 
 void UniViewerTextItem::onServiceRequestCompleted()