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

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Hamish Rodda <rodda@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_IRUNCONTROLLER_H
0008 #define KDEVPLATFORM_IRUNCONTROLLER_H
0009 
0010 #include "interfacesexport.h"
0011 
0012 #include <KJobTrackerInterface>
0013 
0014 class KJob;
0015 
0016 namespace KDevelop
0017 {
0018 class IProject;
0019 class ILaunchMode;
0020 class ILaunchConfiguration;
0021 class LaunchConfigurationType;
0022 
0023 /**
0024  * The main controller for running processes.
0025  */
0026 class KDEVPLATFORMINTERFACES_EXPORT IRunController : public KJobTrackerInterface
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     ///Constructor.
0032     explicit IRunController(QObject *parent);
0033 
0034     /**
0035      * Interrogate the current managed jobs
0036      */
0037     virtual QList<KJob*> currentJobs() const = 0;
0038 
0039     /**
0040      * An enumeration of the possible states for the run controller.
0041      */
0042     enum State {
0043         Idle     /**< No processes are currently running */,
0044         Running  /**< processes are currently running */
0045     };
0046     Q_ENUM(State)
0047 
0048     /**
0049      * Get a list of all launch modes that the app knows
0050      * @returns a list of registered launch modes
0051      */
0052     virtual QList<ILaunchMode*> launchModes() const = 0;
0053 
0054     /**
0055      * Get a list of all available launch configurations
0056      */
0057     virtual QList<ILaunchConfiguration*> launchConfigurations() const = 0;
0058 
0059     /**
0060      * Get a specific launch mode based using its \a id
0061      * @param id the identifier of the launchmode to get
0062      * @returns launch mode for the given id or 0 if no such mode is known
0063      */
0064     virtual ILaunchMode* launchModeForId( const QString& id ) const = 0;
0065     
0066     /**
0067      * add @p mode to the list of registered launch modes
0068      * @param mode the mode to be registered
0069      */
0070     virtual void addLaunchMode( ILaunchMode* mode ) = 0;
0071     
0072     /**
0073      * remove @p mode from the list of registered launch modes
0074      * @param mode the mode to be unregistered
0075      */
0076     virtual void removeLaunchMode( ILaunchMode* mode ) = 0;
0077 
0078     /**
0079      * Get a list of all configuration types that are registered
0080      * @returns a list of run configuration types
0081      */
0082     virtual QList<LaunchConfigurationType*> launchConfigurationTypes() const = 0;
0083 
0084     
0085     /**
0086      * Adds @p type to the list of known run config types
0087      * @param type the new run configuration type
0088      */
0089     virtual void addConfigurationType( LaunchConfigurationType* type ) = 0;
0090 
0091     /**
0092      * Removes @p type from the list of known run config types
0093      * @param type run configuration type that should be removed
0094      */
0095     virtual void removeConfigurationType( LaunchConfigurationType* type ) = 0;
0096     
0097     /**
0098      * Executes the default launch in the given mode
0099      * @param runMode the launch mode to start with
0100      */
0101     virtual void executeDefaultLaunch( const QString& runMode ) = 0;
0102 
0103     virtual KJob* execute(const QString& launchMode, ILaunchConfiguration* launch) = 0;
0104 
0105     /**
0106      * tries to find a launch config type for the given @p id
0107      * @param id the id of the launch configuration type to search
0108      * @returns the launch configuration type if found, or 0 otherwise
0109      */
0110     virtual LaunchConfigurationType* launchConfigurationTypeForId( const QString& id ) = 0;
0111     
0112     /**
0113      * Creates a new launch configuration in the given project or in the session if no project
0114      * was provided using the given launch configuration type and launcher. The configuration 
0115      * is also added to the list of configurations in the runcontroller.
0116      * 
0117      * @param type the launch configuration type to be used for the new config
0118      * @param launcher the mode and id of the launcher to be used in the config
0119      * @param project the project in which the launch configuration should be stored
0120      * @param name the name of the new launch configuration, if this is empty a new default name will be generated
0121      * @returns a new launch configuration
0122      */
0123     virtual ILaunchConfiguration* createLaunchConfiguration( LaunchConfigurationType* type,
0124                                                              const QPair<QString,QString>& launcher,
0125                                                              KDevelop::IProject* project = nullptr,
0126                                                              const QString& name = QString() ) = 0;
0127 
0128     /// Opens a dialog to setup new launch configurations, or to change the existing ones.
0129     virtual void showConfigurationDialog() const = 0;
0130 
0131 public Q_SLOTS:
0132     /**
0133      * Request for all running processes to be killed.
0134      */
0135     virtual void stopAllProcesses() = 0;
0136 
0137 Q_SIGNALS:
0138     /**
0139      * Notify that the state of the run controller has changed to \a {state}.
0140      */
0141     void runStateChanged(State state);
0142 
0143     /**
0144      * Notify that a new job has been registered.
0145      */
0146     void jobRegistered(KJob* job);
0147 
0148     /**
0149      * Notify that a job has been unregistered.
0150      */
0151     void jobUnregistered(KJob* job);
0152 };
0153 
0154 }
0155 
0156 #endif // KDEVPLATFORM_IRUNCONTROLLER_H