2010-07-12 23:10:48 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2012-01-01 00:05:37 +01:00
|
|
|
* Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team.
|
2010-07-12 23:10:48 +02: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 <QObject>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include "project.h"
|
|
|
|
#include "projectfile.h"
|
|
|
|
#include "projectfiledialog.h"
|
|
|
|
|
|
|
|
Project::Project(QWidget *parent) :
|
|
|
|
QObject(parent),
|
|
|
|
mPFile(NULL),
|
|
|
|
mParentWidget(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Project::Project(const QString &filename, QWidget *parent) :
|
|
|
|
QObject(parent),
|
|
|
|
mFilename(filename),
|
|
|
|
mPFile(NULL),
|
|
|
|
mParentWidget(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Project::~Project()
|
|
|
|
{
|
|
|
|
delete mPFile;
|
|
|
|
}
|
|
|
|
|
2011-08-24 21:41:48 +02:00
|
|
|
QString Project::Filename() const
|
|
|
|
{
|
|
|
|
return mFilename;
|
|
|
|
}
|
|
|
|
|
2010-07-12 23:10:48 +02:00
|
|
|
void Project::SetFilename(const QString &filename)
|
|
|
|
{
|
|
|
|
mFilename = filename;
|
|
|
|
}
|
|
|
|
|
2011-08-24 21:41:48 +02:00
|
|
|
bool Project::IsOpen() const
|
|
|
|
{
|
|
|
|
return mPFile != NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-12 23:10:48 +02:00
|
|
|
bool Project::Open()
|
|
|
|
{
|
|
|
|
mPFile = new ProjectFile(mFilename, this);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (QFile::exists(mFilename)) {
|
|
|
|
if (!mPFile->Read()) {
|
2010-07-12 23:10:48 +02:00
|
|
|
QMessageBox msg(QMessageBox::Critical,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
tr("Could not read the project file."),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
mParentWidget);
|
|
|
|
msg.exec();
|
|
|
|
mFilename = QString();
|
|
|
|
mPFile->SetFilename(mFilename);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-14 14:13:54 +02:00
|
|
|
bool Project::Edit()
|
2010-07-12 23:10:48 +02:00
|
|
|
{
|
|
|
|
ProjectFileDialog dlg(mFilename, mParentWidget);
|
2010-08-21 16:08:10 +02:00
|
|
|
QString root = mPFile->GetRootPath();
|
|
|
|
dlg.SetRootPath(root);
|
2010-07-12 23:10:48 +02:00
|
|
|
QStringList includes = mPFile->GetIncludeDirs();
|
|
|
|
dlg.SetIncludepaths(includes);
|
|
|
|
QStringList defines = mPFile->GetDefines();
|
|
|
|
dlg.SetDefines(defines);
|
2010-08-17 18:32:29 +02:00
|
|
|
QStringList paths = mPFile->GetCheckPaths();
|
|
|
|
dlg.SetPaths(paths);
|
2011-08-23 18:54:53 +02:00
|
|
|
QStringList ignorepaths = mPFile->GetExcludedPaths();
|
2011-09-25 19:59:47 +02:00
|
|
|
dlg.SetExcludedPaths(ignorepaths);
|
2011-02-28 14:58:44 +01:00
|
|
|
|
2010-07-12 23:10:48 +02:00
|
|
|
int rv = dlg.exec();
|
2011-10-13 20:53:06 +02:00
|
|
|
if (rv == QDialog::Accepted) {
|
2010-08-21 16:08:10 +02:00
|
|
|
QString root = dlg.GetRootPath();
|
|
|
|
mPFile->SetRootPath(root);
|
2010-07-12 23:10:48 +02:00
|
|
|
QStringList includes = dlg.GetIncludePaths();
|
|
|
|
mPFile->SetIncludes(includes);
|
|
|
|
QStringList defines = dlg.GetDefines();
|
|
|
|
mPFile->SetDefines(defines);
|
2010-08-17 18:32:29 +02:00
|
|
|
QStringList paths = dlg.GetPaths();
|
|
|
|
mPFile->SetCheckPaths(paths);
|
2011-09-25 19:59:47 +02:00
|
|
|
QStringList excludedpaths = dlg.GetExcludedPaths();
|
|
|
|
mPFile->SetExcludedPaths(excludedpaths);
|
2011-02-28 14:58:44 +01:00
|
|
|
|
2010-07-12 23:10:48 +02:00
|
|
|
bool writeSuccess = mPFile->Write();
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!writeSuccess) {
|
2010-07-12 23:10:48 +02:00
|
|
|
QMessageBox msg(QMessageBox::Critical,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
tr("Could not write the project file."),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
mParentWidget);
|
|
|
|
msg.exec();
|
|
|
|
}
|
2012-10-14 14:13:54 +02:00
|
|
|
return writeSuccess;
|
2010-07-12 23:10:48 +02:00
|
|
|
}
|
2012-10-14 14:13:54 +02:00
|
|
|
return false;
|
2010-07-12 23:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Project::Create()
|
|
|
|
{
|
|
|
|
mPFile = new ProjectFile(mFilename, this);
|
|
|
|
}
|