6#include <QtCore/private/qnapi_p.h>
7#include <QtCore/private/qohoscommon_p.h>
8#include <QtCore/private/qohospathutils_p.h>
9#include <QtCore/qfileinfo.h>
10#include <QtGui/QColor>
11#include <qohosenums.h>
12#include <qohosplugincore.h>
17using QOhosWantConstantFlags = QtOhos::enums::ohos::app::ability::wantConstant::Flags;
21void callStartAbility(QNapi::Object baseQAbility, QNapi::Object want, QOhosConsumer<
bool> resultConsumer)
23 qOhosPrintfDebug(
"Calling startAbility() with Want '%s'", QNapi::toJsonString(want).c_str());
25 baseQAbility.evalToPromiseOrRejectOnThrow(
"context.startAbility(*)", {want})
26 .withContext(
std::move(resultConsumer))
29 qOhosPrintfDebug(
"Got success from startAbility()");
34 QtOhos::logJsCallbackError(cbInfo,
"Got error from startAbility()");
35 resultConsumer(
false);
39class QOhosColorPicker :
public QPlatformServiceColorPicker
44 void pickColor() override;
47QOhosColorPicker::QOhosColorPicker() =
default;
49void QOhosColorPicker::pickColor()
51 auto selfRef = QtOhos::makeQThreadSafeRef(
this);
54 jsState.evalToPromiseOrRejectOnThrow(
"@kit.Penkit.imageFeaturePicker.pickForResult()")
57 auto pickedColorInfo = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
58 auto color = pickedColorInfo.get<QNapi::Object>(
"color");
60 color.get<QNapi::Number>(
"red"),
61 color.get<QNapi::Number>(
"green"),
62 color.get<QNapi::Number>(
"blue"),
63 color.get<QNapi::Number>(
"alpha"));
64 selfRef.visitInQtThreadIfAlive(
65 [qColor](QOhosColorPicker &self) {
66 Q_EMIT self.colorPicked(qColor);
71 QtOhos::logJsCallbackError(cbInfo,
"@kit.Penkit.imageFeaturePicker.pickForResult() failed");
77QOhosPlatformServices::QOhosPlatformServices() =
default;
79QPlatformServiceColorPicker *QOhosPlatformServices::colorPicker(QWindow *parent)
82 return new QOhosColorPicker;
85bool QOhosPlatformServices::hasCapability(Capability capability)
const
95bool QOhosPlatformServices::openUrl(
const QUrl &url)
97 return QtOhos::evalInJsThreadWithPromise<
bool>(
98 [&](
QtOhos::
JsState &jsState, QOhosTaskPromise<
bool> evalPromise) {
99 auto mainUiAbility = jsState.defaultQAbilityPeer()->qAbility();
100 if (mainUiAbility.IsEmpty()) {
110 {
"action",
"ohos.want.action.viewData"},
111 {
"entities", QNapi::makeArray(jsState.env(), {
"entity.system.browsable"})},
112 {
"uri", url.toString().toStdString()},
114 : QFileInfo(url.path()).isDir()
118 {
"abilityName",
"MainAbility"},
119 {
"bundleName",
"com.huawei.hmos.filemanager"},
125 {
"fileUri", tryMapPathToOhosFileUri(url.path().toStdString()).value_or(
"")},
132 {
"action",
"ohos.want.action.viewData"},
133 {
"uri", tryMapPathToOhosFileUri(url.path().toStdString()).value_or(
"")},
136 jsState.mapOhosEnumToJs(QOhosWantConstantFlags::FLAG_AUTH_READ_URI_PERMISSION).Int32Value()
137 | jsState.mapOhosEnumToJs(QOhosWantConstantFlags::FLAG_AUTH_WRITE_URI_PERMISSION).Int32Value()
140 callStartAbility(mainUiAbility, want,
std::move(evalPromise));
145bool QOhosPlatformServices::openDocument(
const QUrl &url)
150QByteArray QOhosPlatformServices::desktopEnvironment()
const
152 return QByteArray(
"Ohos");
Combined button and popup list for selecting options.
void invokeInJsThread(std::function< void(JsState &)> task)