author | William Roberts <williamr@symbian.org> |
Thu, 22 Jul 2010 16:32:06 +0100 | |
branch | GCC_SURGE |
changeset 47 | 5b14749788d7 |
parent 27 | e4592d119491 |
parent 44 | 36f374c67aa8 |
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 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include "msgeditorwidget.h" |
|
19 |
||
20 |
// SYSTEM INCLUDES |
|
21 |
#include <HbStyle> |
|
22 |
#include <HbPushButton> |
|
23 |
#include <HbTextItem> |
|
24 |
#include <qgraphicsscene.h> |
|
25 |
#include <HbFrameDrawer> |
|
26 |
#include <HbFrameItem> |
|
27 |
#include <HbAction> |
|
28 |
#include <csmsaccount.h> |
|
29 |
#include <smutset.h> |
|
30 |
#include <hbmessagebox.h> |
|
31 |
#include <QTimer> |
|
32 |
#include "unieditorpluginloader.h" |
|
33 |
#include "unieditorplugininterface.h" |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
34 |
#include "UniSendingSettings.h" |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
35 |
#include "UniEditorGenUtils.h" |
31 | 36 |
#include "debugtraces.h" |
37 |
||
38 |
// LOCAL CONSTANTS |
|
39 |
||
40 |
const QString SEND_ICON("qtg_mono_send"); |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
41 |
const QString BACKGROUND("qtg_fr_input_v_bg"); |
31 | 42 |
const QString BACKGROUND_FRAME("qtg_fr_btn_normal"); |
43 |
||
44 |
const QString SEND_BUTTON_NORMAL("qtg_fr_input_btn_function_normal"); |
|
45 |
const QString SEND_BUTTON_PRESSED("qtg_fr_input_btn_function_pressed"); |
|
46 |
const QString SEND_BUTTON_DISABLED("qtg_fr_input_btn_function_disabled"); |
|
47 |
||
48 |
#define LOC_SMS_CHAR_LIMIT_REACHED hbTrId("txt_messaging_dialog_sms_character_count_exceeded") |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
49 |
#define LOC_HINT_TEXT hbTrId("txt_messaging_formlabel_enter_message_here") |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
50 |
|
31 | 51 |
|
52 |
const TInt KShowCounterLimit = 10; |
|
53 |
||
54 |
QGraphicsItem* FOCUSITEM = 0; |
|
55 |
||
56 |
//--------------------------------------------------------------- |
|
57 |
// MsgEditorWidget::MsgEditorWidget |
|
58 |
// @see header |
|
59 |
//--------------------------------------------------------------- |
|
60 |
MsgEditorWidget::MsgEditorWidget(QGraphicsItem *parent) : |
|
61 |
HbWidget(parent), mMsgEditor(NULL), |
|
62 |
mSendButton(NULL),mPluginLoader(NULL) |
|
63 |
{ |
|
64 |
//setting background. |
|
65 |
HbFrameItem* backGround = new HbFrameItem(this); |
|
66 |
backGround->frameDrawer().setFrameGraphicsName(BACKGROUND); |
|
67 |
backGround->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesVertical); |
|
68 |
backGround->frameDrawer().setFillWholeRect(true); |
|
69 |
this->setBackgroundItem(backGround); |
|
70 |
||
71 |
// Initialize the widget. |
|
72 |
init(); |
|
73 |
} |
|
74 |
||
75 |
//--------------------------------------------------------------- |
|
76 |
// MsgEditorWidget::init |
|
77 |
// @see header |
|
78 |
//--------------------------------------------------------------- |
|
79 |
void MsgEditorWidget::init() |
|
80 |
{ |
|
81 |
// Create mandatory element of mesh layout. |
|
82 |
mMsgEditor = new MsgEditor(this); |
|
83 |
mMsgEditor->setMaxRows(3); // NOTE: Don't remove this line. |
|
84 |
HbStyle::setItemName(mMsgEditor, "msgEditor"); |
|
85 |
||
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
86 |
mSendButton = new HbPushButton(this); |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
87 |
HbStyle::setItemName(mSendButton, "sendButton"); |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
88 |
mSendButton->setEnabled(false); |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
89 |
|
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
90 |
HbFrameItem* backGround = new HbFrameItem(this); |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
91 |
backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
92 |
mSendButton->setBackgroundItem(backGround); |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
93 |
updateButtonBackground(SEND_BUTTON_DISABLED); |
31 | 94 |
mSendButton->setIcon(HbIcon(SEND_ICON)); |
95 |
||
96 |
mCharCounter = new HbTextItem(this); |
|
97 |
HbStyle::setItemName(mCharCounter, "charCounter"); |
|
98 |
mCharCounter->setZValue(1.5); |
|
99 |
||
100 |
mBackgroundItem = new HbFrameItem(this); |
|
101 |
HbStyle::setItemName(mBackgroundItem, "charCounterFrame"); |
|
102 |
||
103 |
mBackgroundItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
104 |
mBackgroundItem->frameDrawer().setFillWholeRect(true); |
|
105 |
||
106 |
mBackgroundItem->frameDrawer().setFrameGraphicsName( |
|
107 |
BACKGROUND_FRAME); |
|
108 |
||
109 |
//Create editor utils object |
|
110 |
mEditorUtils = new UniEditorGenUtils(); |
|
111 |
||
112 |
FOCUSITEM = mSendButton; |
|
113 |
||
114 |
||
115 |
connect(mSendButton, SIGNAL(clicked()),this, SLOT(onClicked())); |
|
116 |
connect(mSendButton, SIGNAL(pressed()),this, SLOT(onPressed())); |
|
117 |
connect(mSendButton, SIGNAL(released()),this, SLOT(onReleased())); |
|
118 |
connect(mMsgEditor, SIGNAL(replyStarted()),this, SIGNAL(replyStarted())); |
|
119 |
connect(mMsgEditor, SIGNAL(textChanged(QString)),this,SLOT(onTextChanged(QString))); |
|
120 |
||
121 |
} |
|
122 |
||
123 |
//--------------------------------------------------------------- |
|
124 |
// MsgEditorWidget::~MsgEditorWidget |
|
125 |
// @see header |
|
126 |
//--------------------------------------------------------------- |
|
127 |
MsgEditorWidget::~MsgEditorWidget() |
|
128 |
{ |
|
129 |
delete mEditorUtils; |
|
130 |
} |
|
131 |
||
132 |
//--------------------------------------------------------------- |
|
133 |
// MsgEditorWidget::content |
|
134 |
// @see header |
|
135 |
//--------------------------------------------------------------- |
|
136 |
QString MsgEditorWidget::content() const |
|
137 |
{ |
|
138 |
return mMsgEditor->text(); |
|
139 |
} |
|
140 |
||
141 |
//--------------------------------------------------------------- |
|
142 |
// MsgEditorWidget::setContent |
|
143 |
// @see header |
|
144 |
//--------------------------------------------------------------- |
|
145 |
void MsgEditorWidget::setContent(const QString &text) |
|
146 |
{ |
|
147 |
mMsgEditor->setText(text); |
|
148 |
} |
|
149 |
||
150 |
//--------------------------------------------------------------- |
|
151 |
// MsgEditorWidget::clear |
|
152 |
// @see header |
|
153 |
//--------------------------------------------------------------- |
|
154 |
void MsgEditorWidget::clear() |
|
155 |
{ |
|
156 |
mMsgEditor->setText(QString()); |
|
157 |
mMsgEditor->setCursorVisibility(Hb::TextCursorHidden); |
|
158 |
} |
|
159 |
||
160 |
//--------------------------------------------------------------- |
|
161 |
// MsgEditorWidget::onTextChanged |
|
162 |
// @see header |
|
163 |
//--------------------------------------------------------------- |
|
164 |
void MsgEditorWidget::onTextChanged(const QString& str) |
|
165 |
{ |
|
166 |
//If char limit is already reached we are about to show the sms limit dialog |
|
167 |
//So we need not process the additional character entered |
|
168 |
if(mSmsCharLimitReached) |
|
169 |
{ |
|
170 |
return; |
|
171 |
} |
|
172 |
if(str.length() > 0 ) |
|
173 |
{ |
|
174 |
if(!mSendButton->isEnabled()) |
|
175 |
{ |
|
176 |
mSendButton->setFocusProxy(mMsgEditor); |
|
177 |
mSendButton->setEnabled(true); |
|
178 |
updateButtonBackground(SEND_BUTTON_NORMAL); |
|
179 |
} |
|
180 |
} |
|
181 |
else |
|
182 |
{ |
|
183 |
if(mSendButton->isEnabled()) |
|
184 |
{ |
|
185 |
mSendButton->setFocusProxy(0); |
|
186 |
mSendButton->setEnabled(false); |
|
187 |
updateButtonBackground(SEND_BUTTON_DISABLED); |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
//Check done for optimization |
|
192 |
//Only if content is deleted we need to call encodingsettings again |
|
193 |
if(mPrevBuffer.isEmpty() || str.size() <= mPrevBuffer.size()) |
|
194 |
{ |
|
195 |
mPluginInterface->setEncodingSettings(EFalse,ESmsEncodingNone,mCharSupportType); |
|
196 |
} |
|
197 |
||
198 |
TInt numOfRemainingChars; |
|
199 |
TInt numOfPDUs; |
|
200 |
TBool unicodeMode; |
|
201 |
TSmsEncoding alternativeEncodingType; |
|
202 |
QString string = str; |
|
203 |
mPluginInterface->getNumPDUs(string, numOfRemainingChars, numOfPDUs, |
|
204 |
unicodeMode, alternativeEncodingType); |
|
205 |
||
206 |
//Set char counter value |
|
207 |
QString display = QString("%1(%2)").arg(numOfRemainingChars).arg(numOfPDUs); |
|
208 |
mCharCounter->setText(display); |
|
209 |
||
210 |
if(numOfPDUs > 1 || numOfRemainingChars <= KShowCounterLimit ) |
|
211 |
{ |
|
212 |
mCharCounter->setVisible(true); |
|
213 |
mBackgroundItem->setVisible(true); |
|
214 |
} |
|
215 |
else |
|
216 |
{ |
|
217 |
mCharCounter->setVisible(false); |
|
218 |
mBackgroundItem->setVisible(false); |
|
219 |
} |
|
220 |
||
221 |
//Check if sms segment limit has been reached |
|
222 |
bool unicode = (unicodeMode) ? true : false; |
|
223 |
int contentSize = mEditorUtils->UTF8Size(string); |
|
224 |
int maxSmsSize = 0; |
|
225 |
TRAP_IGNORE(maxSmsSize = mEditorUtils->MaxSmsMsgSizeL(unicode)); |
|
226 |
||
227 |
if(contentSize > maxSmsSize) |
|
228 |
{ |
|
229 |
//Give breathing time for ITUT to complete its processing |
|
230 |
//without this there is a crash as ITUT cant complete its processing |
|
231 |
mSmsCharLimitReached = true; |
|
232 |
QTimer::singleShot(50, this, SLOT(handleSmsCharLimitReached())); |
|
233 |
if(mPrevBuffer.isEmpty()) |
|
234 |
{ |
|
235 |
//Chop the last char and set it to the editor |
|
236 |
string.chop(1); |
|
237 |
mPrevBuffer = string; |
|
238 |
} |
|
239 |
} |
|
240 |
else |
|
241 |
{ |
|
242 |
//Save the previous buffer |
|
243 |
mPrevBuffer = string; |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
//--------------------------------------------------------------- |
|
248 |
// MsgEditorWidget::handleSmsCharLimitReached |
|
249 |
// @see header |
|
250 |
//--------------------------------------------------------------- |
|
251 |
void MsgEditorWidget::handleSmsCharLimitReached() |
|
252 |
{ |
|
253 |
mSmsCharLimitReached = false; |
|
254 |
||
255 |
HbMessageBox::question(LOC_SMS_CHAR_LIMIT_REACHED, |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
256 |
this,SLOT(onSmsCharLimitReached(HbAction*)), |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
257 |
HbMessageBox::Ok | HbMessageBox::Cancel); |
31 | 258 |
|
259 |
||
260 |
} |
|
261 |
||
262 |
//--------------------------------------------------------------- |
|
263 |
// MsgEditor::onClicked |
|
264 |
// @see header |
|
265 |
//--------------------------------------------------------------- |
|
266 |
void MsgEditorWidget::onClicked() |
|
267 |
{ |
|
268 |
mSendButton->setFocusProxy(0); |
|
269 |
mMsgEditor->setFocusProxy(mSendButton); |
|
270 |
||
271 |
this->scene()->clearFocus(); |
|
272 |
this->scene()->setFocusItem(mSendButton); |
|
273 |
||
274 |
mMsgEditor->setFocusProxy(0); |
|
275 |
||
276 |
mMsgEditor->setCursorVisibility(Hb::TextCursorHidden); |
|
277 |
||
278 |
emit sendMessage(); |
|
279 |
} |
|
280 |
||
281 |
//--------------------------------------------------------------- |
|
282 |
// MsgEditor::updateButtonBackground |
|
283 |
// @see header |
|
284 |
//--------------------------------------------------------------- |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
285 |
void MsgEditorWidget::updateButtonBackground(const QString& bg) |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
286 |
{ |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
287 |
HbFrameItem* drawer = static_cast<HbFrameItem*>(mSendButton->backgroundItem()); |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
288 |
if(drawer) |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
289 |
{ |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
290 |
drawer->frameDrawer().setFrameGraphicsName(bg); |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
291 |
} |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
292 |
} |
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
293 |
|
31 | 294 |
|
295 |
//--------------------------------------------------------------- |
|
296 |
// MsgEditor::onPressed |
|
297 |
// @see header |
|
298 |
//--------------------------------------------------------------- |
|
299 |
void MsgEditorWidget::onPressed() |
|
300 |
{ |
|
301 |
updateButtonBackground(SEND_BUTTON_PRESSED); |
|
302 |
} |
|
303 |
||
304 |
//--------------------------------------------------------------- |
|
305 |
// MsgEditor::onReleased |
|
306 |
// @see header |
|
307 |
//--------------------------------------------------------------- |
|
308 |
void MsgEditorWidget::onReleased() |
|
309 |
{ |
|
310 |
updateButtonBackground(SEND_BUTTON_NORMAL); |
|
311 |
} |
|
312 |
||
313 |
//--------------------------------------------------------------- |
|
314 |
// MsgEditor::setEncodingSettingsL |
|
315 |
// @see header |
|
316 |
//--------------------------------------------------------------- |
|
317 |
void MsgEditorWidget::setEncodingSettingsL() |
|
318 |
{ |
|
319 |
if( mPluginLoader ) |
|
320 |
{ |
|
321 |
delete mPluginLoader; |
|
322 |
} |
|
323 |
mPluginLoader = new UniEditorPluginLoader(this); |
|
324 |
||
325 |
mPluginInterface = |
|
326 |
mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms); |
|
327 |
||
328 |
CSmsSettings* settings = CSmsSettings::NewLC(); |
|
329 |
CSmsAccount* account = CSmsAccount::NewLC(); |
|
330 |
account->LoadSettingsL( *settings ); |
|
331 |
||
332 |
if( settings->CharacterSet() == TSmsDataCodingScheme::ESmsAlphabetUCS2) |
|
333 |
{ |
|
334 |
mCharSupportType = TUniSendingSettings::EUniCharSupportFull; |
|
335 |
} |
|
336 |
else |
|
337 |
{ |
|
338 |
mCharSupportType = TUniSendingSettings::EUniCharSupportReduced; |
|
339 |
} |
|
340 |
||
341 |
CleanupStack::PopAndDestroy( account ); |
|
342 |
CleanupStack::PopAndDestroy( settings ); |
|
343 |
||
344 |
//Set the mPrevBuffer to NULL initially |
|
345 |
mPrevBuffer = QString(); |
|
346 |
||
347 |
mSmsCharLimitReached = false; |
|
348 |
||
349 |
mCharCounter->setVisible(false); |
|
350 |
mBackgroundItem->setVisible(false); |
|
351 |
} |
|
352 |
||
353 |
//--------------------------------------------------------------- |
|
354 |
// MsgEditor::MsgEditor |
|
355 |
// @see header |
|
356 |
//--------------------------------------------------------------- |
|
357 |
MsgEditor::MsgEditor(QGraphicsItem *parent) |
|
358 |
:HbLineEdit(parent) |
|
359 |
{ |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
360 |
this->setPlaceholderText(LOC_HINT_TEXT); |
31 | 361 |
} |
362 |
||
363 |
//--------------------------------------------------------------- |
|
364 |
// MsgEditor::focusInEvent |
|
365 |
// @see header |
|
366 |
//--------------------------------------------------------------- |
|
367 |
void MsgEditor::focusInEvent(QFocusEvent *event) |
|
368 |
{ |
|
369 |
if(event->reason() == Qt::MouseFocusReason) |
|
370 |
{ |
|
371 |
HbLineEdit::focusInEvent(event); |
|
372 |
FOCUSITEM->setFocusProxy(this); |
|
373 |
setCursorVisibility(Hb::TextCursorVisible); |
|
374 |
emit replyStarted(); |
|
375 |
} |
|
376 |
else |
|
377 |
{ |
|
378 |
setCursorVisibility(Hb::TextCursorHidden); |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
//--------------------------------------------------------------- |
|
383 |
// MsgEditor::focusOutEvent |
|
384 |
// @see header |
|
385 |
//--------------------------------------------------------------- |
|
386 |
void MsgEditor::focusOutEvent(QFocusEvent * event) |
|
387 |
{ |
|
388 |
FOCUSITEM->setFocusProxy(0); |
|
389 |
setCursorVisibility(Hb::TextCursorHidden); |
|
390 |
HbLineEdit::focusOutEvent(event); |
|
391 |
} |
|
392 |
||
393 |
//--------------------------------------------------------------- |
|
394 |
// MsgEditor::onSmsCharLimitReached |
|
395 |
// @see header |
|
396 |
//--------------------------------------------------------------- |
|
397 |
void MsgEditorWidget::onSmsCharLimitReached(HbAction* action) |
|
398 |
{ |
|
399 |
HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); |
|
400 |
if (action == dlg->actions().at(0)) { |
|
401 |
||
402 |
//Launch UniEditor |
|
403 |
emit smsCharLimitReached(); |
|
404 |
} |
|
405 |
else { |
|
406 |
//Set the previous content |
|
407 |
setContent( QString(mPrevBuffer)); |
|
408 |
} |
|
409 |
} |
|
410 |
||
411 |
// EOF |