examples/ForumNokia/CalendarExample/src/CalendarAPIexampleEntryView.cpp

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 // INCLUDE FILES
00031 #include <aknviewappui.h>
00032 #include <aknnotewrappers.h> 
00033 #include <CalendarAPIexample.rsg> 
00034 //#include <Testapp.rsg>
00035 
00036 #include "CalendarAPIexampleEntryView.h"
00037 #include "CalendarAPIexampleEntryContainer.h"
00038 #include "CalendarAPIexampleEntriesView.h"
00039 #include "CalendarAPIexampleSearchView.h"
00040 
00041 #include "CalendarAPIexampleEngine.h"
00042 
00043 // CONSTANTS
00044 _LIT(KDeleteConfirmation, "Delete this anniversary?");
00045 
00046 // ================= MEMBER FUNCTIONS =======================
00047 
00048 // Two-phased constructor.
00049 CCalendarAPIexampleEntryView* CCalendarAPIexampleEntryView::NewL(MCalendarEngineCommandsInterface& aEngine)
00050     {
00051     CCalendarAPIexampleEntryView* self = CCalendarAPIexampleEntryView::NewLC(aEngine);
00052     CleanupStack::Pop(self);
00053     return self;
00054     }
00055 
00056 // Two-phased constructor.
00057 CCalendarAPIexampleEntryView* CCalendarAPIexampleEntryView::NewLC(MCalendarEngineCommandsInterface& aEngine)
00058     {
00059     CCalendarAPIexampleEntryView* self = new (ELeave) CCalendarAPIexampleEntryView(aEngine);
00060     CleanupStack::PushL(self);
00061     self->ConstructL();
00062     return self;
00063     }
00064 
00065 
00066 CCalendarAPIexampleEntryView::CCalendarAPIexampleEntryView(
00067     MCalendarEngineCommandsInterface& aEngine) : iEngine(aEngine)
00068     {
00069     
00070     }
00071 
00072 // destructor
00073 CCalendarAPIexampleEntryView::~CCalendarAPIexampleEntryView()
00074     {
00075     delete iContainer;
00076     iContainer = NULL;
00077     }
00078     
00079 // Symbian OS default constructor can leave.
00080 void CCalendarAPIexampleEntryView::ConstructL()
00081     {
00082     BaseConstructL(R_CALENDARAPIEXAMPLE_ENTRY_VIEW);
00083     }
00084     
00085 // ----------------------------------------------------
00086 // CCalendarAPIexampleEntryView::Id()
00087 // Returns ID of View
00088 // ----------------------------------------------------
00089 //  
00090 TUid CCalendarAPIexampleEntryView::Id() const
00091     {
00092     return KEntryViewId;
00093     }
00094     
00095 // ----------------------------------------------------
00096 // CCalendarAPIexampleEntryView::HandleCommandL()
00097 // Takes care of command handling
00098 // ----------------------------------------------------
00099 //          
00100 void CCalendarAPIexampleEntryView::HandleCommandL( TInt aCommand )
00101     {
00102     //If the command handling wouuld be given to AppUi:
00103     //AppUi()->ProcessCommandL(aCommandL);
00104     
00105     switch (aCommand)
00106         {
00107         case ECalendarAPIexampleCmdDelete:
00108             DoDeleteL();
00109             break;
00110         case EAknSoftkeyDone:
00111             DoSaveL();
00112             break;
00113         default:
00114             break;
00115         }
00116     }
00117 
00118 // ----------------------------------------------------
00119 // CCalendarAPIexampleEntryView::DoActivateL()
00120 // Gets called when the view is activated. Creates 
00121 // the entry container, adds it to view control stack
00122 // and sets it visible.
00123 // ----------------------------------------------------
00124 //      
00125 void CCalendarAPIexampleEntryView::DoActivateL(
00126                                     const TVwsViewId& /*aPrevViewId*/,
00127                                     TUid /*aCustomMessageId*/,
00128                                     const TDesC8& /*aCustomMessage*/ )
00129     {
00130     if ( !iContainer )
00131         {
00132         
00133         TBuf<KMaxNameLength> name;
00134         TTime date;
00135         TBool alarm;
00136         TTime alarmTime;
00137         TInt synchronizationMethod;
00138         
00139         iEngine.CreateEntryForModificationL(iModify);
00140         
00141         iEngine.GetValuesToSet(name,date,alarm,alarmTime,
00142                                synchronizationMethod);
00143         
00144         iContainer = CCalendarAPIexampleEntryContainer::NewL(
00145             ClientRect(),name,date.DateTime(),alarm,alarmTime.DateTime(),
00146             synchronizationMethod);
00147                                 
00148         iContainer->SetMopParent(this);
00149 
00150         // Adds Container to View control stack.
00151         AppUi()->AddToStackL( *this, iContainer );
00152 
00153         // Requires to display the default screen.
00154         iContainer->MakeVisible( ETrue );        
00155         }       
00156     }
00157 
00158 // ----------------------------------------------------
00159 // CCalendarAPIexampleEntryView::DoDeactivate()
00160 // Gets called when the view is deactivated. Removes
00161 // the entry container from view control stack and
00162 // deletes it.
00163 // ----------------------------------------------------
00164 //      
00165 void CCalendarAPIexampleEntryView::DoDeactivate()
00166     {
00167     if ( iContainer )
00168         {
00169         // Removes Container from View control stack.
00170         AppUi()->RemoveFromStack(iContainer );
00171         }
00172 
00173     delete iContainer;
00174     iContainer = NULL;
00175     
00176     }
00177 
00178 // ----------------------------------------------------
00179 // CCalendarAPIexampleEntryView::DoSaveL()
00180 // Requests the model to save the current entry. If user
00181 // input is invalid, an information note about it is 
00182 // shown. Otherwise a proper view is activated.
00183 // ----------------------------------------------------
00184 //      
00185 void CCalendarAPIexampleEntryView::DoSaveL()
00186     {
00187     TBuf<KMaxNameLength> name;
00188     TTime date;
00189     TBool alarm;
00190     TTime alarmTime;
00191     TInt sync;
00192 
00193     iContainer->SaveL();
00194 
00195     //Get the values which user has set to these variables
00196     iContainer->GetValues( name, date, alarm,
00197                                 alarmTime, sync );
00198 
00199     
00200     TDateTime dateTime = date.DateTime();
00201     TDateTime alarmDateTime = alarmTime.DateTime();
00202     
00203     TBool valuesOk = iEngine.SetValuesToNewEntry(name,dateTime,alarm,
00204                                                 alarmDateTime,sync);
00205 
00206     // User input invalid, show an information note about it.
00207     if ( !valuesOk )
00208         {
00209         CAknInformationNote* note = new (ELeave) CAknInformationNote;
00210         HBufC* errorMsg = CCoeEnv::Static()->AllocReadResourceLC(
00211                           R_CALENDARAPIEXAMPLE_INVALID_DATA);
00212         note->ExecuteLD(*errorMsg);
00213         CleanupStack::PopAndDestroy(errorMsg);
00214         }
00215     // User input valid.
00216     else
00217         {
00218         iEngine.DoSaveL();
00219 
00220         // We were modifying entry, activate entries view or search view
00221         if (iModify)
00222             {
00223             // After modification, entries still exist in the 
00224             // given search range, activate entries view.
00225             if (iEngine.EntryCount() > 0)
00226                 {
00227                 AppUi()->ActivateLocalViewL(KEntriesViewId);
00228                 }
00229             // After modification, no entries exist anymore in the 
00230             // given search range, activate search view.
00231             else
00232                 {
00233                 AppUi()->ActivateLocalViewL(KSearchViewId);                 
00234                 }
00235             }
00236         // We were adding an entry, activate search view.
00237         else
00238             {
00239             AppUi()->ActivateLocalViewL(KSearchViewId);
00240             }
00241         }
00242     }
00243 
00244 // ----------------------------------------------------
00245 // CCalendarAPIexampleEntryView::DoDeleteL()
00246 // Deletes the entry and activates a proper view.
00247 // ----------------------------------------------------
00248 //      
00249 void CCalendarAPIexampleEntryView::DoDeleteL()
00250     {
00251     
00252     CAknQueryDialog* query = CAknQueryDialog::NewL();
00253     CleanupStack::PushL(query);
00254     query->SetPromptL(KDeleteConfirmation);
00255     CleanupStack::Pop(query);
00256     if (query->ExecuteLD(R_CALENDARAPIEXAMPLE_CONFIRMATION_QUERY))
00257         {
00258         // if we are modifying an entry, delete it and open a proper view
00259         if (iModify)
00260             {
00261             iEngine.ExecuteDeletionL();
00262             }
00263         // no need for deletion, because the new entry is not yet saved.
00264         else
00265             {
00266             AppUi()->ActivateLocalViewL(KSearchViewId);
00267             }
00268         }
00269     }
00270 
00271 
00272 // End of File

Generated by  doxygen 1.6.2