2010-07-12 23:10:48 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2016-01-01 14:34:45 +01:00
|
|
|
* Copyright (C) 2007-2016 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),
|
2016-11-19 21:12:32 +01:00
|
|
|
mProjectFile(NULL),
|
2010-07-12 23:10:48 +02:00
|
|
|
mParentWidget(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Project::Project(const QString &filename, QWidget *parent) :
|
|
|
|
QObject(parent),
|
|
|
|
mFilename(filename),
|
2016-11-19 21:12:32 +01:00
|
|
|
mProjectFile(NULL),
|
2010-07-12 23:10:48 +02:00
|
|
|
mParentWidget(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Project::~Project()
|
|
|
|
{
|
2016-11-19 21:12:32 +01:00
|
|
|
delete mProjectFile;
|
2010-07-12 23:10:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 04:57:28 +02:00
|
|
|
QString Project::getFilename() const
|
2011-08-24 21:41:48 +02:00
|
|
|
{
|
|
|
|
return mFilename;
|
|
|
|
}
|
|
|
|
|
2017-07-28 04:57:28 +02:00
|
|
|
void Project::setFilename(const QString &filename)
|
2010-07-12 23:10:48 +02:00
|
|
|
{
|
|
|
|
mFilename = filename;
|
|
|
|
}
|
|
|
|
|
2017-07-28 04:57:28 +02:00
|
|
|
bool Project::isOpen() const
|
2011-08-24 21:41:48 +02:00
|
|
|
{
|
2016-11-19 21:12:32 +01:00
|
|
|
return mProjectFile != NULL;
|
2011-08-24 21:41:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 04:57:28 +02:00
|
|
|
bool Project::open()
|
2010-07-12 23:10:48 +02:00
|
|
|
{
|
2016-11-19 21:12:32 +01:00
|
|
|
mProjectFile = new ProjectFile(mFilename, this);
|
2016-10-01 12:06:04 +02:00
|
|
|
if (!QFile::exists(mFilename))
|
|
|
|
return false;
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
if (!mProjectFile->read()) {
|
2016-10-01 12:06:04 +02:00
|
|
|
QMessageBox msg(QMessageBox::Critical,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
tr("Could not read the project file."),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
mParentWidget);
|
|
|
|
msg.exec();
|
|
|
|
mFilename = QString();
|
2017-07-28 05:08:59 +02:00
|
|
|
mProjectFile->setFilename(mFilename);
|
2016-10-01 12:06:04 +02:00
|
|
|
return false;
|
2010-07-12 23:10:48 +02:00
|
|
|
}
|
2016-10-01 12:06:04 +02:00
|
|
|
|
|
|
|
return true;
|
2010-07-12 23:10:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 04:57:28 +02:00
|
|
|
bool Project::edit()
|
2010-07-12 23:10:48 +02:00
|
|
|
{
|
|
|
|
ProjectFileDialog dlg(mFilename, mParentWidget);
|
2016-11-19 22:54:32 +01:00
|
|
|
dlg.LoadFromProjectFile(mProjectFile);
|
2016-11-19 20:38:50 +01:00
|
|
|
if (dlg.exec() != QDialog::Accepted)
|
|
|
|
return false;
|
|
|
|
|
2016-11-19 22:54:32 +01:00
|
|
|
dlg.SaveToProjectFile(mProjectFile);
|
2016-11-19 21:12:32 +01:00
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
if (!mProjectFile->write()) {
|
2016-11-19 20:38:50 +01:00
|
|
|
QMessageBox msg(QMessageBox::Critical,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
tr("Could not write the project file."),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
mParentWidget);
|
|
|
|
msg.exec();
|
|
|
|
return false;
|
2010-07-12 23:10:48 +02:00
|
|
|
}
|
2016-11-19 20:38:50 +01:00
|
|
|
|
|
|
|
return true;
|
2010-07-12 23:10:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 04:57:28 +02:00
|
|
|
void Project::create()
|
2010-07-12 23:10:48 +02:00
|
|
|
{
|
2016-11-19 21:12:32 +01:00
|
|
|
mProjectFile = new ProjectFile(mFilename, this);
|
2010-07-12 23:10:48 +02:00
|
|
|
}
|