2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
|
|
|
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
|
|
|
* Leandro Penz, Kimmo Varis, Vesa Pikki
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMenu>
|
2009-03-22 13:32:07 +01:00
|
|
|
#include <QDirIterator>
|
2009-03-01 08:38:21 +01:00
|
|
|
#include <QMenuBar>
|
2009-03-22 13:32:07 +01:00
|
|
|
#include "../src/filelister.h"
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
|
|
|
|
MainWindow::MainWindow() :
|
2009-03-01 21:44:42 +01:00
|
|
|
mSettings(tr("CppCheck"), tr("CppCheck-GUI")),
|
2009-03-22 13:32:07 +01:00
|
|
|
mActionExit(tr("E&xit"), this),
|
|
|
|
mActionCheckFiles(tr("&Check files(s)"), this),
|
|
|
|
mActionCheckDirectory(tr("&Check directory"), this),
|
|
|
|
mActionSettings(tr("&Settings"), this),
|
2009-03-01 08:38:21 +01:00
|
|
|
mResults(mSettings)
|
|
|
|
{
|
|
|
|
QMenu *menu = menuBar()->addMenu(tr("&File"));
|
2009-03-22 13:32:07 +01:00
|
|
|
menu->addAction(&mActionCheckFiles);
|
|
|
|
menu->addAction(&mActionCheckDirectory);
|
2009-03-01 08:38:21 +01:00
|
|
|
menu->addSeparator();
|
2009-03-22 13:32:07 +01:00
|
|
|
menu->addAction(&mActionExit);
|
|
|
|
|
|
|
|
QMenu *menuprogram = menuBar()->addMenu(tr("&Program"));
|
|
|
|
menuprogram->addAction(&mActionSettings);
|
2009-03-01 08:38:21 +01:00
|
|
|
|
|
|
|
setCentralWidget(&mResults);
|
|
|
|
|
|
|
|
|
2009-03-22 13:32:07 +01:00
|
|
|
connect(&mActionExit, SIGNAL(triggered()), this, SLOT(close()));
|
|
|
|
connect(&mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles()));
|
|
|
|
connect(&mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory()));
|
|
|
|
connect(&mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings()));
|
2009-03-01 08:38:21 +01:00
|
|
|
connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone()));
|
|
|
|
LoadSettings();
|
2009-03-01 21:44:42 +01:00
|
|
|
mThread.Initialize(&mResults);
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2009-03-22 13:32:07 +01:00
|
|
|
SaveSettings();
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::LoadSettings()
|
|
|
|
{
|
2009-03-01 21:44:42 +01:00
|
|
|
if (mSettings.value(tr("Window maximized"), false).toBool())
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
|
|
|
showMaximized();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-01 21:44:42 +01:00
|
|
|
resize(mSettings.value(tr("Window width"), 800).toInt(),
|
|
|
|
mSettings.value(tr("Window height"), 600).toInt());
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::SaveSettings()
|
|
|
|
{
|
2009-03-01 21:44:42 +01:00
|
|
|
mSettings.setValue(tr("Window width"), size().width());
|
|
|
|
mSettings.setValue(tr("Window height"), size().height());
|
|
|
|
mSettings.setValue(tr("Window maximized"), isMaximized());
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-22 13:32:07 +01:00
|
|
|
void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-03-22 13:32:07 +01:00
|
|
|
QFileDialog dialog(this);
|
2009-03-22 14:15:16 +01:00
|
|
|
dialog.setDirectory(QDir(mSettings.value(tr("Check path"), "").toString()));
|
2009-03-22 13:32:07 +01:00
|
|
|
dialog.setFileMode(mode);
|
|
|
|
|
|
|
|
if (dialog.exec())
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-03-22 13:32:07 +01:00
|
|
|
QStringList selected = dialog.selectedFiles();
|
|
|
|
QStringList fileNames;
|
|
|
|
QString selection;
|
|
|
|
|
2009-03-22 14:15:16 +01:00
|
|
|
foreach(selection, selected)
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
|
|
|
fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection));
|
|
|
|
}
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
mResults.Clear();
|
|
|
|
mThread.ClearFiles();
|
2009-03-22 13:32:07 +01:00
|
|
|
mThread.SetFiles(RemoveUnacceptedFiles(fileNames));
|
|
|
|
mSettings.setValue(tr("Check path"), dialog.directory().absolutePath());
|
|
|
|
mActionCheckFiles.setDisabled(true);
|
|
|
|
mThread.Check(GetCppCheckSettings());
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-22 13:32:07 +01:00
|
|
|
void MainWindow::CheckFiles()
|
|
|
|
{
|
|
|
|
DoCheckFiles(QFileDialog::ExistingFiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::CheckDirectory()
|
|
|
|
{
|
|
|
|
DoCheckFiles(QFileDialog::DirectoryOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings MainWindow::GetCppCheckSettings()
|
|
|
|
{
|
|
|
|
Settings result;
|
|
|
|
result._debug = false;
|
|
|
|
result._showAll = true;
|
|
|
|
result._checkCodingStyle = true;
|
|
|
|
result._errorsOnly = false;
|
|
|
|
result._verbose = true;
|
|
|
|
result._force = true;
|
|
|
|
result._xml = false;
|
|
|
|
result._unusedFunctions = true;
|
|
|
|
result._security = true;
|
|
|
|
result._jobs = mSettings.value(tr("Check threads"), 1).toInt();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList MainWindow::RemoveDuplicates(const QStringList &list)
|
|
|
|
{
|
|
|
|
QHash<QString, int> hash;
|
|
|
|
QString str;
|
|
|
|
foreach(str, list)
|
|
|
|
{
|
|
|
|
hash[str] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QStringList(hash.uniqueKeys());
|
|
|
|
}
|
|
|
|
|
|
|
|
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 (FileLister::AcceptFile(str.toStdString()))
|
|
|
|
{
|
|
|
|
result << str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
void MainWindow::CheckDone()
|
|
|
|
{
|
2009-03-22 13:32:07 +01:00
|
|
|
mActionCheckFiles.setDisabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ProgramSettings()
|
|
|
|
{
|
|
|
|
SettingsDialog dialog(mSettings);
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
dialog.SaveCheckboxValues();
|
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2009-03-22 13:32:07 +01:00
|
|
|
|