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

Generated by  doxygen 1.6.2