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>
15#ifndef QT_NO_STANDARDPATHS
21template<FileManagement_ErrCode (*ohEnvironmentDirGetter)(
char **)>
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));
31 auto result = QString::fromUtf8(dirPath);
39 tryGetUserDirFromOhEnvironment<OH_Environment_GetUserDesktopDir>,
"OH_Environment_GetUserDesktopDir()");
42 tryGetUserDirFromOhEnvironment<OH_Environment_GetUserDocumentDir>,
"OH_Environment_GetUserDocumentDir()");
45 tryGetUserDirFromOhEnvironment<OH_Environment_GetUserDownloadDir>,
"OH_Environment_GetUserDownloadDir()");
49QStringList QStandardPaths::standardLocations(StandardLocation type)
51 return QStringList(writableLocation(type));
54QString QStandardPaths::writableLocation(StandardLocation type)
56 auto testDirSuffix = QStandardPaths::isTestModeEnabled() ? QLatin1String(
"/.qttest") : QLatin1String(
"");
61 return userDesktopDirFetcher.optValue().value_or(QLatin1String());
62 case DocumentsLocation:
64 return userDocumentDirFetcher.optValue().value_or(QLatin1String());
68 case ApplicationsLocation:
77 case PicturesLocation:
80 case DownloadLocation:
82 return userDownloadDirFetcher.optValue().value_or(QLatin1String());
83 case PublicShareLocation:
86 case TemplatesLocation:
90 return QDir::tempPath();
92 return QDir::homePath();
93 case GenericDataLocation:
96 case GenericStateLocation:
97 return QOhosAppContext::getProperty(QOhosAppContext::Type::filesDir) + testDirSuffix;
99 case GenericCacheLocation:
100 return QOhosAppContext::getProperty(QOhosAppContext::Type::cacheDir) + testDirSuffix;
101 case RuntimeLocation:
103 case GenericConfigLocation:
104 case AppConfigLocation:
105 case AppLocalDataLocation:
106 return QOhosAppContext::getProperty(QOhosAppContext::Type::preferencesDir) + testDirSuffix;
111 return QLatin1String();
QOhosMemoizingJsThreadFetcher< QString > userDesktopDirFetcher(tryGetUserDirFromOhEnvironment< OH_Environment_GetUserDesktopDir >, "OH_Environment_GetUserDesktopDir()")
QOhosMemoizingJsThreadFetcher< QString > userDocumentDirFetcher(tryGetUserDirFromOhEnvironment< OH_Environment_GetUserDocumentDir >, "OH_Environment_GetUserDocumentDir()")
std::optional< QString > tryGetUserDirFromOhEnvironment(QOhosJsState &)
QOhosMemoizingJsThreadFetcher< QString > userDownloadDirFetcher(tryGetUserDirFromOhEnvironment< OH_Environment_GetUserDownloadDir >, "OH_Environment_GetUserDownloadDir()")