messagingfw/deprecate/senduiservices/datautils/src/SendUiDataUtils.cpp
branchRCL_3
changeset 22 d2c4c66342f3
equal deleted inserted replaced
21:e5b3a2155e1a 22:d2c4c66342f3
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:   Utility class for SendUI.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    "SendUiDataUtils.h"
       
    23 #include    <eikenv.h>
       
    24 #include    <apgcli.h>
       
    25 
       
    26 _LIT8( KMmsSymbianInternalPattern, "x-epoc/x-app0");
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CSendUiDataUtils:CSendUiDataUtils
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CSendUiDataUtils::CSendUiDataUtils( RFs& aFs ) : iFs( aFs )
       
    37     {
       
    38     }
       
    39 // -----------------------------------------------------------------------------
       
    40 // CSendUiDataUtils::NewL
       
    41 // Two-phased constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C CSendUiDataUtils* CSendUiDataUtils::NewL( RFs& aFs )
       
    45     {
       
    46     CSendUiDataUtils* self = new(ELeave)CSendUiDataUtils( aFs );
       
    47     return self;
       
    48     }
       
    49 
       
    50 // Destructor
       
    51 CSendUiDataUtils::~CSendUiDataUtils()
       
    52     {
       
    53     if ( iApaLsSession )
       
    54         {
       
    55         iApaLsSession->Close();
       
    56         delete iApaLsSession;
       
    57         }
       
    58     }
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CSendUiDataUtils::ResolveFileMimeTypeL
       
    63 // 
       
    64 // (other items were commented in a header).
       
    65 //
       
    66 // Used by CSendUiImpl
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C void CSendUiDataUtils::ResolveFileMimeTypeL(
       
    70     const TDesC& aFilePath,
       
    71     TDataType& aMimeType )
       
    72     {
       
    73     RFile file;
       
    74 
       
    75     TInt err = file.Open( iFs, aFilePath, EFileShareReadersOnly );
       
    76 
       
    77     if ( err )
       
    78         {
       
    79         User::LeaveIfError( file.Open( iFs, aFilePath, EFileShareAny ) );
       
    80         }
       
    81 
       
    82     CleanupClosePushL( file );
       
    83 
       
    84     ResolveFileMimeTypeL( file, aMimeType );
       
    85 
       
    86     CleanupStack::PopAndDestroy( &file );
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CSendUiDataUtils::ResolveFileMimeTypeL
       
    91 // 
       
    92 // (other items were commented in a header).
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C void CSendUiDataUtils::ResolveFileMimeTypeL(
       
    96     const RFile& aFile,
       
    97     TDataType& aMimeType )
       
    98     {
       
    99     if ( !iApaLsSession )
       
   100         {
       
   101         iApaLsSession = new(ELeave)RApaLsSession();
       
   102         User::LeaveIfError( iApaLsSession->Connect() );
       
   103         }
       
   104 
       
   105     TDataRecognitionResult dataType;
       
   106 
       
   107     TInt err = iApaLsSession->RecognizeData( aFile, dataType );
       
   108     if (    err
       
   109         ||  dataType.iDataType.Des8().Length() == 0
       
   110         ||  !dataType.iDataType.Des8().CompareF( KMmsSymbianInternalPattern ) )
       
   111         {
       
   112         // Not recognized
       
   113         aMimeType = KMsgMimeUnknown();
       
   114         }
       
   115     else
       
   116         {
       
   117         aMimeType = dataType.iDataType;
       
   118         }
       
   119     // The attachment file pointer needs to be reset to the start of the file.
       
   120     TInt pos(0);
       
   121     aFile.Seek( ESeekStart, pos );
       
   122     }
       
   123 
       
   124 //  End of File