calendarui/views/src/calentodocontroller.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002 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:  To-Do view's utility class.
       
    15 *
       
    16 */
       
    17 
       
    18 //debug
       
    19 #include "calendarui_debug.h"
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "calentodocontroller.h"
       
    23 
       
    24 #include <calenagendautils.h>
       
    25 #include <calendateutils.h>
       
    26 #include "calentodocontainer.h"
       
    27 
       
    28 #include <calenservices.h>
       
    29 #include "calennativeview.h"
       
    30 
       
    31 #include <sysutil.h>
       
    32 #include <ErrorUI.h>
       
    33 
       
    34 #include <calinstance.h>
       
    35 #include <calinstanceview.h>
       
    36 #include <calentry.h>
       
    37 #include <calentryview.h>
       
    38 #include <calrrule.h>
       
    39 #include <caltime.h>
       
    40 #include <calcommon.h>
       
    41 #include <eikenv.h>
       
    42 #include <caleninstanceid.h>            // TCalenInstanceId
       
    43 #include <calenviewutils.h>
       
    44 
       
    45 // ================= MEMBER FUNCTIONS =======================
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // CCalenTodoController::CCalenTodoController
       
    49 // C++ default constructor.
       
    50 // (other items were commented in a header).
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 CCalenTodoController::CCalenTodoController( 
       
    54         MCalenServices& aServices )
       
    55     : iServices( aServices )
       
    56     {
       
    57     TRACE_ENTRY_POINT;
       
    58     TRACE_EXIT_POINT;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CCalenTodoController::ConstructL
       
    63 // Symbian OS default constructor.
       
    64 // (other items were commented in a header).
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 void CCalenTodoController::ConstructL()
       
    68     {
       
    69     TRACE_ENTRY_POINT;
       
    70     TRACE_EXIT_POINT;
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // CCalenTodoController::~CCalenTodoController
       
    75 // Destructor.
       
    76 // (other items were commented in a header).
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 CCalenTodoController::~CCalenTodoController()
       
    80     {
       
    81     TRACE_ENTRY_POINT;
       
    82 
       
    83     CleanupInstances();
       
    84     iActiveListIndices.Reset();
       
    85     
       
    86     TRACE_EXIT_POINT;
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CCalenTodoController::RefreshL
       
    91 // Refresh agenda name list.
       
    92 // ----------------------------------------------------------------------------
       
    93 //
       
    94 void CCalenTodoController::RefreshL()
       
    95     {
       
    96     TRACE_ENTRY_POINT;
       
    97 
       
    98     iList.ResetAndDestroy();
       
    99     iActiveListIndices.Reset();
       
   100     
       
   101     CalCommon::TCalViewFilter filter = CalCommon::EIncludeCompletedTodos   |
       
   102                                        CalCommon::EIncludeIncompletedTodos |
       
   103                                        // only fetch the first instance for repeating to-dos!
       
   104                                        CalCommon::EIncludeRptsNextInstanceOnly;
       
   105 
       
   106     TCalTime start;  start.SetTimeLocalL( TCalTime::MinTime() );
       
   107     TCalTime end;  end.SetTimeLocalL( TCalTime::MaxTime() );
       
   108 
       
   109     CalCommon::TCalTimeRange timeRange( start, end );
       
   110     
       
   111     RArray<TInt> colIdArray;
       
   112     CCalenNativeView::GetActiveCollectionidsL( iServices, colIdArray );
       
   113     
       
   114     if(colIdArray.Count() > 0)
       
   115         { 
       
   116         iServices.InstanceViewL(colIdArray)->FindInstanceL( iList, filter, timeRange );
       
   117         }    
       
   118         
       
   119     colIdArray.Reset();
       
   120     
       
   121     CalenAgendaUtils::SortInstanceList( iList );
       
   122     TRACE_EXIT_POINT;
       
   123     }
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CCalenTodoController::InstanceList
       
   127 // Return ToDo instance list pointer.
       
   128 // (other items were commented in a header).
       
   129 // ----------------------------------------------------------------------------
       
   130 //
       
   131 RPointerArray<CCalInstance>& CCalenTodoController::InstanceList()
       
   132     {
       
   133     TRACE_ENTRY_POINT;
       
   134 
       
   135     TRACE_EXIT_POINT;
       
   136     return iList;
       
   137     }
       
   138 
       
   139 // ----------------------------------------------------------------------------
       
   140 // CCalenTodoController::SetToStartL
       
   141 // Index is setted to ZERO and fetch data.
       
   142 // ----------------------------------------------------------------------------
       
   143 //
       
   144 void CCalenTodoController::SetToStartL()
       
   145     {
       
   146     TRACE_ENTRY_POINT;
       
   147 
       
   148     iIndex = 0;
       
   149 
       
   150     TRACE_EXIT_POINT;
       
   151     }
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // CCalenTodoController::SetToNextL
       
   155 // Index is incremented and fetch data.
       
   156 // (other items were commented in a header).
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 void CCalenTodoController::SetToNextL()
       
   160     {
       
   161     TRACE_ENTRY_POINT;
       
   162 
       
   163     ++iIndex;
       
   164 
       
   165     TRACE_EXIT_POINT;
       
   166     }
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CCalenTodoController::IsAtEnd
       
   170 // Check terminus of index.
       
   171 // (other items were commented in a header).
       
   172 // ----------------------------------------------------------------------------
       
   173 //
       
   174 TBool CCalenTodoController::IsAtEnd() const
       
   175     {
       
   176     TRACE_ENTRY_POINT;
       
   177 
       
   178     TRACE_EXIT_POINT;
       
   179     return (iIndex == iList.Count());
       
   180     }
       
   181 
       
   182 // ----------------------------------------------------------------------------
       
   183 // CCalenTodoController::Instance
       
   184 // Return instance id of current index.
       
   185 // (other items were commented in a header).
       
   186 // ----------------------------------------------------------------------------
       
   187 //
       
   188 CCalInstance* CCalenTodoController::Instance() const
       
   189     {
       
   190     TRACE_ENTRY_POINT;
       
   191 
       
   192     if( iIndex < 0 || iIndex >= Count() )
       
   193         {
       
   194         TRACE_EXIT_POINT;
       
   195         return NULL;
       
   196         }
       
   197 
       
   198     TRACE_EXIT_POINT;
       
   199     return iList[ iIndex ];
       
   200     }
       
   201 
       
   202 // ----------------------------------------------------------------------------
       
   203 // CCalenTodoController::InstanceId
       
   204 // Return instance id of the index.
       
   205 // (other items were commented in a header).
       
   206 // ----------------------------------------------------------------------------
       
   207 //
       
   208 CCalInstance* CCalenTodoController::InstanceL(TInt aIndex) const     // Index of list
       
   209     {
       
   210     TRACE_ENTRY_POINT;
       
   211     //1.iActiveListIndices contains iList indices as values.
       
   212     //2.iActiveListIndices is populated in CreateEntryItertorL of container
       
   213     
       
   214     if( aIndex < 0 || aIndex >= Count() || iActiveListIndices.Count() <= 0 )
       
   215         {
       
   216         TRACE_EXIT_POINT;
       
   217         return NULL;
       
   218         }
       
   219 
       
   220     TRACE_EXIT_POINT;
       
   221     return iList[ iActiveListIndices[aIndex] ];
       
   222     }
       
   223 
       
   224 // ----------------------------------------------------------------------------
       
   225 // CCalenTodoController::IsCrossOutL
       
   226 // Check status of cross out.
       
   227 // (other items were commented in a header).
       
   228 // ----------------------------------------------------------------------------
       
   229 //
       
   230 TBool CCalenTodoController::IsCrossOutL(TInt aIndex) // Index of list
       
   231     {
       
   232     TRACE_ENTRY_POINT;
       
   233 
       
   234     TBool crossout( EFalse );
       
   235 
       
   236     if( iList.Count() )
       
   237         {
       
   238         CCalInstance* instance = InstanceL( aIndex );
       
   239         CCalEntry& entry = instance->Entry();
       
   240 
       
   241         if( entry.StatusL() == CCalEntry::ETodoCompleted )
       
   242             {
       
   243             crossout = ETrue;
       
   244             }
       
   245         }
       
   246 
       
   247     TRACE_EXIT_POINT;
       
   248     return crossout;
       
   249     }
       
   250 
       
   251 // ----------------------------------------------------------------------------
       
   252 // CCalenTodoController::Count
       
   253 // Return number of item.
       
   254 // (other items were commented in a header).
       
   255 // ----------------------------------------------------------------------------
       
   256 //
       
   257 TInt CCalenTodoController::Count() const
       
   258     {
       
   259     TRACE_ENTRY_POINT;
       
   260 
       
   261     TRACE_EXIT_POINT;
       
   262     return iList.Count();
       
   263     }
       
   264 
       
   265 
       
   266 TInt CCalenTodoController::FindInstanceIndexL(const TCalenInstanceId& aId) const
       
   267     {
       
   268     TRACE_ENTRY_POINT;
       
   269 
       
   270     for(TInt index(0); index < iList.Count(); ++index)
       
   271         {
       
   272         if( iList[index]->Entry().LocalUidL() == aId.iEntryLocalUid )
       
   273             {
       
   274             // FIXME, if several instances match, we should one
       
   275             // that closest matches aId.iInstanceTime
       
   276             TRACE_EXIT_POINT;
       
   277             return index;
       
   278             }
       
   279         }
       
   280 
       
   281     TRACE_EXIT_POINT;
       
   282     return KErrNotFound;
       
   283     }
       
   284 
       
   285 void CCalenTodoController::CleanupInstances()
       
   286     {
       
   287     TRACE_ENTRY_POINT
       
   288     iList.ResetAndDestroy();
       
   289     TRACE_EXIT_POINT
       
   290     }
       
   291 // End of File