webengine/widgetengine/inc/Preferences.h
changeset 0 dd21522fd290
child 13 10e98eab6f85
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 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 the License "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:  This class represents the Widget Preferences object
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef __WIDGETENGINEPREFERENCES
       
    19 #define __WIDGETENGINEPREFERENCES
       
    20 
       
    21 //  INCLUDES
       
    22 #include <e32base.h>
       
    23 
       
    24 // CONSTANTS
       
    25 
       
    26 // MACROS
       
    27 
       
    28 // DATA TYPES
       
    29 
       
    30 // FUNCTION PROTOTYPES
       
    31 
       
    32 // FORWARD DECLARATION
       
    33 
       
    34 // CLASS DECLARATION
       
    35 template <class K, class V> class RPtrHashMap;
       
    36 
       
    37 /**
       
    38 *  PrefElement
       
    39 *
       
    40 *  @lib widgetengine.dll
       
    41 *  @since 3.2
       
    42 */
       
    43 class PrefElement : public CBase
       
    44 {
       
    45 public :
       
    46     /**
       
    47     * Constructor.
       
    48     */
       
    49     PrefElement();
       
    50     
       
    51     /**
       
    52     * Destructor.
       
    53     */
       
    54     ~PrefElement();
       
    55     
       
    56     /**
       
    57     * setValueL
       
    58     * Set value for a preference
       
    59     * @param const TDesC& aValue - The value to be set
       
    60     * @return none
       
    61     */
       
    62     void setValueL( const TDesC& aValue );
       
    63     
       
    64     /**
       
    65     * setValueSize
       
    66     * Set length of value 
       
    67     * @param const TInt aSize - The length to be set
       
    68     * @return none
       
    69     */
       
    70     void setValueSize( const TInt aSize ) {
       
    71         m_valuesize = aSize;
       
    72     }
       
    73     
       
    74     /**
       
    75     * setCleanFileFlag
       
    76     * @param TBool aCleanFileFlag
       
    77     * @return none
       
    78     */
       
    79     void setCleanFileFlag( const TBool aCleanFileFlag ) {
       
    80         m_cleanFileFlag = aCleanFileFlag;
       
    81     }
       
    82 
       
    83     /**
       
    84     * GetValue
       
    85     * Get value for a preference
       
    86     * @param none
       
    87     * @return const TDesC& - value for the preference
       
    88     */      
       
    89     const TDesC& value() const {
       
    90         if ( m_value ) 
       
    91             return *m_value;
       
    92         else 
       
    93             return KNullDesC();
       
    94     }
       
    95         
       
    96     /**
       
    97     * GetValueSize
       
    98     * Get length of value
       
    99     * @param none
       
   100     * @return TInt - length of value for the preference
       
   101     */      
       
   102     TInt valueSize() const { return m_valuesize; }
       
   103         
       
   104 private :
       
   105     HBufC*  m_value;     // value of the preference: if size > MAX, it's the file name which stores the value
       
   106     TInt    m_valuesize; // length of the value
       
   107     TBool   m_cleanFileFlag;  // flag for deleteing individual preference dat file
       
   108 };
       
   109 
       
   110 
       
   111 /**
       
   112 *  WidgetPreferences
       
   113 *
       
   114 *  @lib widgetengine.dll
       
   115 *  @since 3.1
       
   116 */
       
   117 class WidgetPreferences
       
   118 {
       
   119 
       
   120 public:        
       
   121     WidgetPreferences();
       
   122     ~WidgetPreferences();
       
   123 
       
   124 public:
       
   125     /**
       
   126     * 
       
   127     */
       
   128     void setBasePathL(const TDesC& aValue);
       
   129 
       
   130     /**
       
   131     * 
       
   132     */
       
   133     void setWidgetId(TInt aValue);
       
   134 
       
   135     /**
       
   136     * 
       
   137     */
       
   138     void setWidgetBundleId(const TDesC& aValue);
       
   139     
       
   140     /**
       
   141     * 
       
   142     */
       
   143     TDesC& getWidgetBundleId();
       
   144 
       
   145     /**
       
   146     * Load preferences from persistent storage
       
   147     */
       
   148     void loadL();
       
   149     
       
   150     /**
       
   151     * Save preferences to persistent storage
       
   152     */
       
   153     void saveL();
       
   154     
       
   155     /**
       
   156     * Get preference for a particular key
       
   157     */
       
   158     TInt preferenceL( const TDesC& akey, TPtrC& avalue);
       
   159 
       
   160     
       
   161     /**
       
   162     * Set preference for a particular key
       
   163     */
       
   164     void setPreferenceL( const TDesC& akey, const TDesC& avalue);   
       
   165 
       
   166     /**
       
   167     * Remove preference for a particular key
       
   168     */
       
   169     void removePreferenceL( const TDesC& akey, const TDesC& avalue);   
       
   170     
       
   171 
       
   172 private:
       
   173     RPtrHashMap<TDesC,PrefElement>* m_preferences;                
       
   174     
       
   175     TInt   m_widgetid;
       
   176     HBufC* m_widgetbundleid;
       
   177     HBufC* m_basepath;
       
   178     HBufC* m_filepath;
       
   179 
       
   180 };
       
   181     
       
   182     
       
   183 #endif