File indexing completed on 2024-04-28 08:25:29

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 KRAZY2PLUGIN_H
0021 #define KRAZY2PLUGIN_H
0022 
0023 #include <QVariant>
0024 
0025 #include <kdevplatform/interfaces/iplugin.h>
0026 #include <QList>
0027 
0028 namespace KDevelop
0029 {
0030 class ProblemModel;
0031 }
0032 
0033 class Checker;
0034 class AnalysisResults;
0035 class KJob;
0036 
0037 /**
0038  * KDevelop plugin to show issues reported by Krazy2.
0039  */
0040 class Krazy2Plugin: public KDevelop::IPlugin {
0041 Q_OBJECT
0042 public:
0043 
0044     /**
0045      * Creates a new Krazy2Plugin.
0046      * Adds a KDevelop tool view factory for this Krazy2Plugin.
0047      *
0048      * Unnamed QVariantList parameter required by KPluginFactory.
0049      *
0050      * @param parent Parent object.
0051      */
0052     explicit Krazy2Plugin(QObject* parent, const QVariantList& = QVariantList());
0053 
0054     /**
0055      * Destroys this Krazy2Plugin.
0056      */
0057     ~Krazy2Plugin() override;
0058 
0059     /**
0060      * Remove KDevelop tool view when this Krazy2Plugin is unloaded.
0061      */
0062     void unload() override;
0063 
0064     int configPages() const override { return 1; }
0065 
0066     KDevelop::ConfigPage* configPage(int number, QWidget *parent) override;
0067 
0068     int perProjectConfigPages() const override{ return 1; }
0069 
0070     KDevelop::ConfigPage* perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions &options, QWidget *parent) override;
0071 
0072     QList<const Checker*>* checkers() { return &m_checkers; }
0073 
0074 private slots:
0075     // Check the files that have been selected in the per project Krazy2 settings page
0076     void checkSelectedFiles();
0077 
0078     // Check all files of the project
0079     void checkAllFiles();
0080 
0081     // Triggered when the checker list job is finished
0082     void onListingFinished(KJob *job);
0083 
0084     // Triggered when a Krazy2 analysis job is finished
0085     void onAnalysisFinished(KJob *job);
0086 
0087 private:
0088     // Starts a job that grabs the checker list
0089     void grabCheckerList();
0090 
0091     // Gathers all required data (paths, checker tools) and passes it to the other check method
0092     void check(bool allFiles);
0093 
0094     // Starts the Krazy2 checker job
0095     void check(QStringList paths, QList<const Checker*> &selectedCheckers);
0096 
0097     bool m_analysisInProgress;
0098     KDevelop::ProblemModel *m_model;
0099     QScopedPointer<AnalysisResults> m_results;
0100     QList<const Checker*> m_checkers;
0101 };
0102 
0103 #endif