~carlos-mazieri/ubuntu-filemanager-app/model-using-qfilesystemwatcher

« back to all changes in this revision

Viewing changes to test_folderlistmodel/regression/mimetypes/src/mimetypes/inqt5/qstandardpaths_mac.cpp

  • Committer: carlos.mazieri at gmail
  • Date: 2013-05-25 17:21:13 UTC
  • Revision ID: carlos.mazieri@gmail.com-20130525172113-s8e1ajb7c4egpjw5
added QMimeType to try QIcon::fromTheme() to get icons.

added a private Clipboard handling to prevent Qcliboard not working on Nemo emulator

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 
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
** 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.
 
17
**
 
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.
 
21
**
 
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.
 
29
**
 
30
** Other Usage
 
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.
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QT_NO_DESKTOPSERVICES
 
43
 
 
44
#include "qstandardpaths.h"
 
45
#include <qdir.h>
 
46
#include <qcoreapplication.h>
 
47
 
 
48
#include <ApplicationServices/ApplicationServices.h>
 
49
 
 
50
QT_BEGIN_NAMESPACE
 
51
 
 
52
/*
 
53
    Translates a QStandardPaths::StandardLocation into the mac equivalent.
 
54
*/
 
55
OSType translateLocation(QStandardPaths::StandardLocation type)
 
56
{
 
57
    switch (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;
 
84
    default:
 
85
        return kDesktopFolderType;
 
86
    }
 
87
}
 
88
 
 
89
/*
 
90
    Constructs a full unicode path from a FSRef.
 
91
*/
 
92
static QString getFullPath(const FSRef &ref)
 
93
{
 
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);
 
97
    return QString();
 
98
}
 
99
 
 
100
static QString macLocation(QStandardPaths::StandardLocation type, short domain)
 
101
{
 
102
    // http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html
 
103
    FSRef ref;
 
104
    OSErr err = FSFindFolder(domain, translateLocation(type), false, &ref);
 
105
    if (err)
 
106
       return QString();
 
107
 
 
108
   QString path = getFullPath(ref);
 
109
 
 
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();
 
115
   }
 
116
   return path;
 
117
}
 
118
 
 
119
QString QStandardPaths::writableLocation(StandardLocation type)
 
120
{
 
121
    switch(type) {
 
122
    case HomeLocation:
 
123
        return QDir::homePath();
 
124
    case TempLocation:
 
125
        return QDir::tempPath();
 
126
    case GenericDataLocation:
 
127
    case DataLocation:
 
128
    case CacheLocation:
 
129
    case RuntimeLocation:
 
130
        return macLocation(type, kUserDomain);
 
131
    default:
 
132
        return macLocation(type, kOnAppropriateDisk);
 
133
    }
 
134
}
 
135
 
 
136
QStringList QStandardPaths::standardLocations(StandardLocation type)
 
137
{
 
138
    QStringList dirs;
 
139
 
 
140
    if (type == GenericDataLocation || type == DataLocation || type == CacheLocation) {
 
141
        const QString path = macLocation(type, kOnAppropriateDisk);
 
142
        if (!path.isEmpty())
 
143
            dirs.append(path);
 
144
    }
 
145
 
 
146
    const QString localDir = writableLocation(type);
 
147
    dirs.prepend(localDir);
 
148
    return dirs;
 
149
}
 
150
 
 
151
QString QStandardPaths::displayName(StandardLocation type)
 
152
{
 
153
    if (QStandardPaths::HomeLocation == type)
 
154
        return QCoreApplication::translate("QStandardPaths", "Home");
 
155
 
 
156
    FSRef ref;
 
157
    OSErr err = FSFindFolder(kOnAppropriateDisk, translateLocation(type), false, &ref);
 
158
    if (err)
 
159
        return QString();
 
160
 
 
161
    CFStringRef displayName = 0;
 
162
    err = LSCopyDisplayNameForRef(&ref, &displayName);
 
163
    if (err)
 
164
        return QString();
 
165
 
 
166
    QString result = QString::fromUtf16((ushort*)CFStringGetCharactersPtr(displayName), CFStringGetLength(displayName));
 
167
    CFRelease(displayName);
 
168
    return result;
 
169
}
 
170
 
 
171
QT_END_NAMESPACE
 
172
 
 
173
#endif // QT_NO_DESKTOPSERVICES