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
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-03-01 08:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
2009-06-20 22:23:54 +02:00
|
|
|
#include <QApplication>
|
2009-03-01 08:38:21 +01:00
|
|
|
#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>
|
2010-01-06 00:40:26 +01:00
|
|
|
#include <QDir>
|
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-06-22 10:57:17 +02:00
|
|
|
#include "projectfile.h"
|
2009-07-06 11:30:49 +02:00
|
|
|
#include "report.h"
|
2009-10-25 19:29:10 +01:00
|
|
|
#include "../lib/filelister.h"
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2010-02-23 16:29:49 +01:00
|
|
|
// HTMLHelp is only available in Windows
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <htmlhelp.h>
|
|
|
|
#endif
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
MainWindow::MainWindow() :
|
2010-04-02 07:30:58 +02:00
|
|
|
mSettings(new QSettings("Cppcheck", "Cppcheck-GUI", this)),
|
|
|
|
mApplications(new ApplicationList(this)),
|
|
|
|
mTranslation(new TranslationHandler(this)),
|
|
|
|
mLanguages(new QActionGroup(this))
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
mUI.setupUi(this);
|
|
|
|
mUI.mResults->Initialize(mSettings, mApplications);
|
|
|
|
|
2009-06-20 18:55:23 +02:00
|
|
|
mThread = new ThreadHandler(this);
|
2009-05-24 10:53:29 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
connect(mUI.mActionQuit, SIGNAL(triggered()), this, SLOT(close()));
|
|
|
|
connect(mUI.mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles()));
|
|
|
|
connect(mUI.mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory()));
|
|
|
|
connect(mUI.mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings()));
|
|
|
|
connect(mUI.mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults()));
|
|
|
|
|
|
|
|
connect(mUI.mActionShowAll, SIGNAL(toggled(bool)), this, SLOT(ShowAll(bool)));
|
|
|
|
connect(mUI.mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool)));
|
2009-08-02 14:00:22 +02:00
|
|
|
connect(mUI.mActionShowAllStyle, SIGNAL(toggled(bool)), this, SLOT(ShowAllStyle(bool)));
|
2009-07-02 10:32:29 +02:00
|
|
|
connect(mUI.mActionShowErrors, SIGNAL(toggled(bool)), this, SLOT(ShowErrors(bool)));
|
|
|
|
connect(mUI.mActionCheckAll, SIGNAL(triggered()), this, SLOT(CheckAll()));
|
|
|
|
connect(mUI.mActionUncheckAll, SIGNAL(triggered()), this, SLOT(UncheckAll()));
|
|
|
|
connect(mUI.mActionCollapseAll, SIGNAL(triggered()), mUI.mResults, SLOT(CollapseAllResults()));
|
|
|
|
connect(mUI.mActionExpandAll, SIGNAL(triggered()), mUI.mResults, SLOT(ExpandAllResults()));
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
connect(mUI.mActionRecheck, SIGNAL(triggered()), this, SLOT(ReCheck()));
|
2009-05-24 10:53:29 +02:00
|
|
|
|
2009-07-02 19:23:44 +02:00
|
|
|
connect(mUI.mActionStop, SIGNAL(triggered()), this, SLOT(StopChecking()));
|
2009-07-02 10:32:29 +02:00
|
|
|
connect(mUI.mActionSave, SIGNAL(triggered()), this, SLOT(Save()));
|
2009-05-24 10:53:29 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
connect(mUI.mActionAbout, SIGNAL(triggered()), this, SLOT(About()));
|
|
|
|
connect(mUI.mActionLicense, SIGNAL(triggered()), this, SLOT(ShowLicense()));
|
2009-07-02 10:46:26 +02:00
|
|
|
connect(mUI.mActionToolbar, SIGNAL(toggled(bool)), this, SLOT(ToggleToolbar()));
|
2009-06-14 23:48:16 +02:00
|
|
|
|
2009-07-02 10:46:26 +02:00
|
|
|
connect(mUI.mActionAuthors, SIGNAL(triggered()), this, SLOT(ShowAuthors()));
|
2009-06-20 18:55:23 +02:00
|
|
|
connect(mThread, SIGNAL(Done()), this, SLOT(CheckDone()));
|
2009-07-02 10:32:29 +02:00
|
|
|
connect(mUI.mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded()));
|
2009-07-02 19:11:47 +02:00
|
|
|
connect(mUI.mMenuView, SIGNAL(aboutToShow()), this, SLOT(AboutToShowViewMenu()));
|
2009-05-26 17:21:39 +02:00
|
|
|
|
2010-02-23 16:29:49 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
connect(mUI.mActionHelpContents, SIGNAL(triggered()), this, SLOT(OpenHelpContents()));
|
|
|
|
#else
|
|
|
|
// Hide if not Windows
|
2010-02-23 18:09:05 +01:00
|
|
|
mUI.mActionHelpContents->setVisible(false);
|
2010-02-23 16:29:49 +01:00
|
|
|
#endif
|
|
|
|
|
2009-07-02 12:48:32 +02:00
|
|
|
CreateLanguageMenuItems();
|
2009-03-01 08:38:21 +01:00
|
|
|
LoadSettings();
|
2009-07-02 10:32:29 +02:00
|
|
|
|
|
|
|
mThread->Initialize(mUI.mResults);
|
2009-06-22 17:45:48 +02:00
|
|
|
FormatAndSetTitle();
|
2009-05-26 17:21:39 +02:00
|
|
|
|
|
|
|
EnableCheckButtons(true);
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionClearResults->setEnabled(false);
|
|
|
|
mUI.mActionSave->setEnabled(false);
|
2009-10-13 10:19:00 +02:00
|
|
|
mUI.mActionRecheck->setEnabled(false);
|
2009-07-02 10:32:29 +02:00
|
|
|
|
2009-07-16 07:20:29 +02:00
|
|
|
QStringList args = QCoreApplication::arguments();
|
|
|
|
//Remove the application itself
|
|
|
|
args.removeFirst();
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!args.isEmpty())
|
2009-07-16 07:20:29 +02:00
|
|
|
{
|
|
|
|
DoCheckFiles(args);
|
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
void MainWindow::CreateLanguageMenuItems()
|
|
|
|
{
|
|
|
|
QStringList languages = mTranslation->GetNames();
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
for (int i = 0; i < languages.size(); i++)
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
//Create an action for each language
|
|
|
|
//Language name is pre translated
|
|
|
|
QAction *temp = new QAction(languages[i], this);
|
|
|
|
|
|
|
|
temp->setCheckable(true);
|
|
|
|
|
|
|
|
//Add the action to menu
|
2009-07-02 19:11:47 +02:00
|
|
|
mUI.mMenuLanguage->addAction(temp);
|
2009-07-02 10:32:29 +02:00
|
|
|
|
|
|
|
//Add action to the group
|
|
|
|
mLanguages->addAction(temp);
|
|
|
|
|
|
|
|
//Check it if it's the value stored to settings
|
2010-04-02 07:30:58 +02:00
|
|
|
if (i == mSettings->value(SETTINGS_LANGUAGE, 0).toInt())
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
temp->setChecked(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp->setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(mLanguages, SIGNAL(triggered(QAction *)),
|
|
|
|
this, SLOT(MapLanguage(QAction *)));
|
2009-06-14 23:48:16 +02:00
|
|
|
}
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
void MainWindow::LoadSettings()
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (mSettings->value(SETTINGS_WINDOW_MAXIMIZED, false).toBool())
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
|
|
|
showMaximized();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
resize(mSettings->value(SETTINGS_WINDOW_WIDTH, 800).toInt(),
|
|
|
|
mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt());
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionShowAll->setChecked(mSettings->value(SETTINGS_SHOW_ALL, true).toBool());
|
|
|
|
mUI.mActionShowStyle->setChecked(mSettings->value(SETTINGS_SHOW_STYLE, true).toBool());
|
2009-08-02 14:00:22 +02:00
|
|
|
mUI.mActionShowAllStyle->setChecked(mSettings->value(SETTINGS_SHOW_ALL_STYLE, true).toBool());
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionShowErrors->setChecked(mSettings->value(SETTINGS_SHOW_ERRORS, true).toBool());
|
|
|
|
|
|
|
|
mUI.mResults->ShowResults(SHOW_ALL, mUI.mActionShowAll->isChecked());
|
|
|
|
mUI.mResults->ShowResults(SHOW_ERRORS, mUI.mActionShowErrors->isChecked());
|
|
|
|
mUI.mResults->ShowResults(SHOW_STYLE, mUI.mActionShowStyle->isChecked());
|
2009-08-02 14:00:22 +02:00
|
|
|
mUI.mResults->ShowResults(SHOW_ALL_STYLE, mUI.mActionShowAllStyle->isChecked());
|
2009-07-01 23:05:09 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionToolbar->setChecked(mSettings->value(SETTINGS_TOOLBARS_SHOW, true).toBool());
|
2009-07-02 19:11:47 +02:00
|
|
|
mUI.mToolBar->setVisible(mSettings->value(SETTINGS_TOOLBARS_SHOW, true).toBool());
|
2009-07-02 10:32:29 +02:00
|
|
|
|
|
|
|
mApplications->LoadSettings(mSettings);
|
|
|
|
|
2009-07-02 22:41:37 +02:00
|
|
|
SetLanguage(mSettings->value(SETTINGS_LANGUAGE, mTranslation->SuggestLanguage()).toInt());
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::SaveSettings()
|
|
|
|
{
|
2009-07-02 22:41:37 +02:00
|
|
|
//Force toolbar checkbox value to be updated
|
|
|
|
AboutToShowViewMenu();
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->setValue(SETTINGS_WINDOW_WIDTH, size().width());
|
|
|
|
mSettings->setValue(SETTINGS_WINDOW_HEIGHT, size().height());
|
|
|
|
mSettings->setValue(SETTINGS_WINDOW_MAXIMIZED, isMaximized());
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->setValue(SETTINGS_SHOW_ALL, mUI.mActionShowAll->isChecked());
|
|
|
|
mSettings->setValue(SETTINGS_SHOW_STYLE, mUI.mActionShowStyle->isChecked());
|
2009-08-02 14:00:22 +02:00
|
|
|
mSettings->setValue(SETTINGS_SHOW_ALL_STYLE, mUI.mActionShowAllStyle->isChecked());
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->setValue(SETTINGS_SHOW_ERRORS, mUI.mActionShowErrors->isChecked());
|
2009-07-04 10:06:29 +02:00
|
|
|
mSettings->setValue(SETTINGS_TOOLBARS_SHOW, mUI.mToolBar->isVisible());
|
2009-07-01 23:05:09 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mApplications->SaveSettings(mSettings);
|
|
|
|
|
|
|
|
mSettings->setValue(SETTINGS_LANGUAGE, mTranslation->GetCurrentLanguage());
|
|
|
|
mUI.mResults->SaveSettings();
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2009-07-16 07:20:29 +02:00
|
|
|
void MainWindow::DoCheckFiles(const QStringList &files)
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (files.isEmpty())
|
2009-07-16 07:20:29 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ClearResults();
|
|
|
|
|
|
|
|
QStringList fileNames;
|
|
|
|
QString selection;
|
|
|
|
|
|
|
|
foreach(selection, files)
|
|
|
|
{
|
|
|
|
fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection));
|
|
|
|
}
|
|
|
|
|
|
|
|
mUI.mResults->Clear();
|
|
|
|
mThread->ClearFiles();
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (fileNames.isEmpty())
|
2009-07-16 07:20:29 +02:00
|
|
|
{
|
|
|
|
QMessageBox msg(QMessageBox::Warning,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
tr("No suitable files found to check!"),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
msg.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mUI.mResults->CheckingStarted();
|
|
|
|
|
|
|
|
mThread->SetFiles(RemoveUnacceptedFiles(fileNames));
|
|
|
|
QFileInfo inf(fileNames[0]);
|
|
|
|
QString absDirectory = inf.absoluteDir().path();
|
|
|
|
mSettings->setValue(SETTINGS_CHECK_PATH, absDirectory);
|
|
|
|
EnableCheckButtons(false);
|
|
|
|
mUI.mActionSettings->setEnabled(false);
|
|
|
|
|
|
|
|
mUI.mResults->SetCheckDirectory(absDirectory);
|
|
|
|
|
|
|
|
Settings checkSettings = GetCppcheckSettings();
|
|
|
|
mThread->Check(checkSettings, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MainWindow::SelectFilesToCheck(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.
|
2010-04-02 07:30:58 +02:00
|
|
|
if (mode == QFileDialog::ExistingFiles)
|
2009-06-17 21:35:24 +02:00
|
|
|
{
|
|
|
|
selected = QFileDialog::getOpenFileNames(this,
|
|
|
|
tr("Select files to check"),
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
|
2010-04-02 07:30:58 +02:00
|
|
|
if (selected.isEmpty())
|
2009-06-22 10:57:17 +02:00
|
|
|
mCurrentDirectory.clear();
|
2010-01-06 10:34:02 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QFileInfo inf(selected[0]);
|
|
|
|
mCurrentDirectory = inf.absolutePath();
|
|
|
|
}
|
2009-06-22 17:45:48 +02:00
|
|
|
FormatAndSetTitle();
|
2009-06-17 21:35:24 +02:00
|
|
|
}
|
2010-04-02 07:30:58 +02:00
|
|
|
else if (mode == QFileDialog::DirectoryOnly)
|
2009-06-17 21:35:24 +02:00
|
|
|
{
|
|
|
|
QString dir = QFileDialog::getExistingDirectory(this,
|
|
|
|
tr("Select directory to check"),
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!dir.isEmpty())
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
|
|
|
mCurrentDirectory = dir;
|
2009-06-17 21:35:24 +02:00
|
|
|
selected.append(dir);
|
2009-08-02 13:08:04 +02:00
|
|
|
dir = QDir::toNativeSeparators(dir);
|
2009-06-22 17:45:48 +02:00
|
|
|
FormatAndSetTitle(dir);
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
2009-06-17 21:35:24 +02:00
|
|
|
}
|
|
|
|
|
2009-07-16 07:20:29 +02:00
|
|
|
return selected;
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2009-03-22 13:32:07 +01:00
|
|
|
void MainWindow::CheckFiles()
|
|
|
|
{
|
2009-07-16 07:20:29 +02:00
|
|
|
DoCheckFiles(SelectFilesToCheck(QFileDialog::ExistingFiles));
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::CheckDirectory()
|
|
|
|
{
|
2009-07-16 07:20:29 +02:00
|
|
|
DoCheckFiles(SelectFilesToCheck(QFileDialog::DirectoryOnly));
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
2009-05-24 10:53:29 +02:00
|
|
|
Settings MainWindow::GetCppcheckSettings()
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
2009-06-22 10:57:17 +02:00
|
|
|
ProjectFile pfile;
|
2009-03-22 13:32:07 +01:00
|
|
|
Settings result;
|
2009-06-22 10:57:17 +02:00
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!mCurrentDirectory.isEmpty())
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
|
|
|
// Format project filename (directory name + .cppcheck) and load
|
|
|
|
// the project file if it is found.
|
|
|
|
QStringList parts = mCurrentDirectory.split("/");
|
2010-01-03 08:39:00 +01:00
|
|
|
QString projfile = mCurrentDirectory + "/" + parts[parts.count() - 1] + ".cppcheck";
|
2009-06-22 10:57:17 +02:00
|
|
|
bool projectRead = false;
|
2010-04-02 07:30:58 +02:00
|
|
|
if (QFile::exists(projfile))
|
2010-01-03 08:39:00 +01:00
|
|
|
{
|
|
|
|
qDebug() << "Reading project file " << projfile;
|
|
|
|
projectRead = pfile.Read(projfile);
|
|
|
|
}
|
2009-06-22 10:57:17 +02:00
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (projectRead)
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
|
|
|
QStringList classes = pfile.GetDeAllocatedClasses();
|
|
|
|
QString classname;
|
|
|
|
foreach(classname, classes)
|
|
|
|
{
|
|
|
|
result.addAutoAllocClass(classname.toStdString());
|
|
|
|
}
|
2009-07-04 00:38:47 +02:00
|
|
|
|
|
|
|
QStringList dirs = pfile.GetIncludeDirs();
|
|
|
|
QString dir;
|
|
|
|
foreach(dir, dirs)
|
|
|
|
{
|
2010-01-06 00:40:26 +01:00
|
|
|
QString incdir;
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!QDir::isAbsolutePath(dir))
|
2010-01-06 00:40:26 +01:00
|
|
|
incdir = mCurrentDirectory + "/";
|
|
|
|
incdir += dir;
|
|
|
|
incdir = QDir::cleanPath(incdir);
|
2010-01-06 02:15:56 +01:00
|
|
|
|
|
|
|
// include paths must end with '/'
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!incdir.endsWith("/"))
|
2010-01-06 02:15:56 +01:00
|
|
|
incdir += "/";
|
2010-01-06 00:40:26 +01:00
|
|
|
result._includePaths.push_back(incdir.toStdString());
|
2009-07-04 00:38:47 +02:00
|
|
|
}
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-22 13:32:07 +01:00
|
|
|
result._debug = false;
|
|
|
|
result._checkCodingStyle = true;
|
|
|
|
result._errorsOnly = false;
|
|
|
|
result._verbose = true;
|
2009-07-02 10:32:29 +02:00
|
|
|
result._force = mSettings->value(SETTINGS_CHECK_FORCE, 1).toBool();
|
2009-03-22 13:32:07 +01:00
|
|
|
result._xml = false;
|
2009-07-02 10:32:29 +02:00
|
|
|
result._jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt();
|
2009-05-24 10:53:29 +02:00
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (result._jobs <= 0)
|
2009-05-24 10:55:54 +02:00
|
|
|
{
|
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;
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (info.isDir())
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
|
|
|
QDirIterator it(path, QDirIterator::Subdirectories);
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
while (it.hasNext())
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
|
|
|
list << it.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list << path;
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list)
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
QString str;
|
|
|
|
foreach(str, list)
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (getFileLister()->acceptFile(str.toStdString()))
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
|
|
|
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-07-02 10:32:29 +02:00
|
|
|
mUI.mActionSettings->setEnabled(true);
|
2010-04-02 07:30:58 +02:00
|
|
|
if (mUI.mResults->HasResults())
|
2009-06-20 22:05:17 +02:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionClearResults->setEnabled(true);
|
|
|
|
mUI.mActionSave->setEnabled(true);
|
2009-06-20 22:05:17 +02:00
|
|
|
}
|
2009-06-20 22:23:54 +02:00
|
|
|
|
|
|
|
// Notify user - if the window is not active - that check is ready
|
|
|
|
QApplication::alert(this, 3000);
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ProgramSettings()
|
|
|
|
{
|
2009-06-06 11:51:14 +02:00
|
|
|
SettingsDialog dialog(mSettings, mApplications, this);
|
2010-04-02 07:30:58 +02:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
|
|
|
dialog.SaveCheckboxValues();
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mResults->UpdateSettings(dialog.ShowFullPath(),
|
|
|
|
dialog.SaveFullPath(),
|
|
|
|
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()
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mResults->Clear();
|
|
|
|
mUI.mActionClearResults->setEnabled(false);
|
|
|
|
mUI.mActionSave->setEnabled(false);
|
2009-03-22 16:42:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::EnableCheckButtons(bool enable)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionStop->setEnabled(!enable);
|
|
|
|
mUI.mActionCheckFiles->setEnabled(enable);
|
2009-10-13 10:19:00 +02:00
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!enable || mThread->HasPreviousFiles())
|
2009-10-13 10:19:00 +02:00
|
|
|
mUI.mActionRecheck->setEnabled(enable);
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionCheckDirectory->setEnabled(enable);
|
2009-03-22 16:42:00 +01:00
|
|
|
}
|
|
|
|
|
2009-03-22 18:39:44 +01:00
|
|
|
void MainWindow::ShowAll(bool checked)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mResults->ShowResults(SHOW_ALL, checked);
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ShowStyle(bool checked)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mResults->ShowResults(SHOW_STYLE, checked);
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
|
|
|
|
2009-08-02 14:00:22 +02:00
|
|
|
void MainWindow::ShowAllStyle(bool checked)
|
|
|
|
{
|
|
|
|
mUI.mResults->ShowResults(SHOW_ALL_STYLE, checked);
|
|
|
|
}
|
|
|
|
|
2009-03-22 18:39:44 +01:00
|
|
|
void MainWindow::ShowErrors(bool checked)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mResults->ShowResults(SHOW_ERRORS, checked);
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
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
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!mThread->IsChecking())
|
2009-07-04 14:54:28 +02:00
|
|
|
{
|
2009-07-04 10:06:29 +02:00
|
|
|
SaveSettings();
|
2009-06-04 16:02:35 +02:00
|
|
|
event->accept();
|
2009-07-04 10:06:29 +02:00
|
|
|
}
|
2009-06-04 16:02:35 +02:00
|
|
|
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)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionShowAll->setChecked(checked);
|
2009-05-23 10:17:27 +02:00
|
|
|
ShowAll(checked);
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionShowStyle->setChecked(checked);
|
2009-05-23 10:17:27 +02:00
|
|
|
ShowStyle(checked);
|
|
|
|
|
2009-08-02 14:00:22 +02:00
|
|
|
mUI.mActionShowAllStyle->setChecked(checked);
|
|
|
|
ShowStyle(checked);
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionShowErrors->setChecked(checked);
|
2009-05-23 10:17:27 +02:00
|
|
|
ShowErrors(checked);
|
|
|
|
}
|
2009-05-24 10:53:29 +02:00
|
|
|
|
|
|
|
void MainWindow::About()
|
|
|
|
{
|
2009-10-25 21:06:58 +01:00
|
|
|
AboutDialog *dlg = new AboutDialog(CppCheck::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()
|
|
|
|
{
|
2009-07-02 19:23:44 +02:00
|
|
|
FileViewDialog *dlg = new FileViewDialog(":COPYING", tr("License"), this);
|
2009-07-02 18:46:26 +02:00
|
|
|
dlg->resize(570, 400);
|
2009-06-14 11:57:43 +02:00
|
|
|
dlg->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ShowAuthors()
|
|
|
|
{
|
2009-07-02 19:23:44 +02:00
|
|
|
FileViewDialog *dlg = new FileViewDialog(":AUTHORS", tr("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;
|
2009-07-06 11:30:49 +02:00
|
|
|
QString filter(tr("XML files (*.xml);;Text files (*.txt);;CSV files (*.csv)"));
|
2009-06-17 23:34:22 +02:00
|
|
|
QString selectedFile = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Save the report file"),
|
|
|
|
QString(),
|
|
|
|
filter,
|
|
|
|
&selectedFilter);
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!selectedFile.isEmpty())
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2009-11-19 23:19:44 +01:00
|
|
|
Report::Type type = Report::TXT;
|
2010-04-02 07:30:58 +02:00
|
|
|
if (selectedFilter == tr("XML files (*.xml)"))
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2009-07-06 11:30:49 +02:00
|
|
|
type = Report::XML;
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!selectedFile.endsWith(".xml", Qt::CaseInsensitive))
|
2009-07-06 11:30:49 +02:00
|
|
|
selectedFile += ".xml";
|
2009-06-17 23:34:22 +02:00
|
|
|
}
|
2010-04-02 07:30:58 +02:00
|
|
|
else if (selectedFilter == tr("Text files (*.txt)"))
|
2009-07-06 11:30:49 +02:00
|
|
|
{
|
|
|
|
type = Report::TXT;
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!selectedFile.endsWith(".txt", Qt::CaseInsensitive))
|
2009-07-06 11:30:49 +02:00
|
|
|
selectedFile += ".txt";
|
|
|
|
}
|
2010-04-02 07:30:58 +02:00
|
|
|
else if (selectedFilter == tr("CSV files (*.csv)"))
|
2009-06-17 23:34:22 +02:00
|
|
|
{
|
2009-07-06 11:30:49 +02:00
|
|
|
type = Report::CSV;
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!selectedFile.endsWith(".csv", Qt::CaseInsensitive))
|
2009-07-06 11:30:49 +02:00
|
|
|
selectedFile += ".csv";
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
2009-11-19 23:19:44 +01:00
|
|
|
else
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (selectedFile.endsWith(".xml", Qt::CaseInsensitive))
|
2009-11-19 23:19:44 +01:00
|
|
|
type = Report::XML;
|
2010-04-02 07:30:58 +02:00
|
|
|
else if (selectedFile.endsWith(".txt", Qt::CaseInsensitive))
|
2009-11-19 23:19:44 +01:00
|
|
|
type = Report::TXT;
|
2010-04-02 07:30:58 +02:00
|
|
|
else if (selectedFile.endsWith(".csv", Qt::CaseInsensitive))
|
2009-11-19 23:19:44 +01:00
|
|
|
type = Report::CSV;
|
|
|
|
}
|
2009-06-17 23:34:22 +02:00
|
|
|
|
2009-07-06 11:30:49 +02:00
|
|
|
mUI.mResults->Save(selectedFile, type);
|
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()
|
|
|
|
{
|
|
|
|
}
|
2009-06-22 17:45:48 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
void MainWindow::ToggleToolbar()
|
2009-07-01 22:46:42 +02:00
|
|
|
{
|
2009-07-02 19:11:47 +02:00
|
|
|
mUI.mToolBar->setVisible(mUI.mActionToolbar->isChecked());
|
2009-07-01 22:46:42 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 17:45:48 +02:00
|
|
|
void MainWindow::FormatAndSetTitle(const QString &text)
|
|
|
|
{
|
|
|
|
QString title;
|
2010-04-02 07:30:58 +02:00
|
|
|
if (text.isEmpty())
|
2009-06-22 17:45:48 +02:00
|
|
|
title = tr("Cppcheck");
|
|
|
|
else
|
|
|
|
title = QString(tr("Cppcheck - %1")).arg(text);
|
|
|
|
setWindowTitle(title);
|
|
|
|
}
|
2009-07-01 22:46:42 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
|
|
|
|
void MainWindow::SetLanguage(int index)
|
2009-07-01 22:46:42 +02:00
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (mTranslation->GetCurrentLanguage() == index)
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString error;
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!mTranslation->SetLanguage(index, error))
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
2009-07-03 16:20:54 +02:00
|
|
|
QMessageBox msg(QMessageBox::Critical,
|
2009-07-02 10:32:29 +02:00
|
|
|
tr("Cppcheck"),
|
2009-07-03 16:20:54 +02:00
|
|
|
QString(tr("Failed to change the language:\n\n%1\n\n")).arg(error),
|
2009-07-02 10:32:29 +02:00
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
|
|
|
|
msg.exec();
|
|
|
|
}
|
2009-07-01 22:46:42 +02:00
|
|
|
else
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
2009-07-02 12:48:32 +02:00
|
|
|
//Translate everything that is visible here
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.retranslateUi(this);
|
2009-07-02 10:46:26 +02:00
|
|
|
mUI.mResults->Translate();
|
2009-07-02 12:48:32 +02:00
|
|
|
QStringList languages = mTranslation->GetNames();
|
|
|
|
QList<QAction *> actions = mLanguages->actions();
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (languages.size() <= actions.size())
|
2009-07-02 12:48:32 +02:00
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
for (int i = 0; i < languages.size(); i++)
|
2009-07-02 12:48:32 +02:00
|
|
|
{
|
|
|
|
actions[i]->setText(tr(languages[i].toLatin1()));
|
|
|
|
}
|
|
|
|
}
|
2009-07-02 10:32:29 +02:00
|
|
|
}
|
2009-07-01 22:46:42 +02:00
|
|
|
}
|
2009-07-02 10:32:29 +02:00
|
|
|
|
|
|
|
void MainWindow::MapLanguage(QAction *action)
|
|
|
|
{
|
|
|
|
//Find the action that has the language that user clicked
|
|
|
|
QList<QAction *> actions = mLanguages->actions();
|
2010-04-02 07:30:58 +02:00
|
|
|
for (int i = 0; i < actions.size(); i++)
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (actions[i] == action)
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
SetLanguage(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-02 19:11:47 +02:00
|
|
|
void MainWindow::AboutToShowViewMenu()
|
|
|
|
{
|
|
|
|
mUI.mActionToolbar->setChecked(mUI.mToolBar->isVisible());
|
|
|
|
}
|
2009-07-02 19:23:44 +02:00
|
|
|
|
|
|
|
void MainWindow::StopChecking()
|
|
|
|
{
|
|
|
|
mThread->Stop();
|
|
|
|
mUI.mResults->DisableProgressbar();
|
|
|
|
}
|
2010-02-23 16:29:49 +01:00
|
|
|
|
|
|
|
void MainWindow::OpenHelpContents()
|
|
|
|
{
|
|
|
|
OpenHtmlHelpContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OpenHtmlHelpContents()
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
QString file("/cppcheck.chm");
|
|
|
|
QString exeFolder = QDir::currentPath();
|
|
|
|
exeFolder += file;
|
|
|
|
exeFolder = QDir::toNativeSeparators(exeFolder);
|
|
|
|
HtmlHelp(NULL, exeFolder.utf16(), HH_DISPLAY_TOPIC, NULL);
|
|
|
|
#endif // WIN32
|
|
|
|
}
|