File indexing completed on 2024-04-28 04:36:30
0001 /* 0002 SPDX-FileCopyrightText: 2006 Adam Treat <treat@kde.org> 0003 SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KDEVPLATFORM_IPROJECTCONTROLLER_H 0009 #define KDEVPLATFORM_IPROJECTCONTROLLER_H 0010 0011 #include <QObject> 0012 #include <QList> 0013 #include <QUrl> 0014 0015 #include "interfacesexport.h" 0016 0017 namespace KDevelop 0018 { 0019 0020 class IProject; 0021 class ProjectBuildSetModel; 0022 class ProjectModel; 0023 class ProjectBaseItem; 0024 class ProjectChangesModel; 0025 0026 /** 0027 * @class IProjectController 0028 */ 0029 class KDEVPLATFORMINTERFACES_EXPORT IProjectController : public QObject 0030 { 0031 Q_OBJECT 0032 public: 0033 explicit IProjectController( QObject *parent = nullptr ); 0034 ~IProjectController() override; 0035 0036 Q_INVOKABLE virtual KDevelop::IProject* projectAt( int ) const = 0; 0037 Q_INVOKABLE virtual int projectCount() const = 0; 0038 Q_INVOKABLE virtual QList<IProject*> projects() const = 0; 0039 0040 /** 0041 * Provides access to the model representing the open projects 0042 * @returns the model containing the projects and their items 0043 */ 0044 virtual ProjectModel* projectModel() = 0; 0045 0046 0047 /** 0048 * @returns an instance to the model that keeps track of the state 0049 * of the files per project. 0050 */ 0051 virtual ProjectChangesModel* changesModel() = 0; 0052 0053 virtual ProjectBuildSetModel* buildSetModel() = 0; 0054 0055 /** 0056 * Find an open project using the name of the project 0057 * @param name the name of the project to be found 0058 * @returns the project or null if no project with that name is open 0059 */ 0060 virtual KDevelop::IProject* findProjectByName( const QString& name ) = 0; 0061 0062 /** 0063 * Finding an open project for a given file or folder in the project 0064 * @param url the url of a file/folder belonging to an open project 0065 * @returns the first open project containing the url or null if no such 0066 * project can be found 0067 */ 0068 virtual IProject* findProjectForUrl( const QUrl& url ) const = 0; 0069 0070 /** 0071 * Checks whether the given project name is used already or not. The project 0072 * controller supports only 1 project with a given name to be open at any time 0073 * @param name the name of the project to be opened or created 0074 * @returns whether the name is already used for an open project 0075 */ 0076 virtual bool isProjectNameUsed( const QString& name ) const = 0; 0077 0078 virtual QUrl projectsBaseDirectory() const = 0; 0079 0080 enum FormattingOptions { 0081 FormatHtml, 0082 FormatPlain 0083 }; 0084 0085 /** 0086 * Returns a pretty short representation of the base path of the url, considering the currently loaded projects: 0087 * When the file is part of a currently loaded project, that projects name is shown as prefix instead of the 0088 * the full file path. 0089 * The returned path always has a training slash. 0090 * @param format formatting used for the string 0091 */ 0092 virtual QString prettyFilePath(const QUrl& url, FormattingOptions format = FormatHtml) const = 0; 0093 0094 /** 0095 * Returns a pretty short representation of the given url, considering the currently loaded projects: 0096 * When the file is part of a currently loaded project, that projects name is shown as prefix instead of the 0097 * the full file path. 0098 * @param format formatting used for the string 0099 */ 0100 virtual QString prettyFileName(const QUrl& url, FormattingOptions format = FormatHtml) const = 0; 0101 0102 /** 0103 * @returns whether project files should be parsed or not 0104 */ 0105 static bool parseAllProjectSources(); 0106 0107 public Q_SLOTS: 0108 /** 0109 * Tries finding a project-file for the given source-url and opens it. 0110 * If no .kdev4 project file is found, the user is asked to import a project. 0111 */ 0112 virtual void openProjectForUrl( const QUrl &sourceUrl ) = 0; 0113 /** 0114 * open the project from the given kdev4 project file. This only reads 0115 * the file and starts creating the project model from it. The opening process 0116 * is finished once @ref projectOpened signal is emitted. 0117 * @param url a kdev4 project file top open 0118 */ 0119 virtual void openProject( const QUrl & url = QUrl() ) = 0; 0120 /** 0121 * close the given project. Closing the project is done in steps and 0122 * the @ref projectClosing and @ref projectClosed signals are emitted. Only when 0123 * the latter signal is emitted it is guaranteed that the project has been closed. 0124 * The @ref IProject object will be deleted after the closing has finished. 0125 */ 0126 virtual void closeProject( IProject* ) = 0; 0127 0128 /** 0129 * Close all projects 0130 * 0131 * This usually calls closeProject() on all controlled projects 0132 * @sa closeProject() 0133 */ 0134 virtual void closeAllProjects() = 0; 0135 0136 virtual void configureProject( IProject* ) = 0; 0137 0138 /** 0139 * Schedules all files of the @p project for reparsing by @see BackgroundParser 0140 * The @p forceAll argument is for triggering a full reparse of the entire project 0141 * after the initial import. 0142 */ 0143 virtual void reparseProject( IProject* project, bool forceUpdate = false, bool forceAll = false ) = 0; 0144 0145 // virtual void changeCurrentProject( KDevelop::ProjectBaseItem* ) = 0; 0146 0147 Q_SIGNALS: 0148 /** 0149 * Emitted right before a project is started to be loaded. 0150 * 0151 * At this point all sanity checks have been done, so the project 0152 * is really going to be loaded. Will be followed by @ref projectOpened signal 0153 * when loading completes or by @ref projectOpeningAborted if there are errors during loading 0154 * or it is aborted. 0155 * 0156 * @param project the project that is about to be opened. 0157 */ 0158 void projectAboutToBeOpened( KDevelop::IProject* project ); 0159 /** 0160 * emitted after a project is completely opened and the project model 0161 * has been populated. 0162 * @param project the project that has been opened. 0163 */ 0164 void projectOpened( KDevelop::IProject* project ); 0165 /** 0166 * emitted when starting to close a project that has been completely loaded before 0167 * (the @ref projectOpened signal has been emitted). 0168 * @param project the project that is going to be closed. 0169 */ 0170 void projectClosing( KDevelop::IProject* project ); 0171 /** 0172 * emitted when a project has been closed completely. 0173 * The project object is still valid, the deletion will be done 0174 * delayed during the next run of the event loop. 0175 * @param project the project that has been closed. 0176 */ 0177 void projectClosed( KDevelop::IProject* project ); 0178 /** 0179 * emitted when a project could not be loaded correctly or loading was aborted. 0180 * @p project contents may not be initialized properly. 0181 * @param project the project which loading has been aborted. 0182 */ 0183 void projectOpeningAborted( KDevelop::IProject* project ); 0184 0185 /** 0186 * emitted whenever the project configuration dialog accepted 0187 * changes 0188 * @param project the project whose configuration has changed 0189 */ 0190 void projectConfigurationChanged( KDevelop::IProject* project ); 0191 }; 0192 0193 } 0194 #endif 0195