5#include <QtCore/qurl.h>
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.h>
11#include <qohosenums.h>
12#include <qohosplugincore.h>
16using QOhosWantConstantFlags = QtOhos::enums::ohos::app::ability::wantConstant::Flags;
20void callStartAbility(QNapi::Object baseQAbility, QNapi::Object want, QOhosConsumer<
bool> resultConsumer)
22 qOhosPrintfDebug(
"Calling startAbility() with Want '%s'", QNapi::toJsonString(want).c_str());
24 baseQAbility.evalToPromiseOrRejectOnThrow(
"context.startAbility(*)", {want})
25 .withContext(
std::move(resultConsumer))
28 qOhosPrintfDebug(
"Got success from startAbility()");
33 QtOhos::logJsCallbackError(cbInfo,
"Got error from startAbility()");
34 resultConsumer(
false);
38class QOhosColorPicker :
public QPlatformServiceColorPicker
43 void pickColor() override;
46QOhosColorPicker::QOhosColorPicker() =
default;
48void QOhosColorPicker::pickColor()
50 auto selfRef = QtOhos::makeQThreadSafeRef(
this);
53 jsState.evalToPromiseOrRejectOnThrow(
"@kit.Penkit.imageFeaturePicker.pickForResult()")
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);
70 QtOhos::logJsCallbackError(cbInfo,
"@kit.Penkit.imageFeaturePicker.pickForResult() failed");
81 return new QOhosColorPicker;
96 return QtOhos::evalInJsThreadWithPromise<
bool>(
97 [&](
QtOhos::
JsState &jsState, QOhosTaskPromise<
bool> evalPromise) {
98 auto mainUiAbility = jsState.defaultQAbilityPeer()->qAbility();
99 if (mainUiAbility.IsEmpty()) {
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(mainUiAbility, want,
std::move(evalPromise));
151 return QByteArray(
"Ohos");
Combined button and popup list for selecting options.
void invokeInJsThread(std::function< void(JsState &)> task)