contentmgmt/contentaccessfwfordrm/source/f32agent/f32defaultattributes.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2004-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 <f32file.h>
       
    21 
       
    22 #include <caf/attributeset.h>
       
    23 #include <caf/stringattributeset.h>
       
    24 #include <caf/virtualpath.h>
       
    25 #include <caf/caferr.h>
       
    26 #include "f32defaultattributes.h"
       
    27 
       
    28 
       
    29 using namespace ContentAccess;
       
    30 
       
    31 TInt TF32DefaultAttributes::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& )
       
    32 	{
       
    33 	TInt err = KErrNone;
       
    34 	// All files handled by the F32 agent are unprotected and have the same
       
    35 	// standard set of attributes
       
    36 	switch(aAttribute)
       
    37 		{
       
    38 		case EIsForwardable:
       
    39 		case EIsModifyable:
       
    40 		case EIsCopyable:
       
    41 		case ECanPlay:
       
    42 		case ECanPrint:
       
    43 		case ECanExecute:
       
    44 		case ECanView:
       
    45 		case ECanRewind:
       
    46 		case ECopyPaste:
       
    47 		case ECanMove:
       
    48 		case ECanRename:
       
    49 		case ECanAutomaticConsume:
       
    50 			aValue = ETrue;
       
    51 			break;
       
    52 		case EIsMediaPlayerOnly:
       
    53 		case EIsAutomatedUseOnly:
       
    54 		case EIsProtected:			
       
    55 		case EPreviewAvailable:
       
    56 			aValue = EFalse;
       
    57 			break;
       
    58 		case ETrackNumber:
       
    59 		case EContentCDataInUse:
       
    60 		case EContentVersion:
       
    61 		default:
       
    62 			err = KErrCANotSupported;
       
    63 			break;
       
    64 		};
       
    65 	return err;
       
    66 	}
       
    67 
       
    68 TInt TF32DefaultAttributes::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUri) 
       
    69 	{
       
    70 	TInt i = 0;
       
    71 	TInt attribute = 0;
       
    72 	TInt value=0;
       
    73 	TInt err = KErrNone;
       
    74 	TInt numAttributes = aAttributeSet.Count();
       
    75 	
       
    76 	// loop through all the attriutes in the set and find their values
       
    77 	for(i = 0; i < numAttributes; i++)
       
    78 		{
       
    79 		attribute = aAttributeSet[i];
       
    80 		err = GetAttribute(attribute, value, aUri);
       
    81 		aAttributeSet.SetValue(attribute, value, err);
       
    82 		}	
       
    83 	return KErrNone;
       
    84 	}
       
    85 
       
    86 TInt TF32DefaultAttributes::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUri)
       
    87 	{
       
    88 	TInt err = KErrNone;
       
    89 	TBuf8 <KMaxDataTypeLength> mimeType;
       
    90 
       
    91 	switch(aAttribute)
       
    92 		{
       
    93 		case EMimeType:
       
    94 			TRAP(err, GetMimeTypeL(aUri, mimeType));
       
    95 			if(err == KErrNone)
       
    96 				{
       
    97 				aValue.Copy(mimeType);
       
    98 				}
       
    99 			break;
       
   100 		default:
       
   101 			err = KErrCANotSupported;
       
   102 			break;
       
   103 		};
       
   104 	return err;
       
   105 	}
       
   106 
       
   107 TInt TF32DefaultAttributes::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUri)
       
   108 	{
       
   109 	TInt i = 0;
       
   110 	TInt attribute = 0;
       
   111 	TInt err = KErrNone;
       
   112 	TBuf <KMaxDataTypeLength> buf;
       
   113 
       
   114 	TInt numAttributes = aStringAttributeSet.Count();
       
   115 
       
   116 	// loop through all the attriutes in the set and find their values
       
   117 	for(i = 0; i < numAttributes; i++)
       
   118 		{
       
   119 		buf.SetLength(0);
       
   120 		attribute = aStringAttributeSet[i];
       
   121 		err = GetStringAttribute(attribute, buf, aUri);
       
   122 		err = aStringAttributeSet.SetValue(attribute,buf, err);
       
   123 		if(err != KErrNone)
       
   124 			{
       
   125 			return err;
       
   126 			}
       
   127 		}	
       
   128 	return KErrNone;
       
   129 	}
       
   130 
       
   131 void TF32DefaultAttributes::GetMimeTypeL(const TDesC& aURI, TDes8& aMimeType)
       
   132 	{
       
   133 	TUid appUid(KNullUid);
       
   134 	TDataType dataType;
       
   135 	RApaLsSession apparcSession;
       
   136 	
       
   137 	// Connect to Apparc
       
   138 	User::LeaveIfError(apparcSession.Connect());
       
   139 	CleanupClosePushL(apparcSession);
       
   140 
       
   141 	User::LeaveIfError(apparcSession.AppForDocument(aURI, appUid, dataType));
       
   142 	
       
   143 	if(dataType.Des8().Length() == 0)
       
   144 		{
       
   145 		User::Leave(KErrNotFound);
       
   146 		}
       
   147 
       
   148 	aMimeType.Append(dataType.Des8());
       
   149 	CleanupStack::PopAndDestroy(&apparcSession);
       
   150 	}
       
   151 
       
   152 
       
   153 TInt TF32DefaultAttributes::GetAttribute(TInt aAttribute, TInt& aValue, RFile& /*aFile*/)
       
   154 	{
       
   155 	return GetAttribute(aAttribute, aValue, KNullDesC);
       
   156 	}
       
   157 	
       
   158 TInt TF32DefaultAttributes::GetAttributeSet(RAttributeSet& aAttributeSet, RFile& aFile)
       
   159 	{
       
   160 	TInt i = 0;
       
   161 	TInt attribute = 0;
       
   162 	TInt value = 0;
       
   163 	TInt err = KErrNone;
       
   164 	TInt numAttributes = aAttributeSet.Count();
       
   165 	
       
   166 	// loop through all the attributes in the set and find their values
       
   167 	for(i = 0; i < numAttributes; i++)
       
   168 		{
       
   169 		attribute = aAttributeSet[i];
       
   170 		err = GetAttribute(attribute, value, aFile);
       
   171 		aAttributeSet.SetValue(attribute, value, err);
       
   172 		}	
       
   173 	return KErrNone;
       
   174 	}
       
   175 	
       
   176 TInt TF32DefaultAttributes::GetStringAttribute(TInt aAttribute, TDes& aValue, RFile& aFile)
       
   177 	{
       
   178 	TInt err = KErrNone;
       
   179 	TBuf8 <KMaxDataTypeLength> mimeType;
       
   180 
       
   181 	switch(aAttribute)
       
   182 		{
       
   183 		case EMimeType:
       
   184 			TRAP(err, GetMimeTypeL(aFile, mimeType));
       
   185 			if(err == KErrNone)
       
   186 				{
       
   187 				aValue.Copy(mimeType);
       
   188 				}
       
   189 			break;
       
   190 		default:
       
   191 			err = KErrCANotSupported;
       
   192 			break;
       
   193 		};
       
   194 	return err;
       
   195 	}
       
   196 	
       
   197 TInt TF32DefaultAttributes::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, RFile& aFile)
       
   198 	{
       
   199 	TInt i = 0;
       
   200 	TInt attribute = 0;
       
   201 	TInt err = KErrNone;
       
   202 	TBuf <KMaxDataTypeLength> buf;
       
   203 
       
   204 	TInt numAttributes = aStringAttributeSet.Count();
       
   205 
       
   206 	// loop through all the attriutes in the set and find their values
       
   207 	for(i = 0; i < numAttributes; i++)
       
   208 		{
       
   209 		buf.SetLength(0);
       
   210 		attribute = aStringAttributeSet[i];
       
   211 		err = GetStringAttribute(attribute, buf, aFile);
       
   212 		err = aStringAttributeSet.SetValue(attribute,buf, err);
       
   213 		if(err != KErrNone)
       
   214 			{
       
   215 			return err;
       
   216 			}
       
   217 		}	
       
   218 	return KErrNone;
       
   219 	}
       
   220 	
       
   221 void TF32DefaultAttributes::GetMimeTypeL(RFile& aFile, TDes8& aMimeType)
       
   222 	{
       
   223 	TUid appUid(KNullUid);
       
   224 	TDataType dataType;
       
   225 	RApaLsSession apparcSession;
       
   226 	
       
   227 	// Connect to Apparc
       
   228 	User::LeaveIfError(apparcSession.Connect());
       
   229 	CleanupClosePushL(apparcSession);
       
   230 
       
   231 	User::LeaveIfError(apparcSession.AppForDocument(aFile, appUid, dataType));
       
   232 	
       
   233 	if(dataType.Des8().Length() == 0)
       
   234 		{
       
   235 		User::Leave(KErrNotFound);
       
   236 		}
       
   237 	
       
   238 	aMimeType.Append(dataType.Des8());
       
   239 	CleanupStack::PopAndDestroy(&apparcSession);
       
   240 	}
       
   241 
       
   242 TInt TF32DefaultAttributes::CheckUniqueId(const TDesC& aUniqueId)
       
   243 	{
       
   244 	// The only UniqueId values that make sense for the F32 agent are
       
   245 	// a zero length descriptor (indicating the application is referring to the entire file 
       
   246 	// or KDefaultContentObject which is also the entire file in the case of the F32 agent
       
   247 	if(aUniqueId.Length() == 0 || aUniqueId == KDefaultContentObject())
       
   248 		{
       
   249 		return KErrNone;	
       
   250 		}
       
   251 	else 
       
   252 		{
       
   253 		return KErrNotFound;	
       
   254 		}
       
   255 	}
       
   256 	
       
   257 TInt TF32DefaultAttributes::CheckVirtualPath(const TVirtualPathPtr& aVirtualPath)
       
   258 	{
       
   259 	// check the Unique Id
       
   260 	TInt err = CheckUniqueId(aVirtualPath.UniqueId());
       
   261 	
       
   262 	// check if the file exists
       
   263 	
       
   264 	
       
   265 	return err;
       
   266 	}	
       
   267 	
       
   268 TUint TF32DefaultAttributes::GetFileMode(TContentShareMode aMode)
       
   269 	{
       
   270 	
       
   271 	TUint fileMode = EFileStream | EFileRead;
       
   272 
       
   273 	if(aMode  == EContentShareReadWrite)
       
   274 		{
       
   275 		fileMode |= EFileShareReadersOrWriters;
       
   276 		}
       
   277 	else if(aMode == EContentShareExclusive)
       
   278 		{
       
   279 		fileMode  |= EFileShareExclusive;
       
   280 		}
       
   281 	else
       
   282 		{
       
   283 		fileMode |= EFileShareReadersOnly;
       
   284 		}
       
   285 		
       
   286 	return fileMode;
       
   287 	}