examples/SFExamples/PIM/ContactAddNew/src/ContactWrite.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 "ContactWrite.h"
00018 
00019 CContactWrite* CContactWrite::NewL()
00020         {
00021         CContactWrite* self = new (ELeave) CContactWrite();
00022         CleanupStack::PushL(self);
00023         self->ConstructL();
00024         CleanupStack::Pop(self);
00025         return self;
00026         }
00027 
00028 CContactWrite::~CContactWrite()
00029         {
00030         delete iCntDb;
00031         }
00032 
00033 void CContactWrite::ConstructL()
00034         {
00035         TRAPD(error, iCntDb = CContactDatabase::OpenL());
00036         if (KErrNotFound == error)
00037                 {
00038                 iCntDb = CContactDatabase::CreateL();
00039                 }
00040         else
00041                 {
00042                 User::LeaveIfError(error);
00043                 }
00044         }
00045 
00046 CContactDatabase& CContactWrite::CntDatabase()
00047         {
00048         return *iCntDb;
00049         }
00050 
00051 void CContactWrite::AddCardL(const TDesC& aFirstName, const TDesC& aLastName,
00052                                                                                                                 const TDesC& aPhone)
00053         {
00054         CContactCard* contactCard = CContactCard::NewLC();
00055 
00056         CContactItemField* firstName = CContactItemField::NewLC(KStorageTypeText);
00057         firstName->AddFieldTypeL(KUidContactFieldGivenName);
00058         firstName->TextStorage()->SetTextL(aFirstName);
00059         contactCard->AddFieldL(*firstName);
00060         CleanupStack::Pop(firstName);
00061 
00062         CContactItemField* lastName = CContactItemField::NewLC(KStorageTypeText);
00063         lastName->AddFieldTypeL(KUidContactFieldFamilyName);
00064         lastName->TextStorage()->SetTextL(aLastName);
00065         contactCard->AddFieldL(*lastName);
00066         CleanupStack::Pop(lastName);
00067 
00068         CContactItemField* phone = CContactItemField::NewLC(KStorageTypeText);
00069         phone->AddFieldTypeL(KUidContactFieldPhoneNumber);
00070         phone->TextStorage()->SetTextL(aPhone);
00071         contactCard->AddFieldL(*phone);
00072         CleanupStack::Pop(phone);
00073 
00074         iCntDb->AddNewContactL( *contactCard );
00075 
00076         CleanupStack::PopAndDestroy(contactCard);
00077         }
00078 
00079 
00080 // End of File

Generated by  doxygen 1.6.2