2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2009-05-30 07:48:12 +02:00
|
|
|
* Copyright (C) 2007-2009 Daniel Marjamäki and Cppcheck team.
|
2009-03-01 08:38:21 +01:00
|
|
|
*
|
|
|
|
* 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-05-24 10:53:29 +02:00
|
|
|
#include <QMessageBox>
|
2009-05-26 17:21:39 +02:00
|
|
|
#include <QToolBar>
|
2009-06-09 09:51:27 +02:00
|
|
|
#include <QKeySequence>
|
2009-06-17 21:35:24 +02:00
|
|
|
#include <QFileInfo>
|
2009-06-04 14:35:41 +02:00
|
|
|
#include "aboutdialog.h"
|
2009-06-20 18:55:23 +02:00
|
|
|
#include "threadhandler.h"
|
2009-06-14 11:57:43 +02:00
|
|
|
#include "fileviewdialog.h"
|
2009-03-22 13:32:07 +01:00
|
|
|
#include "../src/filelister.h"
|
2009-05-24 10:53:29 +02:00
|
|
|
#include "../src/cppcheckexecutor.h"
|
2009-03-01 08:38:21 +01:00
|
|
|
|
|
|
|
MainWindow::MainWindow() :
|
2009-05-24 10:53:29 +02: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-05-24 10:53:29 +02:00
|
|
|
mActionShowAll(tr("show possible false positives"), this),
|
2009-03-22 18:39:44 +01:00
|
|
|
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-06-02 00:26:44 +02:00
|
|
|
mActionShowCollapseAll(tr("Collapse all"), this),
|
|
|
|
mActionShowExpandAll(tr("Expand all"), this),
|
2009-05-24 10:53:29 +02:00
|
|
|
mActionAbout(tr("About"), this),
|
2009-06-14 11:57:43 +02:00
|
|
|
mActionShowLicense(tr("License..."), this),
|
|
|
|
mActionShowAuthors(tr("Authors..."), this),
|
2009-05-26 17:21:39 +02:00
|
|
|
mActionStop(tr("Stop checking"), this),
|
|
|
|
mActionSave(tr("Save results to a file"), this),
|
2009-05-23 13:26:04 +02:00
|
|
|
mResults(mSettings, mApplications)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-06-14 23:48:16 +02:00
|
|
|
CreateMenus();
|
|
|
|
CreateToolbar();
|
2009-06-20 18:55:23 +02:00
|
|
|
mThread = new ThreadHandler(this);
|
2009-05-24 10:53:29 +02:00
|
|
|
|
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-06-02 00:26:44 +02:00
|
|
|
connect(&mActionShowCollapseAll, SIGNAL(triggered()), &mResults, SLOT(CollapseAllResults()));
|
|
|
|
connect(&mActionShowExpandAll, SIGNAL(triggered()), &mResults, SLOT(ExpandAllResults()));
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2009-03-22 16:42:00 +01:00
|
|
|
connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck()));
|
2009-05-24 10:53:29 +02:00
|
|
|
|
2009-06-20 18:55:23 +02:00
|
|
|
connect(&mActionStop, SIGNAL(triggered()), mThread, SLOT(Stop()));
|
2009-05-26 17:21:39 +02:00
|
|
|
connect(&mActionSave, SIGNAL(triggered()), this, SLOT(Save()));
|
2009-05-24 10:53:29 +02:00
|
|
|
|
2009-05-26 17:21:39 +02:00
|
|
|
connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About()));
|
2009-06-14 11:57:43 +02:00
|
|
|
connect(&mActionShowLicense, SIGNAL(triggered()), this, SLOT(ShowLicense()));
|
|
|
|
connect(&mActionShowAuthors, SIGNAL(triggered()), this, SLOT(ShowAuthors()));
|
2009-06-14 23:48:16 +02:00
|
|
|
|
2009-06-20 18:55:23 +02:00
|
|
|
connect(mThread, SIGNAL(Done()), this, SLOT(CheckDone()));
|
2009-06-03 20:18:22 +02:00
|
|
|
connect(&mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded()));
|
2009-05-26 17:21:39 +02:00
|
|
|
|
2009-05-28 15:30:44 +02:00
|
|
|
mActionCheckDirectory.setIcon(QIcon(":icon.png"));
|
2009-05-28 10:32:32 +02:00
|
|
|
mActionReCheck.setIcon(QIcon(":images/view-refresh.png"));
|
|
|
|
mActionSettings.setIcon(QIcon(":images/preferences-system.png"));
|
|
|
|
mActionAbout.setIcon(QIcon(":images/help-browser.png"));
|
|
|
|
mActionStop.setIcon(QIcon(":images/process-stop.png"));
|
|
|
|
mActionSave.setIcon(QIcon(":images/media-floppy.png"));
|
|
|
|
mActionClearResults.setIcon(QIcon(":images/edit-clear.png"));
|
2009-05-26 17:21:39 +02:00
|
|
|
|
2009-06-09 09:51:27 +02:00
|
|
|
mActionReCheck.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
|
|
|
|
mActionCheckDirectory.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
|
|
|
|
mActionSave.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
|
|
|
mActionAbout.setShortcut(QKeySequence(Qt::Key_F1));
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
LoadSettings();
|
2009-06-20 18:55:23 +02:00
|
|
|
mThread->Initialize(&mResults);
|
2009-05-24 10:53:29 +02:00
|
|
|
setWindowTitle(tr("Cppcheck"));
|
2009-05-26 17:21:39 +02:00
|
|
|
|
|
|
|
EnableCheckButtons(true);
|
2009-06-03 20:18:22 +02:00
|
|
|
|
|
|
|
mActionClearResults.setEnabled(false);
|
|
|
|
mActionSave.setEnabled(false);
|
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
|
|
|
}
|
|
|
|
|
2009-06-14 23:48:16 +02:00
|
|
|
void MainWindow::CreateMenus()
|
|
|
|
{
|
|
|
|
// File-menu
|
|
|
|
QMenu *menu = menuBar()->addMenu(tr("&File"));
|
|
|
|
menu->addAction(&mActionCheckFiles);
|
|
|
|
menu->addAction(&mActionCheckDirectory);
|
|
|
|
menu->addAction(&mActionReCheck);
|
|
|
|
menu->addAction(&mActionStop);
|
|
|
|
menu->addAction(&mActionClearResults);
|
|
|
|
menu->addAction(&mActionSave);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(&mActionExit);
|
|
|
|
|
|
|
|
// View-menu
|
|
|
|
QMenu *menuview = menuBar()->addMenu(tr("&View"));
|
|
|
|
menuview->addAction(&mActionShowAll);
|
|
|
|
menuview->addAction(&mActionShowSecurity);
|
|
|
|
menuview->addAction(&mActionShowStyle);
|
|
|
|
menuview->addAction(&mActionShowUnused);
|
|
|
|
menuview->addAction(&mActionShowErrors);
|
|
|
|
menuview->addSeparator();
|
|
|
|
menuview->addAction(&mActionShowCheckAll);
|
|
|
|
menuview->addAction(&mActionShowUncheckAll);
|
|
|
|
menuview->addSeparator();
|
|
|
|
menuview->addAction(&mActionShowCollapseAll);
|
|
|
|
menuview->addAction(&mActionShowExpandAll);
|
|
|
|
|
|
|
|
mActionShowAll.setCheckable(true);
|
|
|
|
mActionShowSecurity.setCheckable(true);
|
|
|
|
mActionShowStyle.setCheckable(true);
|
|
|
|
mActionShowUnused.setCheckable(true);
|
|
|
|
mActionShowErrors.setCheckable(true);
|
|
|
|
|
|
|
|
// Program-menu
|
|
|
|
QMenu *menuprogram = menuBar()->addMenu(tr("&Program"));
|
|
|
|
menuprogram->addAction(&mActionSettings);
|
|
|
|
|
|
|
|
// Help-menu
|
|
|
|
QMenu *menuHelp = menuBar()->addMenu(tr("&Help"));
|
|
|
|
menuHelp->addAction(&mActionShowLicense);
|
|
|
|
menuHelp->addAction(&mActionShowAuthors);
|
|
|
|
menuHelp->addSeparator();
|
|
|
|
menuHelp->addAction(&mActionAbout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::CreateToolbar()
|
|
|
|
{
|
|
|
|
QToolBar *toolbar = addToolBar("Toolbar");
|
|
|
|
toolbar->setIconSize(QSize(22, 22));
|
|
|
|
|
|
|
|
toolbar->addAction(&mActionCheckDirectory);
|
|
|
|
toolbar->addAction(&mActionSave);
|
|
|
|
toolbar->addAction(&mActionReCheck);
|
|
|
|
toolbar->addAction(&mActionStop);
|
|
|
|
toolbar->addAction(&mActionClearResults);
|
|
|
|
toolbar->addAction(&mActionSettings);
|
|
|
|
toolbar->addAction(&mActionAbout);
|
|
|
|
}
|
|
|
|
|
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-06-17 21:35:24 +02:00
|
|
|
QStringList selected;
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-06-17 21:35:24 +02:00
|
|
|
// NOTE: we use QFileDialog::getOpenFileNames() and
|
|
|
|
// QFileDialog::getExistingDirectory() because they show native Windows
|
|
|
|
// selection dialog which is a lot more usable than QT:s own dialog.
|
|
|
|
if (mode == QFileDialog::ExistingFiles)
|
|
|
|
{
|
|
|
|
selected = QFileDialog::getOpenFileNames(this,
|
|
|
|
tr("Select files to check"),
|
|
|
|
mSettings.value(tr("Check path"), "").toString());
|
|
|
|
}
|
|
|
|
else if (mode == QFileDialog::DirectoryOnly)
|
|
|
|
{
|
|
|
|
QString dir = QFileDialog::getExistingDirectory(this,
|
|
|
|
tr("Select directory to check"),
|
|
|
|
mSettings.value(tr("Check path"), "").toString());
|
|
|
|
if (!dir.isEmpty())
|
|
|
|
selected.append(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected.count() > 0)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-03-22 13:32:07 +01:00
|
|
|
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();
|
2009-06-20 18:55:23 +02:00
|
|
|
mThread->ClearFiles();
|
2009-06-09 08:30:28 +02:00
|
|
|
|
|
|
|
if (fileNames.isEmpty())
|
|
|
|
{
|
2009-06-09 09:51:27 +02:00
|
|
|
QMessageBox msg(QMessageBox::Warning,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
tr("No suitable files found to check!"),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
msg.exec();
|
2009-06-09 08:30:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-09 10:21:17 +02:00
|
|
|
mResults.CheckingStarted();
|
|
|
|
|
2009-06-20 18:55:23 +02:00
|
|
|
mThread->SetFiles(RemoveUnacceptedFiles(fileNames));
|
2009-06-17 21:35:24 +02:00
|
|
|
QFileInfo inf(fileNames[0]);
|
|
|
|
QString absDirectory = inf.absoluteDir().path();
|
|
|
|
mSettings.setValue(tr("Check path"), absDirectory);
|
2009-03-22 16:42:00 +01:00
|
|
|
EnableCheckButtons(false);
|
2009-06-17 21:35:24 +02:00
|
|
|
mResults.SetCheckDirectory(absDirectory);
|
2009-06-20 18:55:23 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-05-24 10:53:29 +02:00
|
|
|
Settings MainWindow::GetCppcheckSettings()
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
|
|
|
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();
|
2009-05-24 10:53:29 +02:00
|
|
|
|
2009-05-24 10:55:54 +02:00
|
|
|
if (result._jobs <= 0)
|
|
|
|
{
|
2009-05-24 10:53:29 +02:00
|
|
|
result._jobs = 1;
|
|
|
|
}
|
|
|
|
|
2009-03-22 13:32:07 +01:00
|
|
|
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-06-06 11:51:14 +02:00
|
|
|
SettingsDialog dialog(mSettings, mApplications, this);
|
2009-03-22 13:32:07 +01:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
dialog.SaveCheckboxValues();
|
2009-06-03 20:18:22 +02:00
|
|
|
mResults.UpdateSettings(dialog.ShowFullPath(),
|
|
|
|
dialog.SaveFullPath(),
|
2009-06-09 09:51:27 +02:00
|
|
|
dialog.SaveAllErrors(),
|
|
|
|
dialog.ShowNoErrorsMessage());
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
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);
|
2009-06-20 18:55:23 +02:00
|
|
|
mThread->Check(GetCppcheckSettings(), true);
|
2009-03-22 16:42:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ClearResults()
|
|
|
|
{
|
|
|
|
mResults.Clear();
|
2009-06-03 20:18:22 +02:00
|
|
|
mActionClearResults.setEnabled(false);
|
|
|
|
mActionSave.setEnabled(false);
|
2009-03-22 16:42:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::EnableCheckButtons(bool enable)
|
|
|
|
{
|
2009-05-26 17:21:39 +02:00
|
|
|
mActionStop.setEnabled(!enable);
|
2009-03-22 16:42:00 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-06-04 16:02:35 +02:00
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
// Check that we aren't checking files
|
2009-06-20 18:55:23 +02:00
|
|
|
if (!mThread->IsChecking())
|
2009-06-04 16:02:35 +02:00
|
|
|
event->accept();
|
|
|
|
else
|
|
|
|
{
|
2009-06-09 09:51:27 +02:00
|
|
|
QString text(tr("Cannot exit while checking.\n\n" \
|
|
|
|
"Stop the checking before exiting."));
|
|
|
|
|
|
|
|
QMessageBox msg(QMessageBox::Warning,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
text,
|
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
|
|
|
|
msg.exec();
|
|
|
|
|
|
|
|
|
2009-06-04 16:02:35 +02:00
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
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);
|
|
|
|
}
|
2009-05-24 10:53:29 +02:00
|
|
|
|
|
|
|
void MainWindow::About()
|
|
|
|
{
|
|
|
|
//TODO make a "GetVersionNumber" function to core cppcheck
|
|
|
|
CppCheckExecutor exec;
|
|
|
|
CppCheck check(exec);
|
2009-05-24 10:55:54 +02:00
|
|
|
const char *argv[] = {"", "--version"};
|
2009-05-24 10:53:29 +02:00
|
|
|
QString version = check.parseFromArgs(2, argv).c_str();
|
2009-05-24 10:55:54 +02:00
|
|
|
version.replace("Cppcheck ", "");
|
|
|
|
|
2009-06-04 14:35:41 +02:00
|
|
|
AboutDialog *dlg = new AboutDialog(version, this);
|
2009-06-14 11:57:43 +02:00
|
|
|
dlg->exec();
|
2009-05-24 10:53:29 +02:00
|
|
|
}
|
2009-05-26 17:21:39 +02:00
|
|
|
|
2009-06-14 11:57:43 +02:00
|
|
|
void MainWindow::ShowLicense()
|
|
|
|
{
|
|
|
|
FileViewDialog *dlg = new FileViewDialog(":COPYING", this);
|
2009-06-14 22:22:19 +02:00
|
|
|
dlg->resize(550, 400);
|
2009-06-14 11:57:43 +02:00
|
|
|
dlg->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ShowAuthors()
|
|
|
|
{
|
|
|
|
FileViewDialog *dlg = new FileViewDialog(":AUTHORS", this);
|
2009-06-14 22:22:19 +02:00
|
|
|
dlg->resize(350, 400);
|
2009-06-14 11:57:43 +02:00
|
|
|
dlg->exec();
|
|
|
|
}
|
2009-05-26 17:21:39 +02:00
|
|
|
|
|
|
|
void MainWindow::Save()
|
|
|
|
{
|
2009-06-17 23:34:22 +02:00
|
|
|
QString selectedFilter;
|
|
|
|
QString filter(tr("XML files (*.xml);;Text files (*.txt)"));
|
|
|
|
QString selectedFile = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Save the report file"),
|
|
|
|
QString(),
|
|
|
|
filter,
|
|
|
|
&selectedFilter);
|
|
|
|
|
|
|
|
if (!selectedFile.isEmpty())
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2009-06-17 23:34:22 +02:00
|
|
|
//Check if xml file type was selected
|
|
|
|
bool xml = selectedFilter == tr("XML files (*.xml)");
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2009-06-17 23:34:22 +02:00
|
|
|
//Force xml extension to the file
|
|
|
|
if (xml && !selectedFile.endsWith(".xml", Qt::CaseInsensitive))
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2009-06-17 23:34:22 +02:00
|
|
|
selectedFile += ".xml";
|
|
|
|
}
|
2009-06-12 20:22:45 +02:00
|
|
|
|
2009-06-17 23:34:22 +02:00
|
|
|
//Force .txt extension
|
|
|
|
if (!xml && !selectedFile.endsWith(".txt", Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
selectedFile += ".txt";
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
2009-06-17 23:34:22 +02:00
|
|
|
|
|
|
|
mResults.Save(selectedFile, xml);
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
2009-05-26 17:21:39 +02:00
|
|
|
}
|
|
|
|
|
2009-06-03 20:18:22 +02:00
|
|
|
void MainWindow::ResultsAdded()
|
|
|
|
{
|
|
|
|
mActionClearResults.setEnabled(true);
|
|
|
|
mActionSave.setEnabled(true);
|
|
|
|
}
|