messagingappbase/msgeditor/modelsrc/MsgAttachmentUtils.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  MsgAttachmentUtils implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ========== INCLUDE FILES ================================
       
    21 
       
    22 #include <featmgr.h>
       
    23 #include <data_caging_path_literals.hrh>
       
    24 
       
    25 #include <eikenv.h>                 // for CEikonEnv
       
    26 #include <eikproc.h>                // for CEikProcess
       
    27 #include <gulicon.h>
       
    28 #include <apparc.h>                 // for CApaApplication
       
    29 #include <apgcli.h>                 // for RApaLsSession
       
    30 #include <apacln.h>                 // for TApaDocCleanupItem
       
    31 #include <txtetext.h>               // for CPlainText
       
    32 #include <gdi.h>
       
    33 #include <bautils.h>                // NearestLanguageFile
       
    34 
       
    35 #include <avkon.rsg>                // for R_QTN_SIZE_xx
       
    36 #include <aknlayout.cdl.h> // LAF
       
    37 #include <AknUtils.h>
       
    38 
       
    39 #include <AknCommonDialogsDynMem.h>
       
    40 
       
    41 #ifdef RD_MULTIPLE_DRIVE
       
    42 #include <driveinfo.h>
       
    43 #endif
       
    44 
       
    45 #include <NpdApi.h>                 // Notepad API
       
    46 #include <StringLoader.h>           // StringLoader
       
    47 
       
    48 #include <MGFetch.h>               // for MediaGallery
       
    49 
       
    50 #include <NewFileServiceClient.h>
       
    51 #include <NewFileService.hrh>
       
    52 #include <AiwCommon.h>
       
    53 
       
    54 #include "MsgEditorCommon.h"        // for KMsgEditorTempDir
       
    55 #include "MsgAttachmentUtils.h"
       
    56 #include "MsgEditorModelPanic.h"    // Panics
       
    57 #include <MsgEditorAppUi.rsg>       // resouce identifiers
       
    58 
       
    59 // ========== EXTERNAL DATA STRUCTURES =====================
       
    60 
       
    61 // ========== EXTERNAL FUNCTION PROTOTYPES =================
       
    62 
       
    63 // ========== CONSTANTS ====================================
       
    64 
       
    65 const TInt KMsgAttaFileNameLength = 20;
       
    66 _LIT( KTxtAttaFilenameExtension, ".txt" );
       
    67 _LIT( KMsgEditorAppUiResourceFileName, "msgeditorappui.rsc" );
       
    68 
       
    69 _LIT( KMsgEditorTempDir, ":\\system\\temp\\msgeditor_temp\\" );
       
    70 
       
    71 const TInt KLocalKilo = 1024;
       
    72 
       
    73 const TUid KUidCamcorder = { 0x101F857A };
       
    74 const TUid KUidVoiceRec  = { 0x100058CA };
       
    75 //const TUid KUidCamera    = { 0x1000593F };
       
    76 
       
    77 // ========== MACROS =======================================
       
    78 
       
    79 // ========== LOCAL CONSTANTS AND MACROS ===================
       
    80 
       
    81 // ========== MODULE DATA STRUCTURES =======================
       
    82 
       
    83 // ========== LOCAL FUNCTION PROTOTYPES ====================
       
    84 
       
    85 // ========== LOCAL FUNCTIONS ==============================
       
    86 
       
    87 // ========== MEMBER FUNCTIONS =============================
       
    88 
       
    89 // ---------------------------------------------------------
       
    90 // MsgAttachmentUtils::FetchFile
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 EXPORT_C TBool MsgAttachmentUtils::FetchFileL (
       
    94     TMsgAttachmentFetchType aType,
       
    95     TFileName& aFileName,
       
    96     TBool aCheckDiskSpace )
       
    97     {
       
    98     return FetchFileL( aType, aFileName, KNullUid, aCheckDiskSpace );
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------
       
   102 // MsgAttachmentUtils::FetchFile
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 EXPORT_C TBool MsgAttachmentUtils::FetchFileL (
       
   106     TMsgAttachmentFetchType aType,
       
   107     TFileName& aFileName,
       
   108     const TUid& /*aAppUid*/,
       
   109     TBool aCheckDiskSpace )
       
   110     {
       
   111     TBool result = EFalse;
       
   112     CDesCArrayFlat* files = new ( ELeave ) CDesC16ArrayFlat( 1 );
       
   113     CleanupStack::PushL( files );
       
   114     result = FetchFileL( aType, aFileName, *files, aCheckDiskSpace, EFalse, NULL );
       
   115     CleanupStack::PopAndDestroy( ); //files
       
   116     return result;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // MsgAttachmentUtils::FetchFile
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 EXPORT_C TBool MsgAttachmentUtils::FetchFileL (
       
   124     TMsgAttachmentFetchType aType,
       
   125     TFileName& aFileName,
       
   126     CDesCArray& aSelectedFiles,    
       
   127     TBool aCheckDiskSpace,
       
   128     TBool aMultiSelect,
       
   129     MMGFetchVerifier* aVerifier )
       
   130     {
       
   131     TBool result = FetchFileL( aType, aSelectedFiles, NULL, aCheckDiskSpace, aMultiSelect, aVerifier );
       
   132     if ( aSelectedFiles.MdcaCount() )
       
   133         {
       
   134         aFileName.Zero();
       
   135         aFileName = aSelectedFiles.MdcaPoint( 0 );
       
   136         }
       
   137     return result;
       
   138     }
       
   139     
       
   140 // ---------------------------------------------------------
       
   141 // MsgAttachmentUtils::FetchFile
       
   142 // ---------------------------------------------------------
       
   143 //
       
   144 EXPORT_C TBool MsgAttachmentUtils::FetchFileL (
       
   145     TMsgAttachmentFetchType aType,
       
   146     CDesCArray& aSelectedFiles,
       
   147     CAiwGenericParamList* aParams,
       
   148     TBool /*aCheckDiskSpace*/,
       
   149     TBool aMultiSelect,
       
   150     MMGFetchVerifier* aVerifier )
       
   151     {
       
   152     TBool result = EFalse;
       
   153 
       
   154     switch ( aType )
       
   155         {
       
   156         case EImage:
       
   157             {
       
   158             result = FetchExistingL( EImageFile, aSelectedFiles, aMultiSelect, aVerifier );
       
   159             break;
       
   160             }
       
   161         case EAudio:
       
   162             {
       
   163             result = FetchExistingL( EAudioFile, aSelectedFiles, aMultiSelect, aVerifier );
       
   164             break;
       
   165             }
       
   166         case EVideo:
       
   167             {
       
   168             result = FetchExistingL( EVideoFile, aSelectedFiles, aMultiSelect, aVerifier );
       
   169             break;
       
   170             }
       
   171         case ENewAudio:
       
   172             {
       
   173             result = FetchNewL( ENewFileServiceAudio, aSelectedFiles, aParams, aMultiSelect );
       
   174             break;
       
   175             }
       
   176         case ENewImage:
       
   177             {
       
   178             result = FetchNewL( ENewFileServiceImage, aSelectedFiles, aParams, aMultiSelect );
       
   179             break;
       
   180             }
       
   181         case ENewVideo:
       
   182             {
       
   183             result = FetchNewL( ENewFileServiceVideo, aSelectedFiles, aParams, aMultiSelect );
       
   184             break;
       
   185             }
       
   186         case ENote:
       
   187             {
       
   188             result = FetchNoteL( aSelectedFiles );
       
   189             break;
       
   190             }
       
   191         case ESVG:
       
   192             {
       
   193             result = FetchExistingL( EPresentationsFile, aSelectedFiles, aMultiSelect, aVerifier );
       
   194             break;
       
   195             }
       
   196         default:
       
   197             {
       
   198             break;
       
   199             }
       
   200         }
       
   201 
       
   202     return result;
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------
       
   206 // MsgAttachmentUtils::FetchExistingL
       
   207 //
       
   208 //
       
   209 // ---------------------------------------------------------
       
   210 
       
   211 TBool MsgAttachmentUtils::FetchExistingL( TMediaFileType aFileType,
       
   212                                          CDesCArray& aSelectedFiles,
       
   213                                          TBool aMultiSelect,
       
   214                                          MMGFetchVerifier* aVerifier )
       
   215 
       
   216     {
       
   217     return MGFetch::RunL( aSelectedFiles, aFileType, aMultiSelect, aVerifier );
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------
       
   221 // MsgAttachmentUtils::FetchNoteL
       
   222 //
       
   223 //
       
   224 // ---------------------------------------------------------
       
   225 TBool MsgAttachmentUtils::FetchNoteL( CDesCArray& aSelectedFiles )
       
   226     {
       
   227     TBool result = EFalse;
       
   228     CEikonEnv* eikonEnv = CEikonEnv::Static();
       
   229 
       
   230     // get memo content from notepad to buffer.
       
   231     HBufC* title = eikonEnv->AllocReadResourceLC( R_QTN_NMAKE_FETCH_MEMO_PRMPT );
       
   232     HBufC* buf = CNotepadApi::FetchMemoL( title );
       
   233     CleanupStack::PopAndDestroy( title );
       
   234 
       
   235     if ( buf )
       
   236         {
       
   237         CleanupStack::PushL( buf );
       
   238 
       
   239         RFs& fs = eikonEnv->FsSession();
       
   240 
       
   241         TFileName filename;
       
   242         TInt max = KMsgAttaFileNameLength;
       
   243 
       
   244         // first try to create filename from memo text.
       
   245         MsgAttachmentUtils::GetFileNameFromBuffer (
       
   246             filename, *buf, max, &KTxtAttaFilenameExtension );
       
   247 
       
   248         if ( filename.Length() == 0 )
       
   249             {
       
   250             eikonEnv->ReadResourceL( filename, R_QTN_MMS_NO_NAME_FOR_FILE );
       
   251             filename.Append( KTxtAttaFilenameExtension );
       
   252             }
       
   253 
       
   254         TFileName pathname;
       
   255         GetMsgEditorTempPath( pathname, &filename );
       
   256 
       
   257         // check the file name for validity and possible name duplicates.
       
   258         TInt err = CApaApplication::GenerateFileName( fs, pathname );
       
   259 
       
   260         if ( err == KErrNone )
       
   261             {
       
   262             // write buffer to text file (unicode).
       
   263             CPlainText* text = CPlainText::NewL();
       
   264             CleanupStack::PushL( text );
       
   265             text->InsertL( 0, *buf );
       
   266             text->ExportAsTextL( pathname, CPlainText::EOrganiseByParagraph, 0 );
       
   267             CleanupStack::PopAndDestroy( text );
       
   268             aSelectedFiles.AppendL( pathname );
       
   269             result = ETrue;
       
   270             }
       
   271 
       
   272         CleanupStack::PopAndDestroy( buf );
       
   273         }
       
   274     return result;
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------
       
   278 // MsgAttachmentUtils::FetchNewL
       
   279 //
       
   280 //
       
   281 // ---------------------------------------------------------
       
   282 TBool MsgAttachmentUtils::FetchNewL( TNewServiceFileType aType,
       
   283                                     CDesCArray& aSelectedFiles,
       
   284                                     CAiwGenericParamList* aParams,
       
   285                                     TBool aMultiSelect )
       
   286     {
       
   287     TBool result = EFalse;    
       
   288     CNewFileServiceClient* fileClient = NewFileServiceFactory::NewClientL();
       
   289     CleanupStack::PushL( fileClient );
       
   290 
       
   291     TUid appUid = KUidCamcorder; 
       
   292     switch ( aType )
       
   293         {
       
   294         case ENewFileServiceImage:
       
   295         case ENewFileServiceVideo:
       
   296             {
       
   297             appUid = KUidCamcorder;
       
   298             break;
       
   299             }
       
   300         case ENewFileServiceAudio:
       
   301             {
       
   302             appUid = KUidVoiceRec;
       
   303             break;
       
   304             }
       
   305         default:
       
   306             User::Leave( KErrArgument );
       
   307             break;
       
   308         }
       
   309     
       
   310     result = fileClient->NewFileL(
       
   311         appUid, 
       
   312         aSelectedFiles,
       
   313         aParams,
       
   314         aType,
       
   315         aMultiSelect );
       
   316     CleanupStack::PopAndDestroy( fileClient ); // params
       
   317     return result;
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // MsgAttachmentUtils::FetchAnyFileL
       
   322 //
       
   323 //
       
   324 // ---------------------------------------------------------
       
   325 EXPORT_C TBool MsgAttachmentUtils::FetchAnyFileL( TFileName& aFileName,
       
   326                                                   CCoeEnv& aCoeEnv,
       
   327                                                   MAknFileSelectionObserver* aVerifier,
       
   328                                                   MAknFileFilter* aFilter )
       
   329     {
       
   330     TBool result( EFalse );
       
   331     TInt resourceFileOffset( -1 );
       
   332     
       
   333     if ( !aCoeEnv.IsResourceAvailableL( R_MEB_MEMORY_SELECTION_DIALOG ) )
       
   334         {
       
   335         TParse parse;
       
   336         parse.Set( KMsgEditorAppUiResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   337         
       
   338         TFileName fileName( parse.FullName() );
       
   339         BaflUtils::NearestLanguageFile( aCoeEnv.FsSession(), fileName );
       
   340         
       
   341         resourceFileOffset = aCoeEnv.AddResourceFileL( fileName );
       
   342         }
       
   343 
       
   344     TInt supportedTypes = AknCommonDialogsDynMem::EMemoryTypePhone | 
       
   345                           AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage | 
       
   346                           AknCommonDialogsDynMem::EMemoryTypeMMCExternal;
       
   347                            
       
   348     result = AknCommonDialogsDynMem::RunSelectDlgLD( supportedTypes,
       
   349                                                      aFileName,
       
   350                                                      R_MEB_MEMORY_SELECTION_DIALOG,
       
   351                                                      aFilter,
       
   352                                                      aVerifier );
       
   353     
       
   354     if ( resourceFileOffset != -1 )
       
   355         {
       
   356         aCoeEnv.DeleteResourceFile( resourceFileOffset );
       
   357         }
       
   358         
       
   359     return result;
       
   360     }
       
   361 
       
   362 // ---------------------------------------------------------
       
   363 // MsgAttachmentUtils::CombineIconsL
       
   364 //
       
   365 //
       
   366 // ---------------------------------------------------------
       
   367 //
       
   368 EXPORT_C CFbsBitmap* MsgAttachmentUtils::CombineIconsL(
       
   369     const CFbsBitmap* aFirstBmp,
       
   370     const CFbsBitmap* aSecondBmp,
       
   371     const CFbsBitmap* aSecondBmpMask )
       
   372     {
       
   373     __ASSERT_DEBUG( aFirstBmp, Panic( ENullPointer ) );
       
   374 
       
   375     // Resolve icon layout
       
   376     TRect mainPane;
       
   377     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPane );
       
   378     TAknLayoutRect listPaneLayout;
       
   379     listPaneLayout.LayoutRect(
       
   380         mainPane,
       
   381         AknLayout::list_gen_pane( 0 ) );
       
   382     TAknLayoutRect doubleGraphicLayout;
       
   383     doubleGraphicLayout.LayoutRect(
       
   384         listPaneLayout.Rect(),
       
   385         AknLayout::list_double_large_graphic_pane_list_double2_large_graphic_pane_list_single_big_large_graphic_pane( 0 ) );
       
   386     TAknLayoutRect iconLayout;
       
   387     iconLayout.LayoutRect(             
       
   388         doubleGraphicLayout.Rect(),
       
   389         AknLayout::List_pane_elements__double_large_graphic__Line_8() );
       
   390 
       
   391     TInt cleanupCount = 0;
       
   392 
       
   393     TDisplayMode dispMode = aFirstBmp->DisplayMode();
       
   394     if ( dispMode == EGray2 )
       
   395         {
       
   396         // Convert hard masks to soft masks:
       
   397         CFbsBitmap* temp = InvertBitmapL( aFirstBmp );
       
   398         CleanupStack::PushL( temp );
       
   399         aFirstBmp = temp;
       
   400         cleanupCount++;
       
   401         dispMode = EGray256;
       
   402         }
       
   403 
       
   404     // Create target bitmap, device and gc
       
   405     CFbsBitmap* bmp = new ( ELeave ) CFbsBitmap();
       
   406     CleanupStack::PushL( bmp );
       
   407     User::LeaveIfError( bmp->Create( iconLayout.Rect().Size(), dispMode ) );
       
   408     CFbsBitmapDevice* pBmpDev = CFbsBitmapDevice::NewL( bmp );
       
   409     CleanupStack::Pop(); // bmp
       
   410     CleanupStack::PushL( pBmpDev );
       
   411     CBitmapContext* pBmpCtx = NULL;
       
   412     User::LeaveIfError( pBmpDev->CreateBitmapContext( pBmpCtx ) );
       
   413     CleanupStack::PushL( pBmpCtx );
       
   414     
       
   415     // Clear the target bitmap.
       
   416     // Black background for soft masks
       
   417     pBmpCtx->SetBrushColor( ( dispMode == EGray256 )
       
   418         ? KRgbBlack
       
   419         : KRgbWhite );
       
   420     pBmpCtx->Clear();
       
   421 
       
   422     // First draw the source bitmap...
       
   423     const TSize bmpSize1( aFirstBmp->SizeInPixels() );
       
   424     const TPoint origin1(
       
   425         ( iconLayout.Rect().Width() - bmpSize1.iWidth ) / 2,
       
   426         ( iconLayout.Rect().Height() - bmpSize1.iHeight ) / 2 );
       
   427 
       
   428     pBmpCtx->BitBlt( origin1, aFirstBmp );
       
   429 
       
   430     if ( aSecondBmp )
       
   431         {
       
   432         if ( aSecondBmp->DisplayMode() == EGray2 )
       
   433             {
       
   434             // Convert hard masks to soft masks:
       
   435             CFbsBitmap* temp = InvertBitmapL( aSecondBmp );
       
   436             CleanupStack::PushL( temp );
       
   437             aSecondBmp = temp;
       
   438             cleanupCount++;
       
   439             }
       
   440 
       
   441         // ...then draw the other bitmap on top.
       
   442         const TSize bmpSize2( aSecondBmp->SizeInPixels() );
       
   443         const TPoint origin2( 0, iconLayout.Rect().Height() - bmpSize2.iHeight );
       
   444 
       
   445         if ( !aSecondBmpMask )
       
   446             {
       
   447             pBmpCtx->BitBlt( origin2, aSecondBmp );
       
   448             }
       
   449         else
       
   450             {
       
   451             pBmpCtx->BitBltMasked(
       
   452                 origin2,
       
   453                 aSecondBmp,
       
   454                 TRect( bmpSize2 ),
       
   455                 aSecondBmpMask,
       
   456                 ETrue );
       
   457             }
       
   458         }
       
   459 
       
   460     // Cleanup.
       
   461     CleanupStack::PopAndDestroy( 2 ); // pBmpDev, pBmpCtx
       
   462     CleanupStack::PopAndDestroy( cleanupCount );
       
   463 
       
   464     // Return the new bitmap.
       
   465     return bmp;
       
   466     }
       
   467 
       
   468 // ---------------------------------------------------------
       
   469 // MsgAttachmentUtils::InvertBitmapL
       
   470 //
       
   471 //
       
   472 // ---------------------------------------------------------
       
   473 //
       
   474 CFbsBitmap* MsgAttachmentUtils::InvertBitmapL( const CFbsBitmap* aBitmap )
       
   475     {
       
   476     // Create target bitmap, device and gc
       
   477     CFbsBitmap* bmp = new ( ELeave ) CFbsBitmap();
       
   478     CleanupStack::PushL( bmp );
       
   479     User::LeaveIfError( bmp->Create( aBitmap->SizeInPixels(), aBitmap->DisplayMode() ) );
       
   480     CFbsBitmapDevice* pBmpDev = CFbsBitmapDevice::NewL( bmp );
       
   481     CleanupStack::Pop(); // bmp
       
   482     CleanupStack::PushL( pBmpDev );
       
   483     CBitmapContext* pBmpCtx = NULL;
       
   484     User::LeaveIfError( pBmpDev->CreateBitmapContext( pBmpCtx ) );
       
   485     CleanupStack::Pop(); // pBmpDev
       
   486 
       
   487     // Set drawing mode to "NOTPEN" -> bitmap will be inverted
       
   488     pBmpCtx->SetDrawMode( CGraphicsContext::EDrawModeNOTPEN );
       
   489     pBmpCtx->BitBlt( TPoint( 0, 0 ), aBitmap );
       
   490 
       
   491     // Cleanup.
       
   492     delete pBmpCtx;
       
   493     delete pBmpDev;
       
   494 
       
   495     // Return the new bitmap.
       
   496     return bmp;
       
   497     }
       
   498 
       
   499 
       
   500 // ---------------------------------------------------------
       
   501 // MsgAttachmentUtils::FileSizeToStringL
       
   502 //
       
   503 //
       
   504 // ---------------------------------------------------------
       
   505 //
       
   506 EXPORT_C void MsgAttachmentUtils::FileSizeToStringL(
       
   507     TDes& aTarget, TInt aFileSize, TBool aKilobytesMinimum /*= EFalse*/ )
       
   508     {
       
   509     TInt fileSize = aFileSize;
       
   510     TInt resId = R_QTN_SIZE_B;
       
   511 
       
   512     if ( aKilobytesMinimum || aFileSize >= KLocalKilo )
       
   513         {
       
   514         resId = R_QTN_SIZE_KB;
       
   515         fileSize /= KLocalKilo;
       
   516         if ( aFileSize % KLocalKilo )
       
   517             {
       
   518             fileSize++;
       
   519             }
       
   520         }
       
   521 
       
   522     HBufC *buf = StringLoader::LoadLC( resId, fileSize );
       
   523     aTarget.Zero();
       
   524     aTarget.Append( *buf );
       
   525 
       
   526     CleanupStack::PopAndDestroy( buf );
       
   527     }
       
   528 
       
   529 //----------------------------------------------------------------------------
       
   530 // from: TBool CImRecvConvert::IsIllegalChar(const TUint aChar)
       
   531 //----------------------------------------------------------------------------
       
   532 LOCAL_C TBool IsIllegalChar(const TUint aChar)
       
   533     {
       
   534     return (
       
   535         aChar == '*'  ||
       
   536         aChar == '\\' ||
       
   537         aChar == '<'  ||
       
   538         aChar == '>'  ||
       
   539         aChar == ':'  ||
       
   540         aChar == '.'  ||
       
   541         aChar == '"'  ||
       
   542         aChar == '/'  ||
       
   543         aChar == '|'  ||
       
   544         aChar == '?'  ||
       
   545         aChar == CEditableText::EParagraphDelimiter  ||
       
   546         aChar == CEditableText::ELineBreak  ||
       
   547         aChar <  ' ' );
       
   548     }
       
   549 
       
   550 // ---------------------------------------------------------
       
   551 // MsgAttachmentUtils::GetFileNameFromBuffer
       
   552 //
       
   553 //
       
   554 // ---------------------------------------------------------
       
   555 //
       
   556 EXPORT_C void MsgAttachmentUtils::GetFileNameFromBuffer(
       
   557     TFileName& aFileName,
       
   558     const TDesC& aBuffer,
       
   559     TInt aMaxLength,
       
   560     const TDesC* aExt /*= NULL*/ )
       
   561     {
       
   562     if ( aExt != NULL )
       
   563         {
       
   564         aMaxLength -= aExt->Length();
       
   565         }
       
   566 
       
   567     TInt len = aBuffer.Length();
       
   568     TInt max = Min( len, aMaxLength );
       
   569 
       
   570     __ASSERT_DEBUG( max > 0, Panic( EMsgZeroLength ) );
       
   571 
       
   572     aFileName.Zero();
       
   573 
       
   574     TInt cc = 0;
       
   575     TUint ch;
       
   576     TUint ch1 = 0;
       
   577     TBool spaces = EFalse;
       
   578     for ( TInt i = 0; i < len && cc < max; i++ )
       
   579         {
       
   580         ch = aBuffer[i];
       
   581 
       
   582         // ignore spaces from beginning of the buffer until first
       
   583         // non-space is encountered.
       
   584         if ( !spaces && ch != ' ' )
       
   585             {
       
   586             spaces = ETrue;
       
   587             }
       
   588 
       
   589         if ( i > 0 )
       
   590             {
       
   591             ch1 = aBuffer[i - 1];
       
   592             }
       
   593 
       
   594         // strip illegal chars away.
       
   595         // checks also if previous and current chars are '.'
       
   596         if ( spaces && ! IsIllegalChar( ch ) )
       
   597             {
       
   598             if ( !( i > 0 && ch == '.' && ch1 == '.' ) )
       
   599                 {
       
   600                 aFileName.Append( ch );
       
   601                 cc++;
       
   602                 }
       
   603             }
       
   604         }
       
   605 
       
   606     aFileName.Trim();
       
   607 
       
   608     // If filename is empty at this point, do not append extension either.
       
   609     // Instead, empty filename is returned so that caller can use whatever
       
   610     // default s/he has for it.
       
   611     if ( aFileName.Length() > 0 && aExt != NULL )
       
   612         {
       
   613         aFileName.Append( *aExt );
       
   614         }
       
   615     }
       
   616 
       
   617 // ---------------------------------------------------------
       
   618 // MsgAttachmentUtils::GetMsgEditorTempPath
       
   619 //
       
   620 // Returns temp path used by msg editors and optionally
       
   621 // appends file name to it.
       
   622 // ---------------------------------------------------------
       
   623 //
       
   624 EXPORT_C void MsgAttachmentUtils::GetMsgEditorTempPath(
       
   625     TFileName& aTempPath,
       
   626     const TDesC* aFileName /*= NULL*/ )
       
   627     {
       
   628     TInt driveNumber( EDriveD );
       
   629     
       
   630 #ifdef RD_MULTIPLE_DRIVE
       
   631     if ( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRam, driveNumber ) != KErrNone )
       
   632         {
       
   633         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, driveNumber );
       
   634         }
       
   635 #endif
       
   636 
       
   637     TChar driveCharacter;
       
   638     CEikonEnv::Static()->FsSession().DriveToChar( driveNumber, driveCharacter );
       
   639 
       
   640     aTempPath.Append( driveCharacter );
       
   641     aTempPath.Append( KMsgEditorTempDir );
       
   642     
       
   643     if ( aFileName )
       
   644         {
       
   645         aTempPath.Append( *aFileName );
       
   646         }
       
   647     }
       
   648 
       
   649 // End of File