2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
|
|
|
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
|
|
|
* Leandro Penz, Kimmo Varis, Vesa Pikki
|
|
|
|
*
|
|
|
|
* 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 "settingsdialog.h"
|
2009-03-22 13:32:07 +01:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QDebug>
|
2009-05-23 12:37:30 +02:00
|
|
|
#include <QTabWidget>
|
|
|
|
#include "applicationdialog.h"
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list) :
|
|
|
|
mSettings(programSettings),
|
|
|
|
mApplications(list)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-05-23 12:37:30 +02:00
|
|
|
//Create a layout for the settings dialog
|
|
|
|
QVBoxLayout *dialoglayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
//Create a tabwidget and add it to dialogs layout
|
|
|
|
QTabWidget *tabs = new QTabWidget();
|
|
|
|
dialoglayout->addWidget(tabs);
|
|
|
|
|
|
|
|
//Add ok and cancel buttons
|
2009-03-22 13:32:07 +01:00
|
|
|
QPushButton *cancel = new QPushButton(tr("Cancel"));
|
|
|
|
QPushButton *ok = new QPushButton(tr("Ok"));
|
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
//Add a layout for ok/cancel buttons
|
|
|
|
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
|
|
|
|
|
|
|
buttonLayout->addWidget(ok);
|
|
|
|
buttonLayout->addWidget(cancel);
|
|
|
|
//Add button layout to the main dialog layout
|
|
|
|
dialoglayout->addLayout(buttonLayout);
|
|
|
|
|
|
|
|
//Connect OK buttons
|
|
|
|
connect(ok, SIGNAL(clicked()),
|
|
|
|
this, SLOT(accept()));
|
|
|
|
connect(cancel, SIGNAL(clicked()),
|
|
|
|
this, SLOT(reject()));
|
|
|
|
|
|
|
|
|
|
|
|
//Begin adding tabs and tab content
|
|
|
|
|
|
|
|
//General tab
|
|
|
|
QWidget *general = new QWidget();
|
2009-05-23 13:26:04 +02:00
|
|
|
tabs->addTab(general, tr("General"));
|
2009-05-23 12:37:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
//layout for general tab
|
2009-03-22 13:32:07 +01:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
|
|
//Number of jobs
|
|
|
|
QHBoxLayout *jobsLayout = new QHBoxLayout();
|
|
|
|
mJobs = new QLineEdit(programSettings.value(tr("Check threads"), 1).toString());
|
|
|
|
jobsLayout->addWidget(new QLabel(tr("Number of threads: ")));
|
|
|
|
jobsLayout->addWidget(mJobs);
|
|
|
|
mJobs->setValidator(new QIntValidator(this));
|
|
|
|
layout->addLayout(jobsLayout);
|
|
|
|
|
|
|
|
//Force
|
2009-03-22 19:00:06 +01:00
|
|
|
mForce = AddCheckbox(layout,
|
|
|
|
tr("Force checking on files that have \"too many\" configurations"),
|
|
|
|
tr("Check force"),
|
|
|
|
false);
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
general->setLayout(layout);
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
//Add tab for setting user startable applications
|
|
|
|
QWidget *applications = new QWidget();
|
2009-05-23 13:26:04 +02:00
|
|
|
tabs->addTab(applications, tr("Applications"));
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
QVBoxLayout *appslayout = new QVBoxLayout();
|
|
|
|
mListWidget = new QListWidget();
|
|
|
|
appslayout->addWidget(mListWidget);
|
|
|
|
applications->setLayout(appslayout);
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
QPushButton *add = new QPushButton(tr("Add application"));
|
|
|
|
appslayout->addWidget(add);
|
|
|
|
connect(add, SIGNAL(clicked()),
|
|
|
|
this, SLOT(AddApplication()));
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
QPushButton *del = new QPushButton(tr("Delete application"));
|
|
|
|
appslayout->addWidget(del);
|
|
|
|
connect(del, SIGNAL(clicked()),
|
|
|
|
this, SLOT(DeleteApplication()));
|
|
|
|
|
|
|
|
QPushButton *modify = new QPushButton(tr("Modify application"));
|
|
|
|
appslayout->addWidget(modify);
|
|
|
|
connect(modify, SIGNAL(clicked()),
|
|
|
|
this, SLOT(ModifyApplication()));
|
|
|
|
|
2009-05-23 17:45:05 +02:00
|
|
|
QPushButton *def = new QPushButton(tr("Make default application"));
|
|
|
|
appslayout->addWidget(def);
|
|
|
|
connect(def, SIGNAL(clicked()),
|
|
|
|
this, SLOT(DefaultApplication()));
|
|
|
|
|
2009-05-23 13:26:04 +02:00
|
|
|
connect(mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
|
|
|
|
this, SLOT(ModifyApplication()));
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2009-05-23 17:45:05 +02:00
|
|
|
mListWidget->setSortingEnabled(false);
|
2009-05-23 12:37:30 +02:00
|
|
|
PopulateListWidget();
|
2009-03-22 13:32:07 +01:00
|
|
|
|
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
setLayout(dialoglayout);
|
2009-03-22 13:32:07 +01:00
|
|
|
setWindowTitle(tr("Settings"));
|
|
|
|
LoadSettings();
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
{
|
2009-03-22 13:32:07 +01:00
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::CheckState SettingsDialog::BoolToCheckState(bool yes)
|
|
|
|
{
|
|
|
|
if (yes)
|
|
|
|
{
|
|
|
|
return Qt::Checked;
|
|
|
|
}
|
|
|
|
return Qt::Unchecked;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsDialog::CheckStateToBool(Qt::CheckState state)
|
|
|
|
{
|
|
|
|
if (state == Qt::Checked)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QCheckBox* SettingsDialog::AddCheckbox(QVBoxLayout *layout,
|
|
|
|
const QString &label,
|
|
|
|
const QString &settings,
|
|
|
|
bool value)
|
|
|
|
{
|
|
|
|
QCheckBox *result = new QCheckBox(label);
|
|
|
|
result->setCheckState(BoolToCheckState(mSettings.value(settings, value).toBool()));
|
|
|
|
layout->addWidget(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::LoadSettings()
|
|
|
|
{
|
|
|
|
resize(mSettings.value(tr("Check dialog width"), 800).toInt(), mSettings.value(tr("Check dialog height"), 600).toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::SaveSettings()
|
|
|
|
{
|
|
|
|
mSettings.setValue(tr("Check dialog width"), size().width());
|
|
|
|
mSettings.setValue(tr("Check dialog height"), size().height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::SaveCheckboxValues()
|
|
|
|
{
|
|
|
|
mSettings.setValue(tr("Check threads"), mJobs->text().toInt());
|
|
|
|
SaveCheckboxValue(mForce, tr("Check force"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
|
|
|
|
{
|
|
|
|
mSettings.setValue(name, CheckStateToBool(box->checkState()));
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2009-05-23 12:37:30 +02:00
|
|
|
|
|
|
|
void SettingsDialog::AddApplication()
|
|
|
|
{
|
2009-05-23 13:26:04 +02:00
|
|
|
ApplicationDialog dialog("", "", tr("Add a new application"));
|
2009-05-23 12:37:30 +02:00
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
2009-05-23 13:26:04 +02:00
|
|
|
mApplications.AddApplicationType(dialog.GetName(), dialog.GetPath());
|
2009-05-23 12:37:30 +02:00
|
|
|
mListWidget->addItem(dialog.GetName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::DeleteApplication()
|
|
|
|
{
|
|
|
|
|
|
|
|
QList<QListWidgetItem *> selected = mListWidget->selectedItems();
|
|
|
|
QListWidgetItem *item = 0;
|
|
|
|
|
2009-05-23 13:26:04 +02:00
|
|
|
foreach(item, selected)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2009-05-23 13:26:04 +02:00
|
|
|
qDebug() << item;
|
2009-05-23 12:37:30 +02:00
|
|
|
mApplications.RemoveApplication(mListWidget->row(item));
|
|
|
|
mListWidget->clear();
|
|
|
|
PopulateListWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::ModifyApplication()
|
|
|
|
{
|
|
|
|
QList<QListWidgetItem *> selected = mListWidget->selectedItems();
|
|
|
|
QListWidgetItem *item = 0;
|
2009-05-23 13:26:04 +02:00
|
|
|
foreach(item, selected)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
|
|
|
int row = mListWidget->row(item);
|
|
|
|
|
|
|
|
ApplicationDialog dialog(mApplications.GetApplicationName(row),
|
|
|
|
mApplications.GetApplicationPath(row),
|
|
|
|
tr("Modify an application"));
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
2009-05-23 13:26:04 +02:00
|
|
|
mApplications.SetApplicationType(row, dialog.GetName(), dialog.GetPath());
|
2009-05-23 12:37:30 +02:00
|
|
|
item->setText(dialog.GetName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-23 17:45:05 +02:00
|
|
|
void SettingsDialog::DefaultApplication()
|
|
|
|
{
|
|
|
|
QList<QListWidgetItem *> selected = mListWidget->selectedItems();
|
|
|
|
if (selected.size() > 0)
|
|
|
|
{
|
|
|
|
int index = mListWidget->row(selected[0]);
|
|
|
|
mApplications.MoveFirst(index);
|
|
|
|
mListWidget->clear();
|
|
|
|
PopulateListWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
void SettingsDialog::PopulateListWidget()
|
|
|
|
{
|
2009-05-23 13:26:04 +02:00
|
|
|
for (int i = 0;i < mApplications.GetApplicationCount();i++)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
|
|
|
mListWidget->addItem(mApplications.GetApplicationName(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|