author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#ifndef QT_NO_DESKTOPSERVICES |
|
43 |
||
44 |
#include <qprocess.h> |
|
45 |
#include <qstringlist.h> |
|
46 |
#include <qdir.h> |
|
47 |
#include <qurl.h> |
|
48 |
#include <qstringlist.h> |
|
49 |
#include <private/qcore_mac_p.h> |
|
50 |
#include <qcoreapplication.h> |
|
51 |
||
52 |
QT_BEGIN_NAMESPACE |
|
53 |
||
54 |
/* |
|
55 |
Translates a QDesktopServices::StandardLocation into the mac equivalent. |
|
56 |
*/ |
|
57 |
OSType translateLocation(QDesktopServices::StandardLocation type) |
|
58 |
{ |
|
59 |
switch (type) { |
|
60 |
case QDesktopServices::DesktopLocation: |
|
61 |
return kDesktopFolderType; break; |
|
62 |
||
63 |
case QDesktopServices::DocumentsLocation: |
|
64 |
return kDocumentsFolderType; break; |
|
65 |
||
66 |
case QDesktopServices::FontsLocation: |
|
67 |
// There are at least two different font directories on the mac: /Library/Fonts and ~/Library/Fonts. |
|
68 |
// To select a specific one we have to specify a different first parameter when calling FSFindFolder. |
|
69 |
return kFontsFolderType; break; |
|
70 |
||
71 |
case QDesktopServices::ApplicationsLocation: |
|
72 |
return kApplicationsFolderType; break; |
|
73 |
||
74 |
case QDesktopServices::MusicLocation: |
|
75 |
return kMusicDocumentsFolderType; break; |
|
76 |
||
77 |
case QDesktopServices::MoviesLocation: |
|
78 |
return kMovieDocumentsFolderType; break; |
|
79 |
||
80 |
case QDesktopServices::PicturesLocation: |
|
81 |
return kPictureDocumentsFolderType; break; |
|
82 |
||
83 |
case QDesktopServices::TempLocation: |
|
84 |
return kTemporaryFolderType; break; |
|
85 |
||
86 |
case QDesktopServices::DataLocation: |
|
87 |
return kApplicationSupportFolderType; break; |
|
88 |
||
89 |
case QDesktopServices::CacheLocation: |
|
90 |
return kCachedDataFolderType; break; |
|
91 |
||
92 |
default: |
|
93 |
return kDesktopFolderType; break; |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
static bool lsOpen(const QUrl &url) |
|
98 |
{ |
|
99 |
if (!url.isValid() || url.scheme().isEmpty()) |
|
100 |
return false; |
|
101 |
||
102 |
QCFType<CFURLRef> cfUrl = CFURLCreateWithString(0, QCFString(QString::fromLatin1(url.toEncoded())), 0); |
|
103 |
if (cfUrl == 0) |
|
104 |
return false; |
|
105 |
||
106 |
const OSStatus err = LSOpenCFURLRef(cfUrl, 0); |
|
107 |
return (err == noErr); |
|
108 |
} |
|
109 |
||
110 |
static bool launchWebBrowser(const QUrl &url) |
|
111 |
{ |
|
112 |
return lsOpen(url); |
|
113 |
} |
|
114 |
||
115 |
static bool openDocument(const QUrl &file) |
|
116 |
{ |
|
117 |
if (!file.isValid()) |
|
118 |
return false; |
|
119 |
||
120 |
// LSOpen does not work in this case, use QProcess open instead. |
|
121 |
return QProcess::startDetached(QLatin1String("open"), QStringList() << file.toLocalFile()); |
|
122 |
} |
|
123 |
||
124 |
/* |
|
125 |
Constructs a full unicode path from a FSRef. |
|
126 |
*/ |
|
127 |
static QString getFullPath(const FSRef &ref) |
|
128 |
{ |
|
129 |
QByteArray ba(2048, 0); |
|
130 |
if (FSRefMakePath(&ref, reinterpret_cast<UInt8 *>(ba.data()), ba.size()) == noErr) |
|
131 |
return QString::fromUtf8(ba).normalized(QString::NormalizationForm_C); |
|
132 |
return QString(); |
|
133 |
} |
|
134 |
||
135 |
QString QDesktopServices::storageLocation(StandardLocation type) |
|
136 |
{ |
|
137 |
if (type == HomeLocation) |
|
138 |
return QDir::homePath(); |
|
139 |
||
140 |
if (type == TempLocation) |
|
141 |
return QDir::tempPath(); |
|
142 |
||
143 |
short domain = kOnAppropriateDisk; |
|
144 |
||
145 |
if (type == DataLocation || type == CacheLocation) |
|
146 |
domain = kUserDomain; |
|
147 |
||
148 |
// http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html |
|
149 |
FSRef ref; |
|
150 |
OSErr err = FSFindFolder(domain, translateLocation(type), false, &ref); |
|
151 |
if (err) |
|
152 |
return QString(); |
|
153 |
||
154 |
QString path = getFullPath(ref); |
|
155 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
if (type == DataLocation || type == CacheLocation) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
if (QCoreApplication::organizationName().isEmpty() == false) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
path += QLatin1Char('/') + QCoreApplication::organizationName(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
if (QCoreApplication::applicationName().isEmpty() == false) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
path += QLatin1Char('/') + QCoreApplication::applicationName(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
} |
0 | 162 |
|
163 |
return path; |
|
164 |
} |
|
165 |
||
166 |
QString QDesktopServices::displayName(StandardLocation type) |
|
167 |
{ |
|
168 |
if (QDesktopServices::HomeLocation == type) |
|
169 |
return QObject::tr("Home"); |
|
170 |
||
171 |
FSRef ref; |
|
172 |
OSErr err = FSFindFolder(kOnAppropriateDisk, translateLocation(type), false, &ref); |
|
173 |
if (err) |
|
174 |
return QString(); |
|
175 |
||
176 |
QCFString displayName; |
|
177 |
err = LSCopyDisplayNameForRef(&ref, &displayName); |
|
178 |
if (err) |
|
179 |
return QString(); |
|
180 |
||
181 |
return static_cast<QString>(displayName); |
|
182 |
} |
|
183 |
||
184 |
QT_END_NAMESPACE |
|
185 |
||
186 |
#endif // QT_NO_DESKTOPSERVICES |