pimappservices/calendar/client/src/calattachment.cpp
changeset 0 f979ecb2b13e
child 10 38571fd2a704
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "agmattachment.h"
       
    17 #include "calclient.h"
       
    18 #include "calsessionimpl.h"
       
    19 #include "calcommonimpl.h"
       
    20 
       
    21 
       
    22 /** Allocates and constructs a new file attachment from binary data.
       
    23 @param aBinaryData The attachment binary data. CCalAttachment takes ownership.
       
    24 @return A pointer to the new attachment.
       
    25 @leave KErrArgument If the aBinaryData parameter is NULL or if it points to an empty descriptor.
       
    26 Otherwise one of the system-wide error codes.
       
    27 @pre None
       
    28 @post A EFile attachment is created with the given binary data.
       
    29 @publishedPartner
       
    30 @released
       
    31 @capability None
       
    32 */
       
    33 EXPORT_C CCalAttachment* CCalAttachment::NewFileL(TDesC8* aBinaryData)
       
    34 	{
       
    35 	__ASSERT_ALWAYS(aBinaryData && aBinaryData->Length() > 0, User::Leave(KErrArgument));
       
    36 
       
    37 	CCalAttachment* self = new (ELeave) CCalAttachment();
       
    38 	CleanupStack::PushL(self);
       
    39 	self->ConstructL(EFile, aBinaryData);
       
    40 	CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 /** Allocates and constructs a new file attachment from a file handle.
       
    45 The file will be moved to the Calendar store when the entry containing this attachment is stored. 
       
    46 To avoid the file being moved to the Calendar store, a copy should be made and a file handle to 
       
    47 the copy passed into this function.
       
    48 @param aFileHandle The handle to the attachment file. CCalAttachment will make a copy of the handel.
       
    49 The file handle must be opened using the mode EFileWrite and it should belong to a shared 
       
    50 file server session. 
       
    51 @see ShareProtected
       
    52 @return A pointer to the new attachment.
       
    53 @leave KErrAccessDenied If the file pointed to by this file handle is read only. 
       
    54 Otherwise one of the system-wide error codes.
       
    55 @panic If the file handle has not been initialised by calling RFs::Open.
       
    56 @pre None
       
    57 @post A EFile attachment is created with the given file handle.
       
    58 @publishedPartner
       
    59 @released
       
    60 @capability None
       
    61 */
       
    62 EXPORT_C CCalAttachment* CCalAttachment::NewFileL(RFile& aFileHandle)
       
    63 	{
       
    64 	CCalAttachment* self = new (ELeave) CCalAttachment();
       
    65 	CleanupStack::PushL(self);
       
    66 	self->ConstructL(EFile, NULL);
       
    67 	self->FileAttachment()->SetResourceL(aFileHandle);
       
    68 	CleanupStack::Pop(self);
       
    69 	return self;
       
    70 	}
       
    71 
       
    72 /** Allocates and constructs a new file attachment with a content ID.
       
    73 Content IDs are only used during import and export. The actual attachment data is specified 
       
    74 by calling SetResourceL. 
       
    75 If an entry is stored which references an attachment that only has a content ID and no data, 
       
    76 then the StoreL function will leave with KErrArgument.
       
    77 @param aContentId A descriptor containing the content ID. CCalAttachment doesn't take ownership.
       
    78 @return A pointer to the new attachment.
       
    79 @leave KErrArgument if the parameter is an empty descriptor.
       
    80 Otherwise any of the system-wide error codes.
       
    81 @pre None
       
    82 @post A EFile attachment is created with the given content ID.
       
    83 @publishedPartner
       
    84 @released
       
    85 @capability None
       
    86 */
       
    87 EXPORT_C CCalAttachment* CCalAttachment::NewFileByContentIdL(const TDesC8& aContentId)
       
    88 	{
       
    89 	__ASSERT_ALWAYS(aContentId.Length() > 0, User::Leave(KErrArgument));
       
    90 	CCalAttachment* self = new (ELeave) CCalAttachment();
       
    91 	CleanupStack::PushL(self);
       
    92 	self->ConstructL(EFile, NULL);
       
    93 	self->FileAttachment()->SetContentIdL(aContentId);
       
    94 	CleanupStack::Pop(self);
       
    95 	return self;
       
    96 	}
       
    97 
       
    98 /** Allocates and constructs a new URI attachment. URIs are defined in RFC 3986.
       
    99 @return A pointer to the new attachment.
       
   100 @param aUri A descriptor containing the attachment URI. CCalAttachment doesn't take ownership.
       
   101 @return A pointer to the new attachment.
       
   102 @leave KErrArgument if the parameter is an empty descriptor.
       
   103 Otherwise any of the system-wide error codes.
       
   104 @pre None
       
   105 @post A EUri attachment is created with the given data.
       
   106 @publishedPartner
       
   107 @released
       
   108 @capability None
       
   109 */
       
   110 EXPORT_C CCalAttachment* CCalAttachment::NewUriL(const TDesC8& aUri)
       
   111 	{
       
   112 	__ASSERT_ALWAYS(aUri.Length() > 0, User::Leave(KErrArgument));
       
   113 	CCalAttachment* self = new (ELeave) CCalAttachment();
       
   114 	CleanupStack::PushL(self);
       
   115 	HBufC8* uriCopy = aUri.AllocLC();
       
   116 	self->ConstructL(EUri, uriCopy);
       
   117 	CleanupStack::Pop(uriCopy);
       
   118 	CleanupStack::Pop(self);
       
   119 	return self;
       
   120 	}
       
   121 
       
   122 CCalAttachment* CCalAttachment::NewL(CAgnAttachment& aAttachment, CCalSessionImpl& aSessionImpl)
       
   123 	{
       
   124 	CCalAttachment* self = new (ELeave) CCalAttachment(aAttachment);
       
   125 	CleanupStack::PushL(self);
       
   126 	self->CreateFileAttachmentImplIfRequiredL(&aSessionImpl);
       
   127 	CleanupStack::Pop(self);
       
   128 	return self;
       
   129 	}
       
   130 
       
   131 CCalAttachment::CCalAttachment()
       
   132 	{
       
   133 	}
       
   134 
       
   135 CCalAttachment::CCalAttachment(CAgnAttachment& aAttachment) :
       
   136 	iAttachmentImpl(&aAttachment)
       
   137 	{
       
   138 	}
       
   139 	
       
   140 void CCalAttachment::ConstructL(TType aType, TDesC8* aData)
       
   141 	{
       
   142 	switch (aType)
       
   143 		{
       
   144 		case EFile:
       
   145 			iAttachmentImpl = AttachmentFactory::NewAttachmentL(CCalContent::EDispositionInline);
       
   146 			iAttachmentImpl->SetAttribute(EExportInline);
       
   147 			break;
       
   148 		case EUri:
       
   149 			iAttachmentImpl = AttachmentFactory::NewAttachmentL(CCalContent::EDispositionUrl);
       
   150 			break;
       
   151 		default:
       
   152 			CalUtils::Panic(EInvalidAttachmentType);
       
   153 		}
       
   154 	
       
   155 	iAttachmentImpl->SetFlag(CAgnAttachment::EOwnedByCalAttachment);
       
   156 	CreateFileAttachmentImplIfRequiredL(NULL);
       
   157 	
       
   158 	// must set data last because ownership is taken
       
   159 	if (aData)
       
   160 		{
       
   161 		iAttachmentImpl->SetValue(aData);
       
   162 		iAttachmentImpl->SetFlag(CAgnAttachment::EDataHasBeenSet);
       
   163 		}
       
   164 	}
       
   165 	
       
   166 void CCalAttachment::CreateFileAttachmentImplIfRequiredL(CCalSessionImpl* aSessionImpl)
       
   167 	{
       
   168 	if (Type() == EFile && !iFileAttachment)
       
   169 		{
       
   170 		iFileAttachment = new (ELeave) CCalAttachmentFile(*this, aSessionImpl);
       
   171 		}
       
   172 	}
       
   173 
       
   174 /** The destructor frees all resources owned by the attachment, prior to its destruction.
       
   175 @pre An attachment object has been constructed.
       
   176 @post The attachment object is destroyed.
       
   177 @publishedPartner
       
   178 @released
       
   179 @capability None
       
   180 */
       
   181 EXPORT_C CCalAttachment::~CCalAttachment()
       
   182 	{
       
   183 	if (iAttachmentImpl && iAttachmentImpl->FlagsSet(CAgnAttachment::EOwnedByCalAttachment))
       
   184 		{
       
   185 		delete iAttachmentImpl;
       
   186 		}
       
   187 	delete iFileAttachment;
       
   188 	}
       
   189 
       
   190 CAgnAttachment& CCalAttachment::Impl() const
       
   191 	{
       
   192 	ASSERT(iAttachmentImpl);
       
   193 	return *iAttachmentImpl;
       
   194 	}
       
   195 
       
   196 /**Get the type of the attachment, CCalAttachment::TType.
       
   197 @return The attachment type.
       
   198 @pre None
       
   199 @post None
       
   200 @publishedPartner
       
   201 @released
       
   202 @capability None
       
   203 */
       
   204 EXPORT_C CCalAttachment::TType CCalAttachment::Type() const
       
   205 	{
       
   206 	CCalAttachment::TType calType = CCalAttachment::EUri;
       
   207 	switch (iAttachmentImpl->Type())
       
   208 		{
       
   209 		case CCalContent::EDispositionUrl:
       
   210 			calType = CCalAttachment::EUri;
       
   211 			break;
       
   212 		case CCalContent::EDispositionInline:
       
   213 			calType = CCalAttachment::EFile;
       
   214 			break;
       
   215 		default:
       
   216 			CalUtils::Panic(EInvalidAttachmentType);
       
   217 			break;
       
   218 		}
       
   219 	return calType;
       
   220 	}
       
   221 
       
   222 /** Get the value of an attachment, as defined by the VALUE property in vCalendar / iCalendar (RFC 2445).
       
   223 Note that content IDs are exported as part the VALUE property, but these are not accessible through this function.
       
   224 @return For EUri types, this returns the URI.
       
   225 For EFile types, this returns the binary data of the attachment file if present. If the binary data is not present, 
       
   226 it may be loaded by calling CCalAttachmentFile::LoadBinaryDataL().
       
   227 @pre None
       
   228 @post None
       
   229 @publishedPartner
       
   230 @released
       
   231 @capability None
       
   232 */
       
   233 EXPORT_C const TDesC8& CCalAttachment::Value() const
       
   234 	{
       
   235 	return iAttachmentImpl->Content();
       
   236 	}
       
   237 
       
   238 /** Set the value of the MIME type (RFC 2046).
       
   239 @param aMimeType The MIME type of the attachment.
       
   240 @leave KErrArgument If the MIME type is longer than KCalAttachmentMaxMimeTypeLength.
       
   241 @pre None
       
   242 @post The MIME type of this attachment has been updated.
       
   243 @publishedPartner
       
   244 @released
       
   245 @capability None
       
   246 */
       
   247 EXPORT_C void CCalAttachment::SetMimeTypeL(const TDesC8& aMimeType)
       
   248 	{
       
   249 	__ASSERT_ALWAYS(aMimeType.Length() <= KCalAttachmentMaxMimeTypeLength, User::Leave(KErrArgument));
       
   250 	iAttachmentImpl->SetMimeTypeL(aMimeType);
       
   251 	}
       
   252 
       
   253 /** Get the MIME type (RFC 2046).
       
   254 @return The MIME type of the attachment, or an empty descriptor if none has been set.
       
   255 @pre None
       
   256 @post None
       
   257 @publishedPartner
       
   258 @released
       
   259 @capability None
       
   260 */
       
   261 EXPORT_C const TDesC8& CCalAttachment::MimeType() const
       
   262 	{
       
   263 	return iAttachmentImpl->MimeType();
       
   264 	}
       
   265 
       
   266 /** Set the label for the attachment.
       
   267 The label is the user-visible name for the attachment. 
       
   268 It could be the filename, but does not have to be. Setting the label has no effect on the actual filename.
       
   269 @param aName The attachment label.
       
   270 @leave KErrArgument If the label is longer than KCalAttachmentMaxLabelLength.
       
   271 @pre None
       
   272 @post The attachment's label has been updated.
       
   273 @publishedPartner
       
   274 @released
       
   275 @capability None
       
   276 */
       
   277 EXPORT_C void CCalAttachment::SetLabelL(const TDesC& aName)
       
   278 	{
       
   279 	iAttachmentImpl->SetLabelL(aName);
       
   280 	}
       
   281 
       
   282 /** Get the label for the attachment.
       
   283 @return The label for the attachment, or an empty descriptor if none has been set.
       
   284 @pre None
       
   285 @post None
       
   286 @publishedPartner
       
   287 @released
       
   288 @capability None
       
   289 */
       
   290 EXPORT_C const TDesC& CCalAttachment::Label() const
       
   291 	{
       
   292 	return iAttachmentImpl->Label();
       
   293 	}
       
   294 
       
   295 /** Allow access to the file-specific functions of a file attachment.
       
   296 @return If this is a EFile attachment, return a pointer to CCalAttachmentFile. 
       
   297 The caller does not take ownership.
       
   298 Return NULL if this is a EUri attachment. 
       
   299 
       
   300 This function can be used to test whether an attachment has file-specific data, e.g.
       
   301 @code
       
   302 	CCalAttachment* attachment = entry->Attachment(aIndex);
       
   303 	
       
   304 	CCalAttachmentFile* attachmentFile = attachment->FileAttachment();
       
   305 	if (attachmentFile)
       
   306 		{
       
   307 		TInt attachSize = attachmentFile->Size();
       
   308 		...
       
   309 		}
       
   310 @endcode
       
   311 
       
   312 @pre None
       
   313 @post None
       
   314 @publishedPartner
       
   315 @released
       
   316 @capability None
       
   317 */
       
   318 EXPORT_C CCalAttachmentFile* CCalAttachment::FileAttachment() const
       
   319 	{
       
   320 	return iFileAttachment;
       
   321 	}
       
   322 
       
   323 /** Sets attributes of an attachment.
       
   324 @param aAttribute The attribute or attributes to be set, as defined in CCalAttachment::TAttributes.
       
   325 @pre None
       
   326 @post The attachment's attribute data has been updated.
       
   327 @publishedPartner
       
   328 @released
       
   329 @capability None
       
   330 */
       
   331 EXPORT_C void CCalAttachment::SetAttribute(TUint16 aAttribute)
       
   332 	{
       
   333 	iAttachmentImpl->SetAttribute(aAttribute);
       
   334 	}
       
   335 
       
   336 /** Clears attributes of an attachment.
       
   337 @param aAttribute The attribute or attributes to be cleared, as defined in CCalAttachment::TAttributes.
       
   338 @pre None
       
   339 @post The attachment's attribute data has been updated.
       
   340 @publishedPartner
       
   341 @released
       
   342 @capability None
       
   343 */
       
   344 EXPORT_C void CCalAttachment::ClearAttribute(TUint16 aAttribute)
       
   345 	{
       
   346 	iAttachmentImpl->ClearAttribute(aAttribute);
       
   347 	}
       
   348 
       
   349 /** Tests attributes of an attachment, as defined in CCalAttachment::TAttributes.
       
   350 @param aAttribute The attribute or attributes to be tested.
       
   351 @return ETrue if the attachment has all these attributes. Otherwise EFalse.
       
   352 @pre None
       
   353 @post None
       
   354 @publishedPartner
       
   355 @released
       
   356 @capability None
       
   357 */
       
   358 EXPORT_C TBool CCalAttachment::IsAttributeSet(TUint16 aAttribute) const
       
   359 	{
       
   360 	return iAttachmentImpl->IsAttributeSet(aAttribute);
       
   361 	}
       
   362 
       
   363 // CCalAttachmentFile //
       
   364 
       
   365 CCalAttachmentFile::CCalAttachmentFile(CCalAttachment& aAttachment, CCalSessionImpl* aCalSessionImpl) 
       
   366 	{
       
   367 	__ASSERT_ALWAYS(aAttachment.Type() == CCalAttachment::EFile, CalUtils::Panic(EInvalidAttachmentType));
       
   368 	iAttachmentImpl = static_cast<CAgnAttachmentFile*>(&aAttachment.Impl());
       
   369 	
       
   370 	iCalSessionImpl = aCalSessionImpl;
       
   371 	if (iCalSessionImpl)
       
   372 		{
       
   373 		iCalSessionImpl->IncrementReferenceCount();
       
   374 		}
       
   375 	}
       
   376 
       
   377 CCalAttachmentFile::~CCalAttachmentFile()
       
   378 	{
       
   379 	if (iCalSessionImpl)
       
   380 		{
       
   381 		iCalSessionImpl->DecrementReferenceCount();
       
   382 		}
       
   383 	}
       
   384 
       
   385 /** Set the content ID of a file attachment. 
       
   386 The content ID is only used during import / export of attachments.
       
   387 @param aContentId The content ID.
       
   388 @pre None
       
   389 @post The attachment's content ID has been set.
       
   390 @publishedPartner
       
   391 @released
       
   392 @capability None
       
   393 */
       
   394 EXPORT_C void CCalAttachmentFile::SetContentIdL(const TDesC8& aContentId)
       
   395 	{
       
   396 	iAttachmentImpl->SetContentIdL(aContentId);
       
   397 	}
       
   398 	
       
   399 /** Fetch the content ID of a file attachment.
       
   400 Note that the content ID of an entry is not stored in the calendar store. Content IDs are intended to 
       
   401 be used on import / export only.
       
   402 @return The content ID. This will be an empty descriptor if no content ID has been set.
       
   403 @pre None
       
   404 @post None
       
   405 @publishedPartner
       
   406 @released
       
   407 @capability None
       
   408 */
       
   409 EXPORT_C const TDesC8& CCalAttachmentFile::ContentId() const
       
   410 	{
       
   411 	return iAttachmentImpl->ContentId();
       
   412 	}
       
   413 
       
   414 /** Set the drive on which to store a file attachment.
       
   415 The default value is the same as the current calendar file. 
       
   416 @param aDrive The drive on which to store a file attachment.
       
   417 The first character of the string specifies the drive letter. The second character, if present, must be a semi-colon.
       
   418 The following strings are all valid and will set the drive to D:
       
   419 "D"
       
   420 "D:"
       
   421 "D:\someFolder\someFile.ext"
       
   422 The drive letter can be given in either upper or lower case.
       
   423 @leave KErrArgument if the parameter is an empty descriptor, or if the first character is not a drive letter (A to Z), or if the 
       
   424 second character exists but is not the drive separator ':'.
       
   425 Otherwise any of the system-wide error codes.
       
   426 @pre None
       
   427 @post The attachment's drive has been set.
       
   428 @publishedPartner
       
   429 @released
       
   430 @capability None
       
   431 */
       
   432 EXPORT_C void CCalAttachmentFile::SetDriveL(const TDesC& aDrive)
       
   433 	{
       
   434 	__ASSERT_ALWAYS(aDrive.Length() > 0, User::Leave(KErrArgument));
       
   435 	TChar driveLetter = aDrive[0];
       
   436 	__ASSERT_ALWAYS(driveLetter.IsAlpha(), User::Leave(KErrArgument));
       
   437 
       
   438 	if (aDrive.Length() == 1)
       
   439 		{
       
   440 		TDriveName drive(aDrive);
       
   441 		drive.Append(':');
       
   442 		iAttachmentImpl->SetDriveL(drive);
       
   443 		}
       
   444 	else
       
   445 		{
       
   446 		__ASSERT_ALWAYS(aDrive[1] == ':', User::Leave(KErrArgument));
       
   447 		iAttachmentImpl->SetDriveL(aDrive);	
       
   448 		}
       
   449 	}
       
   450 
       
   451 /** Get the drive on which a file attachment is stored.
       
   452 The default value is the same as the current calendar file.
       
   453 @return The drive containing the file attachment.
       
   454 @pre None
       
   455 @post None
       
   456 @publishedPartner
       
   457 @released
       
   458 @capability None
       
   459 */
       
   460 EXPORT_C TDriveName CCalAttachmentFile::Drive() const
       
   461 	{
       
   462 	return iAttachmentImpl->Drive();
       
   463 	}
       
   464 
       
   465 /** Get the size of the attachment in bytes. 
       
   466 This is the same as the size of the attachment file.
       
   467 @return The size in bytes.
       
   468 @pre None
       
   469 @post None
       
   470 @publishedPartner
       
   471 @released
       
   472 @capability None
       
   473 */
       
   474 EXPORT_C TInt CCalAttachmentFile::Size() const
       
   475 	{
       
   476 	return iAttachmentImpl->Size();
       
   477 	}
       
   478 
       
   479 /** Set the last modified time of an attachment file.
       
   480 The user is responsible for setting the last modified time.
       
   481 @param aUtcTime The last modified time in UTC. 
       
   482 @pre None
       
   483 @post The attachment's last modified time has been set.
       
   484 @publishedPartner
       
   485 @released
       
   486 @capability None
       
   487 */
       
   488 EXPORT_C void CCalAttachmentFile::SetLastModifiedTimeUtc(const TTime& aUtcTime)
       
   489 	{
       
   490 	return iAttachmentImpl->SetLastModifiedTimeUtc(aUtcTime);
       
   491 	}
       
   492 
       
   493 /** Get the last modified time of a file attachment.
       
   494 The user is responsible for setting the last modified time.
       
   495 @return The last modified time of the attachment file in UTC.
       
   496 @pre None
       
   497 @post None
       
   498 @publishedPartner
       
   499 @released
       
   500 @capability None
       
   501 */
       
   502 EXPORT_C const TTime& CCalAttachmentFile::LastModifiedTimeUtc() const
       
   503 	{
       
   504 	return iAttachmentImpl->LastModifiedTimeUtc();
       
   505 	}
       
   506 
       
   507 /** Sets an attachment's data from a file handle.
       
   508 @param aFileHandle The handle to the attachment file. CCalAttachmentFile will make copy of "aFileHandle"
       
   509 The file handle must be opened using the mode EFileWrite and it should belong to a shared file server session. 
       
   510 @see ShareProtected
       
   511 @leave KErrAccessDenied If the file pointed to by this file handle is read only. 
       
   512 @leave KErrArgument If this attachment's data has already been set or if the attachment was not created from a content ID.
       
   513 Otherwise any of the system-wide error codes.
       
   514 @panic If the file handle has not been initialised by calling RFs::Open.
       
   515 @pre This attachment has been created from a content ID, and SetResourceL has not been called previously.
       
   516 @post The attachment takes ownership of the given file handle.
       
   517 @publishedPartner
       
   518 @released
       
   519 @capability None
       
   520 */
       
   521 EXPORT_C void CCalAttachmentFile::SetResourceL(RFile& aFileHandle)
       
   522 	{
       
   523 	TUint attValue = 0;
       
   524 	
       
   525 	// Panics if the file handle is invalid:
       
   526 	User::LeaveIfError(aFileHandle.Att(attValue));
       
   527 	if (attValue & KEntryAttReadOnly)
       
   528 		{
       
   529 		User::Leave(KErrAccessDenied);
       
   530 		}
       
   531 	
       
   532 	if (iAttachmentImpl->FlagsSet(CAgnAttachment::EDataHasBeenSet))
       
   533 		{
       
   534 		User::Leave(KErrArgument);
       
   535 		}
       
   536 	else
       
   537 		{
       
   538 		iAttachmentImpl->CopyFileHandle(aFileHandle);
       
   539 		}
       
   540 	}
       
   541 
       
   542 /** Fetch the file handle for this attachment.
       
   543 If a new file handle has been set but the attachment has not been stored, nothing happens.
       
   544 @param aFileHandle On return, this file handle will point to the attachment file in the calendar store.
       
   545 @leave KErrArgument If this attachment has not been fetched from the calendar store.
       
   546 @leave KErrNotFound If the attachment has been deleted from the calendar store.
       
   547 @leave KErrNotReady If the attachment file is on a drive where the media has been removed.
       
   548 Otherwise any of the system-wide error codes.
       
   549 @pre The calendar attachment has been fetched from the calendar store.
       
   550 @post None
       
   551 @publishedPartner
       
   552 @released
       
   553 @capability ReadUserData
       
   554 */
       
   555 EXPORT_C void CCalAttachmentFile::FetchFileHandleL(RFile& aFileHandle) const
       
   556 	{
       
   557 	if (iAttachmentImpl->IsFileHandleSet() || ! iCalSessionImpl)
       
   558 		{
       
   559 		User::Leave(KErrArgument);
       
   560 		}
       
   561 
       
   562 	iCalSessionImpl->Server().FetchFileHandleL(aFileHandle, iAttachmentImpl->Uid(), iCalSessionImpl->FileId());
       
   563 	}
       
   564 
       
   565 /** Load the binary data into the attachment object to be accessed through the CCalAttachment::Value function.
       
   566 Note that binary data can be very large so this may use up a lot of RAM.
       
   567 If binary data has already been loaded, this function will do nothing. In that case, CCalAttachment::Value will 
       
   568 return a non-empty descriptor.
       
   569 @leave KErrArgument If this attachment has not been fetched from the calendar store.
       
   570 @leave KErrNotFound If the attachment has been deleted from the calendar store.
       
   571 @leave KErrNotReady If the attachment file is on a drive where the media has been removed.
       
   572 Otherwise any of the system-wide error codes.
       
   573 @pre A file attachment object has been fetched from the calendar store.
       
   574 @post The attachment object owns a copy of the binary data from the calendar store.
       
   575 @publishedPartner
       
   576 @released
       
   577 @capability ReadUserData
       
   578 */
       
   579 EXPORT_C void CCalAttachmentFile::LoadBinaryDataL()
       
   580 	{
       
   581 	if (iAttachmentImpl->Content().Length() == 0)
       
   582 		{
       
   583 		// if no binary data present, try to fetch it from the file directly
       
   584 		RFile fileHandle;
       
   585 		FetchFileHandleL(fileHandle);
       
   586 		CleanupClosePushL(fileHandle);
       
   587 
       
   588 		TInt size;
       
   589 		User::LeaveIfError(fileHandle.Size(size));
       
   590 		HBufC8* data = HBufC8::NewLC(size);
       
   591 		TPtr8 ptr = data->Des();
       
   592 		User::LeaveIfError(fileHandle.Read(ptr));
       
   593 
       
   594 		CleanupStack::Pop(data);
       
   595 		CleanupStack::PopAndDestroy(&fileHandle); // fileHandle.Close
       
   596 
       
   597 		// store binary data in attachment
       
   598 		iAttachmentImpl->SetValue(data);
       
   599 		}
       
   600 	}