ncdengine/provider/server/src/ncdnodeseenfolderimpl.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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 #include "ncdnodeseenfolderimpl.h"
       
    20 #include "catalogsdebug.h"
       
    21 #include "ncdnodefunctionids.h"
       
    22 #include "catalogsbasemessage.h"
       
    23 #include "ncdnodemanager.h"
       
    24 #include "ncdnodefolder.h"
       
    25 #include "ncdnodeseenimpl.h"
       
    26 #include "catalogsutils.h"
       
    27 #include "ncdnodeidentifier.h"
       
    28 
       
    29 CNcdNodeSeenFolder* CNcdNodeSeenFolder::NewL( CNcdNodeFolder& aParent ) 
       
    30     {
       
    31     DLTRACEIN((""));
       
    32     CNcdNodeSeenFolder* self = NewLC( aParent );
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36 
       
    37 
       
    38 CNcdNodeSeenFolder* CNcdNodeSeenFolder::NewLC( CNcdNodeFolder& aParent ) 
       
    39     {
       
    40     DLTRACEIN((""));
       
    41     CNcdNodeSeenFolder* self = new( ELeave ) CNcdNodeSeenFolder( aParent );
       
    42     CleanupClosePushL( *self );
       
    43     self->ConstructL();
       
    44     return self;
       
    45     }
       
    46     
       
    47 
       
    48 CNcdNodeSeenFolder::CNcdNodeSeenFolder( CNcdNodeFolder& aParent ) :
       
    49     iOwnerNode( aParent ) 
       
    50     {
       
    51     }
       
    52     
       
    53 
       
    54 void CNcdNodeSeenFolder::ConstructL() 
       
    55     {
       
    56     }
       
    57     
       
    58 
       
    59 CNcdNodeSeenFolder::~CNcdNodeSeenFolder() 
       
    60     {
       
    61     DLTRACEIN((""));
       
    62     }
       
    63 
       
    64 
       
    65 void CNcdNodeSeenFolder::ReceiveMessage(
       
    66     MCatalogsBaseMessage* aMessage,
       
    67     TInt aFunctionNumber )
       
    68     {
       
    69     DLTRACEIN((""));
       
    70     
       
    71     DASSERT( aMessage );
       
    72         
       
    73     TInt trapError( KErrNone );
       
    74     
       
    75     switch( aFunctionNumber )
       
    76         {
       
    77         case NcdNodeFunctionIds::ENcdNodeSeenFolderSetContentsSeen:
       
    78             TRAP( trapError, SetContentsSeenRequestL( *aMessage ) );
       
    79             break;
       
    80             
       
    81         case NcdNodeFunctionIds::ENcdNodeSeenFolderNewCount:
       
    82             TRAP( trapError, NewCountRequestL( *aMessage ) );
       
    83             break;
       
    84             
       
    85         case NcdNodeFunctionIds::ENcdNodeSeenFolderNewNodes:
       
    86             TRAP( trapError, NewNodesRequestL( *aMessage ) );
       
    87             break;
       
    88 
       
    89         case NcdNodeFunctionIds::ENcdRelease:
       
    90             ReleaseRequest( *aMessage );
       
    91             break;
       
    92             
       
    93         default:
       
    94             DLERROR(("Unidentified function request"));
       
    95             DASSERT( EFalse );
       
    96             break;
       
    97         }
       
    98        
       
    99     if ( trapError != KErrNone )
       
   100         {
       
   101         // Because something went wrong the complete has not been
       
   102         // yet called for the message.
       
   103         // So, inform the client about the error.
       
   104         aMessage->CompleteAndRelease( trapError );
       
   105         }
       
   106     }
       
   107     
       
   108 
       
   109 void CNcdNodeSeenFolder::CounterPartLost( const MCatalogsSession& /*aSession*/ )
       
   110     {
       
   111     DLTRACEIN((""));
       
   112     }    
       
   113     
       
   114     
       
   115 void CNcdNodeSeenFolder::SetContentsSeenRequestL(
       
   116     MCatalogsBaseMessage& aMessage ) const
       
   117     {
       
   118     DLTRACEIN((""));
       
   119     SetContentsSeenL();        
       
   120     aMessage.CompleteAndRelease( KErrNone );
       
   121     }
       
   122     
       
   123     
       
   124 void CNcdNodeSeenFolder::NewCountRequestL(
       
   125     MCatalogsBaseMessage& aMessage ) const
       
   126     {
       
   127     DLTRACEIN((""));
       
   128     
       
   129     // Read the level number.
       
   130     RCatalogsMessageReader reader;
       
   131     reader.OpenLC( aMessage );
       
   132     
       
   133     TInt level = reader().ReadInt32L();
       
   134     DASSERT( level > 0 );
       
   135     
       
   136     CleanupStack::PopAndDestroy( &reader );
       
   137     
       
   138     TInt count = NewChildCountL( level - 1 );
       
   139     
       
   140     aMessage.CompleteAndReleaseL( count, KErrNone );
       
   141     }
       
   142     
       
   143     
       
   144 void CNcdNodeSeenFolder::NewNodesRequestL(
       
   145     MCatalogsBaseMessage& aMessage ) const
       
   146     {
       
   147     DLTRACEIN((""));
       
   148     
       
   149     // Read the level number
       
   150     RCatalogsMessageReader reader;
       
   151     reader.OpenLC( aMessage );
       
   152     
       
   153     TInt level = reader().ReadInt32L();
       
   154     DASSERT( level > 0 );
       
   155     
       
   156     CleanupStack::PopAndDestroy( &reader );
       
   157     
       
   158     RPointerArray<CNcdNodeIdentifier> newNodes;
       
   159     CleanupResetAndDestroyPushL( newNodes );
       
   160     
       
   161     NewChildrenL( level - 1, newNodes );
       
   162     TInt newCount = newNodes.Count();
       
   163     
       
   164     DLINFO(("found %d new nodes", newCount ));
       
   165     
       
   166     // Write the node identifier to output buffer.
       
   167     RCatalogsBufferWriter writer;
       
   168     writer.OpenLC();
       
   169     writer().WriteInt32L( newCount );
       
   170     
       
   171     for ( TInt i = 0; i < newCount; i++ ) 
       
   172         {
       
   173         newNodes[ i ]->ExternalizeL( writer() );
       
   174         }
       
   175         
       
   176     aMessage.CompleteAndReleaseL( writer.PtrL(), KErrNone );
       
   177     
       
   178     CleanupStack::PopAndDestroy( &writer );
       
   179     CleanupStack::PopAndDestroy( &newNodes );
       
   180     }
       
   181     
       
   182 
       
   183 void CNcdNodeSeenFolder::ReleaseRequest( MCatalogsBaseMessage& aMessage ) const
       
   184     {
       
   185     DLTRACEIN((""));
       
   186 
       
   187     // Decrease the reference count for this object.
       
   188     // When the reference count reaches zero, this object will be destroyed
       
   189     // and removed from the session.
       
   190     MCatalogsSession& requestSession( aMessage.Session() );
       
   191     TInt handle( aMessage.Handle() );
       
   192     aMessage.CompleteAndRelease( KErrNone );
       
   193     requestSession.RemoveObject( handle );
       
   194                 
       
   195     DLTRACEOUT((""));
       
   196     }    
       
   197 
       
   198 
       
   199 TInt CNcdNodeSeenFolder::NewChildCountL(
       
   200     TInt aRecursionLevel ) const 
       
   201     {
       
   202     DLTRACEIN((""));
       
   203     DASSERT( aRecursionLevel >= 0 );
       
   204     
       
   205     CNcdNodeManager& nodeManager = iOwnerNode.NodeManager();
       
   206     
       
   207     TInt newCount( 0 );
       
   208 
       
   209     for ( TInt i = 0; i < iOwnerNode.ChildCount(); i++ ) 
       
   210         {
       
   211         const CNcdNodeIdentifier& childIdentifier =
       
   212             iOwnerNode.ChildL( i );
       
   213         CNcdNode* child = nodeManager.NodePtrL( childIdentifier );
       
   214         if ( child ) 
       
   215             {
       
   216             // Increase the count if the node is not seen, but skip transparent nodes since
       
   217             // they are not visible in proxy side anyway.
       
   218             if ( !child->NodeSeen().IsSeenL() &&
       
   219                  child->ClassId() != NcdNodeClassIds::ENcdTransparentFolderNodeClassId ) 
       
   220                 {
       
   221                 newCount++;
       
   222                 }
       
   223             else if ( child->ClassId() == NcdNodeClassIds::ENcdTransparentFolderNodeClassId
       
   224                       && aRecursionLevel == 0 ) 
       
   225                 {
       
   226                 // Transparent child, add the children of the folder to child count.
       
   227                 CNcdNodeFolder* transparent = static_cast<CNcdNodeFolder*>( child );
       
   228                 newCount += transparent->NodeSeenFolder().NewChildCountL( aRecursionLevel );
       
   229                 }
       
   230                                   
       
   231             if ( aRecursionLevel > 0 ) 
       
   232                 {
       
   233                 // If recursion level is greater than 0 and the
       
   234                 // the node is a folder, add the child count of
       
   235                 // the folder too.
       
   236                 if ( CNcdNodeFactory::NodeTypeL( *child ) == CNcdNodeFactory::ENcdNodeFolder )
       
   237                     {
       
   238                     CNcdNodeFolder* folder = static_cast<CNcdNodeFolder*>( child );
       
   239                     
       
   240                     // If the folder is transparent folder, the recursion level must not
       
   241                     // be decreased.
       
   242                     TInt nextRecursionLevel( aRecursionLevel - 1 );
       
   243                     if ( folder->ClassId() == NcdNodeClassIds::ENcdTransparentFolderNodeClassId ) 
       
   244                         {
       
   245                         nextRecursionLevel++;
       
   246                         }
       
   247                         
       
   248                     newCount += folder->NodeSeenFolder().NewChildCountL(
       
   249                         nextRecursionLevel );
       
   250                     }
       
   251                 }
       
   252             }
       
   253         }
       
   254         
       
   255     return newCount;
       
   256     }
       
   257     
       
   258     
       
   259 void CNcdNodeSeenFolder::NewChildrenL(
       
   260     TInt aRecursionLevel, RPointerArray<CNcdNodeIdentifier>& aNodes ) const
       
   261     {
       
   262     DLTRACEIN(("level %d", aRecursionLevel));
       
   263     DASSERT( aRecursionLevel >= 0 );
       
   264     
       
   265     CNcdNodeManager& nodeManager = iOwnerNode.NodeManager();
       
   266     TInt childCount = iOwnerNode.ChildCount();
       
   267     
       
   268     for ( TInt i = 0; i < childCount; i++ ) 
       
   269         {
       
   270         const CNcdNodeIdentifier& childId = iOwnerNode.ChildL( i );
       
   271         CNcdNode* child = nodeManager.NodePtrL( childId );
       
   272         if ( !child ) 
       
   273             {
       
   274             continue;
       
   275             }
       
   276         
       
   277         // If the child is transparent folder, don't add it to the array.
       
   278         if ( child->ClassId() != NcdNodeClassIds::ENcdTransparentFolderNodeClassId && !child->NodeSeen().IsSeenL() ) 
       
   279             {
       
   280             // Create copy of the identifier and add it to the array.
       
   281             CNcdNodeIdentifier* copy = CNcdNodeIdentifier::NewLC( childId );
       
   282             aNodes.AppendL( copy );
       
   283             CleanupStack::Pop( copy );
       
   284             }
       
   285         else if ( child->ClassId() == NcdNodeClassIds::ENcdTransparentFolderNodeClassId
       
   286                   && aRecursionLevel == 0 ) 
       
   287             {
       
   288             // Transparent child, and this is the last recursion level. The children of the
       
   289             // transparent folder must be added to the array.
       
   290             CNcdNodeFolder* transparent = static_cast<CNcdNodeFolder*>( child );
       
   291             transparent->NodeSeenFolder().NewChildrenL( aRecursionLevel, aNodes );
       
   292             }            
       
   293                           
       
   294         if ( aRecursionLevel > 0 ) 
       
   295             {
       
   296             // If the node is a folder, go further in recursion.
       
   297             CNcdNodeFactory::TNcdNodeType nodeType = CNcdNodeFactory::NodeTypeL( *child );
       
   298             if ( nodeType == CNcdNodeFactory::ENcdNodeFolder || 
       
   299                  nodeType == CNcdNodeFactory::ENcdNodeRoot )
       
   300                 {
       
   301                 CNcdNodeFolder* folder = static_cast<CNcdNodeFolder*>( child );
       
   302                                 
       
   303                 // If the folder is transparent folder, the recursion level must not
       
   304                 // be decreased.
       
   305                 TInt nextRecursionLevel( aRecursionLevel - 1 );
       
   306                 if ( folder->ClassId() == NcdNodeClassIds::ENcdTransparentFolderNodeClassId ) 
       
   307                     {
       
   308                     nextRecursionLevel++;
       
   309                     }
       
   310                 folder->NodeSeenFolder().NewChildrenL( nextRecursionLevel, aNodes );
       
   311                 }
       
   312             }
       
   313         }
       
   314     }
       
   315     
       
   316 
       
   317 void CNcdNodeSeenFolder::SetContentsSeenL() const
       
   318     {
       
   319     DLTRACEIN((""));
       
   320 
       
   321     CNcdNodeManager& nodeManager = iOwnerNode.NodeManager();
       
   322     
       
   323     // Set the children of the folder as seen.
       
   324     for ( TInt i = 0; i < iOwnerNode.ChildCount(); i++ ) 
       
   325         {
       
   326         const CNcdNodeIdentifier& childIdentifier =
       
   327             iOwnerNode.ChildL( i );
       
   328         CNcdNode* child = nodeManager.NodePtrL( childIdentifier );
       
   329         if ( child ) 
       
   330             {
       
   331             // If the child is transparent folder, set its contents as seen since in
       
   332             // UI they are immediate children of this folder.
       
   333             if ( child->ClassId() == NcdNodeClassIds::ENcdTransparentFolderNodeClassId ) 
       
   334                 {
       
   335                 CNcdNodeFolder* transparent = static_cast<CNcdNodeFolder*>( child );
       
   336                 transparent->NodeSeenFolder().SetContentsSeenL();
       
   337                 }
       
   338             else 
       
   339                 {
       
   340                 child->NodeSeen().SetSeenL();
       
   341                 }
       
   342             }
       
   343         }
       
   344     }