examples/SFExamples/PIM/ContactSort/src/ContactSortAppUi.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 #include <eikapp.h>
00018 #include <ContactSort.rsg>
00019 
00020 #include "ContactSortAppUi.h"
00021 #include "ContactSortMainView.h"
00022 #include "ContactRead.h"
00023 #include "ContactSort.hrh"
00024 
00025 void CContactSortAppUi::ConstructL()
00026         {
00027         BaseConstructL(EAknEnableSkin);
00028         iMainView = CContactSortMainView::NewL(ClientRect());
00029 
00030         iContactReader = CContactRead::NewL();
00031         }
00032         
00033 CContactSortAppUi::~CContactSortAppUi()
00034     {
00035     delete iContactReader;
00036 #ifdef __SERIES60_3X__
00037         delete iMainView;
00038 #endif
00039     }
00040 
00041 void CContactSortAppUi::HandleCommandL(TInt aCommand)
00042         {
00043         switch ( aCommand )
00044                 {
00045 #ifdef __SERIES60_3X__
00046                 case EAknSoftkeyExit:
00047 #endif
00048                 case EEikCmdExit:
00049                         {
00050                         User::Exit(0);
00051                         break;
00052                         }
00053                 case EContactSort:
00054                         {
00055                         // \PIM\PopulateContact should have created at least 3 cards
00056                         // with both first names and last names.
00057                         CContactIdArray* result = NULL;
00058                         TRAPD(error, result = iContactReader->SortByNameL());
00059                         // report result on the Label control
00060                         if (KErrNone == error)
00061                                 {
00062                                 CleanupStack::PushL(result);
00063                                 TBuf<256> textBuf;
00064                                 _LIT(KPrefix, "success :");
00065                                 _LIT(KNoName, "NoName");
00066                                 textBuf.Append(KPrefix());
00067                                 for (TInt ii = 0; ii < result->Count() && ii < 3; ++ii)
00068                                         {
00069                                         CDesCArray* last = iContactReader->ReadTextFieldL((*result)[ii], KUidContactFieldFamilyName);
00070                                         CleanupStack::PushL(last);
00071                                         CDesCArray* first = iContactReader->ReadTextFieldL((*result)[ii], KUidContactFieldGivenName);
00072                                         if (last->Count() > 0)
00073                                                 textBuf.Append(last->MdcaPoint(0));
00074                                         else
00075                                                 textBuf.Append(KNoName());
00076                                         if (first->Count() > 0)
00077                                                 textBuf.Append(first->MdcaPoint(0));
00078                                         else
00079                                                 textBuf.Append(KNoName());
00080                                         delete first;
00081                                         CleanupStack::PopAndDestroy(last);
00082                                         }
00083                                 CleanupStack::PopAndDestroy(result);
00084                                 iMainView->SetTextL(textBuf);
00085                                 }
00086                         else
00087                                 {
00088                                 _LIT(KErrorMsg, "Symbian Error Code = %D");
00089                                 TBuf<32> errorBuf;
00090                                 errorBuf.Format(KErrorMsg(), error);
00091                                 iMainView->SetTextL(errorBuf);
00092                                 }
00093                         break;
00094                         }
00095                 default:
00096                         break;
00097                 }
00098         }
00099 
00100         
00101 #ifdef __SERIES60_3X__
00102 
00103 void CContactSortAppUi::HandleResourceChangeL(TInt aType)
00104         {
00105         CAknAppUi::HandleResourceChangeL(aType);
00106         iMainView->SetRect(ClientRect());
00107         }
00108 
00109 #endif
00110         
00111 // End of File

Generated by  doxygen 1.6.2