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

0001 /*
0002     SPDX-FileCopyrightText: 2010-2012 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_ABSTRACTFILEMANAGERPLUGIN_H
0008 #define KDEVPLATFORM_ABSTRACTFILEMANAGERPLUGIN_H
0009 
0010 #include "projectexport.h"
0011 
0012 #include "interfaces/iprojectfilemanager.h"
0013 
0014 #include <QVariant>
0015 
0016 #include <interfaces/iplugin.h>
0017 
0018 class KDirWatch;
0019 
0020 namespace KDevelop {
0021 
0022 class AbstractFileManagerPluginPrivate;
0023 class AbstractFileManagerPluginImportBenchmark;
0024 
0025 /**
0026  * This class can be used as a common base for file managers.
0027  *
0028  * It supports remote files using KIO and uses KDirWatch to synchronize with on-disk changes.
0029  */
0030 class KDEVPLATFORMPROJECT_EXPORT AbstractFileManagerPlugin : public IPlugin, public virtual IProjectFileManager
0031 {
0032     Q_OBJECT
0033     Q_INTERFACES( KDevelop::IProjectFileManager )
0034 
0035 public:
0036     explicit AbstractFileManagerPlugin( const QString& componentName, QObject *parent = nullptr,
0037                                         const QVariantList &args = QVariantList() );
0038     ~AbstractFileManagerPlugin() override;
0039 
0040 //
0041 // IProjectFileManager interface
0042 //
0043     Features features() const override;
0044 
0045     ProjectFolderItem* addFolder( const Path& folder, ProjectFolderItem *parent ) override;
0046     ProjectFileItem* addFile( const Path& file, ProjectFolderItem *parent ) override;
0047     bool removeFilesAndFolders( const QList<ProjectBaseItem*> &items ) override;
0048     bool moveFilesAndFolders(const QList< ProjectBaseItem* >& items, ProjectFolderItem* newParent) override;
0049     bool copyFilesAndFolders(const Path::List& items, ProjectFolderItem* newParent) override;
0050     bool renameFolder(ProjectFolderItem* folder, const Path& newPath) override;
0051     bool renameFile(ProjectFileItem* file, const Path& newPath) override;
0052 
0053     QList<ProjectFolderItem*> parse( ProjectFolderItem *item ) override;
0054     ProjectFolderItem *import( IProject *project ) override;
0055     bool reload(ProjectFolderItem* item) override;
0056     KJob* createImportJob(ProjectFolderItem* item) override;
0057 
0058 protected:
0059 //
0060 // AbstractFileManagerPlugin interface
0061 //
0062     /**
0063      * Filter interface making it possible to hide files and folders from a project.
0064      *
0065      * The default implementation will query all IProjectFilter plugins and ask them
0066      * whether a given url should be included or not.
0067      *
0068      * @return True when @p path should belong to @p project, false otherwise.
0069      */
0070     virtual bool isValid(const Path& path, const bool isFolder, IProject* project) const;
0071 
0072     /**
0073      * Customization hook enabling you to create custom FolderItems if required.
0074      *
0075      * The default implementation will return a simple @c ProjectFolderItem
0076      */
0077     virtual ProjectFolderItem* createFolderItem( IProject* project, const Path& path,
0078                                                  ProjectBaseItem* parent = nullptr);
0079 
0080     /**
0081      * Customization hook enabling you to create custom FileItems if required.
0082      *
0083      * The default implementation will return a simple @c ProjectFileItem
0084      */
0085     virtual ProjectFileItem* createFileItem( IProject* project, const Path& path,
0086                                              ProjectBaseItem* parent);
0087 
0088     /**
0089      * @return the @c KDirWatch for the given @p project.
0090      */
0091     KDirWatch* projectWatcher( IProject* project ) const;
0092 
0093 Q_SIGNALS:
0094     void reloadedFileItem(KDevelop::ProjectFileItem* file);
0095     void reloadedFolderItem(KDevelop::ProjectFolderItem* folder);
0096 
0097     void folderAdded(KDevelop::ProjectFolderItem* folder);
0098     void folderRemoved(KDevelop::ProjectFolderItem* folder);
0099     void folderRenamed(const KDevelop::Path& oldFolder, KDevelop::ProjectFolderItem* newFolder);
0100 
0101     void fileAdded(KDevelop::ProjectFileItem* file);
0102     void fileRemoved(KDevelop::ProjectFileItem* file);
0103     void fileRenamed(const KDevelop::Path& oldFile, KDevelop::ProjectFileItem* newFile);
0104 
0105 private:
0106     const QScopedPointer<class AbstractFileManagerPluginPrivate> d_ptr;
0107     Q_DECLARE_PRIVATE(AbstractFileManagerPlugin)
0108     friend class AbstractFileManagerPluginPrivate;
0109 public:
0110     friend class AbstractFileManagerPluginImportBenchmark;
0111 };
0112 
0113 }
0114 
0115 #endif // KDEVPLATFORM_ABSTRACTFILEMANAGERPLUGIN_H