2015-08-16 17:36:10 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
|
|
|
* Copyright (C) 2007-2015 Daniel Marjamäki and Cppcheck team.
|
|
|
|
*
|
|
|
|
* 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 "librarydialog.h"
|
|
|
|
#include "ui_librarydialog.h"
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QFileDialog>
|
2015-08-23 12:49:51 +02:00
|
|
|
#include <QTextStream>
|
2015-08-16 17:36:10 +02:00
|
|
|
|
|
|
|
// TODO: get/compare functions from header
|
|
|
|
|
|
|
|
LibraryDialog::LibraryDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::LibraryDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-08-23 12:49:51 +02:00
|
|
|
ui->buttonSave->setEnabled(false);
|
2015-08-16 17:36:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LibraryDialog::~LibraryDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
void LibraryDialog::openCfg()
|
|
|
|
{
|
|
|
|
const QSettings settings;
|
|
|
|
const QString datadir = settings.value("DATADIR",QString()).toString();
|
|
|
|
|
|
|
|
QString selectedFilter;
|
|
|
|
const QString filter(tr("Library files (*.cfg)"));
|
|
|
|
const QString selectedFile = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Open library file"),
|
|
|
|
datadir,
|
|
|
|
filter,
|
|
|
|
&selectedFilter);
|
|
|
|
|
|
|
|
if (!selectedFile.isEmpty()) {
|
2015-08-23 16:03:24 +02:00
|
|
|
mFileName.clear();
|
2015-08-16 17:36:10 +02:00
|
|
|
QFile file(selectedFile);
|
|
|
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
2015-08-23 16:03:24 +02:00
|
|
|
data.open(file);
|
2015-08-23 12:49:51 +02:00
|
|
|
mFileName = selectedFile;
|
|
|
|
ui->buttonSave->setEnabled(false);
|
|
|
|
ui->functions->clear();
|
2015-08-23 16:03:24 +02:00
|
|
|
foreach(const struct LibraryData::Function &function, data.functions)
|
2015-08-23 13:34:50 +02:00
|
|
|
ui->functions->addItem(function.name);
|
2015-08-16 17:36:10 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-23 12:49:51 +02:00
|
|
|
}
|
2015-08-16 17:36:10 +02:00
|
|
|
|
2015-08-23 12:49:51 +02:00
|
|
|
void LibraryDialog::saveCfg()
|
|
|
|
{
|
2015-08-23 16:03:24 +02:00
|
|
|
if (mFileName.isNull())
|
|
|
|
return;
|
2015-08-23 12:49:51 +02:00
|
|
|
QFile file(mFileName);
|
|
|
|
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
2015-08-23 13:34:50 +02:00
|
|
|
QTextStream ts(&file);
|
2015-08-23 16:03:24 +02:00
|
|
|
ts << data.toString();
|
2015-08-23 12:49:51 +02:00
|
|
|
ui->buttonSave->setEnabled(false);
|
|
|
|
}
|
2015-08-16 17:36:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryDialog::selectFunction(int row)
|
|
|
|
{
|
2015-08-23 16:03:24 +02:00
|
|
|
const LibraryData::Function &function = data.functions[row];
|
2015-08-16 17:36:10 +02:00
|
|
|
ui->functionreturn->setChecked(!function.noreturn);
|
|
|
|
ui->useretval->setChecked(function.useretval);
|
|
|
|
ui->leakignore->setChecked(function.leakignore);
|
|
|
|
ui->arguments->clear();
|
2015-08-23 16:03:24 +02:00
|
|
|
foreach(const LibraryData::Function::Arg &arg, function.args) {
|
2015-08-16 17:36:10 +02:00
|
|
|
QString s("arg");
|
2015-08-23 16:03:24 +02:00
|
|
|
if (arg.nr != LibraryData::Function::Arg::ANY)
|
2015-08-16 17:36:10 +02:00
|
|
|
s += QString::number(arg.nr);
|
|
|
|
if (arg.formatstr)
|
|
|
|
s += " formatstr";
|
2015-08-23 12:49:51 +02:00
|
|
|
else if (arg.strz)
|
2015-08-16 17:36:10 +02:00
|
|
|
s += " strz";
|
|
|
|
else if (!arg.valid.isNull())
|
|
|
|
s += " " + arg.valid;
|
|
|
|
ui->arguments->addItem(s);
|
|
|
|
}
|
|
|
|
}
|
2015-08-23 12:49:51 +02:00
|
|
|
|
|
|
|
void LibraryDialog::changeFunction()
|
|
|
|
{
|
2015-08-23 13:34:50 +02:00
|
|
|
foreach(const QListWidgetItem *item, ui->functions->selectedItems()) {
|
2015-08-23 16:03:24 +02:00
|
|
|
LibraryData::Function &function = data.functions[ui->functions->row(item)];
|
2015-08-23 12:49:51 +02:00
|
|
|
function.noreturn = !ui->functionreturn->isChecked();
|
|
|
|
function.useretval = ui->useretval->isChecked();
|
|
|
|
function.leakignore = ui->leakignore->isChecked();
|
|
|
|
}
|
|
|
|
ui->buttonSave->setEnabled(true);
|
|
|
|
}
|
|
|
|
|