screengrabber/inc/sgengine.h
changeset 55 2d9cac8919d3
parent 53 819e59dfc032
child 56 392f7045e621
equal deleted inserted replaced
53:819e59dfc032 55:2d9cac8919d3
     1 /*
       
     2 * Copyright (c) 2010 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 #ifndef SGENGINE_H
       
    19 #define SGENGINE_H
       
    20 
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include <f32file.h>
       
    26 #include <w32std.h>
       
    27 #include <mdaaudiotoneplayer.h> 
       
    28 #include <qsymbianevent.h>
       
    29 
       
    30 
       
    31 class CFrameImageData;
       
    32 class CDictionaryFileStore;
       
    33 class CImageEncoder;
       
    34 class EngineWrapper;
       
    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 KSGSettingSingleCaptureMemoryInUseMultiDrive     = { 0x04 };
       
    43 const TUid KSGSettingSingleCaptureFileName                  = { 0x05 };
       
    44 
       
    45 const TUid KSGSettingSequantialCaptureHotkey                = { 0x06 };
       
    46 const TUid KSGSettingSequantialCaptureImageFormat           = { 0x07 };
       
    47 const TUid KSGSettingSequantialCaptureDelay                 = { 0x08 };
       
    48 const TUid KSGSettingSequantialCaptureMemoryInUseMultiDrive = { 0x0A };
       
    49 const TUid KSGSettingSequantialCaptureFileName              = { 0x0B };
       
    50 
       
    51 const TUid KSGSettingVideoCaptureHotkey                     = { 0x0C };
       
    52 const TUid KSGSettingVideoCaptureVideoFormat                = { 0x0D };
       
    53 const TUid KSGSettingVideoCaptureMemoryInUseMultiDrive      = { 0x0F };
       
    54 const TUid KSGSettingVideoCaptureFileName                   = { 0x10 };
       
    55 
       
    56 const TUid KUidScreenGrabber = { 0x101FB751 };
       
    57 
       
    58 
       
    59 #define TRANSPARENCY_INDEX 30
       
    60 #define TRANSPARENCY_ALTERNATIVE_INDEX 24
       
    61 
       
    62 enum TScreenGrabberSettingCaptureModes
       
    63     {
       
    64     ECaptureModeSingleCapture = 0,
       
    65     ECaptureModeSequantialCapture,
       
    66     ECaptureModeVideoCapture
       
    67     };
       
    68     
       
    69 enum TScreenGrabberSettingHotkeys
       
    70     {
       
    71     EHotkeySendKey = 0,
       
    72     EHotkeyPowerKey,
       
    73     EHotkeySideKey,
       
    74     EHotkeyCameraKey1
       
    75     };
       
    76 
       
    77 enum TScreenGrabberSettingImageFormats
       
    78     {
       
    79     EImageFormatPNG = 0,
       
    80     EImageFormatJPGHQ,
       
    81     EImageFormatJPGLQ,
       
    82     EImageFormatBMP,
       
    83     EImageFormatGIF,
       
    84     EImageFormatMBM
       
    85     };
       
    86 
       
    87 enum TScreenGrabberSettingVideoFormats
       
    88     {
       
    89     EVideoFormatAnimatedGIF = 0
       
    90     };
       
    91 
       
    92 enum TScreenGrabberSettingMultiDrive
       
    93 	{
       
    94 	EPhoneMemory = 0,
       
    95 	EMemoryCard
       
    96 	};
       
    97 	
       
    98 
       
    99 class TGrabSettings
       
   100     {
       
   101 public:
       
   102     TInt            iCaptureMode;
       
   103     
       
   104     TInt            iSingleCaptureHotkey;
       
   105     TInt            iSingleCaptureImageFormat;
       
   106     TInt            iSingleCaptureMemoryInUseMultiDrive;
       
   107     TFileName       iSingleCaptureFileName;
       
   108 
       
   109     TInt            iSequantialCaptureHotkey;
       
   110     TInt            iSequantialCaptureImageFormat;
       
   111     TInt            iSequantialCaptureDelay;
       
   112     TInt            iSequantialCaptureMemoryInUseMultiDrive;
       
   113     TFileName       iSequantialCaptureFileName;
       
   114 
       
   115     TInt            iVideoCaptureHotkey;
       
   116     TInt            iVideoCaptureVideoFormat;
       
   117     TInt		    iVideoCaptureMemoryInUseMultiDrive;
       
   118     TFileName       iVideoCaptureFileName;
       
   119     };
       
   120 
       
   121 class TVideoFrame
       
   122     {
       
   123 public:
       
   124     TUint       iWidth;
       
   125     TUint       iHeight;
       
   126     TUint       iXPos;
       
   127     TUint       iYPos;
       
   128     TUint       iDelay; // 1000 = 1 sec
       
   129     TBool       iEnableTransparency;
       
   130     TBool       iFillsWholeScreen;
       
   131     TFileName   iFileStorePath;
       
   132     };
       
   133 
       
   134 
       
   135 typedef CArrayFixSeg<TVideoFrame> CVideoFrameArray;
       
   136 
       
   137 /**
       
   138  *  CEngine
       
   139  * 
       
   140  */
       
   141 class SGEngine : public CActive //, public MMdaAudioToneObserver
       
   142     {
       
   143     
       
   144     // active object states
       
   145 
       
   146     enum TState 
       
   147         {
       
   148         EIdle = 0,              // do nothing
       
   149         EEncodingImage,         // ICL encoding of an image
       
   150         ESequenceDelay,         // waiting till next capture
       
   151         ECancelCapturing,       // asking to cancel capturing
       
   152         ENextVideoFrame,        // get next frame for video
       
   153         ECancelVideoCapturing,  // asking to cancel video capturing  
       
   154         EQueryDelay             // waiting till to remove query
       
   155         };
       
   156     
       
   157 public:
       
   158     // Constructors and destructor
       
   159 
       
   160     /**
       
   161      * Destructor.
       
   162      */
       
   163     ~SGEngine();
       
   164 
       
   165     /**
       
   166      * Two-phased constructor.
       
   167      */
       
   168     static SGEngine* NewL(EngineWrapper *aEngineWrapper);
       
   169 
       
   170     /**
       
   171      * Two-phased constructor.
       
   172      */
       
   173     static SGEngine* NewLC(EngineWrapper *aEngineWrapper);
       
   174     
       
   175     /**
       
   176      * returns current settings
       
   177      */
       
   178     inline TGrabSettings GrabSettings(){ return iGrabSettings; };
       
   179     
       
   180     /**
       
   181      * saves settings to engine
       
   182      */
       
   183     void SaveSettingsL(TGrabSettings aGrabSettings);
       
   184     
       
   185     /**
       
   186      * takes one screen shot
       
   187      */
       
   188     bool TakeScreenShotAndSaveL();
       
   189 
       
   190     TBool DriveOK(TDriveNumber aNumber);
       
   191     
       
   192     TBool IsDriveMMC(TDriveNumber aDrive);
       
   193     
       
   194 #if defined(HB_QT_S60_EVENT_FILTER)
       
   195     TBool HandleCaptureCommandsL(const TWsEvent* aEvent);
       
   196 #else
       
   197     TBool HandleCaptureCommandsL(const QSymbianEvent *event);
       
   198 #endif
       
   199 	
       
   200     
       
   201     void ActivateModelL();
       
   202     void DeActivateModelL();
       
   203     void ActivateCaptureKeysL(TBool aChangeKey=EFalse);
       
   204 	void EnableRcpOfFoc(TBool aState);
       
   205     void LoadSettingsL();
       
   206 	
       
   207 private:
       
   208 
       
   209     void CapturingFinishedL(TInt aErr);
       
   210 
       
   211     void RunL();
       
   212     void DoCancel();
       
   213     void SaveVideoL(TInt aErr);
       
   214     void CleanTemporaryFilesL();
       
   215     void LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TInt& aValue);
       
   216     void LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TDes& aValue); 
       
   217 
       
   218     void SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TInt& aValue);
       
   219     void SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TDes& aValue);
       
   220 
       
   221     void CancelCapturing();
       
   222     void CaptureFrameForVideoL();
       
   223 	
       
   224     
       
   225     /**
       
   226      * Constructor for performing 1st stage construction
       
   227      */
       
   228     SGEngine();
       
   229 
       
   230     /**
       
   231      * EPOC default constructor for performing 2nd stage construction
       
   232      */
       
   233     void ConstructL(EngineWrapper *aEngineWrapper);
       
   234     
       
   235     
       
   236 private:
       
   237 	RFs 		  iFileSession;
       
   238 
       
   239     CActiveScheduler* iActiveScheduler;
       
   240 	CActiveSchedulerWait* iWait;
       
   241  
       
   242     TGrabSettings           iGrabSettings;              // a simple class to store the settings used in the screen capture
       
   243     RWindowGroup            iRootWin;                   // application's window group
       
   244     TInt                    iCapturedKey;               // a handle to the key which is captured
       
   245     TInt                    iCapturedKeyUnD;            // a handle to the key which is captured, up and down
       
   246     TInt                    iCapturedKeyHash;           // a handle to the hash key which is captured
       
   247     TInt                    iCapturedKeyHashUnD;        // a handle to the hash key which is captured, up and down
       
   248     TBool                   iHashKeyCapturingActivated; // captures hash key is activated    
       
   249     CFbsBitmap*             iPreviouslyCapturedBitmap;  // a previously captured bitmap
       
   250     TFileName               iSaveFileName;   
       
   251     CImageEncoder*          iImageEncoder;              // engine from ICL to do the image conversion// target filename of the taken screen shot
       
   252     CFrameImageData*        iFrameImageData;            // frame and image block data needed by ICL
       
   253     TState                  iState;                     // state of this active object
       
   254     TBool                   iHashKeyDown;               // stores state if hash key is currently down
       
   255     TBool                   iCapturingInProgress;       // boolean to check if capturing is in progress
       
   256     TBool                   iStopCapturing;             // boolean to specify if to ask capturing
       
   257     TUint                   iNumberOfTakenShots;        // a number of the taken screen shots in the sequantial mode
       
   258     RTimer                  iTimer;                     // a timer for async delays
       
   259     TUint                   iCurrentFrameNumber;        // a number of taken frames in video mode
       
   260     TTime                   iPreviousFrameTaken;        // time when the last frame was taken
       
   261     TSize                   iVideoDimensions;           // dimension of the video
       
   262     TSize                   iPreviousFrameScreenDimension; // dimension of the screen in previous frame
       
   263     CVideoFrameArray*       iVideoFrameArray;           // the frames of the video
       
   264     EngineWrapper*          iEngineWrapper;             // Eninewrapper that is used for communicating between QT and Symbian
       
   265     };
       
   266 
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 #endif // SGENGINE_H