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_COPY_H 17 #define PASTE_BOARD_COPY_H 18 19 #include "pasteboard_client.h" 20 21 namespace OHOS { 22 namespace MiscServices { 23 using namespace OHOS::AppExecFwk; 24 struct CopyInfo { 25 std::string srcUri; 26 std::string destUri; 27 std::string srcPath; 28 std::string destPath; 29 bool isExist = false; 30 bool operator==(const CopyInfo &infos) const 31 { 32 return (srcUri == infos.srcUri && destUri == infos.destUri); 33 } 34 bool operator<(const CopyInfo &infos) const 35 { 36 if (srcUri == infos.srcUri) { 37 return destUri < infos.destUri; 38 } 39 return srcUri < infos.srcUri; 40 } 41 }; 42 43 class PasteBoardCopyFile { 44 public: 45 static PasteBoardCopyFile &GetInstance(); 46 int32_t CopyPasteData(PasteData &pasteData, std::shared_ptr<GetDataParams> dataParams); 47 private: 48 PasteBoardCopyFile() = default; 49 ~PasteBoardCopyFile() = default; 50 DISALLOW_COPY_AND_MOVE(PasteBoardCopyFile); 51 static bool IsDirectory(const std::string &path); 52 static bool IsFile(const std::string &path); 53 static std::string GetRealPath(const std::string& path); 54 static bool IsRemoteUri(const std::string &uri); 55 static int32_t CheckCopyParam(PasteData &pasteData, std::shared_ptr<GetDataParams> dataParams); 56 static int32_t InitCopyInfo(const std::string srcUri, std::shared_ptr<GetDataParams> dataParams, 57 std::shared_ptr<CopyInfo> copyInfo, int32_t index); 58 static void OnProgressNotify(std::shared_ptr<GetDataParams> params); 59 static int32_t CopyFileData(PasteData &pasteData, std::shared_ptr<GetDataParams> dataParams); 60 61 static void HandleProgress(int32_t index, CopyInfo &info, uint64_t processSize, uint64_t totalSize, 62 std::shared_ptr<GetDataParams> dataParams); 63 static ProgressListener progressListener_; 64 }; 65 } // namespace MiscServices 66 } // namespace OHOS 67 68 #endif // PASTE_BOARD_COPY_H