examples/SFExamples/PIM/AgendaUpdate/src/CalWrite.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 #include "CalWrite.h"
00018 
00019 CCalWrite* CCalWrite::NewL()
00020         {
00021         CCalWrite* self = new (ELeave) CCalWrite();
00022         CleanupStack::PushL(self);
00023         self->ConstructL();
00024         CleanupStack::Pop(self);
00025         return self;
00026         }
00027 
00028 CCalWrite::~CCalWrite()
00029         {
00030         delete iCalView;
00031         delete iCalSes;
00032         }
00033 
00034 void CCalWrite::ConstructL()
00035         {
00036         iCalSes = CCalSession::NewL();
00037         const TDesC& name = iCalSes->DefaultFileNameL();
00038         TRAPD(error, iCalSes->CreateCalFileL(name));
00039         if (error != KErrAlreadyExists)
00040                 {
00041                 User::LeaveIfError(error);
00042                 }
00043         iCalSes->OpenL(KNullDesC());
00044         iCalView = CCalEntryView::NewL(*iCalSes, *this);
00045         }
00046 
00047 CCalEntryView& CCalWrite::CalView()
00048         {
00049         return *iCalView;
00050         }
00051 
00052 void CCalWrite::RescheduleL(TCalLocalUid aEventId, TTime aNewTimeUtc)
00053         {
00054         // find the event
00055         CCalEntry* entry = iCalView->FetchL(aEventId);
00056         // reschedule, keep original duration.
00057         if (NULL != entry)
00058                 {
00059                 CleanupStack::PushL(entry);
00060                 TCalTime start = entry->StartTimeL();
00061                 TCalTime end = entry->EndTimeL();
00062                 TTime startUtc = start.TimeUtcL();
00063                 TTime endUtc = end.TimeUtcL();
00064                 TTimeIntervalMicroSeconds duration = endUtc.MicroSecondsFrom(startUtc);
00065                 start.SetTimeUtcL(aNewTimeUtc);
00066                 end.SetTimeUtcL(aNewTimeUtc + duration);
00067                 entry->SetStartAndEndTimeL(start, end); 
00068                 // commit to the database
00069                 RPointerArray<CCalEntry> array;
00070                 CleanupClosePushL(array);
00071                 array.AppendL(entry);
00072                 // we don't transfer ownership of entry
00073                 TInt success=0;
00074                 iCalView->UpdateL(array, success);
00075                 CleanupStack::PopAndDestroy(&array);
00076                 if (success < 1)
00077                         {
00078                         User::Leave(KErrGeneral);
00079                         }
00080                 CleanupStack::PopAndDestroy(entry);
00081                 }
00082         }
00083 
00084 // End of File

Generated by  doxygen 1.6.2