14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 // INCLUDES |
18 // INCLUDES |
19 #include <HbTextEdit> |
|
20 #include <HbTextItem> |
19 #include <HbTextItem> |
21 #include <HbFrameItem> |
|
22 #include <HbFrameDrawer> |
|
23 #include <HbIconItem> |
20 #include <HbIconItem> |
24 #include <HbAction> |
|
25 #include <HbMainWindow> |
21 #include <HbMainWindow> |
26 #include <HbDeviceProfile> |
22 #include <HbDeviceProfile> |
27 #include <QImageReader> |
23 #include <QImageReader> |
28 #include <QFileInfo> |
24 #include <QFileInfo> |
29 #include <MsgMediaResolver.h> |
25 #include <MsgMediaResolver.h> |
30 #include <MsgImageInfo.h> |
26 #include <MsgImageInfo.h> |
31 #include <HbIconAnimationManager> |
27 #include <HbIconAnimationManager> |
32 #include <HbIconAnimator> |
28 #include <HbIconAnimator> |
33 #include <HbIcon> |
|
34 #include <QGraphicsLinearLayout> |
29 #include <QGraphicsLinearLayout> |
35 #include <HbNotificationDialog> |
30 #include <HbNotificationDialog> |
36 |
31 |
37 #include <csmsaccount.h> |
|
38 #include <smutset.h> |
|
39 #include <xqaiwrequest.h> |
32 #include <xqaiwrequest.h> |
40 #include <xqrequestinfo.h> |
33 #include <xqrequestinfo.h> |
41 #include <xqsharablefile.h> |
34 #include <xqsharablefile.h> |
42 #include <xqappmgr.h> |
35 #include <xqappmgr.h> |
43 #include <xqconversions.h> |
36 #include <xqconversions.h> |
44 #include <hbmessagebox.h> |
37 #include <hbmessagebox.h> |
45 #include <hbcolorscheme.h> |
38 |
46 #include <QColor> |
|
47 // USER INCLUDES |
39 // USER INCLUDES |
48 #include "msgunieditorbody.h" |
40 #include "msgunieditorbody.h" |
49 #include "UniEditorGenUtils.h" |
41 #include "UniEditorGenUtils.h" |
50 #include "UniSendingSettings.h" |
|
51 #include "msgunieditormonitor.h" |
42 #include "msgunieditormonitor.h" |
52 |
43 |
53 #include "mmsconformancecheck.h" |
44 #include "mmsconformancecheck.h" |
54 #include "unieditorpluginloader.h" |
|
55 #include "unieditorplugininterface.h" |
|
56 #include "convergedmessage.h" |
|
57 #include "msgmediautil.h" |
|
58 #include "msgunieditorpixmapwidget.h" |
45 #include "msgunieditorpixmapwidget.h" |
59 #include "msgunieditoraudiowidget.h" |
46 #include "msgunieditoraudiowidget.h" |
|
47 #include "msgunieditorview.h" |
60 |
48 |
61 // Constants |
49 // Constants |
62 const QString BACKGROUND_FRAME("qtg_fr_messaging_char_count"); |
|
63 const QString CHAR_COUNTER_COLOR("qtc_messaging_char_count"); |
|
64 |
|
65 const int KShowCounterLimit = 10; |
|
66 const int BYTES_TO_KBYTES_FACTOR = 1024; |
50 const int BYTES_TO_KBYTES_FACTOR = 1024; |
67 |
51 |
68 //Localized Constants for item specific menu |
52 //Localized Constants for item specific menu |
69 #define LOC_TITLE hbTrId("txt_messaging_title_messaging") |
|
70 #define LOC_UNABLE_TO_ADD_CONTENT hbTrId("txt_messaging_dpopinfo_unable_to_add_more_content") |
|
71 #define LOC_UNABLE_TO_ATTACH_ITEM hbTrId("txt_messaging_dpopinfo_unable_to_attach_item_avai") |
53 #define LOC_UNABLE_TO_ATTACH_ITEM hbTrId("txt_messaging_dpopinfo_unable_to_attach_item_avai") |
72 #define LOC_PROCESSING hbTrId("txt_messaging_formlabel_loading") |
54 #define LOC_PROCESSING hbTrId("txt_messaging_formlabel_loading") |
73 #define LOC_HINT_TEXT hbTrId("txt_messaging_formlabel_enter_message_here") |
|
74 #define LOC_ATTACHED_PHOTO_SIZE hbTrId("txt_messaging_dpopinfo_attached_photo_size_is_l1") |
55 #define LOC_ATTACHED_PHOTO_SIZE hbTrId("txt_messaging_dpopinfo_attached_photo_size_is_l1") |
75 |
56 |
76 const QString ANIMATION_ICON("qtg_anim_loading"); |
57 const QString ANIMATION_ICON("qtg_anim_loading"); |
77 const QString ANIMATION_FILE(":/qtg_anim_loading.axml"); |
58 const QString ANIMATION_FILE("qtg_anim_loading.axml"); |
78 // LOCAL FUNCTIONS |
59 // LOCAL FUNCTIONS |
79 |
60 |
80 //--------------------------------------------------------------- |
61 //--------------------------------------------------------------- |
81 // showInsertFailureNote |
62 // showInsertFailureNote |
82 // @return fullPath of unified editor's temporary dir |
63 // @return fullPath of unified editor's temporary dir |
83 //--------------------------------------------------------------- |
64 //--------------------------------------------------------------- |
84 void showInsertFailureNote() |
65 void showInsertFailureNote() |
85 { |
66 { |
86 int availableSize = |
67 int availableSize = |
87 (MsgUnifiedEditorMonitor::maxMmsSize() - MsgUnifiedEditorMonitor::messageSize()) |
68 (MsgUnifiedEditorMonitor::maxMmsSize() - MsgUnifiedEditorMonitor::messageSize()) |
88 /BYTES_TO_KBYTES_FACTOR; |
69 /BYTES_TO_KBYTES_FACTOR; |
89 QString displayStr = QString(LOC_UNABLE_TO_ATTACH_ITEM) |
70 QString displayStr = QString(LOC_UNABLE_TO_ATTACH_ITEM) |
90 .arg(availableSize); |
71 .arg(availableSize); |
91 |
72 |
92 HbMessageBox::information(displayStr, 0, 0, HbMessageBox::Ok); |
73 HbMessageBox::information(displayStr, 0, 0, HbMessageBox::Ok); |
93 } |
74 } |
94 |
75 |
95 |
76 |
96 MsgUnifiedEditorBody::MsgUnifiedEditorBody( QGraphicsItem *parent ) : |
77 MsgUnifiedEditorBody::MsgUnifiedEditorBody( QGraphicsItem *parent ) : |
97 MsgUnifiedEditorBaseWidget(parent), |
78 MsgUnifiedEditorBaseWidget(parent), |
98 mHasImage(false), |
79 mHasImage(false), |
99 mHasAudio(false), |
80 mHasAudio(false), |
100 mTextEdit(0), |
|
101 mPixmapItem(0), |
81 mPixmapItem(0), |
102 mAudioItem(0), |
82 mAudioItem(0), |
103 mImageSize(0), |
83 mImageSize(0), |
104 mAudioSize(0), |
84 mAudioSize(0), |
105 mVideoSize(0), |
|
106 mProcessImageOperation(0), |
85 mProcessImageOperation(0), |
107 mMediaResolver(0), |
86 mMediaResolver(0), |
108 mImageInfo(0), |
87 mImageInfo(0), |
109 mProcessingWidget(0), |
88 mProcessingWidget(0), |
110 mDraftMessage(false), |
89 mDraftMessage(false) |
111 mIsImageResizing(false) |
90 { |
112 { |
91 this->setObjectName("body"); |
113 mTextEdit = new HbTextEdit(this); |
92 mMmsConformanceCheck = new MmsConformanceCheck; |
114 mTextEdit->setPlaceholderText(LOC_HINT_TEXT); |
|
115 mTextEdit->setFontSpec(HbFontSpec(HbFontSpec::Secondary)); |
|
116 HbStyle::setItemName(mTextEdit,"textEdit"); |
|
117 connect(mTextEdit, SIGNAL(contentsChanged()), this, SLOT(onTextChanged())); |
|
118 |
|
119 mMmsConformanceCheck = new MmsConformanceCheck; |
|
120 |
|
121 mCharCounter = new HbTextItem(this); |
|
122 HbStyle::setItemName(mCharCounter, "charCounter"); |
|
123 mCharCounter->setZValue(1.5); |
|
124 |
|
125 QColor color = HbColorScheme::color(CHAR_COUNTER_COLOR); |
|
126 mCharCounter->setTextColor(color); |
|
127 |
|
128 mBackgroundItem = new HbFrameItem(this); |
|
129 HbStyle::setItemName(mBackgroundItem, "charCounterFrame"); |
|
130 |
|
131 mBackgroundItem->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal); |
|
132 mBackgroundItem->frameDrawer().setFillWholeRect(true); |
|
133 |
|
134 mBackgroundItem->frameDrawer().setFrameGraphicsName(BACKGROUND_FRAME); |
|
135 |
|
136 mPluginLoader = new UniEditorPluginLoader(this); |
|
137 |
|
138 mPluginInterface = |
|
139 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms); |
|
140 |
|
141 TRAP_IGNORE( |
|
142 CSmsSettings* settings = CSmsSettings::NewLC(); |
|
143 CSmsAccount* account = CSmsAccount::NewLC(); |
|
144 account->LoadSettingsL( *settings ); |
|
145 |
|
146 if( settings->CharacterSet() == TSmsDataCodingScheme::ESmsAlphabetUCS2) |
|
147 { |
|
148 mCharSupportType = TUniSendingSettings::EUniCharSupportFull; |
|
149 } |
|
150 else |
|
151 { |
|
152 mCharSupportType = TUniSendingSettings::EUniCharSupportReduced; |
|
153 } |
|
154 |
|
155 CleanupStack::PopAndDestroy( account ); |
|
156 CleanupStack::PopAndDestroy( settings ); |
|
157 ); |
|
158 |
|
159 mCharCounter->setVisible(false); |
|
160 mBackgroundItem->setVisible(false); |
|
161 } |
93 } |
162 |
94 |
163 MsgUnifiedEditorBody::~MsgUnifiedEditorBody() |
95 MsgUnifiedEditorBody::~MsgUnifiedEditorBody() |
164 { |
96 { |
165 delete mMmsConformanceCheck; |
97 delete mMmsConformanceCheck; |
166 delete mProcessImageOperation; |
98 delete mProcessImageOperation; |
167 delete mMediaResolver; |
99 delete mMediaResolver; |
168 delete mImageInfo; |
100 delete mImageInfo; |
169 } |
101 } |
170 |
102 |
171 QString MsgUnifiedEditorBody::text() |
103 void MsgUnifiedEditorBody::setImage(const QString& imagefile, bool draftMessage) |
172 { |
104 { |
173 return mTextEdit->toPlainText(); |
105 |
174 } |
106 // do nothing if filepath is empty |
175 |
|
176 void MsgUnifiedEditorBody::setImage(QString& imagefile, bool draftMessage) |
|
177 { |
|
178 // do nothing if filepath is empty |
|
179 if (imagefile.isEmpty()) |
107 if (imagefile.isEmpty()) |
180 { |
108 { |
181 return; |
109 return; |
182 } |
110 } |
|
111 |
|
112 //disable image option in menu. |
|
113 emit enableMenuAction(PHOTO,false); |
183 |
114 |
184 mDraftMessage = draftMessage; |
115 mDraftMessage = draftMessage; |
185 if (!mImageInfo) |
116 if (!mImageInfo) |
186 { |
117 { |
187 setImage(true); |
118 setImage(true); |
540 mHasAudio = audio; |
463 mHasAudio = audio; |
541 } |
464 } |
542 |
465 |
543 int MsgUnifiedEditorBody::bodySize() |
466 int MsgUnifiedEditorBody::bodySize() |
544 { |
467 { |
545 int bodysize = 0; |
468 return mImageSize + mAudioSize; |
546 |
|
547 if( mImageSize || mTextEdit->toPlainText().size() || |
|
548 mAudioSize || mVideoSize ) |
|
549 { |
|
550 |
|
551 UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils); |
|
552 |
|
553 bodysize += mImageSize + mAudioSize + mVideoSize + |
|
554 genUtils->UTF8Size(mTextEdit->toPlainText()) + |
|
555 KEstimatedMimeHeaderSize + KEstimatedMmsSmilHeaderSize; |
|
556 delete genUtils; |
|
557 } |
|
558 return bodysize; |
|
559 } |
|
560 |
|
561 int MsgUnifiedEditorBody::messageSize() |
|
562 { |
|
563 int estimatedMediaSize = bodySize(); |
|
564 if(!estimatedMediaSize) |
|
565 { |
|
566 // This is the first media content to be inserted |
|
567 estimatedMediaSize = KEstimatedMmsSmilHeaderSize; |
|
568 } |
|
569 |
|
570 return estimatedMediaSize + MsgUnifiedEditorMonitor::subjectSize() + MsgUnifiedEditorMonitor::containerSize(); |
|
571 } |
|
572 |
|
573 void MsgUnifiedEditorBody::onTextChanged() |
|
574 { |
|
575 QString string = text(); |
|
576 |
|
577 if( string.size() > mPrevBuffer.size() && |
|
578 MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Mms ) |
|
579 { |
|
580 // reject any text input if mms size limit is reached |
|
581 int futureSize = bodySize() + |
|
582 MsgUnifiedEditorMonitor::containerSize() + MsgUnifiedEditorMonitor::subjectSize(); |
|
583 if(futureSize > MsgUnifiedEditorMonitor::maxMmsSize()) |
|
584 { |
|
585 mTextEdit->setPlainText(mPrevBuffer); |
|
586 HbMessageBox::information(LOC_UNABLE_TO_ADD_CONTENT, 0, 0, HbMessageBox::Ok); |
|
587 mTextEdit->setCursorPosition(mPrevBuffer.length()); |
|
588 return; |
|
589 } |
|
590 else if(!mPrevBuffer.isEmpty()) |
|
591 { |
|
592 //Save the previous buffer |
|
593 mPrevBuffer = string; |
|
594 // emit signal to indicate change in content |
|
595 emit contentChanged(); |
|
596 return; |
|
597 } |
|
598 } |
|
599 |
|
600 //Check done for optimization |
|
601 //Only if content is deleted we need to call encodingsettings again |
|
602 if (mPrevBuffer.isEmpty() || string.size() <= mPrevBuffer.size()) |
|
603 { |
|
604 mPluginInterface->setEncodingSettings(EFalse, ESmsEncodingNone, |
|
605 mCharSupportType); |
|
606 } |
|
607 |
|
608 TInt numOfRemainingChars; |
|
609 TInt numOfPDUs; |
|
610 TBool unicodeMode; |
|
611 TSmsEncoding alternativeEncodingType; |
|
612 mPluginInterface->getNumPDUs(string, numOfRemainingChars, numOfPDUs, |
|
613 unicodeMode, alternativeEncodingType); |
|
614 |
|
615 //Save the unicode value returned |
|
616 mUnicode = unicodeMode; |
|
617 //Save the old buffer |
|
618 mPrevBuffer = string; |
|
619 |
|
620 // emit signal to indicate change in content |
|
621 emit contentChanged(); |
|
622 |
|
623 if(MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Sms) |
|
624 { |
|
625 //Set char counter value |
|
626 QString display = QString("%1(%2)").arg(numOfRemainingChars).arg( |
|
627 numOfPDUs); |
|
628 mCharCounter->setText(display); |
|
629 |
|
630 if (numOfPDUs > 1 || numOfRemainingChars <= KShowCounterLimit) |
|
631 { |
|
632 mCharCounter->setVisible(true); |
|
633 mBackgroundItem->setVisible(true); |
|
634 } |
|
635 else |
|
636 { |
|
637 mCharCounter->setVisible(false); |
|
638 mBackgroundItem->setVisible(false); |
|
639 } |
|
640 } |
|
641 } |
469 } |
642 |
470 |
643 void MsgUnifiedEditorBody::EditorOperationEvent( |
471 void MsgUnifiedEditorBody::EditorOperationEvent( |
644 TUniEditorProcessImageOperationEvent aEvent, TFileName& aFileName) |
472 TUniEditorProcessImageOperationEvent aEvent, TFileName& aFileName) |
645 { |
473 { |
646 delete mImageInfo; |
474 delete mImageInfo; |
647 mImageInfo = NULL; |
475 mImageInfo = NULL; |
648 |
476 |
649 if (aEvent == EUniEditorProcessImageOperationComplete && |
477 if (aEvent == EUniEditorProcessImageOperationComplete && |
650 aFileName.Length() > 0) |
478 aFileName.Length() > 0) |
651 { |
479 { |
652 mImageFile = XQConversions::s60DescToQString(aFileName); |
480 mImageFile = XQConversions::s60DescToQString(aFileName); |
706 { |
531 { |
707 delete mProcessingWidget; |
532 delete mProcessingWidget; |
708 mProcessingWidget = NULL; |
533 mProcessingWidget = NULL; |
709 } |
534 } |
710 |
535 |
711 } |
|
712 |
|
713 // --------------------------------------------------------- |
|
714 // MsgUnifiedEditorBody::isUnicode |
|
715 // --------------------------------------------------------- |
|
716 // |
|
717 bool MsgUnifiedEditorBody::isUnicode() |
|
718 { |
|
719 return mUnicode; |
|
720 } |
|
721 |
|
722 // --------------------------------------------------------- |
|
723 // MsgUnifiedEditorBody::disableCharCounter |
|
724 // --------------------------------------------------------- |
|
725 // |
|
726 void MsgUnifiedEditorBody::disableCharCounter() |
|
727 { |
|
728 mCharCounter->setVisible(false); |
|
729 mBackgroundItem->setVisible(false); |
|
730 } |
|
731 |
|
732 // --------------------------------------------------------- |
|
733 // MsgUnifiedEditorBody::enableCharCounter |
|
734 // --------------------------------------------------------- |
|
735 // |
|
736 void MsgUnifiedEditorBody::enableCharCounter() |
|
737 { |
|
738 mPluginInterface->setEncodingSettings(EFalse, ESmsEncodingNone, |
|
739 mCharSupportType); |
|
740 |
|
741 TInt numOfRemainingChars; |
|
742 TInt numOfPDUs; |
|
743 TBool unicodeMode; |
|
744 TSmsEncoding alternativeEncodingType; |
|
745 QString string = mTextEdit->toPlainText(); |
|
746 mPluginInterface->getNumPDUs(string, |
|
747 numOfRemainingChars, numOfPDUs, unicodeMode, |
|
748 alternativeEncodingType); |
|
749 |
|
750 //Save the unicode value returned |
|
751 mUnicode = unicodeMode; |
|
752 |
|
753 //Set char counter value |
|
754 QString display = QString("%1(%2)").arg(numOfRemainingChars).arg( |
|
755 numOfPDUs); |
|
756 mCharCounter->setText(display); |
|
757 |
|
758 if (numOfPDUs > 1 || numOfRemainingChars <= KShowCounterLimit) |
|
759 { |
|
760 mCharCounter->setVisible(true); |
|
761 mBackgroundItem->setVisible(true); |
|
762 } |
|
763 else |
|
764 { |
|
765 mCharCounter->setVisible(false); |
|
766 mBackgroundItem->setVisible(false); |
|
767 } |
|
768 |
|
769 } |
|
770 |
|
771 //--------------------------------------------------------------- |
|
772 // MsgUnifiedEditorBody :: setFocus |
|
773 // @see header file |
|
774 //--------------------------------------------------------------- |
|
775 void MsgUnifiedEditorBody::setFocus() |
|
776 { |
|
777 mTextEdit->setFocus(Qt::MouseFocusReason); |
|
778 } |
536 } |
779 |
537 |
780 //--------------------------------------------------------------- |
538 //--------------------------------------------------------------- |
781 // MsgUnifiedEditorBody :: removeMediaContent |
539 // MsgUnifiedEditorBody :: removeMediaContent |
782 // @see header file |
540 // @see header file |