diff -r 238255e8b033 -r 84d9eb65b26f messagingapp/msgui/unifiededitor/src/msgmonitor.cpp --- a/messagingapp/msgui/unifiededitor/src/msgmonitor.cpp Fri Apr 16 14:56:15 2010 +0300 +++ b/messagingapp/msgui/unifiededitor/src/msgmonitor.cpp Mon May 03 12:29:07 2010 +0300 @@ -11,52 +11,49 @@ * * Contributors: * - * Description: + * Description: Helper class to monitor msg construction in unified editor * */ // INCLUDES #include "debugtraces.h" +#include +#include // USER INCLUDES #include "msgmonitor.h" +#include "msgunieditorview.h" +#include "msgunieditoraddress.h" +#include "msgunieditorsubject.h" #include "msgunieditorbody.h" -#include "msgunieditorsubject.h" #include "msgattachmentcontainer.h" #include "UniEditorGenUtils.h" // Constants // Define static +ConvergedMessage::MessageType MsgMonitor::mMessageType; int MsgMonitor::mBodySize; int MsgMonitor::mContainerSize; int MsgMonitor::mSubjectSize; int MsgMonitor::mMaxMmsSize; +int MsgMonitor::mMaxSmsRecipients; +int MsgMonitor::mMaxMmsRecipients; + +//Localized strings +#define LOC_POP_MESSAGE_CHANGE_MUL hbTrId("txt_messaging_dpopinfo_message_type_changed_to_mul") +#define LOC_POP_MESSAGE_CHANGE_TEXT hbTrId("txt_messaging_dpopinfo_message_type_changed_to_tex") //--------------------------------------------------------------- // MsgMonitor::MsgMonitor // @see header file //--------------------------------------------------------------- MsgMonitor::MsgMonitor(QObject* parent) : -QObject(parent) +QObject(parent), +mSkipNote(false) { init(); -} - -//--------------------------------------------------------------- -// MsgMonitor::init -// @see header file -//--------------------------------------------------------------- -void MsgMonitor::init() -{ - mBodySize = 0; - mContainerSize = 0; - mSubjectSize = 0; - - mMaxMmsSize = 0; - UniEditorGenUtils* uniEditorGenUtils = new UniEditorGenUtils; - mMaxMmsSize = KDefaultMaxSize; - TRAP_IGNORE(mMaxMmsSize = uniEditorGenUtils->MaxMmsMsgSizeL()); + mUniEditorGenUtils = new UniEditorGenUtils; } //--------------------------------------------------------------- @@ -65,87 +62,196 @@ //--------------------------------------------------------------- MsgMonitor::~MsgMonitor() { -} - -//--------------------------------------------------------------- -// MsgMonitor::messageSize -// @see header file -//--------------------------------------------------------------- -int MsgMonitor::messageSize() -{ - return mBodySize + mContainerSize + mSubjectSize; + delete mUniEditorGenUtils; } //--------------------------------------------------------------- -// MsgMonitor::bodySize +// MsgMonitor::init // @see header file //--------------------------------------------------------------- -int MsgMonitor::bodySize() +void MsgMonitor::init() { - return mBodySize; -} + mMessageType = ConvergedMessage::Sms; + mBodySize = 0; + mContainerSize = 0; + mSubjectSize = 0; + + UniEditorGenUtils* uniEditorGenUtils = new UniEditorGenUtils; -//--------------------------------------------------------------- -// MsgMonitor::containerSize -// @see header file -//--------------------------------------------------------------- -int MsgMonitor::containerSize() -{ - return mContainerSize; + mMaxMmsSize = KDefaultMaxSize; + TRAP_IGNORE(mMaxMmsSize = uniEditorGenUtils->MaxMmsMsgSizeL()); + + mMaxSmsRecipients = KDefaultSmsRecipients; + TRAP_IGNORE(mMaxSmsRecipients = uniEditorGenUtils->MaxSmsRecipientsL()); + + mMaxMmsRecipients = KDefaultMmsRecipients; + TRAP_IGNORE(mMaxMmsRecipients = uniEditorGenUtils->MaxMmsRecipientsL()); + + delete uniEditorGenUtils; } //--------------------------------------------------------------- -// MsgMonitor::subjectSize +// MsgMonitor::checkMsgTypeChange // @see header file //--------------------------------------------------------------- -int MsgMonitor::subjectSize() +void MsgMonitor::checkMsgTypeChange() { - return mSubjectSize; + // fetch editor's content + MsgUnifiedEditorBody* edBody = view()->mBody; + QStringList objList = edBody->mediaContent(); + QString bodyText = edBody->text(); + + MsgUnifiedEditorSubject* edSubject = view()->mSubjectField; + ConvergedMessage::Priority priority = ConvergedMessage::Normal; + QString subjectText; + if(edSubject) + { + priority = edSubject->priority(); + subjectText = edSubject->text(); + } + + MsgUnifiedEditorAddress* edCc = view()->mCcField; + MsgUnifiedEditorAddress* edBcc = view()->mBccField; + int ccCount = 0; + int bccCount = 0; + if(edCc && edBcc) + { + ccCount = edCc->addressCount(); + bccCount = edBcc->addressCount(); + } + + MsgAttachmentContainer* edContainer = view()->mAttachmentContainer; + bool hasMMAttachmentContent = false; + int attachmentCount = 0; + if(edContainer) + { + hasMMAttachmentContent = edContainer->hasMMContent(); + attachmentCount = edContainer->count(); + } + + // find out the msgtype based on content + ConvergedMessage::MessageType projectedMsgType = ConvergedMessage::Sms; + + // check for presence of MMS content + // 1. If any media-object is present inside body + // 2. If priority is set to other than Normal + // 3. If subject has some content + // 4. If CC/BCC has some content + // 5. If MM attachments are present + // 6. If only one non-MM attachment is present e.g. vcf + // and body text is also present + // 7. If body text size exceeds sms text-size limit + if( !objList.isEmpty() || + (priority != ConvergedMessage::Normal) || + !subjectText.isEmpty() || + (ccCount || bccCount) || + hasMMAttachmentContent || + ((attachmentCount == 1) && !bodyText.isEmpty()) + ) + { + projectedMsgType = ConvergedMessage::Mms; + } + else + { + projectedMsgType = ConvergedMessage::Sms; + } + + // optimization 1: if projected type is still sms means + // the message under composition has only plain text + if(projectedMsgType == ConvergedMessage::Sms) + { + bool hasUnicodeText = edBody->isUnicode(); + int bodyTextSize = mUniEditorGenUtils->UTF8Size(bodyText); + int maxSmsSize = mUniEditorGenUtils->MaxSmsMsgSizeL(hasUnicodeText); + if(bodyTextSize > maxSmsSize) + { + projectedMsgType = ConvergedMessage::Mms; + } + } + + // show type change note, if needed + if(mMessageType != projectedMsgType) + { + mMessageType = projectedMsgType; + QString noteStr; + if(projectedMsgType == ConvergedMessage::Sms) + { + noteStr = LOC_POP_MESSAGE_CHANGE_TEXT; + } + else + { + noteStr = LOC_POP_MESSAGE_CHANGE_MUL; + + //Disable char counter + edBody->disableCharCounter(); + } + showPopup(noteStr); + } + + // update size of editor component + HbWidget* senderWidget = qobject_cast(sender()); + updateSizeInfo(senderWidget); } //--------------------------------------------------------------- -// MsgMonitor::maxMmsSize -// @see header file -//--------------------------------------------------------------- -int MsgMonitor::maxMmsSize() -{ - return mMaxMmsSize; -} - -//--------------------------------------------------------------- -// MsgMonitor::onSizeChanged +// MsgMonitor::updateSizeInfo // @see header file //--------------------------------------------------------------- -void MsgMonitor::onSizeChanged(int aSize) +void MsgMonitor::updateSizeInfo(HbWidget* aWidget) { - // TODO: implement this correctly - HbWidget* senderWidget = qobject_cast(sender()); - // if sent by body widget MsgUnifiedEditorBody* body = NULL; - body = qobject_cast(senderWidget); + body = qobject_cast(aWidget); if(body) { - mBodySize = aSize; + mBodySize = view()->mBody->bodySize(); return; } // if sent by attachment container widget MsgAttachmentContainer* container = NULL; - container = qobject_cast(senderWidget); + container = qobject_cast(aWidget); if(container) { - mContainerSize = aSize; + mContainerSize = view()->mAttachmentContainer->containerSize(); return; } // if sent by subject widget MsgUnifiedEditorSubject* subject = NULL; - subject = qobject_cast(senderWidget); + subject = qobject_cast(aWidget); if(subject) { - mSubjectSize = aSize; + mSubjectSize = view()->mSubjectField->subjectSize(); } } +//--------------------------------------------------------------- +// MsgMonitor::showPopup +// @see header file +//--------------------------------------------------------------- +void MsgMonitor::showPopup(const QString& text) +{ + if(!mSkipNote) + { + HbNotificationDialog* dlg = new HbNotificationDialog(); + dlg->setFocusPolicy(Qt::NoFocus); + dlg->setDismissPolicy(HbPopup::TapAnywhere); + dlg->setAttribute(Qt::WA_DeleteOnClose, true); + dlg->setText(text); + dlg->show(); + } + // reset skip note flag + mSkipNote = false; +} + +//--------------------------------------------------------------- +// MsgMonitor::view +// @see header file +//--------------------------------------------------------------- +MsgUnifiedEditorView* MsgMonitor::view() +{ + return static_cast(this->parent()); +} + //EOF