plugins/contacts/symbian/contactsmodel/cntmodel/src/ccontactdatabase.cpp
changeset 5 603d3f8b6302
parent 0 876b1a06bc25
equal deleted inserted replaced
3:e4ebb16b39ea 5:603d3f8b6302
  1055 	const_cast<CContactDatabase*>(this)->FetchGroupAndTemplateListsL();
  1055 	const_cast<CContactDatabase*>(this)->FetchGroupAndTemplateListsL();
  1056 	CContactIdArray* copyArray = CContactIdArray::NewL(iGroupIds);
  1056 	CContactIdArray* copyArray = CContactIdArray::NewL(iGroupIds);
  1057 	return copyArray;
  1057 	return copyArray;
  1058 	}
  1058 	}
  1059 
  1059 
       
  1060 /** 
       
  1061 Sets a list of contact items in the database to be members of a contact group.
       
  1062 
       
  1063 The items and the group are identified by their IDs. 
       
  1064 
       
  1065 @capability WriteUserData
       
  1066 
       
  1067 @param aItemIdList The list of IDs of the items to add to the group.
       
  1068 @param aGroupId  The ID of the group to which the items should be added. 
       
  1069 
       
  1070 @leave KErrNotFound Either the group or the item does not exist.
       
  1071 @leave KErrNotSupported The group is not of type KUidContactGroup. 
       
  1072 @leave KErrDiskFull The disk does not have enough free space to perform the operation.
       
  1073 */
       
  1074 EXPORT_C void CContactDatabase::AddContactsToGroupL(RArray<TContactItemId>& aItemIdList, TContactItemId aGroupId)
       
  1075 	{
       
  1076 	//Remember if the group was already opened, if so open it at the end of the method
       
  1077 	TBool isAlreadyOpened = iCntSvr->CloseContact(aGroupId);
       
  1078 	CContactItem* cntGroup = OpenNoMergeLCX(aGroupId); //double push
       
  1079 
       
  1080 	if (cntGroup->Type() != KUidContactGroup)
       
  1081 		User::Leave(KErrNotSupported);
       
  1082 
       
  1083 	CContactGroup* group = static_cast<CContactGroup*>(cntGroup);
       
  1084 
       
  1085     TBool isGroupModified = EFalse;
       
  1086     TInt itemCount = aItemIdList.Count();
       
  1087     for (TInt i = 0; i < itemCount; ++i)
       
  1088         {
       
  1089     	TContactItemId itemId = aItemIdList[i];
       
  1090     	if (!group->ContainsItem(itemId))
       
  1091 		    {
       
  1092 		    group->AddContactL(itemId);
       
  1093 		    isGroupModified = ETrue;
       
  1094 		    }
       
  1095         }
       
  1096 
       
  1097     if (isGroupModified)
       
  1098         {
       
  1099 	    iCntSvr->CommitContactL(*cntGroup);
       
  1100 		}
       
  1101 	else
       
  1102 		{
       
  1103 		iCntSvr->CloseContact(cntGroup->Id());
       
  1104 		}
       
  1105 
       
  1106 	CleanupStack::PopAndDestroy(cntGroup);	// cntGroup
       
  1107 	CleanupStack::Pop(); // Pop the lock
       
  1108 	cntGroup = NULL;
       
  1109 	if (isAlreadyOpened)
       
  1110 		{
       
  1111 		CContactItem* dummy = OpenContactL(aGroupId);
       
  1112 		delete dummy;				
       
  1113 		}
       
  1114 	}
  1060 
  1115 
  1061 /** 
  1116 /** 
  1062 Sets a contact item in the database to be a member of a contact group.
  1117 Sets a contact item in the database to be a member of a contact group.
  1063 
  1118 
  1064 The item and group are identified by their IDs. 
  1119 The item and group are identified by their IDs. 
  1243 		}
  1298 		}
  1244 
  1299 
  1245 	}
  1300 	}
  1246 
  1301 
  1247 
  1302 
       
  1303 /** 
       
  1304 Removes the association between a list of contact items and a group.
       
  1305 
       
  1306 The items and the group are identified by their IDs. 
       
  1307 
       
  1308 @capability WriteUserData
       
  1309 
       
  1310 @param aItemId The list of IDs of the items to remove.
       
  1311 @param aGroupId The ID of the group from which the items should be removed. 
       
  1312 
       
  1313 @leave KErrDiskFull The disk does not have enough free space to perform the operation.
       
  1314 */
       
  1315 EXPORT_C void CContactDatabase::RemoveContactsFromGroupL(RArray<TContactItemId>& aItemIdList, TContactItemId aGroupId)
       
  1316 	{
       
  1317 	//Remember if the group was already opened, if so open it at the end of the method
       
  1318 	TBool isAlreadyOpened = iCntSvr->CloseContact(aGroupId);
       
  1319 	CContactItem* cntGroup = OpenNoMergeLCX(aGroupId); //double push
       
  1320 	
       
  1321 	if (cntGroup->Type() != KUidContactGroup)
       
  1322 		{
       
  1323 		User::Leave(KErrNotSupported);
       
  1324 		}
       
  1325 
       
  1326 	CContactGroup* group = static_cast<CContactGroup*>(cntGroup);
       
  1327 	
       
  1328     TBool isGroupModified = EFalse;
       
  1329     TInt itemCount = aItemIdList.Count();
       
  1330     for (TInt i = 0; i < itemCount; ++i)
       
  1331         {
       
  1332     	TContactItemId itemId = aItemIdList[i];
       
  1333     	if (group->ContainsItem(itemId))
       
  1334 		    {
       
  1335 		    group->RemoveContactL(itemId);
       
  1336 		    isGroupModified = ETrue;
       
  1337 		    }
       
  1338 		else
       
  1339 		    {
       
  1340             User::Leave(KErrNotFound);
       
  1341             }
       
  1342         }
       
  1343 
       
  1344     if (isGroupModified)
       
  1345         {
       
  1346 	    iCntSvr->CommitContactL(*cntGroup);
       
  1347 		}
       
  1348 	else
       
  1349 		{
       
  1350 		iCntSvr->CloseContact(cntGroup->Id());
       
  1351 		}
       
  1352     
       
  1353 	CleanupStack::PopAndDestroy(2); // cntGroup, CntItemClose
       
  1354 	cntGroup = NULL;
       
  1355 	
       
  1356 	if (isAlreadyOpened)
       
  1357 		{
       
  1358 		CContactItem* dummy = OpenContactL(aGroupId);
       
  1359 		delete dummy;				
       
  1360 		}
       
  1361 	}
       
  1362 	
       
  1363     
  1248 /**
  1364 /**
  1249 Sets a field containing a telephone number as a speed dial field. The field 
  1365 Sets a field containing a telephone number as a speed dial field. The field 
  1250 is identified by aFieldIndex within the contact item aItem. It is assigned a 
  1366 is identified by aFieldIndex within the contact item aItem. It is assigned a 
  1251 speed dial position between 1 and 9 inclusive.
  1367 speed dial position between 1 and 9 inclusive.
  1252 
  1368