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/qdir.h>
10#include <QtCore/qlogging.h>
11#include <filemanagement/environment/oh_environment.h>
14#ifndef QT_NO_STANDARDPATHS
22 char *dirPath =
nullptr;
23 FileManagement_ErrCode dirGetterRetVal = QOhosJsThreadGateway::eval(
25 return ohEnvironmentDirGetter(&dirPath);
27 if (dirGetterRetVal != FileManagement_ErrCode::ERR_OK || dirPath ==
nullptr) {
28 qOhosPrintfDebug(
"OH_Environment_GetUser* dir getter failed, retval: %d",
static_cast<
int>(dirGetterRetVal));
32 auto result = QString::fromUtf8(dirPath);
39template<FileManagement_ErrCode (*ohEnvironmentDirGetter)(
char **)>
42 static std::optional<QString> cachedDirPath;
44 if (!cachedDirPath.has_value())
45 cachedDirPath = tryGetUserDirFromOhEnvironment(ohEnvironmentDirGetter);
52QStringList QStandardPaths::standardLocations(StandardLocation type)
54 return QStringList(writableLocation(type));
57QString QStandardPaths::writableLocation(StandardLocation type)
59 auto testDirSuffix = QStandardPaths::isTestModeEnabled() ? QLatin1String(
"/.qttest") : QLatin1String(
"");
64 return tryGetCachedUserDirFromOhEnvironment<OH_Environment_GetUserDesktopDir>().value_or(QLatin1String());
65 case DocumentsLocation:
67 return tryGetCachedUserDirFromOhEnvironment<OH_Environment_GetUserDocumentDir>().value_or(QLatin1String());
71 case ApplicationsLocation:
80 case PicturesLocation:
83 case DownloadLocation:
85 return tryGetCachedUserDirFromOhEnvironment<OH_Environment_GetUserDownloadDir>().value_or(QLatin1String());
86 case PublicShareLocation:
89 case TemplatesLocation:
93 return QDir::tempPath();
95 return QDir::homePath();
96 case GenericDataLocation:
99 case GenericStateLocation:
100 return QOhosAppContext::getProperty(QOhosAppContext::Type::filesDir) + testDirSuffix;
102 case GenericCacheLocation:
103 return QOhosAppContext::getProperty(QOhosAppContext::Type::cacheDir) + testDirSuffix;
104 case RuntimeLocation:
106 case GenericConfigLocation:
107 case AppConfigLocation:
108 case AppLocalDataLocation:
109 return QOhosAppContext::getProperty(QOhosAppContext::Type::preferencesDir) + testDirSuffix;
114 return QLatin1String();
std::optional< QString > tryGetCachedUserDirFromOhEnvironment()
std::optional< QString > tryGetUserDirFromOhEnvironment(FileManagement_ErrCode(*ohEnvironmentDirGetter)(char **))