18 #include "msgeditorwidget.h" |
18 #include "msgeditorwidget.h" |
19 |
19 |
20 // SYSTEM INCLUDES |
20 // SYSTEM INCLUDES |
21 #include <HbStyle> |
21 #include <HbStyle> |
22 #include <HbPushButton> |
22 #include <HbPushButton> |
|
23 #include <HbTextItem> |
23 #include <qgraphicsscene.h> |
24 #include <qgraphicsscene.h> |
|
25 #include <HbFrameDrawer> |
|
26 #include <HbFrameItem> |
|
27 #include <csmsaccount.h> |
|
28 #include <smutset.h> |
|
29 #include <hbmessagebox.h> |
|
30 #include <QTimer> |
|
31 #include "unieditorpluginloader.h" |
|
32 #include "unieditorplugininterface.h" |
|
33 #include "unisendingsettings.h" |
|
34 #include "unieditorgenutils.h" |
24 #include "debugtraces.h" |
35 #include "debugtraces.h" |
25 |
36 |
26 // LOCAL CONSTANTS |
37 // LOCAL CONSTANTS |
27 const QString PLUGINPATH("conversationviewplugin.dll"); |
38 const QString PLUGINPATH("conversationviewplugin.dll"); |
28 |
39 |
29 const QString SMS_SERVICE("messaging.mserver.sms"); |
40 const QString SEND_ICON("qtg_mono_send"); |
30 const QString SEND_BUTTON(QObject::tr("Send")); |
41 const QString BACKGROUND("qtg_fr_input_bg"); |
31 |
42 const QString BACKGROUND_FRAME("qtg_fr_btn_normal"); |
32 const QString SEND_ICON(":/icons/qtg_mono_send.png"); |
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; |
33 |
53 |
34 QGraphicsItem* FOCUSITEM = 0; |
54 QGraphicsItem* FOCUSITEM = 0; |
35 |
55 |
36 //--------------------------------------------------------------- |
56 //--------------------------------------------------------------- |
37 // MsgEditorWidget::MsgEditorWidget |
57 // MsgEditorWidget::MsgEditorWidget |
38 // @see header |
58 // @see header |
39 //--------------------------------------------------------------- |
59 //--------------------------------------------------------------- |
40 MsgEditorWidget::MsgEditorWidget(QGraphicsItem *parent) : |
60 MsgEditorWidget::MsgEditorWidget(QGraphicsItem *parent) : |
41 HbWidget(parent), mServiceId(SMS_SERVICE), mMsgEditor(NULL), |
61 HbWidget(parent), mMsgEditor(NULL), |
42 mSendButton(NULL) |
62 mSendButton(NULL),mPluginLoader(NULL) |
43 { |
63 { |
44 int baseId = style()->registerPlugin(PLUGINPATH); |
64 int baseId = style()->registerPlugin(PLUGINPATH); |
45 |
65 |
46 #ifdef _DEBUG_TRACES_ |
66 #ifdef _DEBUG_TRACES_ |
47 qDebug() << "MsgEditorWidget BASE ID --->" << baseId; |
67 qDebug() << "MsgEditorWidget BASE ID --->" << baseId; |
48 #endif |
68 #endif |
49 |
69 |
50 setPluginBaseId(baseId); |
70 setPluginBaseId(baseId); |
|
71 |
|
72 //setting background. |
|
73 HbFrameItem* backGround = new HbFrameItem(this); |
|
74 backGround->frameDrawer().setFrameGraphicsName(BACKGROUND); |
|
75 backGround->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesVertical); |
|
76 backGround->frameDrawer().setFillWholeRect(true); |
|
77 this->setBackgroundItem(backGround); |
51 |
78 |
52 // Initialize the widget. |
79 // Initialize the widget. |
53 init(); |
80 init(); |
54 } |
81 } |
55 |
82 |
59 //--------------------------------------------------------------- |
86 //--------------------------------------------------------------- |
60 void MsgEditorWidget::init() |
87 void MsgEditorWidget::init() |
61 { |
88 { |
62 // Create mandatory element of mesh layout. |
89 // Create mandatory element of mesh layout. |
63 mMsgEditor = new MsgEditor(this); |
90 mMsgEditor = new MsgEditor(this); |
64 mMsgEditor->setMaxRows(5); // NOTE: Don't remove this line. |
91 mMsgEditor->setMaxRows(3); // NOTE: Don't remove this line. |
65 HbStyle::setItemName(mMsgEditor, "msgEditor"); |
92 HbStyle::setItemName(mMsgEditor, "msgEditor"); |
66 |
93 |
67 mSendButton = new HbPushButton(this); |
94 mSendButton = new HbPushButton(this); |
68 HbStyle::setItemName(mSendButton, "sendButton"); |
95 HbStyle::setItemName(mSendButton, "sendButton"); |
69 mSendButton->setIcon(HbIcon(SEND_ICON)); |
96 mSendButton->setIcon(HbIcon(SEND_ICON)); |
70 mSendButton->setEnabled(false); |
97 mSendButton->setEnabled(false); |
|
98 HbFrameDrawer* drawer = new HbFrameDrawer(this); |
|
99 drawer->setFrameType(HbFrameDrawer::NinePieces); |
|
100 mSendButton->setFrameBackground(drawer); |
|
101 updateButtonBackground(SEND_BUTTON_DISABLED); |
|
102 |
|
103 mCharCounter = new HbTextItem(this); |
|
104 HbStyle::setItemName(mCharCounter, "charCounter"); |
|
105 mCharCounter->setZValue(1.5); |
|
106 |
|
107 mBackgroundItem = new HbFrameItem(this); |
|
108 HbStyle::setItemName(mBackgroundItem, "charCounterFrame"); |
|
109 |
|
110 mBackgroundItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
111 mBackgroundItem->frameDrawer().setFillWholeRect(true); |
|
112 |
|
113 mBackgroundItem->frameDrawer().setFrameGraphicsName( |
|
114 BACKGROUND_FRAME); |
|
115 |
|
116 //Create editor utils object |
|
117 mEditorUtils = new UniEditorGenUtils(); |
|
118 |
71 FOCUSITEM = mSendButton; |
119 FOCUSITEM = mSendButton; |
72 |
120 |
|
121 |
73 connect(mSendButton, SIGNAL(clicked()),this, SLOT(onClicked())); |
122 connect(mSendButton, SIGNAL(clicked()),this, SLOT(onClicked())); |
|
123 connect(mSendButton, SIGNAL(pressed()),this, SLOT(onPressed())); |
|
124 connect(mSendButton, SIGNAL(released()),this, SLOT(onReleased())); |
74 connect(mMsgEditor, SIGNAL(replyStarted()),this, SIGNAL(replyStarted())); |
125 connect(mMsgEditor, SIGNAL(replyStarted()),this, SIGNAL(replyStarted())); |
75 connect(mMsgEditor, SIGNAL(textChanged(QString)),this,SLOT(onTextChanged(QString))); |
126 connect(mMsgEditor, SIGNAL(textChanged(QString)),this,SLOT(onTextChanged(QString))); |
76 |
127 |
77 } |
128 } |
78 |
129 |
121 mMsgEditor->setText(QString()); |
164 mMsgEditor->setText(QString()); |
122 mMsgEditor->setCursorVisibility(Hb::TextCursorHidden); |
165 mMsgEditor->setCursorVisibility(Hb::TextCursorHidden); |
123 } |
166 } |
124 |
167 |
125 //--------------------------------------------------------------- |
168 //--------------------------------------------------------------- |
126 // MsgEditorWidget::clear |
169 // MsgEditorWidget::onTextChanged |
127 // @see header |
170 // @see header |
128 //--------------------------------------------------------------- |
171 //--------------------------------------------------------------- |
129 void MsgEditorWidget::onTextChanged(const QString& str) |
172 void MsgEditorWidget::onTextChanged(const QString& str) |
130 { |
173 { |
|
174 //If char limit is already reached we are about to show the sms limit dialog |
|
175 //So we need not process the additional character entered |
|
176 if(mSmsCharLimitReached) |
|
177 { |
|
178 return; |
|
179 } |
131 if(str.length() > 0 ) |
180 if(str.length() > 0 ) |
132 { |
181 { |
133 if(!mSendButton->isEnabled()) |
182 if(!mSendButton->isEnabled()) |
134 { |
183 { |
135 mSendButton->setFocusProxy(mMsgEditor); |
184 mSendButton->setFocusProxy(mMsgEditor); |
136 mSendButton->setEnabled(true); |
185 mSendButton->setEnabled(true); |
|
186 updateButtonBackground(SEND_BUTTON_NORMAL); |
137 } |
187 } |
138 } |
188 } |
139 else |
189 else |
140 { |
190 { |
141 if(mSendButton->isEnabled()) |
191 if(mSendButton->isEnabled()) |
142 { |
192 { |
143 mSendButton->setFocusProxy(0); |
193 mSendButton->setFocusProxy(0); |
144 mSendButton->setEnabled(false); |
194 mSendButton->setEnabled(false); |
|
195 updateButtonBackground(SEND_BUTTON_DISABLED); |
145 } |
196 } |
146 } |
197 } |
|
198 |
|
199 //Check done for optimization |
|
200 //Only if content is deleted we need to call encodingsettings again |
|
201 if(mPrevBuffer.isEmpty() || str.size() <= mPrevBuffer.size()) |
|
202 { |
|
203 mPluginInterface->setEncodingSettings(EFalse,ESmsEncodingNone,mCharSupportType); |
|
204 } |
|
205 |
|
206 TInt numOfRemainingChars; |
|
207 TInt numOfPDUs; |
|
208 TBool unicodeMode; |
|
209 TSmsEncoding alternativeEncodingType; |
|
210 QString string = str; |
|
211 mPluginInterface->getNumPDUs(string, numOfRemainingChars, numOfPDUs, |
|
212 unicodeMode, alternativeEncodingType); |
|
213 |
|
214 //Set char counter value |
|
215 QString display = QString("%1(%2)").arg(numOfRemainingChars).arg(numOfPDUs); |
|
216 mCharCounter->setText(display); |
|
217 |
|
218 if(numOfPDUs > 1 || numOfRemainingChars <= KShowCounterLimit ) |
|
219 { |
|
220 mCharCounter->setVisible(true); |
|
221 mBackgroundItem->setVisible(true); |
|
222 } |
|
223 else |
|
224 { |
|
225 mCharCounter->setVisible(false); |
|
226 mBackgroundItem->setVisible(false); |
|
227 } |
|
228 |
|
229 //Check if sms segment limit has been reached |
|
230 bool unicode = (unicodeMode) ? true : false; |
|
231 int contentSize = mEditorUtils->UTF8Size(string); |
|
232 int maxSmsSize = mEditorUtils->MaxSmsMsgSizeL(unicode); |
|
233 |
|
234 if(contentSize > maxSmsSize) |
|
235 { |
|
236 //Give breathing time for ITUT to complete its processing |
|
237 //without this there is a crash as ITUT cant complete its processing |
|
238 mSmsCharLimitReached = true; |
|
239 QTimer::singleShot(50, this, SLOT(handleSmsCharLimitReached())); |
|
240 if(mPrevBuffer.isEmpty()) |
|
241 { |
|
242 //Chop the last char and set it to the editor |
|
243 string.chop(1); |
|
244 mPrevBuffer = string; |
|
245 } |
|
246 } |
|
247 else |
|
248 { |
|
249 //Save the previous buffer |
|
250 mPrevBuffer = string; |
|
251 } |
|
252 } |
|
253 |
|
254 //--------------------------------------------------------------- |
|
255 // MsgEditorWidget::handleSmsCharLimitReached |
|
256 // @see header |
|
257 //--------------------------------------------------------------- |
|
258 void MsgEditorWidget::handleSmsCharLimitReached() |
|
259 { |
|
260 mSmsCharLimitReached = false; |
|
261 |
|
262 if(HbMessageBox::question(LOC_SMS_CHAR_LIMIT_REACHED, |
|
263 LOC_DIALOG_OK, |
|
264 LOC_BUTTON_CANCEL)) |
|
265 { |
|
266 //Launch UniEditor |
|
267 emit smsCharLimitReached(); |
|
268 return; |
|
269 } |
|
270 else |
|
271 { |
|
272 //Set the previous content |
|
273 setContent(QString(mPrevBuffer)); |
|
274 return; |
|
275 } |
|
276 |
147 } |
277 } |
148 |
278 |
149 //--------------------------------------------------------------- |
279 //--------------------------------------------------------------- |
150 // MsgEditor::onClicked |
280 // MsgEditor::onClicked |
151 // @see header |
281 // @see header |
163 mMsgEditor->setCursorVisibility(Hb::TextCursorHidden); |
293 mMsgEditor->setCursorVisibility(Hb::TextCursorHidden); |
164 |
294 |
165 emit sendMessage(); |
295 emit sendMessage(); |
166 } |
296 } |
167 |
297 |
|
298 //--------------------------------------------------------------- |
|
299 // MsgEditor::updateButtonBackground |
|
300 // @see header |
|
301 //--------------------------------------------------------------- |
|
302 void MsgEditorWidget::updateButtonBackground(const QString& bg) |
|
303 { |
|
304 HbFrameDrawer* drawer = mSendButton->frameBackground(); |
|
305 if(drawer) |
|
306 { |
|
307 drawer->setFrameGraphicsName(bg); |
|
308 } |
|
309 } |
|
310 |
|
311 //--------------------------------------------------------------- |
|
312 // MsgEditor::onPressed |
|
313 // @see header |
|
314 //--------------------------------------------------------------- |
|
315 void MsgEditorWidget::onPressed() |
|
316 { |
|
317 updateButtonBackground(SEND_BUTTON_PRESSED); |
|
318 } |
|
319 |
|
320 //--------------------------------------------------------------- |
|
321 // MsgEditor::onReleased |
|
322 // @see header |
|
323 //--------------------------------------------------------------- |
|
324 void MsgEditorWidget::onReleased() |
|
325 { |
|
326 updateButtonBackground(SEND_BUTTON_NORMAL); |
|
327 } |
|
328 |
|
329 //--------------------------------------------------------------- |
|
330 // MsgEditor::setEncodingSettings |
|
331 // @see header |
|
332 //--------------------------------------------------------------- |
|
333 void MsgEditorWidget::setEncodingSettings() |
|
334 { |
|
335 if( mPluginLoader ) |
|
336 { |
|
337 delete mPluginLoader; |
|
338 } |
|
339 mPluginLoader = new UniEditorPluginLoader(this); |
|
340 |
|
341 mPluginInterface = |
|
342 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms); |
|
343 |
|
344 CSmsSettings* settings = CSmsSettings::NewLC(); |
|
345 CSmsAccount* account = CSmsAccount::NewLC(); |
|
346 account->LoadSettingsL( *settings ); |
|
347 |
|
348 if( settings->CharacterSet() == TSmsDataCodingScheme::ESmsAlphabetUCS2) |
|
349 { |
|
350 mCharSupportType = TUniSendingSettings::EUniCharSupportFull; |
|
351 } |
|
352 else |
|
353 { |
|
354 mCharSupportType = TUniSendingSettings::EUniCharSupportReduced; |
|
355 } |
|
356 |
|
357 CleanupStack::PopAndDestroy( account ); |
|
358 CleanupStack::PopAndDestroy( settings ); |
|
359 |
|
360 //Set the mPrevBuffer to NULL initially |
|
361 mPrevBuffer = QString(); |
|
362 |
|
363 mSmsCharLimitReached = false; |
|
364 |
|
365 mCharCounter->setVisible(false); |
|
366 mBackgroundItem->setVisible(false); |
|
367 } |
168 |
368 |
169 //--------------------------------------------------------------- |
369 //--------------------------------------------------------------- |
170 // MsgEditor::MsgEditor |
370 // MsgEditor::MsgEditor |
171 // @see header |
371 // @see header |
172 //--------------------------------------------------------------- |
372 //--------------------------------------------------------------- |