1 /*
2     SPDX-FileCopyrightText: 2004 Roberto Raggi <roberto@kdevelop.org>
3     SPDX-FileCopyrightText: 2006 Matt Rogers <mattr@kde.org>
4     SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
5     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
6     SPDX-FileCopyrightText: 2012 Milian Wolff <mail@milianw.de>
7 
8     SPDX-License-Identifier: LGPL-2.0-or-later
9 */
10 
11 #ifndef KDEVPLATFORM_IPROJECTFILEMANAGER_H
12 #define KDEVPLATFORM_IPROJECTFILEMANAGER_H
13 
14 #include <QObject>
15 
16 #include <project/projectexport.h>
17 
18 #include <util/path.h>
19 
20 class KJob;
21 
22 namespace KDevelop
23 {
24 
25 class IProject;
26 class ProjectBaseItem;
27 class ProjectFolderItem;
28 class ProjectFileItem;
29 
30 /**
31  * @short An interface to project file management
32  *
33  * FileManager is the class you want to implement for integrating
34  * a project manager in KDevelop.  For build systems, implement its
35  * child class, BuildManager.
36  *
37  * These classes \e do \e not cause files, folders etc. to be created
38  * or removed on disk.  They simply read from and write to the file(s)
39  * which describe the structure (eg. CMakeLists.txt for cmake, Makefile.am for automake, etc).
40  *
41  * @author Roberto Raggi, Matt Rogers, Hamish Rodda, Milian Wolff
42  */
43 class KDEVPLATFORMPROJECT_EXPORT IProjectFileManager
44 {
45 public:
46 
47     virtual ~IProjectFileManager();
48     /** Features the file manager supports */
49     enum Feature
50     {
51         None     = 0 ,     ///< This manager supports nothing
52         Folders  = 1 << 0, ///< Folders are supported by the manager
53         Targets  = 1 << 1, ///< Targets are supported by the manager
54         Files    = 1 << 2  ///< Files are supported by the manager
55     };
56     Q_DECLARE_FLAGS( Features, Feature )
57 
58     /**
59      * @return the Features supported by the filemanager
60      */
61     virtual Features features() const = 0;
62 
63     /**
64      * This method initialize the model item @arg dom
65      * @return The list of the sub folders
66      */
67     virtual QList<ProjectFolderItem*> parse(ProjectFolderItem *dom) = 0;
68 
69     /**
70      * This method creates the root item from the file @arg fileName
71      * @return The created item
72      */
73     virtual ProjectFolderItem *import(IProject *project) = 0;
74 
75     /**
76      * @brief This method creates an import job for the given @p item
77      *
78      * @details The default implementation should be suitable for most needs,
79      * it'll create an instance of class @ref ImportProjectJob
80      *
81      * @return a job that imports the project
82      */
83     virtual KJob* createImportJob(ProjectFolderItem* item);
84 
85     /**
86      * Add a folder to the project and create it on disk.
87      *
88      * Adds the folder specified by @p folder to @p parent and modifies the
89      * underlying build system if needed
90      */
91     virtual ProjectFolderItem* addFolder(const Path& folder, ProjectFolderItem* parent) = 0;
92 
93     /**
94      * Add a file to a folder and create it on disk.
95      *
96      * Adds the file specified by @p file to the folder @p parent and modifies
97      * the underlying build system if needed. The file is not added to a target
98      */
99     virtual ProjectFileItem* addFile(const Path& file, ProjectFolderItem *parent) = 0;
100 
101     /**
102      * Remove files or folders from the project and delete them from disk
103      *
104      * Removes the files or folders specified by @p items and
105      * modifies the underlying build system if needed.
106      *
107      * Note: Do not attempt to remove subitems along with their parents
108      */
109     virtual bool removeFilesAndFolders(const QList<ProjectBaseItem*> &items) = 0;
110 
111     /**
112      * Move files and folders within a given project
113      *
114      * Moves the files or folders specified by @p items to @p newParent and
115      * modifies the underlying build system as needed
116      *
117      * Note: Do not attempt to move subitems along with their parents
118      */
119     virtual bool moveFilesAndFolders(const QList< KDevelop::ProjectBaseItem* > &items, KDevelop::ProjectFolderItem* newParent) = 0;
120 
121     /**
122      * Copy files and folders within a given project
123      *
124      * Copies the files or folders specified by @p items to @p newParent and
125      * modifies the underlying build system as needed
126      *
127      * Note: Do not attempt to copy subitems along with their parents
128      */
129     virtual bool copyFilesAndFolders(const Path::List &items, KDevelop::ProjectFolderItem* newParent) = 0;
130 
131     /**
132      * Rename a file in the project
133      *
134      * Renames the file specified by @p oldFile to @p newPath
135      */
136     virtual bool renameFile(ProjectFileItem* file, const Path& newPath) = 0;
137 
138     /**
139      * Rename a folder in the project
140      *
141      * Renames the folder specified by @p oldFile to @p newPath
142      */
143     virtual bool renameFolder(ProjectFolderItem* oldFolder, const Path& newPath) = 0;
144 
145     /**
146      * Reload an item in the project
147      *
148      * Reloads the item specified by @p item
149      */
150     virtual bool reload(ProjectFolderItem* item) = 0;
151 
152 Q_SIGNALS:
153     void folderAdded(KDevelop::ProjectFolderItem* folder);
154     void folderRemoved(KDevelop::ProjectFolderItem* folder);
155     void folderRenamed(const KDevelop::Path& oldFolder, KDevelop::ProjectFolderItem* newFolder);
156 
157     void fileAdded(KDevelop::ProjectFileItem* file);
158     void fileRemoved(KDevelop::ProjectFileItem* file);
159     void fileRenamed(const KDevelop::Path& oldFile, KDevelop::ProjectFileItem* newFile);
160 };
161 
162 #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
163 Q_DECLARE_OPERATORS_FOR_FLAGS(IProjectFileManager::Features)
164 #endif
165 
166 }
167 
168 #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
169 Q_DECLARE_OPERATORS_FOR_FLAGS(KDevelop::IProjectFileManager::Features)
170 #endif
171 
172 Q_DECLARE_INTERFACE( KDevelop::IProjectFileManager, "org.kdevelop.IProjectFileManager")
173 
174 #endif
175