|
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 "msgunieditorbodyeditor.h" |
|
19 |
|
20 // SYSTEM INCLUDES |
|
21 #include <HbStyle> |
|
22 #include <HbPushButton> |
|
23 #include <HbTextItem> |
|
24 #include <HbFrameDrawer> |
|
25 #include <HbFrameItem> |
|
26 #include <csmsaccount.h> |
|
27 #include <smutset.h> |
|
28 #include <hbmessagebox.h> |
|
29 #include <hbcolorscheme.h> |
|
30 #include <QColor> |
|
31 |
|
32 #include "unieditorpluginloader.h" |
|
33 #include "unieditorplugininterface.h" |
|
34 #include "UniSendingSettings.h" |
|
35 #include "UniEditorGenUtils.h" |
|
36 #include "msgunieditormonitor.h" |
|
37 #include "debugtraces.h" |
|
38 |
|
39 // LOCAL CONSTANTS |
|
40 |
|
41 const QString SEND_ICON("qtg_mono_send"); |
|
42 const QString BACKGROUND("qtg_fr_input_v_bg"); |
|
43 const QString BACKGROUND_FRAME("qtg_fr_messaging_char_count"); |
|
44 const QString CHAR_COUNTER_COLOR("qtc_messaging_char_count"); |
|
45 |
|
46 const QString SEND_BUTTON_NORMAL("qtg_fr_btn_green_normal"); |
|
47 const QString SEND_BUTTON_PRESSED("qtg_fr_btn_green_pressed"); |
|
48 const QString SEND_BUTTON_DISABLED("qtg_fr_btn_disabled"); |
|
49 |
|
50 const QString SEND_BUTTON_NORMAL_COLOR("qtc_callhandling_answer_normal"); |
|
51 const QString SEND_BUTTON_PRESSED_COLOR("qtc_callhandling_answer_pressed"); |
|
52 const QString SEND_BUTTON_DISABLED_COLOR("qtc_button_disabled"); |
|
53 |
|
54 #define LOC_SMS_CHAR_LIMIT_REACHED hbTrId("txt_messaging_dialog_sms_character_count_exceeded") |
|
55 #define LOC_HINT_TEXT hbTrId("txt_messaging_formlabel_enter_message_here") |
|
56 #define LOC_UNABLE_TO_ADD_CONTENT hbTrId("txt_messaging_dpopinfo_unable_to_add_more_content") |
|
57 |
|
58 |
|
59 const TInt KShowCounterLimit = 10; |
|
60 |
|
61 |
|
62 //--------------------------------------------------------------- |
|
63 // MsgUnifiedEditorBodyEditor::MsgUnifiedEditorBodyEditor |
|
64 // @see header |
|
65 //--------------------------------------------------------------- |
|
66 MsgUnifiedEditorBodyEditor::MsgUnifiedEditorBodyEditor(QGraphicsItem *parent) : |
|
67 MsgUnifiedEditorBaseWidget(parent), |
|
68 mMsgEditor(NULL), |
|
69 mSendButton(NULL), |
|
70 mPluginLoader(NULL) |
|
71 { |
|
72 this->setObjectName("bodyText"); |
|
73 |
|
74 setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed); |
|
75 |
|
76 //setting background. |
|
77 HbFrameItem* backGround = new HbFrameItem(this); |
|
78 backGround->frameDrawer().setFrameGraphicsName(BACKGROUND); |
|
79 backGround->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesVertical); |
|
80 backGround->frameDrawer().setFillWholeRect(true); |
|
81 //fixing to 2 pixel to avoid extra line on top of frame. |
|
82 backGround->frameDrawer().setBorderWidth(2); |
|
83 this->setBackgroundItem(backGround); |
|
84 |
|
85 // Initialize the widget. |
|
86 init(); |
|
87 |
|
88 setEncodingSettingsL(); |
|
89 } |
|
90 |
|
91 //--------------------------------------------------------------- |
|
92 // MsgUnifiedEditorBodyEditor::init |
|
93 // @see header |
|
94 //--------------------------------------------------------------- |
|
95 void MsgUnifiedEditorBodyEditor::init() |
|
96 { |
|
97 // Create mandatory element of mesh layout. |
|
98 mMsgEditor = new MsgEditor(this); |
|
99 HbStyle::setItemName(mMsgEditor, "msgEditor"); |
|
100 |
|
101 mSendButton = new HbPushButton(this); |
|
102 HbStyle::setItemName(mSendButton, "sendButton"); |
|
103 mSendButton->setEnabled(false); |
|
104 |
|
105 HbFrameItem* backGround = new HbFrameItem(this); |
|
106 backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
107 mSendButton->setBackgroundItem(backGround); |
|
108 updateButtonBackgroundAndColor(SEND_BUTTON_DISABLED,SEND_BUTTON_DISABLED_COLOR); |
|
109 mSendButton->setIcon(HbIcon(SEND_ICON)); |
|
110 |
|
111 mCharCounter = new HbTextItem(this); |
|
112 HbStyle::setItemName(mCharCounter, "charCounter"); |
|
113 mCharCounter->setZValue(1.5); |
|
114 |
|
115 QColor color = HbColorScheme::color(CHAR_COUNTER_COLOR); |
|
116 mCharCounter->setTextColor(color); |
|
117 |
|
118 mBackgroundItem = new HbFrameItem(this); |
|
119 HbStyle::setItemName(mBackgroundItem, "charCounterFrame"); |
|
120 |
|
121 mBackgroundItem->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal); |
|
122 mBackgroundItem->frameDrawer().setFillWholeRect(true); |
|
123 |
|
124 mBackgroundItem->frameDrawer().setFrameGraphicsName(BACKGROUND_FRAME); |
|
125 |
|
126 //Create editor utils object |
|
127 mEditorUtils = q_check_ptr(new UniEditorGenUtils()); |
|
128 |
|
129 connect(mSendButton, SIGNAL(clicked()),this, SIGNAL(sendMessage())); |
|
130 connect(mSendButton, SIGNAL(pressed()),this, SLOT(onPressed())); |
|
131 connect(mSendButton, SIGNAL(released()),this, SLOT(onReleased())); |
|
132 connect(mMsgEditor, SIGNAL(contentsChanged()),this,SLOT(onContentsChanged())); |
|
133 |
|
134 } |
|
135 |
|
136 //--------------------------------------------------------------- |
|
137 // MsgUnifiedEditorBodyEditor::~MsgUnifiedEditorBodyEditor |
|
138 // @see header |
|
139 //--------------------------------------------------------------- |
|
140 MsgUnifiedEditorBodyEditor::~MsgUnifiedEditorBodyEditor() |
|
141 { |
|
142 delete mEditorUtils; |
|
143 } |
|
144 |
|
145 //--------------------------------------------------------------- |
|
146 // MsgUnifiedEditorBodyEditor::content |
|
147 // @see header |
|
148 //--------------------------------------------------------------- |
|
149 QString MsgUnifiedEditorBodyEditor::content() const |
|
150 { |
|
151 return mMsgEditor->toPlainText(); |
|
152 } |
|
153 |
|
154 //--------------------------------------------------------------- |
|
155 // MsgUnifiedEditorBodyEditor::setContent |
|
156 // @see header |
|
157 //--------------------------------------------------------------- |
|
158 void MsgUnifiedEditorBodyEditor::setContent(const QString &text) |
|
159 { |
|
160 mMsgEditor->setPlainText(text); |
|
161 } |
|
162 |
|
163 //--------------------------------------------------------------- |
|
164 // MsgUnifiedEditorBodyEditor::enableSendButton |
|
165 // @see header |
|
166 //--------------------------------------------------------------- |
|
167 void MsgUnifiedEditorBodyEditor::enableSendButton(bool enable) |
|
168 { |
|
169 if(enable) |
|
170 { |
|
171 if(!mSendButton->isEnabled()) |
|
172 { |
|
173 mSendButton->setFocusProxy(mMsgEditor); |
|
174 mSendButton->setEnabled(true); |
|
175 updateButtonBackgroundAndColor(SEND_BUTTON_NORMAL,SEND_BUTTON_NORMAL_COLOR); |
|
176 } |
|
177 } |
|
178 else |
|
179 { |
|
180 if(mSendButton->isEnabled()) |
|
181 { |
|
182 mSendButton->setFocusProxy(0); |
|
183 mSendButton->setEnabled(false); |
|
184 updateButtonBackgroundAndColor(SEND_BUTTON_DISABLED,SEND_BUTTON_DISABLED_COLOR); |
|
185 } |
|
186 } |
|
187 } |
|
188 |
|
189 //--------------------------------------------------------------- |
|
190 // MsgUnifiedEditorBodyEditor::onContentsChanged |
|
191 // @see header |
|
192 //--------------------------------------------------------------- |
|
193 void MsgUnifiedEditorBodyEditor::onContentsChanged() |
|
194 { |
|
195 QString text = this->content(); |
|
196 |
|
197 mPluginInterface->setEncodingSettings(EFalse, ESmsEncodingNone,mCharSupportType); |
|
198 |
|
199 TInt numOfRemainingChars; |
|
200 TInt numOfPDUs; |
|
201 TBool unicodeMode; |
|
202 TSmsEncoding alternativeEncodingType; |
|
203 mPluginInterface->getNumPDUs(text, numOfRemainingChars, numOfPDUs, |
|
204 unicodeMode, alternativeEncodingType); |
|
205 |
|
206 // emit signal to indicate change in content |
|
207 int contentSize = mEditorUtils->UTF8Size(text); |
|
208 QVariantList dataList; |
|
209 dataList << contentSize << unicodeMode; |
|
210 emit contentsChanged(dataList); |
|
211 |
|
212 if(MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Sms) |
|
213 { |
|
214 //Set char counter value |
|
215 QString display = QString("%1(%2)").arg(numOfRemainingChars).arg( |
|
216 numOfPDUs); |
|
217 mCharCounter->setText(display); |
|
218 |
|
219 if (numOfPDUs > 1 || numOfRemainingChars <= KShowCounterLimit) |
|
220 { |
|
221 mCharCounter->setVisible(true); |
|
222 mBackgroundItem->setVisible(true); |
|
223 } |
|
224 else |
|
225 { |
|
226 mCharCounter->setVisible(false); |
|
227 mBackgroundItem->setVisible(false); |
|
228 } |
|
229 } |
|
230 } |
|
231 |
|
232 //--------------------------------------------------------------- |
|
233 // MsgUnifiedEditorBodyEditor::updateButtonBackgroundAndColor |
|
234 // @see header |
|
235 //--------------------------------------------------------------- |
|
236 void MsgUnifiedEditorBodyEditor::updateButtonBackgroundAndColor(const QString& bg,const QString& iconColor) |
|
237 { |
|
238 HbFrameItem* drawer = static_cast<HbFrameItem*>(mSendButton->backgroundItem()); |
|
239 if(drawer) |
|
240 { |
|
241 drawer->frameDrawer().setFrameGraphicsName(bg); |
|
242 } |
|
243 QColor color = HbColorScheme::color(iconColor); |
|
244 |
|
245 if(color.isValid()) |
|
246 { |
|
247 mSendButton->icon().setColor(color); |
|
248 } |
|
249 } |
|
250 |
|
251 //--------------------------------------------------------------- |
|
252 // MsgUnifiedEditorBodyEditor::onPressed |
|
253 // @see header |
|
254 //--------------------------------------------------------------- |
|
255 void MsgUnifiedEditorBodyEditor::onPressed() |
|
256 { |
|
257 updateButtonBackgroundAndColor(SEND_BUTTON_PRESSED,SEND_BUTTON_PRESSED_COLOR); |
|
258 } |
|
259 |
|
260 //--------------------------------------------------------------- |
|
261 // MsgUnifiedEditorBodyEditor::onReleased |
|
262 // @see header |
|
263 //--------------------------------------------------------------- |
|
264 void MsgUnifiedEditorBodyEditor::onReleased() |
|
265 { |
|
266 updateButtonBackgroundAndColor(SEND_BUTTON_NORMAL,SEND_BUTTON_NORMAL_COLOR); |
|
267 } |
|
268 |
|
269 //--------------------------------------------------------------- |
|
270 // MsgUnifiedEditorBodyEditor::setEncodingSettingsL |
|
271 // @see header |
|
272 //--------------------------------------------------------------- |
|
273 void MsgUnifiedEditorBodyEditor::setEncodingSettingsL() |
|
274 { |
|
275 mPluginLoader = new UniEditorPluginLoader(this); |
|
276 |
|
277 mPluginInterface = |
|
278 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms); |
|
279 |
|
280 QT_TRAP_THROWING( CSmsSettings* settings = CSmsSettings::NewLC(); |
|
281 CSmsAccount* account = CSmsAccount::NewLC(); |
|
282 account->LoadSettingsL( *settings ); |
|
283 |
|
284 if( settings->CharacterSet() == TSmsDataCodingScheme::ESmsAlphabetUCS2) |
|
285 { |
|
286 mCharSupportType = TUniSendingSettings::EUniCharSupportFull; |
|
287 } |
|
288 else |
|
289 { |
|
290 mCharSupportType = TUniSendingSettings::EUniCharSupportReduced; |
|
291 } |
|
292 |
|
293 CleanupStack::PopAndDestroy( account ); |
|
294 CleanupStack::PopAndDestroy( settings )); |
|
295 |
|
296 |
|
297 mCharCounter->setVisible(false); |
|
298 mBackgroundItem->setVisible(false); |
|
299 } |
|
300 |
|
301 //--------------------------------------------------------------- |
|
302 // MsgUnifiedEditorBodyEditor::packMessage |
|
303 // @see header |
|
304 //--------------------------------------------------------------- |
|
305 void MsgUnifiedEditorBodyEditor::packMessage(ConvergedMessage &msg) |
|
306 { |
|
307 msg.setBodyText(mMsgEditor->toPlainText()); |
|
308 } |
|
309 |
|
310 //--------------------------------------------------------------- |
|
311 // MsgUnifiedEditorBodyEditor::populateContent |
|
312 // @see header |
|
313 //--------------------------------------------------------------- |
|
314 void MsgUnifiedEditorBodyEditor::populateContent(const ConvergedMessage& msg) |
|
315 { |
|
316 QString bodyTxt = msg.bodyText(); |
|
317 mMsgEditor->setPlainText(msg.bodyText()); |
|
318 } |
|
319 |
|
320 //--------------------------------------------------------------- |
|
321 // MsgEditor::MsgEditor |
|
322 // @see header |
|
323 //--------------------------------------------------------------- |
|
324 MsgEditor::MsgEditor(QGraphicsItem *parent) : |
|
325 HbTextEdit(parent) |
|
326 { |
|
327 this->setFontSpec(HbFontSpec(HbFontSpec::Secondary)); |
|
328 this->setPlaceholderText(LOC_HINT_TEXT); |
|
329 this->setSmileysEnabled(true); |
|
330 } |
|
331 |
|
332 //--------------------------------------------------------------- |
|
333 // MsgEditor::inputMethodEvent |
|
334 // @see header |
|
335 //--------------------------------------------------------------- |
|
336 void MsgEditor::inputMethodEvent(QInputMethodEvent *event) |
|
337 { |
|
338 bool showNote = false; |
|
339 |
|
340 if( MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Mms && |
|
341 !event->commitString().isEmpty()) |
|
342 { |
|
343 QString str = event->commitString(); |
|
344 int comitStrSize = str.toUtf8().size(); |
|
345 |
|
346 if(MsgUnifiedEditorMonitor::messageSize()+ comitStrSize > MsgUnifiedEditorMonitor::maxMmsSize()) |
|
347 { |
|
348 showNote = true; |
|
349 // reject any text input if mms size limit is reached |
|
350 event->setCommitString(QString()); |
|
351 } |
|
352 } |
|
353 |
|
354 HbTextEdit::inputMethodEvent(event); |
|
355 |
|
356 if(showNote) |
|
357 { |
|
358 HbMessageBox* mb = new HbMessageBox(LOC_UNABLE_TO_ADD_CONTENT,HbMessageBox::MessageTypeInformation); |
|
359 mb->setStandardButtons(HbMessageBox::Ok); |
|
360 mb->setAttribute(Qt::WA_DeleteOnClose); |
|
361 mb->setFocusPolicy(Qt::NoFocus); |
|
362 mb->show(); |
|
363 } |
|
364 } |
|
365 |
|
366 // EOF |