phoneuis/easydialing/src/easydialingplugin.cpp
branchRCL_3
changeset 19 544e34b3255a
parent 17 38529f706030
child 25 91c2fb4b78df
equal deleted inserted replaced
17:38529f706030 19:544e34b3255a
   116 
   116 
   117 // MODULE DATA STRUCTURES
   117 // MODULE DATA STRUCTURES
   118 
   118 
   119 // LOCAL FUNCTION PROTOTYPES
   119 // LOCAL FUNCTION PROTOTYPES
   120 
   120 
   121 TInt CompareTPsMatchLocation( const TPsMatchLocation& a1, const TPsMatchLocation& a2);
   121 TInt CompareTPsMatchLocation( const TPsMatchLocation& a1, const TPsMatchLocation& a2 );
   122 
   122 
   123 void AppendStringWithMatchDataL(
   123 void AppendStringWithMatchDataL(
   124         TDes& aBuffer,
   124         TDes& aBuffer,
   125         const TDesC& aText,
   125         const TDesC& aText,
   126         CPSRequestHandler* aPSHandler,
   126         CPSRequestHandler* aPSHandler,
   137 static TBool IsItuTCharacter( TChar aChar );
   137 static TBool IsItuTCharacter( TChar aChar );
   138 
   138 
   139 static TInt Find( const MVPbkContactLink* aLink, const RPointerArray<MVPbkContactLink>& aArray );
   139 static TInt Find( const MVPbkContactLink* aLink, const RPointerArray<MVPbkContactLink>& aArray );
   140 
   140 
   141 template <class T>
   141 template <class T>
   142 inline void CleanupResetAndDestroyPushL(T& aRef);
   142 inline void CleanupResetAndDestroyPushL( T& aRef );
   143 
   143 
   144 
   144 
   145 
   145 
   146 // -----------------------------------------------------------------------------
   146 // -----------------------------------------------------------------------------
   147 // CEasyDialingPlugin
   147 // CEasyDialingPlugin
   201     // Find a handle to ca launcher extension MCCAConnectionExt.
   201     // Find a handle to ca launcher extension MCCAConnectionExt.
   202     // Easydialing has to use the extension API, because it needs function CloseAppL
   202     // Easydialing has to use the extension API, because it needs function CloseAppL
   203     // only found in extension.
   203     // only found in extension.
   204     // MCCAConnection extension has to be obtained through MCCAParameter extension,
   204     // MCCAConnection extension has to be obtained through MCCAParameter extension,
   205     // since MCCAConnection is not designed to be extensible API.
   205     // since MCCAConnection is not designed to be extensible API.
   206     MCCAParameter* parameter = TCCAFactory::NewParameterL();    
   206     MCCAParameter* parameter = TCCAFactory::NewParameterL();
   207     TAny* any = parameter->CcaParameterExtension( KMCCAConnectionExtUid );
   207     TAny* any = parameter->CcaParameterExtension( KMCCAConnectionExtUid );
   208     
   208     
   209     // Parameter can be deallocated since "any" containing pointer to contact launcher
   209     // Parameter can be deallocated since "any" containing pointer to contact launcher
   210     // is not tied to parameter in any way.
   210     // is not tied to parameter in any way.
   211     parameter->Close();
   211     parameter->Close();
   231     iResourceFileOffset = iCoeEnv->AddResourceFileL( resourceFileName );
   231     iResourceFileOffset = iCoeEnv->AddResourceFileL( resourceFileName );
   232   
   232   
   233     SetComponentsToInheritVisibility( ETrue );
   233     SetComponentsToInheritVisibility( ETrue );
   234     }
   234     }
   235 
   235 
   236 // ---------------------------------------------------------
   236 // -----------------------------------------------------------------------------
   237 // ~CEasyDialingPlugin
   237 // ~CEasyDialingPlugin
   238 // The desctructor
   238 // The desctructor
   239 // ---------------------------------------------------------
   239 // -----------------------------------------------------------------------------
   240 //
   240 //
   241 CEasyDialingPlugin::~CEasyDialingPlugin()
   241 CEasyDialingPlugin::~CEasyDialingPlugin()
   242     {
   242     {
   243     iObservers.Reset();
   243     iObservers.Reset();
   244     
   244     
   320     model->SetItemTextArray( iListBoxModel );
   320     model->SetItemTextArray( iListBoxModel );
   321     model->SetOwnershipType( ELbmDoesNotOwnItemArray );
   321     model->SetOwnershipType( ELbmDoesNotOwnItemArray );
   322 
   322 
   323     iContactListBox->MakeVisible( EFalse );
   323     iContactListBox->MakeVisible( EFalse );
   324     
   324     
   325     SetFocus( EFalse );    
   325     SetFocus( EFalse );
   326     iContactListBox->ActivateL();
   326     iContactListBox->ActivateL();
   327     
   327     
   328     GfxTransEffect::Register( iContactListBox, 
   328     GfxTransEffect::Register( iContactListBox, 
   329                               KGfxContactListBoxUid, EFalse );
   329                               KGfxContactListBoxUid, EFalse );
   330     
   330     
   342 // Resets easydialing plugin.
   342 // Resets easydialing plugin.
   343 // -----------------------------------------------------------------------------
   343 // -----------------------------------------------------------------------------
   344 //
   344 //
   345 void CEasyDialingPlugin::Reset()
   345 void CEasyDialingPlugin::Reset()
   346     {
   346     {
   347     // PCS searches completing must be discarded, if the complete
   347     // PCS searches completing after the Reset() call must be discarded
   348     // after Reset() -call.    
       
   349     iDiscardCompletingSearches = ETrue;
   348     iDiscardCompletingSearches = ETrue;
   350     
   349     
   351     iNewSearchNeeded = EFalse;
   350     iNewSearchNeeded = EFalse;
   352     iSearchString.Zero();
   351     iSearchString.Zero();
   353     iListBoxModel->Reset();
   352     iListBoxModel->Reset();
   602     // convert rect to absolute coordinates
   601     // convert rect to absolute coordinates
   603     rect.SetRect( PositionRelativeToScreen(), rect.Size() );
   602     rect.SetRect( PositionRelativeToScreen(), rect.Size() );
   604     
   603     
   605     iContactListBox->SetMaxRect( rect );
   604     iContactListBox->SetMaxRect( rect );
   606     iContactListBox->SetRectToNumberOfItems( iNumberOfNames );
   605     iContactListBox->SetRectToNumberOfItems( iNumberOfNames );
       
   606     
       
   607     TInt itemToMakeVisible = iContactListBox->CurrentItemIndex();  
       
   608     if ( itemToMakeVisible == KErrNotFound && iNumberOfNames )
       
   609         {
       
   610         // if no current item is set, make sure that the list is then 
       
   611         // scrolled to the bottom.
       
   612         itemToMakeVisible = iNumberOfNames - 1;
       
   613         } 
       
   614     iContactListBox->ScrollToMakeItemVisible( itemToMakeVisible );
   607     }
   615     }
   608 
   616 
   609 
   617 
   610 // -----------------------------------------------------------------------------
   618 // -----------------------------------------------------------------------------
   611 // FocusChanged
   619 // FocusChanged
   826         default:
   834         default:
   827             break;
   835             break;
   828         }
   836         }
   829     
   837     
   830     // Reset focus unless it is flagged to be remembered.
   838     // Reset focus unless it is flagged to be remembered.
   831     if ( ! iRememberFocus )
   839     if ( !iRememberFocus )
   832         {
   840         {
   833         SetFocus( EFalse );
   841         SetFocus( EFalse );
   834         DrawDeferred();
   842         DrawDeferred();
   835         }
   843         }
   836     
   844     
   878         // not to the keyboard it is made with. While this is not strictly
   886         // not to the keyboard it is made with. While this is not strictly
   879         // identical to checking the used keyboard, this behaves identically
   887         // identical to checking the used keyboard, this behaves identically
   880         // in most of the normal cases, and makes the logic simpler.
   888         // in most of the normal cases, and makes the logic simpler.
   881         if ( IsItuTCharacter( iSearchString[i] ) )
   889         if ( IsItuTCharacter( iSearchString[i] ) )
   882             {
   890             {
   883             item->SetMode( EItut );
   891             item->SetMode( EPredictiveItuT );
   884             }
   892             }
   885         else 
   893         else 
   886             {
   894             {
   887             item->SetMode( EQwerty );
   895             item->SetMode( EPredictiveDefaultKeyboard );
   888             }
   896             }
   889         
   897         
   890         iPredictiveSearchQuery->AppendL(*item);
   898         iPredictiveSearchQuery->AppendL(*item);
   891 
   899 
   892         // Previous CPsQuery::AppendL takes the ownership of item.
   900         // Previous CPsQuery::AppendL takes the ownership of item.
  1146         
  1154         
  1147         LaunchSearchL();
  1155         LaunchSearchL();
  1148         }
  1156         }
  1149 
  1157 
  1150     // Give up focus, if iRememberFocus flag is not set.
  1158     // Give up focus, if iRememberFocus flag is not set.
  1151     if ( ! iRememberFocus )
  1159     if ( !iRememberFocus )
  1152         {
  1160         {
  1153         SetFocus( EFalse );
  1161         SetFocus( EFalse );
  1154         DrawDeferred();
  1162         DrawDeferred();
  1155         }    
  1163         }    
  1156     iRememberFocus = EFalse;
  1164     iRememberFocus = EFalse;
  1253 // -----------------------------------------------------------------------------
  1261 // -----------------------------------------------------------------------------
  1254 //
  1262 //
  1255 HBufC* CEasyDialingPlugin::CreateContactStringLC( CPsClientData* aResult,
  1263 HBufC* CEasyDialingPlugin::CreateContactStringLC( CPsClientData* aResult,
  1256         CEasyDialingContactDataManager::TNameOrder aNameOrder )
  1264         CEasyDialingContactDataManager::TNameOrder aNameOrder )
  1257     {
  1265     {
  1258     TPtr firstName = aResult->Data( iFirstNamePCSIndex )->Des();
  1266     TPtrC firstName = *aResult->Data( iFirstNamePCSIndex );
  1259     TPtr lastName = aResult->Data( iLastNamePCSIndex )->Des();
  1267     TPtrC lastName = *aResult->Data( iLastNamePCSIndex );
  1260     TPtr companyName( NULL, 0 );
  1268     TPtrC companyName( KNullDesC );
  1261     
  1269     
  1262     if ( iCompanyNamePCSIndex != KErrNotFound )
  1270     if ( iCompanyNamePCSIndex != KErrNotFound )
  1263         {
  1271         {
  1264         companyName.Set( aResult->Data( iCompanyNamePCSIndex )->Des() );
  1272         companyName.Set( *aResult->Data( iCompanyNamePCSIndex ) );
  1265         }
  1273         }
  1266     return EasyDialingUtils::CreateContactStringLC( firstName, lastName, companyName, aNameOrder );
  1274     return EasyDialingUtils::CreateContactStringLC( firstName, lastName, companyName, aNameOrder );
  1267     }
  1275     }
  1268 
  1276 
  1269 
  1277 
  1277     if ( !aObserver )
  1285     if ( !aObserver )
  1278         {
  1286         {
  1279         return;
  1287         return;
  1280         }
  1288         }
  1281     
  1289     
  1282     User::LeaveIfError( iObservers.Append( aObserver ) );
  1290     iObservers.AppendL( aObserver );
  1283     }
  1291     }
  1284 
  1292 
  1285 
  1293 
  1286 // -----------------------------------------------------------------------------
  1294 // -----------------------------------------------------------------------------
  1287 // RemoveObserver
  1295 // RemoveObserver
  1416     
  1424     
  1417     else if ( aMenuResourceId == R_EASYDIALING_OPTIONS_ON_OFF_CASCADE_MENU )
  1425     else if ( aMenuResourceId == R_EASYDIALING_OPTIONS_ON_OFF_CASCADE_MENU )
  1418         {
  1426         {
  1419         if ( IsEnabled() )
  1427         if ( IsEnabled() )
  1420             {
  1428             {
  1421             aMenuPane.SetItemButtonState( EEasyDialingOn, EEikMenuItemSymbolOn );      
  1429             aMenuPane.SetItemButtonState( EEasyDialingOn, EEikMenuItemSymbolOn );
  1422             }
  1430             }
  1423         else
  1431         else
  1424             {
  1432             {
  1425             aMenuPane.SetItemButtonState( EEasyDialingOff, EEikMenuItemSymbolOn );
  1433             aMenuPane.SetItemButtonState( EEasyDialingOff, EEikMenuItemSymbolOn );
  1426             }
  1434             }
  1747             
  1755             
  1748         // Pause contact data manager when panning and flicking listbox.
  1756         // Pause contact data manager when panning and flicking listbox.
  1749         // This ensures smooth and responsive listbox touch handling.
  1757         // This ensures smooth and responsive listbox touch handling.
  1750         case EEventFlickStarted:
  1758         case EEventFlickStarted:
  1751         case EEventPanningStarted:
  1759         case EEventPanningStarted:
       
  1760         case KEasyDialingScrollingStarted:
  1752             iContactDataManager->Pause( ETrue );
  1761             iContactDataManager->Pause( ETrue );
  1753             break;
  1762             break;
  1754             
  1763             
  1755         case EEventFlickStopped:
  1764         case EEventFlickStopped:
  1756         case EEventPanningStopped:
  1765         case EEventPanningStopped:
       
  1766         case KEasyDialingScrollingStopped:
  1757             iContactDataManager->Pause( EFalse );
  1767             iContactDataManager->Pause( EFalse );
       
  1768             
       
  1769             // Touching the listbox always removes the visual focus from any list item.
       
  1770             // Move the focus away from the listbox after panning has ended to
       
  1771             // align our internal state with the visual lack of focus.
       
  1772             if ( IsFocused() )
       
  1773                 {
       
  1774                 SetFocus( EFalse );
       
  1775                 DrawDeferred();
       
  1776                 }
  1758             break;
  1777             break;
  1759             
  1778             
  1760         // We are not interested about the other listbox events.
  1779         // We are not interested about the other listbox events.
  1761         default:
  1780         default:
  1762             break;
  1781             break;
  1786     if ( iSearchString.Length() > 0 )
  1805     if ( iSearchString.Length() > 0 )
  1787         {
  1806         {
  1788         if ( iContactLauncherActive )
  1807         if ( iContactLauncherActive )
  1789             {
  1808             {
  1790             // Set the flag to make a search when communication launcher exits.
  1809             // Set the flag to make a search when communication launcher exits.
  1791             iNewSearchNeeded = ETrue;                   
  1810             iNewSearchNeeded = ETrue;
  1792             }
  1811             }
  1793         else
  1812         else
  1794             {
  1813             {
  1795             // We get here if user e.g. leaves dialer open and goes to Contacts
  1814             // We get here if user e.g. leaves dialer open and goes to Contacts
  1796             // application and does some editing.
  1815             // application and does some editing.
  1867 // based on their location.
  1886 // based on their location.
  1868 // -----------------------------------------------------------------------------
  1887 // -----------------------------------------------------------------------------
  1869 //
  1888 //
  1870 TInt CompareTPsMatchLocation( const TPsMatchLocation& a1, const TPsMatchLocation& a2)
  1889 TInt CompareTPsMatchLocation( const TPsMatchLocation& a1, const TPsMatchLocation& a2)
  1871     {
  1890     {
  1872     if ( a1.index == a2.index )
  1891     return a1.index - a2.index;
  1873         {
       
  1874         return 0;
       
  1875         }
       
  1876     return ( a1.index > a2.index ) ? 1 : -1;
       
  1877     }
  1892     }
  1878 
  1893 
  1879 
  1894 
  1880 // -----------------------------------------------------------------------------
  1895 // -----------------------------------------------------------------------------
  1881 // AppendStringWithMatchDataL
  1896 // AppendStringWithMatchDataL
  1905         matchIndices.Sort( order );
  1920         matchIndices.Sort( order );
  1906        
  1921        
  1907         TInt numberOfIndices = matchIndices.Count();
  1922         TInt numberOfIndices = matchIndices.Count();
  1908         TInt textOffset = 0;
  1923         TInt textOffset = 0;
  1909         
  1924         
  1910         for (TInt i = 0; i < numberOfIndices ; i++ )
  1925         for ( TInt i = 0; i < numberOfIndices ; i++ )
  1911             {
  1926             {
  1912             TInt matchingPartStart = matchIndices[i].index;
  1927             TInt matchingPartStart = matchIndices[i].index;
  1913             TInt matchingPartLength = matchIndices[i].length;
  1928             TInt matchingPartLength = matchIndices[i].length;
  1914             
  1929             
  1915             // Append the non-matching part (if exists) 
  1930             // Append the non-matching part (if exists) 
  1922             // Append matching separator charactes.
  1937             // Append matching separator charactes.
  1923             aBuffer.Append( KHighlightSeparatorChar );
  1938             aBuffer.Append( KHighlightSeparatorChar );
  1924             
  1939             
  1925             TPtrC matchingPart = aText.Mid( matchingPartStart, matchingPartLength );
  1940             TPtrC matchingPart = aText.Mid( matchingPartStart, matchingPartLength );
  1926             aBuffer.Append( matchingPart );
  1941             aBuffer.Append( matchingPart );
  1927     
  1942             
  1928             // Append matching separator charactes.
  1943             // Append matching separator charactes.
  1929             aBuffer.Append( KHighlightSeparatorChar );
  1944             aBuffer.Append( KHighlightSeparatorChar );
  1930                     
  1945             
  1931             textOffset = matchingPartStart + matchingPartLength;
  1946             textOffset = matchingPartStart + matchingPartLength;
  1932             }
  1947             }
  1933 
  1948 
  1934         CleanupStack::PopAndDestroy( &matchIndices );
  1949         CleanupStack::PopAndDestroy( &matchIndices );
  1935         CleanupStack::PopAndDestroy( matchingParts );
  1950         CleanupStack::PopAndDestroy( matchingParts );