36 |
36 |
37 |
37 |
38 //consts |
38 //consts |
39 |
39 |
40 //regexp |
40 //regexp |
41 const QString NUMBER_PATTERN("(\\(?(\\+|\\d))((?:\\d)((?:[\\s-/.\\)\\(])*(?:(\\d+|\\))))*(?:\\d|\\)))|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))"); |
41 const QString NUMBER_PATTERN("(\\(?(\\+|\\d))((?:\\d)((?:[\\s-/.\\)\\(])*(?:(\\d+|\\))))*(?:\\d?|\\)))|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))"); |
42 |
42 |
43 const QString EMAIL_PATTERN("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?"); |
43 const QString EMAIL_PATTERN("[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?"); |
44 |
44 |
45 const QString URL_PATTERN("(((ht|f|rt)(tp|sp)(s?)\\:\\/\\/)|(www|wap)(?:\\.))(([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*)(\\.)([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\'\\/\\\\+&%\\$#_=~]*))+"); |
45 const QString URL_PATTERN("(((ht|f|rt)(tp|sp)(s?)\\:\\/\\/)|(www|wap)(?:\\.))(([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*)(\\.)([-\\w]*[0-9a-zA-Z])+(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\?\\,\'\\/\\\\+&%\\$#_=~]*))+[a-zA-Z0-9/]"); |
46 |
|
47 |
46 |
48 //rules |
47 //rules |
49 const QString NUMBER_RULE("NUMBER_RULE"); |
48 const QString NUMBER_RULE("NUMBER_RULE"); |
50 const QString EMAIL_RULE("EMAIL_RULE"); |
49 const QString EMAIL_RULE("EMAIL_RULE"); |
51 const QString URL_RULE("URL_RULE"); |
50 const QString URL_RULE("URL_RULE"); |
52 |
51 |
53 //localization |
52 //localization |
54 #define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info") |
53 #define LOC_CONTACT_INFO hbTrId("txt_messaging_menu_contact_info") |
55 #define LOC_CALL hbTrId("txt_common_menu_call_verb") |
54 #define LOC_CALL hbTrId("txt_common_menu_call_verb") |
56 #define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
55 #define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
57 #define LOC_SAVE_TO_CONTACTS hbTrId("txt_common_menu_save_to_contacts") |
56 #define LOC_SAVE_TO_CONTACTS hbTrId("txt_common_menu_save_to_contacts") |
58 #define LOC_COPY hbTrId("txt_common_menu_copy") |
57 #define LOC_COPY hbTrId("txt_common_menu_copy") |
59 #define LOC_CREATE_EMAIL hbTrId("txt_messaging_menu_create_mail") |
58 #define LOC_CREATE_EMAIL hbTrId("txt_messaging_menu_create_mail") |
242 |
241 |
243 void UniViewerTextItem::addNumberMenu(HbMenu* contextMenu,const QString& data) |
242 void UniViewerTextItem::addNumberMenu(HbMenu* contextMenu,const QString& data) |
244 { |
243 { |
245 HbAction* action = NULL; |
244 HbAction* action = NULL; |
246 |
245 |
247 action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo())); |
246 QString number = data; |
248 action->setData(data); |
247 number.remove(NUMBER_RULE); |
|
248 int contactId = MsgContactHandler::resolveContactDisplayName( |
|
249 number, |
|
250 QContactPhoneNumber::DefinitionName, |
|
251 QContactPhoneNumber::FieldNumber); |
|
252 |
|
253 if(contactId > 0) |
|
254 { |
|
255 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
256 action->setData(data); |
|
257 } |
|
258 else |
|
259 { |
|
260 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
|
261 action->setData(data); |
|
262 } |
249 |
263 |
250 action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
264 action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
251 action->setData(data); |
265 action->setData(data); |
252 |
266 |
253 action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
267 action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
254 action->setData(data); |
268 action->setData(data); |
255 |
269 |
|
270 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
|
271 action->setData(data); |
|
272 } |
|
273 |
|
274 void UniViewerTextItem::addEmailMenu(HbMenu* contextMenu,const QString& data) |
|
275 { |
|
276 HbAction* action = NULL; |
|
277 |
|
278 action = contextMenu->addAction(LOC_CREATE_EMAIL, this, SLOT(createEmail())); |
|
279 action->setData(data); |
|
280 |
|
281 action = contextMenu->addAction(LOC_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
282 action->setData(data); |
|
283 |
256 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
284 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
257 action->setData(data); |
285 action->setData(data); |
258 |
286 |
259 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
287 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
260 action->setData(data); |
288 action->setData(data); |
261 } |
289 } |
262 |
290 |
263 void UniViewerTextItem::addEmailMenu(HbMenu* contextMenu,const QString& data) |
291 void UniViewerTextItem::addUrlMenu(HbMenu* contextMenu,const QString& data) |
264 { |
292 { |
265 HbAction* action = NULL; |
293 HbAction* action = NULL; |
266 |
294 |
267 action = contextMenu->addAction(LOC_CREATE_EMAIL, this, SLOT(createEmail())); |
|
268 action->setData(data); |
|
269 |
|
270 action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
271 action->setData(data); |
|
272 |
|
273 action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
|
274 action->setData(data); |
|
275 |
|
276 action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
|
277 action->setData(data); |
|
278 } |
|
279 |
|
280 void UniViewerTextItem::addUrlMenu(HbMenu* contextMenu,const QString& data) |
|
281 { |
|
282 HbAction* action = NULL; |
|
283 |
|
284 action = contextMenu->addAction(LOC_OPEN_LINK, this, SLOT(openLink())); |
295 action = contextMenu->addAction(LOC_OPEN_LINK, this, SLOT(openLink())); |
285 action->setData(data); |
296 action->setData(data); |
286 |
297 |
287 action = contextMenu->addAction(LOC_ADD_TO_BOOKMARKS, this, SLOT(addToBookmarks())); |
298 action = contextMenu->addAction(LOC_ADD_TO_BOOKMARKS, this, SLOT(addToBookmarks())); |
288 action->setData(data); |
299 action->setData(data); |
289 |
300 |
290 action = contextMenu->addAction(LOC_COPY_LINK, this, SLOT(copyToClipboard())); |
301 action = contextMenu->addAction(LOC_COPY_LINK, this, SLOT(copyToClipboard())); |
291 action->setData(data); |
302 action->setData(data); |
292 } |
303 } |
293 |
304 |
294 void UniViewerTextItem::shortTapAction(QString anchor) |
305 void UniViewerTextItem::handleShortTap(QString anchor,const QPointF& pos) |
295 { |
306 { |
296 HbAction action; |
307 HbAction action; |
297 action.setData(anchor); |
308 action.setData(anchor); |
298 |
309 |
299 if(anchor.contains(NUMBER_RULE)) |
310 if(anchor.contains(NUMBER_RULE)) |
300 { |
311 { |
301 //open vcard template. |
312 QString data = anchor; |
302 connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo())); |
313 data.remove(NUMBER_RULE); |
|
314 int contactId = MsgContactHandler::resolveContactDisplayName( |
|
315 data, |
|
316 QContactPhoneNumber::DefinitionName, |
|
317 QContactPhoneNumber::FieldNumber); |
|
318 |
|
319 if(contactId > 0 ) |
|
320 { |
|
321 //if resolved conatct open contact card |
|
322 connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo())); |
|
323 } |
|
324 else |
|
325 { |
|
326 //unresolved contact show popup. |
|
327 highlightText(true); |
|
328 |
|
329 HbMenu* contextMenu = new HbMenu(); |
|
330 contextMenu->setDismissPolicy(HbPopup::TapAnywhere); |
|
331 contextMenu->setAttribute(Qt::WA_DeleteOnClose, true); |
|
332 contextMenu->setPreferredPos(pos); |
|
333 connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed())); |
|
334 |
|
335 addNumberMenu(contextMenu,anchor); |
|
336 |
|
337 contextMenu->show(); |
|
338 } |
303 } |
339 } |
304 else if(anchor.contains(EMAIL_RULE)) |
340 else if(anchor.contains(EMAIL_RULE)) |
305 { |
341 { |
306 //Create email |
342 //Create email |
307 connect(&action,SIGNAL(triggered()),this,SLOT(createEmail())); |
343 connect(&action,SIGNAL(triggered()),this,SLOT(createEmail())); |