examples/SFExamples/PIM/AgendaRemove/src/AgendaRemoveAppUi.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 <AgendaRemove.rsg>
00019 
00020 #include "AgendaRemoveAppUi.h"
00021 #include "AgendaRemoveMainView.h"
00022 #include "CalWrite.h"
00023 #include "AgendaRemove.hrh"
00024 
00025 void CAgendaRemoveAppUi::ConstructL()
00026         {
00027         BaseConstructL(EAknEnableSkin);
00028         iMainView = CAgendaRemoveMainView::NewL(ClientRect());
00029 
00030         iCalendarWriter = CCalWrite::NewL();
00031         }
00032         
00033 CAgendaRemoveAppUi::~CAgendaRemoveAppUi()
00034     {
00035     delete iCalendarWriter;
00036 #ifdef __SERIES60_3X__
00037         delete iMainView;
00038 #endif
00039     }
00040 
00041 void CAgendaRemoveAppUi::HandleCommandL(TInt aCommand)
00042         {
00043         switch ( aCommand )
00044                 {
00045 #ifdef __SERIES60_3X__
00046                 case EAknSoftkeyExit:
00047 #endif
00048                 case EEikCmdExit:
00049                         {
00050                         User::Exit(0);
00051                         break;
00052                         }
00053                 case EAgendaRemove:
00054                         {
00055                         CCalEntryView& calView = iCalendarWriter->CalView();
00056                         // Let's find a recently modified celendar entry.
00057                         // with any luck, it will be one created by
00058                         // \PIM\PopulateAgenda
00059                         RArray<TCalLocalUid> calIds;
00060                         CleanupClosePushL(calIds);
00061                         // start with entries modified in the last day. keep going
00062                         // back in time one day at a time until we find at least 1 entry
00063                         TTime backThen;
00064                         TTimeIntervalDays oneDay(1);
00065                         backThen.UniversalTime();
00066                         backThen -= oneDay;
00067                         TCalTime daysBack;
00068                         // worst case scenario, we only go back 1 month.
00069                         // just do something once in a while, will you please ?
00070                         TTime lastMonth;
00071                         lastMonth.UniversalTime();
00072                         lastMonth -= TTimeIntervalMonths(1);
00073                         while (calIds.Count() < 1 && backThen > lastMonth)
00074                                 {
00075                                 daysBack.SetTimeUtcL(backThen);
00076                                 calView.GetIdsModifiedSinceDateL(daysBack, calIds);
00077                                 backThen -= oneDay;
00078                                 }
00079                         
00080                         if (calIds.Count() > 0)
00081                                 {
00082                                 TRAPD(error, iCalendarWriter->RemoveL(calIds[0]));
00083                                 // report error on the Label control
00084                                 if (KErrNone == error)
00085                                         {
00086                                         _LIT(KSuccess, "It Worked!");
00087                                         iMainView->SetTextL(KSuccess());
00088                                         }
00089                                 else
00090                                         {
00091                                         _LIT(KErrorMsg, "Symbian Error Code = %D");
00092                                         TBuf<32> errorBuf;
00093                                         errorBuf.Format(KErrorMsg(), error);
00094                                         iMainView->SetTextL(errorBuf);
00095                                         }
00096                                 }
00097                         else
00098                                 {
00099                                 _LIT(KNotFound, "Nothing done for a month");
00100                                 iMainView->SetTextL(KNotFound());
00101                                 }
00102                         CleanupStack::PopAndDestroy(&calIds);
00103                         break;
00104                         }
00105                 default:
00106                         break;
00107                 }
00108         }
00109 
00110         
00111 #ifdef __SERIES60_3X__
00112 
00113 void CAgendaRemoveAppUi::HandleResourceChangeL(TInt aType)
00114         {
00115         CAknAppUi::HandleResourceChangeL(aType);
00116         iMainView->SetRect(ClientRect());
00117         }
00118 
00119 #endif
00120         
00121 // End of File

Generated by  doxygen 1.6.2