PECengine/AttributeLibrary2/SrcWVAttributes/CPEngWVStatusTextConstruct.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  WV Status Text implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CPEngWVAttributeConstructBase.h"
       
    20 #include "CPEngWVAttributeModelBase.h"
       
    21 #include "CPEngWVStatusTextConstruct.h"
       
    22 #include "PresenceAttributeDefValueCRKeys.h"
       
    23 
       
    24 #include "MPEngXMLSerializer.h"
       
    25 #include "MPEngXMLParser.h"
       
    26 
       
    27 #include <MPEngPresenceAttrModel2.h>
       
    28 #include <PEngWVPresenceAttributes2.h>
       
    29 
       
    30 #include <E32Base.h>
       
    31 #include <S32Strm.h>
       
    32 
       
    33 
       
    34 
       
    35 //  DATA TYPES
       
    36 /**
       
    37  * Status text CSP name table.
       
    38  *
       
    39  * @since 3.0
       
    40  */
       
    41 const TWVCspAttributeNameEntry KStatusTextCspNameTable[] =
       
    42     {
       
    43         {
       
    44         EWVCspV11,
       
    45         LIT_AS_DESC8_PTR( KStatusTextXMLTag ),
       
    46         LIT_AS_DESC8_PTR( KPresenceSubListAttributesNS )
       
    47         },
       
    48         {
       
    49         EWVCspV12,
       
    50         LIT_AS_DESC8_PTR( KStatusTextXMLTag ),
       
    51         LIT_AS_DESC8_PTR( KPresenceSubListAttributesNS_CSP12 )
       
    52         }
       
    53     };
       
    54 
       
    55 
       
    56 const TInt KStatusTextCspNameTableCount = sizeof( KStatusTextCspNameTable ) / sizeof( TWVCspAttributeNameEntry );
       
    57 
       
    58 
       
    59 
       
    60 
       
    61 // =============== CPEngWVStatusTextConstruct MEMBER FUNCTIONS ===============
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CPEngWVStatusTextConstruct::CPEngWVStatusTextConstruct
       
    65 // C++ constructor can NOT contain any code, that
       
    66 // might leave.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CPEngWVStatusTextConstruct::CPEngWVStatusTextConstruct( TPEngWVCspVersion aCurrentCspVer )
       
    70         : CPEngWVAttributeConstructBase( aCurrentCspVer,
       
    71                                          KStatusTextCspNameTable,
       
    72                                          KStatusTextCspNameTableCount )
       
    73     {
       
    74     }
       
    75 
       
    76 
       
    77 // Destructor
       
    78 CPEngWVStatusTextConstruct::~CPEngWVStatusTextConstruct()
       
    79     {
       
    80     }
       
    81 
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CPEngWVStatusTextConstruct::NewAttributeInstanceLC()
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 MPEngPresenceAttrModelTypeImp* CPEngWVStatusTextConstruct::NewAttributeInstanceLC(
       
    89     TBool aUserOwnAttribute ) const
       
    90     {
       
    91     CPEngWVStatusTextModel* model = new ( ELeave ) CPEngWVStatusTextModel(
       
    92         aUserOwnAttribute );
       
    93     CleanupStack::PushL( model );
       
    94     model->ResetDataL();
       
    95     return model;
       
    96     }
       
    97 
       
    98 
       
    99 
       
   100 
       
   101 // ================= CPEngWVStatusTextModel MEMBER FUNCTIONS =================
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CPEngWVStatusTextConstruct::CPEngWVStatusTextConstruct::CPEngWVStatusTextModel
       
   105 // C++ constructor can NOT contain any code, that
       
   106 // might leave.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::CPEngWVStatusTextModel(
       
   110     TBool aUserOwnAttribute )
       
   111         : CPEngWVAttributeModelBase( aUserOwnAttribute )
       
   112     {
       
   113     }
       
   114 
       
   115 
       
   116 // Destructor
       
   117 CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::~CPEngWVStatusTextModel()
       
   118     {
       
   119     delete iStatusText;
       
   120     }
       
   121 
       
   122 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::SetDataL()
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 TBool CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::SetDataL( TInt* /*aIntData*/,
       
   129                                                                     const TDesC8* /*a8Data*/,
       
   130                                                                     const TDesC16* a16Data,
       
   131                                                                     TInt aField,
       
   132                                                                     TInt aGroup )
       
   133     {
       
   134     if ( a16Data &&
       
   135          ( aGroup == KPEngDefaultAttrValueGroup ) &&
       
   136          ( aField == EPEngStatusText ) )
       
   137         {
       
   138         //check the data length
       
   139         if ( a16Data->Length() > KPEngMaxWVStatusTextLength )
       
   140             {
       
   141             User::Leave( KErrArgument );
       
   142             }
       
   143 
       
   144 
       
   145         HBufC* tmp = a16Data->AllocL();
       
   146         delete iStatusText;
       
   147         iStatusText = tmp;
       
   148 
       
   149         return ETrue;
       
   150         }
       
   151 
       
   152 
       
   153     return EFalse;
       
   154     }
       
   155 
       
   156 
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::GetData()
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TBool CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::GetData( TInt* /*aIntData*/,
       
   163                                                                    TPtrC8* /*a8Data*/,
       
   164                                                                    TPtrC16* a16Data,
       
   165                                                                    TInt aField,
       
   166                                                                    TInt aGroup ) const
       
   167     {
       
   168     if ( a16Data &&
       
   169          ( aGroup == KPEngDefaultAttrValueGroup ) &&
       
   170          ( aField == EPEngStatusText ) )
       
   171         {
       
   172         a16Data->Set( *iStatusText );
       
   173         return ETrue;
       
   174         }
       
   175 
       
   176 
       
   177     return EFalse;
       
   178     }
       
   179 
       
   180 
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::EncodeDataToXmlL()
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 void CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::EncodeDataToXmlL(
       
   187     MPEngXMLSerializer& aSerializer ) const
       
   188     {
       
   189     aSerializer.StartTagL( KPresenceValueXMLTag )
       
   190     .UnicodeTextL( *iStatusText )
       
   191     .EndTagL( KPresenceValueXMLTag );
       
   192     }
       
   193 
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::DecodeDataFromXmlL()
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::DecodeDataFromXmlL(
       
   201     MPEngXMLParser& aParser,
       
   202     const TDesC8& aValueBlock )
       
   203     {
       
   204     if ( aParser.DecodeL( aValueBlock, KPresenceValueXMLTag, EFalse ) )
       
   205         {
       
   206         HBufC* tmp = aParser.ResultAsUnicodeTextL();
       
   207 
       
   208         if ( tmp->Length() > KPEngMaxWVStatusTextLength )
       
   209             {
       
   210             CleanupStack::PushL( tmp );
       
   211             HBufC* tmp2 = tmp->Left( KPEngMaxWVStatusTextLength ).AllocL();
       
   212             delete iStatusText;
       
   213             iStatusText = tmp2;
       
   214             CleanupStack::PopAndDestroy( tmp );
       
   215             }
       
   216         else
       
   217             {
       
   218             delete iStatusText;
       
   219             iStatusText = tmp;
       
   220             }
       
   221         }
       
   222     else
       
   223         {
       
   224         HBufC* tmpText = HBufC::NewL( 0 );  //by default status text is empty == 0 length
       
   225         delete iStatusText;
       
   226         iStatusText = tmpText;
       
   227         }
       
   228     }
       
   229 
       
   230 
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::ResetDataL()
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::ResetDataL()
       
   237     {
       
   238     HBufC* tmpText = HBufC::NewL( 0 );  //by default status text is empty == 0 length
       
   239     delete iStatusText;
       
   240     iStatusText = tmpText;
       
   241     }
       
   242 
       
   243 
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::DataExternalizeSize()
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 TInt CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::DataExternalizeSize() const
       
   250     {
       
   251     return iStatusText->Size() + 4;  //4 bytes for descriptor overhead
       
   252     }
       
   253 
       
   254 
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::ExternalizeDataL()
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::ExternalizeDataL(
       
   261     RWriteStream& aStream ) const
       
   262     {
       
   263     aStream << iStatusText->Left( KPEngMaxWVStatusTextLength );
       
   264     }
       
   265 
       
   266 
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::InternalizeDataL()
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CPEngWVStatusTextConstruct::CPEngWVStatusTextModel::InternalizeDataL(
       
   273     RReadStream& aStream )
       
   274     {
       
   275     HBufC* tmpText = HBufC::NewL( aStream, KPEngMaxWVStatusTextLength );
       
   276     delete iStatusText;
       
   277     iStatusText = tmpText;
       
   278     }
       
   279 
       
   280 
       
   281 //  End of File
       
   282 
       
   283