|
1 /* This file is part of the KDE project. |
|
2 |
|
3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
|
5 This library is free software: you can redistribute it and/or modify |
|
6 it under the terms of the GNU Lesser General Public License as published by |
|
7 the Free Software Foundation, either version 2.1 or 3 of the License. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 GNU Lesser General Public License for more details. |
|
13 |
|
14 You should have received a copy of the GNU Lesser General Public License |
|
15 along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 |
|
18 #include "backendheader.h" |
|
19 #include <QtCore/QString> |
|
20 #include <QtCore/QDebug> |
|
21 |
|
22 #include <CoreFoundation/CoreFoundation.h> |
|
23 #include <QVarLengthArray> |
|
24 |
|
25 QT_BEGIN_NAMESPACE |
|
26 |
|
27 namespace Phonon |
|
28 { |
|
29 namespace QT7 |
|
30 { |
|
31 |
|
32 Q_GLOBAL_STATIC(QString, gErrorString) |
|
33 int gErrorType = NO_ERROR; |
|
34 |
|
35 void gSetErrorString(const QString &errorString) |
|
36 { |
|
37 if (qgetenv("PHONON_DEBUG") == "1"){ |
|
38 qDebug() << "Error:" << errorString; |
|
39 } |
|
40 |
|
41 if (!gErrorString()->isEmpty()) |
|
42 return; // not yet caught. |
|
43 |
|
44 *gErrorString() = errorString; |
|
45 } |
|
46 |
|
47 QString gGetErrorString() |
|
48 { |
|
49 return *gErrorString(); |
|
50 } |
|
51 |
|
52 void gSetErrorLocation(const QString &errorLocation) |
|
53 { |
|
54 if (qgetenv("PHONON_DEBUG") == "1"){ |
|
55 qDebug() << "Location:" << errorLocation; |
|
56 } |
|
57 } |
|
58 |
|
59 void gSetErrorType(int errorType) |
|
60 { |
|
61 if (gErrorType != NO_ERROR) |
|
62 return; // not yet caught. |
|
63 gErrorType = errorType; |
|
64 } |
|
65 |
|
66 int gGetErrorType() |
|
67 { |
|
68 return gErrorType; |
|
69 } |
|
70 |
|
71 void gClearError() |
|
72 { |
|
73 gErrorString()->clear(); |
|
74 gErrorType = NO_ERROR; |
|
75 } |
|
76 |
|
77 ///////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
79 PhononAutoReleasePool::PhononAutoReleasePool() |
|
80 { |
|
81 pool = (void*)[[NSAutoreleasePool alloc] init]; |
|
82 } |
|
83 |
|
84 PhononAutoReleasePool::~PhononAutoReleasePool() |
|
85 { |
|
86 [(NSAutoreleasePool*)pool release]; |
|
87 } |
|
88 |
|
89 ///////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
91 QString PhononCFString::toQString(CFStringRef str) |
|
92 { |
|
93 if(!str) |
|
94 return QString(); |
|
95 CFIndex length = CFStringGetLength(str); |
|
96 const UniChar *chars = CFStringGetCharactersPtr(str); |
|
97 if (chars) |
|
98 return QString(reinterpret_cast<const QChar *>(chars), length); |
|
99 |
|
100 QVarLengthArray<UniChar> buffer(length); |
|
101 CFStringGetCharacters(str, CFRangeMake(0, length), buffer.data()); |
|
102 return QString(reinterpret_cast<const QChar *>(buffer.constData()), length); |
|
103 } |
|
104 |
|
105 PhononCFString::operator QString() const |
|
106 { |
|
107 if (string.isEmpty() && type) |
|
108 const_cast<PhononCFString*>(this)->string = toQString(type); |
|
109 return string; |
|
110 } |
|
111 |
|
112 CFStringRef PhononCFString::toCFStringRef(const QString &string) |
|
113 { |
|
114 return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(string.unicode()), |
|
115 string.length()); |
|
116 } |
|
117 |
|
118 PhononCFString::operator CFStringRef() const |
|
119 { |
|
120 if (!type) |
|
121 const_cast<PhononCFString*>(this)->type = toCFStringRef(string); |
|
122 return type; |
|
123 } |
|
124 |
|
125 }} |
|
126 |
|
127 QT_END_NAMESPACE |