2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2009-05-30 07:48:12 +02:00
|
|
|
* Copyright (C) 2007-2009 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 "settingsdialog.h"
|
2009-06-06 11:51:14 +02:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QWidget>
|
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-07-02 10:32:29 +02:00
|
|
|
#include "common.h"
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
SettingsDialog::SettingsDialog(QSettings *programSettings,
|
|
|
|
ApplicationList *list,
|
2009-06-06 11:51:14 +02:00
|
|
|
QWidget *parent) :
|
2010-04-02 07:30:58 +02:00
|
|
|
QDialog(parent),
|
|
|
|
mSettings(programSettings),
|
|
|
|
mApplications(list),
|
|
|
|
mTempApplications(new ApplicationList(this))
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.setupUi(this);
|
2009-07-02 10:32:29 +02:00
|
|
|
mTempApplications->Copy(list);
|
2009-07-02 18:14:12 +02:00
|
|
|
|
|
|
|
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(Ok()));
|
|
|
|
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
|
|
|
|
mUI.mJobs->setText(programSettings->value(SETTINGS_CHECK_THREADS, 1).toString());
|
|
|
|
mUI.mForce->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_CHECK_FORCE, false).toBool()));
|
|
|
|
mUI.mShowFullPath->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_FULL_PATH, false).toBool()));
|
|
|
|
mUI.mShowNoErrorsMessage->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_NO_ERRORS, false).toBool()));
|
|
|
|
|
|
|
|
|
|
|
|
connect(mUI.mButtonAdd, SIGNAL(clicked()),
|
2009-05-23 12:37:30 +02:00
|
|
|
this, SLOT(AddApplication()));
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-07-02 18:14:12 +02:00
|
|
|
connect(mUI.mButtonDelete, SIGNAL(clicked()),
|
2009-05-23 12:37:30 +02:00
|
|
|
this, SLOT(DeleteApplication()));
|
|
|
|
|
2009-07-02 18:14:12 +02:00
|
|
|
connect(mUI.mButtonModify, SIGNAL(clicked()),
|
2009-05-23 12:37:30 +02:00
|
|
|
this, SLOT(ModifyApplication()));
|
|
|
|
|
2009-07-02 18:14:12 +02:00
|
|
|
connect(mUI.mButtonDefault, SIGNAL(clicked()),
|
2009-05-23 17:45:05 +02:00
|
|
|
this, SLOT(DefaultApplication()));
|
|
|
|
|
2009-07-02 18:14:12 +02:00
|
|
|
connect(mUI.mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
|
2009-05-23 13:26:04 +02:00
|
|
|
this, SLOT(ModifyApplication()));
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.mListWidget->setSortingEnabled(false);
|
2009-05-23 12:37:30 +02:00
|
|
|
PopulateListWidget();
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.mSaveAllErrors->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_ALL_ERRORS, false).toBool()));
|
|
|
|
mUI.mSaveFullPath->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_FULL_PATH, false).toBool()));
|
|
|
|
|
2009-03-22 13:32:07 +01:00
|
|
|
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)
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (yes)
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
|
|
|
return Qt::Checked;
|
|
|
|
}
|
|
|
|
return Qt::Unchecked;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsDialog::CheckStateToBool(Qt::CheckState state)
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (state == Qt::Checked)
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::LoadSettings()
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
resize(mSettings->value(SETTINGS_CHECK_DIALOG_WIDTH, 800).toInt(),
|
|
|
|
mSettings->value(SETTINGS_CHECK_DIALOG_HEIGHT, 600).toInt());
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::SaveSettings()
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->setValue(SETTINGS_CHECK_DIALOG_WIDTH, size().width());
|
|
|
|
mSettings->setValue(SETTINGS_CHECK_DIALOG_HEIGHT, size().height());
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::SaveCheckboxValues()
|
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
int jobs = mUI.mJobs->text().toInt();
|
2010-04-02 07:30:58 +02:00
|
|
|
if (jobs <= 0)
|
2009-05-24 10:55:54 +02:00
|
|
|
{
|
2009-05-24 10:53:29 +02:00
|
|
|
jobs = 1;
|
|
|
|
}
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mSettings->setValue(SETTINGS_CHECK_THREADS, jobs);
|
2009-07-02 18:14:12 +02:00
|
|
|
SaveCheckboxValue(mUI.mForce, SETTINGS_CHECK_FORCE);
|
|
|
|
SaveCheckboxValue(mUI.mSaveAllErrors, SETTINGS_SAVE_ALL_ERRORS);
|
|
|
|
SaveCheckboxValue(mUI.mSaveFullPath, SETTINGS_SAVE_FULL_PATH);
|
|
|
|
SaveCheckboxValue(mUI.mShowFullPath, SETTINGS_SHOW_FULL_PATH);
|
|
|
|
SaveCheckboxValue(mUI.mShowNoErrorsMessage, SETTINGS_SHOW_NO_ERRORS);
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
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-06-06 11:57:16 +02:00
|
|
|
ApplicationDialog dialog("", "", tr("Add a new application"), this);
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mTempApplications->AddApplicationType(dialog.GetName(), dialog.GetPath());
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.mListWidget->addItem(dialog.GetName());
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::DeleteApplication()
|
|
|
|
{
|
|
|
|
|
2009-07-02 18:14:12 +02:00
|
|
|
QList<QListWidgetItem *> selected = mUI.mListWidget->selectedItems();
|
2009-05-23 12:37:30 +02:00
|
|
|
QListWidgetItem *item = 0;
|
|
|
|
|
2009-05-23 13:26:04 +02:00
|
|
|
foreach(item, selected)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
mTempApplications->RemoveApplication(mUI.mListWidget->row(item));
|
|
|
|
mUI.mListWidget->clear();
|
2009-05-23 12:37:30 +02:00
|
|
|
PopulateListWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::ModifyApplication()
|
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
QList<QListWidgetItem *> selected = mUI.mListWidget->selectedItems();
|
2009-05-23 12:37:30 +02:00
|
|
|
QListWidgetItem *item = 0;
|
2009-05-23 13:26:04 +02:00
|
|
|
foreach(item, selected)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
int row = mUI.mListWidget->row(item);
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
ApplicationDialog dialog(mTempApplications->GetApplicationName(row),
|
|
|
|
mTempApplications->GetApplicationPath(row),
|
2009-05-23 12:37:30 +02:00
|
|
|
tr("Modify an application"));
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mTempApplications->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()
|
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
QList<QListWidgetItem *> selected = mUI.mListWidget->selectedItems();
|
2010-04-02 07:30:58 +02:00
|
|
|
if (selected.size() > 0)
|
2009-05-23 17:45:05 +02:00
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
int index = mUI.mListWidget->row(selected[0]);
|
2009-07-02 10:32:29 +02:00
|
|
|
mTempApplications->MoveFirst(index);
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.mListWidget->clear();
|
2009-05-23 17:45:05 +02:00
|
|
|
PopulateListWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
void SettingsDialog::PopulateListWidget()
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
for (int i = 0; i < mTempApplications->GetApplicationCount(); i++)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.mListWidget->addItem(mTempApplications->GetApplicationName(i));
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
2009-06-08 15:58:26 +02:00
|
|
|
|
|
|
|
// If list contains items select first item
|
2010-04-02 07:30:58 +02:00
|
|
|
if (mTempApplications->GetApplicationCount())
|
2009-06-08 15:58:26 +02:00
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.mListWidget->setCurrentRow(0);
|
2009-06-08 15:58:26 +02:00
|
|
|
}
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
2009-05-24 11:08:51 +02:00
|
|
|
void SettingsDialog::Ok()
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mApplications->Copy(mTempApplications);
|
2009-05-24 11:08:51 +02:00
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
2009-06-03 20:18:22 +02:00
|
|
|
bool SettingsDialog::ShowFullPath()
|
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
return CheckStateToBool(mUI.mShowFullPath->checkState());
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsDialog::SaveFullPath()
|
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
return CheckStateToBool(mUI.mSaveFullPath->checkState());
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsDialog::SaveAllErrors()
|
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
return CheckStateToBool(mUI.mSaveAllErrors->checkState());
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
2009-06-09 09:51:27 +02:00
|
|
|
|
|
|
|
bool SettingsDialog::ShowNoErrorsMessage()
|
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
return CheckStateToBool(mUI.mShowNoErrorsMessage->checkState());
|
2009-06-09 09:51:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|