author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 11 Jun 2010 13:35:48 +0300 | |
changeset 34 | 84197e66a4bd |
parent 31 | ebfee66fde93 |
child 43 | 35b64624a9e7 |
permissions | -rw-r--r-- |
31 | 1 |
/* |
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* Message body preview class. |
|
16 |
* has in built logic for finding phone number, email, url. |
|
17 |
* |
|
18 |
*/ |
|
19 |
||
20 |
#include "univiewertextitem.h" |
|
21 |
#include "msgcontacthandler.h" |
|
22 |
||
23 |
#include <QRegExp> |
|
24 |
#include <QApplication> |
|
25 |
#include <QClipboard> |
|
26 |
#include <QTextBlock> |
|
27 |
||
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
28 |
#include <HbTapGesture> |
31 | 29 |
#include <HbMenu> |
30 |
#include <HbAction> |
|
31 |
#include <cntservicescontact.h> |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
32 |
#include <xqservicerequest.h> |
31 | 33 |
#include <xqaiwrequest.h> |
34 |
#include <xqappmgr.h> |
|
35 |
||
36 |
||
37 |
//consts |
|
38 |
||
39 |
//regexp |
|
40 |
const QString NUMBER_PATTERN("(\\(|\\+|\\d)((?:\\d{2,})((?:[\\s-/.\\)\\()])*(?:(\\d+|\\))))*)|((\\*#)(?:\\d+(\\*|#)(?:\\d+#)?))"); |
|
41 |
||
42 |
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 |
||
44 |
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 |
||
46 |
//rules |
|
47 |
const QString NUMBER_RULE("NUMBER_RULE"); |
|
48 |
const QString EMAIL_RULE("EMAIL_RULE"); |
|
49 |
const QString URL_RULE("URL_RULE"); |
|
50 |
||
51 |
//localization |
|
52 |
#define LOC_OPEN_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info") |
|
53 |
#define LOC_CALL hbTrId("txt_common_menu_call_verb") |
|
54 |
#define LOC_SEND_MESSAGE hbTrId("txt_common_menu_send_message") |
|
55 |
#define LOC_SAVE_TO_CONTACTS hbTrId("txt_common_menu_save_to_contacts") |
|
56 |
#define LOC_COPY hbTrId("txt_common_menu_copy") |
|
57 |
#define LOC_CREATE_EMAIL hbTrId("txt_messaging_menu_create_mail") |
|
58 |
#define LOC_OPEN_LINK hbTrId("txt_messaging_menu_open_link") |
|
59 |
#define LOC_ADD_TO_BOOKMARKS hbTrId("txt_messaging_menu_add_to_bookmarks") |
|
60 |
#define LOC_COPY_LINK hbTrId("txt_messaging_menu_copy_link") |
|
61 |
||
62 |
UniViewerTextItem::UniViewerTextItem(QGraphicsItem* parent): |
|
63 |
HbTextEdit(parent), |
|
64 |
mFindOn(true), |
|
65 |
mCursorPos(-1) |
|
66 |
{ |
|
67 |
this->setReadOnly(true); |
|
68 |
this->setScrollable(false); |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
69 |
this->setSmileysEnabled(true); |
31 | 70 |
this->setCursorVisibility(Hb::TextCursorHidden); |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
71 |
this->setFlag(QGraphicsItem::ItemIsFocusable,false); |
31 | 72 |
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
73 |
this->setBackgroundItem(0); |
31 | 74 |
|
75 |
//inserting rules and patterns to map. |
|
76 |
mRules.insert(NUMBER_RULE,NUMBER_PATTERN); |
|
77 |
mRules.insert(EMAIL_RULE,EMAIL_PATTERN); |
|
78 |
mRules.insert(URL_RULE,URL_PATTERN); |
|
79 |
||
80 |
mFormatNormal.setForeground(palette().link()); |
|
81 |
mFormatNormal.setBackground(Qt::transparent); |
|
82 |
||
83 |
mFormatHighlight.setBackground(palette().highlight()); |
|
84 |
mFormatHighlight.setForeground(palette().highlightedText()); |
|
85 |
||
86 |
connect(this, SIGNAL(aboutToShowContextMenu(HbMenu*,QPointF)), |
|
87 |
this, SLOT(aboutToShowContextMenu(HbMenu*,QPointF))); |
|
88 |
} |
|
89 |
||
90 |
UniViewerTextItem::~UniViewerTextItem() |
|
91 |
{ |
|
92 |
} |
|
93 |
||
94 |
void UniViewerTextItem::setFindOn(bool on) |
|
95 |
{ |
|
96 |
mFindOn = on; |
|
97 |
} |
|
98 |
||
99 |
void UniViewerTextItem::setText(const QString& text) |
|
100 |
{ |
|
101 |
||
102 |
this->setPlainText(text); |
|
103 |
applyRule(); |
|
104 |
} |
|
105 |
||
106 |
void UniViewerTextItem::applyRule() |
|
107 |
{ |
|
108 |
||
109 |
if(mFindOn == false) |
|
110 |
{ |
|
111 |
return; |
|
112 |
} |
|
113 |
||
114 |
QMap<QString, QString>::const_iterator i; |
|
115 |
for (i = mRules.constBegin(); i != mRules.constEnd(); ++i) |
|
116 |
{ |
|
117 |
QString ruleName = i.key(); |
|
118 |
QString rule = i.value(); |
|
119 |
QRegExp ruleExp(rule); |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
120 |
ruleExp.setCaseSensitivity(Qt::CaseInsensitive); |
31 | 121 |
|
122 |
QTextCursor cursor = this->document()->find(ruleExp); |
|
123 |
||
124 |
while(cursor.hasSelection()) |
|
125 |
{ |
|
126 |
// Insert anchor in the document |
|
127 |
QTextCharFormat f; |
|
128 |
f.setFontUnderline(true); |
|
129 |
f.setForeground(palette().link()); |
|
130 |
||
131 |
//prepending rule name to identiy different fragment to which |
|
132 |
//catagory it belongs to. |
|
133 |
QString txt = cursor.selectedText().prepend(ruleName); |
|
134 |
||
135 |
if(ruleName == NUMBER_RULE) |
|
136 |
{ |
|
137 |
//removing special char(s) from phone numbers. |
|
138 |
QRegExp numberCharExp("[\\s-/.\\(\\)]"); |
|
139 |
txt = txt.remove(numberCharExp); |
|
140 |
} |
|
141 |
||
142 |
f.setAnchorHref(txt); |
|
143 |
f.setAnchor(true); |
|
144 |
cursor.mergeCharFormat(f); |
|
145 |
||
146 |
// Find next |
|
147 |
cursor = this->document()->find(ruleExp, cursor); |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
||
153 |
void UniViewerTextItem::aboutToShowContextMenu(HbMenu *contextMenu, const QPointF &pos) |
|
154 |
{ |
|
155 |
// Check if there is an anchor at this pos |
|
156 |
QString anchor = this->anchorAt(pos); |
|
157 |
||
158 |
if(!anchor.isEmpty() && !this->textCursor().hasSelection()) |
|
159 |
{ |
|
160 |
//remove default actions. |
|
161 |
contextMenu->clearActions(); |
|
162 |
||
163 |
if(anchor.contains(QRegExp("^"+NUMBER_RULE))) |
|
164 |
{ |
|
165 |
addNumberMenu(contextMenu,anchor); |
|
166 |
} |
|
167 |
else if(anchor.contains(QRegExp("^"+EMAIL_RULE))) |
|
168 |
{ |
|
169 |
addEmailMenu(contextMenu,anchor); |
|
170 |
} |
|
171 |
else if(anchor.contains(QRegExp("^"+URL_RULE))) |
|
172 |
{ |
|
173 |
addUrlMenu(contextMenu,anchor); |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
connect(contextMenu,SIGNAL(aboutToClose()),this,SLOT(menuClosed())); |
|
178 |
||
179 |
} |
|
180 |
||
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
181 |
void UniViewerTextItem::gestureEvent(QGestureEvent* event) |
31 | 182 |
{ |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
183 |
//handle gesture to highlight and dehighlight find item. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
184 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
185 |
if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture))) |
31 | 186 |
{ |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
187 |
//capturing gesture position, and map to local co-ordinates. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
188 |
QPointF pos = mapFromScene(tap->scenePosition()); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
189 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
190 |
switch (tap->state()) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
191 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
192 |
case Qt::GestureStarted: |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
193 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
194 |
//highlight find item. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
195 |
QTextDocument* doc = this->document(); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
196 |
mCursorPos = doc->documentLayout()->hitTest(pos, Qt::ExactHit); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
197 |
highlightText(true); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
198 |
break; |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
199 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
200 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
201 |
case Qt::GestureFinished: |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
202 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
203 |
if (HbTapGesture::Tap == tap->tapStyleHint()) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
204 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
205 |
//gesture is finshed dehighlight text. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
206 |
highlightText(false); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
207 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
208 |
QString anchor = this->anchorAt(pos); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
209 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
210 |
//do short tap action. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
211 |
if (!anchor.isEmpty() && !this->textCursor().hasSelection()) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
212 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
213 |
shortTapAction(anchor); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
214 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
215 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
216 |
break; |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
217 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
218 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
219 |
case Qt::GestureCanceled: |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
220 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
221 |
//gesture is canceled due to pan or swipe, dehighlight text. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
222 |
if (HbTapGesture::Tap == tap->tapStyleHint()) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
223 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
224 |
highlightText(false); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
225 |
break; |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
226 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
227 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
228 |
default: |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
229 |
break; |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
230 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
231 |
event->accept(); |
31 | 232 |
} |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
233 |
else |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
234 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
235 |
event->ignore(); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
236 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
237 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
238 |
//passing gesture event to base class. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
239 |
HbTextEdit::gestureEvent(event); |
31 | 240 |
} |
241 |
||
242 |
void UniViewerTextItem::addNumberMenu(HbMenu* contextMenu,const QString& data) |
|
243 |
{ |
|
244 |
HbAction* action = NULL; |
|
245 |
||
246 |
action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
247 |
action->setData(data); |
|
248 |
||
249 |
action = contextMenu->addAction(LOC_CALL, this, SLOT(call())); |
|
250 |
action->setData(data); |
|
251 |
||
252 |
action = contextMenu->addAction(LOC_SEND_MESSAGE, this, SLOT(sendMessage())); |
|
253 |
action->setData(data); |
|
254 |
||
255 |
action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
|
256 |
action->setData(data); |
|
257 |
||
258 |
action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
|
259 |
action->setData(data); |
|
260 |
} |
|
261 |
||
262 |
void UniViewerTextItem::addEmailMenu(HbMenu* contextMenu,const QString& data) |
|
263 |
{ |
|
264 |
HbAction* action = NULL; |
|
265 |
||
266 |
action = contextMenu->addAction(LOC_CREATE_EMAIL, this, SLOT(createEmail())); |
|
267 |
action->setData(data); |
|
268 |
||
269 |
action = contextMenu->addAction(LOC_OPEN_CONTACT_INFO, this, SLOT(openContactInfo())); |
|
270 |
action->setData(data); |
|
271 |
||
272 |
action = contextMenu->addAction(LOC_SAVE_TO_CONTACTS, this, SLOT(saveToContacts())); |
|
273 |
action->setData(data); |
|
274 |
||
275 |
action = contextMenu->addAction(LOC_COPY, this, SLOT(copyToClipboard())); |
|
276 |
action->setData(data); |
|
277 |
} |
|
278 |
||
279 |
void UniViewerTextItem::addUrlMenu(HbMenu* contextMenu,const QString& data) |
|
280 |
{ |
|
281 |
HbAction* action = NULL; |
|
282 |
||
283 |
action = contextMenu->addAction(LOC_OPEN_LINK, this, SLOT(openLink())); |
|
284 |
action->setData(data); |
|
285 |
||
286 |
action = contextMenu->addAction(LOC_ADD_TO_BOOKMARKS, this, SLOT(addToBookmarks())); |
|
287 |
action->setData(data); |
|
288 |
||
289 |
action = contextMenu->addAction(LOC_COPY_LINK, this, SLOT(copyToClipboard())); |
|
290 |
action->setData(data); |
|
291 |
} |
|
292 |
||
293 |
void UniViewerTextItem::shortTapAction(QString anchor) |
|
294 |
{ |
|
295 |
HbAction action; |
|
296 |
action.setData(anchor); |
|
297 |
||
298 |
if(anchor.contains(NUMBER_RULE)) |
|
299 |
{ |
|
300 |
//open vcard template. |
|
301 |
connect(&action,SIGNAL(triggered()),this,SLOT(openContactInfo())); |
|
302 |
} |
|
303 |
else if(anchor.contains(EMAIL_RULE)) |
|
304 |
{ |
|
305 |
//Create email |
|
306 |
connect(&action,SIGNAL(triggered()),this,SLOT(createEmail())); |
|
307 |
} |
|
308 |
else if(anchor.contains(URL_RULE)) |
|
309 |
{ |
|
310 |
//Open link in the browser |
|
311 |
connect(&action,SIGNAL(triggered()),this,SLOT(openLink())); |
|
312 |
} |
|
313 |
||
314 |
action.trigger(); |
|
315 |
} |
|
316 |
||
317 |
||
318 |
void UniViewerTextItem::copyToClipboard() |
|
319 |
{ |
|
320 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
321 |
||
322 |
if(action) |
|
323 |
{ |
|
324 |
QMimeData* data = new QMimeData(); |
|
325 |
QString str = action->data().toString(); |
|
326 |
||
327 |
//removing rule name before setting it to clipboard. |
|
328 |
str.remove(QRegExp("^"+NUMBER_RULE)); |
|
329 |
str.remove(QRegExp("^"+EMAIL_RULE)); |
|
330 |
str.remove(QRegExp("^"+URL_RULE)); |
|
331 |
||
332 |
data->setText(str); |
|
333 |
QApplication::clipboard()->setMimeData(data); |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
void UniViewerTextItem::call() |
|
338 |
{ |
|
339 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
340 |
||
341 |
if(action) |
|
342 |
{ |
|
343 |
QString phoneNumber = action->data().toString(); |
|
344 |
phoneNumber.remove(NUMBER_RULE); |
|
345 |
||
346 |
//invoke dialer service and pass phoneNumber. |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
347 |
QString serviceName("com.nokia.symbian.ICallDial"); |
31 | 348 |
QString operation("dial(QString)"); |
349 |
||
350 |
XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName,operation,false); |
|
351 |
||
352 |
connect(serviceRequest, SIGNAL(requestCompleted(QVariant)), |
|
353 |
this, SLOT(onServiceRequestCompleted())); |
|
354 |
||
355 |
connect(serviceRequest, SIGNAL(requestError(int)), |
|
356 |
this, SLOT(onServiceRequestCompleted())); |
|
357 |
||
358 |
*serviceRequest << phoneNumber; |
|
359 |
serviceRequest->send(); |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
void UniViewerTextItem::sendMessage() |
|
364 |
{ |
|
365 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
366 |
||
367 |
if(action) |
|
368 |
{ |
|
369 |
QString phoneNumber = action->data().toString(); |
|
370 |
phoneNumber.remove(NUMBER_RULE); |
|
371 |
||
372 |
//invoke editor & pass phoneNumber. |
|
373 |
emit sendMessage(phoneNumber); |
|
374 |
} |
|
375 |
} |
|
376 |
||
377 |
void UniViewerTextItem::createEmail() |
|
378 |
{ |
|
379 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
380 |
||
381 |
if ( action ) |
|
382 |
{ |
|
383 |
QString emailId = action->data().toString(); |
|
384 |
emailId.remove(EMAIL_RULE); |
|
385 |
||
386 |
// Launch email editor |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
387 |
QString interfaceName("com.nokia.symbian.IEmailMessageSend"); |
31 | 388 |
QString operation("send(QVariant)"); |
389 |
XQApplicationManager appManager; |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
390 |
XQAiwRequest* request = appManager.create(interfaceName, |
31 | 391 |
operation, true); |
392 |
if ( request == NULL ) |
|
393 |
{ |
|
394 |
return; |
|
395 |
} |
|
396 |
||
397 |
// Fill args |
|
398 |
QStringList recipients; |
|
399 |
recipients.append(emailId); |
|
400 |
||
401 |
QMap<QString,QVariant> map; |
|
402 |
map.insert(QString("to"),recipients); |
|
403 |
||
404 |
QList<QVariant> args; |
|
405 |
args.append(map); |
|
406 |
||
407 |
// Result handlers |
|
408 |
connect (request, SIGNAL(requestOk(const QVariant&)), |
|
409 |
this, SLOT(handleOk(const QVariant&))); |
|
410 |
connect (request, SIGNAL(requestError(const QVariant&)), |
|
411 |
this, SLOT(handleError(const QVariant&))); |
|
412 |
||
413 |
request->setArguments(args); |
|
414 |
request->send(); |
|
415 |
delete request; |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
void UniViewerTextItem::openLink() |
|
420 |
{ |
|
421 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
422 |
||
423 |
if(action) |
|
424 |
{ |
|
425 |
QString url = action->data().toString(); |
|
426 |
url.remove(URL_RULE); |
|
427 |
//invoke browser service & pass url. |
|
428 |
} |
|
429 |
} |
|
430 |
||
431 |
void UniViewerTextItem::addToBookmarks() |
|
432 |
{ |
|
433 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
434 |
||
435 |
if(action) |
|
436 |
{ |
|
437 |
QString url = action->data().toString(); |
|
438 |
url.remove(URL_RULE); |
|
439 |
//invoke browser service to save url. |
|
440 |
} |
|
441 |
} |
|
442 |
||
443 |
void UniViewerTextItem::openContactInfo() |
|
444 |
{ |
|
445 |
HbAction* action = qobject_cast<HbAction*>(sender()); |
|
446 |
||
447 |
if(action) |
|
448 |
{ |
|
449 |
QList<QVariant> args; |
|
450 |
QString operation; |
|
451 |
||
452 |
QString data = action->data().toString(); |
|
453 |
||
454 |
if(data.contains(QRegExp("^"+NUMBER_RULE))) |
|
455 |
{ |
|
456 |
data.remove(NUMBER_RULE); |
|
457 |
||
458 |
int contactId = MsgContactHandler::resolveContactDisplayName( |
|
459 |
data, |
|
460 |
QContactPhoneNumber::DefinitionName, |
|
461 |
QContactPhoneNumber::FieldNumber); |
|
462 |
||
463 |
if(contactId > 0) |
|
464 |
{ |
|
465 |
//open contact card |
|
466 |
operation = QString("open(int)"); |
|
467 |
args << contactId; |
|
468 |
} |
|
469 |
else |
|
470 |
{ |
|
471 |
//save to contacts with phone number field prefilled. |
|
472 |
||
473 |
operation = QString("editCreateNew(QString,QString)"); |
|
474 |
QString type = QContactPhoneNumber::DefinitionName; |
|
475 |
||
476 |
args << type; |
|
477 |
args << data; |
|
478 |
} |
|
479 |
} |
|
480 |
else if(data.contains(QRegExp("^"+EMAIL_RULE))) |
|
481 |
{ |
|
482 |
data.remove(EMAIL_RULE); |
|
483 |
||
484 |
int contactId = MsgContactHandler::resolveContactDisplayName( |
|
485 |
data, |
|
486 |
QContactEmailAddress::DefinitionName, |
|
487 |
QContactEmailAddress::FieldEmailAddress); |
|
488 |
||
489 |
if(contactId > 0) |
|
490 |
{ |
|
491 |
//open contact card |
|
492 |
operation = QString("open(int)"); |
|
493 |
args << contactId; |
|
494 |
} |
|
495 |
else |
|
496 |
{ |
|
497 |
//save to contacts with e-mail field prefilled. |
|
498 |
||
499 |
operation = QString("editCreateNew(QString,QString)"); |
|
500 |
||
501 |
QString type = QContactEmailAddress::DefinitionName; |
|
502 |
||
503 |
args << type; |
|
504 |
args << data; |
|
505 |
} |
|
506 |
} |
|
507 |
||
508 |
//service stuff. |
|
509 |
QString serviceName("com.nokia.services.phonebookservices"); |
|
510 |
||
511 |
XQAiwRequest* request; |
|
512 |
XQApplicationManager appManager; |
|
513 |
request = appManager.create(serviceName, "Fetch", operation, true); // embedded |
|
514 |
if ( request == NULL ) |
|
515 |
{ |
|
516 |
return; |
|
517 |
} |
|
518 |
||
519 |
// Result handlers |
|
520 |
connect (request, SIGNAL(requestOk(const QVariant&)), |
|
521 |
this, SLOT(handleOk(const QVariant&))); |
|
522 |
connect (request, SIGNAL(requestError(const QVariant&)), |
|
523 |
this, SLOT(handleError(const QVariant&))); |
|
524 |
||
525 |
request->setArguments(args); |
|
526 |
request->send(); |
|
527 |
delete request; |
|
528 |
} |
|
529 |
} |
|
530 |
||
531 |
||
532 |
void UniViewerTextItem::saveToContacts() |
|
533 |
{ |
|
534 |
//handler for save to contacts. |
|
535 |
} |
|
536 |
||
537 |
void UniViewerTextItem::onServiceRequestCompleted() |
|
538 |
{ |
|
539 |
//service request is now complete. delete it. |
|
540 |
||
541 |
XQServiceRequest* request = qobject_cast<XQServiceRequest*>(sender()); |
|
542 |
||
543 |
if(request) |
|
544 |
{ |
|
545 |
delete request; |
|
546 |
} |
|
547 |
} |
|
548 |
||
549 |
void UniViewerTextItem::menuClosed() |
|
550 |
{ |
|
551 |
highlightText(false); |
|
552 |
} |
|
553 |
||
554 |
void UniViewerTextItem::highlightText(bool highlight) |
|
555 |
{ |
|
556 |
QTextBlock textBlock = this->document()->findBlock(mCursorPos); |
|
557 |
||
558 |
QTextBlock::iterator it; |
|
559 |
||
560 |
for (it = textBlock.begin(); !(it.atEnd()); ++it) |
|
561 |
{ |
|
562 |
QTextFragment currentFragment = it.fragment(); |
|
563 |
||
564 |
if (currentFragment.isValid() && currentFragment.contains(mCursorPos) |
|
565 |
&& currentFragment.charFormat().fontUnderline()) |
|
566 |
{ |
|
567 |
int start = currentFragment.position(); |
|
568 |
int length = currentFragment.length(); |
|
569 |
||
570 |
QTextCursor cursor = this->textCursor(); |
|
571 |
cursor.clearSelection(); |
|
572 |
cursor.setPosition(start); |
|
573 |
cursor.setPosition(start + length,QTextCursor::KeepAnchor); |
|
574 |
||
575 |
if(highlight) |
|
576 |
{ |
|
577 |
cursor.mergeCharFormat(mFormatHighlight); |
|
578 |
} |
|
579 |
else |
|
580 |
{ |
|
581 |
cursor.mergeCharFormat(mFormatNormal); |
|
582 |
} |
|
583 |
||
584 |
cursor.clearSelection(); |
|
585 |
break; |
|
586 |
} |
|
587 |
} |
|
588 |
} |
|
589 |
||
590 |
//--------------------------------------------------------------- |
|
591 |
// UniViewerTextItem::handleOk |
|
592 |
// |
|
593 |
//--------------------------------------------------------------- |
|
594 |
void UniViewerTextItem::handleOk(const QVariant& result) |
|
595 |
{ |
|
596 |
Q_UNUSED(result) |
|
597 |
} |
|
598 |
||
599 |
//--------------------------------------------------------------- |
|
600 |
// UniViewerTextItem::handleError |
|
601 |
// |
|
602 |
//--------------------------------------------------------------- |
|
603 |
void UniViewerTextItem::handleError(int errorCode, const QString& errorMessage) |
|
604 |
{ |
|
605 |
Q_UNUSED(errorMessage) |
|
606 |
Q_UNUSED(errorCode) |
|
607 |
} |