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_UTILITIES_HXX_ 25cdf0e10cSrcweir #define _CONNECTIVITY_MACAB_UTILITIES_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 28cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <time.h> 31cdf0e10cSrcweir #include <premac.h> 32cdf0e10cSrcweir #include <Carbon/Carbon.h> 33cdf0e10cSrcweir #include <AddressBook/ABAddressBookC.h> 34cdf0e10cSrcweir #include <postmac.h> 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace connectivity 37cdf0e10cSrcweir { 38cdf0e10cSrcweir namespace macab 39cdf0e10cSrcweir { 40cdf0e10cSrcweir // ------------------------------------------------------------------------- CFStringToOUString(const CFStringRef sOrig)41cdf0e10cSrcweir inline ::rtl::OUString CFStringToOUString(const CFStringRef sOrig) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir /* Copied all-but directly from code by Florian Heckl in 44cdf0e10cSrcweir * cws_src680_aquafilepicker01 45cdf0e10cSrcweir * File was: fpicker/source/aqua/CFStringUtilities 46cdf0e10cSrcweir * I only removed commented debugging lines and changed variable 47cdf0e10cSrcweir * names. 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir if (NULL == sOrig) { 50cdf0e10cSrcweir return rtl::OUString(); 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir CFRetain(sOrig); 54cdf0e10cSrcweir CFIndex nStringLength = CFStringGetLength(sOrig); 55cdf0e10cSrcweir 56cdf0e10cSrcweir UniChar unichars[nStringLength+1]; 57cdf0e10cSrcweir 58cdf0e10cSrcweir //'close' the string buffer correctly 59cdf0e10cSrcweir unichars[nStringLength] = '\0'; 60cdf0e10cSrcweir 61cdf0e10cSrcweir CFStringGetCharacters (sOrig, CFRangeMake(0,nStringLength), unichars); 62cdf0e10cSrcweir CFRelease(sOrig); 63cdf0e10cSrcweir 64cdf0e10cSrcweir return rtl::OUString(unichars); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir // ------------------------------------------------------------------------- OUStringToCFString(const::rtl::OUString & aString)68cdf0e10cSrcweir inline CFStringRef OUStringToCFString(const ::rtl::OUString& aString) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir /* Copied directly from code by Florian Heckl in 71cdf0e10cSrcweir * cws_src680_aquafilepicker01 72cdf0e10cSrcweir * File was: fpicker/source/aqua/CFStringUtilities 73cdf0e10cSrcweir */ 74cdf0e10cSrcweir 75cdf0e10cSrcweir CFStringRef ref = CFStringCreateWithCharacters(kCFAllocatorDefault, aString.getStr(), aString.getLength()); 76cdf0e10cSrcweir 77cdf0e10cSrcweir return ref; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir // ------------------------------------------------------------------------- CFDateToDateTime(const CFDateRef _cfDate)81cdf0e10cSrcweir inline com::sun::star::util::DateTime CFDateToDateTime(const CFDateRef _cfDate) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir /* Carbon can give us the time since 2001 of any CFDateRef, 84cdf0e10cSrcweir * and it also stores the time since 1970 as a constant, 85cdf0e10cSrcweir * basically allowing us to get the unixtime of any 86cdf0e10cSrcweir * CFDateRef. From there, it is just a matter of choosing what 87cdf0e10cSrcweir * we want to do with it. 88cdf0e10cSrcweir */ 89cdf0e10cSrcweir com::sun::star::util::DateTime nRet; 90cdf0e10cSrcweir double timeSince2001 = CFDateGetAbsoluteTime(_cfDate); 91cdf0e10cSrcweir time_t unixtime = timeSince2001+kCFAbsoluteTimeIntervalSince1970; 92cdf0e10cSrcweir struct tm *ptm = localtime(&unixtime); 93cdf0e10cSrcweir nRet.Year = ptm->tm_year+1900; 94cdf0e10cSrcweir nRet.Month = ptm->tm_mon+1; 95cdf0e10cSrcweir nRet.Day = ptm->tm_mday; 96cdf0e10cSrcweir nRet.Hours = ptm->tm_hour; 97cdf0e10cSrcweir nRet.Minutes = ptm->tm_min; 98cdf0e10cSrcweir nRet.Seconds = ptm->tm_sec; 99cdf0e10cSrcweir nRet.HundredthSeconds = 0; 100cdf0e10cSrcweir return nRet; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir // ------------------------------------------------------------------------- fixLabel(const::rtl::OUString _originalLabel)104cdf0e10cSrcweir inline ::rtl::OUString fixLabel(const ::rtl::OUString _originalLabel) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir /* Get the length, and make sure that there is actually a string 107cdf0e10cSrcweir * here. 108cdf0e10cSrcweir */ 109cdf0e10cSrcweir if(_originalLabel.indexOf(::rtl::OUString::createFromAscii("_$!<")) == 0) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir return _originalLabel.copy(4,_originalLabel.getLength()-8); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir return _originalLabel; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir // ------------------------------------------------------------------------- ABTypeToDataType(const ABPropertyType _abType)118cdf0e10cSrcweir inline sal_Int32 ABTypeToDataType(const ABPropertyType _abType) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir sal_Int32 dataType; 121cdf0e10cSrcweir switch(_abType) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir case kABStringProperty: 124cdf0e10cSrcweir dataType = ::com::sun::star::sdbc::DataType::CHAR; 125cdf0e10cSrcweir break; 126cdf0e10cSrcweir case kABDateProperty: 127cdf0e10cSrcweir dataType = ::com::sun::star::sdbc::DataType::TIMESTAMP; 128cdf0e10cSrcweir break; 129cdf0e10cSrcweir case kABIntegerProperty: 130cdf0e10cSrcweir dataType = ::com::sun::star::sdbc::DataType::INTEGER; 131cdf0e10cSrcweir break; 132cdf0e10cSrcweir case kABRealProperty: 133cdf0e10cSrcweir dataType = ::com::sun::star::sdbc::DataType::FLOAT; 134cdf0e10cSrcweir break; 135cdf0e10cSrcweir default: 136cdf0e10cSrcweir dataType = -1; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir return dataType; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir void impl_throwError(sal_uInt16 _nErrorId); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir #endif // _ CONNECTIVITY_MACAB_UTILITIES_HXX_ 146