diff --git a/gui/FileList.cpp b/gui/FileList.cpp
new file mode 100644
index 000000000..11413d6e7
--- /dev/null
+++ b/gui/FileList.cpp
@@ -0,0 +1,105 @@
+/*
+ * Cppcheck - A tool for static C/C++ code analysis
+ * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include
+#include
+#include "filelist.h"
+
+QStringList FileList::GetDefaultFilters()
+{
+ QStringList extensions;
+ extensions << "*.cpp" << "*.cxx" << "*.cc" << "*.c" << "*.c++" << "*.txx";
+ return extensions;
+}
+
+bool FileList::FilterMatches(const QFileInfo &inf)
+{
+ if (inf.isFile())
+ {
+ const QStringList filters = FileList::GetDefaultFilters();
+ QString ext("*.");
+ ext += inf.suffix();
+ if (filters.contains(ext))
+ return true;
+ }
+ return false;
+}
+
+void FileList::AddFile(const QString &filepath)
+{
+ QFileInfo inf(filepath);
+ if (FilterMatches(inf))
+ mFileList << inf;
+}
+
+void FileList::AddDirectory(const QString &directory, bool recursive)
+{
+ QDir dir(directory);
+ dir.setSorting(QDir::Name);
+ const QStringList filters = FileList::GetDefaultFilters();
+ const QStringList origNameFilters = dir.nameFilters();
+ dir.setNameFilters(filters);
+ if (!recursive)
+ {
+ dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
+ QFileInfoList items = dir.entryInfoList();
+ mFileList += items;
+ }
+ else
+ {
+ dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
+ QFileInfoList items = dir.entryInfoList();
+ mFileList += items;
+
+ dir.setNameFilters(origNameFilters);
+ dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
+ QFileInfoList list = dir.entryInfoList();
+ QFileInfo item;
+ foreach(item, list)
+ {
+ const QString path = item.canonicalFilePath();
+ AddDirectory(path, recursive);
+ }
+ }
+}
+
+void FileList::AddPathList(const QStringList &paths)
+{
+ QString path;
+ foreach(path, paths)
+ {
+ QFileInfo inf(path);
+ if (inf.isFile())
+ AddFile(path);
+ else
+ AddDirectory(path, true);
+ }
+}
+
+QStringList FileList::GetFileList() const
+{
+ QStringList names;
+ QFileInfo item;
+ foreach(item, mFileList)
+ {
+ QString name = QDir::fromNativeSeparators(item.canonicalFilePath());
+ names << name;
+ }
+ return names;
+}
diff --git a/gui/FileList.h b/gui/FileList.h
new file mode 100644
index 000000000..fc002b9af
--- /dev/null
+++ b/gui/FileList.h
@@ -0,0 +1,81 @@
+/*
+ * Cppcheck - A tool for static C/C++ code analysis
+ * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef FILELIST_H
+#define FILELIST_H
+
+#include
+#include
+#include
+
+/**
+ * @brief A class for listing files and directories to check.
+ * This class creates a list of files to check. If directory name is given then
+ * all files in the directory matching the filter will be added. The directory
+ * can be also added recursively when all files in subdirectories are added too.
+ * The filenames are matched against the filter and only those files whose
+ * filename extension is included in the filter list are added.
+ */
+class FileList
+{
+public:
+
+ /**
+ * @brief Add filename to the list.
+ * @param filepath Full path to the file.
+ */
+ void AddFile(const QString &filepath);
+
+ /**
+ * @brief Add files in the directory to the list.
+ * @param directory Full pathname to directory to add.
+ * @param recursive If true also files in subdirectories are added.
+ */
+ void AddDirectory(const QString &directory, bool recursive = false);
+
+ /**
+ * @brief Add list of filenames and directories to the list.
+ * @param paths List of paths to add.
+ */
+ void AddPathList(const QStringList &paths);
+
+ /**
+ * @brief Return list of filenames (to check).
+ * @return list of filenames to check.
+ */
+ QStringList GetFileList() const;
+
+protected:
+
+ /**
+ * @brief Return list of default filename extensions included.
+ * @return list of default filename extensions included.
+ */
+ static QStringList GetDefaultFilters();
+
+ /**
+ * @brief Test if filename matches the filename extensions filtering.
+ * @param true if filename matches filterin.
+ */
+ bool FilterMatches(const QFileInfo &inf);
+
+private:
+ QFileInfoList mFileList;
+};
+
+#endif // FILELIST_H
diff --git a/gui/gui.pro b/gui/gui.pro
index 405f0abff..adccf59c7 100644
--- a/gui/gui.pro
+++ b/gui/gui.pro
@@ -64,7 +64,8 @@ HEADERS += mainwindow.h \
xmlreport.h \
translationhandler.h \
csvreport.h \
- logview.h
+ logview.h \
+ filelist.h
SOURCES += main.cpp \
mainwindow.cpp\
@@ -87,7 +88,8 @@ SOURCES += main.cpp \
xmlreport.cpp \
translationhandler.cpp \
csvreport.cpp \
- logview.cpp
+ logview.cpp \
+ filelist.cpp
win32 {
DEFINES += _CRT_SECURE_NO_WARNINGS
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 2819355b2..00fec5463 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -34,7 +34,7 @@
#include "project.h"
#include "report.h"
#include "logview.h"
-#include "../lib/filelister.h"
+#include "filelist.h"
// HTMLHelp is only available in Windows
#ifdef WIN32
@@ -210,13 +210,9 @@ void MainWindow::DoCheckFiles(const QStringList &files)
}
ClearResults();
- QStringList fileNames;
- QString selection;
-
- foreach(selection, files)
- {
- fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection));
- }
+ FileList pathList;
+ pathList.AddPathList(files);
+ QStringList fileNames = pathList.GetFileList();
mUI.mResults->Clear();
mThread->ClearFiles();
@@ -234,7 +230,7 @@ void MainWindow::DoCheckFiles(const QStringList &files)
mUI.mResults->CheckingStarted(fileNames.count());
- mThread->SetFiles(RemoveUnacceptedFiles(fileNames));
+ mThread->SetFiles(fileNames);
QDir inf(mCurrentDirectory);
const QString absDirectory = inf.absolutePath();
mSettings->setValue(SETTINGS_CHECK_PATH, absDirectory);
@@ -362,43 +358,6 @@ Settings MainWindow::GetCppcheckSettings()
return result;
}
-QStringList MainWindow::GetFilesRecursively(const QString &path)
-{
- QFileInfo info(path);
- QStringList list;
-
- if (info.isDir())
- {
- QDirIterator it(path, QDirIterator::Subdirectories);
-
- while (it.hasNext())
- {
- list << it.next();
- }
- }
- else
- {
- list << path;
- }
-
- return list;
-}
-
-QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list)
-{
- QStringList result;
- QString str;
- foreach(str, list)
- {
- if (getFileLister()->acceptFile(str.toStdString()))
- {
- result << str;
- }
- }
-
- return result;
-}
-
void MainWindow::CheckDone()
{
if (mExiting)
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index 9dade7908..dd1c939f5 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -251,14 +251,6 @@ protected:
*/
void DoCheckFiles(const QStringList &files);
- /**
- * @brief Get all files recursively from given path
- *
- * @param path Path to get files from
- * @return List of file paths
- */
- QStringList GetFilesRecursively(const QString &path);
-
/**
* @brief Get our default cppcheck settings and read project file.
*
@@ -266,14 +258,6 @@ protected:
*/
Settings GetCppcheckSettings();
- /**
- * @brief Removes all unaccepted (by cppcheck core) files from the list
- *
- * @param list List to remove unaccepted files from
- * @return List of files that are all accepted by cppcheck core
- */
- QStringList RemoveUnacceptedFiles(const QStringList &list);
-
/**
* @brief Load program settings
*