messagingapp/msgui/unifiededitor/src/msgunieditoraddress.cpp
branchRCL_3
changeset 57 ebe688cedc25
equal deleted inserted replaced
54:fa1df4b99609 57:ebe688cedc25
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDES
       
    19 #include <QTimer>
       
    20 #include <HbTextItem>
       
    21 #include <HbPushButton>
       
    22 #include <HbAction>
       
    23 #include <hbmessagebox.h>
       
    24 #include <cntservicescontact.h>
       
    25 #include <xqaiwrequest.h>
       
    26 #include <xqappmgr.h>
       
    27 #include <telconfigcrkeys.h>        // KCRUidTelephonyConfiguration
       
    28 #include <centralrepository.h>
       
    29 #include <HbNotificationDialog>
       
    30 #include <commonphoneparser.h>      // Common phone number validity checker
       
    31 #include <xqconversions.h>
       
    32 #include <HbEditorInterface>
       
    33 
       
    34 // USER INCLUDES
       
    35 #include "debugtraces.h"
       
    36 #include "msgunieditoraddress.h"
       
    37 #include "msgunieditorlineedit.h"
       
    38 #include "msgunieditormonitor.h"
       
    39 #include "UniEditorGenUtils.h"
       
    40 
       
    41 const QString PBK_ICON("qtg_mono_contacts");
       
    42 const QString REPLACEMENT_STR("; ");
       
    43 const QString COMMA_SEPERATOR(",");
       
    44 
       
    45 // Constants
       
    46 const int KDefaultGsmNumberMatchLength = 7;  //matching unique ph numbers
       
    47 #define LOC_SMS_RECIPIENT_LIMIT_REACHED hbTrId("txt_messaging_dialog_number_of_recipients_exceeded")
       
    48 #define LOC_MMS_RECIPIENT_LIMIT_REACHED hbTrId("txt_messaging_dpopinfo_unable_to_add_more_recipien")
       
    49 #define LOC_DIALOG_OK hbTrId("txt_common_button_ok")
       
    50 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
       
    51 #define LOC_INVALID_RECIPIENT hbTrId("txt_messaging_dialog_invalid_recipient_found")
       
    52 #define LOC_INVALID_RECIPIENT_NOT_ADDED hbTrId("txt_messaging_dialog_invalid_recipient_not_added")
       
    53 #define LOC_INVALID_RECIPIENTS_NOT_ADDED hbTrId("txt_messaging_dialog_invalid_recipients_not_added")
       
    54 
       
    55 
       
    56 
       
    57 
       
    58 
       
    59 MsgUnifiedEditorAddress::MsgUnifiedEditorAddress( const QString& label,
       
    60                                                   QGraphicsItem *parent ) :
       
    61 MsgUnifiedEditorBaseWidget(parent),
       
    62 mSkipMaxRecipientQuery(false),
       
    63 mAboutToExceedMaxSmsRecipients(false),
       
    64 mAboutToExceedMaxMmsRecipients(false),
       
    65 mExceedsMaxMmsRecipientsBy(0)
       
    66 {
       
    67     this->setContentsMargins(0,0,0,0);
       
    68 
       
    69     mLaunchBtn = new HbPushButton(this);
       
    70     HbStyle::setItemName(mLaunchBtn,"launchBtn");
       
    71     connect(mLaunchBtn,SIGNAL(clicked()),this,SLOT(fetchContacts()));
       
    72 
       
    73     mLaunchBtn->setIcon(HbIcon(PBK_ICON));
       
    74 
       
    75     mAddressEdit = new MsgUnifiedEditorLineEdit(label,this);
       
    76     HbStyle::setItemName(mAddressEdit,"addressField");
       
    77 
       
    78     mAddressEdit->setMaxRows(40);
       
    79     connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
       
    80             this, SLOT(onContentsChanged(const QString&)));
       
    81 
       
    82     mAddressEdit->setInputMethodHints(Qt::ImhPreferNumbers);
       
    83     
       
    84     //To allow only latin char(s) in address fields.
       
    85     HbEditorInterface editorInterface(mAddressEdit);
       
    86     editorInterface.setInputConstraints(HbEditorConstraintLatinAlphabetOnly);
       
    87 }
       
    88 
       
    89 MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress()
       
    90 {
       
    91 	//TODO: Should remove this code depending on orbit's reply whether it is needed
       
    92 	//to unregister the same plugin registered on two different widgets twice.
       
    93     //style()->unregisterPlugin(mPluginPath);
       
    94 }
       
    95 
       
    96 void MsgUnifiedEditorAddress::fetchContacts()
       
    97 {
       
    98     mLaunchBtn->blockSignals(true);
       
    99 
       
   100     QList<QVariant> args;
       
   101     QString serviceName("com.nokia.services.phonebookservices");
       
   102     QString operation("fetch(QString,QString,QString)");
       
   103     XQAiwRequest* request;
       
   104     XQApplicationManager appManager;
       
   105     request = appManager.create(serviceName, "Fetch", operation, true); // embedded
       
   106     if ( request == NULL )
       
   107         {
       
   108         return;
       
   109         }
       
   110 
       
   111     // Result handlers
       
   112     connect (request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
       
   113     connect (request, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
       
   114 
       
   115     args << QString(tr("Phonebook"));
       
   116     args << KCntActionAll;
       
   117     args << KCntFilterDisplayAll;
       
   118 
       
   119     request->setArguments(args);
       
   120     request->send();
       
   121     delete request;
       
   122 
       
   123     //unblock click signal after some delay.
       
   124     QTimer::singleShot(250,this,SLOT(unblockSignals()));
       
   125 }
       
   126 
       
   127 void MsgUnifiedEditorAddress::handleOk(const QVariant& value)
       
   128 {
       
   129    CntServicesContactList contactList =
       
   130            qVariantValue<CntServicesContactList>(value);
       
   131     int count = contactList.count();
       
   132 
       
   133     ConvergedMessageAddressList addrlist;
       
   134     for(int i = 0; i < count; i++ )
       
   135     {
       
   136         ConvergedMessageAddress* address =
       
   137                 new ConvergedMessageAddress();
       
   138         if(!contactList[i].mPhoneNumber.isEmpty())
       
   139         {
       
   140             address->setAddress(contactList[i].mPhoneNumber);
       
   141         }
       
   142         else
       
   143         {
       
   144             address->setAddress(contactList[i].mEmailAddress);
       
   145         }
       
   146         address->setAlias(contactList[i].mDisplayName);
       
   147         addrlist << address;
       
   148     }
       
   149     setAddresses(addrlist);
       
   150 }
       
   151 
       
   152 void MsgUnifiedEditorAddress::handleError(int errorCode, const QString& errorMessage)
       
   153 {
       
   154     Q_UNUSED(errorMessage)
       
   155     Q_UNUSED(errorCode)
       
   156 }
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // MsgUnifiedEditorAddress::addresses
       
   160 // @see header
       
   161 // ----------------------------------------------------------------------------
       
   162 ConvergedMessageAddressList MsgUnifiedEditorAddress::addresses(
       
   163         bool removeDuplicates)
       
   164 {
       
   165 #ifdef _DEBUG_TRACES_
       
   166     qCritical() << "MsgUnifiedEditorAddress::addresses start";
       
   167 #endif
       
   168     // sync-up map to account for user-actions on edit-field
       
   169     syncDeletionsToMap();
       
   170     syncAdditionsToMap();
       
   171 
       
   172     ConvergedMessageAddressList addresses;
       
   173     if(removeDuplicates)
       
   174     {
       
   175         QStringList uniqueAddr;
       
   176         uniqueAddr = uniqueAddressList();
       
   177         foreach(QString addr, uniqueAddr)
       
   178         {
       
   179             ConvergedMessageAddress* address = new ConvergedMessageAddress;
       
   180             address->setAddress(addr);
       
   181             address->setAlias(mAddressMap.value(addr));
       
   182             addresses.append(address);
       
   183         }
       
   184     }
       
   185     else
       
   186     {
       
   187         QMap<QString, QString>::iterator i = mAddressMap.begin();
       
   188         while (i != mAddressMap.end())
       
   189         {
       
   190             ConvergedMessageAddress* address = new ConvergedMessageAddress;
       
   191             address->setAddress(i.key());
       
   192             address->setAlias(i.value());
       
   193             addresses.append(address);
       
   194             i++;
       
   195         }
       
   196     }
       
   197 #ifdef _DEBUG_TRACES_
       
   198     qCritical() << "MsgUnifiedEditorAddress::addresses end";
       
   199 #endif
       
   200     return addresses;
       
   201 }
       
   202 
       
   203 int MsgUnifiedEditorAddress::addressCount()
       
   204 {
       
   205     return mAddressEdit->addresses().count();
       
   206 }
       
   207 
       
   208 void MsgUnifiedEditorAddress::setAddresses(ConvergedMessageAddressList addrlist)
       
   209 {
       
   210     // avoid processing if no info available
       
   211     if(addrlist.count() == 0)
       
   212     {
       
   213         return;
       
   214     }
       
   215 
       
   216     // ensure flags are reset before starting the addr addition
       
   217     mAboutToExceedMaxSmsRecipients = false;
       
   218     mAboutToExceedMaxMmsRecipients = false;
       
   219     mExceedsMaxMmsRecipientsBy = 0;
       
   220 
       
   221     // first, we check if MMS max-recipient count will exceed
       
   222     int count = addrlist.count();
       
   223 	int futureCount = count + MsgUnifiedEditorMonitor::msgAddressCount();
       
   224 	if(futureCount > MsgUnifiedEditorMonitor::maxMmsRecipients())
       
   225 	{
       
   226 	    mAboutToExceedMaxMmsRecipients = true;
       
   227 	    mExceedsMaxMmsRecipientsBy =
       
   228 	            futureCount - MsgUnifiedEditorMonitor::maxMmsRecipients();
       
   229 	}
       
   230 	// else, check if SMS max-recipient count will exceed
       
   231 	else if(!mSkipMaxRecipientQuery)
       
   232 	{
       
   233 	    futureCount = count + addressCount();
       
   234 	    if( (addressCount() <= MsgUnifiedEditorMonitor::maxSmsRecipients()) &&
       
   235 	        (futureCount > MsgUnifiedEditorMonitor::maxSmsRecipients()) )
       
   236 	    {
       
   237 	        mAboutToExceedMaxSmsRecipients = true;
       
   238 	    }
       
   239 	}
       
   240 
       
   241 	int  invalidCount= 0;
       
   242     QString invalidContacts;
       
   243     for(int i = 0; i < count; i++ )
       
   244         {
       
   245         bool isValid = false;
       
   246         isValid = checkValidAddress(addrlist.at(i)->address());
       
   247         if(!isValid)
       
   248            {
       
   249             invalidCount ++;
       
   250             // append the comma till last but one contact.
       
   251             // add the invalid ocntacts to the " , " seperated string.
       
   252             if(invalidCount > 1)
       
   253                 {
       
   254                 invalidContacts.append(COMMA_SEPERATOR);
       
   255                 }
       
   256             invalidContacts.append(addrlist.at(i)->alias());
       
   257            }
       
   258        else
       
   259            {
       
   260            mAddressMap.insertMulti(addrlist[i]->address(), addrlist[i]->alias());
       
   261            if(!addrlist[i]->alias().isEmpty())
       
   262               {
       
   263               mAddressEdit->setText(addrlist[i]->alias());
       
   264               }
       
   265            else
       
   266               {
       
   267               mAddressEdit->setText(addrlist[i]->address(), false);
       
   268               }
       
   269            }
       
   270        }
       
   271     if(invalidCount)
       
   272         {
       
   273         QString invalidStr;
       
   274         (invalidCount == 1)?(invalidStr = QString(LOC_INVALID_RECIPIENT_NOT_ADDED)) :(invalidStr = QString(LOC_INVALID_RECIPIENTS_NOT_ADDED));
       
   275         // append line seperator
       
   276          invalidStr.append("<br>");
       
   277          invalidStr.append(invalidContacts);
       
   278          HbMessageBox::information(invalidStr, 0, 0, HbMessageBox::Ok);
       
   279         }
       
   280 
       
   281     // addition operation complete, reset flags
       
   282     mAboutToExceedMaxSmsRecipients = false;
       
   283     mAboutToExceedMaxMmsRecipients = false;
       
   284     mExceedsMaxMmsRecipientsBy = 0;
       
   285 }
       
   286 
       
   287 int MsgUnifiedEditorAddress::contactMatchDigits()
       
   288 {
       
   289     // Read the amount of digits to be used in contact matching
       
   290     // The key is owned by PhoneApp
       
   291     int matchDigitCount = 0;
       
   292     TRAP_IGNORE(
       
   293         CRepository* repository = CRepository::NewLC(KCRUidTelConfiguration);
       
   294         if ( repository->Get(KTelMatchDigits, matchDigitCount) == KErrNone )
       
   295         {
       
   296             // Min is 7
       
   297             matchDigitCount = Max(matchDigitCount, KDefaultGsmNumberMatchLength);
       
   298         }
       
   299         CleanupStack::PopAndDestroy(); // repository
       
   300     );
       
   301     return matchDigitCount;
       
   302 }
       
   303 
       
   304 void MsgUnifiedEditorAddress::onContentsChanged(const QString& text)
       
   305 {
       
   306     // Max MMS recipient count check
       
   307     if( mAboutToExceedMaxMmsRecipients ||
       
   308         (MsgUnifiedEditorMonitor::msgAddressCount() >= MsgUnifiedEditorMonitor::maxMmsRecipients()) )
       
   309     {
       
   310         if(mAboutToExceedMaxMmsRecipients)
       
   311         {// show discreet note only once
       
   312             --mExceedsMaxMmsRecipientsBy;
       
   313             if(!mExceedsMaxMmsRecipientsBy)
       
   314             {
       
   315                 HbMessageBox::information(LOC_MMS_RECIPIENT_LIMIT_REACHED, 0, 0, HbMessageBox::Ok);
       
   316             }
       
   317             resetToPrevious();
       
   318         }
       
   319         else
       
   320         {
       
   321             // update monitor data
       
   322             emit contentChanged();
       
   323             if(MsgUnifiedEditorMonitor::msgAddressCount() > MsgUnifiedEditorMonitor::maxMmsRecipients())
       
   324             {
       
   325                 HbMessageBox::information(LOC_MMS_RECIPIENT_LIMIT_REACHED, 0, 0, HbMessageBox::Ok);
       
   326                 resetToPrevious();
       
   327                 // reset monitor data
       
   328                 emit contentChanged();
       
   329             }
       
   330             else
       
   331             {
       
   332                 mPrevBuffer = text;
       
   333             }
       
   334         }
       
   335         return;
       
   336     }
       
   337 
       
   338     // Max SMS recipient count check
       
   339     if( !mSkipMaxRecipientQuery &&
       
   340         (MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Sms) &&
       
   341         (mAddressEdit->addresses().count() > MsgUnifiedEditorMonitor::maxSmsRecipients()) )
       
   342     {
       
   343         // when we show this dialog, we don't want the intermediate states
       
   344         // to be signalled to us
       
   345         disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
       
   346                 this, SLOT(onContentsChanged(const QString&)));
       
   347         QTimer::singleShot(50, this, SLOT(handleRecipientLimitReached()));
       
   348     }
       
   349     else
       
   350     {
       
   351         if(!mAboutToExceedMaxSmsRecipients)
       
   352         {// remember addresses before the block insertion started
       
   353             mPrevBuffer = text;
       
   354         }
       
   355         emit contentChanged();
       
   356     }
       
   357 }
       
   358 
       
   359 void MsgUnifiedEditorAddress::handleRecipientLimitReached()
       
   360 {
       
   361     HbMessageBox* dlg = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   362     dlg->setAttribute(Qt::WA_DeleteOnClose);
       
   363     dlg->setFocusPolicy(Qt::NoFocus);
       
   364     dlg->setTimeout(HbPopup::NoTimeout);
       
   365 
       
   366     dlg->setText(LOC_SMS_RECIPIENT_LIMIT_REACHED);
       
   367     
       
   368     dlg->clearActions();
       
   369     HbAction* okAction = new HbAction(LOC_DIALOG_OK,dlg);
       
   370     dlg->addAction(okAction);
       
   371 
       
   372     HbAction* cancelAction = new HbAction(LOC_BUTTON_CANCEL,dlg);
       
   373     dlg->addAction(cancelAction);
       
   374 
       
   375     dlg->open(this,SLOT(onMaxRecipientsReached(HbAction*)));
       
   376     // reconnect to get back updates
       
   377     connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
       
   378             this, SLOT(onContentsChanged(const QString&)));
       
   379 }
       
   380 
       
   381 void MsgUnifiedEditorAddress::syncDeletionsToMap()
       
   382 {
       
   383     // get address list from edit-field
       
   384     QStringList addrList = mAddressEdit->addresses();
       
   385 
       
   386     QMap<QString, QString>::iterator i = mAddressMap.begin();
       
   387     while (i != mAddressMap.end())
       
   388     {
       
   389         // check if either key or value is present in the list
       
   390         if( !(addrList.contains(i.value(), Qt::CaseSensitive) ||
       
   391               addrList.contains(i.key(), Qt::CaseSensitive)) )
       
   392         {// if none are present, then delete entry from map
       
   393             i = mAddressMap.erase(i);
       
   394         }
       
   395         else
       
   396         {
       
   397             // ensure that the matched contact is removed from the
       
   398             // address's list
       
   399             int matchedIndex = addrList.indexOf(i.value());
       
   400             if(matchedIndex == -1)
       
   401             {
       
   402                 matchedIndex = addrList.indexOf(i.key());
       
   403             }
       
   404             if(matchedIndex != -1)
       
   405             {
       
   406                 addrList.removeAt(matchedIndex);
       
   407             }
       
   408             // now go to next index in map
       
   409             ++i;
       
   410         }
       
   411     }
       
   412 }
       
   413 
       
   414 void MsgUnifiedEditorAddress::syncAdditionsToMap()
       
   415 {
       
   416     // remove already mapped addresses from edit-field
       
   417     QStringList userInputAddrList(mAddressEdit->addresses());
       
   418     QStringList mapAddrList = mAddressMap.values();
       
   419     mapAddrList << mAddressMap.keys();
       
   420     foreach(QString addr, mapAddrList)
       
   421     {
       
   422         userInputAddrList.removeOne(addr);
       
   423     }
       
   424 
       
   425     // add the unmapped addresses to address-map
       
   426     foreach(QString addr, userInputAddrList)
       
   427     {
       
   428         mAddressMap.insertMulti(addr, QString());
       
   429     }
       
   430 }
       
   431 
       
   432 QStringList MsgUnifiedEditorAddress::uniqueAddressList()
       
   433 {
       
   434     int matchDigitCount = MsgUnifiedEditorAddress::contactMatchDigits();
       
   435     QStringList mapAddrList = mAddressMap.keys();
       
   436     for(int j = 0;j<mapAddrList.count()-1;j++)
       
   437     {
       
   438         for(int i =j+1;i<mapAddrList.count();i++)
       
   439         {
       
   440             if(0 == mapAddrList[j].right(matchDigitCount).compare(mapAddrList[i].right(matchDigitCount)))
       
   441             {
       
   442                mapAddrList.removeAt(i);
       
   443                i--;
       
   444             }
       
   445         }
       
   446     }
       
   447     return mapAddrList;
       
   448 }
       
   449 
       
   450 // ----------------------------------------------------------------------------
       
   451 // MsgUnifiedEditorAddress::skipMaxRecipientQuery
       
   452 // @see header
       
   453 // ----------------------------------------------------------------------------
       
   454 void MsgUnifiedEditorAddress::skipMaxRecipientQuery(bool skip)
       
   455 {
       
   456     mSkipMaxRecipientQuery = skip;
       
   457 }
       
   458 
       
   459 void MsgUnifiedEditorAddress::setFocus()
       
   460 {
       
   461     mAddressEdit->setFocus(Qt::MouseFocusReason);
       
   462 }
       
   463 
       
   464 // ----------------------------------------------------------------------------
       
   465 // MsgUnifiedEditorAddress::resetToPrevious
       
   466 // @see header
       
   467 // ----------------------------------------------------------------------------
       
   468 void MsgUnifiedEditorAddress::resetToPrevious()
       
   469 {
       
   470     // when we do this reset operation, we don't want the intermediate states
       
   471     // to be signalled to us
       
   472     disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
       
   473             this, SLOT(onContentsChanged(const QString&)));
       
   474 
       
   475     mAddressEdit->clearContent();
       
   476     QStringList list = mPrevBuffer.split(REPLACEMENT_STR,
       
   477             QString::SkipEmptyParts);
       
   478     int count = list.count();
       
   479     QStringList valList = mAddressMap.values();
       
   480     for(int i=0; i<count; i++)
       
   481     {
       
   482         QString addr = list.at(i);
       
   483         if(valList.contains(addr))
       
   484         {
       
   485             mAddressEdit->setText(addr);
       
   486         }
       
   487         else
       
   488         {
       
   489             mAddressEdit->setText(addr, false);
       
   490         }
       
   491     }
       
   492     syncDeletionsToMap();
       
   493     connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
       
   494             this, SLOT(onContentsChanged(const QString&)));
       
   495 }
       
   496 
       
   497 // ----------------------------------------------------------------------------
       
   498 // MsgUnifiedEditorAddress::onMaxRecipientsReached
       
   499 // @see header
       
   500 // ----------------------------------------------------------------------------
       
   501 void MsgUnifiedEditorAddress::onMaxRecipientsReached(HbAction* action)
       
   502 {
       
   503     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   504     if (action == dlg->actions().at(0)) {
       
   505         // accept new content, update prev-buffer
       
   506         emit contentChanged();
       
   507         mPrevBuffer = mAddressEdit->content();
       
   508     }
       
   509     else {
       
   510         // reject the new content, keep the old
       
   511         resetToPrevious();
       
   512     }
       
   513 }
       
   514 
       
   515 // ----------------------------------------------------------------------------
       
   516 // MsgUnifiedEditorAddress::validateContacts
       
   517 // @see header
       
   518 // ----------------------------------------------------------------------------
       
   519 bool MsgUnifiedEditorAddress::validateContacts()
       
   520 {
       
   521     UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils);
       
   522 
       
   523     // sync-up map to account for user-actions on address-field
       
   524     syncDeletionsToMap();
       
   525     syncAdditionsToMap();
       
   526 
       
   527     // get the list of contacts in address-field
       
   528     QStringList fieldAddresses(mAddressEdit->addresses());
       
   529 
       
   530     bool isValid = true;
       
   531     foreach(QString addr, fieldAddresses)
       
   532     {
       
   533         // run address validation only if address is unmapped
       
   534         // (i.e. user-inserted)
       
   535         if(mAddressMap.contains(addr))
       
   536         {
       
   537         isValid = checkValidAddress(addr);
       
   538             if(!isValid)
       
   539             {
       
   540                 mAddressEdit->highlightInvalidString(addr);
       
   541                 QString invalidAddrStr =
       
   542                         QString(LOC_INVALID_RECIPIENT).arg(addr);
       
   543                 HbMessageBox* dlg = new HbMessageBox(invalidAddrStr,
       
   544                         HbMessageBox::MessageTypeInformation);
       
   545                 dlg->setDismissPolicy(HbPopup::TapInside);
       
   546                 dlg->setTimeout(HbPopup::NoTimeout);
       
   547                 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
       
   548                 dlg->open(this, SLOT(handleInvalidContactDialog(HbAction*)));
       
   549                 break;
       
   550             }
       
   551         }
       
   552     }
       
   553 
       
   554     return isValid;
       
   555 }
       
   556 // ----------------------------------------------------------------------------
       
   557 // MsgUnifiedEditorAddress::checkValidAddress
       
   558 // @see header
       
   559 // ----------------------------------------------------------------------------
       
   560 bool MsgUnifiedEditorAddress::checkValidAddress(const QString& addr)
       
   561     {
       
   562     bool isValid = false;
       
   563     
       
   564     HBufC *tempAddr = XQConversions::qStringToS60Desc(addr);
       
   565     	
       
   566     // 1. perform number validation
       
   567     isValid = CommonPhoneParser::IsValidPhoneNumber(
       
   568             *tempAddr,
       
   569             CommonPhoneParser::ESMSNumber );
       
   570 
       
   571     // 2. if number validity fails, then perform email addr validation
       
   572     UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils);
       
   573     if(!isValid)
       
   574         { // additional check for MMS only
       
   575         isValid = genUtils->IsValidEmailAddress(
       
   576                     *tempAddr );
       
   577         } 
       
   578     delete genUtils;
       
   579     delete tempAddr;
       
   580     return isValid;
       
   581     }
       
   582 
       
   583 void MsgUnifiedEditorAddress::handleInvalidContactDialog(
       
   584         HbAction* act)
       
   585 {
       
   586     Q_UNUSED(act);
       
   587     QTimer::singleShot(250, this, SLOT(setFocus()));
       
   588 }
       
   589 
       
   590 void MsgUnifiedEditorAddress::unblockSignals()
       
   591 {
       
   592     mLaunchBtn->blockSignals(false);
       
   593 }
       
   594 
       
   595 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
       
   596 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList)
       
   597 
       
   598 //EOF