camerauis/cameraapp/generic/common/inc/CamUtility.h
changeset 0 1ddebce53859
child 20 38fb6f7eacd5
equal deleted inserted replaced
-1:000000000000 0:1ddebce53859
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  Utility functions for the Camera Application*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CAMUTILITY_H
       
    21 #define CAMUTILITY_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <CAknMemorySelectionSettingPage.h>
       
    26  
       
    27 #include <bldvariant.hrh>
       
    28 #include "CamPSI.h"	// Product Specific Information
       
    29 #include "CamSettings.hrh"  // for TCamMediaStorage
       
    30 #include "CamSettingsInternal.hrh"
       
    31 #include "camlogging.h"
       
    32 #include "camconfigurationtypes.h"
       
    33 
       
    34 #ifndef CAMERAAPP_PLUGIN_BUILD
       
    35 #include "CamResourceIDs.h"
       
    36 #endif //CAMERAAPP_PLUGIN_BUILD
       
    37 
       
    38 #include <driveinfo.h>
       
    39 
       
    40 // CONSTANTS
       
    41 /* estimated average image sizes */
       
    42 const TInt KCamImageSize3MP = 750000; 
       
    43 const TInt KCamImageSize2MP = 475000;
       
    44 const TInt KCamImageSize1_3MP = 325000;
       
    45 const TInt KCamImageSize1MP = 90000;
       
    46 const TInt KCamImageSizeVGA = 56500;
       
    47 
       
    48 const TInt KCamLocationTrailStopped = 0;
       
    49 const TInt KCamLocationTrailNoValidData = 1;
       
    50 const TInt KCamLocationTrailSearchingDevice = 2;
       
    51 const TInt KCamLocationTrailGPSDataAvail = 3;
       
    52 
       
    53 // A multiple of the image size is kept as a buffer to ensure that a
       
    54 // complex last image can be captured
       
    55 const TInt KCamImageDataBufferMultiplier = 1;
       
    56 
       
    57 // Name of the server that takes foreground when charger is inserted
       
    58 _LIT( KAknCapServer, "akncapserver" );
       
    59 // Location data notification windows use this server.
       
    60 _LIT( KAknNotifyServer, "aknnfysrv"    );
       
    61 
       
    62 // Phonebook server
       
    63 _LIT( KPbkServer, "Pbk2ServerApp" );
       
    64 
       
    65 // DATA TYPES
       
    66 /**
       
    67 * Memory card status, as returned by MemoryCardStatus()
       
    68 */
       
    69 enum TCamMemoryCardStatus
       
    70     {
       
    71     ECamMemoryCardNotInserted,
       
    72     ECamMemoryCardLocked,
       
    73     ECamMemoryCardInserted
       
    74     };
       
    75 
       
    76 #ifndef CAMERAAPP_PLUGIN_BUILD
       
    77 #define ROID(resource_id)               (CamUtility::ResourceOrientationID(resource_id))
       
    78 
       
    79 // Capture tone resources
       
    80 _LIT( KCamCaptureTone1,      "z:\\system\\sounds\\digital\\cameraappCapture1.wav"  );
       
    81 _LIT( KCamCaptureTone2,      "z:\\system\\sounds\\digital\\cameraappCapture2.wav"  );
       
    82 _LIT( KCamCaptureTone3,      "z:\\system\\sounds\\digital\\cameraappCapture3.wav"  );
       
    83 _LIT( KCamCaptureTone4,      "z:\\system\\sounds\\digital\\cameraappCapture4.wav"  );
       
    84 _LIT( KCamBurstCaptureTone1,      "z:\\system\\sounds\\digital\\cameraappCaptureShort1.wav"  );
       
    85 _LIT( KCamBurstCaptureTone2,      "z:\\system\\sounds\\digital\\cameraappCaptureShort2.wav"  );
       
    86 _LIT( KCamBurstCaptureTone3,      "z:\\system\\sounds\\digital\\cameraappCaptureShort3.wav"  );
       
    87 _LIT( KCamBurstCaptureTone4,      "z:\\system\\sounds\\digital\\cameraappCaptureShort4.wav"  );
       
    88 _LIT( KCamVideoStartTone,    "z:\\system\\sounds\\digital\\cameraappStart.wav"     );
       
    89 _LIT( KCamVideoPauseTone,    "z:\\system\\sounds\\digital\\cameraappStop.wav"      );
       
    90 _LIT( KCamVideoStopTone,     "z:\\system\\sounds\\digital\\cameraappStop.wav"      );
       
    91 _LIT( KCamAutoFocusComplete, "z:\\system\\sounds\\digital\\cameraappFocusSucc.wav" );
       
    92 
       
    93 #endif //CAMERAAPP_PLUGIN_BUILD
       
    94 
       
    95 // CLASS DECLARATION
       
    96 
       
    97 /**
       
    98 * Application wide utility functions
       
    99 *
       
   100 *  @since 2.8
       
   101 */
       
   102 
       
   103 class CamUtility
       
   104     {
       
   105     public : // New functions
       
   106 
       
   107         /**
       
   108         * Get free space in selected memory
       
   109         * @since 2.8
       
   110         * @param aMemory memory card or internal memory
       
   111         * @param aCriticalLevel The critical threshold on the specified drive 
       
   112         * @return free space in selected memory (in bytes)
       
   113         */
       
   114         static TInt64 MemoryFree( 
       
   115                     DriveInfo::TDefaultDrives aMemory,
       
   116                     TInt aCriticalLevel = 0 );
       
   117 
       
   118         /**
       
   119         * Returns the memory card status.
       
   120         * @since 2.8
       
   121         * @return the status.
       
   122         */
       
   123         static TCamMemoryCardStatus MemoryCardStatus();
       
   124 
       
   125         /**
       
   126         * Get drive number for memory card.
       
   127         * @since 2.8
       
   128         * @return drive number for memory card
       
   129         */
       
   130         static TInt MemoryCardDrive();
       
   131 
       
   132         /**
       
   133         * Get drive number for phone memory.
       
   134         * @since 2.8
       
   135         * @return drive number for phone memory
       
   136         */
       
   137         static TInt PhoneMemoryDrive();
       
   138 
       
   139 
       
   140         /**
       
   141         * Get drive number for mass storage memory.
       
   142         * @since 3.2
       
   143         * @return drive number for mass storage memory
       
   144         */
       
   145         static TInt MassMemoryDrive();
       
   146     
       
   147         /**
       
   148         * Get drive type for a given drive number.
       
   149         * @since 3.2
       
   150         * @return DriveInfo::TDefaultDrives type for the drive number
       
   151         */
       
   152     	static TInt GetDriveTypeFromDriveNumber( TInt aDrive );
       
   153 
       
   154         /**
       
   155         * Map camera storage location to memory selection dialog storage location
       
   156         * @param aStorage The camera storage location to map 
       
   157         * @since 3.0
       
   158         * @return the memory selection dialog's mapped memory storage location value
       
   159         */
       
   160         static TInt MapToSettingsListMemory( TInt aStorage );
       
   161         
       
   162         /**
       
   163         * Map memory selection dialog storage location to camera storage location 
       
   164         * @param aStorage The settings list memory location to map 
       
   165         * @since 3.0
       
   166         * @return the camera storage location mapped from the memory selection dialog's location value
       
   167         */
       
   168         static TInt MapFromSettingsListMemory( TInt aStorage );
       
   169 
       
   170         /**
       
   171         * Suggest a new unique filename 
       
   172         * @since 2.8
       
   173         * @param aFilePath (in/out) drive and path for file name 
       
   174         *                     (must include trailing '\')
       
   175         *                     On return contains the full path and
       
   176         *                     generated file name with extension
       
   177         * @param aFilename    (in/out) filename (without path or extension)
       
   178         * @param aSuggestedNumeral number initially appended to the name to ensure
       
   179         *                     uniqueness, the actual number used may be higher
       
   180         * @param aExt         file extension (".jpg" or ".3gp")
       
   181         */
       
   182         static void GetUniqueNameL( TDes& aFilePath, 
       
   183                          TDes& aFilename, 
       
   184                          TInt aSuggestedNumeral,
       
   185                          const TDesC& aExt );
       
   186 
       
   187         /**
       
   188         * Generate a image file name based on base name and counter.
       
   189         * @since 2.8
       
   190         * @param aCounter image counter [1...]
       
   191         * @param aBaseName name base 
       
   192         * @param aFilename descriptor to hold the generated file name.
       
   193         *                  Does not include path or extension. Example:
       
   194         *                  "Image(001)"
       
   195         */
       
   196         static void FormatFileName( TUint aCounter,
       
   197                              const TDesC& aBaseName,
       
   198                              TDes& aFilename );
       
   199 
       
   200         /** 
       
   201         * Checks if given filename contains illegal characters or
       
   202         * is otherwise illegal.
       
   203         * @since 2.8
       
   204         * @param aFilename descriptor that holds file name to check.
       
   205         */
       
   206         static TBool CheckFileNameValidityL( const TDesC& aFilename );
       
   207 
       
   208         /** 
       
   209         * Generate a file name based on date and counter.
       
   210         * @since 2.8
       
   211         * @param aFilename descriptor to hold the generated file name.
       
   212         *                  Does not include path or extension. Example:
       
   213         *                  "240305(001)"
       
   214         */
       
   215         static void FormatDateFileNameL( TDes& aFilename );
       
   216 
       
   217         /** 
       
   218         * Format current date into given descriptor in a format
       
   219         * suitable for file names.        
       
   220         * @since 2.8
       
   221         * @param aBuffer the buffer to receive the formatted date.
       
   222         */
       
   223         static void GetCurrentDateForNameBaseL( TDes& aBuffer );
       
   224 
       
   225 
       
   226         /** 
       
   227         * Return the path and filename of the application MBM file
       
   228         * @since 2.8
       
   229         * @param aResName Populated with path and filename of MBM file
       
   230         */
       
   231         static void ResourceFileName( TDes& aResName );
       
   232 
       
   233 		/**
       
   234 		* Return Product Specific Information in the form of a TInt
       
   235 		* @since 2.8
       
   236 		* @param aKey The enumeration key identifying the data required
       
   237 		* @param aValue A reference to TInt that will hold the data
       
   238 		* @return KErrNone if successful, KErrNotSupported if no valid data.
       
   239 		*/		
       
   240 		static TInt GetPsiInt( TCamPsiKey aKey, TInt& aValue );
       
   241 
       
   242 		/**
       
   243 		* Return Product Specific Information in the form of a TInt array
       
   244 		* @since 3.0
       
   245 		* @param aKey The enumeration key identifying the data required
       
   246 		* @param aValue A reference to a TInt array that will hold the data
       
   247 		* @return KErrNone if successful, KErrNotSupported if no valid data.
       
   248 		*/		
       
   249 		static TInt GetPsiIntArrayL( TCamPsiKey aKey, RArray<TInt>& aValue );
       
   250         
       
   251         /**
       
   252 		* Return Product Specific Information in the form of a TInt
       
   253 		* @since 2.8
       
   254 		* @param aKey The enumeration key identifying the data required
       
   255 		* @param aValue A reference to TInt that will hold the data
       
   256 		* @return KErrNone if successful, KErrNotSupported if no valid data.
       
   257 		*/		
       
   258 		static TInt GetCommonPsiInt( TCamPsiKey aKey, TInt& aValue );
       
   259 
       
   260 		/**
       
   261 		* Return Product Specific Information in the form of a TAny*
       
   262 		* @since 2.8
       
   263 		* @param aKey The enumeration key identifying the data required
       
   264 		* @param aValue A pointer to where the data should be copied to.
       
   265 		*        note, data is Mem::Copied, so sufficient space must be
       
   266 		*        available in the buffer passed in to "aValue"
       
   267 		* @return KErrNone if successful, KErrNotSupported if no valid data.
       
   268 		*/
       
   269         static TInt GetPsiAnyL( TCamPsiKey aKey, TAny* aValue );
       
   270 
       
   271 		/**
       
   272 		* Return maximum size for an MMS message
       
   273 		* @since 2.8
       
   274 		* @return The maximum size
       
   275 		*/
       
   276         static TInt MaxMmsSizeInBytesL();
       
   277 
       
   278 		/**
       
   279 		* Compares two strings.
       
   280 		* @since 2.8
       
   281 		* @param aFirst The first string.
       
   282 		* @param aSecond The second string
       
   283         * @return ETrue if the strings are equivalent.
       
   284 		*/
       
   285         static TBool CompareIgnoreCase( const TDesC& aFirst, 
       
   286                                       const TDesC& aSecond );
       
   287 
       
   288 		/**
       
   289 		* Deletes a video clip.
       
   290 		* @since 2.8
       
   291 		* @param aFilename The filename of the video clip
       
   292 		*/
       
   293         static void DeleteVideoL( const TDesC& aFilename );
       
   294 
       
   295 		/**
       
   296 		* Deletes an image.
       
   297 		* @since 2.8
       
   298 		* @param aFilename The filename of the image
       
   299 		*/
       
   300         static void DeleteStillImageL( const TDesC& aFilename );
       
   301 
       
   302 		/**
       
   303 		* Returns the thumbnail path for an image.
       
   304 		* @since 2.8
       
   305 		* @param aImagePath The path of the image
       
   306 		* @param aThumbnailPath The path of the thumbnail image
       
   307 		*/
       
   308         static void GetThumbnailPath( const TDesC& aImagePath, 
       
   309                                             TDes& aThumbnailPath );
       
   310 
       
   311 		/**
       
   312 		* Renames a still image.
       
   313 		* @since 2.8
       
   314 		* @param aOldPath The old path of the image
       
   315 		* @param aNewName The new name of the image
       
   316 		* @param aNewPath Receives the new path of the image.
       
   317 		*/
       
   318         static void RenameStillImageL( const TDesC& aOldPath,
       
   319                                               const TDesC& aNewName,
       
   320                                               TDes& aNewPath );
       
   321 
       
   322 		/**
       
   323 		* Takes a window group ID and a group name.  Checks to see if the
       
   324         * window group referred to by the ID has a name containing the 
       
   325         * window group name string.
       
   326 		* @since 3.0
       
   327 		* @param aWindowId ID of the window group
       
   328 		* @param aWindowGroupName Name to check for
       
   329         * @return ETrue if ID matches name
       
   330 		*/
       
   331         static TBool IdMatchesName( TInt aWindowId, const TDesC& aWindowGroupName );
       
   332             
       
   333 		/**
       
   334 		* Returns the correct resource ID for the current orientation
       
   335 		* @since 3.0
       
   336 		* @param aDefaultResourceID The resource ID for the default orientation
       
   337 		* @return The new resource ID
       
   338 		*/
       
   339 		
       
   340         static TInt ResourceOrientationID( TInt aDefaultResourceID );
       
   341         
       
   342         /**
       
   343         * Map light sensitivity id to ISO rating value.
       
   344         * 
       
   345         */
       
   346         static TInt MapLightSensitivity2IsoValueL( TCamLightSensitivityId aLightSensitivityId, RArray<TInt>& aSupportedValues );
       
   347 
       
   348         /**
       
   349         * Map UI sharpness setting id to Camera sharpness setting value.
       
   350         *
       
   351         */
       
   352         static TInt MapSharpnessId2SharpnessValueL( TCamImageSharpnessId aSharpnessId );
       
   353 
       
   354         /**
       
   355         * Obtain resource id for specific video reoslution 
       
   356         * (for primary camera)
       
   357         * @since 3.0
       
   358         * @param aResolution video reoslution
       
   359         * @return resource id
       
   360         */
       
   361         static TInt MapVideoQualityToViewFinderRes( TCamVideoResolution aResolution );
       
   362                                                    
       
   363 		/**
       
   364 		* Determines if the battery power is good
       
   365 		* @since 3.0
       
   366 		* @return ETrue if the battery is OK, and EFalse if it is 
       
   367 		*         low or almost empty
       
   368 		*/
       
   369 		static TBool IsBatteryPowerOK();
       
   370 
       
   371 		/**
       
   372 		* Determines if the battery power is empty
       
   373 		* @since 3.0
       
   374 		* @return ETrue if the battery is Empty 
       
   375 		*/
       
   376 		static TBool IsBatteryPowerEmpty();
       
   377 		        
       
   378 		/**
       
   379 		* Determines if the battery is being charged
       
   380 		* @since 3.0
       
   381 		* @return ETrue if the battery is charging
       
   382 		*/
       
   383 		static TBool IsBatteryCharging();
       
   384 
       
   385         /**
       
   386         * Determines if LocationTrail is started
       
   387         * @return ETrue if LocationTrail is started
       
   388         */
       
   389         static TBool IsLocationAware();
       
   390 
       
   391         /**
       
   392         * Replaces original bitmap by bitmap with alpha channel.
       
   393         * @since S60 5.0
       
   394         * @param aBmp, bitmap 
       
   395         * @param aMask, mask 
       
   396         * @param aColor, Color used instead of white.  
       
   397         */                                    
       
   398         static void SetAlphaL( CFbsBitmap*& aBmp, CFbsBitmap*& aMask, 
       
   399                                TRgb aColor = KRgbWhite );
       
   400         
       
   401     /**
       
   402     * Determines if USB is active
       
   403     * @return ETrue if USB is active
       
   404     */
       
   405     static TBool IsUsbActive();
       
   406     
       
   407     /**
       
   408     * Determines if the device has a NHD display.
       
   409     * This method is meant to be used with the layouts only
       
   410     * @return ETrue if NHD (640 x 360) display
       
   411     */
       
   412     static TBool IsNhdDevice();
       
   413 
       
   414     /**
       
   415     * Determines device qwerty-mode state.
       
   416     * This method is meant to be used with secondary camera.
       
   417     * @return ETrue if qwerty keyboard is open
       
   418     */
       
   419     static TBool IsQwertyOpen(); 
       
   420 
       
   421     /**
       
   422     * Get layout rectangle for given resolution in given mode.
       
   423     * @param aMode ECamControllerVideo or ECamControllerImage.
       
   424     * @param aResolution Resolution enumeration from 
       
   425     * CCamAppController::GetCurrentVideoResolution or
       
   426     * CCamAppController::GetCurrentImageResolution depending 
       
   427     * on the mode.
       
   428     *                    
       
   429     */
       
   430     static TRect ViewfinderLayout( TCamCameraMode aMode,
       
   431                                    TInt           aResolution );
       
   432 
       
   433   private:
       
   434                                    
       
   435     /**
       
   436     * Helper method for ViewfinderLayout.
       
   437     */
       
   438     static TAknWindowLineLayout ViewfinderLayoutTouch( TCamCameraMode aMode,
       
   439                                                        TInt           aResolution );
       
   440 
       
   441     /**
       
   442     * Helper method for ViewfinderLayout.
       
   443     */
       
   444     static TAknWindowLineLayout ViewfinderLayoutNonTouch( TCamCameraMode aMode,
       
   445                                                           TInt           aResolution );
       
   446 
       
   447 
       
   448     };
       
   449 
       
   450 #endif      // CAMUTILITY_H 
       
   451             
       
   452 // End of File