browserutilities/favouritesengine/ClientServer/inc/FavouritesItemImpl.h
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 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 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: 
       
    15 *      Declaration of class CFavouritesItemImpl.
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef FAVOURITES_ITEM_IMPL_H
       
    22 #define FAVOURITES_ITEM_IMPL_H
       
    23 
       
    24 //  INCLUDES
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <s32strm.h>
       
    28 #include <FavouritesItem.h>
       
    29 #include <FavouritesLimits.h>
       
    30 #include <FavouritesWapAp.h>
       
    31 
       
    32 // CLASS DECLARATION
       
    33 
       
    34 /**
       
    35 * Implementation class behind proxy CFavouritesItem.
       
    36 */
       
    37 NONSHARABLE_CLASS(CFavouritesItemImpl): public CBase
       
    38     {
       
    39 
       
    40     public:     // Constructors and destructor
       
    41         
       
    42         /**
       
    43         * Two-phased constructor. Leaves on failure.
       
    44         * @return The constructed item.
       
    45         */
       
    46         static CFavouritesItemImpl* NewL();
       
    47 
       
    48         /**
       
    49         * Two-phased constructor. Leaves on failure.
       
    50         * @return The constructed item.
       
    51         */
       
    52         static CFavouritesItemImpl* NewLC();
       
    53 
       
    54         /**
       
    55         * Destructor.
       
    56         */
       
    57         virtual ~CFavouritesItemImpl();
       
    58 
       
    59         /**
       
    60         * Assignment operator.
       
    61         * @param aCopyFrom Assign from this.
       
    62         */
       
    63         CFavouritesItemImpl& operator=( const CFavouritesItemImpl& aCopyFrom );
       
    64 
       
    65     protected:      // Constructors
       
    66         
       
    67         /**
       
    68         * C++ constructor.
       
    69         */
       
    70         inline CFavouritesItemImpl();
       
    71 
       
    72         /**
       
    73         * Second-phase constructor.
       
    74         */
       
    75         void ConstructL();
       
    76 
       
    77     public:     // Query
       
    78 
       
    79         /**
       
    80         * Get unique id of the item.
       
    81         * @return The unique id.
       
    82         */
       
    83         inline TInt Uid() const;
       
    84 
       
    85         /**
       
    86         * Get the uid of the parent folder of this item.
       
    87         * @return The unique id of the parent folder.
       
    88         */
       
    89         inline TInt ParentFolder() const;
       
    90 
       
    91         /**
       
    92         * Get type of the item (item or folder).
       
    93         * @return The type of the item. It is either EFolder or EItem
       
    94         * (never ENone).
       
    95         */
       
    96         inline CFavouritesItem::TType Type() const;
       
    97 
       
    98         /**
       
    99         * Get the name of this item.
       
   100         * @return The name of this item.
       
   101         */
       
   102         inline const TDesC& Name() const;
       
   103 
       
   104         /**
       
   105         * Get the URL of this item.
       
   106         * @return The URL of this item.
       
   107         */
       
   108         inline const TDesC& Url() const;
       
   109 
       
   110         /**
       
   111         * Get WAP Access Point id associated with this item.
       
   112         * @return The WAP Access Point id.
       
   113         */
       
   114         inline TFavouritesWapAp WapAp() const;
       
   115 
       
   116         /**
       
   117         * Get the username associated with this item.
       
   118         * @return The username.
       
   119         */
       
   120         inline const TDesC& UserName() const;
       
   121 
       
   122         /**
       
   123         * Get password associated with this item.
       
   124         * @return The password.
       
   125         */
       
   126         inline const TDesC& Password() const;
       
   127 
       
   128         /**
       
   129         * Get context id associated with this item.
       
   130         * @return The context id.
       
   131         */
       
   132         inline TInt32 ContextId() const;
       
   133 
       
   134         /**
       
   135         * Check if this is an item (not folder).
       
   136         * @return ETrue if this is an item.
       
   137         */
       
   138         inline TBool IsItem() const;
       
   139 
       
   140         /**
       
   141         * Check if this is a folder.
       
   142         * @return ETrue if this is a folder.
       
   143         */
       
   144         inline TBool IsFolder() const;
       
   145 
       
   146         /**
       
   147         * Check if this is a factory item.
       
   148         * @return ETrue if this is a factory item.
       
   149         */
       
   150         inline TBool IsFactoryItem() const;
       
   151 
       
   152         /**
       
   153         * Check if this is a read-only in database. Note that ETrue value does
       
   154         * not prevent modifying this CFavouritesItemImpl object.
       
   155         * @return ETrue if this is read-only in database.
       
   156         */
       
   157         inline TBool IsReadOnly() const;
       
   158 
       
   159         /**
       
   160         * Get last modification time (of database entry), universal time.
       
   161         * This can be zero if:
       
   162         * - Last modification time is not available in database (old
       
   163         *   databases); or
       
   164         * - Engine does not support this feature.
       
   165         * Note that zero means Modified().Int64() == 0, and not
       
   166         * Time::NullTTime().
       
   167         */
       
   168         inline TTime Modified() const;
       
   169 
       
   170         /**
       
   171         * Check if this is hidden.
       
   172         * @return ETrue if this is hidden.
       
   173         */
       
   174         inline TBool IsHidden() const;
       
   175         
       
   176     public:     // update
       
   177 
       
   178         /**
       
   179         * Set parent folder.
       
   180         * @param aId The unique id of the parent folder.
       
   181         */
       
   182         inline void SetParentFolder( TInt aId );
       
   183 
       
   184         /**
       
   185         * Set item type (item or folder).
       
   186         * @param aType The type to be set. ENone cannot be set (if that is
       
   187         * specified, it is ignored).
       
   188         */
       
   189         inline void SetType( CFavouritesItem::TType aType );
       
   190 
       
   191         /**
       
   192         * Set name of the item. Leading or trailing whitespace is trimmed.
       
   193         * Length limit is KFavouritesMaxName (leaves with KErrOverflow).
       
   194         * @param aName The name to be set.
       
   195         */
       
   196         void SetNameL( const TDesC& aName );
       
   197 
       
   198         /**
       
   199         * Set URL of the item.
       
   200         * Length limit is KFavouritesMaxURL (leaves with KErrOverflow).
       
   201         * @param aUrl The URL to be set.
       
   202         */
       
   203         inline void SetUrlL( const TDesC& aUrl );
       
   204 
       
   205         /**
       
   206         * Set WAP Access Point of the item.
       
   207         * @param aAccessPoint The WAP Access point to be set.
       
   208         */
       
   209         inline void SetWapAp( const TFavouritesWapAp& aAccessPoint );
       
   210 
       
   211         /**
       
   212         * Set username of the item.
       
   213         * Length limit is KFavouritesMaxUserName (leaves with KErrOverflow).
       
   214         * @param aUserName The username to be set.
       
   215         */
       
   216         inline void SetUserNameL( const TDesC& aUserName );
       
   217 
       
   218         /**
       
   219         * Set password.
       
   220         * Length limit is KFavouritesMaxPassword (leaves with KErrOverflow).
       
   221         * @param aPassword The password to be set.
       
   222         */
       
   223         inline void SetPasswordL( const TDesC& aPassword );
       
   224 
       
   225         /**
       
   226         * Set context id of the item.
       
   227         * @param aContextId The context id to be set.
       
   228         */
       
   229         inline void SetContextId( TInt32 aContextId );
       
   230         
       
   231         /**
       
   232         * Set hidden value of the item.
       
   233         * @param aHidden The hidden value to be set.
       
   234         */
       
   235         inline void SetHidden( TBool aHidden );
       
   236 
       
   237     public:     // Streaming
       
   238 
       
   239         /**
       
   240         * Externalize into a stream.
       
   241         * @param aStream The stream to externalize to.
       
   242         */
       
   243         void ExternalizeL( RWriteStream& aStream ) const;
       
   244 
       
   245         /**
       
   246         * Internalize from a stream.
       
   247         * @param aStream The stream to externalize from.
       
   248         */
       
   249         void InternalizeL( RReadStream& aStream );
       
   250 
       
   251         /**
       
   252         * Externalize update-delta into a stream.
       
   253         * This is a performance oprtimization to reduce data transfer between
       
   254         * client and server. When database is updated (using an item), only
       
   255         * the changed data is synced back to the item (name, uid,
       
   256         * last-mod-time).
       
   257         * @param aStream The stream to externalize to.
       
   258         */
       
   259         void ExternalizeUpdateDeltaL( RWriteStream& aStream ) const;
       
   260 
       
   261         /**
       
   262         * Internalize update-delta from a stream.
       
   263         * This is a performance oprtimization to reduce data transfer between
       
   264         * client and server. When database is updated (using an item), only
       
   265         * the changed data is synced back to the item (name, uid,
       
   266         * last-mod-time).
       
   267         * @param aStream The stream to externalize from.
       
   268         */
       
   269         void InternalizeUpdateDeltaL( RReadStream& aStream );
       
   270 
       
   271     private:    // Streaming utils
       
   272 
       
   273         /**
       
   274         * Externalize descriptor member to a stream.
       
   275         * @param aBuf Buffer.
       
   276         * @param aStream The stream to externalize to.
       
   277         */
       
   278         void BufToStreamL( const TDesC& aBuf, RWriteStream& aStream ) const;
       
   279 
       
   280         /**
       
   281         * Internalize HBufC* member from a stream.
       
   282         * @param aBuf Buffer.
       
   283         * @param aStream The stream to internalize from.
       
   284         */
       
   285         void BufFromStreamL( HBufC*& aBuf, RReadStream& aStream );
       
   286 
       
   287     private:
       
   288 
       
   289         /**
       
   290         * Set buffer from string. Leaves for exceeding aMaxLength.
       
   291         * @param aBuf Buffer.
       
   292         * @param aDesc Descriptor to set from.
       
   293         * @param aMaxLength Max length.
       
   294         */
       
   295         void SetBufL( HBufC*& aBuf, const TDesC& aDesc, TInt aMaxLength );
       
   296 
       
   297         /**
       
   298         * Set unique id of the item.
       
   299         * @param aUid The unique id to be set.
       
   300         */
       
   301         inline void SetUid( TInt aUid );
       
   302 
       
   303         /**
       
   304         * Set factory item flag of the item.
       
   305         * @param aFactoryItem The factory item flag to be set.
       
   306         */
       
   307         inline void SetFactoryItem( TBool aFactoryItem );
       
   308 
       
   309         /**
       
   310         * Set read-only flag of the item.
       
   311         * @param aReadOnly The read-only flag to be set.
       
   312         */
       
   313         inline void SetReadOnly( TBool aReadOnly );
       
   314 
       
   315         /**
       
   316         * Set last modification time of the item.
       
   317         * @param aReadOnly The last modification time to be set.
       
   318         */
       
   319         inline void SetModified( TTime aModified );
       
   320 
       
   321         /**
       
   322         * Validate the item.
       
   323         * - For all kinds: valid name required.
       
   324         * - For items: URL must be present.
       
   325         * - For folders: URL, Username, Password must be empty;
       
   326         *                WAP Access Point must not be specified.
       
   327         * @return ETrue if the item matches the above criteria.
       
   328         */
       
   329         TBool IsValid() const;
       
   330 
       
   331         /**
       
   332         * Create a bookmark name from a string.
       
   333         * Leading / trailing whitespace is removed. Note that the resulting
       
   334         * name may be zero length (if aSource is made up from whitespace only).
       
   335         * In this case the return value is KErrNone, though the name is not
       
   336         * valid.
       
   337         * @param aSource The string to create name from.
       
   338         * @param aTarget Resulting name is placed here. Previous content is
       
   339         * overwritten. Must be large enough to hold the result;
       
   340         * the result's length equals to or less than aSource length (i.e.
       
   341         * aSource.Length() is enough for aTarget).
       
   342         * @return
       
   343         * - KErrOverflow if name was trimmed (because it was too long);
       
   344         * - KErrNone otherwise.
       
   345         */
       
   346         static TInt MakeName( const TDesC& aSource, TDes& aTarget );
       
   347 
       
   348         /**
       
   349         * Check if aName is a valid bookmark name.
       
   350         * @return aName Name to check. Not expecting trailing/leading
       
   351         * whitespace or whitespace other than spaces (i.e. should be a name
       
   352         * that comes from MakeName()).
       
   353         * @return ETrue if the name is valid.
       
   354         */
       
   355         static TBool IsValidName( const TDesC& aName );
       
   356 
       
   357     private:    // Data
       
   358 
       
   359         TInt iUid;                      ///< Uid of the item.
       
   360         TInt iParentFolder;             ///< Uid of the parent folder.
       
   361         CFavouritesItem::TType iType;   ///< Type (EFolder or EItem).
       
   362         HBufC* iName;                   ///< Name, owned. Never NULL.
       
   363         HBufC* iUrl;                    ///< URL, owned. Never NULL.
       
   364         TFavouritesWapAp iWapAp;        ///< WAP Access Point.
       
   365         HBufC* iUserName;               ///< Username, owned. Never NULL.
       
   366         HBufC* iPassword;               ///< Password, owned. Never NULL.
       
   367         TBool iReadOnly;                ///< Read-only flag.
       
   368         TBool iFactoryItem;             ///< Factory item flag.
       
   369         TInt32 iContextId;              ///< Context id.
       
   370         TTime iModified;                ///< Last modification time.
       
   371         TBool iHidden;                  ///< hidden flag.
       
   372 
       
   373     private:    // Friend classes
       
   374 
       
   375         friend class RFavouritesDb;
       
   376         friend class CFavouritesSrvDb;
       
   377         friend class RFavouritesSrvTable;
       
   378         friend class CFavouritesItem;
       
   379 
       
   380     };
       
   381 
       
   382 #endif
       
   383 
       
   384 #include "FavouritesItemImpl.inl"
       
   385 
       
   386 // End of File