phonebookui/Phonebook2/NamesListExtension/src/NamesListUiExtensionPlugin.cpp
branchRCL_3
changeset 3 04ab22b956c2
parent 0 e686773b3f54
child 14 81f8547efd4f
equal deleted inserted replaced
0:e686773b3f54 3:04ab22b956c2
    38 #include <MPbk2AppUi.h>
    38 #include <MPbk2AppUi.h>
    39 #include <MPbk2ApplicationServices.h>
    39 #include <MPbk2ApplicationServices.h>
    40 #include <MPbk2ApplicationServices2.h>
    40 #include <MPbk2ApplicationServices2.h>
    41 #include <CPbk2StoreConfiguration.h>
    41 #include <CPbk2StoreConfiguration.h>
    42 #include <TVPbkContactStoreUriPtr.h>
    42 #include <TVPbkContactStoreUriPtr.h>
       
    43 #include <CPbk2ApplicationServices.h>
    43 
    44 
    44 #include <MPbk2ContactUiControl.h>
    45 #include <MPbk2ContactUiControl.h>
    45 #include <MPbk2ViewExplorer.h>
    46 #include <MPbk2ViewExplorer.h>
    46 #include <CPbk2ViewState.h>
    47 #include <CPbk2ViewState.h>
    47 
    48 
    58 #include <CVPbkContactStoreUriArray.h>
    59 #include <CVPbkContactStoreUriArray.h>
    59 #include <MPbk2ContactUiControl2.h>
    60 #include <MPbk2ContactUiControl2.h>
    60 #include <MVPbkContactStore.h>
    61 #include <MVPbkContactStore.h>
    61 #include <MVPbkContactStoreList.h>
    62 #include <MVPbkContactStoreList.h>
    62 #include <MVPbkContactStoreInfo.h>
    63 #include <MVPbkContactStoreInfo.h>
       
    64 #include <MVPbkContactStoreProperties.h>
    63 
    65 
    64 // Debugging headers
    66 // Debugging headers
    65 
    67 
    66 #include <Pbk2Debug.h>
    68 #include <Pbk2Debug.h>
    67 #include <Pbk2Profile.h>
    69 #include <Pbk2Profile.h>
   100     if ( iCCAConnection )
   102     if ( iCCAConnection )
   101         {
   103         {
   102         iCCAConnection->Close();
   104         iCCAConnection->Close();
   103         }
   105         }
   104     delete iContentProvider;
   106     delete iContentProvider;
       
   107     if ( iLocalStore )
       
   108         {
       
   109         iLocalStore->Close( *this );
       
   110         }
       
   111     Release( iAppServices );
   105     }
   112     }
   106 
   113 
   107     
   114     
   108 
   115 
   109 // --------------------------------------------------------------------------
   116 // --------------------------------------------------------------------------
   124 // CNamesListUIExtensionPlugin::ConstructL
   131 // CNamesListUIExtensionPlugin::ConstructL
   125 // --------------------------------------------------------------------------
   132 // --------------------------------------------------------------------------
   126 //
   133 //
   127 void CNamesListUIExtensionPlugin::ConstructL()
   134 void CNamesListUIExtensionPlugin::ConstructL()
   128     {
   135     {
       
   136     iLocalStoreContactsCount = 0;	
       
   137     iAppServices = CPbk2ApplicationServices::InstanceL();
   129     }
   138     }
   130 
   139 
   131 // --------------------------------------------------------------------------
   140 // --------------------------------------------------------------------------
   132 // CNamesListUIExtensionPlugin::ContentProviderL
   141 // CNamesListUIExtensionPlugin::ContentProviderL
   133 // --------------------------------------------------------------------------
   142 // --------------------------------------------------------------------------
   134 //
   143 //
   135 inline CSpbContentProvider& CNamesListUIExtensionPlugin::ContentProviderL()
   144 inline CSpbContentProvider& CNamesListUIExtensionPlugin::ContentProviderL()
   136 	{
   145 	{
   137     if( !iContentProvider )
   146     if( !iContentProvider )
   138         {
   147         {
   139         MPbk2ApplicationServices& apps = Phonebook2::Pbk2AppUi()->ApplicationServices();
   148         TAny* ext = iAppServices->MPbk2ApplicationServicesExtension( 
   140         TAny* ext = apps.MPbk2ApplicationServicesExtension( 
       
   141             KMPbk2ApplicationServicesExtension2Uid );
   149             KMPbk2ApplicationServicesExtension2Uid );
   142         if( !ext )
   150         if( !ext )
   143             {
   151             {
   144             User::Leave( KErrNotReady );
   152             User::Leave( KErrNotReady );
   145             }
   153             }
   146         CPbk2StoreManager& storeManager = 
   154         CPbk2StoreManager& storeManager = 
   147             static_cast<MPbk2ApplicationServices2*>(ext)->StoreManager();
   155             static_cast<MPbk2ApplicationServices2*>(ext)->StoreManager();
   148         iContentProvider = CSpbContentProvider::NewL( apps.ContactManager(), storeManager,  
   156         iContentProvider = CSpbContentProvider::NewL( iAppServices->ContactManager(), storeManager,  
   149             CSpbContentProvider::EStatusMessage | CSpbContentProvider::EPhoneNumber );
   157             CSpbContentProvider::EStatusMessage | CSpbContentProvider::EPhoneNumber );
   150         }
   158         }
   151 	return *iContentProvider;
   159 	return *iContentProvider;
   152 	}
   160 	}
   153 
   161 
   286                 {
   294                 {
   287                 DimItem( aMenuPane, EPbk2CmdRemoveFromTopContacts );
   295                 DimItem( aMenuPane, EPbk2CmdRemoveFromTopContacts );
   288                 }
   296                 }
   289             break;
   297             break;
   290             }
   298             }
   291 /* Patrik 23.10.2008 Removed as agreed by ECE program management.
       
   292         case R_PHONEBOOK2_MOVE_TOPCONTACTS:
       
   293             {
       
   294             if( !Pbk2NlxMenuFiltering::TopRearrangingReadyL( aControl ) || 
       
   295                 aControl.ContactsMarked() ) 
       
   296                 {
       
   297                 DimItem( aMenuPane, EPbk2CmdMoveInTopContactsList);
       
   298                 }
       
   299             break;
       
   300             }
       
   301 */
       
   302         case R_PHONEBOOK2_NAMELIST_CALL_CONTACT_MENU:
   299         case R_PHONEBOOK2_NAMELIST_CALL_CONTACT_MENU:
   303             {
   300             {
   304             if ( Pbk2NlxMenuFiltering::AddToFavoritesCmdSelected( aControl ) )
   301             if ( Pbk2NlxMenuFiltering::AddToFavoritesCmdSelected( aControl ) )
   305                 {
   302                 {
   306                 DimItem( aMenuPane, EPbk2CmdCall );
   303                 DimItem( aMenuPane, EPbk2CmdCall );
   422                 }
   419                 }
   423             break;
   420             break;
   424             }
   421             }
   425         case R_PHONEBOOK2_MERGE_CONTACTS:
   422         case R_PHONEBOOK2_MERGE_CONTACTS:
   426             {
   423             {
   427             MVPbkContactStoreList& storeList = 
       
   428                 Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager().ContactStoresL();
       
   429             // only phone memory contacts can be merged
       
   430             MVPbkContactStore* store = storeList.Find( VPbkContactStoreUris::DefaultCntDbUri() );
       
   431             TInt numberOfContacts = 0;
   424             TInt numberOfContacts = 0;
   432             if( store )
   425             MVPbkContactLink* mylink = MyCardLink();
   433                 {
   426             numberOfContacts = iLocalStoreContactsCount - ( mylink ? 1 : 0 );
   434                 MVPbkContactLink* mylink = MyCardLink();
   427             
   435                 numberOfContacts = store->StoreInfo().NumberOfContactsL() - ( mylink ? 1 : 0 );
       
   436                 }
       
   437             // there must be two contacts to do merge
   428             // there must be two contacts to do merge
   438             if ( numberOfContacts  < KMinNumOfContactsToMerge )
   429             if ( numberOfContacts  < KMinNumOfContactsToMerge )
   439                 {
   430                 {
   440                 aMenuPane->SetItemDimmed( EPbk2CmdMergeContacts, ETrue );
   431                 aMenuPane->SetItemDimmed( EPbk2CmdMergeContacts, ETrue );
   441                 }
   432                 }
   532 	CPbk2MyCard* mycard = NULL;
   523 	CPbk2MyCard* mycard = NULL;
   533 	if( iNamesListExViewRef )
   524 	if( iNamesListExViewRef )
   534 		{
   525 		{
   535 		mycard = iNamesListExViewRef->MyCard();
   526 		mycard = iNamesListExViewRef->MyCard();
   536 		}
   527 		}
   537 	
   528     InitLocalStoreObserverL();
       
   529     
   538     MPbk2ContactUiControlExtension* extension = 
   530     MPbk2ContactUiControlExtension* extension = 
   539         CPbk2NameslistUiControlExtension::NewL( aContactManager, ContentProviderL(), mycard );
   531         CPbk2NameslistUiControlExtension::NewL( aContactManager, ContentProviderL(), mycard );
   540     return extension;
   532     return extension;
   541     }
   533     }
   542 
   534 
   732         
   724         
   733         default:
   725         default:
   734             break;
   726             break;
   735         }
   727         }
   736     }            
   728     }            
   737 	
   729 // --------------------------------------------------------------------------
       
   730 // CNamesListUIExtensionPlugin::StoreReady
       
   731 // --------------------------------------------------------------------------
       
   732 //
       
   733 void CNamesListUIExtensionPlugin::StoreReady( MVPbkContactStore& aContactStore )
       
   734     {
       
   735     if ( aContactStore.StoreProperties().Name().UriDes().Compare
       
   736             ( VPbkContactStoreUris::DefaultCntDbUri() ) )
       
   737         {
       
   738         iLocalStoreContactsCount = iLocalStore->StoreInfo().NumberOfContactsL();
       
   739         }
       
   740     }
       
   741 
       
   742 // --------------------------------------------------------------------------
       
   743 // CNamesListUIExtensionPlugin::StoreUnavailable
       
   744 // --------------------------------------------------------------------------
       
   745 //
       
   746 void CNamesListUIExtensionPlugin::StoreUnavailable
       
   747         ( MVPbkContactStore& aContactStore, TInt /*aReason*/ )
       
   748     {
       
   749     if ( aContactStore.StoreProperties().Name().UriDes().Compare
       
   750             ( VPbkContactStoreUris::DefaultCntDbUri() ) && iLocalStore )
       
   751         {
       
   752         iLocalStore->Close( *this );
       
   753         iLocalStore = NULL;
       
   754         }
       
   755     }
       
   756 
       
   757 // --------------------------------------------------------------------------
       
   758 // CNamesListUIExtensionPlugin::HandleStoreEventL
       
   759 // --------------------------------------------------------------------------
       
   760 //
       
   761 void CNamesListUIExtensionPlugin::HandleStoreEventL(
       
   762         MVPbkContactStore& aContactStore,
       
   763         TVPbkContactStoreEvent aStoreEvent )
       
   764     {
       
   765     if ( aContactStore.StoreProperties().Name().UriDes().Compare
       
   766             ( VPbkContactStoreUris::DefaultCntDbUri() ) )
       
   767         {
       
   768         switch ( aStoreEvent.iEventType )
       
   769            {
       
   770            case TVPbkContactStoreEvent::EContactAdded:
       
   771                {
       
   772                iLocalStoreContactsCount++;
       
   773                break;
       
   774                }
       
   775     
       
   776            case TVPbkContactStoreEvent::EContactDeleted:
       
   777                {
       
   778                iLocalStoreContactsCount--;
       
   779                break;
       
   780                }
       
   781                
       
   782            case TVPbkContactStoreEvent::EStoreBackupRestoreCompleted:
       
   783            case TVPbkContactStoreEvent::EUnknownChanges:
       
   784                {
       
   785                iLocalStoreContactsCount = iLocalStore->StoreInfo().NumberOfContactsL();
       
   786                break;
       
   787                }
       
   788                
       
   789            default:
       
   790                break;
       
   791            }
       
   792         }
       
   793     }
       
   794 // --------------------------------------------------------------------------
       
   795 // CNamesListUIExtensionPlugin::InitLocalStoreObserverL
       
   796 // --------------------------------------------------------------------------
       
   797 //
       
   798 void CNamesListUIExtensionPlugin::InitLocalStoreObserverL()
       
   799     {
       
   800     if ( !iLocalStore )
       
   801         {
       
   802         MVPbkContactStoreList& storeList = iAppServices->ContactManager().ContactStoresL();
       
   803         iLocalStore = storeList.Find( VPbkContactStoreUris::DefaultCntDbUri() );
       
   804         if ( iLocalStore )
       
   805             {
       
   806             iLocalStore->OpenL( *this );
       
   807             }
       
   808         }
       
   809     }
   738 //  End of File
   810 //  End of File