textinput/peninputarc/src/peninputlayouteng/peninputimefinder.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Implementation for CImePluginFinder
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "peninputimefinder.h"  
       
    20 #include "aknfeppeninputimeplugin.h"
       
    21 
       
    22 const TInt KImePluginInterface = 0x10207363;
       
    23 
       
    24 // ======== EXTERNAL FUNCTIONS ========
       
    25 
       
    26 //
       
    27 // Cleaup function
       
    28 //
       
    29 extern void Cleanup( TAny* aAny );
       
    30 
       
    31 // ======== LOCAL FUNCTIONS ============
       
    32 
       
    33 //
       
    34 // Binary search comaration method
       
    35 //
       
    36 static TInt CompareImePlguin(const TInternalImePlguinImplDetail& aIme1, 
       
    37                              const TInternalImePlguinImplDetail& aIme2)
       
    38     {
       
    39     //order is descent
       
    40     return (aIme2.iMeritValue - aIme1.iMeritValue);
       
    41     }
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CImePluginFinder::NewL
       
    47 // Factory function
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CImePluginFinder* CImePluginFinder::NewL()
       
    51     {
       
    52     return new(ELeave)CImePluginFinder();
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CImePluginFinder::~CImePluginFinder
       
    57 // Destructor
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CImePluginFinder::~CImePluginFinder()
       
    61     {
       
    62     Reset();
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CImePluginFinder::InitializeL
       
    67 // Initialze the finder and prepare all internal data
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CImePluginFinder::InitializeL(CPtiEngine* aPtiEngine)
       
    71     {
       
    72     //only initialzed once
       
    73     if( iInitialized )
       
    74         {
       
    75         return;
       
    76         }
       
    77     
       
    78     //list all ime imeplementation
       
    79     RImplInfoPtrArray infoArray;
       
    80     TUid id;
       
    81     id.iUid = KImePluginInterface;
       
    82     
       
    83     TEComResolverParams params;
       
    84     CleanupStack::PushL( TCleanupItem( Cleanup, &infoArray ) );
       
    85     REComSession::ListImplementationsL(id, infoArray);
       
    86     
       
    87     TUid dtor_ID_Key;
       
    88     CAknFepPenInputImePlugin* imeInterface = NULL;
       
    89     RArray<CAknFepPenInputImePlugin::TImePlguinImplDetail> details;
       
    90     
       
    91     for(TInt i = 0; i < infoArray.Count(); ++i )
       
    92         {
       
    93         TUid imeImplId = infoArray[i]->ImplementationUid();
       
    94         TRAP_IGNORE(imeInterface = REINTERPRET_CAST(CAknFepPenInputImePlugin*, 
       
    95                                  REComSession::CreateImplementationL(imeImplId, 
       
    96                                                                      dtor_ID_Key, 
       
    97                                                                      NULL)));
       
    98 
       
    99         if( !imeInterface )
       
   100             {
       
   101             continue;
       
   102             }
       
   103 
       
   104         imeInterface->iDtor_ID_Key = dtor_ID_Key;         
       
   105         imeInterface->SupportModes(aPtiEngine, details);
       
   106         
       
   107         //store all imeplemtnation details to internal array
       
   108         //this is important, because other list use the pointer 
       
   109         //to internal data of the iAllImplementations. Once iAllImplementations
       
   110         //changes, the pointers in other array may be invalid.
       
   111         for(TInt j = 0; j < details.Count(); ++j)
       
   112             {
       
   113             TInternalImePlguinImplDetail intDetail;
       
   114             intDetail.iImplementationId = details[j].iImplementationId;
       
   115             intDetail.iMode = details[j].iMode;
       
   116             intDetail.iMeritValue = details[j].iMeritValue;
       
   117             intDetail.iLanguage = details[j].iLanguage;
       
   118             iAllImplementations.AppendL(intDetail);
       
   119             }
       
   120             
       
   121         details.Reset();
       
   122         delete imeInterface;
       
   123         }
       
   124         
       
   125     for(TInt i = 0; i < iAllImplementations.Count(); ++i)
       
   126         {
       
   127         AddImplementationL(iAllImplementations[i]);
       
   128         }
       
   129         
       
   130     CleanupStack::PopAndDestroy(&infoArray); // infoArray    
       
   131     REComSession::FinalClose();//cleanup ecom
       
   132     iInitialized = ETrue;
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // CImePluginFinder::SupportLanguagesL
       
   137 // Get pen support language list
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CImePluginFinder::SupportLanguages(RArray<TInt>& aLanguageLists)
       
   141     {
       
   142     aLanguageLists.Reset();
       
   143     for( TInt i = 0; i < iPluginList.Count(); ++i )
       
   144         {
       
   145         aLanguageLists.InsertInOrder(iPluginList[i].iLanguage);
       
   146         }
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CImePluginFinder::GetImePlugins
       
   151 // Get IME plugin implementation list
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CImePluginFinder::GetImePlugins(TInt aLanguage, TInt aPluginMode, 
       
   155                                      RArray<TInt>& aImplmentationIds)
       
   156     {
       
   157     aImplmentationIds.Reset();
       
   158     InternalGetImePlugins(aLanguage, aPluginMode, aImplmentationIds);
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CImePluginFinder::GetImePlugins
       
   163 // Get IME plugin implementation list
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CImePluginFinder::GetImePlugins(TInt aLanguage, RArray<TInt>& aImplmentationIds)
       
   167     {
       
   168     aImplmentationIds.Reset();
       
   169     InternalGetImePlugins(aLanguage, EPluginInputModeHwr, aImplmentationIds);
       
   170     InternalGetImePlugins(aLanguage, EPluginInputModeVkb, aImplmentationIds);
       
   171    // InternalGetImePlugins(aLanguage, EPluginInputModeCommon, aImplmentationIds);
       
   172     }
       
   173     
       
   174 // ---------------------------------------------------------------------------
       
   175 // CImePluginFinder::Initialized
       
   176 // Test the Ime Finder initialiaztion state
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 TBool CImePluginFinder::Initialized()
       
   180     {
       
   181     return iInitialized; 
       
   182     }
       
   183     
       
   184 // ---------------------------------------------------------------------------
       
   185 // CImePluginFinder::RefreshL
       
   186 // Refresh internal data after system changes
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CImePluginFinder::RefreshL(CPtiEngine* aPtiEngine)
       
   190     {
       
   191     Reset();
       
   192     InitializeL(aPtiEngine);
       
   193     }
       
   194 // ---------------------------------------------------------------------------
       
   195 // CImePluginFinder::IsSupportPluginMode
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 TBool CImePluginFinder::IsSupportPluginMode( TLanguage aLanguage, TPluginInputMode aMode )
       
   199     {
       
   200     TImePluginLangAndMode ref;
       
   201     ref.iLanguage = aLanguage;
       
   202     ref.iMode = aMode,
       
   203     ref.iImePluginList = NULL;
       
   204     
       
   205     TInt index = iPluginList.FindInSignedKeyOrder(ref);
       
   206     return index != KErrNotFound ? ETrue : EFalse;
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CImePluginFinder::CImePluginFinder
       
   211 // Constructor
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 CImePluginFinder::CImePluginFinder()
       
   215     {
       
   216     }
       
   217     
       
   218 // ---------------------------------------------------------------------------
       
   219 // CImePluginFinder::InternalGetImePlugins
       
   220 // Internal version of get IME plugin implementation list
       
   221 // ---------------------------------------------------------------------------
       
   222 //
       
   223 void CImePluginFinder::InternalGetImePlugins(TInt aLanguage, TInt aPluginMode, 
       
   224                                              RArray<TInt>& aImplmentationIds)
       
   225     {
       
   226     //find language in list
       
   227     TImePluginLangAndMode ref;
       
   228     ref.iLanguage = aLanguage;
       
   229     ref.iMode = aPluginMode,
       
   230     ref.iImePluginList = NULL;
       
   231     
       
   232     TInt index = iPluginList.FindInSignedKeyOrder(ref);
       
   233     if( index != KErrNotFound )
       
   234         {
       
   235         iPluginList[index].iImePluginList->GetImePlugins(aImplmentationIds);
       
   236         }
       
   237     }
       
   238     
       
   239 // ---------------------------------------------------------------------------
       
   240 // CImePluginFinder::FreeList
       
   241 // Free a list
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CImePluginFinder::FreeList(RArray<TImePluginLangAndMode>& aList)
       
   245     {
       
   246     for( TInt i = 0; i < aList.Count(); ++i )
       
   247         {
       
   248         delete aList[i].iImePluginList;
       
   249         }
       
   250     aList.Close();
       
   251     }
       
   252     
       
   253 // ---------------------------------------------------------------------------
       
   254 // CImePluginFinder::Reset
       
   255 // Reset all data and free memory
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CImePluginFinder::Reset()
       
   259     {
       
   260     FreeList( iPluginList );
       
   261     iAllImplementations.Close();
       
   262     iInitialized = EFalse;
       
   263     }
       
   264  
       
   265 // ---------------------------------------------------------------------------
       
   266 // CImePluginFinder::AddImplementationL
       
   267 // Add a implementation into internal data structure
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 void CImePluginFinder::AddImplementationL(const TInternalImePlguinImplDetail& aImplDetail)
       
   271     {
       
   272     //find language in list
       
   273     TImePluginLangAndMode ref;
       
   274     ref.iLanguage = aImplDetail.iLanguage;
       
   275     ref.iMode = aImplDetail.iMode;
       
   276     //ref.iImePluginList = NULL;
       
   277     
       
   278     TInt index = iPluginList.FindInSignedKeyOrder(ref);
       
   279     if( index != KErrNotFound )
       
   280         {
       
   281         iPluginList[index].iImePluginList->Insert(&aImplDetail);
       
   282         }
       
   283     else
       
   284         {
       
   285         ref.iImePluginList = new(ELeave) CImePluginList();
       
   286         ref.iImePluginList->Insert(&aImplDetail);
       
   287         iPluginList.InsertInSignedKeyOrder(ref);
       
   288         }
       
   289     }
       
   290 
       
   291 // ======== class CImePluginList========
       
   292 
       
   293 // ---------------------------------------------------------------------------
       
   294 // CImePluginList::CImePluginList
       
   295 // 
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 CImePluginList::CImePluginList()
       
   299     {
       
   300     }
       
   301     
       
   302 // ---------------------------------------------------------------------------
       
   303 // CImePluginList::~CImePluginList
       
   304 // Destructor
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 CImePluginList::~CImePluginList()
       
   308     {
       
   309     iPriList.Close();
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // CImePluginList::Insert
       
   314 // Insert a implementation in the list and keep priority order
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 void CImePluginList::Insert(const TInternalImePlguinImplDetail* aImplDetail)
       
   318     {
       
   319     //find position
       
   320     iPriList.InsertInOrder(aImplDetail, 
       
   321                            TLinearOrder<TInternalImePlguinImplDetail>(CompareImePlguin));
       
   322     }
       
   323     
       
   324 // ---------------------------------------------------------------------------
       
   325 // CImePluginList::GetImePlugins
       
   326 // Get Ime plugin list
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 void CImePluginList::GetImePlugins(RArray<TInt>& aImplmentationIds)
       
   330     {
       
   331     for(TInt i = 0; i < iPriList.Count(); ++i )
       
   332         {
       
   333         aImplmentationIds.Append(iPriList[i]->iImplementationId);
       
   334         }
       
   335     }
       
   336 
       
   337 // End of file
       
   338