screengrabber/inc/SGModel.h
branchRCL_3
changeset 19 b3cee849fa46
parent 18 48060abbbeaf
child 20 fad26422216a
equal deleted inserted replaced
18:48060abbbeaf 19:b3cee849fa46
     1 /*
       
     2 * Copyright (c) 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __SCREENGRABBER_MODEL_H__
       
    21 #define __SCREENGRABBER_MODEL_H__
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 
       
    26 #include <CAknMemorySelectionSettingPage.h>
       
    27 #include <eikenv.h>
       
    28 #include <mdaaudiotoneplayer.h>
       
    29 #include <bamdesca.h>
       
    30 #include "SGStd.h"
       
    31 
       
    32 
       
    33 #define TRANSPARENCY_INDEX 30
       
    34 #define TRANSPARENCY_ALTERNATIVE_INDEX 24
       
    35 
       
    36 
       
    37 // setting keys (do not change uids of existing keys to maintain compatibility to older versions!)
       
    38 const TUid KSGSettingCaptureMode                            = { 0x00 };
       
    39 
       
    40 const TUid KSGSettingSingleCaptureHotkey                    = { 0x01 };
       
    41 const TUid KSGSettingSingleCaptureImageFormat               = { 0x02 };
       
    42 const TUid KSGSettingSingleCaptureMemoryInUse               = { 0x03 };
       
    43 const TUid KSGSettingSingleCaptureMemoryInUseMultiDrive     = { 0x04 };
       
    44 const TUid KSGSettingSingleCaptureFileName                  = { 0x05 };
       
    45 
       
    46 const TUid KSGSettingSequantialCaptureHotkey                = { 0x06 };
       
    47 const TUid KSGSettingSequantialCaptureImageFormat           = { 0x07 };
       
    48 const TUid KSGSettingSequantialCaptureDelay                 = { 0x08 };
       
    49 const TUid KSGSettingSequantialCaptureMemoryInUse           = { 0x09 };
       
    50 const TUid KSGSettingSequantialCaptureMemoryInUseMultiDrive = { 0x0A };
       
    51 const TUid KSGSettingSequantialCaptureFileName              = { 0x0B };
       
    52 
       
    53 const TUid KSGSettingVideoCaptureHotkey                     = { 0x0C };
       
    54 const TUid KSGSettingVideoCaptureVideoFormat                = { 0x0D };
       
    55 const TUid KSGSettingVideoCaptureMemoryInUse                = { 0x0E };
       
    56 const TUid KSGSettingVideoCaptureMemoryInUseMultiDrive      = { 0x0F };
       
    57 const TUid KSGSettingVideoCaptureFileName                   = { 0x10 };
       
    58 
       
    59 
       
    60 class CImageEncoder;
       
    61 class CFbsBitmap;
       
    62 class CFrameImageData;
       
    63 class CAknGlobalConfirmationQuery;
       
    64 class CSavedQuery;
       
    65 class CDictionaryFileStore;
       
    66 class CMGXFileManager;
       
    67 class CMGXFileNotificationHandler;
       
    68 
       
    69 class TGrabSettings
       
    70     {
       
    71 public:
       
    72     TInt                                        iCaptureMode;
       
    73     
       
    74     TInt                                        iSingleCaptureHotkey;
       
    75     TInt                                        iSingleCaptureImageFormat;
       
    76     CAknMemorySelectionSettingPage::TMemory     iSingleCaptureMemoryInUse; 
       
    77     TDriveNumber                                iSingleCaptureMemoryInUseMultiDrive;
       
    78     TFileName                                   iSingleCaptureFileName;
       
    79 
       
    80     TInt                                        iSequantialCaptureHotkey;
       
    81     TInt                                        iSequantialCaptureImageFormat;
       
    82     TInt                                        iSequantialCaptureDelay;
       
    83     CAknMemorySelectionSettingPage::TMemory     iSequantialCaptureMemoryInUse; 
       
    84     TDriveNumber                                iSequantialCaptureMemoryInUseMultiDrive;
       
    85     TFileName                                   iSequantialCaptureFileName;
       
    86 
       
    87     TInt                                        iVideoCaptureHotkey;
       
    88     TInt                                        iVideoCaptureVideoFormat;
       
    89     CAknMemorySelectionSettingPage::TMemory     iVideoCaptureMemoryInUse; 
       
    90     TDriveNumber                                iVideoCaptureMemoryInUseMultiDrive;
       
    91     TFileName                                   iVideoCaptureFileName;
       
    92     };
       
    93 
       
    94 
       
    95 class TVideoFrame
       
    96     {
       
    97 public:
       
    98     TUint       iWidth;
       
    99     TUint       iHeight;
       
   100     TUint       iXPos;
       
   101     TUint       iYPos;
       
   102     TUint       iDelay; // 100 = 1 sec
       
   103     TBool       iEnableTransparency;
       
   104     TBool       iFillsWholeScreen;
       
   105     TFileName   iFileStorePath;
       
   106     };
       
   107 
       
   108 
       
   109 typedef CArrayFixSeg<TVideoFrame> CVideoFrameArray;
       
   110 
       
   111 
       
   112 class CScreenGrabberModel : public CActive, public MMdaAudioToneObserver
       
   113 	{
       
   114 	// active object states
       
   115 	enum TState 
       
   116 		{
       
   117 		EIdle = 0,              // do nothing
       
   118 		EEncodingImage,         // ICL encoding of an image
       
   119 		ESequenceDelay,         // waiting till next capture
       
   120 		ECancelCapturing,       // asking to cancel capturing
       
   121 		ENextVideoFrame,        // get next frame for video
       
   122 		ECancelVideoCapturing,  // asking to cancel video capturing  
       
   123 		EQueryDelay             // waiting till to remove query
       
   124 		};
       
   125 
       
   126 public:
       
   127 	static CScreenGrabberModel* NewL();
       
   128 	~CScreenGrabberModel();
       
   129 	void ActivateModelL();
       
   130 	void DeActivateModelL();
       
   131 
       
   132 private:
       
   133 	CScreenGrabberModel();
       
   134 	void ConstructL();
       
   135 
       
   136 	void RunL();
       
   137 	void DoCancel();
       
   138 
       
   139     void LoadSettingsL();
       
   140     void TakeScreenShotAndSaveL();
       
   141     void CaptureFrameForVideoL();
       
   142     void SaveVideoL(TInt aErr);
       
   143     void CapturingFinishedL(TInt aErr);
       
   144     void CleanTemporaryFilesL();
       
   145     TBool MemoryCardOK();
       
   146     TBool DriveOK(TDriveNumber aNumber);
       
   147     void PlayBeepSound();
       
   148     void LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TInt& aValue);
       
   149     void LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TDes& aValue);
       
   150     void SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TInt& aValue);
       
   151     void SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TDes& aValue);
       
   152     TInt UpdateFileToGallery(const TDesC& aFullPath);
       
   153 
       
   154 public:
       
   155     inline TGrabSettings GrabSettings() { return iGrabSettings; }
       
   156     void SaveSettingsL(TGrabSettings aGrabSettings);
       
   157     void ActivateCaptureKeysL(TBool aChangeKey=EFalse);
       
   158     void CancelCapturing();
       
   159     TBool HandleCaptureCommandsL(const TWsEvent& aEvent);
       
   160     void MatoPrepareComplete(TInt aError);
       
   161     void MatoPlayComplete(TInt aError);
       
   162 
       
   163 private:
       
   164     CMdaAudioToneUtility*   iMdaAudioToneUtility;       // a tone player
       
   165     TGrabSettings           iGrabSettings;              // a simple class to store the settings used in the screen capture
       
   166     CEikonEnv*              iEnv;                       // pointer to our eikon environment
       
   167 	RWindowGroup            iRootWin;                   // application's window group
       
   168 	TInt                    iCapturedKey;               // a handle to the key which is captured
       
   169 	TInt                    iCapturedKeyUnD;            // a handle to the key which is captured, up and down
       
   170 	TInt                    iCapturedKeyHash;           // a handle to the hash key which is captured
       
   171 	TInt                    iCapturedKeyHashUnD;        // a handle to the hash key which is captured, up and down
       
   172 	CImageEncoder*          iImageEncoder;              // engine from ICL to do the image conversion
       
   173     CFbsBitmap*             iPreviouslyCapturedBitmap;  // a previously captured bitmap
       
   174 	TState                  iState;                     // state of this active object
       
   175     TFileName               iSaveFileName;              // target filename of the taken screen shot
       
   176     CFrameImageData*        iFrameImageData;            // frame and image block data needed by ICL
       
   177     CSavedQuery*            iSavedQuery;                // a class to display global queries
       
   178 	RTimer                  iTimer;                     // a timer for async delays
       
   179     TBool 				    iCapturingInProgress;   	// boolean to check if capturing is in progress
       
   180     TBool                   iStopCapturing;             // boolean to specify if to ask capturing
       
   181     TUint                   iNumberOfTakenShots;        // a number of the taken screen shots in the sequantial mode
       
   182     TUint                   iCurrentFrameNumber;        // a number of taken frames in video mode
       
   183     TTime                   iPreviousFrameTaken;        // time when the last frame was taken
       
   184     TSize                   iVideoDimensions;           // dimension of the video
       
   185     TSize                   iPreviousFrameScreenDimension; // dimension of the screen in previous frame
       
   186     CVideoFrameArray*       iVideoFrameArray;           // the frames of the video
       
   187     TBool                   iHashKeyCapturingActivated; // captures hash key is activated
       
   188     TBool                   iHashKeyDown;               // stores state if hash key is currently down
       
   189     TBool                   iGalleryUpdaterSupported;   // specifies if it is possible to update the file to gallery
       
   190     TBool                   iGalleryUpdaterInitialized; // specifies if gallery updater has been initialized or not
       
   191     RLibrary                iGalleryUpdaterDLL;         // specifies pointer to Media Gallery File API DLL
       
   192     CMGXFileManager*        iMGXFileManager;            // Media Gallery FileManager instance
       
   193     };
       
   194 
       
   195 
       
   196 class CSavedQuery : public CActive
       
   197     {
       
   198 public:
       
   199     static CSavedQuery* NewL();
       
   200     ~CSavedQuery();
       
   201     void DisplayL(const TDesC &aText, TBool aDisplayErrorNote=EFalse);
       
   202 
       
   203 private:
       
   204     void DoCancel();
       
   205     void RunL();
       
   206 
       
   207 private: 
       
   208     CSavedQuery();
       
   209     void ConstructL();
       
   210     void DisplayWithGraphicsL(const TDesC &aText, TBool aDisplayErrorNote);
       
   211     void DisplayWithoutGraphicsL(const TDesC &aText);
       
   212 
       
   213 private:
       
   214     CAknGlobalConfirmationQuery*    iGlobalConfirmationQuery;
       
   215     TBool                           iVisible;
       
   216     };
       
   217 
       
   218 
       
   219 // these classes have been copied Media Gallery File API
       
   220 
       
   221 class MGXFileManagerFactory
       
   222     {
       
   223     public:
       
   224         static CMGXFileManager* NewFileManagerL( RFs& aFs );
       
   225         static 
       
   226             CMGXFileNotificationHandler* NewFileNotificationHandlerL();
       
   227     };
       
   228 
       
   229 class CMGXFileManager : public CBase
       
   230     {
       
   231     public:
       
   232         virtual TBool SuccessFileNameL( const TDesC& aFileName,
       
   233                                         TDriveNumber aDrive ) = 0;
       
   234         virtual void UpdateL() = 0;
       
   235         virtual void UpdateL( const TDesC& aFullPath ) = 0;
       
   236         virtual void UpdateL( const TDesC& aOldName,
       
   237                               const TDesC& aNewName ) = 0;
       
   238         virtual void UpdateL( const MDesCArray& aFileNameArray ) = 0;
       
   239     };
       
   240 
       
   241 
       
   242 #endif // __SCREENGRABBER_MODEL_H__