phonebookui/Phonebook2/UIControls/src/CPbk2NamesListEmptyState.cpp
branchRCL_3
changeset 18 d4f567ce2e7c
parent 0 e686773b3f54
equal deleted inserted replaced
17:2666d9724c76 18:d4f567ce2e7c
    39 #include <aknsfld.h>
    39 #include <aknsfld.h>
    40 
    40 
    41 // Debugging headers
    41 // Debugging headers
    42 #include <Pbk2Debug.h>
    42 #include <Pbk2Debug.h>
    43 
    43 
       
    44 #include <aknnavi.h>
       
    45 #include <aknnavide.h> 
       
    46 #include <aknnavilabel.h>
       
    47 
    44 
    48 
    45 /// Unnamed namespace for local definitions
    49 /// Unnamed namespace for local definitions
    46 namespace {
    50 namespace {
    47 
    51 
    48 const TInt KNumberOfContacts = 0;
    52 const TInt KNumberOfContacts = 0;
   122 // CPbk2NamesListEmptyState::ActivateStateL
   126 // CPbk2NamesListEmptyState::ActivateStateL
   123 // --------------------------------------------------------------------------
   127 // --------------------------------------------------------------------------
   124 //
   128 //
   125 void CPbk2NamesListEmptyState::ActivateStateL()
   129 void CPbk2NamesListEmptyState::ActivateStateL()
   126     {
   130     {
   127     AllowCommandsToShowThemselves( ETrue );  
   131     AllowCommandsToShowThemselves( ETrue );
   128 	
   132     CPbk2NamesListControl& namesListControl = 
   129 	// hide findbox since there is no contact
   133         reinterpret_cast<CPbk2NamesListControl&>(CoeControl());
       
   134     if( namesListControl.GetMarkingMode() )
       
   135         {
       
   136         // If NamesListEmptyState and Marking mode are both active,
       
   137         // the Marking mode should be canceled. 
       
   138         iListBox.SetMarkingMode(EFalse);
       
   139         CEikonEnv* eikonEnv = CEikonEnv::Static();
       
   140         if ( eikonEnv && eikonEnv->AppUiFactory() )
       
   141             {
       
   142             CEikStatusPane* statusPane = eikonEnv->AppUiFactory()->StatusPane();
       
   143             if ( statusPane )
       
   144                 {
       
   145 
       
   146                 CAknNavigationControlContainer* naviPane =
       
   147                         (CAknNavigationControlContainer *)statusPane->ControlL(
       
   148                                 TUid::Uid(EEikStatusPaneUidNavi));
       
   149                 CAknNavigationDecorator* decorator = naviPane->Top();
       
   150                         naviPane->Pop( decorator );
       
   151                 naviPane->DrawDeferred();
       
   152                 }
       
   153             }
       
   154         }
       
   155 
       
   156     // hide findbox since there is no contact
   130     if ( iFindBox && iFindBox->IsVisible() )
   157     if ( iFindBox && iFindBox->IsVisible() )
   131         {
   158         {
   132         iFindBox->MakeVisible( EFalse );                
   159         iFindBox->MakeVisible( EFalse );
   133         }
   160         }
   134 
   161 
   135     }
   162     }
   136 
   163 
   137 // --------------------------------------------------------------------------
   164 // --------------------------------------------------------------------------
   138 // CPbk2NamesListEmptyState::DeactivateState
   165 // CPbk2NamesListEmptyState::DeactivateState
   139 // --------------------------------------------------------------------------
   166 // --------------------------------------------------------------------------
   140 //
   167 //
   141 void CPbk2NamesListEmptyState::DeactivateState()
   168 void CPbk2NamesListEmptyState::DeactivateState()
   142     {
   169     {
   143     AllowCommandsToShowThemselves( EFalse );  	
   170     AllowCommandsToShowThemselves( EFalse );
   144 	
   171 
   145     if ( iFindBox && !iFindBox->IsFocused() )
   172     if ( iFindBox && !iFindBox->IsFocused() )
   146         {
   173         {
   147         iFindBox->SetFocus( ETrue );
   174         iFindBox->SetFocus( ETrue );
   148         }
   175         }
   149     }
   176     }
   295 // CPbk2NamesListEmptyState::HandleListboxEventL
   322 // CPbk2NamesListEmptyState::HandleListboxEventL
   296 // --------------------------------------------------------------------------
   323 // --------------------------------------------------------------------------
   297 //
   324 //
   298 void CPbk2NamesListEmptyState::HandleListboxEventL
   325 void CPbk2NamesListEmptyState::HandleListboxEventL
   299         (TInt aEvent, TInt aListboxIndex,
   326         (TInt aEvent, TInt aListboxIndex,
   300 		TBool /*aMantainFocus*/) 
   327         TBool /*aMantainFocus*/) 
   301     {
   328     {
   302     iListBox.HandleEventL( aEvent, aListboxIndex );
   329     iListBox.HandleEventL( aEvent, aListboxIndex );
   303     iParent.DrawDeferred();
   330     iParent.DrawDeferred();
   304     }
   331     }
   305 // --------------------------------------------------------------------------
   332 // --------------------------------------------------------------------------
   347 TInt CPbk2NamesListEmptyState::NumberOfContacts() const
   374 TInt CPbk2NamesListEmptyState::NumberOfContacts() const
   348     {
   375     {
   349     // The listbox can also have command items.
   376     // The listbox can also have command items.
   350     TInt result = iListBox.NumberOfItems() - CommandItemCount();
   377     TInt result = iListBox.NumberOfItems() - CommandItemCount();
   351     if ( result < 0 )
   378     if ( result < 0 )
   352     	{
   379         {
   353     	result = KNumberOfContacts; // No contacts 
   380         result = KNumberOfContacts; // No contacts 
   354     	}
   381         }
   355     return result;
   382     return result;
   356     }
   383     }
   357 
   384 
   358 // --------------------------------------------------------------------------
   385 // --------------------------------------------------------------------------
   359 // CPbk2NamesListEmptyState::FocusedContactL
   386 // CPbk2NamesListEmptyState::FocusedContactL
   489 // --------------------------------------------------------------------------
   516 // --------------------------------------------------------------------------
   490 //
   517 //
   491 MVPbkContactLinkArray*
   518 MVPbkContactLinkArray*
   492         CPbk2NamesListEmptyState::SelectedContactsOrFocusedContactL() const
   519         CPbk2NamesListEmptyState::SelectedContactsOrFocusedContactL() const
   493     {
   520     {
   494 	CVPbkContactLinkArray* array = NULL;
   521     CVPbkContactLinkArray* array = NULL;
   495 	// my card is showing on empty list, check if the wanted contact is it
   522     // my card is showing on empty list, check if the wanted contact is it
   496 	TInt currentItem = iListBox.CurrentItemIndex();
   523     TInt currentItem = iListBox.CurrentItemIndex();
   497 	// if focused index is command item
   524     // if focused index is command item
   498 	if( currentItem < CommandItemCount() )
   525     if( currentItem < CommandItemCount() )
   499 		{
   526         {
   500 		// check if the command is my card ( this search is copied from CommandItemAt - function to avoid const cast)
   527         // check if the command is my card ( this search is copied from CommandItemAt - function to avoid const cast)
   501 		// Some of the commands might be disabled. Skip those.
   528         // Some of the commands might be disabled. Skip those.
   502 		TInt enabledCount = 0;
   529         TInt enabledCount = 0;
   503 		TInt indexOfResult = KErrNotFound;
   530         TInt indexOfResult = KErrNotFound;
   504 		for ( TInt n = 0; n < iCommandItems.Count() && indexOfResult == KErrNotFound; ++n )
   531         for ( TInt n = 0; n < iCommandItems.Count() && indexOfResult == KErrNotFound; ++n )
   505 			{
   532             {
   506 			if ( iCommandItems[ n ]->IsEnabled() )
   533             if ( iCommandItems[ n ]->IsEnabled() )
   507 				{
   534                 {
   508 				enabledCount++;
   535                 enabledCount++;
   509 				if ( enabledCount-1 == currentItem )
   536                 if ( enabledCount-1 == currentItem )
   510 					{
   537                     {
   511 					indexOfResult = n;
   538                     indexOfResult = n;
   512 					}
   539                     }
   513 				}
   540                 }
   514 			}
   541             }
   515 		MPbk2UiControlCmdItem* item = iCommandItems[ indexOfResult ];
   542         MPbk2UiControlCmdItem* item = iCommandItems[ indexOfResult ];
   516 		// check if the command item was a my card
   543         // check if the command item was a my card
   517 		if( item->CommandId() == EPbk2CmdOpenMyCard )
   544         if( item->CommandId() == EPbk2CmdOpenMyCard )
   518 			{
   545             {
   519 			// get extension point and my card link
   546             // get extension point and my card link
   520 			TAny* object = item->ControlCmdItemExtension( TUid::Uid( KPbk2ControlCmdItemExtensionUID ) );
   547             TAny* object = item->ControlCmdItemExtension( TUid::Uid( KPbk2ControlCmdItemExtensionUID ) );
   521 			if(  object )
   548             if(  object )
   522 				{
   549                 {
   523 				MPbk2DoubleListboxCmdItemExtension* extension = 
   550                 MPbk2DoubleListboxCmdItemExtension* extension = 
   524 						static_cast<MPbk2DoubleListboxCmdItemExtension*>( object );
   551                         static_cast<MPbk2DoubleListboxCmdItemExtension*>( object );
   525 				// if extension exists
   552                 // if extension exists
   526 				if( extension )
   553                 if( extension )
   527 					{
   554                     {
   528 					const MVPbkContactLink* link = extension->Link();
   555                     const MVPbkContactLink* link = extension->Link();
   529 					// if link exists, add it to the array
   556                     // if link exists, add it to the array
   530 					if( link )
   557                     if( link )
   531 						{
   558                         {
   532 						array = CVPbkContactLinkArray::NewLC();
   559                         array = CVPbkContactLinkArray::NewLC();
   533 						array->AppendL( link->CloneLC() );
   560                         array->AppendL( link->CloneLC() );
   534 						CleanupStack::Pop( 2 );	// array, link
   561                         CleanupStack::Pop( 2 );    // array, link
   535 						}
   562                         }
   536 					}
   563                     }
   537 				}
   564                 }
   538 			}
   565             }
   539 		}
   566         }
   540 	return array;
   567     return array;
   541     }
   568     }
   542 
   569 
   543 // --------------------------------------------------------------------------
   570 // --------------------------------------------------------------------------
   544 // CPbk2NamesListEmptyState::SelectedContactsIteratorL
   571 // CPbk2NamesListEmptyState::SelectedContactsIteratorL
   545 // --------------------------------------------------------------------------
   572 // --------------------------------------------------------------------------
   605 // --------------------------------------------------------------------------
   632 // --------------------------------------------------------------------------
   606 // CPbk2NamesListEmptyState::CommandItemCount
   633 // CPbk2NamesListEmptyState::CommandItemCount
   607 // --------------------------------------------------------------------------
   634 // --------------------------------------------------------------------------
   608 //
   635 //
   609 TInt CPbk2NamesListEmptyState::CommandItemCount() const
   636 TInt CPbk2NamesListEmptyState::CommandItemCount() const
   610 	{
   637     {
   611     // Some of the commands might be disabled. Don't count those.
   638     // Some of the commands might be disabled. Don't count those.
   612 	TInt enabledCommandCount = 0;
   639     TInt enabledCommandCount = 0;
   613 	for ( TInt n = 0; n < iCommandItems.Count(); ++n ) 
   640     for ( TInt n = 0; n < iCommandItems.Count(); ++n ) 
   614 		{
   641         {
   615 		if ( iCommandItems[ n ]->IsEnabled() )
   642         if ( iCommandItems[ n ]->IsEnabled() )
   616 			{
   643             {
   617 			enabledCommandCount++;
   644             enabledCommandCount++;
   618 			}
   645             }
   619 		}
   646         }
   620 	return enabledCommandCount;
   647     return enabledCommandCount;
   621     }
   648     }
   622 
   649 
   623 // --------------------------------------------------------------------------
   650 // --------------------------------------------------------------------------
   624 // CPbk2NamesListEmptyState::CommandItemAt
   651 // CPbk2NamesListEmptyState::CommandItemAt
   625 // --------------------------------------------------------------------------
   652 // --------------------------------------------------------------------------
   626 //
   653 //
   627 const MPbk2UiControlCmdItem&
   654 const MPbk2UiControlCmdItem&
   628 CPbk2NamesListEmptyState::CommandItemAt( TInt aIndex ) const
   655 CPbk2NamesListEmptyState::CommandItemAt( TInt aIndex ) const
   629 	{
   656     {
   630     // Some of the commands might be disabled. Skip those.
   657     // Some of the commands might be disabled. Skip those.
   631 	TInt enabledCount = 0;
   658     TInt enabledCount = 0;
   632 	TInt indexOfResult = KErrNotFound;
   659     TInt indexOfResult = KErrNotFound;
   633 	for ( TInt n = 0; n < iCommandItems.Count()&& indexOfResult == KErrNotFound; ++n ) 
   660     for ( TInt n = 0; n < iCommandItems.Count()&& indexOfResult == KErrNotFound; ++n ) 
   634 	
   661     
   635 		{
   662         {
   636 		if ( iCommandItems[ n ]->IsEnabled() )
   663         if ( iCommandItems[ n ]->IsEnabled() )
   637 			{
   664             {
   638 			enabledCount++;
   665             enabledCount++;
   639 			if ( enabledCount-1 == aIndex )
   666             if ( enabledCount-1 == aIndex )
   640 				{
   667                 {
   641 				indexOfResult = n;
   668                 indexOfResult = n;
   642 				}
   669                 }
   643 			}
   670             }
   644 		}
   671         }
   645 	return *iCommandItems[ indexOfResult ];
   672     return *iCommandItems[ indexOfResult ];
   646 	}
   673     }
   647 
   674 
   648 // --------------------------------------------------------------------------
   675 // --------------------------------------------------------------------------
   649 // CPbk2NamesListEmptyState::FocusedCommandItem
   676 // CPbk2NamesListEmptyState::FocusedCommandItem
   650 // --------------------------------------------------------------------------
   677 // --------------------------------------------------------------------------
   651 //
   678 //
   652 const MPbk2UiControlCmdItem*
   679 const MPbk2UiControlCmdItem*
   653 CPbk2NamesListEmptyState::FocusedCommandItem() const
   680 CPbk2NamesListEmptyState::FocusedCommandItem() const
   654 	{
   681     {
   655 	const MPbk2UiControlCmdItem* cmdItem = NULL;
   682     const MPbk2UiControlCmdItem* cmdItem = NULL;
   656 	// Is the focus on a command item:
   683     // Is the focus on a command item:
   657     TInt focusListIndex = iListBox.CurrentItemIndex();
   684     TInt focusListIndex = iListBox.CurrentItemIndex();
   658     const TInt commandItemCount = CommandItemCount();
   685     const TInt commandItemCount = CommandItemCount();
   659     if ( focusListIndex != KErrNotFound && focusListIndex < commandItemCount )
   686     if ( focusListIndex != KErrNotFound && focusListIndex < commandItemCount )
   660         {
   687         {
   661         // Yes it's a command item.
   688         // Yes it's a command item.
   662         cmdItem = &CommandItemAt(focusListIndex); 
   689         cmdItem = &CommandItemAt(focusListIndex); 
   663         }
   690         }
   664 	return cmdItem;
   691     return cmdItem;
   665     }
   692     }
   666 
   693 
   667 // --------------------------------------------------------------------------
   694 // --------------------------------------------------------------------------
   668 // CPbk2NamesListEmptyState::DeleteCommandItemL
   695 // CPbk2NamesListEmptyState::DeleteCommandItemL
   669 // --------------------------------------------------------------------------
   696 // --------------------------------------------------------------------------
   670 //
   697 //
   671 void CPbk2NamesListEmptyState::DeleteCommandItemL( TInt /*aIndex*/ )
   698 void CPbk2NamesListEmptyState::DeleteCommandItemL( TInt /*aIndex*/ )
   672 	{
   699     {
   673     // ownership & management of iCommandItems is wasted in names list
   700     // ownership & management of iCommandItems is wasted in names list
   674     // control. Do nothing here
   701     // control. Do nothing here
   675     }
   702     }
   676 
   703 
   677 // --------------------------------------------------------------------------
   704 // --------------------------------------------------------------------------
   680 //
   707 //
   681 void CPbk2NamesListEmptyState::AddCommandItemL(MPbk2UiControlCmdItem* /*aCommand*/, TInt /*aIndex*/)
   708 void CPbk2NamesListEmptyState::AddCommandItemL(MPbk2UiControlCmdItem* /*aCommand*/, TInt /*aIndex*/)
   682     {
   709     {
   683     // ownership & management of iCommandItems is wasted in names list
   710     // ownership & management of iCommandItems is wasted in names list
   684     // control. Do nothing here
   711     // control. Do nothing here
   685 	}	
   712     }    
   686 
   713 
   687 // --------------------------------------------------------------------------
   714 // --------------------------------------------------------------------------
   688 // CPbk2NamesListEmptyState::DynInitMenuPaneL
   715 // CPbk2NamesListEmptyState::DynInitMenuPaneL
   689 // --------------------------------------------------------------------------
   716 // --------------------------------------------------------------------------
   690 //
   717 //
   696 
   723 
   697     //No contacts visible in this state
   724     //No contacts visible in this state
   698     TInt pos; // Stores the position of the searched menu item.
   725     TInt pos; // Stores the position of the searched menu item.
   699             // This position is not needed or used anywhere
   726             // This position is not needed or used anywhere
   700     
   727     
   701     if (aMenuPane->MenuItemExists(EAknUnmarkAll, pos))
   728     if ( aMenuPane->MenuItemExists ( EAknCmdMarkingModeEnter, pos ) )
   702         {
   729         {
   703         aMenuPane->SetItemDimmed(EAknUnmarkAll, ETrue);
   730         aMenuPane->SetItemDimmed( EAknCmdMarkingModeEnter, ETrue );
   704         }
       
   705     if (aMenuPane->MenuItemExists(EAknMarkAll, pos))
       
   706         {
       
   707         aMenuPane->SetItemDimmed(EAknMarkAll, ETrue);
       
   708         }
   731         }
   709     }
   732     }
   710 
   733 
   711 // --------------------------------------------------------------------------
   734 // --------------------------------------------------------------------------
   712 // CPbk2NamesListEmptyState::ProcessCommandL
   735 // CPbk2NamesListEmptyState::ProcessCommandL
   942     if ( aVisible )
   965     if ( aVisible )
   943         {        
   966         {        
   944         // ownership not transferred
   967         // ownership not transferred
   945         iListBox.SetListCommands( &iCommandItems );
   968         iListBox.SetListCommands( &iCommandItems );
   946         SubscribeCmdItemsVisibility();        
   969         SubscribeCmdItemsVisibility();        
   947         UpdateCommandEnabled( EPbk2CmdRcl, ETrue ); 			
   970         UpdateCommandEnabled( EPbk2CmdRcl, ETrue );             
   948         UpdateCommandEnabled( EPbk2CmdAddFavourites, EFalse ); 
   971         UpdateCommandEnabled( EPbk2CmdAddFavourites, EFalse ); 
   949 		//MyCard is stored separately and may also contain data         
   972         //MyCard is stored separately and may also contain data         
   950         UpdateCommandEnabled( EPbk2CmdOpenMyCard, ETrue ); 
   973         UpdateCommandEnabled( EPbk2CmdOpenMyCard, ETrue ); 
   951         }
   974         }
   952     else
   975     else
   953         {
   976         {
   954         UnsubscribeCmdItemsVisibility();        
   977         UnsubscribeCmdItemsVisibility();        
   960 // --------------------------------------------------------------------------
   983 // --------------------------------------------------------------------------
   961 //    
   984 //    
   962 void CPbk2NamesListEmptyState::CmdItemVisibilityChanged( TInt aCmdItemId, TBool aVisible ) 
   985 void CPbk2NamesListEmptyState::CmdItemVisibilityChanged( TInt aCmdItemId, TBool aVisible ) 
   963     {
   986     {
   964     TInt cmdItemIndex = FindCommand(aCmdItemId);
   987     TInt cmdItemIndex = FindCommand(aCmdItemId);
   965     TRAP_IGNORE( HandleCommandEventL(
   988     TRAP_IGNORE(
       
   989         // If command item is changed to be visible, set its hidden selection to ETrue.
       
   990         if( aVisible )
       
   991             {
       
   992             TInt enableCmdCount = EnabledCommandCount();
       
   993             TListItemProperties prop( iListBox.ItemDrawer()->Properties(enableCmdCount) );
       
   994             prop.SetHiddenSelection(aVisible);
       
   995             iListBox.ItemDrawer()->SetPropertiesL(enableCmdCount-1, prop);
       
   996             }
       
   997     
       
   998         HandleCommandEventL(
   966                 (aVisible ? EItemAdded : EItemRemoved),
   999                 (aVisible ? EItemAdded : EItemRemoved),
   967                  cmdItemIndex) );		
  1000                  cmdItemIndex);
       
  1001         );
   968     }
  1002     }
   969 
  1003 
   970 // --------------------------------------------------------------------------
  1004 // --------------------------------------------------------------------------
   971 // CPbk2NamesListEmptyState::UpdateCommandEnabled
  1005 // CPbk2NamesListEmptyState::UpdateCommandEnabled
   972 // --------------------------------------------------------------------------
  1006 // --------------------------------------------------------------------------
  1047         {
  1081         {
  1048         iListBox.View()->DeselectItem( i );
  1082         iListBox.View()->DeselectItem( i );
  1049         }
  1083         }
  1050     }
  1084     }
  1051 
  1085 
       
  1086 // --------------------------------------------------------------------------
       
  1087 // CPbk2NamesListEmptyState::EnabledCommandCount
       
  1088 // --------------------------------------------------------------------------
       
  1089 // 
       
  1090 TInt CPbk2NamesListEmptyState::EnabledCommandCount() const
       
  1091     {
       
  1092     TInt result = 0;
       
  1093     for ( TInt i = 0; i < iCommandItems.Count(); ++i )
       
  1094         {
       
  1095         if(iCommandItems[i]->IsEnabled())
       
  1096             {
       
  1097             result++;
       
  1098             }
       
  1099         }
       
  1100     return result;    
       
  1101     }
       
  1102 
  1052 //  End of File
  1103 //  End of File