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