pimappservices/calendar/server/inc/agsattachmentindex.h
changeset 0 f979ecb2b13e
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 #ifndef __AGSATTACHMENTINDEX_H__
       
    17 #define __AGSATTACHMENTINDEX_H__
       
    18 
       
    19 #include "agmattachment.h"
       
    20 #include <calattachmentmanager.h>
       
    21 #include <badesca.h>
       
    22 
       
    23 class CAgnEntry;
       
    24 class CAgnServFile;
       
    25 
       
    26 /** 
       
    27 Class for storing metadata about a file attachment, used in the attachment index.
       
    28 @internalComponent
       
    29 */
       
    30 class CAgnAttachmentIndexItem : public CBase
       
    31 	{
       
    32 public:
       
    33 	static CAgnAttachmentIndexItem* NewL(const CAgnAttachmentFile& aAttachment, TCalLocalUid aLocalUid);
       
    34 	static CAgnAttachmentIndexItem* NewL(RReadStream& aReadStream);
       
    35 	~CAgnAttachmentIndexItem();
       
    36 	
       
    37 
       
    38 	TInt Size() const;
       
    39 	const TTime& LastModifiedDateUtc() const;
       
    40 	const TDesC& FileName() const;
       
    41 	void SetFileName(HBufC* aFileName);//Take the ownership
       
    42 	const RArray<TCalLocalUid>& Entries() const;
       
    43 	TCalAttachmentUid Uid() const;
       
    44 
       
    45 	void AddEntryL(TCalLocalUid aLocalUid);
       
    46 	void DeleteEntry(TCalLocalUid aLocalUid);
       
    47 	
       
    48 	void InternalizeL(RReadStream& aReadStream);
       
    49 	void ExternalizeL(RWriteStream& aWriteStream) const;
       
    50 
       
    51 private:
       
    52 	CAgnAttachmentIndexItem(const CAgnAttachmentFile& aAttachment);
       
    53 	CAgnAttachmentIndexItem();
       
    54 	void ConstructL(const CAgnAttachmentFile& aAttachment, TCalLocalUid aLocalUid);
       
    55 
       
    56 private:
       
    57 	TInt					iSize;
       
    58 	TTime					iLastModifiedDateUtc;
       
    59 	HBufC*					iFileName;
       
    60 	RArray<TCalLocalUid>	iEntries;
       
    61 	TCalAttachmentUid		iUid;
       
    62 	};
       
    63 
       
    64 /** 
       
    65 The attachment index stores metadata about all file attachments in the Calendar database.
       
    66 URI attachments are not stored here.
       
    67 @internalComponent
       
    68 */
       
    69 class CAgnAttachmentIndex : public CBase
       
    70 	{
       
    71 public:
       
    72 	CAgnAttachmentIndex();
       
    73 	~CAgnAttachmentIndex();
       
    74 
       
    75 	// called when an entry is added, deleted or updated from the indexes
       
    76 	void AddEntryL(CAgnEntry& aEntry);
       
    77 	void DeleteEntryL(CAgnEntry& aEntry);
       
    78 
       
    79 	// completely remove an attachment
       
    80 	void RemoveAttachment(TCalAttachmentUid aUid);
       
    81 	
       
    82 	// attachment array operations
       
    83 	const CAgnAttachmentIndexItem* Attachment(TCalAttachmentUid aUid) const; // doesn't return ownership
       
    84 	TInt Count() const;
       
    85 
       
    86 	void Reset();
       
    87 	void CommitL(CAgnServFile& aServFile);
       
    88 	void Rollback();
       
    89 
       
    90 	// get all attachments sorted as specified	
       
    91 	void GetSortedIndexL(CCalAttachmentManager::TSortOrder aSortOrder, RPointerArray<CAgnAttachmentIndexItem>& aAttachments) const;
       
    92 	
       
    93 	// Get the file name for given attachment uid. Return KNullDesC if the attachment with that uid is not found
       
    94 	const TDesC& FileName(TCalAttachmentUid aUid);
       
    95 
       
    96 	void InternalizeL(RReadStream& aReadStream);
       
    97 	void ExternalizeL(RWriteStream& aWriteStream) const;
       
    98 
       
    99 private:
       
   100 	void RemoveEntryFromAttachmentL(TCalLocalUid aEntryUid, TCalAttachmentUid aAttachmentUid);
       
   101 	TInt AttachmentIndex(TCalAttachmentUid aUid) const;
       
   102 	
       
   103 	static TInt SortBySizeLargestFirst(const CAgnAttachmentIndexItem& aLeft, const CAgnAttachmentIndexItem& aRight);
       
   104 	static TInt SortByDateModifiedNewestFirst(const CAgnAttachmentIndexItem& aLeft, const CAgnAttachmentIndexItem& aRight);
       
   105 	static TInt SortByDateModifiedOldestFirst(const CAgnAttachmentIndexItem& aLeft, const CAgnAttachmentIndexItem& aRight);
       
   106 	
       
   107 private:
       
   108 	RPointerArray<CAgnAttachmentIndexItem>	iIndex;
       
   109 	CDesCArray* 							iFileRollbackArray;
       
   110 	};
       
   111 
       
   112 #endif // __AGSATTACHMENTINDEX_H__