File indexing completed on 2024-04-28 04:36:31

0001 /*
0002     SPDX-FileCopyrightText: 2009 Andreas Pakulat <apaku@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_LAUNCHCONFIGURATIONTYPE_H
0008 #define KDEVPLATFORM_LAUNCHCONFIGURATIONTYPE_H
0009 
0010 #include "interfacesexport.h"
0011 
0012 #include <QObject>
0013 
0014 class QMenu;
0015 class QIcon;
0016 class QUrl;
0017 class QStringList;
0018 class KConfigGroup;
0019 
0020 namespace KDevelop
0021 {
0022 class IProject;
0023 class ILaunchConfiguration;
0024 class ProjectBaseItem;
0025 class ILauncher;
0026 class LaunchConfigurationPageFactory;
0027 class LaunchConfigurationTypePrivate;
0028 
0029 /**
0030  * Launch configuration types are used to be able to create
0031  * new launch configurations. Each launch configuration has a
0032  * specific type, which specifies which launchers can be used
0033  * for the configuration as well as which config pages are needed
0034  * to setup the launch configuration
0035  */
0036 class KDEVPLATFORMINTERFACES_EXPORT LaunchConfigurationType : public QObject
0037 {
0038 Q_OBJECT
0039 public:
0040     LaunchConfigurationType();
0041     ~LaunchConfigurationType() override;
0042 
0043     /**
0044      * Provide a unique identifier for the type
0045      * among other things this will be used to create a config group in launch
0046      * configurations for the pages of this config type
0047      * @returns a unique identifier for this launch configuration type
0048      */
0049     virtual QString id() const = 0;
0050 
0051     /**
0052      * Provide a user visible name for the type
0053      * @returns a translatable string for the type
0054      */
0055     virtual QString name() const = 0;
0056 
0057     /**
0058      * Add @p starter to this configuration type
0059      * @param starter the launcher that can start configurations of this type
0060      */
0061     void addLauncher( ILauncher* starter );
0062 
0063     /**
0064      * remove @p starter from this configuration type
0065      * @param starter the launcher that should not start configurations of this type
0066      */
0067     void removeLauncher( ILauncher* starter );
0068 
0069     /**
0070      * Access all launchers that are usable with this type
0071      * @returns a list of launchers that can be used with configurations of this type
0072      */
0073     QList<ILauncher*> launchers() const;
0074 
0075     /**
0076      * Convenience method to access a launcher given its @p id
0077      * @param id the id of the launcher to be found
0078      * @returns the launcher with the given id or 0 if there's no such launcher in this configuration type
0079      */
0080     ILauncher* launcherForId(const QString& id) const;
0081 
0082     /**
0083      * Provide a list of widgets to configure a launch configuration for this type
0084      * @returns a list of factories to create config pages from.
0085      */
0086     virtual QList<LaunchConfigurationPageFactory*> configPages() const = 0;
0087 
0088     /**
0089      * Provide an icon for this launch configuration type
0090      * @returns an icon to be used for representing launch configurations of this type
0091      */
0092     virtual QIcon icon() const = 0;
0093 
0094     /**
0095      * Check whether this launch configuration type can launch the given project item
0096      * @param item the project tree item to test
0097      * @returns true if this configuration type can launch the given item, false otherwise
0098      */
0099     virtual bool canLaunch( KDevelop::ProjectBaseItem* item ) const = 0;
0100 
0101     /**
0102      * Configure the given launch configuration to execute the selected item
0103      * @param config the configuration to setup
0104      * @param item the item to launch
0105      */
0106     virtual void configureLaunchFromItem( KConfigGroup config,
0107                                           KDevelop::ProjectBaseItem* item ) const = 0;
0108 
0109     /**
0110      * Configure the given launch configuration to execute the selected item
0111      * @param config the configuration to setup
0112      * @param args argument list
0113      */
0114     virtual void configureLaunchFromCmdLineArguments( KConfigGroup config,
0115                                                       const QStringList &args ) const = 0;
0116 
0117     /**
0118     * Check whether this launch configuration type can launch the given file
0119     * @param file the file to test launchability
0120     * @returns true if this configuration type can launch the given file, false otherwise
0121     */
0122     virtual bool canLaunch( const QUrl& file ) const = 0;
0123 
0124     /**
0125      * Creates and returns a menu that will be added to the UI where the interface will be
0126      * able to add any suggestion it needs, like default targets.
0127      * Can be a nullptr if there are no suggestions.
0128      * Caller takes ownership of the returned menu.
0129      */
0130     virtual QMenu* launcherSuggestions() { return nullptr; }
0131 
0132 Q_SIGNALS:
0133     void signalAddLaunchConfiguration(KDevelop::ILaunchConfiguration* launch);
0134 
0135 private:
0136     const QScopedPointer<class LaunchConfigurationTypePrivate> d_ptr;
0137     Q_DECLARE_PRIVATE(LaunchConfigurationType)
0138 };
0139 
0140 }
0141 
0142 #endif
0143