javaextensions/pim/common/inc.s60/pimexternalchanges.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Native-originated external change data.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef PIMEXTERNALCHANGES_H
       
    20 #define PIMEXTERNALCHANGES_H
       
    21 
       
    22 /** @file
       
    23  * This file contains definitions and helper classes for passing external
       
    24  * changes from the adapters to the Framework.
       
    25  */
       
    26 
       
    27 #include <e32base.h>
       
    28 #include "pimcommon.h"
       
    29 #include "pimpanics.h"
       
    30 
       
    31 /**
       
    32  * External change types.
       
    33  */
       
    34 typedef enum
       
    35 {
       
    36     EPIMExternalChangeNew,
       
    37     EPIMExternalChangeModified,
       
    38     EPIMExternalChangeRemoved
       
    39 } TPIMExternalChangeType;
       
    40 
       
    41 /**
       
    42  * Simple class for passing external modifications to entries (items) in
       
    43  * a native database. The class encapsulates Item ID and type of change for
       
    44  * single item. Adapters produce these objects and Framework consumes them.
       
    45  */
       
    46 NONSHARABLE_CLASS(CPIMItemStateChange) : public CBase
       
    47 {
       
    48 public: // Constructors and destructor
       
    49 
       
    50     /**
       
    51      * Constructor.
       
    52      * Object data is explicitly set with this constructor. No default
       
    53      * constructor is provided.
       
    54      * @param aItemID ID of the item this change applies to. The ownership
       
    55      *        of the value is transferred to this class
       
    56      * @param aChangeType Type of change for the associated item.
       
    57      */
       
    58     CPIMItemStateChange(
       
    59         HBufC8* aItemID,
       
    60         TPIMExternalChangeType aChangeType)
       
    61             :
       
    62             iItemID(aItemID),
       
    63             iChangeType(aChangeType)
       
    64     {
       
    65         __ASSERT_DEBUG(iItemID || *iItemID != KPIMNullItemID,
       
    66         User::Panic(KPIMPanicCategory,
       
    67         EPIMPanicExternalChangeInit));
       
    68     }
       
    69 
       
    70     /**
       
    71      * Destructor.
       
    72      */
       
    73     ~CPIMItemStateChange()
       
    74     {
       
    75         delete iItemID;
       
    76     }
       
    77 
       
    78     /**
       
    79      * Provides ID of the changed item.
       
    80      * @return Item ID.
       
    81      */
       
    82     TPIMItemID ItemID() const
       
    83     {
       
    84         return *iItemID;
       
    85     }
       
    86 
       
    87     /**
       
    88      * Provides type of change for the associated item.
       
    89      * @return Change type.
       
    90      */
       
    91     TPIMExternalChangeType ChangeType() const
       
    92     {
       
    93         return iChangeType;
       
    94     }
       
    95 
       
    96 private: // Prohibited operations
       
    97 
       
    98     // Prohibit default constructor
       
    99     CPIMItemStateChange()
       
   100     {}
       
   101 
       
   102 private: // Data
       
   103 
       
   104     HBufC8* iItemID; // Owned
       
   105     TPIMExternalChangeType iChangeType;
       
   106 
       
   107 };
       
   108 
       
   109 /**
       
   110  * Simple class for passing external modifications to categories in
       
   111  * a native database. The class encapsulates category name and type of change
       
   112  * for single item. Adapters produce these objects and Framework consumes
       
   113  * them. \b Note that the object contains heap-allocated data.
       
   114  */
       
   115 NONSHARABLE_CLASS(CPIMCategoryStateChange) : public CBase
       
   116 {
       
   117 public:
       
   118 
       
   119     //@{
       
   120     /**
       
   121      * Constructors.
       
   122      * Object data is explicitly set with this constructor. No default
       
   123      * constructor is provided.
       
   124      * @param aCategory Name of the category this change applies to.
       
   125      *        The object takes the ownership of the argument. The
       
   126      *        argument must not be NULL; otherwise a panic is raised.
       
   127      * @param aNewCategory Name of the new category if \a aChangeType
       
   128      *        is EPIMExternalChangeModified, in which case it must not
       
   129      *        be NULL; otherwise it must be NULL.
       
   130      * @param aChangeType Type of change for the associated item.
       
   131      */
       
   132     CPIMCategoryStateChange(
       
   133         HBufC* aCategory,
       
   134         TPIMExternalChangeType aChangeType)
       
   135             :
       
   136             iCategory(aCategory),
       
   137             iChangeType(aChangeType)
       
   138             // iNewCategoryName is left NULL
       
   139 
       
   140     {
       
   141         __ASSERT_DEBUG(iCategory,
       
   142         User::Panic(KPIMPanicCategory,
       
   143         EPIMPanicExternalChangeInit));
       
   144     }
       
   145 
       
   146     CPIMCategoryStateChange(
       
   147         HBufC* aCategory,
       
   148         TPIMExternalChangeType aChangeType,
       
   149         HBufC* aNewCategoryName)
       
   150             :
       
   151             iCategory(aCategory),
       
   152             iChangeType(aChangeType),
       
   153             iNewCategoryName(aNewCategoryName)
       
   154     {
       
   155         __ASSERT_DEBUG(iCategory,
       
   156                        User::Panic(KPIMPanicCategory,
       
   157                                    EPIMPanicExternalChangeInit));
       
   158 
       
   159 #if _DEBUG
       
   160         if (aChangeType == EPIMExternalChangeModified)
       
   161         {
       
   162             __ASSERT_DEBUG(
       
   163                 iNewCategoryName,
       
   164                 User::Panic(KPIMPanicCategory,
       
   165                             EPIMPanicExternalChangeInit));
       
   166         }
       
   167         else
       
   168         {
       
   169             __ASSERT_DEBUG(
       
   170                 !iNewCategoryName,
       
   171                 User::Panic(KPIMPanicCategory,
       
   172                             EPIMPanicExternalChangeInit));
       
   173         }
       
   174 #endif // _DEBUG
       
   175     }
       
   176     //@}
       
   177 
       
   178     /**
       
   179      * Destructor. Deletes the owned category name and new name
       
   180      * of that category, if present.
       
   181      */
       
   182     ~CPIMCategoryStateChange()
       
   183     {
       
   184         delete iCategory;
       
   185         delete iNewCategoryName;
       
   186     }
       
   187 
       
   188     /**
       
   189      * Provides name of the changed category.
       
   190      * @return Category name.
       
   191      */
       
   192     const TDesC& Category() const
       
   193     {
       
   194         return *iCategory;
       
   195     }
       
   196 
       
   197     /**
       
   198      * Provides the new name of a renamed category.
       
   199      *
       
   200      * @return New name of a renamed category if change type is
       
   201      *         EPIMExternalChangeModified.
       
   202      *
       
   203      * @par Leaving:
       
   204      * @li \c KErrGeneral - Change type is not
       
   205      *     EPIMExternalChangeModified.
       
   206      */
       
   207     const TDesC& NewCategoryNameL() const
       
   208     {
       
   209         if (!iNewCategoryName)
       
   210         {
       
   211             User::Leave(KErrGeneral);
       
   212         }
       
   213 
       
   214         return *iNewCategoryName;
       
   215     }
       
   216 
       
   217     /**
       
   218      * Provides type of change for the associated item.
       
   219      * @return Change type.
       
   220      */
       
   221     TPIMExternalChangeType ChangeType() const
       
   222     {
       
   223         return iChangeType;
       
   224     }
       
   225 
       
   226 private: // Prohibited operations
       
   227 
       
   228     // Prohibit default constructor
       
   229     CPIMCategoryStateChange()
       
   230     {}
       
   231 
       
   232 private: // Data
       
   233     HBufC* iCategory; // owned
       
   234     TPIMExternalChangeType iChangeType;
       
   235     HBufC* iNewCategoryName; // owned
       
   236 };
       
   237 
       
   238 #endif // PIMEXTERNALCHANGES_H
       
   239 // End of File