|
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 // INCLUDES |
|
19 #include <HbTextEdit> |
|
20 #include <HbTextItem> |
|
21 #include <HbFrameItem> |
|
22 #include <HbFrameDrawer> |
|
23 #include <HbIconItem> |
|
24 #include <HbPushButton> |
|
25 #include <HbAction> |
|
26 #include <hbinputeditorinterface.h> |
|
27 //#include <HbGestureSceneFilter> |
|
28 //#include <HbGesture> |
|
29 #include <HbMenu> |
|
30 #include <HbMainWindow> |
|
31 #include <HbDeviceProfile> |
|
32 #include <QImageReader> |
|
33 #include <QFileInfo> |
|
34 #include <MsgMediaResolver.h> |
|
35 #include <MsgImageInfo.h> |
|
36 #include <HbIconAnimationManager> |
|
37 #include <HbIconAnimator> |
|
38 #include <HbIcon> |
|
39 #include <QGraphicsLinearLayout> |
|
40 #include <HbNotificationDialog> |
|
41 |
|
42 #include <csmsaccount.h> |
|
43 #include <smutset.h> |
|
44 #include <xqaiwrequest.h> |
|
45 #include <xqrequestinfo.h> |
|
46 #include <xqsharablefile.h> |
|
47 #include <xqappmgr.h> |
|
48 |
|
49 // USER INCLUDES |
|
50 #include "msgunieditorbody.h" |
|
51 #include "UniEditorGenUtils.h" |
|
52 #include "unisendingsettings.h" |
|
53 #include "msgmonitor.h" |
|
54 #include "s60qconversions.h" |
|
55 #include "mmsconformancecheck.h" |
|
56 #include "unieditorpluginloader.h" |
|
57 #include "unieditorplugininterface.h" |
|
58 #include "convergedmessage.h" |
|
59 #include "msgmediautil.h" |
|
60 |
|
61 // Constants |
|
62 const QString EDITOR_FRAME("qtg_fr_lineedit_normal"); |
|
63 const QString BACKGROUND_FRAME("qtg_fr_btn_normal"); |
|
64 const QString AUDIO_REGION("AudioRegion"); |
|
65 const QString VIDEO_REGION("VideoRegion"); |
|
66 const QString IMAGE_REGION("ImageRegion"); |
|
67 const QString INVALID_REGION("InvalidRegion"); |
|
68 const QString SEND_ICON("qtg_mono_send"); |
|
69 const int KShowCounterLimit = 10; |
|
70 const int BYTES_TO_KBYTES_FACTOR = 1024; |
|
71 |
|
72 //Localized Constants for item specific menu |
|
73 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
74 #define LOC_REMOVE hbTrId("txt_common_menu_remove") |
|
75 #define LOC_DETAILS hbTrId("txt_common_menu_details") |
|
76 #define LOC_TITLE hbTrId("txt_messaging_title_messaging") |
|
77 #define LOC_UNABLE_TO_ADD_CONTENT hbTrId("txt_messaging_dpopinfo_unable_to_add_more_content") |
|
78 #define LOC_UNABLE_TO_ATTACH_ITEM hbTrId("txt_messaging_dpopinfo_unable_to_attach_item_avai") |
|
79 #define LOC_PROCESSING hbTrId("txt_messaging_formlabel_loading") |
|
80 |
|
81 const QString AUDIO_ICON("qtg_mono_audio"); |
|
82 const QString ANIMATION_ICON("qtg_anim_loading"); |
|
83 const QString ANIMATION_FILE(":/qtg_anim_loading.axml"); |
|
84 // LOCAL FUNCTIONS |
|
85 |
|
86 //--------------------------------------------------------------- |
|
87 // showInsertFailureNote |
|
88 // @return fullPath of unified editor's temporary dir |
|
89 //--------------------------------------------------------------- |
|
90 void showInsertFailureNote() |
|
91 { |
|
92 int availableSize = |
|
93 (MsgMonitor::maxMmsSize() - MsgMonitor::messageSize()) |
|
94 /BYTES_TO_KBYTES_FACTOR; |
|
95 QString displayStr = QString(LOC_UNABLE_TO_ATTACH_ITEM) |
|
96 .arg(availableSize); |
|
97 HbNotificationDialog* dlg = new HbNotificationDialog(); |
|
98 dlg->setFocusPolicy(Qt::NoFocus); |
|
99 dlg->setDismissPolicy(HbPopup::TapAnywhere); |
|
100 dlg->setAttribute(Qt::WA_DeleteOnClose, true); |
|
101 dlg->setText(displayStr); |
|
102 dlg->show(); |
|
103 } |
|
104 |
|
105 |
|
106 MsgUnifiedEditorBody::MsgUnifiedEditorBody( QGraphicsItem *parent ) : |
|
107 MsgUnifiedEditorBaseWidget(parent), |
|
108 mHasImage(false), |
|
109 mHasAudio(false), |
|
110 mTextEdit(0), |
|
111 mEditorFrame(0), |
|
112 mIconItem(0), |
|
113 mAudioItem(0), |
|
114 mImageSize(0), |
|
115 mAudioSize(0), |
|
116 mVideoSize(0), |
|
117 mProcessImageOperation(0), |
|
118 mMediaResolver(0), |
|
119 mImageInfo(0), |
|
120 mProcessingWidget(0) |
|
121 { |
|
122 mTextEdit = new HbTextEdit(this); |
|
123 HbStyle::setItemName(mTextEdit,"textEdit"); |
|
124 |
|
125 HbFrameDrawer* frameDrawer = new HbFrameDrawer(EDITOR_FRAME, |
|
126 HbFrameDrawer::NinePieces); |
|
127 |
|
128 mEditorFrame = new HbFrameItem(frameDrawer,this); |
|
129 HbStyle::setItemName(mEditorFrame,"textEditFrame"); |
|
130 mEditorFrame->setZValue(-1); |
|
131 |
|
132 // add "Send" action in VKB |
|
133 HbEditorInterface editorInterface(mTextEdit); |
|
134 HbAction *sendAction = new HbAction(HbIcon(SEND_ICON), QString(),this); |
|
135 connect(sendAction, SIGNAL(triggered()),this, SIGNAL(sendMessage())); |
|
136 editorInterface.addAction(sendAction); |
|
137 |
|
138 /* mGestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this); |
|
139 mGestureFilter->setLongpressAnimation(true); |
|
140 HbGesture *gesture = new HbGesture(HbGesture::longpress, 5); |
|
141 mGestureFilter->addGesture(gesture); |
|
142 connect(gesture, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF)));*/ |
|
143 connect(mTextEdit, SIGNAL(contentsChanged()), this, SLOT(onTextChanged())); |
|
144 |
|
145 mMmsConformanceCheck = new MmsConformanceCheck; |
|
146 |
|
147 mCharCounter = new HbTextItem(this); |
|
148 HbStyle::setItemName(mCharCounter, "charCounter"); |
|
149 mCharCounter->setZValue(1.5); |
|
150 mCharCounter->setText("160(1)"); |
|
151 |
|
152 mBackgroundItem = new HbFrameItem(this); |
|
153 HbStyle::setItemName(mBackgroundItem, "charCounterFrame"); |
|
154 |
|
155 mBackgroundItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
156 mBackgroundItem->frameDrawer().setFillWholeRect(true); |
|
157 |
|
158 mBackgroundItem->frameDrawer().setFrameGraphicsName( |
|
159 BACKGROUND_FRAME); |
|
160 |
|
161 mPluginLoader = new UniEditorPluginLoader(this); |
|
162 |
|
163 mPluginInterface = |
|
164 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms); |
|
165 |
|
166 TRAP_IGNORE( |
|
167 CSmsSettings* settings = CSmsSettings::NewLC(); |
|
168 CSmsAccount* account = CSmsAccount::NewLC(); |
|
169 account->LoadSettingsL( *settings ); |
|
170 |
|
171 if( settings->CharacterSet() == TSmsDataCodingScheme::ESmsAlphabetUCS2) |
|
172 { |
|
173 mCharSupportType = TUniSendingSettings::EUniCharSupportFull; |
|
174 } |
|
175 else |
|
176 { |
|
177 mCharSupportType = TUniSendingSettings::EUniCharSupportReduced; |
|
178 } |
|
179 |
|
180 CleanupStack::PopAndDestroy( account ); |
|
181 CleanupStack::PopAndDestroy( settings ); |
|
182 ); |
|
183 |
|
184 mCharCounter->setVisible(false); |
|
185 mBackgroundItem->setVisible(false); |
|
186 } |
|
187 |
|
188 MsgUnifiedEditorBody::~MsgUnifiedEditorBody() |
|
189 { |
|
190 delete mMmsConformanceCheck; |
|
191 delete mProcessImageOperation; |
|
192 delete mMediaResolver; |
|
193 delete mImageInfo; |
|
194 } |
|
195 |
|
196 QString MsgUnifiedEditorBody::text() |
|
197 { |
|
198 return mTextEdit->toPlainText(); |
|
199 } |
|
200 |
|
201 void MsgUnifiedEditorBody::setImage(QString& imagefile) |
|
202 { |
|
203 if (!mImageInfo) |
|
204 { |
|
205 setImage(true); |
|
206 |
|
207 mImageFile = imagefile; |
|
208 if (mIconItem) |
|
209 { |
|
210 delete mIconItem; |
|
211 mIconItem = NULL; |
|
212 mImageSize = 0; |
|
213 } |
|
214 |
|
215 int error = KErrNone; |
|
216 |
|
217 if( !mProcessImageOperation ) |
|
218 { |
|
219 TRAP(error,mProcessImageOperation = |
|
220 CUniEditorProcessImageOperation::NewL(*this)); |
|
221 } |
|
222 if( !mMediaResolver && error == KErrNone ) |
|
223 { |
|
224 TRAP(error,mMediaResolver = CMsgMediaResolver::NewL()); |
|
225 } |
|
226 |
|
227 if( error == KErrNone) |
|
228 { |
|
229 mMediaResolver->SetCharacterSetRecognition(EFalse); |
|
230 HBufC *name = S60QConversions::qStringToS60Desc(imagefile); |
|
231 RFile file; |
|
232 TRAP(error, file = mMediaResolver->FileHandleL(*name)); |
|
233 if(error == KErrNone) |
|
234 { |
|
235 TRAP(error,mImageInfo = static_cast<CMsgImageInfo*> |
|
236 (mMediaResolver->CreateMediaInfoL(file))); |
|
237 if (error == KErrNone) |
|
238 { |
|
239 TRAP(error, mMediaResolver->ParseInfoDetailsL( |
|
240 mImageInfo, file)); |
|
241 } |
|
242 file.Close(); |
|
243 } |
|
244 delete name; |
|
245 } |
|
246 |
|
247 if (error == KErrNone) |
|
248 { |
|
249 mSavedImageFile = imagefile; |
|
250 startResizeAnimation(); |
|
251 mProcessImageOperation->Process(mImageInfo); |
|
252 } |
|
253 else |
|
254 { |
|
255 delete mImageInfo; |
|
256 mImageInfo = NULL; |
|
257 mSavedImageFile.clear(); |
|
258 handleSetImage(); |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 void MsgUnifiedEditorBody::handleSetImage() |
|
264 { |
|
265 //check for insert conformance |
|
266 if(EInsertSuccess != mMmsConformanceCheck->checkModeForInsert(mImageFile)) |
|
267 return; |
|
268 |
|
269 int msgSize = messageSize(); |
|
270 QFileInfo fileinfo(mImageFile); |
|
271 int imageSize = fileinfo.size() + KEstimatedMimeHeaderSize; |
|
272 if ( (imageSize + msgSize) <= MsgMonitor::maxMmsSize()) |
|
273 { |
|
274 mImageSize = imageSize; |
|
275 } |
|
276 else |
|
277 { |
|
278 mImageFile.clear(); |
|
279 setImage(false); |
|
280 //Show appropriate note and leave |
|
281 showInsertFailureNote(); |
|
282 return; |
|
283 } |
|
284 |
|
285 mIconItem = new HbIconItem(this); |
|
286 mIconItem->hide(); |
|
287 //mIconItem->setIconName(mImageFile); |
|
288 QPixmap pixmap(mImageFile); |
|
289 mIconItem->setIcon(HbIcon(pixmap)); |
|
290 |
|
291 HbStyle::setItemName(mIconItem, "pixmap"); |
|
292 mIconItem->setAlignment(Qt::AlignHCenter | Qt::AlignTop); |
|
293 // mIconItem->installSceneEventFilter(mGestureFilter); |
|
294 |
|
295 // repolish the body widget |
|
296 this->repolish(); |
|
297 |
|
298 // emit signal to indicate addition of image |
|
299 emit contentChanged(); |
|
300 } |
|
301 |
|
302 void MsgUnifiedEditorBody::setAudio(QString& audiofile) |
|
303 { |
|
304 //check for insert conformance |
|
305 if(EInsertSuccess != mMmsConformanceCheck->checkModeForInsert(audiofile)) |
|
306 return; |
|
307 |
|
308 setAudio(true); |
|
309 mAudioFile = audiofile; |
|
310 if(mAudioItem) |
|
311 { |
|
312 delete mAudioItem; |
|
313 mAudioItem = NULL; |
|
314 mAudioSize = 0; |
|
315 } |
|
316 |
|
317 int msgSize = messageSize(); |
|
318 QFileInfo fileinfo(mAudioFile); |
|
319 int audioSize = fileinfo.size() + KEstimatedMimeHeaderSize; |
|
320 if((audioSize + msgSize) <= MsgMonitor::maxMmsSize() ) |
|
321 { |
|
322 mAudioSize = audioSize; |
|
323 } |
|
324 else |
|
325 { |
|
326 mAudioFile.clear(); |
|
327 setAudio(false); |
|
328 //Show appropriate note and leave |
|
329 showInsertFailureNote(); |
|
330 return; |
|
331 } |
|
332 |
|
333 HbIconItem* audioIcon = new HbIconItem(AUDIO_ICON); |
|
334 mAudioItem = new HbPushButton(this); |
|
335 mAudioItem->hide(); |
|
336 HbStyle::setItemName(mAudioItem,"audioItem"); |
|
337 mAudioItem->setIcon(audioIcon->icon()); |
|
338 mAudioItem->setText(fileinfo.baseName()); |
|
339 MsgMediaUtil mediaUtil; |
|
340 mAudioItem->setAdditionalText(mediaUtil.mediaDuration(mAudioFile)); |
|
341 mAudioItem->setTextAlignment(Qt::AlignVCenter | Qt::AlignLeft); |
|
342 connect(mAudioItem, SIGNAL(longPress(QPointF)), this, SLOT(longPressed(QPointF))); |
|
343 |
|
344 // repolish the body widget |
|
345 this->repolish(); |
|
346 |
|
347 // emit signal to indicate addition of audio |
|
348 emit contentChanged(); |
|
349 } |
|
350 |
|
351 void MsgUnifiedEditorBody::setText(QString& text) |
|
352 { |
|
353 mTextEdit->setPlainText(text); |
|
354 } |
|
355 |
|
356 const QStringList MsgUnifiedEditorBody::mediaContent() |
|
357 { |
|
358 QStringList mediaFiles; |
|
359 // Pick mImageFile only if mSavedImageFile is empty |
|
360 // as it means we are not in middle of resizing |
|
361 if (mHasImage && mSavedImageFile.isEmpty()) |
|
362 mediaFiles << mImageFile; |
|
363 if(mHasAudio) |
|
364 mediaFiles << mAudioFile; |
|
365 |
|
366 //TODO: append video content |
|
367 |
|
368 return mediaFiles; |
|
369 } |
|
370 |
|
371 QSizeF MsgUnifiedEditorBody::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
372 { |
|
373 QSizeF szHint = HbWidget::sizeHint(which,constraint); |
|
374 |
|
375 HbMainWindow* mMainWindow = this->mainWindow(); |
|
376 if(!mMainWindow) |
|
377 { |
|
378 return szHint; |
|
379 } |
|
380 |
|
381 qreal leftMargin = 0.0; |
|
382 qreal rightMargin = 0.0; |
|
383 qreal chromeHeight = 0.0; |
|
384 qreal toolbarHeight = 0.0; |
|
385 qreal bodyItemSpacing = 0.0; |
|
386 |
|
387 style()->parameter("hb-param-margin-gene-left",leftMargin); |
|
388 style()->parameter("hb-param-margin-gene-right",rightMargin); |
|
389 style()->parameter("hb-param-widget-chrome-height",chromeHeight); |
|
390 style()->parameter("hb-param-widget-toolbar-height",toolbarHeight); |
|
391 style()->parameter("hb-param-margin-gene-middle-vertical",bodyItemSpacing); |
|
392 |
|
393 HbDeviceProfile prf = HbDeviceProfile::profile(mMainWindow); |
|
394 qreal unt = prf.unitValue(); |
|
395 |
|
396 // Note: With NGA, the orientation change does not cause HW to switch orientation. |
|
397 // So, the HW resolution also remains unchanged. We need to swap values of width & |
|
398 // height to map portrait resolution to landscape resolution. |
|
399 qreal maxWidth = 0.0, maxHeight = 0.0; |
|
400 |
|
401 // Landscape |
|
402 if(mMainWindow->orientation() == Qt::Horizontal) |
|
403 { |
|
404 maxHeight = mMainWindow->width()-chromeHeight-toolbarHeight; |
|
405 maxWidth = (mMainWindow->height()-leftMargin-rightMargin-(2*unt))/2; |
|
406 } |
|
407 else |
|
408 { |
|
409 maxWidth = mMainWindow->width()-leftMargin-rightMargin; |
|
410 maxHeight = mMainWindow->height()-chromeHeight-toolbarHeight; |
|
411 } |
|
412 szHint.setHeight(maxHeight); |
|
413 |
|
414 // add space for audio |
|
415 if(mAudioItem) |
|
416 { |
|
417 if(mMainWindow->orientation() == Qt::Horizontal) |
|
418 { |
|
419 mAudioItem->setStretched(true); |
|
420 } |
|
421 else |
|
422 { |
|
423 mAudioItem->setStretched(false); |
|
424 } |
|
425 QSizeF audioSize = mAudioItem->effectiveSizeHint(which, constraint); |
|
426 szHint.rheight() += (audioSize.height() + bodyItemSpacing); |
|
427 mAudioItem->show(); |
|
428 } |
|
429 |
|
430 if(mIconItem || mProcessingWidget) |
|
431 { |
|
432 QSizeF imageSize(0.0,0.0); |
|
433 QSizeF defaultImageSize(QImageReader(mImageFile).size()); |
|
434 |
|
435 if(!defaultImageSize.isEmpty()) |
|
436 { |
|
437 imageSize.setWidth(maxWidth); |
|
438 if(mMainWindow->orientation() == Qt::Vertical) |
|
439 { |
|
440 szHint.rheight() += bodyItemSpacing; |
|
441 } |
|
442 |
|
443 qreal newHeight = 0.0; |
|
444 if(defaultImageSize.width() <= imageSize.width()) |
|
445 { |
|
446 // resize not needed |
|
447 newHeight = qMin(defaultImageSize.height(), maxHeight); |
|
448 imageSize.setHeight(newHeight); |
|
449 } |
|
450 else |
|
451 { |
|
452 // keep aspect-ratio and resize |
|
453 newHeight = imageSize.width()*(defaultImageSize.height()/defaultImageSize.width()); |
|
454 newHeight = qMin(newHeight,maxHeight); |
|
455 imageSize.setHeight(newHeight); |
|
456 } |
|
457 |
|
458 if(newHeight == maxHeight) |
|
459 { |
|
460 qreal newWidth = defaultImageSize.width()*newHeight/defaultImageSize.height(); |
|
461 imageSize.setWidth(newWidth); |
|
462 } |
|
463 |
|
464 if(mIconItem) |
|
465 { |
|
466 mIconItem->setPreferredSize(imageSize); |
|
467 mIconItem->setSize(imageSize); |
|
468 if(mMainWindow->orientation() == Qt::Horizontal) |
|
469 { |
|
470 QPointF currPos = mIconItem->pos(); |
|
471 currPos.setX(leftMargin+((maxWidth-imageSize.width())/2)); |
|
472 mIconItem->setPos(currPos); |
|
473 } |
|
474 mIconItem->show(); |
|
475 } |
|
476 |
|
477 if(mProcessingWidget) |
|
478 { |
|
479 imageSize.setHeight(mProcessingWidget->preferredHeight()); |
|
480 mProcessingWidget->setPreferredSize(imageSize); |
|
481 mProcessingWidget->show(); |
|
482 } |
|
483 szHint.rheight() += imageSize.height(); |
|
484 } |
|
485 } |
|
486 |
|
487 |
|
488 mTextEdit->setMinimumHeight(maxHeight); |
|
489 szHint.rheight() += bodyItemSpacing; |
|
490 return szHint; |
|
491 } |
|
492 |
|
493 void MsgUnifiedEditorBody::longPressed(QPointF position) |
|
494 { |
|
495 HbMenu* menu = new HbMenu; |
|
496 menu->addAction(LOC_OPEN, this, SLOT(openMedia())); |
|
497 menu->addAction(LOC_REMOVE, this, SLOT(removeMedia())); |
|
498 menu->addAction(LOC_DETAILS, this, SLOT(viewDetails())); |
|
499 |
|
500 menu->setDismissPolicy(HbPopup::TapAnywhere); |
|
501 menu->setAttribute(Qt::WA_DeleteOnClose, true); |
|
502 menu->setPreferredPos(position); |
|
503 |
|
504 menu->setObjectName(getHitRegion(position)); |
|
505 menu->show(); |
|
506 } |
|
507 |
|
508 void MsgUnifiedEditorBody::removeMedia() |
|
509 { |
|
510 HbAction* action = qobject_cast<HbAction*>(sender()); |
|
511 QString objName = action->parent()->objectName(); |
|
512 if(objName == IMAGE_REGION) |
|
513 { |
|
514 mImageFile.clear(); |
|
515 if(mIconItem) |
|
516 { |
|
517 // mIconItem->removeSceneEventFilter(mGestureFilter); |
|
518 delete mIconItem; |
|
519 mIconItem = NULL; |
|
520 } |
|
521 setImage(false); |
|
522 mImageSize = 0; |
|
523 } |
|
524 else if(objName == AUDIO_REGION) |
|
525 { |
|
526 mAudioFile.clear(); |
|
527 if(mAudioItem) |
|
528 { |
|
529 delete mAudioItem; |
|
530 mAudioItem = NULL; |
|
531 } |
|
532 setAudio(false); |
|
533 mAudioSize = 0; |
|
534 } |
|
535 else if(objName == VIDEO_REGION) |
|
536 { |
|
537 //TODO: complete this with video handling story |
|
538 } |
|
539 else |
|
540 { |
|
541 // return without doing anything |
|
542 return; |
|
543 } |
|
544 |
|
545 this->repolish(); |
|
546 |
|
547 emit contentChanged(); |
|
548 } |
|
549 |
|
550 //--------------------------------------------------------------- |
|
551 // MsgUnifiedEditorBody :: openMedia |
|
552 // @see header file |
|
553 //--------------------------------------------------------------- |
|
554 void MsgUnifiedEditorBody::openMedia() |
|
555 { |
|
556 HbAction* action = qobject_cast<HbAction*>(sender()); |
|
557 QString objName = action->parent()->objectName(); |
|
558 |
|
559 QString fileName; |
|
560 if ( objName == IMAGE_REGION ) |
|
561 { |
|
562 fileName = mImageFile; |
|
563 } |
|
564 else if ( objName == AUDIO_REGION ) |
|
565 { |
|
566 fileName = mAudioFile; |
|
567 } |
|
568 else |
|
569 { |
|
570 return; |
|
571 } |
|
572 |
|
573 XQSharableFile sf; |
|
574 XQAiwRequest* request = 0; |
|
575 |
|
576 if ( !sf.open(fileName) ) |
|
577 { |
|
578 return; |
|
579 } |
|
580 |
|
581 // Get handlers |
|
582 XQApplicationManager appManager; |
|
583 QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf); |
|
584 if (fileHandlers.count() > 0) |
|
585 { |
|
586 XQAiwInterfaceDescriptor d = fileHandlers.first(); |
|
587 request = appManager.create(sf, d); |
|
588 |
|
589 if ( !request ) |
|
590 { |
|
591 sf.close(); |
|
592 return ; |
|
593 } |
|
594 } |
|
595 else |
|
596 { |
|
597 sf.close(); |
|
598 return; |
|
599 } |
|
600 |
|
601 // Result handlers |
|
602 connect (request, SIGNAL(requestOk(const QVariant&)), |
|
603 this, SLOT(handleOk(const QVariant&))); |
|
604 connect (request, SIGNAL(requestError(const QVariant&)), |
|
605 this, SLOT(handleError(const QVariant&))); |
|
606 |
|
607 request->setEmbedded(true); |
|
608 request->setSynchronous(true); |
|
609 |
|
610 // Fill args |
|
611 QList<QVariant> args; |
|
612 args << qVariantFromValue(sf); |
|
613 request->setArguments(args); |
|
614 |
|
615 // Fill headers |
|
616 QString key("WindowTitle"); |
|
617 QVariant value(QString(LOC_TITLE)); |
|
618 XQRequestInfo info; |
|
619 info.setInfo(key, value); |
|
620 request->setInfo(info); |
|
621 |
|
622 request->send(); |
|
623 |
|
624 // Cleanup |
|
625 sf.close(); |
|
626 delete request; |
|
627 } |
|
628 |
|
629 void MsgUnifiedEditorBody::viewDetails() |
|
630 { |
|
631 //open details view. |
|
632 } |
|
633 |
|
634 bool MsgUnifiedEditorBody::hasImage() |
|
635 { |
|
636 return mHasImage; |
|
637 } |
|
638 |
|
639 void MsgUnifiedEditorBody::setImage(bool image) |
|
640 { |
|
641 mHasImage = image; |
|
642 } |
|
643 |
|
644 bool MsgUnifiedEditorBody::hasAudio() |
|
645 { |
|
646 return mHasAudio; |
|
647 } |
|
648 |
|
649 void MsgUnifiedEditorBody::setAudio(bool audio) |
|
650 { |
|
651 mHasAudio = audio; |
|
652 } |
|
653 |
|
654 int MsgUnifiedEditorBody::bodySize() |
|
655 { |
|
656 int bodysize = 0; |
|
657 |
|
658 if( mImageSize || mTextEdit->toPlainText().size() || |
|
659 mAudioSize || mVideoSize ) |
|
660 { |
|
661 UniEditorGenUtils* uniEditorGenUtils = new UniEditorGenUtils; |
|
662 bodysize += mImageSize + mAudioSize + mVideoSize + |
|
663 uniEditorGenUtils->UTF8Size(mTextEdit->toPlainText()) + |
|
664 KEstimatedMimeHeaderSize + KEstimatedMmsSmilHeaderSize; |
|
665 delete uniEditorGenUtils; |
|
666 } |
|
667 return bodysize; |
|
668 } |
|
669 |
|
670 int MsgUnifiedEditorBody::messageSize() |
|
671 { |
|
672 int estimatedMediaSize = bodySize(); |
|
673 if(!estimatedMediaSize) |
|
674 { |
|
675 // This is the first media content to be inserted |
|
676 estimatedMediaSize = KEstimatedMmsSmilHeaderSize; |
|
677 } |
|
678 |
|
679 return estimatedMediaSize + MsgMonitor::subjectSize() + MsgMonitor::containerSize(); |
|
680 } |
|
681 |
|
682 QString MsgUnifiedEditorBody::getHitRegion(QPointF position) |
|
683 { |
|
684 if(mIconItem) |
|
685 { |
|
686 QPolygonF imageHitRegion = mIconItem->mapToScene(mIconItem->boundingRect()); |
|
687 if(imageHitRegion.containsPoint(position, Qt::OddEvenFill)) |
|
688 { |
|
689 return IMAGE_REGION; |
|
690 } |
|
691 } |
|
692 |
|
693 if(mAudioItem) |
|
694 { |
|
695 QPolygonF audioHitRegion = mAudioItem->mapToScene(mAudioItem->boundingRect()); |
|
696 if(audioHitRegion.containsPoint(position, Qt::OddEvenFill)) |
|
697 { |
|
698 return AUDIO_REGION; |
|
699 } |
|
700 } |
|
701 |
|
702 //TODO : add hit test for video region with video userstory |
|
703 |
|
704 return INVALID_REGION; |
|
705 } |
|
706 |
|
707 void MsgUnifiedEditorBody::onTextChanged() |
|
708 { |
|
709 QString string = text(); |
|
710 |
|
711 if( string.size() > mPrevBuffer.size() && |
|
712 MsgMonitor::messageType() == ConvergedMessage::Mms ) |
|
713 { |
|
714 // reject any text input if mms size limit is reached |
|
715 int futureSize = bodySize() + |
|
716 MsgMonitor::containerSize() + MsgMonitor::subjectSize(); |
|
717 if(futureSize > MsgMonitor::maxMmsSize()) |
|
718 { |
|
719 mTextEdit->setPlainText(mPrevBuffer); |
|
720 HbNotificationDialog::launchDialog(LOC_UNABLE_TO_ADD_CONTENT); |
|
721 mTextEdit->setCursorPosition(mPrevBuffer.length()); |
|
722 return; |
|
723 } |
|
724 else if(!mPrevBuffer.isEmpty()) |
|
725 { |
|
726 //Save the previous buffer |
|
727 mPrevBuffer = string; |
|
728 // emit signal to indicate change in content |
|
729 emit contentChanged(); |
|
730 return; |
|
731 } |
|
732 } |
|
733 |
|
734 //Check done for optimization |
|
735 //Only if content is deleted we need to call encodingsettings again |
|
736 if (mPrevBuffer.isEmpty() || string.size() <= mPrevBuffer.size()) |
|
737 { |
|
738 mPluginInterface->setEncodingSettings(EFalse, ESmsEncodingNone, |
|
739 mCharSupportType); |
|
740 } |
|
741 |
|
742 TInt numOfRemainingChars; |
|
743 TInt numOfPDUs; |
|
744 TBool unicodeMode; |
|
745 TSmsEncoding alternativeEncodingType; |
|
746 mPluginInterface->getNumPDUs(string, numOfRemainingChars, numOfPDUs, |
|
747 unicodeMode, alternativeEncodingType); |
|
748 |
|
749 //Save the unicode value returned |
|
750 mUnicode = unicodeMode; |
|
751 //Save the old buffer |
|
752 mPrevBuffer = string; |
|
753 |
|
754 // emit signal to indicate change in content |
|
755 emit contentChanged(); |
|
756 |
|
757 if(MsgMonitor::messageType() == ConvergedMessage::Sms) |
|
758 { |
|
759 //Set char counter value |
|
760 QString display = QString("%1(%2)").arg(numOfRemainingChars).arg( |
|
761 numOfPDUs); |
|
762 mCharCounter->setText(display); |
|
763 |
|
764 if (numOfPDUs > 1 || numOfRemainingChars <= KShowCounterLimit) |
|
765 { |
|
766 mCharCounter->setVisible(true); |
|
767 mBackgroundItem->setVisible(true); |
|
768 } |
|
769 else |
|
770 { |
|
771 mCharCounter->setVisible(false); |
|
772 mBackgroundItem->setVisible(false); |
|
773 } |
|
774 } |
|
775 } |
|
776 |
|
777 void MsgUnifiedEditorBody::EditorOperationEvent( |
|
778 TUniEditorProcessImageOperationEvent aEvent, TFileName aFileName) |
|
779 { |
|
780 stopResizeAnimation(); |
|
781 |
|
782 delete mImageInfo; |
|
783 mImageInfo = NULL; |
|
784 |
|
785 if (aEvent == EUniEditorProcessImageOperationComplete && |
|
786 aFileName.Length() > 0) |
|
787 { |
|
788 mImageFile = S60QConversions::s60DescToQString(aFileName); |
|
789 } |
|
790 else |
|
791 { |
|
792 mImageFile = mSavedImageFile; |
|
793 } |
|
794 mSavedImageFile.clear(); |
|
795 //handle the processed image from ProcessImage Operation |
|
796 handleSetImage(); |
|
797 } |
|
798 |
|
799 void MsgUnifiedEditorBody::startResizeAnimation() |
|
800 { |
|
801 QGraphicsLinearLayout* processingLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
802 |
|
803 mProcessingWidget = new HbWidget(this); |
|
804 HbStyle::setItemName(mProcessingWidget,"pixmap"); |
|
805 mProcessingWidget->hide(); |
|
806 mProcessingWidget->setLayout(processingLayout); |
|
807 |
|
808 HbTextItem* processingText = new HbTextItem(LOC_PROCESSING,mProcessingWidget); |
|
809 processingText->setAlignment(Qt::AlignCenter); |
|
810 processingLayout->addItem(processingText); |
|
811 |
|
812 HbIconItem* animationItem = new HbIconItem(ANIMATION_ICON,mProcessingWidget); |
|
813 processingLayout->addItem(animationItem); |
|
814 |
|
815 HbIconAnimator& iconAnimator = animationItem->animator(); |
|
816 HbIconAnimationManager* iconAnimationManager = HbIconAnimationManager::global(); |
|
817 iconAnimationManager->addDefinitionFile(ANIMATION_FILE); |
|
818 |
|
819 iconAnimator.startAnimation(); |
|
820 |
|
821 this->repolish(); |
|
822 } |
|
823 |
|
824 void MsgUnifiedEditorBody::stopResizeAnimation() |
|
825 { |
|
826 if(mProcessingWidget) |
|
827 { |
|
828 delete mProcessingWidget; |
|
829 mProcessingWidget = NULL; |
|
830 } |
|
831 } |
|
832 |
|
833 // --------------------------------------------------------- |
|
834 // MsgUnifiedEditorBody::isUnicode |
|
835 // --------------------------------------------------------- |
|
836 // |
|
837 bool MsgUnifiedEditorBody::isUnicode() |
|
838 { |
|
839 return mUnicode; |
|
840 } |
|
841 |
|
842 // --------------------------------------------------------- |
|
843 // MsgUnifiedEditorBody::disableCharCounter |
|
844 // --------------------------------------------------------- |
|
845 // |
|
846 void MsgUnifiedEditorBody::disableCharCounter() |
|
847 { |
|
848 mCharCounter->setVisible(false); |
|
849 mBackgroundItem->setVisible(false); |
|
850 } |
|
851 |
|
852 //--------------------------------------------------------------- |
|
853 // MsgUnifiedEditorBody :: handleOk |
|
854 // @see header file |
|
855 //--------------------------------------------------------------- |
|
856 void MsgUnifiedEditorBody::handleOk(const QVariant& result) |
|
857 { |
|
858 Q_UNUSED(result) |
|
859 } |
|
860 |
|
861 //--------------------------------------------------------------- |
|
862 // MsgUnifiedEditorBody :: handleError |
|
863 // @see header file |
|
864 //--------------------------------------------------------------- |
|
865 void MsgUnifiedEditorBody::handleError(int errorCode, |
|
866 const QString& errorMessage) |
|
867 { |
|
868 Q_UNUSED(errorMessage) |
|
869 Q_UNUSED(errorCode) |
|
870 } |
|
871 |
|
872 //--------------------------------------------------------------- |
|
873 // MsgUnifiedEditorBody :: setFocus |
|
874 // @see header file |
|
875 //--------------------------------------------------------------- |
|
876 void MsgUnifiedEditorBody::setFocus() |
|
877 { |
|
878 mTextEdit->setFocus(Qt::MouseFocusReason); |
|
879 } |
|
880 // EOF |