32 #include <xqconversions.h> |
31 #include <xqconversions.h> |
33 |
32 |
34 // USER INCLUDES |
33 // USER INCLUDES |
35 #include "debugtraces.h" |
34 #include "debugtraces.h" |
36 #include "msgunieditoraddress.h" |
35 #include "msgunieditoraddress.h" |
37 #include "msgunifiededitorlineedit.h" |
36 #include "msgunieditorlineedit.h" |
38 #include "msgmonitor.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"); |
41 const QString REPLACEMENT_STR("; "); |
43 const QString replacementStr("; "); |
42 const QString COMMA_SEPERATOR(","); |
44 |
43 |
45 // Constants |
44 // Constants |
46 const int KDefaultGsmNumberMatchLength = 7; //matching unique ph numbers |
45 const int KDefaultGsmNumberMatchLength = 7; //matching unique ph numbers |
47 #define LOC_SMS_RECIPIENT_LIMIT_REACHED hbTrId("txt_messaging_dialog_number_of_recipients_exceeded") |
46 #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") |
47 #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") |
48 #define LOC_DIALOG_OK hbTrId("txt_common_button_ok") |
50 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel") |
49 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel") |
51 #define LOC_INVALID_RECIPIENT hbTrId("txt_messaging_dialog_invalid_recipient_found") |
50 #define LOC_INVALID_RECIPIENT hbTrId("txt_messaging_dialog_invalid_recipient_found") |
|
51 #define LOC_INVALID_RECIPIENT_NOT_ADDED hbTrId("txt_messaging_dialog_invalid_recipient_not_added") |
|
52 #define LOC_INVALID_RECIPIENTS_NOT_ADDED hbTrId("txt_messaging_dialog_invalid_recipients_not_added") |
|
53 |
|
54 |
|
55 |
|
56 |
52 |
57 |
53 MsgUnifiedEditorAddress::MsgUnifiedEditorAddress( const QString& label, |
58 MsgUnifiedEditorAddress::MsgUnifiedEditorAddress( const QString& label, |
54 QGraphicsItem *parent ) : |
59 QGraphicsItem *parent ) : |
55 MsgUnifiedEditorBaseWidget(parent), |
60 MsgUnifiedEditorBaseWidget(parent), |
56 mSkipMaxRecipientQuery(false), |
61 mSkipMaxRecipientQuery(false), |
71 |
76 |
72 mAddressEdit->setMaxRows(40); |
77 mAddressEdit->setMaxRows(40); |
73 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
78 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
74 this, SLOT(onContentsChanged(const QString&))); |
79 this, SLOT(onContentsChanged(const QString&))); |
75 |
80 |
76 // add "Send" action in VKB |
|
77 HbEditorInterface editorInterface(mAddressEdit); |
|
78 mAddressEdit->setInputMethodHints(Qt::ImhPreferNumbers); |
81 mAddressEdit->setInputMethodHints(Qt::ImhPreferNumbers); |
79 HbAction *sendAction = new HbAction(HbIcon(SEND_ICON), QString(),this); |
82 } |
80 connect(sendAction, SIGNAL(triggered()),this, SIGNAL(sendMessage())); |
|
81 editorInterface.addAction(sendAction); |
|
82 } |
|
83 |
83 |
84 MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress() |
84 MsgUnifiedEditorAddress::~MsgUnifiedEditorAddress() |
85 { |
85 { |
86 //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 |
87 //to unregister the same plugin registered on two different widgets twice. |
87 //to unregister the same plugin registered on two different widgets twice. |
88 //style()->unregisterPlugin(mPluginPath); |
88 //style()->unregisterPlugin(mPluginPath); |
89 } |
89 } |
90 |
90 |
91 void MsgUnifiedEditorAddress::fetchContacts() |
91 void MsgUnifiedEditorAddress::fetchContacts() |
92 { |
92 { |
|
93 mLaunchBtn->blockSignals(true); |
|
94 |
93 QList<QVariant> args; |
95 QList<QVariant> args; |
94 QString serviceName("com.nokia.services.phonebookservices"); |
96 QString serviceName("com.nokia.services.phonebookservices"); |
95 QString operation("fetch(QString,QString,QString)"); |
97 QString operation("fetch(QString,QString,QString)"); |
96 XQAiwRequest* request; |
98 XQAiwRequest* request; |
97 XQApplicationManager appManager; |
99 XQApplicationManager appManager; |
123 ConvergedMessageAddressList addrlist; |
128 ConvergedMessageAddressList addrlist; |
124 for(int i = 0; i < count; i++ ) |
129 for(int i = 0; i < count; i++ ) |
125 { |
130 { |
126 ConvergedMessageAddress* address = |
131 ConvergedMessageAddress* address = |
127 new ConvergedMessageAddress(); |
132 new ConvergedMessageAddress(); |
128 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 } |
129 address->setAlias(contactList[i].mDisplayName); |
141 address->setAlias(contactList[i].mDisplayName); |
130 addrlist << address; |
142 addrlist << address; |
131 } |
143 } |
132 setAddresses(addrlist); |
144 setAddresses(addrlist); |
133 } |
145 } |
188 return mAddressEdit->addresses().count(); |
200 return mAddressEdit->addresses().count(); |
189 } |
201 } |
190 |
202 |
191 void MsgUnifiedEditorAddress::setAddresses(ConvergedMessageAddressList addrlist) |
203 void MsgUnifiedEditorAddress::setAddresses(ConvergedMessageAddressList addrlist) |
192 { |
204 { |
|
205 // avoid processing if no info available |
|
206 if(addrlist.count() == 0) |
|
207 { |
|
208 return; |
|
209 } |
|
210 |
193 // ensure flags are reset before starting the addr addition |
211 // ensure flags are reset before starting the addr addition |
194 mAboutToExceedMaxSmsRecipients = false; |
212 mAboutToExceedMaxSmsRecipients = false; |
195 mAboutToExceedMaxMmsRecipients = false; |
213 mAboutToExceedMaxMmsRecipients = false; |
196 mExceedsMaxMmsRecipientsBy = 0; |
214 mExceedsMaxMmsRecipientsBy = 0; |
197 |
215 |
198 // first, we check if MMS max-recipient count will exceed |
216 // first, we check if MMS max-recipient count will exceed |
199 int count = addrlist.count(); |
217 int count = addrlist.count(); |
200 int futureCount = count + MsgMonitor::msgAddressCount(); |
218 int futureCount = count + MsgUnifiedEditorMonitor::msgAddressCount(); |
201 if(futureCount > MsgMonitor::maxMmsRecipients()) |
219 if(futureCount > MsgUnifiedEditorMonitor::maxMmsRecipients()) |
202 { |
220 { |
203 mAboutToExceedMaxMmsRecipients = true; |
221 mAboutToExceedMaxMmsRecipients = true; |
204 mExceedsMaxMmsRecipientsBy = |
222 mExceedsMaxMmsRecipientsBy = |
205 futureCount - MsgMonitor::maxMmsRecipients(); |
223 futureCount - MsgUnifiedEditorMonitor::maxMmsRecipients(); |
206 } |
224 } |
207 // else, check if SMS max-recipient count will exceed |
225 // else, check if SMS max-recipient count will exceed |
208 else if(!mSkipMaxRecipientQuery) |
226 else if(!mSkipMaxRecipientQuery) |
209 { |
227 { |
210 futureCount = count + addressCount(); |
228 futureCount = count + addressCount(); |
211 if( (addressCount() <= MsgMonitor::maxSmsRecipients()) && |
229 if( (addressCount() <= MsgUnifiedEditorMonitor::maxSmsRecipients()) && |
212 (futureCount > MsgMonitor::maxSmsRecipients()) ) |
230 (futureCount > MsgUnifiedEditorMonitor::maxSmsRecipients()) ) |
213 { |
231 { |
214 mAboutToExceedMaxSmsRecipients = true; |
232 mAboutToExceedMaxSmsRecipients = true; |
215 } |
233 } |
216 } |
234 } |
217 |
235 |
218 |
236 int invalidCount= 0; |
|
237 QString invalidContacts; |
219 for(int i = 0; i < count; i++ ) |
238 for(int i = 0; i < count; i++ ) |
220 { |
239 { |
221 mAddressMap.insertMulti(addrlist[i]->address(), addrlist[i]->alias()); |
240 bool isValid = false; |
222 if(!addrlist[i]->alias().isEmpty()) |
241 isValid = checkValidAddress(addrlist.at(i)->address()); |
223 { |
242 if(!isValid) |
224 mAddressEdit->setText(addrlist[i]->alias()); |
243 { |
225 } |
244 invalidCount ++; |
226 else |
245 // append the comma till last but one contact. |
227 { |
246 // add the invalid ocntacts to the " , " seperated string. |
228 mAddressEdit->setText(addrlist[i]->address(), false); |
247 if(invalidCount > 1) |
229 } |
248 { |
230 } |
249 invalidContacts.append(COMMA_SEPERATOR); |
|
250 } |
|
251 invalidContacts.append(addrlist.at(i)->alias()); |
|
252 } |
|
253 else |
|
254 { |
|
255 mAddressMap.insertMulti(addrlist[i]->address(), addrlist[i]->alias()); |
|
256 if(!addrlist[i]->alias().isEmpty()) |
|
257 { |
|
258 mAddressEdit->setText(addrlist[i]->alias()); |
|
259 } |
|
260 else |
|
261 { |
|
262 mAddressEdit->setText(addrlist[i]->address(), false); |
|
263 } |
|
264 } |
|
265 } |
|
266 if(invalidCount) |
|
267 { |
|
268 QString invalidStr; |
|
269 (invalidCount == 1)?(invalidStr = QString(LOC_INVALID_RECIPIENT_NOT_ADDED)) :(invalidStr = QString(LOC_INVALID_RECIPIENTS_NOT_ADDED)); |
|
270 // append line seperator |
|
271 invalidStr.append("<br>"); |
|
272 invalidStr.append(invalidContacts); |
|
273 HbMessageBox::information(invalidStr); |
|
274 } |
231 |
275 |
232 // addition operation complete, reset flags |
276 // addition operation complete, reset flags |
233 mAboutToExceedMaxSmsRecipients = false; |
277 mAboutToExceedMaxSmsRecipients = false; |
234 mAboutToExceedMaxMmsRecipients = false; |
278 mAboutToExceedMaxMmsRecipients = false; |
235 mExceedsMaxMmsRecipientsBy = 0; |
279 mExceedsMaxMmsRecipientsBy = 0; |
254 |
298 |
255 void MsgUnifiedEditorAddress::onContentsChanged(const QString& text) |
299 void MsgUnifiedEditorAddress::onContentsChanged(const QString& text) |
256 { |
300 { |
257 // Max MMS recipient count check |
301 // Max MMS recipient count check |
258 if( mAboutToExceedMaxMmsRecipients || |
302 if( mAboutToExceedMaxMmsRecipients || |
259 (MsgMonitor::msgAddressCount() >= MsgMonitor::maxMmsRecipients()) ) |
303 (MsgUnifiedEditorMonitor::msgAddressCount() >= MsgUnifiedEditorMonitor::maxMmsRecipients()) ) |
260 { |
304 { |
261 if(mAboutToExceedMaxMmsRecipients) |
305 if(mAboutToExceedMaxMmsRecipients) |
262 {// show discreet note only once |
306 {// show discreet note only once |
263 --mExceedsMaxMmsRecipientsBy; |
307 --mExceedsMaxMmsRecipientsBy; |
264 if(!mExceedsMaxMmsRecipientsBy) |
308 if(!mExceedsMaxMmsRecipientsBy) |
288 return; |
332 return; |
289 } |
333 } |
290 |
334 |
291 // Max SMS recipient count check |
335 // Max SMS recipient count check |
292 if( !mSkipMaxRecipientQuery && |
336 if( !mSkipMaxRecipientQuery && |
293 (MsgMonitor::messageType() == ConvergedMessage::Sms) && |
337 (MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Sms) && |
294 (mAddressEdit->addresses().count() > MsgMonitor::maxSmsRecipients()) ) |
338 (mAddressEdit->addresses().count() > MsgUnifiedEditorMonitor::maxSmsRecipients()) ) |
295 { |
339 { |
296 // when we show this dialog, we don't want the intermediate states |
340 // when we show this dialog, we don't want the intermediate states |
297 // to be signalled to us |
341 // to be signalled to us |
298 disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
342 disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
299 this, SLOT(onContentsChanged(const QString&))); |
343 this, SLOT(onContentsChanged(const QString&))); |
315 dlg->setAttribute(Qt::WA_DeleteOnClose); |
359 dlg->setAttribute(Qt::WA_DeleteOnClose); |
316 dlg->setFocusPolicy(Qt::NoFocus); |
360 dlg->setFocusPolicy(Qt::NoFocus); |
317 dlg->setTimeout(HbPopup::NoTimeout); |
361 dlg->setTimeout(HbPopup::NoTimeout); |
318 |
362 |
319 dlg->setText(LOC_SMS_RECIPIENT_LIMIT_REACHED); |
363 dlg->setText(LOC_SMS_RECIPIENT_LIMIT_REACHED); |
320 |
364 |
|
365 dlg->clearActions(); |
321 HbAction* okAction = new HbAction(LOC_DIALOG_OK,dlg); |
366 HbAction* okAction = new HbAction(LOC_DIALOG_OK,dlg); |
322 dlg->addAction(okAction); |
367 dlg->addAction(okAction); |
323 |
368 |
324 HbAction* cancelAction = new HbAction(LOC_BUTTON_CANCEL,dlg); |
369 HbAction* cancelAction = new HbAction(LOC_BUTTON_CANCEL,dlg); |
325 dlg->addAction(cancelAction); |
370 dlg->addAction(cancelAction); |
326 |
371 |
327 dlg->open(this,SLOT(onMaxRecipientsReached(HbAction*))); |
372 dlg->open(this,SLOT(onMaxRecipientsReached(HbAction*))); |
328 // reconnect to get back updates |
373 // reconnect to get back updates |
329 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
374 connect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
330 this, SLOT(onContentsChanged(const QString&))); |
375 this, SLOT(onContentsChanged(const QString&))); |
331 emit contentChanged(); |
|
332 } |
376 } |
333 |
377 |
334 void MsgUnifiedEditorAddress::syncDeletionsToMap() |
378 void MsgUnifiedEditorAddress::syncDeletionsToMap() |
335 { |
379 { |
336 // get address list from edit-field |
380 // get address list from edit-field |
412 // to be signalled to us |
468 // to be signalled to us |
413 disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
469 disconnect(mAddressEdit, SIGNAL(contentsChanged(const QString&)), |
414 this, SLOT(onContentsChanged(const QString&))); |
470 this, SLOT(onContentsChanged(const QString&))); |
415 |
471 |
416 mAddressEdit->clearContent(); |
472 mAddressEdit->clearContent(); |
417 QStringList list = mPrevBuffer.split(replacementStr, |
473 QStringList list = mPrevBuffer.split(REPLACEMENT_STR, |
418 QString::SkipEmptyParts); |
474 QString::SkipEmptyParts); |
419 int count = list.count(); |
475 int count = list.count(); |
420 QStringList valList = mAddressMap.values(); |
476 QStringList valList = mAddressMap.values(); |
421 for(int i=0; i<count; i++) |
477 for(int i=0; i<count; i++) |
422 { |
478 { |
465 syncAdditionsToMap(); |
522 syncAdditionsToMap(); |
466 |
523 |
467 // get the list of contacts in address-field |
524 // get the list of contacts in address-field |
468 QStringList fieldAddresses(mAddressEdit->addresses()); |
525 QStringList fieldAddresses(mAddressEdit->addresses()); |
469 |
526 |
470 bool allValid = true; |
527 bool isValid = true; |
471 foreach(QString addr, fieldAddresses) |
528 foreach(QString addr, fieldAddresses) |
472 { |
529 { |
473 // run address validation only if address is unmapped |
530 // run address validation only if address is unmapped |
474 // (i.e. user-inserted) |
531 // (i.e. user-inserted) |
475 if(mAddressMap.contains(addr)) |
532 if(mAddressMap.contains(addr)) |
476 { |
533 { |
477 // 1. perform number validation |
534 isValid = checkValidAddress(addr); |
478 allValid = CommonPhoneParser::IsValidPhoneNumber( |
535 if(!isValid) |
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 { |
536 { |
492 mAddressEdit->highlightInvalidString(addr); |
537 mAddressEdit->highlightInvalidString(addr); |
493 QString invalidAddrStr = |
538 QString invalidAddrStr = |
494 QString(LOC_INVALID_RECIPIENT).arg(addr); |
539 QString(LOC_INVALID_RECIPIENT).arg(addr); |
495 HbMessageBox* dlg = new HbMessageBox(invalidAddrStr, |
540 HbMessageBox* dlg = new HbMessageBox(invalidAddrStr, |
500 dlg->open(this, SLOT(handleInvalidContactDialog(HbAction*))); |
545 dlg->open(this, SLOT(handleInvalidContactDialog(HbAction*))); |
501 break; |
546 break; |
502 } |
547 } |
503 } |
548 } |
504 } |
549 } |
|
550 |
|
551 return isValid; |
|
552 } |
|
553 // ---------------------------------------------------------------------------- |
|
554 // MsgUnifiedEditorAddress::checkValidAddress |
|
555 // @see header |
|
556 // ---------------------------------------------------------------------------- |
|
557 bool MsgUnifiedEditorAddress::checkValidAddress(const QString& addr) |
|
558 { |
|
559 bool isValid = false; |
|
560 |
|
561 HBufC *tempAddr = XQConversions::qStringToS60Desc(addr); |
|
562 |
|
563 // 1. perform number validation |
|
564 isValid = CommonPhoneParser::IsValidPhoneNumber( |
|
565 *tempAddr, |
|
566 CommonPhoneParser::ESMSNumber ); |
|
567 |
|
568 // 2. if number validity fails, then perform email addr validation |
|
569 UniEditorGenUtils* genUtils = new UniEditorGenUtils; |
|
570 if(!isValid) |
|
571 { // additional check for MMS only |
|
572 isValid = genUtils->IsValidEmailAddress( |
|
573 *tempAddr ); |
|
574 } |
505 delete genUtils; |
575 delete genUtils; |
506 return allValid; |
576 delete tempAddr; |
507 } |
577 return isValid; |
|
578 } |
508 |
579 |
509 void MsgUnifiedEditorAddress::handleInvalidContactDialog( |
580 void MsgUnifiedEditorAddress::handleInvalidContactDialog( |
510 HbAction* act) |
581 HbAction* act) |
511 { |
582 { |
512 Q_UNUSED(act); |
583 Q_UNUSED(act); |
513 QTimer::singleShot(250, this, SLOT(setFocus())); |
584 QTimer::singleShot(250, this, SLOT(setFocus())); |
514 } |
585 } |
515 |
586 |
|
587 void MsgUnifiedEditorAddress::unblockSignals() |
|
588 { |
|
589 mLaunchBtn->blockSignals(false); |
|
590 } |
|
591 |
516 Q_IMPLEMENT_USER_METATYPE(CntServicesContact) |
592 Q_IMPLEMENT_USER_METATYPE(CntServicesContact) |
517 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList) |
593 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList) |
518 |
594 |
519 //EOF |
595 //EOF |