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"
|
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>
|
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-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-07-02 10:32:29 +02:00
|
|
|
mSettings(new QSettings("Cppcheck", "Cppcheck-GUI", this)),
|
|
|
|
mApplications(new ApplicationList(this)),
|
|
|
|
mTranslation(new TranslationHandler(this)),
|
|
|
|
mLanguages(new QActionGroup(this))
|
|
|
|
{
|
|
|
|
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-03-01 08:38:21 +01:00
|
|
|
|
2009-03-22 18:39:44 +01: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.mActionShowSecurity, SIGNAL(toggled(bool)), this, SLOT(ShowSecurity(bool)));
|
|
|
|
connect(mUI.mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool)));
|
|
|
|
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
|
|
|
|
|
|
|
|
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-07-02 12:48:32 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
|
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();
|
|
|
|
|
2009-07-02 17:57:09 +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
|
|
|
|
if (i == mSettings->value(SETTINGS_LANGUAGE, 0).toInt())
|
|
|
|
{
|
|
|
|
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-07-02 10:32:29 +02:00
|
|
|
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
void MainWindow::LoadSettings()
|
|
|
|
{
|
2009-07-02 10:32:29 +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.mActionShowSecurity->setChecked(mSettings->value(SETTINGS_SHOW_SECURITY, true).toBool());
|
|
|
|
mUI.mActionShowStyle->setChecked(mSettings->value(SETTINGS_SHOW_STYLE, true).toBool());
|
|
|
|
mUI.mActionShowErrors->setChecked(mSettings->value(SETTINGS_SHOW_ERRORS, true).toBool());
|
|
|
|
|
2009-07-01 23:05:09 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mResults->ShowResults(SHOW_ALL, mUI.mActionShowAll->isChecked());
|
|
|
|
mUI.mResults->ShowResults(SHOW_ERRORS, mUI.mActionShowErrors->isChecked());
|
|
|
|
mUI.mResults->ShowResults(SHOW_SECURITY, mUI.mActionShowSecurity->isChecked());
|
|
|
|
mUI.mResults->ShowResults(SHOW_STYLE, mUI.mActionShowStyle->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);
|
|
|
|
|
|
|
|
QString error = "";
|
|
|
|
|
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-01 23:05:09 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->setValue(SETTINGS_SHOW_ALL, mUI.mActionShowAll->isChecked());
|
|
|
|
mSettings->setValue(SETTINGS_SHOW_SECURITY, mUI.mActionShowSecurity->isChecked());
|
|
|
|
mSettings->setValue(SETTINGS_SHOW_STYLE, mUI.mActionShowStyle->isChecked());
|
|
|
|
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-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"),
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
|
2009-06-22 10:57:17 +02:00
|
|
|
if (selected.isEmpty())
|
|
|
|
mCurrentDirectory.clear();
|
2009-06-22 17:45:48 +02:00
|
|
|
FormatAndSetTitle();
|
2009-06-17 21:35:24 +02:00
|
|
|
}
|
|
|
|
else if (mode == QFileDialog::DirectoryOnly)
|
|
|
|
{
|
|
|
|
QString dir = QFileDialog::getExistingDirectory(this,
|
|
|
|
tr("Select directory to check"),
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->value(SETTINGS_CHECK_PATH, "").toString());
|
2009-06-17 21:35:24 +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-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
|
|
|
}
|
|
|
|
|
|
|
|
if (selected.count() > 0)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-06-20 22:13:08 +02:00
|
|
|
ClearResults();
|
|
|
|
|
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-07-02 10:32:29 +02:00
|
|
|
mUI.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-07-02 10:32:29 +02:00
|
|
|
mUI.mResults->CheckingStarted();
|
2009-06-09 10:21:17 +02:00
|
|
|
|
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();
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->setValue(SETTINGS_CHECK_PATH, absDirectory);
|
2009-03-22 16:42:00 +01:00
|
|
|
EnableCheckButtons(false);
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionSettings->setEnabled(false);
|
|
|
|
|
|
|
|
mUI.mResults->SetCheckDirectory(absDirectory);
|
2009-06-22 10:57:17 +02:00
|
|
|
|
|
|
|
Settings checkSettings = GetCppcheckSettings();
|
|
|
|
mThread->Check(checkSettings, 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
|
|
|
{
|
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
|
|
|
|
|
|
|
if (!mCurrentDirectory.isEmpty())
|
|
|
|
{
|
|
|
|
// Format project filename (directory name + .cppcheck) and load
|
|
|
|
// the project file if it is found.
|
|
|
|
QStringList parts = mCurrentDirectory.split("/");
|
|
|
|
QString projfile = parts[parts.count() - 1] + ".cppcheck";
|
|
|
|
bool projectRead = false;
|
|
|
|
if (QFile::exists(projfile))
|
|
|
|
projectRead = pfile.Read(mCurrentDirectory + "/" + projfile);
|
|
|
|
|
|
|
|
if (projectRead)
|
|
|
|
{
|
|
|
|
QStringList classes = pfile.GetDeAllocatedClasses();
|
|
|
|
QString classname;
|
|
|
|
foreach(classname, classes)
|
|
|
|
{
|
|
|
|
result.addAutoAllocClass(classname.toStdString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-22 13:32:07 +01:00
|
|
|
result._debug = false;
|
|
|
|
result._showAll = true;
|
|
|
|
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-06-27 09:30:32 +02:00
|
|
|
result._unusedFunctions = false;
|
2009-03-22 13:32:07 +01:00
|
|
|
result._security = true;
|
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
|
|
|
|
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-07-02 10:32:29 +02:00
|
|
|
mUI.mActionSettings->setEnabled(true);
|
|
|
|
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
|
|
|
|
2009-07-02 19:23:44 +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);
|
2009-03-22 13:32:07 +01:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
mUI.mActionRecheck->setEnabled(enable);
|
|
|
|
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::ShowSecurity(bool checked)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mResults->ShowResults(SHOW_SECURITY, 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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2009-07-04 10:06:29 +02:00
|
|
|
if (!mThread->IsChecking()) {
|
|
|
|
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.mActionShowSecurity->setChecked(checked);
|
2009-05-23 10:17:27 +02:00
|
|
|
ShowSecurity(checked);
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionShowStyle->setChecked(checked);
|
2009-05-23 10:17:27 +02:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
//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()
|
|
|
|
{
|
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;
|
|
|
|
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
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.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()
|
|
|
|
{
|
|
|
|
}
|
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;
|
|
|
|
if (text.isEmpty())
|
|
|
|
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
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
if (mTranslation->GetCurrentLanguage() == index)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString error;
|
|
|
|
if (!mTranslation->SetLanguage(index, error))
|
|
|
|
{
|
|
|
|
QMessageBox msg(QMessageBox::Warning,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
QString(tr("Failed to change language:\n\n%1")).arg(error),
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (languages.size() <= actions.size())
|
|
|
|
{
|
2009-07-02 18:14:12 +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();
|
2009-07-02 17:57:09 +02:00
|
|
|
for (int i = 0; i < actions.size(); i++)
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
if (actions[i] == action)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|