File indexing completed on 2024-04-28 04:37:23

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_PROJECTCONTROLLER_H
0009 #define KDEVPLATFORM_PROJECTCONTROLLER_H
0010 
0011 #include <interfaces/iprojectcontroller.h>
0012 
0013 #include <QUrl>
0014 
0015 #include <KIO/UDSEntry>
0016 
0017 #include "shellexport.h"
0018 
0019 namespace Sublime {
0020     class Area;
0021 }
0022 
0023 namespace KIO {
0024     class Job;
0025 }
0026 
0027 namespace KDevelop
0028 {
0029 
0030 class IProject;
0031 class Core;
0032 class Context;
0033 class ContextMenuExtension;
0034 class IPlugin;
0035 class ProjectControllerPrivate;
0036 
0037 class KDEVPLATFORMSHELL_EXPORT IProjectDialogProvider : public QObject
0038 {
0039 Q_OBJECT
0040 public:
0041     IProjectDialogProvider();
0042     ~IProjectDialogProvider() override;
0043 
0044 public Q_SLOTS:
0045     /**
0046      * Displays some UI to ask the user for the project location.
0047      *
0048      * @param fetch will tell the UI that the user might want to fetch the project first
0049      * @param startUrl tells where to look first
0050      */
0051     virtual QUrl askProjectConfigLocation(bool fetch, const QUrl& startUrl = QUrl(),
0052                                           const QUrl& repoUrl = QUrl(), IPlugin* plugin = nullptr) = 0;
0053     virtual bool userWantsReopen() = 0;
0054 };
0055 
0056 class KDEVPLATFORMSHELL_EXPORT ProjectController : public IProjectController
0057 {
0058     Q_OBJECT
0059     Q_CLASSINFO( "D-Bus Interface", "org.kdevelop.ProjectController" )
0060     friend class Core;
0061     friend class CorePrivate;
0062     friend class ProjectPreferences;
0063 
0064 public:
0065     explicit ProjectController( Core* core );
0066     ~ProjectController() override;
0067 
0068     IProject* projectAt( int ) const override;
0069     int projectCount() const override;
0070     QList<IProject*> projects() const override;
0071 
0072     ProjectBuildSetModel* buildSetModel() override;
0073     ProjectModel* projectModel() override;
0074     ProjectChangesModel* changesModel() override;
0075     IProject* findProjectByName( const QString& name ) override;
0076     IProject* findProjectForUrl( const QUrl& ) const override;
0077 
0078     bool isProjectNameUsed( const QString& name ) const override;
0079     void setDialogProvider(IProjectDialogProvider*);
0080 
0081     QUrl projectsBaseDirectory() const override;
0082     QString prettyFileName(const QUrl& url, FormattingOptions format = FormatHtml) const override;
0083     QString prettyFilePath(const QUrl& url, FormattingOptions format = FormatHtml) const override;
0084 
0085     ContextMenuExtension contextMenuExtension(KDevelop::Context* ctx, QWidget* parent);
0086 
0087     enum FetchFlag {
0088         NoFetchFlags = 0,
0089         FetchShowErrorIfNotSupported = 1,
0090     };
0091     Q_DECLARE_FLAGS(FetchFlags, FetchFlag)
0092 
0093     /**
0094      * @param repoUrl url identifying the repo
0095      * @returns @c true if a plugin was found to handle the repo (also if user cancelled), @c false otherwise
0096      */
0097     bool fetchProjectFromUrl(const QUrl& repoUrl, FetchFlags fetchFlags = FetchShowErrorIfNotSupported);
0098 
0099 public Q_SLOTS:
0100     Q_SCRIPTABLE void openProjectForUrl( const QString &sourceUrl ) { openProjectForUrl(QUrl(sourceUrl)); }
0101     void openProjectForUrl( const QUrl &sourceUrl ) override;
0102     void fetchProject();
0103     void openProject( const QUrl &KDev4ProjectFile = QUrl() ) override;
0104     void abortOpeningProject( IProject* );
0105     void projectImportingFinished( IProject* );
0106     void closeProject( IProject* ) override;
0107     void closeAllProjects() override;
0108     void configureProject( IProject* ) override;
0109 
0110     void reparseProject( IProject* project, bool forceUpdate = false, bool forceAll = false  ) override;
0111 
0112     void eventuallyOpenProjectFile(KIO::Job* job, const KIO::UDSEntryList& entries);
0113     void openProjectForUrlSlot(bool);
0114 //     void changeCurrentProject( ProjectBaseItem* );
0115     void openProjects(const QList<QUrl>& projects);
0116     void commitCurrentProject();
0117 
0118     // Maps the given path from the source to the equivalent path within the build directory
0119     // of the corresponding project. If the path is already in the build directory and fallbackRoot is true,
0120     // then it is mapped to the root of the build directory.
0121     // This is used through DBus from within kdevplatform_shell_environment.sh
0122     // If reverse is true, maps the opposite direction, from build to source. [ Used in kdevplatform_shell_environment.sh ]
0123     Q_SCRIPTABLE QString mapSourceBuild( const QString& path, bool reverse = false, bool fallbackRoot = true ) const;
0124 
0125 protected:
0126     /**
0127      * Add the existing project @p project to the controller
0128      *
0129      * @note Method is used for testing objectives, consider using openProject() instead!
0130      * @note takes ownership over the project
0131      *
0132      * @sa openProject()
0133      */
0134     void addProject(IProject* proj);
0135     /**
0136      * Remove the project @p project from the controller
0137      *
0138      * @note Ownership is passed on to the caller
0139      */
0140     void takeProject(IProject* proj);
0141 
0142     virtual void loadSettings( bool projectIsLoaded );
0143     virtual void saveSettings( bool projectIsLoaded );
0144 
0145     virtual void initialize();
0146 
0147 Q_SIGNALS:
0148     void initialized();
0149 
0150 private:
0151     //FIXME Do not load all of this just for the project being opened...
0152     //void legacyLoading();
0153     void setupActions();
0154     void cleanup();
0155 
0156     void saveRecentProjectsActionEntries();
0157 
0158     // helper methods for closeProject()
0159     void unloadUnusedProjectPlugins(IProject* proj);
0160     void disableProjectCloseAction();
0161     void closeAllOpenedFiles(IProject* proj);
0162     void initializePluginCleanup(IProject* proj);
0163 
0164 private:
0165     const QScopedPointer<class ProjectControllerPrivate> d_ptr;
0166     Q_DECLARE_PRIVATE(ProjectController)
0167     friend class ProjectControllerPrivate;
0168 };
0169 
0170 class ProjectDialogProvider : public IProjectDialogProvider
0171 {
0172 Q_OBJECT
0173 public:
0174     explicit ProjectDialogProvider(ProjectControllerPrivate* p);
0175     ~ProjectDialogProvider() override;
0176     ProjectControllerPrivate* const d;
0177 
0178 public Q_SLOTS:
0179     QUrl askProjectConfigLocation(bool fetch, const QUrl& startUrl,
0180                                   const QUrl& repoUrl, IPlugin* plugin) override;
0181     bool userWantsReopen() override;
0182 };
0183 
0184 
0185 }
0186 #endif