ncdengine/provider/client/src/ncdsearchrootnodeproxy.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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 CNcdSearchRootNodeProxy class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdsearchrootnodeproxy.h"
       
    20 #include "catalogsclientserver.h"
       
    21 #include "ncdnodemanagerproxy.h"
       
    22 #include "ncdoperationmanagerproxy.h"
       
    23 #include "ncdnodeidentifier.h"
       
    24 #include "catalogsdebug.h"
       
    25 #include "ncdnodefunctionids.h"
       
    26 #include "catalogsinterfaceidentifier.h"
       
    27 #include "ncdloadnodeoperationproxy.h"
       
    28 #include "ncdchildentity.h"
       
    29 #include "ncdchildloadmode.h"
       
    30 #include "ncderrors.h"
       
    31 
       
    32 // ======== PUBLIC MEMBER FUNCTIONS ========
       
    33 
       
    34 CNcdSearchRootNodeProxy* CNcdSearchRootNodeProxy::NewL( MCatalogsClientServer& aSession,
       
    35                                             TInt aHandle,
       
    36                                             CNcdNodeManagerProxy& aNodeManager,
       
    37                                             CNcdOperationManagerProxy& aOperationManager,
       
    38                                             CNcdFavoriteManagerProxy& aFavoriteManager )
       
    39     {
       
    40     CNcdSearchRootNodeProxy* self = 
       
    41         CNcdSearchRootNodeProxy::NewLC(
       
    42             aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager );
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 CNcdSearchRootNodeProxy* CNcdSearchRootNodeProxy::NewLC( MCatalogsClientServer& aSession,
       
    48                                              TInt aHandle,
       
    49                                              CNcdNodeManagerProxy& aNodeManager,
       
    50                                              CNcdOperationManagerProxy& aOperationManager,
       
    51                                              CNcdFavoriteManagerProxy& aFavoriteManager )
       
    52     {
       
    53     CNcdSearchRootNodeProxy* self = 
       
    54         new( ELeave ) CNcdSearchRootNodeProxy(
       
    55             aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager );  
       
    56     // Using PushL because the object does not have any references yet
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 CNcdSearchRootNodeProxy::CNcdSearchRootNodeProxy( MCatalogsClientServer& aSession,
       
    64                                       TInt aHandle,
       
    65                                       CNcdNodeManagerProxy& aNodeManager,
       
    66                                       CNcdOperationManagerProxy& aOperationManager,
       
    67                                       CNcdFavoriteManagerProxy& aFavoriteManager ) 
       
    68 : CNcdSearchNodeFolderProxy( aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager )
       
    69     {
       
    70     }
       
    71 
       
    72 
       
    73 void CNcdSearchRootNodeProxy::ConstructL()
       
    74     {
       
    75     CNcdNodeFolderProxy::ConstructL(); 
       
    76     }
       
    77 
       
    78 CNcdSearchRootNodeProxy::~CNcdSearchRootNodeProxy()
       
    79     {
       
    80     }
       
    81 
       
    82 
       
    83 MNcdNode::TState CNcdSearchRootNodeProxy::State() const
       
    84     {
       
    85     DLTRACEIN((""));
       
    86     // Search root is a local node that can't be loaded and
       
    87     // therefore is always initialized.
       
    88     DLTRACEOUT(("Initialized"));
       
    89     return MNcdNode::EStateInitialized;
       
    90     }
       
    91 
       
    92 
       
    93 MNcdLoadNodeOperation* CNcdSearchRootNodeProxy::LoadL(
       
    94     MNcdLoadNodeOperationObserver& /*aObserver*/ )
       
    95     {
       
    96     DLTRACEIN((""));
       
    97     DLTRACEOUT((""));
       
    98     // return null because search root can't be loaded.
       
    99     return NULL;
       
   100     }
       
   101 
       
   102 TInt CNcdSearchRootNodeProxy::ChildCount() const
       
   103     {
       
   104     return iChildren.Count();
       
   105     }
       
   106 
       
   107 
       
   108 MNcdNode* CNcdSearchRootNodeProxy::ChildL( TInt aIndex )
       
   109     {
       
   110     DLTRACEIN(( _L("This parent: %S, %S"), &Namespace(), &Id() ));
       
   111 
       
   112            
       
   113     if ( aIndex < 0 || aIndex >= iChildren.Count() )
       
   114         {
       
   115         // Nothing to be done 
       
   116         DLERROR(( "Index error. child count: %d Given index: %d", 
       
   117                   iChildren.Count(), aIndex ));
       
   118         DASSERT( EFalse );
       
   119         User::Leave( KErrArgument );
       
   120         }
       
   121         
       
   122     const CNcdNodeIdentifier* child = &iChildren[aIndex]->Identifier();
       
   123         
       
   124     MNcdNode* node( NULL );
       
   125     
       
   126     node = &NodeManager().NodeL( *child );
       
   127     
       
   128     // Increase the reference counter by one
       
   129     node->AddRef();
       
   130     
       
   131     DLTRACEOUT((""));
       
   132 
       
   133     return node;
       
   134     }
       
   135 
       
   136 MNcdLoadNodeOperation* CNcdSearchRootNodeProxy::LoadChildrenL( 
       
   137         TInt aIndex, TInt aSize, TNcdChildLoadMode aMode,
       
   138         MNcdLoadNodeOperationObserver& aObserver )
       
   139     {
       
   140     DLTRACEIN((""));
       
   141     if( aSize < 1 || aIndex < 0 || ( aMode == ELoadMetadata && aIndex + aSize > ChildCount() ))
       
   142         {
       
   143         // Nothing to be done 
       
   144         DLERROR(( "Argument error. ChildCount: %d Given index: %d, size: %d",
       
   145                   ChildCount(), aIndex, aSize ));
       
   146         DASSERT( EFalse );
       
   147         User::Leave( KErrArgument );
       
   148         }
       
   149     if( aMode == ELoadMetadata )
       
   150         {
       
   151         // Child metadata can be loaded in a regular load op
       
   152         return CNcdSearchNodeFolderProxy::LoadChildrenL( aIndex,
       
   153             aSize,
       
   154             aMode,
       
   155             aObserver );
       
   156         }
       
   157     else
       
   158         {
       
   159         
       
   160         return NULL;
       
   161         }
       
   162     }
       
   163 
       
   164 void CNcdSearchRootNodeProxy::OperationComplete( 
       
   165     MNcdLoadNodeOperation& /*aOperation*/, TInt aError )
       
   166     {
       
   167     DLTRACEIN(( "Error: %d", aError ));
       
   168     
       
   169     if ( aError == KErrNone || aError == KNcdErrorSomeCatalogsFailedToLoad ) 
       
   170         {
       
   171         // update proxy's status from the server
       
   172         TRAP_IGNORE( InternalizeL() );
       
   173         }
       
   174     }
       
   175