examples/SFExamples/PIM/AgendaSearch/src/AgendaSearchAppUi.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 <AgendaSearch.rsg>
00019 
00020 #include "AgendaSearchAppUi.h"
00021 #include "AgendaSearchMainView.h"
00022 #include "CalRead.h"
00023 #include "AgendaSearch.hrh"
00024 
00025 void CAgendaSearchAppUi::ConstructL()
00026         {
00027         BaseConstructL(EAknEnableSkin);
00028         iMainView = CAgendaSearchMainView::NewL(ClientRect());
00029 
00030         iCalendarReader = CCalRead::NewL();
00031         }
00032         
00033 CAgendaSearchAppUi::~CAgendaSearchAppUi()
00034     {
00035     delete iCalendarReader;
00036 #ifdef __SERIES60_3X__
00037         delete iMainView;
00038 #endif
00039     }
00040 
00041 void CAgendaSearchAppUi::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 EAgendaSearch:
00054                         {
00055                         // we are going to try to find an entry added by \PIM\PopulateAgenda
00056                         // the time slot should always be one hour.
00057                         // we are going to start a year from now, at midnight.
00058                         // then go back one day at a time for a month or until
00059                         // we find an occupied slot.
00060                         TTime temp;
00061                         TTime notTooFar;
00062                         TTimeIntervalMinutes oneHour(59);// prevents overlap
00063                         TTimeIntervalDays oneDay(1);
00064                         TBool instanceFound = EFalse;
00065                         TInt error = KErrNone;
00066                         temp.UniversalTime();
00067                         TDateTime futureDate = temp.DateTime();
00068                         futureDate.SetHour(0);
00069                         futureDate.SetMinute(0);
00070                         futureDate.SetSecond(0);
00071                         futureDate.SetMicroSecond(0);
00072                         TTime future(futureDate);
00073                         future += TTimeIntervalYears(1);
00074                         notTooFar = future - TTimeIntervalMonths(1);
00075                         while (error == KErrNone && !instanceFound && future > notTooFar)
00076                                 {
00077                                 TRAP(error, instanceFound = iCalendarReader->CheckFreeL(future, oneHour));
00078                                 future -= oneDay;
00079                                 }
00080                         if (KErrNone == error)
00081                                 {
00082                                 if (instanceFound)
00083                                         {
00084                                         _LIT(KSuccess, "Found Instance");
00085                                         iMainView->SetTextL(KSuccess());
00086                                         }
00087                                 else
00088                                         {
00089                                         _LIT(KNotFound, "Free Slot 1 Month");
00090                                         iMainView->SetTextL(KNotFound());
00091                                         }
00092                                 }
00093                         else
00094                                 {
00095                                 _LIT(KErrorMsg, "Symbian Error Code = %D");
00096                                 TBuf<32> errorBuf;
00097                                 errorBuf.Format(KErrorMsg(), error);
00098                                 iMainView->SetTextL(errorBuf);
00099                                 }
00100                         break;
00101                         }
00102                 default:
00103                         break;
00104                 }
00105         }
00106 
00107         
00108 #ifdef __SERIES60_3X__
00109 
00110 void CAgendaSearchAppUi::HandleResourceChangeL(TInt aType)
00111         {
00112         CAknAppUi::HandleResourceChangeL(aType);
00113         iMainView->SetRect(ClientRect());
00114         }
00115 
00116 #endif
00117         
00118 // End of File

Generated by  doxygen 1.6.2