messagingfw/senduiservices/src/SendUiUtils.cpp
branchRCL_3
changeset 23 d51193d814ea
parent 0 8e480a14352b
equal deleted inserted replaced
22:d2c4c66342f3 23:d51193d814ea
       
     1 /*
       
     2 * Copyright (c) 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 private utilities for SendUi.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <apmstd.h>
       
    23 #include <apgcli.h>
       
    24 #include <caf/caf.h>
       
    25 #include <MsgMimeTypes.h>
       
    26 
       
    27 #include "SendUiUtils.h"
       
    28 
       
    29 // CONSTANTS
       
    30 _LIT8( KMmsSymbianInternalPattern, "x-epoc/x-app0");
       
    31 
       
    32 const TInt KSenduiUrlMaxLen = 1024;
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // SendUiUtils::OpenFileHandleL
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 RFile SendUiUtils::OpenFileHandleL( const TDesC& aFilePath, RFs& aFs )
       
    41     {
       
    42     RFile fileHandle;
       
    43     TInt err = fileHandle.Open( aFs, aFilePath, EFileShareReadersOnly );
       
    44     if ( err )
       
    45         {
       
    46         User::LeaveIfError( fileHandle.Open( aFs, aFilePath, EFileShareAny ) );
       
    47         }
       
    48 
       
    49     return fileHandle;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // SendUiUtils::DrmContentUrlL
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 TBool SendUiUtils::HasContentUrlL( RFile& aFile )
       
    57     {
       
    58     TBuf<KSenduiUrlMaxLen> contentUrl;
       
    59     ContentAccess::CData* content = ContentAccess::CData::NewLC(
       
    60         aFile,
       
    61         ContentAccess::KDefaultContentObject,
       
    62         ContentAccess::EPeek );
       
    63 
       
    64     TInt error = content->GetStringAttribute( ContentAccess::EContentURI, contentUrl );
       
    65     CleanupStack::PopAndDestroy( content );
       
    66     
       
    67     return !error;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // SendUiUtils::ResolveMimeTypeL
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void SendUiUtils::ResolveMimeTypeL( const RFile& aFile, TDataType& aMimeType )
       
    75     {
       
    76     RApaLsSession lsSession;
       
    77     CleanupClosePushL( lsSession );
       
    78     User::LeaveIfError( lsSession.Connect() );
       
    79 
       
    80     TDataRecognitionResult dataType;
       
    81 
       
    82     TInt err = lsSession.RecognizeData( aFile, dataType );
       
    83     if ( err
       
    84         ||  dataType.iDataType.Des8().Length() == 0
       
    85         ||  !dataType.iDataType.Des8().CompareF( KMmsSymbianInternalPattern ) )
       
    86         {
       
    87         // Not recognized
       
    88         aMimeType = KMsgMimeUnknown();
       
    89         }
       
    90     else
       
    91         {
       
    92         aMimeType = dataType.iDataType;
       
    93         }
       
    94     // The attachment file pointer needs to be reset to the start of the file.
       
    95     TInt pos( 0 );
       
    96     aFile.Seek( ESeekStart, pos );
       
    97     CleanupStack::PopAndDestroy( &lsSession );
       
    98     }
       
    99 
       
   100 //  End of File