tdf#144694 In direct SQL dialog, activate options 'Run SQL command
[LibreOffice.git] / connectivity / source / drivers / macab / MacabRecords.hxx
blob8d0d5cf6f796cb4857ec37fd21ad11b959579c7c
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <string_view>
25 #include <vector>
27 #include "MacabRecord.hxx"
28 #include "MacabHeader.hxx"
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>
36 namespace connectivity::macab
38 /* This struct is for converting CF types to AB types (Core Foundation
39 * types to Address Book types).
41 struct lcl_CFType {
42 CFTypeID cf;
43 sal_Int32 ab;
46 class MacabRecords{
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.
52 sal_Int32 recordsSize;
53 sal_Int32 currentRecord;
54 CFStringRef recordType;
55 MacabHeader *header;
56 MacabRecord **records;
57 ABAddressBookRef addressBook;
58 OUString m_sName;
60 /* For converting CF types to AB types */
61 std::vector<lcl_CFType> lcl_CFTypes;
63 /* For required properties */
64 std::vector<CFStringRef> requiredProperties;
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.
72 void bootstrap_CF_types();
73 void bootstrap_requiredProperties();
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);
83 ~MacabRecords();
85 void initialize();
87 void setHeader(MacabHeader *_header);
88 MacabHeader *getHeader() const;
90 void setName(const OUString& _sName);
91 OUString const & getName() const;
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);
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;
102 sal_Int32 size() const;
104 MacabHeader *createHeaderForRecordType(const CFArrayRef _records, const CFStringRef _recordType) const;
105 MacabRecord *createMacabRecord(const ABRecordRef _abrecord, const MacabHeader *_header, const CFStringRef _recordType) const;
107 MacabRecords *begin();
108 sal_Int32 end() const;
109 class iterator{
110 protected:
111 MacabRecords *records;
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;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */