ncdengine/provider/client/src/ncdqueryimpl.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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32strm.h>
       
    20 #include <bamdesca.h>
       
    21 
       
    22 #include "ncdqueryimpl.h"
       
    23 #include "ncdqueryitemimpl.h"
       
    24 #include "ncdquerytextitemimpl.h"
       
    25 #include "ncdquerynumericitemimpl.h"
       
    26 #include "ncdquerypincodeitemimpl.h"
       
    27 #include "ncdqueryselectionitemimpl.h"
       
    28 #include "ncd_cp_query.h"
       
    29 #include "ncd_cp_queryelement.h"
       
    30 #include "catalogsarray.h"
       
    31 #include "catalogsinterfaceidentifier.h"
       
    32 #include "catalogsconstants.h"
       
    33 #include "catalogsutils.h"
       
    34 #include "catalogsdebug.h"
       
    35 #include "ncdstring.h"
       
    36 #include "ncdclientlocalizer.h"
       
    37 #include "ncdlocalizerutils.h"
       
    38 
       
    39 // ======== MEMBER FUNCTIONS ========
       
    40 
       
    41 CNcdQuery* CNcdQuery::NewL( RReadStream& aReadStream )
       
    42     {
       
    43     CNcdQuery* self = CNcdQuery::NewLC( aReadStream );
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 CNcdQuery* CNcdQuery::NewLC( RReadStream& aReadStream )
       
    49     {
       
    50     CNcdQuery* self = new ( ELeave ) CNcdQuery( EFalse );
       
    51     // Using PushL because the object does not have any references yet
       
    52     CleanupStack::PushL( self );
       
    53 
       
    54     self->ConstructL();
       
    55     self->InternalizeL( aReadStream );
       
    56     self->InternalAddRef();
       
    57     return self;
       
    58     }
       
    59     
       
    60 CNcdQuery* CNcdQuery::NewL( const MNcdConfigurationProtocolQuery& aQuery,
       
    61     TBool aIsSecureConnection )
       
    62     {
       
    63     CNcdQuery* self = CNcdQuery::NewLC( aQuery, aIsSecureConnection );
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 CNcdQuery* CNcdQuery::NewLC( const MNcdConfigurationProtocolQuery& aQuery,
       
    69     TBool aIsSecureConnection )
       
    70     {
       
    71     CNcdQuery* self = new ( ELeave ) CNcdQuery( aIsSecureConnection );
       
    72     // Using PushL because the object does not have any references yet
       
    73     CleanupStack::PushL( self );
       
    74 
       
    75     self->ConstructL();
       
    76     self->InternalizeL( aQuery );
       
    77     self->InternalAddRef();
       
    78     return self;
       
    79     }
       
    80 
       
    81 CNcdQuery* CNcdQuery::NewL( const RPointerArray<CNcdString>& aPaymentMethodNames,
       
    82                             const MDesC8Array& aPaymentMethodTypes )
       
    83     {
       
    84     CNcdQuery* self = CNcdQuery::NewLC( aPaymentMethodNames,
       
    85                                         aPaymentMethodTypes );
       
    86     CleanupStack::Pop( self );
       
    87     return self;
       
    88     }
       
    89 
       
    90 CNcdQuery* CNcdQuery::NewLC( const RPointerArray<CNcdString>& aPaymentMethodNames,
       
    91                              const MDesC8Array& aPaymentMethodTypes )
       
    92     {
       
    93     CNcdQuery* self = new ( ELeave ) CNcdQuery( EFalse );
       
    94     // Using PushL because the object does not have any references yet
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL( aPaymentMethodNames, aPaymentMethodTypes );
       
    97     self->InternalAddRef();
       
    98     return self;
       
    99     }
       
   100 
       
   101 void CNcdQuery::SetClientLocalizer( MNcdClientLocalizer* aLocalizer ) 
       
   102     {
       
   103     iClientLocalizer = aLocalizer;
       
   104     }
       
   105     
       
   106 MNcdClientLocalizer* CNcdQuery::ClientLocalizer() const 
       
   107     {
       
   108     return iClientLocalizer;
       
   109     }
       
   110 
       
   111     
       
   112 void CNcdQuery::InternalizeL( RReadStream& aReadStream )
       
   113     {
       
   114     delete iId;
       
   115     iId = NULL;
       
   116     iId = HBufC::NewL( aReadStream, KMaxTInt );
       
   117     iIsOptional = aReadStream.ReadInt32L();
       
   118     iSemantics = static_cast<MNcdQuery::TSemantics>(
       
   119         aReadStream.ReadInt32L());
       
   120     delete iTitle;
       
   121     iTitle = NULL;
       
   122     iTitle = CNcdString::NewL( aReadStream );
       
   123     delete iBody;
       
   124     iBody = NULL;
       
   125     iBody = CNcdString::NewL( aReadStream );
       
   126     iResponse = static_cast<TResponse>( aReadStream.ReadInt32L() );
       
   127     iIsSecureConnection = aReadStream.ReadInt32L();
       
   128     TInt itemCount( aReadStream.ReadInt32L() );
       
   129     iItems.ResetAndRelease();
       
   130     for ( TInt i = 0 ; i < itemCount ; i++ )
       
   131         {
       
   132         TNcdInterfaceId interfaceId = static_cast<TNcdInterfaceId>(aReadStream.ReadInt32L());
       
   133         CNcdQueryItem* item = NULL;
       
   134         switch ( interfaceId )
       
   135             {
       
   136             case ENcdQueryTextItemUid:
       
   137                 {
       
   138                 item = CNcdQueryTextItem::NewL( aReadStream, *this );
       
   139                 break;
       
   140                 }
       
   141             case ENcdQueryNumericItemUid:
       
   142                 {
       
   143                 item = CNcdQueryNumericItem::NewL( aReadStream, *this );
       
   144                 break;
       
   145                 }
       
   146             case ENcdQueryPinCodeItemUid:
       
   147                 {
       
   148                 item = CNcdQueryPinCodeItem::NewL( aReadStream, *this );
       
   149                 break;
       
   150                 }
       
   151             case ENcdQuerySelectionItemUid:
       
   152                 {
       
   153                 item = CNcdQuerySelectionItem::NewL( aReadStream, *this );
       
   154                 break;
       
   155                 }
       
   156             default:
       
   157                 {
       
   158                 User::Leave( KErrCorrupt );
       
   159                 break;
       
   160                 }
       
   161             }
       
   162 
       
   163         // Object's refcount must be at least 1 for Release() to work correctly
       
   164         item->AddRef();
       
   165         CleanupReleasePushL( *item );
       
   166         iItems.AppendL( item );        
       
   167         CleanupStack::Pop( item );
       
   168         }
       
   169     }
       
   170     
       
   171 void CNcdQuery::InternalizeL( const MNcdConfigurationProtocolQuery& aQuery )
       
   172     {
       
   173     delete iId;
       
   174     iId = NULL;
       
   175     iId = aQuery.Id().AllocL();
       
   176     iIsOptional = aQuery.Optional();
       
   177     iSemantics = aQuery.Semantics();
       
   178     delete iTitle;
       
   179     iTitle = NULL;
       
   180     iTitle = CNcdString::NewL( aQuery.Title().Key(), aQuery.Title().Data() );
       
   181     delete iBody;
       
   182     iBody = NULL;
       
   183     iBody = CNcdString::NewL( aQuery.BodyText().Key(), aQuery.BodyText().Data() );
       
   184         
       
   185     iItems.ResetAndRelease();    
       
   186     for ( TInt i = 0 ; i < aQuery.QueryElementCount() ; i++ )
       
   187         {
       
   188         const MNcdConfigurationProtocolQueryElement& queryElement =
       
   189             aQuery.QueryElementL( i );
       
   190         CNcdQueryItem* item = NULL;
       
   191         switch ( queryElement.Type() )
       
   192             {
       
   193             case MNcdConfigurationProtocolQueryElement::EFreeText:
       
   194             case MNcdConfigurationProtocolQueryElement::EFile:
       
   195             case MNcdConfigurationProtocolQueryElement::EGpsLocation:
       
   196             case MNcdConfigurationProtocolQueryElement::EConfiguration:
       
   197                 {
       
   198                 item = CNcdQueryTextItem::NewL( queryElement, *this );                
       
   199                 break;
       
   200                 }
       
   201             case MNcdConfigurationProtocolQueryElement::ENumeric:
       
   202                 {
       
   203                 if ( queryElement.Semantics() ==
       
   204                     MNcdQueryItem::ESemanticsPinCode )
       
   205                     {
       
   206                     item = CNcdQueryPinCodeItem::NewL( queryElement, *this );
       
   207                     }
       
   208                 else
       
   209                     {
       
   210                     item = CNcdQueryNumericItem::NewL( queryElement, *this );
       
   211                     }
       
   212                 break;
       
   213                 }            
       
   214             case MNcdConfigurationProtocolQueryElement::ESingleSelect:
       
   215             case MNcdConfigurationProtocolQueryElement::EMultiSelect:
       
   216                 {
       
   217                 item = CNcdQuerySelectionItem::NewL( queryElement, *this );                
       
   218                 break;
       
   219                 }
       
   220             default:
       
   221                 {
       
   222                 User::Leave( KErrCorrupt );
       
   223                 break;
       
   224                 }
       
   225             }
       
   226         
       
   227         // Object's refcount must be at least 1 for Release() to work correctly
       
   228         item->AddRef();
       
   229         CleanupReleasePushL( *item );		
       
   230         iItems.AppendL( item );
       
   231         CleanupStack::Pop( item );        
       
   232         }
       
   233     }
       
   234     
       
   235 void CNcdQuery::ExternalizeL( RWriteStream& aWriteStream ) const
       
   236     {
       
   237     aWriteStream << *iId;
       
   238     aWriteStream.WriteInt32L( iIsOptional );
       
   239     aWriteStream.WriteInt32L( iSemantics );
       
   240     iTitle->ExternalizeL( aWriteStream );
       
   241     iBody->ExternalizeL( aWriteStream );
       
   242     aWriteStream.WriteInt32L( iResponse );
       
   243     aWriteStream.WriteInt32L( iIsSecureConnection );
       
   244     aWriteStream.WriteInt32L( iItems.Count() );
       
   245     for ( TInt i = 0 ; i < iItems.Count() ; i++ )
       
   246         {
       
   247         aWriteStream.WriteInt32L( iItems[i]->Type() );
       
   248         iItems[i]->ExternalizeL( aWriteStream );
       
   249         }
       
   250     }
       
   251     
       
   252     
       
   253 TInt CNcdQuery::ItemCount() const
       
   254     {
       
   255     return iItems.Count();
       
   256     }
       
   257 
       
   258 CNcdQueryItem& CNcdQuery::QueryItemL( TInt aIndex )
       
   259     {
       
   260     DLTRACEIN((""));
       
   261     if ( aIndex < 0 || aIndex >= iItems.Count() )
       
   262         {
       
   263         User::Leave( KErrArgument );
       
   264         }
       
   265     DLTRACEOUT((""));
       
   266     return *iItems[aIndex];
       
   267     }
       
   268 
       
   269 const TDesC& CNcdQuery::Id() const
       
   270     {
       
   271     return *iId;
       
   272     }
       
   273 
       
   274 TBool CNcdQuery::AllItemsSet() const
       
   275     {
       
   276     DLTRACEIN((""));
       
   277     for ( TInt i = 0 ; i < iItems.Count() ; i++ )
       
   278         {
       
   279         if( !iItems[i]->IsSet() )
       
   280             {
       
   281             DLTRACEOUT(("EFalse"));
       
   282             return EFalse;
       
   283             }
       
   284         }
       
   285     DLTRACEOUT(("ETrue"));
       
   286     return ETrue;
       
   287     }
       
   288 
       
   289 TBool CNcdQuery::IsOptional() const
       
   290     {
       
   291     return iIsOptional;
       
   292     }
       
   293     
       
   294 MNcdQuery::TSemantics CNcdQuery::Semantics() const
       
   295     {
       
   296     return iSemantics;
       
   297     }
       
   298     
       
   299 const TDesC& CNcdQuery::MessageTitle() const
       
   300     {
       
   301     DLTRACEIN((""));
       
   302     return CNcdLocalizerUtils::LocalizedString(
       
   303         *iTitle, iClientLocalizer, iLocalizedTitle );
       
   304     }
       
   305     
       
   306 const TDesC& CNcdQuery::MessageBody() const
       
   307     {
       
   308     DLTRACEIN((""))
       
   309     return CNcdLocalizerUtils::LocalizedString(
       
   310         *iBody, iClientLocalizer, iLocalizedBody );
       
   311     }
       
   312     
       
   313 RCatalogsArray< MNcdQueryItem > CNcdQuery::QueryItemsL()
       
   314     {
       
   315     DLTRACEIN((""));
       
   316     RCatalogsArray< MNcdQueryItem > array;
       
   317     TRAPD( err,
       
   318         {
       
   319         for ( TInt i = 0 ; i < iItems.Count() ; i++ )
       
   320             {
       
   321             // don't show invisible items
       
   322             if( ! iItems[i]->IsInvisible() )
       
   323                 {
       
   324                 DLTRACE((_L("Adding item: id=%S description=%S message=%S semantics=%d"),
       
   325                      &iItems[i]->Id(), &iItems[i]->Description(),
       
   326                      &iItems[i]->Message(), iItems[i]->Semantics() ));
       
   327                 array.AppendL( iItems[i] );
       
   328                 iItems[i]->AddRef();
       
   329                 }
       
   330             }
       
   331         });
       
   332     if ( err != KErrNone )
       
   333         {        
       
   334         array.ResetAndRelease();
       
   335         User::Leave( err );
       
   336         }   
       
   337     return array;
       
   338     }
       
   339 
       
   340 void CNcdQuery::SetResponseL( TResponse aResponse )
       
   341     {
       
   342     iResponse = aResponse;
       
   343     }
       
   344 
       
   345 MNcdQuery::TResponse CNcdQuery::Response()
       
   346     {
       
   347     return iResponse;
       
   348     }
       
   349     
       
   350 TBool CNcdQuery::IsSecureConnection() const
       
   351     {
       
   352     return iIsSecureConnection;
       
   353     }
       
   354     
       
   355 CNcdQuery::~CNcdQuery()
       
   356     {
       
   357     DLTRACEIN((""));
       
   358     delete iId;
       
   359     delete iTitle;
       
   360     delete iBody;
       
   361     delete iLocalizedTitle;
       
   362     delete iLocalizedBody;
       
   363     iItems.ResetAndRelease();
       
   364     }
       
   365     
       
   366 CNcdQuery::CNcdQuery( TBool aIsSecureConnection )
       
   367     : CCatalogsInterfaceBase( NULL ),
       
   368       iIsSecureConnection( aIsSecureConnection )
       
   369     {    
       
   370     }
       
   371     
       
   372 void CNcdQuery::ConstructL()
       
   373     {
       
   374     
       
   375     iTitle = CNcdString::NewL( KNullDesC, KNullDesC );
       
   376     iBody = CNcdString::NewL( KNullDesC, KNullDesC );
       
   377     AssignDesL( iId, KNullDesC );
       
   378         
       
   379     // Register the interfaces of this object
       
   380     MNcdQuery* query( this );
       
   381     AddInterfaceL( 
       
   382         CCatalogsInterfaceIdentifier::NewL( query, this, MNcdQuery::KInterfaceUid ) );
       
   383     }
       
   384 
       
   385 void CNcdQuery::ConstructL( const RPointerArray<CNcdString>& aPaymentMethodNames,
       
   386                             const MDesC8Array& aPaymentMethodTypes )
       
   387     {
       
   388     ConstructL();
       
   389 
       
   390     AssignDesL( iId, KQueryIdPaymentMethod() );
       
   391     iSemantics = MNcdQuery::ESemanticsPaymentMethodSelectionQuery;
       
   392     
       
   393     CNcdQuerySelectionItem* item = 
       
   394         CNcdQuerySelectionItem::NewLC( aPaymentMethodNames, aPaymentMethodTypes, *this );
       
   395 	item->AddRef();
       
   396     iItems.AppendL( item );
       
   397     CleanupStack::Pop( item );
       
   398 
       
   399     }