messagingapp/msgui/unifiededitor/src/msgunieditormonitor.cpp
changeset 76 60a8a215b0ec
parent 48 4f501b74aeb1
equal deleted inserted replaced
73:ecf6a73a9186 76:60a8a215b0ec
    16  */
    16  */
    17 
    17 
    18 // INCLUDES
    18 // INCLUDES
    19 #include "debugtraces.h"
    19 #include "debugtraces.h"
    20 #include <HbNotificationDialog>
    20 #include <HbNotificationDialog>
    21 #include <HbWidget>
       
    22 
    21 
    23 // USER INCLUDES
    22 // USER INCLUDES
    24 #include "msgunieditormonitor.h"
    23 #include "msgunieditormonitor.h"
    25 #include "msgunieditorview.h"
       
    26 #include "msgunieditoraddress.h"
       
    27 #include "msgunieditorsubject.h"
       
    28 #include "msgunieditorbody.h"
       
    29 #include "msgunieditorattachmentcontainer.h"
       
    30 #include "UniEditorGenUtils.h"
    24 #include "UniEditorGenUtils.h"
    31 
    25 
    32 // Constants
    26 // Constants
    33 
    27 
    34 // Define static
    28 // Define static
    35 ConvergedMessage::MessageType MsgUnifiedEditorMonitor::mMessageType;
    29 ConvergedMessage::MessageType MsgUnifiedEditorMonitor::mMessageType = ConvergedMessage::Sms;
    36 int MsgUnifiedEditorMonitor::mBodySize;
    30 int MsgUnifiedEditorMonitor::mBodySize = 0;
    37 int MsgUnifiedEditorMonitor::mContainerSize;
    31 int MsgUnifiedEditorMonitor::mBodyTextSize = 0;
    38 int MsgUnifiedEditorMonitor::mSubjectSize;
    32 int MsgUnifiedEditorMonitor::mContainerSize = 0;
    39 int MsgUnifiedEditorMonitor::mMaxMmsSize;
    33 int MsgUnifiedEditorMonitor::mBodyContentSize = 0;
    40 int MsgUnifiedEditorMonitor::mMaxSmsRecipients;
    34 int MsgUnifiedEditorMonitor::mSubjectSize = 0;
    41 int MsgUnifiedEditorMonitor::mMaxMmsRecipients;
    35 int MsgUnifiedEditorMonitor::mMaxMmsSize = 0;
    42 int MsgUnifiedEditorMonitor::mMsgCurrAddressCount;
    36 int MsgUnifiedEditorMonitor::mMaxSmsRecipients = 0;
       
    37 int MsgUnifiedEditorMonitor::mMaxMmsRecipients = 0;
       
    38 int MsgUnifiedEditorMonitor::mToAddressCount = 0;
       
    39 int MsgUnifiedEditorMonitor::mCcAddressCount = 0;
       
    40 int MsgUnifiedEditorMonitor::mBccAddressCount = 0;
       
    41 bool MsgUnifiedEditorMonitor::mReadyForSend = false;
    43 
    42 
    44 //Localized strings
    43 //Localized strings
    45 #define LOC_POP_MESSAGE_CHANGE_MUL hbTrId("txt_messaging_dpopinfo_message_type_changed_to_mul")
    44 #define LOC_POP_MESSAGE_CHANGE_MUL hbTrId("txt_messaging_dpopinfo_message_type_changed_to_mul")
    46 #define LOC_POP_MESSAGE_CHANGE_TEXT hbTrId("txt_messaging_dpopinfo_message_type_changed_to_tex")
    45 #define LOC_POP_MESSAGE_CHANGE_TEXT hbTrId("txt_messaging_dpopinfo_message_type_changed_to_tex")
    47 
    46 
    49 // MsgUnifiedEditorMonitor::MsgUnifiedEditorMonitor
    48 // MsgUnifiedEditorMonitor::MsgUnifiedEditorMonitor
    50 // @see header file
    49 // @see header file
    51 //---------------------------------------------------------------
    50 //---------------------------------------------------------------
    52 MsgUnifiedEditorMonitor::MsgUnifiedEditorMonitor(QObject* parent) :
    51 MsgUnifiedEditorMonitor::MsgUnifiedEditorMonitor(QObject* parent) :
    53 QObject(parent),
    52 QObject(parent),
    54 mSkipNote(false)
    53 mSkipNote(false),
       
    54 mContainerHasMmsContent(false),
       
    55 mPriority(ConvergedMessage::Normal),
       
    56 mEmailPresent(false),
       
    57 mUniCode(false),
       
    58 mImageResizing(false)
    55 {    
    59 {    
    56     mUniEditorGenUtils = q_check_ptr( new UniEditorGenUtils);
    60     mUniEditorGenUtils = q_check_ptr( new UniEditorGenUtils);
    57     init(); 
    61     init(); 
    58 }
    62 }
    59 
    63 
    61 // MsgUnifiedEditorMonitor::~MsgUnifiedEditorMonitor
    65 // MsgUnifiedEditorMonitor::~MsgUnifiedEditorMonitor
    62 // @see header file
    66 // @see header file
    63 //---------------------------------------------------------------
    67 //---------------------------------------------------------------
    64 MsgUnifiedEditorMonitor::~MsgUnifiedEditorMonitor()
    68 MsgUnifiedEditorMonitor::~MsgUnifiedEditorMonitor()
    65 {
    69 {
       
    70     reset();
    66     delete mUniEditorGenUtils;
    71     delete mUniEditorGenUtils;
    67 }
    72 }
    68 
    73 
    69 //---------------------------------------------------------------
    74 //---------------------------------------------------------------
    70 // MsgUnifiedEditorMonitor::init
    75 // MsgUnifiedEditorMonitor::reset
    71 // @see header file
    76 // @see header file
    72 //---------------------------------------------------------------
    77 //---------------------------------------------------------------
    73 void MsgUnifiedEditorMonitor::init()
    78 void MsgUnifiedEditorMonitor::reset()
    74 {
    79 {
    75     mMessageType = ConvergedMessage::Sms;
    80     mMessageType = ConvergedMessage::Sms;
    76     mBodySize = 0;
    81     mBodySize = 0;
       
    82     mBodyTextSize = 0;
    77     mContainerSize = 0;
    83     mContainerSize = 0;
       
    84     mBodyContentSize = 0;
    78     mSubjectSize = 0;
    85     mSubjectSize = 0;
    79     mMsgCurrAddressCount = 0;
    86     mMaxMmsSize = 0;
    80 
    87     mMaxSmsRecipients = 0;
       
    88     mMaxMmsRecipients = 0;
       
    89     mToAddressCount = 0;
       
    90     mCcAddressCount = 0;
       
    91     mBccAddressCount = 0;
       
    92     mReadyForSend = false;
       
    93 }
       
    94 
       
    95 //---------------------------------------------------------------
       
    96 // MsgUnifiedEditorMonitor::init
       
    97 // @see header file
       
    98 //---------------------------------------------------------------
       
    99 void MsgUnifiedEditorMonitor::init()
       
   100 {
    81     mMaxMmsSize = KDefaultMaxSize;
   101     mMaxMmsSize = KDefaultMaxSize;
       
   102    
    82     TRAP_IGNORE(mMaxMmsSize = mUniEditorGenUtils->MaxMmsMsgSizeL());
   103     TRAP_IGNORE(mMaxMmsSize = mUniEditorGenUtils->MaxMmsMsgSizeL());
    83 
   104 
    84     mMaxSmsRecipients = KDefaultSmsRecipients;
   105     mMaxSmsRecipients = KDefaultSmsRecipients;
    85     TRAP_IGNORE(mMaxSmsRecipients = mUniEditorGenUtils->MaxSmsRecipientsL());
   106     TRAP_IGNORE(mMaxSmsRecipients = mUniEditorGenUtils->MaxSmsRecipientsL());
    86 
   107 
    87     mMaxMmsRecipients = KDefaultMmsRecipients;
   108     mMaxMmsRecipients = KDefaultMmsRecipients;
    88     TRAP_IGNORE(mMaxMmsRecipients = mUniEditorGenUtils->MaxMmsRecipientsL());
   109     TRAP_IGNORE(mMaxMmsRecipients = mUniEditorGenUtils->MaxMmsRecipientsL());
    89 }
   110 }
    90 
   111 
    91 //---------------------------------------------------------------
   112 //---------------------------------------------------------------
    92 // MsgUnifiedEditorMonitor::handleContentChange
   113 // MsgUnifiedEditorMonitor::handleContentsChanged
    93 // @see header file
   114 // @see header file
    94 //---------------------------------------------------------------
   115 //---------------------------------------------------------------
    95 void MsgUnifiedEditorMonitor::handleContentChange()
   116 void MsgUnifiedEditorMonitor::handleContentsChanged(const QVariant& data)
    96 {
   117 {
       
   118     QString objectName = sender()->objectName();
       
   119     
       
   120     if(objectName == "attachmentContainer")
       
   121     {
       
   122         QVariantList dataList = data.toList();
       
   123         mContainerSize = dataList.at(0).toInt();
       
   124         mContainerHasMmsContent = dataList.at(1).toBool();        
       
   125     }
       
   126 
       
   127     if(objectName == "body")
       
   128     {
       
   129         if(data.type() == QVariant::Bool)
       
   130         {
       
   131           mImageResizing = data.toBool();
       
   132         }
       
   133         else
       
   134         {
       
   135         mBodySize = data.toInt();
       
   136         updateBodyContentSize();
       
   137         }
       
   138     }
       
   139     
       
   140     if(objectName == "bodyText")
       
   141     {
       
   142         QVariantList dataList = data.toList();
       
   143         mBodyTextSize = dataList.at(0).toInt();
       
   144         mUniCode = dataList.at(1).toBool(); 
       
   145         updateBodyContentSize();
       
   146         
       
   147     }
       
   148     
       
   149     if(objectName == "subject")
       
   150     {
       
   151         QVariantList dataList = data.toList();
       
   152         mSubjectSize = dataList.at(0).toInt();
       
   153         mPriority = ConvergedMessage::Priority(dataList.at(1).toInt());
       
   154         
       
   155     }
       
   156     
       
   157     if(objectName == "to")
       
   158     {
       
   159         QVariantList dataList = data.toList();
       
   160         mToAddressCount = dataList.at(0).toInt();
       
   161         mEmailPresent = dataList.at(1).toBool();        
       
   162     }
       
   163     
       
   164     if(objectName == "cc")
       
   165     {
       
   166         QVariantList dataList = data.toList();
       
   167         mCcAddressCount = dataList.at(0).toInt();
       
   168     }
       
   169     
       
   170     if(objectName == "bcc")
       
   171     {
       
   172         QVariantList dataList = data.toList();
       
   173         mBccAddressCount = dataList.at(0).toInt(); 
       
   174     }
       
   175     
    97     // get the projected message type & show the type change note
   176     // get the projected message type & show the type change note
    98     ConvergedMessage::MessageType newMsgType = projectedMsgType();    
   177     ConvergedMessage::MessageType newMsgType = projectedMsgType();    
    99     if(mMessageType != newMsgType)
   178     if(mMessageType != newMsgType)
   100     {
   179     {
   101         mMessageType = newMsgType;
   180         mMessageType = newMsgType;
   108         {
   187         {
   109             noteStr = LOC_POP_MESSAGE_CHANGE_MUL;
   188             noteStr = LOC_POP_MESSAGE_CHANGE_MUL;
   110         }
   189         }
   111         showPopup(noteStr);
   190         showPopup(noteStr);
   112     }
   191     }
   113 
   192     
   114     HbWidget* senderWidget = qobject_cast<HbWidget*>(sender());
       
   115     updateMsgInfo(senderWidget);
       
   116     updateSend();
   193     updateSend();
       
   194     
       
   195     //emit when content is modified after opening a draft message.
       
   196     if(!mSkipNote)
       
   197     {
       
   198     emit contentsChanged();
       
   199     }
   117 }
   200 }
   118 
   201 
   119 //---------------------------------------------------------------
   202 //---------------------------------------------------------------
   120 // MsgUnifiedEditorMonitor::projectedMsgType
   203 // MsgUnifiedEditorMonitor::projectedMsgType
   121 // @see header file
   204 // @see header file
   131         otherMMSCriteriaMet() )
   214         otherMMSCriteriaMet() )
   132     {
   215     {
   133         newMsgType = ConvergedMessage::Mms;
   216         newMsgType = ConvergedMessage::Mms;
   134     }
   217     }
   135     return newMsgType;
   218     return newMsgType;
   136 }
       
   137 
       
   138 //---------------------------------------------------------------
       
   139 // MsgUnifiedEditorMonitor::updateMsgInfo
       
   140 // @see header file
       
   141 //---------------------------------------------------------------
       
   142 void MsgUnifiedEditorMonitor::updateMsgInfo(HbWidget* senderWidget)
       
   143 {
       
   144     if(mMessageType == ConvergedMessage::Mms)
       
   145     {
       
   146         //Disable char counter & add subject
       
   147         view()->mBody->disableCharCounter();
       
   148         view()->addSubject();
       
   149     }
       
   150     else
       
   151     {
       
   152         //Enable char counter
       
   153         view()->mBody->enableCharCounter();    
       
   154     }
       
   155 
       
   156     // check if sent by body widget
       
   157     MsgUnifiedEditorBody* body = NULL;
       
   158     body = qobject_cast<MsgUnifiedEditorBody*>(senderWidget);
       
   159     if(body)
       
   160     {
       
   161         mBodySize = view()->mBody->bodySize();
       
   162         view()->setAttachOptionEnabled(
       
   163                 MsgUnifiedEditorView::TBE_PHOTO, !view()->mBody->hasImage());
       
   164         view()->setAttachOptionEnabled(
       
   165                 MsgUnifiedEditorView::TBE_SOUND, !view()->mBody->hasAudio());
       
   166         return;
       
   167     }
       
   168     
       
   169     // check if sent by subject widget
       
   170     MsgUnifiedEditorSubject* subject = NULL;
       
   171     subject = qobject_cast<MsgUnifiedEditorSubject*>(senderWidget);
       
   172     if(subject)
       
   173     {
       
   174         mSubjectSize = view()->mSubjectField->subjectSize();
       
   175         return;
       
   176     }
       
   177 
       
   178     // check if sent by attachment container widget
       
   179     MsgAttachmentContainer* container = NULL;
       
   180     container = qobject_cast<MsgAttachmentContainer*>(senderWidget);
       
   181     if(container)
       
   182     {
       
   183         mContainerSize = view()->mAttachmentContainer->containerSize();
       
   184         return;
       
   185     }
       
   186 
       
   187     // handle content change from other widgets e.g. To, Cc, Bcc address field
       
   188     int totalAddressCount = view()->mToField->addressCount();
       
   189     if(view()->mCcField && view()->mBccField)
       
   190     {
       
   191         totalAddressCount += view()->mCcField->addressCount() +
       
   192                 view()->mBccField->addressCount();
       
   193     }
       
   194     mMsgCurrAddressCount = totalAddressCount;
       
   195     return;
       
   196 }
   219 }
   197 
   220 
   198 //---------------------------------------------------------------
   221 //---------------------------------------------------------------
   199 // MsgUnifiedEditorMonitor::showPopup
   222 // MsgUnifiedEditorMonitor::showPopup
   200 // @see header file
   223 // @see header file
   213     // reset skip note flag
   236     // reset skip note flag
   214     mSkipNote = false;
   237     mSkipNote = false;
   215 }
   238 }
   216 
   239 
   217 //---------------------------------------------------------------
   240 //---------------------------------------------------------------
   218 // MsgUnifiedEditorMonitor::view
       
   219 // @see header file
       
   220 //---------------------------------------------------------------
       
   221 MsgUnifiedEditorView* MsgUnifiedEditorMonitor::view()
       
   222 {
       
   223     return static_cast<MsgUnifiedEditorView*>(this->parent());
       
   224 }
       
   225 
       
   226 //---------------------------------------------------------------
       
   227 // MsgUnifiedEditorMonitor::bodyHasMMSContent
   241 // MsgUnifiedEditorMonitor::bodyHasMMSContent
   228 // @see header file
   242 // @see header file
   229 //---------------------------------------------------------------
   243 //---------------------------------------------------------------
   230 bool MsgUnifiedEditorMonitor::bodyHasMMSContent()
   244 bool MsgUnifiedEditorMonitor::bodyHasMMSContent()
   231 {
   245 {
   232     MsgUnifiedEditorBody* edBody = view()->mBody;
   246     bool result = false;
   233     // If any media-object is present inside body
   247 
   234     if(!edBody->mediaContent().isEmpty())
       
   235     {
       
   236         return true;
       
   237     }
       
   238     
       
   239     int bodyTextSize = mUniEditorGenUtils->UTF8Size(edBody->text());
       
   240     int maxSmsSize = 0;
   248     int maxSmsSize = 0;
   241     TRAP_IGNORE(maxSmsSize = 
   249     TRAP_IGNORE(maxSmsSize = mUniEditorGenUtils->MaxSmsMsgSizeL(mUniCode));
   242            mUniEditorGenUtils->MaxSmsMsgSizeL(edBody->isUnicode()));
   250 
   243     // If body text size exceeds sms text-size limit
   251     // If body text size exceeds sms text-size limit
   244     if(bodyTextSize > maxSmsSize)
   252     if( mBodyTextSize > maxSmsSize || mBodySize)
   245     {
   253     {
   246         return true;
   254         result = true;
   247     }
   255     }
   248     return false;
   256 
       
   257     return result;
   249 }
   258 }
   250 
   259 
   251 //---------------------------------------------------------------
   260 //---------------------------------------------------------------
   252 // MsgUnifiedEditorMonitor::subjectHasMMSContent
   261 // MsgUnifiedEditorMonitor::subjectHasMMSContent
   253 // @see header file
   262 // @see header file
   254 //---------------------------------------------------------------
   263 //---------------------------------------------------------------
   255 bool MsgUnifiedEditorMonitor::subjectHasMMSContent()
   264 bool MsgUnifiedEditorMonitor::subjectHasMMSContent()
   256 {
   265 {
   257     MsgUnifiedEditorSubject* edSubject = view()->mSubjectField;
   266     bool result = false;
   258     ConvergedMessage::Priority priority = ConvergedMessage::Normal;
   267     if(mPriority != ConvergedMessage::Normal || mSubjectSize)
   259     QString subjectText;
   268     {
   260     if(edSubject)
   269         result =  true;
   261     {
   270     }
   262         priority = edSubject->priority();
   271     
   263         subjectText = edSubject->text();
   272     return result;
   264     }
       
   265     // If priority is set to other than Normal or
       
   266     // If subject has some content
       
   267     if( (priority != ConvergedMessage::Normal) ||
       
   268         !subjectText.isEmpty() )
       
   269     {
       
   270         return true;
       
   271     }
       
   272     return false;
       
   273 }
   273 }
   274 
   274 
   275 //---------------------------------------------------------------
   275 //---------------------------------------------------------------
   276 // MsgUnifiedEditorMonitor::containerHasMMSContent
   276 // MsgUnifiedEditorMonitor::containerHasMMSContent
   277 // @see header file
   277 // @see header file
   278 //---------------------------------------------------------------
   278 //---------------------------------------------------------------
   279 bool MsgUnifiedEditorMonitor::containerHasMMSContent()
   279 bool MsgUnifiedEditorMonitor::containerHasMMSContent()
   280 {
   280 {
   281     QString bodyText = view()->mBody->text();
   281     bool result = false;
   282     MsgAttachmentContainer* edContainer = view()->mAttachmentContainer;
   282     
   283     bool hasMMAttachmentContent = false;
   283     if(mContainerHasMmsContent || mContainerSize && mBodyTextSize)
   284     int attachmentCount = 0;
   284     {
   285     if(edContainer)
   285         result = true;
   286     {
   286     }
   287         hasMMAttachmentContent = edContainer->hasMMContent();
   287     
   288         attachmentCount = edContainer->count();
   288     return result;
   289     }
       
   290     // If MM attachments are present or
       
   291     // If only one non-MM attachment is present e.g. vcf along with body text
       
   292     if( hasMMAttachmentContent ||
       
   293         ((attachmentCount == 1) && !bodyText.isEmpty()) )
       
   294     {
       
   295         return true;
       
   296     }
       
   297     return false;
       
   298 }
   289 }
   299 
   290 
   300 //---------------------------------------------------------------
   291 //---------------------------------------------------------------
   301 // MsgUnifiedEditorMonitor::otherMMSCriteriaMet
   292 // MsgUnifiedEditorMonitor::otherMMSCriteriaMet
   302 // @see header file
   293 // @see header file
   303 //---------------------------------------------------------------
   294 //---------------------------------------------------------------
   304 bool MsgUnifiedEditorMonitor::otherMMSCriteriaMet()
   295 bool MsgUnifiedEditorMonitor::otherMMSCriteriaMet()
   305 {
   296 {
   306     MsgUnifiedEditorAddress* edCc = view()->mCcField;
   297     bool result = false;
   307     MsgUnifiedEditorAddress* edBcc = view()->mBccField;
   298     
   308     int ccCount = 0;
   299     if(mCcAddressCount || mBccAddressCount || mEmailPresent ||
   309     int bccCount = 0;
   300        mToAddressCount > mMaxSmsRecipients)
   310     if(edCc && edBcc)
   301     {
   311     {
   302         result = true;
   312         ccCount = edCc->addressCount();
   303     }
   313         bccCount = edBcc->addressCount();
   304     return result;
   314     }
       
   315     // If CC/BCC has some content or
       
   316     // If to-recipients count exceeds max sms recipient count
       
   317     if( ccCount || bccCount ||
       
   318         (view()->mToField->addressCount() > mMaxSmsRecipients) )
       
   319     {
       
   320         return true;
       
   321     }
       
   322     
       
   323     // If to-field contains an email address
       
   324     bool isEmailPresent = false;
       
   325     ConvergedMessageAddressList addrList = view()->mToField->addresses();
       
   326     TRAP_IGNORE(isEmailPresent = mUniEditorGenUtils->VerifyEmailAddressesL(addrList));
       
   327     if(isEmailPresent)
       
   328     {
       
   329         return true;
       
   330     }
       
   331     return false;
       
   332 }
   305 }
   333 
   306 
   334 //---------------------------------------------------------------
   307 //---------------------------------------------------------------
   335 // MsgUnifiedEditorMonitor::updateSend
   308 // MsgUnifiedEditorMonitor::updateSend
   336 // @see header file
   309 // @see header file
   337 //---------------------------------------------------------------
   310 //---------------------------------------------------------------
   338 void MsgUnifiedEditorMonitor::updateSend()
   311 void MsgUnifiedEditorMonitor::updateSend()
   339 {
   312 {
   340     if (mMsgCurrAddressCount > 0 && (mSubjectSize + mBodySize + mContainerSize) > 0 && !view()->mBody->isImageResizing())
   313 
       
   314     if ( (mToAddressCount + mCcAddressCount + mBccAddressCount) > 0 &&
       
   315          (mSubjectSize + mBodyContentSize + mContainerSize) > 0 &&
       
   316          !mImageResizing )
   341     {
   317     {
   342         emit enableSend(true);
   318         emit enableSend(true);
       
   319         mReadyForSend = true;
   343     }
   320     }
   344     else
   321     else
   345     {
   322     {
   346         emit enableSend(false);
   323         emit enableSend(false);
   347     }
   324         mReadyForSend = false;
   348 }
   325     }
   349 
   326 
       
   327 }
       
   328 
       
   329 void MsgUnifiedEditorMonitor::updateBodyContentSize()
       
   330 {
       
   331     if(mBodySize || mBodyTextSize)
       
   332     {
       
   333         mBodyContentSize = mBodySize + mBodyTextSize + KEstimatedMimeHeaderSize 
       
   334                            + KEstimatedMmsSmilHeaderSize;
       
   335     }
       
   336     else
       
   337     {
       
   338         mBodyContentSize = 0; 
       
   339     }
       
   340 }
   350 
   341 
   351 //EOF
   342 //EOF