ncdengine/provider/server/src/ncdsubscriptiondatacompleter.cpp
changeset 4 32704c33136d
equal deleted inserted replaced
-1:000000000000 4:32704c33136d
       
     1 /*
       
     2 * Copyright (c) 2007 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:   Implements CNcdSubscriptionDataCompleterDataCompleter class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdsubscriptiondatacompleter.h"
       
    20 
       
    21 #include "ncdsubscriptionmanagerimpl.h"
       
    22 #include "ncdnodeidentifier.h"
       
    23 #include "ncdsubscriptionmanagerobserver.h"
       
    24 #include "catalogsdebug.h"
       
    25 #include "ncdnodemanager.h"
       
    26 #include "ncdsubscriptionimpl.h"
       
    27 #include "ncdsubscriptiongroup.h"
       
    28 #include "ncdnodemetadataimpl.h"
       
    29 #include "ncdnodeiconimpl.h"
       
    30 #include "ncdpurchaseoptionimpl.h"
       
    31 #include "ncdnodeimpl.h"
       
    32 
       
    33 
       
    34 CNcdSubscriptionDataCompleter::CNcdSubscriptionDataCompleter(
       
    35     CNcdSubscriptionManager& aSubscriptionManager,
       
    36     CNcdNodeManager& aNodeManager,
       
    37     CNcdOperationManager& aOperationManager ) :
       
    38     iSubscriptionManager( aSubscriptionManager ),
       
    39     iNodeManager( aNodeManager ),
       
    40     iOperationManager( aOperationManager )
       
    41     {
       
    42     }
       
    43 
       
    44 void CNcdSubscriptionDataCompleter::ConstructL()
       
    45     {
       
    46     }
       
    47 
       
    48 
       
    49 CNcdSubscriptionDataCompleter* CNcdSubscriptionDataCompleter::NewL(
       
    50     CNcdSubscriptionManager& aSubscriptionManager,
       
    51     CNcdNodeManager& aNodeManager,
       
    52     CNcdOperationManager& aOperationManager )
       
    53     {
       
    54     CNcdSubscriptionDataCompleter* self =   
       
    55         CNcdSubscriptionDataCompleter::NewLC( aSubscriptionManager,
       
    56                                               aNodeManager,
       
    57                                               aOperationManager );
       
    58     CleanupStack::Pop( self );
       
    59     return self;        
       
    60     }
       
    61 
       
    62 CNcdSubscriptionDataCompleter* CNcdSubscriptionDataCompleter::NewLC(
       
    63     CNcdSubscriptionManager& aSubscriptionManager,
       
    64     CNcdNodeManager& aNodeManager,
       
    65     CNcdOperationManager& aOperationManager )
       
    66     {
       
    67     CNcdSubscriptionDataCompleter* self = 
       
    68         new( ELeave ) CNcdSubscriptionDataCompleter( aSubscriptionManager,
       
    69                                                      aNodeManager,
       
    70                                                      aOperationManager );
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     return self;        
       
    74     }
       
    75 
       
    76 CNcdSubscriptionDataCompleter::~CNcdSubscriptionDataCompleter()
       
    77     {
       
    78     DLTRACEIN((""));
       
    79 
       
    80     iNodeIds.ResetAndDestroy();
       
    81     delete iPurchaseOptionIds;
       
    82     iPurchaseOptionIds = NULL;
       
    83     
       
    84     iContext = NULL;
       
    85     iInternalizationObserver = NULL;
       
    86 
       
    87     DLTRACEOUT((""));
       
    88     }
       
    89 
       
    90 TInt CNcdSubscriptionDataCompleter::CompleteSubscriptions(
       
    91     TUid aClientUid,
       
    92     RPointerArray<CNcdNodeIdentifier> aNodeIds,
       
    93     MDesCArray* aPurchaseOptionIds,
       
    94     MCatalogsContext* aContext,
       
    95     MNcdSubscriptionManagerObserver* aObserver )
       
    96     {
       
    97     DLTRACEIN((""));
       
    98     iClientUid = aClientUid;    
       
    99     iNodeIds = aNodeIds;
       
   100     iPurchaseOptionIds = aPurchaseOptionIds;
       
   101     iContext = aContext;
       
   102     iInternalizationObserver = aObserver;
       
   103 
       
   104     if ( aNodeIds.Count() != iPurchaseOptionIds->MdcaCount() )
       
   105         {
       
   106         return KErrArgument;
       
   107         }
       
   108 
       
   109     iIndexer = 0;
       
   110 
       
   111 
       
   112     ProceedCompletion();
       
   113     
       
   114         
       
   115     DLTRACEOUT((""));
       
   116     return KErrNone;
       
   117     }
       
   118 
       
   119 void CNcdSubscriptionDataCompleter::ProceedCompletion()
       
   120     {
       
   121     DLTRACEIN((""));
       
   122     const TInt KSubscriptionAmount( iNodeIds.Count() );
       
   123     while ( iIndexer < KSubscriptionAmount )
       
   124         {
       
   125         
       
   126         CNcdNodeIdentifier& currentNodeIdentifier = *iNodeIds[iIndexer];
       
   127         const TDesC& currentPurchaseOptionId =
       
   128             iPurchaseOptionIds->MdcaPoint( iIndexer );
       
   129         
       
   130         TRAPD( error, 
       
   131             {
       
   132             // pointer to current subscription should not be
       
   133             // stored to prevent errors if the subscription is for
       
   134             // some reason deleted
       
   135             CNcdSubscription& currentSubscription =
       
   136                 SubscriptionL( currentNodeIdentifier,
       
   137                                currentPurchaseOptionId );
       
   138         
       
   139             if ( SubscriptionIncomplete( currentSubscription ) )
       
   140                 {                
       
   141                 CNcdNodeMetaData& meta =
       
   142                     iNodeManager.NodeMetaDataL( currentNodeIdentifier );
       
   143 
       
   144                 CompleteSubscriptionL( currentSubscription,
       
   145                                        meta,
       
   146                                        currentPurchaseOptionId,
       
   147                                        iClientUid );
       
   148                 }
       
   149             } );
       
   150         if ( error != KErrNone )
       
   151             {
       
   152             // Nothing to be done, meta data was not found
       
   153             // or some other error situation and could not
       
   154             // complete the subscription info
       
   155             }
       
   156         
       
   157         ++iIndexer;
       
   158         }
       
   159     
       
   160     // All subscriptions completed. Notify and delete this.
       
   161     iSubscriptionManager.NotifyListeners( iClientUid );
       
   162     if ( iInternalizationObserver )
       
   163         {
       
   164         iInternalizationObserver->SubscriptionsInternalizeComplete(
       
   165             KErrNone );
       
   166         }        
       
   167     iSubscriptionManager.SubscriptionCompleted( this );
       
   168     }
       
   169 
       
   170 void CNcdSubscriptionDataCompleter::CompleteSubscriptionL(
       
   171     CNcdSubscription& aCurrentSubscription,
       
   172     const CNcdNodeMetaData& aCurrentNodeMetaData,
       
   173     const TDesC& aPurchaseOptionId,
       
   174     TUid aClientUid ) const
       
   175     {
       
   176     DLTRACEIN((""));
       
   177     
       
   178     CompleteSubscriptionNameL( aCurrentSubscription, 
       
   179                                aCurrentNodeMetaData,
       
   180                                aPurchaseOptionId );
       
   181 
       
   182     TRAPD( error, CompleteSubscriptionIconL(
       
   183                       aCurrentSubscription,
       
   184                       aCurrentNodeMetaData ) );
       
   185     // Leave on error situations. If the meta data does not
       
   186     // have an icon then this is not an error situation.
       
   187     if ( error != KErrNone && error != KErrNotFound )
       
   188         {
       
   189         User::Leave( error );
       
   190         }
       
   191 
       
   192     TRAP_IGNORE( iSubscriptionManager.SaveGroupIntoDatabaseL( 
       
   193                      aClientUid,
       
   194                      aCurrentSubscription.ParentGroup() ) );    
       
   195 
       
   196     DLTRACEOUT((""));
       
   197     }
       
   198 
       
   199 
       
   200 CNcdSubscription& CNcdSubscriptionDataCompleter::SubscriptionL(
       
   201     const CNcdNodeIdentifier& aNodeIdentifier,
       
   202     const TDesC& aPurchaseOptionId ) const
       
   203     {
       
   204     DLTRACEIN((""));
       
   205     return iSubscriptionManager.SubscriptionL(
       
   206             aNodeIdentifier.NodeId(),
       
   207             aNodeIdentifier.NodeNameSpace(),
       
   208             aPurchaseOptionId,
       
   209             aNodeIdentifier.ClientUid() );
       
   210     }
       
   211 
       
   212 TBool CNcdSubscriptionDataCompleter::SubscriptionIncomplete(
       
   213     const CNcdSubscription& aSubscription ) const
       
   214     {
       
   215     DLTRACEIN((""));
       
   216     if ( aSubscription.SubscriptionName() == KNullDesC )
       
   217         {
       
   218         return ETrue;
       
   219         }
       
   220     if ( aSubscription.ParentGroup().Icon() == KNullDesC8 )
       
   221         {
       
   222         return ETrue;
       
   223         }
       
   224     return EFalse;
       
   225     }
       
   226 
       
   227 void CNcdSubscriptionDataCompleter::CompleteSubscriptionNameL(
       
   228     CNcdSubscription& aSubscription,
       
   229     const CNcdNodeMetaData& aMetaData,
       
   230     const TDesC& aPurchaseOptionId ) const
       
   231     {
       
   232     DLTRACEIN((""));
       
   233     CNcdPurchaseOptionImpl& subscriptionPo =
       
   234         aMetaData.PurchaseOptionByIdL( aPurchaseOptionId );
       
   235     const TDesC& subscriptionName = subscriptionPo.PurchaseOptionName();        
       
   236     aSubscription.SetSubscriptionNameL( subscriptionName );
       
   237     DLTRACEOUT((""));
       
   238     }
       
   239 
       
   240 void CNcdSubscriptionDataCompleter::CompleteSubscriptionIconL(
       
   241     CNcdSubscription& aSubscription,
       
   242     const CNcdNodeMetaData& aMetaData ) const
       
   243     {
       
   244     DLTRACEIN((""));
       
   245     CNcdNodeIcon& nodeIcon = aMetaData.IconL();
       
   246     HBufC8* icon = nodeIcon.IconDataL();
       
   247     CleanupStack::PushL( icon );
       
   248     aSubscription.ParentGroup().SetIconL( *icon );
       
   249     CleanupStack::PopAndDestroy( icon );
       
   250     DLTRACEOUT((""));
       
   251     }