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
qohospathutils.cpp
Go to the documentation of this file.
1
// Copyright (C) 2026 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
<
QtCore
/
private
/
qohospathutils_p
.
h
>
5
6
#
include
<
QtCore
/
private
/
qohoscommon_p
.
h
>
7
#
include
<
QtCore
/
private
/
qohoslogger_p
.
h
>
8
#
include
<
QtCore
/
qscopeguard
.
h
>
9
#
include
<
cstdlib
>
10
#
include
<
filemanagement
/
file_uri
/
oh_file_uri
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
namespace
{
15
16
template
<
typename
ConvFunc>
17
std
::
optional
<
std
::
string
>
tryCallOhFileUriConversionFunc
(ConvFunc convFunc,
const
std::string &input)
18
{
19
char
*outputPtr =
nullptr
;
20
auto
outputPtrGuard = qScopeGuard([&outputPtr]() { ::free(outputPtr); });
21
auto
convFuncRetVal = convFunc(input.c_str(), input.size(), &outputPtr);
22
23
if
(convFuncRetVal == ::FileManagement_ErrCode::ERR_OK && outputPtr !=
nullptr
)
24
return
std::string(outputPtr);
25
26
qOhosPrintfWarning(
27
"OH FileUri conversion function '%s' failed for input '%s', retval: %d"
,
28
convFunc.name(), input.c_str(),
static_cast
<
int
>(convFuncRetVal));
29
30
return
std::nullopt;
31
}
32
33
}
34
35
std
::
optional
<
std
::
string
>
tryMapPathToOhosFileUri
(
const
std::string &path)
36
{
37
return
tryCallOhFileUriConversionFunc(Q_OHOS_NAMED_FUNC(::OH_FileUri_GetUriFromPath), path);
38
}
39
40
std
::
optional
<
std
::
string
>
tryMapOhosFileUriToPath
(
const
std::string &ohosFileUri)
41
{
42
return
tryCallOhFileUriConversionFunc(Q_OHOS_NAMED_FUNC(::OH_FileUri_GetPathFromUri), ohosFileUri);
43
}
44
45
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE::tryCallOhFileUriConversionFunc
std::optional< std::string > tryCallOhFileUriConversionFunc(ConvFunc convFunc, const std::string &input)
Definition
qohospathutils.cpp:17
tryMapPathToOhosFileUri
std::optional< std::string > tryMapPathToOhosFileUri(const std::string &path)
Definition
qohospathutils.cpp:35
tryMapOhosFileUriToPath
std::optional< std::string > tryMapOhosFileUriToPath(const std::string &ohosFileUri)
Definition
qohospathutils.cpp:40
qtbase
src
corelib
platform
ohos
qohospathutils.cpp
Generated on
for Qt by
1.18.0