harvester/composerplugins/imagecomposer/inc/imagecomposerao.h
changeset 0 c53acadfccc6
child 19 b73252188534
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Composer image active object
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32msgqueue.h>
       
    20 
       
    21 #include "mdeobject.h"
       
    22 #include "mdeobjectquery.h"
       
    23 #include "harvesterexifutil.h"
       
    24 #include "mdeharvestersession.h"
       
    25 
       
    26 #ifndef __CIMAGECOMPOSERAO_H__
       
    27 #define __CIMAGECOMPOSERAO_H__
       
    28 
       
    29 _LIT( KImageComposerPanic, "CImageComposerAO" );
       
    30 
       
    31 class CMdERelationQuery;
       
    32 
       
    33 class CImageComposerAO : public CActive, public MMdEQueryObserver
       
    34     {
       
    35     public:
       
    36     
       
    37         enum TRequestType
       
    38             {
       
    39             ERequestReady = 0,
       
    40             ERequestGetObject,
       
    41             ERequestCompose
       
    42             };
       
    43 
       
    44         /**
       
    45         * Construction
       
    46         */
       
    47         static CImageComposerAO* NewL();
       
    48 
       
    49         /**
       
    50         * Destruction
       
    51         */
       
    52         virtual ~CImageComposerAO();
       
    53         
       
    54         /**
       
    55          * Adds new item to composing queue.
       
    56          * @param aItems  Items to add to the queue.
       
    57          * @param aForce  Force composing to items in aItems array
       
    58          */
       
    59         void AddToQueue( const RArray<TItemId>& aItems, TBool aForce );
       
    60 
       
    61         /**
       
    62          * Checks if composing is completed.
       
    63          * @return ETrue, if complete.
       
    64          */
       
    65         TBool IsComposingComplete();
       
    66 
       
    67         /**
       
    68          * Sets mde client session to be used by this composer.
       
    69          * @param aSession  Mde client session.
       
    70          */
       
    71         void SetSession( CMdESession* aSession );
       
    72         
       
    73         /**
       
    74          * Remove MdE client session used by this composer.
       
    75          */
       
    76         void RemoveSession();
       
    77         
       
    78         /**
       
    79          * Writes location data to Exif.
       
    80          * @param aMdeObject  Mde object of the image.
       
    81          * @param aLocationObject  Related mde location object.
       
    82          */
       
    83         void DoWriteExifL( CMdEObject* aMdEObject, CMdEObject* aLocationObject );
       
    84         
       
    85         
       
    86         
       
    87         
       
    88         
       
    89     public: // from MMdEQueryObserver
       
    90 
       
    91 	    /**
       
    92 	     * Callback to handle new results received from a query.
       
    93 	     * From MMdEQueryObserver.
       
    94 	     */
       
    95         virtual void HandleQueryNewResults( CMdEQuery& aQuery, TInt aFirstNewItemIndex,
       
    96             TInt aNewItemCount );
       
    97 
       
    98 	    /**
       
    99 	     * Callback to handle new results received from a query.
       
   100 	     * From MMdEQueryObserver.
       
   101 	     */
       
   102         virtual void HandleQueryNewResults( CMdEQuery& aQuery, TInt aNewObjectItemCount, 
       
   103             TInt aNewRelationItemCount, TInt aNewEventItemCount );
       
   104 
       
   105 	    /**
       
   106 	     * Callback to handle all results of a completed query.
       
   107 	     * From MMdEQueryObserver.
       
   108 	     * @param aQuery  Completed query
       
   109 	     * @param aError  Error code, KErrNone on success.
       
   110 	     */
       
   111         virtual void HandleQueryCompleted( CMdEQuery& aQuery, TInt aError );
       
   112 
       
   113     protected:
       
   114 
       
   115     	/**
       
   116     	 * RunL
       
   117     	 * From CActive.
       
   118     	 */
       
   119         virtual void RunL();
       
   120 
       
   121     	/**
       
   122     	 * DoCancel
       
   123     	 * From CActive.
       
   124     	 */
       
   125         virtual void DoCancel();
       
   126 
       
   127     	/**
       
   128     	 * RunError. Error handler in case RunL() leaves.
       
   129     	 * From CActive.
       
   130     	 * @param aError  Leave code from RunL.
       
   131     	 * @return  Error code. KErrNone if error was handled.
       
   132     	 */
       
   133         virtual TInt RunError( TInt aError );
       
   134 
       
   135     private:
       
   136 
       
   137         /**
       
   138         * Private constructor
       
   139         */    
       
   140         CImageComposerAO();
       
   141         
       
   142         /**
       
   143         * 2nd phase construction
       
   144         */    
       
   145         void ConstructL(); // second-phase constructor
       
   146         
       
   147         /**
       
   148          * Gets an object from MdE DB.
       
   149          * Leave on queue errors.
       
   150          * Leaves with KErrNotFound, if object is not found.
       
   151          * 
       
   152          * @param Returned value of current composing request's object ID. 
       
   153          *        Value is changed when item is read from composing queue.
       
   154          */
       
   155         void GetObjectFromMdeL(TItemId& aMdEObjectId);
       
   156         
       
   157         /**
       
   158          * Writes (=composes) new metadata to a image file.
       
   159          */
       
   160         void ComposeL();
       
   161         
       
   162         /**
       
   163          * SetNextRequest
       
   164          * Sets next state for this active object's RunL.
       
   165          * @param aNextRequest  State to set.
       
   166          */
       
   167         void SetNextRequest( TRequestType aNextRequest );
       
   168         
       
   169         /**
       
   170          * @brief Starts the write of GPS tags to a image file.
       
   171          * 
       
   172          * Starts a query to search for related location data in mde.
       
   173          * If found, HandleQueryCompleted will start adding found info
       
   174          * to image file.
       
   175          * 
       
   176          * @param aObjectId  Object to whichs add GPS tags.
       
   177          * 
       
   178          * @see HandleQueryCompleted
       
   179          * @see StartWritingGPSTagsL
       
   180          * @see DoWriteExifL
       
   181          */
       
   182         void WriteGPSTagsL( TItemId aObjectId );
       
   183         
       
   184         /**
       
   185          * Checks if given mime type is JPEG image.
       
   186          * @param aMimeType  a mime type string.
       
   187          * @return ETrue if mime type is image/jpeg.
       
   188          */
       
   189         static TBool IsJpeg( const TDesC& aMimeType );
       
   190         
       
   191         
       
   192         /**
       
   193          * Starts writing GPS tags to image file.
       
   194          * @param aQuery  Mde query which contains results for related
       
   195          *                location object query.
       
   196          */
       
   197         void StartWritingGPSTagsL( CMdEQuery& aQuery );
       
   198 
       
   199         /**
       
   200          * Converts a TDateTime object's date to a Exif GPS date string.
       
   201          *
       
   202          * @param aTime  TDateTime object to extract the date from.
       
   203          * @param aTgtDes  Target descriptor for the string.
       
   204          */
       
   205         void TimeToGpsDateStringL( TTime aTime, TDes& aTgtDes );
       
   206 
       
   207         /**
       
   208          * Converts a TTime object's time to a Exif GPS time string.
       
   209          *
       
   210          * @param aTime  TDateTime object to extract the time from.
       
   211          * @param aTgtDes  Target descriptor for the string.
       
   212          */
       
   213         void TimeToGpsTimeStringL( TDateTime aTime, TDes8& aTgtDes );
       
   214 
       
   215 
       
   216         /**
       
   217          * CompareItemIds
       
   218          */
       
   219 		static TInt CompareTItemIds( const TItemId& aLeft, const TItemId& aRight )
       
   220 			{
       
   221 			return aLeft - aRight;
       
   222 			}
       
   223 
       
   224     private:
       
   225 
       
   226     	/** Pointer to a mde object */
       
   227         CMdEObject* iMdeObject;
       
   228         
       
   229         /** Pointer to mde session to use */
       
   230         CMdESession* iSession;
       
   231         
       
   232         CMdEHarvesterSession* iMdEHarvesterSession;
       
   233         
       
   234         /** Next state of this active object's RunL() */
       
   235         TRequestType iNextRequest;
       
   236         
       
   237         /** Queue of items to compose */
       
   238         RArray<TItemId> iItemQueue;
       
   239         
       
   240         /** A relation query used to seach for related location objects */
       
   241         CMdERelationQuery* iRelationQuery;
       
   242         
       
   243         /** Mde default namespace. NOT OWN. */
       
   244         CMdENamespaceDef* iDefaultNamespace;
       
   245         
       
   246         /** Image Object Def. NOT OWN. */
       
   247         CMdEObjectDef* iImageObjectDef;
       
   248 
       
   249         /** "Base" Object Def. NOT OWN. */
       
   250         CMdEObjectDef* iObjectDef;
       
   251 
       
   252         /** Location Object Def. NOT OWN. */
       
   253         CMdEObjectDef* iLocationObjectDef;
       
   254         
       
   255         /**
       
   256          * Array used to skip new coming id after explicit change of
       
   257          * MdE object in composer.
       
   258          */
       
   259         RArray<TItemId> iNextItemsSkip;
       
   260         
       
   261         /**
       
   262          * Array of item id's which will be forced to be composed
       
   263          * No timestamp checking will be done for these objects
       
   264          */
       
   265         RArray<TItemId> iForceObjectIds;
       
   266         
       
   267         CHarvesterExifUtil* iExifUtil;
       
   268         
       
   269         RFs iFs;
       
   270     };
       
   271 
       
   272 #endif // __CIMAGECOMPOSERAO_H__