messagingapp/msgui/unifiededitor/src/msgmonitor.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 38 4e4b6adb1024
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
     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: Helper class to monitor msg construction in unified editor
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDES
       
    19 #include "debugtraces.h"
       
    20 #include <HbNotificationDialog>
       
    21 #include <HbWidget>
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "msgmonitor.h"
       
    25 #include "msgunieditorview.h"
       
    26 #include "msgunieditoraddress.h"
       
    27 #include "msgunieditorsubject.h"
       
    28 #include "msgunieditorbody.h"
       
    29 #include "msgattachmentcontainer.h"
       
    30 #include "UniEditorGenUtils.h"
       
    31 
       
    32 // Constants
       
    33 
       
    34 // Define static
       
    35 ConvergedMessage::MessageType MsgMonitor::mMessageType;
       
    36 int MsgMonitor::mBodySize;
       
    37 int MsgMonitor::mContainerSize;
       
    38 int MsgMonitor::mSubjectSize;
       
    39 int MsgMonitor::mMaxMmsSize;
       
    40 int MsgMonitor::mMaxSmsRecipients;
       
    41 int MsgMonitor::mMaxMmsRecipients;
       
    42 
       
    43 //Localized strings
       
    44 #define LOC_POP_MESSAGE_CHANGE_MUL hbTrId("txt_messaging_dpopinfo_message_type_changed_to_mul")
       
    45 #define LOC_POP_MESSAGE_CHANGE_TEXT hbTrId("txt_messaging_dpopinfo_message_type_changed_to_tex")
       
    46 
       
    47 //---------------------------------------------------------------
       
    48 // MsgMonitor::MsgMonitor
       
    49 // @see header file
       
    50 //---------------------------------------------------------------
       
    51 MsgMonitor::MsgMonitor(QObject* parent) :
       
    52 QObject(parent),
       
    53 mSkipNote(false)
       
    54 {
       
    55     init();
       
    56     mUniEditorGenUtils = new UniEditorGenUtils;
       
    57 }
       
    58 
       
    59 //---------------------------------------------------------------
       
    60 // MsgMonitor::~MsgMonitor
       
    61 // @see header file
       
    62 //---------------------------------------------------------------
       
    63 MsgMonitor::~MsgMonitor()
       
    64 {
       
    65     delete mUniEditorGenUtils;
       
    66 }
       
    67 
       
    68 //---------------------------------------------------------------
       
    69 // MsgMonitor::init
       
    70 // @see header file
       
    71 //---------------------------------------------------------------
       
    72 void MsgMonitor::init()
       
    73 {
       
    74     mMessageType = ConvergedMessage::Sms;
       
    75     mBodySize = 0;
       
    76     mContainerSize = 0;
       
    77     mSubjectSize = 0;
       
    78 
       
    79     UniEditorGenUtils* uniEditorGenUtils = new UniEditorGenUtils;
       
    80 
       
    81     mMaxMmsSize = KDefaultMaxSize;
       
    82     TRAP_IGNORE(mMaxMmsSize = uniEditorGenUtils->MaxMmsMsgSizeL());
       
    83 
       
    84     mMaxSmsRecipients = KDefaultSmsRecipients;
       
    85     TRAP_IGNORE(mMaxSmsRecipients = uniEditorGenUtils->MaxSmsRecipientsL());
       
    86 
       
    87     mMaxMmsRecipients = KDefaultMmsRecipients;
       
    88     TRAP_IGNORE(mMaxMmsRecipients = uniEditorGenUtils->MaxMmsRecipientsL());
       
    89 
       
    90     delete uniEditorGenUtils;
       
    91 }
       
    92 
       
    93 //---------------------------------------------------------------
       
    94 // MsgMonitor::checkMsgTypeChange
       
    95 // @see header file
       
    96 //---------------------------------------------------------------
       
    97 void MsgMonitor::checkMsgTypeChange()
       
    98 {
       
    99     // fetch editor's content 
       
   100     MsgUnifiedEditorBody* edBody = view()->mBody;
       
   101     QStringList objList = edBody->mediaContent();
       
   102     QString bodyText = edBody->text();
       
   103     
       
   104     MsgUnifiedEditorSubject* edSubject = view()->mSubjectField;
       
   105     ConvergedMessage::Priority priority = ConvergedMessage::Normal;
       
   106     QString subjectText;
       
   107     if(edSubject)
       
   108     {
       
   109         priority = edSubject->priority();
       
   110         subjectText = edSubject->text();
       
   111     }
       
   112 
       
   113     MsgUnifiedEditorAddress* edCc = view()->mCcField;
       
   114     MsgUnifiedEditorAddress* edBcc = view()->mBccField;
       
   115     int ccCount = 0;
       
   116     int bccCount = 0;
       
   117     if(edCc && edBcc)
       
   118     {
       
   119         ccCount = edCc->addressCount();
       
   120         bccCount = edBcc->addressCount();
       
   121     }
       
   122     
       
   123     MsgAttachmentContainer* edContainer = view()->mAttachmentContainer;
       
   124     bool hasMMAttachmentContent = false;
       
   125     int attachmentCount = 0;
       
   126     if(edContainer)
       
   127     {
       
   128         hasMMAttachmentContent = edContainer->hasMMContent();
       
   129         attachmentCount = edContainer->count();
       
   130     }
       
   131 
       
   132     // find out the msgtype based on content
       
   133     ConvergedMessage::MessageType projectedMsgType = ConvergedMessage::Sms;
       
   134 
       
   135     // check for presence of MMS content
       
   136     // 1. If any media-object is present inside body
       
   137     // 2. If priority is set to other than Normal
       
   138     // 3. If subject has some content
       
   139     // 4. If CC/BCC has some content
       
   140     // 5. If MM attachments are present
       
   141     // 6. If only one non-MM attachment is present e.g. vcf 
       
   142     //    and body text is also present
       
   143     // 7. If body text size exceeds sms text-size limit
       
   144     if( !objList.isEmpty() || 
       
   145         (priority != ConvergedMessage::Normal) || 
       
   146         !subjectText.isEmpty() ||
       
   147         (ccCount || bccCount) ||
       
   148         hasMMAttachmentContent ||
       
   149         ((attachmentCount == 1) && !bodyText.isEmpty())
       
   150       )
       
   151     {
       
   152         projectedMsgType = ConvergedMessage::Mms;
       
   153     }
       
   154     else
       
   155     {
       
   156         projectedMsgType = ConvergedMessage::Sms;
       
   157     }
       
   158 
       
   159     // optimization 1: if projected type is still sms means
       
   160     // the message under composition has only plain text
       
   161     if(projectedMsgType == ConvergedMessage::Sms)
       
   162     {
       
   163         bool hasUnicodeText = edBody->isUnicode();
       
   164         int bodyTextSize = mUniEditorGenUtils->UTF8Size(bodyText);
       
   165         int maxSmsSize = mUniEditorGenUtils->MaxSmsMsgSizeL(hasUnicodeText);
       
   166         if(bodyTextSize > maxSmsSize)
       
   167         {
       
   168             projectedMsgType = ConvergedMessage::Mms;
       
   169         }
       
   170     }
       
   171         
       
   172     // show type change note, if needed
       
   173     if(mMessageType != projectedMsgType)
       
   174     {
       
   175         mMessageType = projectedMsgType;
       
   176         QString noteStr;
       
   177         if(projectedMsgType == ConvergedMessage::Sms)
       
   178         {
       
   179             noteStr = LOC_POP_MESSAGE_CHANGE_TEXT;
       
   180         }
       
   181         else
       
   182         {
       
   183             noteStr = LOC_POP_MESSAGE_CHANGE_MUL;
       
   184             
       
   185             //Disable char counter
       
   186             edBody->disableCharCounter();
       
   187         }
       
   188         showPopup(noteStr);
       
   189     }
       
   190     
       
   191     // update size of editor component
       
   192     HbWidget* senderWidget = qobject_cast<HbWidget*>(sender());
       
   193     updateSizeInfo(senderWidget);
       
   194 }
       
   195 
       
   196 //---------------------------------------------------------------
       
   197 // MsgMonitor::updateSizeInfo
       
   198 // @see header file
       
   199 //---------------------------------------------------------------
       
   200 void MsgMonitor::updateSizeInfo(HbWidget* aWidget)
       
   201 {
       
   202     // if sent by body widget
       
   203     MsgUnifiedEditorBody* body = NULL;    
       
   204     body = qobject_cast<MsgUnifiedEditorBody*>(aWidget);
       
   205     if(body)
       
   206     {
       
   207         mBodySize = view()->mBody->bodySize();
       
   208         return;
       
   209     }
       
   210     
       
   211     // if sent by attachment container widget
       
   212     MsgAttachmentContainer* container = NULL;
       
   213     container = qobject_cast<MsgAttachmentContainer*>(aWidget);
       
   214     if(container)
       
   215     {
       
   216         mContainerSize = view()->mAttachmentContainer->containerSize();
       
   217         return;
       
   218     }
       
   219 
       
   220     // if sent by subject widget
       
   221     MsgUnifiedEditorSubject* subject = NULL;
       
   222     subject = qobject_cast<MsgUnifiedEditorSubject*>(aWidget);
       
   223     if(subject)
       
   224     {
       
   225         mSubjectSize = view()->mSubjectField->subjectSize();
       
   226     }
       
   227 }
       
   228 
       
   229 //---------------------------------------------------------------
       
   230 // MsgMonitor::showPopup
       
   231 // @see header file
       
   232 //---------------------------------------------------------------
       
   233 void MsgMonitor::showPopup(const QString& text)
       
   234 {
       
   235     if(!mSkipNote)
       
   236     {
       
   237         HbNotificationDialog* dlg = new HbNotificationDialog();
       
   238         dlg->setFocusPolicy(Qt::NoFocus);
       
   239         dlg->setDismissPolicy(HbPopup::TapAnywhere);
       
   240         dlg->setAttribute(Qt::WA_DeleteOnClose, true);
       
   241         dlg->setText(text);
       
   242         dlg->show();
       
   243     }
       
   244     // reset skip note flag
       
   245     mSkipNote = false;
       
   246 }
       
   247 
       
   248 //---------------------------------------------------------------
       
   249 // MsgMonitor::view
       
   250 // @see header file
       
   251 //---------------------------------------------------------------
       
   252 MsgUnifiedEditorView* MsgMonitor::view()
       
   253 {
       
   254     return static_cast<MsgUnifiedEditorView*>(this->parent());
       
   255 }
       
   256 
       
   257 //EOF