IMPSengine/client/src/impsgroupcli.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002-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 * const definition class.
       
    16 *
       
    17 */
       
    18 
       
    19 #include    "impsGroupHandler.h"
       
    20 #include    "ImpsGroupCli.h"
       
    21 #include    "ImpsGroupCommand.h"
       
    22 #include    "impsServerCommon.h"
       
    23 #include    "impsliterals.h"
       
    24 #include    "WVEngineInternalCRKeys.h"
       
    25 #include    "impsdatautils.h"
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 const TImpsContent KCreateGroupElements[]               = { EImpsKeySession,
       
    30                                                             EImpsKeyTransaction,
       
    31                                                             EImpsKeyTransactionContent,
       
    32                                                             EImpsKeyCreateGroup_Request };
       
    33 const TImpsContent KDeleteGroupElements[]               = { EImpsKeySession,
       
    34                                                             EImpsKeyTransaction,
       
    35                                                             EImpsKeyTransactionContent,
       
    36                                                             EImpsKeyDeleteGroup_Request };
       
    37 const TImpsContent KJoinGroupElements[]                 = { EImpsKeySession,
       
    38                                                             EImpsKeyTransaction,
       
    39                                                             EImpsKeyTransactionContent,
       
    40                                                             EImpsKeyJoinGroup_Request };
       
    41 const TImpsContent KLeaveGroupElements[]                = { EImpsKeySession,
       
    42                                                             EImpsKeyTransaction,
       
    43                                                             EImpsKeyTransactionContent,
       
    44                                                             EImpsKeyLeaveGroup_Request };
       
    45 const TImpsContent KGetGroupGroupElements[]             = { EImpsKeySession,
       
    46                                                             EImpsKeyTransaction,
       
    47                                                             EImpsKeyTransactionContent,
       
    48                                                             EImpsKeyGetGroupMembers_Request };
       
    49 const TImpsContent KAddGroupMembersElements[]           = { EImpsKeySession,
       
    50                                                             EImpsKeyTransaction,
       
    51                                                             EImpsKeyTransactionContent,
       
    52                                                             EImpsKeyAddGroupMembers_Request };
       
    53 const TImpsContent KRemoveGroupMembersElements[]        = { EImpsKeySession,
       
    54                                                             EImpsKeyTransaction,
       
    55                                                             EImpsKeyTransactionContent,
       
    56                                                             EImpsKeyRemoveGroupMembers_Request };
       
    57 const TImpsContent KModifyGroupMembersElements[]        = { EImpsKeySession,
       
    58                                                             EImpsKeyTransaction,
       
    59                                                             EImpsKeyTransactionContent,
       
    60                                                             EImpsKeyMemberAccess_Request };
       
    61 const TImpsContent KGetGroupGroupPropertiesElements[]   = { EImpsKeySession,
       
    62                                                             EImpsKeyTransaction,
       
    63                                                             EImpsKeyTransactionContent,
       
    64                                                             EImpsKeyGetGroupProps_Request };
       
    65 const TImpsContent KSetGroupGroupPropertiesElements[]   = { EImpsKeySession,
       
    66                                                             EImpsKeyTransaction,
       
    67                                                             EImpsKeyTransactionContent,
       
    68                                                             EImpsKeySetGroupProps_Request };
       
    69 const TImpsContent KRejectListElements[]                = { EImpsKeySession,
       
    70                                                             EImpsKeyTransaction,
       
    71                                                             EImpsKeyTransactionContent,
       
    72                                                             EImpsKeyRejectList_Request };
       
    73 const TImpsContent KImpsSubscribeGroupNoticeRequest[]   = { EImpsKeySession,
       
    74                                                             EImpsKeyTransaction,
       
    75                                                             EImpsKeyTransactionContent,
       
    76                                                             EImpsKeySubscribeGroupNotice_Request };
       
    77 // LOCAL CONSTANTS AND MACROS
       
    78 _LIT( KMaxNro,               "%d" );
       
    79 
       
    80 
       
    81 // ================= MEMBER FUNCTIONS =======================
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // RImpsGroupClient2::RImpsGroupClient2
       
    85 // ---------------------------------------------------------
       
    86 EXPORT_C RImpsGroupClient2::RImpsGroupClient2() :
       
    87         RImpsClient2(), 
       
    88         iHandlerCallBack( NULL ),
       
    89         iCommand( NULL )
       
    90     {
       
    91     SetOpIdRange( ); 
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // RImpsGroupClient2::RegisterL
       
    96 // ---------------------------------------------------------
       
    97 EXPORT_C void RImpsGroupClient2::RegisterL(
       
    98     RImpsEng& aEngine, 
       
    99     MImpsGroupHandler2* aObserver,
       
   100     const TDesC& aClientId,
       
   101     TBool aReceiveNew,
       
   102     TInt aPriority )
       
   103     {
       
   104 
       
   105     iHandlerCallBack = aObserver;
       
   106     iHandler = CImpsGroupHandler2::NewL( *this, aPriority );
       
   107     iCommand = CImpsGroupCommand2::NewL( *this );
       
   108     iActiveCommand = iCommand;
       
   109 
       
   110     // Start the handler
       
   111     iHandler->StartRun();
       
   112     iHandleNew = aReceiveNew;
       
   113     iAnyContent = EFalse;
       
   114 
       
   115     // Send registeration to the server thread
       
   116     TInt err = DoRegister( aEngine, iHandler );
       
   117     User::LeaveIfError( err ); 
       
   118 
       
   119     DoAssign( aClientId );
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------
       
   123 // RImpsGroupClient2::UnRegister
       
   124 // ---------------------------------------------------------
       
   125 //
       
   126 EXPORT_C void RImpsGroupClient2::Unregister()
       
   127    {
       
   128    DoUnregister();
       
   129    }
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // RImpsGroupClient2::DoRegister()
       
   133 // ----------------------------------------------------------------------------
       
   134 TInt RImpsGroupClient2::DoRegister(
       
   135    RImpsEng& aEngine,
       
   136    CImpsHandler2* aHandler )
       
   137    {
       
   138    return DoRegister2( aEngine, aHandler, EImpsGroupRegister );
       
   139    }
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // RImpsGroupClient2::CreateGroupL
       
   143 // ----------------------------------------------------------------------------
       
   144 EXPORT_C TInt RImpsGroupClient2::CreateGroupL(
       
   145     const TDesC& aGroupId,
       
   146     const CImpsCommonGroupProps* aProperties,
       
   147     const TDesC& aScreenName,
       
   148     TBool aJoinGroup,
       
   149     TBool aSubscribeNotification )
       
   150     {
       
   151     IncreaseOpId( );
       
   152     iCommand->ResetMembers();
       
   153     iCommand->InitialiseL( KCreateGroupElements,
       
   154                            sizeof( KCreateGroupElements ) /
       
   155                            sizeof( KCreateGroupElements[0] ) );
       
   156 
       
   157     TInt index(0);
       
   158     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   159     iCommand->AddKeyL( CREATEKEY( EImpsKeyGroupProperties, 0 ) );
       
   160 
       
   161     iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   162     iCommand->InsertElementL( KImpsName, EImpsKeyName );
       
   163     iCommand->InsertElementL( aProperties->GroupName( ), EImpsKeyValue );
       
   164     iCommand->PopKeyL( );
       
   165     index++;
       
   166 
       
   167     if( aProperties->IsOpen( ) != EImpsPropUndef )
       
   168         {
       
   169         iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   170         iCommand->InsertElementL( KImpsAccessType, EImpsKeyName );
       
   171         if( aProperties->IsOpen( ) == EImpsPropYes )
       
   172             iCommand->InsertElementL( KImpsOpen, EImpsKeyValue );
       
   173         else
       
   174             iCommand->InsertElementL( KImpsRestricted, EImpsKeyValue );
       
   175         iCommand->PopKeyL( );
       
   176         index++;
       
   177         }
       
   178 
       
   179     if( aProperties->IsPrivateAllowed( ) != EImpsPropUndef )
       
   180         {
       
   181         iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   182         iCommand->InsertElementL( KImpsPrivateMessaging, EImpsKeyName );
       
   183         if( aProperties->IsPrivateAllowed( ) == EImpsPropYes )
       
   184             iCommand->InsertElementL( KImpsTrue, EImpsKeyValue );
       
   185         else
       
   186             iCommand->InsertElementL( KImpsFalse, EImpsKeyValue );
       
   187         iCommand->PopKeyL( );
       
   188         index++;
       
   189         }
       
   190 
       
   191     if( aProperties->IsPublic( ) != EImpsPropUndef )
       
   192         {
       
   193         iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   194         iCommand->InsertElementL( KImpsType, EImpsKeyName );
       
   195         if( aProperties->IsPublic( ) == EImpsPropYes )
       
   196             iCommand->InsertElementL( KImpsPublic, EImpsKeyValue );
       
   197         else
       
   198             iCommand->InsertElementL( KImpsPrivate, EImpsKeyValue );
       
   199         iCommand->PopKeyL( );
       
   200         index++;
       
   201         }
       
   202 
       
   203     if( aProperties->IsSearchable( ) != EImpsPropUndef )
       
   204         {
       
   205         iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   206         iCommand->InsertElementL( KImpsSearchable, EImpsKeyName );
       
   207         if( aProperties->IsSearchable( ) == EImpsPropYes )
       
   208             iCommand->InsertElementL( KImpsTrue, EImpsKeyValue );
       
   209         else
       
   210             iCommand->InsertElementL( KImpsFalse, EImpsKeyValue );
       
   211         iCommand->PopKeyL( );
       
   212         index++;
       
   213         }
       
   214 
       
   215     if( aProperties->Topic( ).Length() ) 
       
   216         {
       
   217         iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   218         iCommand->InsertElementL( KImpsTopic, EImpsKeyName );
       
   219         iCommand->InsertElementL( aProperties->Topic( ), EImpsKeyValue );
       
   220         iCommand->PopKeyL( );
       
   221         index++;
       
   222         }
       
   223 
       
   224       // AutoDelete for CSP 1.2
       
   225       TReal version (0);
       
   226       TRAPD( err, version = TImpsDataUtils::GetCenRepRealValueL( 
       
   227        			KCRUIDWVEngineVariation, KWVEngineCspVersion )	);
       
   228 	 if ( !err && version == 1.2 )
       
   229 	      {
       
   230 	      if( aProperties->AutoDelete( ) != EImpsPropUndef )
       
   231 	          {
       
   232 	          iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   233 	          iCommand->InsertElementL( KImpsAutoDelete, EImpsKeyName );
       
   234 	          if( aProperties->AutoDelete( ) == EImpsPropYes )
       
   235 	            {
       
   236 		          iCommand->InsertElementL( KImpsTrue, EImpsKeyValue );	
       
   237 		          }
       
   238 	            else
       
   239 		          {
       
   240 		          iCommand->InsertElementL( KImpsFalse, EImpsKeyValue );	
       
   241 		          }
       
   242             iCommand->PopKeyL( );
       
   243             index++;
       
   244             }
       
   245         }
       
   246     iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   247     iCommand->InsertElementL( KImpsMaxActiveUsers, EImpsKeyName );
       
   248     TInt  i = aProperties->MaxNbrOfUsers( );
       
   249     TBuf<10> nro; 
       
   250     nro.Format( KMaxNro, i );
       
   251     iCommand->InsertElementL( nro, EImpsKeyValue );
       
   252 
       
   253     iCommand->PopKeyL( );
       
   254 
       
   255     TPtrC wellcome = aProperties->Welcome( );
       
   256     if( wellcome.Length( ) )
       
   257         {
       
   258         iCommand->AddKeyL( CREATEKEY( EImpsKeyWelcomeNote, 0) );
       
   259         iCommand->InsertElementL( KImpsContentType, EImpsKeyContentType );
       
   260         iCommand->InsertElementL( wellcome, EImpsKeyContentData );
       
   261         iCommand->PopKeyL( ); // Pop out welcomenote
       
   262         }
       
   263     iCommand->PopKeyL( ); // Pop out group properties
       
   264     iCommand->InsertElementL( aJoinGroup, EImpsKeyJoinGroup );
       
   265 
       
   266     if( aScreenName.Length() ) 
       
   267         {
       
   268         iCommand->AddKeyL( CREATEKEY( EImpsKeyScreenName, 0) );
       
   269         iCommand->InsertElementL( aScreenName, EImpsKeySName );
       
   270         iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   271         iCommand->PopKeyL( ); // ScreenName
       
   272         }
       
   273 
       
   274     iCommand->InsertElementL( aSubscribeNotification, 
       
   275                               EImpsKeySubscribeNotification );
       
   276 
       
   277     iCommand->PackAndSendL( EImpsCreateGroupReq, iOpId  );
       
   278     return iOpId;
       
   279     }
       
   280 
       
   281 // ----------------------------------------------------------------------------
       
   282 // RImpsGroupClient2::DeleteGroupL
       
   283 // ----------------------------------------------------------------------------
       
   284 EXPORT_C TInt RImpsGroupClient2::DeleteGroupL(
       
   285     const TDesC& aGroupId )
       
   286     {
       
   287     IncreaseOpId( );
       
   288     iCommand->ResetMembers();
       
   289     iCommand->InitialiseL( KDeleteGroupElements,
       
   290                            sizeof( KDeleteGroupElements ) /
       
   291                            sizeof( KDeleteGroupElements[0] ) );
       
   292 
       
   293     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   294     iCommand->PackAndSendL( EImpsDeleteGroupReq, iOpId  );
       
   295     return iOpId;
       
   296     }
       
   297 
       
   298 // ----------------------------------------------------------------------------
       
   299 // RImpsGroupClient2::JoinGroupL
       
   300 // ----------------------------------------------------------------------------
       
   301 EXPORT_C TInt RImpsGroupClient2::JoinGroupL(
       
   302             const TDesC& aGroupId,
       
   303             const TDesC& aScreenName,
       
   304             TBool aUsers,
       
   305             TBool aSubscribeNotification )
       
   306     {
       
   307     IncreaseOpId( );
       
   308     iCommand->ResetMembers();
       
   309     iCommand->InitialiseL( KJoinGroupElements,
       
   310                            sizeof( KJoinGroupElements ) /
       
   311                            sizeof( KJoinGroupElements[0] ) );
       
   312 
       
   313     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   314     iCommand->AddKeyL( CREATEKEY( EImpsKeyScreenName, 0) );
       
   315     iCommand->InsertElementL( aScreenName, EImpsKeySName );
       
   316     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   317     iCommand->PopKeyL( ); // ScreenName
       
   318     iCommand->InsertElementL( aUsers, EImpsKeyJoinedRequest );
       
   319     iCommand->InsertElementL( aSubscribeNotification , 
       
   320                               EImpsKeySubscribeNotification );
       
   321     iCommand->PackAndSendL( EImpsJoinGroupReq, iOpId  );
       
   322     return iOpId;
       
   323     }
       
   324 
       
   325 // ----------------------------------------------------------------------------
       
   326 // RImpsGroupClient2::LeaveGroupL
       
   327 // ----------------------------------------------------------------------------
       
   328 EXPORT_C TInt RImpsGroupClient2::LeaveGroupL(
       
   329     const TDesC& aGroupId )
       
   330     {
       
   331     IncreaseOpId( );
       
   332     iCommand->ResetMembers();
       
   333     iCommand->InitialiseL( KLeaveGroupElements,
       
   334                            sizeof( KLeaveGroupElements ) /
       
   335                            sizeof( KLeaveGroupElements[0] ) );
       
   336 
       
   337     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   338     iCommand->PackAndSendL( EImpsLeaveGroupReq, iOpId  );
       
   339     return iOpId;
       
   340     }
       
   341 
       
   342 // ----------------------------------------------------------------------------
       
   343 // RImpsGroupClient2::GroupMembersL
       
   344 // ----------------------------------------------------------------------------
       
   345 EXPORT_C TInt RImpsGroupClient2::GroupMembersL(
       
   346     const TDesC& aGroupId )
       
   347     {
       
   348     IncreaseOpId( );
       
   349     iCommand->ResetMembers();
       
   350     iCommand->InitialiseL( KGetGroupGroupElements,
       
   351                            sizeof( KGetGroupGroupElements ) /
       
   352                            sizeof( KGetGroupGroupElements[0] ) );
       
   353 
       
   354     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   355     iCommand->PackAndSendL( EImpsGroupMembersReq, iOpId  );
       
   356     return iOpId;
       
   357     }
       
   358 
       
   359 // ----------------------------------------------------------------------------
       
   360 // RImpsGroupClient2::AddMembersL
       
   361 // ----------------------------------------------------------------------------
       
   362 EXPORT_C TInt RImpsGroupClient2::AddMembersL(
       
   363     const TDesC& aGroupId,
       
   364     const MDesCArray& aUserList,
       
   365     const MDesCArray& aScreenNameList )
       
   366     {
       
   367     TInt count1 = aUserList.MdcaCount();
       
   368     TInt count2 = aScreenNameList.MdcaCount();
       
   369     if ( !count1 && !count2 )
       
   370         {
       
   371         User::Leave( KErrArgument );
       
   372         }
       
   373 
       
   374     IncreaseOpId( );
       
   375     iCommand->ResetMembers();
       
   376     iCommand->InitialiseL( KAddGroupMembersElements,
       
   377                            sizeof( KAddGroupMembersElements ) /
       
   378                            sizeof( KAddGroupMembersElements[0] ) );
       
   379 
       
   380     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   381     iCommand->AddKeyL( CREATEKEY( EImpsKeyUserList, 0 ) );
       
   382 
       
   383     TInt i = 0;
       
   384     for( i =0; i<count1; i++ )
       
   385         {
       
   386         iCommand->AddKeyL( CREATEKEY( EImpsKeyUser, i ) );
       
   387         iCommand->InsertElementL( aUserList.MdcaPoint( i ), EImpsKeyUserID );
       
   388         iCommand->PopKeyL( ); // Pop the Userkey out
       
   389         }
       
   390     for( i=0; i<count2; i++ )
       
   391         {
       
   392         iCommand->AddKeyL( CREATEKEY( EImpsKeyScreenName, i ) );
       
   393         iCommand->InsertElementL( aScreenNameList.MdcaPoint( i ), 
       
   394                                   EImpsKeySName );
       
   395         iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   396         iCommand->PopKeyL( ); // Pop the EImpsKeyScreenName out
       
   397         }
       
   398     iCommand->PackAndSendL( EImpsAddGroupMembersReq, iOpId  );
       
   399     return iOpId;
       
   400     }
       
   401 
       
   402 // ----------------------------------------------------------------------------
       
   403 // RImpsGroupClient2::RemoveMembersL
       
   404 // ----------------------------------------------------------------------------
       
   405 EXPORT_C TInt RImpsGroupClient2::RemoveMembersL(
       
   406     const TDesC& aGroupId,
       
   407     const MDesCArray& aUserList )
       
   408     {
       
   409     TInt count = aUserList.MdcaCount();
       
   410     if ( !count )
       
   411         {
       
   412         User::Leave( KErrArgument );
       
   413         }
       
   414 
       
   415     IncreaseOpId( );
       
   416     iCommand->ResetMembers();
       
   417     iCommand->InitialiseL( KRemoveGroupMembersElements,
       
   418                            sizeof( KRemoveGroupMembersElements ) /
       
   419                            sizeof( KRemoveGroupMembersElements[0] ) );
       
   420 
       
   421     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   422     iCommand->AddKeyL( CREATEKEY( EImpsKeyUserList, 0 ) );
       
   423 
       
   424     for( TInt i=0; i<count; i++ )
       
   425         {
       
   426         iCommand->AddKeyL( CREATEKEY( EImpsKeyUser, i ) );
       
   427         iCommand->InsertElementL( aUserList.MdcaPoint( i ), EImpsKeyUserID );
       
   428         iCommand->PopKeyL( ); // Pop the Userkey out
       
   429         }
       
   430     iCommand->PackAndSendL( EImpsRemoveGroupMembersReq, iOpId  );
       
   431     return iOpId;
       
   432     }
       
   433 
       
   434 // ----------------------------------------------------------------------------
       
   435 // RImpsGroupClient2::ModifyMembersAccessL
       
   436 // ----------------------------------------------------------------------------
       
   437 EXPORT_C TInt RImpsGroupClient2::ModifyMembersAccessL(
       
   438     const TDesC& aGroupId,
       
   439     const MDesCArray* aAdminList,
       
   440     const MDesCArray* aModerList,
       
   441     const MDesCArray* aOrdinaryList )
       
   442     {
       
   443     IncreaseOpId( );
       
   444     iCommand->ResetMembers();
       
   445     iCommand->InitialiseL( KModifyGroupMembersElements,
       
   446                            sizeof( KModifyGroupMembersElements ) /
       
   447                            sizeof( KModifyGroupMembersElements[0] ) );
       
   448 
       
   449     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   450 
       
   451     if( aAdminList )
       
   452         {
       
   453         iCommand->AddKeyL( CREATEKEY( EImpsKeyAdmin, 0 ) );
       
   454         iCommand->AddKeyL( CREATEKEY( EImpsKeyUserList, 0 ) );
       
   455         TInt count = aAdminList->MdcaCount();
       
   456         for( TInt i=0; i < count; i++ )
       
   457             {
       
   458             iCommand->AddKeyL( CREATEKEY( EImpsKeyUser, i ) );
       
   459             iCommand->InsertElementL( aAdminList->MdcaPoint( i ), 
       
   460                                       EImpsKeyUserID );
       
   461             iCommand->PopKeyL( ); // Pop the Userkey out
       
   462             }
       
   463         iCommand->PopKeyL( );
       
   464         iCommand->PopKeyL( );
       
   465         }
       
   466 
       
   467     if( aOrdinaryList )
       
   468         {
       
   469         iCommand->AddKeyL( CREATEKEY( EImpsKeyUsers, 0 ) );
       
   470         iCommand->AddKeyL( CREATEKEY( EImpsKeyUserList, 0 ) );
       
   471         TInt count = aOrdinaryList->MdcaCount( );
       
   472         for( TInt i=0; i < count; i++ )
       
   473             {
       
   474             iCommand->AddKeyL( CREATEKEY( EImpsKeyUser, i ) );
       
   475             iCommand->InsertElementL( aOrdinaryList->MdcaPoint( i ), 
       
   476                                       EImpsKeyUserID );
       
   477             iCommand->PopKeyL( ); // Pop the Userkey out
       
   478             }
       
   479         iCommand->PopKeyL( );
       
   480         iCommand->PopKeyL( );
       
   481         }
       
   482     if( aModerList )
       
   483         {
       
   484         iCommand->AddKeyL( CREATEKEY( EImpsKeyMod, 0 ) );
       
   485         iCommand->AddKeyL( CREATEKEY( EImpsKeyUserList, 0 ) );
       
   486         TInt count = aModerList->MdcaCount( );
       
   487         for( TInt i=0; i < count; i++ )
       
   488             {
       
   489             iCommand->AddKeyL( CREATEKEY( EImpsKeyUser, i ) );
       
   490             iCommand->InsertElementL( aModerList->MdcaPoint( i ), 
       
   491                                       EImpsKeyUserID );
       
   492             iCommand->PopKeyL( ); // Pop the Userkey out
       
   493             }
       
   494         }
       
   495 
       
   496     iCommand->PackAndSendL( EImpsGroupMemberAccessReq, iOpId  );
       
   497     return iOpId;
       
   498     }
       
   499 
       
   500 // ----------------------------------------------------------------------------
       
   501 // RImpsGroupClient2::GroupPropertiesL
       
   502 // ----------------------------------------------------------------------------
       
   503 EXPORT_C TInt RImpsGroupClient2::GroupPropertiesL(
       
   504     const TDesC& aGroupId )
       
   505     {
       
   506     IncreaseOpId( );
       
   507     iCommand->ResetMembers();
       
   508     iCommand->InitialiseL( KGetGroupGroupPropertiesElements,
       
   509                            sizeof( KGetGroupGroupPropertiesElements ) /
       
   510                            sizeof( KGetGroupGroupPropertiesElements[0] ) );
       
   511 
       
   512     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   513     iCommand->PackAndSendL( EImpsGroupPropertiesReq, iOpId  );
       
   514     return iOpId;
       
   515     }
       
   516 
       
   517 // ----------------------------------------------------------------------------
       
   518 // RImpsGroupClient2::SetGroupPropertiesL
       
   519 // ----------------------------------------------------------------------------
       
   520 EXPORT_C TInt RImpsGroupClient2::SetGroupPropertiesL(
       
   521     const TDesC& aGroupId,
       
   522     const CImpsCommonGroupProps* aGroupProps,
       
   523     const CImpsPrivateGroupProps* aOwnProps )
       
   524     {
       
   525     IncreaseOpId( );
       
   526     iCommand->ResetMembers();
       
   527     iCommand->InitialiseL( KSetGroupGroupPropertiesElements,
       
   528                            sizeof( KSetGroupGroupPropertiesElements ) /
       
   529                            sizeof( KSetGroupGroupPropertiesElements[0] ) );
       
   530 
       
   531     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   532     if ( aGroupProps )
       
   533         {
       
   534         TInt index(0);
       
   535         iCommand->AddKeyL( CREATEKEY( EImpsKeyGroupProperties, 0 ) );
       
   536         iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   537         iCommand->InsertElementL( KImpsName, EImpsKeyName );
       
   538         iCommand->InsertElementL( aGroupProps->GroupName( ), EImpsKeyValue );
       
   539         iCommand->PopKeyL( );
       
   540         index++;
       
   541 
       
   542         if( aGroupProps->IsOpen( ) != EImpsPropUndef )
       
   543             {
       
   544             iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   545             iCommand->InsertElementL( KImpsAccessType, EImpsKeyName );
       
   546             if( aGroupProps->IsOpen( ) == EImpsPropYes )
       
   547                 iCommand->InsertElementL( KImpsOpen, EImpsKeyValue );
       
   548             else
       
   549                 iCommand->InsertElementL( KImpsRestricted, EImpsKeyValue );
       
   550             iCommand->PopKeyL( );
       
   551             index++;
       
   552             }
       
   553 
       
   554         if( aGroupProps->IsPrivateAllowed( ) != EImpsPropUndef )
       
   555             {
       
   556             iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   557             iCommand->InsertElementL( KImpsPrivateMessaging, EImpsKeyName );
       
   558             if( aGroupProps->IsPrivateAllowed( ) == EImpsPropYes )
       
   559                 iCommand->InsertElementL( KImpsTrue, EImpsKeyValue );
       
   560             else
       
   561                 iCommand->InsertElementL( KImpsFalse, EImpsKeyValue );
       
   562             iCommand->PopKeyL( );
       
   563             index++;
       
   564             }
       
   565 
       
   566         if( aGroupProps->IsPublic( ) != EImpsPropUndef )
       
   567             {
       
   568             iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   569             iCommand->InsertElementL( KImpsType, EImpsKeyName );
       
   570             if( aGroupProps->IsPublic( ) == EImpsPropYes )
       
   571                 iCommand->InsertElementL( KImpsPublic, EImpsKeyValue );
       
   572             else
       
   573                 iCommand->InsertElementL( KImpsPrivate, EImpsKeyValue );
       
   574             iCommand->PopKeyL( );
       
   575             index++;
       
   576             }
       
   577 
       
   578         if( aGroupProps->IsSearchable( ) != EImpsPropUndef )
       
   579             {
       
   580             iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   581             iCommand->InsertElementL( KImpsSearchable, EImpsKeyName );
       
   582             if( aGroupProps->IsSearchable( ) == EImpsPropYes )
       
   583                 iCommand->InsertElementL( KImpsTrue, EImpsKeyValue );
       
   584             else
       
   585                 iCommand->InsertElementL( KImpsFalse, EImpsKeyValue );
       
   586             iCommand->PopKeyL( );
       
   587             index++;
       
   588             }
       
   589 
       
   590         iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   591         iCommand->InsertElementL( KImpsTopic, EImpsKeyName );
       
   592         iCommand->InsertElementL( aGroupProps->Topic( ), EImpsKeyValue );
       
   593         iCommand->PopKeyL( );
       
   594         index++;
       
   595 
       
   596         // AutoDelete for CSP 1.2
       
   597         TReal version (0);
       
   598     	TRAPD( err, version = TImpsDataUtils::GetCenRepRealValueL( 
       
   599         			KCRUIDWVEngineVariation, KWVEngineCspVersion )	);
       
   600 	    if ( !err && version == 1.2 )
       
   601 	        {
       
   602 	        if( aGroupProps->AutoDelete( ) != EImpsPropUndef )
       
   603 	            {
       
   604 	            iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   605 	            iCommand->InsertElementL( KImpsAutoDelete, EImpsKeyName );
       
   606 	            if( aGroupProps->AutoDelete( ) == EImpsPropYes )
       
   607 		            {
       
   608 		            iCommand->InsertElementL( KImpsTrue, EImpsKeyValue );	
       
   609 		            }
       
   610 	            else
       
   611 		            {
       
   612 		            iCommand->InsertElementL( KImpsFalse, EImpsKeyValue );	
       
   613 		            }
       
   614 	            iCommand->PopKeyL( );
       
   615 	            index++;
       
   616 	            }
       
   617 	        }
       
   618         
       
   619         iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   620         iCommand->InsertElementL( KImpsMaxActiveUsers, EImpsKeyName );
       
   621         TInt  i = aGroupProps->MaxNbrOfUsers( );
       
   622         TBuf<10> nro; 
       
   623         nro.Format( KMaxNro, i );
       
   624         iCommand->InsertElementL( nro, EImpsKeyValue );
       
   625         iCommand->PopKeyL( );
       
   626 
       
   627         TPtrC wellcome = aGroupProps->Welcome( );
       
   628         if( wellcome.Length( ) )
       
   629             {
       
   630             iCommand->AddKeyL( CREATEKEY( EImpsKeyWelcomeNote, 0) );
       
   631             iCommand->InsertElementL( KImpsContentType, EImpsKeyContentType );
       
   632             iCommand->InsertElementL( wellcome, EImpsKeyContentData );
       
   633             iCommand->PopKeyL( );
       
   634             }
       
   635         iCommand->PopKeyL( );
       
   636         }
       
   637     if ( aOwnProps )
       
   638         {
       
   639         iCommand->AddKeyL( CREATEKEY( EImpsKeyOwnProperties, 0 ) );
       
   640 
       
   641         TInt index(0);
       
   642         if( aOwnProps->IsPrivateAllowed( ) != EImpsPropUndef )
       
   643             {
       
   644             iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   645             iCommand->InsertElementL( KImpsPrivateMessaging, EImpsKeyName );
       
   646             if( aOwnProps->IsPrivateAllowed( ) == EImpsPropYes )
       
   647                 iCommand->InsertElementL( KImpsTrue, EImpsKeyValue );
       
   648             else
       
   649                 iCommand->InsertElementL( KImpsFalse, EImpsKeyValue );
       
   650             iCommand->PopKeyL( );
       
   651             index++;
       
   652             }
       
   653 
       
   654         if( aOwnProps->IsMember( ) != EImpsPropUndef )
       
   655             {
       
   656             iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   657             iCommand->InsertElementL( KImpsIsMember, EImpsKeyName );
       
   658             if( aOwnProps->IsMember( ) == EImpsPropYes )
       
   659                 iCommand->InsertElementL( KImpsTrue, EImpsKeyValue );
       
   660             else
       
   661                 iCommand->InsertElementL( KImpsFalse, EImpsKeyValue );
       
   662             iCommand->PopKeyL( );
       
   663             index++;
       
   664             }
       
   665 
       
   666         if( aOwnProps->Privileges( ) != EImpsUserUndef )
       
   667             {
       
   668             iCommand->AddKeyL( CREATEKEY( EImpsKeyProperty, index ) );
       
   669             iCommand->InsertElementL( KImpsPriviledgeLevel, EImpsKeyName );
       
   670             switch( aOwnProps->Privileges( ) )
       
   671                 {
       
   672                 case EImpsOrdinary:
       
   673                     iCommand->InsertElementL( KImpsUser, EImpsKeyValue );
       
   674                     break;
       
   675                 case EImpsModerator:
       
   676                     iCommand->InsertElementL( KImpsMod, EImpsKeyValue );
       
   677                     break;
       
   678                 case EImpsAdmin:
       
   679                     iCommand->InsertElementL( KImpsAdmin, EImpsKeyValue );
       
   680                     break;
       
   681                 default:
       
   682                     // notice: OPa for Thumb build
       
   683                     break;
       
   684                 }
       
   685             }
       
   686         }
       
   687     iCommand->PackAndSendL( EImpsSetGroupPropertiesReq, iOpId  );
       
   688     return iOpId;
       
   689     }
       
   690 
       
   691 // ----------------------------------------------------------------------------
       
   692 // RImpsGroupClient2::SetRejectListL
       
   693 // ----------------------------------------------------------------------------
       
   694 EXPORT_C TInt RImpsGroupClient2::SetRejectListL(
       
   695     const TDesC& aGroupId,
       
   696     const MDesCArray* aRejectedList,
       
   697     const MDesCArray* aEnabledList )
       
   698     {
       
   699     IncreaseOpId( );
       
   700     iCommand->ResetMembers();
       
   701     iCommand->InitialiseL( KRejectListElements,
       
   702                            sizeof( KRejectListElements ) /
       
   703                            sizeof( KRejectListElements[0] ) );
       
   704 
       
   705     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   706 
       
   707     if( aRejectedList )
       
   708         {
       
   709         iCommand->AddKeyL( CREATEKEY( EImpsKeyAddList, 0 ) );
       
   710         TInt count = aRejectedList->MdcaCount( );
       
   711         for( TInt i=0; i < count; i++ )
       
   712             {
       
   713             iCommand->InsertElementL( aRejectedList->MdcaPoint( i ), 
       
   714                                       EImpsKeyUserID, i);
       
   715             }
       
   716         iCommand->PopKeyL( );
       
   717         }
       
   718 
       
   719     if( aEnabledList )
       
   720         {
       
   721         iCommand->AddKeyL( CREATEKEY( EImpsKeyRemoveList, 0 ) );
       
   722         TInt count = aEnabledList->MdcaCount( );
       
   723         for( TInt i=0; i < count; i++ )
       
   724             {
       
   725             iCommand->InsertElementL( aEnabledList->MdcaPoint( i ), 
       
   726                                       EImpsKeyUserID, i);
       
   727             }
       
   728         }
       
   729     iCommand->PackAndSendL( EImpsGroupRejectListReq, iOpId  );
       
   730     return iOpId;
       
   731     }
       
   732 
       
   733 // ----------------------------------------------------------------------------
       
   734 // RImpsGroupClient2::SubscribeL
       
   735 // ----------------------------------------------------------------------------
       
   736 EXPORT_C TInt RImpsGroupClient2::SubscribeL(
       
   737     const TDesC& aGroupId )
       
   738     {
       
   739     IncreaseOpId( );
       
   740     iCommand->ResetMembers();
       
   741     iCommand->InitialiseL( KImpsSubscribeGroupNoticeRequest,
       
   742                            sizeof( KImpsSubscribeGroupNoticeRequest ) /
       
   743                            sizeof( KImpsSubscribeGroupNoticeRequest[0] ) );
       
   744 
       
   745     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   746     iCommand->InsertElementIntL( EImpsS, EImpsKeySubscribeType );
       
   747     iCommand->PackAndSendL( EImpsSubsGroupNoticeSet, iOpId );
       
   748     return iOpId;
       
   749     }
       
   750 
       
   751 // ----------------------------------------------------------------------------
       
   752 // RImpsGroupClient2::UnsubscribeL
       
   753 // ----------------------------------------------------------------------------
       
   754 EXPORT_C TInt RImpsGroupClient2::UnsubscribeL(
       
   755     const TDesC& aGroupId )
       
   756     {
       
   757     IncreaseOpId( );
       
   758     iCommand->ResetMembers();
       
   759     iCommand->InitialiseL( KImpsSubscribeGroupNoticeRequest,
       
   760                            sizeof( KImpsSubscribeGroupNoticeRequest ) /
       
   761                            sizeof( KImpsSubscribeGroupNoticeRequest[0] ) );
       
   762 
       
   763     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   764     iCommand->InsertElementIntL( EImpsU, EImpsKeySubscribeType );
       
   765     iCommand->PackAndSendL( EImpsSubsGroupNoticeUnset, iOpId  );
       
   766     return iOpId;
       
   767     }
       
   768 
       
   769 // ----------------------------------------------------------------------------
       
   770 // RImpsGroupClient2::CheckSubscriptionL
       
   771 // ----------------------------------------------------------------------------
       
   772 EXPORT_C TInt RImpsGroupClient2::CheckSubscriptionL(
       
   773     const TDesC& aGroupId )
       
   774     {
       
   775     IncreaseOpId( );
       
   776     iCommand->ResetMembers();
       
   777     iCommand->InitialiseL( KImpsSubscribeGroupNoticeRequest,
       
   778                            sizeof( KImpsSubscribeGroupNoticeRequest ) /
       
   779                            sizeof( KImpsSubscribeGroupNoticeRequest[0] ) );
       
   780 
       
   781     iCommand->InsertElementL( aGroupId, EImpsKeyGroupID );
       
   782     iCommand->InsertElementIntL( EImpsG, EImpsKeySubscribeType );
       
   783     iCommand->PackAndSendL( EImpsSubsGroupNoticeGet, iOpId  );
       
   784     return iOpId;
       
   785     }
       
   786 
       
   787 // ----------------------------------------------------------------------------
       
   788 // RImpsGroupClient2::Handler
       
   789 // ----------------------------------------------------------------------------
       
   790 MImpsGroupHandler2* RImpsGroupClient2::Handler( )
       
   791     {
       
   792     return iHandlerCallBack;
       
   793     }
       
   794     
       
   795     
       
   796 // ================= OTHER EXPORTED FUNCTIONS ==============
       
   797 
       
   798 
       
   799 //  End of File 
       
   800 
       
   801 
       
   802