1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 31 #include "MacabGroup.hxx" 32 #include "MacabRecords.hxx" 33 #include "macabutilities.hxx" 34 35 using namespace connectivity::macab; 36 37 // ------------------------------------------------------------------------- 38 /* A MacabGroup is basically a MacabRecords with a different constructor. 39 * It only exists as a different entity for clarification purposes (a group 40 * is its own entity in the Mac OS X Address Book) and because its 41 * construction is so unique (it is based on an already existent 42 * MacabRecords of the entire address book). 43 */ 44 MacabGroup::MacabGroup(const ABAddressBookRef _addressBook, const MacabRecords *_allRecords, const ABGroupRef _xGroup) 45 : MacabRecords(_addressBook) 46 { 47 sal_Int32 i, j, nAllRecordsSize; 48 CFArrayRef xGroupMembers = ABGroupCopyArrayOfAllMembers(_xGroup); 49 ABPersonRef xPerson; 50 CFStringRef sGroupMemberUID; 51 sal_Bool bFound; 52 macabfield *xRecordField; 53 54 // Set the group's name (stored in MacabRecords as m_sName) 55 CFStringRef sGroupName; 56 sGroupName = (CFStringRef) ABRecordCopyValue(_xGroup, kABGroupNameProperty); 57 m_sName = CFStringToOUString(sGroupName); 58 CFRelease(sGroupName); 59 60 // The _group's_ records (remember MacabGroup inherits from MacabRecords) 61 recordsSize = (sal_Int32) CFArrayGetCount(xGroupMembers); 62 records = new MacabRecord *[recordsSize]; 63 setHeader(_allRecords->getHeader()); 64 65 /* Go through each record in the group and try to find that record's UID 66 * in the MacabRecords that was passed in. If it is found, add that 67 * record to the group. Otherwise, report an error. (All records should 68 * exist in the MacabRecords that was passed in.) 69 */ 70 nAllRecordsSize = _allRecords->size(); 71 for(i = 0; i < recordsSize; i++) 72 { 73 xPerson = (ABPersonRef) CFArrayGetValueAtIndex(xGroupMembers,i); 74 if(xPerson != NULL) 75 { 76 sGroupMemberUID = (CFStringRef) ABRecordCopyValue(xPerson, kABUIDProperty); 77 if(sGroupMemberUID != NULL) 78 { 79 bFound = sal_False; 80 for(j = 0; j < nAllRecordsSize; j++) 81 { 82 xRecordField = _allRecords->getField(j,CFStringToOUString(kABUIDProperty)); 83 if(xRecordField != NULL && xRecordField->value != NULL) 84 { 85 if(CFEqual(xRecordField->value, sGroupMemberUID)) 86 { 87 /* Found the matching UID! Insert into the group... */ 88 insertRecord(_allRecords->getRecord(j)); 89 bFound = sal_True; 90 break; 91 } 92 } 93 } 94 OSL_ENSURE(bFound, "MacabGroup::MacabGroup : Could not find group member based on UID!\n"); 95 CFRelease(sGroupMemberUID); 96 } 97 } 98 } 99 100 CFRelease(xGroupMembers); 101 } 102 103