2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2010-04-13 21:23:17 +02:00
|
|
|
* Copyright (C) 2007-2010 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"
|
2010-07-12 19:21:45 +02:00
|
|
|
#include "project.h"
|
2009-07-06 11:30:49 +02:00
|
|
|
#include "report.h"
|
2010-09-01 08:12:24 +02:00
|
|
|
#include "statsdialog.h"
|
2010-07-16 16:48:13 +02:00
|
|
|
#include "logview.h"
|
2010-08-11 16:22:39 +02:00
|
|
|
#include "filelist.h"
|
2010-08-20 21:25:43 +02:00
|
|
|
#include "helpwindow.h"
|
2009-03-01 08:38:21 +01:00
|
|
|
|
|
|
|
MainWindow::MainWindow() :
|
2010-04-15 20:08:51 +02:00
|
|
|
mSettings(new QSettings("Cppcheck", "Cppcheck-GUI", this)),
|
|
|
|
mApplications(new ApplicationList(this)),
|
|
|
|
mTranslation(new TranslationHandler(this)),
|
2010-07-16 16:48:13 +02:00
|
|
|
mLanguages(new QActionGroup(this)),
|
2010-07-17 22:52:50 +02:00
|
|
|
mLogView(NULL),
|
2010-08-21 11:02:52 +02:00
|
|
|
mHelpWindow(NULL),
|
2010-08-24 23:56:45 +02:00
|
|
|
mProject(NULL),
|
|
|
|
mExiting(false)
|
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);
|
2010-07-16 22:27:57 +02:00
|
|
|
mLogView = new LogView(mSettings);
|
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()));
|
2010-07-10 15:37:36 +02:00
|
|
|
connect(mUI.mActionOpenXML, SIGNAL(triggered()), this, SLOT(OpenXML()));
|
2009-07-02 10:32:29 +02:00
|
|
|
|
|
|
|
connect(mUI.mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool)));
|
|
|
|
connect(mUI.mActionShowErrors, SIGNAL(toggled(bool)), this, SLOT(ShowErrors(bool)));
|
2010-10-18 19:50:34 +02:00
|
|
|
connect(mUI.mActionShowWarnings, SIGNAL(toggled(bool)), this, SLOT(ShowWarnings(bool)));
|
|
|
|
connect(mUI.mActionShowPerformance, SIGNAL(toggled(bool)), this, SLOT(ShowPerformance(bool)));
|
2009-07-02 10:32:29 +02:00
|
|
|
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()));
|
2010-11-21 19:55:34 +01:00
|
|
|
connect(mUI.mActionShowHidden, SIGNAL(triggered()), mUI.mResults, SLOT(ShowHiddenResults()));
|
2010-07-16 16:48:13 +02:00
|
|
|
connect(mUI.mActionViewLog, SIGNAL(triggered()), this, SLOT(ShowLogView()));
|
2010-09-01 08:12:24 +02:00
|
|
|
connect(mUI.mActionViewStats, SIGNAL(triggered()), this, SLOT(ShowStatistics()));
|
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()));
|
2010-07-03 19:03:53 +02:00
|
|
|
connect(mUI.mActionToolBarMain, SIGNAL(toggled(bool)), this, SLOT(ToggleMainToolBar()));
|
2010-07-03 18:37:09 +02:00
|
|
|
connect(mUI.mActionToolBarView, SIGNAL(toggled(bool)), this, SLOT(ToggleViewToolBar()));
|
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()));
|
2010-11-24 09:48:07 +01:00
|
|
|
connect(mUI.mResults, SIGNAL(ResultsHidden(bool)), mUI.mActionShowHidden, SLOT(setEnabled(bool)));
|
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-07-13 11:33:24 +02:00
|
|
|
connect(mUI.mActionNewProjectFile, SIGNAL(triggered()), this, SLOT(NewProjectFile()));
|
|
|
|
connect(mUI.mActionOpenProjectFile, SIGNAL(triggered()), this, SLOT(OpenProjectFile()));
|
2010-08-15 11:12:28 +02:00
|
|
|
connect(mUI.mActionCloseProjectFile, SIGNAL(triggered()), this, SLOT(CloseProjectFile()));
|
2010-08-15 15:12:32 +02:00
|
|
|
connect(mUI.mActionEditProjectFile, SIGNAL(triggered()), this, SLOT(EditProjectFile()));
|
2010-07-07 20:18:42 +02:00
|
|
|
|
2010-02-23 16:29:49 +01:00
|
|
|
connect(mUI.mActionHelpContents, SIGNAL(triggered()), this, SLOT(OpenHelpContents()));
|
|
|
|
|
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);
|
2010-08-25 19:59:30 +02:00
|
|
|
EnableProjectOpenActions(true);
|
2010-08-25 17:54:45 +02:00
|
|
|
EnableProjectActions(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()
|
|
|
|
{
|
2010-07-16 16:48:13 +02:00
|
|
|
delete mLogView;
|
2010-08-21 11:02:52 +02:00
|
|
|
delete mHelpWindow;
|
2010-08-15 10:35:46 +02:00
|
|
|
delete mProject;
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
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.mActionShowStyle->setChecked(mSettings->value(SETTINGS_SHOW_STYLE, true).toBool());
|
|
|
|
mUI.mActionShowErrors->setChecked(mSettings->value(SETTINGS_SHOW_ERRORS, true).toBool());
|
2010-10-18 19:50:34 +02:00
|
|
|
mUI.mActionShowWarnings->setChecked(mSettings->value(SETTINGS_SHOW_WARNINGS, true).toBool());
|
|
|
|
mUI.mActionShowPerformance->setChecked(mSettings->value(SETTINGS_SHOW_PERFORMANCE, true).toBool());
|
2009-07-02 10:32:29 +02:00
|
|
|
|
|
|
|
mUI.mResults->ShowResults(SHOW_ERRORS, mUI.mActionShowErrors->isChecked());
|
|
|
|
mUI.mResults->ShowResults(SHOW_STYLE, mUI.mActionShowStyle->isChecked());
|
2009-07-01 23:05:09 +02:00
|
|
|
|
2010-07-03 19:03:53 +02:00
|
|
|
mUI.mActionToolBarMain->setChecked(mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool());
|
|
|
|
mUI.mToolBarMain->setVisible(mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool());
|
2010-07-03 18:37:09 +02:00
|
|
|
mUI.mToolBarView->setVisible(mSettings->value(SETTINGS_TOOLBARS_VIEW_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_STYLE, mUI.mActionShowStyle->isChecked());
|
|
|
|
mSettings->setValue(SETTINGS_SHOW_ERRORS, mUI.mActionShowErrors->isChecked());
|
2010-10-18 19:50:34 +02:00
|
|
|
mSettings->setValue(SETTINGS_SHOW_WARNINGS, mUI.mActionShowWarnings->isChecked());
|
|
|
|
mSettings->setValue(SETTINGS_SHOW_PERFORMANCE, mUI.mActionShowPerformance->isChecked());
|
2010-07-03 19:03:53 +02:00
|
|
|
mSettings->setValue(SETTINGS_TOOLBARS_MAIN_SHOW, mUI.mToolBarMain->isVisible());
|
2010-07-03 18:37:09 +02:00
|
|
|
mSettings->setValue(SETTINGS_TOOLBARS_VIEW_SHOW, mUI.mToolBarView->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());
|
2010-11-23 20:57:16 +01:00
|
|
|
mUI.mResults->SaveSettings(mSettings);
|
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();
|
|
|
|
|
2010-08-09 21:15:05 +02:00
|
|
|
FileList pathList;
|
|
|
|
pathList.AddPathList(files);
|
|
|
|
QStringList fileNames = pathList.GetFileList();
|
2009-07-16 07:20:29 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-07-04 17:54:41 +02:00
|
|
|
mUI.mResults->CheckingStarted(fileNames.count());
|
2009-07-16 07:20:29 +02:00
|
|
|
|
2010-08-09 21:15:05 +02:00
|
|
|
mThread->SetFiles(fileNames);
|
2010-07-18 11:57:48 +02:00
|
|
|
QDir inf(mCurrentDirectory);
|
2010-08-09 21:25:43 +02:00
|
|
|
const QString checkPath = inf.canonicalPath();
|
|
|
|
mSettings->setValue(SETTINGS_CHECK_PATH, checkPath);
|
2009-07-16 07:20:29 +02:00
|
|
|
EnableCheckButtons(false);
|
|
|
|
mUI.mActionSettings->setEnabled(false);
|
2010-07-12 01:18:26 +02:00
|
|
|
mUI.mActionOpenXML->setEnabled(false);
|
2010-08-09 21:25:43 +02:00
|
|
|
mUI.mResults->SetCheckDirectory(checkPath);
|
2009-07-16 07:20:29 +02:00
|
|
|
|
|
|
|
Settings checkSettings = GetCppcheckSettings();
|
2010-08-25 17:54:45 +02:00
|
|
|
EnableProjectActions(false);
|
2010-08-25 19:59:30 +02:00
|
|
|
EnableProjectOpenActions(false);
|
2009-07-16 07:20:29 +02:00
|
|
|
mThread->Check(checkSettings, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2010-08-19 21:28:56 +02:00
|
|
|
if (mProject)
|
|
|
|
{
|
|
|
|
QMessageBox msgBox(this);
|
|
|
|
msgBox.setWindowTitle(tr("Cppcheck"));
|
|
|
|
const QString msg(tr("You must close the project file before selecting new files or directories!"));
|
|
|
|
msgBox.setText(msg);
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.exec();
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-07-18 11:57:48 +02:00
|
|
|
qDebug() << "Setting current directory to: " << dir;
|
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
|
|
|
}
|
|
|
|
|
2010-08-24 23:47:05 +02:00
|
|
|
bool MainWindow::GetCheckProject()
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
2010-12-15 18:45:53 +01:00
|
|
|
// We have successfully loaded project earlier and use that project
|
2010-08-24 23:47:05 +02:00
|
|
|
if (mProject)
|
|
|
|
return true;
|
2009-06-22 10:57:17 +02:00
|
|
|
|
2010-08-24 23:47:05 +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-08-25 17:54:45 +02:00
|
|
|
const QString filename = parts[parts.count() - 1] + ".cppcheck";;
|
|
|
|
const QString projfile = mCurrentDirectory + "/" + filename;
|
2010-04-02 07:30:58 +02:00
|
|
|
if (QFile::exists(projfile))
|
2010-01-03 08:39:00 +01:00
|
|
|
{
|
2010-08-24 23:47:05 +02:00
|
|
|
qDebug() << "Opening project file: " << projfile;
|
|
|
|
mProject = new Project();
|
|
|
|
mProject->SetFilename(projfile);
|
2010-08-25 17:54:45 +02:00
|
|
|
FormatAndSetTitle(tr("Project: ") + QString(" ") + filename);
|
2010-08-24 23:47:05 +02:00
|
|
|
return mProject->Open();
|
2010-01-03 08:39:00 +01:00
|
|
|
}
|
2010-08-15 10:35:46 +02:00
|
|
|
}
|
2010-08-24 23:47:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
2009-06-22 10:57:17 +02:00
|
|
|
|
2010-11-26 21:51:38 +01:00
|
|
|
void MainWindow::AddIncludeDirs(const QStringList &includeDirs, Settings &result)
|
|
|
|
{
|
|
|
|
QString dir;
|
|
|
|
foreach(dir, includeDirs)
|
|
|
|
{
|
|
|
|
QString incdir;
|
|
|
|
if (!QDir::isAbsolutePath(dir))
|
|
|
|
incdir = mCurrentDirectory + "/";
|
|
|
|
incdir += dir;
|
|
|
|
incdir = QDir::cleanPath(incdir);
|
|
|
|
|
|
|
|
// include paths must end with '/'
|
|
|
|
if (!incdir.endsWith("/"))
|
|
|
|
incdir += "/";
|
|
|
|
result._includePaths.push_back(incdir.toStdString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:47:05 +02:00
|
|
|
Settings MainWindow::GetCppcheckSettings()
|
|
|
|
{
|
|
|
|
Settings result;
|
2010-11-26 21:35:45 +01:00
|
|
|
|
|
|
|
QString globalIncludes = mSettings->value(SETTINGS_GLOBAL_INCLUDE_PATHS).toString();
|
|
|
|
if (!globalIncludes.isEmpty())
|
|
|
|
{
|
|
|
|
QStringList includes = globalIncludes.split(";");
|
2010-11-26 21:51:38 +01:00
|
|
|
AddIncludeDirs(includes, result);
|
2010-11-26 21:35:45 +01:00
|
|
|
}
|
|
|
|
|
2010-08-24 23:47:05 +02:00
|
|
|
bool projectRead = GetCheckProject();
|
2010-08-15 10:35:46 +02:00
|
|
|
if (projectRead)
|
|
|
|
{
|
2010-08-24 23:47:05 +02:00
|
|
|
ProjectFile *pfile = mProject->GetProjectFile();
|
2010-08-15 10:35:46 +02:00
|
|
|
QStringList dirs = pfile->GetIncludeDirs();
|
2010-11-26 21:51:38 +01:00
|
|
|
AddIncludeDirs(dirs, result);
|
|
|
|
|
2010-08-21 21:59:55 +02:00
|
|
|
QStringList defines = pfile->GetDefines();
|
|
|
|
QString define;
|
|
|
|
foreach(define, defines)
|
|
|
|
{
|
|
|
|
if (!result.userDefines.empty())
|
|
|
|
result.userDefines += ";";
|
|
|
|
result.userDefines += define.toStdString();
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-06 22:28:41 +02:00
|
|
|
result.addEnabled("style");
|
2010-08-28 08:16:01 +02:00
|
|
|
result.debug = false;
|
2010-08-29 08:38:03 +02:00
|
|
|
result.debugwarnings = mSettings->value(SETTINGS_SHOW_DEBUG_WARNINGS, 0).toBool();
|
2009-03-22 13:32:07 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
void MainWindow::CheckDone()
|
|
|
|
{
|
2010-07-17 22:52:50 +02:00
|
|
|
if (mExiting)
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-04 17:54:41 +02:00
|
|
|
mUI.mResults->CheckingFinished();
|
2009-03-22 16:42:00 +01:00
|
|
|
EnableCheckButtons(true);
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mActionSettings->setEnabled(true);
|
2010-07-12 01:18:26 +02:00
|
|
|
mUI.mActionOpenXML->setEnabled(true);
|
2010-08-25 17:54:45 +02:00
|
|
|
EnableProjectActions(true);
|
2010-08-25 19:59:30 +02:00
|
|
|
EnableProjectOpenActions(true);
|
2010-07-13 11:46:28 +02:00
|
|
|
|
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
|
|
|
{
|
2010-11-26 21:35:45 +01:00
|
|
|
dialog.SaveSettingValues();
|
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);
|
2010-07-07 11:25:47 +02:00
|
|
|
|
|
|
|
const int filesCount = mThread->GetPreviousFilesCount();
|
|
|
|
Q_ASSERT(filesCount > 0); // If no files should not be able to recheck
|
|
|
|
mUI.mResults->CheckingStarted(filesCount);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-07-10 15:37:36 +02:00
|
|
|
void MainWindow::OpenXML()
|
|
|
|
{
|
|
|
|
QString selectedFilter;
|
|
|
|
QString filter(tr("XML files (*.xml)"));
|
|
|
|
QString selectedFile = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Open the report file"),
|
|
|
|
QString(),
|
|
|
|
filter,
|
|
|
|
&selectedFilter);
|
|
|
|
|
|
|
|
if (!selectedFile.isEmpty())
|
|
|
|
{
|
|
|
|
mUI.mResults->ReadErrorsXml(selectedFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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::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
|
|
|
|
2010-10-18 19:50:34 +02:00
|
|
|
void MainWindow::ShowWarnings(bool checked)
|
|
|
|
{
|
|
|
|
mUI.mResults->ShowResults(SHOW_WARNINGS, checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ShowPerformance(bool checked)
|
|
|
|
{
|
|
|
|
mUI.mResults->ShowResults(SHOW_PERFORMANCE, 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
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!mThread->IsChecking())
|
2009-07-04 14:54:28 +02:00
|
|
|
{
|
2010-08-21 11:02:52 +02:00
|
|
|
delete mHelpWindow;
|
|
|
|
mHelpWindow = NULL;
|
|
|
|
|
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
|
|
|
|
{
|
2010-07-16 11:44:11 +02:00
|
|
|
QString text(tr("Checking is running.\n\n" \
|
|
|
|
"Do you want to stop the checking and exit Cppcheck?."));
|
2009-06-09 09:51:27 +02:00
|
|
|
|
|
|
|
QMessageBox msg(QMessageBox::Warning,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
text,
|
2010-07-16 11:44:11 +02:00
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
2009-06-09 09:51:27 +02:00
|
|
|
this);
|
|
|
|
|
2010-07-16 11:44:11 +02:00
|
|
|
msg.setDefaultButton(QMessageBox::No);
|
|
|
|
int rv = msg.exec();
|
|
|
|
if (rv == QMessageBox::Yes)
|
|
|
|
{
|
|
|
|
// This isn't really very clean way to close threads but since the app is
|
|
|
|
// exiting it doesn't matter.
|
|
|
|
mThread->Stop();
|
|
|
|
SaveSettings();
|
2010-07-17 22:52:50 +02:00
|
|
|
mExiting = true;
|
2010-07-16 11:44:11 +02:00
|
|
|
}
|
2010-07-17 22:52:50 +02:00
|
|
|
event->ignore();
|
2009-06-04 16:02:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
void MainWindow::ToggleAllChecked(bool 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);
|
2010-10-18 19:50:34 +02:00
|
|
|
mUI.mActionShowWarnings->setChecked(checked);
|
|
|
|
ShowWarnings(checked);
|
|
|
|
mUI.mActionShowPerformance->setChecked(checked);
|
|
|
|
ShowPerformance(checked);
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
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
|
|
|
|
2010-07-03 19:03:53 +02:00
|
|
|
void MainWindow::ToggleMainToolBar()
|
2009-07-01 22:46:42 +02:00
|
|
|
{
|
2010-07-03 19:03:53 +02:00
|
|
|
mUI.mToolBarMain->setVisible(mUI.mActionToolBarMain->isChecked());
|
2009-07-01 22:46:42 +02:00
|
|
|
}
|
|
|
|
|
2010-07-03 18:37:09 +02:00
|
|
|
void MainWindow::ToggleViewToolBar()
|
|
|
|
{
|
|
|
|
mUI.mToolBarView->setVisible(mUI.mActionToolBarView->isChecked());
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2010-07-03 19:03:53 +02:00
|
|
|
mUI.mActionToolBarMain->setChecked(mUI.mToolBarMain->isVisible());
|
2010-07-03 18:37:09 +02:00
|
|
|
mUI.mActionToolBarView->setChecked(mUI.mToolBarView->isVisible());
|
2009-07-02 19:11:47 +02:00
|
|
|
}
|
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()
|
|
|
|
{
|
2010-08-21 11:02:52 +02:00
|
|
|
if (mHelpWindow == NULL)
|
2010-08-25 20:08:07 +02:00
|
|
|
{
|
|
|
|
const QString fname = qApp->applicationDirPath() + "/online-help.qhc";
|
|
|
|
if (!QFileInfo(fname).exists())
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Cppcheck Help"), tr("Failed to load help file (not found)"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-21 11:02:52 +02:00
|
|
|
mHelpWindow = new HelpWindow;
|
2010-08-25 20:08:07 +02:00
|
|
|
if (!mHelpWindow->load(fname))
|
|
|
|
{
|
|
|
|
delete mHelpWindow;
|
|
|
|
mHelpWindow = NULL;
|
|
|
|
QMessageBox::warning(this, tr("Cppcheck Help"), tr("Failed to load help file"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-08-21 11:02:52 +02:00
|
|
|
|
|
|
|
mHelpWindow->show();
|
|
|
|
if (!mHelpWindow->isActiveWindow())
|
|
|
|
mHelpWindow->activateWindow();
|
2010-02-23 16:29:49 +01:00
|
|
|
}
|
2010-07-07 20:18:42 +02:00
|
|
|
|
2010-07-13 11:33:24 +02:00
|
|
|
void MainWindow::OpenProjectFile()
|
2010-07-07 20:18:42 +02:00
|
|
|
{
|
2010-08-24 19:50:25 +02:00
|
|
|
delete mProject;
|
2010-08-15 10:35:46 +02:00
|
|
|
|
2010-07-07 20:18:42 +02:00
|
|
|
const QString filter = tr("Project files (*.cppcheck);;All files(*.*)");
|
|
|
|
QString filepath = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Select Project File"),
|
|
|
|
QString(),
|
|
|
|
filter);
|
|
|
|
|
|
|
|
if (!filepath.isEmpty())
|
|
|
|
{
|
2010-08-17 17:06:17 +02:00
|
|
|
QFileInfo inf(filepath);
|
|
|
|
const QString filename = inf.fileName();
|
2010-08-25 17:54:45 +02:00
|
|
|
FormatAndSetTitle(tr("Project: ") + QString(" ") + filename);
|
2010-08-17 17:06:17 +02:00
|
|
|
|
2010-08-15 11:12:28 +02:00
|
|
|
mUI.mActionCloseProjectFile->setEnabled(true);
|
2010-08-15 15:12:32 +02:00
|
|
|
mUI.mActionEditProjectFile->setEnabled(true);
|
2010-08-15 10:35:46 +02:00
|
|
|
mProject = new Project(filepath, this);
|
|
|
|
mProject->Open();
|
2010-08-21 18:38:51 +02:00
|
|
|
QString rootpath = mProject->GetProjectFile()->GetRootPath();
|
|
|
|
|
|
|
|
// If root path not give or "current dir" then use project file's directory
|
|
|
|
// as check path
|
|
|
|
if (rootpath.isEmpty() || rootpath == ".")
|
|
|
|
mCurrentDirectory = inf.canonicalPath();
|
|
|
|
else
|
|
|
|
mCurrentDirectory = rootpath;
|
|
|
|
|
2010-08-15 10:35:46 +02:00
|
|
|
QStringList paths = mProject->GetProjectFile()->GetCheckPaths();
|
|
|
|
if (!paths.isEmpty())
|
2010-08-19 21:06:45 +02:00
|
|
|
{
|
2010-08-21 18:38:51 +02:00
|
|
|
for (int i = 0; i < paths.size(); i++)
|
|
|
|
{
|
|
|
|
if (!QDir::isAbsolutePath(paths[i]))
|
|
|
|
{
|
|
|
|
QString path = mCurrentDirectory + "/";
|
|
|
|
path += paths[i];
|
|
|
|
paths[i] = QDir::cleanPath(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-15 10:35:46 +02:00
|
|
|
DoCheckFiles(paths);
|
2010-08-19 21:06:45 +02:00
|
|
|
}
|
2010-07-07 20:18:42 +02:00
|
|
|
}
|
|
|
|
}
|
2010-07-08 17:59:06 +02:00
|
|
|
|
2010-07-13 11:33:24 +02:00
|
|
|
void MainWindow::NewProjectFile()
|
2010-07-08 17:59:06 +02:00
|
|
|
{
|
2010-07-12 19:21:45 +02:00
|
|
|
const QString filter = tr("Project files (*.cppcheck);;All files(*.*)");
|
|
|
|
QString filepath = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Select Project Filename"),
|
|
|
|
QString(),
|
|
|
|
filter);
|
|
|
|
|
|
|
|
if (!filepath.isEmpty())
|
|
|
|
{
|
2010-08-25 17:54:45 +02:00
|
|
|
EnableProjectActions(true);
|
2010-08-17 17:06:17 +02:00
|
|
|
QFileInfo inf(filepath);
|
|
|
|
const QString filename = inf.fileName();
|
2010-08-25 17:54:45 +02:00
|
|
|
FormatAndSetTitle(tr("Project: ") + QString(" ") + filename);
|
2010-08-15 21:51:15 +02:00
|
|
|
|
2010-08-24 19:50:25 +02:00
|
|
|
delete mProject;
|
2010-08-15 21:51:15 +02:00
|
|
|
mProject = new Project(filepath, this);
|
|
|
|
mProject->Create();
|
|
|
|
mProject->Edit();
|
2010-07-12 19:21:45 +02:00
|
|
|
}
|
2010-07-08 17:59:06 +02:00
|
|
|
}
|
2010-07-16 16:48:13 +02:00
|
|
|
|
2010-08-15 11:12:28 +02:00
|
|
|
void MainWindow::CloseProjectFile()
|
|
|
|
{
|
|
|
|
delete mProject;
|
|
|
|
mProject = NULL;
|
2010-08-25 17:54:45 +02:00
|
|
|
EnableProjectActions(false);
|
2010-08-25 19:59:30 +02:00
|
|
|
EnableProjectOpenActions(true);
|
2010-08-17 17:06:17 +02:00
|
|
|
FormatAndSetTitle();
|
2010-08-15 15:12:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::EditProjectFile()
|
|
|
|
{
|
|
|
|
if (!mProject)
|
|
|
|
{
|
|
|
|
QMessageBox msg(QMessageBox::Critical,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
QString(tr("No project file loaded")),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
msg.exec();
|
|
|
|
return;
|
2010-07-12 19:21:45 +02:00
|
|
|
}
|
2010-08-15 15:12:32 +02:00
|
|
|
mProject->Edit();
|
2010-07-08 17:59:06 +02:00
|
|
|
}
|
2010-07-16 16:48:13 +02:00
|
|
|
|
|
|
|
void MainWindow::ShowLogView()
|
|
|
|
{
|
|
|
|
if (mLogView == NULL)
|
2010-07-16 22:27:57 +02:00
|
|
|
mLogView = new LogView(mSettings);
|
2010-07-16 16:48:13 +02:00
|
|
|
|
|
|
|
mLogView->show();
|
|
|
|
if (!mLogView->isActiveWindow())
|
|
|
|
mLogView->activateWindow();
|
|
|
|
}
|
|
|
|
|
2010-09-01 08:12:24 +02:00
|
|
|
void MainWindow::ShowStatistics()
|
|
|
|
{
|
|
|
|
StatsDialog statsDialog(this);
|
|
|
|
|
|
|
|
// Show a dialog with the previous scan statistics and project information
|
|
|
|
if (mProject)
|
|
|
|
{
|
|
|
|
statsDialog.setProject(*mProject);
|
|
|
|
}
|
|
|
|
statsDialog.setPathSelected(mCurrentDirectory);
|
|
|
|
statsDialog.setNumberOfFilesScanned(mThread->GetPreviousFilesCount());
|
|
|
|
statsDialog.setScanDuration(mThread->GetPreviousScanDuration() / 1000.0);
|
2010-11-29 23:01:45 +01:00
|
|
|
statsDialog.setStatistics(mUI.mResults->GetStatistics());
|
2010-09-01 08:12:24 +02:00
|
|
|
|
|
|
|
statsDialog.exec();
|
|
|
|
}
|
|
|
|
|
2010-07-16 16:48:13 +02:00
|
|
|
void MainWindow::Log(const QString &logline)
|
|
|
|
{
|
|
|
|
if (mLogView)
|
|
|
|
{
|
|
|
|
mLogView->AppendLine(logline);
|
|
|
|
}
|
|
|
|
}
|
2010-08-25 17:54:45 +02:00
|
|
|
|
2010-08-28 19:37:21 +02:00
|
|
|
void MainWindow::DebugError(const ErrorItem &item)
|
|
|
|
{
|
|
|
|
if (mLogView)
|
|
|
|
{
|
|
|
|
mLogView->AppendLine(item.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-25 17:54:45 +02:00
|
|
|
void MainWindow::EnableProjectActions(bool enable)
|
|
|
|
{
|
|
|
|
mUI.mActionCloseProjectFile->setEnabled(enable);
|
|
|
|
mUI.mActionEditProjectFile->setEnabled(enable);
|
|
|
|
}
|
2010-08-25 19:59:30 +02:00
|
|
|
|
|
|
|
void MainWindow::EnableProjectOpenActions(bool enable)
|
|
|
|
{
|
|
|
|
mUI.mActionNewProjectFile->setEnabled(enable);
|
|
|
|
mUI.mActionOpenProjectFile->setEnabled(enable);
|
|
|
|
}
|