5#include <QtCore/private/qcore_ohos_p.h>
6#include <QtCore/qurl.h>
7#include <QtCore/private/qnapi_p.h>
8#include <QtCore/private/qohoscommon_p.h>
9#include <QtCore/private/qohospathutils_p.h>
10#include <QtCore/qfileinfo.h>
11#include <QtGui/qcolor.h>
12#include <qohosqpaenums.h>
16using QOhosWantConstantFlags = QtOhosQpa::enums::ohos::app::ability::wantConstant::Flags;
20void callStartAbility(QNapi::Object baseQAbility, QNapi::Object want, QOhosTaskPromise<
bool> resultPromise)
22 qOhosPrintfDebug(
"Calling startAbility() with Want '%s'", QNapi::toJsonString(want).c_str());
24 auto thenCatchPromises =
std::move(resultPromise).makeThenCatchBranches(Q_FUNC_INFO);
25 baseQAbility.evalToPromiseOrRejectOnThrow(
"context.startAbility(*)", {want})
27 [thenPromise = std::move(thenCatchPromises.first)](
const QOhosCallbackInfo &) {
28 qOhosPrintfDebug(
"Got success from startAbility()");
32 [catchPromise = std::move(thenCatchPromises.second)](
const QOhosCallbackInfo &cbInfo) {
33 QtOhos::logJsCallbackError(cbInfo,
"Got error from startAbility()");
38class QOhosColorPicker :
public QPlatformServiceColorPicker
43 void pickColor() override;
46QOhosColorPicker::QOhosColorPicker() =
default;
48void QOhosColorPicker::pickColor()
50 auto selfRef = QtOhos::makeQThreadSafeRef(
this);
51 QOhosJsThreadGateway::invoke(
52 [selfRef](QOhosJsState &jsState) {
53 jsState.evalToPromiseOrRejectOnThrow(
"@kit.Penkit.imageFeaturePicker.pickForResult()")
55 [selfRef](
const QOhosCallbackInfo &cbInfo) {
56 auto pickedColorInfo = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
57 auto color = pickedColorInfo.get<QNapi::Object>(
"color");
59 color.get<QNapi::Number>(
"red"),
60 color.get<QNapi::Number>(
"green"),
61 color.get<QNapi::Number>(
"blue"),
62 color.get<QNapi::Number>(
"alpha"));
63 selfRef.visitInQtThreadIfAlive(
64 [qColor](QOhosColorPicker &self) {
65 Q_EMIT self.colorPicked(qColor);
69 [](
const QOhosCallbackInfo &cbInfo) {
70 QtOhos::logJsCallbackError(cbInfo,
"@kit.Penkit.imageFeaturePicker.pickForResult() failed");
76QOhosPlatformServices::QOhosPlatformServices() =
default;
78QPlatformServiceColorPicker *QOhosPlatformServices::colorPicker(QWindow *parent)
81 return new QOhosColorPicker;
84bool QOhosPlatformServices::hasCapability(Capability capability)
const
94bool QOhosPlatformServices::openUrl(
const QUrl &url)
96 return QOhosJsThreadGateway::evalWithPromise<
bool>(
97 [&](QOhosJsState &jsState, QOhosTaskPromise<
bool> evalPromise) {
98 auto optMainUiAbility = jsState.defaultQAbility();
99 if (!optMainUiAbility) {
109 {
"action",
"ohos.want.action.viewData"},
110 {
"entities", QNapi::makeArray(jsState.env(), {
"entity.system.browsable"})},
111 {
"uri", url.toString().toStdString()},
113 : QFileInfo(url.path()).isDir()
117 {
"abilityName",
"MainAbility"},
118 {
"bundleName",
"com.huawei.hmos.filemanager"},
124 {
"fileUri", tryMapPathToOhosFileUri(url.path().toStdString()).value_or(
"")},
131 {
"action",
"ohos.want.action.viewData"},
132 {
"uri", tryMapPathToOhosFileUri(url.path().toStdString()).value_or(
"")},
135 jsState.mapOhosEnumToJs(QOhosWantConstantFlags::FLAG_AUTH_READ_URI_PERMISSION).Int32Value()
136 | jsState.mapOhosEnumToJs(QOhosWantConstantFlags::FLAG_AUTH_WRITE_URI_PERMISSION).Int32Value()
139 callStartAbility(optMainUiAbility.value(), want, std::move(evalPromise));
144bool QOhosPlatformServices::openDocument(
const QUrl &url)
149QByteArray QOhosPlatformServices::desktopEnvironment()
const
151 return QByteArray(
"Ohos");