contentmgmt/contentaccessfwfordrm/source/caf/supplieroutputfile.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2003-2009 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 the License "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "apgcli.h"
       
    20 #include "apmstd.h"
       
    21 #include "supplieroutputfile.h"
       
    22 
       
    23 #include <caf/caftypes.h>
       
    24 #include "resolver.h"
       
    25 
       
    26 #ifndef REMOVE_CAF1
       
    27 #include <caf/attribute.h>
       
    28 #include <caf/content.h>
       
    29 #include <caf/bitset.h>
       
    30 #endif
       
    31 
       
    32 
       
    33 using namespace ContentAccess;
       
    34 
       
    35 #ifndef REMOVE_CAF1
       
    36 EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType)
       
    37 	{
       
    38 	return CSupplierOutputFile::NewL(aFileName, aOutputType, KNullDesC8());
       
    39 	}
       
    40 #endif
       
    41 
       
    42 EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType, const TDesC8& aMimeType)
       
    43 	{
       
    44 	CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
       
    45 	CleanupStack::PushL(self);
       
    46 	self->ConstructL(aFileName, aMimeType, aOutputType);
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(RReadStream& aStream)
       
    52 	{
       
    53 	CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
       
    54 	CleanupStack::PushL(self);
       
    55 	self->InternalizeL(aStream);
       
    56 	CleanupStack::Pop(self);
       
    57 	return self;		
       
    58 	}
       
    59 
       
    60 CSupplierOutputFile::CSupplierOutputFile()
       
    61 	{
       
    62 	}
       
    63 	
       
    64 
       
    65 void CSupplierOutputFile::ConstructL(const TDesC& aFileName, const TDesC8& aMimeType, const TOutputType aOutputType)
       
    66 	{
       
    67 	iOutputType = aOutputType;
       
    68 	
       
    69 	CAgentResolver *resolver = CAgentResolver::NewL(EFalse);
       
    70 	CleanupStack::PushL(resolver);
       
    71 	iFileName = resolver->ConvertAgentFileNameL(aFileName);
       
    72 	CleanupStack::PopAndDestroy(resolver);
       
    73 	iMimeType.Copy(aMimeType);
       
    74 	
       
    75 	// convert mime type to lower case
       
    76 	iMimeType.LowerCase();
       
    77 	}
       
    78 
       
    79 
       
    80 CSupplierOutputFile::~CSupplierOutputFile()
       
    81 	{
       
    82 	delete iFileName;
       
    83 #ifndef REMOVE_CAF1
       
    84 	delete iAttr;
       
    85 #endif
       
    86 	}
       
    87 
       
    88 
       
    89 EXPORT_C TPtrC CSupplierOutputFile::FileName() const
       
    90 	{
       
    91 	return *iFileName;
       
    92 	}
       
    93 
       
    94 EXPORT_C TOutputType CSupplierOutputFile::OutputType() const
       
    95 	{
       
    96 	return iOutputType;
       
    97 	}
       
    98 
       
    99 EXPORT_C TPtrC8 CSupplierOutputFile::MimeTypeL()
       
   100 	{
       
   101 	TUid uid;
       
   102 	TDataType dataType;
       
   103 	RApaLsSession apparcSession;
       
   104 
       
   105 	if(iMimeType.Length() == 0)
       
   106 		{
       
   107 		// Use the Application Architecture Server to find the Mime type of the output File
       
   108 		User::LeaveIfError(apparcSession.Connect());
       
   109 		CleanupClosePushL(apparcSession);
       
   110 		    
       
   111    		// Use a temp FS session to preserve platsec 
       
   112 		RFs tempFsSession; 
       
   113 		User::LeaveIfError(tempFsSession.Connect());     
       
   114 	  	CleanupClosePushL(tempFsSession);
       
   115 	  	User::LeaveIfError(tempFsSession.ShareProtected());  
       
   116 	  	
       
   117 	  	// Open file here and send the handle because AppArc doesn't have Allfiles capability 
       
   118 	  	RFile tempFile; 
       
   119 	  	User::LeaveIfError(tempFile.Open(tempFsSession, *iFileName, EFileRead|EFileShareAny)); 
       
   120 	  	CleanupClosePushL(tempFile); 
       
   121    
       
   122 		User::LeaveIfError(apparcSession.AppForDocument(tempFile, uid, dataType)); 
       
   123 
       
   124 		iMimeType.Copy(dataType.Des8().Left(KMaxDataTypeLength)); 
       
   125 
       
   126 		CleanupStack::PopAndDestroy(&tempFile); // close 
       
   127 		CleanupStack::PopAndDestroy(&tempFsSession);    // close 
       
   128 		CleanupStack::PopAndDestroy(&apparcSession);	// close
       
   129 		}
       
   130 
       
   131 	return iMimeType;
       
   132 	}
       
   133 
       
   134 EXPORT_C void CSupplierOutputFile::ExternalizeL(RWriteStream& aStream) const
       
   135 	{
       
   136 	aStream.WriteInt32L(static_cast <TInt> (iOutputType));
       
   137 	aStream.WriteInt32L(iFileName->Des().Length());
       
   138 	aStream.WriteL(*iFileName);
       
   139 	aStream.WriteInt32L(iMimeType.Length());
       
   140 	aStream.WriteL(iMimeType);
       
   141 	}
       
   142 
       
   143 void CSupplierOutputFile::InternalizeL(RReadStream& aStream)
       
   144 	{
       
   145 	TInt length = 0;
       
   146 	iOutputType = static_cast <TOutputType> (aStream.ReadInt32L());
       
   147 	length = aStream.ReadInt32L();
       
   148 	iFileName = HBufC::NewL(length);
       
   149 	if(length)
       
   150 		{
       
   151 		TPtr filename = iFileName->Des();
       
   152 		aStream.ReadL(filename, length);
       
   153 		}
       
   154 	length = aStream.ReadInt32L();
       
   155 	aStream.ReadL(iMimeType, length);
       
   156 	}
       
   157 
       
   158 
       
   159 
       
   160 #ifndef REMOVE_CAF1
       
   161 EXPORT_C CAttribute &  CSupplierOutputFile::AttributesL (TBool aPreloaded) 
       
   162 	{
       
   163 	// retrieve the attributes, only need to do this once since this instance
       
   164 	// will only ever refer to one output file 
       
   165 	if(!iAttr)
       
   166 		{
       
   167 		// create a content consumer interface for the output file produced
       
   168 		CContent* content = CContent::NewLC(FileName());	
       
   169 		iAttr = content->NewAttributeL(ETrue);
       
   170 		CleanupStack::PopAndDestroy(content);
       
   171 		}
       
   172 	else if(aPreloaded)  // update all attribute bits
       
   173 		{
       
   174 		CBitset &bitset = iAttr->QuerySet();
       
   175 		bitset.SetAll();
       
   176 		iAttr->GetL();
       
   177 		}
       
   178 	return *iAttr;
       
   179 	}
       
   180 #endif // #ifndef REMOVE_CAF1