52 |
53 |
53 //localization |
54 //localization |
54 #define LOC_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info") |
55 #define LOC_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info") |
55 #define LOC_CALL hbTrId("txt_common_menu_call_verb") |
56 #define LOC_CALL hbTrId("txt_common_menu_call_verb") |
56 #define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
57 #define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
57 #define LOC_SAVE_TO_CONTACTS hbTrId("txt_common_menu_save_to_contacts") |
|
58 #define LOC_COPY hbTrId("txt_common_menu_copy") |
58 #define LOC_COPY hbTrId("txt_common_menu_copy") |
59 #define LOC_CREATE_EMAIL hbTrId("txt_messaging_menu_create_mail") |
59 #define LOC_CREATE_EMAIL hbTrId("txt_messaging_menu_create_mail") |
60 #define LOC_OPEN_LINK hbTrId("txt_messaging_menu_open_link") |
60 #define LOC_OPEN_LINK hbTrId("txt_messaging_menu_open_link") |
61 #define LOC_ADD_TO_BOOKMARKS hbTrId("txt_messaging_menu_add_to_bookmarks") |
61 #define LOC_ADD_TO_BOOKMARKS hbTrId("txt_messaging_menu_add_to_bookmarks") |
62 #define LOC_COPY_LINK hbTrId("txt_messaging_menu_copy_link") |
62 #define LOC_COPY_LINK hbTrId("txt_messaging_menu_copy_link") |
70 this->setScrollable(false); |
70 this->setScrollable(false); |
71 this->setCursorVisibility(Hb::TextCursorHidden); |
71 this->setCursorVisibility(Hb::TextCursorHidden); |
72 this->setFlag(QGraphicsItem::ItemIsFocusable,false); |
72 this->setFlag(QGraphicsItem::ItemIsFocusable,false); |
73 this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
73 this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
74 this->setBackgroundItem(0); |
74 this->setBackgroundItem(0); |
|
75 this->setSmileysEnabled(true); |
75 |
76 |
76 //inserting rules and patterns to map. |
77 //inserting rules and patterns to map. |
77 mRules.insert(NUMBER_RULE,NUMBER_PATTERN); |
78 mRules.insert(NUMBER_RULE,NUMBER_PATTERN); |
78 mRules.insert(EMAIL_RULE,EMAIL_PATTERN); |
79 mRules.insert(EMAIL_RULE,EMAIL_PATTERN); |
79 mRules.insert(URL_RULE,URL_PATTERN); |
80 mRules.insert(URL_RULE,URL_PATTERN); |
249 |
251 |
250 void UniViewerTextItem::addNumberMenu(HbMenu* contextMenu,const QString& data) |
252 void UniViewerTextItem::addNumberMenu(HbMenu* contextMenu,const QString& data) |
251 { |
253 { |
252 HbAction* action = NULL; |
254 HbAction* action = NULL; |
253 |
255 |
254 QString number = data; |
256 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
255 number.remove(NUMBER_RULE); |
257 action->setData(data); |
256 int contactId = MsgContactHandler::resolveContactDisplayName( |
258 |
257 number, |
|
258 QContactPhoneNumber::DefinitionName, |
|
259 QContactPhoneNumber::FieldNumber); |
|
260 |
|
261 if(contactId > 0) |
|
262 { |
|
263 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
264 action->setData(data); |
|
265 } |
|
266 else |
|
267 { |
|
268 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
|
269 action->setData(data); |
|
270 } |
|
271 |
|
272 action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
259 action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
273 action->setData(data); |
260 action->setData(data); |
274 |
261 |
275 action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
262 action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
276 action->setData(data); |
263 action->setData(data); |
287 action->setData(data); |
274 action->setData(data); |
288 |
275 |
289 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
276 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
290 action->setData(data); |
277 action->setData(data); |
291 |
278 |
292 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
|
293 action->setData(data); |
|
294 |
|
295 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
279 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
296 action->setData(data); |
280 action->setData(data); |
297 } |
281 } |
298 |
282 |
299 void UniViewerTextItem::addUrlMenu(HbMenu* contextMenu,const QString& data) |
283 void UniViewerTextItem::addUrlMenu(HbMenu* contextMenu,const QString& data) |
310 action->setData(data); |
294 action->setData(data); |
311 } |
295 } |
312 |
296 |
313 void UniViewerTextItem::handleShortTap(QString anchor,const QPointF& pos) |
297 void UniViewerTextItem::handleShortTap(QString anchor,const QPointF& pos) |
314 { |
298 { |
|
299 Q_UNUSED(pos) |
|
300 |
|
301 // Primary Actions |
|
302 |
315 HbAction action; |
303 HbAction action; |
316 action.setData(anchor); |
304 action.setData(anchor); |
317 |
305 |
318 if(anchor.contains(NUMBER_RULE)) |
306 if(anchor.contains(NUMBER_RULE)) |
319 { |
307 { |
320 QString data = anchor; |
308 connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo())); |
321 data.remove(NUMBER_RULE); |
|
322 int contactId = MsgContactHandler::resolveContactDisplayName( |
|
323 data, |
|
324 QContactPhoneNumber::DefinitionName, |
|
325 QContactPhoneNumber::FieldNumber); |
|
326 |
|
327 if(contactId > 0 ) |
|
328 { |
|
329 //if resolved conatct open contact card |
|
330 connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo())); |
|
331 } |
|
332 else |
|
333 { |
|
334 //unresolved contact show popup. |
|
335 highlightText(true); |
|
336 |
|
337 HbMenu* contextMenu = new HbMenu(); |
|
338 contextMenu->setDismissPolicy(HbPopup::TapAnywhere); |
|
339 contextMenu->setAttribute(Qt::WA_DeleteOnClose, true); |
|
340 contextMenu->setPreferredPos(pos); |
|
341 connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed())); |
|
342 |
|
343 addNumberMenu(contextMenu,anchor); |
|
344 |
|
345 contextMenu->show(); |
|
346 } |
|
347 } |
309 } |
348 else if(anchor.contains(EMAIL_RULE)) |
310 else if(anchor.contains(EMAIL_RULE)) |
349 { |
311 { |
350 //Create email |
312 //Create email |
351 connect(&action,SIGNAL(triggered()),this,SLOT(createEmail())); |
313 connect(&action,SIGNAL(triggered()),this,SLOT(createEmail())); |
487 } |
449 } |
488 } |
450 } |
489 |
451 |
490 void UniViewerTextItem::openContactInfo() |
452 void UniViewerTextItem::openContactInfo() |
491 { |
453 { |
492 HbAction* action = qobject_cast<HbAction*>(sender()); |
454 HbAction* action = qobject_cast<HbAction*> (sender()); |
493 |
455 |
494 if(action) |
456 if (action) { |
495 { |
457 int contactId = -1; |
|
458 QString data = action->data().toString(); |
|
459 QVariant contactType; |
|
460 |
|
461 if (data.contains(QRegExp("^" + NUMBER_RULE))) { |
|
462 data.remove(NUMBER_RULE); |
|
463 |
|
464 contactId = MsgContactHandler::resolveContactDisplayName(data, |
|
465 QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); |
|
466 |
|
467 contactType = QContactPhoneNumber::DefinitionName; |
|
468 } |
|
469 else if (data.contains(QRegExp("^" + EMAIL_RULE))) { |
|
470 data.remove(EMAIL_RULE); |
|
471 |
|
472 contactId = MsgContactHandler::resolveContactDisplayName(data, |
|
473 QContactEmailAddress::DefinitionName, QContactEmailAddress::FieldEmailAddress); |
|
474 |
|
475 contactType = QContactEmailAddress::DefinitionName; |
|
476 } |
|
477 |
496 //service stuff. |
478 //service stuff. |
497 QString service("phonebookservices"); |
|
498 QString interface; |
|
499 QString operation; |
|
500 QList<QVariant> args; |
479 QList<QVariant> args; |
501 |
480 XQAiwRequest* request = NULL; |
502 QString data = action->data().toString(); |
|
503 |
|
504 if(data.contains(QRegExp("^"+NUMBER_RULE))) |
|
505 { |
|
506 data.remove(NUMBER_RULE); |
|
507 |
|
508 int contactId = MsgContactHandler::resolveContactDisplayName( |
|
509 data, |
|
510 QContactPhoneNumber::DefinitionName, |
|
511 QContactPhoneNumber::FieldNumber); |
|
512 |
|
513 if(contactId > 0) |
|
514 { |
|
515 //open contact card |
|
516 interface = QString("com.nokia.symbian.IContactsView"); |
|
517 operation = QString("openContactCard(int)"); |
|
518 args << contactId; |
|
519 } |
|
520 else |
|
521 { |
|
522 //save to contacts with phone number field prefilled. |
|
523 interface = QString("com.nokia.symbian.IContactsEdit"); |
|
524 operation = QString("editCreateNew(QString,QString)"); |
|
525 QString type = QContactPhoneNumber::DefinitionName; |
|
526 args << type; |
|
527 args << data; |
|
528 } |
|
529 } |
|
530 else if(data.contains(QRegExp("^"+EMAIL_RULE))) |
|
531 { |
|
532 data.remove(EMAIL_RULE); |
|
533 |
|
534 int contactId = MsgContactHandler::resolveContactDisplayName( |
|
535 data, |
|
536 QContactEmailAddress::DefinitionName, |
|
537 QContactEmailAddress::FieldEmailAddress); |
|
538 |
|
539 if(contactId > 0) |
|
540 { |
|
541 //open contact card |
|
542 interface = QString("com.nokia.symbian.IContactsView"); |
|
543 operation = QString("openContactCard(int)"); |
|
544 args << contactId; |
|
545 } |
|
546 else |
|
547 { |
|
548 //save to contacts with e-mail field prefilled. |
|
549 interface = QString("com.nokia.symbian.IContactsEdit"); |
|
550 operation = QString("editCreateNew(QString,QString)"); |
|
551 QString type = QContactEmailAddress::DefinitionName; |
|
552 args << type; |
|
553 args << data; |
|
554 } |
|
555 } |
|
556 XQAiwRequest* request; |
|
557 XQApplicationManager appManager; |
481 XQApplicationManager appManager; |
558 request = appManager.create(service, interface, operation, true); // embedded |
482 |
559 if ( request == NULL ) |
483 if (contactId > 0) { |
560 { |
484 // open existing contact card |
561 return; |
485 request = appManager.create(XQI_CONTACTS_VIEW, XQOP_CONTACTS_VIEW_CONTACT_CARD, true); // Embedded |
562 } |
486 args << contactId; |
|
487 } |
|
488 else { |
|
489 // open temp contact card |
|
490 request = appManager.create(XQI_CONTACTS_VIEW, |
|
491 XQOP_CONTACTS_VIEW_TEMP_CONTACT_CARD_WITH_DETAIL, true); // Embedded |
|
492 args << contactType; // Type |
|
493 args << data; // Actual data |
|
494 } |
|
495 |
|
496 if (request == NULL) { |
|
497 return; |
|
498 } |
563 |
499 |
564 // Result handlers |
500 // Result handlers |
565 connect (request, SIGNAL(requestOk(const QVariant&)), |
501 connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
566 this, SLOT(handleOk(const QVariant&))); |
502 connect(request, SIGNAL(requestError(const QVariant&)), this, |
567 connect (request, SIGNAL(requestError(const QVariant&)), |
503 SLOT(handleError(const QVariant&))); |
568 this, SLOT(handleError(const QVariant&))); |
504 |
569 |
|
570 request->setArguments(args); |
505 request->setArguments(args); |
571 request->send(); |
506 request->send(); |
572 delete request; |
507 delete request; |
573 } |
508 } |
574 } |
|
575 |
|
576 |
|
577 void UniViewerTextItem::saveToContacts() |
|
578 { |
|
579 openContactInfo(); |
|
580 } |
509 } |
581 |
510 |
582 void UniViewerTextItem::onServiceRequestCompleted() |
511 void UniViewerTextItem::onServiceRequestCompleted() |
583 { |
512 { |
584 //service request is now complete. delete it. |
513 //service request is now complete. delete it. |