examples/SFExamples/PIM/ContactStandard/src/ContactStandardAppUi.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 <ContactStandard.rsg>
00019 
00020 #include "ContactStandardAppUi.h"
00021 #include "ContactStandardMainView.h"
00022 #include "ContactWrite.h"
00023 #include "ContactStandard.hrh"
00024 #include <S32MEM.H> // for descriptor-backed streams.
00025 
00026 void CContactStandardAppUi::ConstructL()
00027         {
00028         BaseConstructL(EAknEnableSkin);
00029         iMainView = CContactStandardMainView::NewL(ClientRect());
00030 
00031         iContactWriter = CContactWrite::NewL();
00032         }
00033         
00034 CContactStandardAppUi::~CContactStandardAppUi()
00035         {
00036         delete iContactWriter;
00037 #ifdef __SERIES60_3X__
00038         delete iMainView;
00039 #endif
00040         }
00041 
00042 void CContactStandardAppUi::HandleCommandL(TInt aCommand)
00043         {
00044         switch ( aCommand )
00045                 {
00046 #ifdef __SERIES60_3X__
00047                 case EAknSoftkeyExit:
00048 #endif
00049                 case EEikCmdExit:
00050                         {
00051                         User::Exit(0);
00052                         break;
00053                         }
00054                 case EContactStandard:
00055                         {
00056                         CContactDatabase& cntDb = iContactWriter->CntDatabase();
00057                         TContactItemId cntId = cntDb.OwnCardId();
00058                         // this is just one easy way to get a TContactItemId.
00059                         // the \PIM\PopulateContact sample code would have created
00060                         // an own card
00061 
00062                         if (KNullContactId != cntId)
00063                                 {
00064                                 // let's make a descriptor-backed stream.
00065                                 // 4Kb should be enough to hold most picture-free contact cards.
00066                                 HBufC8* buffer = HBufC8::NewLC(4096);
00067                                 TPtr8 bufferPtr = buffer->Des();
00068 
00069                                 RDesWriteStream writeStream(bufferPtr);
00070                                 TRAPD(error, iContactWriter->ExportContactL(cntId, writeStream));
00071                                 writeStream.Close();
00072 
00073                                 // report error on the Label control
00074                                 if (KErrNone == error)
00075                                         {
00076                                         // make a read stream to re-import the contact
00077                                         // from the descriptor
00078 
00079                                         RDesReadStream readStream(*buffer);
00080                                         TRAP(error, iContactWriter->ImportContactL(readStream));
00081                                         readStream.Close();
00082 
00083                                         if (KErrNone == error)
00084                                                 {
00085                                                 _LIT(KSuccess, "It Worked!");
00091                                                 iMainView->SetTextL(KSuccess());
00092                                                 }
00093                                         }
00094                                 if (KErrNone != error)
00095                                         {
00096                                         _LIT(KErrorMsg, "Symbian Error Code = %D");
00097                                         TBuf<32> errorBuf;
00098                                         errorBuf.Format(KErrorMsg(), error);
00099                                         iMainView->SetTextL(errorBuf);
00100                                         }
00101                                 CleanupStack::PopAndDestroy(buffer);
00102                                 }
00103                         else
00104                                 {
00105                                 _LIT(KNotFound, "No Own Card");
00106                                 iMainView->SetTextL(KNotFound());
00107                                 }
00108                         break;
00109                         }
00110                 default:
00111                         break;
00112                 }
00113         }
00114 
00115         
00116 #ifdef __SERIES60_3X__
00117 
00118 void CContactStandardAppUi::HandleResourceChangeL(TInt aType)
00119         {
00120         CAknAppUi::HandleResourceChangeL(aType);
00121         iMainView->SetRect(ClientRect());
00122         }
00123 
00124 #endif
00125         
00126 // End of File

Generated by  doxygen 1.6.2