File indexing completed on 2024-04-21 04:34:32
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 #include "analysisparameters.h" 0021 0022 #include <QDir> 0023 #include <QFileInfo> 0024 0025 #include "checker.h" 0026 0027 //public: 0028 0029 AnalysisParameters::AnalysisParameters(): 0030 m_checkersInitialized(false) { 0031 } 0032 0033 AnalysisParameters::~AnalysisParameters() { 0034 qDeleteAll(m_availableCheckers); 0035 } 0036 0037 bool AnalysisParameters::wereCheckersInitialized() const { 0038 return m_checkersInitialized; 0039 } 0040 0041 void AnalysisParameters::initializeCheckers(const QList<const Checker*>& availableCheckers) { 0042 qDeleteAll(m_availableCheckers); 0043 0044 m_availableCheckers = availableCheckers; 0045 0046 foreach (const Checker* checker, m_availableCheckers) { 0047 if (!checker->isExtra()) { 0048 m_checkersToRun.append(checker); 0049 } 0050 } 0051 0052 m_checkersInitialized = true; 0053 } 0054 0055 const QList<const Checker*>& AnalysisParameters::availableCheckers() const { 0056 return m_availableCheckers; 0057 } 0058 0059 const QList<const Checker*>& AnalysisParameters::checkersToRun() const { 0060 return m_checkersToRun; 0061 } 0062 0063 void AnalysisParameters::setCheckersToRun(const QList<const Checker*>& checkersToRun) { 0064 m_checkersToRun = checkersToRun; 0065 0066 foreach (const Checker* checker, checkersToRun) { 0067 if (!m_availableCheckers.contains(checker)) { 0068 m_checkersToRun.removeOne(checker); 0069 } 0070 } 0071 } 0072 0073 QStringList AnalysisParameters::filesToBeAnalyzed() const { 0074 QStringList fileNames; 0075 foreach (const QString& path, m_filesAndDirectories) { 0076 QFileInfo pathInfo(path); 0077 if (pathInfo.isDir()) { 0078 fileNames.append(findFiles(path)); 0079 } else if (pathInfo.isFile() && pathInfo.isReadable()) { 0080 fileNames.append(pathInfo.canonicalFilePath()); 0081 } 0082 } 0083 0084 fileNames.removeDuplicates(); 0085 return fileNames; 0086 } 0087 0088 const QStringList& AnalysisParameters::filesAndDirectories() const { 0089 return m_filesAndDirectories; 0090 } 0091 0092 void AnalysisParameters::setFilesAndDirectories(const QStringList& paths) { 0093 m_filesAndDirectories = paths; 0094 } 0095 0096 //private: 0097 0098 QStringList AnalysisParameters::findFiles(const QString& directory) const { 0099 QStringList fileNames; 0100 foreach (const QFileInfo& fileInfo, QDir(directory).entryInfoList(QDir::AllEntries | QDir::Hidden)) { 0101 if (fileInfo.isDir() && fileInfo.fileName() != "." && fileInfo.fileName() != "..") { 0102 fileNames.append(findFiles(fileInfo.canonicalFilePath())); 0103 } else if (fileInfo.isFile() && fileInfo.isReadable()) { 0104 fileNames.append(fileInfo.canonicalFilePath()); 0105 } 0106 } 0107 0108 return fileNames; 0109 }