phonebookui/Phonebook/inc/CPbkAttachmentFile.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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 "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 *     Attachment file handler
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef __CPbkAttachmentFile_H__
       
    21 #define __CPbkAttachmentFile_H__
       
    22 
       
    23 // INCLUDES
       
    24 #include    <f32file.h>     // File modes
       
    25 #include    <bamdesca.h>    // MDesCArray
       
    26 
       
    27 //  CLASS DECLARATION 
       
    28 
       
    29 /**
       
    30  * @internal Only Phonebook internal use supported!
       
    31  *
       
    32  * Class which creates a temporary file at construction and deletes the
       
    33  * file when destroyed.
       
    34  */
       
    35 class CPbkAttachmentFile : public CBase
       
    36 	{
       
    37     public: // Interface
       
    38         /// Drive enumeration
       
    39         enum TTempDrive
       
    40             {
       
    41             /// RAM disk. Contents lost at power-down
       
    42             ERamDisk = 1,
       
    43             /// Persistent file system
       
    44             EPersistent
       
    45             };
       
    46 
       
    47         /**
       
    48          * Creates new attachment file.
       
    49          *
       
    50          * @param aBaseName basename used to build a unique filename. Used
       
    51          *                  as-is if the filename is not in use.
       
    52          * @param aRfs      open file server session handle.
       
    53          * @param aFileMode mode in which to create the file, see RFile::Create.
       
    54          */
       
    55 		IMPORT_C static CPbkAttachmentFile* NewL
       
    56             (const TDesC& aBaseName, 
       
    57             RFs& aRfs,
       
    58             TUint aFileMode = EFileStream|EFileShareExclusive|EFileWrite);
       
    59 
       
    60         /**
       
    61          * Like NewL but leaves the created object on the cleanup stack.
       
    62          * @see CPbkAttachmentFile::NewL
       
    63          */
       
    64 		IMPORT_C static CPbkAttachmentFile* NewLC
       
    65             (const TDesC& aBaseName, 
       
    66             RFs& aRfs,
       
    67             TUint aFileMode = EFileStream|EFileShareExclusive|EFileWrite);
       
    68 
       
    69         /**
       
    70          * Destructor. Closes and deletes the file from the file system.
       
    71          * If Release() has been called the file is not deleted.
       
    72          */
       
    73         ~CPbkAttachmentFile();
       
    74 
       
    75         /**
       
    76          * Returns the full file name.
       
    77          */
       
    78         IMPORT_C const TDesC& FileName() const;
       
    79 
       
    80         /**
       
    81          * Returns the opened attachment file.
       
    82          */
       
    83         IMPORT_C RFile& File();
       
    84 
       
    85         /**
       
    86          * Switches drive to use from RAM disk to persistent disk or vice 
       
    87          * versa and recreates the attachment file on the other drive. Current
       
    88          * file is closed and deleted.
       
    89          */
       
    90         IMPORT_C void SwitchDriveL();
       
    91 
       
    92         /**
       
    93          * Closes the file and releases ownership of it. After calling this 
       
    94          * function the file is no longer deleted in destructor. 
       
    95          */
       
    96         IMPORT_C void Release();
       
    97 
       
    98 	private:  // Implementation
       
    99         CPbkAttachmentFile();
       
   100         void ConstructL(const TDesC& aBaseName);
       
   101         void CreateFileL(const TDesC& aDrive, const TDesC& aDir, const TDesC& aBaseName);
       
   102         void DeleteFile();
       
   103     
       
   104     private:  // Data
       
   105         /// Ref: Handle to file server
       
   106         RFs iRfs;
       
   107         /// Own: file mode
       
   108         TUint iFileMode;
       
   109         /// Own: cleaned up base name
       
   110         HBufC* iBaseName;
       
   111         /// Own: name of the file
       
   112         HBufC* iFileName;
       
   113         /// Own: the opened file
       
   114         RFile iFile;
       
   115         /// Own: ETrue if this object owns the file and should delete it in
       
   116         /// destructor
       
   117         TBool iOwnsFile;
       
   118 	};
       
   119 
       
   120 
       
   121 /**
       
   122  * Array of CPbkAttachmentFile objects. This array owns the object it contains,
       
   123  * in other words it will delete the contained objects in its destructor.
       
   124  * Implements MDesCArray interface through which the file names can be 
       
   125  * retrieved.
       
   126  */
       
   127 class CPbkAttachmentFileArray : 
       
   128         public CArrayPtrFlat<CPbkAttachmentFile>, public MDesCArray
       
   129     {
       
   130     public:  // Interface
       
   131         /**
       
   132          * Constructor.
       
   133          * @param aGranularity array reallocation granularity.
       
   134          */
       
   135         IMPORT_C CPbkAttachmentFileArray(TInt aGranularity);
       
   136 
       
   137         /**
       
   138          * Destructor. Deletes all CPbkAttachmentFile objects in the array.
       
   139          */
       
   140         IMPORT_C ~CPbkAttachmentFileArray();
       
   141 
       
   142     public:  // from MDesCArray
       
   143         IMPORT_C TInt MdcaCount() const;
       
   144         IMPORT_C TPtrC MdcaPoint(TInt aIndex) const;
       
   145     };
       
   146 
       
   147 #endif // __CPbkAttachmentFile_H__
       
   148 
       
   149 // End of File