ncdengine/provider/server/inc/ncdfavoritemanagerimpl.h
changeset 4 32704c33136d
child 11 62bf59ab417f
child 19 7ca52d38f8c3
equal deleted inserted replaced
-1:000000000000 4:32704c33136d
       
     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:   Contains CNcdFavoriteManager class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef NCDFAVORITEMANAGER_H
       
    20 #define NCDFAVORITEMANAGER_H
       
    21 
       
    22 #include "catalogscommunicable.h"
       
    23 #include "ncdstoragedataitem.h"
       
    24 
       
    25 class CNcdNodeManager;
       
    26 class CNcdNodeIdentifier;
       
    27 class RWriteStream;
       
    28 class MNcdStorageManager;
       
    29 class CNcdNodeDisclaimer;
       
    30 class CNcdGeneralManager;
       
    31 
       
    32 /**
       
    33  * CNcdFavoriteManager manages the list of favorite nodes.
       
    34  */
       
    35 class CNcdFavoriteManager : public CCatalogsCommunicable 
       
    36 {
       
    37 public:
       
    38     /**
       
    39      * NewL
       
    40      *
       
    41      */
       
    42     static CNcdFavoriteManager* NewL( CNcdGeneralManager& aGeneralManager );
       
    43     
       
    44     
       
    45     /**
       
    46      * NewLC
       
    47      *
       
    48      */
       
    49     static CNcdFavoriteManager* NewLC( CNcdGeneralManager& aGeneralManager );
       
    50 
       
    51     /**
       
    52      * Destructor
       
    53      */
       
    54     virtual ~CNcdFavoriteManager();
       
    55     
       
    56     /**
       
    57      * Returns the number of clients whose favorite identifiers has been loaded to
       
    58      * ram cache.
       
    59      */
       
    60     TInt ClientCount() const;
       
    61     
       
    62     /**
       
    63      * Returns a client uid by the given index.
       
    64      *
       
    65      * @param aClientIndex The index.
       
    66      * @return The client uid.
       
    67      * @leave KErrNotFound If the given index is out of range.
       
    68      */
       
    69     TUid ClientL( TInt aClientIndex ) const; 
       
    70     
       
    71     /**
       
    72      * Returns the client's favorite nodes.
       
    73      *
       
    74      * @param aClientUid The client uid.
       
    75      * @return The favorite nodes.
       
    76      * @leave System wide error code.
       
    77      */
       
    78     const RPointerArray<CNcdNodeIdentifier>& FavoriteNodesL(
       
    79         const TUid& aClientUid );
       
    80         
       
    81     /**
       
    82      * Tells whether the given node is a favorite node.
       
    83      *
       
    84      * @param aNodeIdentifier The node identifier.
       
    85      * @return ETrue if the node is a favorite node, otherwise false.
       
    86      */
       
    87     TBool IsFavorite( const CNcdNodeIdentifier& aNodeIdentifier ) const;
       
    88              
       
    89 
       
    90     /**
       
    91      * Removes client's favorites from database
       
    92      */
       
    93     void RemoveFavoritesL( const TUid& aClientUid );
       
    94     
       
    95 public: // from CCatalogsCommunicable
       
    96 
       
    97     /**
       
    98      * @see CCatalogsCommunicable::ReceiveMessage
       
    99      */
       
   100     virtual void ReceiveMessage(
       
   101         MCatalogsBaseMessage* aMessage, 
       
   102         TInt aFunctionNumber );
       
   103         
       
   104     /**
       
   105      * @see CCatalogsCommunicable::CounterPartLost
       
   106      */
       
   107     virtual void CounterPartLost(
       
   108         const MCatalogsSession& aSession );
       
   109     
       
   110 protected:
       
   111 
       
   112     class CNcdClientFavorites;
       
   113     class CNcdTemporaryFavorites;
       
   114     
       
   115     CNcdFavoriteManager( CNcdGeneralManager& aGeneralManager );
       
   116     
       
   117     void ConstructL();
       
   118     
       
   119     /**
       
   120      * Called from ReceiveMessage if favorite is added.
       
   121      */
       
   122     void AddFavoriteRequestL( MCatalogsBaseMessage& aMessage );
       
   123 
       
   124     /**
       
   125      * Called from ReceiveMessage if favorite is removed.
       
   126      */
       
   127     void RemoveFavoriteRequestL( MCatalogsBaseMessage& aMessage );
       
   128     
       
   129     /**
       
   130      * Called from ReceiveMessage if disclaimer need to be added or removed.
       
   131      */
       
   132     void SetDisclaimerRequestL( MCatalogsBaseMessage& aMessage );
       
   133     
       
   134     /**
       
   135      * Called from ReceiveMessage if disclaimer handle is requested.
       
   136      */
       
   137     void DisclaimerHandleRequestL( MCatalogsBaseMessage& aMessage );
       
   138     
       
   139     /**
       
   140      * Called from ReceiveMessage if proxy object wants to release the server side
       
   141      * object.
       
   142      */    
       
   143     void ReleaseRequest( MCatalogsBaseMessage& aMessage );
       
   144     
       
   145     /**
       
   146      * Called from ReceiveMessage if proxy object wants to internalize its state
       
   147      * from server side.
       
   148      */    
       
   149     void InternalizeRequestL( MCatalogsBaseMessage& aMessage );
       
   150     
       
   151     /**
       
   152      * Adds the given favorite node.
       
   153      *
       
   154      * @param aNodeIdentifier The identifier.
       
   155      */
       
   156     void AddFavoriteL( CNcdNodeIdentifier* aNodeIdentifier );
       
   157     
       
   158     /**
       
   159      * Adds the given favorite node temporarily. The node is removed from
       
   160      * favorites when the given session is closed.
       
   161      *
       
   162      * If the node is favorite node already, nothing is done.
       
   163      *
       
   164      * @param aNodeIdentifier The identifier.
       
   165      * @param aSession The session.
       
   166      */
       
   167     void AddTemporaryFavoriteL(
       
   168         CNcdNodeIdentifier* aNodeIdentifier,
       
   169         MCatalogsSession& aSession );
       
   170     
       
   171     /**
       
   172      * Removes the given favorite node.
       
   173      *
       
   174      * @param aNodeIdentifier The identifier.
       
   175      */
       
   176     void RemoveFavoriteL( CNcdNodeIdentifier* aNodeIdentifier );
       
   177     
       
   178     /**
       
   179      * Removes the temporary favorites of the given session.
       
   180      *
       
   181      * @param aSession The session.
       
   182      */
       
   183     void RemoveTemporaryFavoritesL( MCatalogsSession& aSession );
       
   184     
       
   185     /**
       
   186      * Externalizes the favorite identifiers of the given client to the given stream.
       
   187      *
       
   188      * @param aStream The stream.
       
   189      * @param aClientUid The client uid.
       
   190      */
       
   191     void ExternalizeIdentifiersL( RWriteStream& aStream, const TUid& aClientUid );
       
   192     
       
   193     /**
       
   194      * Finds the favorite node set of the given client.
       
   195      *
       
   196      * @param aClientUid The client uid.
       
   197      * @return Index of the set in iFavorites member variable or KErrNone if the
       
   198      *         client does not exist.
       
   199      */
       
   200     TInt FindClientFavorites( const TUid& aClientUid ) const;
       
   201     
       
   202     /**
       
   203      * Returns the temporary favorites of the given session. The given
       
   204      * object is created if there is no existing CNcdTemporaryFavorites object
       
   205      * for the given session.
       
   206      *
       
   207      * @param aSession The session.
       
   208      * @return The temporary favorites of the session.
       
   209      */
       
   210     CNcdTemporaryFavorites& TemporaryFavoritesL( MCatalogsSession& aSession );
       
   211     
       
   212     /**
       
   213      * Tells whether the given session has temporary favorites.
       
   214      *
       
   215      * @param aSession The session.
       
   216      * @return ETrue if there are temporary favorites, otherwise false.
       
   217      */
       
   218     TBool HasTemporaryFavorites( MCatalogsSession& aSession ) const;
       
   219     
       
   220     /**
       
   221      * Loads the client's favorite identifiers from database. If the database
       
   222      * does not contain any favorite identifiers, creates an empty identifier set
       
   223      * for the client to iFavorites member variable.
       
   224      *
       
   225      * @param aClientUid The client uid.
       
   226      */
       
   227     void DbLoadFavoritesL( const TUid& aClientUid );
       
   228     
       
   229     /**
       
   230      * Saves the given client's favorite identifiers to the database.
       
   231      *
       
   232      * @param aFavorites The favorites to save.
       
   233      */ 
       
   234     void DbSaveFavoritesL( CNcdClientFavorites& aFavorites );    
       
   235     
       
   236     
       
   237 private:
       
   238 
       
   239     /**
       
   240      * CNcdClientFavorites object encapsulates the favorite identifiers of one
       
   241      * client.
       
   242      */
       
   243     class CNcdClientFavorites : public CBase,
       
   244                                 public MNcdStorageDataItem
       
   245         {
       
   246     public:
       
   247         static CNcdClientFavorites* NewLC( const TUid& aClientUid );
       
   248         ~CNcdClientFavorites();
       
   249         
       
   250         TUid ClientUid() const;
       
   251         void AddFavoriteL( CNcdNodeIdentifier* aNodeIdentifier );
       
   252         void RemoveFavorite( const CNcdNodeIdentifier& aNodeIdentifier );
       
   253         void RemoveFavorites();
       
   254         void SetDisclaimerL(
       
   255             const CNcdNodeIdentifier& aNodeIdentifier,
       
   256             const CNcdNodeDisclaimer& aDisclaimer );
       
   257         void RemoveDisclaimer( const CNcdNodeIdentifier& aNodeIdentifier );
       
   258         CNcdNodeDisclaimer* Disclaimer(
       
   259             const CNcdNodeIdentifier& aNodeIdentifier ) const;
       
   260             
       
   261         TBool HasFavorite( const CNcdNodeIdentifier& aNodeIdentifier ) const;
       
   262         
       
   263         const RPointerArray<CNcdNodeIdentifier>& Identifiers() const;
       
   264         void ExternalizeIdentifiersL( RWriteStream& aStream ) const;
       
   265                 
       
   266     public: // from MNcdStorageDataItem
       
   267 
       
   268         /* 
       
   269         * @see MNcdStorageDataItem::ExternalizeL
       
   270         */
       
   271         virtual void ExternalizeL( RWriteStream& aStream );
       
   272 
       
   273         /* 
       
   274         * @see MNcdStorageDataItem::InternalizeL
       
   275         */
       
   276         virtual void InternalizeL( RReadStream& aStream );
       
   277         
       
   278     protected:
       
   279         CNcdClientFavorites( const TUid& aClientUid );
       
   280         void CloseDisclaimers();
       
   281         
       
   282     private: 
       
   283         
       
   284         // Node identifiers.
       
   285         RPointerArray<CNcdNodeIdentifier> iIdentifiers;
       
   286         // Node disclaimers. A disclaimer at index 'i' is disclaimer of the node at
       
   287         // the same index.
       
   288         RPointerArray<CNcdNodeDisclaimer> iDisclaimers;
       
   289         
       
   290         // Client uid.
       
   291         TUid iClientUid;
       
   292         };
       
   293         
       
   294         
       
   295     class CNcdTemporaryFavorites : public CBase 
       
   296         {
       
   297     public: // public functions
       
   298         CNcdTemporaryFavorites( MCatalogsSession& aSession );
       
   299         ~CNcdTemporaryFavorites();
       
   300         
       
   301         
       
   302     public: // member variables
       
   303         MCatalogsSession& iSession;
       
   304         RPointerArray<CNcdNodeIdentifier> iFavoriteIdentifiers;
       
   305         };
       
   306         
       
   307     CNcdGeneralManager& iGeneralManager;
       
   308     
       
   309     // Node manager.        
       
   310     CNcdNodeManager& iNodeManager;
       
   311     
       
   312     // Favorite nodes of all the clients.
       
   313     RPointerArray<CNcdClientFavorites> iFavorites;
       
   314     
       
   315     // Temp favorite mappings.
       
   316     RPointerArray<CNcdTemporaryFavorites> iTempFavorites;
       
   317     
       
   318     // Storage manager.
       
   319     MNcdStorageManager& iStorageManager;       
       
   320 };
       
   321 
       
   322 #endif