2012-05-27 05:09:52 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* 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 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* 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 "SettingsWidget.h"
|
2012-05-27 18:09:54 -04:00
|
|
|
#include "ui_SettingsWidgetGeneral.h"
|
2012-05-27 05:09:52 -04:00
|
|
|
#include "ui_SettingsWidgetSecurity.h"
|
|
|
|
|
2012-07-14 13:09:28 -04:00
|
|
|
#include "autotype/AutoType.h"
|
2012-05-27 14:10:41 -04:00
|
|
|
#include "core/Config.h"
|
|
|
|
|
2013-04-17 17:18:21 -04:00
|
|
|
class SettingsWidget::ExtraPage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ExtraPage(ISettingsPage* page, QWidget* widget): settingsPage(page), widget(widget)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void loadSettings() const
|
|
|
|
{
|
|
|
|
settingsPage->loadSettings(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveSettings() const
|
|
|
|
{
|
|
|
|
settingsPage->saveSettings(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QSharedPointer<ISettingsPage> settingsPage;
|
|
|
|
QWidget* widget;
|
|
|
|
};
|
|
|
|
|
2012-05-27 05:09:52 -04:00
|
|
|
SettingsWidget::SettingsWidget(QWidget* parent)
|
|
|
|
: EditWidget(parent)
|
|
|
|
, m_secWidget(new QWidget())
|
2012-05-27 18:09:54 -04:00
|
|
|
, m_generalWidget(new QWidget())
|
2012-05-27 05:09:52 -04:00
|
|
|
, m_secUi(new Ui::SettingsWidgetSecurity())
|
2012-05-27 18:09:54 -04:00
|
|
|
, m_generalUi(new Ui::SettingsWidgetGeneral())
|
2012-05-27 05:09:52 -04:00
|
|
|
{
|
2012-05-27 05:12:12 -04:00
|
|
|
setHeadline(tr("Application Settings"));
|
2012-05-27 05:09:52 -04:00
|
|
|
|
|
|
|
m_secUi->setupUi(m_secWidget);
|
2012-05-27 18:09:54 -04:00
|
|
|
m_generalUi->setupUi(m_generalWidget);
|
|
|
|
add(tr("General"), m_generalWidget);
|
2012-05-27 05:09:52 -04:00
|
|
|
add(tr("Security"), m_secWidget);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(accepted()), SLOT(saveSettings()));
|
2012-05-27 14:29:15 -04:00
|
|
|
connect(this, SIGNAL(rejected()), SLOT(reject()));
|
2012-05-27 05:09:52 -04:00
|
|
|
|
2012-06-10 15:54:58 -04:00
|
|
|
connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)),
|
|
|
|
this, SLOT(enableAutoSaveOnExit(bool)));
|
|
|
|
|
2013-04-22 15:33:42 -04:00
|
|
|
connect(m_generalUi->rememberLastDatabasesCheckBox, SIGNAL(toggled(bool)),
|
|
|
|
m_generalUi->autoReopenLastDatabases, SLOT(setEnabled(bool)));
|
|
|
|
|
2012-05-27 05:09:52 -04:00
|
|
|
connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)),
|
|
|
|
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool)));
|
2013-04-22 15:33:42 -04:00
|
|
|
|
2012-05-27 05:09:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsWidget::~SettingsWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-17 17:18:21 -04:00
|
|
|
void SettingsWidget::addSettingsPage(ISettingsPage *page)
|
|
|
|
{
|
|
|
|
QWidget * widget = page->createWidget();
|
|
|
|
widget->setParent(this);
|
|
|
|
m_extraPages.append(ExtraPage(page, widget));
|
|
|
|
add(page->name(), widget);
|
|
|
|
}
|
|
|
|
|
2012-05-27 05:09:52 -04:00
|
|
|
void SettingsWidget::loadSettings()
|
|
|
|
{
|
2012-05-27 18:09:54 -04:00
|
|
|
m_generalUi->rememberLastDatabasesCheckBox->setChecked(config()->get("RememberLastDatabases").toBool());
|
2013-04-22 15:33:42 -04:00
|
|
|
m_generalUi->autoReopenLastDatabases->setChecked(config()->get("AutoReopenLastDatabases").toBool());
|
2012-05-30 05:21:42 -04:00
|
|
|
m_generalUi->modifiedExpandedChangedCheckBox->setChecked(config()->get("ModifiedOnExpandedStateChanges").toBool());
|
2012-06-10 10:28:46 -04:00
|
|
|
m_generalUi->autoSaveAfterEveryChangeCheckBox->setChecked(config()->get("AutoSaveAfterEveryChange").toBool());
|
2012-06-10 15:54:58 -04:00
|
|
|
m_generalUi->autoSaveOnExitCheckBox->setChecked(config()->get("AutoSaveOnExit").toBool());
|
2012-07-14 13:09:28 -04:00
|
|
|
|
|
|
|
m_globalAutoTypeKey = static_cast<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt());
|
|
|
|
m_globalAutoTypeModifiers = static_cast<Qt::KeyboardModifiers>(config()->get("GlobalAutoTypeModifiers").toInt());
|
|
|
|
if (m_globalAutoTypeKey > 0 && m_globalAutoTypeModifiers > 0) {
|
|
|
|
m_generalUi->autoTypeShortcutWidget->setShortcut(m_globalAutoTypeKey, m_globalAutoTypeModifiers);
|
|
|
|
}
|
|
|
|
|
2012-05-27 14:10:41 -04:00
|
|
|
m_secUi->clearClipboardCheckBox->setChecked(config()->get("security/clearclipboard").toBool());
|
|
|
|
m_secUi->clearClipboardSpinBox->setValue(config()->get("security/clearclipboardtimeout").toInt());
|
|
|
|
|
2013-04-17 17:18:21 -04:00
|
|
|
Q_FOREACH (const ExtraPage& page, m_extraPages)
|
|
|
|
page.loadSettings();
|
|
|
|
|
2012-05-27 05:09:52 -04:00
|
|
|
setCurrentRow(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::saveSettings()
|
|
|
|
{
|
2012-05-27 18:09:54 -04:00
|
|
|
config()->set("RememberLastDatabases", m_generalUi->rememberLastDatabasesCheckBox->isChecked());
|
2013-04-22 15:33:42 -04:00
|
|
|
config()->set("AutoReopenLastDatabases", m_generalUi->rememberLastDatabasesCheckBox->isChecked()
|
|
|
|
&& m_generalUi->autoReopenLastDatabases->isChecked());
|
2012-05-30 05:21:42 -04:00
|
|
|
config()->set("ModifiedOnExpandedStateChanges", m_generalUi->modifiedExpandedChangedCheckBox->isChecked());
|
2012-06-10 10:28:46 -04:00
|
|
|
config()->set("AutoSaveAfterEveryChange", m_generalUi->autoSaveAfterEveryChangeCheckBox->isChecked());
|
2012-06-10 15:54:58 -04:00
|
|
|
config()->set("AutoSaveOnExit", m_generalUi->autoSaveOnExitCheckBox->isChecked());
|
2012-07-14 13:09:28 -04:00
|
|
|
config()->set("GlobalAutoTypeKey", m_generalUi->autoTypeShortcutWidget->key());
|
|
|
|
config()->set("GlobalAutoTypeModifiers", static_cast<int>(m_generalUi->autoTypeShortcutWidget->modifiers()));
|
2012-05-27 14:10:41 -04:00
|
|
|
config()->set("security/clearclipboard", m_secUi->clearClipboardCheckBox->isChecked());
|
|
|
|
config()->set("security/clearclipboardtimeout", m_secUi->clearClipboardSpinBox->value());
|
2012-05-27 14:29:15 -04:00
|
|
|
|
2013-04-17 17:18:21 -04:00
|
|
|
Q_FOREACH (const ExtraPage& page, m_extraPages)
|
|
|
|
page.saveSettings();
|
|
|
|
|
2012-05-27 14:29:15 -04:00
|
|
|
Q_EMIT editFinished(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::reject()
|
|
|
|
{
|
2012-07-14 13:09:28 -04:00
|
|
|
// register the old key again as it might have changed
|
|
|
|
if (m_globalAutoTypeKey > 0 && m_globalAutoTypeModifiers > 0) {
|
|
|
|
autoType()->registerGlobalShortcut(m_globalAutoTypeKey, m_globalAutoTypeModifiers);
|
|
|
|
}
|
|
|
|
|
2012-05-27 14:29:15 -04:00
|
|
|
Q_EMIT editFinished(false);
|
2012-05-27 05:09:52 -04:00
|
|
|
}
|
2012-06-10 15:54:58 -04:00
|
|
|
|
|
|
|
void SettingsWidget::enableAutoSaveOnExit(bool checked)
|
|
|
|
{
|
2012-06-12 04:11:13 -04:00
|
|
|
m_generalUi->autoSaveOnExitCheckBox->setEnabled(!checked);
|
2012-06-10 15:54:58 -04:00
|
|
|
}
|