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