1
/****************************************************************************
3
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the QtGui module of the Qt Toolkit.
9
** $QT_BEGIN_LICENSE:LGPL$
10
** GNU Lesser General Public License Usage
11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
** In addition, as a special exception, Nokia gives you certain additional
19
** rights. These rights are described in the Nokia Qt LGPL Exception
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
40
****************************************************************************/
42
#ifndef QT_NO_DESKTOPSERVICES
44
#include "qstandardpaths.h"
46
#include <qcoreapplication.h>
48
#include <ApplicationServices/ApplicationServices.h>
53
Translates a QStandardPaths::StandardLocation into the mac equivalent.
55
OSType translateLocation(QStandardPaths::StandardLocation type)
58
case QStandardPaths::ConfigLocation:
59
return kPreferencesFolderType;
60
case QStandardPaths::DesktopLocation:
61
return kDesktopFolderType;
62
case QStandardPaths::DocumentsLocation:
63
return kDocumentsFolderType;
64
case QStandardPaths::FontsLocation:
65
// There are at least two different font directories on the mac: /Library/Fonts and ~/Library/Fonts.
66
// To select a specific one we have to specify a different first parameter when calling FSFindFolder.
67
return kFontsFolderType;
68
case QStandardPaths::ApplicationsLocation:
69
return kApplicationsFolderType;
70
case QStandardPaths::MusicLocation:
71
return kMusicDocumentsFolderType;
72
case QStandardPaths::MoviesLocation:
73
return kMovieDocumentsFolderType;
74
case QStandardPaths::PicturesLocation:
75
return kPictureDocumentsFolderType;
76
case QStandardPaths::TempLocation:
77
return kTemporaryFolderType;
78
case QStandardPaths::GenericDataLocation:
79
case QStandardPaths::RuntimeLocation:
80
case QStandardPaths::DataLocation:
81
return kApplicationSupportFolderType;
82
case QStandardPaths::CacheLocation:
83
return kCachedDataFolderType;
85
return kDesktopFolderType;
90
Constructs a full unicode path from a FSRef.
92
static QString getFullPath(const FSRef &ref)
94
QByteArray ba(2048, 0);
95
if (FSRefMakePath(&ref, reinterpret_cast<UInt8 *>(ba.data()), ba.size()) == noErr)
96
return QString::fromUtf8(ba).normalized(QString::NormalizationForm_C);
100
static QString macLocation(QStandardPaths::StandardLocation type, short domain)
102
// http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html
104
OSErr err = FSFindFolder(domain, translateLocation(type), false, &ref);
108
QString path = getFullPath(ref);
110
if (type == QStandardPaths::DataLocation || type == QStandardPaths::CacheLocation) {
111
if (!QCoreApplication::organizationName().isEmpty())
112
path += QLatin1Char('/') + QCoreApplication::organizationName();
113
if (!QCoreApplication::applicationName().isEmpty())
114
path += QLatin1Char('/') + QCoreApplication::applicationName();
119
QString QStandardPaths::writableLocation(StandardLocation type)
123
return QDir::homePath();
125
return QDir::tempPath();
126
case GenericDataLocation:
129
case RuntimeLocation:
130
return macLocation(type, kUserDomain);
132
return macLocation(type, kOnAppropriateDisk);
136
QStringList QStandardPaths::standardLocations(StandardLocation type)
140
if (type == GenericDataLocation || type == DataLocation || type == CacheLocation) {
141
const QString path = macLocation(type, kOnAppropriateDisk);
146
const QString localDir = writableLocation(type);
147
dirs.prepend(localDir);
151
QString QStandardPaths::displayName(StandardLocation type)
153
if (QStandardPaths::HomeLocation == type)
154
return QCoreApplication::translate("QStandardPaths", "Home");
157
OSErr err = FSFindFolder(kOnAppropriateDisk, translateLocation(type), false, &ref);
161
CFStringRef displayName = 0;
162
err = LSCopyDisplayNameForRef(&ref, &displayName);
166
QString result = QString::fromUtf16((ushort*)CFStringGetCharactersPtr(displayName), CFStringGetLength(displayName));
167
CFRelease(displayName);
173
#endif // QT_NO_DESKTOPSERVICES