IMPSengine/datautils/src/impsdatautils.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002 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: Util classes for imps data accessor
       
    15 * 
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <e32base.h>
       
    21 #include    <centralrepository.h>
       
    22 #include    <imcvcodc.h>
       
    23 #include	<miutconv.h>
       
    24 #include    "impskey.h"
       
    25 #include    "impsdatautils.h"
       
    26 #include    "impsdataaccessor.h"
       
    27 #include    "impsliterals.h"
       
    28 #include    "wvengineinternalcrkeys.h"
       
    29 
       
    30 // ================= MEMBER FUNCTIONS =======================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // TImpsDataUtils::TImpsDataUtils(
       
    34 // -----------------------------------------------------------------------------
       
    35 EXPORT_C TImpsDataUtils::TImpsDataUtils()
       
    36     {
       
    37     }
       
    38    
       
    39 // -----------------------------------------------------------------------------
       
    40 // TImpsDataUtils::GetSenderL
       
    41 // -----------------------------------------------------------------------------
       
    42 EXPORT_C void TImpsDataUtils::GetSenderL(
       
    43             MImpsKey* aKey, 
       
    44             MImpsDataAccessor* aAc,
       
    45             TPtrC& aSender,      // Sender(User(UserID) or ScreenName if a GroupID
       
    46             TPtrC& aGroup)       // Sender(ScreenName(SName, GroupID))
       
    47     {
       
    48 
       
    49     aKey->AddL( CREATEKEY( EImpsKeySender, 0 ) );
       
    50 
       
    51     // Get User:UserID
       
    52     TDesC* myPtr;
       
    53     aKey->AddL( CREATEKEY( EImpsKeyUser, 0 ) );
       
    54     aKey->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
    55     if ( aAc->RestoreDescL( aKey, myPtr ) )
       
    56         {
       
    57         aSender.Set( *myPtr );
       
    58         aGroup.Set( KNullDesC );
       
    59         aKey->PopL( 2 );       // UserID, User
       
    60         }
       
    61     else
       
    62         {
       
    63         aKey->PopL( 2 );       // UserID, User
       
    64         aKey->AddL( CREATEKEY( EImpsKeyGroup, 0 ) );
       
    65         aKey->AddL( CREATEKEY( EImpsKeyScreenName, 0 ) );    
       
    66         aKey->AddL( CREATEKEY( EImpsKeySName, 0 ) ); 
       
    67         if ( aAc->RestoreDescL( aKey, myPtr ) )        
       
    68             {
       
    69 			if( myPtr )
       
    70                 aSender.Set( *myPtr );
       
    71             else
       
    72                 aSender.Set( KNullDesC );
       
    73             aKey->ReplaceLastL( CREATEKEY( EImpsKeyGroupID, 0 ) ); 
       
    74             aAc->RestoreDescL( aKey, myPtr );
       
    75             if( myPtr )
       
    76                 aGroup.Set( *myPtr );
       
    77             else
       
    78                 aGroup.Set( KNullDesC );
       
    79             }
       
    80         aKey->PopL( 3 );
       
    81         }
       
    82 
       
    83     aKey->PopL();   // Sender
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // TImpsDataUtils::SetSenderL
       
    88 // -----------------------------------------------------------------------------
       
    89 EXPORT_C void TImpsDataUtils::SetSenderL(
       
    90             MImpsKey* aKey,
       
    91             MImpsDataAccessor* aAc,
       
    92             const TDesC* aSender,
       
    93             const TDesC* aGroupId )
       
    94     {
       
    95     aKey->AddL( CREATEKEY( EImpsKeySender, 0 ) );
       
    96 
       
    97     if ( aSender && !aGroupId )
       
    98         {
       
    99         // Pure UserID
       
   100         aKey->AddL( CREATEKEY( EImpsKeyUser, 0 ) );
       
   101         aKey->AddL( CREATEKEY( EImpsKeyUserID, 0 ) );
       
   102         aAc->StoreDescL( aKey, *aSender );
       
   103         aKey->PopL( 2 );
       
   104         }
       
   105     else if ( aSender && aGroupId )
       
   106         {
       
   107         // Screen Name
       
   108         aKey->AddL( CREATEKEY( EImpsKeyGroup, 0 ) );
       
   109         aKey->AddL( CREATEKEY( EImpsKeyScreenName, 0 ) );
       
   110         aKey->AddL( CREATEKEY( EImpsKeySName, 0 ) );
       
   111         aAc->StoreDescL( aKey, *aSender );
       
   112         aKey->ReplaceLastL( CREATEKEY( EImpsKeyGroupID, 0 ) );
       
   113         aAc->StoreDescL( aKey, *aGroupId );
       
   114         aKey->PopL( 3 );
       
   115         }
       
   116     else if ( !aSender && aGroupId )
       
   117         {
       
   118         // Sender is Group, well ... maybe it is possible in principle
       
   119         aKey->AddL( CREATEKEY( EImpsKeyGroup, 0 ) );
       
   120         aKey->AddL( CREATEKEY( EImpsKeyGroupID, 0 ) );
       
   121         aAc->StoreDescL( aKey, *aGroupId );
       
   122         aKey->PopL( 2 );
       
   123         }
       
   124 
       
   125     aKey->PopL();
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // TImpsDataUtils::SetContentDataL
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 EXPORT_C void TImpsDataUtils::SetContentDataL( 
       
   133     MImpsKey* aKey,
       
   134     MImpsDataAccessor* aAc,
       
   135     const TDesC& aContent )
       
   136     {
       
   137 	if ( aContent.Length() > 0 )
       
   138 		{		
       
   139     aKey->AddL( CREATEKEY( EImpsKeyContentData, 0 ) );
       
   140 	    aAc->StoreDescL( aKey, aContent );
       
   141     aKey->PopL();
       
   142 		}
       
   143 	else
       
   144 		{
       
   145 		TPtrC p;
       
   146 		p.Set( KNullDesC );
       
   147 	    aKey->AddL( CREATEKEY( EImpsKeyContentData, 0 ) );
       
   148     	aAc->StoreDescL( aKey, p );
       
   149     	aKey->PopL();
       
   150 		}
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // TImpsDataUtils::GetContentDataL
       
   155 // version for 16-bit
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 EXPORT_C void TImpsDataUtils::GetContentDataL( 
       
   159     MImpsKey* aKey,
       
   160     MImpsDataAccessor* aAc,
       
   161     TPtrC& aContent )
       
   162     {
       
   163     TDesC* myPtr;
       
   164     aKey->AddL( CREATEKEY( EImpsKeyContentData, 0 ) );
       
   165     if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   166         {
       
   167         aContent.Set( *myPtr );
       
   168         }
       
   169     else
       
   170         {
       
   171         aContent.Set( KNullDesC );
       
   172         }
       
   173     aKey->PopL();
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // TImpsDataUtils::SetResultStatusL
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C void TImpsDataUtils::SetResultStatusL( 
       
   181     MImpsKey* aKey,
       
   182     MImpsDataAccessor* aAc,
       
   183     TInt aCode )
       
   184     {
       
   185     aKey->Reset();  // OPa
       
   186 
       
   187     TImpsDataUtils::AddValuesFromArrayL( 
       
   188         aKey, 
       
   189         KSetResultCodeElements, 
       
   190         sizeof( KSetResultCodeElements ) /
       
   191         sizeof( KSetResultCodeElements[0] ) );
       
   192     aAc->StoreIntegerL( aKey, aCode );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // TImpsDataUtils::GetResultStatusL
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C TBool TImpsDataUtils::GetResultStatusL( 
       
   200     MImpsKey* aKey,
       
   201     MImpsDataAccessor* aAc,
       
   202     TInt& aCode )
       
   203     {
       
   204 
       
   205     aKey->Reset();  // OPa
       
   206 
       
   207     TImpsDataUtils::AddValuesFromArrayL( 
       
   208         aKey, 
       
   209         KTransContentElements, 
       
   210         sizeof( KTransContentElements ) /
       
   211         sizeof( KTransContentElements[0] ) );
       
   212 
       
   213     TBool ret(EFalse);
       
   214     TInt enumi(0);
       
   215     TInt index(0);
       
   216     TImpsKeyType type;
       
   217     if( aAc->RestoreAlternativeL( aKey, enumi, index, type ) )
       
   218         {
       
   219         switch ( enumi )
       
   220             {
       
   221             case EImpsKeyStatus:
       
   222             case EImpsKeyLogin_Response:
       
   223             case EImpsKeyDisconnect:
       
   224             case EImpsKeyKeepAlive_Response:
       
   225             case EImpsKeyGetPresence_Response:
       
   226             case EImpsKeyListManage_Response:
       
   227             case EImpsKeyGetAttributeList_Response:
       
   228             case EImpsKeySendMessage_Response:
       
   229             case EImpsKeyDeliveryReport_Request:
       
   230             case EImpsKeyLeaveGroup_Response:
       
   231                 aKey->AddL( enumi, type );
       
   232                 aKey->AddL( EImpsKeyResult );
       
   233                 aKey->AddL( EImpsKeyCode );
       
   234                 if( aAc->RestoreIntegerL( aKey, aCode ) )
       
   235                     ret = ETrue;
       
   236                 break;
       
   237             default:
       
   238               break;
       
   239             }
       
   240         }
       
   241     return ret;
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // TImpsDataUtils::GetNewMessageIdL
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 EXPORT_C TBool TImpsDataUtils::GetNewMessageIdL( 
       
   249             MImpsKey* aKey,
       
   250             MImpsDataAccessor* aAc,
       
   251             TPtrC& aId )
       
   252     {
       
   253 
       
   254     aKey->Reset();
       
   255 
       
   256     TImpsDataUtils::AddValuesFromArrayL( 
       
   257         aKey, 
       
   258         KTransContentElements, 
       
   259         sizeof( KTransContentElements ) /
       
   260         sizeof( KTransContentElements[0] ) );
       
   261 
       
   262     aKey->AddL( CREATEKEY( EImpsKeyNewMessage, 0 ) );
       
   263     aKey->AddL( CREATEKEY( EImpsKeyMessageInfo, 0 ) );
       
   264     aKey->AddL( CREATEKEY( EImpsKeyMessageID, 0 ) );
       
   265 
       
   266     TDesC* myPtr;
       
   267     if ( aAc->RestoreDescL( aKey, myPtr ) )
       
   268         {
       
   269         aId.Set( *myPtr );
       
   270         return ETrue;
       
   271         }
       
   272     else
       
   273         {
       
   274         aId.Set( KNullDesC );
       
   275         }
       
   276 
       
   277     return EFalse;
       
   278 
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // TImpsDataUtils::CreateClientIdL
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 EXPORT_C void TImpsDataUtils::CreateClientIdL( 
       
   286             MImpsKey* aKey,
       
   287             MImpsDataAccessor* aAc,
       
   288             const TDesC& aClientId )
       
   289     {
       
   290     aKey->AddL( CREATEKEY( EImpsKeyClientID, 0 ) );
       
   291     // '+' prefix or all numbers means MSISDN, other is URL
       
   292 
       
   293     TInt len = aClientId.Length( );
       
   294     TInt i(0);
       
   295     TBool isMSISDN( ETrue );
       
   296     for( i = 0; i < len; i++)
       
   297         {
       
   298         TChar cha = aClientId[i];
       
   299         if( !i && !( cha == '+' || cha.IsDigit( ) ) )
       
   300             {
       
   301             isMSISDN = EFalse;
       
   302             break;
       
   303             }
       
   304         if( i && !cha.IsDigit( ) )
       
   305             {
       
   306             isMSISDN = EFalse;
       
   307             break;
       
   308             }
       
   309         }
       
   310     if ( isMSISDN )
       
   311         {
       
   312         aKey->AddL( CREATEKEY( EImpsKeyMSISDN, 0 ) );
       
   313         }
       
   314     else
       
   315         {
       
   316         aKey->AddL( CREATEKEY( EImpsKeyURL, 0 ) );
       
   317         }
       
   318     aAc->StoreDescL( aKey, aClientId );
       
   319     aKey->PopL( 2 );
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // TImpsDataUtils::GetMessageTypeL
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 EXPORT_C TInt TImpsDataUtils::GetMessageTypeL( MImpsDataAccessor* aAc )
       
   327     {
       
   328     CImpsKey* myKey = CImpsKey::NewLC();
       
   329     myKey->AddL( CREATEKEY( EImpsKeySession, 0) );
       
   330     myKey->AddL( CREATEKEY( EImpsKeyTransaction, 0 ) );
       
   331     myKey->AddL( CREATEKEY( EImpsKeyTransactionContent, 0 ) );
       
   332     TInt enumi( 0 );
       
   333     TInt index( 0 );
       
   334     TImpsKeyType type( EImpsKeyTypeIM );
       
   335     if( aAc->RestoreAlternativeL( myKey, enumi, index, type ) )
       
   336         {
       
   337         CleanupStack::PopAndDestroy( );  //myKey
       
   338         return enumi;
       
   339         }
       
   340 
       
   341     CleanupStack::PopAndDestroy( );  //myKey
       
   342     return EImpsMessageNone;
       
   343 
       
   344     }
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // TImpsDataUtils::GetTransactionIDL
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 EXPORT_C void TImpsDataUtils::GetTransactionIDL( 
       
   351     MImpsDataAccessor* aAc, TPtrC& aID  )
       
   352     {
       
   353     TDesC* myPtr;
       
   354     CImpsKey* myKey = CImpsKey::NewLC();
       
   355     myKey->AddL( CREATEKEY( EImpsKeySession, 0) );
       
   356     myKey->AddL( CREATEKEY( EImpsKeyTransaction, 0 ) );
       
   357     myKey->AddL( CREATEKEY( EImpsKeyTransactionDescriptor, 0 ) );
       
   358     myKey->AddL( CREATEKEY( EImpsKeyTransactionID, 0 ) );
       
   359     if( aAc->RestoreDescL( myKey, myPtr ) )
       
   360         aID.Set( *myPtr );
       
   361     else
       
   362         aID.Set( KNullDesC );
       
   363     CleanupStack::PopAndDestroy( );  //myKey
       
   364     }
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // TImpsDataUtils::SetTransactionIDL
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 EXPORT_C void TImpsDataUtils::SetTransactionIDL( 
       
   371     MImpsDataAccessor* aAc, const TDesC& aID  )
       
   372     {
       
   373     CImpsKey* myKey = CImpsKey::NewLC();
       
   374     myKey->AddL( CREATEKEY( EImpsKeySession, 0) );
       
   375     myKey->AddL( CREATEKEY( EImpsKeyTransaction, 0 ) );
       
   376     myKey->AddL( CREATEKEY( EImpsKeyTransactionDescriptor, 0 ) );
       
   377     myKey->AddL( CREATEKEY( EImpsKeyTransactionID, 0 ) );
       
   378     aAc->StoreDescL( myKey, aID );
       
   379     CleanupStack::PopAndDestroy( );  //myKey
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // TImpsDataUtils::GetSessionIDL
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 EXPORT_C void TImpsDataUtils::GetSessionIDL( MImpsDataAccessor* aAc, TPtrC& aID  )
       
   387     {
       
   388     TDesC* myPtr;
       
   389     CImpsKey* myKey = CImpsKey::NewLC();
       
   390     myKey->AddL( CREATEKEY( EImpsKeySession, 0) );
       
   391     myKey->AddL( CREATEKEY( EImpsKeySessionDescriptor, 0 ) );
       
   392     myKey->AddL( CREATEKEY( EImpsKeySessionID, 0 ) );
       
   393     if( aAc->RestoreDescL( myKey, myPtr ) )
       
   394         aID.Set( *myPtr );
       
   395     else
       
   396         aID.Set( KNullDesC );
       
   397     CleanupStack::PopAndDestroy( );  //myKey
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // TImpsDataUtils::SetSessionIDL
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 EXPORT_C void TImpsDataUtils::SetSessionIDL( MImpsDataAccessor* aAc, const TDesC& aID  )
       
   405     {
       
   406     CImpsKey* myKey = CImpsKey::NewLC();
       
   407     myKey->AddL( CREATEKEY( EImpsKeySession, 0) );
       
   408     myKey->AddL( CREATEKEY( EImpsKeySessionDescriptor, 0 ) );
       
   409     myKey->AddL( CREATEKEY( EImpsKeySessionID, 0 ) );
       
   410     aAc->StoreDescL( myKey, aID );
       
   411     CleanupStack::PopAndDestroy( );  //myKey
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // TImpsDataUtils::GetSessionTypeL
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 EXPORT_C void TImpsDataUtils::GetSessionTypeL( 
       
   419     MImpsDataAccessor* aAc, TImpsSessionType& aID  )
       
   420     {
       
   421     CImpsKey* myKey = CImpsKey::NewLC();
       
   422     myKey->AddL( CREATEKEY( EImpsKeySession, 0) );
       
   423     myKey->AddL( CREATEKEY( EImpsKeySessionDescriptor, 0 ) );
       
   424     myKey->AddL( CREATEKEY( EImpsKeySessionType, 0 ) );
       
   425     TInt id;
       
   426     if( aAc->RestoreIntegerL( myKey, id ) )
       
   427         aID = ( TImpsSessionType ) id;
       
   428     else
       
   429         aID = EImpsUndefSes;
       
   430     CleanupStack::PopAndDestroy( );  //myKey
       
   431     }
       
   432 
       
   433 // -----------------------------------------------------------------------------
       
   434 // TImpsDataUtils::SetSessionTypeL
       
   435 // -----------------------------------------------------------------------------
       
   436 //
       
   437 EXPORT_C void TImpsDataUtils::SetSessionTypeL( 
       
   438     MImpsDataAccessor* aAc, const TImpsSessionType aType )
       
   439     {
       
   440     CImpsKey* myKey = CImpsKey::NewLC();
       
   441     myKey->AddL( CREATEKEY( EImpsKeySession, 0) );
       
   442     myKey->AddL( CREATEKEY( EImpsKeySessionDescriptor, 0 ) );
       
   443     myKey->AddL( CREATEKEY( EImpsKeySessionType, 0 ) );
       
   444     aAc->StoreIntegerL( myKey, aType );
       
   445     CleanupStack::PopAndDestroy( );  //myKey
       
   446     }
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // TImpsDataUtils::GetPollL
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 EXPORT_C TBool TImpsDataUtils::GetPollL( 
       
   453     MImpsKey* aKey,
       
   454     MImpsDataAccessor* aAc,
       
   455     TBool& aBool )
       
   456     {
       
   457     CImpsFields* fields = aAc->GetImpsFields();
       
   458     if ( fields->CspVersion() == EImpsCspVersion11 )
       
   459         {
       
   460         TImpsDataUtils::AddValuesFromArrayL( 
       
   461         aKey, 
       
   462         KGetPollElements, 
       
   463         sizeof( KGetPollElements ) /
       
   464         sizeof( KGetPollElements[0] ) );
       
   465         }
       
   466     else
       
   467         {
       
   468         TImpsDataUtils::AddValuesFromArrayL( 
       
   469             aKey, 
       
   470             KGet12PollElements, 
       
   471             sizeof( KGet12PollElements ) /
       
   472             sizeof( KGet12PollElements[0] ) );
       
   473         }
       
   474     if( aAc->RestoreBooleanL( aKey, aBool ))
       
   475         {
       
   476         return ETrue;
       
   477         }
       
   478     return EFalse;
       
   479     }
       
   480 
       
   481 
       
   482 // -----------------------------------------------------------------------------
       
   483 // TImpsDataUtils::AddValuesFromArrayL
       
   484 // Add values to a key straight from an array
       
   485 // -----------------------------------------------------------------------------
       
   486 //											    
       
   487 EXPORT_C void TImpsDataUtils::AddValuesFromArrayL( 
       
   488     MImpsKey* aImpsKey, const TImpsContent* aElementArray, TInt aSize )
       
   489     {
       
   490     for( TInt i = 0; i < aSize; i++ )
       
   491         {
       
   492         aImpsKey->AddL( CREATEKEY( aElementArray[i], 0 ) );
       
   493         }
       
   494     }
       
   495 
       
   496 // ---------------------------------------------------------
       
   497 // TImpsDataUtils::CopyNewUsersL
       
   498 // ---------------------------------------------------------
       
   499 //
       
   500 EXPORT_C void TImpsDataUtils::CopyNewUsersL( 
       
   501             MImpsDataAccessor& aSource,
       
   502             MImpsDataAccessor& aDestination)
       
   503     {
       
   504     CImpsKey* myKey = CImpsKey::NewLC(); // << myKey
       
   505     TImpsDataUtils::AddValuesFromArrayL( 
       
   506         myKey, 
       
   507         KTransContentElements, 
       
   508         sizeof( KTransContentElements ) /
       
   509         sizeof( KTransContentElements[0] ) );
       
   510    
       
   511     myKey->AddL( CREATEKEY( EImpsKeyGroupChangeNotice, 0 ) );
       
   512     myKey->AddL( CREATEKEY( EImpsKeyJoined, 0 ) );
       
   513         
       
   514     // copy joined users
       
   515     aDestination.CopyDataL(aSource, myKey);
       
   516 
       
   517     CleanupStack::PopAndDestroy( );           // >> myKey
       
   518     }
       
   519 // ---------------------------------------------------------
       
   520 // TImpsDataUtils::CopyLeftUsersL
       
   521 // ---------------------------------------------------------
       
   522 //
       
   523 EXPORT_C void TImpsDataUtils::CopyLeftUsersL( 
       
   524             MImpsDataAccessor& aSource,
       
   525             MImpsDataAccessor& aDestination)
       
   526     {
       
   527     CImpsKey* myKey = CImpsKey::NewLC(); // << myKey
       
   528     TImpsDataUtils::AddValuesFromArrayL( 
       
   529         myKey, 
       
   530         KTransContentElements, 
       
   531         sizeof( KTransContentElements ) /
       
   532         sizeof( KTransContentElements[0] ) );
       
   533    
       
   534     myKey->AddL( CREATEKEY( EImpsKeyGroupChangeNotice, 0 ) );
       
   535     myKey->AddL( CREATEKEY( EImpsKeyLeft, 0 ) );
       
   536         
       
   537     // copy left users
       
   538     aDestination.CopyDataL(aSource, myKey);
       
   539 
       
   540     CleanupStack::PopAndDestroy( );           // >> myKey
       
   541     }
       
   542     
       
   543 // ---------------------------------------------------------
       
   544 // TImpsDataUtils::CopyGroupPropertiesL
       
   545 // ---------------------------------------------------------
       
   546 //
       
   547 EXPORT_C void TImpsDataUtils::CopyGroupPropertiesL( 
       
   548             MImpsDataAccessor& aSource,
       
   549             MImpsDataAccessor& aDestination)
       
   550     {
       
   551     CImpsKey* myKey = STATIC_CAST (CImpsKey*, aSource.NewKeyL()); 
       
   552     CleanupStack::PushL(myKey);         // << myKey
       
   553 
       
   554     TImpsDataUtils::AddValuesFromArrayL( 
       
   555         myKey, 
       
   556         KTransContentElements, 
       
   557         sizeof( KTransContentElements ) /
       
   558         sizeof( KTransContentElements[0] ) );
       
   559 
       
   560     TInt primitive(0);
       
   561     TInt index(0);
       
   562     TImpsKeyType type;
       
   563     if( aSource.RestoreAlternativeL( myKey, primitive, index, type ) )
       
   564         {
       
   565         myKey->AddL( CREATEKEY( primitive, 0 ) );
       
   566         myKey->AddL( CREATEKEY( EImpsKeyGroupProperties, 0 ) );
       
   567         
       
   568         // copy left users
       
   569         aDestination.CopyDataL(aSource, myKey);
       
   570 
       
   571         CleanupStack::PopAndDestroy( );           // >> myKey
       
   572         }
       
   573     }
       
   574     
       
   575 // ---------------------------------------------------------
       
   576 // TImpsDataUtils::CopyOwnPropertiesL
       
   577 // ---------------------------------------------------------
       
   578 //
       
   579 EXPORT_C void TImpsDataUtils::CopyOwnPropertiesL( 
       
   580             MImpsDataAccessor& aSource,
       
   581             MImpsDataAccessor& aDestination)
       
   582     {
       
   583     CImpsKey* myKey = STATIC_CAST (CImpsKey*, aSource.NewKeyL()); 
       
   584     CleanupStack::PushL(myKey);         // << myKey
       
   585 
       
   586     TImpsDataUtils::AddValuesFromArrayL( 
       
   587         myKey, 
       
   588         KTransContentElements, 
       
   589         sizeof( KTransContentElements ) /
       
   590         sizeof( KTransContentElements[0] ) );
       
   591 
       
   592     TInt primitive(0);
       
   593     TInt index(0);
       
   594     TImpsKeyType type;
       
   595     if( aSource.RestoreAlternativeL( myKey, primitive, index, type ) )
       
   596         {
       
   597         myKey->AddL( CREATEKEY( primitive, 0 ) );
       
   598         myKey->AddL( CREATEKEY( EImpsKeyOwnProperties, 0 ) );
       
   599         
       
   600         // copy left users
       
   601         aDestination.CopyDataL(aSource, myKey);
       
   602 
       
   603         CleanupStack::PopAndDestroy( );           // >> myKey
       
   604         }
       
   605     }
       
   606 
       
   607 // ---------------------------------------------------------
       
   608 // TImpsDataUtils::GetCenRepIntValueL
       
   609 // ---------------------------------------------------------
       
   610 //
       
   611 EXPORT_C TInt TImpsDataUtils::GetCenRepIntValueL( 
       
   612                 TUid aRepositoryUid,
       
   613                 TUint32 aId )
       
   614     {
       
   615     TInt value( 0 );
       
   616     CRepository* repository = CRepository::NewLC( aRepositoryUid ); // << repository    
       
   617     User::LeaveIfError( repository->Get( aId, value ) );    
       
   618     CleanupStack::PopAndDestroy(); // >> repository
       
   619     return value;
       
   620     }
       
   621     
       
   622 // ---------------------------------------------------------
       
   623 // TImpsDataUtils::GetCenRepRealValueL
       
   624 // ---------------------------------------------------------
       
   625 //
       
   626 EXPORT_C TReal TImpsDataUtils::GetCenRepRealValueL( 
       
   627                 TUid aRepositoryUid,
       
   628                 TUint32 aId )
       
   629     {
       
   630     TReal value( 0 );
       
   631     CRepository* repository = CRepository::NewLC( aRepositoryUid ); // << repository    
       
   632     User::LeaveIfError( repository->Get( aId, value ) );    
       
   633     CleanupStack::PopAndDestroy(); // >> repository
       
   634     return value;
       
   635     }
       
   636     
       
   637 // -----------------------------------------------------------------------------
       
   638 // TImpsDataUtils::SetBinaryContentDataL
       
   639 // -----------------------------------------------------------------------------
       
   640 //
       
   641 EXPORT_C void TImpsDataUtils::SetBinaryContentDataL( 
       
   642     MImpsKey* aKey,
       
   643     MImpsDataAccessor* aAc,
       
   644     const TDesC8& aContent )
       
   645     {
       
   646     // first set the content encoding
       
   647     aKey->AddL( CREATEKEY( EImpsKeyContentEncoding, 0 ) );
       
   648     aAc->StoreIntegerL( aKey, EImpsBASE64 );
       
   649     aKey->PopL( 2 );
       
   650     // then manipulate the data    
       
   651     aKey->AddL( CREATEKEY( EImpsKeyContentData, 0 ) );
       
   652     if( aContent.Length() != 0 )
       
   653         {
       
   654         // BASE64 encoding
       
   655         TImCodecB64 codec;
       
   656         codec.Initialise();
       
   657         // Encoder doesn't itself cope with buffer overflows, 
       
   658         // so allocate twice big buffer to be sure that there is enough 
       
   659         // space for B64 data
       
   660         HBufC8* base64Buf = HBufC8::NewLC( aContent.Size() * 2 ); // << base64Buf
       
   661         TPtr8 base64Data( base64Buf->Des() );
       
   662         codec.Encode( aContent, base64Data );
       
   663         // finally, store the data
       
   664         aAc->StoreDesc8L( aKey, base64Data );
       
   665         CleanupStack::PopAndDestroy(1); // >> base64Buf
       
   666         }
       
   667     else
       
   668         { 
       
   669         TPtrC8 content( KNullDesC8 );
       
   670         aAc->StoreDesc8L( aKey, content );
       
   671         }
       
   672     aKey->PopL();
       
   673     }
       
   674 
       
   675     
       
   676 // -----------------------------------------------------------------------------
       
   677 // TImpsDataUtils::GetContentTypeL
       
   678 // -----------------------------------------------------------------------------
       
   679 //
       
   680 EXPORT_C void TImpsDataUtils::GetContentTypeL( 
       
   681     MImpsDataAccessor* aAc,
       
   682     TPtrC& aContentType )
       
   683     {
       
   684     CImpsKey* myKey = CImpsKey::NewLC(); // << myKey
       
   685     TImpsDataUtils::AddValuesFromArrayL( 
       
   686         myKey, 
       
   687         KNewMessageElements, 
       
   688         sizeof( KNewMessageElements ) /
       
   689         sizeof( KNewMessageElements[0] ) );
       
   690         
       
   691     myKey->AddL( CREATEKEY( EImpsKeyMessageInfo, 0 ) );
       
   692     myKey->AddL( CREATEKEY( EImpsKeyContentType, 0 ) );
       
   693     
       
   694     TDesC* myPtr;
       
   695     if ( aAc->RestoreDescL( myKey, myPtr ) )
       
   696         {
       
   697         aContentType.Set( *myPtr );
       
   698         }
       
   699     else
       
   700         {
       
   701         aContentType.Set( KNullDesC );
       
   702         }
       
   703     CleanupStack::PopAndDestroy(); //  >>> myKey
       
   704     }  
       
   705     
       
   706     
       
   707 // -----------------------------------------------------------------------------
       
   708 // TImpsDataUtils::GetContentDataTypeL
       
   709 // -----------------------------------------------------------------------------
       
   710 //
       
   711 EXPORT_C TImpsDataType TImpsDataUtils::GetContentDataTypeL( 
       
   712             MImpsDataAccessor* aAc, TInt aIndex )
       
   713     {
       
   714     TImpsDataType dataType ( EImpsDataTypeDesc );
       
   715     
       
   716     CImpsKey* myKey = CImpsKey::NewLC(); // << myKey
       
   717     myKey->AddL( CREATEKEY( EImpsKeySession, 0 ) );
       
   718     // find the right transaction
       
   719     myKey->AddL( CREATEKEY( EImpsKeyTransaction, aIndex ) );
       
   720     myKey->AddL( CREATEKEY( EImpsKeyTransactionContent, 0 ) );
       
   721 
       
   722     // find the primitive
       
   723     TInt primitive(0);
       
   724     TInt index(0);
       
   725     TImpsKeyType keyType;
       
   726     if( aAc->RestoreAlternativeL( myKey, primitive, index, keyType ) )
       
   727         {
       
   728         switch ( primitive )
       
   729             {
       
   730             case EImpsKeyNewMessage:
       
   731                 myKey->AddL( CREATEKEY( EImpsKeyNewMessage, 0 ) );
       
   732             break;
       
   733             case EImpsKeySendMessage_Request:
       
   734                 myKey->AddL( CREATEKEY( EImpsKeySendMessage_Request, 0 ) );
       
   735             break;
       
   736             default:
       
   737             break;
       
   738             }
       
   739         
       
   740         myKey->AddL( CREATEKEY( EImpsKeyMessageInfo, 0 ) );
       
   741         myKey->AddL( CREATEKEY( EImpsKeyContentType, 0 ) );
       
   742     
       
   743         TDesC* myPtr;
       
   744         if ( aAc->RestoreDescL( myKey, myPtr ) )
       
   745             {
       
   746             if ( !myPtr->Left(KImpsContentType().Length()).CompareF( KImpsContentType ) || myPtr->Length() == 0 )
       
   747                 {
       
   748                 dataType = EImpsDataTypeDesc;
       
   749                 }
       
   750             else
       
   751                 {    
       
   752                 dataType = EImpsDataTypeDesc8;         
       
   753                 }
       
   754             }
       
   755         }
       
   756     CleanupStack::PopAndDestroy(); //  >>> myKey
       
   757     return dataType;
       
   758     }
       
   759             
       
   760             
       
   761                
       
   762 //  End of File