wvuing/wvuiprocess/Src/CCASearchInterfacePC.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Implementation for PC Search Interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CCASearchInterfacePC.h"
       
    22 #include "MCASearchBackgroundObserverPC.h"
       
    23 #include "MCASearchInterface.h"
       
    24 #include "MCASearchObserverInterfacePC.h"
       
    25 #include "MCAStoredContacts.h"
       
    26 #include "CCAStorageManagerFactory.h"
       
    27 #include "MCAGroupManagerInterface.h"
       
    28 #include "MCAExtendedStoredGroup.h"
       
    29 #include "MCAGroupOperations.h"
       
    30 #include "MCAStoredGroups.h"
       
    31 #include "ImpsCSPAllErrors.h"
       
    32 #include "TEnumsPC.h"
       
    33 #include "MCAServerContactsArrayPC.h"
       
    34 #include "CCAServerContactsArrayPC.h"
       
    35 
       
    36 
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CCASearchInterfacePC: Constructor
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CCASearchInterfacePC::CCASearchInterfacePC( MCASearchInterface* aSearchInterface,
       
    46                                             MCABackgroundInterface& aBackgroundInterface,
       
    47                                             MCAGroupManagerInterface& aGroupMgrInterface )
       
    48         : iSearchInterface( aSearchInterface ),
       
    49         iBackgroundInterface( aBackgroundInterface ),
       
    50         iGroupMgrInterface( aGroupMgrInterface )
       
    51     {
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CCASearchInterfacePC: ConstructL
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CCASearchInterfacePC::ConstructL(  )
       
    59     {
       
    60     iStoredGroupsInterface = CCAStorageManagerFactory::GroupListInterfaceL();
       
    61     }
       
    62 
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CCASearchInterfacePC: NewL
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CCASearchInterfacePC* CCASearchInterfacePC::NewL( MCASearchInterface* aSearchInterface,
       
    69                                                   MCABackgroundInterface& aBackgroundInterface,
       
    70                                                   MCAGroupManagerInterface& aGroupMgrInterface )
       
    71     {
       
    72 
       
    73 
       
    74     CCASearchInterfacePC* self = new ( ELeave ) CCASearchInterfacePC( aSearchInterface,
       
    75                                                                       aBackgroundInterface,
       
    76                                                                       aGroupMgrInterface );
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL();
       
    79     CleanupStack::Pop( self );
       
    80     return self;
       
    81 
       
    82     }
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CCASearchInterfacePC: Destructor
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CCASearchInterfacePC::~CCASearchInterfacePC()
       
    90     {
       
    91     if ( iBackgroundObserver )
       
    92         {
       
    93         iBackgroundInterface.UnRegisterBackgroundObserver( this );
       
    94         }
       
    95     // delete searchpairs
       
    96 
       
    97     if ( iSearchPairs )
       
    98         {
       
    99         iSearchPairs->ResetAndDestroy();
       
   100         delete iSearchPairs;
       
   101         iSearchPairs = NULL;
       
   102         }
       
   103 
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CCASearchInterfacePC: StartSearchL
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 TInt CCASearchInterfacePC::StartSearchL( TInt aSearchLimit,
       
   112                                          MCASearchObserverInterfacePC* aObserver, CSearchPairs* aSearchPairs )
       
   113     {
       
   114     //This code is not yet useful for the existing chat.
       
   115     //the current calls for searching to the engine are synchronous calls.
       
   116     AddObserver( aObserver );
       
   117 
       
   118     //For the existing chat application with synchronous calls
       
   119     //to search, pass NULL as the observer
       
   120     if ( !aSearchPairs )
       
   121         {
       
   122         aSearchPairs = SearchPairs();
       
   123         }
       
   124 
       
   125     return iSearchInterface->StartSearchL( *aSearchPairs, aSearchLimit, NULL );
       
   126     }
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CCASearchInterfacePC: EndSearchL
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 TInt CCASearchInterfacePC::EndSearchL()
       
   134     {
       
   135     RemoveObserver();
       
   136     return iSearchInterface->EndSearchL();
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CCASearchInterfacePC: SearchNextL
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 TInt CCASearchInterfacePC::SearchNextL( TInt aIndex, MCASearchObserverInterfacePC* aObserver )
       
   145     {
       
   146     //This code is not yet useful for the existing chat.
       
   147     //the current calls for searching to the engine are synchronous calls.
       
   148     AddObserver( aObserver );
       
   149 
       
   150     //For the existing chat application with synchronous calls
       
   151     //to search, pass NULL as the observer
       
   152     return iSearchInterface->SearchNextL( aIndex, NULL );
       
   153     }
       
   154 
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CCASearchInterfacePC: AddObserver
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CCASearchInterfacePC::AddObserver( MCASearchObserverInterfacePC* aObserver )
       
   161     {
       
   162     iSearchObserverPC = aObserver;
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CCASearchInterfacePC: RemoveObserver
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CCASearchInterfacePC::RemoveObserver()
       
   170     {
       
   171     //Not the owner of observer. so dont delete
       
   172     iSearchObserverPC = NULL;
       
   173     }
       
   174 
       
   175 
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CCASearchInterfacePC: HandleSearchError
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CCASearchInterfacePC::HandleSearchError( TInt aErrorCode )
       
   182     {
       
   183     if ( iSearchObserverPC )
       
   184         {
       
   185         iSearchObserverPC->HandleSearchError( aErrorCode );
       
   186         }
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CCASearchInterfacePC: HandleSearchFinished
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CCASearchInterfacePC::HandleSearchFinished( )
       
   194     {
       
   195     if ( iSearchObserverPC )
       
   196         {
       
   197         iSearchObserverPC->HandleSearchFinished();
       
   198         }
       
   199 
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CCASearchInterfacePC::BackgroundTaskStatus
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 TInt CCASearchInterfacePC::BackgroundTaskStatus( TEnumsPC::TCABackgroundTasks aTaskID )
       
   207     {
       
   208     MCABackgroundInterface::TCABackgroundTasks eventSource = ConvertToTCABackgroundTasks( aTaskID );
       
   209     return iBackgroundInterface.BackgroundTaskStatus( eventSource );
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CCASearchInterfacePC::RegisterBackgroundObserver
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 TInt CCASearchInterfacePC::RegisterBackgroundObserver(
       
   217     MCASearchBackgroundObserverPC* aBackgroundObserver,
       
   218     TInt aTaskMask,
       
   219     TInt aEventMask	)
       
   220     {
       
   221     iBackgroundObserver = aBackgroundObserver;
       
   222     TInt status = iBackgroundInterface.RegisterBackgroundObserver( this,
       
   223                                                                    aTaskMask, aEventMask );
       
   224     ASSERT( aBackgroundObserver );
       
   225     return status;
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CCASearchInterfacePC::UnRegisterBackgroundObserver
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CCASearchInterfacePC::UnRegisterBackgroundObserver(
       
   233     MCASearchBackgroundObserverPC* aBackgroundObserver )
       
   234 
       
   235     {
       
   236     if ( iBackgroundObserver == aBackgroundObserver )
       
   237         {
       
   238         iBackgroundInterface.UnRegisterBackgroundObserver( this );
       
   239         }
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CCASearchInterfacePC::HandleBackgroundEvent
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CCASearchInterfacePC::HandleBackgroundEvent(
       
   247     MCABackgroundInterface::TCABackgroundTasks aEventSource,
       
   248     MCABackgroundInterface::TCABackgroundStatus aStatus,
       
   249     TInt aSubTaskNumber,
       
   250     TInt aLeaveCode
       
   251 )
       
   252     {
       
   253     TEnumsPC::TCABackgroundTasks eventSource = ConvertTCABackgroundTasksToTEnumsPC( aEventSource );
       
   254     TEnumsPC::TCABackgroundStatus status = ConvertTCABackgroundStatus( aStatus );
       
   255     iBackgroundObserver->HandleBackgroundEventPC( eventSource,
       
   256                                                   status, aSubTaskNumber, aLeaveCode );
       
   257     }
       
   258 
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CCASearchInterfacePC::ConvertToTCABackgroundTasks
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 MCABackgroundInterface::TCABackgroundTasks CCASearchInterfacePC::
       
   265 ConvertToTCABackgroundTasks( TEnumsPC::TCABackgroundTasks aSource )
       
   266     {
       
   267     MCABackgroundInterface::TCABackgroundTasks eventSource;
       
   268     switch ( aSource )
       
   269         {
       
   270         case TEnumsPC::EGroupFetch:
       
   271             {
       
   272             eventSource = MCABackgroundInterface::EGroupFetch;
       
   273             break;
       
   274             }
       
   275         case TEnumsPC::EPresenceTask:
       
   276             {
       
   277             eventSource = MCABackgroundInterface::EPresence;
       
   278             break;
       
   279             }
       
   280         case TEnumsPC::EWhisperSync:
       
   281             {
       
   282             eventSource = MCABackgroundInterface::EWhisperSync;
       
   283             break;
       
   284             }
       
   285         case TEnumsPC::EBlockGrantListFetch:
       
   286         default:
       
   287             {
       
   288             eventSource = MCABackgroundInterface::EBlockGrantListFetch;
       
   289             break;
       
   290             }
       
   291         }
       
   292 
       
   293     return eventSource;
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CCASearchInterfacePC::ConvertTCABackgroundTasksToTEnumsPC
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 TEnumsPC::TCABackgroundTasks CCASearchInterfacePC::ConvertTCABackgroundTasksToTEnumsPC
       
   301 ( MCABackgroundInterface::TCABackgroundTasks aEventSource )
       
   302     {
       
   303     TEnumsPC::TCABackgroundTasks eventSource;
       
   304     switch ( aEventSource )
       
   305         {
       
   306         case MCABackgroundInterface::EGroupFetch:
       
   307             {
       
   308             eventSource = TEnumsPC::EGroupFetch;
       
   309             break;
       
   310             }
       
   311         case MCABackgroundInterface::EPresence:
       
   312             {
       
   313             eventSource = TEnumsPC::EPresenceTask;
       
   314             break;
       
   315             }
       
   316         case MCABackgroundInterface::EWhisperSync:
       
   317             {
       
   318             eventSource = TEnumsPC::EWhisperSync;
       
   319             break;
       
   320             }
       
   321         case MCABackgroundInterface::EBlockGrantListFetch:
       
   322             {
       
   323             eventSource = TEnumsPC::EBlockGrantListFetch;
       
   324             break;
       
   325             }
       
   326         default:
       
   327             {
       
   328             eventSource = TEnumsPC::EFailed;
       
   329             break;
       
   330             }
       
   331         }
       
   332 
       
   333     return eventSource;
       
   334     }
       
   335 
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // CCASearchInterfacePC::ConvertTCABackgroundStatus
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 TEnumsPC::TCABackgroundStatus CCASearchInterfacePC::ConvertTCABackgroundStatus
       
   342 ( MCABackgroundInterface::TCABackgroundStatus aStatus )
       
   343     {
       
   344     TEnumsPC::TCABackgroundStatus status;
       
   345 
       
   346     switch ( aStatus )
       
   347         {
       
   348         case MCABackgroundInterface::EUnknown:
       
   349             {
       
   350             status = TEnumsPC::EUnknownStatus;
       
   351             break;
       
   352             }
       
   353         case MCABackgroundInterface::EIdleStarted:
       
   354             {
       
   355             status = TEnumsPC::EIdleStarted;
       
   356             break;
       
   357             }
       
   358         case MCABackgroundInterface::EStarting:
       
   359             {
       
   360             status = TEnumsPC::EStarting;
       
   361             break;
       
   362             }
       
   363         case MCABackgroundInterface::EWaiting:
       
   364             {
       
   365             status = TEnumsPC::EWaiting;
       
   366             break;
       
   367             }
       
   368         case MCABackgroundInterface::ECompleted:
       
   369             {
       
   370             status = TEnumsPC::ECompleted;
       
   371             break;
       
   372             }
       
   373         case MCABackgroundInterface::ECancelled:
       
   374             {
       
   375             status = TEnumsPC::ECancelled;
       
   376             break;
       
   377             }
       
   378         case MCABackgroundInterface::EFailed:
       
   379         default:
       
   380             {
       
   381             status = TEnumsPC::EFailedStatus;
       
   382             break;
       
   383             }
       
   384         }
       
   385 
       
   386     return status;
       
   387     }
       
   388 
       
   389 
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CCASearchInterfacePC::SetRequestL
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 void CCASearchInterfacePC::SetRequestL(  RArray<TEnumsPC::TSearchCriteria>&  aSearchCriteriaArray,
       
   396                                          CDesCArray& aSearchStringArray )
       
   397     {
       
   398     TInt count = aSearchCriteriaArray.Count();
       
   399     ASSERT( count );
       
   400     SetSearchPairsL( count );
       
   401 
       
   402     for ( TInt i( 0 ); i < count; i++ )
       
   403         {
       
   404         CImpsSearchRequest* request = CImpsSearchRequest::NewL();
       
   405         CleanupStack::PushL( request );
       
   406         request->SetRequestL( ConvertToTImpsSearchElement(
       
   407                                   aSearchCriteriaArray[i] ), aSearchStringArray[i] );
       
   408         iSearchPairs->AppendL( request ); //Takes the ownership
       
   409         CleanupStack::Pop( request );
       
   410         }
       
   411 
       
   412     }
       
   413 
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CCASearchInterfacePC::ConvertToTImpsSearchElement
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 TImpsSearchElement CCASearchInterfacePC::
       
   420 ConvertToTImpsSearchElement( TEnumsPC::TSearchCriteria aElement )
       
   421     {
       
   422     TImpsSearchElement searchElement( EImpsUserID );
       
   423 
       
   424     switch ( aElement )
       
   425         {
       
   426         case TEnumsPC::ESearchGroupName:
       
   427             {
       
   428             searchElement = EImpsGroupName;
       
   429             break;
       
   430             }
       
   431         case TEnumsPC::ESearchGroupTopic:
       
   432             {
       
   433             searchElement = EImpsGroupTopic;
       
   434             break;
       
   435             }
       
   436         case TEnumsPC::ESearchGroupUserIDJoined:
       
   437             {
       
   438             searchElement = EImpsGroupUserIDJoined;
       
   439             break;
       
   440             }
       
   441         case TEnumsPC::ESearchUserName:
       
   442             {
       
   443             searchElement = EImpsUserFirstName;
       
   444             break;
       
   445             }
       
   446 
       
   447         case TEnumsPC::ESearchUserLastName:
       
   448             {
       
   449             searchElement = EImpsUserLastName;
       
   450             break;
       
   451             }
       
   452         case TEnumsPC::ESearchUserID:
       
   453             {
       
   454             searchElement = EImpsUserID;
       
   455             break;
       
   456             }
       
   457         case TEnumsPC::ESearchUserMobileNumber:
       
   458             {
       
   459             searchElement = EImpsUserMobileNumber;
       
   460             break;
       
   461             }
       
   462         case TEnumsPC::ESearchUserEmailAddress:
       
   463             {
       
   464             searchElement = EImpsUserEmailAddress;
       
   465             break;
       
   466             }
       
   467         default:
       
   468             {
       
   469             break;
       
   470             }
       
   471         }
       
   472 
       
   473     return searchElement;
       
   474     }
       
   475 
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // CCASearchInterfacePC::SearchPairs
       
   479 // (other items were commented in a header).
       
   480 // -----------------------------------------------------------------------------
       
   481 //
       
   482 CSearchPairs* CCASearchInterfacePC::SearchPairs()
       
   483     {
       
   484     return iSearchPairs;
       
   485     }
       
   486 
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CCASearchInterfacePC::SetSearchPairsL
       
   490 // (other items were commented in a header).
       
   491 // -----------------------------------------------------------------------------
       
   492 //
       
   493 void CCASearchInterfacePC::SetSearchPairsL( TInt aCount )
       
   494     {
       
   495     if ( iSearchPairs )
       
   496         {
       
   497         iSearchPairs->ResetAndDestroy();
       
   498         delete iSearchPairs;
       
   499         iSearchPairs = NULL;
       
   500         }
       
   501 
       
   502     if ( aCount > 0 )
       
   503         {
       
   504         iSearchPairs = new ( ELeave ) CSearchPairs( aCount );
       
   505         }
       
   506 
       
   507     }
       
   508 
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CCASearchInterfacePC::IsSearchPairsSet
       
   512 // (other items were commented in a header).
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 TBool CCASearchInterfacePC::IsSearchPairsSet()
       
   516     {
       
   517     if ( SearchPairs() )
       
   518         {
       
   519         return ETrue;
       
   520         }
       
   521     else
       
   522         {
       
   523         return EFalse;
       
   524         }
       
   525     }
       
   526 
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CCASearchInterfacePC::GetSearchStringLC
       
   530 // (other items were commented in a header).
       
   531 // -----------------------------------------------------------------------------
       
   532 //
       
   533 HBufC* CCASearchInterfacePC::GetSearchStringLC()
       
   534     {
       
   535     HBufC* searchString = HBufC::NewLC( 0 );
       
   536 
       
   537     TInt count = iSearchPairs->Count();
       
   538 
       
   539     for ( TInt i = 0; i < count; i++ )
       
   540         {
       
   541         TPtrC newValue = ( *iSearchPairs )[i]->Value();
       
   542 
       
   543         TInt space = 0;
       
   544         if ( i < count - 1 )
       
   545             {
       
   546             // Memory needed for space
       
   547             space = KSpace().Length();
       
   548             }
       
   549 
       
   550         // Reallocate for adding
       
   551         searchString = searchString->ReAllocL(
       
   552                            searchString->Length() + newValue.Length() + space );
       
   553 
       
   554         // Update cleanup stack
       
   555         // we are deliberately calling pop and pushL for
       
   556         // because we are poping old value and pushing new value
       
   557         // Codescanner warning ignored
       
   558         CleanupStack::Pop( ); //searchString
       
   559         CleanupStack::PushL( searchString );
       
   560 
       
   561         // Append data
       
   562         TPtr searchStringPtr( searchString->Des() );
       
   563         searchStringPtr.Append( newValue );
       
   564         if ( i < count - 1 )
       
   565             {
       
   566             // Append space
       
   567             searchStringPtr.Append( KEmptyDesC );
       
   568             }
       
   569         }
       
   570     return searchString;
       
   571     }
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // CCASearchInterfacePC: FindAnyContactL
       
   575 // -----------------------------------------------------------------------------
       
   576 //
       
   577 TBool CCASearchInterfacePC::FindAnyContactL( const TDesC& aContactId )
       
   578     {
       
   579     MCAStoredContacts* contacts =
       
   580         CCAStorageManagerFactory::ContactListInterfaceL();
       
   581     if ( contacts->FindAnyContact( aContactId ) )
       
   582         {
       
   583         return ETrue;
       
   584         }
       
   585     return EFalse;
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CCASearchInterfacePC: GetPropertiesL
       
   590 // -----------------------------------------------------------------------------
       
   591 //
       
   592 TEnumsPC::TImpsCSPAllErrors CCASearchInterfacePC::GetPropertiesL( const TDesC& aGroupId,
       
   593                                                                   CImpsCommonGroupProps*& aCommonProps,
       
   594                                                                   CImpsPrivateGroupProps*& aPrivateProps )
       
   595     {
       
   596     MCAGroupOperations* grOps = iGroupMgrInterface.GroupOperationsL( aGroupId );
       
   597 
       
   598     TInt err( KErrNone );
       
   599 
       
   600     err = grOps->GetPropertiesL( aCommonProps, aPrivateProps );
       
   601     TEnumsPC::TImpsCSPAllErrors impsErr = ( TEnumsPC::TImpsCSPAllErrors )err;
       
   602     return impsErr;
       
   603     }
       
   604 
       
   605 // -----------------------------------------------------------------------------
       
   606 // CCASearchInterfacePC::GetGroupName
       
   607 // -----------------------------------------------------------------------------
       
   608 //
       
   609 TPtrC CCASearchInterfacePC::GetGroupNameL( const TDesC& aWvid, TBool& aHasCommonProps,
       
   610                                            TEnumsPC::TImpsCSPAllErrors& aImpsError )
       
   611     {
       
   612     // we have the group so we can fetch the properties for it
       
   613     CImpsPrivateGroupProps* privateProps = NULL;
       
   614     CImpsCommonGroupProps* commonProps = NULL;
       
   615     MCAGroupOperations* grOps =
       
   616         iGroupMgrInterface.GroupOperationsL( aWvid );
       
   617     if ( grOps )
       
   618         {
       
   619         aImpsError = ( TEnumsPC::TImpsCSPAllErrors )grOps->GetPropertiesL(
       
   620                          commonProps, privateProps ) ;
       
   621         if ( commonProps )
       
   622             {
       
   623             aHasCommonProps = ETrue;
       
   624             return commonProps->GroupName();
       
   625             }
       
   626         else
       
   627             {
       
   628             aHasCommonProps = EFalse;
       
   629             }
       
   630 
       
   631         }
       
   632     return KNullDesC(); //Error condition
       
   633     }
       
   634 
       
   635 // -----------------------------------------------------------------------------
       
   636 // CCASearchInterfacePC: SetGroupNameL
       
   637 // -----------------------------------------------------------------------------
       
   638 //
       
   639 TEnumsPC::TImpsCSPAllErrors CCASearchInterfacePC::ConvertImpsErrorToUiEnums( TInt aImpsError )
       
   640     {
       
   641     TEnumsPC::TImpsCSPAllErrors impsErr;
       
   642     switch ( aImpsError )
       
   643         {
       
   644         case ECSPInsufficientGroupPrivileges:
       
   645             {
       
   646             impsErr = TEnumsPC::ECSPInsufficientGroupPrivileges;
       
   647             break;
       
   648             }
       
   649         case ECSPNotSupported:
       
   650             {
       
   651             impsErr = TEnumsPC::ECSPNotSupported;
       
   652             break;
       
   653             }
       
   654         case ECSPInvalidParameter:
       
   655             {
       
   656             impsErr =  TEnumsPC::ECSPInvalidParameter;
       
   657             break;
       
   658             }
       
   659         case 0:
       
   660             {
       
   661             impsErr =  TEnumsPC::EImpsErrNone;
       
   662             break;
       
   663             }
       
   664         default:
       
   665             {
       
   666             impsErr = TEnumsPC::ECSPMultipleErrors; //general errors.
       
   667             break;
       
   668             }
       
   669         }
       
   670     return impsErr;
       
   671     }
       
   672 // -----------------------------------------------------------------------------
       
   673 // CCASearchInterfacePC: SetGroupNameL
       
   674 // -----------------------------------------------------------------------------
       
   675 //
       
   676 void CCASearchInterfacePC::SetGroupNameL( const TDesC& aGroupId, const TDesC& aGroupName )
       
   677     {
       
   678     MCAStoredGroups* storedGroups =
       
   679         CCAStorageManagerFactory::GroupListInterfaceL();
       
   680     MCAExtendedStoredGroup* storedGrp =
       
   681         static_cast<MCAExtendedStoredGroup*>( storedGroups->FindGroup( aGroupId ) );
       
   682     storedGrp->SetGroupNameL( aGroupName );
       
   683     }
       
   684 // -----------------------------------------------------------------------------
       
   685 // CCASearchInterfacePC: SaveChangesL
       
   686 // -----------------------------------------------------------------------------
       
   687 //
       
   688 void CCASearchInterfacePC::SaveChangesL( const TDesC& aGroupId )
       
   689     {
       
   690     if ( iStoredGroupsInterface )
       
   691         {
       
   692         MCAExtendedStoredGroup* storedGrp =
       
   693             static_cast<MCAExtendedStoredGroup*>( iStoredGroupsInterface->FindGroup( aGroupId ) );
       
   694         if ( storedGrp )
       
   695             {
       
   696             storedGrp->SaveChangesL();
       
   697             }
       
   698         }
       
   699     }
       
   700 // -----------------------------------------------------------------------------
       
   701 // CCASearchInterfacePC: CreateGroupL
       
   702 // -----------------------------------------------------------------------------
       
   703 //
       
   704 void CCASearchInterfacePC::CreateGroupL( const TDesC& aGroupId )
       
   705     {
       
   706     if ( iStoredGroupsInterface )
       
   707         {
       
   708         // Ownership not transferred to caller. Hence CodeScanner occasionally gives
       
   709         //false positives for this issue and the warning is ignored.
       
   710         MCAExtendedStoredGroup* group = iStoredGroupsInterface->CreateGroupL();
       
   711 
       
   712         if ( group )
       
   713             {
       
   714             CleanupStack::PushL( group );
       
   715             group->SetGroupIdL( aGroupId );
       
   716             CleanupStack::Pop();
       
   717             }
       
   718 
       
   719         }
       
   720     }
       
   721 
       
   722 // -----------------------------------------------------------------------------
       
   723 // CCASearchInterfacePC::GetPairArrayForServerContactsArrayL
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 MCAServerContactsArrayPC* CCASearchInterfacePC::GetPairArrayForServerContactsArrayLC()
       
   727     {
       
   728 
       
   729     CCAServerContactsArrayPC* pairsArray = NULL;
       
   730 
       
   731     if ( iStoredGroupsInterface )
       
   732         {
       
   733 
       
   734         RPointerArray<MCAStoredGroup> groupList;
       
   735 
       
   736         CDesCArray* groupNames = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   737         CleanupStack::PushL( groupNames );
       
   738 
       
   739         CDesCArray* groupIds = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   740         CleanupStack::PushL( groupIds );
       
   741 
       
   742         CleanupClosePushL( groupList );
       
   743 
       
   744 
       
   745         iStoredGroupsInterface->PopulateGroupsListL( groupList );
       
   746 
       
   747         TInt count( groupList.Count() );
       
   748         //For each item in the group list get the groupname and group id
       
   749         for ( TInt index( 0 ); index < count; index++ )
       
   750             {
       
   751             groupNames->AppendL( groupList[ index ]->GroupName() );
       
   752             groupIds->AppendL( groupList[ index ]->GroupId() );
       
   753             }
       
   754 
       
   755         //Codescanner warning ignored since we have used CleanupClosePushL
       
   756         //to push the groupList
       
   757         CleanupStack::PopAndDestroy(); // groupList.Close()
       
   758 
       
   759         // servercontactsarray takes the ownership. Codescanner warning ignored
       
   760         CleanupStack::Pop( 2 ); // groupIds,groupNames
       
   761 
       
   762         pairsArray = CCAServerContactsArrayPC::NewL( groupNames, groupIds, KNullDesC );
       
   763 
       
   764         CleanupStack::PushL( pairsArray );
       
   765 
       
   766         }
       
   767 
       
   768 
       
   769     //Not owned. Transfer ownership of pairsArray to the caller.
       
   770     return pairsArray;
       
   771 
       
   772     }
       
   773 
       
   774 // -----------------------------------------------------------------------------
       
   775 // CCASearchInterfacePC::FindGroup
       
   776 // -----------------------------------------------------------------------------
       
   777 //
       
   778 TBool CCASearchInterfacePC::FindGroup( const TDesC& aWvid )
       
   779     {
       
   780     if ( iStoredGroupsInterface )
       
   781         {
       
   782         MCAExtendedStoredGroup* group =
       
   783             static_cast <MCAExtendedStoredGroup*> (
       
   784                 iStoredGroupsInterface->FindGroup( aWvid ) );
       
   785 
       
   786         if ( group )
       
   787             {
       
   788             return ETrue;
       
   789             }
       
   790         }
       
   791     return EFalse;//error condition or did not find a group by wvid
       
   792     }
       
   793 
       
   794 
       
   795 // -----------------------------------------------------------------------------
       
   796 // CCASearchInterfacePC::DeleteGroupL
       
   797 // -----------------------------------------------------------------------------
       
   798 //
       
   799 TInt CCASearchInterfacePC::DeleteGroupL( const TDesC& aGroupId, TBool aDeleteFromNetwork )
       
   800     {
       
   801     return iGroupMgrInterface.DeleteGroupL( aGroupId, aDeleteFromNetwork );
       
   802     }
       
   803 
       
   804 // -----------------------------------------------------------------------------
       
   805 // CCASearchInterfacePC::IsFavouriteChatGroup
       
   806 // -----------------------------------------------------------------------------
       
   807 //
       
   808 TBool CCASearchInterfacePC::IsFavouriteChatGroup( const TDesC& aGroupId ) const
       
   809     {
       
   810     TBool isFavourite( EFalse );
       
   811 
       
   812     MCAStoredGroup* group = iStoredGroupsInterface->FindGroup( aGroupId );
       
   813     if ( group )
       
   814         {
       
   815         isFavourite = ( group->StorageType() ==
       
   816                         TStorageManagerGlobals::EStoragePersistent );
       
   817         }
       
   818     return isFavourite;
       
   819     }
       
   820 // -----------------------------------------------------------------------------
       
   821 // CCASearchInterfacePC::JoinedGroups
       
   822 // -----------------------------------------------------------------------------
       
   823 //
       
   824 TInt CCASearchInterfacePC::JoinedGroups()
       
   825     {
       
   826     return iGroupMgrInterface.JoinedGroups();
       
   827     }
       
   828 // End of File
       
   829