phonebookengines/VirtualPhonebook/VPbkEng/src/CVPbkTopContactManagerImpl.cpp
changeset 0 e686773b3f54
child 39 a6539d1e8e43
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Top Contact management implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "CVPbkTopContactManagerImpl.h"
       
    21 
       
    22 #include <CVPbkContactStoreUriArray.h>
       
    23 #include <CVPbkContactManager.h>
       
    24 #include <CVPbkContactLinkArray.h>
       
    25 #include <MVPbkContactLink.h>
       
    26 
       
    27 #include "CVPbkTopContactOperation.h"
       
    28 
       
    29 
       
    30 CVPbkTopContactManagerImpl* CVPbkTopContactManagerImpl::NewL(
       
    31     CVPbkContactManager& aContactManager )
       
    32     {
       
    33     CVPbkTopContactManagerImpl* self =
       
    34         new (ELeave) CVPbkTopContactManagerImpl();
       
    35     CleanupStack::PushL( self );
       
    36     self->iContactManager = &aContactManager;
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop( self );
       
    39     return self;
       
    40     }
       
    41 
       
    42 CVPbkTopContactManagerImpl* CVPbkTopContactManagerImpl::NewL()
       
    43 	{
       
    44     CVPbkTopContactManagerImpl* self =
       
    45         new (ELeave) CVPbkTopContactManagerImpl();
       
    46 	CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48 	CleanupStack::Pop( self );
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 void CVPbkTopContactManagerImpl::ConstructL()
       
    53     {
       
    54     if ( !iContactManager )
       
    55         {
       
    56         // If a contact manager was not given, we need to create one.
       
    57         CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewLC();
       
    58         iOurContactManager = CVPbkContactManager::NewL(*uriArray);
       
    59         CleanupStack::PopAndDestroy( uriArray );
       
    60         iContactManager = iOurContactManager;
       
    61         }
       
    62     }
       
    63 
       
    64 CVPbkTopContactManagerImpl::CVPbkTopContactManagerImpl()
       
    65     {
       
    66     }
       
    67 
       
    68 CVPbkTopContactManagerImpl::~CVPbkTopContactManagerImpl()
       
    69     {
       
    70     delete iOurContactManager;
       
    71     }
       
    72 
       
    73 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::GetTopContactsViewL(
       
    74         MVPbkOperationResultObserver<MVPbkContactViewBase*>& aObserver,
       
    75         MVPbkOperationErrorObserver& aErrorObserver )
       
    76     {
       
    77     return CVPbkTopContactOperation::NewGetViewOperationL(
       
    78             *iContactManager,
       
    79             aObserver, 
       
    80             aErrorObserver,
       
    81             CVPbkTopContactOperation::EGetTopContacts );
       
    82     }
       
    83 
       
    84 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::GetNonTopContactsViewL(
       
    85         MVPbkOperationResultObserver<MVPbkContactViewBase*>& aObserver,
       
    86         MVPbkOperationErrorObserver& aErrorObserver )
       
    87     {
       
    88     return CVPbkTopContactOperation::NewGetViewOperationL(
       
    89             *iContactManager,
       
    90             aObserver, 
       
    91             aErrorObserver,
       
    92             CVPbkTopContactOperation::EGetNonTopContacts );
       
    93     }
       
    94 
       
    95 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::GetTopContactLinksL(
       
    96         MVPbkOperationResultObserver<MVPbkContactLinkArray*>& aObserver,
       
    97         MVPbkOperationErrorObserver& aErrorObserver )
       
    98     {
       
    99     return CVPbkTopContactOperation::NewGetViewLinksOperationL(
       
   100             *iContactManager,
       
   101             aObserver, 
       
   102             aErrorObserver,
       
   103             CVPbkTopContactOperation::EGetTopContactLinks );
       
   104     }
       
   105 
       
   106 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::GetNonTopContactLinksL(
       
   107         MVPbkOperationResultObserver<MVPbkContactLinkArray*>& aObserver,
       
   108         MVPbkOperationErrorObserver& aErrorObserver )
       
   109     {
       
   110     return CVPbkTopContactOperation::NewGetViewLinksOperationL(
       
   111             *iContactManager,
       
   112             aObserver, 
       
   113             aErrorObserver,
       
   114             CVPbkTopContactOperation::EGetNonTopContactLinks );
       
   115     }
       
   116 
       
   117 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::AddToTopL(
       
   118         const MVPbkContactLink& aContactLink,
       
   119         MVPbkOperationObserver& aObserver,
       
   120         MVPbkOperationErrorObserver& aErrorObserver )
       
   121     {
       
   122     CVPbkContactLinkArray* links = CVPbkContactLinkArray::NewLC();
       
   123     MVPbkContactLink* link = aContactLink.CloneLC();
       
   124     links->AppendL( link );
       
   125     CleanupStack::Pop(); // link
       
   126     MVPbkContactOperationBase* op = AddToTopL(
       
   127             *links, 
       
   128             aObserver,
       
   129             aErrorObserver );
       
   130     CleanupStack::PopAndDestroy( links );
       
   131     return op;
       
   132     }
       
   133 
       
   134 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::AddToTopL(
       
   135         const MVPbkContactLinkArray& aContactLinks,
       
   136         MVPbkOperationObserver& aObserver,
       
   137         MVPbkOperationErrorObserver& aErrorObserver )
       
   138     {
       
   139     return CVPbkTopContactOperation::NewTopOperationL(
       
   140             *iContactManager,
       
   141             aContactLinks,
       
   142             aObserver,
       
   143             aErrorObserver,
       
   144             CVPbkTopContactOperation::EAddToTop );
       
   145     }
       
   146 
       
   147 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::AddToTopL(
       
   148         const TDesC8& aPackedLinks,
       
   149         MVPbkOperationObserver& aObserver,
       
   150         MVPbkOperationErrorObserver& aErrorObserver )
       
   151     {
       
   152     MVPbkContactLinkArray* links = iContactManager->CreateLinksLC(
       
   153             aPackedLinks );
       
   154     MVPbkContactOperationBase* op = AddToTopL(
       
   155             *links,
       
   156             aObserver,
       
   157             aErrorObserver );
       
   158     CleanupStack::PopAndDestroy(); //links
       
   159     return op;
       
   160     }
       
   161 
       
   162 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::RemoveFromTopL(
       
   163         const MVPbkContactLink& aContactLink,
       
   164         MVPbkOperationObserver& aObserver,
       
   165         MVPbkOperationErrorObserver& aErrorObserver )
       
   166     {
       
   167     CVPbkContactLinkArray* links = CVPbkContactLinkArray::NewLC();
       
   168     MVPbkContactLink* link = aContactLink.CloneLC();
       
   169     links->AppendL( link );
       
   170     CleanupStack::Pop(); // link
       
   171     MVPbkContactOperationBase* op = RemoveFromTopL(
       
   172             *links, 
       
   173             aObserver, 
       
   174             aErrorObserver );
       
   175     CleanupStack::PopAndDestroy( links );
       
   176     return op;
       
   177     }
       
   178 
       
   179 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::RemoveFromTopL(
       
   180         const MVPbkContactLinkArray& aContactLinks,
       
   181         MVPbkOperationObserver& aObserver,
       
   182         MVPbkOperationErrorObserver& aErrorObserver )
       
   183     {
       
   184     return CVPbkTopContactOperation::NewTopOperationL(
       
   185             *iContactManager,
       
   186             aContactLinks,
       
   187             aObserver,
       
   188             aErrorObserver,
       
   189             CVPbkTopContactOperation::ERemoveFromTop );
       
   190     }
       
   191 
       
   192 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::RemoveFromTopL(
       
   193         const TDesC8& aPackedLinks,
       
   194         MVPbkOperationObserver& aObserver,
       
   195         MVPbkOperationErrorObserver& aErrorObserver )
       
   196     {
       
   197     MVPbkContactLinkArray* links = iContactManager->CreateLinksLC(
       
   198             aPackedLinks );
       
   199     MVPbkContactOperationBase* op = RemoveFromTopL(
       
   200             *links, 
       
   201             aObserver, 
       
   202             aErrorObserver );
       
   203     CleanupStack::PopAndDestroy(); //links
       
   204     return op;
       
   205     }
       
   206 
       
   207 MVPbkContactOperationBase* CVPbkTopContactManagerImpl::SetTopOrderL(
       
   208         const MVPbkContactLinkArray& aContactLinks,
       
   209         MVPbkOperationObserver& aObserver,
       
   210         MVPbkOperationErrorObserver& aErrorObserver )
       
   211     {
       
   212     return CVPbkTopContactOperation::NewTopOperationL(
       
   213             *iContactManager,
       
   214             aContactLinks,
       
   215             aObserver,
       
   216             aErrorObserver,
       
   217             CVPbkTopContactOperation::EReorderTop );
       
   218     }
       
   219 
       
   220 TBool CVPbkTopContactManagerImpl::IsTopContact(
       
   221         const MVPbkBaseContact& aContact )
       
   222     {
       
   223     return CVPbkTopContactOperation::TopOrder( aContact ) != KErrNotFound;
       
   224     }
       
   225 
       
   226 // end of file