/** Reads the contact item from the database using the given contact item ID. @param aItemId The Id number of the contact to be read. @param aView Specifies the fields to be read. @param aInfoToRead not used @param aSessionId The ID of the session that issued the request. This is used to prevent Phonebook Synchroniser deadlock. @param aIccOpenCheck Specifies if validation with the Phonebook Synchroniser is needed for this contact. @leave KErrArgument if the itemID can't be set within select statement @leave KErrNotFound if a contact item with aItemId does not exist within contact database @leave KSqlErrBusy the database file is locked; thrown if RSqlStatement::Next() returns this error @leave KErrNoMemory an out of memory condition has occurred - the statement will be reset;thrown if RSqlStatement::Next() returns this error @leave KSqlErrGeneral a run-time error has occured - this function must not be called again;thrown if RSqlStatement::Next() returns this error @leave KSqlErrMisuse this function has been called after a previous call returned KSqlAtEnd or KSqlErrGeneral.thrown if RSqlStatement::Next() returns this error @leave KSqlErrStmtExpired the SQL statement has expired (if new functions or collating sequences have been registered or if an authorizer function has been added or changed); thrown if RSqlStatement::Next() returns this error @return CContactItem created from reading the database tables. */ CContactItem* CPplContactItemManager::ReadLC(TContactItemId aItemId, const CContactItemViewDef& aView, TInt aInfoToRead, TUint aSessionId, TBool aIccOpenCheck) const { CContactTemplate* sysTemplate = NULL; if (aItemId != KGoldenTemplateId) { sysTemplate = const_cast<CContactTemplate*>(&iContactProperties.SystemTemplateL()); } RSqlStatement selectStmt; CleanupClosePushL(selectStmt); User::LeaveIfError(selectStmt.Prepare(iDatabase, iSelectStatement->SqlStringL())); TInt err = selectStmt.BindInt(KFirstParam, aItemId); if(err != KErrNone) { User::Leave(KErrArgument); } CContactItem* item = NULL; TUid type(KNullUid); if((err = selectStmt.Next()) == KSqlAtRow) { TInt contactId = selectStmt.ColumnInt(iSelectStatement->ParameterIndex(KContactId)); TInt templateId = selectStmt.ColumnInt(iSelectStatement->ParameterIndex(KContactTemplateId)); TInt typeFlags = selectStmt.ColumnInt(iSelectStatement->ParameterIndex(KContactTypeFlags)); type = TCntPersistenceUtility::TypeFlagsToContactTypeUid(typeFlags); item = CContactItem::NewLC(type); item->SetId(contactId); TPtrC guid = selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactGuidString)); item->SetUidStringL(guid); TInt attr = (typeFlags & EContactAttributes_Mask) >> EContactAttributes_Shift; item->SetAttributes(attr); item->SetTemplateRefId(templateId); item->SetLastModified(TTime(selectStmt.ColumnInt64(iSelectStatement->ParameterIndex(KContactLastModified)))); item->SetCreationDate(TTime(selectStmt.ColumnInt64(iSelectStatement->ParameterIndex(KContactCreationDate)))); item->SetAccessCount(selectStmt.ColumnInt(iSelectStatement->ParameterIndex(KContactAccessCount))); RArray<TPtrC> fastAccessFields; CleanupClosePushL(fastAccessFields); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactFirstName))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactLastName))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactCompanyName))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactFirstNamePrn))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactLastNamePrn))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactCompanyNamePrn))); //set first name, last name, company name, first name pronunciation, last name pronunciation, company name pronunciation for (TInt fieldNum = item->CardFields().Count() - 1; fieldNum>=0; --fieldNum) { CContactItemField& textField = (item->CardFields())[fieldNum]; const TInt nameFieldIndex = NameFieldIndex(textField); // Check if field is first name, last name, company name, // first name pronunciation, last name pronunciation, company name pronunciation. if (nameFieldIndex != KErrNotFound) { HBufC* text = HBufC::NewLC(fastAccessFields[nameFieldIndex].Size()); text->Des() = fastAccessFields[nameFieldIndex]; textField.TextStorage()->SetText(text); CleanupStack::PopAndDestroy(text); } } CleanupStack::PopAndDestroy(&fastAccessFields); }
void T_CntImageRescaler::testRescaleUtility() { // delete the possible image directory, it must not leave // even if the folder was not found. TRAPD( err, TCntImageRescaleUtility::DeleteImageDirectoryL() ); test( err == KErrNone ); // path for image directory, existense of the directory is not // checked TPath path = TCntImageRescaleUtility::ImageDirectoryL(); test( path.Length() > 0 ); test( path.Find(KImagesFolder) != KErrNotFound ); TPath dir = TCntImageRescaleUtility::CreateImageDirectoryL(); test( dir.Length() > 0 ); test( dir.Find( KImagesFolder) != KErrNotFound ); // make a test image file (empty file) RFs fs; CleanupClosePushL( fs ); User::LeaveIfError( fs.Connect() ); TPath imagePath; imagePath.Append( dir ); imagePath.Append( KImageName ); RFile file; CleanupClosePushL(file); User::LeaveIfError(file.Create( fs, imagePath, EFileWrite )); CleanupStack::PopAndDestroy(); CContactItem* item = CContactItem::NewLC(KUidContactCard); CContactItemField* field = CContactItemField::NewL( KStorageTypeText, KUidContactFieldCodImage ); field->SetMapping( KUidContactFieldVCardMapUnknown ); item->AddFieldL( *field ); // add image without GUID TRAPD( err2, TCntImageRescaleUtility::StoreImageFieldL( *item, imagePath ) ); test( err2 == KErrNone ); // then update with GUID value _LIT(KGuid, "guid"); TBufC<4> buffer ( KGuid ); item->SetUidStringL( buffer ); TRAPD( err3, TCntImageRescaleUtility::UpdateImageNameL( *item ) ); test( err3 == KErrNone ); CContactItemFieldSet& fields = item->CardFields(); TInt privateImageIndex = fields.Find( KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown ); test( privateImageIndex != KErrNotFound ); TPtrC fieldText = fields[privateImageIndex].TextStorage()->Text(); // how it should look like TPath newPath; newPath.Append( TCntImageRescaleUtility::ImageDirectoryL() ); newPath.Append( buffer ); newPath.Append( KImageName ); RDebug::Print( _L("%S"), &newPath ); RDebug::Print( _L("%S"), &fieldText ); test( newPath.Compare(fieldText) == 0 ); BaflUtils::DeleteFile( fs, newPath ); CleanupStack::PopAndDestroy(2); // item, RFs }