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