messagingapp/msgui/unifiededitor/src/msgunieditorscrollarea.cpp
changeset 76 60a8a215b0ec
equal deleted inserted replaced
73:ecf6a73a9186 76:60a8a215b0ec
       
     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: manages scrollable portion of view.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "msgunieditorscrollarea.h"
       
    19 
       
    20 #include <QGraphicsLinearLayout>
       
    21 #include <HbGroupBox>
       
    22 #include <HbAction>
       
    23 #include <QInputContext>
       
    24 #include <qfile.h>
       
    25 #include <qapplication.h>
       
    26 #include <xqconversions.h>
       
    27 #include <commonphoneparser.h> 
       
    28 #include <HbNotificationDialog>
       
    29 #include <hbmainwindow.h>
       
    30 
       
    31 #include "msgunieditoraddress.h"
       
    32 #include "msgunieditorsubject.h"
       
    33 #include "msgunieditorbody.h"
       
    34 #include "msgunieditorsubject.h"
       
    35 #include "msgunieditorbody.h"
       
    36 #include "msgunieditormonitor.h"
       
    37 #include "msgunieditorattachmentcontainer.h"
       
    38 #include "UniEditorGenUtils.h"
       
    39 #include "msgunieditorview.h"
       
    40 
       
    41 // LOCALIZED CONSTANTS
       
    42 //To,Cc.Bcc
       
    43 #define LOC_TO  hbTrId("txt_messaging_formlabel_to")
       
    44 #define LOC_CC  hbTrId("txt_messaging_formlabel_cc")
       
    45 #define LOC_BCC hbTrId("txt_messaging_formlabel_bcc")
       
    46 //group box
       
    47 #define LOC_OTHER_RECIPIENTS(n) hbTrId("txt_messaging_title_ln_other_recipients",n)
       
    48 #define LOC_OTHER_RECIPIENTS_EXPAND hbTrId("txt_messaging_title_other_recipients")
       
    49 
       
    50 // attachment addition failure note
       
    51 #define LOC_UNABLE_TO_ADD_ATTACHMENTS hbTrId("txt_messaging_dpopinfo_unable_to_attach_l1_of_l2")
       
    52 
       
    53 //---------------------------------------------------------------
       
    54 // MsgUnifiedEditorScrollArea::MsgUnifiedEditorScrollArea
       
    55 //
       
    56 //---------------------------------------------------------------
       
    57 MsgUnifiedEditorScrollArea::MsgUnifiedEditorScrollArea(MsgUnifiedEditorMonitor* msgMonitor,QGraphicsItem *parent) :
       
    58 HbScrollArea(parent),
       
    59 mMsgMonitor(msgMonitor),
       
    60 mMainLayout(0),
       
    61 mToField(0),
       
    62 mCcField(0),
       
    63 mBccField(0),
       
    64 mSubjectField(0),
       
    65 mBody(0),
       
    66 mAttachmentContainer(0),
       
    67 mEnableScrolling(true)
       
    68 {
       
    69     init();
       
    70 }
       
    71 
       
    72 //---------------------------------------------------------------
       
    73 // MsgUnifiedEditorScrollArea::~MsgUnifiedEditorScrollArea
       
    74 //
       
    75 //---------------------------------------------------------------
       
    76 MsgUnifiedEditorScrollArea::~MsgUnifiedEditorScrollArea()
       
    77 {
       
    78 }
       
    79 
       
    80 //---------------------------------------------------------------
       
    81 // MsgUnifiedEditorScrollArea::init
       
    82 //
       
    83 //---------------------------------------------------------------
       
    84 void MsgUnifiedEditorScrollArea::init()
       
    85 {
       
    86     HbWidget* contentWidget = new HbWidget(this);
       
    87     this->setContentWidget(contentWidget);
       
    88 
       
    89     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, contentWidget);
       
    90     qreal vTopSpacing = 0.0;
       
    91     qreal vItemSpacing = 0.0;
       
    92     style()->parameter("hb-param-margin-gene-top",vTopSpacing);    
       
    93     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);
       
    94     
       
    95     mMainLayout->setContentsMargins(0,0,0,0);
       
    96     mMainLayout->setSpacing(vItemSpacing);
       
    97 
       
    98     mToField = new MsgUnifiedEditorAddress( LOC_TO, this ); 
       
    99     mToField->setObjectName("to");
       
   100     
       
   101     mBody =  new MsgUnifiedEditorBody(this);
       
   102         
       
   103     mMainLayout->addItem(mToField);
       
   104     mMainLayout->addItem(mBody);
       
   105     mMainLayout->addStretch(2);
       
   106  
       
   107     connect(mToField, SIGNAL(contentsChanged(const QVariant&)),
       
   108             mMsgMonitor, SLOT(handleContentsChanged(const QVariant&)));
       
   109     
       
   110     connect(mBody, SIGNAL(contentsChanged(const QVariant&)),
       
   111             mMsgMonitor, SLOT(handleContentsChanged(const QVariant&))); 
       
   112     
       
   113     connect(mBody,SIGNAL(enableMenuAction(int,bool)),this,SIGNAL(enableMenuAction(int,bool)));
       
   114     
       
   115 }
       
   116 
       
   117 //---------------------------------------------------------------
       
   118 // MsgUnifiedEditorScrollArea::addCcBcc
       
   119 //
       
   120 //---------------------------------------------------------------
       
   121 void MsgUnifiedEditorScrollArea::addCcBcc(bool needFocus)
       
   122 {
       
   123     if(mCcField && mBccField)
       
   124     { // do nothing if already present
       
   125         return;
       
   126     }
       
   127 
       
   128     mCcField    = new MsgUnifiedEditorAddress( LOC_CC, this );
       
   129     mCcField->setObjectName("cc");
       
   130 
       
   131     mBccField   = new MsgUnifiedEditorAddress( LOC_BCC, this );
       
   132     mBccField->setObjectName("bcc");
       
   133 
       
   134     mCcField->skipMaxRecipientQuery(true);
       
   135     mBccField->skipMaxRecipientQuery(true);
       
   136 
       
   137     connect(mCcField, SIGNAL(contentsChanged(const QVariant&)),
       
   138         mMsgMonitor, SLOT(handleContentsChanged(const QVariant&)));
       
   139 
       
   140     connect(mBccField, SIGNAL(contentsChanged(const QVariant&)),
       
   141         mMsgMonitor, SLOT(handleContentsChanged(const QVariant&)));
       
   142 
       
   143     HbWidget* groupWidget = new HbWidget(this);
       
   144     groupWidget->setContentsMargins(0,0,0,0);
       
   145 
       
   146     QGraphicsLinearLayout* ccBccLayout = new QGraphicsLinearLayout(Qt::Vertical, groupWidget);
       
   147     ccBccLayout->setContentsMargins(0,0,0,0);
       
   148 
       
   149     qreal vItemSpacing = 0.0;    
       
   150     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);
       
   151     ccBccLayout->setSpacing(vItemSpacing);
       
   152     ccBccLayout->addItem(mCcField);
       
   153     ccBccLayout->addItem(mBccField);
       
   154 
       
   155     HbGroupBox* groupBox = new HbGroupBox(0);  
       
   156     groupBox->setObjectName("groupBox");
       
   157 
       
   158     groupBox->setContentWidget(groupWidget);
       
   159     groupBox->setHeading(LOC_OTHER_RECIPIENTS_EXPAND);
       
   160     mMainLayout->insertItem(1,groupBox);
       
   161     connect(groupBox, SIGNAL(toggled(bool)), this, SLOT(updateOtherRecipientCount(bool)));
       
   162 
       
   163     //emit signal to remove CcBcc action
       
   164     emit enableMenuAction(CCBCC, false);
       
   165 
       
   166     this->updateGeometry();
       
   167     
       
   168     if(needFocus)
       
   169     {
       
   170         setFocus(mCcField);
       
   171     }
       
   172 }
       
   173 
       
   174 //---------------------------------------------------------------
       
   175 // MsgUnifiedEditorScrollArea::addSubject
       
   176 //
       
   177 //---------------------------------------------------------------
       
   178 void MsgUnifiedEditorScrollArea::addSubject(bool needFocus)
       
   179 {
       
   180     // do nothing if already present
       
   181     if(mSubjectField)
       
   182     { 
       
   183         return;
       
   184     }
       
   185 
       
   186     mSubjectField = new MsgUnifiedEditorSubject(this);
       
   187 
       
   188     int index = 0;
       
   189     if(mCcField && mBccField)
       
   190     {
       
   191         index = 2;
       
   192     }
       
   193     else
       
   194     {
       
   195         index = 1;
       
   196     }
       
   197 
       
   198     mMainLayout->insertItem(index,mSubjectField);
       
   199     connect(mSubjectField, SIGNAL(contentsChanged(const QVariant&)),
       
   200             mMsgMonitor, SLOT(handleContentsChanged(const QVariant&)));
       
   201 
       
   202     //emit signal to remove CcBcc action
       
   203     emit enableMenuAction(SUBJECT, false); 
       
   204     
       
   205     if(needFocus)
       
   206     {
       
   207         setFocus(mSubjectField);
       
   208     }
       
   209 }
       
   210 
       
   211 //---------------------------------------------------------------
       
   212 // MsgUnifiedEditorScrollArea::setImage
       
   213 //
       
   214 //---------------------------------------------------------------
       
   215 void MsgUnifiedEditorScrollArea::setImage(const QString& path, bool draftMessage)
       
   216 {
       
   217     mBody->setImage(path,draftMessage);
       
   218 }
       
   219 
       
   220 //---------------------------------------------------------------
       
   221 // MsgUnifiedEditorScrollArea::setAudio
       
   222 //
       
   223 //---------------------------------------------------------------
       
   224 void MsgUnifiedEditorScrollArea::setAudio(const QString& filePath)
       
   225 {
       
   226     mBody->setAudio(filePath);
       
   227 }
       
   228 
       
   229 //---------------------------------------------------------------
       
   230 // MsgUnifiedEditorScrollArea::setFocus
       
   231 //
       
   232 //---------------------------------------------------------------
       
   233 void MsgUnifiedEditorScrollArea::setFocus(MsgUnifiedEditorBaseWidget* item)
       
   234 {
       
   235     if(item)
       
   236     {
       
   237         item->setFocus();  
       
   238     }
       
   239     
       
   240     //open vkb
       
   241     postInputPanelEvent();
       
   242 }
       
   243 
       
   244 //---------------------------------------------------------------
       
   245 // MsgUnifiedEditorScrollArea::changePriority
       
   246 //
       
   247 //---------------------------------------------------------------
       
   248 void MsgUnifiedEditorScrollArea::changePriority()
       
   249 {
       
   250     HbAction* action = qobject_cast<HbAction*>(sender());
       
   251 
       
   252     ConvergedMessage::Priority priority = ConvergedMessage::Normal;
       
   253    if(action)
       
   254         {
       
   255         int data = action->data().toInt();
       
   256         priority = ConvergedMessage::Priority(data);
       
   257         }
       
   258 
       
   259     addSubject();
       
   260     mSubjectField->setPriority(priority);
       
   261 }
       
   262 
       
   263 //---------------------------------------------------------------
       
   264 // MsgUnifiedEditorScrollArea::updateOtherRecipientCount
       
   265 //
       
   266 //---------------------------------------------------------------
       
   267 void MsgUnifiedEditorScrollArea::updateOtherRecipientCount(bool state)
       
   268 {
       
   269     HbGroupBox* groupBox = qobject_cast<HbGroupBox*>(sender());
       
   270     if(groupBox)
       
   271     {
       
   272         if(!state)
       
   273         {
       
   274            groupBox->setHeading(LOC_OTHER_RECIPIENTS_EXPAND);
       
   275         }
       
   276         else
       
   277         {
       
   278             int addrCount = mCcField->addressCount();
       
   279             addrCount += mBccField->addressCount();
       
   280             if(addrCount > 0)
       
   281             {
       
   282                 groupBox->setHeading(LOC_OTHER_RECIPIENTS(addrCount));    
       
   283             }
       
   284         }
       
   285     }
       
   286 }
       
   287 
       
   288 //---------------------------------------------------------------
       
   289 // MsgUnifiedEditorScrollArea::contactsValid
       
   290 //
       
   291 //---------------------------------------------------------------
       
   292 bool MsgUnifiedEditorScrollArea::contactsValid()
       
   293 {
       
   294         bool res = ( !mToField->validateContacts() ||
       
   295                     (mCcField && !mCcField->validateContacts()) ||
       
   296                     (mBccField && !mBccField->validateContacts()) );
       
   297         
       
   298         return !res;
       
   299 }
       
   300 
       
   301 //---------------------------------------------------------------
       
   302 // MsgUnifiedEditorScrollArea::currentAddress
       
   303 //
       
   304 //---------------------------------------------------------------
       
   305 ConvergedMessageAddress* MsgUnifiedEditorScrollArea::currentAddress()
       
   306 {
       
   307     ConvergedMessageAddress* currentAdd = NULL;
       
   308     
       
   309     ConvergedMessageAddressList addList = mToField->addresses();
       
   310     int count = addList.count();
       
   311     if(count)
       
   312     {
       
   313         currentAdd = addList.takeFirst();
       
   314     }
       
   315     
       
   316     while(addList.count())
       
   317     {
       
   318         ConvergedMessageAddress* obj =  addList.takeFirst();
       
   319         delete obj;
       
   320     }
       
   321     
       
   322     return currentAdd;
       
   323 }
       
   324 
       
   325 //---------------------------------------------------------------
       
   326 // MsgUnifiedEditorScrollArea::packMessage
       
   327 //
       
   328 //---------------------------------------------------------------
       
   329 int MsgUnifiedEditorScrollArea::packMessage(ConvergedMessage &msg, bool isSave)
       
   330 {
       
   331     // If isSave is true (save to draft usecase), then don't remove duplicates
       
   332     // If isSave is false (send usecase), then remove duplicates
       
   333     bool removeDuplicates = !isSave;
       
   334     ConvergedMessageAddressList addresses = mToField->addresses(removeDuplicates);
       
   335     
       
   336     ConvergedMessageAddressList ccAddresses;
       
   337     ConvergedMessageAddressList bccAddresses;
       
   338     ConvergedMessageAttachmentList mediaList;
       
   339     int errorCode = 0;
       
   340     //Don't format the addresses for save to drfats case
       
   341     if(!isSave)
       
   342     {
       
   343        formatAddresses(addresses);
       
   344     }
       
   345     
       
   346     msg.addToRecipients(addresses);
       
   347 
       
   348     if(MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Mms)
       
   349     {
       
   350         if(mCcField)
       
   351         {
       
   352             ccAddresses = mCcField->addresses(removeDuplicates);
       
   353         }
       
   354 
       
   355         if(mBccField)
       
   356         {
       
   357             bccAddresses = mBccField->addresses(removeDuplicates);
       
   358         }
       
   359 
       
   360         if(removeDuplicates)
       
   361         {
       
   362             int matchDigitsCount = MsgUnifiedEditorAddress::contactMatchDigits();
       
   363             //comapre cc and to field,remove duplicate from cc
       
   364             foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
       
   365             {
       
   366                 foreach(ConvergedMessageAddress *toAddress,addresses)
       
   367                 {
       
   368                     if(0 == ccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
       
   369                     {
       
   370                         ccAddresses.removeOne(ccAddress);
       
   371                     }
       
   372                 }
       
   373             }
       
   374             //comapre bcc and cc field,remove duplicate from bcc
       
   375             foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
       
   376             {
       
   377                 foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
       
   378                 {
       
   379                     if(0 == bccAddress->address().right(matchDigitsCount).compare(ccAddress->address().right(matchDigitsCount)))
       
   380                     {
       
   381                         bccAddresses.removeOne(bccAddress);
       
   382                     }
       
   383                 }
       
   384             }
       
   385             //comapre bcc and to field,remove duplicate from bcc
       
   386             foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
       
   387             {
       
   388                 foreach(ConvergedMessageAddress *toAddress,addresses)
       
   389                 {
       
   390                     if(0 == bccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
       
   391                     {
       
   392                         bccAddresses.removeOne(bccAddress);
       
   393                     }
       
   394                 }
       
   395             }
       
   396         }
       
   397 
       
   398         if(ccAddresses.count()>0)
       
   399         {
       
   400         //Don't format the addresses for save to drfats case
       
   401         if(!isSave)
       
   402         {
       
   403            formatAddresses(ccAddresses);
       
   404         }        
       
   405         msg.addCcRecipients(ccAddresses);
       
   406         }
       
   407         if(bccAddresses.count()>0)
       
   408         {
       
   409         //Don't format the addresses for save to drfats case
       
   410         if(!isSave)
       
   411         {
       
   412            formatAddresses(bccAddresses);        
       
   413         }
       
   414         msg.addBccRecipients(bccAddresses);
       
   415         }
       
   416         if(mSubjectField)
       
   417         {
       
   418             msg.setSubject(mSubjectField->text());
       
   419             msg.setPriority(mSubjectField->priority());
       
   420         }
       
   421 
       
   422         QStringList mediafiles(mBody->mediaContent());
       
   423         if (!mediafiles.isEmpty())
       
   424         {
       
   425             for (int i = 0; i < mediafiles.size(); ++i)
       
   426             {
       
   427                 if(QFile::exists(mediafiles.at(i)))
       
   428                 {
       
   429                 ConvergedMessageAttachment* attachment =
       
   430                     new ConvergedMessageAttachment(
       
   431                         mediafiles.at(i),
       
   432                         ConvergedMessageAttachment::EInline);
       
   433                 mediaList << attachment;
       
   434                 }
       
   435                 else
       
   436                 {   mBody->removeMediaContent(mediafiles.at(i));
       
   437                     errorCode = KErrNotFound;
       
   438                 }
       
   439             }
       
   440 
       
   441         }
       
   442         if(mediaList.count() > 0)
       
   443         {
       
   444             msg.addAttachments(mediaList);
       
   445         }
       
   446     }
       
   447 
       
   448     // sms/mms attachment list
       
   449     ConvergedMessageAttachmentList attachmentList;
       
   450         if(mAttachmentContainer)
       
   451         {
       
   452             MsgUnifiedEditorAttachmentList editorAttachmentList =
       
   453                 mAttachmentContainer->attachmentList();
       
   454                 for (int i = 0; i < editorAttachmentList.count(); ++i)
       
   455                 {
       
   456                     if(QFile::exists(editorAttachmentList.at(i)->path()))
       
   457                     {
       
   458                         ConvergedMessageAttachment* attachment =
       
   459                                                 new ConvergedMessageAttachment(
       
   460                                                     editorAttachmentList.at(i)->path(),
       
   461                                                     ConvergedMessageAttachment::EAttachment);
       
   462                                             attachmentList << attachment;    
       
   463                     }
       
   464                     else
       
   465                     {
       
   466                         mAttachmentContainer->deleteAttachment(editorAttachmentList.at(i));
       
   467                         errorCode = KErrNotFound;
       
   468                     }   
       
   469                 }
       
   470             }
       
   471         if(attachmentList.count() > 0)
       
   472         {
       
   473             msg.addAttachments(attachmentList);
       
   474         }
       
   475         return errorCode;
       
   476 }
       
   477 
       
   478 // ----------------------------------------------------------------------------
       
   479 // MsgUnifiedEditorScrollArea::formatAddresses
       
   480 // @see header
       
   481 // ----------------------------------------------------------------------------
       
   482 void MsgUnifiedEditorScrollArea::formatAddresses(ConvergedMessageAddressList& addresses)
       
   483 {       
       
   484     for(int i=0; i < addresses.count() ;i++ )
       
   485     {
       
   486         QString addr = addresses[i]->address();
       
   487         
       
   488         HBufC *tempAddr = XQConversions::qStringToS60Desc(addr);     
       
   489             
       
   490         TPtr ptr = tempAddr->Des();
       
   491                     
       
   492          // Note: This is just to parse spaces etc away from phonenumbers.
       
   493          //       Ignore EFalse returned for email addresses.   
       
   494         CommonPhoneParser::ParsePhoneNumber(ptr , 
       
   495                                             CommonPhoneParser::ESMSNumber );        
       
   496        
       
   497         addr = XQConversions::s60DescToQString(tempAddr->Des()); 
       
   498         
       
   499         addresses[i]->setAddress(addr);
       
   500         
       
   501         delete tempAddr;                                                       
       
   502     }       
       
   503 }
       
   504 
       
   505 //---------------------------------------------------------------
       
   506 // MsgUnifiedEditorScrollArea::addAttachment
       
   507 //
       
   508 //---------------------------------------------------------------
       
   509 int MsgUnifiedEditorScrollArea::addAttachment(const QString& filepath)
       
   510 {
       
   511     // do nothing if filepath is empty
       
   512     if(filepath.isEmpty())
       
   513     {
       
   514         return MsgAttachmentContainer::EAddSuccess;
       
   515     }
       
   516 
       
   517     if(!mAttachmentContainer)
       
   518     {
       
   519         mAttachmentContainer = new MsgAttachmentContainer(this);
       
   520         connect(mAttachmentContainer, SIGNAL(emptyAttachmentContainer()),
       
   521                 this, SLOT(removeAttachmentContainer()));
       
   522         connect(mAttachmentContainer, SIGNAL(contentsChanged(const QVariant&)),
       
   523                 mMsgMonitor, SLOT(handleContentsChanged(const QVariant&)));
       
   524         
       
   525         int index = mMainLayout->count() - 1;
       
   526         mMainLayout->insertItem(index,mAttachmentContainer);
       
   527     }
       
   528 
       
   529     int ret = mAttachmentContainer->addAttachment(filepath);
       
   530     if(ret != MsgAttachmentContainer::EAddSuccess)
       
   531     {
       
   532         // delete container, if it is empty
       
   533         if(mAttachmentContainer->count() == 0)
       
   534         {
       
   535             removeAttachmentContainer();
       
   536         }
       
   537     }
       
   538     return ret;
       
   539 }
       
   540 
       
   541 //---------------------------------------------------------------
       
   542 // MsgUnifiedEditorScrollArea::removeAttachmentContainer
       
   543 //
       
   544 //---------------------------------------------------------------
       
   545 void MsgUnifiedEditorScrollArea::removeAttachmentContainer()
       
   546 {
       
   547     if(mAttachmentContainer)
       
   548     {
       
   549         mMainLayout->removeItem(mAttachmentContainer);
       
   550         mAttachmentContainer->setParent(NULL);
       
   551         delete mAttachmentContainer;
       
   552         mAttachmentContainer = NULL;
       
   553     }
       
   554 }
       
   555 
       
   556 //---------------------------------------------------------------
       
   557 // MsgUnifiedEditorScrollArea::addAttachments
       
   558 //
       
   559 //---------------------------------------------------------------
       
   560 void MsgUnifiedEditorScrollArea::addAttachments(const QStringList files)
       
   561 {    
       
   562     int fcount = files.count();
       
   563     int i=0;
       
   564     for(i=0; i<fcount; i++)
       
   565     {
       
   566         int status = addAttachment(files.at(i));
       
   567         if(status == MsgAttachmentContainer::EAddSizeExceed)
       
   568         {
       
   569             QString displayStr = QString(LOC_UNABLE_TO_ADD_ATTACHMENTS)
       
   570                     .arg(fcount-i).arg(fcount);
       
   571             HbNotificationDialog::launchDialog(displayStr);
       
   572             break;
       
   573         }
       
   574     }
       
   575 }
       
   576 
       
   577 //---------------------------------------------------------------
       
   578 // MsgUnifiedEditorScrollArea::fileNameInUse
       
   579 //
       
   580 //---------------------------------------------------------------
       
   581 bool MsgUnifiedEditorScrollArea::fileNameInUse(const QString& fileName)
       
   582 {
       
   583     bool inUse = false;
       
   584     
       
   585     if(mAttachmentContainer)
       
   586     {
       
   587         inUse = mAttachmentContainer->fileNameInUse(fileName);
       
   588     }
       
   589     
       
   590     return inUse;
       
   591 }
       
   592 
       
   593 //---------------------------------------------------------------
       
   594 // MsgUnifiedEditorScrollArea::scrollByAmount
       
   595 //
       
   596 //---------------------------------------------------------------
       
   597 bool MsgUnifiedEditorScrollArea::scrollByAmount(const QPointF &delta)
       
   598 {
       
   599     if(mEnableScrolling)
       
   600     {
       
   601         return HbScrollArea::scrollByAmount(delta);
       
   602     }
       
   603     else
       
   604     {
       
   605         return false;
       
   606     }
       
   607 }
       
   608 
       
   609 //---------------------------------------------------------------
       
   610 // MsgUnifiedEditorScrollArea::enableScrolling
       
   611 //
       
   612 //---------------------------------------------------------------
       
   613 void MsgUnifiedEditorScrollArea::enableScrolling(bool enable)
       
   614 {
       
   615     mEnableScrolling = enable;
       
   616 }
       
   617 
       
   618 //---------------------------------------------------------------
       
   619 // MsgUnifiedEditorScrollArea::postInputPanelEvent
       
   620 //
       
   621 //---------------------------------------------------------------
       
   622 void MsgUnifiedEditorScrollArea::postInputPanelEvent()
       
   623 {
       
   624     // This opens the VKB
       
   625     QInputContext *ic = qApp->inputContext();
       
   626     if (ic)
       
   627     {
       
   628         QEvent event(QEvent::RequestSoftwareInputPanel);
       
   629         ic->filterEvent(&event);
       
   630     }
       
   631 }
       
   632 
       
   633 //---------------------------------------------------------------
       
   634 // MsgUnifiedEditorScrollArea::populateContent
       
   635 //
       
   636 //---------------------------------------------------------------
       
   637 void MsgUnifiedEditorScrollArea::populateContent(const ConvergedMessage& msg, bool draftMessage, bool checkForInline)
       
   638 {
       
   639     mToField->skipMaxRecipientQuery(true);
       
   640 
       
   641     mToField->setAddresses(msg.toAddressList(),draftMessage);
       
   642     
       
   643     if(msg.ccAddressList().count() > 0 )
       
   644     {
       
   645         if(!mCcField)
       
   646         {
       
   647             addCcBcc();
       
   648         }
       
   649         mCcField->setAddresses(msg.ccAddressList(),draftMessage);
       
   650     }
       
   651     
       
   652     if(msg.bccAddressList().count() > 0 )
       
   653     {
       
   654         if(!mBccField)
       
   655         {
       
   656             addCcBcc();
       
   657         }
       
   658         mBccField->setAddresses(msg.bccAddressList(),draftMessage);
       
   659     }
       
   660     
       
   661     if(msg.subject().size() > 0)
       
   662     {
       
   663         if(!mSubjectField)
       
   664         {
       
   665             addSubject();
       
   666         }
       
   667         mSubjectField->setText(msg.subject());
       
   668     }
       
   669 
       
   670     if(msg.priority()==ConvergedMessage::High ||
       
   671         msg.priority() == ConvergedMessage::Low)
       
   672     {
       
   673         if(!mSubjectField)
       
   674         {
       
   675             addSubject();
       
   676         }
       
   677         mSubjectField->setPriority(msg.priority());
       
   678     }
       
   679 
       
   680 
       
   681     ConvergedMessageAttachmentList attachmentList = msg.attachments();
       
   682 
       
   683     UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils);
       
   684 
       
   685     QStringList pendingAttList;
       
   686 
       
   687     int attachmentCount = attachmentList.count();
       
   688 
       
   689     for( int i=0; i < attachmentCount; i++ )
       
   690     {
       
   691         QString filePath = msg.attachments().at(i)->filePath();
       
   692         
       
   693         bool inlineContent = true;
       
   694         
       
   695         if(checkForInline)
       
   696         {
       
   697             inlineContent = (attachmentList.at(i)->attachmentType() == ConvergedMessageAttachment::EInline);
       
   698         }
       
   699 
       
   700         if (inlineContent)
       
   701         {
       
   702             int imageSize=0;
       
   703             QString mimeType;            
       
   704             TMsgMediaType mediaType = EMsgMediaUnknown;
       
   705             
       
   706             TRAP_IGNORE(genUtils->getFileInfoL(filePath,imageSize,
       
   707                         mimeType,mediaType));
       
   708 
       
   709             switch(mediaType)
       
   710             {
       
   711                 case EMsgMediaImage:
       
   712                 {
       
   713                     mBody->setImage(filePath,draftMessage);
       
   714                     break;
       
   715                 }
       
   716                 case EMsgMediaAudio:
       
   717                 {
       
   718                     mBody->setAudio(filePath);
       
   719                     break;
       
   720                 }
       
   721                 default:
       
   722                 {
       
   723                     pendingAttList << filePath;
       
   724                     break;
       
   725                 }
       
   726             }
       
   727         }
       
   728         else
       
   729         {
       
   730             pendingAttList << filePath;
       
   731         }
       
   732     }
       
   733     // add pending attachments to editor
       
   734     addAttachments(pendingAttList);
       
   735 
       
   736     delete genUtils;
       
   737     
       
   738     // ensure that any msg-type change after this are shown
       
   739     mToField->skipMaxRecipientQuery(false);
       
   740 
       
   741 }