imgeditor_plat/image_editor_utilities_api/inc/ImageEditorUtils.h
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description: 
       
    16 * Static utility class.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef IMAGEEDITORUTILS_H
       
    22 #define IMAGEEDITORUTILS_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <coemain.h>
       
    26 
       
    27 class CMGXFileManager;
       
    28 class RFs;
       
    29 
       
    30 
       
    31 /**
       
    32  *  Static utility class
       
    33  *
       
    34  *  @code
       
    35  *   ?good_class_usage_example(s)
       
    36  *  @endcode
       
    37  *
       
    38  *  @lib ImageEditorUtils.lib
       
    39  *  @since S60 v5.0
       
    40  */
       
    41 class ImageEditorUtils
       
    42 {
       
    43 public:
       
    44 
       
    45     /**  Memory location */
       
    46     enum TMemoryLocation
       
    47 	  {
       
    48 		  EPhone,
       
    49 		  EMmc,
       
    50 		  EMixed
       
    51     };
       
    52 
       
    53     /**  Memory location selection options  */
       
    54     enum TMemorySelection
       
    55     {
       
    56       ESelectAutomatic,
       
    57       ESelectPhone,
       
    58       ESelectMmc
       
    59     };
       
    60 
       
    61     /**
       
    62      * Generates a new name for the loaded document at the startup.
       
    63      * If automatic memory selection is used, the generated file is located on the 
       
    64      * MMC dy default. If the MMC is full or not present, the file will be in phone 
       
    65      * memory. Optionally the file can be forced onto either drive.
       
    66      * Internally, ImageFitsToDriveL is used to check the space.
       
    67      *
       
    68      * Media gallery album id list is no longer supported due to Media Gallery removal. 
       
    69      * If an invalid album list is passed the behaviour is undefined.     
       
    70      *
       
    71      * @since S60 v5.0
       
    72      * @param aFsSession file server session handle
       
    73      * @param aSourceFileName source file name
       
    74      * @param aTargetFileName target file name
       
    75      * @param aMgAlbumIdList list of the albums the source image belongs to
       
    76      * @param aReservedFileNames  additional list of already reserved file names
       
    77      * @param aMemoryInUse  where the target file is created
       
    78      * @return KErrNone if successfully generated file name
       
    79      *         KSIEENotEnoughDiskSpace if no disk space to save the file
       
    80      *         (size of aSourceFileName used to check the space)
       
    81      *         KSIEEOpenFile if the source filename is invalid
       
    82      */
       
    83      IMPORT_C static TInt GenerateNewDocumentNameL (
       
    84         RFs& aFsSession, 
       
    85         const TDesC& aSourceFileName, 
       
    86         TDes& aTargetFileName,
       
    87         RArray<TInt>* aMgAlbumIdList = NULL,
       
    88         const CDesCArray* aReservedFileNames = NULL,
       
    89         ImageEditorUtils::TMemorySelection aMemoryInUse = ImageEditorUtils::ESelectAutomatic
       
    90         );
       
    91         
       
    92     /**
       
    93      * Generates a new name for the loaded document in filename query. A 
       
    94      * unique filename is generated by adding running number after source 
       
    95      * filename until unique name is found. e.g. if image name is "Image", 
       
    96      * first attempt for new filename is "Image-001". If that is already 
       
    97      * in use, "Image-002" is tried and so on. First unused filename is 
       
    98      * then proposed for the user.
       
    99      * ImageFitsToDriveL is used to check the space. 
       
   100      *
       
   101      * @since S60 v5.0
       
   102      * @param aFsSession file server session handle
       
   103      * @param aSourceFileName source file name
       
   104      * @param aTargetFileName target file name
       
   105      * @param aDrive the drive where the target file is to be created
       
   106      * @param aReservedFileNames  additional list of already reserved file names
       
   107      * @return KErrNone if successfully generated file name
       
   108      *         KSIEENotEnoughDiskSpace if no disk space to save the file
       
   109      *         (size of aSourceFileName used to check the space)
       
   110      *         KSIEEOpenFile if the source filename is invalid
       
   111      */    
       
   112     IMPORT_C static TInt GenerateNewFileNameL (
       
   113         RFs& aFsSession, 
       
   114         const TDesC& aSourceFileName, 
       
   115         TDes& aTargetFileName,
       
   116         TFileName aDrive,
       
   117         const CDesCArray* aReservedFileNames = NULL );
       
   118         
       
   119         
       
   120     /**	GenerateFilePath
       
   121 	 *	    
       
   122      * Generates a path for an image file. The memory selection option is given
       
   123      * as a parameter.
       
   124      * ImageEditorUtilsImageFitsToDriveL is used to check the space.
       
   125      *
       
   126      * Media gallery album id list is no longer supported due to Media Gallery removal. 
       
   127      * If an invalid album list is passed the behaviour is undefined.     
       
   128      *
       
   129      * @since S60 v5.0
       
   130      * @param aFsSession file server session handle
       
   131      * @param aSourceFileName source file name
       
   132      * @param aTargetFileName target file name
       
   133      * @param aMgAlbumIdList list of the albums the source image belongs to
       
   134      * @param aReservedFileNames  additional list of already reserved file names
       
   135      * @param aMemoryInUse  where the target file is created
       
   136      * @return KErrNone if successfully generated file name
       
   137      *         KSIEENotEnoughDiskSpace if no disk space to save the file
       
   138      *         (size of aSourceFileName used to check the space)
       
   139      *         KSIEEOpenFile if the source filename is invalid
       
   140 	*/
       
   141 	IMPORT_C static TInt GenerateFilePathL (
       
   142 	    RFs& aFsSession, 
       
   143     	const TDesC& aSourceFileName, 
       
   144     	TDes& aTargetFileName,
       
   145     	ImageEditorUtils::TMemorySelection aMemoryInUse );
       
   146 
       
   147     /**
       
   148      * Checks whether there is enough disk space to save
       
   149      * the given file.
       
   150      *
       
   151      * @since S60 v5.0
       
   152      * @param aFsSession file server session handle
       
   153      * @param aSourceFile the file that would be saved
       
   154      * @param aTargetPath the path to save (only drive part needed)
       
   155      * @return ETrue if there is enough disk space to save the file
       
   156      *         EFalse if there is not enough disk space
       
   157      */
       
   158      IMPORT_C static TBool ImageFitsToDriveL (
       
   159         RFs& aFsSession,
       
   160         const TDesC& aSourceFile,
       
   161         const TDesC& aTargetPath
       
   162         );
       
   163 
       
   164     /**
       
   165      * Checks whether there is enough disk space to save
       
   166      * the given list of files.     
       
   167      *
       
   168      * @since S60 v5.0
       
   169      * @param aFsSession file server session handle
       
   170      * @param aSourceFileList the files that would be saved
       
   171      * @param aTargetFileList the paths to save (only drive part needed)
       
   172      * @return ETrue if there is enough disk space to save the files
       
   173      *         EFalse if there is not enough disk space
       
   174      */
       
   175      IMPORT_C static TBool ImagesFitToDriveL (
       
   176         RFs& aFsSession,
       
   177         const CDesCArray& aSourceFileList,
       
   178         const CDesCArray& aTargetFileList
       
   179         );
       
   180 
       
   181     /**
       
   182      * Notifies the system that a new image has been saved,
       
   183      * This is depreciated now and not used after MediaGallery removal.
       
   184      *
       
   185      * @since S60 v5.0
       
   186      * @param aFsSession file server session handle
       
   187      * @param aFileName name of the new file
       
   188      * @return -
       
   189      */
       
   190      IMPORT_C static void NotifyNewMediaDocumentL (
       
   191         RFs& aFsSession,
       
   192         const TDesC& aFileName
       
   193         );
       
   194 
       
   195     /**
       
   196      * Notifies the system that new images have been saved,
       
   197      * making them visible in the Media Gallery.
       
   198      * This is depreciated now and not used after MediaGallery removal.
       
   199      *
       
   200      * @since S60 v5.0
       
   201      * @param aFsSession file server session handle
       
   202      * @param aFileNameArray new file names
       
   203      * @return -
       
   204      */
       
   205      IMPORT_C static void NotifyNewMediaDocumentL (
       
   206         RFs& aFsSession,
       
   207         const MDesCArray& aFileNameArray
       
   208         );
       
   209 
       
   210     /**
       
   211      * Finds out in which Media Gallery Album the file belongs to.
       
   212      * If compiled without album support, this function
       
   213      * returns an empty array.
       
   214      * Reset() is called for the array at the begining.
       
   215      *
       
   216      * @since S60 v5.0
       
   217      * @param aAlbumList on return, contains the ID:s of the 
       
   218      *                   Media Gallery albums the file belongs to
       
   219      * @param aFileName the image file name
       
   220      * @return -
       
   221      */
       
   222      IMPORT_C static void FindAlbumsForImageFileL ( 
       
   223         RArray<TInt>& aAlbumIdList,
       
   224         const TDesC& aFilename
       
   225         );
       
   226 
       
   227     /**
       
   228      * Adds the given image file to the given album (e.g. video album).
       
   229      * If compiled without album support, this function does nothing.
       
   230      *
       
   231      * @since S60 v5.0
       
   232      * @param aFileName file name to be added to the album
       
   233      * @param aAlbumId id of the album
       
   234      * @return -
       
   235      */
       
   236      IMPORT_C static void AddImageFileToAlbumL ( 
       
   237                                  const TDesC& aFileName,
       
   238                                  TInt aAlbumId
       
   239                                  );
       
   240 
       
   241     /**
       
   242      * Helper function to get the manufacturer and model of the device.
       
   243      * Uses Shared Data client to retrieve the information.
       
   244      * If compiled on a public SDKs, which do not contain shared data,
       
   245      * this returns empty descriptors.
       
   246      *
       
   247      * @since S60 v5.0
       
   248      * @param aMake manufacturer of the device
       
   249      * @param aModel model of the device
       
   250      * @return -
       
   251      */
       
   252      IMPORT_C static void GetMakeAndModelL( TDes8& aMake, TDes8& aModel );
       
   253 
       
   254     /**
       
   255      * Copies file without opening it, using RFs::ReadFileSection.
       
   256      * Synchronous.
       
   257      *
       
   258      * @since S60 v5.0
       
   259      * @param aFsSession file server session handle
       
   260      * @param aSourceFileName source file name
       
   261      * @param aDestinationFileName destination file name
       
   262      * @param aOverwriteTarget is the target overwritten if it exists
       
   263      * @return error code
       
   264      */
       
   265      IMPORT_C static TInt CopyFile (
       
   266 		                          RFs& aFsSession,
       
   267                               const TDesC& aSourceFileName,
       
   268                               const TDesC& aDestinationFileName, 
       
   269                               TBool aOverwrite = ETrue
       
   270                               );
       
   271 
       
   272 private:
       
   273 
       
   274     /**
       
   275      * Finds the offset of the edited image suffix of form "-NNN", 
       
   276      * where NNN is the edit sequence number.
       
   277      *
       
   278      * @since S60 v5.0
       
   279      * @param aName image name without extension
       
   280      * @return offset of the edited image suffix
       
   281      */
       
   282      static TInt FindSuffix ( 
       
   283                     const TDesC &   aName
       
   284                     );
       
   285 
       
   286     /**
       
   287      * Checks if a file with the specified name already exists in the system.
       
   288      *
       
   289      * @since S60 v5.0
       
   290      * @param aFs file server session handle
       
   291      * @param aFileName file name to be checked
       
   292      * @param aReservedFileNames explicitly recerved file names
       
   293      * @return TBool
       
   294      */
       
   295      static TBool FileAlreadyExistsL ( 
       
   296                        RFs& aFsSession, 
       
   297                        const TDesC& aFileName,
       
   298                        const CDesCArray* aReservedFileNames 
       
   299                        );
       
   300 
       
   301     /**
       
   302      * Internal implementation of CopyFile
       
   303      *
       
   304      * @since S60 v5.0
       
   305      * @param aFsSession file server session handle
       
   306      * @param aSourceFileName source file
       
   307      * @param aDestinationFileName destination file
       
   308      * @param aSourceFileSize source file size in bytes
       
   309      * @return -
       
   310      */
       
   311      static void DoCopyL (
       
   312                    RFs& aFsSession,
       
   313                    const TDesC& aSourceFileName,
       
   314                    const TDesC& aDestinationFileName,
       
   315                    TUint aSourceFileSize 
       
   316                    );
       
   317 };
       
   318 
       
   319 
       
   320 #endif // IMAGEEDITORUTILS_H
       
   321 
       
   322