contentmgmt/contentaccessfwfordrm/source/f32agent/f32agentcontent.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 <caf/caf.h>
       
    20 #include <apmstd.h>
       
    21 #include "f32agentcontent.h"
       
    22 #include "f32defaultattributes.h"
       
    23 #include "f32agentui.h"
       
    24 
       
    25 using namespace ContentAccess;
       
    26 
       
    27 CF32AgentContent* CF32AgentContent::NewL(const TDesC& aURI, TContentShareMode aShareMode)
       
    28 	{
       
    29 	CF32AgentContent* self = new (ELeave) CF32AgentContent;
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL(aURI, aShareMode);
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CF32AgentContent* CF32AgentContent::NewL(RFile& aFile)
       
    37 	{
       
    38 	CF32AgentContent* self = new (ELeave) CF32AgentContent;
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL(aFile);
       
    41 	CleanupStack::Pop(self);
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 CF32AgentContent::CF32AgentContent()
       
    46 	{
       
    47 	}
       
    48 
       
    49 CF32AgentContent::~CF32AgentContent()
       
    50 	{
       
    51 	iFile.Close();
       
    52 	if(iURI)
       
    53 		{
       
    54 		// file session only created when file is opened by name
       
    55 		iFs.Close();
       
    56 		}
       
    57 	delete iURI;
       
    58 	}
       
    59   
       
    60 void CF32AgentContent::ConstructL(const TDesC& aURI, TContentShareMode aShareMode)
       
    61 	{
       
    62 	iURI = aURI.AllocL();
       
    63 	iShareMode = aShareMode;
       
    64 	
       
    65 	// Test that the file exists and hold it open so nobody deletes it etc
       
    66 	TUint mode = TF32DefaultAttributes::GetFileMode(aShareMode);
       
    67 	User::LeaveIfError(iFs.Connect());
       
    68 	User::LeaveIfError(iFile.Open(iFs, *iURI, mode));
       
    69 	}
       
    70 
       
    71 void CF32AgentContent::ConstructL(RFile& aFile)
       
    72 	{
       
    73 	User::LeaveIfError(iFile.Duplicate(aFile));
       
    74 	}
       
    75 
       
    76 TInt CF32AgentContent::OpenContainer(const TDesC&)
       
    77 	{
       
    78 	return KErrNotFound;
       
    79 	}
       
    80 
       
    81 TInt CF32AgentContent::CloseContainer()
       
    82 	{
       
    83 	return KErrNotFound;
       
    84 	}
       
    85 
       
    86 void CF32AgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& aArray)
       
    87 	{
       
    88 	TBuf8 <KMaxDataTypeLength> mimeType;
       
    89 	CEmbeddedObject *embeddedObject = NULL;
       
    90 	
       
    91 	// the only embedded object is the file itself	
       
    92 	// Try to get the mime type
       
    93 	mimeType.SetLength(0);
       
    94 	if(iURI)
       
    95 		{
       
    96 		TF32DefaultAttributes::GetMimeTypeL(*iURI, mimeType);
       
    97 		}
       
    98 	else
       
    99 		{
       
   100 		TF32DefaultAttributes::GetMimeTypeL(iFile, mimeType);
       
   101 		}	
       
   102 	embeddedObject = CEmbeddedObject::NewL(KDefaultContentObject(), mimeType, EContentObject);
       
   103 	CleanupStack::PushL(embeddedObject);
       
   104 	aArray.AppendL(embeddedObject);
       
   105 	
       
   106 	// Now owned by the array so do not destroy
       
   107 	CleanupStack::Pop(embeddedObject);
       
   108 	}
       
   109 
       
   110 void CF32AgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& aArray, TEmbeddedType aType)
       
   111 	{
       
   112 	// the only embedded object is the file itself
       
   113 	if(aType == EContentObject)
       
   114 		{
       
   115 		// just get the default object since there is only one content object
       
   116 		GetEmbeddedObjectsL(aArray);
       
   117 		}
       
   118 	}
       
   119 
       
   120 void CF32AgentContent::SearchL(RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8& aMimeType, TBool /* aRecurse */)
       
   121 	{
       
   122 	TBuf8 <KMaxDataTypeLength> mimeType;
       
   123 	
       
   124 	CEmbeddedObject *embeddedObject = NULL;
       
   125 	
       
   126 	// the only embedded object is the file itself	
       
   127 	if(iURI)
       
   128 		{
       
   129 		TF32DefaultAttributes::GetMimeTypeL(*iURI, mimeType);
       
   130 		}
       
   131 	else
       
   132 		{
       
   133 		TF32DefaultAttributes::GetMimeTypeL(iFile, mimeType);
       
   134 		}
       
   135 	
       
   136 	// Check the file has the correct mime type
       
   137 	if(aMimeType == mimeType)
       
   138 		{
       
   139 		embeddedObject = CEmbeddedObject::NewL(KDefaultContentObject(), mimeType, EContentObject);
       
   140 		CleanupStack::PushL(embeddedObject);		
       
   141 		aArray.AppendL(embeddedObject);
       
   142 	
       
   143 		// Now owned by the array so do not destroy
       
   144 		CleanupStack::Pop(embeddedObject);
       
   145 		}
       
   146 	else
       
   147 		{
       
   148 		// Mime type was incorrect. Set error to indicate no content object
       
   149 		// of the desired type was found in the file.
       
   150 		User::Leave(KErrNotFound);
       
   151 		}
       
   152 	}
       
   153 
       
   154 TInt CF32AgentContent::Search(RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8& aMimeType, TBool aRecurse)
       
   155 	{
       
   156 	TRAPD( err, SearchL(aArray, aMimeType, aRecurse) );
       
   157 	return err;
       
   158 	}
       
   159 
       
   160 TInt CF32AgentContent::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& aUniqueId)
       
   161 	{
       
   162 	// check that the unique Id exists
       
   163 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
       
   164 		{
       
   165 		return KErrNotFound;	
       
   166 		}
       
   167 	
       
   168 	TInt err = KErrNone;
       
   169 	if(iURI)
       
   170 		{
       
   171 		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, *iURI);
       
   172 		}
       
   173 	else
       
   174 		{
       
   175 		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iFile);
       
   176 		}
       
   177 	return err;
       
   178 	}
       
   179 
       
   180 TInt CF32AgentContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId)
       
   181 	{
       
   182 	// check that the unique Id exists
       
   183 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
       
   184 		{
       
   185 		return KErrNotFound;	
       
   186 		}
       
   187 		
       
   188 	TInt err = KErrNone;
       
   189 	if(iURI)
       
   190 		{
       
   191 		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, *iURI);
       
   192 		}
       
   193 	else
       
   194 		{
       
   195 		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iFile);
       
   196 		}
       
   197 	return err;
       
   198 	}
       
   199 
       
   200 TInt CF32AgentContent::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUniqueId)
       
   201 	{
       
   202 	// check that the unique Id exists
       
   203 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
       
   204 		{
       
   205 		return KErrNotFound;	
       
   206 		}
       
   207 		
       
   208 	TInt err = KErrNone;
       
   209 	if(iURI)
       
   210 		{
       
   211 		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, *iURI);
       
   212 		}
       
   213 	else
       
   214 		{
       
   215 		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iFile);
       
   216 		}
       
   217 	return err;
       
   218 	}
       
   219 
       
   220 TInt CF32AgentContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId)
       
   221 	{
       
   222 	// check that the unique Id exists
       
   223 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
       
   224 		{
       
   225 		return KErrNotFound;	
       
   226 		}
       
   227 	
       
   228 	TInt err = KErrNone;
       
   229 	if(iURI)
       
   230 		{
       
   231 		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, *iURI);
       
   232 		}
       
   233 	else
       
   234 		{
       
   235 		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iFile);
       
   236 		}
       
   237 	return err;
       
   238 	}
       
   239 
       
   240 TInt CF32AgentContent::AgentSpecificCommand(TInt , const TDesC8& , TDes8& )
       
   241 	{
       
   242 	return KErrCANotSupported;
       
   243 	}
       
   244 
       
   245 void CF32AgentContent::AgentSpecificCommand(TInt , const TDesC8& , TDes8& , TRequestStatus& aStatus)
       
   246 	{
       
   247 	TRequestStatus* ptr = &aStatus;
       
   248 	User::RequestComplete(ptr, KErrCANotSupported);
       
   249 	}
       
   250 
       
   251 void CF32AgentContent::NotifyStatusChange(TEventMask , TRequestStatus& aStatus, const TDesC& )
       
   252 	{
       
   253 	TRequestStatus* ptr = &aStatus;
       
   254 	User::RequestComplete(ptr, KErrCANotSupported);
       
   255 	}
       
   256 
       
   257 TInt CF32AgentContent::CancelNotifyStatusChange(TRequestStatus& , const TDesC& )
       
   258 	{
       
   259 	return KErrCANotSupported;
       
   260 	}
       
   261 
       
   262 void CF32AgentContent::RequestRights(TRequestStatus& aStatus, const TDesC& )
       
   263 	{
       
   264 	TRequestStatus* ptr = &aStatus;
       
   265 	User::RequestComplete(ptr, KErrCANotSupported);
       
   266 	}
       
   267 
       
   268 TInt CF32AgentContent::CancelRequestRights(TRequestStatus& , const TDesC& )
       
   269 	{
       
   270 	return KErrCANotSupported;
       
   271 	}
       
   272 
       
   273 void CF32AgentContent::DisplayInfoL(TDisplayInfo aInfo, const TDesC& aUniqueId)
       
   274 	{
       
   275 	// Check that the client hasn't specified some incorrect UniqueId
       
   276 	User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aUniqueId));
       
   277 
       
   278 
       
   279 	if(iURI)
       
   280 		{
       
   281 		// Open the file handle in order to pass it to the Agent UI
       
   282 		RFs fs;
       
   283 		RFile file;
       
   284 		
       
   285 		// default share mode of EFileShareReadersOnly
       
   286 		TUint mode = EFileShareReadersOnly | EFileStream | EFileRead;
       
   287 
       
   288 		if(iShareMode == EContentShareReadWrite)
       
   289 			{
       
   290 			mode = EFileShareAny | EFileStream | EFileRead;
       
   291 			}
       
   292 		else if(iShareMode == EContentShareExclusive)
       
   293 			{
       
   294 			mode = EFileShareExclusive | EFileStream | EFileRead;
       
   295 			}
       
   296 
       
   297 		
       
   298 		User::LeaveIfError(fs.Connect());
       
   299 		CleanupClosePushL(fs);
       
   300 		User::LeaveIfError(file.Open(fs, *iURI, mode));
       
   301 		CleanupClosePushL(file);
       
   302 		AgentUiL().DisplayInfoL(aInfo, file);	
       
   303 		CleanupStack::PopAndDestroy(2, &fs); // file, fs
       
   304 		}
       
   305 	else
       
   306 		{
       
   307 		// just pass existing file handle
       
   308 		AgentUiL().DisplayInfoL(aInfo, iFile);
       
   309 		}
       
   310 	}
       
   311 
       
   312 TInt CF32AgentContent::SetProperty(TAgentProperty aProperty, TInt aValue)
       
   313 	{
       
   314 	if(aProperty==EAgentPropertyAgentUI)
       
   315 		// should only pass type EAgentPropertyAgentUI 
       
   316 		{
       
   317 		
       
   318 		CF32AgentUi* ui = NULL;
       
   319 	
       
   320 		// get a pointer to the UI
       
   321 		TRAPD(err, ui = &AgentUiL());
       
   322 		if(err)
       
   323 			{
       
   324 			return err;
       
   325 			}
       
   326 		return ui->SetProperty(aProperty, aValue);
       
   327 		}
       
   328 	else
       
   329 		{
       
   330 		return KErrCANotSupported;
       
   331 		}
       
   332 	}
       
   333 
       
   334 
       
   335 CF32AgentUi& CF32AgentContent::AgentUiL()
       
   336 	{
       
   337 	if(!iAgentUi)
       
   338 		{
       
   339 		// load agent UI from f32AgentUi.dll
       
   340 		iAgentUi = TF32AgentUiFactory::CreateF32AgentUiL();
       
   341 		}
       
   342 	return *iAgentUi;
       
   343 	}