28 #include <HbAction> |
28 #include <HbAction> |
29 #include <HbTapGesture> |
29 #include <HbTapGesture> |
30 |
30 |
31 #include <xqservicerequest.h> |
31 #include <xqservicerequest.h> |
32 #include <xqappmgr.h> |
32 #include <xqappmgr.h> |
|
33 #include <xqaiwdecl.h> |
|
34 #include <xqaiwrequest.h> |
33 #include <cntservicescontact.h> |
35 #include <cntservicescontact.h> |
34 #include <qtcontacts.h> |
36 #include <qtcontacts.h> |
35 #include <xqservicerequest.h> |
|
36 #include <xqaiwrequest.h> |
|
37 #include "msgcontacthandler.h" |
37 #include "msgcontacthandler.h" |
38 |
38 |
39 // LOCAL CONSTANTS |
39 // LOCAL CONSTANTS |
40 const QString ADDRESS_SEPARATOR("; "); |
40 const QString ADDRESS_SEPARATOR("; "); |
41 const QString ADDRESS_OPEN(" ("); |
41 const QString ADDRESS_OPEN(" ("); |
42 const QString ADDRESS_CLOSE(")"); |
42 const QString ADDRESS_CLOSE(")"); |
43 const QString SPACE(" "); |
43 const QString SPACE(" "); |
|
44 const QChar AT_SIGN('@'); |
44 |
45 |
45 //localization |
46 //localization |
46 #define LOC_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info") |
47 #define LOC_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info") |
47 #define LOC_CALL hbTrId("txt_common_menu_call_verb") |
48 #define LOC_CALL hbTrId("txt_common_menu_call_verb") |
48 #define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
49 #define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
49 #define LOC_SAVE_TO_CONTACTS hbTrId("txt_common_menu_save_to_contacts") |
|
50 #define LOC_COPY hbTrId("txt_common_menu_copy") |
50 #define LOC_COPY hbTrId("txt_common_menu_copy") |
|
51 #define LOC_CREATE_EMAIL hbTrId("txt_messaging_menu_create_mail") |
51 |
52 |
52 const QString BG_FRAME_GRAPHICS("qtg_fr_lineedit_normal"); |
53 const QString BG_FRAME_GRAPHICS("qtg_fr_lineedit_normal"); |
53 |
54 |
54 //--------------------------------------------------------------- |
55 //--------------------------------------------------------------- |
55 // UniViewerAddressWidget::UniViewerAddressWidget |
56 // UniViewerAddressWidget::UniViewerAddressWidget |
347 // Check if there is an anchor at this pos |
348 // Check if there is an anchor at this pos |
348 QString anchor = this->anchorAt(pos); |
349 QString anchor = this->anchorAt(pos); |
349 |
350 |
350 if(!anchor.isEmpty() && !this->textCursor().hasSelection()) |
351 if(!anchor.isEmpty() && !this->textCursor().hasSelection()) |
351 { |
352 { |
|
353 // Secondary Actions |
352 populateMenu(contextMenu,anchor); |
354 populateMenu(contextMenu,anchor); |
353 } |
355 } |
354 } |
356 } |
355 |
357 |
356 void UniViewerAddressWidget::populateMenu(HbMenu* contextMenu,const QString& data) |
358 void UniViewerAddressWidget::populateMenu(HbMenu* contextMenu,const QString& data) |
357 { |
359 { |
358 HbAction* action = NULL; |
360 HbAction* action = NULL; |
359 |
361 |
360 int contactId = MsgContactHandler::resolveContactDisplayName( |
362 // Finding if the data is an Email Address |
361 data, |
363 QBool isEmail = data.contains(AT_SIGN, Qt::CaseInsensitive); |
362 QContactPhoneNumber::DefinitionName, |
364 |
363 QContactPhoneNumber::FieldNumber); |
365 if (isEmail) { |
364 |
366 action = contextMenu->addAction(LOC_CREATE_EMAIL, this, SLOT(createEmail())); |
365 if(contactId > 0) |
367 action->setData(data); |
366 { |
368 |
367 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
369 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
368 action->setData(data); |
370 action->setData(data); |
369 } |
371 } |
370 else |
372 else { |
371 { |
373 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
372 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
374 action->setData(data); |
373 action->setData(data); |
375 |
374 } |
376 action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
375 |
377 action->setData(data); |
376 action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
378 |
377 action->setData(data); |
379 action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
378 |
380 action->setData(data); |
379 action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
381 } |
380 action->setData(data); |
|
381 |
382 |
382 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
383 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
383 action->setData(data); |
384 action->setData(data); |
384 |
385 |
385 connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed())); |
386 connect(contextMenu, SIGNAL(aboutToClose()), this, SLOT(menuClosed())); |
386 } |
387 } |
387 |
388 |
388 void UniViewerAddressWidget::shortTapAction(QString anchor,const QPointF& pos) |
389 void UniViewerAddressWidget::shortTapAction(QString anchor,const QPointF& pos) |
389 { |
390 { |
|
391 Q_UNUSED(pos) |
|
392 |
|
393 // Primary Actions |
|
394 |
390 HbAction action; |
395 HbAction action; |
391 action.setData(anchor); |
396 action.setData(anchor); |
392 |
397 |
393 |
398 if (anchor.contains(AT_SIGN, Qt::CaseInsensitive)) { |
394 int contactId = MsgContactHandler::resolveContactDisplayName( |
399 // Email address |
395 anchor, |
400 connect(&action, SIGNAL(triggered()), this, SLOT(createEmail())); |
396 QContactPhoneNumber::DefinitionName, |
401 } |
397 QContactPhoneNumber::FieldNumber); |
402 else { |
398 |
403 connect(&action, SIGNAL(triggered()), this, SLOT(openContactInfo())); |
399 if(contactId > 0 ) |
|
400 { |
|
401 //if resolved conatct open contact card |
|
402 connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo())); |
|
403 } |
|
404 else |
|
405 { |
|
406 //unresolved contact show popup. |
|
407 highlightText(true); |
|
408 |
|
409 HbMenu* contextMenu = new HbMenu(); |
|
410 contextMenu->setDismissPolicy(HbPopup::TapAnywhere); |
|
411 contextMenu->setAttribute(Qt::WA_DeleteOnClose, true); |
|
412 contextMenu->setPreferredPos(pos); |
|
413 |
|
414 populateMenu(contextMenu,anchor); |
|
415 |
|
416 contextMenu->show(); |
|
417 } |
404 } |
418 |
405 |
419 action.trigger(); |
406 action.trigger(); |
420 } |
407 } |
421 |
408 |
469 } |
459 } |
470 |
460 |
471 |
461 |
472 void UniViewerAddressWidget::openContactInfo() |
462 void UniViewerAddressWidget::openContactInfo() |
473 { |
463 { |
474 HbAction* action = qobject_cast<HbAction*>(sender()); |
464 HbAction* action = qobject_cast<HbAction*> (sender()); |
475 |
465 |
476 if(action) |
466 if (action) { |
477 { |
467 QString data = action->data().toString(); |
478 QString data = action->data().toString(); |
468 int contactId = -1; |
479 |
469 QVariant contactType; |
480 int contactId = MsgContactHandler::resolveContactDisplayName( |
470 |
481 data, |
471 if (data.contains(AT_SIGN, Qt::CaseInsensitive)) { |
482 QContactPhoneNumber::DefinitionName, |
472 // Email address |
483 QContactPhoneNumber::FieldNumber); |
473 contactId = MsgContactHandler::resolveContactDisplayName(data, |
484 |
474 QContactEmailAddress::DefinitionName, QContactEmailAddress::FieldEmailAddress); |
485 // if contact is unresolved on phone number field |
475 contactType = QContactEmailAddress::DefinitionName; |
486 // then, try resolving it on email address field |
476 } |
487 if(contactId <= 0) |
477 else { |
488 { |
478 contactId = MsgContactHandler::resolveContactDisplayName(data, |
489 contactId = MsgContactHandler::resolveContactDisplayName( |
479 QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); |
490 data, |
480 contactType = QContactPhoneNumber::DefinitionName; |
491 QContactEmailAddress::DefinitionName, |
|
492 QContactEmailAddress::FieldEmailAddress); |
|
493 } |
481 } |
494 |
482 |
495 //service stuff. |
483 //service stuff. |
496 QString service("phonebookservices"); |
|
497 QString interface; |
|
498 QString operation; |
|
499 QList<QVariant> args; |
484 QList<QVariant> args; |
500 |
485 XQAiwRequest* request = NULL; |
501 if(contactId > 0) |
486 XQApplicationManager appManager; |
502 { |
487 |
503 //open contact card |
488 if (contactId > 0) { |
504 interface = QString("com.nokia.symbian.IContactsView"); |
489 // open existing contact card |
505 operation = QString("openContactCard(int)"); |
490 request = appManager.create(XQI_CONTACTS_VIEW, XQOP_CONTACTS_VIEW_CONTACT_CARD, true); // Embedded |
506 args << contactId; |
491 args << contactId; |
507 } |
492 } |
508 else |
493 else { |
509 { |
494 // open temp contact card |
510 //save to contacts with phone number field prefilled. |
495 request = appManager.create(XQI_CONTACTS_VIEW, |
511 interface = QString("com.nokia.symbian.IContactsEdit"); |
496 XQOP_CONTACTS_VIEW_TEMP_CONTACT_CARD_WITH_DETAIL, true); // Embedded |
512 operation = QString("editCreateNew(QString,QString)"); |
497 args << contactType; // Type |
513 QString type = QContactPhoneNumber::DefinitionName; |
498 args << data; // Actual data |
514 args << type; |
499 } |
515 args << data; |
500 |
516 } |
501 if (request == NULL) { |
517 XQAiwRequest* request; |
502 return; |
518 XQApplicationManager appManager; |
503 } |
519 request = appManager.create(service, interface, operation, true); // embedded |
|
520 if ( request == NULL ) |
|
521 { |
|
522 return; |
|
523 } |
|
524 |
504 |
525 // Result handlers |
505 // Result handlers |
526 connect (request, SIGNAL(requestOk(const QVariant&)), |
506 connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
527 this, SLOT(handleOk(const QVariant&))); |
507 connect(request, SIGNAL(requestError(const QVariant&)), this, |
528 connect (request, SIGNAL(requestError(const QVariant&)), |
508 SLOT(handleError(const QVariant&))); |
529 this, SLOT(handleError(const QVariant&))); |
509 |
530 |
|
531 request->setArguments(args); |
510 request->setArguments(args); |
532 request->send(); |
511 request->send(); |
533 delete request; |
512 delete request; |
534 } |
513 } |
535 } |
514 } |
536 |
515 |
537 void UniViewerAddressWidget::handleOk(const QVariant& result) |
516 void UniViewerAddressWidget::handleOk(const QVariant& result) |
538 { |
517 { |
539 Q_UNUSED(result) |
518 Q_UNUSED(result) |
540 } |
519 } |
541 |
520 |
542 void UniViewerAddressWidget::handleError(int errorCode, const QString& errorMessage) |
521 void UniViewerAddressWidget::handleError(int errorCode, const QString& errorMessage) |
543 { |
522 { |
544 Q_UNUSED(errorMessage) |
523 Q_UNUSED(errorMessage) |
545 Q_UNUSED(errorCode) |
524 Q_UNUSED(errorCode) |
546 } |
|
547 |
|
548 void UniViewerAddressWidget::saveToContacts() |
|
549 { |
|
550 openContactInfo(); |
|
551 } |
525 } |
552 |
526 |
553 void UniViewerAddressWidget::sendMessage() |
527 void UniViewerAddressWidget::sendMessage() |
554 { |
528 { |
555 HbAction* action = qobject_cast<HbAction*>(sender()); |
529 HbAction* action = qobject_cast<HbAction*>(sender()); |
583 //invoke editor & pass phoneNumber. |
557 //invoke editor & pass phoneNumber. |
584 emit sendMessage(phoneNumber,alias); |
558 emit sendMessage(phoneNumber,alias); |
585 } |
559 } |
586 } |
560 } |
587 |
561 |
|
562 //--------------------------------------------------------------- |
|
563 // UniViewerAddressWidget::createEmail |
|
564 // @see header file |
|
565 //--------------------------------------------------------------- |
|
566 void UniViewerAddressWidget::createEmail() |
|
567 { |
|
568 HbAction* action = qobject_cast<HbAction*> (sender()); |
|
569 |
|
570 if (action) { |
|
571 QString emailId = action->data().toString(); |
|
572 |
|
573 // Launch email editor |
|
574 QString interfaceName("com.nokia.symbian.IEmailMessageSend"); |
|
575 QString operation("send(QVariant)"); |
|
576 XQApplicationManager appManager; |
|
577 XQAiwRequest* request = appManager.create(interfaceName, operation, true); |
|
578 if (request == NULL) { |
|
579 return; |
|
580 } |
|
581 |
|
582 // Fill args |
|
583 QStringList recipients; |
|
584 recipients.append(emailId); |
|
585 |
|
586 QMap<QString, QVariant> map; |
|
587 map.insert(QString("to"), recipients); |
|
588 |
|
589 QList<QVariant> args; |
|
590 args.append(map); |
|
591 |
|
592 // Result handlers |
|
593 connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
|
594 connect(request, SIGNAL(requestError(const QVariant&)), this, |
|
595 SLOT(handleError(const QVariant&))); |
|
596 |
|
597 request->setArguments(args); |
|
598 request->send(); |
|
599 delete request; |
|
600 } |
|
601 } |
|
602 |
588 // EOF |
603 // EOF |