mobilemessaging/unieditor/application/src/UniEditorSaveOperation.cpp
branchRCL_3
changeset 60 7fdbb852d323
child 77 da6ac9d688df
equal deleted inserted replaced
57:ebe688cedc25 60:7fdbb852d323
       
     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          if( !(iSaveType == ESendingSave && iDocument.UniState() == EUniSms) )
       
   387              {
       
   388 	        iDocument.DataModel()->SmilList().RemoveSmilL( *iEditStore );
       
   389 	        if ( iSaveType == ESendingSave )
       
   390 	            {
       
   391 	            iDocument.DataModel()->SmilModel().RemoveEmptySlides();
       
   392 	            }
       
   393             
       
   394 	        if ( iDocument.DataModel()->SmilModel().SlideCount() != 0 )
       
   395 	            {
       
   396 	            // Model is not empty -> Compose new SMIL
       
   397 	            iDom = iDocument.DataModel()->SmilModel().ComposeL();
       
   398 	            iDocument.DataModel()->SmilList().CreateSmilAttachmentL( *this, *iEditStore, iDom );
       
   399 	            SetPending();
       
   400 	            return;
       
   401 	            }
       
   402              }
       
   403         }
       
   404         
       
   405     iOperationState = EUniEditorSaveFinalize;
       
   406     CompleteSelf( KErrNone );
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------
       
   410 // CMmsDocument::DoFinalizeSaveL
       
   411 // ---------------------------------------------------------
       
   412 //
       
   413 void CUniEditorSaveOperation::DoFinalizeSaveL()
       
   414     {
       
   415     // Set new state immediately in case some function leaves.
       
   416     iOperationState = EUniEditorSavePlugins;
       
   417 
       
   418     // Set message root after composing SMIL but before calling SaveMessageL
       
   419     TMsvAttachmentId root( 0 );  
       
   420     if ( iDocument.DataModel()->SmilList().Count() )
       
   421         {
       
   422         root = iDocument.DataModel()->SmilList().GetSmilAttachmentByIndex( 0 );
       
   423         }
       
   424     iDocument.Mtm().SetMessageRoot( root );
       
   425 
       
   426 
       
   427     TMsvEntry tEntry = iDocument.Entry();
       
   428     iDocument.Mtm().SaveMessageL( *iEditStore, tEntry );
       
   429     
       
   430     HBufC* description = CreateDescriptionL();
       
   431     if ( description )
       
   432         {
       
   433         tEntry.iDescription.Set( *description );
       
   434         CleanupStack::PushL( description );
       
   435         }
       
   436 
       
   437     // Set details
       
   438     TBuf<KMaxDetailsLength> detailsBuf; 
       
   439     iHeader.MakeDetailsL( detailsBuf );
       
   440     tEntry.iDetails.Set( detailsBuf );
       
   441 
       
   442     if ( iComposeSmil && IsForward() )
       
   443         {
       
   444         //New SMIL composed. This is a normal message from now on.
       
   445         TUniMsvEntry::SetForwardedMessage( tEntry, EFalse );
       
   446         }
       
   447 
       
   448     TUniMsvEntry::SetEditorOriented( tEntry, ETrue );
       
   449     TUniMsvEntry::SetCharSetSupport( tEntry, iDocument.CharSetSupport() );
       
   450 
       
   451     TUniMessageCurrentType curType = EUniMessageCurrentTypeSms;
       
   452     
       
   453     if( iDocument.UniState() == EUniMms )
       
   454         {
       
   455         curType = EUniMessageCurrentTypeMms;
       
   456         
       
   457         TUniSendingSettings settings;
       
   458         
       
   459         if( iDocument.UniState() == EUniMms )
       
   460             {
       
   461             CUniEditorPlugin* mmsPlugin = iDocument.MmsPlugin();
       
   462             
       
   463             if ( mmsPlugin )
       
   464                 {
       
   465                 mmsPlugin->GetSendingSettingsL( settings );
       
   466                 switch ( settings.iPriority )
       
   467                     {
       
   468                     case TUniSendingSettings::EUniPriorityHigh:
       
   469                         {
       
   470                         tEntry.SetPriority( EMsvHighPriority );
       
   471                         break;
       
   472                         }
       
   473                     case TUniSendingSettings::EUniPriorityLow:
       
   474                         {
       
   475                         tEntry.SetPriority( EMsvLowPriority );
       
   476                         break;
       
   477                         }
       
   478                     default:
       
   479                         {
       
   480                         tEntry.SetPriority( EMsvMediumPriority );
       
   481                         break;
       
   482                         }
       
   483                     }
       
   484                 }
       
   485             else
       
   486                 {
       
   487                 // Should not happen but better to handle anyway.
       
   488                 tEntry.SetPriority( EMsvMediumPriority );
       
   489                 }
       
   490             }
       
   491         }
       
   492     else
       
   493         { 
       
   494         // Message is sms -> remove priority
       
   495         tEntry.SetPriority( EMsvMediumPriority );
       
   496         }
       
   497 
       
   498     TUniMsvEntry::SetCurrentMessageType( tEntry, curType );
       
   499 
       
   500     tEntry.SetAttachment( EFalse );
       
   501 
       
   502     if ( iSaveType >= EClosingSave )
       
   503         {
       
   504         // Update timestamp  
       
   505         tEntry.iDate.UniversalTime();
       
   506 
       
   507         if ( !tEntry.Visible() )
       
   508             {
       
   509             // Save from close or exit save.
       
   510             // Message should be visible after save
       
   511             tEntry.SetVisible( ETrue );
       
   512             tEntry.SetInPreparation( EFalse );
       
   513             }
       
   514         }
       
   515     else 
       
   516         {
       
   517         // Save made because user launched Message Info, Preview or Objects view 
       
   518         // Message should stay invisible and in preparation if it was.
       
   519         if ( !tEntry.Visible() )
       
   520             {
       
   521             // Guarantee that when Visible is ETrue InPreparation is EFalse 
       
   522             tEntry.SetInPreparation( ETrue );
       
   523             }
       
   524         }
       
   525 
       
   526 
       
   527 
       
   528     iDocument.CurrentEntry().ChangeL( tEntry );
       
   529     
       
   530     if ( description )
       
   531         {
       
   532         // This must not be popped before ChangeL
       
   533         CleanupStack::PopAndDestroy( description );
       
   534         }
       
   535 
       
   536     iDocument.SetHeaderModified( EFalse );
       
   537     iDocument.SetBodyModified( EFalse );
       
   538     iDocument.SetPrevSaveType( iSaveType );
       
   539 
       
   540     CompleteSelf( KErrNone );
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------
       
   544 // CUniEditorSaveOperation::CreateDescriptionL
       
   545 //
       
   546 // Creates description buffer. Returns NULL if description is not
       
   547 // wanted to be updated.
       
   548 // ---------------------------------------------------------
       
   549 //
       
   550 HBufC* CUniEditorSaveOperation::CreateDescriptionL()
       
   551     {
       
   552     CUniDataModel* model = iDocument.DataModel();
       
   553 
       
   554     if( iDocument.UniState() == EUniSms )
       
   555         {
       
   556         if( model->ObjectList().Count() == 0 &&
       
   557             model->AttachmentList().Count() == 1 )
       
   558             { 
       
   559             // No objects and one attachment
       
   560             CUniObject* obj = model->AttachmentList().GetByIndex( 0 );
       
   561             if (    obj &&  obj->MimeType().Length() > 0 )
       
   562                 {
       
   563                 TInt res = 0;
       
   564                 if( obj->MimeType().CompareF( KMsgMimeVCard ) == 0 )
       
   565                     { 
       
   566                     // There's only one VCard
       
   567                     res = R_UNIEDITOR_BIOTYPE_VCARD;
       
   568                     }
       
   569                 else if( obj->MimeType().CompareF( KMsgMimeVCal ) == 0 ||
       
   570                          obj->MimeType().CompareF( KMsgMimeICal ) == 0 )
       
   571                     { 
       
   572                     // There's only one VCal
       
   573                     res = R_UNIEDITOR_BIOTYPE_VCAL;
       
   574                     }
       
   575                 if( res )
       
   576                     {
       
   577                     return StringLoader::LoadL( res, iView.ControlEnv() );
       
   578                     }
       
   579                 }
       
   580             }
       
   581         }
       
   582     
       
   583     TPtrC subject = iDocument.Mtm().SubjectL();
       
   584     TInt firstTextSlide = -1;
       
   585     for ( TInt i = 0; i < model->SmilModel().SlideCount() && firstTextSlide == -1; i++ )
       
   586         {
       
   587         CUniObject* obj = model->SmilModel().GetObject( i, EUniRegionText );
       
   588         if ( obj && obj->MediaType() == EMsgMediaText )
       
   589             {
       
   590             firstTextSlide = i;
       
   591             }
       
   592         }
       
   593         
       
   594     if ( subject.Length() <= 0 &&
       
   595          firstTextSlide != -1 &&
       
   596          iDocument.CurrentSlide() != firstTextSlide )
       
   597         {
       
   598         return NULL;
       
   599         }
       
   600         
       
   601     TInt length = 0;
       
   602     if ( subject.Length() <= 0 )
       
   603         {
       
   604         if ( model->SmilType() == EMmsSmil )
       
   605             {
       
   606             CMsgBodyControl* body = static_cast<CMsgBodyControl*>( iView.ControlById( EMsgComponentIdBody ) );
       
   607             if ( body )
       
   608                 {
       
   609                 length = body->TextContent().DocumentLength();
       
   610                 
       
   611                 // No subject. Change description.
       
   612                 if ( !length )
       
   613                     {
       
   614                     return KNullDesC().AllocL();
       
   615                     }
       
   616                 else
       
   617                     {
       
   618                     TBuf<KUniMaxDescription> description;
       
   619                     description.Zero();
       
   620                     length = ( length < KUniMaxDescription ? length : KUniMaxDescription );
       
   621                    
       
   622                     // 107-24185 : Emoticon support for SMS and MMS
       
   623                     
       
   624                     HBufC *text = body->Editor().GetTextInHBufL();
       
   625                     CleanupStack::PushL( text );
       
   626                     description.Copy( text->Ptr(), length );
       
   627                     CleanupStack::PopAndDestroy( text );
       
   628                     while( length-- )
       
   629                         {
       
   630                         if (    description[length] == CEditableText::ETabCharacter
       
   631                             ||  description[length] == CEditableText::EPageBreak
       
   632                             ||  description[length] == CEditableText::ENonBreakingSpace
       
   633                             ||  description[length] == CEditableText::EHyphen
       
   634                             ||  description[length] == CEditableText::ENonBreakingHyphen
       
   635                             ||  description[length] == CEditableText::ELeftSingleQuote
       
   636                             ||  description[length] == CEditableText::ERightSingleQuote
       
   637                             ||  description[length] == CEditableText::ELeftDoubleQuote
       
   638                             ||  description[length] == CEditableText::ERightDoubleQuote
       
   639                             ||  description[length] == CEditableText::EBullet
       
   640                             ||  description[length] == CEditableText::EEllipsis
       
   641                             ||  description[length] == CEditableText::ELineBreak
       
   642                             ||  description[length] == CEditableText::EParagraphDelimiter 
       
   643                             ||  description[length] == CEditableText::EPictureCharacter
       
   644                             ||  description[length] == CEditableText::EZeroWidthNoBreakSpace
       
   645                             ||  description[length] == CEditableText::EByteOrderMark
       
   646                             ||  description[length] == CEditableText::EReversedByteOrderMark            
       
   647                             ||  description[length] == '\n' )
       
   648                             {
       
   649                             description[length] = ' ';
       
   650                             }
       
   651                         }
       
   652                     description.Trim();
       
   653                     return description.AllocL();
       
   654                     }
       
   655                 }
       
   656             }
       
   657         }
       
   658     else
       
   659         {
       
   660         
       
   661         TBuf<KUniMaxDescription> description;
       
   662         description.Zero();
       
   663         length = subject.Length();     
       
   664         // Saving as pure text from the editor which may contain emoticons.
       
   665         HBufC *text = iHeader.SubjectControl()->Editor().GetTextInHBufL();
       
   666         if(text)
       
   667             {
       
   668         CleanupStack::PushL( text );
       
   669         description.Copy( text->Ptr(), length );
       
   670         CleanupStack::PopAndDestroy( text );
       
   671             
       
   672        
       
   673 
       
   674         while( length-- )
       
   675             {
       
   676             if ( description[length] == CEditableText::EParagraphDelimiter ||
       
   677                 description[length] == '\n' )
       
   678                 description[length] = ' ';
       
   679             }
       
   680         description.Trim();
       
   681         return description.AllocL();
       
   682         }
       
   683         else
       
   684          {
       
   685             return KNullDesC().AllocL();
       
   686             }
       
   687         }
       
   688         
       
   689     return NULL;
       
   690     }
       
   691 
       
   692 // ---------------------------------------------------------
       
   693 // CUniEditorSaveOperation::DoSavePluginsL
       
   694 //
       
   695 // 2nd phase constructor.
       
   696 // ---------------------------------------------------------
       
   697 void CUniEditorSaveOperation::DoSavePluginsL()
       
   698     {
       
   699     iOperationState = EUniEditorSaveEnd;
       
   700     
       
   701     if( iDocument.SmsPlugin() )
       
   702         {
       
   703         iDocument.SmsPlugin()->SaveHeadersL( *iEditStore );
       
   704         }
       
   705         
       
   706     if( iDocument.MmsPlugin() )
       
   707         {
       
   708         iDocument.MmsPlugin()->SaveHeadersL( *iEditStore );
       
   709         }
       
   710                 
       
   711     CompleteSelf( KErrNone );
       
   712     }
       
   713 
       
   714 // ---------------------------------------------------------
       
   715 // CUniEditorSaveOperation::DoCancelCleanup
       
   716 //
       
   717 // ---------------------------------------------------------
       
   718 //
       
   719 void CUniEditorSaveOperation::DoCancelCleanup()
       
   720     {    
       
   721     if ( iSavedObject )
       
   722         {
       
   723         iSavedObject->Cancel();
       
   724         }
       
   725     
       
   726     iDocument.DataModel()->SmilList().Cancel();
       
   727     
       
   728     delete iEditStore;
       
   729     iEditStore = NULL;
       
   730     }
       
   731 
       
   732 // ---------------------------------------------------------
       
   733 // CUniEditorSaveOperation::RunL
       
   734 //
       
   735 // ---------------------------------------------------------
       
   736 //
       
   737 void CUniEditorSaveOperation::RunL()
       
   738     {
       
   739     PrintOperationAndState();
       
   740     
       
   741     if ( !SetErrorAndReport( iStatus.Int() ) )
       
   742         {
       
   743         DoSaveStepL();
       
   744         }
       
   745     }
       
   746 // ---------------------------------------------------------
       
   747 // CUniEditorSaveOperation::RunError
       
   748 // ---------------------------------------------------------
       
   749 //
       
   750 TInt CUniEditorSaveOperation::RunError( TInt aError )
       
   751     {
       
   752    
       
   753    if(aError == KErrDiskFull)
       
   754         {
       
   755             iOperationState = EUniEditorSaveError;  
       
   756             CompleteSelf( KErrNone );
       
   757             return KErrNone;               
       
   758         }
       
   759    if ( aError == KLeaveExit )
       
   760         {
       
   761         return KLeaveExit;
       
   762         }
       
   763     else
       
   764         {
       
   765         CompleteSelf( aError );
       
   766         return KErrNone;
       
   767         }
       
   768     }
       
   769 
       
   770 // ---------------------------------------------------------
       
   771 // CUniEditorSaveOperation::ObjectSaveReady
       
   772 // ---------------------------------------------------------
       
   773 //
       
   774 void CUniEditorSaveOperation::ObjectSaveReady( TInt aError )
       
   775     {
       
   776     if ( iSavedObject )
       
   777         {
       
   778         iSavedObject = NULL;
       
   779         iOperationState = EUniEditorSaveEnd;    
       
   780         }
       
   781     else if ( iOperationState == EUniEditorSaveAttachment )
       
   782         {
       
   783         iOperationState = EUniEditorSaveSmilCompose;
       
   784         }
       
   785     else if ( iOperationState == EUniEditorSaveObjects )
       
   786         {
       
   787         iOperationState = EUniEditorSaveAttachment; 
       
   788         }
       
   789         
       
   790     CompleteOperation( aError );
       
   791     }
       
   792 
       
   793 // ---------------------------------------------------------
       
   794 // CUniEditorSaveOperation::SmilComposeEvent
       
   795 // ---------------------------------------------------------
       
   796 //
       
   797 void CUniEditorSaveOperation::SmilComposeEvent( TInt aError )
       
   798     {
       
   799     iOperationState = EUniEditorSaveFinalize;
       
   800     CompleteOperation( aError );
       
   801     }
       
   802 
       
   803 // EOF