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_readable.h" 20 #include "tlv_writeable.h" 21 22 namespace OHOS { 23 namespace MiscServices { 24 class API_EXPORT MineCustomData : public TLVWriteable, public TLVReadable { 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 30 bool EncodeTLV(WriteOnlyBuffer &buffer) const override; 31 bool DecodeTLV(ReadOnlyBuffer &buffer) override; 32 size_t CountTLV() const override; 33 34 private: 35 std::map<std::string, std::vector<uint8_t>> itemData_; 36 }; 37 38 class API_EXPORT PasteDataEntry : public TLVWriteable, public TLVReadable { 39 public: 40 using UDType = UDMF::UDType; 41 PasteDataEntry() = default; 42 PasteDataEntry(const PasteDataEntry &entry); 43 PasteDataEntry &operator=(const PasteDataEntry &entry); 44 PasteDataEntry(const std::string &utdId, const EntryValue &value); 45 PasteDataEntry(const std::string &utdId, const std::string &mimeType, const EntryValue &value); 46 47 std::shared_ptr<std::string> ConvertToPlainText() const; 48 std::shared_ptr<std::string> ConvertToHtml() const; 49 std::shared_ptr<Uri> ConvertToUri() const; 50 std::shared_ptr<AAFwk::Want> ConvertToWant() const; 51 std::shared_ptr<Media::PixelMap> ConvertToPixelMap() const; 52 std::shared_ptr<MineCustomData> ConvertToCustomData() const; 53 54 void SetValue(const EntryValue &value); 55 EntryValue GetValue() const; 56 void SetUtdId(const std::string &utdId); 57 std::string GetUtdId() const; 58 void SetMimeType(const std::string &mimeType); 59 std::string GetMimeType() const; 60 void SetFileSize(int64_t fileSize); 61 int64_t GetFileSize() const; 62 bool HasContent(const std::string &utdId) const; 63 bool HasContentByMimeType(const std::string &mimeType) const; 64 65 bool EncodeTLV(WriteOnlyBuffer &buffer) const override; 66 bool DecodeTLV(ReadOnlyBuffer &buffer) override; 67 size_t CountTLV() const override; 68 69 private: 70 std::string utdId_; 71 std::string mimeType_; // pasteboard mimeType 72 EntryValue value_; 73 }; 74 75 class API_EXPORT CommonUtils { 76 public: 77 using UDType = UDMF::UDType; 78 static std::string Convert(UDType uDType); 79 static std::string Convert2MimeType(const std::string &utdId); 80 static UDType Convert(int32_t uDType, const std::string &mimeType); 81 static std::string Convert2UtdId(int32_t uDType, const std::string &mimeType); 82 static bool IsFileUri(const std::string &utdId); 83 }; 84 } // namespace MiscServices 85 } // namespace OHOS 86 #endif // PASTE_BOARD_ENTRY_H