1 /*
2     SPDX-FileCopyrightText: 2017 Alexander Potashev <aspotashev@gmail.com>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KDEVPLATFORM_PLUGIN_PROJECTMANAGERVIEW_CUTCOPYPASTEHELPERS_H
8 #define KDEVPLATFORM_PLUGIN_PROJECTMANAGERVIEW_CUTCOPYPASTEHELPERS_H
9 
10 #include <util/path.h>
11 #include <project/projectmodel.h>
12 
13 namespace CutCopyPasteHelpers
14 {
15 
16 enum class Operation {
17     COPY,
18     CUT,
19 };
20 
21 enum class TaskStatus
22 {
23     SUCCESS,
24     FAILURE,
25     SKIPPED,
26 };
27 
28 enum class TaskType
29 {
30     COPY,
31     MOVE,
32     DELETION,
33 };
34 
35 struct TaskInfo
36 {
37     TaskInfo() = default;
38     TaskInfo(const TaskStatus status, const TaskType type,
39              const KDevelop::Path::List& src, const KDevelop::Path& dest);
40 
41     static TaskInfo createMove(const bool ok, const KDevelop::Path::List& src, const KDevelop::Path& dest);
42     static TaskInfo createCopy(const bool ok, const KDevelop::Path::List& src, const KDevelop::Path& dest);
43     static TaskInfo createDeletion(const bool ok, const KDevelop::Path::List& src, const KDevelop::Path& dest);
44 
45     TaskStatus m_status;
46     TaskType m_type;
47     KDevelop::Path::List m_src;
48     KDevelop::Path m_dest;
49 };
50 
51 struct SourceToDestinationMap
52 {
53     KDevelop::Path::List filteredPaths;
54 
55     // finalPaths is a map: source path -> new paths. If source path
56     // succeeds to copy/move, then the new paths must be highlighted
57     // in the project manager view.
58     // Highlighting of all destination files without regard of which
59     // operations were successful won't work in the case when the destination
60     // file already exists and a replacing copy/move fails.
61     QHash<KDevelop::Path, KDevelop::Path::List> finalPaths;
62 };
63 
64 SourceToDestinationMap mapSourceToDestination(const KDevelop::Path::List& sourcePaths, const KDevelop::Path& destinationPath);
65 
66 QVector<TaskInfo> copyMoveItems(const KDevelop::Path::List& paths, KDevelop::ProjectBaseItem* destItem, const Operation operation);
67 
68 void showWarningDialogForFailedPaste(QWidget* parent, const QVector<TaskInfo>& tasks);
69 
70 } // namespace CutCopyPasteHelpers
71 
72 Q_DECLARE_TYPEINFO(CutCopyPasteHelpers::TaskInfo, Q_MOVABLE_TYPE);
73 
74 #endif // KDEVPLATFORM_PLUGIN_PROJECTMANAGERVIEW_CUTCOPYPASTEHELPERS_H
75