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