1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PASTE_BOARD_ENTRY_H 17 #define PASTE_BOARD_ENTRY_H 18 19 #include "tlv_object.h" 20 #include "unified_meta.h" 21 #include "uri.h" 22 namespace OHOS { 23 namespace MiscServices { 24 class API_EXPORT MineCustomData : public TLVObject { 25 public: 26 MineCustomData() = default; 27 std::map<std::string, std::vector<uint8_t>> GetItemData(); 28 void AddItemData(const std::string& mimeType, const std::vector<uint8_t>& arrayBuffer); 29 bool Encode(std::vector<std::uint8_t>& buffer) override; 30 bool Decode(const std::vector<std::uint8_t>& buffer) override; 31 size_t Count() override; 32 33 private: 34 std::map<std::string, std::vector<uint8_t>> itemData_; 35 }; 36 37 class API_EXPORT PasteDataEntry : public TLVObject { 38 public: 39 using UDType = UDMF::UDType; 40 PasteDataEntry() = default; 41 PasteDataEntry(const PasteDataEntry& entry); 42 PasteDataEntry& operator=(const PasteDataEntry& entry); 43 PasteDataEntry(const std::string& utdId, const EntryValue& value); 44 PasteDataEntry(const std::string& utdId, const std::string& mimeType, const EntryValue& value); 45 46 std::shared_ptr<std::string> ConvertToPlianText() const; 47 std::shared_ptr<std::string> ConvertToHtml() const; 48 std::shared_ptr<Uri> ConvertToUri() const; 49 std::shared_ptr<AAFwk::Want> ConvertToWant() const; 50 std::shared_ptr<Media::PixelMap> ConvertToPixelMap() const; 51 std::shared_ptr<MineCustomData> ConvertToCustomData() const; 52 53 void SetValue(const EntryValue& value); 54 EntryValue GetValue() const; 55 void SetUtdId(const std::string& utdId); 56 std::string GetUtdId() const; 57 void SetMimeType(const std::string& mimeType); 58 std::string GetMimeType() const; 59 bool Encode(std::vector<std::uint8_t>& buffer) override; 60 bool Decode(const std::vector<std::uint8_t>& buffer) override; 61 size_t Count() override; 62 bool HasContent(const std::string &utdId) const; 63 64 bool Marshalling(std::vector<std::uint8_t>& buffer); 65 bool Unmarshalling(const std::vector<std::uint8_t>& buffer); 66 private: 67 std::string utdId_; 68 std::string mimeType_; // pasteboard mimeType 69 EntryValue value_; 70 }; 71 72 class API_EXPORT CommonUtils { 73 public: 74 using UDType = UDMF::UDType; 75 static std::string Convert(UDType uDType); 76 static std::string Convert2MimeType(const std::string& utdId); 77 static UDType Convert(int32_t uDType, const std::string& mimeType); 78 static std::string Convert2UtdId(int32_t uDType, const std::string& mimeType); 79 static bool IsFileUri(const std::string &utdId); 80 }; 81 } // namespace MiscServices 82 } // namespace OHOS 83 #endif // PASTE_BOARD_ENTRY_H