LibreOffice Module connectivity (master) 1
MacabGroup.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "MacabGroup.hxx"
22#include "MacabRecords.hxx"
23#include "macabutilities.hxx"
24
25using namespace connectivity::macab;
26
27
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).
33 */
34MacabGroup::MacabGroup(const ABAddressBookRef _addressBook, const MacabRecords *_allRecords, const ABGroupRef _xGroup)
35 : MacabRecords(_addressBook)
36{
37 sal_Int32 i, j, nAllRecordsSize;
38 CFArrayRef xGroupMembers = ABGroupCopyArrayOfAllMembers(_xGroup);
39 ABPersonRef xPerson;
40 CFStringRef sGroupMemberUID;
41 bool bFound;
42 macabfield *xRecordField;
43
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);
49
50 // The _group's_ records (remember MacabGroup inherits from MacabRecords)
51 recordsSize = static_cast<sal_Int32>(CFArrayGetCount(xGroupMembers));
53 setHeader(_allRecords->getHeader());
54
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.)
59 */
60 nAllRecordsSize = _allRecords->size();
61 for(i = 0; i < recordsSize; i++)
62 {
63 xPerson = static_cast<ABPersonRef>(const_cast<void *>(CFArrayGetValueAtIndex(xGroupMembers,i)));
64 if(xPerson != nullptr)
65 {
66 sGroupMemberUID = static_cast<CFStringRef>(ABRecordCopyValue(xPerson, kABUIDProperty));
67 if(sGroupMemberUID != nullptr)
68 {
69 bFound = false;
70 for(j = 0; j < nAllRecordsSize; j++)
71 {
72 xRecordField = _allRecords->getField(j,CFStringToOUString(kABUIDProperty));
73 if(xRecordField != nullptr && xRecordField->value != nullptr)
74 {
75 if(CFEqual(xRecordField->value, sGroupMemberUID))
76 {
77 /* Found the matching UID! Insert into the group... */
78 insertRecord(_allRecords->getRecord(j));
79 bFound = true;
80 break;
81 }
82 }
83 }
84 OSL_ENSURE(bFound, "MacabGroup::MacabGroup : Could not find group member based on UID!");
85 CFRelease(sGroupMemberUID);
86 }
87 }
88 }
89
90 CFRelease(xGroupMembers);
91}
92
93/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setHeader(MacabHeader *_header)
macabfield * getField(const sal_Int32 _recordNumber, const sal_Int32 _columnNumber) const
MacabHeader * getHeader() const
MacabRecord * insertRecord(MacabRecord *_newRecord, const sal_Int32 _location)
MacabRecord * getRecord(const sal_Int32 _location) const
OUString CFStringToOUString(const CFStringRef sOrig)
int i