/** * Create a new template and add it to the database * @param aDb Contact database * @param aTemplateName Name for the template * @param aFieldSet Array of fields which should are added to the template * @return TContactItemId Id of the newly created template */ TContactItemId CreatePhonebookTemplateL(CContactDatabase& aDb, const TDesC& aTemplateName, RArray<TFieldEntry>& aFieldSet) { CContactItem* temp = aDb.CreateContactCardTemplateLC(aTemplateName); TContactItemId templateId = temp->Id(); CleanupStack::PopAndDestroy(temp); temp=NULL; //Remove all the unnecessary fields temp = aDb.OpenContactLX(templateId); CleanupStack::PushL(temp); const TInt fieldCount = temp->CardFields().Count(); for(TInt i=fieldCount-1;i>=0;i--) temp->RemoveField(i); // Add each of the required fields to the template for (TInt j=0; j<aFieldSet.Count(); ++j) { TFieldEntry fieldEntry=aFieldSet[j]; CContactItemField* field = CContactItemField::NewLC(KStorageTypeText,fieldEntry.iField); if (fieldEntry.iFieldType!=KNullUid) field->AddFieldTypeL(fieldEntry.iFieldType); temp->AddFieldL(*field); CleanupStack::Pop(field); } aDb.CommitContactL(*temp); CleanupStack::PopAndDestroy(2); // temp, close template return templateId; }
QList<CContactItemField *> CntTransformPresence::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactPresence::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to presence const QContactPresence &presenceDetail(static_cast<const QContactPresence&>(detail)); HBufC* detailCount = HBufC::NewLC(KMaxDetailCounterLength); detailCount->Des().AppendNum(m_detailCounter); // Transform presence informaiton if(presenceDetail.presenceState() != QContactPresence::PresenceUnknown) { QString presence = QString::number(presenceDetail.presenceState()); CContactItemField* presenceField = CContactItemField::NewLC(KStorageTypeText); TPtrC presenceEncodedText(reinterpret_cast<const TUint16*>(presence.utf16())); presenceField->TextStorage()->SetTextL(presenceEncodedText); presenceField->AddFieldTypeL(KUidContactFieldPresence); presenceField->SetLabelL(*detailCount); fieldList.append(presenceField); CleanupStack::Pop(presenceField); } // Transform statusMessage TPtrC statusMsgText(reinterpret_cast<const TUint16*>(presenceDetail.presenceStateText().utf16())); if(statusMsgText.Length()) { CContactItemField* statusMsgField = CContactItemField::NewLC(KStorageTypeText); statusMsgField->TextStorage()->SetTextL(statusMsgText); statusMsgField->AddFieldTypeL(KUidContactFieldStatusMsg); statusMsgField->SetLabelL(*detailCount); fieldList.append(statusMsgField); CleanupStack::Pop(statusMsgField); } CleanupStack::PopAndDestroy(detailCount); if(fieldList.count() > 0) { m_detailCounter++; } return fieldList; }
QList<CContactItemField *> CntTransformPhoneNumber::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactPhoneNumber::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to phonenumber const QContactPhoneNumber &phoneNumber(static_cast<const QContactPhoneNumber&>(detail)); //get the subType QStringList subTypes = phoneNumber.subTypes(); //create new field TPtrC fieldText(reinterpret_cast<const TUint16*>(phoneNumber.number().utf16())); if(fieldText.Length()) { CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText); newField->TextStorage()->SetTextL(fieldText); //no subtype if(!subTypes.count()) { newField->AddFieldTypeL(KUidContactFieldPhoneNumber); newField->SetMapping(KUidContactFieldVCardMapTEL); } //landline else if (subTypes.contains(QContactPhoneNumber::SubTypeLandline)) { newField->AddFieldTypeL(KUidContactFieldPhoneNumber); newField->SetMapping(KUidContactFieldVCardMapTEL); newField->AddFieldTypeL(KUidContactFieldVCardMapVOICE); } //mobile else if (subTypes.contains(QContactPhoneNumber::SubTypeMobile)) { newField->AddFieldTypeL(KUidContactFieldPhoneNumber); newField->SetMapping(KUidContactFieldVCardMapTEL); newField->AddFieldTypeL(KUidContactFieldVCardMapCELL); } //fax else if (subTypes.contains(QContactPhoneNumber::SubTypeFax)) { newField->AddFieldTypeL(KUidContactFieldFax); newField->SetMapping(KUidContactFieldVCardMapTEL); newField->AddFieldTypeL(KUidContactFieldVCardMapFAX); } //pager else if (subTypes.contains(QContactPhoneNumber::SubTypePager)) { newField->AddFieldTypeL(KUidContactFieldPhoneNumber); newField->SetMapping(KUidContactFieldVCardMapTEL); newField->AddFieldTypeL(KUidContactFieldVCardMapPAGER); } //bbs else if (subTypes.contains(QContactPhoneNumber::SubTypeBulletinBoardSystem)) { newField->AddFieldTypeL(KUidContactFieldPhoneNumber); newField->SetMapping(KUidContactFieldVCardMapTEL); newField->AddFieldTypeL(KUidContactFieldVCardMapBBS); } //car else if (subTypes.contains(QContactPhoneNumber::SubTypeCar)) { newField->AddFieldTypeL(KUidContactFieldPhoneNumber); newField->SetMapping(KUidContactFieldVCardMapTEL); newField->AddFieldTypeL(KUidContactFieldVCardMapCAR); } //DTMF else if (subTypes.contains(QContactPhoneNumber::SubTypeDtmfMenu)) { newField->AddFieldTypeL(KUidContactFieldDTMF); newField->SetMapping(KUidContactFieldVCardMapUnknown); } // assistant number else if (subTypes.contains(QContactPhoneNumber::SubTypeAssistant)) { newField->AddFieldTypeL(KUidContactFieldPhoneNumber); newField->SetMapping(KUidContactFieldVCardMapAssistantTel); } // video calls else if (subTypes.contains(QContactPhoneNumber::SubTypeVideo)) { newField->AddFieldTypeL(KUidContactFieldPhoneNumber); newField->SetMapping(KUidContactFieldVCardMapTEL); newField->AddFieldTypeL(KUidContactFieldVCardMapVIDEO); } else { User::LeaveIfError(KErrNotSupported); } //contexts setContextsL(phoneNumber, *newField); fieldList.append(newField); CleanupStack::Pop(newField); } return fieldList; }
QList<CContactItemField *> CntTransformOnlineAccount::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactOnlineAccount::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to phonenumber const QContactOnlineAccount &onlineAccount(static_cast<const QContactOnlineAccount&>(detail)); //get the subType QStringList subTypes = onlineAccount.subTypes(); //create new field TPtrC fieldText(reinterpret_cast<const TUint16*>(onlineAccount.accountUri().utf16())); if(fieldText.Length()) { HBufC* detailCount = HBufC::NewLC(KMaxDetailCounterLength); detailCount->Des().AppendNum(m_detailCounter); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText); newField->TextStorage()->SetTextL(fieldText); //no subtype if(!subTypes.count()) { User::LeaveIfError(KErrArgument); } // online account else if (subTypes.contains(QContactOnlineAccount::SubTypeImpp)) { newField->AddFieldTypeL(KUidContactFieldIMPP); newField->SetMapping(KUidContactFieldVCardMapUnknown); } //internet else if (subTypes.contains(QContactOnlineAccount::SubTypeSipVoip)) { newField->AddFieldTypeL(KUidContactFieldSIPID); newField->SetMapping(KUidContactFieldVCardMapSIPID); newField->AddFieldTypeL(KUidContactFieldVCardMapVOIP); } //share video else if (subTypes.contains(QContactOnlineAccount::SubTypeVideoShare)) { newField->AddFieldTypeL(KUidContactFieldSIPID); newField->SetMapping(KUidContactFieldVCardMapSIPID); newField->AddFieldTypeL(KUidContactFieldVCardMapSWIS); } //sip else if (subTypes.contains(QContactOnlineAccount::SubTypeSip)) { newField->AddFieldTypeL(KUidContactFieldSIPID); newField->SetMapping(KUidContactFieldVCardMapSIPID); newField->AddFieldTypeL(KUidContactFieldVCardMapSIPID); } else { User::LeaveIfError(KErrNotSupported); } //contexts setContextsL(onlineAccount, *newField); newField->SetLabelL(*detailCount); fieldList.append(newField); CleanupStack::Pop(newField); // Transform Service Provider Text TPtrC ServiceProviderText(reinterpret_cast<const TUint16*>(onlineAccount.serviceProvider().utf16())); if(ServiceProviderText.Length()) { CContactItemField* serviceProviderField = CContactItemField::NewLC(KStorageTypeText); serviceProviderField->TextStorage()->SetTextL(ServiceProviderText); serviceProviderField->AddFieldTypeL(KUidContactFieldServiceProvider); serviceProviderField->SetLabelL(*detailCount); fieldList.append(serviceProviderField); CleanupStack::Pop(serviceProviderField); } CleanupStack::PopAndDestroy(detailCount); } if(fieldList.count() > 0) { m_detailCounter++; } return fieldList; }
static void PhonebookWriteReqL(PktBuf &in, PktBuf &out) { TUint16 memtype, ns, type, subtype; TUint32 location; CContactItem *item; CContactItemFieldSet *fieldset; CContactItemField *field; TBuf<64> name; TPtrC family_name, given_name; int i, s; g->InitPhoneBookL(); in >> memtype; in >> location; if (memtype != GN_MT_ME) { out << (TUint16)GNAPPLET_MSG_PHONEBOOK_WRITE_RESP; out << (TUint16)GN_ERR_INVALIDMEMORYTYPE; return; } fieldset = CContactItemFieldSet::NewLC(); in >> ns; for (i = 0; i < ns; i++) { in >> type >> subtype >> name; switch (type) { case GN_PHONEBOOK_ENTRY_Name: for (s = 0; s < name.Length() && name[s] != ' '; s++) ; if (s >= 1 && s < name.Length()) { family_name.Set(name.Ptr(), s); given_name.Set(name.Ptr() + s + 1, name.Length() - s - 1); } else { family_name.Set(name); } if (family_name.Length() > 0) { field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldFamilyName); //field->SetLabelL(_L("alma")); field->SetMapping(KUidContactFieldVCardMapUnusedN); field->TextStorage()->SetTextL(family_name); fieldset->AddL(*field); } if (given_name.Length() > 0) { field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldGivenName); //field->SetLabelL(_L("alma")); field->SetMapping(KUidContactFieldVCardMapUnusedN); field->TextStorage()->SetTextL(given_name); fieldset->AddL(*field); } break; case GN_PHONEBOOK_ENTRY_Email: field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldEMail); field->SetMapping(KUidContactFieldVCardMapEMAILINTERNET); field->TextStorage()->SetTextL(name); fieldset->AddL(*field); break; case GN_PHONEBOOK_ENTRY_Note: field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldNote); field->SetMapping(KUidContactFieldVCardMapNOTE); field->TextStorage()->SetTextL(name); fieldset->AddL(*field); break; case GN_PHONEBOOK_ENTRY_Number: if (subtype == GN_PHONEBOOK_NUMBER_Fax) { field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldFax); field->SetMapping(KUidContactFieldVCardMapTEL); field->AddFieldTypeL(KUidContactFieldVCardMapFAX); } else { field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldPhoneNumber); field->SetMapping(KUidContactFieldVCardMapTEL); switch (subtype) { case GN_PHONEBOOK_NUMBER_Home: field->AddFieldTypeL(KUidContactFieldVCardMapHOME); break; case GN_PHONEBOOK_NUMBER_Mobile: field->AddFieldTypeL(KUidContactFieldVCardMapCELL); break; case GN_PHONEBOOK_NUMBER_Work: field->AddFieldTypeL(KUidContactFieldVCardMapWORK); break; } } field->TextStorage()->SetTextL(name); fieldset->AddL(*field); break; case GN_PHONEBOOK_ENTRY_Ringtone: //field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldRingTone); //field->TextStorage()->SetTextL(name); //fieldset->AddL(*field); break; case GN_PHONEBOOK_ENTRY_Group: //field = CContactItemField::NewL(KStorageTypeText, //field->TextStorage()->SetTextL(name); //fieldset->AddL(*field); break; case GN_PHONEBOOK_ENTRY_URL: field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldUrl); field->SetMapping(KUidContactFieldVCardMapURL); field->TextStorage()->SetTextL(name); fieldset->AddL(*field); break; default: break; } } in.FinishL(); TRAPD(error, item = g->cdb->OpenContactL(location)); if (error == KErrNone) { item->UpdateFieldSet(fieldset); CleanupStack::Pop(fieldset); CleanupStack::PushL(item); g->cdb->CommitContactL(*item); } else { item = CContactCard::NewL(); item->UpdateFieldSet(fieldset); CleanupStack::Pop(fieldset); CleanupStack::PushL(item); location = g->cdb->AddNewContactL(*item); } CleanupStack::Pop(item); out << (TUint16)GNAPPLET_MSG_PHONEBOOK_WRITE_RESP; out << (TUint16)GN_ERR_NONE; out << memtype; out << location; cons->Printf(_L("write: %d\n"), location); }