Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qstandardpaths_haiku.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias Koenig <tobias.koenig@kdab.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:critical reason:provides-trusted-directory-paths
4
6
7#ifndef QT_NO_STANDARDPATHS
8
9#ifndef QT_BOOTSTRAPPED
10#include <qcoreapplication.h>
11#endif
12
13#include <qfile.h>
14
15#include <FindDirectory.h>
16#include <Path.h>
17#include <PathFinder.h>
18#include <StringList.h>
19
21
22namespace {
23
24void appendOrganizationAndApp(QString &path)
25{
26#ifndef QT_BOOTSTRAPPED
27 const QString org = QCoreApplication::organizationName();
28 if (!org.isEmpty())
29 path += u'/' + org;
30 const QString appName = QCoreApplication::applicationName();
31 if (!appName.isEmpty())
32 path += u'/' + appName;
33#else
34 Q_UNUSED(path);
35#endif
36}
37
38/*
39 * Returns the generic standard path for given directory type.
40 */
41QString haikuStandardPath(directory_which which)
42{
43 BPath standardPath;
44
45 if (find_directory(which, &standardPath, false) != B_OK)
46 return QString();
47
48 return QFile::decodeName(standardPath.Path());
49}
50
51/*
52 * Returns the generic standard paths for given path type.
53 */
54QStringList haikuStandardPaths(path_base_directory baseDirectory)
55{
56 BStringList paths;
57
58 if (BPathFinder::FindPaths(baseDirectory, paths) != B_OK)
59 return QStringList();
60
61 QStringList standardPaths;
62 for (int i = 0; i < paths.CountStrings(); ++i) {
63 standardPaths << QFile::decodeName(paths.StringAt(i).String());
64 }
65
66 return standardPaths;
67}
68
69/*
70 * Returns the application specific standard path for given directory type.
71 */
72QString haikuAppStandardPath(directory_which which)
73{
74 QString path = haikuStandardPath(which);
75 if (!path.isEmpty())
76 appendOrganizationAndApp(path);
77
78 return path;
79}
80
81/*
82 * Returns the application specific standard paths for given path type.
83 */
84QStringList haikuAppStandardPaths(path_base_directory baseDirectory)
85{
86 QStringList paths = haikuStandardPaths(baseDirectory);
87 for (int i = 0; i < paths.count(); ++i)
89
90 return paths;
91}
92
93} // namespace
94
95QString QStandardPaths::writableLocation(StandardLocation type)
96{
97 switch (type) {
98 case DesktopLocation:
99 return haikuStandardPath(B_DESKTOP_DIRECTORY);
100 case DocumentsLocation: // fall through
101 case PicturesLocation:
102 case MusicLocation:
103 case MoviesLocation:
104 case DownloadLocation:
105 case PublicShareLocation:
106 case TemplatesLocation:
107 case HomeLocation:
108 return haikuStandardPath(B_USER_DIRECTORY);
109 case FontsLocation:
110 return haikuStandardPath(B_USER_NONPACKAGED_FONTS_DIRECTORY);
111 case ApplicationsLocation:
112 return haikuStandardPath(B_USER_NONPACKAGED_BIN_DIRECTORY);
113 case TempLocation:
114 return haikuStandardPath(B_SYSTEM_TEMP_DIRECTORY);
115 case AppDataLocation: // fall through
116 case AppLocalDataLocation:
117 return haikuAppStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY);
118 case GenericDataLocation:
119 return haikuStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY);
120 case CacheLocation:
121 return haikuAppStandardPath(B_USER_CACHE_DIRECTORY);
122 case GenericCacheLocation:
123 return haikuStandardPath(B_USER_CACHE_DIRECTORY);
124 case ConfigLocation:
125 case AppConfigLocation:
126 case StateLocation:
127 case GenericStateLocation:
128 return haikuAppStandardPath(B_USER_SETTINGS_DIRECTORY);
129 case GenericConfigLocation:
130 return haikuStandardPath(B_USER_SETTINGS_DIRECTORY);
131 default:
132 return QString();
133 }
134}
135
136QStringList QStandardPaths::standardLocations(StandardLocation type)
137{
138 QStringList paths;
139
140 const QString writablePath = writableLocation(type);
141 if (!writablePath.isEmpty())
142 paths += writablePath;
143
144 switch (type) {
145 case DocumentsLocation: // fall through
146 case PicturesLocation:
147 case MusicLocation:
148 case MoviesLocation:
149 case DownloadLocation:
150 case PublicShareLocation:
151 case TemplatesLocation:
152 case HomeLocation:
153 paths += haikuStandardPath(B_USER_NONPACKAGED_DIRECTORY);
154 break;
155 case FontsLocation:
156 paths += haikuStandardPaths(B_FIND_PATH_FONTS_DIRECTORY);
157 break;
158 case ApplicationsLocation:
159 paths += haikuStandardPaths(B_FIND_PATH_BIN_DIRECTORY);
160 paths += haikuStandardPaths(B_FIND_PATH_APPS_DIRECTORY);
161 break;
162 case AppDataLocation: // fall through
163 case AppLocalDataLocation:
164 paths += haikuAppStandardPaths(B_FIND_PATH_DATA_DIRECTORY);
165 break;
166 case GenericDataLocation:
167 paths += haikuStandardPaths(B_FIND_PATH_DATA_DIRECTORY);
168 break;
169 case CacheLocation:
170 paths += haikuAppStandardPath(B_SYSTEM_CACHE_DIRECTORY);
171 break;
172 case GenericCacheLocation:
173 paths += haikuStandardPath(B_SYSTEM_CACHE_DIRECTORY);
174 break;
175 case ConfigLocation: // fall through
176 case AppConfigLocation:
177 paths += haikuAppStandardPath(B_SYSTEM_SETTINGS_DIRECTORY);
178 break;
179 case GenericConfigLocation:
180 paths += haikuStandardPath(B_SYSTEM_SETTINGS_DIRECTORY);
181 break;
182 default:
183 break;
184 }
185
186 return paths;
187}
188
189QT_END_NAMESPACE
190
191#endif // QT_NO_STANDARDPATHS
QString haikuAppStandardPath(directory_which which)
QString haikuStandardPath(directory_which which)
void appendOrganizationAndApp(QString &path)
QStringList haikuStandardPaths(path_base_directory baseDirectory)
QStringList haikuAppStandardPaths(path_base_directory baseDirectory)