userdict/inc/UdictModel.h
changeset 0 9a3a17bfeb67
equal deleted inserted replaced
-1:000000000000 0:9a3a17bfeb67
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:     The engine class of Japanese user dictionary.
       
    15 *                It wraps PtiEngine to access the User dictionary.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #ifndef UDICTMODEL_H
       
    25 #define UDICTMODEL_H
       
    26 
       
    27 //  INCLUDES
       
    28 #include    "UdictElement.h"
       
    29 #include    <badesca.h>
       
    30 
       
    31 // DATA TYPES
       
    32 typedef CArrayFixFlat<TUDictElement> CUserDictList;
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class CPtiEngine;
       
    36 class MPtiUserDictionary;
       
    37 
       
    38 // CLASS DECLARATION
       
    39 
       
    40 /**
       
    41 *  The engine of Japanese user dictionary.
       
    42 *  The main role of this class is accessing the User dictionary data via
       
    43 *  CPtiEngeine.
       
    44 *  @since 2.6
       
    45 */
       
    46 class CUserDictModel : public CBase, public MDesCArray
       
    47     {   
       
    48     public:  // Constructors and destructor
       
    49         
       
    50         /**
       
    51         * Two-phased constructor.
       
    52         */
       
    53         static CUserDictModel* NewL();
       
    54 
       
    55         /**
       
    56         * Destructor.
       
    57         */
       
    58         ~CUserDictModel();
       
    59 
       
    60     public: // New functions
       
    61         
       
    62         /**
       
    63         * Returns the self object as interface to access the registered
       
    64         * word list.
       
    65         * @return a pointer of the interface of the registered word list.
       
    66         */
       
    67         inline MDesCArray* List();
       
    68         
       
    69         /**
       
    70         * Gets an element of the registered word list.
       
    71         * @param aIndex is the position of the element.
       
    72         * @return a reference to an element of the registered word list,
       
    73         *         located at aIndex.
       
    74         */
       
    75         inline const TUDictElement& ListItem(TInt aIndex) const;
       
    76 
       
    77         /**
       
    78         * Tests if the User dictionary data is changed by another application.
       
    79         * @return ETrue, if the User dictionary data is changed.
       
    80         */
       
    81         inline TBool IsChangedByAnotherApp() const;
       
    82         
       
    83         /**
       
    84         * Sets the flag which notifies the User dictionary is changed by
       
    85         * another application.
       
    86         * @param aFlag is set to the of User dictionary update flag. 
       
    87         */
       
    88         inline void SetChangeNotice(TBool aFlag);
       
    89 
       
    90         /**
       
    91         * Tests if the user dictionary has enough space to add word or not.
       
    92         * @return ETrue, the user dictionary has no space to register.
       
    93         */
       
    94         inline TBool IsDictionaryFull();
       
    95 
       
    96         /**
       
    97         * Reload User dictionary data to reflect the changes by another
       
    98         * application.
       
    99         */
       
   100         inline void ReloadDictInfoL();
       
   101         
       
   102         /**
       
   103         * Stops the file storing in registering and deleting until SaveNow()
       
   104         * is called.
       
   105         */
       
   106         inline void DelaySavingL();
       
   107 
       
   108         /**
       
   109         * Stores cahges of the dictionary data to the file.
       
   110         */
       
   111         inline void SaveNowL();
       
   112 
       
   113         /**
       
   114         * Adds a new word to the User dictionary.
       
   115         * This function might leave. It leaves with KErrAlreadyExists if the 
       
   116         * word is already registered, KErrDiskFull if the dictionary has no
       
   117         * space to register.
       
   118         *
       
   119         * @param aItem is added to the User dictionary
       
   120         * @return index of a new word inserted to the registered word list. 
       
   121         */
       
   122         TInt AddNewWordL(const TUDictElement& aItem);
       
   123 
       
   124         /**
       
   125         * Deletes the word from the User dictionary.
       
   126         * @param aIndex is the position of the deleted item in the word list.
       
   127         */
       
   128         void DeleteWordL(TInt aIndex);
       
   129         
       
   130         /**
       
   131         * Modifies the registered word of User dictionary.
       
   132         * If modifying the word is failed, it leaves.
       
   133         *
       
   134         * @param aIndex is the position of the modified word
       
   135         * @param aItem is a modified entry 
       
   136         * @return index of a modified word relocated in the registered
       
   137         *         word list.
       
   138         */
       
   139         TInt ModifyWordL(TInt aIndex, const TUDictElement& aItem);
       
   140 
       
   141         /**
       
   142         * Initializes the registered word list.
       
   143         * It copies the User dictionary data to iItemList, which is the 
       
   144         * registered word list and sorts the list by Unicode collation
       
   145         * algorithm.
       
   146         */
       
   147         void InitListL();
       
   148 
       
   149     private:
       
   150 
       
   151         /**
       
   152         * C++ default constructor.
       
   153         */
       
   154         CUserDictModel();
       
   155 
       
   156         /**
       
   157         * By default Symbian 2nd phase constructor is private.
       
   158         */
       
   159         void ConstructL();
       
   160         
       
   161     private:  // Functions from base classes
       
   162                 
       
   163         /**
       
   164         * From MDesCArray, returns a number of elements in the array.
       
   165         * @return a number of elements in the registered word list. 
       
   166         */
       
   167         TInt MdcaCount() const;
       
   168         
       
   169         /**
       
   170         * From MDesCArray,
       
   171         * Retruns a descriptor for the ListBox's item.
       
   172         * @param aIndex is a position of the registered word list.
       
   173         * @return a descriptor for the ListBox's item representing the element
       
   174         *         located at aIndex within the word list.
       
   175         */
       
   176         TPtrC16 MdcaPoint(TInt aIndex) const;
       
   177 
       
   178     private:    // Data
       
   179 
       
   180         // The array of registered words.
       
   181         // The original User dictionary data is copied to this array.
       
   182         CUserDictList* iItemList; // own
       
   183 
       
   184         // The predictive text input engine.
       
   185         // It provides the API to access the User dictionary data.
       
   186         CPtiEngine* iPtiEngine; // own
       
   187 
       
   188         // PtiEngine's user dictionary interface.
       
   189         MPtiUserDictionary* iDictionary ;
       
   190 
       
   191     private:
       
   192     
       
   193         class TWordListKey : public TKeyArrayFix
       
   194             {
       
   195             public:  // Constructor
       
   196 
       
   197                 /**
       
   198                 * C++ default constructor.
       
   199                 */
       
   200                 TWordListKey();
       
   201 
       
   202             private:  // Functions from base classes
       
   203 
       
   204                 /**
       
   205                 * From TKey, Compares the keys of two elements.
       
   206                 * @param aLeft is the index of the Left element
       
   207                 * @param aRight is the index of the Right element
       
   208                 * @return zero, if both elements are identical.
       
   209                 *         positive, if the left element is greater.
       
   210                 *         negative, if the right element is greater.
       
   211                 */            
       
   212                 TInt Compare(TInt aLeft, TInt aRight) const;
       
   213             };
       
   214     };
       
   215 
       
   216 #endif      // UDICTMODEL_H
       
   217             
       
   218 // End of File