examples/SFExamples/PIM/AgendaStandard/src/AgendaStandardAppUi.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 <eikapp.h>
00018 #include <AgendaStandard.rsg>
00019 
00020 #include "AgendaStandardAppUi.h"
00021 #include "AgendaStandardMainView.h"
00022 #include "CalWrite.h"
00023 #include "AgendaStandard.hrh"
00024 #include <S32MEM.H> // for descriptor-backed streams.
00025 
00026 void CAgendaStandardAppUi::ConstructL()
00027         {
00028         BaseConstructL(EAknEnableSkin);
00029         iMainView = CAgendaStandardMainView::NewL(ClientRect());
00030 
00031         iCalendarWriter = CCalWrite::NewL();
00032         }
00033         
00034 CAgendaStandardAppUi::~CAgendaStandardAppUi()
00035     {
00036     delete iCalendarWriter;
00037 #ifdef __SERIES60_3X__
00038         delete iMainView;
00039 #endif
00040     }
00041 
00042 void CAgendaStandardAppUi::HandleCommandL(TInt aCommand)
00043         {
00044         switch ( aCommand )
00045                 {
00046 #ifdef __SERIES60_3X__
00047                 case EAknSoftkeyExit:
00048 #endif
00049                 case EEikCmdExit:
00050                         {
00051                         User::Exit(0);
00052                         break;
00053                         }
00054                 case EAgendaStandard:
00055                         {
00056                         CCalEntryView& calView = iCalendarWriter->CalView();
00057                         // Let's find a recently modified celendar entry.
00058                         // with any luck, it will be one created by
00059                         // \PIM\PopulateAgenda
00060                         RArray<TCalLocalUid> calIds;
00061                         CleanupClosePushL(calIds);
00062                         // start with entries modified in the last day. keep going
00063                         // back in time one day at a time until we find at least 1 entry
00064                         TTime backThen;
00065                         TTimeIntervalDays oneDay(1);
00066                         backThen.UniversalTime();
00067                         backThen -= oneDay;
00068                         TCalTime daysBack;
00069                         // worst case scenario, we only go back 1 month.
00070                         // just do something once in a while, will you please ?
00071                         TTime lastMonth;
00072                         lastMonth.UniversalTime();
00073                         lastMonth -= TTimeIntervalMonths(1);
00074                         while (calIds.Count() < 1 && backThen > lastMonth)
00075                                 {
00076                                 daysBack.SetTimeUtcL(backThen);
00077                                 calView.GetIdsModifiedSinceDateL(daysBack, calIds);
00078                                 backThen -= oneDay;
00079                                 }
00080                         
00081                         if (calIds.Count() > 0)
00082                                 {
00083                                 // let's make a descriptor-backed stream.
00084                                 // 4Kb should be enough to hold any calendar entry.
00085                                 HBufC8* buffer = HBufC8::NewLC(4096);
00086                                 TPtr8 bufferPtr = buffer->Des();
00087 
00088                                 RDesWriteStream writeStream(bufferPtr);
00089                                 TRAPD(error, iCalendarWriter->ExportEventL(calIds[0], writeStream));
00090                                 writeStream.Close();
00091 
00092                                 // report error on the Label control
00093                                 if (KErrNone == error)
00094                                         {
00095                                         // make a read stream to re-import the contact
00096                                         // from the descriptor
00097 
00098                                         RDesReadStream readStream(*buffer);
00099                                         TRAP(error, iCalendarWriter->ImportEventL(readStream));
00100                                         readStream.Close();
00101 
00102                                         if (KErrNone == error || error == KErrAlreadyExists)
00103                                                 {
00104                                                 error = KErrNone;
00105                                                 _LIT(KSuccess, "It Worked!");
00106                                                 iMainView->SetTextL(KSuccess());
00107                                                 }
00108                                         }
00109                                 if (KErrNone != error)
00110                                         {
00111                                         _LIT(KErrorMsg, "Symbian Error Code = %D");
00112                                         TBuf<32> errorBuf;
00113                                         errorBuf.Format(KErrorMsg(), error);
00114                                         iMainView->SetTextL(errorBuf);
00115                                         }
00116                                 CleanupStack::PopAndDestroy(buffer);
00117                                 }
00118                         else
00119                                 {
00120                                 _LIT(KNotFound, "Nothing done for a month");
00121                                 iMainView->SetTextL(KNotFound());
00122                                 }
00123                         CleanupStack::PopAndDestroy(&calIds);
00124                         break;
00125                         }
00126                 default:
00127                         break;
00128                 }
00129         }
00130 
00131         
00132 #ifdef __SERIES60_3X__
00133 
00134 void CAgendaStandardAppUi::HandleResourceChangeL(TInt aType)
00135         {
00136         CAknAppUi::HandleResourceChangeL(aType);
00137         iMainView->SetRect(ClientRect());
00138         }
00139 
00140 #endif
00141         
00142 // End of File

Generated by  doxygen 1.6.2