messagingapp/msgui/unifiededitor/src/msgunieditoraddress.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
child 47 5b14749788d7
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
    14  * Description:
    14  * Description:
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 // INCLUDES
    18 // INCLUDES
    19 #include "debugtraces.h"
    19 #include <QTimer>
    20 #include <HbTextItem>
    20 #include <HbTextItem>
    21 #include <HbPushButton>
    21 #include <HbPushButton>
    22 #include <HbAction>
    22 #include <HbAction>
    23 #include <hbinputeditorinterface.h>
    23 #include <hbinputeditorinterface.h>
       
    24 #include <hbmessagebox.h>
    24 #include <cntservicescontact.h>
    25 #include <cntservicescontact.h>
    25 #include <xqaiwrequest.h>
    26 #include <xqaiwrequest.h>
    26 #include <xqappmgr.h>
    27 #include <xqappmgr.h>
    27 #include <telconfigcrkeys.h>        // KCRUidTelephonyConfiguration
    28 #include <telconfigcrkeys.h>        // KCRUidTelephonyConfiguration
    28 #include <centralrepository.h>
    29 #include <centralrepository.h>
       
    30 #include <HbNotificationDialog>
       
    31 #include <commonphoneparser.h>      // Common phone number validity checker
       
    32 #include <xqconversions.h>
    29 
    33 
    30 // USER INCLUDES
    34 // USER INCLUDES
       
    35 #include "debugtraces.h"
    31 #include "msgunieditoraddress.h"
    36 #include "msgunieditoraddress.h"
    32 #include "msgunifiededitorlineedit.h"
    37 #include "msgunifiededitorlineedit.h"
       
    38 #include "msgmonitor.h"
       
    39 #include "unieditorgenutils.h"
    33 
    40 
    34 const QString PBK_ICON("qtg_mono_contacts");
    41 const QString PBK_ICON("qtg_mono_contacts");
    35 const QString SEND_ICON("qtg_mono_send");
    42 const QString SEND_ICON("qtg_mono_send");
       
    43 const QString replacementStr("; ");
    36 
    44 
    37 // Constants
    45 // Constants
    38 const int KDefaultGsmNumberMatchLength = 7;  //matching unique ph numbers
    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")
    39 
    52 
    40 MsgUnifiedEditorAddress::MsgUnifiedEditorAddress( const QString& label,
    53 MsgUnifiedEditorAddress::MsgUnifiedEditorAddress( const QString& label,
    41                                                   const QString& pluginPath,
       
    42                                                   QGraphicsItem *parent ) :
    54                                                   QGraphicsItem *parent ) :
    43 HbWidget(parent),
    55 MsgUnifiedEditorBaseWidget(parent),
    44 mPluginPath(pluginPath)
    56 mSkipMaxRecipientQuery(false),
    45 {
    57 mAboutToExceedMaxSmsRecipients(false),
    46     #ifdef _DEBUG_TRACES_
    58 mAboutToExceedMaxMmsRecipients(false),
    47     qDebug() << "MsgUnifiedEditorAddress calling HbStyle::registerPlugin";
    59 mExceedsMaxMmsRecipientsBy(0)
    48     #endif
    60 {
    49 
       
    50     this->setContentsMargins(0,0,0,0);
    61     this->setContentsMargins(0,0,0,0);
    51     setPluginBaseId(style()->registerPlugin(mPluginPath));
    62 
    52     
       
    53     mLaunchBtn = new HbPushButton(this);
    63     mLaunchBtn = new HbPushButton(this);
    54     HbStyle::setItemName(mLaunchBtn,"launchBtn");
    64     HbStyle::setItemName(mLaunchBtn,"launchBtn");
    55     connect(mLaunchBtn,SIGNAL(clicked()),this,SLOT(fetchContacts()));
    65     connect(mLaunchBtn,SIGNAL(clicked()),this,SLOT(fetchContacts()));
    56 
    66 
    57     mLaunchBtn->setIcon(HbIcon(PBK_ICON));
    67     mLaunchBtn->setIcon(HbIcon(PBK_ICON));
    59     mAddressEdit = new MsgUnifiedEditorLineEdit(label,this);
    69     mAddressEdit = new MsgUnifiedEditorLineEdit(label,this);
    60     HbStyle::setItemName(mAddressEdit,"addressField");
    70     HbStyle::setItemName(mAddressEdit,"addressField");
    61 
    71 
    62     mAddressEdit->setMaxRows(40);
    72     mAddressEdit->setMaxRows(40);
    63     connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
    73     connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
    64             this, SLOT(onContentsAdded(const QString&)));
    74             this, SLOT(onContentsChanged(const QString&)));
    65 
    75 
    66     // add "Send" action in VKB
    76     // add "Send" action in VKB
    67     HbEditorInterface editorInterface(mAddressEdit);
    77     HbEditorInterface editorInterface(mAddressEdit);
    68     mAddressEdit->setInputMethodHints(Qt::ImhPreferNumbers);
    78     mAddressEdit->setInputMethodHints(Qt::ImhPreferNumbers);
    69     HbAction *sendAction = new HbAction(HbIcon(SEND_ICON), QString(),this);
    79     HbAction *sendAction = new HbAction(HbIcon(SEND_ICON), QString(),this);
    70     connect(sendAction, SIGNAL(triggered()),this, SIGNAL(sendMessage()));
    80     connect(sendAction, SIGNAL(triggered()),this, SIGNAL(sendMessage()));
    71     editorInterface.addAction(sendAction);
    81     editorInterface.addAction(sendAction);
    72     
       
    73     }
    82     }
    74 
    83 
    75 MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress()
    84 MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress()
    76 {
    85 {
    77     style()->unregisterPlugin(mPluginPath);
    86 	//TODO: Should remove this code depending on orbit's reply whether it is needed
       
    87 	//to unregister the same plugin registered on two different widgets twice.
       
    88     //style()->unregisterPlugin(mPluginPath);
    78 }
    89 }
    79 
    90 
    80 void MsgUnifiedEditorAddress::fetchContacts()
    91 void MsgUnifiedEditorAddress::fetchContacts()
    81 {
    92 {
    82     QList<QVariant> args;
    93     QList<QVariant> args;
    85     XQAiwRequest* request;
    96     XQAiwRequest* request;
    86     XQApplicationManager appManager;
    97     XQApplicationManager appManager;
    87     request = appManager.create(serviceName, "Fetch", operation, true); // embedded
    98     request = appManager.create(serviceName, "Fetch", operation, true); // embedded
    88     if ( request == NULL )
    99     if ( request == NULL )
    89         {
   100         {
    90         return;       
   101         return;
    91         }
   102         }
    92 
   103 
    93     // Result handlers
   104     // Result handlers
    94     connect (request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
   105     connect (request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
    95     connect (request, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
   106     connect (request, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
    96     
   107 
    97     args << QString(tr("Phonebook")); 
   108     args << QString(tr("Phonebook"));
    98     args << KCntActionAll;
   109     args << KCntActionAll;
    99     args << KCntFilterDisplayAll;
   110     args << KCntFilterDisplayAll;
   100     
   111 
   101     request->setArguments(args);
   112     request->setArguments(args);
   102     request->send();
   113     request->send();
   103     delete request;
   114     delete request;
   104 }
   115 }
   105 
   116 
   106 void MsgUnifiedEditorAddress::handleOk(const QVariant& value)
   117 void MsgUnifiedEditorAddress::handleOk(const QVariant& value)
   107 {
   118 {
   108    CntServicesContactList contactList;
   119    CntServicesContactList contactList =
   109     contactList = qVariantValue<CntServicesContactList>(value);
   120            qVariantValue<CntServicesContactList>(value);
   110 
   121     int count = contactList.count();
   111     for(int i = 0; i < contactList.count(); i++ )
   122 
   112     {
   123     ConvergedMessageAddressList addrlist;
   113         mAddressMap.insert(contactList[i].mPhoneNumber, contactList[i].mDisplayName);
   124     for(int i = 0; i < count; i++ )
   114         if(!contactList[i].mDisplayName.isEmpty())
   125     {
   115         {
   126         ConvergedMessageAddress* address =
   116             mAddressEdit->setText(contactList[i].mDisplayName);
   127                 new ConvergedMessageAddress();
   117         }
   128         address->setAddress(contactList[i].mPhoneNumber);
   118         else
   129         address->setAlias(contactList[i].mDisplayName);
   119         {
   130         addrlist << address;
   120             mAddressEdit->setText(contactList[i].mPhoneNumber);
   131     }
   121         }
   132     setAddresses(addrlist);
   122     }
       
   123 }
   133 }
   124 
   134 
   125 void MsgUnifiedEditorAddress::handleError(int errorCode, const QString& errorMessage)
   135 void MsgUnifiedEditorAddress::handleError(int errorCode, const QString& errorMessage)
   126 {
   136 {
   127     Q_UNUSED(errorMessage)
   137     Q_UNUSED(errorMessage)
   128     Q_UNUSED(errorCode)
   138     Q_UNUSED(errorCode)
   129 }
   139 }
   130 
   140 
   131 ConvergedMessageAddressList MsgUnifiedEditorAddress::addresses()
   141 // ----------------------------------------------------------------------------
   132 {
   142 // MsgUnifiedEditorAddress::addresses
   133     #ifdef _DEBUG_TRACES_
   143 // @see header
   134     qCritical() << "MsgUnifiedEditorAddress::address start";
   144 // ----------------------------------------------------------------------------
       
   145 ConvergedMessageAddressList MsgUnifiedEditorAddress::addresses(
       
   146         bool removeDuplicates)
       
   147 {
       
   148 #ifdef _DEBUG_TRACES_
       
   149     qCritical() << "MsgUnifiedEditorAddress::addresses start";
   135 #endif
   150 #endif
   136     // sync-up map to account for user-actions on edit-field
   151     // sync-up map to account for user-actions on edit-field
   137     syncDeletionsToMap();
   152     syncDeletionsToMap();
   138     syncAdditionsToMap();
   153     syncAdditionsToMap();
   139 
   154 
   140     QStringList uniqueAddr;
       
   141     uniqueAddr = uniqueAddressList();
       
   142 
       
   143     ConvergedMessageAddressList addresses;
   155     ConvergedMessageAddressList addresses;
   144     foreach(QString addr, uniqueAddr)
   156     if(removeDuplicates)
   145     {
   157     {
   146         ConvergedMessageAddress* address = new ConvergedMessageAddress;
   158         QStringList uniqueAddr;
   147         address->setAddress(addr);
   159         uniqueAddr = uniqueAddressList();
   148         if(!mAddressMap.value(addr).isEmpty())
   160         foreach(QString addr, uniqueAddr)
   149         {
   161         {
       
   162             ConvergedMessageAddress* address = new ConvergedMessageAddress;
       
   163             address->setAddress(addr);
   150             address->setAlias(mAddressMap.value(addr));
   164             address->setAlias(mAddressMap.value(addr));
   151          }
   165             addresses.append(address);
   152         addresses.append(address);
   166         }
   153     }
   167     }
   154     #ifdef _DEBUG_TRACES_
   168     else
   155     qCritical() << "MsgUnifiedEditorAddress::address end";
   169     {
       
   170         QMap<QString, QString>::iterator i = mAddressMap.begin();
       
   171         while (i != mAddressMap.end())
       
   172         {
       
   173             ConvergedMessageAddress* address = new ConvergedMessageAddress;
       
   174             address->setAddress(i.key());
       
   175             address->setAlias(i.value());
       
   176             addresses.append(address);
       
   177             i++;
       
   178         }
       
   179     }
       
   180 #ifdef _DEBUG_TRACES_
       
   181     qCritical() << "MsgUnifiedEditorAddress::addresses end";
   156 #endif
   182 #endif
   157     return addresses;
   183     return addresses;
   158 }
   184 }
   159 
   185 
   160 int MsgUnifiedEditorAddress::addressCount()
   186 int MsgUnifiedEditorAddress::addressCount()
   162     return mAddressEdit->addresses().count();
   188     return mAddressEdit->addresses().count();
   163 }
   189 }
   164 
   190 
   165 void MsgUnifiedEditorAddress::setAddresses(ConvergedMessageAddressList addrlist)
   191 void MsgUnifiedEditorAddress::setAddresses(ConvergedMessageAddressList addrlist)
   166 {
   192 {
   167 	int count = addrlist.count();
   193     // ensure flags are reset before starting the addr addition
       
   194     mAboutToExceedMaxSmsRecipients = false;
       
   195     mAboutToExceedMaxMmsRecipients = false;
       
   196     mExceedsMaxMmsRecipientsBy = 0;
       
   197 
       
   198     // first, we check if MMS max-recipient count will exceed
       
   199     int count = addrlist.count();
       
   200 	int futureCount = count + MsgMonitor::msgAddressCount();
       
   201 	if(futureCount > MsgMonitor::maxMmsRecipients())
       
   202 	{
       
   203 	    mAboutToExceedMaxMmsRecipients = true;
       
   204 	    mExceedsMaxMmsRecipientsBy =
       
   205 	            futureCount - MsgMonitor::maxMmsRecipients();
       
   206 	}
       
   207 	// else, check if SMS max-recipient count will exceed
       
   208 	else if(!mSkipMaxRecipientQuery)
       
   209 	{
       
   210 	    futureCount = count + addressCount();
       
   211 	    if( (addressCount() <= MsgMonitor::maxSmsRecipients()) &&
       
   212 	        (futureCount > MsgMonitor::maxSmsRecipients()) )
       
   213 	    {
       
   214 	        mAboutToExceedMaxSmsRecipients = true;
       
   215 	    }
       
   216 	}
       
   217 
       
   218 
   168     for(int i = 0; i < count; i++ )
   219     for(int i = 0; i < count; i++ )
   169     {
   220     {
   170         mAddressMap.insert(addrlist[i]->address(), addrlist[i]->alias());
   221         mAddressMap.insertMulti(addrlist[i]->address(), addrlist[i]->alias());
   171         if(!addrlist[i]->alias().isEmpty())
   222         if(!addrlist[i]->alias().isEmpty())
   172         {
   223         {
   173             mAddressEdit->setText(addrlist[i]->alias());
   224             mAddressEdit->setText(addrlist[i]->alias());
   174         }
   225         }
   175         else
   226         else
   176         {
   227         {
   177             mAddressEdit->setText(addrlist[i]->address());
   228             mAddressEdit->setText(addrlist[i]->address(), false);
   178         }
   229         }
   179     }
   230     }
       
   231 
       
   232     // addition operation complete, reset flags
       
   233     mAboutToExceedMaxSmsRecipients = false;
       
   234     mAboutToExceedMaxMmsRecipients = false;
       
   235     mExceedsMaxMmsRecipientsBy = 0;
   180 }
   236 }
   181 
   237 
   182 int MsgUnifiedEditorAddress::contactMatchDigits()
   238 int MsgUnifiedEditorAddress::contactMatchDigits()
   183     {
   239 {
   184     // Read the amount of digits to be used in contact matching
   240     // Read the amount of digits to be used in contact matching
   185     // The key is owned by PhoneApp    
   241     // The key is owned by PhoneApp
   186     CRepository* repository = CRepository::NewLC(KCRUidTelConfiguration);
       
   187     int matchDigitCount = 0;
   242     int matchDigitCount = 0;
   188     if ( repository->Get(KTelMatchDigits, matchDigitCount) == KErrNone )
   243     TRAP_IGNORE(
   189         {
   244         CRepository* repository = CRepository::NewLC(KCRUidTelConfiguration);
   190     // Min is 7
   245         if ( repository->Get(KTelMatchDigits, matchDigitCount) == KErrNone )
   191     matchDigitCount = Max(matchDigitCount, KDefaultGsmNumberMatchLength);
   246         {
   192         }
   247             // Min is 7
   193     CleanupStack::PopAndDestroy(); // repository
   248             matchDigitCount = Max(matchDigitCount, KDefaultGsmNumberMatchLength);
   194 
   249         }
       
   250         CleanupStack::PopAndDestroy(); // repository
       
   251     );
   195     return matchDigitCount;
   252     return matchDigitCount;
   196 
   253 }
   197     }
   254 
   198    
   255 void MsgUnifiedEditorAddress::onContentsChanged(const QString& text)
   199 void MsgUnifiedEditorAddress::onContentsAdded(const QString& text)
   256 {
   200 {
   257     // Max MMS recipient count check
   201     if(!text.isEmpty())
   258     if( mAboutToExceedMaxMmsRecipients ||
   202     {
   259         (MsgMonitor::msgAddressCount() >= MsgMonitor::maxMmsRecipients()) )
       
   260     {
       
   261         if(mAboutToExceedMaxMmsRecipients)
       
   262         {// show discreet note only once
       
   263             --mExceedsMaxMmsRecipientsBy;
       
   264             if(!mExceedsMaxMmsRecipientsBy)
       
   265             {
       
   266                 HbNotificationDialog::launchDialog(
       
   267                         LOC_MMS_RECIPIENT_LIMIT_REACHED);
       
   268             }
       
   269             resetToPrevious();
       
   270         }
       
   271         else
       
   272         {
       
   273             // update monitor data
       
   274             emit contentChanged();
       
   275             if(MsgMonitor::msgAddressCount() > MsgMonitor::maxMmsRecipients())
       
   276             {
       
   277                 HbNotificationDialog::launchDialog(
       
   278                         LOC_MMS_RECIPIENT_LIMIT_REACHED);
       
   279                 resetToPrevious();
       
   280                 // reset monitor data
       
   281                 emit contentChanged();
       
   282             }
       
   283             else
       
   284             {
       
   285                 mPrevBuffer = text;
       
   286             }
       
   287         }
       
   288         return;
       
   289     }
       
   290 
       
   291     // Max SMS recipient count check
       
   292     if( !mSkipMaxRecipientQuery &&
       
   293         (MsgMonitor::messageType() == ConvergedMessage::Sms) &&
       
   294         (mAddressEdit->addresses().count() > MsgMonitor::maxSmsRecipients()) )
       
   295     {
       
   296         // when we show this dialog, we don't want the intermediate states
       
   297         // to be signalled to us
   203         disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
   298         disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
   204                 this, SLOT(onContentsAdded(const QString&)));
   299                 this, SLOT(onContentsChanged(const QString&)));
       
   300         QTimer::singleShot(50, this, SLOT(handleRecipientLimitReached()));
       
   301     }
       
   302     else
       
   303     {
       
   304         if(!mAboutToExceedMaxSmsRecipients)
       
   305         {// remember addresses before the block insertion started
       
   306             mPrevBuffer = text;
       
   307         }
   205         emit contentChanged();
   308         emit contentChanged();
   206         connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
   309     }
   207                 this, SLOT(onContentsRemoved(const QString&)));
   310 }
   208     }
   311 
   209 }
   312 void MsgUnifiedEditorAddress::handleRecipientLimitReached()
   210 
   313 {
   211 void MsgUnifiedEditorAddress::onContentsRemoved(const QString& text)
   314     HbMessageBox* dlg = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   212 {
   315     dlg->setAttribute(Qt::WA_DeleteOnClose);
   213     if(text.isEmpty())
   316     dlg->setFocusPolicy(Qt::NoFocus);
   214     {
   317     dlg->setTimeout(HbPopup::NoTimeout);
   215         disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
   318 
   216                 this, SLOT(onContentsRemoved(const QString&)));
   319     dlg->setText(LOC_SMS_RECIPIENT_LIMIT_REACHED);
   217         emit contentChanged();
   320 
   218         connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
   321     HbAction* okAction = new HbAction(LOC_DIALOG_OK,dlg);
   219                 this, SLOT(onContentsAdded(const QString&)));
   322     dlg->addAction(okAction);
   220     }
   323 
       
   324     HbAction* cancelAction = new HbAction(LOC_BUTTON_CANCEL,dlg);
       
   325     dlg->addAction(cancelAction);
       
   326 
       
   327     dlg->open(this,SLOT(onMaxRecipientsReached(HbAction*)));
       
   328     // reconnect to get back updates
       
   329     connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
       
   330             this, SLOT(onContentsChanged(const QString&)));
       
   331     emit contentChanged();
   221 }
   332 }
   222 
   333 
   223 void MsgUnifiedEditorAddress::syncDeletionsToMap()
   334 void MsgUnifiedEditorAddress::syncDeletionsToMap()
   224 {
   335 {
   225     // get address list from edit-field
   336     // get address list from edit-field
   241     }
   352     }
   242 }
   353 }
   243 
   354 
   244 void MsgUnifiedEditorAddress::syncAdditionsToMap()
   355 void MsgUnifiedEditorAddress::syncAdditionsToMap()
   245 {
   356 {
   246     QStringList mapAddrList = mAddressMap.values();
       
   247 
       
   248     // remove already mapped addresses from edit-field
   357     // remove already mapped addresses from edit-field
   249     QStringList userInputAddrList(mAddressEdit->addresses());
   358     QStringList userInputAddrList(mAddressEdit->addresses());
       
   359     QStringList mapAddrList = mAddressMap.values();
       
   360     mapAddrList << mAddressMap.keys();
   250     foreach(QString addr, mapAddrList)
   361     foreach(QString addr, mapAddrList)
   251     {
   362     {
   252         userInputAddrList.removeAll(addr);
   363         userInputAddrList.removeOne(addr);
   253     }
   364     }
   254 
   365 
   255     // add the unmapped addresses to address-map
   366     // add the unmapped addresses to address-map
   256     foreach(QString addr, userInputAddrList)
   367     foreach(QString addr, userInputAddrList)
   257     {
   368     {
   258         mAddressMap.insertMulti(addr, addr);
   369         mAddressMap.insertMulti(addr, QString());
   259     }
   370     }
   260 }
   371 }
   261 
   372 
   262 QStringList MsgUnifiedEditorAddress::uniqueAddressList()
   373 QStringList MsgUnifiedEditorAddress::uniqueAddressList()
   263 {
   374 {
   265     QStringList mapAddrList = mAddressMap.keys();
   376     QStringList mapAddrList = mAddressMap.keys();
   266     for(int j = 0;j<mapAddrList.count()-1;j++)
   377     for(int j = 0;j<mapAddrList.count()-1;j++)
   267     {
   378     {
   268         for(int i =j+1;i<mapAddrList.count();i++)
   379         for(int i =j+1;i<mapAddrList.count();i++)
   269         {
   380         {
   270             if(0 == mapAddrList[j].right(matchDigitCount).compare(mapAddrList[i].right(matchDigitCount)))     
   381             if(0 == mapAddrList[j].right(matchDigitCount).compare(mapAddrList[i].right(matchDigitCount)))
   271             {
   382             {
   272                mapAddrList.removeAt(i);
   383                mapAddrList.removeAt(i);
   273                i--;
   384                i--;
   274             }
   385             }
   275         }
   386         }
   276     }
   387     }
   277     return mapAddrList;
   388     return mapAddrList;
   278 }
   389 }
       
   390 
       
   391 // ----------------------------------------------------------------------------
       
   392 // MsgUnifiedEditorAddress::skipMaxRecipientQuery
       
   393 // @see header
       
   394 // ----------------------------------------------------------------------------
       
   395 void MsgUnifiedEditorAddress::skipMaxRecipientQuery(bool skip)
       
   396 {
       
   397     mSkipMaxRecipientQuery = skip;
       
   398 }
       
   399 
       
   400 void MsgUnifiedEditorAddress::setFocus()
       
   401 {
       
   402     mAddressEdit->setFocus(Qt::MouseFocusReason);
       
   403 }
       
   404 
       
   405 // ----------------------------------------------------------------------------
       
   406 // MsgUnifiedEditorAddress::resetToPrevious
       
   407 // @see header
       
   408 // ----------------------------------------------------------------------------
       
   409 void MsgUnifiedEditorAddress::resetToPrevious()
       
   410 {
       
   411     // when we do this reset operation, we don't want the intermediate states
       
   412     // to be signalled to us
       
   413     disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
       
   414             this, SLOT(onContentsChanged(const QString&)));
       
   415 
       
   416     mAddressEdit->clearContent();
       
   417     QStringList list = mPrevBuffer.split(replacementStr,
       
   418             QString::SkipEmptyParts);
       
   419     int count = list.count();
       
   420     QStringList valList = mAddressMap.values();
       
   421     for(int i=0; i<count; i++)
       
   422     {
       
   423         QString addr = list.at(i);
       
   424         if(valList.contains(addr))
       
   425         {
       
   426             mAddressEdit->setText(addr);
       
   427         }
       
   428         else
       
   429         {
       
   430             mAddressEdit->setText(addr, false);
       
   431         }
       
   432     }
       
   433     syncDeletionsToMap();
       
   434     connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)),
       
   435             this, SLOT(onContentsChanged(const QString&)));
       
   436 }
       
   437 
       
   438 // ----------------------------------------------------------------------------
       
   439 // MsgUnifiedEditorAddress::onMaxRecipientsReached
       
   440 // @see header
       
   441 // ----------------------------------------------------------------------------
       
   442 void MsgUnifiedEditorAddress::onMaxRecipientsReached(HbAction* action)
       
   443 {
       
   444     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   445     if (action == dlg->actions().at(0)) {
       
   446         // accept new content, update prev-buffer
       
   447         mPrevBuffer = mAddressEdit->content();
       
   448     }
       
   449     else {
       
   450         // reject the new content, keep the old
       
   451         resetToPrevious();
       
   452     }
       
   453 }
       
   454 
       
   455 // ----------------------------------------------------------------------------
       
   456 // MsgUnifiedEditorAddress::validateContacts
       
   457 // @see header
       
   458 // ----------------------------------------------------------------------------
       
   459 bool MsgUnifiedEditorAddress::validateContacts()
       
   460 {
       
   461     UniEditorGenUtils* genUtils = new UniEditorGenUtils;
       
   462 
       
   463     // sync-up map to account for user-actions on address-field
       
   464     syncDeletionsToMap();
       
   465     syncAdditionsToMap();
       
   466 
       
   467     // get the list of contacts in address-field
       
   468     QStringList fieldAddresses(mAddressEdit->addresses());
       
   469 
       
   470     bool allValid = true;
       
   471     foreach(QString addr, fieldAddresses)
       
   472     {
       
   473         // run address validation only if address is unmapped
       
   474         // (i.e. user-inserted)
       
   475         if(mAddressMap.contains(addr))
       
   476         {
       
   477             // 1. perform number validation
       
   478             allValid = CommonPhoneParser::IsValidPhoneNumber(
       
   479                     *XQConversions::qStringToS60Desc(addr),
       
   480                     CommonPhoneParser::ESMSNumber );
       
   481 
       
   482             // 2. if number validity fails, then perform email addr validation
       
   483             if( !allValid &&
       
   484                 (MsgMonitor::messageType() == ConvergedMessage::Mms) )
       
   485             { // additional check for MMS only
       
   486                 allValid = genUtils->IsValidEmailAddress(
       
   487                         *XQConversions::qStringToS60Desc(addr) );
       
   488             }
       
   489 
       
   490             if(!allValid)
       
   491             {
       
   492                 mAddressEdit->highlightInvalidString(addr);
       
   493                 QString invalidAddrStr =
       
   494                         QString(LOC_INVALID_RECIPIENT).arg(addr);
       
   495                 HbMessageBox* dlg = new HbMessageBox(invalidAddrStr,
       
   496                         HbMessageBox::MessageTypeInformation);
       
   497                 dlg->setDismissPolicy(HbPopup::TapInside);
       
   498                 dlg->setTimeout(HbPopup::NoTimeout);
       
   499                 dlg->setAttribute(Qt::WA_DeleteOnClose, true);
       
   500                 dlg->open(this, SLOT(handleInvalidContactDialog(HbAction*)));
       
   501                 break;
       
   502             }
       
   503         }
       
   504     }
       
   505     delete genUtils;
       
   506     return allValid;
       
   507 }
       
   508 
       
   509 void MsgUnifiedEditorAddress::handleInvalidContactDialog(
       
   510         HbAction* act)
       
   511 {
       
   512     Q_UNUSED(act);
       
   513     QTimer::singleShot(250, this, SLOT(setFocus()));
       
   514 }
       
   515 
   279 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
   516 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
   280 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList)
   517 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList)
   281 
   518 
   282 //EOF
   519 //EOF