• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 operator==(const CopyInfo &infos) const
30     {
31         return (srcUri == infos.srcUri && destUri == infos.destUri);
32     }
33     bool operator<(const CopyInfo &infos) const
34     {
35         if (srcUri == infos.srcUri) {
36             return destUri < infos.destUri;
37         }
38         return srcUri < infos.srcUri;
39     }
40 };
41 
42 class PasteBoardCopyFile {
43 public:
44     static PasteBoardCopyFile &GetInstance();
45     int32_t CopyPasteData(PasteData &pasteData, std::shared_ptr<GetDataParams> dataParams);
46 private:
47     PasteBoardCopyFile() = default;
48     ~PasteBoardCopyFile() = default;
49     DISALLOW_COPY_AND_MOVE(PasteBoardCopyFile);
50     static bool IsDirectory(const std::string &path);
51     static bool IsFile(const std::string &path);
52     static std::string GetRealPath(const std::string& path);
53     static bool IsRemoteUri(const std::string &uri);
54     static int32_t CheckCopyParam(PasteData &pasteData, std::shared_ptr<GetDataParams> dataParams);
55     static int32_t InitCopyInfo(const std::string srcUri, std::shared_ptr<GetDataParams> dataParams,
56         std::shared_ptr<CopyInfo> copyInfo, int32_t index);
57     static void OnProgressNotify(std::shared_ptr<GetDataParams> params);
58     static int32_t CopyFileData(PasteData &pasteData, std::shared_ptr<GetDataParams> dataParams);
59 
60     static void HandleProgress(int32_t index, const CopyInfo &info, uint64_t processSize, uint64_t totalSize,
61         std::shared_ptr<GetDataParams> dataParams);
62     static ProgressListener progressListener_;
63     static std::atomic_bool canCancel_;
64     static bool ShouldKeepRecord(int32_t &ret, const std::string &destUri, std::shared_ptr<PasteDataRecord> record);
65 };
66 } // namespace MiscServices
67 } // namespace OHOS
68 
69 #endif // PASTE_BOARD_COPY_H