File indexing completed on 2024-06-16 08:27:28

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef EXTERNALLANGUAGE_H
0012 #define EXTERNALLANGUAGE_H
0013 
0014 #include "language.h"
0015 
0016 #include <QProcess>
0017 
0018 class KProcess;
0019 
0020 /**
0021 Base class for Language support that relies on an external program; so this
0022 class provides functionality for dealing with external processes.
0023 
0024 @author Daniel Clarke
0025 @author David Saxton
0026 */
0027 class ExternalLanguage : public Language
0028 {
0029     Q_OBJECT
0030 public:
0031     ExternalLanguage(ProcessChain *processChain, const QString &name);
0032     ~ExternalLanguage() override;
0033 
0034 protected slots:
0035     void processStdout();
0036     void processStderr();
0037     void processExited(int, QProcess::ExitStatus);
0038 
0039 protected:
0040     /**
0041      * Call this to start the language process. ExternalLanguage will ensure
0042      * that communication et all is properly set up.
0043      * @return true on success, false on error
0044      */
0045     bool start();
0046     /**
0047      * @returns whether the string outputted to stdout is an error or not
0048      */
0049     virtual bool isError(const QString &message) const = 0;
0050     /**
0051      * @returns whether the string outputted to stderr is fatal (stopped compilation)
0052      */
0053     virtual bool isStderrOutputFatal(const QString &message) const
0054     {
0055         Q_UNUSED(message);
0056         return true;
0057     }
0058     /**
0059      * @returns whether the string outputted to stdout is a warning or not
0060      */
0061     virtual bool isWarning(const QString &message) const = 0;
0062     /**
0063      * Called when the process outputs a (non warning/error) message
0064      */
0065     virtual void outputtedMessage(const QString & /*message*/) {};
0066     /**
0067      * Called when the process outputs a warning
0068      */
0069     virtual void outputtedWarning(const QString & /*message*/) {};
0070     /**
0071      * Called when the process outputs an error
0072      */
0073     virtual void outputtedError(const QString & /*message*/) {};
0074     /**
0075      * Called when the process exits (called before any signals are emitted,
0076      * etc). If you reinherit this function, you should return whether
0077      * everything is OK.
0078      */
0079     virtual bool processExited(bool successfully)
0080     {
0081         return successfully;
0082     }
0083     /**
0084      * Call this function if your process could not be started - the process
0085      * will be deleted, and a failure signal emitted.
0086      */
0087     void processInitFailed();
0088     /**
0089      * Disconnects and deletes the language's process.
0090      */
0091     void deleteLanguageProcess();
0092     /**
0093      * Creates process and makes connections, ready for the derived class to
0094      * add arguments and start the process.
0095      */
0096     void resetLanguageProcess();
0097     /**
0098      * Prints out the command used for running the process, with any arguments
0099      * that contain spaces put into quotation marks.
0100      */
0101     void displayProcessCommand();
0102 
0103     KProcess *m_languageProcess;
0104 };
0105 
0106 #endif