examples/ForumNokia/CalendarExample/src/CalendarAPIexampleEntriesView.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 // INCLUDE FILES
00006 #include <aknviewappui.h>
00007 #include <AknQueryDialog.h> // CAknQueryDialog
00008 #include <CalendarAPIexample.rsg>
00009 #include "CalendarAPIexampleEntriesView.h"
00010 #include "CalendarAPIexampleEntriesContainer.h"
00011 #include "CalendarAPIexample.hrh"
00012 #include "CalendarAPIexampleSearchView.h"
00013 #include "CalendarAPIexampleEntryView.h"
00014 #include "CalendarAPIexampleDocument.h"
00015 
00016 // CONSTANTS
00017 _LIT(KDeleteConfirmation, "Delete the selected anniversary?");
00018 
00019 // ================= MEMBER FUNCTIONS =======================
00020 
00021 
00022 // Two-phased constructor.
00023 CCalendarAPIexampleEntriesView* CCalendarAPIexampleEntriesView::NewL(MCalendarEngineCommandsInterface& aEngine)
00024     {
00025     CCalendarAPIexampleEntriesView* self = CCalendarAPIexampleEntriesView::NewLC(aEngine);
00026     CleanupStack::Pop(self);
00027     return self;
00028     }
00029 
00030 // Two-phased constructor.
00031 CCalendarAPIexampleEntriesView* CCalendarAPIexampleEntriesView::NewLC(MCalendarEngineCommandsInterface& aEngine)
00032     {
00033     CCalendarAPIexampleEntriesView* self = new (ELeave) CCalendarAPIexampleEntriesView(aEngine);
00034     CleanupStack::PushL(self);
00035     self->ConstructL();
00036     return self;
00037     }
00038 
00039 
00040 CCalendarAPIexampleEntriesView::CCalendarAPIexampleEntriesView(
00041     MCalendarEngineCommandsInterface& aEngine) : iEngine(aEngine)
00042     {
00043        
00044     }
00045 
00046 
00047 
00048 // destructor
00049 CCalendarAPIexampleEntriesView::~CCalendarAPIexampleEntriesView()
00050     {
00051     delete iContainer;
00052     iContainer = NULL;
00053     }
00054     
00055 // Symbian OS default constructor can leave.
00056 void CCalendarAPIexampleEntriesView::ConstructL()
00057     {
00058     BaseConstructL(R_CALENDARAPIEXAMPLE_ENTRIES_VIEW);  
00059     }
00060     
00061 // ----------------------------------------------------
00062 // CCalendarAPIexampleEntriesView::Id()
00063 // Returns ID of View
00064 // ----------------------------------------------------
00065 //  
00066 TUid CCalendarAPIexampleEntriesView::Id() const
00067     {
00068     return KEntriesViewId;
00069     }
00070     
00071 // ----------------------------------------------------
00072 // CCalendarAPIexampleEntriesView::HandleCommandL()
00073 // Takes care of command handling
00074 // ----------------------------------------------------
00075 //  
00076 void CCalendarAPIexampleEntriesView::HandleCommandL( TInt aCommand )
00077     {
00078     switch (aCommand)
00079         {
00080         case ECalendarAPIexampleCmdEdit:
00081             DoEditL();
00082             break;
00083         case ECalendarAPIexampleCmdDelete:
00084             DoDeleteL();
00085             break;
00086         case EAknSoftkeyBack:
00087             AppUi()->ActivateLocalViewL(KSearchViewId);
00088             break;
00089         default:
00090             break;
00091         }
00092     }
00093     
00094 // ----------------------------------------------------
00095 // CCalendarAPIexampleEntriesView::DoActivateL()
00096 // Gets called when the view is activated. Creates 
00097 // the entries container, adds it to view control stack
00098 // and sets it visible.
00099 // ----------------------------------------------------
00100 //  
00101 void CCalendarAPIexampleEntriesView::DoActivateL(
00102                                         const TVwsViewId& /*aPrevViewId*/,
00103                                         TUid /*aCustomMessageId*/,
00104                                         const TDesC8& /*aCustomMessage*/ )
00105     {
00106     if ( !iContainer )
00107         {
00108         iContainer = CCalendarAPIexampleEntriesContainer::NewL(
00109                                                 ClientRect(), *this, iEngine);
00110         iContainer->SetMopParent(this);
00111 
00112         // Adds Container to View control stack.
00113         AppUi()->AddToStackL( *this, iContainer );
00114 
00115         // Requires to display the default screen.
00116         iContainer->MakeVisible( ETrue );        
00117         }       
00118     }
00119     
00120 // ----------------------------------------------------
00121 // CCalendarAPIexampleEntriesView::DoDeactivate()
00122 // Gets called when the view is deactivated. Removes
00123 // the entries container from view control stack and
00124 // deletes it.
00125 // ----------------------------------------------------
00126 //      
00127 void CCalendarAPIexampleEntriesView::DoDeactivate()
00128     {
00129     if ( iContainer )
00130         {
00131         // Removes Container from View control stack.
00132         AppUi()->RemoveFromStack(iContainer );
00133         }
00134 
00135     delete iContainer;
00136     iContainer = NULL;
00137     
00138     }    
00139 
00140 // ----------------------------------------------------
00141 // CCalendarAPIexampleEntriesView::DoDeleteL()
00142 // Deletes the selected entry. If the last entry in the
00143 // list was deleted, search view is activated, otherwise
00144 // list is reloaded.
00145 // ----------------------------------------------------
00146 //  Called from This views handleCommandL
00147 void CCalendarAPIexampleEntriesView::DoDeleteL()
00148     {
00149     CAknQueryDialog* query = CAknQueryDialog::NewL();
00150     CleanupStack::PushL(query);
00151     query->SetPromptL(KDeleteConfirmation);
00152     CleanupStack::Pop(query);
00153     if (query->ExecuteLD(R_CALENDARAPIEXAMPLE_CONFIRMATION_QUERY))
00154         {
00155         iEngine.DeleteEntryL(iContainer->CurrentItemIndex());
00156         
00157         // No more entries exist in the listbox, activate search view
00158         if (iEngine.EntryCount() == 0)
00159             {
00160             AppUi()->ActivateLocalViewL(KSearchViewId);
00161             }
00162         // reload listbox after deletion
00163         else
00164             {
00165             iContainer->PopulateListBoxL();
00166             }
00167         }
00168     }
00169 
00170 // ----------------------------------------------------
00171 // CCalendarAPIexampleEntriesView::DoEditL()
00172 // Tell model which entry is to be edited and activate
00173 // entry view.
00174 // ----------------------------------------------------
00175 //  
00176 void CCalendarAPIexampleEntriesView::DoEditL()
00177     {
00178     iEngine.SetModifyIndex(iContainer->CurrentItemIndex());
00179     AppUi()->ActivateLocalViewL(KEntryViewId);
00180     }
00181 
00182 // End of File

Generated by  doxygen 1.6.2