messagingapp/msgutils/unieditorplugins/unieditormmsplugin/src/unieditormmsplugin_p.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     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:
       
    15  *
       
    16  */
       
    17 
       
    18 #include "unieditormmsplugin_p.h"
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <f32file.h>
       
    23 #include <msvids.h> 
       
    24 #include <mtclreg.h>
       
    25 #include <commdb.h> 
       
    26 #include <mmsconst.h>
       
    27 #include <mmsclient.h>
       
    28 #include <mmsheaders.h>
       
    29 #include <mmssettings.h>
       
    30 #include <mmsmsventry.h>
       
    31 #include <bautils.h>
       
    32 #include <data_caging_path_literals.hrh> 
       
    33 
       
    34 #include <MuiuOperationWait.h>
       
    35 #include <QDir>
       
    36 
       
    37 #include "UniSendingSettings.h"
       
    38 #include "unidatamodelloader.h"
       
    39 #include "unidatamodelplugininterface.h"
       
    40 #include "s60qconversions.h"
       
    41 #include "debugtraces.h"
       
    42 #include "UniEditorGenUtils.h"
       
    43 #include "sessioneventhandler.h"
       
    44 
       
    45 // Possible values for mms validity period in seconds
       
    46 const TInt32 KUniMmsValidityPeriod1h = 3600;
       
    47 const TInt32 KUniMmsValidityPeriod6h = 21600;
       
    48 const TInt32 KUniMmsValidityPeriod24h = 86400;
       
    49 const TInt32 KUniMmsValidityPeriod3Days = 259200;
       
    50 const TInt32 KUniMmsValidityPeriodWeek = 604800;
       
    51 const TInt32 KUniMmsValidityPeriodMax = 0;
       
    52 
       
    53 const TInt  KMaxDetailsLength = 64; // Copy max this many chars to TMsvEntry::iDetails
       
    54 _LIT( KAddressSeparator, ";" );
       
    55 
       
    56 #define KSenduiMtmMmsUidValue 0x100058E1
       
    57 const TUid KSenduiMtmMmsUid = {KSenduiMtmMmsUidValue};
       
    58 
       
    59 const QString MMSStr("mms");
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // Two-phased constructor.
       
    63 // @see Header
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CUniEditorMmsPluginPrivate* CUniEditorMmsPluginPrivate::NewL()
       
    67 {
       
    68     CUniEditorMmsPluginPrivate* self = new ( ELeave ) CUniEditorMmsPluginPrivate(); 
       
    69     return self;
       
    70 }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // Destructor
       
    74 // @see Header
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CUniEditorMmsPluginPrivate::~CUniEditorMmsPluginPrivate()
       
    78 {
       
    79     //In case there is no settings at all leave occurs and resource not freed
       
    80     delete iMmsHeader;
       
    81     delete iMmsMtm;
       
    82     delete iMtmRegistry;
       
    83     delete iDataModelPluginLoader;
       
    84     delete iSessionHandler;
       
    85     delete iSession;
       
    86 }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // C++ default constructor
       
    90 // @see Header
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CUniEditorMmsPluginPrivate::CUniEditorMmsPluginPrivate( )
       
    94 : iSessionHandler(0)
       
    95 {
       
    96     iSessionHandler = new SessionEventHandler();
       
    97     iSessionHandler->start();
       
    98     iSession = CMsvSession::OpenSyncL(*iSessionHandler);
       
    99 }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // convertFromL
       
   103 // @see Header
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 ConvergedMessage* CUniEditorMmsPluginPrivate::convertFromL( TMsvId aId )
       
   107 {
       
   108     QDEBUG_WRITE("Enter convertFromL");
       
   109 
       
   110     MmsMtmL()->SwitchCurrentEntryL( aId );
       
   111     MmsMtmL()->LoadMessageL();
       
   112 
       
   113     TMsvEntry entry =MmsMtmL()->Entry().Entry();
       
   114 
       
   115     ConvergedMessage* msg = new ConvergedMessage;
       
   116     
       
   117     CleanupStack::PushL(msg);
       
   118     if( entry.Parent() == KMsvDraftEntryIdValue )
       
   119     {
       
   120        convertFromDraftsL(*msg);
       
   121     }
       
   122     CleanupStack::Pop(msg);
       
   123     QDEBUG_WRITE("Exit convertFromL");
       
   124     return msg;
       
   125 }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // convertFromDraftsL
       
   129 // @see Header
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CUniEditorMmsPluginPrivate::convertFromDraftsL(
       
   133     ConvergedMessage& aMessage )
       
   134 {
       
   135     QDEBUG_WRITE("Enter convertFromDraftsL");
       
   136     
       
   137     TMsvEntry entry =MmsMtmL()->Entry().Entry();
       
   138 
       
   139     //Message id 
       
   140     ConvergedMessageId id(entry.Id());
       
   141     aMessage.setMessageId(id);
       
   142 
       
   143     // Set Message type
       
   144     aMessage.setMessageType(ConvergedMessage::Mms);
       
   145 
       
   146     //Populate recipients
       
   147     populateRecipientsL(aMessage);
       
   148 
       
   149     //populate convergedmessage with the subject
       
   150     aMessage.setSubject(S60QConversions::s60DescToQString(
       
   151         MmsMtmL()->SubjectL()));
       
   152 
       
   153     // Priority
       
   154     TMsvPriority priority = entry.Priority();
       
   155     if( EMsvHighPriority == priority )
       
   156     {
       
   157         aMessage.setPriority(ConvergedMessage::High);
       
   158     }
       
   159     else if( EMsvLowPriority == priority )
       
   160     {
       
   161         aMessage.setPriority(ConvergedMessage::Low);
       
   162     }
       
   163     else if( EMsvMediumPriority == priority )
       
   164     {
       
   165         aMessage.setPriority(ConvergedMessage::Normal);
       
   166     }
       
   167 
       
   168     // Set direction and location
       
   169     aMessage.setDirection(ConvergedMessage::Outgoing);
       
   170     aMessage.setLocation (ConvergedMessage::Draft);
       
   171 
       
   172 
       
   173     if(!iDataModelPluginLoader)
       
   174     {
       
   175         iDataModelPluginLoader = new UniDataModelLoader;  
       
   176         iDataModelPluginLoader->loadPlugins();  
       
   177         iMmsDataPlugin = iDataModelPluginLoader->getDataModelPlugin(MMSStr);
       
   178     }
       
   179 
       
   180     iMmsDataPlugin->restore(*MmsMtmL());
       
   181 
       
   182     int slideCount = iMmsDataPlugin->slideCount();
       
   183 
       
   184     int attachmentCount = iMmsDataPlugin->attachmentCount();
       
   185 
       
   186     ConvergedMessageAttachmentList attachmentList;
       
   187 
       
   188     if (slideCount > 0)
       
   189     {
       
   190         UniMessageInfoList slideContentList = 
       
   191             iMmsDataPlugin->slideContent(0);
       
   192         for (int i = 0; i < slideContentList.size(); ++i)
       
   193         {
       
   194             if( slideContentList.at(i)->mimetype().contains("text") )
       
   195             {
       
   196                 QString textContent;
       
   197                 QFile file(slideContentList.at(i)->path());
       
   198                 file.open(QIODevice::ReadOnly);
       
   199                 textContent = file.readAll();
       
   200                 aMessage.setBodyText(textContent);
       
   201                 file.close();
       
   202             }
       
   203             else
       
   204             {
       
   205             ConvergedMessageAttachment* attachment =
       
   206                 new ConvergedMessageAttachment(
       
   207                     slideContentList.at(i)->path(),
       
   208                     ConvergedMessageAttachment::EInline);
       
   209             attachmentList << attachment;
       
   210             }
       
   211         }
       
   212         
       
   213         foreach(UniMessageInfo* slide,slideContentList)
       
   214         {
       
   215             delete slide;
       
   216         }
       
   217     }
       
   218 
       
   219     
       
   220     if(attachmentCount > 0)
       
   221     {
       
   222         UniMessageInfoList modelAttachmentList = 
       
   223             iMmsDataPlugin->attachmentList();
       
   224 
       
   225         for (int i = 0; i < modelAttachmentList.count(); ++i)
       
   226         {
       
   227             ConvergedMessageAttachment* attachment =
       
   228                 new ConvergedMessageAttachment(
       
   229                     modelAttachmentList.at(i)->path(),
       
   230                     ConvergedMessageAttachment::EAttachment);
       
   231             attachmentList << attachment;
       
   232         }
       
   233         
       
   234         foreach(UniMessageInfo* attachment,modelAttachmentList)
       
   235         {
       
   236             delete attachment;
       
   237         }
       
   238     }
       
   239 
       
   240     if(attachmentList.count() > 0)
       
   241     {
       
   242         aMessage.addAttachments(attachmentList);
       
   243     }       
       
   244 
       
   245     //Delete the pluginloader instance
       
   246     delete iDataModelPluginLoader;
       
   247     iDataModelPluginLoader = NULL;
       
   248     iMmsDataPlugin = NULL;
       
   249 
       
   250     QDEBUG_WRITE("Exit convertFromDraftsL");
       
   251 }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // convertToL
       
   255 // @see Header
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 TMsvId CUniEditorMmsPluginPrivate::convertToL(ConvergedMessage *aMessage)
       
   259 {
       
   260     QDEBUG_WRITE("Enter ConvertToL");
       
   261 
       
   262     if (!iDataModelPluginLoader)
       
   263     {
       
   264         iDataModelPluginLoader = new UniDataModelLoader;
       
   265         iDataModelPluginLoader->loadPlugins();
       
   266         iMmsDataPlugin = iDataModelPluginLoader->getDataModelPlugin(MMSStr);
       
   267     }
       
   268 
       
   269     // create message in drafts.
       
   270     CMsvEntry* cEntry = MmsMtmL()->Session().GetEntryL(KMsvDraftEntryId);
       
   271 
       
   272     CleanupStack::PushL(cEntry);
       
   273     MmsMtmL()->SwitchCurrentEntryL(cEntry->EntryId());
       
   274 
       
   275     TMsvEntry entry;
       
   276     entry.iMtm = MmsMtmL()->Type();
       
   277     entry.iType = KUidMsvMessageEntry;
       
   278     entry.iServiceId = MmsMtmL()->DefaultServiceL();
       
   279     entry.iDate.UniversalTime();
       
   280 
       
   281     cEntry->CreateL(entry);
       
   282 
       
   283     TMsvId entryId = entry.Id();
       
   284 
       
   285     //Since entry is created if any of the below functions leave 
       
   286     //the created entry has to be deleted
       
   287     TInt error = KErrNone;
       
   288     TRAP(error,DoConvertToL(aMessage,entry));
       
   289     
       
   290     CleanupStack::PopAndDestroy(cEntry);
       
   291     
       
   292     //Delete the pluginloader instance
       
   293     delete iDataModelPluginLoader;
       
   294     iDataModelPluginLoader = NULL;
       
   295     iMmsDataPlugin = NULL;
       
   296 
       
   297     if (error != KErrNone)
       
   298     {
       
   299         this->deleteDraftsEntryL(entryId);
       
   300         entryId = -1; //Set Invalid entry id
       
   301     }
       
   302     QDEBUG_WRITE_FORMAT("Exit ConvertToL the entryId= ",entryId);
       
   303     return entryId;
       
   304 }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // DoConvertToL
       
   308 // @see Header
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 void CUniEditorMmsPluginPrivate::DoConvertToL(ConvergedMessage *aMessage,
       
   312     TMsvEntry& entry)
       
   313 {
       
   314     TMsvId entryId = entry.Id();
       
   315  
       
   316      // switch to created entry
       
   317      MmsMtmL()->SwitchCurrentEntryL(entryId);
       
   318 
       
   319      //Add recipients
       
   320      addRecipientsL(aMessage);
       
   321 
       
   322      //There is no size check inside plugin as it assumes 
       
   323      //we get proper data from editor
       
   324      HBufC* sub = S60QConversions::qStringToS60Desc(aMessage->subject());
       
   325      if( sub )
       
   326      {
       
   327          CleanupStack::PushL(sub);
       
   328          MmsMtmL()->SetSubjectL( *sub );
       
   329          CleanupStack::PopAndDestroy(sub);
       
   330      }
       
   331 
       
   332      //Add attachments
       
   333      // fetch attachment list and populate the smil model
       
   334      ConvergedMessageAttachmentList attachmentlist = aMessage->attachments();
       
   335      int attachmentcount = attachmentlist.count();
       
   336      if ((attachmentcount> 0) || !(aMessage->bodyText().isEmpty()))
       
   337      {
       
   338          QDEBUG_WRITE("Before calling iMmsDataPlugin->restore");
       
   339          iMmsDataPlugin->restore(*MmsMtmL());
       
   340 
       
   341          QDEBUG_WRITE("Before calling iMmsDataPlugin->addSlide");
       
   342 
       
   343          bool slideContentAdded = false;
       
   344 
       
   345          //Adding first slide
       
   346          iMmsDataPlugin->addSlide(0);
       
   347 
       
   348          for(int i=0; i < attachmentcount; i++)
       
   349          {
       
   350              //only file path is needed to be passed 
       
   351              UniMessageInfo *info = new UniMessageInfo(
       
   352                  QDir::toNativeSeparators(attachmentlist[i]->filePath()),
       
   353                                           0,
       
   354                                           QString());
       
   355 
       
   356              if(attachmentlist[i]->attachmentType() ==
       
   357                  ConvergedMessageAttachment::EInline )
       
   358              {
       
   359                  slideContentAdded = true;
       
   360                  iMmsDataPlugin->addObject(0,info);
       
   361              }
       
   362              else if(attachmentlist[i]->attachmentType() ==
       
   363                  ConvergedMessageAttachment::EAttachment)
       
   364              {
       
   365                  //Add attachment
       
   366                  iMmsDataPlugin->addAttachment(info);
       
   367              }
       
   368              delete info;
       
   369          }
       
   370 
       
   371          if(!(aMessage->bodyText().isEmpty()))
       
   372          {
       
   373              slideContentAdded = true;
       
   374              iMmsDataPlugin->addTextObject(0,aMessage->bodyText());
       
   375          }
       
   376 
       
   377          if( slideContentAdded )
       
   378          {
       
   379              iMmsDataPlugin->saveObjects();
       
   380 
       
   381              // Open store even if we didn't need it here.
       
   382              // -> We don't need to check later whether the store 
       
   383              //is open or not.    
       
   384              CMsvStore* editStore = MmsMtmL()->Entry().EditStoreL();
       
   385              
       
   386              //Ensure that the store is deleted if anything 
       
   387              //leaves before deletion otherwise the entry store will be locked
       
   388              //and entry cant be deleted
       
   389              CleanupStack::PushL(editStore);
       
   390               
       
   391              //Compose the smil if slide is added
       
   392              iMmsDataPlugin->composeSmil(*editStore);
       
   393 
       
   394              //Commit the store before setting the root
       
   395              editStore->CommitL();
       
   396 
       
   397              //delete the store before setMessageRoot is called
       
   398              CleanupStack::PopAndDestroy(editStore);
       
   399 
       
   400              //Set message root after composing SMIL but before 
       
   401              //calling SaveMessageL and after the store has been deleted
       
   402              MmsMtmL()->SetMessageRootL( 
       
   403                  iMmsDataPlugin->getSmilAttachmentByIndex( ));
       
   404          }
       
   405          else
       
   406          {
       
   407              //Remove the slide   
       
   408              iMmsDataPlugin->removeSlide(0);
       
   409 
       
   410              // Open store even if we didn't need it here.
       
   411              // -> We don't need to check later whether the store is open or not.    
       
   412              CMsvStore* editStore = MmsMtmL()->Entry().EditStoreL();
       
   413              
       
   414              //Ensure that the store is deleted if anything 
       
   415              //leaves before deletion otherwise the entry store will be locked
       
   416              //and entry cant be deleted
       
   417              CleanupStack::PushL(editStore);
       
   418              
       
   419              //Commit the store before setting the root
       
   420              editStore->CommitL();
       
   421 
       
   422              //delete the store before setMessageRoot is called
       
   423              CleanupStack::PopAndDestroy(editStore);
       
   424          }
       
   425      }
       
   426 
       
   427      //Set the priority before calling save
       
   428      ConvergedMessage::Priority priority = aMessage->priority();
       
   429      if (ConvergedMessage::High == priority)
       
   430      {
       
   431          MmsMtmL()->SetMessagePriority(EMmsPriorityHigh);
       
   432      }
       
   433      else if (ConvergedMessage::Low == priority)
       
   434      {
       
   435          MmsMtmL()->SetMessagePriority(EMmsPriorityLow);
       
   436      }
       
   437      else if (ConvergedMessage::Normal == priority)
       
   438      {
       
   439          MmsMtmL()->SetMessagePriority(EMmsPriorityNormal);
       
   440      }
       
   441 
       
   442      //Saving the changes
       
   443      MmsMtmL()->SaveMessageL();
       
   444 
       
   445      entry = MmsMtmL()->Entry().Entry();
       
   446 
       
   447      TBuf<KMaxDetailsLength> detailsBuf;
       
   448      MakeDetailsL( detailsBuf );
       
   449      entry.iDetails.Set( detailsBuf );
       
   450 
       
   451      MmsMtmL()->Entry().ChangeL(entry); // commit changes      
       
   452 
       
   453 }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // sendL
       
   457 // @see Header
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 void CUniEditorMmsPluginPrivate::sendL( TMsvId aId )
       
   461 {
       
   462     QDEBUG_WRITE("Enter sendL");
       
   463 
       
   464     MmsMtmL()->SwitchCurrentEntryL( aId );
       
   465     MmsMtmL()->LoadMessageL();
       
   466     CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   467     CMsvOperation* oper = MmsMtmL()->SendL( wait->iStatus );
       
   468     CleanupStack::PushL( oper );
       
   469     wait->Start();
       
   470     CleanupStack::PopAndDestroy( oper );
       
   471     CleanupStack::PopAndDestroy( wait );
       
   472 
       
   473     QDEBUG_WRITE("Exit sendL");
       
   474 }
       
   475 
       
   476 // -----------------------------------------------------------------------------
       
   477 // validateServiceL
       
   478 // @see Header
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 TBool CUniEditorMmsPluginPrivate::validateServiceL( TBool /*aEmailOverSms*/ )
       
   482 {
       
   483     QDEBUG_WRITE("Enter ValidateServiceL");
       
   484 
       
   485     //Check if the mms client mtm object is already created or not
       
   486     if( iMmsMtm )
       
   487     {
       
   488         // If mms client mtm object is already created restore the settings
       
   489         iMmsMtm->RestoreSettingsL();
       
   490     }
       
   491 
       
   492     TMsvId service = MmsMtmL()->DefaultServiceL();
       
   493     TBool valid( MmsMtmL()->ValidateService( service ) == KErrNone );
       
   494 
       
   495     QDEBUG_WRITE_FORMAT("Exit ValidateServiceL the return val= ",valid);
       
   496     return valid;
       
   497 }
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // isServiceValidL
       
   501 // @see Header
       
   502 // -----------------------------------------------------------------------------
       
   503 //
       
   504 TBool CUniEditorMmsPluginPrivate::isServiceValidL()
       
   505 {
       
   506     return MmsMtmL()->ValidateService( MmsMtmL()->DefaultServiceL() ) == KErrNone;
       
   507 }
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // MmsMtmL
       
   511 // @see Header
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 CMmsClientMtm* CUniEditorMmsPluginPrivate::MmsMtmL()
       
   515 {
       
   516     if ( !iMmsMtm )
       
   517     {
       
   518         if ( !iMtmRegistry )
       
   519         {            
       
   520             iMtmRegistry = CClientMtmRegistry::NewL( *iSession );
       
   521         }
       
   522         iMmsMtm = static_cast<CMmsClientMtm*>( iMtmRegistry->NewMtmL( 
       
   523             KSenduiMtmMmsUid ) );
       
   524     }
       
   525     return iMmsMtm;
       
   526 }
       
   527 
       
   528 // ---------------------------------------------------------
       
   529 // MakeDetailsL
       
   530 // @see Header
       
   531 // ---------------------------------------------------------
       
   532 //
       
   533 void CUniEditorMmsPluginPrivate::MakeDetailsL( TDes& aDetails )
       
   534 {
       
   535     // This very same code can be found in CUniAddressHandler. 
       
   536     // They should be put in common location some day...
       
   537     const CMsvRecipientList& addresses = MmsMtmL()->AddresseeList();
       
   538     TInt addrCnt = addresses.Count();
       
   539 
       
   540     TPtrC stringToAdd;
       
   541     for ( TInt i = 0; i < addrCnt; i++)
       
   542     {
       
   543         // Only address is converted to western. 
       
   544         // There may numbers in contact name - they must not be converted 
       
   545         TPtrC alias = TMmsGenUtils::Alias( addresses[i] );
       
   546         HBufC* addressBuf = NULL;
       
   547 
       
   548         if ( alias.Length() != 0 )
       
   549         {
       
   550             stringToAdd.Set( alias );
       
   551         }
       
   552         else
       
   553         {
       
   554             TPtrC address = TMmsGenUtils::PureAddress( addresses[i] );
       
   555             addressBuf = HBufC::NewLC( address.Length() );
       
   556             TPtr addressPtr = addressBuf->Des();
       
   557             addressPtr.Copy( address );
       
   558             stringToAdd.Set( addressPtr );
       
   559 
       
   560             // Internal data structures always holds the address data in western format.
       
   561             // UI is responsible of doing language specific conversions.    
       
   562             //MuiuTextUtils::ConvertDigitsTo( addressPtr, EDigitTypeWestern );
       
   563             UniEditorGenUtils* genUtils = new UniEditorGenUtils();
       
   564             genUtils->ConvertDigitsTo( addressPtr, EDigitTypeWestern );
       
   565             delete genUtils;
       
   566         }
       
   567 
       
   568         if ( ( aDetails.Length() != 0 ) &&   // Not a first address
       
   569                 ( aDetails.Length() + KAddressSeparator().Length() < KMaxDetailsLength ) )
       
   570         {
       
   571             // Add separator
       
   572             aDetails.Append( KAddressSeparator() );
       
   573         }
       
   574 
       
   575         if ( aDetails.Length() + stringToAdd.Length() < KMaxDetailsLength ) 
       
   576         {
       
   577             // whole string fits. Add it.
       
   578             aDetails.Append( stringToAdd );
       
   579             if ( addressBuf )
       
   580             {
       
   581                 CleanupStack::PopAndDestroy( addressBuf );
       
   582             }
       
   583         }
       
   584         else
       
   585         {
       
   586             // Only part of the string fits
       
   587             TInt charsToAdd = KMaxDetailsLength - aDetails.Length();
       
   588 
       
   589             if ( charsToAdd <= 0 )
       
   590             {
       
   591                 // Cannot add any more chars 
       
   592                 break;
       
   593             }
       
   594 
       
   595             if ( charsToAdd >= stringToAdd.Length() )
       
   596             {
       
   597                 // Guarantee that charsToAdd is not larger that stringToAdd lenght 
       
   598                 charsToAdd = stringToAdd.Length();
       
   599             }
       
   600 
       
   601             aDetails.Append( stringToAdd.Left( charsToAdd ) );
       
   602             if ( addressBuf )
       
   603             {
       
   604                 CleanupStack::PopAndDestroy( addressBuf );
       
   605             }
       
   606             break;
       
   607         }
       
   608     }
       
   609 }
       
   610 
       
   611 //---------------------------------------------------------------
       
   612 // CUniEditorMmsPluginPrivate::addRecipientsL
       
   613 // @see header
       
   614 //---------------------------------------------------------------
       
   615 void CUniEditorMmsPluginPrivate::addRecipientsL(ConvergedMessage *message)
       
   616 {
       
   617     //add To feilds
       
   618     ConvergedMessageAddressList toAddressArray = message->toAddressList();
       
   619     addRecipientsL(toAddressArray, EMsvRecipientTo);
       
   620 
       
   621     //add cc feilds
       
   622     ConvergedMessageAddressList ccAddressArray = message->ccAddressList();
       
   623     addRecipientsL(ccAddressArray, EMsvRecipientCc);
       
   624 
       
   625     //add bcc feilds
       
   626     ConvergedMessageAddressList bccAddressArray = message->bccAddressList();
       
   627     addRecipientsL(bccAddressArray, EMsvRecipientBcc);
       
   628 }
       
   629 
       
   630 //---------------------------------------------------------------
       
   631 // CUniEditorMmsPluginPrivate::addRecipientsL
       
   632 // @see header
       
   633 //---------------------------------------------------------------
       
   634 void CUniEditorMmsPluginPrivate::addRecipientsL(
       
   635     const ConvergedMessageAddressList &array,
       
   636     TMsvRecipientType recpType)
       
   637 {    
       
   638 
       
   639     for (int i = 0; i < array.count(); ++i)
       
   640     {
       
   641         if(array[i]->address().isEmpty())
       
   642         {
       
   643             continue;
       
   644         }
       
   645         // convert from QString to HBufC
       
   646         HBufC* addr = S60QConversions::qStringToS60Desc(array[i]->address());
       
   647 
       
   648         CleanupStack::PushL(addr);
       
   649 
       
   650         if(TMmsGenUtils::Alias(*addr).Length() > 0)
       
   651         {    
       
   652             MmsMtmL()->AddAddresseeL(recpType, TMmsGenUtils::PureAddress(*addr),
       
   653                 TMmsGenUtils::Alias(*addr));
       
   654         }
       
   655         else
       
   656         {
       
   657             HBufC* displayName = S60QConversions::qStringToS60Desc(array[i]->alias());
       
   658             if(displayName)
       
   659             {
       
   660                 CleanupStack::PushL(displayName);
       
   661 
       
   662                 MmsMtmL()->AddAddresseeL(recpType, TMmsGenUtils::PureAddress(*addr),
       
   663                     *displayName);
       
   664 
       
   665                 CleanupStack::PopAndDestroy(displayName);
       
   666             }
       
   667             else
       
   668             {
       
   669                 MmsMtmL()->AddAddresseeL(recpType, TMmsGenUtils::PureAddress(*addr));    
       
   670             }
       
   671         }
       
   672         CleanupStack::PopAndDestroy(addr);
       
   673     }
       
   674 }
       
   675 
       
   676 // ----------------------------------------------------------------------------
       
   677 // CUniEditorMmsPluginPrivate::populateRecipientsL
       
   678 // @see header
       
   679 // ----------------------------------------------------------------------------
       
   680 //
       
   681 void CUniEditorMmsPluginPrivate::populateRecipientsL(
       
   682     ConvergedMessage &aMessage)
       
   683     {
       
   684     QDEBUG_WRITE("Enter populateRecipientsL");
       
   685 
       
   686 
       
   687     // get recipient list
       
   688     const CMsvRecipientList& addresses = MmsMtmL()->AddresseeList();
       
   689     TInt count = addresses.Count();
       
   690 
       
   691     // extract each address and populate into ConvergedMessageAddress
       
   692     for (TInt i = 0; i < count; ++i)
       
   693         {
       
   694         //Address
       
   695         QString address = S60QConversions::s60DescToQString(
       
   696             TMmsGenUtils::PureAddress(addresses[i]));
       
   697         //Alias
       
   698         QString alias = S60QConversions::s60DescToQString(
       
   699             TMmsGenUtils::Alias(addresses[i]));
       
   700 
       
   701         //add recipient to convergedMessage
       
   702         ConvergedMessageAddress messageAddress(address, alias);
       
   703         if (addresses.Type(i) == EMsvRecipientTo)
       
   704             {
       
   705             aMessage.addToRecipient(messageAddress);
       
   706             }
       
   707         else if (addresses.Type(i) == EMsvRecipientCc)
       
   708             {
       
   709             aMessage.addCcRecipient(messageAddress);
       
   710             }
       
   711         else if (addresses.Type(i) == EMsvRecipientBcc)
       
   712             {
       
   713             aMessage.addBccRecipient(messageAddress);
       
   714             }
       
   715         }
       
   716 
       
   717     QDEBUG_WRITE("Exit populateRecipientsL");
       
   718 
       
   719     }
       
   720 
       
   721 // ----------------------------------------------------------------------------
       
   722 // CUniEditorMmsPluginPrivate::deleteDraftsEntryL
       
   723 // @see header
       
   724 // ----------------------------------------------------------------------------
       
   725 //
       
   726 void CUniEditorMmsPluginPrivate::deleteDraftsEntryL( TMsvId aId )
       
   727 {
       
   728     CMsvEntry* pEntry = iSession->GetEntryL(KMsvDraftEntryIdValue);
       
   729     CleanupStack::PushL(pEntry);
       
   730     pEntry->DeleteL( aId );
       
   731     CleanupStack::PopAndDestroy(pEntry);
       
   732 }
       
   733 
       
   734 //  End of File