File indexing completed on 2024-04-21 04:34:33

0001 /*
0002  * This file is part of KDevelop Krazy2 Plugin.
0003  *
0004  * Copyright 2012 Daniel Calviño Sánchez <danxuliu@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License
0008  * as published by the Free Software Foundation; either version 2
0009  * of the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program. If not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef CHECKERLISTJOB_H
0021 #define CHECKERLISTJOB_H
0022 
0023 #include <KJob>
0024 
0025 #include <QProcess>
0026 
0027 class Checker;
0028 
0029 /**
0030  * Job to get the checker list from krazy2,
0031  * The job executes a krazy2 process asking it to print a list with all the
0032  * available checkers and then parses the output to populate a QList with
0033  * Checker objects.
0034  *
0035  * The path to the krazy2 executable is got from "Krazy2" configuration group.
0036  *
0037  * The job is killable.
0038  */
0039 class CheckerListJob: public KJob {
0040 Q_OBJECT
0041 public:
0042 
0043     /**
0044      * Creates a new CheckerListJob with the given parent.
0045      *
0046      * @param parent The parent QObject.
0047      */
0048     explicit CheckerListJob(QObject* parent = nullptr);
0049 
0050     //<KJob>
0051 
0052     /**
0053      * Starts krazy2 asking it to print a list with all the checkers.
0054      */
0055     void start() override;
0056 
0057     //</KJob>
0058 
0059     /**
0060      * Sets the checker list to populate.
0061      *
0062      * @param checkerList The checker list to populate.
0063      * @see CheckerListParser::setCheckerList()
0064      */
0065     void setCheckerList(QList<const Checker*>* checkerList);
0066 
0067 protected:
0068 
0069     //<KJob>
0070 
0071     /**
0072      * Kills the underlying process.
0073      *
0074      * @return Always true.
0075      */
0076     bool doKill() override;
0077 
0078     //</KJob>
0079 
0080 private:
0081 
0082     /**
0083      * The checker list to populate.
0084      */
0085     QList<const Checker*>* m_checkerList;
0086 
0087     /**
0088      * The krazy2 process to parse its output.
0089      */
0090     QProcess* m_process;
0091 
0092 private Q_SLOTS:
0093 
0094     /**
0095      * Populates the checker list and ends this CheckerListJob emitting the
0096      * result.
0097      *
0098      * @param exitCode Unused.
0099      */
0100     void handleProcessFinished(int exitCode);
0101 
0102     /**
0103      * Sets the error code and error text for this CheckerListJob and ends it
0104      * emitting the result.
0105      *
0106      * @param processError The error occurred in the underlying process.
0107      */
0108     void handleProcessError(QProcess::ProcessError processError);
0109 
0110 };
0111 
0112 #endif