mobilemessaging/unieditor/application/src/UniEditorSaveOperation.cpp
changeset 0 72b543305e3a
child 2 0bf1d54f37d9
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006,2007 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:   Provides CUniEditorSaveOperation methods.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ========== INCLUDE FILES ================================
       
    21 
       
    22 #include <cmsvattachment.h>
       
    23 
       
    24 #include <txtrich.h>
       
    25 #include <eikrted.h>
       
    26 
       
    27 #include <MuiuMsvUiServiceUtilities.h>
       
    28 #include <StringLoader.h>
       
    29 
       
    30 #include <MsgEditorView.h>
       
    31 #include <MsgBodyControl.h>
       
    32 #include <MsgExpandableControl.h>
       
    33 #include <MsgBaseControl.h>
       
    34 #include <msgimagecontrol.h>
       
    35 
       
    36 #include <unimsventry.h>
       
    37 
       
    38 // MsgMedia stuff
       
    39 #include <MsgMimeTypes.h>
       
    40 #include <MsgMediaInfo.h>
       
    41 #include <MsgTextInfo.h>
       
    42 #include <MsgImageInfo.h>
       
    43 
       
    44 // UniModel + UniUtils
       
    45 #include <unidatautils.h>
       
    46 #include <unidatamodel.h>
       
    47 #include <unismilmodel.h>
       
    48 #include <unismillist.h>
       
    49 #include <uniobjectlist.h>
       
    50 #include <uniaddresshandler.h>
       
    51 
       
    52 #include <UniEditor.rsg>
       
    53 
       
    54 #include "UniPluginApi.h"
       
    55 #include "UniClientMtm.h"
       
    56 
       
    57 #include "UniSendingSettings.h"
       
    58 #include "UniEditorHeader.h"
       
    59 #include "UniEditorDocument.h"
       
    60 #include "UniEditorSaveOperation.h"
       
    61 #include "UniEditorAppUi.h" 
       
    62 // ========== EXTERNAL DATA STRUCTURES =====================
       
    63 
       
    64 // ========== EXTERNAL FUNCTION PROTOTYPES =================
       
    65 
       
    66 // ========== CONSTANTS ====================================
       
    67 
       
    68 const TInt  KMaxDetailsLength   = 64;   // Copy max this many chars to TMsvEntry iDetails
       
    69 const TInt  KUniMaxDescription  = 64;
       
    70 
       
    71 // ========== MACROS =======================================
       
    72 
       
    73 // ========== LOCAL CONSTANTS AND MACROS ===================
       
    74 
       
    75 // ========== MODULE DATA STRUCTURES =======================
       
    76 
       
    77 // ========== LOCAL FUNCTION PROTOTYPES ====================
       
    78 
       
    79 // ========== LOCAL FUNCTIONS ==============================
       
    80 
       
    81 // ========== MEMBER FUNCTIONS =============================
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // CUniEditorSaveOperation::NewL
       
    85 //
       
    86 // Factory method.
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 CUniEditorSaveOperation* CUniEditorSaveOperation::NewL( 
       
    90         MUniEditorOperationObserver& aObserver,
       
    91         CUniEditorDocument& aDocument,
       
    92         CUniEditorHeader& aHeader,
       
    93         CMsgEditorView& aView,
       
    94         RFs& aFs )
       
    95     {
       
    96     CUniEditorSaveOperation* self = 
       
    97         new ( ELeave ) CUniEditorSaveOperation( aObserver, aDocument, aHeader, aView, aFs );
       
    98         
       
    99     CleanupStack::PushL( self );
       
   100     self->ConstructL();
       
   101     CleanupStack::Pop( self );
       
   102     
       
   103     return self;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // CUniEditorSaveOperation::CUniEditorSaveOperation
       
   108 //
       
   109 // Constructor.
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 CUniEditorSaveOperation::CUniEditorSaveOperation(
       
   113         MUniEditorOperationObserver& aObserver,
       
   114         CUniEditorDocument& aDocument,
       
   115         CUniEditorHeader& aHeader,
       
   116         CMsgEditorView& aView,
       
   117         RFs& aFs ) :
       
   118     CUniEditorOperation( aObserver, aDocument, aFs, EUniEditorOperationSave ),
       
   119     iHeader( aHeader ),
       
   120     iView( aView )
       
   121     {
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CUniEditorSaveOperation::ConstructL
       
   126 //
       
   127 // 2nd phase constructor.
       
   128 // ---------------------------------------------------------
       
   129 //
       
   130 void CUniEditorSaveOperation::ConstructL()
       
   131     {
       
   132     BaseConstructL();
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CUniEditorSaveOperation::~CUniEditorSaveOperation
       
   137 //
       
   138 // Destructor.
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 CUniEditorSaveOperation::~CUniEditorSaveOperation()
       
   142     {
       
   143     Cancel();
       
   144     delete iDom;
       
   145     delete iEditStore;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------
       
   149 // CUniEditorSaveOperation::Save
       
   150 //
       
   151 // SaveL
       
   152 // ---------------------------------------------------------
       
   153 //
       
   154 void CUniEditorSaveOperation::Save( TUniSaveType aSaveType )
       
   155     {
       
   156     ResetErrors();
       
   157     
       
   158     iSavedObject = NULL;
       
   159     iSaveType = aSaveType;
       
   160     
       
   161     iOperationState = EUniEditorSaveCheck;
       
   162         
       
   163     CompleteSelf( KErrNone );
       
   164     }
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // CUniEditorSaveOperation::SaveL
       
   169 //
       
   170 // SaveL
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CUniEditorSaveOperation::SaveL( CUniObject& aObject )
       
   174     {
       
   175     if ( !MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL( iDocument.Session(),
       
   176                                                                aObject.Size( ETrue ) ) )
       
   177         {
       
   178         iSavedObject = &aObject;
       
   179         iSavedObject->Save( *this, CMsvAttachment::EMsvFile );
       
   180         SetPending();
       
   181         }
       
   182     else
       
   183         {
       
   184         User::Leave( KErrDiskFull );
       
   185         }
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------
       
   189 // CUniEditorSaveOperation::CheckDiskSpaceL
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 TBool CUniEditorSaveOperation::CheckDiskSpaceL()
       
   193     {
       
   194     // First calculate disk space needed for new attas
       
   195     TInt spaceNeeded = iDocument.DataModel()->ObjectList().SpaceNeededForSaveAll();
       
   196     spaceNeeded += iDocument.DataModel()->AttachmentList().SpaceNeededForSaveAll();
       
   197 
       
   198     if ( iComposeSmil )
       
   199         {
       
   200         spaceNeeded += iDocument.DataModel()->SmilModel().SmilComposeSize();
       
   201         }
       
   202 
       
   203     // Disk space check
       
   204     return !( MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL( 
       
   205                 iDocument.Session(),
       
   206                 spaceNeeded ) );
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------
       
   210 // CUniEditorSaveOperation::DoSaveStepL
       
   211 // ---------------------------------------------------------
       
   212 //
       
   213 void CUniEditorSaveOperation::DoSaveStepL()
       
   214     {
       
   215     switch ( iOperationState )
       
   216         {
       
   217         case EUniEditorSaveCheck:
       
   218             {
       
   219             DoSaveChecksL();
       
   220             break;
       
   221             }
       
   222         case EUniEditorSaveObjects:
       
   223             {
       
   224             DoSaveObjectL();
       
   225             break;
       
   226             }
       
   227         case EUniEditorSaveAttachment:
       
   228             {
       
   229             DoSaveAttachments();
       
   230             break;
       
   231             }
       
   232         case EUniEditorSaveSmilCompose:
       
   233             {
       
   234             DoComposeSmilL();
       
   235             break;
       
   236             }
       
   237         case EUniEditorSaveFinalize:
       
   238             {
       
   239             DoFinalizeSaveL();
       
   240             break;
       
   241             }
       
   242         case EUniEditorSavePlugins:
       
   243             {
       
   244             DoSavePluginsL();
       
   245             break;
       
   246             }
       
   247         case EUniEditorSaveEnd:
       
   248             {
       
   249             if ( iEditStore )
       
   250                 {
       
   251                 iEditStore->CommitL();
       
   252                 delete iEditStore;
       
   253                 iEditStore = NULL;
       
   254                 }
       
   255             iObserver.EditorOperationEvent(
       
   256                 EUniEditorOperationSave,
       
   257                 EUniEditorOperationComplete );
       
   258             break;
       
   259             }
       
   260        case EUniEditorSaveError:
       
   261 	       {
       
   262        		if(iEditStore)
       
   263        			{
       
   264        			delete iEditStore;
       
   265 	            iEditStore = NULL;
       
   266 	            }
       
   267 	            static_cast<CUniEditorAppUi*>(CEikonEnv::Static()->AppUi())->ExitWithoutSave();
       
   268 	       	}
       
   269         default:
       
   270             {
       
   271             // Shouldn't be here!
       
   272             delete iEditStore;
       
   273             iEditStore = NULL;
       
   274             iObserver.EditorOperationEvent(
       
   275                 EUniEditorOperationSave,
       
   276                 EUniEditorOperationError );
       
   277             break;
       
   278             }
       
   279         }
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------
       
   283 // CUniEditorSaveOperation::DoSaveChecksL
       
   284 // ---------------------------------------------------------
       
   285 //
       
   286 void CUniEditorSaveOperation::DoSaveChecksL()
       
   287     {
       
   288     if ( !iDocument.Modified() &&
       
   289         iSaveType <= iDocument.PrevSaveType() )
       
   290         {
       
   291         iOperationState = EUniEditorSaveEnd;
       
   292         CompleteSelf( KErrNone );
       
   293         //nothing to do!
       
   294         return;
       
   295         }
       
   296 
       
   297     iOperationState = EUniEditorSaveEnd; // initialize state in case CheckDiskSpaceL leaves
       
   298     if ( CheckDiskSpaceL() )
       
   299         {
       
   300         iOperationState = EUniEditorSaveObjects;
       
   301         // TODO: Open edit store already here
       
   302         //iEditStore = iDocument.Mtm().Entry().EditStoreL();
       
   303 
       
   304         iHeader.CopyHeadersToMtmL( iDocument.HeaderModified(),
       
   305                                    EFalse );
       
   306 
       
   307         iComposeSmil = EFalse;
       
   308         if ( iDocument.DataModel()->SmilType() == EMmsSmil )
       
   309             {
       
   310             //ReleaseImage( ETrue );
       
   311             if ( /* iDocument.BodyModified() */
       
   312                 !iDocument.DataModel( )->ObjectList().Count() <= 0 ||
       
   313                 ( !IsForward() && iSaveType == ESendingSave ) )
       
   314                 {
       
   315                 iComposeSmil = ETrue;
       
   316                 }
       
   317             if ( iComposeSmil ||
       
   318                 iSaveType > iDocument.PrevSaveType() )
       
   319                 {
       
   320                 if ( IsForward() )
       
   321                     {
       
   322                     iDocument.DataModel()->ObjectList().EnsureAllObjectsHaveContentLocationL();
       
   323                     // TODO: Pass edit store as a parameter to objectlist
       
   324                     //iDocument.DataModel()->ObjectList().EnsureAllObjectsHaveContentLocationL( *iEditStore );
       
   325                     }
       
   326                 }
       
   327             }
       
   328         }
       
   329     else
       
   330         {
       
   331         SetError( KErrDiskFull );
       
   332         iOperationState = EUniEditorSaveEnd;
       
   333         }
       
   334       
       
   335     CompleteSelf( KErrNone );
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------
       
   339 // CUniEditorSaveOperation::DoSaveObjectL
       
   340 // ---------------------------------------------------------
       
   341 //
       
   342 void CUniEditorSaveOperation::DoSaveObjectL()
       
   343     {
       
   344     if ( iDocument.BodyModified() )
       
   345         {
       
   346         // Processing will continue from CUniEditorSaveOperation::ObjectSaveReady when
       
   347         // save has been performed
       
   348         iDocument.DataModel()->ObjectList().SaveAll( *this, CMsvAttachment::EMsvFile );    
       
   349         // TODO: Pass edit store as a parameter to objectlist
       
   350         //iDocument.DataModel()->ObjectList().SaveAll( *this, *iEditStore, CMsvAttachment::EMsvFile );    
       
   351         SetPending();
       
   352         }
       
   353     else
       
   354         {
       
   355         iOperationState = EUniEditorSaveAttachment;
       
   356         CompleteSelf( KErrNone );
       
   357         }
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------
       
   361 // CUniEditorSaveOperation::DoSaveAttachments
       
   362 // ---------------------------------------------------------
       
   363 //
       
   364 void CUniEditorSaveOperation::DoSaveAttachments()
       
   365     {
       
   366     // Processing will continue from CUniEditorSaveOperation::ObjectSaveReady when
       
   367     // save has been performed
       
   368     iDocument.DataModel()->AttachmentList().SaveAll( *this, CMsvAttachment::EMsvFile );    
       
   369     // TODO: Pass edit store as a parameter to objectlist
       
   370     //iDocument.DataModel()->AttachmentList().SaveAll( *this, *iEditStore, CMsvAttachment::EMsvFile );    
       
   371     SetPending();
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------
       
   375 // CMmsDocument::DoSaveStepL
       
   376 // ---------------------------------------------------------
       
   377 //
       
   378 void CUniEditorSaveOperation::DoComposeSmilL()
       
   379     {
       
   380     // TODO: Open edit store already in "save checks"
       
   381     // Open store even if we didn't need it here.
       
   382     // -> We don't need to check later whether the store is open or not.
       
   383     iEditStore = iDocument.Mtm().Entry().EditStoreL();
       
   384     if ( iComposeSmil )
       
   385         {
       
   386         iDocument.DataModel()->SmilList().RemoveSmilL( *iEditStore );
       
   387         if ( iSaveType == ESendingSave )
       
   388             {
       
   389             iDocument.DataModel()->SmilModel().RemoveEmptySlides();
       
   390             }
       
   391             
       
   392         if ( iDocument.DataModel()->SmilModel().SlideCount() != 0 )
       
   393             {
       
   394             // Model is not empty -> Compose new SMIL
       
   395             iDom = iDocument.DataModel()->SmilModel().ComposeL();
       
   396             iDocument.DataModel()->SmilList().CreateSmilAttachmentL( *this, *iEditStore, iDom );
       
   397             SetPending();
       
   398             return;
       
   399             }
       
   400         }
       
   401         
       
   402     iOperationState = EUniEditorSaveFinalize;
       
   403     CompleteSelf( KErrNone );
       
   404     }
       
   405 
       
   406 // ---------------------------------------------------------
       
   407 // CMmsDocument::DoFinalizeSaveL
       
   408 // ---------------------------------------------------------
       
   409 //
       
   410 void CUniEditorSaveOperation::DoFinalizeSaveL()
       
   411     {
       
   412     // Set new state immediately in case some function leaves.
       
   413     iOperationState = EUniEditorSavePlugins;
       
   414 
       
   415     // Set message root after composing SMIL but before calling SaveMessageL
       
   416     TMsvAttachmentId root( 0 );  
       
   417     if ( iDocument.DataModel()->SmilList().Count() )
       
   418         {
       
   419         root = iDocument.DataModel()->SmilList().GetSmilAttachmentByIndex( 0 );
       
   420         }
       
   421     iDocument.Mtm().SetMessageRoot( root );
       
   422 
       
   423 
       
   424     TMsvEntry tEntry = iDocument.Entry();
       
   425     iDocument.Mtm().SaveMessageL( *iEditStore, tEntry );
       
   426     
       
   427     HBufC* description = CreateDescriptionL();
       
   428     if ( description )
       
   429         {
       
   430         tEntry.iDescription.Set( *description );
       
   431         CleanupStack::PushL( description );
       
   432         }
       
   433 
       
   434     // Set details
       
   435     TBuf<KMaxDetailsLength> detailsBuf; 
       
   436     iHeader.MakeDetailsL( detailsBuf );
       
   437     tEntry.iDetails.Set( detailsBuf );
       
   438 
       
   439     if ( iComposeSmil && IsForward() )
       
   440         {
       
   441         //New SMIL composed. This is a normal message from now on.
       
   442         TUniMsvEntry::SetForwardedMessage( tEntry, EFalse );
       
   443         }
       
   444 
       
   445     TUniMsvEntry::SetEditorOriented( tEntry, ETrue );
       
   446     TUniMsvEntry::SetCharSetSupport( tEntry, iDocument.CharSetSupport() );
       
   447 
       
   448     TUniMessageCurrentType curType = EUniMessageCurrentTypeSms;
       
   449     
       
   450     if( iDocument.UniState() == EUniMms )
       
   451         {
       
   452         curType = EUniMessageCurrentTypeMms;
       
   453         
       
   454         TUniSendingSettings settings;
       
   455         
       
   456         if( iDocument.UniState() == EUniMms )
       
   457             {
       
   458             CUniEditorPlugin* mmsPlugin = iDocument.MmsPlugin();
       
   459             
       
   460             if ( mmsPlugin )
       
   461                 {
       
   462                 mmsPlugin->GetSendingSettingsL( settings );
       
   463                 switch ( settings.iPriority )
       
   464                     {
       
   465                     case TUniSendingSettings::EUniPriorityHigh:
       
   466                         {
       
   467                         tEntry.SetPriority( EMsvHighPriority );
       
   468                         break;
       
   469                         }
       
   470                     case TUniSendingSettings::EUniPriorityLow:
       
   471                         {
       
   472                         tEntry.SetPriority( EMsvLowPriority );
       
   473                         break;
       
   474                         }
       
   475                     default:
       
   476                         {
       
   477                         tEntry.SetPriority( EMsvMediumPriority );
       
   478                         break;
       
   479                         }
       
   480                     }
       
   481                 }
       
   482             else
       
   483                 {
       
   484                 // Should not happen but better to handle anyway.
       
   485                 tEntry.SetPriority( EMsvMediumPriority );
       
   486                 }
       
   487             }
       
   488         }
       
   489     else
       
   490         { 
       
   491         // Message is sms -> remove priority
       
   492         tEntry.SetPriority( EMsvMediumPriority );
       
   493         }
       
   494 
       
   495     TUniMsvEntry::SetCurrentMessageType( tEntry, curType );
       
   496 
       
   497     tEntry.SetAttachment( EFalse );
       
   498 
       
   499     if ( iSaveType >= EClosingSave )
       
   500         {
       
   501         // Update timestamp  
       
   502         tEntry.iDate.UniversalTime();
       
   503 
       
   504         if ( !tEntry.Visible() )
       
   505             {
       
   506             // Save from close or exit save.
       
   507             // Message should be visible after save
       
   508             tEntry.SetVisible( ETrue );
       
   509             tEntry.SetInPreparation( EFalse );
       
   510             }
       
   511         }
       
   512     else 
       
   513         {
       
   514         // Save made because user launched Message Info, Preview or Objects view 
       
   515         // Message should stay invisible and in preparation if it was.
       
   516         if ( !tEntry.Visible() )
       
   517             {
       
   518             // Guarantee that when Visible is ETrue InPreparation is EFalse 
       
   519             tEntry.SetInPreparation( ETrue );
       
   520             }
       
   521         }
       
   522 
       
   523 
       
   524 
       
   525     iDocument.CurrentEntry().ChangeL( tEntry );
       
   526     
       
   527     if ( description )
       
   528         {
       
   529         // This must not be popped before ChangeL
       
   530         CleanupStack::PopAndDestroy( description );
       
   531         }
       
   532 
       
   533     iDocument.SetHeaderModified( EFalse );
       
   534     iDocument.SetBodyModified( EFalse );
       
   535     iDocument.SetPrevSaveType( iSaveType );
       
   536 
       
   537     CompleteSelf( KErrNone );
       
   538     }
       
   539 
       
   540 // ---------------------------------------------------------
       
   541 // CUniEditorSaveOperation::CreateDescriptionL
       
   542 //
       
   543 // Creates description buffer. Returns NULL if description is not
       
   544 // wanted to be updated.
       
   545 // ---------------------------------------------------------
       
   546 //
       
   547 HBufC* CUniEditorSaveOperation::CreateDescriptionL()
       
   548     {
       
   549     CUniDataModel* model = iDocument.DataModel();
       
   550 
       
   551     if( iDocument.UniState() == EUniSms )
       
   552         {
       
   553         if( model->ObjectList().Count() == 0 &&
       
   554             model->AttachmentList().Count() == 1 )
       
   555             { 
       
   556             // No objects and one attachment
       
   557             CUniObject* obj = model->AttachmentList().GetByIndex( 0 );
       
   558             if (    obj &&  obj->MimeType().Length() > 0 )
       
   559                 {
       
   560                 TInt res = 0;
       
   561                 if( obj->MimeType().CompareF( KMsgMimeVCard ) == 0 )
       
   562                     { 
       
   563                     // There's only one VCard
       
   564                     res = R_UNIEDITOR_BIOTYPE_VCARD;
       
   565                     }
       
   566                 else if( obj->MimeType().CompareF( KMsgMimeVCal ) == 0 ||
       
   567                          obj->MimeType().CompareF( KMsgMimeICal ) == 0 )
       
   568                     { 
       
   569                     // There's only one VCal
       
   570                     res = R_UNIEDITOR_BIOTYPE_VCAL;
       
   571                     }
       
   572                 if( res )
       
   573                     {
       
   574                     return StringLoader::LoadL( res, iView.ControlEnv() );
       
   575                     }
       
   576                 }
       
   577             }
       
   578         }
       
   579     
       
   580     TPtrC subject = iDocument.Mtm().SubjectL();
       
   581     TInt firstTextSlide = -1;
       
   582     for ( TInt i = 0; i < model->SmilModel().SlideCount() && firstTextSlide == -1; i++ )
       
   583         {
       
   584         CUniObject* obj = model->SmilModel().GetObject( i, EUniRegionText );
       
   585         if ( obj && obj->MediaType() == EMsgMediaText )
       
   586             {
       
   587             firstTextSlide = i;
       
   588             }
       
   589         }
       
   590         
       
   591     if ( subject.Length() <= 0 &&
       
   592          firstTextSlide != -1 &&
       
   593          iDocument.CurrentSlide() != firstTextSlide )
       
   594         {
       
   595         return NULL;
       
   596         }
       
   597         
       
   598     TInt length = 0;
       
   599     if ( subject.Length() <= 0 )
       
   600         {
       
   601         if ( model->SmilType() == EMmsSmil )
       
   602             {
       
   603             CMsgBodyControl* body = static_cast<CMsgBodyControl*>( iView.ControlById( EMsgComponentIdBody ) );
       
   604             if ( body )
       
   605                 {
       
   606                 length = body->TextContent().DocumentLength();
       
   607                 
       
   608                 // No subject. Change description.
       
   609                 if ( !length )
       
   610                     {
       
   611                     return KNullDesC().AllocL();
       
   612                     }
       
   613                 else
       
   614                     {
       
   615                     TBuf<KUniMaxDescription> description;
       
   616                     description.Zero();
       
   617                     length = ( length < KUniMaxDescription ? length : KUniMaxDescription );
       
   618                    
       
   619                     // 107-24185 : Emoticon support for SMS and MMS
       
   620                     
       
   621                     HBufC *text = body->Editor().GetTextInHBufL();
       
   622                     CleanupStack::PushL( text );
       
   623                     description.Copy( text->Ptr(), length );
       
   624                     CleanupStack::PopAndDestroy( text );
       
   625                     while( length-- )
       
   626                         {
       
   627                         if (    description[length] == CEditableText::ETabCharacter
       
   628                             ||  description[length] == CEditableText::EPageBreak
       
   629                             ||  description[length] == CEditableText::ENonBreakingSpace
       
   630                             ||  description[length] == CEditableText::EHyphen
       
   631                             ||  description[length] == CEditableText::ENonBreakingHyphen
       
   632                             ||  description[length] == CEditableText::ELeftSingleQuote
       
   633                             ||  description[length] == CEditableText::ERightSingleQuote
       
   634                             ||  description[length] == CEditableText::ELeftDoubleQuote
       
   635                             ||  description[length] == CEditableText::ERightDoubleQuote
       
   636                             ||  description[length] == CEditableText::EBullet
       
   637                             ||  description[length] == CEditableText::EEllipsis
       
   638                             ||  description[length] == CEditableText::ELineBreak
       
   639                             ||  description[length] == CEditableText::EParagraphDelimiter 
       
   640                             ||  description[length] == CEditableText::EPictureCharacter
       
   641                             ||  description[length] == CEditableText::EZeroWidthNoBreakSpace
       
   642                             ||  description[length] == CEditableText::EByteOrderMark
       
   643                             ||  description[length] == CEditableText::EReversedByteOrderMark            
       
   644                             ||  description[length] == '\n' )
       
   645                             {
       
   646                             description[length] = ' ';
       
   647                             }
       
   648                         }
       
   649                     description.Trim();
       
   650                     return description.AllocL();
       
   651                     }
       
   652                 }
       
   653             }
       
   654         }
       
   655     else
       
   656         {
       
   657         
       
   658         TBuf<KUniMaxDescription> description;
       
   659         description.Zero();
       
   660         length = subject.Length();
       
   661         CMsgExpandableControl* header = static_cast<CMsgExpandableControl*>( iView.ControlById( EMsgComponentIdSubject ) );
       
   662         
       
   663         // Saving as pure text from the editor which may contain emoticons.
       
   664         HBufC *text = header->Editor().GetTextInHBufL();
       
   665         CleanupStack::PushL( text );
       
   666         description.Copy( text->Ptr(), length );
       
   667         CleanupStack::PopAndDestroy( text );
       
   668        
       
   669 
       
   670         while( length-- )
       
   671             {
       
   672             if ( description[length] == CEditableText::EParagraphDelimiter ||
       
   673                 description[length] == '\n' )
       
   674                 description[length] = ' ';
       
   675             }
       
   676         description.Trim();
       
   677         return description.AllocL();
       
   678         }
       
   679         
       
   680     return NULL;
       
   681     }
       
   682 
       
   683 // ---------------------------------------------------------
       
   684 // CUniEditorSaveOperation::DoSavePluginsL
       
   685 //
       
   686 // 2nd phase constructor.
       
   687 // ---------------------------------------------------------
       
   688 void CUniEditorSaveOperation::DoSavePluginsL()
       
   689     {
       
   690     iOperationState = EUniEditorSaveEnd;
       
   691     
       
   692     if( iDocument.SmsPlugin() )
       
   693         {
       
   694         iDocument.SmsPlugin()->SaveHeadersL( *iEditStore );
       
   695         }
       
   696         
       
   697     if( iDocument.MmsPlugin() )
       
   698         {
       
   699         iDocument.MmsPlugin()->SaveHeadersL( *iEditStore );
       
   700         }
       
   701                 
       
   702     CompleteSelf( KErrNone );
       
   703     }
       
   704 
       
   705 // ---------------------------------------------------------
       
   706 // CUniEditorSaveOperation::DoCancelCleanup
       
   707 //
       
   708 // ---------------------------------------------------------
       
   709 //
       
   710 void CUniEditorSaveOperation::DoCancelCleanup()
       
   711     {    
       
   712     if ( iSavedObject )
       
   713         {
       
   714         iSavedObject->Cancel();
       
   715         }
       
   716     
       
   717     iDocument.DataModel()->SmilList().Cancel();
       
   718     
       
   719     delete iEditStore;
       
   720     iEditStore = NULL;
       
   721     }
       
   722 
       
   723 // ---------------------------------------------------------
       
   724 // CUniEditorSaveOperation::RunL
       
   725 //
       
   726 // ---------------------------------------------------------
       
   727 //
       
   728 void CUniEditorSaveOperation::RunL()
       
   729     {
       
   730     PrintOperationAndState();
       
   731     
       
   732     if ( !SetErrorAndReport( iStatus.Int() ) )
       
   733         {
       
   734         DoSaveStepL();
       
   735         }
       
   736     }
       
   737 // ---------------------------------------------------------
       
   738 // CUniEditorSaveOperation::RunError
       
   739 // ---------------------------------------------------------
       
   740 //
       
   741 TInt CUniEditorSaveOperation::RunError( TInt aError )
       
   742     {
       
   743    
       
   744    if(aError == KErrDiskFull)
       
   745         {
       
   746             iOperationState = EUniEditorSaveError;  
       
   747             CompleteSelf( KErrNone );
       
   748             return KErrNone;               
       
   749         }
       
   750    if ( aError == KLeaveExit )
       
   751         {
       
   752         return KLeaveExit;
       
   753         }
       
   754     else
       
   755         {
       
   756         CompleteSelf( aError );
       
   757         return KErrNone;
       
   758         }
       
   759     }
       
   760 
       
   761 // ---------------------------------------------------------
       
   762 // CUniEditorSaveOperation::ObjectSaveReady
       
   763 // ---------------------------------------------------------
       
   764 //
       
   765 void CUniEditorSaveOperation::ObjectSaveReady( TInt aError )
       
   766     {
       
   767     if ( iSavedObject )
       
   768         {
       
   769         iSavedObject = NULL;
       
   770         iOperationState = EUniEditorSaveEnd;    
       
   771         }
       
   772     else if ( iOperationState == EUniEditorSaveAttachment )
       
   773         {
       
   774         iOperationState = EUniEditorSaveSmilCompose;
       
   775         }
       
   776     else if ( iOperationState == EUniEditorSaveObjects )
       
   777         {
       
   778         iOperationState = EUniEditorSaveAttachment; 
       
   779         }
       
   780         
       
   781     CompleteOperation( aError );
       
   782     }
       
   783 
       
   784 // ---------------------------------------------------------
       
   785 // CUniEditorSaveOperation::SmilComposeEvent
       
   786 // ---------------------------------------------------------
       
   787 //
       
   788 void CUniEditorSaveOperation::SmilComposeEvent( TInt aError )
       
   789     {
       
   790     iOperationState = EUniEditorSaveFinalize;
       
   791     CompleteOperation( aError );
       
   792     }
       
   793 
       
   794 // EOF