Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qstandardpaths_ohos.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
"qstandardpaths.h"
5
6
#
include
<
QtCore
/
private
/
qcore_ohos_p
.
h
>
7
#
include
<
QtCore
/
private
/
qohosappcontext_p
.
h
>
8
#
include
<
QtCore
/
private
/
qohoscommon_p
.
h
>
9
#
include
<
QtCore
/
private
/
qohosmemoizingjsthreadfetcher_p
.
h
>
10
#
include
<
QtCore
/
qdir
.
h
>
11
#
include
<
QtCore
/
qlogging
.
h
>
12
#
include
<
filemanagement
/
environment
/
oh_environment
.
h
>
13
#
include
<
optional
>
14
15
#
ifndef
QT_NO_STANDARDPATHS
16
17
QT_BEGIN_NAMESPACE
18
19
namespace
{
20
21
template
<FileManagement_ErrCode (*ohEnvironmentDirGetter)(
char
**)>
22
std
::
optional
<
QString
>
tryGetUserDirFromOhEnvironment
(QOhosJsState &)
23
{
24
char
*dirPath =
nullptr
;
25
FileManagement_ErrCode dirGetterRetVal = ohEnvironmentDirGetter(&dirPath);
26
if
(dirGetterRetVal != FileManagement_ErrCode::ERR_OK || dirPath ==
nullptr
) {
27
qOhosPrintfDebug(
"OH_Environment_GetUser* dir getter failed, retval: %d"
,
static_cast
<
int
>(dirGetterRetVal));
28
return
std
::nullopt;
29
}
30
31
auto
result = QString::fromUtf8(dirPath);
32
33
::free(dirPath);
34
35
return
result;
36
}
37
38
QOhosMemoizingJsThreadFetcher
<
QString
>
userDesktopDirFetcher
(
39
tryGetUserDirFromOhEnvironment<OH_Environment_GetUserDesktopDir>,
"OH_Environment_GetUserDesktopDir()"
);
40
41
QOhosMemoizingJsThreadFetcher
<
QString
>
userDocumentDirFetcher
(
42
tryGetUserDirFromOhEnvironment<OH_Environment_GetUserDocumentDir>,
"OH_Environment_GetUserDocumentDir()"
);
43
44
QOhosMemoizingJsThreadFetcher
<
QString
>
userDownloadDirFetcher
(
45
tryGetUserDirFromOhEnvironment<OH_Environment_GetUserDownloadDir>,
"OH_Environment_GetUserDownloadDir()"
);
46
47
}
48
49
QStringList QStandardPaths::standardLocations(StandardLocation type)
50
{
51
const
QString writable = writableLocation(type);
52
return
writable.isEmpty() ? QStringList{} : QStringList{writable};
53
}
54
55
QString QStandardPaths::writableLocation(StandardLocation type)
56
{
57
auto
testDirSuffix = QStandardPaths::isTestModeEnabled() ? QLatin1String(
"/.qttest"
) : QLatin1String(
""
);
58
59
switch
(type) {
60
case
DesktopLocation:
61
// NOTE: return empty string if the dir isn't available, even in the doc says otherwise
62
return
userDesktopDirFetcher.optValue().value_or(QLatin1String());
63
case
DocumentsLocation:
64
// NOTE: return empty string if the dir isn't available, even in the doc says otherwise
65
return
userDocumentDirFetcher.optValue().value_or(QLatin1String());
66
case
FontsLocation:
67
// NOT SUPPORTED
68
break
;
69
case
ApplicationsLocation:
70
// NOT SUPPORTED
71
break
;
72
case
MusicLocation:
73
// NOT SUPPORTED
74
break
;
75
case
MoviesLocation:
76
// NOT SUPPORTED
77
break
;
78
case
PicturesLocation:
79
// NOT SUPPORTED
80
break
;
81
case
DownloadLocation:
82
// NOTE: return empty string if the dir isn't available, even in the doc says otherwise
83
return
userDownloadDirFetcher.optValue().value_or(QLatin1String());
84
case
PublicShareLocation:
85
// NOT SUPPORTED
86
break
;
87
case
TemplatesLocation:
88
// NOT SUPPORTED
89
break
;
90
case
TempLocation:
91
return
QDir::tempPath();
92
case
HomeLocation:
93
return
QDir::homePath();
94
case
GenericDataLocation:
95
case
AppDataLocation:
96
case
StateLocation:
97
case
GenericStateLocation:
98
return
QOhosAppContext::getProperty(QOhosAppContext::Type::filesDir) + testDirSuffix;
99
case
CacheLocation:
100
case
GenericCacheLocation:
101
return
QOhosAppContext::getProperty(QOhosAppContext::Type::cacheDir) + testDirSuffix;
102
case
RuntimeLocation:
103
case
ConfigLocation:
104
case
GenericConfigLocation:
105
case
AppConfigLocation:
106
case
AppLocalDataLocation:
107
return
QOhosAppContext::getProperty(QOhosAppContext::Type::preferencesDir) + testDirSuffix;
108
default
:
109
break
;
110
}
111
112
return
QLatin1String();
113
}
114
115
QT_END_NAMESPACE
116
117
#
endif
// QT_NO_STANDARDPATHS
QT_BEGIN_NAMESPACE::userDesktopDirFetcher
QOhosMemoizingJsThreadFetcher< QString > userDesktopDirFetcher(tryGetUserDirFromOhEnvironment< OH_Environment_GetUserDesktopDir >, "OH_Environment_GetUserDesktopDir()")
QT_BEGIN_NAMESPACE::userDocumentDirFetcher
QOhosMemoizingJsThreadFetcher< QString > userDocumentDirFetcher(tryGetUserDirFromOhEnvironment< OH_Environment_GetUserDocumentDir >, "OH_Environment_GetUserDocumentDir()")
QT_BEGIN_NAMESPACE::tryGetUserDirFromOhEnvironment
std::optional< QString > tryGetUserDirFromOhEnvironment(QOhosJsState &)
Definition
qstandardpaths_ohos.cpp:22
QT_BEGIN_NAMESPACE::userDownloadDirFetcher
QOhosMemoizingJsThreadFetcher< QString > userDownloadDirFetcher(tryGetUserDirFromOhEnvironment< OH_Environment_GetUserDownloadDir >, "OH_Environment_GetUserDownloadDir()")
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtbase
src
corelib
io
qstandardpaths_ohos.cpp
Generated on
for Qt by
1.18.0