calendarui/multicaluidialog/src/multicaluidialogmodel.cpp
changeset 0 f979ecb2b13e
child 11 0f07cd1b5772
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2  * Copyright (c) 2009 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 : Implemrntation class for calenmultidbutility .
       
    15  *                 
       
    16  *
       
    17  */
       
    18 // system include.
       
    19 #include <calsession.h>
       
    20 #include <calentryview.h>
       
    21 #include <calentry.h>
       
    22 #include <CalenInterimUtils2.h>
       
    23 #include <calcalendarinfo.h>
       
    24 #include <calcalendariterator.h>
       
    25 // user include.
       
    26 #include "multicaluidialogmodel.h"
       
    27 #include "calendarui_debug.h"
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // CMultiCalUiDialogModel::CMultiCalUiDialogModel
       
    31 // Constructor
       
    32 // ----------------------------------------------------------------------------
       
    33 //
       
    34 CMultiCalUiDialogModel::CMultiCalUiDialogModel()
       
    35     {
       
    36     TRACE_ENTRY_POINT
       
    37     TRACE_EXIT_POINT
       
    38     }
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // CMultiCalUiDialogModel::NewL
       
    42 // First phase constructor
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 CMultiCalUiDialogModel* CMultiCalUiDialogModel::NewL()
       
    46     {
       
    47     TRACE_ENTRY_POINT
       
    48     CMultiCalUiDialogModel* self = CMultiCalUiDialogModel::NewLC();
       
    49     CleanupStack::Pop(self);
       
    50     TRACE_EXIT_POINT
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CMultiCalUiDialogModel::NewLC
       
    56 // First phase constructor
       
    57 // ----------------------------------------------------------------------------
       
    58 //
       
    59 CMultiCalUiDialogModel* CMultiCalUiDialogModel::NewLC()
       
    60     {
       
    61     TRACE_ENTRY_POINT
       
    62     CMultiCalUiDialogModel* self = new (ELeave) CMultiCalUiDialogModel();
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL();
       
    65     TRACE_EXIT_POINT
       
    66     return self;
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // CMultiCalUiDialogModel::~CMultiCalUiDialogModel
       
    71 // Rest of the details are commented in header.
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 CMultiCalUiDialogModel::~CMultiCalUiDialogModel()
       
    75     {
       
    76     TRACE_ENTRY_POINT
       
    77 
       
    78     iCalendarInfoList.ResetAndDestroy();
       
    79 
       
    80     if (iCalendarsSession)
       
    81         {
       
    82         delete iCalendarsSession;
       
    83         iCalendarsSession = NULL;
       
    84         }
       
    85 
       
    86     iCalEntryViewArray.ResetAndDestroy();
       
    87 
       
    88     iCalSessionArray.ResetAndDestroy();
       
    89 
       
    90     iCalendarStatus.Reset();
       
    91 
       
    92     if (iInterimUtils)
       
    93         {
       
    94         delete iInterimUtils;
       
    95         iInterimUtils = NULL;
       
    96         }
       
    97 
       
    98     iCalEntries.Reset();
       
    99 
       
   100     TRACE_EXIT_POINT;
       
   101     }
       
   102 
       
   103 // ----------------------------------------------------------------------------
       
   104 // CMultiCalUiDialogModel::SetCalEntry
       
   105 // Rest of the details are commented in header.
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 void CMultiCalUiDialogModel::SetCalEntry(
       
   109         const RPointerArray<CCalEntry>& aCalEntries)
       
   110     {
       
   111     TRACE_ENTRY_POINT
       
   112     //We take only the pointers to entries , we dont own it
       
   113     //So never do iCalEntries.ResetAndDestroy() only Reset
       
   114     for (TInt i = 0; i < aCalEntries.Count(); i++)
       
   115         {
       
   116         iCalEntries.AppendL(aCalEntries[i]);
       
   117         }
       
   118 
       
   119     TRACE_EXIT_POINT;
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 // CMultiCalUiDialogModel::GetMultiDbInfo
       
   124 // Rest of the details are commented in header.
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 RPointerArray<CCalCalendarInfo>& CMultiCalUiDialogModel::GetCalendarInfoArray()
       
   128     {
       
   129     TRACE_ENTRY_POINT
       
   130     TRACE_EXIT_POINT;
       
   131     return iCalendarInfoList;
       
   132     }
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CMultiCalUiDialogModel::ConstructL
       
   136 // Second phase constructor
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 void CMultiCalUiDialogModel::ConstructL()
       
   140     {
       
   141     TRACE_ENTRY_POINT
       
   142     //iCalSessionArray takes ownership of this.
       
   143     CCalSession* defaultSession = CCalSession::NewL();
       
   144 
       
   145     GetAllCalendarInfoL(iCalendarInfoList);
       
   146 
       
   147     for (TInt index = 0; index < iCalendarInfoList.Count(); index++)
       
   148         {
       
   149         iCalendarStatus.Append(0);
       
   150 
       
   151         if (!index) //First create the default session
       
   152             {
       
   153             const TPtrC name = iCalendarInfoList[index]->FileNameL();
       
   154             defaultSession->OpenL(name);
       
   155             iCalSessionArray.Append(defaultSession);
       
   156             CCalEntryView* entryView = CCalEntryView::NewL(*defaultSession);
       
   157             CleanupStack::PushL(entryView);
       
   158             iCalEntryViewArray.Append(entryView);
       
   159             CleanupStack::Pop(entryView);
       
   160             }
       
   161         else
       
   162             {
       
   163             CCalSession* session = CCalSession::NewL(*defaultSession);
       
   164             CleanupStack::PushL(session);
       
   165             const TPtrC name = iCalendarInfoList[index]->FileNameL();
       
   166             session->OpenL(name);
       
   167             CleanupStack::Pop(session);
       
   168             iCalSessionArray.Append(session);
       
   169             CCalEntryView* entryView = CCalEntryView::NewL(*session);
       
   170             CleanupStack::PushL(entryView);
       
   171             iCalEntryViewArray.Append(entryView);
       
   172             CleanupStack::Pop(entryView);
       
   173             }
       
   174         }
       
   175 
       
   176     iInterimUtils = CCalenInterimUtils2::NewL();
       
   177 
       
   178     TRACE_EXIT_POINT;
       
   179     }
       
   180 
       
   181 // ----------------------------------------------------------------------------
       
   182 // CMultiCalUiDialogModel::SetCalendarStatus
       
   183 // Rest of the details are commented in header.
       
   184 // ----------------------------------------------------------------------------
       
   185 //
       
   186 void CMultiCalUiDialogModel::SetCalendarStatus(TInt aIndex, TBool aStatus)
       
   187     {
       
   188     TRACE_ENTRY_POINT
       
   189     __ASSERT_ALWAYS(aIndex >= 0,User::Invariant());
       
   190     iCalendarStatus.Remove(aIndex);
       
   191     iCalendarStatus.Insert(aStatus,aIndex);
       
   192     TRACE_EXIT_POINT;
       
   193     }
       
   194 
       
   195 // ----------------------------------------------------------------------------
       
   196 // CMultiCalUiDialogModel::GetCalendarStatus
       
   197 // Rest of the details are commented in header.
       
   198 // ----------------------------------------------------------------------------
       
   199 //
       
   200 TBool CMultiCalUiDialogModel::GetCalendarStatus(TInt aIndex)
       
   201     {
       
   202     TRACE_ENTRY_POINT
       
   203     __ASSERT_ALWAYS(aIndex >= 0,User::Invariant());
       
   204     TRACE_EXIT_POINT;
       
   205     return iCalendarStatus[aIndex];
       
   206     }
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // CMultiCalUiDialogModel::MarkedCalendarsCount
       
   210 // Rest of the details are commented in header.
       
   211 // ----------------------------------------------------------------------------
       
   212 //
       
   213 TInt CMultiCalUiDialogModel::MarkedCalendarsCount()
       
   214     {
       
   215     TRACE_ENTRY_POINT
       
   216     TInt count = NULL;
       
   217     for (TInt i = 0; i < iCalendarStatus.Count(); i++)
       
   218         {
       
   219         if (iCalendarStatus[i])
       
   220             {
       
   221             count++;
       
   222             }
       
   223         }TRACE_EXIT_POINT;
       
   224     return count;
       
   225     }
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // CMultiCalUiDialogModel::StoreCalEntryL
       
   229 // Rest of the details are commented in header.
       
   230 // ----------------------------------------------------------------------------
       
   231 //
       
   232 void CMultiCalUiDialogModel::StoreCalEntryL()
       
   233     {
       
   234     TRACE_ENTRY_POINT
       
   235     //Create copy for entires.
       
   236     RPointerArray<CCalEntry> copyEntries;
       
   237     CreateCopyL(copyEntries);
       
   238 
       
   239     //Store the copy into calendars
       
   240     for (TInt i = 0; i < iCalEntryViewArray.Count(); i++)
       
   241         {
       
   242         if (iCalendarStatus[i])
       
   243             {
       
   244             TInt numSuccess;
       
   245             iCalEntryViewArray[i]->StoreL(copyEntries, numSuccess);
       
   246             }
       
   247         }
       
   248 
       
   249     copyEntries.ResetAndDestroy();
       
   250     TRACE_EXIT_POINT;
       
   251     }
       
   252 
       
   253 // ----------------------------------------------------------------------------
       
   254 // CMultiCalUiDialogModel::CreateCopyL
       
   255 // Rest of the details are commented in header.
       
   256 // ----------------------------------------------------------------------------
       
   257 //
       
   258 void CMultiCalUiDialogModel::CreateCopyL(
       
   259         RPointerArray<CCalEntry>& aCalCopyEntries)
       
   260     {
       
   261     TRACE_ENTRY_POINT;
       
   262 
       
   263     for (TInt i = 0; i < iCalEntries.Count(); i++)
       
   264         {
       
   265         const CCalEntry* sourceEntry = iCalEntries[i];
       
   266 
       
   267         HBufC8* guid = iInterimUtils->GlobalUidL();
       
   268         CleanupStack::PushL(guid);
       
   269 
       
   270         CCalEntry* copyEntry = CCalEntry::NewL(sourceEntry->EntryTypeL(),
       
   271                 guid, CCalEntry::EMethodNone, 0);
       
   272 
       
   273         CleanupStack::Pop(guid); // ownership was passed
       
   274         CleanupStack::PushL(copyEntry);
       
   275 
       
   276         sourceEntry->DescriptionL(); // make sure entry is fully loaded
       
   277         copyEntry->CopyFromL(*sourceEntry, CCalEntry::EDontCopyId);
       
   278         copyEntry->DescriptionL(); // make sure entry is fully copied
       
   279 
       
   280         aCalCopyEntries.AppendL(copyEntry);
       
   281 
       
   282         CleanupStack::Pop(copyEntry);
       
   283         }
       
   284 
       
   285     TRACE_EXIT_POINT;;
       
   286     }
       
   287 
       
   288 // ----------------------------------------------------------------------------
       
   289 // CMultiCalUiDialogModel::GetAllCalendarInfoL
       
   290 // Rest of the details are commented in header.
       
   291 // ----------------------------------------------------------------------------
       
   292 //
       
   293 void CMultiCalUiDialogModel::GetAllCalendarInfoL(RPointerArray<
       
   294         CCalCalendarInfo>& aCalendarInfoList)
       
   295     {
       
   296     TRACE_ENTRY_POINT
       
   297 
       
   298     if (!iCalendarsSession)
       
   299         {
       
   300         iCalendarsSession = CCalSession::NewL();
       
   301         }
       
   302     CCalCalendarIterator* calIter = CCalCalendarIterator::NewL(
       
   303             *iCalendarsSession);
       
   304     CleanupStack::PushL(calIter);
       
   305     CCalCalendarInfo* calendarInfo = calIter->FirstL();
       
   306     while (calendarInfo)
       
   307         {
       
   308         aCalendarInfoList.AppendL(calendarInfo);
       
   309         calendarInfo = calIter->NextL();
       
   310         }
       
   311     CleanupStack::PopAndDestroy(calIter);
       
   312 
       
   313     TRACE_EXIT_POINT;
       
   314     }
       
   315 
       
   316 // end of file