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),
|
2009-03-22 16:42:00 +01:00
|
|
|
mActionClearResults(tr("Clear &results"), this),
|
|
|
|
mActionReCheck(tr("Recheck files"), this),
|
|
|
|
mActionCheckDirectory(tr("Check &directory"), this),
|
2009-03-22 13:32:07 +01:00
|
|
|
mActionSettings(tr("&Settings"), this),
|
2009-03-22 18:39:44 +01:00
|
|
|
mActionShowAll(tr("Show &more errors"), this),
|
|
|
|
mActionShowSecurity(tr("Show &security errors"), this),
|
|
|
|
mActionShowStyle(tr("Show s&tyle errors"), this),
|
|
|
|
mActionShowUnused(tr("Show errors on &unused functions"), this),
|
|
|
|
mActionShowErrors(tr("Show &common errors"), this),
|
2009-05-23 10:17:27 +02:00
|
|
|
mActionShowCheckAll(tr("Check all"), this),
|
|
|
|
mActionShowUncheckAll(tr("Uncheck all"), this),
|
2009-05-23 13:26:04 +02:00
|
|
|
mResults(mSettings, mApplications)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
|
|
|
QMenu *menu = menuBar()->addMenu(tr("&File"));
|
2009-03-22 13:32:07 +01:00
|
|
|
menu->addAction(&mActionCheckFiles);
|
|
|
|
menu->addAction(&mActionCheckDirectory);
|
2009-03-22 16:42:00 +01:00
|
|
|
menu->addAction(&mActionReCheck);
|
|
|
|
menu->addAction(&mActionClearResults);
|
2009-03-01 08:38:21 +01:00
|
|
|
menu->addSeparator();
|
2009-03-22 13:32:07 +01:00
|
|
|
menu->addAction(&mActionExit);
|
|
|
|
|
2009-03-22 18:39:44 +01:00
|
|
|
QMenu *menuview = menuBar()->addMenu(tr("&View"));
|
|
|
|
mActionShowAll.setCheckable(true);
|
|
|
|
mActionShowSecurity.setCheckable(true);
|
|
|
|
mActionShowStyle.setCheckable(true);
|
|
|
|
mActionShowUnused.setCheckable(true);
|
|
|
|
mActionShowErrors.setCheckable(true);
|
|
|
|
|
|
|
|
menuview->addAction(&mActionShowAll);
|
|
|
|
menuview->addAction(&mActionShowSecurity);
|
|
|
|
menuview->addAction(&mActionShowStyle);
|
|
|
|
menuview->addAction(&mActionShowUnused);
|
|
|
|
menuview->addAction(&mActionShowErrors);
|
2009-05-23 10:17:27 +02:00
|
|
|
menuview->addAction(&mActionShowCheckAll);
|
|
|
|
menuview->addAction(&mActionShowUncheckAll);
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2009-03-22 13:32:07 +01:00
|
|
|
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-22 16:42:00 +01:00
|
|
|
connect(&mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults()));
|
2009-03-22 18:39:44 +01:00
|
|
|
|
|
|
|
connect(&mActionShowAll, SIGNAL(toggled(bool)), this, SLOT(ShowAll(bool)));
|
|
|
|
connect(&mActionShowSecurity, SIGNAL(toggled(bool)), this, SLOT(ShowSecurity(bool)));
|
|
|
|
connect(&mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool)));
|
|
|
|
connect(&mActionShowUnused, SIGNAL(toggled(bool)), this, SLOT(ShowUnused(bool)));
|
|
|
|
connect(&mActionShowErrors, SIGNAL(toggled(bool)), this, SLOT(ShowErrors(bool)));
|
2009-05-23 10:17:27 +02:00
|
|
|
connect(&mActionShowCheckAll, SIGNAL(triggered()), this, SLOT(CheckAll()));
|
|
|
|
connect(&mActionShowUncheckAll, SIGNAL(triggered()), this, SLOT(UncheckAll()));
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2009-03-22 16:42:00 +01:00
|
|
|
connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck()));
|
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-22 18:51:49 +01:00
|
|
|
setWindowTitle(tr("CppCheck"));
|
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
|
|
|
}
|
2009-03-22 18:39:44 +01:00
|
|
|
|
|
|
|
mActionShowAll.setChecked(mSettings.value(tr("Show all"), true).toBool());
|
|
|
|
mActionShowSecurity.setChecked(mSettings.value(tr("Show security"), true).toBool());
|
|
|
|
mActionShowStyle.setChecked(mSettings.value(tr("Show style"), true).toBool());
|
|
|
|
mActionShowUnused.setChecked(mSettings.value(tr("Show unused"), true).toBool());
|
|
|
|
mActionShowErrors.setChecked(mSettings.value(tr("Show errors"), true).toBool());
|
|
|
|
|
|
|
|
mResults.ShowResults(SHOW_ALL, mActionShowAll.isChecked());
|
|
|
|
mResults.ShowResults(SHOW_ERRORS, mActionShowErrors.isChecked());
|
|
|
|
mResults.ShowResults(SHOW_SECURITY, mActionShowSecurity.isChecked());
|
|
|
|
mResults.ShowResults(SHOW_STYLE, mActionShowStyle.isChecked());
|
|
|
|
mResults.ShowResults(SHOW_UNUSED, mActionShowUnused.isChecked());
|
2009-05-23 12:37:30 +02:00
|
|
|
mApplications.LoadSettings(mSettings);
|
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-22 18:39:44 +01:00
|
|
|
|
|
|
|
mSettings.setValue(tr("Show all"), mActionShowAll.isChecked());
|
|
|
|
mSettings.setValue(tr("Show security"), mActionShowSecurity.isChecked());
|
|
|
|
mSettings.setValue(tr("Show style"), mActionShowStyle.isChecked());
|
|
|
|
mSettings.setValue(tr("Show unused"), mActionShowUnused.isChecked());
|
|
|
|
mSettings.setValue(tr("Show errors"), mActionShowErrors.isChecked());
|
2009-05-23 12:37:30 +02:00
|
|
|
mApplications.SaveSettings(mSettings);
|
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());
|
2009-03-22 16:42:00 +01:00
|
|
|
EnableCheckButtons(false);
|
|
|
|
mThread.Check(GetCppCheckSettings(), false);
|
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;
|
2009-03-22 16:42:00 +01:00
|
|
|
result._force = mSettings.value(tr("Check force"), 1).toBool();
|
2009-03-22 13:32:07 +01:00
|
|
|
result._xml = false;
|
|
|
|
result._unusedFunctions = true;
|
|
|
|
result._security = true;
|
|
|
|
result._jobs = mSettings.value(tr("Check threads"), 1).toInt();
|
|
|
|
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 (FileLister::AcceptFile(str.toStdString()))
|
|
|
|
{
|
|
|
|
result << str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
void MainWindow::CheckDone()
|
|
|
|
{
|
2009-03-22 16:42:00 +01:00
|
|
|
EnableCheckButtons(true);
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ProgramSettings()
|
|
|
|
{
|
2009-05-23 13:26:04 +02:00
|
|
|
SettingsDialog dialog(mSettings, mApplications);
|
2009-03-22 13:32:07 +01:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
dialog.SaveCheckboxValues();
|
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-03-22 16:42:00 +01:00
|
|
|
|
|
|
|
void MainWindow::ReCheck()
|
|
|
|
{
|
|
|
|
ClearResults();
|
|
|
|
EnableCheckButtons(false);
|
|
|
|
mThread.Check(GetCppCheckSettings(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ClearResults()
|
|
|
|
{
|
|
|
|
mResults.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::EnableCheckButtons(bool enable)
|
|
|
|
{
|
|
|
|
mActionCheckFiles.setEnabled(enable);
|
|
|
|
mActionReCheck.setEnabled(enable);
|
|
|
|
mActionCheckDirectory.setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
2009-03-22 18:39:44 +01:00
|
|
|
|
|
|
|
void MainWindow::ShowAll(bool checked)
|
|
|
|
{
|
|
|
|
mResults.ShowResults(SHOW_ALL, checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ShowSecurity(bool checked)
|
|
|
|
{
|
|
|
|
mResults.ShowResults(SHOW_SECURITY, checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ShowStyle(bool checked)
|
|
|
|
{
|
|
|
|
mResults.ShowResults(SHOW_STYLE, checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ShowUnused(bool checked)
|
|
|
|
{
|
|
|
|
mResults.ShowResults(SHOW_UNUSED, checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ShowErrors(bool checked)
|
|
|
|
{
|
|
|
|
mResults.ShowResults(SHOW_ERRORS, checked);
|
|
|
|
}
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
void MainWindow::CheckAll()
|
|
|
|
{
|
|
|
|
ToggleAllChecked(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::UncheckAll()
|
|
|
|
{
|
|
|
|
ToggleAllChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ToggleAllChecked(bool checked)
|
|
|
|
{
|
|
|
|
mActionShowAll.setChecked(checked);
|
|
|
|
ShowAll(checked);
|
|
|
|
|
|
|
|
mActionShowSecurity.setChecked(checked);
|
|
|
|
ShowSecurity(checked);
|
|
|
|
|
|
|
|
mActionShowStyle.setChecked(checked);
|
|
|
|
ShowStyle(checked);
|
|
|
|
|
|
|
|
mActionShowUnused.setChecked(checked);
|
|
|
|
ShowUnused(checked);
|
|
|
|
|
|
|
|
mActionShowErrors.setChecked(checked);
|
|
|
|
ShowErrors(checked);
|
|
|
|
}
|