javaextensions/pim/framework/src.s60/cpimtodoitem.cpp
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:  PIM ToDo item specialization.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // CLASS HEADER
       
    20 #include  "cpimtodoitem.h"
       
    21 
       
    22 // INTERNAL INCLUDES
       
    23 #include "cpimitemdata.h"
       
    24 #include "pimtodo.h"
       
    25 #include "mpimadaptermanager.h"
       
    26 #include "cpimtodovalidator.h"
       
    27 #include "cpimmanager.h"
       
    28 #include "pimpanics.h"
       
    29 #include "logger.h"
       
    30 
       
    31 // FORWARD DECLARATIONS
       
    32 class MPIMToDoAdapterManager;
       
    33 class MPIMToDoListAdapter;
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // C++ constructor
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CPIMToDoItem::CPIMToDoItem(const CPIMToDoValidator& aValidator) :
       
    40         CPIMItem(aValidator)
       
    41 {
       
    42     JELOG2(EPim);
       
    43 }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CPIMToDoItem::NewL
       
    47 // Two-phase constructor
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CPIMToDoItem* CPIMToDoItem::NewL(const CPIMToDoValidator& aValidator)
       
    51 {
       
    52     JELOG2(EPim);
       
    53     CPIMToDoItem* self = NewLC(aValidator);
       
    54     CleanupStack::Pop(self);
       
    55     return self;
       
    56 }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CPIMToDoItem::NewLC
       
    60 // Two-phase constructor. Leaves item to the cleanup stack
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CPIMToDoItem* CPIMToDoItem::NewLC(const CPIMToDoValidator& aValidator)
       
    64 {
       
    65     JELOG2(EPim);
       
    66     CPIMToDoItem* self = new(ELeave) CPIMToDoItem(aValidator);
       
    67     CleanupStack::PushL(self);
       
    68     self->ConstructL();
       
    69     return self;
       
    70 }
       
    71 
       
    72 pimbaseitem* pimbaseitem::getToDoItemInstance(pimbasemanager* aPimManager)
       
    73 {
       
    74     JELOG2(EPim);
       
    75     CPIMManager* pimManager = reinterpret_cast<CPIMManager*>(aPimManager);
       
    76     CPIMToDoItem* todoItem = NULL;
       
    77     TInt error = 0;
       
    78     TRAP(error,
       
    79     {
       
    80         const CPIMToDoValidator& todoValidator = pimManager->ToDoValidator();
       
    81         todoItem = CPIMToDoItem::NewL(todoValidator);
       
    82     }
       
    83         );
       
    84     if (error != KErrNone)
       
    85         throw KErrGeneral;
       
    86     return todoItem;
       
    87 }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // Destructor
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CPIMToDoItem::~CPIMToDoItem()
       
    94 {
       
    95     JELOG2(EPim);
       
    96 }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CPIMToDoItem::SetToDoAdapterAssociation
       
   100 // (other items were commented in a header)
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CPIMToDoItem::SetToDoAdapterAssociation(
       
   104     MPIMToDoAdapterManager* aToDoAdapterManager,
       
   105     MPIMToDoListAdapter* aToDoListAdapter)
       
   106 {
       
   107     JELOG2(EPim);
       
   108     __ASSERT_DEBUG(aToDoAdapterManager, User::Panic(KPIMPanicCategory,
       
   109                    EPIMPanicNullArgument));
       
   110 
       
   111     iToDoAdapterManager = aToDoAdapterManager;
       
   112     iToDoListAdapter = aToDoListAdapter;
       
   113 
       
   114     SetBaseAdapterAssociation(iToDoAdapterManager->GetAdapterManager(),
       
   115                               iToDoListAdapter ? iToDoListAdapter->GetPimListAdapter() : NULL);
       
   116 }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CPIMToDoItem::RemoveAdapterAssociation
       
   120 // (other items were commented in a header)
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CPIMToDoItem::RemoveAdapterAssociation()
       
   124 {
       
   125     JELOG2(EPim);
       
   126     iToDoAdapterManager = NULL;
       
   127     iToDoListAdapter = NULL;
       
   128 
       
   129     CPIMItem::RemoveAdapterAssociation();
       
   130 }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CPIMToDoItem::ItemType
       
   134 // (other items were commented in a header)
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 TPIMListType CPIMToDoItem::ItemType() const
       
   138 {
       
   139     JELOG2(EPim);
       
   140     return EPIMToDoList;
       
   141 }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CPIMToDoItem::commit
       
   145 // (other items were commented in a header)
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CPIMToDoItem::commit()
       
   149 {
       
   150     JELOG2(EPim);
       
   151     TInt error = KErrNone;
       
   152     TRAP(error,
       
   153     {
       
   154         if (iToDoAdapterManager)
       
   155         {
       
   156             // The item is associated with a list
       
   157             if (iToDoListAdapter)
       
   158             {
       
   159                 // The list is open
       
   160                 if (iItemID->Compare(KPIMNullItemID) == 0)
       
   161                 {
       
   162                     // The item does not have database entry
       
   163                     iToDoListAdapter->CreateToDoItemL(*this);
       
   164                 }
       
   165                 else
       
   166                 {
       
   167                     iToDoListAdapter->WriteToDoItemL(*this);
       
   168                 }
       
   169 
       
   170                 SetModified(EFalse);
       
   171                 UpdateUidFieldL(EPIMToDoUid, iItemID->Des());
       
   172                 UpdateRevisionFieldL(EPIMToDoRevision, LastModified());
       
   173             }
       
   174             else
       
   175             {
       
   176                 // The associated list is closed
       
   177                 User::Leave(KErrDisconnected);   // codescanner::leave
       
   178             }
       
   179         }
       
   180         else
       
   181         {
       
   182             // The item is not associated with a list
       
   183             User::Leave(KErrDisMounted);   // codescanner::leave
       
   184         }
       
   185     }
       
   186         );
       
   187     if (error != KErrNone)
       
   188         throw error;
       
   189 }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // CPIMToDoItem::ListClosed
       
   193 // (other items were commented in a header)
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CPIMToDoItem::ListClosed()
       
   197 {
       
   198     JELOG2(EPim);
       
   199     iToDoListAdapter = NULL;
       
   200     CPIMItem::ListClosed();
       
   201 }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CPIMToDoItem::SetToDoItemIdL
       
   205 // (other items were commented in a header)
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CPIMToDoItem::SetToDoItemIdL(const TPIMItemID& aToDoItemId)
       
   209 {
       
   210     JELOG2(EPim);
       
   211     // Remove old one
       
   212     CPIMItem::SetIdL(aToDoItemId);
       
   213 
       
   214     // Update UID field if it is supported
       
   215     if (iAdapterManager && iAdapterManager->IsSupportedField(
       
   216                 EPIMToDoUid))
       
   217     {
       
   218         UpdateUidFieldL(EPIMToDoUid, aToDoItemId);
       
   219     }
       
   220 }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CPIMToDoItem::ToDoItemId
       
   224 // (other items were commented in a header)
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 const TPIMItemID CPIMToDoItem::ToDoItemId() const
       
   228 {
       
   229     JELOG2(EPim);
       
   230     if (!iItemID)
       
   231     {
       
   232         return KPIMNullItemID();
       
   233     }
       
   234     return iItemID->Des();
       
   235 }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CPIMToDoItem::SetLastModifiedL
       
   239 // (other items were commented in a header)
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 void CPIMToDoItem::SetLastModifiedL(TPIMDate aLastModified)
       
   243 {
       
   244     JELOG2(EPim);
       
   245     CPIMItem::SetLastModifiedL(aLastModified);
       
   246     if (iAdapterManager)
       
   247     {
       
   248         UpdateRevisionFieldL(EPIMToDoRevision, LastModified());
       
   249     }
       
   250 }
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // CPIMToDoItem::PrepareForLoadL
       
   254 // (other items were commented in a header)
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257 void CPIMToDoItem::PrepareForLoadL()
       
   258 {
       
   259     JELOG2(EPim);
       
   260     // Prepare base class for loading from the database
       
   261     CPIMItem::PrepareForLoadL();
       
   262 }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // CPIMToDoItem::IsReadOnly
       
   266 // (other items were commented in a header)
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 TBool CPIMToDoItem::IsReadOnly(const TPIMField& aField)
       
   270 {
       
   271     JELOG2(EPim);
       
   272     TBool retVal = EFalse;
       
   273 
       
   274     if (aField == EPIMToDoUid || aField == EPIMToDoRevision)
       
   275     {
       
   276         retVal = (iItemID->Compare(KPIMNullItemID) != 0);
       
   277     }
       
   278 
       
   279     return retVal;
       
   280 }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // CPIMToDoItem::AddIntL
       
   284 // (other items were commented in a header)
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CPIMToDoItem::AddIntL(TPIMField aField, TPIMAttribute aAttributes,
       
   288                            TInt aValue)
       
   289 {
       
   290     JELOG2(EPim);
       
   291     if (aField == EPIMToDoPriority)
       
   292     {
       
   293         aValue = SimplifyPriority(aValue);
       
   294     }
       
   295     // else not the priority field; not interested
       
   296     CPIMItem::addInt(aField, aAttributes, aValue);
       
   297 }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CPIMToDoItem::SetIntL
       
   301 // (other items were commented in a header)
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CPIMToDoItem::SetIntL(TPIMField aField, TInt aIndex,
       
   305                            TPIMAttribute aAttributes, TInt aValue)
       
   306 {
       
   307     JELOG2(EPim);
       
   308     if (aField == EPIMToDoPriority)
       
   309     {
       
   310         aValue = SimplifyPriority(aValue);
       
   311     }
       
   312     // else not the priority field; not interested
       
   313     CPIMItem::setInt(aField, aIndex, aAttributes, aValue);
       
   314 }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CPIMToDoItem::SimplifyPriority
       
   318 // (other items were commented in a header)
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 TInt CPIMToDoItem::SimplifyPriority(TInt aPriority)
       
   322 {
       
   323     JELOG2(EPim);
       
   324     // Note: the lower the value, the higher the priority.
       
   325     TInt retVal = aPriority;
       
   326 
       
   327     if (aPriority == EPIMToDoPriorityMinValue) // 0
       
   328     {
       
   329         retVal = EPIMToDoPriorityMedium; // the default
       
   330     }
       
   331     else if ((EPIMToDoPriorityHigh <= aPriority) && (aPriority
       
   332              < EPIMToDoPriorityMedium))
       
   333     {
       
   334         retVal = EPIMToDoPriorityHigh;
       
   335     }
       
   336     else if ((EPIMToDoPriorityMedium <= aPriority) && (aPriority
       
   337              < EPIMToDoPriorityLow))
       
   338     {
       
   339         retVal = EPIMToDoPriorityMedium;
       
   340     }
       
   341     else if ((EPIMToDoPriorityLow <= aPriority) && (aPriority
       
   342              <= EPIMToDoPriorityMaxValue))
       
   343     {
       
   344         retVal = EPIMToDoPriorityLow;
       
   345     }
       
   346 
       
   347     // else don't touch it
       
   348     return retVal;
       
   349 }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CPIMToDoItem::GetItemData
       
   353 // (other items were commented in a header)
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 MPIMItemData& CPIMToDoItem::ItemData()
       
   357 {
       
   358     JELOG2(EPim);
       
   359     return *iItemData;
       
   360 }
       
   361 
       
   362 // ---------------------------------------------------------------------------
       
   363 // CPIMToDoItem::GetItemData
       
   364 // (other items were commented in a header)
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 const MPIMItemData& CPIMToDoItem::ItemData() const
       
   368 {
       
   369     return *iItemData;
       
   370 }
       
   371 
       
   372 int CPIMToDoItem::getPreferredIndex(TPIMField /*aField*/) const
       
   373 {
       
   374     // shouldnt reach this code
       
   375     return KErrGeneral;
       
   376 }
       
   377 
       
   378 //  End of File