mirror of
https://gitee.com/openharmony/distributeddatamgr_pasteboard
synced 2025-03-01 05:36:50 +00:00
JS -> NDK paste failed.
Signed-off-by: cuile4 <cuile4@huawei.com> Change-Id: I65143f775bde91f9b9a5af886c92630883731ed6 Signed-off-by: cuile4 <cuile4@huawei.com>
This commit is contained in:
parent
03ca8d3c28
commit
95e31d7c95
@ -47,6 +47,8 @@ public:
|
|||||||
static std::shared_ptr<std::vector<std::pair<std::string, UDMF::ValueType>>> Convert(
|
static std::shared_ptr<std::vector<std::pair<std::string, UDMF::ValueType>>> Convert(
|
||||||
const std::vector<std::shared_ptr<PasteDataEntry>> &entries);
|
const std::vector<std::shared_ptr<PasteDataEntry>> &entries);
|
||||||
|
|
||||||
|
static UDMF::ValueType Convert(const std::shared_ptr<PasteDataEntry>& entry);
|
||||||
|
|
||||||
static std::vector<std::string> Convert(const std::vector<std::string> &utdIds);
|
static std::vector<std::string> Convert(const std::vector<std::string> &utdIds);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -125,6 +125,48 @@ std::vector<std::shared_ptr<PasteDataEntry>> ConvertUtils::Convert(
|
|||||||
return pbEntries;
|
return pbEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UDMF::ValueType ConvertUtils::Convert(const std::shared_ptr<PasteDataEntry>& entry)
|
||||||
|
{
|
||||||
|
auto utdId = entry->GetUtdId();
|
||||||
|
auto value = entry->GetValue();
|
||||||
|
if (std::holds_alternative<std::monostate>(value) || std::holds_alternative<std::shared_ptr<Object>>(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
auto mimeType = entry->GetMimeType();
|
||||||
|
auto object = std::make_shared<UDMF::Object>();
|
||||||
|
if (mimeType == MIMETYPE_TEXT_PLAIN) {
|
||||||
|
object->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
|
||||||
|
if (std::holds_alternative<std::string>(value)) {
|
||||||
|
object->value_[UDMF::CONTENT] = std::get<std::string>(value);
|
||||||
|
}
|
||||||
|
} else if (mimeType == MIMETYPE_TEXT_HTML) {
|
||||||
|
object->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
|
||||||
|
if (std::holds_alternative<std::string>(value)) {
|
||||||
|
object->value_[UDMF::HTML_CONTENT] = std::get<std::string>(value);
|
||||||
|
}
|
||||||
|
} else if (mimeType == MIMETYPE_TEXT_URI) {
|
||||||
|
object->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
|
||||||
|
if (std::holds_alternative<std::string>(value)) {
|
||||||
|
object->value_[UDMF::FILE_URI_PARAM] = std::get<std::string>(value);
|
||||||
|
}
|
||||||
|
} else if (mimeType == MIMETYPE_PIXELMAP) {
|
||||||
|
object->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
|
||||||
|
if (std::holds_alternative<std::shared_ptr<OHOS::Media::PixelMap>>(value)) {
|
||||||
|
object->value_[UDMF::PIXEL_MAP] = std::get<std::shared_ptr<OHOS::Media::PixelMap>>(value);
|
||||||
|
}
|
||||||
|
} else if (mimeType == MIMETYPE_TEXT_WANT) {
|
||||||
|
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "mimeType is want,udmf not surpport");
|
||||||
|
} else {
|
||||||
|
object->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
|
||||||
|
if (std::holds_alternative<std::vector<uint8_t>>(value)) {
|
||||||
|
auto arrayBuffer = std::get<std::vector<uint8_t>>(value);
|
||||||
|
object->value_[UDMF::ARRAY_BUFFER] = arrayBuffer;
|
||||||
|
object->value_[UDMF::ARRAY_BUFFER_LENGTH] = static_cast<int64_t>(arrayBuffer.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<std::vector<std::pair<std::string, UDMF::ValueType>>> ConvertUtils::Convert(
|
std::shared_ptr<std::vector<std::pair<std::string, UDMF::ValueType>>> ConvertUtils::Convert(
|
||||||
const std::vector<std::shared_ptr<PasteDataEntry>> &entries)
|
const std::vector<std::shared_ptr<PasteDataEntry>> &entries)
|
||||||
{
|
{
|
||||||
@ -138,7 +180,7 @@ std::shared_ptr<std::vector<std::pair<std::string, UDMF::ValueType>>> ConvertUti
|
|||||||
if (udmfEntryMap.find(entry->GetUtdId()) == udmfEntryMap.end()) {
|
if (udmfEntryMap.find(entry->GetUtdId()) == udmfEntryMap.end()) {
|
||||||
entryUtdIds.emplace_back(entry->GetUtdId());
|
entryUtdIds.emplace_back(entry->GetUtdId());
|
||||||
}
|
}
|
||||||
udmfEntryMap.insert_or_assign(entry->GetUtdId(), entry->GetValue());
|
udmfEntryMap.insert_or_assign(entry->GetUtdId(), Convert(entry));
|
||||||
}
|
}
|
||||||
for (auto const &utdId : entryUtdIds) {
|
for (auto const &utdId : entryUtdIds) {
|
||||||
auto item = udmfEntryMap.find(utdId);
|
auto item = udmfEntryMap.find(utdId);
|
||||||
|
@ -233,7 +233,7 @@ std::shared_ptr<std::string> PasteDataEntry::ConvertToHtml() const
|
|||||||
std::shared_ptr<Uri> PasteDataEntry::ConvertToUri() const
|
std::shared_ptr<Uri> PasteDataEntry::ConvertToUri() const
|
||||||
{
|
{
|
||||||
std::string res;
|
std::string res;
|
||||||
if (GetUtdId() != UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::FILE_URI)) {
|
if (!UDMF::UnifiedDataUtils::IsFileUri(GetUtdId())) {
|
||||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "type error, utdId:%{public}s", GetUtdId().c_str());
|
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "type error, utdId:%{public}s", GetUtdId().c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ std::string CommonUtils::Convert2MimeType(const std::string &utdId)
|
|||||||
if (utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::HTML)) {
|
if (utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::HTML)) {
|
||||||
return MIMETYPE_TEXT_HTML;
|
return MIMETYPE_TEXT_HTML;
|
||||||
}
|
}
|
||||||
if (utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::FILE_URI)) {
|
if (UDMF::UnifiedDataUtils::IsFileUri(utdId)) {
|
||||||
return MIMETYPE_TEXT_URI;
|
return MIMETYPE_TEXT_URI;
|
||||||
}
|
}
|
||||||
if (utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::SYSTEM_DEFINED_PIXEL_MAP)) {
|
if (utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::SYSTEM_DEFINED_PIXEL_MAP)) {
|
||||||
|
@ -578,7 +578,7 @@ bool PasteDataRecord::HasEmptyEntry() const
|
|||||||
if (udmfValue_ && !std::holds_alternative<std::monostate>(*udmfValue_)) {
|
if (udmfValue_ && !std::holds_alternative<std::monostate>(*udmfValue_)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (auto const &entry : entries_) {
|
for (auto const &entry : GetEntries()) {
|
||||||
if (std::holds_alternative<std::monostate>(entry->GetValue())) {
|
if (std::holds_alternative<std::monostate>(entry->GetValue())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user