File indexing completed on 2024-04-28 04:39:08

0001 /*
0002     SPDX-FileCopyrightText: 2017 Alexander Potashev <aspotashev@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_PLUGIN_PROJECTMANAGERVIEW_CUTCOPYPASTEHELPERS_H
0008 #define KDEVPLATFORM_PLUGIN_PROJECTMANAGERVIEW_CUTCOPYPASTEHELPERS_H
0009 
0010 #include <util/path.h>
0011 #include <project/projectmodel.h>
0012 
0013 namespace CutCopyPasteHelpers
0014 {
0015 
0016 enum class Operation {
0017     COPY,
0018     CUT,
0019 };
0020 
0021 enum class TaskStatus
0022 {
0023     SUCCESS,
0024     FAILURE,
0025     SKIPPED,
0026 };
0027 
0028 enum class TaskType
0029 {
0030     COPY,
0031     MOVE,
0032     DELETION,
0033 };
0034 
0035 struct TaskInfo
0036 {
0037     TaskInfo() = default;
0038     TaskInfo(const TaskStatus status, const TaskType type,
0039              const KDevelop::Path::List& src, const KDevelop::Path& dest);
0040 
0041     static TaskInfo createMove(const bool ok, const KDevelop::Path::List& src, const KDevelop::Path& dest);
0042     static TaskInfo createCopy(const bool ok, const KDevelop::Path::List& src, const KDevelop::Path& dest);
0043     static TaskInfo createDeletion(const bool ok, const KDevelop::Path::List& src, const KDevelop::Path& dest);
0044 
0045     TaskStatus m_status;
0046     TaskType m_type;
0047     KDevelop::Path::List m_src;
0048     KDevelop::Path m_dest;
0049 };
0050 
0051 struct SourceToDestinationMap
0052 {
0053     KDevelop::Path::List filteredPaths;
0054 
0055     // finalPaths is a map: source path -> new paths. If source path
0056     // succeeds to copy/move, then the new paths must be highlighted
0057     // in the project manager view.
0058     // Highlighting of all destination files without regard of which
0059     // operations were successful won't work in the case when the destination
0060     // file already exists and a replacing copy/move fails.
0061     QHash<KDevelop::Path, KDevelop::Path::List> finalPaths;
0062 };
0063 
0064 SourceToDestinationMap mapSourceToDestination(const KDevelop::Path::List& sourcePaths, const KDevelop::Path& destinationPath);
0065 
0066 QVector<TaskInfo> copyMoveItems(const KDevelop::Path::List& paths, KDevelop::ProjectBaseItem* destItem, const Operation operation);
0067 
0068 void showWarningDialogForFailedPaste(QWidget* parent, const QVector<TaskInfo>& tasks);
0069 
0070 } // namespace CutCopyPasteHelpers
0071 
0072 Q_DECLARE_TYPEINFO(CutCopyPasteHelpers::TaskInfo, Q_MOVABLE_TYPE);
0073 
0074 #endif // KDEVPLATFORM_PLUGIN_PROJECTMANAGERVIEW_CUTCOPYPASTEHELPERS_H