diff -r ecf6a73a9186 -r 60a8a215b0ec messagingapp/msgui/unifiededitor/src/msgunieditorbody.cpp --- a/messagingapp/msgui/unifiededitor/src/msgunieditorbody.cpp Tue Oct 05 13:58:47 2010 +0530 +++ b/messagingapp/msgui/unifiededitor/src/msgunieditorbody.cpp Tue Oct 19 11:30:16 2010 +0530 @@ -16,12 +16,8 @@ */ // INCLUDES -#include #include -#include -#include #include -#include #include #include #include @@ -30,51 +26,36 @@ #include #include #include -#include #include #include -#include -#include #include #include #include #include #include #include -#include -#include + // USER INCLUDES #include "msgunieditorbody.h" #include "UniEditorGenUtils.h" -#include "UniSendingSettings.h" #include "msgunieditormonitor.h" #include "mmsconformancecheck.h" -#include "unieditorpluginloader.h" -#include "unieditorplugininterface.h" -#include "convergedmessage.h" -#include "msgmediautil.h" #include "msgunieditorpixmapwidget.h" #include "msgunieditoraudiowidget.h" +#include "msgunieditorview.h" // Constants -const QString BACKGROUND_FRAME("qtg_fr_messaging_char_count"); -const QString CHAR_COUNTER_COLOR("qtc_messaging_char_count"); - -const int KShowCounterLimit = 10; const int BYTES_TO_KBYTES_FACTOR = 1024; //Localized Constants for item specific menu -#define LOC_TITLE hbTrId("txt_messaging_title_messaging") -#define LOC_UNABLE_TO_ADD_CONTENT hbTrId("txt_messaging_dpopinfo_unable_to_add_more_content") #define LOC_UNABLE_TO_ATTACH_ITEM hbTrId("txt_messaging_dpopinfo_unable_to_attach_item_avai") #define LOC_PROCESSING hbTrId("txt_messaging_formlabel_loading") -#define LOC_HINT_TEXT hbTrId("txt_messaging_formlabel_enter_message_here") #define LOC_ATTACHED_PHOTO_SIZE hbTrId("txt_messaging_dpopinfo_attached_photo_size_is_l1") const QString ANIMATION_ICON("qtg_anim_loading"); -const QString ANIMATION_FILE(":/qtg_anim_loading.axml"); +const QString ANIMATION_FILE("qtg_anim_loading.axml"); // LOCAL FUNCTIONS //--------------------------------------------------------------- @@ -84,10 +65,10 @@ void showInsertFailureNote() { int availableSize = - (MsgUnifiedEditorMonitor::maxMmsSize() - MsgUnifiedEditorMonitor::messageSize()) - /BYTES_TO_KBYTES_FACTOR; + (MsgUnifiedEditorMonitor::maxMmsSize() - MsgUnifiedEditorMonitor::messageSize()) + /BYTES_TO_KBYTES_FACTOR; QString displayStr = QString(LOC_UNABLE_TO_ATTACH_ITEM) - .arg(availableSize); + .arg(availableSize); HbMessageBox::information(displayStr, 0, 0, HbMessageBox::Ok); } @@ -97,67 +78,18 @@ MsgUnifiedEditorBaseWidget(parent), mHasImage(false), mHasAudio(false), -mTextEdit(0), mPixmapItem(0), mAudioItem(0), mImageSize(0), mAudioSize(0), -mVideoSize(0), mProcessImageOperation(0), mMediaResolver(0), mImageInfo(0), mProcessingWidget(0), -mDraftMessage(false), -mIsImageResizing(false) +mDraftMessage(false) { - mTextEdit = new HbTextEdit(this); - mTextEdit->setPlaceholderText(LOC_HINT_TEXT); - mTextEdit->setFontSpec(HbFontSpec(HbFontSpec::Secondary)); - HbStyle::setItemName(mTextEdit,"textEdit"); - connect(mTextEdit, SIGNAL(contentsChanged()), this, SLOT(onTextChanged())); - - mMmsConformanceCheck = new MmsConformanceCheck; - - mCharCounter = new HbTextItem(this); - HbStyle::setItemName(mCharCounter, "charCounter"); - mCharCounter->setZValue(1.5); - - QColor color = HbColorScheme::color(CHAR_COUNTER_COLOR); - mCharCounter->setTextColor(color); - - mBackgroundItem = new HbFrameItem(this); - HbStyle::setItemName(mBackgroundItem, "charCounterFrame"); - - mBackgroundItem->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal); - mBackgroundItem->frameDrawer().setFillWholeRect(true); - - mBackgroundItem->frameDrawer().setFrameGraphicsName(BACKGROUND_FRAME); - - mPluginLoader = new UniEditorPluginLoader(this); - - mPluginInterface = - mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms); - - TRAP_IGNORE( - CSmsSettings* settings = CSmsSettings::NewLC(); - CSmsAccount* account = CSmsAccount::NewLC(); - account->LoadSettingsL( *settings ); - - if( settings->CharacterSet() == TSmsDataCodingScheme::ESmsAlphabetUCS2) - { - mCharSupportType = TUniSendingSettings::EUniCharSupportFull; - } - else - { - mCharSupportType = TUniSendingSettings::EUniCharSupportReduced; - } - - CleanupStack::PopAndDestroy( account ); - CleanupStack::PopAndDestroy( settings ); - ); - - mCharCounter->setVisible(false); - mBackgroundItem->setVisible(false); + this->setObjectName("body"); + mMmsConformanceCheck = new MmsConformanceCheck; } MsgUnifiedEditorBody::~MsgUnifiedEditorBody() @@ -168,18 +100,17 @@ delete mImageInfo; } -QString MsgUnifiedEditorBody::text() -{ - return mTextEdit->toPlainText(); -} - -void MsgUnifiedEditorBody::setImage(QString& imagefile, bool draftMessage) +void MsgUnifiedEditorBody::setImage(const QString& imagefile, bool draftMessage) { - // do nothing if filepath is empty + + // do nothing if filepath is empty if (imagefile.isEmpty()) { return; } + + //disable image option in menu. + emit enableMenuAction(PHOTO,false); mDraftMessage = draftMessage; if (!mImageInfo) @@ -233,7 +164,10 @@ { mSavedImageFile = imagefile; startResizeAnimation(); - mIsImageResizing = true; + + // image resize is started. set the image resize flag. + emit contentsChanged(true); + mProcessImageOperation->Process(mImageInfo); } else @@ -254,9 +188,13 @@ { //check for insert conformance if(EInsertSuccess != mMmsConformanceCheck->checkModeForInsert(mImageFile)) + { + //enable image option in menu as insertion failed. + emit enableMenuAction(PHOTO,true); return; + } - int msgSize = messageSize(); + int msgSize = MsgUnifiedEditorMonitor::messageSize(); QFileInfo fileinfo(mImageFile); int imageSize = fileinfo.size() + KEstimatedMimeHeaderSize; if ( (imageSize + msgSize) <= MsgUnifiedEditorMonitor::maxMmsSize()) @@ -269,6 +207,10 @@ setImage(false); //Show appropriate note and leave showInsertFailureNote(); + + //enable image option in menu as insertion failed. + emit enableMenuAction(PHOTO,true); + return; } @@ -283,10 +225,10 @@ this->repolish(); // emit signal to indicate addition of image - emit contentChanged(); + emit contentsChanged(bodySize()); } -void MsgUnifiedEditorBody::setAudio(QString& audiofile) +void MsgUnifiedEditorBody::setAudio(const QString& audiofile) { // do nothing if filepath is empty if(audiofile.isEmpty()) @@ -308,7 +250,7 @@ mAudioSize = 0; } - int msgSize = messageSize(); + int msgSize = MsgUnifiedEditorMonitor::messageSize(); QFileInfo fileinfo(mAudioFile); int audioSize = fileinfo.size() + KEstimatedMimeHeaderSize; if((audioSize + msgSize) <= MsgUnifiedEditorMonitor::maxMmsSize() ) @@ -334,15 +276,10 @@ this->repolish(); // emit signal to indicate addition of audio - emit contentChanged(); -} - -void MsgUnifiedEditorBody::setText(QString& text) -{ - if(!text.isEmpty()) - { - mTextEdit->setPlainText(text); - } + emit contentsChanged(bodySize()); + + //disable sound option in menu. + emit enableMenuAction(SOUND,false); } const QStringList MsgUnifiedEditorBody::mediaContent() @@ -383,23 +320,10 @@ HbDeviceProfile prf = HbDeviceProfile::profile(mMainWindow); qreal unt = prf.unitValue(); - // Note: With NGA, the orientation change does not cause HW to switch orientation. - // So, the HW resolution also remains unchanged. We need to swap values of width & - // height to map portrait resolution to landscape resolution. - qreal maxWidth = 0.0, maxHeight = 0.0; - - // Landscape - if(mMainWindow->orientation() == Qt::Horizontal) - { - maxHeight = mMainWindow->width()-chromeHeight-toolbarHeight; - maxWidth = (mMainWindow->height()-leftMargin-rightMargin-(2*unt))/2; - } - else - { - maxWidth = mMainWindow->width()-leftMargin-rightMargin; - maxHeight = mMainWindow->height()-chromeHeight-toolbarHeight; - } - szHint.setHeight(maxHeight); + qreal maxWidth = mMainWindow->width()-leftMargin-rightMargin; + qreal maxHeight = mMainWindow->height()-chromeHeight-toolbarHeight; + + szHint.setHeight(0); // add space for audio if(mAudioItem) @@ -455,12 +379,6 @@ { mPixmapItem->setPreferredSize(imageSize); mPixmapItem->setSize(imageSize); - if(mMainWindow->orientation() == Qt::Horizontal) - { - QPointF currPos = mPixmapItem->pos(); - currPos.setX(leftMargin+((maxWidth-imageSize.width())/2)); - mPixmapItem->setPos(currPos); - } mPixmapItem->show(); } @@ -474,8 +392,6 @@ } } - - mTextEdit->setMinimumHeight(maxHeight); szHint.rheight() += bodyItemSpacing; return szHint; } @@ -501,6 +417,10 @@ } setImage(false); mImageSize = 0; + + //enable photo option in menu. + emit enableMenuAction(PHOTO,true); + } else if(audio)//remove audio item { @@ -513,11 +433,14 @@ } setAudio(false); mAudioSize = 0; + + //enable sound option in menu. + emit enableMenuAction(SOUND,true); } this->repolish(); - emit contentChanged(); + emit contentsChanged(bodySize()); } bool MsgUnifiedEditorBody::hasImage() @@ -542,109 +465,14 @@ int MsgUnifiedEditorBody::bodySize() { - int bodysize = 0; - - if( mImageSize || mTextEdit->toPlainText().size() || - mAudioSize || mVideoSize ) - { - - UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils); - - bodysize += mImageSize + mAudioSize + mVideoSize + - genUtils->UTF8Size(mTextEdit->toPlainText()) + - KEstimatedMimeHeaderSize + KEstimatedMmsSmilHeaderSize; - delete genUtils; - } - return bodysize; -} - -int MsgUnifiedEditorBody::messageSize() -{ - int estimatedMediaSize = bodySize(); - if(!estimatedMediaSize) - { - // This is the first media content to be inserted - estimatedMediaSize = KEstimatedMmsSmilHeaderSize; - } - - return estimatedMediaSize + MsgUnifiedEditorMonitor::subjectSize() + MsgUnifiedEditorMonitor::containerSize(); -} - -void MsgUnifiedEditorBody::onTextChanged() -{ - QString string = text(); - - if( string.size() > mPrevBuffer.size() && - MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Mms ) - { - // reject any text input if mms size limit is reached - int futureSize = bodySize() + - MsgUnifiedEditorMonitor::containerSize() + MsgUnifiedEditorMonitor::subjectSize(); - if(futureSize > MsgUnifiedEditorMonitor::maxMmsSize()) - { - mTextEdit->setPlainText(mPrevBuffer); - HbMessageBox::information(LOC_UNABLE_TO_ADD_CONTENT, 0, 0, HbMessageBox::Ok); - mTextEdit->setCursorPosition(mPrevBuffer.length()); - return; - } - else if(!mPrevBuffer.isEmpty()) - { - //Save the previous buffer - mPrevBuffer = string; - // emit signal to indicate change in content - emit contentChanged(); - return; - } - } - - //Check done for optimization - //Only if content is deleted we need to call encodingsettings again - if (mPrevBuffer.isEmpty() || string.size() <= mPrevBuffer.size()) - { - mPluginInterface->setEncodingSettings(EFalse, ESmsEncodingNone, - mCharSupportType); - } - - TInt numOfRemainingChars; - TInt numOfPDUs; - TBool unicodeMode; - TSmsEncoding alternativeEncodingType; - mPluginInterface->getNumPDUs(string, numOfRemainingChars, numOfPDUs, - unicodeMode, alternativeEncodingType); - - //Save the unicode value returned - mUnicode = unicodeMode; - //Save the old buffer - mPrevBuffer = string; - - // emit signal to indicate change in content - emit contentChanged(); - - if(MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Sms) - { - //Set char counter value - QString display = QString("%1(%2)").arg(numOfRemainingChars).arg( - numOfPDUs); - mCharCounter->setText(display); - - if (numOfPDUs > 1 || numOfRemainingChars <= KShowCounterLimit) - { - mCharCounter->setVisible(true); - mBackgroundItem->setVisible(true); - } - else - { - mCharCounter->setVisible(false); - mBackgroundItem->setVisible(false); - } - } + return mImageSize + mAudioSize; } void MsgUnifiedEditorBody::EditorOperationEvent( TUniEditorProcessImageOperationEvent aEvent, TFileName& aFileName) { delete mImageInfo; - mImageInfo = NULL; + mImageInfo = NULL; if (aEvent == EUniEditorProcessImageOperationComplete && aFileName.Length() > 0) @@ -662,7 +490,8 @@ mSavedImageFile.clear(); // image resize is complete. reset the image resize flag - mIsImageResizing = false; + emit contentsChanged(false); + //handle the processed image from ProcessImage Operation handleSetImage(); @@ -671,10 +500,6 @@ void MsgUnifiedEditorBody::startResizeAnimation() { - // emit signal to indicate disable the send tool button. - emit enableSendButton(false); - - QGraphicsLinearLayout* processingLayout = new QGraphicsLinearLayout(Qt::Vertical); mProcessingWidget = new HbWidget(this); @@ -710,73 +535,6 @@ } -// --------------------------------------------------------- -// MsgUnifiedEditorBody::isUnicode -// --------------------------------------------------------- -// -bool MsgUnifiedEditorBody::isUnicode() -{ - return mUnicode; -} - -// --------------------------------------------------------- -// MsgUnifiedEditorBody::disableCharCounter -// --------------------------------------------------------- -// -void MsgUnifiedEditorBody::disableCharCounter() -{ - mCharCounter->setVisible(false); - mBackgroundItem->setVisible(false); -} - -// --------------------------------------------------------- -// MsgUnifiedEditorBody::enableCharCounter -// --------------------------------------------------------- -// -void MsgUnifiedEditorBody::enableCharCounter() - { - mPluginInterface->setEncodingSettings(EFalse, ESmsEncodingNone, - mCharSupportType); - - TInt numOfRemainingChars; - TInt numOfPDUs; - TBool unicodeMode; - TSmsEncoding alternativeEncodingType; - QString string = mTextEdit->toPlainText(); - mPluginInterface->getNumPDUs(string, - numOfRemainingChars, numOfPDUs, unicodeMode, - alternativeEncodingType); - - //Save the unicode value returned - mUnicode = unicodeMode; - - //Set char counter value - QString display = QString("%1(%2)").arg(numOfRemainingChars).arg( - numOfPDUs); - mCharCounter->setText(display); - - if (numOfPDUs > 1 || numOfRemainingChars <= KShowCounterLimit) - { - mCharCounter->setVisible(true); - mBackgroundItem->setVisible(true); - } - else - { - mCharCounter->setVisible(false); - mBackgroundItem->setVisible(false); - } - - } - -//--------------------------------------------------------------- -// MsgUnifiedEditorBody :: setFocus -// @see header file -//--------------------------------------------------------------- -void MsgUnifiedEditorBody::setFocus() -{ - mTextEdit->setFocus(Qt::MouseFocusReason); -} - //--------------------------------------------------------------- // MsgUnifiedEditorBody :: removeMediaContent // @see header file @@ -810,6 +568,6 @@ this->repolish(); - emit contentChanged(); + emit contentsChanged(bodySize()); } // EOF