phonebookui/Phonebook2/GroupExtension/src/CPguBelongsToGroupsCmd.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007-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 belongs to groups command.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPguBelongsToGroupsCmd.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "CPguGroupPopup.h"
       
    23 #include <Pbk2GroupUIRes.rsg>
       
    24 #include <Pbk2UIControls.rsg>
       
    25 #include <MPbk2CommandObserver.h>
       
    26 #include <MPbk2ContactUiControl.h>
       
    27 #include <CPbk2StoreConfiguration.h>
       
    28 #include <MPbk2AppUi.h>
       
    29 #include <MPbk2ApplicationServices.h>
       
    30 #include <MPbk2ContactViewSupplier.h>
       
    31 
       
    32 // Virtual Phonebook
       
    33 #include <CVPbkContactManager.h>
       
    34 #include <MVPbkContactLink.h>
       
    35 #include <MVPbkContactGroup.h>
       
    36 #include <MVPbkContactStore.h>
       
    37 #include <MVPbkContactStoreList.h>
       
    38 #include <MVPbkContactOperationBase.h>
       
    39 #include <TVPbkContactStoreUriPtr.h>
       
    40 
       
    41 // System includes
       
    42 #include <avkon.hrh>
       
    43 #include <coemain.h>
       
    44 
       
    45 // Debugging headers
       
    46 #include <Pbk2Debug.h>
       
    47 
       
    48 /// Unnamed namespace for local definitions
       
    49 namespace {
       
    50 
       
    51 #ifdef _DEBUG
       
    52 enum TPanicCode
       
    53     {
       
    54     EPanicPreCond_NewL = 1,
       
    55     EPanicPreCond_ExecuteLD,
       
    56     EPanicContactNotGroup,
       
    57     ERunL_InvalidState
       
    58     };
       
    59 
       
    60 void Panic(TPanicCode aReason)
       
    61     {
       
    62     _LIT(KPanicText, "CPguBelongsToGroupsCmd");
       
    63     User::Panic(KPanicText,aReason);
       
    64     }
       
    65 #endif // _DEBUG
       
    66 
       
    67 } /// namespace
       
    68 
       
    69 // --------------------------------------------------------------------------
       
    70 // CPguBelongsToGroupsCmd::CPguBelongsToGroupsCmd
       
    71 // --------------------------------------------------------------------------
       
    72 //
       
    73 CPguBelongsToGroupsCmd::CPguBelongsToGroupsCmd
       
    74         ( MPbk2ContactUiControl& aUiControl ) :
       
    75             CActive( CActive::EPriorityIdle ),
       
    76             iUiControl( &aUiControl )
       
    77     {
       
    78     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
    79         ("CPguBelongsToGroupsCmd::CPguBelongsToGroupsCmd(0x%x)"),this);
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // CPguBelongsToGroupsCmd::ConstructL
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 inline void CPguBelongsToGroupsCmd::ConstructL()
       
    87     {
       
    88     CActiveScheduler::Add( this );
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CPguBelongsToGroupsCmd::NewL
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 CPguBelongsToGroupsCmd* CPguBelongsToGroupsCmd::NewL
       
    96         ( MPbk2ContactUiControl& aUiControl )
       
    97     {
       
    98     CPguBelongsToGroupsCmd* self =
       
    99         new(ELeave) CPguBelongsToGroupsCmd( aUiControl );
       
   100     CleanupStack::PushL( self );
       
   101     self->ConstructL();
       
   102     CleanupStack::Pop( self );
       
   103     return self;
       
   104     }
       
   105 
       
   106 // --------------------------------------------------------------------------
       
   107 // CPguBelongsToGroupsCmd::~CPguBelongsToGroupsCmd
       
   108 // --------------------------------------------------------------------------
       
   109 //
       
   110 CPguBelongsToGroupsCmd::~CPguBelongsToGroupsCmd()
       
   111     {
       
   112     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   113         ("CPguBelongsToGroupsCmd::~CPguBelongsToGroupsCmd(0x%x)"),this);
       
   114     Cancel();
       
   115     delete iRetrieveOperation;
       
   116     delete iStoreContact;
       
   117     delete iGroupsJoined;
       
   118     }
       
   119 
       
   120 // --------------------------------------------------------------------------
       
   121 // CPguBelongsToGroupsCmd::ExecuteLD
       
   122 // --------------------------------------------------------------------------
       
   123 //
       
   124 void CPguBelongsToGroupsCmd::ExecuteLD()
       
   125     {
       
   126     __ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_ExecuteLD));
       
   127     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   128         ("CPguBelongsToGroupsCmd::ExecuteLD(0x%x)"), this);
       
   129 
       
   130     CleanupStack::PushL( this );
       
   131 
       
   132     if (iUiControl)
       
   133         {
       
   134         MVPbkContactLink* link = iUiControl->FocusedContactL()->CreateLinkLC();
       
   135         iRetrieveOperation =
       
   136             Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   137                 ContactManager().RetrieveContactL( *link, *this );
       
   138         CleanupStack::PopAndDestroy(); // link
       
   139         }
       
   140     else
       
   141         {
       
   142         IssueRequest( EFinishCommand );
       
   143         }
       
   144     CleanupStack::Pop( this );
       
   145     }
       
   146 
       
   147 // --------------------------------------------------------------------------
       
   148 // CPguBelongsToGroupsCmd::AddObserver
       
   149 // --------------------------------------------------------------------------
       
   150 //
       
   151 void CPguBelongsToGroupsCmd::AddObserver( MPbk2CommandObserver& aObserver )
       
   152     {
       
   153     iCommandObserver = &aObserver;
       
   154     }
       
   155 
       
   156 // --------------------------------------------------------------------------
       
   157 // CPguBelongsToGroupsCmd::ResetUiControl
       
   158 // --------------------------------------------------------------------------
       
   159 //
       
   160 void CPguBelongsToGroupsCmd::ResetUiControl(
       
   161         MPbk2ContactUiControl& aUiControl)
       
   162     {
       
   163     if (iUiControl == &aUiControl)
       
   164         {
       
   165         iUiControl = NULL;
       
   166         }
       
   167     }
       
   168 
       
   169 // --------------------------------------------------------------------------
       
   170 // CPguBelongsToGroupsCmd::RunL
       
   171 // --------------------------------------------------------------------------
       
   172 //
       
   173 void CPguBelongsToGroupsCmd::RunL()
       
   174     {
       
   175     switch ( iState )
       
   176         {
       
   177         case ELaunchPopup:
       
   178             {
       
   179             LaunchGroupPopupL();
       
   180             break;
       
   181             }
       
   182         case EFinishCommand:
       
   183             {
       
   184             if ( iCommandObserver )
       
   185                 {
       
   186                 iCommandObserver->CommandFinished( *this );
       
   187                 }
       
   188             break;
       
   189             }
       
   190         default:
       
   191             {
       
   192             __ASSERT_DEBUG( EFalse, Panic(ERunL_InvalidState) );
       
   193             break;
       
   194             }
       
   195         }
       
   196     }
       
   197 
       
   198 // --------------------------------------------------------------------------
       
   199 // CPguBelongsToGroupsCmd::DoCancel
       
   200 // --------------------------------------------------------------------------
       
   201 //
       
   202 void CPguBelongsToGroupsCmd::DoCancel()
       
   203     {
       
   204     // Do nothing
       
   205     }
       
   206 
       
   207 // --------------------------------------------------------------------------
       
   208 // CPguBelongsToGroupsCmd::RunError
       
   209 // --------------------------------------------------------------------------
       
   210 //
       
   211 TInt CPguBelongsToGroupsCmd::RunError( TInt aError )
       
   212     {
       
   213     CCoeEnv::Static()->HandleError( aError );
       
   214     return KErrNone;
       
   215     }
       
   216 
       
   217 // --------------------------------------------------------------------------
       
   218 // CPguBelongsToGroupsCmd::VPbkSingleContactOperationComplete
       
   219 // --------------------------------------------------------------------------
       
   220 //
       
   221 void CPguBelongsToGroupsCmd::VPbkSingleContactOperationComplete(
       
   222         MVPbkContactOperationBase& /*aOperation*/,
       
   223         MVPbkStoreContact* aContact )
       
   224     {
       
   225     delete iRetrieveOperation;
       
   226     iRetrieveOperation = NULL;
       
   227 
       
   228     iStoreContact = aContact;
       
   229     IssueRequest( ELaunchPopup );
       
   230     }
       
   231 
       
   232 // --------------------------------------------------------------------------
       
   233 // CPguBelongsToGroupsCmd::VPbkSingleContactOperationFailed
       
   234 // --------------------------------------------------------------------------
       
   235 //
       
   236 void CPguBelongsToGroupsCmd::VPbkSingleContactOperationFailed(
       
   237         MVPbkContactOperationBase& /*aOperation*/,
       
   238         TInt aError )
       
   239     {
       
   240     delete iRetrieveOperation;
       
   241     iRetrieveOperation = NULL;
       
   242     if ( iCommandObserver )
       
   243         {
       
   244         iCommandObserver->CommandFinished( *this );
       
   245         }
       
   246     CCoeEnv::Static()->HandleError( aError );
       
   247     }
       
   248 
       
   249 // --------------------------------------------------------------------------
       
   250 // CPguBelongsToGroupsCmd::IsContactIncluded
       
   251 // --------------------------------------------------------------------------
       
   252 //
       
   253 TBool CPguBelongsToGroupsCmd::IsContactIncluded(
       
   254         const MVPbkBaseContact& /*aContact*/ )
       
   255     {
       
   256     return EFalse;
       
   257     }
       
   258 
       
   259 
       
   260 // --------------------------------------------------------------------------
       
   261 // CPguBelongsToGroupsCmd::LaunchGroupPopupL
       
   262 // --------------------------------------------------------------------------
       
   263 //
       
   264 void CPguBelongsToGroupsCmd::LaunchGroupPopupL()
       
   265     {
       
   266     iGroupsJoined = iStoreContact->GroupsJoinedLC();
       
   267     CleanupStack::Pop();
       
   268 
       
   269     MVPbkContactViewBase* groupsView =
       
   270         Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   271             ViewSupplier().AllGroupsViewL();
       
   272 
       
   273     CPguGroupPopup* groupPopup = CPguGroupPopup::NewL(
       
   274             iGroupsJoined,
       
   275             R_QTN_PHOB_QTL_ENTRY_IS_IN_GRP,
       
   276             R_QTN_PHOB_ENTRY_IS_IN_NO_GRP,
       
   277             R_PBK2_SOFTKEYS_EMPTY_BACK_EMPTY,
       
   278             EAknListBoxViewerFlags,
       
   279             *groupsView );
       
   280 
       
   281     groupPopup->ExecuteLD();
       
   282 
       
   283     IssueRequest( EFinishCommand );
       
   284     }
       
   285 
       
   286 // --------------------------------------------------------------------------
       
   287 // CPguBelongsToGroupsCmd::IssueRequest
       
   288 // --------------------------------------------------------------------------
       
   289 //
       
   290 void CPguBelongsToGroupsCmd::IssueRequest( TProcessState aState )
       
   291     {
       
   292     if ( !IsActive() )
       
   293         {
       
   294         iState = aState;
       
   295         TRequestStatus* status = &iStatus;
       
   296         User::RequestComplete( status, KErrNone );
       
   297         SetActive();
       
   298         }
       
   299     }
       
   300 //  End of File