creator/engine/src/creator_contactelement.cpp
changeset 17 4f2773374eff
child 19 4b22a598b890
equal deleted inserted replaced
15:e11368ed4880 17:4f2773374eff
       
     1 /*
       
     2 * Copyright (c) 2010 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 
       
    20 #include "creator_contactelement.h"
       
    21 #include "creator_traces.h"
       
    22 #include "creator_factory.h"
       
    23 #include "creator_contactsetcache.h"
       
    24 #include <xml/documentparameters.h>
       
    25 
       
    26 using namespace Xml;
       
    27 using namespace creatorcontact;
       
    28 
       
    29 /**
       
    30  * Contact field element mappings:
       
    31  */
       
    32 enum TContactFieldDataType
       
    33     {
       
    34     EDataTypeText,
       
    35     EDataTypeBinary,
       
    36     EDataTypeDateTime    
       
    37     };
       
    38     
       
    39 class FieldMapping
       
    40 {
       
    41 public:
       
    42     TPtrC iElementName;
       
    43     TInt  iFieldCode;
       
    44     TContactFieldDataType iDataType;
       
    45 };
       
    46 
       
    47 CCreatorContactElementBase* CCreatorContactElementBase::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext)
       
    48     {
       
    49     LOGSTRING("Creator: CCreatorContactElementBase::NewL");
       
    50     CCreatorContactElementBase* self = new (ELeave) CCreatorContactElementBase(aEngine);
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL(aName, aContext);
       
    53     CleanupStack::Pop();
       
    54     return self;
       
    55     }
       
    56 CCreatorContactElementBase::CCreatorContactElementBase(CCreatorEngine* aEngine) : CCreatorScriptElement(aEngine)
       
    57     { }
       
    58 
       
    59 CCreatorContactElement* CCreatorContactElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext)
       
    60     {
       
    61     LOGSTRING("Creator: CCreatorContactElement::NewL");
       
    62     CCreatorContactElement* self = new (ELeave) CCreatorContactElement(aEngine);
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL(aName, aContext);
       
    65     CleanupStack::Pop();
       
    66     return self;
       
    67     }
       
    68 CCreatorContactElement::CCreatorContactElement(CCreatorEngine* aEngine) 
       
    69 : 
       
    70 CCreatorContactElementBase(aEngine)
       
    71     { 
       
    72     iIsCommandElement = ETrue;
       
    73     }
       
    74 
       
    75 
       
    76 void CCreatorContactElement::ExecuteCommandL()
       
    77     {}
       
    78 
       
    79 CCreatorContactSetElement* CCreatorContactSetElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext)
       
    80     {
       
    81     LOGSTRING("Creator: CCreatorContactSetElement::NewL");
       
    82     CCreatorContactSetElement* self = new (ELeave) CCreatorContactSetElement(aEngine);
       
    83     CleanupStack::PushL(self);
       
    84     self->ConstructL(aName, aContext);
       
    85     CleanupStack::Pop();
       
    86     return self;
       
    87     }
       
    88 CCreatorContactSetElement::CCreatorContactSetElement(CCreatorEngine* aEngine) 
       
    89 : 
       
    90 CCreatorContactElementBase(aEngine)
       
    91     { }
       
    92 
       
    93 void CCreatorContactSetElement::ExecuteCommandL()
       
    94     { }
       
    95 
       
    96 void CCreatorContactSetElement::AddToCacheL()
       
    97     {    
       
    98     LOGSTRING("Creator: CCreatorContactSetElement::AddToCacheL");
       
    99     const CCreatorScriptAttribute* linkIdAttr = this->FindAttributeByName(KId);
       
   100     const CCreatorScriptAttribute* existingElemsAttr = this->FindAttributeByName(KExistingContacts);
       
   101     TInt numOfExistingContacts = 0;
       
   102     if( existingElemsAttr )
       
   103         {
       
   104         numOfExistingContacts = ConvertStrToIntL(existingElemsAttr->Value());
       
   105         }
       
   106     if( linkIdAttr )
       
   107         {
       
   108         TInt linkId = ConvertStrToIntL(linkIdAttr->Value());
       
   109         if( linkId > 0 )
       
   110             {    
       
   111             CCreatorContactSet* newSet = CCreatorContactSet::NewL(linkId, numOfExistingContacts);
       
   112             CleanupStack::PushL(newSet);
       
   113             ContactLinkCache::Instance()->AppendL(newSet);
       
   114             CleanupStack::Pop(newSet);
       
   115                  
       
   116             // Mark sub-elements (i.e. contacts) to this contact-set:
       
   117             for( TInt i = 0; i < iSubElements.Count(); ++i )
       
   118                 {
       
   119                 for( TInt j = 0; j < iSubElements[i]->CommandParameters().Count(); ++j)
       
   120                     {
       
   121                     CCreatorModuleBaseParameters* params = iSubElements[i]->CommandParameters()[j];
       
   122                     if( params )
       
   123                         {
       
   124                         params->SetScriptLinkId(linkId);
       
   125                         }
       
   126                     }
       
   127                 }
       
   128             }
       
   129         }
       
   130     }
       
   131 
       
   132 CCreatorContactGroupElement* CCreatorContactGroupElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext)
       
   133     {
       
   134     LOGSTRING("Creator: CCreatorContactGroupElement::NewL");
       
   135     CCreatorContactGroupElement* self = new (ELeave) CCreatorContactGroupElement(aEngine);
       
   136     CleanupStack::PushL(self);
       
   137     self->ConstructL(aName, aContext);
       
   138     CleanupStack::Pop();
       
   139     return self;
       
   140     }
       
   141 CCreatorContactGroupElement::CCreatorContactGroupElement(CCreatorEngine* aEngine)
       
   142 : 
       
   143 CCreatorContactElementBase(aEngine)
       
   144     { 
       
   145     iIsCommandElement = ETrue;
       
   146     }
       
   147 
       
   148 
       
   149 void CCreatorContactGroupElement::ExecuteCommandL()
       
   150     {}
       
   151 
       
   152 CCreatorContactFieldElement* CCreatorContactFieldElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext)
       
   153     {
       
   154     LOGSTRING("Creator: CCreatorContactFieldElement::NewL");
       
   155     CCreatorContactFieldElement* self = new (ELeave) CCreatorContactFieldElement(aEngine);
       
   156     CleanupStack::PushL(self);
       
   157     self->ConstructL(aName, aContext);
       
   158     CleanupStack::Pop();
       
   159     return self;
       
   160     }
       
   161 
       
   162 CCreatorContactFieldElement::CCreatorContactFieldElement(CCreatorEngine* aEngine) 
       
   163 : 
       
   164 CCreatorScriptElement(aEngine)
       
   165     { }