Qt 4.8
qcore_mac.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <private/qcore_mac_p.h>
43 #include <new>
44 
46 
48 {
49  if (!str)
50  return QString();
51 
52  CFIndex length = CFStringGetLength(str);
53  if (length == 0)
54  return QString();
55 
57  CFStringGetCharacters(str, CFRangeMake(0, length), reinterpret_cast<UniChar *>(const_cast<QChar *>(string.unicode())));
58 
59  return string;
60 }
61 
62 QCFString::operator QString() const
63 {
64  if (string.isEmpty() && type)
65  const_cast<QCFString*>(this)->string = toQString(type);
66  return string;
67 }
68 
70 {
71  return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(string.unicode()),
72  string.length());
73 }
74 
75 QCFString::operator CFStringRef() const
76 {
77  if (!type) {
78  if (string.d->data != string.d->array)
79  const_cast<QCFString*>(this)->string.realloc(); // ### Qt5: do we really need this stupid user protection?
80  const_cast<QCFString*>(this)->type =
81  CFStringCreateWithCharactersNoCopy(0,
82  reinterpret_cast<const UniChar *>(string.unicode()),
83  string.length(),
84  kCFAllocatorNull);
85  }
86  return type;
87 }
88 
89 
90 #if !defined(Q_OS_IOS)
91 void qt_mac_to_pascal_string(const QString &s, Str255 str, TextEncoding encoding, int len)
92 {
93  if(len == -1)
94  len = s.length();
95 #if 0
96  UnicodeMapping mapping;
97  mapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
98  kTextEncodingDefaultVariant,
99  kUnicode16BitFormat);
100  mapping.otherEncoding = (encoding ? encoding : );
101  mapping.mappingVersion = kUnicodeUseLatestMapping;
102 
103  UnicodeToTextInfo info;
104  OSStatus err = CreateUnicodeToTextInfo(&mapping, &info);
105  if(err != noErr) {
106  qDebug("Qt: internal: Unable to create pascal string '%s'::%d [%ld]",
107  s.left(len).latin1(), (int)encoding, err);
108  return;
109  }
110  const int unilen = len * 2;
111  const UniChar *unibuf = (UniChar *)s.unicode();
112  ConvertFromUnicodeToPString(info, unilen, unibuf, str);
113  DisposeUnicodeToTextInfo(&info);
114 #else
115  Q_UNUSED(encoding);
116  CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());
117 #endif
118 }
119 
121 {
122  return QCFString(CFStringCreateWithPascalString(0, pstr, CFStringGetSystemEncoding()));
123 }
124 
125 OSErr qt_mac_create_fsref(const QString &file, FSRef *fsref)
126 {
127  return FSPathMakeRef(reinterpret_cast<const UInt8 *>(file.toUtf8().constData()), fsref, 0);
128 }
129 
130 // Don't use this function, it won't work in 10.5 (Leopard) and up
131 OSErr qt_mac_create_fsspec(const QString &file, FSSpec *spec)
132 {
133  FSRef fsref;
134  OSErr ret = qt_mac_create_fsref(file, &fsref);
135  if (ret == noErr)
136  ret = FSGetCatalogInfo(&fsref, kFSCatInfoNone, 0, 0, spec, 0);
137  return ret;
138 }
139 #endif // !defined(Q_OS_IOS)
140 
double d
Definition: qnumeric_p.h:62
const struct __CFString * CFStringRef
OSErr qt_mac_create_fsspec(const QString &file, FSSpec *spec)
Definition: qcore_mac.cpp:131
static mach_timebase_info_data_t info
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static CFStringRef toCFStringRef(const QString &str)
Definition: qcore_mac.cpp:69
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
The QString class provides a Unicode character string.
Definition: qstring.h:83
OSErr qt_mac_create_fsref(const QString &file, FSRef *fsref)
Definition: qcore_mac.cpp:125
Q_CORE_EXPORT void qDebug(const char *,...)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool isEmpty(const char *str)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
signed long OSStatus
QCFString(const QString &str)
Definition: qcore_mac_p.h:141
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString string
Definition: qcore_mac_p.h:149
static QMap< QByteArray, int > mapping
Definition: qaxserver.cpp:577
QString qt_mac_from_pascal_string(const Str255 pstr)
Definition: qcore_mac.cpp:120
void qt_mac_to_pascal_string(const QString &s, Str255 str, TextEncoding encoding, int len)
Definition: qcore_mac.cpp:91
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729