phonebookui/Phonebook/App/src/CPbkGroupMembersListAppView.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *          Provides group members list View methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CPbkGroupMembersListAppView.h"  // This class's declaration
       
    22 
       
    23 #include <barsread.h>					// TResourceReader
       
    24 #include <cntview.h>					// CContactGroupView
       
    25 #include <eikmenup.h>					// CEikMenuPane
       
    26 #include <akntitle.h>					// CAknTitlePane
       
    27 #include <aknNaviDe.h>					// CAknNavigationDecorator
       
    28 #include <akntabgrp.h>					// CAknTabGroup
       
    29 #include <AknQueryDialog.h>				// CAknQueryDialog
       
    30 #include <StringLoader.h>
       
    31 #include <cntitem.h>					// TContactItemId
       
    32 
       
    33 
       
    34 // Send UI
       
    35 #include <sendui.h>						// Send UI API
       
    36 #include <sendnorm.rsg>					// for Send UI functionality
       
    37 #include <SenduiMtmUids.h>				// Send UI MTM uid's
       
    38 
       
    39 #include <Phonebook.rsg>				// Phonebook resources
       
    40 #include <CPbkControlContainer.h>
       
    41 #include "CPbkAppUi.h"					// Phonebook application UI class
       
    42 #include "CPbkAssignToGroupCmd.h"
       
    43 #include "CPbkRemoveFromGroupCmd.h"
       
    44 #include "CPbkAppGlobals.h"
       
    45 
       
    46 #include <CPbkContactEngine.h>
       
    47 #include <PbkCommandHandler.h>
       
    48 #include <CPbkConstants.h>
       
    49 #include <CPbkAiwInterestArray.h>
       
    50 
       
    51 #include <PbkView.rsg>					// PbkView dll resources
       
    52 #include <CPbkViewState.h>
       
    53 #include <CPbkContactViewListControl.h>
       
    54 #include <CPbkGroupMembersFetchDlg.h>
       
    55 #include <PbkIconInfo.h>
       
    56 #include <Phonebook.hrh>
       
    57 #include <MenuFilteringFlags.h>
       
    58 #include <cshelp/phob.hlp.hrh>
       
    59 
       
    60 // Debugging headers
       
    61 #include <pbkdebug.h>
       
    62 #include "PbkProfiling.h"
       
    63 
       
    64 
       
    65 /// Unnamed namespace for local definitions
       
    66 namespace {
       
    67 
       
    68 // LOCAL CONSTANTS AND MACROS
       
    69 #ifdef _DEBUG
       
    70 enum TPanicCode
       
    71     {
       
    72     EPanicPostCond_DoActivateL = 1,
       
    73     EPanicPostCond_DoDeactivate,
       
    74     EPanicPreCond_HandleCommandL,
       
    75     EPanicPreCond_ConstructL,
       
    76     EPanicPostCond_ConstructL,
       
    77     EPanicPreCond_DynInitMenuPaneL,
       
    78     EPanicPreCond_CmdRemoveFromFolderL,
       
    79     EPanicPreCond_CmdFetchMembersL,
       
    80     EPanicPreCond_LoadGroupMembersViewL,
       
    81     EPanicPostCond_LoadGroupMembersViewL,
       
    82     EPanicPreCond_HandleCommandKeyL,
       
    83     EPanicIcon_StatusPaneUpdateL
       
    84     };
       
    85 #endif
       
    86 
       
    87 
       
    88 // ==================== LOCAL FUNCTIONS ====================
       
    89 
       
    90 #ifdef _DEBUG
       
    91 void Panic(TPanicCode aReason)
       
    92     {
       
    93     _LIT(KPanicText, "CPbkGroupMembersListAppView");
       
    94     User::Panic(KPanicText, aReason);
       
    95     }
       
    96 #endif
       
    97 
       
    98 }  // namespace
       
    99 
       
   100 
       
   101 // ================= MEMBER FUNCTIONS =======================
       
   102 
       
   103 // CPbkGroupMembersListAppView::TIsViewReady
       
   104 inline CPbkGroupMembersListAppView::TIsViewReady::TIsViewReady()
       
   105     : iReadyViewFlags(EReset)
       
   106     {
       
   107     }
       
   108 
       
   109 inline TBool AllBitsSet(TUint aFlags, TUint aBits)
       
   110     {
       
   111     return (((aFlags & aBits)==aBits) ? ETrue : EFalse);
       
   112     }
       
   113 
       
   114 inline TBool CPbkGroupMembersListAppView::TIsViewReady::AreViewsReady() const
       
   115     {
       
   116     return AllBitsSet(iReadyViewFlags, EAllGroupsReady | EControlReady);
       
   117     }
       
   118 
       
   119 inline void CPbkGroupMembersListAppView::TIsViewReady::SetAllGroupsViewReady()
       
   120     {
       
   121     iReadyViewFlags |= EAllGroupsReady;
       
   122     }
       
   123 
       
   124 inline void CPbkGroupMembersListAppView::TIsViewReady::SetControlReady()
       
   125     {
       
   126     iReadyViewFlags |= EControlReady;
       
   127     }
       
   128 
       
   129 ///////////////////////////////////////////////////////////////////////////////
       
   130 // CPbkGroupMembersListAppView
       
   131 
       
   132 inline CPbkGroupMembersListAppView::CPbkGroupMembersListAppView() :
       
   133         iGroupId(KNullContactId),
       
   134         iFocusedContact(KNullContactId)
       
   135     {
       
   136     }
       
   137 
       
   138 inline void CPbkGroupMembersListAppView::ConstructL()
       
   139     {
       
   140     // PreCond
       
   141      __ASSERT_DEBUG(!iContainer, Panic(EPanicPreCond_ConstructL));
       
   142 
       
   143     // Init base class
       
   144     // this base construct is profiled in base class CPbkContactListAppView
       
   145     BaseConstructL(R_PHONEBOOK_GROUPMEMBERSLIST_APPVIEW);
       
   146 
       
   147     // PostCond
       
   148      __ASSERT_DEBUG(!iContainer, Panic(EPanicPostCond_ConstructL));
       
   149     }
       
   150 
       
   151 CPbkGroupMembersListAppView* CPbkGroupMembersListAppView::NewL()
       
   152     {
       
   153     CPbkGroupMembersListAppView* self =
       
   154 		new (ELeave) CPbkGroupMembersListAppView();
       
   155     CleanupStack::PushL(self);
       
   156     self->ConstructL();
       
   157     CleanupStack::Pop();  // self
       
   158     return self;
       
   159     }
       
   160 
       
   161 CPbkGroupMembersListAppView::~CPbkGroupMembersListAppView()
       
   162     {
       
   163     delete iNaviDeco;
       
   164 
       
   165     if (iContainer)
       
   166         {
       
   167         // Remove the container from the view stack
       
   168         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   169         // Destroy the control container
       
   170         delete iContainer;
       
   171         }
       
   172 
       
   173     if (iGroupMembersView)
       
   174         {
       
   175         iGroupMembersView->Close(*this);
       
   176         }
       
   177     if (iAllGroupsView)
       
   178         {
       
   179         iAllGroupsView->Close(*this);
       
   180         }
       
   181     }
       
   182 
       
   183 inline void CPbkGroupMembersListAppView::CmdBackL()
       
   184     {
       
   185     CPbkViewState* state = iContainer->Control()->GetStateLC();
       
   186     PbkAppUi()->ActivatePreviousViewL(state);
       
   187     CleanupStack::PopAndDestroy();  // state
       
   188     }
       
   189 
       
   190 void CPbkGroupMembersListAppView::CmdOpenMeViewsL()
       
   191 	{
       
   192     if (!Control().ItemsMarked())
       
   193         {
       
   194         CPbkViewState* state = Control().GetStateLC();
       
   195         state->SetParentContactId(iGroupId);
       
   196         PbkAppUi()->ActivatePhonebookViewL(CPbkAppUi::KPbkContactInfoViewUid, state);
       
   197         CleanupStack::PopAndDestroy();  // state
       
   198         Control().HandleMarkableListUpdateAfterCommandExecution();
       
   199         }
       
   200 	}
       
   201 
       
   202 void CPbkGroupMembersListAppView::CmdRemoveFromFolderL()
       
   203 	{
       
   204     __ASSERT_DEBUG(
       
   205         iContainer &&
       
   206         iContainer->Control()->NumberOfItems() > 0,
       
   207         Panic(EPanicPreCond_CmdRemoveFromFolderL));
       
   208 
       
   209     iFocusedContact =
       
   210 		iContainer->Control()->FocusedContactIdL();
       
   211 
       
   212     CContactIdArray* items = NULL;
       
   213     if (iContainer->Control()->ItemsMarked())
       
   214         {
       
   215         items = CContactIdArray::NewLC
       
   216 			(&iContainer->Control()->MarkedItemsL());
       
   217         }
       
   218     else
       
   219         {
       
   220         items = CContactIdArray::NewLC();
       
   221         items->AddL(iFocusedContact);
       
   222         }
       
   223 
       
   224     //original we will ask user if they really want to remove contacts from group,
       
   225     //but currently we decide that we will just do it without asking user
       
   226     if (items->Count() >= 1)
       
   227         {
       
   228         CPbkRemoveFromGroupCmd* cmd = CPbkRemoveFromGroupCmd::NewL(*Engine(),
       
   229                 *items, *iContainer->Control(), iGroupId);
       
   230         PbkAppUi()->AddAndExecuteCommandL(cmd);
       
   231         }
       
   232 
       
   233     
       
   234 
       
   235 
       
   236     CleanupStack::PopAndDestroy(); // items
       
   237     }
       
   238 
       
   239 void CPbkGroupMembersListAppView::CmdFetchMembersL()
       
   240 	{
       
   241     __ASSERT_DEBUG(
       
   242         iContainer &&
       
   243         Engine()->AllContactsView().CountL() > 0,
       
   244         Panic(EPanicPreCond_CmdFetchMembersL));
       
   245 
       
   246     // Remove thumbnail from screen for the duration of the fetch
       
   247     iContainer->Control()->HideThumbnail();
       
   248 
       
   249     CPbkGroupMembersFetchDlg::TParams params;
       
   250     params.iGroupId = iGroupId;
       
   251     CPbkGroupMembersFetchDlg* groupMembersFetch =
       
   252 		CPbkGroupMembersFetchDlg::NewL(params, *Engine());
       
   253     TInt res = 0;
       
   254     res = groupMembersFetch->ExecuteLD();
       
   255     if (res && params.iMarkedEntries)
       
   256         {
       
   257         CleanupStack::PushL(params.iMarkedEntries);
       
   258         CPbkAssignToGroupCmd* cmd = CPbkAssignToGroupCmd::NewL
       
   259             (*Engine(), *params.iMarkedEntries, *iContainer->Control(), iGroupId);
       
   260         PbkAppUi()->AddAndExecuteCommandL(cmd);
       
   261         CleanupStack::PopAndDestroy(); // params.iMarkedEntries
       
   262         }
       
   263 	}
       
   264 
       
   265 inline void CPbkGroupMembersListAppView::CmdContextMenuL()
       
   266     {
       
   267     if (iContainer->Control()->ItemsMarked())
       
   268         {
       
   269         LaunchPopupMenuL(R_PBK_GROUPMEMBERS_CONTEXT_MENUBAR_MARKED_ITEMS);
       
   270         }
       
   271     else
       
   272         {
       
   273         LaunchPopupMenuL(R_PBK_GROUPMEMBERS_CONTEXT_MENUBAR);
       
   274         }
       
   275     }
       
   276 
       
   277 /**
       
   278  * Helper method for HandleCommandKeyL.
       
   279  */
       
   280 inline void CPbkGroupMembersListAppView::NavigateGroupL(TInt aDir)
       
   281     {
       
   282     if (aDir == 0) return;
       
   283 
       
   284     TInt groupIndex = iAllGroupsView->FindL(iGroupId) + aDir;
       
   285     const TInt groupCount = iAllGroupsView->CountL();
       
   286     if (groupCount > 1)
       
   287         {
       
   288         if (groupIndex < 0)
       
   289             {
       
   290             groupIndex = groupCount + groupIndex;
       
   291             }
       
   292         else if (groupIndex >= groupCount)
       
   293             {
       
   294             groupIndex = groupIndex - groupCount;
       
   295             }
       
   296         const TContactItemId groupId = iAllGroupsView->AtL(groupIndex);
       
   297         CPbkViewState* state = iContainer->Control()->GetStateLC();
       
   298         state->SetFocusedContactId(groupId);
       
   299         PbkAppUi()->ActivatePhonebookViewL
       
   300 			(CPbkAppUi::KPbkGroupMembersListViewUid, state);
       
   301         CleanupStack::PopAndDestroy(state);
       
   302         }
       
   303     }
       
   304 
       
   305 TBool CPbkGroupMembersListAppView::HandleCommandKeyL
       
   306         (const TKeyEvent& aKeyEvent,
       
   307         TEventCode aType)
       
   308     {
       
   309     // PreCond: (this is the precond for all Cmd* functions at the same time)
       
   310     __ASSERT_DEBUG(iContainer, Panic(EPanicPreCond_HandleCommandKeyL));
       
   311 
       
   312     // check if groups view is ready
       
   313     if (iViewsLoadingReady.AreViewsReady())
       
   314         {
       
   315         switch (aKeyEvent.iCode)
       
   316             {
       
   317             case EKeyLeftArrow: // FALLTHROUGH
       
   318             case EKeyRightArrow:
       
   319                 {
       
   320                 TInt dir = 0;
       
   321                 switch (aKeyEvent.iCode)
       
   322                     {
       
   323                     case EKeyLeftArrow:
       
   324                         {
       
   325                         dir = -1;
       
   326                         break;
       
   327                         }
       
   328                     case EKeyRightArrow:
       
   329                         {
       
   330                         dir = 1;
       
   331                         break;
       
   332                         }
       
   333                     }
       
   334                 // Handle mirrored layout by negating the directionality
       
   335                 if (AknLayoutUtils::LayoutMirrored())
       
   336                     {
       
   337                     dir = -1 * dir;
       
   338                     }
       
   339                 NavigateGroupL(dir);
       
   340                 return ETrue;
       
   341                 }
       
   342             }
       
   343         }
       
   344 
       
   345     // Key not handled here, try base class
       
   346     return CPbkContactListAppView::HandleCommandKeyL(aKeyEvent, aType);
       
   347     }
       
   348 
       
   349 CPbkViewState* CPbkGroupMembersListAppView::GetViewStateLC() const
       
   350     {
       
   351     return iContainer ? iContainer->Control()->GetStateLC() : NULL;
       
   352     }
       
   353 
       
   354 CPbkContactViewListControl& CPbkGroupMembersListAppView::Control()
       
   355     {
       
   356     return *iContainer->Control();
       
   357     }
       
   358 
       
   359 void CPbkGroupMembersListAppView::HandleCommandL
       
   360         (TInt aCommandId)
       
   361     {
       
   362     // PreCond: (this is the precond for all Cmd* functions at the same time)
       
   363     __ASSERT_DEBUG(iContainer, Panic(EPanicPreCond_HandleCommandL));
       
   364 
       
   365     // Process view-specific commands
       
   366     switch (aCommandId)
       
   367         {
       
   368         case EAknSoftkeyBack:
       
   369 			{
       
   370             CmdBackL();
       
   371             break;
       
   372 			}
       
   373 
       
   374         case EPbkCmdRemoveFromFolder:
       
   375 			{
       
   376             CmdRemoveFromFolderL();
       
   377             break;
       
   378 			}
       
   379 
       
   380         case EPbkCmdFetchMembers:
       
   381 			{
       
   382             PbkAppUi()->FFSClCheckL(PbkCommandHandler(this,
       
   383                 &CPbkGroupMembersListAppView::CmdFetchMembersL));
       
   384             break;
       
   385 			}
       
   386 
       
   387         case EPbkCmdContextMenu:
       
   388 			{
       
   389             CmdContextMenuL();
       
   390             break;
       
   391 			}
       
   392         case EPbkCmdSendUICommand:
       
   393             {
       
   394             // Set up flags depending on current UI state
       
   395             TUint flags = 0;
       
   396             if (iContainer->Control()->ItemsMarked())
       
   397                 {
       
   398                 flags |= KPbkItemsMarked;
       
   399                 }
       
   400             HandleSendContactsL( flags );
       
   401             break;
       
   402             }
       
   403         default:
       
   404 			{
       
   405             // Command not handled here, forward it to base class
       
   406             CPbkContactListAppView::HandleCommandL(aCommandId);
       
   407             break;
       
   408 			}
       
   409         }
       
   410     }
       
   411 
       
   412 void CPbkGroupMembersListAppView::DynInitMenuPaneL
       
   413         (TInt aResourceId, CEikMenuPane* aMenuPane)
       
   414     {
       
   415     __ASSERT_DEBUG(iContainer, Panic(EPanicPreCond_DynInitMenuPaneL));
       
   416 
       
   417     // Set up flags depending on current UI state
       
   418     TUint flags = 0;
       
   419     if (iContainer->Control()->NumberOfItems() == 0)
       
   420         {
       
   421         flags |= KPbkControlEmpty;
       
   422         }
       
   423     if (iContainer->Control()->ItemsMarked())
       
   424         {
       
   425         flags |= KPbkItemsMarked;
       
   426         }
       
   427     if (Engine()->AllContactsView().CountL() == 0)
       
   428         {
       
   429         flags |= KPbkContactListEmpty;
       
   430         }
       
   431 
       
   432     // Offer the menu to AIW first
       
   433     if (iAiwInterestArray->InitMenuPaneL(aResourceId, *aMenuPane, flags))
       
   434         {
       
   435         // No need to continue
       
   436         return;
       
   437         }
       
   438 
       
   439     switch (aResourceId)
       
   440         {
       
   441         case R_PBK_GROUPMEMBERS_MENU:
       
   442             {
       
   443             OptionsMenuFilteringL(*aMenuPane, flags);
       
   444             break;
       
   445             }
       
   446         case R_PBK_GROUPMEMBERS_SENDCONTACTMENU:
       
   447             {
       
   448             SendContactMenuFilteringL(*aMenuPane, flags);
       
   449             break;
       
   450             }
       
   451         case R_PBK_GROUPMEMBERS_CONTEXTMENU:
       
   452             {
       
   453             ContextMenuFilteringL(*aMenuPane, flags);
       
   454             break;
       
   455             }
       
   456         default:
       
   457             {
       
   458             break;
       
   459             }
       
   460         }
       
   461 
       
   462     CPbkContactListAppView::DynInitMenuPaneL(aResourceId, aMenuPane);
       
   463     }
       
   464 
       
   465 void CPbkGroupMembersListAppView::OptionsMenuFilteringL
       
   466         (CEikMenuPane& aMenuPane, TUint aFlags)
       
   467     {
       
   468     if ((aFlags & KPbkControlEmpty) || (aFlags & KPbkItemsMarked))
       
   469         {
       
   470         // if members list is empty or items are marked filter options list
       
   471         aMenuPane.SetItemDimmed(EPbkCmdOpenMeViews, ETrue);
       
   472         aMenuPane.SetItemDimmed(EPbkCmdWrite, ETrue);
       
   473         aMenuPane.SetItemDimmed(EPbkCmdBelongsToGroups, ETrue);
       
   474         }
       
   475     if ((aFlags & KPbkItemsMarked) && !(aFlags & KPbkControlEmpty))
       
   476         {
       
   477         // if items are marked items but list is not empty
       
   478         aMenuPane.SetItemDimmed(EPbkCmdFetchMembers, ETrue);
       
   479         }
       
   480     if (aFlags & KPbkControlEmpty)
       
   481         {
       
   482         // if members list is empty, no options menu items
       
   483         aMenuPane.SetItemDimmed(EPbkCmdRemoveFromFolder, ETrue);
       
   484         }
       
   485     if (aFlags & KPbkContactListEmpty)
       
   486         {
       
   487         // Fetch members not available if names list is empty
       
   488         aMenuPane.SetItemDimmed(EPbkCmdFetchMembers, ETrue);
       
   489         }
       
   490     }
       
   491 
       
   492 void CPbkGroupMembersListAppView::SendContactMenuFilteringL
       
   493         (CEikMenuPane& aMenuPane, TUint aFlags)
       
   494     {
       
   495 	CPbkAppGlobals* globals =	// does not take ownership
       
   496         CPbkAppGlobals::InstanceL();
       
   497 
       
   498     // By default disable filtering of send contact menu,
       
   499     // when there are marked items
       
   500     TBool markedItemsFiltering = EFalse;
       
   501 
       
   502     // Check is multiple vCard sending via BT/IR supported
       
   503     if (!Engine()->Constants()->LocallyVariatedFeatureEnabled
       
   504         (EPbkLVMultipleVCardOverBTAndIR))
       
   505         {
       
   506         // It is not supported. Marked items filtering is
       
   507         // now needed if there is no mailbox set up
       
   508         markedItemsFiltering = !globals->SendUiL()->ValidateServiceL
       
   509             (KSenduiMtmSmtpUid, TSendingCapabilities(0,0,0));
       
   510         }
       
   511 
       
   512     // If members list is empty, no options menu items
       
   513     if ((aFlags & KPbkControlEmpty)
       
   514         || ((aFlags & KPbkItemsMarked) && markedItemsFiltering))
       
   515         {
       
   516         // Hide "Send contact" menu
       
   517         aMenuPane.SetItemDimmed(EPbkCmdSendUICommand, ETrue);
       
   518         }
       
   519 	else
       
   520 		{
       
   521 		aMenuPane.SetItemDimmed(EPbkCmdSendUICommand, EFalse);	
       
   522 		}
       
   523     }
       
   524 
       
   525 void CPbkGroupMembersListAppView::ContextMenuFilteringL
       
   526         (CEikMenuPane& aMenuPane, TUint aFlags)
       
   527     {
       
   528     if (aFlags & KPbkContactListEmpty)
       
   529         {
       
   530         // Fetch members not available if names list is empty
       
   531         aMenuPane.SetItemDimmed(EPbkCmdFetchMembers, ETrue);
       
   532         }
       
   533     }
       
   534 
       
   535 TUid CPbkGroupMembersListAppView::Id() const
       
   536     {
       
   537     return CPbkAppUi::KPbkGroupMembersListViewUid;
       
   538     }
       
   539 
       
   540 void CPbkGroupMembersListAppView::HandleStatusPaneSizeChange()
       
   541     {
       
   542     // Resize the container to fill the client rectangle
       
   543     if (iContainer)
       
   544         {
       
   545         iContainer->SetRect(ClientRect());
       
   546         }
       
   547     }
       
   548 
       
   549 void CPbkGroupMembersListAppView::DoActivateL
       
   550         (const TVwsViewId& aPrevViewId,
       
   551          TUid aCustomMessageId,
       
   552          const TDesC8& aCustomMessage)
       
   553     {
       
   554     CContactGroup* group = NULL;
       
   555 
       
   556     if (iContainer)
       
   557         {
       
   558         iContainer->DestroyControl();
       
   559         }
       
   560 
       
   561     if (aCustomMessageId == CPbkViewState::Uid())
       
   562         {
       
   563         // Get the group id from the parameter
       
   564         CPbkViewState* viewState = CPbkViewState::NewLC(aCustomMessage);
       
   565         CContactItem* item = Engine()->Database().
       
   566 			ReadContactL(viewState->FocusedContactId());
       
   567         if (item->Type() == KUidContactGroup)
       
   568             {
       
   569             iGroupId = viewState->FocusedContactId();
       
   570             group = static_cast<CContactGroup*>(item);
       
   571             CleanupStack::PopAndDestroy(viewState);
       
   572             CleanupStack::PushL(group);
       
   573             }
       
   574         else if (item->Type() == KUidContactCard)
       
   575             {
       
   576             iFocusedContact = viewState->FocusedContactId();
       
   577             CleanupStack::PopAndDestroy(viewState);
       
   578             delete item;
       
   579             }
       
   580         }
       
   581     if (iGroupId == KNullContactId)
       
   582         {
       
   583         // No state to activate
       
   584         User::Leave(KErrNotFound);
       
   585         }
       
   586 
       
   587     // Read the contact group unless already done
       
   588     if (!group)
       
   589         {
       
   590         group = Engine()->ReadContactGroupL(iGroupId);
       
   591         CleanupStack::PushL(group);
       
   592         }
       
   593 
       
   594     // Update application-wide state leave-safely
       
   595     TPtrC groupLabel = group->GetGroupLabelL();
       
   596     CPbkAppUi::CViewActivationTransaction* viewActivationTransaction =
       
   597         PbkAppUi()->HandleViewActivationLC
       
   598             (Id(), aPrevViewId, &groupLabel, NULL);
       
   599 
       
   600     // Register this object as observer to all groups view
       
   601     if (!iAllGroupsView)
       
   602         {
       
   603         iAllGroupsView = &Engine()->AllGroupsViewL();
       
   604         iAllGroupsView->OpenL(*this);
       
   605         }
       
   606 
       
   607     LoadGroupMembersViewL(iGroupId);
       
   608 
       
   609     // Create the control container
       
   610     TBool containerCreated = EFalse;
       
   611     if (!iContainer)
       
   612         {
       
   613         CContainer* container = CContainer::NewLC(this, *this);
       
   614         container->SetRect(ClientRect());
       
   615 
       
   616         container->SetHelpContext(TCoeHelpContext(ApplicationUid(),
       
   617         	KPHOB_HLP_GROUP_MEMBER_LIST));
       
   618         	
       
   619         CleanupStack::Pop(container);
       
   620         iContainer = container;
       
   621         containerCreated = ETrue;
       
   622         }
       
   623         
       
   624     // Create the view-side UI control
       
   625     CPbkContactViewListControl* control = CPbkContactViewListControl::NewL
       
   626         (*Engine(), *iGroupMembersView, R_PBK_GROUP_MEMBERS_LIST_VIEW_CONTROL,
       
   627 		iContainer);
       
   628     iContainer->SetControl(control, ClientRect());
       
   629     control->AddObserverL(*this);
       
   630     
       
   631     if ( containerCreated )
       
   632         {
       
   633         AppUi()->AddToViewStackL(*this, iContainer);
       
   634         }
       
   635     ConstructNaviIndicatorsL();
       
   636 
       
   637     // Activate UI control
       
   638     iContainer->ActivateL();
       
   639 
       
   640     // Commit application-wide state changes
       
   641     viewActivationTransaction->Commit();
       
   642     CleanupStack::PopAndDestroy(2);  // viewActivationTransaction, group
       
   643 
       
   644     // PostCond:
       
   645     __ASSERT_DEBUG(iContainer && iContainer->Control(),
       
   646         Panic(EPanicPostCond_DoActivateL));
       
   647     }
       
   648 
       
   649 void CPbkGroupMembersListAppView::DoDeactivate()
       
   650     {
       
   651     PBK_DEBUG_PRINT(PBK_DEBUG_STRING
       
   652 		("CPbkGroupsListAppView(%x)::DoDeactivate()"), this);
       
   653 
       
   654     // delete navigation decorator
       
   655     delete iNaviDeco;
       
   656     iNaviDeco = NULL;
       
   657 
       
   658     if (iContainer)
       
   659         {
       
   660         // Remove view and its control from the view stack
       
   661         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   662         // Destroy the container control
       
   663         delete iContainer;
       
   664         iContainer = NULL;
       
   665         }
       
   666 
       
   667     // Close contact views
       
   668     if (iGroupMembersView)
       
   669         {
       
   670         iGroupMembersView->Close(*this);
       
   671         iGroupMembersView = NULL;
       
   672         }
       
   673     if (iAllGroupsView)
       
   674         {
       
   675         iAllGroupsView->Close(*this);
       
   676         iAllGroupsView = NULL;
       
   677         }
       
   678 
       
   679     // PostCond:
       
   680     __ASSERT_DEBUG(!iContainer && !iNaviDeco && !iGroupMembersView
       
   681 		&& !iAllGroupsView, Panic(EPanicPostCond_DoDeactivate));
       
   682     }
       
   683 
       
   684 void CPbkGroupMembersListAppView::DeleteFocusedEntryL()
       
   685     {
       
   686     CmdRemoveFromFolderL();
       
   687     }
       
   688 
       
   689 void CPbkGroupMembersListAppView::HandleContactViewEvent
       
   690         (const CContactViewBase& aView,
       
   691         const TContactViewEvent& aEvent)
       
   692     {
       
   693     if (&aView == iAllGroupsView &&
       
   694         aEvent.iEventType == TContactViewEvent::EReady)
       
   695         {
       
   696         iViewsLoadingReady.SetAllGroupsViewReady();
       
   697         // navi pane update
       
   698         TRAPD(err, StatusPaneUpdateL(iGroupId));
       
   699         if (err != KErrNone)
       
   700             {
       
   701             iCoeEnv->HandleError(err);
       
   702             }
       
   703         }
       
   704     }
       
   705 
       
   706 void CPbkGroupMembersListAppView::HandleContactViewListControlEventL
       
   707         (CPbkContactViewListControl& /*aControl*/,
       
   708         const TPbkContactViewListControlEvent& aEvent)
       
   709     {
       
   710     if (aEvent.iEventType == TPbkContactViewListControlEvent::EReady)
       
   711         {
       
   712         if (iFocusedContact != KNullContactId)
       
   713             {
       
   714             TInt index = iContainer->Control()->
       
   715 				FindContactIdL(iFocusedContact);
       
   716             if (index >= 0)
       
   717                 {
       
   718                 iContainer->Control()->SetCurrentItemIndexAndDraw(index);
       
   719                 }
       
   720             }
       
   721         iFocusedContact = KNullContactId;
       
   722         iViewsLoadingReady.SetControlReady();
       
   723         // navi pane update
       
   724         StatusPaneUpdateL(iGroupId);
       
   725         }
       
   726     }
       
   727 
       
   728 void CPbkGroupMembersListAppView::StatusPaneUpdateL
       
   729         (TContactItemId aGroupId)
       
   730     {
       
   731     // update the navi decorator
       
   732     if (iViewsLoadingReady.AreViewsReady())
       
   733         {
       
   734         // update the title pane to hold the Groups label
       
   735         CContactGroup* group = Engine()->ReadContactGroupL(aGroupId);
       
   736         CleanupStack::PushL(group);
       
   737         TitlePane()->SetTextL(group->GetGroupLabelL());
       
   738         CleanupStack::PopAndDestroy(group);
       
   739 
       
   740         // check the index and count of the groups to navi pane
       
   741         const TInt index = iAllGroupsView->FindL(aGroupId) + 1;
       
   742 
       
   743         // create navi pane text
       
   744         CArrayFixFlat<TInt>* values = new (ELeave) CArrayFixFlat<TInt>(2);
       
   745         CleanupStack::PushL(values);
       
   746         values->AppendL(index);
       
   747         values->AppendL(iAllGroupsView->CountL());
       
   748         HBufC* buf  = StringLoader::LoadLC(R_QTN_PHOB_NAVI_POS_INDICATOR,
       
   749 			*values);
       
   750 
       
   751         CPbkIconInfoContainer* iconInfoContainer =
       
   752 			CPbkIconInfoContainer::NewL(R_PBK_ICON_INFO_ARRAY, iCoeEnv);
       
   753         CleanupStack::PushL(iconInfoContainer);
       
   754         CGulIcon* icon =
       
   755                 iconInfoContainer->LoadBitmapL(EPbkqgn_prop_group_open_tab1);
       
   756         __ASSERT_DEBUG(icon, Panic(EPanicIcon_StatusPaneUpdateL));
       
   757         CleanupStack::PopAndDestroy(); // iconInfoContainer
       
   758         CleanupStack::PushL(icon);
       
   759 
       
   760         static_cast<CAknTabGroup*>(iNaviDeco->DecoratedControl())
       
   761             ->ReplaceTabL(EPbkGroupMembersListViewId, *buf, icon->Bitmap(),
       
   762 			icon->Mask());
       
   763         // tab group takes ownership of bitmap and mask
       
   764         icon->SetBitmapsOwnedExternally(ETrue);
       
   765         CleanupStack::PopAndDestroy(3); // icon, buf, values
       
   766         }
       
   767     }
       
   768 
       
   769 void CPbkGroupMembersListAppView::LoadGroupMembersViewL
       
   770 		(TContactItemId aGroupId)
       
   771     {
       
   772     // PreCond
       
   773     __ASSERT_DEBUG(Engine(),
       
   774         Panic(EPanicPreCond_LoadGroupMembersViewL));
       
   775 
       
   776     CContactGroupView* groupMembersView = CContactGroupView::NewL(
       
   777         Engine()->Database(), Engine()->AllContactsView(),
       
   778         *this, aGroupId, CContactGroupView::EShowContactsInGroup);
       
   779 	groupMembersView->SetViewFindConfigPlugin
       
   780 		(Engine()->AllContactsView().GetViewFindConfigPlugin());
       
   781 
       
   782     if (iGroupMembersView)
       
   783         {
       
   784         iGroupMembersView->Close(*this);
       
   785         iGroupMembersView = NULL;
       
   786         }
       
   787     iGroupMembersView = groupMembersView;
       
   788 
       
   789     // PostCond
       
   790     __ASSERT_DEBUG(Engine() && iGroupMembersView,
       
   791         Panic(EPanicPostCond_LoadGroupMembersViewL));
       
   792     }
       
   793 
       
   794 void CPbkGroupMembersListAppView::ConstructNaviIndicatorsL()
       
   795     {
       
   796     // navi indicators
       
   797     CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   798     if (statusPane && statusPane->PaneCapabilities
       
   799 		(TUid::Uid(EEikStatusPaneUidNavi)).IsPresent())
       
   800         {
       
   801         CAknNavigationControlContainer* naviPane =
       
   802 			static_cast<CAknNavigationControlContainer*>
       
   803 			(statusPane->ControlL(TUid::Uid(EEikStatusPaneUidNavi)));
       
   804         if (!iNaviDeco)
       
   805             {
       
   806             TResourceReader resReader;
       
   807             iCoeEnv->CreateResourceReaderLC(resReader,
       
   808 				R_PBK_GROUP_MEMBERS_TAB_GROUP);
       
   809             iNaviDeco = naviPane->CreateTabGroupL(resReader);
       
   810             CleanupStack::PopAndDestroy(); // resReader
       
   811             }
       
   812 
       
   813         iNaviDeco->MakeScrollButtonVisible(ETrue);
       
   814         if (Engine()->Database().GroupCount() > 1)
       
   815             {
       
   816             iNaviDeco->SetScrollButtonDimmed
       
   817 				(CAknNavigationDecorator::ERightButton, EFalse);
       
   818             iNaviDeco->SetScrollButtonDimmed
       
   819 				(CAknNavigationDecorator::ELeftButton, EFalse);
       
   820             }
       
   821         else
       
   822             {
       
   823             iNaviDeco->SetScrollButtonDimmed
       
   824 				(CAknNavigationDecorator::ERightButton, ETrue);
       
   825             iNaviDeco->SetScrollButtonDimmed
       
   826 				(CAknNavigationDecorator::ELeftButton, ETrue);
       
   827             }
       
   828         naviPane->PushL(*iNaviDeco);
       
   829         }
       
   830     }
       
   831 
       
   832 
       
   833 //  End of File