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 const QString writable = writableLocation(type);
52 return writable.isEmpty() ? QStringList{} : QStringList{writable};
55QString QStandardPaths::writableLocation(StandardLocation type)
57 auto testDirSuffix = QStandardPaths::isTestModeEnabled() ? QLatin1String(
"/.qttest") : QLatin1String(
"");
62 return userDesktopDirFetcher.optValue().value_or(QLatin1String());
63 case DocumentsLocation:
65 return userDocumentDirFetcher.optValue().value_or(QLatin1String());
69 case ApplicationsLocation:
78 case PicturesLocation:
81 case DownloadLocation:
83 return userDownloadDirFetcher.optValue().value_or(QLatin1String());
84 case PublicShareLocation:
87 case TemplatesLocation:
91 return QDir::tempPath();
93 return QDir::homePath();
94 case GenericDataLocation:
97 case GenericStateLocation:
98 return QOhosAppContext::getProperty(QOhosAppContext::Type::filesDir) + testDirSuffix;
100 case GenericCacheLocation:
101 return QOhosAppContext::getProperty(QOhosAppContext::Type::cacheDir) + testDirSuffix;
102 case RuntimeLocation:
104 case GenericConfigLocation:
105 case AppConfigLocation:
106 case AppLocalDataLocation:
107 return QOhosAppContext::getProperty(QOhosAppContext::Type::preferencesDir) + testDirSuffix;
112 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()")