photosgallery/collectionframework/datasource/plugins/glxdatasourcemde2.5/inc/glxdatasourcemds.h
changeset 0 4e91876724a2
child 14 ce1c7ad1f18b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/photosgallery/collectionframework/datasource/plugins/glxdatasourcemde2.5/inc/glxdatasourcemds.h	Thu Dec 17 08:45:44 2009 +0200
@@ -0,0 +1,437 @@
+/*
+* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: The data source mds class   
+*
+*/
+
+
+
+
+/**
+ * @author Simon Brooks, Alex Birkett
+ */
+
+/**
+ * @internal reviewed 10/07/2007 by M Byrne
+ */
+
+#ifndef _C_GLXDATASOURCEMDS_H_
+#define _C_GLXDATASOURCEMDS_H_
+
+// INCLUDES
+#include <e32base.h>
+#include <w32std.h>
+#include <e32property.h> 
+
+#include <e32cmn.h>
+#include <f32file.h>
+
+#include <mdesession.h>
+
+#include <harvesterclient.h>
+#include <harvestereventenum.h>
+
+#include <mglxtnstorage.h>
+#include <mpxcollectionmessagedefs.h>
+
+#ifdef USE_S60_TNM
+#include <thumbnailmanager.h>
+#include <thumbnailmanagerobserver.h>
+#include <thumbnaildata.h>
+#include <thumbnailobjectsource.h>
+
+#include "mthumbnailfetchrequestobserver.h"
+#endif
+#include "glxdatasource.h"
+
+// FORWARD DECLARATIONS
+class CGlxRequest;
+#ifndef USE_S60_TNM
+class CGlxtnThumbnailCreator;
+class CGlxtnThumbnailDatabase;
+#endif
+class CGlxDataSourceMde ;
+
+// Use this till MDS bug is fixed. Then KMdSPSShutdown is to be used.   
+const TUid KHarvesterPSShutdown = { 0x200009F5 } ;
+//const TUid KMdSPSShutdown   = { 0x20022E94 };
+const TInt KMdSShutdown     = 0x00000002; // values 1 = shutdown, 0 = restart, normal state
+
+static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
+static _LIT_SECURITY_POLICY_C1(KPowerMgmtPolicy,ECapabilityPowerMgmt);
+
+/**
+ * PSCW Listener Observer interface for signaling that MDS has Shutdown/restarted
+ */
+class MGlxMDSShutdownObserver
+    {
+public:
+
+    virtual void ShutdownNotification(TInt aShutdownState) = 0;
+    };
+
+/**
+ *  Active object for observing P&S keys
+ *
+ *  @since S60 v5.0
+ */
+class CGlxMDSShutdownObserver: public CActive
+    {
+public:
+
+    /**
+     * Two-phased constructor.
+     *
+     * @since S60 v5.0
+     * @return Instance of CGlxMDSShutdownObserver.
+     */
+    static CGlxMDSShutdownObserver* NewL( MGlxMDSShutdownObserver& aObserver, const TUid& aKeyCategory,
+                                      const TInt aPropertyKey, TBool aDefineKey);
+
+    /**
+     * Destructor
+     *
+     * @since S60 v5.0
+     */
+    virtual ~CGlxMDSShutdownObserver();
+    
+protected:
+
+    /**
+     * Handles an active object's request completion event.
+     *
+     * @since S60 v5.0
+     */
+    void RunL();
+
+    /**
+     * Implements cancellation of an outstanding request.
+     *
+     * @since S60 v5.0
+     */
+    void DoCancel();
+
+private:
+
+    /**
+     * C++ default constructor
+     *
+     * @since S60 v5.0
+     * @return Instance of CGlxMDSShutdownObserver.
+     */
+    CGlxMDSShutdownObserver( MGlxMDSShutdownObserver& aObserver, const TUid& aKeyCategory,
+                         const TInt iPropertyKey, TBool aDefineKey);
+
+    /**
+     * Symbian 2nd phase constructor can leave.
+     *
+     * @since S60 v5.0
+     */
+    void ConstructL();
+
+private:
+    
+    // not own
+    MGlxMDSShutdownObserver& iObserver;
+    
+    const TUid& iKeyCategory;
+    RProperty iProperty;
+    TInt iPropertyKey;
+    
+    TBool iDefineKey;
+};
+
+
+
+// CONSTANTS
+
+// CLASS DECLARATION
+
+/**
+ *  CGlxDataSourceMde class 
+ *
+ *  Data Source Mde is a Meta Data Data Source.
+ *  @lib GlxDataSourceMde.lib
+ *  @ingroup collection_component_design
+ */
+class CGlxDataSourceMde : public CGlxDataSource,
+                          public MMdESessionObserver,
+                          public MGlxMDSShutdownObserver,
+                          public MMdEObjectObserver,
+                          public MMdEObjectPresentObserver,
+                          public MMdERelationObserver,
+                          public MMdERelationPresentObserver,
+                          public MHarvesterEventObserver
+#ifdef USE_S60_TNM
+						, public MThumbnailManagerObserver
+#else
+                        , public MGlxtnThumbnailStorageObserver
+#endif
+    {
+public:
+    static CGlxDataSourceMde* NewL();
+
+private:
+    ~CGlxDataSourceMde();
+    
+    CGlxDataSourceMde();
+    
+    void ConstructL();
+
+public:
+    // from CGlxDataSource
+    CGlxDataSourceTask* CreateTaskL(CGlxRequest* aRequest,
+            MGlxDataSourceRequestObserver& aObserver);
+public:
+    // from MHarvesterEventObserver
+    void HarvestingUpdated( 
+                HarvesterEventObserverType aHEObserverType, 
+                HarvesterEventState aHarvesterEventState,
+                TInt aItemsLeft );
+
+#ifdef USE_S60_TNM
+public:
+	void FetchThumbnailL(CGlxRequest* aRequest, 
+	        MThumbnailFetchRequestObserver& aObserver);
+	TInt CancelFetchThumbnail();
+#else
+private: 
+    // from MGlxtnThumbnailStorageObserver
+    /**
+    * Notify that a given thumbnail is available in storage.
+    * @param aId Media item ID.
+    * @param aSize Requested thumbnail size.
+    */
+    void ThumbnailAvailable(const TGlxMediaId& aId, const TSize& aSize);
+    /**
+    * Notify that a given thumbnail is available in storage.
+    * @param aId Media item ID.
+    * @param aSize Thumbnail size.
+    */
+    void BackgroundThumbnailError(const TGlxMediaId& aId, TInt aError);
+#endif
+
+private: 
+    /**
+    *  from MMdESessionObserver
+    */
+    void HandleSessionOpened(CMdESession& aSession, TInt aError);
+    
+    void HandleSessionError(CMdESession& aSession, TInt aError);
+
+private: // MMdEObjectObserver
+	/**
+	 * See @ref MMdEObjectObserver::HandleObjectNotification
+	 */
+	void HandleObjectNotification(CMdESession& aSession, 
+						TObserverNotificationType aType,
+						const RArray<TItemId>& aObjectIdArray);
+
+private: // MMdEObjectPresentObserver
+	/**
+	 * See @ref MMdEObjectPresentObserver::HandleObjectPresentNotification
+	 */
+	void HandleObjectPresentNotification(CMdESession& aSession, 
+			TBool aPresent, const RArray<TItemId>& aObjectIdArray);
+
+private: // MMdERelationObserver
+	/**
+	 * See @ref MMdERelationObserver::HandleRelationNotification
+	 */
+	void HandleRelationNotification(CMdESession& aSession, 
+			TObserverNotificationType aType,
+			const RArray<TItemId>& aRelationIdArray);
+	    
+private: //MMdERelationPresentObserver
+	/**
+	 * See @ref MMdERelationPresentObserver::HandleRelationPresentNotification
+	 */
+	void HandleRelationPresentNotification(CMdESession& aSession,
+			TBool aPresent, const RArray<TItemId>& aRelationIdArray);
+
+#ifdef USE_S60_TNM
+    // from MThumbnailManagerObserver
+    void ThumbnailPreviewReady( MThumbnailData& aThumbnail,
+        TThumbnailRequestId aId );
+    
+    void ThumbnailReady( TInt aError, MThumbnailData& aThumbnail,
+        TThumbnailRequestId aId );
+#endif
+		
+private:
+    void BackgroundThumbnailMessageL(const TGlxMediaId& aId, const TSize& aSize, 
+            TInt aError);
+
+    void DoSessionInitL();
+
+    void AddMdEObserversL();
+
+    void ProcessUpdateArray(const RArray<TItemId>& aArray, TMPXChangeEventType aType,
+            TBool aIsObject);
+
+    void ProcessItemUpdateL();
+
+    static TInt ProcessItemUpdate(TAny* aPtr);
+    void CreateSessionL();
+
+    static TInt CreateSession(TAny* aPtr);
+
+    void PrepareMonthsL();
+    void TaskCompletedL();
+
+    void TaskStartedL();
+    
+#ifdef USE_S60_TNM
+    /*
+     * This function doesnt add up any value, added to reduce compiler warnings
+     */
+    void ThumbnailReadyL( TInt aError, MThumbnailData& aThumbnail,
+        TThumbnailRequestId aId, TBool aQuality );
+#endif
+    
+public:
+
+    void CreateSession();
+    
+    inline CMdESession& Session() const;
+    
+#ifndef USE_S60_TNM
+    inline CGlxtnThumbnailCreator& ThumbnailCreator() const;
+
+    inline CGlxtnThumbnailDatabase& ThumbnailDatabase() const;
+#endif
+
+    inline RFs& FileServerSession();
+
+    inline const TGlxMediaId& CameraAlbumId() const;
+
+    inline const TGlxMediaId& FavoritesId() const;
+
+    inline CMdENamespaceDef* NamespaceDef() const;
+
+    inline CMdEObjectDef& ObjectDef() const;
+
+    inline CMdEObjectDef& ImageDef() const;
+
+    inline CMdEObjectDef& VideoDef() const;
+    
+    inline CMdEObjectDef& AlbumDef() const;
+    
+    inline CMdEObjectDef& MediaDef() const;
+    inline CMdEObjectDef& TagDef() const;
+    
+    /**
+     * Return object definition used to describe months.
+     * @return object definition used to describe months.
+     */
+    inline CMdEObjectDef& MonthDef() const;
+    
+    inline CMdERelationDef& ContainsDef() const;
+    
+    inline CMdERelationDef& ContainsLocationDef() const;
+
+    /**
+     * Get the location definition.
+     * @return location definition.
+     */
+    inline CMdEObjectDef& LocationDef() const;
+    
+    TContainerType ContainerType(CMdEObject* aObject);
+    
+    TContainerType ContainerType(CMdEObjectDef* aObjectDef);
+    
+    TItemType ItemType(CMdEObject* aObject);
+ 
+    const TGlxMediaId GetMonthIdL(const TTime& aMonth);
+
+    TBool SameMonth(const TTime& aOldDate, const TTime& aNewDate);
+     
+	TBool ContainerIsLeft(CMdEObjectDef& aObjectDef);    
+	
+	// from MGlxMDSShutdownObserver
+    void ShutdownNotification(TInt aShutdownState);
+
+private:
+#ifdef USE_S60_TNM
+	MThumbnailFetchRequestObserver* iTnFetchObserver; 
+    CThumbnailManager* iTnEngine;
+    CFbsBitmap* iTnThumbnail;
+    CFbsBitmap* iThumbnail;
+    TThumbnailRequestId iTnThumbnailCbId;
+    TBool iTnRequestInProgress;
+    TInt iTnHandle;
+    TGlxMediaId iMediaId;
+    
+#else
+    CGlxtnThumbnailCreator*   iThumbnailCreator;
+    CGlxtnThumbnailDatabase*  iThumbnailDatabase;
+#endif
+
+    CMdESession*              iSession;
+    RFs iFs;
+    TBool                     iSessionOpen;
+    TGlxMediaId               iCameraAlbumId;
+    TGlxMediaId               iFavoritesId;
+    
+    CMdENamespaceDef* iNameSpaceDef;
+    CMdEObjectDef* iObjectDef;
+    CMdEObjectDef* iImageDef;
+    CMdEObjectDef* iVideoDef;
+    CMdEObjectDef* iAlbumDef;
+    CMdEObjectDef* iMediaDef;
+    CMdEObjectDef* iTagDef;
+    CMdEObjectDef* iMonthDef;
+    /**
+     * Location object definition.
+     */
+    CMdEObjectDef* iLocationDef;
+    CMdERelationDef* iContainsDef;
+    CMdERelationDef* iContainsLocationDef;
+    
+    RArray<TTime> iMonthArray;
+    RArray<TGlxMediaId> iMonthList;
+    RArray<TItemId> iAddedItems;
+    
+    TTime iFirstMonth;
+    TTime iLastMonth;
+    
+    CAsyncCallBack* iUpdateCallback;
+    
+    CAsyncCallBack* iCreateSessionCallback;
+    
+    struct TUpdateData
+        {
+        TItemId iId;
+        TMPXChangeEventType iType;
+        TBool iIsObject;
+        };
+    
+    RArray<TUpdateData> iUpdateData;
+	TBool iPauseUpdate;
+    TInt iDeletedCount;
+    
+    RHarvesterClient iHC;
+    TBool iHarvestingOngoing;
+
+    CGlxMDSShutdownObserver* iMDSShutdownObserver;
+
+#ifdef _DEBUG
+    TTime iStartTime;
+    TTime iStopTime;
+#endif    
+    };
+
+#include "glxdatasourcemds.inl"
+
+#endif //_C_GLXDATASOURCEMDE_H_