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