📄 mguardpimmgr.cpp,v
字号:
head 1.4;access;symbols v1_0:1.1.1.3 xueyw:1.1.1 v111:1.1.1.2 MGuard:1.1.1 arelease:1.1.1.1 avendor:1.1.1;locks; strict;comment @// @;1.4date 2007.08.22.11.16.50; author administrator; state Exp;branches;next 1.3;deltatype text;permissions 644;commitid 16046cc1b22345d;kopt kv;filename @MGuardPIMMgr.cpp@;1.3date 2007.08.08.13.50.26; author administrator; state Exp;branches;next 1.2;deltatype text;permissions 644;commitid fbc46b9ca21640d;kopt kv;filename @MGuardPIMMgr.cpp@;1.2date 2007.07.30.13.22.20; author administrator; state Exp;branches;next 1.1;deltatype text;permissions 644;commitid 90c46ade60b0f58;kopt kv;filename @MGuardPIMMgr.cpp@;1.1date 2007.07.24.10.59.30; author administrator; state Exp;branches 1.1.1.1;next ;deltatype text;permissions 644;1.1.1.1date 2007.07.24.10.59.30; author administrator; state Exp;branches;next 1.1.1.2;deltatype text;permissions 644;1.1.1.2date 2007.08.22.11.31.31; author administrator; state Exp;branches;next 1.1.1.3;deltatype text;permissions 644;commitid 81046cc1e913f93;kopt kv;filename @MGuardPIMMgr.cpp@;1.1.1.3date 2007.10.05.14.06.53; author administrator; state Exp;branches;next ;deltatype text;permissions 644;commitid 894470644fb2457;kopt kv;filename @MGuardPIMMgr.cpp@;desc@@1.4log@new AddContact methods1. the original method doesn't work well, The phone restart if the user press the newly added contact2. The new methods doesn't have this issue@text@/** ============================================================================* Name : CMGuardPIMMgr from MGuardPIMMgr.h* Part of : MGuardPIMMgr* Created : 18.07.2007 by xueyw* Description:* CMGuardPIMMgr DLL source* Version :* Copyright: * ============================================================================*/// Include Files #include "MGuardPIMMgr.h" // CMGuardPIMMgr#include <cntitem.h>#include <cntfield.h>#include <cntfldst.h>#include <cpbkcontactengine.h> #include <cpbkcontactitem.h> #include <tpbkcontactitemfield.h> #include <cpbkfieldsinfo.h> // Member FunctionsCMGuardPIMMgr* CMGuardPIMMgr::NewLC() { CMGuardPIMMgr* self = new (ELeave) CMGuardPIMMgr; CleanupStack::PushL(self); self->ConstructL(); return self; }CMGuardPIMMgr* CMGuardPIMMgr::NewL() { CMGuardPIMMgr* self = CMGuardPIMMgr::NewLC(); CleanupStack::Pop(self); return self; }CMGuardPIMMgr::CMGuardPIMMgr()// note, CBase initialises all member variables to zero { }void CMGuardPIMMgr::ConstructL() { iContactDB = CContactDatabase::OpenL( ); }CMGuardPIMMgr::~CMGuardPIMMgr() { delete iContactDB; }TBool CMGuardPIMMgr::AddContact( TDesC& aName, TDesC& aTel, TDesC& aAddr ){ CPbkContactEngine* engine = CPbkContactEngine::NewL(); CleanupStack::PushL( engine ); // Create a contact with few default fields // All the default fields are empty and won't be displayed // until some information is stored in them CPbkContactItem* contact = engine->CreateEmptyContactL(); CleanupStack::PushL( contact ); // Set some default fields contact->FindField( EPbkFieldIdFirstName )->TextStorage()->SetTextL( _L("(MGuard)") ); contact->FindField( EPbkFieldIdLastName )->TextStorage()->SetTextL( aName ); contact->FindField( EPbkFieldIdPhoneNumberMobile )->TextStorage()->SetTextL( aTel ); // Create and set a non-default field CPbkFieldInfo* fieldInfo = engine->FieldsInfo().Find( EPbkFieldIdCountry ); contact->AddFieldL( *fieldInfo ); TPbkContactItemField* field = contact->FindField( EPbkFieldIdCountry ); field->TextStorage()->SetTextL( aAddr ); // Store the contact to the phonebook engine->AddNewContactL( *contact ); CleanupStack::PopAndDestroy( contact ); CleanupStack::PopAndDestroy( engine ); return ETrue;} //TBool CMGuardPIMMgr::ModifyContact()//{// CContactItem* ownCard = iContactDb->OpenContactL( ownCardId );// // CleanupStack::PushL( ownCard );// // TInt index = ownCard->CardFields().Find( KUidContactFieldGivenName );// // ownCard->CardFields()[index].TextStorage()->SetTextL(KOtherForename);// // contactsDb->CommitContactL(*ownCard);// // CleanupStack::PopAndDestroy( ownCard );////}// //TBool CMGuardPIMMgr::FindContact()// {// 6、数据库查询// // 所用的函数有:// // CContactDatabase::FindLC() ;// // CContactDatabase::FindInTextDefLC();. // // FindInTextDefLC() ;// // FindInTextDefAsyncL();// // 例1、 FindInTextDefAsyncL()的应用:// // iContactsDb = CContactDatabase::OpenL();// // iFieldDef = new (ELeave)CContactItemFieldDef();// // iFieldDef->AppendL(KUidContactFieldGivenName);// // iFieldDef->AppendL(KUidContactFieldFamilyName);// // _LIT(KFindToken, "Bond");// // iFinder = // // iContactsDb->FindAsyncL( KFindToken, iFieldDef, this);// // if(iFinder->IsComplete())// // {// // if(iFinder->Error() == KErrNone)// // {// // CContactIdArray* result = iFinder->TakeContactIds();// // for(TInt i=0; i<result->Count(); i++)// // {// // TInt cardId = (*result)[i];// // // do something with the card// // }// // delete result;// // }// // delete iFinder;// // delete iFieldDef;// // delete iContactsDb;// // }// // // 3、从数据库中读出数据// // CContactDatabase* contactsDb = CContactDatabase::OpenL();// // CleanupStack::PushL(contactsDb);// // // Get the ID of the own card and open the contact:// // TContactItemId ownCardId = contactsDb->OwnCardId();// // CContactItem* ownCard = contactsDb->ReadContactL(ownCardId);// // CleanupStack::PushL(ownCard);// // TInt count = ownCard->CardFields().Count();// // contactsDb->CloseContactL(ownCard->Id());// // CleanupStack::PopAndDestroy(); // ownCard// }// //TBool CMGuardPIMMgr::RemoveContact()// {//// } TBool CMGuardPIMMgr::RemoveAllContacts(){ TContactIter iter( *iContactDB );//建立遍历对象 TContactItemId cardId; while( ( cardId = iter.NextL() ) != KNullContactId ) { iContactDB->DeleteContactL( cardId ); } return ETrue;}// End of file@1.3log@add contact support (chs support)@text@d19 4d61 1a61 1TBool CMGuardPIMMgr::AddContact( TBuf<50>& aName, TBuf<50>& aTel, TBuf<50>& aAddr )d63 26a88 52 if ( !iContactDB ) { return EFalse; } // _LIT(KForenameLabel,"Forename"); _LIT(KSurnameLabel,"Surname"); _LIT(KWorkPhoneLabel,"Telephone"); // Create a contact item CContactCard* contact = CContactCard::NewLC(); CContactItemField* field = CContactItemField::NewLC( KStorageTypeText, KUidContactFieldFamilyName ); // Set vCard mapping field->SetMapping( KUidContactFieldVCardMapUnusedN ); // Set field label field->SetLabelL( KSurnameLabel ); // Set fields value field->TextStorage()->SetTextL( aName ); // Add filed into the contact item contact->AddFieldL( *field ); // Pop field from cleanup stack CleanupStack::Pop(); // Add GivenName field// field = CContactItemField::NewLC( KStorageTypeText, KUidContactFieldGivenName );// field->SetMapping( KUidContactFieldVCardMapUnusedN) ; // field->SetLabelL( KForenameLabel );// field->TextStorage()->SetTextL( KForename );// contact->AddFieldL(*field);// CleanupStack::Pop(); // Add phonenumber field field = CContactItemField::NewLC( KStorageTypeText, KUidContactFieldPhoneNumber ); field->SetMapping( KUidContactFieldVCardMapTEL ); field->SetLabelL( KWorkPhoneLabel ); field->TextStorage()->SetTextL( aTel ); contact->AddFieldL(*field); CleanupStack::Pop(); // Add contact to DB iContactDB->AddNewContactL( *contact ); iContactDB->SetOwnCardL( *contact ); // Popup and destroy contact object CleanupStack::PopAndDestroy( 1 ); @1.2log@no message@text@d57 1a57 1TBool CMGuardPIMMgr::AddContact()d64 1a64 1 _LIT(KForenameLabel,"Forename");d68 2a69 10// _LIT(KWorkPhoneLabel,"电话"); _LIT(KForename,"Steve"); // _LIT(KOtherForename,"Bob"); _LIT(KSurname,"Wilkinson"); _LIT(KWorkPhone,"+441617779700"); d80 1a80 1 field->TextStorage()->SetTextL( KSurname );d88 6a93 6 field = CContactItemField::NewLC( KStorageTypeText, KUidContactFieldGivenName ); field->SetMapping( KUidContactFieldVCardMapUnusedN) ; field->SetLabelL( KForenameLabel ); field->TextStorage()->SetTextL( KForename ); contact->AddFieldL(*field); CleanupStack::Pop();d99 2a100 2 field->SetLabelL( _L("你好") ); field->TextStorage()->SetTextL( KWorkPhone );@1.1log@Initial revision@text@d16 3a18 2#include "MGuardPIMMgr.pan" // panic codesd22 1a22 1EXPORT_C CMGuardPIMMgr* CMGuardPIMMgr::NewLC()d31 1a31 1EXPORT_C CMGuardPIMMgr* CMGuardPIMMgr::NewL()d47 1a47 8 // second phase constructor, anything that may leave must be constructed here iString = new (ELeave) TMGuardPIMMgrExampleString; }EXPORT_C CMGuardPIMMgr::~CMGuardPIMMgr() { delete iString;d51 1a51 1EXPORT_C TVersion CMGuardPIMMgr::Version() constd53 1a53 5 // Version number of example API const TInt KMajor = 1; const TInt KMinor = 0; const TInt KBuild = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -