xref: /trunk/main/connectivity/source/drivers/macab/MacabRecords.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CONNECTIVITY_MACAB_RECORDS_HXX_
29 #define _CONNECTIVITY_MACAB_RECORDS_HXX_
30 
31 #include "MacabRecord.hxx"
32 #include "MacabHeader.hxx"
33 
34 #include <premac.h>
35 #include <Carbon/Carbon.h>
36 #include <AddressBook/ABAddressBookC.h>
37 #include <postmac.h>
38 #include <com/sun/star/util/DateTime.hpp>
39 
40 namespace connectivity
41 {
42     namespace macab
43     {
44         /* This struct is for converting CF types to AB types (Core Foundation
45          * types to Address Book types).
46          */
47         struct lcl_CFType {
48             sal_Int32 cf;
49             sal_Int32 ab;
50         };
51 
52         class MacabRecords{
53             protected:
54                 /* MacabRecords is, at its core, a table of macabfields, in the
55                  * form of a header and a list of objects of type MacabRecord.
56                  * It also has a unique name that refers to the name of the table.
57                  */
58                 sal_Int32 recordsSize;
59                 sal_Int32 currentRecord;
60                 CFStringRef recordType;
61                 MacabHeader *header;
62                 MacabRecord **records;
63                 ABAddressBookRef addressBook;
64                 ::rtl::OUString m_sName;
65 
66                 /* For converting CF types to AB types */
67                 sal_Int32 lcl_CFTypesLength;
68                 lcl_CFType *lcl_CFTypes;
69 
70                 /* For required properties */
71                 CFStringRef *requiredProperties;
72                 sal_Int32 numRequiredProperties;
73 
74             private:
75                 /* All of the private methods are for creating a MacabHeader or a
76                  * MacabRecord. They are used by the initialize method that goes
77                  * about filling a MacabRecords using all of the records in the
78                  * Mac OS X Address Book.
79                  */
80                 void bootstrap_CF_types();
81                 void bootstrap_requiredProperties();
82                 MacabHeader *createHeaderForProperty(const ABRecordRef _record, const CFStringRef _propertyName, const CFStringRef _recordType, const sal_Bool _isPropertyRequired) const;
83                 MacabHeader *createHeaderForProperty(const ABPropertyType _propertyType, const CFTypeRef _propertyValue, const CFStringRef _propertyName) const;
84                 void manageDuplicateHeaders(macabfield **_headerNames, const sal_Int32 _length) const;
85                 ABPropertyType getABTypeFromCFType(const CFTypeID cf_type ) const;
86                 void insertPropertyIntoMacabRecord(MacabRecord *_abrecord, const MacabHeader *_header, const ::rtl::OUString  _propertyName, const CFTypeRef _propertyValue) const;
87                 void insertPropertyIntoMacabRecord(const ABPropertyType _propertyType, MacabRecord *_abrecord, const MacabHeader *_header, const ::rtl::OUString  _propertyName, const CFTypeRef _propertyValue) const;
88             public:
89                 MacabRecords(const ABAddressBookRef _addressBook, MacabHeader *_header, MacabRecord **_records, sal_Int32 _numRecords);
90                 MacabRecords(const MacabRecords *_copy);
91                 MacabRecords(const ABAddressBookRef _addressBook);
92                 ~MacabRecords();
93 
94                 void initialize();
95 
96                 void setHeader(MacabHeader *_header);
97                 MacabHeader *getHeader() const;
98 
99                 void setName(const ::rtl::OUString _sName);
100                 ::rtl::OUString getName() const;
101 
102                 MacabRecord *insertRecord(MacabRecord *_newRecord, const sal_Int32 _location);
103                 void insertRecord(MacabRecord *_newRecord);
104                 MacabRecord *getRecord(const sal_Int32 _location) const;
105                 void swap(const sal_Int32 _id1, const sal_Int32 _id2);
106 
107                 macabfield *getField(const sal_Int32 _recordNumber, const sal_Int32 _columnNumber) const;
108                 macabfield *getField(const sal_Int32 _recordNumber, const ::rtl::OUString  _columnName) const;
109                 sal_Int32 getFieldNumber(const ::rtl::OUString  _columnName) const;
110 
111                 sal_Int32 size() const;
112 
113                 MacabHeader *createHeaderForRecordType(const CFArrayRef _records, const CFStringRef _recordType) const;
114                 MacabRecord *createMacabRecord(const ABRecordRef _abrecord, const MacabHeader *_header, const CFStringRef _recordType) const;
115 
116                 MacabRecords *begin();
117                 sal_Int32 end() const;
118                 class iterator{
119                     protected:
120                         MacabRecords *records;
121                     public:
122                         sal_Int32 id;
123                         void operator= (MacabRecords *_records);
124                         iterator();
125                         ~iterator();
126                         void operator++ ();
127                         sal_Bool operator!= (const sal_Int32 i) const;
128                         sal_Bool operator== (const sal_Int32 i) const;
129                         MacabRecord *operator* () const;
130                 };
131 
132         };
133     }
134 }
135 
136 #endif // _CONNECTIVITY_MACAB_RECORDS_HXX_
137