examples/SFExamples/PIM/AgendaUpdate/src/AgendaUpdateAppUi.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 <AgendaUpdate.rsg>
00019 
00020 #include "AgendaUpdateAppUi.h"
00021 #include "AgendaUpdateMainView.h"
00022 #include "CalWrite.h"
00023 #include "AgendaUpdate.hrh"
00024 
00025 void CAgendaUpdateAppUi::ConstructL()
00026         {
00027         BaseConstructL(EAknEnableSkin);
00028         iMainView = CAgendaUpdateMainView::NewL(ClientRect());
00029 
00030         iCalendarWriter = CCalWrite::NewL();
00031         }
00032         
00033 CAgendaUpdateAppUi::~CAgendaUpdateAppUi()
00034     {
00035     delete iCalendarWriter;
00036 #ifdef __SERIES60_3X__
00037         delete iMainView;
00038 #endif
00039     }
00040 
00041 void CAgendaUpdateAppUi::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 EAgendaUpdate:
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                                 // reschedule to 1 month after the last modified window
00083                                 backThen += TTimeIntervalMonths(1);
00084                                 TRAPD(error, iCalendarWriter->RescheduleL(calIds[0], backThen));
00085                                 // report error on the Label control
00086                                 if (KErrNone == error)
00087                                         {
00088                                         _LIT(KSuccess, "It Worked!");
00089                                         iMainView->SetTextL(KSuccess());
00090                                         }
00091                                 else
00092                                         {
00093                                         _LIT(KErrorMsg, "Symbian Error Code = %D");
00094                                         TBuf<32> errorBuf;
00095                                         errorBuf.Format(KErrorMsg(), error);
00096                                         iMainView->SetTextL(errorBuf);
00097                                         }
00098                                 }
00099                         else
00100                                 {
00101                                 _LIT(KNotFound, "Nothing done for a month");
00102                                 iMainView->SetTextL(KNotFound());
00103                                 }
00104                         CleanupStack::PopAndDestroy(&calIds);
00105                         break;
00106                         }
00107                 default:
00108                         break;
00109                 }
00110         }
00111 
00112         
00113 #ifdef __SERIES60_3X__
00114 
00115 void CAgendaUpdateAppUi::HandleResourceChangeL(TInt aType)
00116         {
00117         CAknAppUi::HandleResourceChangeL(aType);
00118         iMainView->SetRect(ClientRect());
00119         }
00120 
00121 #endif
00122         
00123 // End of File

Generated by  doxygen 1.6.2