messagingapp/msgutils/unieditorutils/unieditorplugins/unieditormmsplugin/src/unieditormmsplugin_p.cpp
changeset 25 84d9eb65b26f
child 27 e4592d119491
child 37 518b245aa84c
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 #include <txtetext.h>
       
    34 #include <txtrich.h>
       
    35 #include <txtfmlyr.h>
       
    36 #include <MuiuOperationWait.h>
       
    37 #include <QDir>
       
    38 #include <hbglobal.h>
       
    39 #include <eikrted.h>
       
    40 #include <MsgMediaInfo.h>
       
    41 #include <MsgMediaResolver.h>
       
    42 
       
    43 #include "UniSendingSettings.h"
       
    44 #include "unidatamodelloader.h"
       
    45 #include "unidatamodelplugininterface.h"
       
    46 #include "s60qconversions.h"
       
    47 #include "debugtraces.h"
       
    48 #include "UniEditorGenUtils.h"
       
    49 
       
    50 // Possible values for mms validity period in seconds
       
    51 const TInt32 KUniMmsValidityPeriod1h = 3600;
       
    52 const TInt32 KUniMmsValidityPeriod6h = 21600;
       
    53 const TInt32 KUniMmsValidityPeriod24h = 86400;
       
    54 const TInt32 KUniMmsValidityPeriod3Days = 259200;
       
    55 const TInt32 KUniMmsValidityPeriodWeek = 604800;
       
    56 const TInt32 KUniMmsValidityPeriodMax = 0;
       
    57 
       
    58 const TInt  KMaxDetailsLength = 64; // Copy max this many chars to TMsvEntry::iDetails
       
    59 _LIT( KAddressSeparator, ";" );
       
    60 
       
    61 #define KSenduiMtmMmsUidValue 0x100058E1
       
    62 const TUid KSenduiMtmMmsUid = {KSenduiMtmMmsUidValue};
       
    63 
       
    64 #define LOC_FWD hbTrId("txt_messaging_formlabel_fwd")
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // Two-phased constructor.
       
    68 // @see Header
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CUniEditorMmsPluginPrivate* CUniEditorMmsPluginPrivate::NewL()
       
    72 {
       
    73     CUniEditorMmsPluginPrivate* self = new ( ELeave ) CUniEditorMmsPluginPrivate(); 
       
    74     return self;
       
    75 }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // Destructor
       
    79 // @see Header
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CUniEditorMmsPluginPrivate::~CUniEditorMmsPluginPrivate()
       
    83 {
       
    84     //In case there is no settings at all leave occurs and resource not freed
       
    85     delete iMmsHeader;
       
    86 
       
    87     delete iEditor;
       
    88     delete iDom;
       
    89     delete iUniDataModel;
       
    90     ifsSession.Close();
       
    91 
       
    92     delete iMmsMtm;
       
    93     delete iMtmRegistry;
       
    94     delete iDataModelPluginLoader;
       
    95     delete iSession;
       
    96 }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // C++ default constructor
       
   100 // @see Header
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CUniEditorMmsPluginPrivate::CUniEditorMmsPluginPrivate( )
       
   104 {
       
   105     iSession = CMsvSession::OpenSyncL(*this);
       
   106 }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // convertFromL
       
   110 // @see Header
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 ConvergedMessage* CUniEditorMmsPluginPrivate::convertFromL( TMsvId aId,
       
   114     UniEditorPluginInterface::EditorOperation aOperation )
       
   115 {
       
   116     QDEBUG_WRITE("Enter convertFromL");
       
   117 
       
   118     MmsMtmL()->SwitchCurrentEntryL( aId );
       
   119     MmsMtmL()->LoadMessageL();
       
   120 
       
   121     TMsvEntry entry =MmsMtmL()->Entry().Entry();
       
   122 
       
   123     ConvergedMessage* msg = new ConvergedMessage;
       
   124     
       
   125     CleanupStack::PushL(msg);
       
   126     if( entry.Parent() == KMsvDraftEntryIdValue )
       
   127     {
       
   128        convertFromDraftsL(*msg);
       
   129     }
       
   130     else if( aOperation == UniEditorPluginInterface::Forward)
       
   131     {
       
   132         convertFromForwardHandlerL(*msg);          
       
   133     }
       
   134     CleanupStack::Pop(msg);
       
   135     QDEBUG_WRITE("Exit convertFromL");
       
   136     return msg;
       
   137 }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // convertFromDraftsL
       
   141 // @see Header
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CUniEditorMmsPluginPrivate::convertFromDraftsL(
       
   145     ConvergedMessage& aMessage )
       
   146 {
       
   147     QDEBUG_WRITE("Enter convertFromDraftsL");
       
   148     
       
   149     TMsvEntry entry =MmsMtmL()->Entry().Entry();
       
   150 
       
   151     //Message id 
       
   152     ConvergedMessageId id(entry.Id());
       
   153     aMessage.setMessageId(id);
       
   154 
       
   155     // Set Message type
       
   156     aMessage.setMessageType(ConvergedMessage::Mms);
       
   157 
       
   158     //Populate recipients
       
   159     populateRecipientsL(aMessage);
       
   160 
       
   161     //populate convergedmessage with the subject
       
   162     aMessage.setSubject(S60QConversions::s60DescToQString(
       
   163         MmsMtmL()->SubjectL()));
       
   164 
       
   165     // Priority
       
   166     TMsvPriority priority = entry.Priority();
       
   167     if( EMsvHighPriority == priority )
       
   168     {
       
   169         aMessage.setPriority(ConvergedMessage::High);
       
   170     }
       
   171     else if( EMsvLowPriority == priority )
       
   172     {
       
   173         aMessage.setPriority(ConvergedMessage::Low);
       
   174     }
       
   175     else if( EMsvMediumPriority == priority )
       
   176     {
       
   177         aMessage.setPriority(ConvergedMessage::Normal);
       
   178     }
       
   179 
       
   180     // Set direction and location
       
   181     aMessage.setDirection(ConvergedMessage::Outgoing);
       
   182     aMessage.setLocation (ConvergedMessage::Draft);
       
   183 
       
   184     //Populate body and attachments
       
   185     populateMessageBodyL(aMessage);
       
   186 
       
   187     QDEBUG_WRITE("Exit convertFromDraftsL");
       
   188 }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // convertFromForwardHandlerL
       
   192 // @see Header
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CUniEditorMmsPluginPrivate::convertFromForwardHandlerL(
       
   196     ConvergedMessage &aMessage)
       
   197 {
       
   198     QDEBUG_WRITE("Enter convertFromForwardHandlerL");
       
   199 
       
   200     TMsvEntry entry =MmsMtmL()->Entry().Entry();
       
   201 
       
   202     //populate convergedmessage with the subject prepended with FW:
       
   203     QString subject = LOC_FWD + S60QConversions::s60DescToQString(
       
   204         MmsMtmL()->SubjectL());     
       
   205     aMessage.setSubject(subject);
       
   206 
       
   207     // Priority
       
   208     TMsvPriority priority = entry.Priority();
       
   209     if( EMsvHighPriority == priority )
       
   210     {
       
   211         aMessage.setPriority(ConvergedMessage::High);
       
   212     }
       
   213     else if( EMsvLowPriority == priority )
       
   214     {
       
   215         aMessage.setPriority(ConvergedMessage::Low);
       
   216     }
       
   217     else if( EMsvMediumPriority == priority )
       
   218     {
       
   219         aMessage.setPriority(ConvergedMessage::Normal);
       
   220     }
       
   221 
       
   222     //Populate body and attachments
       
   223     //The region info inside slides is not maintained
       
   224     populateMessageBodyL(aMessage);
       
   225     
       
   226     QDEBUG_WRITE("Exit convertFromForwardHandlerL");
       
   227 }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // populateMessageBodyL
       
   231 // @see Header
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CUniEditorMmsPluginPrivate::populateMessageBodyL(
       
   235     ConvergedMessage &aMessage)
       
   236 {
       
   237     QDEBUG_WRITE("Enter populateMessageBodyL");
       
   238     
       
   239     if(!iDataModelPluginLoader)
       
   240     {
       
   241         iDataModelPluginLoader = new UniDataModelLoader;  
       
   242         iMmsDataPlugin = iDataModelPluginLoader->getDataModelPlugin(ConvergedMessage::Mms);
       
   243     }
       
   244 
       
   245     iMmsDataPlugin->restore(*MmsMtmL());
       
   246 
       
   247     int slideCount = iMmsDataPlugin->slideCount();
       
   248 
       
   249     int attachmentCount = iMmsDataPlugin->attachmentCount();
       
   250 
       
   251     ConvergedMessageAttachmentList attachmentList;
       
   252 
       
   253     if (slideCount > 0)
       
   254     {
       
   255         UniMessageInfoList slideContentList = 
       
   256             iMmsDataPlugin->slideContent(0);
       
   257         for (int i = 0; i < slideContentList.size(); ++i)
       
   258         {
       
   259             if( slideContentList.at(i)->mimetype().contains("text") )
       
   260             {
       
   261                 QString textContent;
       
   262                 QFile file(slideContentList.at(i)->path());
       
   263                 file.open(QIODevice::ReadOnly);
       
   264                 textContent = file.readAll();
       
   265                 aMessage.setBodyText(textContent);
       
   266                 file.close();
       
   267             }
       
   268             else
       
   269             {
       
   270             ConvergedMessageAttachment* attachment =
       
   271                 new ConvergedMessageAttachment(
       
   272                     slideContentList.at(i)->path(),
       
   273                     ConvergedMessageAttachment::EInline);
       
   274             attachmentList << attachment;
       
   275             }
       
   276         }
       
   277         
       
   278         foreach(UniMessageInfo* slide,slideContentList)
       
   279         {
       
   280             delete slide;
       
   281         }
       
   282     }
       
   283 
       
   284     
       
   285     if(attachmentCount > 0)
       
   286     {
       
   287         UniMessageInfoList modelAttachmentList = 
       
   288             iMmsDataPlugin->attachmentList();
       
   289 
       
   290         for (int i = 0; i < modelAttachmentList.count(); ++i)
       
   291         {
       
   292             ConvergedMessageAttachment* attachment =
       
   293                 new ConvergedMessageAttachment(
       
   294                     modelAttachmentList.at(i)->path(),
       
   295                     ConvergedMessageAttachment::EAttachment);
       
   296             attachmentList << attachment;
       
   297         }
       
   298         
       
   299         foreach(UniMessageInfo* attachment,modelAttachmentList)
       
   300         {
       
   301             delete attachment;
       
   302         }
       
   303     }
       
   304 
       
   305     if(attachmentList.count() > 0)
       
   306     {
       
   307         aMessage.addAttachments(attachmentList);
       
   308     }       
       
   309 
       
   310     //Delete the pluginloader instance
       
   311     delete iDataModelPluginLoader;
       
   312     iDataModelPluginLoader = NULL;
       
   313     iMmsDataPlugin = NULL;
       
   314     
       
   315     QDEBUG_WRITE("Exit populateMessageBodyL");
       
   316 }
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // convertToL
       
   320 // @see Header
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 TMsvId CUniEditorMmsPluginPrivate::convertToL(ConvergedMessage *aMessage)
       
   324 {
       
   325     QDEBUG_WRITE("Enter ConvertToL");
       
   326 
       
   327     // create message in drafts.
       
   328     CMsvEntry* cEntry = MmsMtmL()->Session().GetEntryL(KMsvDraftEntryId);
       
   329 
       
   330     CleanupStack::PushL(cEntry);
       
   331     MmsMtmL()->SwitchCurrentEntryL(cEntry->EntryId());
       
   332 
       
   333     TMsvEntry entry;
       
   334     entry.iMtm = MmsMtmL()->Type();
       
   335     entry.iType = KUidMsvMessageEntry;
       
   336     entry.iServiceId = MmsMtmL()->DefaultServiceL();
       
   337     entry.iDate.UniversalTime();
       
   338 
       
   339     cEntry->CreateL(entry);
       
   340 
       
   341     TMsvId entryId = entry.Id();
       
   342 
       
   343     //Since entry is created if any of the below functions leave 
       
   344     //the created entry has to be deleted
       
   345     TInt error = KErrNone;
       
   346     TRAP(error,DoConvertToL(aMessage,entry));
       
   347     
       
   348     CleanupStack::PopAndDestroy(cEntry);
       
   349 
       
   350     if (error != KErrNone)
       
   351     {
       
   352         this->deleteDraftsEntryL(entryId);
       
   353         entryId = -1; //Set Invalid entry id
       
   354     }
       
   355     QDEBUG_WRITE_FORMAT("Exit ConvertToL the entryId= ",entryId);
       
   356     return entryId;
       
   357 }
       
   358 
       
   359 // -----------------------------------------------------------------------------
       
   360 // DoConvertToL
       
   361 // @see Header
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 void CUniEditorMmsPluginPrivate::DoConvertToL(ConvergedMessage *aMessage,
       
   365     TMsvEntry& entry)
       
   366 {
       
   367     TMsvId entryId = entry.Id();
       
   368  
       
   369      // switch to created entry
       
   370      MmsMtmL()->SwitchCurrentEntryL(entryId);
       
   371 
       
   372      //Add recipients
       
   373      addRecipientsL(aMessage);
       
   374 
       
   375      //There is no size check inside plugin as it assumes 
       
   376      //we get proper data from editor
       
   377      HBufC* sub = S60QConversions::qStringToS60Desc(aMessage->subject());
       
   378      if( sub )
       
   379      {
       
   380          CleanupStack::PushL(sub);
       
   381          MmsMtmL()->SetSubjectL( *sub );
       
   382          CleanupStack::PopAndDestroy(sub);
       
   383      }
       
   384 
       
   385      //Add attachments
       
   386      // fetch attachment list and populate the smil model
       
   387      ConvergedMessageAttachmentList attachmentlist = aMessage->attachments();
       
   388      int attachmentcount = attachmentlist.count();
       
   389      if ((attachmentcount> 0) || !(aMessage->bodyText().isEmpty()))
       
   390      {
       
   391         QDEBUG_WRITE("Before calling iUniDataModel->restore");
       
   392 
       
   393         User::LeaveIfError(ifsSession.Connect());
       
   394 
       
   395         delete iUniDataModel;
       
   396         iUniDataModel = NULL;
       
   397 
       
   398         iUniDataModel = CUniDataModel::NewL(ifsSession, *MmsMtmL());
       
   399         iUniDataModel->RestoreL(*this, ETrue);
       
   400 
       
   401         QDEBUG_WRITE("Before calling iUniDataModel->addSlide");
       
   402 
       
   403         bool slideContentAdded = false;
       
   404 
       
   405         //Adding first slide
       
   406         iUniDataModel->SmilModel().AddSlideL(0);
       
   407 
       
   408         for (int i = 0; i < attachmentcount; i++)
       
   409         {
       
   410             if (attachmentlist[i]->attachmentType()
       
   411                     == ConvergedMessageAttachment::EInline)
       
   412             {
       
   413                 slideContentAdded = true;
       
   414                 addObjectL(0, attachmentlist[i]->filePath());
       
   415 
       
   416             }
       
   417             else if (attachmentlist[i]->attachmentType()
       
   418                     == ConvergedMessageAttachment::EAttachment)
       
   419             {
       
   420                 addAttachmentL(attachmentlist[i]->filePath());
       
   421             }
       
   422         }
       
   423 
       
   424         if (! (aMessage->bodyText().isEmpty()))
       
   425         {
       
   426             slideContentAdded = true;
       
   427             addTextObjectL(0, aMessage->bodyText());
       
   428         }
       
   429 
       
   430         if (slideContentAdded)
       
   431         {
       
   432             iUniDataModel->ObjectList().SaveAll(*this, CMsvAttachment::EMsvFile);
       
   433 
       
   434             // Open store even if we didn't need it here.
       
   435             // -> We don't need to check later whether the store 
       
   436             //is open or not.    
       
   437             CMsvStore* editStore = MmsMtmL()->Entry().EditStoreL();
       
   438 
       
   439             //Ensure that the store is deleted if anything 
       
   440             //leaves before deletion otherwise the entry store will be locked
       
   441             //and entry cant be deleted
       
   442             CleanupStack::PushL(editStore);
       
   443 
       
   444             delete iDom;
       
   445             iDom = NULL;
       
   446 
       
   447             iDom = iUniDataModel->SmilModel().ComposeL();
       
   448             iUniDataModel->SmilList().CreateSmilAttachmentL(*this,
       
   449                                                             *editStore,
       
   450                                                             iDom);
       
   451 
       
   452              //Commit the store before setting the root
       
   453              editStore->CommitL();
       
   454 
       
   455              //delete the store before setMessageRoot is called
       
   456              CleanupStack::PopAndDestroy(editStore);
       
   457 
       
   458             //Set message root after composing SMIL but before 
       
   459             //calling SaveMessageL and after the store has been deleted
       
   460             MmsMtmL()->SetMessageRootL(iUniDataModel->SmilList().GetSmilAttachmentByIndex(0));
       
   461         }
       
   462         else
       
   463         {
       
   464             //Remove the slide   
       
   465             iUniDataModel->SmilModel().RemoveSlide(0);
       
   466 
       
   467              // Open store even if we didn't need it here.
       
   468              // -> We don't need to check later whether the store is open or not.    
       
   469              CMsvStore* editStore = MmsMtmL()->Entry().EditStoreL();
       
   470              
       
   471              //Ensure that the store is deleted if anything 
       
   472              //leaves before deletion otherwise the entry store will be locked
       
   473              //and entry cant be deleted
       
   474              CleanupStack::PushL(editStore);
       
   475              
       
   476              //Commit the store before setting the root
       
   477              editStore->CommitL();
       
   478 
       
   479              //delete the store before setMessageRoot is called
       
   480              CleanupStack::PopAndDestroy(editStore);
       
   481          }
       
   482      }
       
   483 
       
   484      //Set the priority before calling save
       
   485      ConvergedMessage::Priority priority = aMessage->priority();
       
   486      if (ConvergedMessage::High == priority)
       
   487      {
       
   488          MmsMtmL()->SetMessagePriority(EMmsPriorityHigh);
       
   489      }
       
   490      else if (ConvergedMessage::Low == priority)
       
   491      {
       
   492          MmsMtmL()->SetMessagePriority(EMmsPriorityLow);
       
   493      }
       
   494      else if (ConvergedMessage::Normal == priority)
       
   495      {
       
   496          MmsMtmL()->SetMessagePriority(EMmsPriorityNormal);
       
   497      }
       
   498 
       
   499      //Saving the changes
       
   500      MmsMtmL()->SaveMessageL();
       
   501 
       
   502      entry = MmsMtmL()->Entry().Entry();
       
   503 
       
   504      TBuf<KMaxDetailsLength> detailsBuf;
       
   505      MakeDetailsL( detailsBuf );
       
   506      entry.iDetails.Set( detailsBuf );
       
   507 
       
   508      MmsMtmL()->Entry().ChangeL(entry); // commit changes      
       
   509 
       
   510 }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // sendL
       
   514 // @see Header
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 void CUniEditorMmsPluginPrivate::sendL( TMsvId aId )
       
   518 {
       
   519     QDEBUG_WRITE("Enter sendL");
       
   520 
       
   521     MmsMtmL()->SwitchCurrentEntryL( aId );
       
   522     MmsMtmL()->LoadMessageL();
       
   523     CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   524     CMsvOperation* oper = MmsMtmL()->SendL( wait->iStatus );
       
   525     CleanupStack::PushL( oper );
       
   526     wait->Start();
       
   527     CleanupStack::PopAndDestroy( oper );
       
   528     CleanupStack::PopAndDestroy( wait );
       
   529 
       
   530     QDEBUG_WRITE("Exit sendL");
       
   531 }
       
   532 
       
   533 // -----------------------------------------------------------------------------
       
   534 // validateServiceL
       
   535 // @see Header
       
   536 // -----------------------------------------------------------------------------
       
   537 //
       
   538 TBool CUniEditorMmsPluginPrivate::validateServiceL( TBool /*aEmailOverSms*/ )
       
   539 {
       
   540     QDEBUG_WRITE("Enter ValidateServiceL");
       
   541 
       
   542     //Check if the mms client mtm object is already created or not
       
   543     if( iMmsMtm )
       
   544     {
       
   545         // If mms client mtm object is already created restore the settings
       
   546         iMmsMtm->RestoreSettingsL();
       
   547     }
       
   548 
       
   549     TMsvId service = MmsMtmL()->DefaultServiceL();
       
   550     TBool valid( MmsMtmL()->ValidateService( service ) == KErrNone );
       
   551 
       
   552     QDEBUG_WRITE_FORMAT("Exit ValidateServiceL the return val= ",valid);
       
   553     return valid;
       
   554 }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // isServiceValidL
       
   558 // @see Header
       
   559 // -----------------------------------------------------------------------------
       
   560 //
       
   561 TBool CUniEditorMmsPluginPrivate::isServiceValidL()
       
   562 {
       
   563     return MmsMtmL()->ValidateService( MmsMtmL()->DefaultServiceL() ) == KErrNone;
       
   564 }
       
   565 
       
   566 // -----------------------------------------------------------------------------
       
   567 // MmsMtmL
       
   568 // @see Header
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 CMmsClientMtm* CUniEditorMmsPluginPrivate::MmsMtmL()
       
   572 {
       
   573     if ( !iMmsMtm )
       
   574     {
       
   575         if ( !iMtmRegistry )
       
   576         {            
       
   577             iMtmRegistry = CClientMtmRegistry::NewL( *iSession );
       
   578         }
       
   579         iMmsMtm = static_cast<CMmsClientMtm*>( iMtmRegistry->NewMtmL( 
       
   580             KSenduiMtmMmsUid ) );
       
   581     }
       
   582     return iMmsMtm;
       
   583 }
       
   584 
       
   585 // ---------------------------------------------------------
       
   586 // MakeDetailsL
       
   587 // @see Header
       
   588 // ---------------------------------------------------------
       
   589 //
       
   590 void CUniEditorMmsPluginPrivate::MakeDetailsL( TDes& aDetails )
       
   591 {
       
   592     // This very same code can be found in CUniAddressHandler. 
       
   593     // They should be put in common location some day...
       
   594     const CMsvRecipientList& addresses = MmsMtmL()->AddresseeList();
       
   595     TInt addrCnt = addresses.Count();
       
   596 
       
   597     TPtrC stringToAdd;
       
   598     for ( TInt i = 0; i < addrCnt; i++)
       
   599     {
       
   600         // Only address is converted to western. 
       
   601         // There may numbers in contact name - they must not be converted 
       
   602         TPtrC alias = TMmsGenUtils::Alias( addresses[i] );
       
   603         HBufC* addressBuf = NULL;
       
   604 
       
   605         if ( alias.Length() != 0 )
       
   606         {
       
   607             stringToAdd.Set( alias );
       
   608         }
       
   609         else
       
   610         {
       
   611             TPtrC address = TMmsGenUtils::PureAddress( addresses[i] );
       
   612             addressBuf = HBufC::NewLC( address.Length() );
       
   613             TPtr addressPtr = addressBuf->Des();
       
   614             addressPtr.Copy( address );
       
   615             stringToAdd.Set( addressPtr );
       
   616 
       
   617             // Internal data structures always holds the address data in western format.
       
   618             // UI is responsible of doing language specific conversions.    
       
   619             //MuiuTextUtils::ConvertDigitsTo( addressPtr, EDigitTypeWestern );
       
   620             UniEditorGenUtils* genUtils = new UniEditorGenUtils();
       
   621             genUtils->ConvertDigitsTo( addressPtr, EDigitTypeWestern );
       
   622             delete genUtils;
       
   623         }
       
   624 
       
   625         if ( ( aDetails.Length() != 0 ) &&   // Not a first address
       
   626                 ( aDetails.Length() + KAddressSeparator().Length() < KMaxDetailsLength ) )
       
   627         {
       
   628             // Add separator
       
   629             aDetails.Append( KAddressSeparator() );
       
   630         }
       
   631 
       
   632         if ( aDetails.Length() + stringToAdd.Length() < KMaxDetailsLength ) 
       
   633         {
       
   634             // whole string fits. Add it.
       
   635             aDetails.Append( stringToAdd );
       
   636             if ( addressBuf )
       
   637             {
       
   638                 CleanupStack::PopAndDestroy( addressBuf );
       
   639             }
       
   640         }
       
   641         else
       
   642         {
       
   643             // Only part of the string fits
       
   644             TInt charsToAdd = KMaxDetailsLength - aDetails.Length();
       
   645 
       
   646             if ( charsToAdd <= 0 )
       
   647             {
       
   648                 // Cannot add any more chars 
       
   649                 break;
       
   650             }
       
   651 
       
   652             if ( charsToAdd >= stringToAdd.Length() )
       
   653             {
       
   654                 // Guarantee that charsToAdd is not larger that stringToAdd lenght 
       
   655                 charsToAdd = stringToAdd.Length();
       
   656             }
       
   657 
       
   658             aDetails.Append( stringToAdd.Left( charsToAdd ) );
       
   659             if ( addressBuf )
       
   660             {
       
   661                 CleanupStack::PopAndDestroy( addressBuf );
       
   662             }
       
   663             break;
       
   664         }
       
   665     }
       
   666 }
       
   667 
       
   668 //---------------------------------------------------------------
       
   669 // CUniEditorMmsPluginPrivate::addRecipientsL
       
   670 // @see header
       
   671 //---------------------------------------------------------------
       
   672 void CUniEditorMmsPluginPrivate::addRecipientsL(ConvergedMessage *message)
       
   673 {
       
   674     //add To feilds
       
   675     ConvergedMessageAddressList toAddressArray = message->toAddressList();
       
   676     addRecipientsL(toAddressArray, EMsvRecipientTo);
       
   677 
       
   678     //add cc feilds
       
   679     ConvergedMessageAddressList ccAddressArray = message->ccAddressList();
       
   680     addRecipientsL(ccAddressArray, EMsvRecipientCc);
       
   681 
       
   682     //add bcc feilds
       
   683     ConvergedMessageAddressList bccAddressArray = message->bccAddressList();
       
   684     addRecipientsL(bccAddressArray, EMsvRecipientBcc);
       
   685 }
       
   686 
       
   687 //---------------------------------------------------------------
       
   688 // CUniEditorMmsPluginPrivate::addRecipientsL
       
   689 // @see header
       
   690 //---------------------------------------------------------------
       
   691 void CUniEditorMmsPluginPrivate::addRecipientsL(
       
   692     const ConvergedMessageAddressList &array,
       
   693     TMsvRecipientType recpType)
       
   694 {    
       
   695 
       
   696     for (int i = 0; i < array.count(); ++i)
       
   697     {
       
   698         if(array[i]->address().isEmpty())
       
   699         {
       
   700             continue;
       
   701         }
       
   702         // convert from QString to HBufC
       
   703         HBufC* addr = S60QConversions::qStringToS60Desc(array[i]->address());
       
   704 
       
   705         CleanupStack::PushL(addr);
       
   706 
       
   707         if(TMmsGenUtils::Alias(*addr).Length() > 0)
       
   708         {    
       
   709             MmsMtmL()->AddAddresseeL(recpType, TMmsGenUtils::PureAddress(*addr),
       
   710                 TMmsGenUtils::Alias(*addr));
       
   711         }
       
   712         else
       
   713         {
       
   714             HBufC* displayName = S60QConversions::qStringToS60Desc(array[i]->alias());
       
   715             if(displayName)
       
   716             {
       
   717                 CleanupStack::PushL(displayName);
       
   718 
       
   719                 MmsMtmL()->AddAddresseeL(recpType, TMmsGenUtils::PureAddress(*addr),
       
   720                     *displayName);
       
   721 
       
   722                 CleanupStack::PopAndDestroy(displayName);
       
   723             }
       
   724             else
       
   725             {
       
   726                 MmsMtmL()->AddAddresseeL(recpType, TMmsGenUtils::PureAddress(*addr));    
       
   727             }
       
   728         }
       
   729         CleanupStack::PopAndDestroy(addr);
       
   730     }
       
   731 }
       
   732 
       
   733 // ----------------------------------------------------------------------------
       
   734 // CUniEditorMmsPluginPrivate::populateRecipientsL
       
   735 // @see header
       
   736 // ----------------------------------------------------------------------------
       
   737 //
       
   738 void CUniEditorMmsPluginPrivate::populateRecipientsL(
       
   739     ConvergedMessage &aMessage)
       
   740     {
       
   741     QDEBUG_WRITE("Enter populateRecipientsL");
       
   742 
       
   743 
       
   744     // get recipient list
       
   745     const CMsvRecipientList& addresses = MmsMtmL()->AddresseeList();
       
   746     TInt count = addresses.Count();
       
   747 
       
   748     // extract each address and populate into ConvergedMessageAddress
       
   749     for (TInt i = 0; i < count; ++i)
       
   750         {
       
   751         //Address
       
   752         QString address = S60QConversions::s60DescToQString(
       
   753             TMmsGenUtils::PureAddress(addresses[i]));
       
   754         //Alias
       
   755         QString alias = S60QConversions::s60DescToQString(
       
   756             TMmsGenUtils::Alias(addresses[i]));
       
   757 
       
   758         //add recipient to convergedMessage
       
   759         ConvergedMessageAddress messageAddress(address, alias);
       
   760         if (addresses.Type(i) == EMsvRecipientTo)
       
   761             {
       
   762             aMessage.addToRecipient(messageAddress);
       
   763             }
       
   764         else if (addresses.Type(i) == EMsvRecipientCc)
       
   765             {
       
   766             aMessage.addCcRecipient(messageAddress);
       
   767             }
       
   768         else if (addresses.Type(i) == EMsvRecipientBcc)
       
   769             {
       
   770             aMessage.addBccRecipient(messageAddress);
       
   771             }
       
   772         }
       
   773 
       
   774     QDEBUG_WRITE("Exit populateRecipientsL");
       
   775 
       
   776     }
       
   777 
       
   778 // ----------------------------------------------------------------------------
       
   779 // CUniEditorMmsPluginPrivate::deleteDraftsEntryL
       
   780 // @see header
       
   781 // ----------------------------------------------------------------------------
       
   782 //
       
   783 void CUniEditorMmsPluginPrivate::deleteDraftsEntryL( TMsvId aId )
       
   784 {
       
   785     CMsvEntry* pEntry = iSession->GetEntryL(KMsvDraftEntryIdValue);
       
   786     CleanupStack::PushL(pEntry);
       
   787     pEntry->DeleteL( aId );
       
   788     CleanupStack::PopAndDestroy(pEntry);
       
   789 }
       
   790 
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // addObjectL
       
   794 // @see Header
       
   795 // -----------------------------------------------------------------------------
       
   796 //
       
   797 void CUniEditorMmsPluginPrivate::addObjectL(int aSlideNum, const QString& aFilePath)
       
   798 {
       
   799 
       
   800     HBufC* filePath = S60QConversions::qStringToS60Desc(aFilePath);
       
   801 
       
   802     if (filePath)
       
   803     {
       
   804         CleanupStack::PushL(filePath);
       
   805         RFile file = iUniDataModel->MediaResolver().FileHandleL(*filePath);
       
   806         CleanupClosePushL(file);
       
   807 
       
   808         iInsertingMedia = iUniDataModel->MediaResolver().CreateMediaInfoL(file);
       
   809 
       
   810         iUniDataModel->MediaResolver().ParseInfoDetailsL(iInsertingMedia, file);
       
   811         iUniDataModel->SmilModel().AddObjectL(*this, aSlideNum, iInsertingMedia);
       
   812 
       
   813         //Since the ownership is transferred dont delete these
       
   814         iInsertingMedia = NULL;
       
   815         CleanupStack::PopAndDestroy(&file);
       
   816         CleanupStack::PopAndDestroy(filePath);
       
   817     }
       
   818 
       
   819 }
       
   820 
       
   821 
       
   822 // -----------------------------------------------------------------------------
       
   823 // addAttachmentL
       
   824 // @see Header
       
   825 // -----------------------------------------------------------------------------
       
   826 //
       
   827 void CUniEditorMmsPluginPrivate::addAttachmentL(const QString& aFilePath)
       
   828 {
       
   829     HBufC * filePath = S60QConversions::qStringToS60Desc(aFilePath);
       
   830     if (filePath)
       
   831     {
       
   832         CleanupStack::PushL(filePath);
       
   833 
       
   834         RFile file = iUniDataModel->MediaResolver().FileHandleL(*filePath);
       
   835         CleanupClosePushL(file);
       
   836 
       
   837         iInsertingMedia = iUniDataModel->MediaResolver().CreateMediaInfoL(file);
       
   838 
       
   839         iUniDataModel->MediaResolver().ParseInfoDetailsL(iInsertingMedia, file);
       
   840         iUniDataModel->AddAttachmentL(*this,
       
   841                                       iInsertingMedia,
       
   842                                       CMsvAttachment::EMsvFile);
       
   843 
       
   844         //Since the ownership is transferred dont delete these
       
   845         iInsertingMedia = NULL;
       
   846 
       
   847         CleanupStack::PopAndDestroy(&file);
       
   848         CleanupStack::PopAndDestroy(filePath);
       
   849     }
       
   850 
       
   851 }
       
   852 
       
   853 
       
   854 // -----------------------------------------------------------------------------
       
   855 // addTextObjectL
       
   856 // @see Header
       
   857 // -----------------------------------------------------------------------------
       
   858 //
       
   859 void CUniEditorMmsPluginPrivate::addTextObjectL(int aSlideNum, const QString& aBodyText)
       
   860 {
       
   861     delete iEditor;
       
   862     iEditor = NULL;
       
   863 
       
   864     HBufC* textContent = S60QConversions::qStringToS60Desc(aBodyText);
       
   865     if (textContent)
       
   866     {
       
   867         CleanupStack::PushL(textContent);
       
   868 
       
   869         iEditor = new CEikRichTextEditor;
       
   870         iEditor->ConstructL(NULL, 0, 0, CEikEdwin::ENoAutoSelection
       
   871                 | CEikEdwin::EOwnsWindow, 0, 0);
       
   872         iEditor->RichText()->InsertL(0, *textContent);
       
   873 
       
   874         iUniDataModel->SmilModel().AddTextObjectL(aSlideNum, iEditor);
       
   875         CleanupStack::PopAndDestroy(textContent);
       
   876     }
       
   877 }
       
   878 
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 // ObjectSaveReady
       
   882 // @see Header
       
   883 // -----------------------------------------------------------------------------
       
   884 //
       
   885 void CUniEditorMmsPluginPrivate::ObjectSaveReady(TInt /*aError*/)
       
   886 {
       
   887 
       
   888 }
       
   889 
       
   890 // -----------------------------------------------------------------------------
       
   891 // MediaInfoParsed
       
   892 // @see Header
       
   893 // -----------------------------------------------------------------------------
       
   894 //
       
   895 void CUniEditorMmsPluginPrivate::MediaInfoParsed()
       
   896 {
       
   897 
       
   898 }
       
   899 
       
   900 // -----------------------------------------------------------------------------
       
   901 // SmilComposeEvent
       
   902 // @see Header
       
   903 // -----------------------------------------------------------------------------
       
   904 //
       
   905 void CUniEditorMmsPluginPrivate::SmilComposeEvent(TInt /*aError*/)
       
   906 {
       
   907 
       
   908 }
       
   909 
       
   910 // -----------------------------------------------------------------------------
       
   911 // RestoreReady
       
   912 // @see Header
       
   913 // -----------------------------------------------------------------------------
       
   914 //
       
   915 void CUniEditorMmsPluginPrivate::RestoreReady(TInt /*aParseResult*/, TInt /*aError*/)
       
   916 {
       
   917 }
       
   918 
       
   919 
       
   920 // HandleSessionEventL
       
   921 // @see Header
       
   922 // -----------------------------------------------------------------------------
       
   923 //
       
   924 void CUniEditorMmsPluginPrivate::HandleSessionEventL(TMsvSessionEvent /*aEvent*/,
       
   925                                                   TAny* /*aArg1*/,
       
   926                                                   TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   927 {
       
   928 // do nothing
       
   929 }
       
   930 
       
   931 //  End of File