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
5
6#ifndef QT_NO_STANDARDPATHS
7
8#ifndef QT_BOOTSTRAPPED
9#include <qcoreapplication.h>
10#endif
11
12#include <qfile.h>
13
14#include <FindDirectory.h>
15#include <Path.h>
16#include <PathFinder.h>
17#include <StringList.h>
18
20
21namespace {
22
23void appendOrganizationAndApp(QString &path)
24{
25#ifndef QT_BOOTSTRAPPED
26 const QString org = QCoreApplication::organizationName();
27 if (!org.isEmpty())
28 path += u'/' + org;
29 const QString appName = QCoreApplication::applicationName();
30 if (!appName.isEmpty())
31 path += u'/' + appName;
32#else
33 Q_UNUSED(path);
34#endif
35}
36
37/*
38 * Returns the generic standard path for given directory type.
39 */
40QString haikuStandardPath(directory_which which)
41{
42 BPath standardPath;
43
44 if (find_directory(which, &standardPath, false) != B_OK)
45 return QString();
46
47 return QFile::decodeName(standardPath.Path());
48}
49
50/*
51 * Returns the generic standard paths for given path type.
52 */
53QStringList haikuStandardPaths(path_base_directory baseDirectory)
54{
55 BStringList paths;
56
57 if (BPathFinder::FindPaths(baseDirectory, paths) != B_OK)
58 return QStringList();
59
60 QStringList standardPaths;
61 for (int i = 0; i < paths.CountStrings(); ++i) {
62 standardPaths << QFile::decodeName(paths.StringAt(i).String());
63 }
64
65 return standardPaths;
66}
67
68/*
69 * Returns the application specific standard path for given directory type.
70 */
71QString haikuAppStandardPath(directory_which which)
72{
73 QString path = haikuStandardPath(which);
74 if (!path.isEmpty())
75 appendOrganizationAndApp(path);
76
77 return path;
78}
79
80/*
81 * Returns the application specific standard paths for given path type.
82 */
83QStringList haikuAppStandardPaths(path_base_directory baseDirectory)
84{
85 QStringList paths = haikuStandardPaths(baseDirectory);
86 for (int i = 0; i < paths.count(); ++i)
88
89 return paths;
90}
91
92} // namespace
93
94QString QStandardPaths::writableLocation(StandardLocation type)
95{
96 switch (type) {
97 case DesktopLocation:
98 return haikuStandardPath(B_DESKTOP_DIRECTORY);
99 case DocumentsLocation: // fall through
100 case PicturesLocation:
101 case MusicLocation:
102 case MoviesLocation:
103 case DownloadLocation:
104 case PublicShareLocation:
105 case TemplatesLocation:
106 case HomeLocation:
107 return haikuStandardPath(B_USER_DIRECTORY);
108 case FontsLocation:
109 return haikuStandardPath(B_USER_NONPACKAGED_FONTS_DIRECTORY);
110 case ApplicationsLocation:
111 return haikuStandardPath(B_USER_NONPACKAGED_BIN_DIRECTORY);
112 case TempLocation:
113 return haikuStandardPath(B_SYSTEM_TEMP_DIRECTORY);
114 case AppDataLocation: // fall through
115 case AppLocalDataLocation:
116 return haikuAppStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY);
117 case GenericDataLocation:
118 return haikuStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY);
119 case CacheLocation:
120 return haikuAppStandardPath(B_USER_CACHE_DIRECTORY);
121 case GenericCacheLocation:
122 return haikuStandardPath(B_USER_CACHE_DIRECTORY);
123 case ConfigLocation:
124 case AppConfigLocation:
125 case StateLocation:
126 case GenericStateLocation:
127 return haikuAppStandardPath(B_USER_SETTINGS_DIRECTORY);
128 case GenericConfigLocation:
129 return haikuStandardPath(B_USER_SETTINGS_DIRECTORY);
130 default:
131 return QString();
132 }
133}
134
135QStringList QStandardPaths::standardLocations(StandardLocation type)
136{
137 QStringList paths;
138
139 const QString writablePath = writableLocation(type);
140 if (!writablePath.isEmpty())
141 paths += writablePath;
142
143 switch (type) {
144 case DocumentsLocation: // fall through
145 case PicturesLocation:
146 case MusicLocation:
147 case MoviesLocation:
148 case DownloadLocation:
149 case PublicShareLocation:
150 case TemplatesLocation:
151 case HomeLocation:
152 paths += haikuStandardPath(B_USER_NONPACKAGED_DIRECTORY);
153 break;
154 case FontsLocation:
155 paths += haikuStandardPaths(B_FIND_PATH_FONTS_DIRECTORY);
156 break;
157 case ApplicationsLocation:
158 paths += haikuStandardPaths(B_FIND_PATH_BIN_DIRECTORY);
159 paths += haikuStandardPaths(B_FIND_PATH_APPS_DIRECTORY);
160 break;
161 case AppDataLocation: // fall through
162 case AppLocalDataLocation:
163 paths += haikuAppStandardPaths(B_FIND_PATH_DATA_DIRECTORY);
164 break;
165 case GenericDataLocation:
166 paths += haikuStandardPaths(B_FIND_PATH_DATA_DIRECTORY);
167 break;
168 case CacheLocation:
169 paths += haikuAppStandardPath(B_SYSTEM_CACHE_DIRECTORY);
170 break;
171 case GenericCacheLocation:
172 paths += haikuStandardPath(B_SYSTEM_CACHE_DIRECTORY);
173 break;
174 case ConfigLocation: // fall through
175 case AppConfigLocation:
176 paths += haikuAppStandardPath(B_SYSTEM_SETTINGS_DIRECTORY);
177 break;
178 case GenericConfigLocation:
179 paths += haikuStandardPath(B_SYSTEM_SETTINGS_DIRECTORY);
180 break;
181 default:
182 break;
183 }
184
185 return paths;
186}
187
188QT_END_NAMESPACE
189
190#endif // QT_NO_STANDARDPATHS
Combined button and popup list for selecting options.
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)