18 // INCLUDES |
18 // INCLUDES |
19 #include <QTimer> |
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> |
|
24 #include <hbmessagebox.h> |
23 #include <hbmessagebox.h> |
25 #include <cntservicescontact.h> |
24 #include <cntservicescontact.h> |
26 #include <xqaiwrequest.h> |
25 #include <xqaiwrequest.h> |
27 #include <xqappmgr.h> |
26 #include <xqappmgr.h> |
28 #include <telconfigcrkeys.h> // KCRUidTelephonyConfiguration |
27 #include <telconfigcrkeys.h> // KCRUidTelephonyConfiguration |
37 #include "msgunieditorlineedit.h" |
36 #include "msgunieditorlineedit.h" |
38 #include "msgunieditormonitor.h" |
37 #include "msgunieditormonitor.h" |
39 #include "UniEditorGenUtils.h" |
38 #include "UniEditorGenUtils.h" |
40 |
39 |
41 const QString PBK_ICON("qtg_mono_contacts"); |
40 const QString PBK_ICON("qtg_mono_contacts"); |
42 const QString SEND_ICON("qtg_mono_send"); |
|
43 const QString REPLACEMENT_STR("; "); |
41 const QString REPLACEMENT_STR("; "); |
44 const QString COMMA_SEPERATOR(","); |
42 const QString COMMA_SEPERATOR(","); |
45 |
43 |
46 // Constants |
44 // Constants |
47 const int KDefaultGsmNumberMatchLength = 7; //matching unique ph numbers |
45 const int KDefaultGsmNumberMatchLength = 7; //matching unique ph numbers |
78 |
76 |
79 mAddressEdit->setMaxRows(40); |
77 mAddressEdit->setMaxRows(40); |
80 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
78 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
81 this, SLOT(onContentsChanged(const QString&))); |
79 this, SLOT(onContentsChanged(const QString&))); |
82 |
80 |
83 // add "Send" action in VKB |
|
84 HbEditorInterface editorInterface(mAddressEdit); |
|
85 mAddressEdit->setInputMethodHints(Qt::ImhPreferNumbers); |
81 mAddressEdit->setInputMethodHints(Qt::ImhPreferNumbers); |
86 HbAction *sendAction = new HbAction(HbIcon(SEND_ICON), QString(),this); |
82 } |
87 connect(sendAction, SIGNAL(triggered()),this, SIGNAL(sendMessage())); |
|
88 editorInterface.addAction(sendAction); |
|
89 } |
|
90 |
83 |
91 MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress() |
84 MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress() |
92 { |
85 { |
93 //TODO: Should remove this code depending on orbit's reply whether it is needed |
86 //TODO: Should remove this code depending on orbit's reply whether it is needed |
94 //to unregister the same plugin registered on two different widgets twice. |
87 //to unregister the same plugin registered on two different widgets twice. |
96 } |
89 } |
97 |
90 |
98 void MsgUnifiedEditorAddress::fetchContacts() |
91 void MsgUnifiedEditorAddress::fetchContacts() |
99 { |
92 { |
100 mLaunchBtn->blockSignals(true); |
93 mLaunchBtn->blockSignals(true); |
101 |
94 |
102 QList<QVariant> args; |
95 QList<QVariant> args; |
103 QString serviceName("com.nokia.services.phonebookservices"); |
96 QString serviceName("com.nokia.services.phonebookservices"); |
104 QString operation("fetch(QString,QString,QString)"); |
97 QString operation("fetch(QString,QString,QString)"); |
105 XQAiwRequest* request; |
98 XQAiwRequest* request; |
106 XQApplicationManager appManager; |
99 XQApplicationManager appManager; |
119 args << KCntFilterDisplayAll; |
112 args << KCntFilterDisplayAll; |
120 |
113 |
121 request->setArguments(args); |
114 request->setArguments(args); |
122 request->send(); |
115 request->send(); |
123 delete request; |
116 delete request; |
124 |
117 |
125 //unblock click signal after some delay. |
118 //unblock click signal after some delay. |
126 QTimer::singleShot(250,this,SLOT(unblockSignals())); |
119 QTimer::singleShot(250,this,SLOT(unblockSignals())); |
127 } |
120 } |
128 |
121 |
129 void MsgUnifiedEditorAddress::handleOk(const QVariant& value) |
122 void MsgUnifiedEditorAddress::handleOk(const QVariant& value) |
135 ConvergedMessageAddressList addrlist; |
128 ConvergedMessageAddressList addrlist; |
136 for(int i = 0; i < count; i++ ) |
129 for(int i = 0; i < count; i++ ) |
137 { |
130 { |
138 ConvergedMessageAddress* address = |
131 ConvergedMessageAddress* address = |
139 new ConvergedMessageAddress(); |
132 new ConvergedMessageAddress(); |
140 address->setAddress(contactList[i].mPhoneNumber); |
133 if(!contactList[i].mPhoneNumber.isEmpty()) |
|
134 { |
|
135 address->setAddress(contactList[i].mPhoneNumber); |
|
136 } |
|
137 else |
|
138 { |
|
139 address->setAddress(contactList[i].mEmailAddress); |
|
140 } |
141 address->setAlias(contactList[i].mDisplayName); |
141 address->setAlias(contactList[i].mDisplayName); |
142 addrlist << address; |
142 addrlist << address; |
143 } |
143 } |
144 setAddresses(addrlist); |
144 setAddresses(addrlist); |
145 } |
145 } |
200 return mAddressEdit->addresses().count(); |
200 return mAddressEdit->addresses().count(); |
201 } |
201 } |
202 |
202 |
203 void MsgUnifiedEditorAddress::setAddresses(ConvergedMessageAddressList addrlist) |
203 void MsgUnifiedEditorAddress::setAddresses(ConvergedMessageAddressList addrlist) |
204 { |
204 { |
|
205 // avoid processing if no info available |
|
206 if(addrlist.count() == 0) |
|
207 { |
|
208 return; |
|
209 } |
|
210 |
205 // ensure flags are reset before starting the addr addition |
211 // ensure flags are reset before starting the addr addition |
206 mAboutToExceedMaxSmsRecipients = false; |
212 mAboutToExceedMaxSmsRecipients = false; |
207 mAboutToExceedMaxMmsRecipients = false; |
213 mAboutToExceedMaxMmsRecipients = false; |
208 mExceedsMaxMmsRecipientsBy = 0; |
214 mExceedsMaxMmsRecipientsBy = 0; |
209 |
215 |
231 QString invalidContacts; |
237 QString invalidContacts; |
232 for(int i = 0; i < count; i++ ) |
238 for(int i = 0; i < count; i++ ) |
233 { |
239 { |
234 bool isValid = false; |
240 bool isValid = false; |
235 isValid = checkValidAddress(addrlist.at(i)->address()); |
241 isValid = checkValidAddress(addrlist.at(i)->address()); |
236 if(!isValid) |
242 if(!isValid) |
237 { |
243 { |
238 invalidCount ++; |
244 invalidCount ++; |
239 // append the comma till last but one contact. |
245 // append the comma till last but one contact. |
240 // add the invalid ocntacts to the " , " seperated string. |
246 // add the invalid ocntacts to the " , " seperated string. |
241 if(invalidCount > 1) |
247 if(invalidCount > 1) |
242 { |
248 { |
243 invalidContacts.append(COMMA_SEPERATOR); |
249 invalidContacts.append(COMMA_SEPERATOR); |
244 } |
250 } |
245 invalidContacts.append(addrlist.at(i)->alias()); |
251 invalidContacts.append(addrlist.at(i)->alias()); |
246 } |
252 } |
247 else |
253 else |
248 { |
254 { |
249 mAddressMap.insertMulti(addrlist[i]->address(), addrlist[i]->alias()); |
255 mAddressMap.insertMulti(addrlist[i]->address(), addrlist[i]->alias()); |
250 if(!addrlist[i]->alias().isEmpty()) |
256 if(!addrlist[i]->alias().isEmpty()) |
251 { |
257 { |
254 else |
260 else |
255 { |
261 { |
256 mAddressEdit->setText(addrlist[i]->address(), false); |
262 mAddressEdit->setText(addrlist[i]->address(), false); |
257 } |
263 } |
258 } |
264 } |
259 |
|
260 } |
265 } |
261 if(invalidCount) |
266 if(invalidCount) |
262 { |
267 { |
263 QString invalidStr; |
268 QString invalidStr; |
264 (invalidCount == 1)?(invalidStr = QString(LOC_INVALID_RECIPIENT_NOT_ADDED)) :(invalidStr = QString(LOC_INVALID_RECIPIENTS_NOT_ADDED)); |
269 (invalidCount == 1)?(invalidStr = QString(LOC_INVALID_RECIPIENT_NOT_ADDED)) :(invalidStr = QString(LOC_INVALID_RECIPIENTS_NOT_ADDED)); |
265 // append line seperator |
270 // append line seperator |
266 invalidStr.append("<br>"); |
271 invalidStr.append("<br>"); |
267 invalidStr.append(invalidContacts); |
272 invalidStr.append(invalidContacts); |
268 HbMessageBox::information(invalidStr); |
273 HbMessageBox::information(invalidStr); |
269 } |
274 } |
270 |
275 |
271 // addition operation complete, reset flags |
276 // addition operation complete, reset flags |
354 dlg->setAttribute(Qt::WA_DeleteOnClose); |
359 dlg->setAttribute(Qt::WA_DeleteOnClose); |
355 dlg->setFocusPolicy(Qt::NoFocus); |
360 dlg->setFocusPolicy(Qt::NoFocus); |
356 dlg->setTimeout(HbPopup::NoTimeout); |
361 dlg->setTimeout(HbPopup::NoTimeout); |
357 |
362 |
358 dlg->setText(LOC_SMS_RECIPIENT_LIMIT_REACHED); |
363 dlg->setText(LOC_SMS_RECIPIENT_LIMIT_REACHED); |
359 |
364 |
|
365 dlg->clearActions(); |
360 HbAction* okAction = new HbAction(LOC_DIALOG_OK,dlg); |
366 HbAction* okAction = new HbAction(LOC_DIALOG_OK,dlg); |
361 dlg->addAction(okAction); |
367 dlg->addAction(okAction); |
362 |
368 |
363 HbAction* cancelAction = new HbAction(LOC_BUTTON_CANCEL,dlg); |
369 HbAction* cancelAction = new HbAction(LOC_BUTTON_CANCEL,dlg); |
364 dlg->addAction(cancelAction); |
370 dlg->addAction(cancelAction); |
365 |
371 |
366 dlg->open(this,SLOT(onMaxRecipientsReached(HbAction*))); |
372 dlg->open(this,SLOT(onMaxRecipientsReached(HbAction*))); |
367 // reconnect to get back updates |
373 // reconnect to get back updates |
368 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
374 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
369 this, SLOT(onContentsChanged(const QString&))); |
375 this, SLOT(onContentsChanged(const QString&))); |
370 emit contentChanged(); |
|
371 } |
376 } |
372 |
377 |
373 void MsgUnifiedEditorAddress::syncDeletionsToMap() |
378 void MsgUnifiedEditorAddress::syncDeletionsToMap() |
374 { |
379 { |
375 // get address list from edit-field |
380 // get address list from edit-field |
384 {// if none are present, then delete entry from map |
389 {// if none are present, then delete entry from map |
385 i = mAddressMap.erase(i); |
390 i = mAddressMap.erase(i); |
386 } |
391 } |
387 else |
392 else |
388 { |
393 { |
|
394 // ensure that the matched contact is removed from the |
|
395 // address's list |
|
396 int matchedIndex = addrList.indexOf(i.value()); |
|
397 if(matchedIndex == -1) |
|
398 { |
|
399 matchedIndex = addrList.indexOf(i.key()); |
|
400 } |
|
401 if(matchedIndex != -1) |
|
402 { |
|
403 addrList.removeAt(matchedIndex); |
|
404 } |
|
405 // now go to next index in map |
389 ++i; |
406 ++i; |
390 } |
407 } |
391 } |
408 } |
392 } |
409 } |
393 |
410 |
481 void MsgUnifiedEditorAddress::onMaxRecipientsReached(HbAction* action) |
498 void MsgUnifiedEditorAddress::onMaxRecipientsReached(HbAction* action) |
482 { |
499 { |
483 HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); |
500 HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); |
484 if (action == dlg->actions().at(0)) { |
501 if (action == dlg->actions().at(0)) { |
485 // accept new content, update prev-buffer |
502 // accept new content, update prev-buffer |
|
503 emit contentChanged(); |
486 mPrevBuffer = mAddressEdit->content(); |
504 mPrevBuffer = mAddressEdit->content(); |
487 } |
505 } |
488 else { |
506 else { |
489 // reject the new content, keep the old |
507 // reject the new content, keep the old |
490 resetToPrevious(); |
508 resetToPrevious(); |
527 dlg->open(this, SLOT(handleInvalidContactDialog(HbAction*))); |
545 dlg->open(this, SLOT(handleInvalidContactDialog(HbAction*))); |
528 break; |
546 break; |
529 } |
547 } |
530 } |
548 } |
531 } |
549 } |
532 |
550 |
533 return isValid; |
551 return isValid; |
534 } |
552 } |
535 // ---------------------------------------------------------------------------- |
553 // ---------------------------------------------------------------------------- |
536 // MsgUnifiedEditorAddress::checkValidAddress |
554 // MsgUnifiedEditorAddress::checkValidAddress |
537 // @see header |
555 // @see header |
538 // ---------------------------------------------------------------------------- |
556 // ---------------------------------------------------------------------------- |
539 bool MsgUnifiedEditorAddress::checkValidAddress(const QString& addr) |
557 bool MsgUnifiedEditorAddress::checkValidAddress(const QString& addr) |
540 { |
558 { |
541 bool isValid = false; |
559 bool isValid = false; |
|
560 |
|
561 HBufC *tempAddr = XQConversions::qStringToS60Desc(addr); |
|
562 |
542 // 1. perform number validation |
563 // 1. perform number validation |
543 isValid = CommonPhoneParser::IsValidPhoneNumber( |
564 isValid = CommonPhoneParser::IsValidPhoneNumber( |
544 *XQConversions::qStringToS60Desc(addr), |
565 *tempAddr, |
545 CommonPhoneParser::ESMSNumber ); |
566 CommonPhoneParser::ESMSNumber ); |
546 |
567 |
547 // 2. if number validity fails, then perform email addr validation |
568 // 2. if number validity fails, then perform email addr validation |
548 UniEditorGenUtils* genUtils = new UniEditorGenUtils; |
569 UniEditorGenUtils* genUtils = new UniEditorGenUtils; |
549 if( !isValid && |
570 if(!isValid) |
550 ( MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Mms) ) |
|
551 { // additional check for MMS only |
571 { // additional check for MMS only |
552 isValid = genUtils->IsValidEmailAddress( |
572 isValid = genUtils->IsValidEmailAddress( |
553 *XQConversions::qStringToS60Desc(addr) ); |
573 *tempAddr ); |
554 } |
574 } |
555 delete genUtils; |
575 delete genUtils; |
|
576 delete tempAddr; |
556 return isValid; |
577 return isValid; |
557 } |
578 } |
558 |
579 |
559 void MsgUnifiedEditorAddress::handleInvalidContactDialog( |
580 void MsgUnifiedEditorAddress::handleInvalidContactDialog( |
560 HbAction* act) |
581 HbAction* act) |