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