LibreOffice Module connectivity (master) 1
MacabRecords.hxx
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#pragma once
21
22#include <sal/config.h>
23
24#include <string_view>
25#include <vector>
26
27#include "MacabRecord.hxx"
28#include "MacabHeader.hxx"
29
30#include <premac.h>
31#include <Carbon/Carbon.h>
32#include <AddressBook/ABAddressBookC.h>
33#include <postmac.h>
34#include <com/sun/star/util/DateTime.hpp>
35
36namespace connectivity::macab
37{
38 /* This struct is for converting CF types to AB types (Core Foundation
39 * types to Address Book types).
40 */
41 struct lcl_CFType {
42 CFTypeID cf;
43 sal_Int32 ab;
44 };
45
47 protected:
48 /* MacabRecords is, at its core, a table of macabfields, in the
49 * form of a header and a list of objects of type MacabRecord.
50 * It also has a unique name that refers to the name of the table.
51 */
52 sal_Int32 recordsSize;
53 sal_Int32 currentRecord;
54 CFStringRef recordType;
57 ABAddressBookRef addressBook;
58 OUString m_sName;
59
60 /* For converting CF types to AB types */
61 std::vector<lcl_CFType> lcl_CFTypes;
62
63 /* For required properties */
64 std::vector<CFStringRef> requiredProperties;
65
66 private:
67 /* All of the private methods are for creating a MacabHeader or a
68 * MacabRecord. They are used by the initialize method that goes
69 * about filling a MacabRecords using all of the records in the
70 * macOS Address Book.
71 */
72 void bootstrap_CF_types();
74 MacabHeader *createHeaderForProperty(const ABRecordRef _record, const CFStringRef _propertyName, const CFStringRef _recordType, const bool _isPropertyRequired) const;
75 MacabHeader *createHeaderForProperty(const ABPropertyType _propertyType, const CFTypeRef _propertyValue, const CFStringRef _propertyName) const;
76 ABPropertyType getABTypeFromCFType(const CFTypeID cf_type ) const;
77 void insertPropertyIntoMacabRecord(MacabRecord *_abrecord, const MacabHeader *_header, const OUString& _propertyName, const CFTypeRef _propertyValue) const;
78 void insertPropertyIntoMacabRecord(const ABPropertyType _propertyType, MacabRecord *_abrecord, const MacabHeader *_header, const OUString& _propertyName, const CFTypeRef _propertyValue) const;
79 public:
80 MacabRecords(const ABAddressBookRef _addressBook, MacabHeader *_header, MacabRecord **_records, sal_Int32 _numRecords);
81 explicit MacabRecords(const MacabRecords *_copy);
82 explicit MacabRecords(const ABAddressBookRef _addressBook);
84
85 void initialize();
86
87 void setHeader(MacabHeader *_header);
88 MacabHeader *getHeader() const;
89
90 void setName(const OUString& _sName);
91 OUString const & getName() const;
92
93 MacabRecord *insertRecord(MacabRecord *_newRecord, const sal_Int32 _location);
94 void insertRecord(MacabRecord *_newRecord);
95 MacabRecord *getRecord(const sal_Int32 _location) const;
96 void swap(const sal_Int32 _id1, const sal_Int32 _id2);
97
98 macabfield *getField(const sal_Int32 _recordNumber, const sal_Int32 _columnNumber) const;
99 macabfield *getField(const sal_Int32 _recordNumber, std::u16string_view _columnName) const;
100 sal_Int32 getFieldNumber(std::u16string_view _columnName) const;
101
102 sal_Int32 size() const;
103
104 MacabHeader *createHeaderForRecordType(const CFArrayRef _records, const CFStringRef _recordType) const;
105 MacabRecord *createMacabRecord(const ABRecordRef _abrecord, const MacabHeader *_header, const CFStringRef _recordType) const;
106
108 sal_Int32 end() const;
109 class iterator{
110 protected:
112 public:
113 sal_Int32 id;
114 iterator& operator= (MacabRecords *_records);
115 iterator();
116 void operator++ ();
117 bool operator!= (const sal_Int32 i) const;
118 bool operator== (const sal_Int32 i) const;
119 MacabRecord *operator* () const;
120 };
121
122 };
123}
124
125/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator!=(const sal_Int32 i) const
bool operator==(const sal_Int32 i) const
iterator & operator=(MacabRecords *_records)
OUString const & getName() const
MacabRecords(const ABAddressBookRef _addressBook, MacabHeader *_header, MacabRecord **_records, sal_Int32 _numRecords)
MacabRecord * createMacabRecord(const ABRecordRef _abrecord, const MacabHeader *_header, const CFStringRef _recordType) const
void swap(const sal_Int32 _id1, const sal_Int32 _id2)
void setName(const OUString &_sName)
std::vector< lcl_CFType > lcl_CFTypes
void insertPropertyIntoMacabRecord(MacabRecord *_abrecord, const MacabHeader *_header, const OUString &_propertyName, const CFTypeRef _propertyValue) const
void setHeader(MacabHeader *_header)
sal_Int32 getFieldNumber(std::u16string_view _columnName) const
macabfield * getField(const sal_Int32 _recordNumber, const sal_Int32 _columnNumber) const
MacabHeader * getHeader() const
MacabHeader * createHeaderForRecordType(const CFArrayRef _records, const CFStringRef _recordType) const
MacabRecord * insertRecord(MacabRecord *_newRecord, const sal_Int32 _location)
MacabHeader * createHeaderForProperty(const ABRecordRef _record, const CFStringRef _propertyName, const CFStringRef _recordType, const bool _isPropertyRequired) const
ABPropertyType getABTypeFromCFType(const CFTypeID cf_type) const
MacabRecord * getRecord(const sal_Int32 _location) const
std::vector< CFStringRef > requiredProperties