engine/collectionframework/datasource/plugins/glxdatasourcemde/inc/glxdatasourcetaskmde.h
changeset 71 27f2d7aec52a
parent 69 45459746d5e8
child 72 0a8e959402e5
equal deleted inserted replaced
69:45459746d5e8 71:27f2d7aec52a
     1 /*
       
     2 * Copyright (c) 2006 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 _C_GLXDATASOURCETASKMDE_H_
       
    21 #define _C_GLXDATASOURCETASKMDE_H_
       
    22 
       
    23 /**
       
    24  * @author Simon Brooks, Alex Birkett
       
    25  */
       
    26 
       
    27 // INCLUDES
       
    28 #include <e32cmn.h>
       
    29 #include <glxdatasource.h>
       
    30 #include <glxdatasourcetask.h>
       
    31 #include <glxfilterproperties.h>
       
    32 #include <mdccommon.h>
       
    33 #include <mdequery.h>
       
    34 #include <mglxtnthumbnailcreatorclient.h>
       
    35 #include <mpxfilter.h>
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 class CGlxDataSourceMde;
       
    39 class CGlxRequest;
       
    40 class CGlxtnThumbnailCreator;
       
    41 class CMdEObjectDef;
       
    42 class CMdEObjectQuery;
       
    43 class CMdESession;
       
    44 
       
    45 
       
    46 /**
       
    47  * Query types supported by subclasses of CGlxDataSourceTaskMde
       
    48  */
       
    49 enum TGlxQueryType
       
    50     {
       
    51     EContainerFirstItemQuery,    // CGlxDataSourceTaskMdeThumbnail+
       
    52     EIdListQuery,                // GlxDataSourceTaskMdeIdList
       
    53     EAttributeQuery,             // CGlxDataSourceTaskMdeAttribute
       
    54     ELocationAttributeQuery,     // CGlxDataSourceTaskMdeAttribute
       
    55     EImageVideoQuery,            // CGlxDataSourceTaskMdeAttribute (but should be general)
       
    56     ECommandRemoveFromContainer, // CGlxDataSourceTaskMdeCommand
       
    57     ECommandAddToContainer,      // CGlxDataSourceTaskMdeCommand
       
    58     ECommandRemoveLocation,      // CGlxDataSourceTaskMdeCommand
       
    59     ECommandAddContainer,        // CGlxDataSourceTaskMdeCommand adds a container
       
    60     ECommandDeleteContainers,    // CGlxDataSourceTaskMdeCommand deletes containers objects
       
    61     ECommandDeleteItems,          // CGlxDataSourceTaskMdeCommand deletes containers objects
       
    62     ECommandRenameContainer,
       
    63     ECommandRename
       
    64     };
       
    65 
       
    66 /**
       
    67  *  CGlxDataSourceTaskMde class 
       
    68  *  Base class for mde tasks: provides task generic functionality.
       
    69  */
       
    70 NONSHARABLE_CLASS(CGlxDataSourceTaskMde) : 	public CGlxDataSourceTask, public MMdEQueryObserver
       
    71 	{
       
    72 public:
       
    73     /**
       
    74      * Constructor.
       
    75      * @param aRequest request to be executed.
       
    76      * @param aObserver observer to be informed when task has completed.
       
    77      * @param aDataSource data source to be used by this object.
       
    78      */
       
    79     CGlxDataSourceTaskMde(CGlxRequest* aRequest, MGlxDataSourceRequestObserver& aObserver, 
       
    80             CGlxDataSource* aDataSource);
       
    81     
       
    82     /**
       
    83      * Destructor.
       
    84      */
       
    85     ~CGlxDataSourceTaskMde();
       
    86     
       
    87     /**
       
    88      * Second stage constructor
       
    89      */
       
    90     virtual void ConstructL();
       
    91 
       
    92 protected: // to be implemented by deriving classes
       
    93     /**
       
    94      * See @ref CGlxDataSourceTask::ExecuteRequestL
       
    95      */ 
       
    96     virtual void ExecuteRequestL() = 0;
       
    97 
       
    98     /**
       
    99      * Must be implemented by deriving classes. To handle query completion
       
   100      * @param aQuery Query that has been completed.
       
   101      */
       
   102     virtual void DoHandleQueryCompletedL(CMdEQuery& aQuery) = 0;
       
   103     
       
   104     /**
       
   105      * Optionally implemented by deriving classes. Used if the deriving class has
       
   106      * to run more than one query. Should start the next query or call HandleRequestComplete() 
       
   107      * if no futher queries are required to be run. If the deriving class only has a single query,
       
   108      * HandleRequestComplete() can be called from DoHandleQueryCompletedL()
       
   109      */
       
   110     virtual void DoNextQueryL() {}
       
   111     
       
   112 public: // From CGlxDataSourceTask
       
   113     /**
       
   114      * See @ref CGlxDataSourceTask::CancelRequest
       
   115      */ 
       
   116     void CancelRequest();
       
   117 
       
   118 private: // from MMdEQueryObserver
       
   119     /**
       
   120      * See @ref MMdEQueryObserver::HandleQueryNewResults
       
   121      */ 
       
   122     void HandleQueryNewResults( CMdEQuery& aQuery,
       
   123                                 TInt aFirstNewItemIndex,
       
   124                                 TInt aNewItemCount );
       
   125     /**
       
   126      * See @ref MMdEQueryObserver::HandleQueryNewResults
       
   127      */
       
   128     void HandleQueryNewResults( CMdEQuery& aQuery,
       
   129                                 TInt aNewObjectItemCount,
       
   130                                 TInt aNewRelationItemCount,
       
   131                                 TInt aNewEventItemCount);
       
   132     /**
       
   133      * See @ref MMdEQueryObserver::HandleQueryCompleted
       
   134      */
       
   135     void HandleQueryCompleted( CMdEQuery& aQuery, TInt aError);
       
   136     
       
   137 protected:
       
   138 
       
   139     /**
       
   140      * Returns a pointer to the CGlxDataSourceMde object passed in on instantiation.
       
   141      * @return a pointer to the CGlxDataSourceMde object passed in on instantiation.
       
   142      */
       
   143     CGlxDataSourceMde* DataSource();
       
   144 
       
   145     void AddMonthFilterL(const TGlxMediaId& aContainerId, TGlxFilterProperties& aFilterProperties);
       
   146     
       
   147     void AddMonthFilterL(CMdEObject* aMonth, TGlxFilterProperties& aFilterProperties);
       
   148         
       
   149 	/**
       
   150 	 * Set query contditions by container id and filter properties.
       
   151      * @param aLogicCondition logic condition to add conditions to
       
   152      * @param aContainerId Id of the container
       
   153      * @param aContainerIsLeft. This should be set to to ETrue if the container is on the left side of the releation, or
       
   154      * EFalse if the container is on the right side of the relation
       
   155      * 
       
   156      */	
       
   157     void SetQueryConditionsL(CMdEQuery& aQuery, const TGlxFilterProperties& aFilterProperties, const TGlxMediaId aContainerId, CMdEObjectDef& aObjectDef);
       
   158 
       
   159     void SetQueryFilterConditionsL(CMdELogicCondition& aLogicCondition, CMdEObjectDef& aObjectDef, const TGlxFilterProperties& aFilterProperties);
       
   160 
       
   161     void SetSortOrderL(CMdEQuery& aQuery, CMdEObjectDef& aObjectDef, const TGlxFilterProperties& aFilterProperties);
       
   162 
       
   163     /**
       
   164      * Returns the maximum number of items that a query should find.
       
   165      * @return Maximum number of results
       
   166      */
       
   167     TInt MaxQueryResultsCount(const TGlxFilterProperties& aFilterProperties) const;
       
   168     
       
   169     /**
       
   170      * Removes and destroys the oldest query in iQueries.
       
   171      */
       
   172     void RemoveQuery();
       
   173 
       
   174     void DoQueryL(CMdEObjectDef& aObjectDef, TBool aIsContent, TGlxQueryType aQueryType, TQueryResultMode aResultMode, const TGlxMediaId& aContainerId);
       
   175 
       
   176     /**
       
   177      * Adds queries for images and or videos to the query queue. The queries will return objects
       
   178      * of type image or video that have ids specified by aObjectIds. 
       
   179      * @param aObjectIds A list of the ids of the required objects.
       
   180      * @param aFilterProperties TGlxFilterProperties.iItemType is used to determine if only 
       
   181      * image or video queries are required if iItemType is not set to EGlxFilterImage or 
       
   182      * EGlxFitlerVideo a query for images will be queued first followed by a query for videos.
       
   183      */
       
   184     void QueueImageVideoObjectQueriesL(const RArray<TItemId>& aObjectIds, const TGlxFilterProperties& aFilterProperties);
       
   185     
       
   186     /**
       
   187      * Adds a query for tag objects that have ids specified by aObjectIds
       
   188      * to the query queue.
       
   189      * @param aObjectIds A list of the ids of the required objects.
       
   190      */
       
   191     void QueueTagObjectQueryL(const RArray<TItemId>& aObjectIds);
       
   192 
       
   193     /**
       
   194      * Adds a query for album objects that have ids specified by aObjectIds
       
   195      * to the query queue.
       
   196      * @param aObjectIds A list of the ids of the required objects.
       
   197      */
       
   198     void QueueAlbumObjectQueryL(const RArray<TItemId>& aObjectIds);
       
   199     
       
   200     /**
       
   201      * Adds a query for "month" objects that have ids specified by aObjectIds
       
   202      * to the query queue.
       
   203      * @param aObjectIds A list of the ids of the required objects.
       
   204      */
       
   205     void QueueMonthObjectQueryL(const RArray<TItemId>& aObjectIds);
       
   206     
       
   207     /**
       
   208      * Adds a query for objects of type specified by aObjectDef
       
   209      * that have ids specified by aObjectIds to the query queue.
       
   210      * @param aObjectDef type of objects required.
       
   211      * @param aObjectIds A list of the ids of the required objects.
       
   212      * @param aQueryType The query type.
       
   213      */
       
   214     void QueueObjectQueryL(CMdEObjectDef& aObjectDef, 
       
   215             const RArray<TItemId>& aObjectIds, const TGlxQueryType& aQueryType);
       
   216 
       
   217     /**
       
   218      * Appends a query to the query queue. (the ownership of the query is transferred)
       
   219      * @param aQuery query to append to the query queue ownership is transferred to 
       
   220      * the query queue. It is expected that aQuery is not on the cleanupstack before the
       
   221      * call to AppendQueryL is made
       
   222      * @param aQueryType the query type.
       
   223      */
       
   224     void AppendQueryL(CMdEQuery* aQuery, const TGlxQueryType& aQueryType);
       
   225     
       
   226     /**
       
   227      * Executes the query at ordinal 0 in the
       
   228      * query list implementation can be overidden by
       
   229      * deriving classes.
       
   230      */
       
   231     virtual void ExecuteQueryL();
       
   232     
       
   233 private:
       
   234     /* 
       
   235     * Helper function TRAPed and called by HandleQueryCompleted()
       
   236     * @param aQuery the query that has been completed
       
   237     */
       
   238     void HandleQueryCompletedL(CMdEQuery& aQuery);
       
   239 
       
   240     /**
       
   241      * Removes the observer from any existing queries, cancels and destroys them
       
   242      */
       
   243     void DestroyQueries();
       
   244     
       
   245 private:
       
   246     /**
       
   247      * Default namespace def (not owned)
       
   248      */
       
   249     CMdENamespaceDef* iDefaultNameSpaceDef;
       
   250 
       
   251 protected:
       
   252     /**
       
   253      * Outstanding queries array (owned)
       
   254      */
       
   255     RPointerArray <CMdEQuery> iQueries;
       
   256     
       
   257     /**
       
   258      * Query types array (owned)
       
   259      */
       
   260     RArray <TGlxQueryType> iQueryTypes;
       
   261 
       
   262     /**
       
   263      * Filter properties
       
   264      */
       
   265     TGlxFilterProperties iFilterProperties;  
       
   266     };
       
   267 
       
   268 #endif //_C_GLXDATASOURCETASKMDE_H_