00001 /* 00002 * Copyright © 2008 Nokia Corporation. 00003 */ 00004 00005 // INCLUDE FILES 00006 #include <aknviewappui.h> 00007 #include <aknnotewrappers.h> 00008 #include <CalendarAPIexample.rsg> 00009 //#include <Testapp.rsg> 00010 00011 #include "CalendarAPIexampleEntryView.h" 00012 #include "CalendarAPIexampleEntryContainer.h" 00013 #include "CalendarAPIexampleEntriesView.h" 00014 #include "CalendarAPIexampleSearchView.h" 00015 00016 #include "CalendarAPIexampleEngine.h" 00017 00018 // CONSTANTS 00019 _LIT(KDeleteConfirmation, "Delete this anniversary?"); 00020 00021 // ================= MEMBER FUNCTIONS ======================= 00022 00023 // Two-phased constructor. 00024 CCalendarAPIexampleEntryView* CCalendarAPIexampleEntryView::NewL(MCalendarEngineCommandsInterface& aEngine) 00025 { 00026 CCalendarAPIexampleEntryView* self = CCalendarAPIexampleEntryView::NewLC(aEngine); 00027 CleanupStack::Pop(self); 00028 return self; 00029 } 00030 00031 // Two-phased constructor. 00032 CCalendarAPIexampleEntryView* CCalendarAPIexampleEntryView::NewLC(MCalendarEngineCommandsInterface& aEngine) 00033 { 00034 CCalendarAPIexampleEntryView* self = new (ELeave) CCalendarAPIexampleEntryView(aEngine); 00035 CleanupStack::PushL(self); 00036 self->ConstructL(); 00037 return self; 00038 } 00039 00040 00041 CCalendarAPIexampleEntryView::CCalendarAPIexampleEntryView( 00042 MCalendarEngineCommandsInterface& aEngine) : iEngine(aEngine) 00043 { 00044 00045 } 00046 00047 // destructor 00048 CCalendarAPIexampleEntryView::~CCalendarAPIexampleEntryView() 00049 { 00050 delete iContainer; 00051 iContainer = NULL; 00052 } 00053 00054 // Symbian OS default constructor can leave. 00055 void CCalendarAPIexampleEntryView::ConstructL() 00056 { 00057 BaseConstructL(R_CALENDARAPIEXAMPLE_ENTRY_VIEW); 00058 } 00059 00060 // ---------------------------------------------------- 00061 // CCalendarAPIexampleEntryView::Id() 00062 // Returns ID of View 00063 // ---------------------------------------------------- 00064 // 00065 TUid CCalendarAPIexampleEntryView::Id() const 00066 { 00067 return KEntryViewId; 00068 } 00069 00070 // ---------------------------------------------------- 00071 // CCalendarAPIexampleEntryView::HandleCommandL() 00072 // Takes care of command handling 00073 // ---------------------------------------------------- 00074 // 00075 void CCalendarAPIexampleEntryView::HandleCommandL( TInt aCommand ) 00076 { 00077 //If the command handling wouuld be given to AppUi: 00078 //AppUi()->ProcessCommandL(aCommandL); 00079 00080 switch (aCommand) 00081 { 00082 case ECalendarAPIexampleCmdDelete: 00083 DoDeleteL(); 00084 break; 00085 case EAknSoftkeyDone: 00086 DoSaveL(); 00087 break; 00088 default: 00089 break; 00090 } 00091 } 00092 00093 // ---------------------------------------------------- 00094 // CCalendarAPIexampleEntryView::DoActivateL() 00095 // Gets called when the view is activated. Creates 00096 // the entry container, adds it to view control stack 00097 // and sets it visible. 00098 // ---------------------------------------------------- 00099 // 00100 void CCalendarAPIexampleEntryView::DoActivateL( 00101 const TVwsViewId& /*aPrevViewId*/, 00102 TUid /*aCustomMessageId*/, 00103 const TDesC8& /*aCustomMessage*/ ) 00104 { 00105 if ( !iContainer ) 00106 { 00107 00108 TBuf<KMaxNameLength> name; 00109 TTime date; 00110 TBool alarm; 00111 TTime alarmTime; 00112 TInt synchronizationMethod; 00113 00114 iEngine.CreateEntryForModificationL(iModify); 00115 00116 iEngine.GetValuesToSet(name,date,alarm,alarmTime, 00117 synchronizationMethod); 00118 00119 iContainer = CCalendarAPIexampleEntryContainer::NewL( 00120 ClientRect(),name,date.DateTime(),alarm,alarmTime.DateTime(), 00121 synchronizationMethod); 00122 00123 iContainer->SetMopParent(this); 00124 00125 // Adds Container to View control stack. 00126 AppUi()->AddToStackL( *this, iContainer ); 00127 00128 // Requires to display the default screen. 00129 iContainer->MakeVisible( ETrue ); 00130 } 00131 } 00132 00133 // ---------------------------------------------------- 00134 // CCalendarAPIexampleEntryView::DoDeactivate() 00135 // Gets called when the view is deactivated. Removes 00136 // the entry container from view control stack and 00137 // deletes it. 00138 // ---------------------------------------------------- 00139 // 00140 void CCalendarAPIexampleEntryView::DoDeactivate() 00141 { 00142 if ( iContainer ) 00143 { 00144 // Removes Container from View control stack. 00145 AppUi()->RemoveFromStack(iContainer ); 00146 } 00147 00148 delete iContainer; 00149 iContainer = NULL; 00150 00151 } 00152 00153 // ---------------------------------------------------- 00154 // CCalendarAPIexampleEntryView::DoSaveL() 00155 // Requests the model to save the current entry. If user 00156 // input is invalid, an information note about it is 00157 // shown. Otherwise a proper view is activated. 00158 // ---------------------------------------------------- 00159 // 00160 void CCalendarAPIexampleEntryView::DoSaveL() 00161 { 00162 TBuf<KMaxNameLength> name; 00163 TTime date; 00164 TBool alarm; 00165 TTime alarmTime; 00166 TInt sync; 00167 00168 iContainer->SaveL(); 00169 00170 //Get the values which user has set to these variables 00171 iContainer->GetValues( name, date, alarm, 00172 alarmTime, sync ); 00173 00174 00175 TDateTime dateTime = date.DateTime(); 00176 TDateTime alarmDateTime = alarmTime.DateTime(); 00177 00178 TBool valuesOk = iEngine.SetValuesToNewEntry(name,dateTime,alarm, 00179 alarmDateTime,sync); 00180 00181 // User input invalid, show an information note about it. 00182 if ( !valuesOk ) 00183 { 00184 CAknInformationNote* note = new (ELeave) CAknInformationNote; 00185 HBufC* errorMsg = CCoeEnv::Static()->AllocReadResourceLC( 00186 R_CALENDARAPIEXAMPLE_INVALID_DATA); 00187 note->ExecuteLD(*errorMsg); 00188 CleanupStack::PopAndDestroy(errorMsg); 00189 } 00190 // User input valid. 00191 else 00192 { 00193 iEngine.DoSaveL(); 00194 00195 // We were modifying entry, activate entries view or search view 00196 if (iModify) 00197 { 00198 // After modification, entries still exist in the 00199 // given search range, activate entries view. 00200 if (iEngine.EntryCount() > 0) 00201 { 00202 AppUi()->ActivateLocalViewL(KEntriesViewId); 00203 } 00204 // After modification, no entries exist anymore in the 00205 // given search range, activate search view. 00206 else 00207 { 00208 AppUi()->ActivateLocalViewL(KSearchViewId); 00209 } 00210 } 00211 // We were adding an entry, activate search view. 00212 else 00213 { 00214 AppUi()->ActivateLocalViewL(KSearchViewId); 00215 } 00216 } 00217 } 00218 00219 // ---------------------------------------------------- 00220 // CCalendarAPIexampleEntryView::DoDeleteL() 00221 // Deletes the entry and activates a proper view. 00222 // ---------------------------------------------------- 00223 // 00224 void CCalendarAPIexampleEntryView::DoDeleteL() 00225 { 00226 00227 CAknQueryDialog* query = CAknQueryDialog::NewL(); 00228 CleanupStack::PushL(query); 00229 query->SetPromptL(KDeleteConfirmation); 00230 CleanupStack::Pop(query); 00231 if (query->ExecuteLD(R_CALENDARAPIEXAMPLE_CONFIRMATION_QUERY)) 00232 { 00233 // if we are modifying an entry, delete it and open a proper view 00234 if (iModify) 00235 { 00236 iEngine.ExecuteDeletionL(); 00237 } 00238 // no need for deletion, because the new entry is not yet saved. 00239 else 00240 { 00241 AppUi()->ActivateLocalViewL(KSearchViewId); 00242 } 00243 } 00244 } 00245 00246 00247 // End of File
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.