Use correct object
[LibreOffice.git] / connectivity / source / drivers / macab / MacabGroup.cxx
bloba57f1729fc2d800a35f64c18411cd56ba5c348be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "MacabGroup.hxx"
22 #include "MacabRecords.hxx"
23 #include "macabutilities.hxx"
25 using namespace connectivity::macab;
28 /* A MacabGroup is basically a MacabRecords with a different constructor.
29 * It only exists as a different entity for clarification purposes (a group
30 * is its own entity in the macOS Address Book) and because its
31 * construction is so unique (it is based on an already existent
32 * MacabRecords of the entire address book).
34 MacabGroup::MacabGroup(const ABAddressBookRef _addressBook, const MacabRecords *_allRecords, const ABGroupRef _xGroup)
35 : MacabRecords(_addressBook)
37 sal_Int32 i, j, nAllRecordsSize;
38 CFArrayRef xGroupMembers = ABGroupCopyArrayOfAllMembers(_xGroup);
39 ABPersonRef xPerson;
40 CFStringRef sGroupMemberUID;
41 bool bFound;
42 macabfield *xRecordField;
44 // Set the group's name (stored in MacabRecords as m_sName)
45 CFStringRef sGroupName;
46 sGroupName = static_cast<CFStringRef>(ABRecordCopyValue(_xGroup, kABGroupNameProperty));
47 m_sName = CFStringToOUString(sGroupName);
48 CFRelease(sGroupName);
50 // The _group's_ records (remember MacabGroup inherits from MacabRecords)
51 recordsSize = static_cast<sal_Int32>(CFArrayGetCount(xGroupMembers));
52 records = new MacabRecord *[recordsSize];
53 setHeader(_allRecords->getHeader());
55 /* Go through each record in the group and try to find that record's UID
56 * in the MacabRecords that was passed in. If it is found, add that
57 * record to the group. Otherwise, report an error. (All records should
58 * exist in the MacabRecords that was passed in.)
60 nAllRecordsSize = _allRecords->size();
61 for(i = 0; i < recordsSize; i++)
63 xPerson = static_cast<ABPersonRef>(const_cast<void *>(CFArrayGetValueAtIndex(xGroupMembers,i)));
64 if(xPerson != nullptr)
66 sGroupMemberUID = static_cast<CFStringRef>(ABRecordCopyValue(xPerson, kABUIDProperty));
67 if(sGroupMemberUID != nullptr)
69 bFound = false;
70 for(j = 0; j < nAllRecordsSize; j++)
72 xRecordField = _allRecords->getField(j,CFStringToOUString(kABUIDProperty));
73 if(xRecordField != nullptr && xRecordField->value != nullptr)
75 if(CFEqual(xRecordField->value, sGroupMemberUID))
77 /* Found the matching UID! Insert into the group... */
78 insertRecord(_allRecords->getRecord(j));
79 bFound = true;
80 break;
84 OSL_ENSURE(bFound, "MacabGroup::MacabGroup : Could not find group member based on UID!");
85 CFRelease(sGroupMemberUID);
90 CFRelease(xGroupMembers);
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */