phonebookui/Phonebook2/UIControls/src/CPbk2FetchDlgGroupMarker.cpp
changeset 0 e686773b3f54
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:  Phonebook 2 fetch dialog group page selection marker.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2FetchDlgGroupMarker.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include <MPbk2FetchDlg.h>
       
    23 #include <CPbk2NamesListControl.h>
       
    24 
       
    25 // Virtual Phonebook
       
    26 #include <MVPbkContactLinkArray.h>
       
    27 #include <MVPbkContactLink.h>
       
    28 #include <MVPbkStoreContact.h>
       
    29 #include <MVPbkContactViewBase.h>
       
    30 #include <CVPbkContactManager.h>
       
    31 #include <MVPbkContactOperationBase.h>
       
    32 #include <MVPbkContactGroup.h>
       
    33 
       
    34 // System includes
       
    35 
       
    36 /// Unnamed namespace for local definitions
       
    37 namespace {
       
    38 
       
    39 #ifdef _DEBUG
       
    40 
       
    41 enum TPanicCode
       
    42     {
       
    43     ELogic = 1
       
    44     };
       
    45 
       
    46 void Panic( TInt aReason )
       
    47     {
       
    48     _LIT( KPanicText, "CPbk2FetchDlgGroupMarker" );
       
    49     User::Panic( KPanicText, aReason );
       
    50     }
       
    51 
       
    52 #endif // _DEBUG
       
    53 
       
    54 }
       
    55 
       
    56 // --------------------------------------------------------------------------
       
    57 // CPbk2FetchDlgGroupMarker::CPbk2FetchDlgGroupMarker
       
    58 // --------------------------------------------------------------------------
       
    59 //
       
    60 CPbk2FetchDlgGroupMarker::CPbk2FetchDlgGroupMarker
       
    61         ( CVPbkContactManager& aContactManager,
       
    62           MVPbkContactLinkArray& aSelectedContacts,
       
    63           MVPbkContactViewBase& aGroupsView,
       
    64           CPbk2NamesListControl& aControl ):
       
    65             CActive( EPriorityIdle ),
       
    66             iContactManager( aContactManager ),
       
    67             iSelectedContacts( aSelectedContacts ),
       
    68             iGroupsView( aGroupsView ),
       
    69             iControl( aControl )
       
    70     {
       
    71     CActiveScheduler::Add( this );
       
    72     }
       
    73 
       
    74 // --------------------------------------------------------------------------
       
    75 // CPbk2FetchDlgGroupMarker::~CPbk2FetchDlgGroupMarker
       
    76 // --------------------------------------------------------------------------
       
    77 //
       
    78 CPbk2FetchDlgGroupMarker::~CPbk2FetchDlgGroupMarker()
       
    79     {
       
    80     Cancel();
       
    81     delete iRetrieveOperation;
       
    82     delete iStoreContact;
       
    83     }
       
    84 
       
    85 // --------------------------------------------------------------------------
       
    86 // CPbk2FetchDlgGroupMarker::ConstructL
       
    87 // --------------------------------------------------------------------------
       
    88 //
       
    89 inline void CPbk2FetchDlgGroupMarker::ConstructL()
       
    90     {
       
    91     }
       
    92 
       
    93 // --------------------------------------------------------------------------
       
    94 // CPbk2FetchDlgGroupPage::NewL
       
    95 // --------------------------------------------------------------------------
       
    96 //
       
    97 CPbk2FetchDlgGroupMarker* CPbk2FetchDlgGroupMarker::NewL
       
    98         ( CVPbkContactManager& aContactManager,
       
    99           MVPbkContactLinkArray& aSelectedContacts,
       
   100           MVPbkContactViewBase& aGroupsView,
       
   101           CPbk2NamesListControl& aControl )
       
   102     {
       
   103     CPbk2FetchDlgGroupMarker* self = new ( ELeave ) CPbk2FetchDlgGroupMarker
       
   104         ( aContactManager, aSelectedContacts, aGroupsView, aControl );
       
   105     CleanupStack::PushL( self );
       
   106     self->ConstructL();
       
   107     CleanupStack::Pop( self );
       
   108     return self;
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CPbk2FetchDlgGroupMarker::MarkSelectedGroupsL
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 void CPbk2FetchDlgGroupMarker::MarkSelectedGroupsL()
       
   116     {
       
   117     iCursor = 0;
       
   118     iState = ERetrieving;
       
   119     IssueRequest();
       
   120     }
       
   121 
       
   122 // --------------------------------------------------------------------------
       
   123 // CPbk2FetchDlgGroupMarker::RunL
       
   124 // --------------------------------------------------------------------------
       
   125 //
       
   126 void CPbk2FetchDlgGroupMarker::RunL()
       
   127     {
       
   128     switch ( iState )
       
   129         {
       
   130         case ERetrieving:
       
   131             {
       
   132             RetrieveNextGroupL();
       
   133             break;
       
   134             }
       
   135         case EInspecting:
       
   136             {
       
   137             SelectGroupL();
       
   138             break;
       
   139             }
       
   140         case EStopping:     // FALLTHROUGH
       
   141         default:
       
   142             {
       
   143             // Do nothing
       
   144             break;
       
   145             }
       
   146         }
       
   147     }
       
   148 
       
   149 // --------------------------------------------------------------------------
       
   150 // CPbk2FetchDlgGroupMarker::DoCancel
       
   151 // --------------------------------------------------------------------------
       
   152 //
       
   153 void CPbk2FetchDlgGroupMarker::DoCancel()
       
   154     {
       
   155     delete iRetrieveOperation;
       
   156     iRetrieveOperation = NULL;
       
   157     }
       
   158 
       
   159 // --------------------------------------------------------------------------
       
   160 // CPbk2FetchDlgGroupMarker::RunError
       
   161 // --------------------------------------------------------------------------
       
   162 //
       
   163 TInt CPbk2FetchDlgGroupMarker::RunError( TInt /*aError*/ )
       
   164     {
       
   165     // Stop on errors
       
   166     Cancel();
       
   167     return KErrNone;
       
   168     }
       
   169 
       
   170 // --------------------------------------------------------------------------
       
   171 // CPbk2FetchDlgGroupMarker::VPbkSingleContactOperationComplete
       
   172 // --------------------------------------------------------------------------
       
   173 //
       
   174 void CPbk2FetchDlgGroupMarker::VPbkSingleContactOperationComplete
       
   175         ( MVPbkContactOperationBase& /*aOperation*/,
       
   176           MVPbkStoreContact* aContact )
       
   177     {
       
   178     delete iStoreContact;
       
   179     iStoreContact = aContact;
       
   180 
       
   181     iState = EInspecting;
       
   182     IssueRequest();
       
   183     }
       
   184 
       
   185 // --------------------------------------------------------------------------
       
   186 // CPbk2FetchDlgGroupMarker::VPbkSingleContactOperationFailed
       
   187 // --------------------------------------------------------------------------
       
   188 //
       
   189 void CPbk2FetchDlgGroupMarker::VPbkSingleContactOperationFailed
       
   190         ( MVPbkContactOperationBase& /*aOperation*/, TInt /*aError*/ )
       
   191     {
       
   192     // Stop on errors
       
   193     iState = EStopping;
       
   194     IssueRequest();
       
   195     }
       
   196 
       
   197 // --------------------------------------------------------------------------
       
   198 // CPbk2FetchDlgGroupMarker::RetrieveNextGroupL
       
   199 // --------------------------------------------------------------------------
       
   200 //
       
   201 void CPbk2FetchDlgGroupMarker::RetrieveNextGroupL()
       
   202     {
       
   203     TInt count = iGroupsView.ContactCountL();
       
   204 
       
   205     if ( count > iCursor )
       
   206         {
       
   207         MVPbkContactLink* link = iGroupsView.CreateLinkLC( iCursor );
       
   208 
       
   209         delete iRetrieveOperation;
       
   210         iRetrieveOperation = NULL;
       
   211         iRetrieveOperation =  iContactManager.RetrieveContactL
       
   212             ( *link, *this );    
       
   213     
       
   214         CleanupStack::PopAndDestroy(); // link
       
   215         }
       
   216     else
       
   217         {
       
   218         // All groups are inspected
       
   219         iState = EStopping;
       
   220         IssueRequest();
       
   221         }
       
   222     }
       
   223 
       
   224 // --------------------------------------------------------------------------
       
   225 // CPbk2FetchDlgGroupMarker::SelectGroupL
       
   226 // --------------------------------------------------------------------------
       
   227 //
       
   228 void CPbk2FetchDlgGroupMarker::SelectGroupL()
       
   229     {
       
   230     MVPbkContactGroup* group = iStoreContact->Group();
       
   231     __ASSERT_DEBUG( group, Panic( ELogic ) );
       
   232 
       
   233     MVPbkContactLinkArray* members = group->ItemsContainedLC();
       
   234     
       
   235     if ( SelectionContainsAllMembersL( *members ) )
       
   236         {
       
   237         iControl.SetSelectedContactL( iCursor, ETrue );
       
   238         }
       
   239     else
       
   240         {
       
   241         iControl.SetSelectedContactL( iCursor, EFalse );
       
   242         }
       
   243 
       
   244     CleanupStack::PopAndDestroy(); // members
       
   245     
       
   246     ++iCursor;
       
   247 
       
   248     iState = ERetrieving;
       
   249     IssueRequest();
       
   250     }
       
   251 
       
   252 // --------------------------------------------------------------------------
       
   253 // CPbk2FetchDlgGroupMarker::SelectionContainsAllMembersL
       
   254 // --------------------------------------------------------------------------
       
   255 //
       
   256 TBool CPbk2FetchDlgGroupMarker::SelectionContainsAllMembersL
       
   257         ( MVPbkContactLinkArray& aMembers )
       
   258     {
       
   259     TBool ret = ETrue;
       
   260 
       
   261     if ( iSelectedContacts.Count() < aMembers.Count() )
       
   262         {
       
   263         // The selection is smaller than member count
       
   264         ret = EFalse;
       
   265         }
       
   266 
       
   267     for ( TInt i = 0; ret && i < aMembers.Count(); ++i )
       
   268         {
       
   269         MVPbkContactLink* compareLink = aMembers.At( i ).CloneLC();
       
   270         if ( iSelectedContacts.Find( *compareLink ) < KErrNone )
       
   271             {
       
   272             // Group member was not found from selected contacts
       
   273             ret = EFalse;
       
   274             }
       
   275         CleanupStack::PopAndDestroy(); // compareLink
       
   276         }
       
   277 
       
   278     return ret;
       
   279     }
       
   280 
       
   281 // --------------------------------------------------------------------------
       
   282 // CPbk2FetchDlgGroupMarker::IssueRequest
       
   283 // --------------------------------------------------------------------------
       
   284 //
       
   285 void CPbk2FetchDlgGroupMarker::IssueRequest()
       
   286     {
       
   287     TRequestStatus* status = &iStatus;
       
   288     User::RequestComplete( status, KErrNone );
       
   289     SetActive();
       
   290     }
       
   291 
       
   292 // End of File