phonebookui/Phonebook2/inc/CPbk2AttachmentFile.h
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Phonebook 2 attachment file.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CPBK2ATTACHMENTFILE_H
       
    20 #define CPBK2ATTACHMENTFILE_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <f32file.h>     // File modes
       
    24 #include <bamdesca.h>    // MDesCArray
       
    25 
       
    26 // CLASS DECLARATION
       
    27 
       
    28 /**
       
    29  * Class which creates a temporary file at construction and deletes the
       
    30  * file when destroyed.
       
    31  */
       
    32 NONSHARABLE_CLASS(CPbk2AttachmentFile) : public CBase
       
    33     {
       
    34     public: // Types
       
    35 
       
    36         /**
       
    37          * Drive enumerations.
       
    38          */
       
    39         enum TTempDrive
       
    40             {
       
    41             /// RAM disk, contents lost at power-down
       
    42             ERamDisk = 1,
       
    43             /// Persistent file system
       
    44             EPersistent
       
    45             };
       
    46 
       
    47     public: // Construction and destruction
       
    48 
       
    49         /**
       
    50          * Creates a new attachment file.
       
    51          *
       
    52          * @param aBaseName Basename used to build an unique filename. Used
       
    53          *                  as-is if the filename is not in use.
       
    54          * @param aRfs      Open file server session handle.
       
    55          * @param aFileMode Mode in which to create the file.
       
    56          *                  @see RFile::Create.
       
    57          * @return  A new instance of this class.
       
    58          */
       
    59         static CPbk2AttachmentFile* NewL(
       
    60                 const TDesC& aBaseName,
       
    61                 RFs& aRfs,
       
    62                 TUint aFileMode = EFileStream|EFileShareExclusive|EFileWrite );
       
    63 
       
    64         /**
       
    65          * Creates a new attachment file.
       
    66          *
       
    67          * @param aBaseName Basename used to build an unique filename. Used
       
    68          *                  as-is if the filename is not in use.
       
    69          * @param aRfs      Open file server session handle.
       
    70          * @param aFileMode Mode in which to create the file.
       
    71          *                  @see RFile::Create.
       
    72          * @return  A new instance of this class.
       
    73          */
       
    74         IMPORT_C static CPbk2AttachmentFile* NewLC(
       
    75                 const TDesC& aBaseName,
       
    76                 RFs& aRfs,
       
    77                 TUint aFileMode = EFileStream|EFileShareExclusive|EFileWrite );
       
    78 
       
    79         /**
       
    80          * Destructor. Closes and deletes the file from the file system.
       
    81          * If Release() has been called the file is not deleted.
       
    82          */
       
    83         ~CPbk2AttachmentFile();
       
    84 
       
    85     public: // Interface
       
    86 
       
    87         /**
       
    88          * Returns the full file name.
       
    89          *
       
    90          * @return  File name.
       
    91          */
       
    92         IMPORT_C const TDesC& FileName() const;
       
    93 
       
    94         /**
       
    95          * Returns the opened attachment file.
       
    96          *
       
    97          * @return  Opened attachment file.
       
    98          */
       
    99         IMPORT_C RFile& File();
       
   100 
       
   101         /**
       
   102          * Switches drive to use from RAM disk to persistent disk or vice
       
   103          * versa and recreates the attachment file on the other drive. Current
       
   104          * file is closed and deleted.
       
   105          */
       
   106         IMPORT_C void SwitchDriveL();
       
   107 
       
   108         /**
       
   109          * Closes the file and releases ownership of it. After calling this
       
   110          * function the file is no longer deleted in destructor.
       
   111          */
       
   112         IMPORT_C void Release();
       
   113 
       
   114     private: // Implementation
       
   115         CPbk2AttachmentFile( RFs& aRfs, TUint aFileMode );
       
   116         void ConstructL( const TDesC& aBaseName );
       
   117         void CreateFileL(
       
   118                 const TDesC& aDrive,
       
   119                 const TDesC& aDir,
       
   120                 const TDesC& aBaseName );
       
   121         void DeleteFile();
       
   122 
       
   123     private: // Data
       
   124         /// Ref: Handle to file server
       
   125         RFs iRfs;
       
   126         /// Own: File mode
       
   127         TUint iFileMode;
       
   128         /// Own: Cleaned up base name
       
   129         HBufC* iBaseName;
       
   130         /// Own: Name of the file
       
   131         HBufC* iFileName;
       
   132         /// Own: The opened file
       
   133         RFile iFile;
       
   134         /// Own: ETrue if this object owns the file and should delete it in
       
   135         ///      the destructor
       
   136         TBool iOwnsFile;
       
   137     };
       
   138 
       
   139 class MPbk2AttachmentFileArray
       
   140     {
       
   141     public:
       
   142         virtual ~MPbk2AttachmentFileArray() {}
       
   143     
       
   144     public:
       
   145         virtual RFile& FileHandleAt( TInt aIndex ) =0;
       
   146     };
       
   147 
       
   148 /**
       
   149  * Array of CPbk2AttachmentFile objects. This array owns the object it contains,
       
   150  * in other words it will delete the contained objects in its destructor.
       
   151  * Implements MDesCArray interface through which the file names can be
       
   152  * retrieved.
       
   153  * Also RFile handle objects can be retrieved by index.
       
   154  */
       
   155 NONSHARABLE_CLASS(CPbk2AttachmentFileArray) :
       
   156         public CArrayPtrFlat<CPbk2AttachmentFile>, 
       
   157         public MDesCArray,
       
   158         public MPbk2AttachmentFileArray
       
   159     {
       
   160     public: // Construction and destruction
       
   161 
       
   162         /**
       
   163          * Constructor.
       
   164          *
       
   165          * @param aGranularity  Array reallocation granularity.
       
   166          */
       
   167         CPbk2AttachmentFileArray(
       
   168                 TInt aGranularity );
       
   169 
       
   170         /**
       
   171          * Destructor.
       
   172          * Deletes all CPbk2AttachmentFile objects in the array.
       
   173          */
       
   174         ~CPbk2AttachmentFileArray();
       
   175 
       
   176     public: // From MDesCArray
       
   177         TInt MdcaCount() const;
       
   178         TPtrC MdcaPoint(
       
   179                 TInt aIndex ) const;
       
   180     
       
   181     public: // From MPbk2AttachmentFileArray
       
   182         RFile& FileHandleAt( TInt aIndex );
       
   183     };
       
   184 
       
   185 #endif // CPBK2ATTACHMENTFILE_H
       
   186 
       
   187 // End of File