examples/ForumNokia/CalendarExample/src/CalendarAPIexampleSearchView.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 
00031 // INCLUDE FILES
00032 #include <avkon.hrh>
00033 #include <aknviewappui.h>
00034 #include <aknnotewrappers.h> //CAknInformationNote
00035 #include <CalendarAPIexample.rsg>
00036 #include "CalendarAPIexampleSearchView.h"
00037 #include "CalendarAPIexampleSearchContainer.h"
00038 #include "CalendarAPIexample.hrh"
00039 #include "CalendarAPIexampleEntryView.h"
00040 #include "CalendarAPIexampleEntriesView.h"
00041 #include "CalendarAPIexampleDocument.h"
00042 
00043 // ================= MEMBER FUNCTIONS =======================
00044 
00045 // Two-phased constructor.
00046 CCalendarAPIexampleSearchView* CCalendarAPIexampleSearchView::NewL(MCalendarEngineCommandsInterface& aEngine)
00047     {
00048     CCalendarAPIexampleSearchView* self = CCalendarAPIexampleSearchView::NewLC(aEngine);
00049     CleanupStack::Pop(self);
00050     return self;
00051     }
00052 
00053 // Two-phased constructor.
00054 CCalendarAPIexampleSearchView* CCalendarAPIexampleSearchView::NewLC(MCalendarEngineCommandsInterface& aEngine)
00055     {
00056     CCalendarAPIexampleSearchView* self = new (ELeave) CCalendarAPIexampleSearchView(aEngine);
00057     CleanupStack::PushL(self);
00058     self->ConstructL();
00059     return self;
00060     }
00061     
00062 // destructor
00063 CCalendarAPIexampleSearchView::~CCalendarAPIexampleSearchView()
00064     {
00065     delete iContainer;
00066     iContainer = NULL;
00067     }
00068 
00069 
00070 CCalendarAPIexampleSearchView::CCalendarAPIexampleSearchView(
00071     MCalendarEngineCommandsInterface& aEngine) : iEngine(aEngine)
00072     {
00073     }
00074 
00075 
00076 // Symbian OS default constructor can leave.    
00077 void CCalendarAPIexampleSearchView::ConstructL()
00078     {
00079     BaseConstructL(R_CALENDARAPIEXAMPLE_SEARCH_VIEW);
00080     }
00081     
00082 // ----------------------------------------------------
00083 // CCalendarAPIexampleSearchView::Id()
00084 // Returns ID of View
00085 // ----------------------------------------------------
00086 //  
00087 TUid CCalendarAPIexampleSearchView::Id() const
00088     {
00089     return KSearchViewId;
00090     }
00091 
00092 // ----------------------------------------------------
00093 // CCalendarAPIexampleSearchView::HandleCommandL()
00094 // Takes care of command handling
00095 // ----------------------------------------------------
00096 //      
00097 void CCalendarAPIexampleSearchView::HandleCommandL( TInt aCommand )
00098     {
00099     switch (aCommand)
00100         {
00101         case EAknSoftkeyExit:
00102             AppUi()->ProcessCommandL(EAknCmdExit);
00103             break;
00104             
00105         case ECalendarAPIexampleCmdAdd:
00106             DoAddL();
00107             break;
00108         case ECalendarAPIexampleCmdSearch:
00109             DoSearchL();            
00110             break;
00111             
00112         default:
00113             break;
00114         }
00115     }
00116  
00117 // ----------------------------------------------------
00118 // CCalendarAPIexampleSearchView::DoActivateL()
00119 // Gets called when the view is activated. Creates 
00120 // the search container, adds it to view control stack
00121 // and sets it visible.
00122 // ----------------------------------------------------
00123 //  
00124 void CCalendarAPIexampleSearchView::DoActivateL(
00125                                         const TVwsViewId& /*aPrevViewId*/,
00126                                         TUid /*aCustomMessageId*/,
00127                                         const TDesC8& /*aCustomMessage*/ )
00128     {
00129     if ( !iContainer )
00130         {
00131         iContainer = CCalendarAPIexampleSearchContainer::NewL(
00132                                                     ClientRect(),*this);
00133         iContainer->SetMopParent(this);
00134 
00135         // Adds Container to View control stack.
00136         AppUi()->AddToStackL( *this, iContainer );
00137 
00138         // Requires to display the default screen.
00139         iContainer->MakeVisible( ETrue );        
00140         }       
00141     }
00142     
00143 // ----------------------------------------------------
00144 // CCalendarAPIexampleSearchView::DoDeactivate()
00145 // Gets called when the view is deactivated. Removes
00146 // the search container from view control stack and
00147 // deletes it.
00148 // ----------------------------------------------------
00149 //      
00150 void CCalendarAPIexampleSearchView::DoDeactivate()
00151     {
00152     if ( iContainer )
00153         {
00154         // Removes Container from View control stack.
00155         AppUi()->RemoveFromStack( iContainer );
00156         }
00157 
00158     delete iContainer;
00159     iContainer = NULL;
00160     
00161     }
00162     
00163 // ----------------------------------------------------
00164 // CCalendarAPIexampleSearchView::DoSearchL()
00165 // Requests the model to do an entry search. If no 
00166 // entries were found, an information note about it is
00167 // displayed. If entries were found, entries view is
00168 // activated.
00169 // ----------------------------------------------------
00170 //      
00171 void CCalendarAPIexampleSearchView::DoSearchL()
00172     {
00173     TSearchType type = iContainer->SearchType();
00174     
00175     iEngine.DoSearchL(type);
00176     
00177     // No entries found, display information note.
00178     if (0 >= iEngine.EntryCount())
00179         {
00180         CAknInformationNote* note = new (ELeave) CAknInformationNote;
00181         HBufC* errorMsg = CCoeEnv::Static()->AllocReadResourceLC(
00182                                     R_CALENDARAPIEXAMPLE_NO_ENTRIES_FOUND);
00183                                     
00184         note->ExecuteLD(*errorMsg);
00185         CleanupStack::PopAndDestroy(errorMsg);
00186         }
00187     // Entries found, activate entries view
00188     else
00189         {
00190         AppUi()->ActivateLocalViewL(KEntriesViewId);        
00191         }
00192     }
00193 
00194 // ----------------------------------------------------
00195 // CCalendarAPIexampleSearchView::DoAddL()
00196 // Resets models modify index, so that next call to 
00197 // models EntryForModifycation will create a new entry.
00198 // Activates the entry view.
00199 // ----------------------------------------------------
00200 //      
00201 void CCalendarAPIexampleSearchView::DoAddL()
00202     {
00203     iEngine.DoAddL();
00204     }
00205     
00206 // End of file

Generated by  doxygen 1.6.2