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