IMPSengine/client/src/impscdatautils.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2003-2005 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 * imps data util class.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <e32base.h>
       
    22 #include    <miutconv.h>
       
    23 #include    "impskey.h"
       
    24 #include    "impscdatautils.h"
       
    25 #include    "impsdataaccessor.h"
       
    26 #include    "impsgrouppropsint.h"
       
    27 #include    "impsservices.h"
       
    28 #include    "impsliterals.h"
       
    29 
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 //
       
    36 TImpsCDataUtils::TImpsCDataUtils()
       
    37     {
       
    38     }
       
    39    
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // TImpsCDataUtils::GetRecipientsL
       
    43 // ----------------------------------------------------------------------------
       
    44 void TImpsCDataUtils::GetRecipientsL(
       
    45     MImpsKey* aKey,
       
    46     MImpsDataAccessor* aAc,
       
    47     CPtrC16Array* aGroups,
       
    48     CPtrC16Array* aUsers,  
       
    49     CPtrC16Array* aSnGroups,      // ScreenName( GroupId )
       
    50     CPtrC16Array* aScreenNs )     // ScreenName( SName );
       
    51     {
       
    52 
       
    53     aKey->AddL( CREATEKEY( EImpsKeyRecipient, 0 ) );
       
    54 
       
    55     // Get User*:UserID
       
    56     TBool more(ETrue);
       
    57     TDesC* myPtr;
       
    58     TInt i = 0;         // aux index
       
    59     for ( i = 0; more; i++)
       
    60         {
       
    61         aKey->AddL( CREATEKEY( EImpsKeyUser, i ) );
       
    62         aKey->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
    63         if ( aAc->RestoreDescL( aKey, myPtr ) )
       
    64             {
       
    65             aUsers->AppendL( *myPtr );
       
    66             }
       
    67         else
       
    68             {
       
    69             more = EFalse;
       
    70             }
       
    71         aKey->PopL( 2 );
       
    72         }
       
    73 
       
    74     // get Group*:GroupID
       
    75     more = ETrue;
       
    76     for ( i = 0; more; i++)
       
    77         {
       
    78         aKey->AddL( CREATEKEY( EImpsKeyGroup, i ) );
       
    79         aKey->AddL( CREATEKEY( EImpsKeyGroupID, 0 ) );
       
    80         if ( aAc->RestoreDescL( aKey, myPtr ) )
       
    81             {
       
    82             aGroups->AppendL( *myPtr );
       
    83             }
       
    84         else
       
    85             {
       
    86             more = EFalse;
       
    87             }
       
    88         aKey->PopL( 2 );
       
    89         }
       
    90 
       
    91     // Group*:ScreenName
       
    92     more = ETrue;
       
    93     for ( i = 0; more; i++)
       
    94         {
       
    95         aKey->AddL( CREATEKEY( EImpsKeyGroup, i ) );
       
    96         aKey->AddL( CREATEKEY( EImpsKeyScreenName, 0 ) );
       
    97         aKey->AddL( CREATEKEY( EImpsKeySName, 0 ) );
       
    98         if ( aAc->RestoreDescL( aKey, myPtr ) )
       
    99             {
       
   100             aScreenNs->AppendL( *myPtr );
       
   101             aKey->ReplaceLastL( CREATEKEY( EImpsKeyGroupID, 0 ) );
       
   102             if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   103                 {
       
   104                 aSnGroups->AppendL( *myPtr );
       
   105                 } // else error in data!
       
   106             }
       
   107         
       
   108             {
       
   109             more = EFalse;
       
   110             }
       
   111         aKey->PopL( 3 );
       
   112         }
       
   113 
       
   114     aKey->PopL();
       
   115 
       
   116     // notice: no contact list supported yet 
       
   117 
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // TImpsCDataUtils::SetRecipientsL
       
   122 // ----------------------------------------------------------------------------
       
   123 void TImpsCDataUtils::SetRecipientsL(
       
   124     MImpsKey* aKey,
       
   125     MImpsDataAccessor* aAc,
       
   126     const MDesC16Array* aGroups,
       
   127     const MDesC16Array* aUserIds,  
       
   128     const MDesC16Array* aSnGroups,         // ScreenName( GroupId )
       
   129     const MDesC16Array* aScreenNames )     // ScreenName( SName );
       
   130     {
       
   131 
       
   132     aKey->AddL( CREATEKEY( EImpsKeyRecipient, 0 ) );
       
   133 
       
   134     TInt i = 0;
       
   135 
       
   136   // User recipients
       
   137     if ( aUserIds )
       
   138         {
       
   139         TInt count = aUserIds->MdcaCount();
       
   140 
       
   141 
       
   142         for ( i = 0; i < count; i++ )
       
   143             {            
       
   144             aKey->AddL( CREATEKEY( EImpsKeyUser, i ) );
       
   145             aKey->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
   146             aAc->StoreDescL( aKey, aUserIds->MdcaPoint( i ) );
       
   147             aKey->PopL( 2 );
       
   148             }
       
   149         } // userids
       
   150 
       
   151     if ( aGroups )
       
   152         {
       
   153         TInt count = aGroups->MdcaCount();
       
   154 
       
   155         for ( i = 0; i < count; i++ )
       
   156             {            
       
   157             aKey->AddL( CREATEKEY( EImpsKeyGroup, i ) );
       
   158             aKey->AddL( CREATEKEY( EImpsKeyGroupID, 0 ) );
       
   159             aAc->StoreDescL( aKey, aGroups->MdcaPoint( i ) );
       
   160             aKey->PopL( 2 );
       
   161             }          
       
   162         }  // groupid
       
   163 
       
   164     if ( aScreenNames )
       
   165         {
       
   166         TInt count = aScreenNames->MdcaCount();
       
   167 
       
   168         for ( i = 0; i < count; i++ )
       
   169             {            
       
   170             aKey->AddL( CREATEKEY( EImpsKeyGroup, i ) );
       
   171             aKey->AddL( CREATEKEY( EImpsKeyScreenName, 0 ) );
       
   172             aKey->AddL( CREATEKEY( EImpsKeySName, 0 ) );
       
   173             aAc->StoreDescL( aKey, aScreenNames->MdcaPoint( i ) );
       
   174             aKey->ReplaceLastL( CREATEKEY( EImpsKeyGroupID, 0 ) );
       
   175             // myAccess->StoreDescL( aKey, *aGroupId );
       
   176             aAc->StoreDescL( aKey, aSnGroups->MdcaPoint( i ) );
       
   177             aKey->PopL( 3 );
       
   178             }
       
   179         } // screenNames
       
   180 
       
   181     aKey->PopL();   // EImpsKeyRecipient
       
   182 
       
   183     }
       
   184 
       
   185 // ----------------------------------------------------------------------------
       
   186 // TImpsCDataUtils::SetSenderL
       
   187 // ----------------------------------------------------------------------------
       
   188 void TImpsCDataUtils::SetSenderL(
       
   189             MImpsKey* aKey,
       
   190             MImpsDataAccessor* aAc,
       
   191             const TDesC* aSender,
       
   192             const TDesC* aGroupId )
       
   193     {
       
   194     aKey->AddL( CREATEKEY( EImpsKeySender, 0 ) );
       
   195 
       
   196     if ( aSender && !aGroupId )
       
   197         {
       
   198         // Pure UserID
       
   199         aKey->AddL( CREATEKEY( EImpsKeyUser, 0 ) );
       
   200         aKey->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
   201         aAc->StoreDescL( aKey, *aSender );
       
   202         aKey->PopL( 2 );
       
   203         }
       
   204     else if ( aSender && aGroupId )
       
   205         {
       
   206         // Screen Name
       
   207         aKey->AddL( CREATEKEY( EImpsKeyGroup, 0 ) );
       
   208         aKey->AddL( CREATEKEY( EImpsKeyScreenName, 0 ) );
       
   209         aKey->AddL( CREATEKEY( EImpsKeySName, 0 ) );
       
   210         aAc->StoreDescL( aKey, *aSender );
       
   211         aKey->ReplaceLastL( CREATEKEY( EImpsKeyGroupID, 0 ) );
       
   212         aAc->StoreDescL( aKey, *aGroupId );
       
   213         aKey->PopL( 3 );
       
   214         }
       
   215     else if ( !aSender && aGroupId )
       
   216         {
       
   217         // Sender is Group, well ... maybe it is possible in principle
       
   218         aKey->AddL( CREATEKEY( EImpsKeyGroup, 0 ) );
       
   219         aKey->AddL( CREATEKEY( EImpsKeyGroupID, 0 ) );
       
   220         aAc->StoreDescL( aKey, *aGroupId );
       
   221         aKey->PopL( 2 );
       
   222         }
       
   223 
       
   224     aKey->PopL();
       
   225     }
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // TImpsCDataUtils::GetUserListL
       
   229 // ----------------------------------------------------------------------------
       
   230 void TImpsCDataUtils::GetUserListL(
       
   231             MImpsKey* aPredecessor,
       
   232             MImpsDataAccessor* aAc,
       
   233             CDesCArray* aUsers,
       
   234             CDesCArray* aScreenNames )
       
   235     {
       
   236     // Get first the users
       
   237     TBool more(ETrue);
       
   238     TDesC* myPtr;
       
   239     TInt i = 0;         // aux index
       
   240     for ( i = 0; more; i++)
       
   241         {
       
   242         aPredecessor->AddL( CREATEKEY( EImpsKeyUser, i ) );
       
   243         aPredecessor->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
   244         if ( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   245             {
       
   246             aUsers->AppendL( *myPtr );
       
   247             }
       
   248         else
       
   249             {
       
   250             more = EFalse;
       
   251             }
       
   252         aPredecessor->PopL( 2 );
       
   253         }
       
   254     // Then get the screennames
       
   255     more = ETrue;
       
   256     for ( i = 0; more; i++)
       
   257         {
       
   258         aPredecessor->AddL( CREATEKEY( EImpsKeyScreenName, i ) );
       
   259         aPredecessor->AddL( CREATEKEY( EImpsKeySName, 0 ) );
       
   260         if ( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   261             {
       
   262             aScreenNames->AppendL( *myPtr );
       
   263             }
       
   264         else
       
   265             {
       
   266             more = EFalse;
       
   267             }
       
   268         aPredecessor->PopL( 2 );
       
   269         }
       
   270     }
       
   271 
       
   272 // ----------------------------------------------------------------------------
       
   273 // TImpsCDataUtils::GetUrlListL
       
   274 // ----------------------------------------------------------------------------
       
   275 void TImpsCDataUtils::GetUrlListL(
       
   276             MImpsDataAccessor* aAc,
       
   277             CDesCArray* aUrlList )
       
   278     {
       
   279     CImpsKey* myKey = CImpsKey::NewLC(); // << myKey
       
   280     TImpsDataUtils::AddValuesFromArrayL( 
       
   281         myKey, 
       
   282         KInviteUserRequestElements, 
       
   283         sizeof( KInviteUserRequestElements ) /
       
   284         sizeof( KInviteUserRequestElements[0] ) );
       
   285         
       
   286     myKey->AddL( CREATEKEY( EImpsKeyURLList, 0 ) );
       
   287    
       
   288     // Get the urls
       
   289     TBool more( ETrue );
       
   290     TDesC* myPtr;
       
   291     TInt i = 0;         // aux index
       
   292     for ( i = 0; more; i++)
       
   293         {
       
   294         myKey->AddL( CREATEKEY( EImpsKeyURL, i ) );
       
   295         if ( aAc->RestoreDescL( myKey, myPtr ) )
       
   296             {
       
   297             aUrlList->AppendL( *myPtr );
       
   298             }
       
   299         else
       
   300             {
       
   301             more = EFalse;
       
   302             }
       
   303         myKey->PopL( );
       
   304         }
       
   305     CleanupStack::PopAndDestroy();
       
   306     }
       
   307 
       
   308 // ----------------------------------------------------------------------------
       
   309 // TImpsCDataUtils::GetModAndAdmL
       
   310 // ----------------------------------------------------------------------------
       
   311 void TImpsCDataUtils::GetModAndAdmL(
       
   312             MImpsKey* aPredecessor,
       
   313             MImpsDataAccessor* aAc,
       
   314             CDesCArray* aModerators,
       
   315             CDesCArray* aAdmins )
       
   316     {
       
   317     // Get first the moderators
       
   318     TBool more(ETrue);
       
   319     TDesC* myPtr;
       
   320     TInt i = 0;         // aux index
       
   321 
       
   322     aPredecessor->AddL( CREATEKEY( EImpsKeyMod, 0 ) );
       
   323     aPredecessor->AddL( CREATEKEY( EImpsKeyUserList, 0 ) );
       
   324     for ( i = 0; more; i++)
       
   325         {
       
   326         aPredecessor->AddL( CREATEKEY( EImpsKeyUser, i ) );
       
   327         aPredecessor->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
   328         if ( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   329             {
       
   330             aModerators->AppendL( *myPtr );
       
   331             }
       
   332         else
       
   333             {
       
   334             more = EFalse;
       
   335             }
       
   336         aPredecessor->PopL( 2 );
       
   337         }
       
   338     aPredecessor->PopL( 2 );  // Pop out UserList,Pop out mod
       
   339     // Then get the admins
       
   340     aPredecessor->AddL( CREATEKEY( EImpsKeyAdmin, 0 ) );
       
   341     aPredecessor->AddL( CREATEKEY( EImpsKeyUserList, 0 ) );
       
   342     more = ETrue;
       
   343     for ( i = 0; more; i++)
       
   344         {
       
   345         aPredecessor->AddL( CREATEKEY( EImpsKeyUser, i ) );
       
   346         aPredecessor->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
   347         if ( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   348             {
       
   349             aAdmins->AppendL( *myPtr );
       
   350             }
       
   351         else
       
   352             {
       
   353             more = EFalse;
       
   354             }
       
   355         aPredecessor->PopL( 2 );
       
   356         }
       
   357     aPredecessor->PopL( 2 );  // Pop out UserList,out Admin
       
   358     }
       
   359  
       
   360 // ----------------------------------------------------------------------------
       
   361 // TImpsCDataUtils::GetUsersL
       
   362 // ----------------------------------------------------------------------------
       
   363 void TImpsCDataUtils::GetUsersL(
       
   364             MImpsKey* aPredecessor,
       
   365             MImpsDataAccessor* aAc,
       
   366             CDesCArray* aUsers )
       
   367     {
       
   368     // Get first the moderators
       
   369     TBool more(ETrue);
       
   370     TDesC* myPtr;
       
   371     TInt i = 0;         // aux index
       
   372 
       
   373     for ( i = 0; more; i++)
       
   374         {
       
   375         aPredecessor->AddL( CREATEKEY( EImpsKeyUser, i ) );
       
   376         aPredecessor->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
   377         if ( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   378             {
       
   379             aUsers->AppendL( *myPtr );
       
   380             }
       
   381         else
       
   382             {
       
   383             more = EFalse;
       
   384             }
       
   385         aPredecessor->PopL( 2 );
       
   386         }
       
   387     }
       
   388 
       
   389 // ----------------------------------------------------------------------------
       
   390 // TImpsCDataUtils::GetGroupPropertiesL
       
   391 // ----------------------------------------------------------------------------
       
   392 void TImpsCDataUtils::GetGroupPropertiesL(
       
   393             MImpsKey* aPredecessor,
       
   394             MImpsDataAccessor* aAc,
       
   395             CImpsCommonGroupPropsInt* aCommonP,
       
   396             CImpsPrivateGroupPropsInt* aPrivateP )
       
   397     {
       
   398     // Get first the common properties
       
   399     TBool more(ETrue);
       
   400     TDesC* myPtr;
       
   401     TInt i = 0;         // aux index
       
   402 
       
   403     aPredecessor->AddL( CREATEKEY( EImpsKeyGroupProperties, 0 ) );
       
   404     for ( i = 0; more; i++)
       
   405         {
       
   406         aPredecessor->AddL( CREATEKEY( EImpsKeyProperty, i ) );
       
   407         aPredecessor->AddL( CREATEKEY( EImpsKeyName, 0 ) );
       
   408         if ( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   409             {
       
   410             aPredecessor->PopL( ); // Pop out Name
       
   411             HBufC* newString = myPtr->AllocLC( );
       
   412             HBufC* mystring = newString;
       
   413             mystring->Des( ).UpperCase( );
       
   414             if( mystring->CompareF( KImpsName ) == 0 )
       
   415                 {
       
   416                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   417                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   418                     {
       
   419                     aCommonP->SetGroupNameL( *myPtr );
       
   420                     }
       
   421                 aPredecessor->PopL( ); // Pop out Value
       
   422                 }
       
   423             if( mystring->CompareF( KImpsAccessType ) == 0 )
       
   424                 {
       
   425                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   426                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   427                     {
       
   428                     HBufC* newString = myPtr->AllocLC( );
       
   429                     HBufC* mystring = newString;
       
   430                     mystring->Des( ).UpperCase( );
       
   431                     if( mystring->CompareF( KImpsOpen ) == 0 )
       
   432                         aCommonP->SetOpen( EImpsPropYes );
       
   433                     else
       
   434                         aCommonP->SetOpen( EImpsPropNo );
       
   435                     CleanupStack::PopAndDestroy(1);
       
   436                     }
       
   437                 aPredecessor->PopL( ); // Pop out Value
       
   438                 }
       
   439             if( mystring->CompareF( KImpsPrivateMessaging ) == 0 )
       
   440                 {
       
   441                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   442                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   443                     {
       
   444                     if( myPtr->CompareF( KImpsTrue ) == 0 )
       
   445                         aCommonP->SetPrivateAllowed( EImpsPropYes  );
       
   446                     else
       
   447                         aCommonP->SetPrivateAllowed( EImpsPropNo );
       
   448                     }
       
   449                 aPredecessor->PopL( ); // Pop out Value
       
   450                 }
       
   451             if( mystring->CompareF( KImpsType ) == 0 )
       
   452                 {
       
   453                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   454                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   455                     {
       
   456                     HBufC* newString = myPtr->AllocLC( );
       
   457                     HBufC* mystring = newString;
       
   458                     mystring->Des( ).UpperCase( );
       
   459                     if( mystring->CompareF( KImpsPublic ) == 0 )
       
   460                         aCommonP->SetPublic( EImpsPropYes  );
       
   461                     else
       
   462                         aCommonP->SetPublic( EImpsPropNo );
       
   463                     CleanupStack::PopAndDestroy(1);
       
   464                     }
       
   465                 aPredecessor->PopL( ); // Pop out Value
       
   466                 }
       
   467             if( mystring->CompareF( KImpsSearchable ) == 0 )
       
   468                 {
       
   469                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   470                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   471                     {
       
   472                     if( myPtr->CompareF( KImpsTrue ) == 0 )
       
   473                         aCommonP->SetSearchable( EImpsPropYes );
       
   474                     else
       
   475                         aCommonP->SetSearchable( EImpsPropNo );
       
   476                     }
       
   477                 aPredecessor->PopL( ); // Pop out Value
       
   478                 }
       
   479             if( mystring->CompareF( KImpsTopic ) == 0 )
       
   480                 {
       
   481                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   482                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   483                     {
       
   484                     aCommonP->SetTopicL( *myPtr );
       
   485                     }
       
   486                 aPredecessor->PopL( ); // Pop out Value
       
   487                 }
       
   488             if( mystring->CompareF( KImpsMaxActiveUsers ) == 0 )
       
   489                 {
       
   490                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   491                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   492                     {
       
   493                     TLex lex;
       
   494                     TUint32 myValue = 0;
       
   495 
       
   496                     lex.Assign( *myPtr );
       
   497                     lex.Val(myValue, EDecimal, 100000);
       
   498                     aCommonP->SetMaxNbrOfUsers( myValue );
       
   499                     }
       
   500                 aPredecessor->PopL( ); // Pop out Value
       
   501                 }
       
   502             if( mystring->CompareF( KImpsNumberOfUsers ) == 0 )
       
   503                 {
       
   504                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   505                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   506                     {
       
   507                     TLex lex;
       
   508                     TUint32 myValue = 0;
       
   509 
       
   510                     lex.Assign( *myPtr );
       
   511                     lex.Val(myValue, EDecimal, 100000);
       
   512                     aCommonP->SetNbrOfUsers( myValue );
       
   513                     }
       
   514                 aPredecessor->PopL( ); // Pop out Value
       
   515                 }
       
   516             // AutoDelete
       
   517             if( mystring->CompareF( KImpsAutoDelete ) == 0 )
       
   518                 {
       
   519                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   520                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   521                     {
       
   522                     if( myPtr->CompareF( KImpsTrue ) == 0 )
       
   523                         aCommonP->SetAutoDelete( EImpsPropYes );
       
   524                     else
       
   525                         aCommonP->SetAutoDelete( EImpsPropNo );
       
   526                     }
       
   527                 aPredecessor->PopL( ); // Pop out Value
       
   528                 }
       
   529             CleanupStack::PopAndDestroy(1);
       
   530             }
       
   531         else
       
   532             {
       
   533             more = EFalse;
       
   534             aPredecessor->PopL( );  // PopOut Name
       
   535             }
       
   536         aPredecessor->PopL( ); // Popout EImpsKeyProperty
       
   537         }
       
   538     aPredecessor->AddL( CREATEKEY( EImpsKeyWelcomeNote, 0 ) );
       
   539     aPredecessor->AddL( CREATEKEY( EImpsKeyContentData, 0 ) );
       
   540     TDesC* myPtrWelcome;
       
   541     if( aAc->RestoreDescL( aPredecessor, myPtrWelcome ) )
       
   542         {
       
   543         aCommonP->SetWelcomeL( *myPtrWelcome );
       
   544         }
       
   545     aPredecessor->PopL( 3 ); // Popout EImpsKeyGroupProperties
       
   546 
       
   547     // Get own properties
       
   548     more = ETrue ;
       
   549     aPredecessor->AddL( CREATEKEY( EImpsKeyOwnProperties, 0 ) );
       
   550     for ( i = 0; more; i++)
       
   551         {
       
   552         aPredecessor->AddL( CREATEKEY( EImpsKeyProperty, i ) );
       
   553         aPredecessor->AddL( CREATEKEY( EImpsKeyName, 0 ) );
       
   554         if ( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   555             {
       
   556             aPredecessor->PopL( ); // Pop out Name
       
   557             HBufC* newString = myPtr->AllocLC( );
       
   558             HBufC* mystring = newString;
       
   559             mystring->Des( ).UpperCase( );
       
   560             if( mystring->CompareF( KImpsPrivateMessaging ) == 0 )
       
   561                 {
       
   562                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   563                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   564                     {
       
   565                     if( myPtr->CompareF( KImpsTrue ) == 0 )
       
   566                         aPrivateP->SetPrivateAllowed( EImpsPropYes );
       
   567                     else
       
   568                         aPrivateP->SetPrivateAllowed( EImpsPropNo );      
       
   569                     }
       
   570                 aPredecessor->PopL( ); // Pop out Value
       
   571                 }
       
   572             if( mystring->CompareF( KImpsIsMember ) == 0 )
       
   573                 {
       
   574                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   575                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   576                     {
       
   577                     if( myPtr->CompareF( KImpsTrue ) == 0 )
       
   578                         aPrivateP->SetMember( EImpsPropYes );
       
   579                     else
       
   580                         aPrivateP->SetMember( EImpsPropNo );
       
   581                     }
       
   582                 aPredecessor->PopL( ); // Pop out Value
       
   583                 }
       
   584             if( mystring->CompareF( KImpsPriviledgeLevel ) == 0 )
       
   585                 {
       
   586                 aPredecessor->AddL( CREATEKEY( EImpsKeyValue, 0 ) );
       
   587                 if( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
   588                     {
       
   589                     HBufC* newString = myPtr->AllocLC( );
       
   590                     HBufC* mystring = newString;
       
   591                     mystring->Des( ).UpperCase( );
       
   592                     if( mystring->CompareF( KImpsUser ) == 0 )
       
   593                         aPrivateP->SetPrivileges( EImpsOrdinary );
       
   594                     if( mystring->CompareF( KImpsMod ) == 0 )
       
   595                         aPrivateP->SetPrivileges( EImpsModerator );
       
   596                     if( mystring->CompareF( KImpsAdmin ) == 0 )
       
   597                         aPrivateP->SetPrivileges( EImpsAdmin );
       
   598                     CleanupStack::PopAndDestroy(1);
       
   599                     }
       
   600                 aPredecessor->PopL( ); // Pop out Value
       
   601                 }
       
   602             CleanupStack::PopAndDestroy(1);
       
   603             }
       
   604         else
       
   605             {
       
   606             more = EFalse;
       
   607             aPredecessor->PopL( );  // PopOut Name
       
   608             }
       
   609         aPredecessor->PopL( );      // Popout EImpsKeyProperty
       
   610         }
       
   611     aPredecessor->PopL( );           // Popout EImpsKeyOwnProperties
       
   612     }
       
   613 
       
   614 
       
   615 // ----------------------------------------------------------------------------
       
   616 // TImpsCDataUtils::GetBlockedListResponseL
       
   617 // ----------------------------------------------------------------------------
       
   618 //
       
   619 void TImpsCDataUtils::GetBlockedListResponseL( 
       
   620             MImpsKey* aKey,
       
   621             MImpsDataAccessor* aAc,
       
   622             CPtrC16Array*                 blockedList,
       
   623             TBool&                        blockedInUse,
       
   624             CPtrC16Array*                 grantedList,
       
   625             TBool&                        grantedInUse
       
   626             )
       
   627     {
       
   628     aKey->Reset();
       
   629     blockedList->Reset();
       
   630     grantedList->Reset();
       
   631     blockedInUse = EFalse;
       
   632     grantedInUse = EFalse;
       
   633     
       
   634     TImpsCDataUtils::AddValuesFromArrayL( 
       
   635         aKey, 
       
   636         KTransContentElements, 
       
   637         sizeof( KTransContentElements ) /
       
   638         sizeof( KTransContentElements[0] ) );
       
   639     aKey->AddL( CREATEKEY( EImpsKeyGetBlockedList_Response, 0 ) );
       
   640     aKey->AddL( CREATEKEY( EImpsKeyBlockList, 0 ) );
       
   641     if ( aAc->CheckBranchExistenceL( aKey ) )
       
   642         {
       
   643         // CSP says this is mandatory, DTD not
       
   644         aKey->AddL( CREATEKEY( EImpsKeyInUse, 0 ) );  
       
   645         aAc->RestoreBooleanL( aKey, blockedInUse );
       
   646         aKey->ReplaceLastL( CREATEKEY( EImpsKeyEntityList, 0 ) );
       
   647         // Search only UserIDs here in this version!!!
       
   648         // Get User*:UserID
       
   649         TBool more(ETrue);
       
   650         TDesC* myPtr;
       
   651         TInt i = 0;         // aux index
       
   652         for ( i = 0; more; i++)
       
   653             {
       
   654             aKey->AddL( CREATEKEY( EImpsKeyUserID, i ) );
       
   655             if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   656                 {
       
   657                 blockedList->AppendL( *myPtr );
       
   658                 }
       
   659             else
       
   660                 {
       
   661                 more = EFalse;
       
   662                 }
       
   663             aKey->PopL();
       
   664             }
       
   665         aKey->PopL();
       
   666         }  // EImpsKeyBlockList
       
   667     aKey->ReplaceLastL( CREATEKEY( EImpsKeyGrantList, 0 ) );
       
   668 
       
   669     if ( aAc->CheckBranchExistenceL( aKey ) )
       
   670         {
       
   671         // CSP says this is mandatory, DTD not
       
   672         aKey->AddL( CREATEKEY( EImpsKeyInUse, 0 ) );  
       
   673         aAc->RestoreBooleanL( aKey, grantedInUse );
       
   674         aKey->ReplaceLastL( CREATEKEY( EImpsKeyEntityList, 0 ) );
       
   675         // Search only UserIDs here in this version!!!
       
   676         // Get User*:UserID
       
   677         TBool more(ETrue);
       
   678         TDesC* myPtr;
       
   679         TInt i = 0;         // aux index
       
   680         for ( i = 0; more; i++)
       
   681             {
       
   682             aKey->AddL( CREATEKEY( EImpsKeyUserID, i ) );
       
   683             if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   684                 {
       
   685                 grantedList->AppendL( *myPtr );
       
   686                 }
       
   687             else
       
   688                 {
       
   689                 more = EFalse;
       
   690                 }
       
   691             aKey->PopL();
       
   692             }
       
   693         aKey->PopL();
       
   694         }  // EImpsKeyGrantList
       
   695 
       
   696 
       
   697     }
       
   698 
       
   699 // ----------------------------------------------------------------------------
       
   700 // TImpsCDataUtils::SetBlockedListRequestL
       
   701 // ----------------------------------------------------------------------------
       
   702 //
       
   703 void TImpsCDataUtils::SetBlockedListRequestL( 
       
   704             MImpsKey* aKey,
       
   705             MImpsDataAccessor* aAc,
       
   706             const MDesCArray* aBlockEntity,
       
   707             const MDesCArray* aUnBlockEntity,
       
   708             TBool aBlockedListInUse,
       
   709             const MDesCArray* aGrantedEntityList,
       
   710             const MDesCArray* aUnGrantEntity,
       
   711             TBool aGrantedListInUse
       
   712             )
       
   713     {
       
   714 
       
   715     TImpsCDataUtils::AddValuesFromArrayL( 
       
   716         aKey, 
       
   717         KTransContentElements, 
       
   718         sizeof( KTransContentElements ) /
       
   719         sizeof( KTransContentElements[0] ) );
       
   720     aKey->AddL( CREATEKEY( EImpsKeyBlockEntity_Request, 0 ) );
       
   721     aKey->AddL( CREATEKEY( EImpsKeyBlockList, 0 ) );        // blocklist
       
   722     aKey->AddL( CREATEKEY( EImpsKeyInUse, 0 ) );            // inuse
       
   723     aAc->StoreBooleanL( aKey, aBlockedListInUse );
       
   724     aKey->ReplaceLastL( CREATEKEY( EImpsKeyAddList, 0 ) ); // block: addlist
       
   725     TInt i = 0;
       
   726     TInt count = 0;
       
   727     if ( aBlockEntity )
       
   728         {
       
   729         count = aBlockEntity->MdcaCount();
       
   730         }
       
   731     for ( i = 0; i < count; i++ )
       
   732         {
       
   733         aKey->AddL( CREATEKEY( EImpsKeyUserID, i ) );
       
   734         aAc->StoreDescL( aKey, aBlockEntity->MdcaPoint( i ) );
       
   735         aKey->PopL();
       
   736         }
       
   737     // block: renovelist
       
   738     aKey->ReplaceLastL( CREATEKEY( EImpsKeyRemoveList, 0 ) ); 
       
   739     count = 0;
       
   740     if ( aUnBlockEntity )
       
   741         {
       
   742         count = aUnBlockEntity->MdcaCount();
       
   743         }
       
   744     for ( i = 0; i < count; i++ )
       
   745         {
       
   746         aKey->AddL( CREATEKEY( EImpsKeyUserID, i ) );
       
   747         aAc->StoreDescL( aKey, aUnBlockEntity->MdcaPoint( i ) );
       
   748         aKey->PopL();
       
   749         }
       
   750     aKey->PopL();   // addlist
       
   751     aKey->ReplaceLastL( CREATEKEY( EImpsKeyGrantList, 0 ) );   // grantList
       
   752     aKey->AddL( CREATEKEY( EImpsKeyInUse, 0 ) ); 
       
   753     aAc->StoreBooleanL( aKey, aGrantedListInUse );
       
   754     aKey->ReplaceLastL( CREATEKEY( EImpsKeyAddList, 0 ) );    // grant:addlist
       
   755     count = 0;
       
   756     if ( aGrantedEntityList )
       
   757         {
       
   758         count = aGrantedEntityList->MdcaCount();
       
   759         }
       
   760     for ( i = 0; i < count; i++ )
       
   761         {
       
   762         aKey->AddL( CREATEKEY( EImpsKeyUserID, i ) );
       
   763         aAc->StoreDescL( aKey, aGrantedEntityList->MdcaPoint( i ) );
       
   764         aKey->PopL();
       
   765         }
       
   766 
       
   767     aKey->ReplaceLastL( CREATEKEY( EImpsKeyRemoveList, 0 ) ); // grant: removelist
       
   768     count = 0;
       
   769     if ( aUnGrantEntity )
       
   770         {
       
   771         count = aUnGrantEntity->MdcaCount();
       
   772         }
       
   773     for ( i = 0; i < count; i++ )
       
   774         {
       
   775         aKey->AddL( CREATEKEY( EImpsKeyUserID, i ) );
       
   776         aAc->StoreDescL( aKey, aUnGrantEntity->MdcaPoint( i ) );
       
   777         aKey->PopL();
       
   778         }
       
   779     }
       
   780 
       
   781 
       
   782 
       
   783 
       
   784 
       
   785 // ----------------------------------------------------------------------------
       
   786 // TImpsCDataUtils::GetDetailedResultL
       
   787 // ----------------------------------------------------------------------------
       
   788 //
       
   789 TBool TImpsCDataUtils::GetDetailedResultL( 
       
   790     MImpsKey* aKey,
       
   791     MImpsDataAccessor* aAc,
       
   792     TPtrC& aDescription,
       
   793     CImpsDetailed*& aDetailed )
       
   794     {
       
   795 
       
   796     TImpsCDataUtils::AddValuesFromArrayL( 
       
   797         aKey, 
       
   798         KTransContentElements, 
       
   799         sizeof( KTransContentElements ) /
       
   800         sizeof( KTransContentElements[0] ) );
       
   801 
       
   802     TBool ret(EFalse);
       
   803     TInt enumi(0);
       
   804     TInt index(0);
       
   805     TInt error(0);
       
   806     TImpsKeyType type;
       
   807     if( aAc->RestoreAlternativeL( aKey, enumi, index, type ) )
       
   808         {
       
   809         switch ( enumi )
       
   810             {
       
   811             case EImpsKeyStatus:
       
   812             case EImpsKeyLogin_Response:
       
   813             case EImpsKeyDisconnect:
       
   814             case EImpsKeyKeepAlive_Response:
       
   815             case EImpsKeyGetPresence_Response:
       
   816             case EImpsKeyListManage_Response:
       
   817             case EImpsKeyGetAttributeList_Response:
       
   818             case EImpsKeySendMessage_Response:
       
   819             case EImpsKeyDeliveryReport_Request:
       
   820             case EImpsKeyLeaveGroup_Response:
       
   821                 aKey->AddL( enumi, type );
       
   822                 aKey->AddL( EImpsKeyResult );
       
   823                 aKey->AddL( EImpsKeyCode );
       
   824                 if( aAc->RestoreIntegerL( aKey, error ) )
       
   825                     ret = ETrue;
       
   826                 break;
       
   827             default:
       
   828               break;
       
   829             }
       
   830         }
       
   831     if( ret )
       
   832         {
       
   833         // Key allready contains code and result
       
   834         // Pop out the code
       
   835         aKey->PopL( );
       
   836 
       
   837         TDesC* myPtr;   
       
   838         aKey->AddL( CREATEKEY( EImpsKeyDescription, 0 ) ); 
       
   839         if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   840             {
       
   841             // description found
       
   842             aDescription.Set( *myPtr );
       
   843             }
       
   844         
       
   845         // Handle actual detailed part on if
       
   846         // error is  201 or 900
       
   847 
       
   848         if ( error == 201 || error == 900 )        
       
   849             {
       
   850             TBool more(ETrue);
       
   851             TInt myInt;
       
   852             for ( TInt i = 0; more; i++ )
       
   853                 {
       
   854                 aKey->ReplaceLastL( CREATEKEY( EImpsKeyDetailedResult, i ) );
       
   855                 if ( aAc->CheckBranchExistenceL( aKey ) )
       
   856                     {
       
   857                     CImpsDetailedResult* oneRes = CImpsDetailedResult::NewL();
       
   858                     CleanupStack::PushL( oneRes );      // <<< oneRes
       
   859                     // Code
       
   860                     aKey->AddL( CREATEKEY( EImpsKeyCode, 0 ) );
       
   861                     // Notice: if we have validator then we do not need to check that
       
   862                     if ( aAc->RestoreIntegerL( aKey, myInt ) )
       
   863                         {
       
   864                         oneRes->SetCode( myInt );
       
   865                         }
       
   866                     // Description?
       
   867                     aKey->ReplaceLastL( CREATEKEY( EImpsKeyDescription, 0 ) );
       
   868                     if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   869                         {
       
   870                         oneRes->SetDescriptorL( *myPtr );
       
   871                         }
       
   872                     // UserID*
       
   873                     TBool more2(ETrue);
       
   874 
       
   875                     TInt j = 0;
       
   876                     for ( j = 0; more2; j++ )
       
   877                         {
       
   878                         aKey->ReplaceLastL( CREATEKEY( EImpsKeyUserID, j ) );
       
   879                         if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   880                             {
       
   881                             CPtrC16Array* users = oneRes->UserIds();
       
   882                             users->AppendL( *myPtr );
       
   883                             }
       
   884                         else
       
   885                             {
       
   886                             more2 = EFalse;
       
   887                             }
       
   888                         }
       
   889 
       
   890                     // GroupId*
       
   891                     more2 = ETrue;
       
   892                     for ( j = 0; more2; j++ )
       
   893                         {
       
   894                         aKey->ReplaceLastL( CREATEKEY( EImpsKeyGroupID, j ) );
       
   895                         if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   896                             {
       
   897                             CPtrC16Array* grs = oneRes->GroupIds();
       
   898                             grs->AppendL( *myPtr );
       
   899                             }
       
   900                         else
       
   901                             {
       
   902                             more2 = EFalse;
       
   903                             }
       
   904                         }
       
   905 
       
   906                     // ScreenName*
       
   907                     more2 = ETrue;
       
   908                     for ( j = 0; more2; j++ )
       
   909                         {
       
   910                         aKey->ReplaceLastL( CREATEKEY( EImpsKeyScreenName, j ) );
       
   911                         if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   912                             {
       
   913                             // This bastard has two elements SName, GroupId
       
   914                             CPtrC16Array* sn = oneRes->SNames();
       
   915                             CPtrC16Array* sng = oneRes->SNameGroups();
       
   916                             aKey->AddL( CREATEKEY( EImpsKeySName, 0 ) );
       
   917                             if ( aAc->RestoreDescL( aKey, myPtr ))
       
   918                                 {
       
   919                                 sn->AppendL( *myPtr );
       
   920                                 }
       
   921                             aKey->ReplaceLastL( CREATEKEY( EImpsKeyGroupID, 0 ) );
       
   922                             if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   923                                 {
       
   924                                 sng->AppendL( *myPtr );
       
   925                                 }
       
   926                             aKey->PopL();
       
   927                             }
       
   928                         else
       
   929                             {
       
   930                             more2 = EFalse;
       
   931                             }
       
   932                         }
       
   933 
       
   934                     // MessageId*
       
   935                     more2 = ETrue;
       
   936                     for ( j = 0; more2; j++ )
       
   937                         {
       
   938                         aKey->ReplaceLastL( CREATEKEY( EImpsKeyMessageID, j ) );
       
   939                         if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   940                             {
       
   941                             CPtrC16Array* msgs = oneRes->MessageIds();
       
   942                             msgs->AppendL( *myPtr );
       
   943                             }
       
   944                         else
       
   945                             {
       
   946                             more2 = EFalse;
       
   947                             }
       
   948                         }
       
   949 
       
   950                     aDetailed->AppendL( oneRes );   // myDet destructor should delete oneRes
       
   951                     CleanupStack::Pop(1);       // >>> oneRes
       
   952                     // Pop out the lasd one
       
   953                     aKey->PopL( );
       
   954                     }
       
   955                 else
       
   956                     {
       
   957                     more = EFalse;
       
   958                     break;
       
   959                     }
       
   960                 }       // for
       
   961             }  // 201/900
       
   962         }
       
   963     return ret;
       
   964     }
       
   965 
       
   966 // -----------------------------------------------------------------------------
       
   967 // TImpsCDataUtils::SetContentTypeL
       
   968 // -----------------------------------------------------------------------------
       
   969 //
       
   970 void TImpsCDataUtils::SetContentTypeL( 
       
   971     MImpsDataAccessor* aAc,
       
   972     TPtrC& aContentType )
       
   973     {
       
   974     CImpsKey* myKey = CImpsKey::NewLC(); // << myKey
       
   975     TImpsDataUtils::AddValuesFromArrayL( 
       
   976         myKey, 
       
   977         KSendMessageElements, 
       
   978         sizeof( KSendMessageElements ) /
       
   979         sizeof( KSendMessageElements[0] ) );
       
   980         
       
   981     myKey->AddL( CREATEKEY( EImpsKeyMessageInfo, 0 ) );
       
   982     myKey->AddL( CREATEKEY( EImpsKeyContentType, 0 ) );    
       
   983     aAc->StoreDescL( myKey, aContentType );
       
   984     CleanupStack::PopAndDestroy(); //  >>> myKey
       
   985     }      
       
   986 
       
   987 // -----------------------------------------------------------------------------
       
   988 // TImpsCDataUtils::GetContentEncodingL
       
   989 // -----------------------------------------------------------------------------
       
   990 //
       
   991 void TImpsCDataUtils::GetContentEncodingL( 
       
   992     MImpsDataAccessor* aAc,
       
   993     TInt& aEncoding )
       
   994     {
       
   995     CImpsKey* myKey = CImpsKey::NewLC(); // << myKey
       
   996     TImpsDataUtils::AddValuesFromArrayL( 
       
   997         myKey, 
       
   998         KNewMessageElements, 
       
   999         sizeof( KNewMessageElements ) /
       
  1000         sizeof( KNewMessageElements[0] ) );
       
  1001         
       
  1002     myKey->AddL( CREATEKEY( EImpsKeyMessageInfo, 0 ) );
       
  1003     myKey->AddL( CREATEKEY( EImpsKeyContentEncoding, 0 ) );    
       
  1004     aAc->RestoreIntegerL( myKey, aEncoding );
       
  1005     CleanupStack::PopAndDestroy(); //  >>> myKey
       
  1006     }   
       
  1007     
       
  1008 // ----------------------------------------------------------------------------
       
  1009 // TImpsCDataUtils::GetUserMapListL
       
  1010 // ----------------------------------------------------------------------------
       
  1011 void TImpsCDataUtils::GetUserMapListL(
       
  1012             MImpsKey* aPredecessor,
       
  1013             MImpsDataAccessor* aAc,
       
  1014             CDesCArray* aUsers,
       
  1015             CDesCArray* aScreenNames )
       
  1016     {
       
  1017     aPredecessor->AddL( CREATEKEY( EImpsKeyUserMapping, 0 ) );
       
  1018     // Get first the users
       
  1019     TBool more(ETrue);
       
  1020     TDesC* myPtr;
       
  1021     TInt i = 0;         // aux index
       
  1022     for ( i = 0; more; i++)
       
  1023         {
       
  1024         aPredecessor->AddL( CREATEKEY( EImpsKeyMapping, i ) );
       
  1025         aPredecessor->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
  1026         if ( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
  1027             {
       
  1028             aUsers->AppendL( *myPtr );
       
  1029             }
       
  1030         else
       
  1031             {
       
  1032             more = EFalse;
       
  1033             }
       
  1034         aPredecessor->PopL( 2 );
       
  1035         }
       
  1036     // Then get the screennames
       
  1037     more = ETrue;
       
  1038     for ( i = 0; more; i++)
       
  1039         {
       
  1040         aPredecessor->AddL( CREATEKEY( EImpsKeyMapping, i ) );
       
  1041         aPredecessor->AddL( CREATEKEY( EImpsKeySName, 0 ) );
       
  1042         if ( aAc->RestoreDescL( aPredecessor, myPtr ) )
       
  1043             {
       
  1044             aScreenNames->AppendL( *myPtr );
       
  1045             }
       
  1046         else
       
  1047             {
       
  1048             more = EFalse;
       
  1049             }
       
  1050         aPredecessor->PopL( 2 );
       
  1051         }
       
  1052     aPredecessor->PopL( ); // UserMapping
       
  1053     }
       
  1054    
       
  1055 //  End of File  
       
  1056