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