1*caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*caf5cd79SAndrew Rist * distributed with this work for additional information 6*caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9*caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10*caf5cd79SAndrew Rist * 11*caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*caf5cd79SAndrew Rist * 13*caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15*caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17*caf5cd79SAndrew Rist * specific language governing permissions and limitations 18*caf5cd79SAndrew Rist * under the License. 19*caf5cd79SAndrew Rist * 20*caf5cd79SAndrew Rist *************************************************************/ 21*caf5cd79SAndrew Rist 22*caf5cd79SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _CONNECTIVITY_MACAB_RECORDS_HXX_ 25cdf0e10cSrcweir #define _CONNECTIVITY_MACAB_RECORDS_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "MacabRecord.hxx" 28cdf0e10cSrcweir #include "MacabHeader.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <premac.h> 31cdf0e10cSrcweir #include <Carbon/Carbon.h> 32cdf0e10cSrcweir #include <AddressBook/ABAddressBookC.h> 33cdf0e10cSrcweir #include <postmac.h> 34cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace connectivity 37cdf0e10cSrcweir { 38cdf0e10cSrcweir namespace macab 39cdf0e10cSrcweir { 40cdf0e10cSrcweir /* This struct is for converting CF types to AB types (Core Foundation 41cdf0e10cSrcweir * types to Address Book types). 42cdf0e10cSrcweir */ 43cdf0e10cSrcweir struct lcl_CFType { 44cdf0e10cSrcweir sal_Int32 cf; 45cdf0e10cSrcweir sal_Int32 ab; 46cdf0e10cSrcweir }; 47cdf0e10cSrcweir 48cdf0e10cSrcweir class MacabRecords{ 49cdf0e10cSrcweir protected: 50cdf0e10cSrcweir /* MacabRecords is, at its core, a table of macabfields, in the 51cdf0e10cSrcweir * form of a header and a list of objects of type MacabRecord. 52cdf0e10cSrcweir * It also has a unique name that refers to the name of the table. 53cdf0e10cSrcweir */ 54cdf0e10cSrcweir sal_Int32 recordsSize; 55cdf0e10cSrcweir sal_Int32 currentRecord; 56cdf0e10cSrcweir CFStringRef recordType; 57cdf0e10cSrcweir MacabHeader *header; 58cdf0e10cSrcweir MacabRecord **records; 59cdf0e10cSrcweir ABAddressBookRef addressBook; 60cdf0e10cSrcweir ::rtl::OUString m_sName; 61cdf0e10cSrcweir 62cdf0e10cSrcweir /* For converting CF types to AB types */ 63cdf0e10cSrcweir sal_Int32 lcl_CFTypesLength; 64cdf0e10cSrcweir lcl_CFType *lcl_CFTypes; 65cdf0e10cSrcweir 66cdf0e10cSrcweir /* For required properties */ 67cdf0e10cSrcweir CFStringRef *requiredProperties; 68cdf0e10cSrcweir sal_Int32 numRequiredProperties; 69cdf0e10cSrcweir 70cdf0e10cSrcweir private: 71cdf0e10cSrcweir /* All of the private methods are for creating a MacabHeader or a 72cdf0e10cSrcweir * MacabRecord. They are used by the initialize method that goes 73cdf0e10cSrcweir * about filling a MacabRecords using all of the records in the 74cdf0e10cSrcweir * Mac OS X Address Book. 75cdf0e10cSrcweir */ 76cdf0e10cSrcweir void bootstrap_CF_types(); 77cdf0e10cSrcweir void bootstrap_requiredProperties(); 78cdf0e10cSrcweir MacabHeader *createHeaderForProperty(const ABRecordRef _record, const CFStringRef _propertyName, const CFStringRef _recordType, const sal_Bool _isPropertyRequired) const; 79cdf0e10cSrcweir MacabHeader *createHeaderForProperty(const ABPropertyType _propertyType, const CFTypeRef _propertyValue, const CFStringRef _propertyName) const; 80cdf0e10cSrcweir void manageDuplicateHeaders(macabfield **_headerNames, const sal_Int32 _length) const; 81cdf0e10cSrcweir ABPropertyType getABTypeFromCFType(const CFTypeID cf_type ) const; 82cdf0e10cSrcweir void insertPropertyIntoMacabRecord(MacabRecord *_abrecord, const MacabHeader *_header, const ::rtl::OUString _propertyName, const CFTypeRef _propertyValue) const; 83cdf0e10cSrcweir void insertPropertyIntoMacabRecord(const ABPropertyType _propertyType, MacabRecord *_abrecord, const MacabHeader *_header, const ::rtl::OUString _propertyName, const CFTypeRef _propertyValue) const; 84cdf0e10cSrcweir public: 85cdf0e10cSrcweir MacabRecords(const ABAddressBookRef _addressBook, MacabHeader *_header, MacabRecord **_records, sal_Int32 _numRecords); 86cdf0e10cSrcweir MacabRecords(const MacabRecords *_copy); 87cdf0e10cSrcweir MacabRecords(const ABAddressBookRef _addressBook); 88cdf0e10cSrcweir ~MacabRecords(); 89cdf0e10cSrcweir 90cdf0e10cSrcweir void initialize(); 91cdf0e10cSrcweir 92cdf0e10cSrcweir void setHeader(MacabHeader *_header); 93cdf0e10cSrcweir MacabHeader *getHeader() const; 94cdf0e10cSrcweir 95cdf0e10cSrcweir void setName(const ::rtl::OUString _sName); 96cdf0e10cSrcweir ::rtl::OUString getName() const; 97cdf0e10cSrcweir 98cdf0e10cSrcweir MacabRecord *insertRecord(MacabRecord *_newRecord, const sal_Int32 _location); 99cdf0e10cSrcweir void insertRecord(MacabRecord *_newRecord); 100cdf0e10cSrcweir MacabRecord *getRecord(const sal_Int32 _location) const; 101cdf0e10cSrcweir void swap(const sal_Int32 _id1, const sal_Int32 _id2); 102cdf0e10cSrcweir 103cdf0e10cSrcweir macabfield *getField(const sal_Int32 _recordNumber, const sal_Int32 _columnNumber) const; 104cdf0e10cSrcweir macabfield *getField(const sal_Int32 _recordNumber, const ::rtl::OUString _columnName) const; 105cdf0e10cSrcweir sal_Int32 getFieldNumber(const ::rtl::OUString _columnName) const; 106cdf0e10cSrcweir 107cdf0e10cSrcweir sal_Int32 size() const; 108cdf0e10cSrcweir 109cdf0e10cSrcweir MacabHeader *createHeaderForRecordType(const CFArrayRef _records, const CFStringRef _recordType) const; 110cdf0e10cSrcweir MacabRecord *createMacabRecord(const ABRecordRef _abrecord, const MacabHeader *_header, const CFStringRef _recordType) const; 111cdf0e10cSrcweir 112cdf0e10cSrcweir MacabRecords *begin(); 113cdf0e10cSrcweir sal_Int32 end() const; 114cdf0e10cSrcweir class iterator{ 115cdf0e10cSrcweir protected: 116cdf0e10cSrcweir MacabRecords *records; 117cdf0e10cSrcweir public: 118cdf0e10cSrcweir sal_Int32 id; 119cdf0e10cSrcweir void operator= (MacabRecords *_records); 120cdf0e10cSrcweir iterator(); 121cdf0e10cSrcweir ~iterator(); 122cdf0e10cSrcweir void operator++ (); 123cdf0e10cSrcweir sal_Bool operator!= (const sal_Int32 i) const; 124cdf0e10cSrcweir sal_Bool operator== (const sal_Int32 i) const; 125cdf0e10cSrcweir MacabRecord *operator* () const; 126cdf0e10cSrcweir }; 127cdf0e10cSrcweir 128cdf0e10cSrcweir }; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir #endif // _CONNECTIVITY_MACAB_RECORDS_HXX_ 133