File indexing completed on 2024-04-28 17:06:31

0001 /*
0002     SPDX-FileCopyrightText: 2006 Shie Erlich <erlich@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2006 Rafi Yanai <yanai@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2006-2022 Krusader Krew <https://krusader.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KRACTIONBASE_H
0010 #define KRACTIONBASE_H
0011 
0012 // QtCore
0013 #include <QString>
0014 
0015 #include "expander.h"
0016 
0017 class KrActionProc;
0018 
0019 class KrActionBase
0020 {
0021 public:
0022     KrActionBase()
0023     {
0024     }
0025     virtual ~KrActionBase();
0026 
0027     /** \brief Specifies the mode for executing the action */
0028     enum ExecType {
0029         Normal, ///< Run the command freely
0030         Terminal, ///< Run the command in new terminal window
0031         CollectOutput, ///< Collect output from this command
0032         CollectOutputSeparateStderr, ///< Like #CollectOutput, but display stderr output separately
0033         RunInTE ///< Run in built-in terminal emulator
0034     };
0035 
0036     /** \brief Command which runs this action
0037      *
0038      * The string of the command may contain placeholders
0039      * which are parsed by the #Expander class, unless #doSubstitution
0040      * returns false
0041      *
0042      * The command is run by the shell, which should be bash (see #Expander)
0043      *
0044      * @see Expander
0045      * @see doSubstitution
0046      *
0047      * @return The command to execute
0048      */
0049     virtual QString command() const = 0;
0050     /** \brief Execution type of the action
0051      *
0052      * @see #ExecType
0053      */
0054     virtual ExecType execType() const = 0;
0055     /** \brief Working directory of the command
0056      *
0057      * @return The working directory of the command. May be \a null,
0058      *   in which case the command is executed in current directory
0059      */
0060     virtual QString startpath() const = 0;
0061     /** \brief Username under which the command is run
0062      *
0063      * @return The username of the command. May be \a null,
0064      *   in which case the command is executed under the current user
0065      */
0066     virtual QString user() const = 0;
0067     /** \brief Name of the action
0068      *
0069      * @return The name of the action which will be shown to the user
0070      *   eg. any string will do
0071      */
0072     virtual QString text() const = 0;
0073     /** \brief Does the command accept URLs as filenames (like KDE apps)?
0074      *
0075      * @return \a true iff it does
0076      */
0077     virtual bool acceptURLs() const = 0;
0078     /** \brief Confirm execution of this action by the user?
0079      *
0080      * @return \a true iff execution should be confirmed
0081      */
0082     virtual bool confirmExecution() const = 0;
0083     /** \brief Can #command contain placeholders?
0084      *
0085      * @return \a true iff #command should be expanded by #Expander
0086      */
0087     virtual bool doSubstitution() const = 0;
0088     /** \brief A factory method for creating KrActionProc
0089      *
0090      * @return A new instance of KrActionProc
0091      */
0092     virtual KrActionProc *actionProcFactoryMethod();
0093     virtual void handleError(const Error &err);
0094 
0095     void exec();
0096 };
0097 
0098 #endif