diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index c899cd70d..cc87a5745 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -32,7 +32,6 @@ #include "gui/FileDialog.h" #include "gui/entry/EntryView.h" #include "gui/group/GroupView.h" -#include "http/Service.h" DatabaseManagerStruct::DatabaseManagerStruct() : dbWidget(Q_NULLPTR) @@ -54,8 +53,6 @@ DatabaseTabWidget::DatabaseTabWidget(QWidget* parent) connect(this, SIGNAL(tabCloseRequested(int)), SLOT(closeDatabase(int))); connect(autoType(), SIGNAL(globalShortcutTriggered()), SLOT(performGlobalAutoType())); - - (new Service(this))->start(); } DatabaseTabWidget::~DatabaseTabWidget() diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 1eff09656..2ecad9b92 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "autotype/AutoType.h" #include "core/Config.h" @@ -32,6 +33,40 @@ #include "gui/entry/EntryView.h" #include "gui/group/GroupView.h" +#include "http/Service.h" +#include "http/HttpSettings.h" +#include "http/OptionDialog.h" +#include "gui/SettingsWidget.h" + +class HttpPlugin: public ISettingsPage { +public: + HttpPlugin(DatabaseTabWidget * tabWidget): m_service(new Service(tabWidget)) { + } + virtual ~HttpPlugin() { + } + virtual QString name() { + return QObject::tr("Http"); + } + virtual QWidget * createWidget() { + OptionDialog * dlg = new OptionDialog(); + QObject::connect(dlg, SIGNAL(removeSharedEncryptionKeys()), m_service.data(), SLOT(removeSharedEncryptionKeys())); + QObject::connect(dlg, SIGNAL(removeStoredPermissions()), m_service.data(), SLOT(removeStoredPermissions())); + return dlg; + } + virtual void loadSettings(QWidget * widget) { + qobject_cast(widget)->loadSettings(); + } + virtual void saveSettings(QWidget * widget) { + qobject_cast(widget)->saveSettings(); + if (HttpSettings::isEnabled()) + m_service->start(); + else + m_service->stop(); + } +private: + QScopedPointer m_service; +}; + const QString MainWindow::BaseWindowTitle = "KeePassX"; MainWindow::MainWindow() @@ -39,6 +74,8 @@ MainWindow::MainWindow() { m_ui->setupUi(this); + m_ui->settingsWidget->addSettingsPage(new HttpPlugin(m_ui->tabWidget)); + setWindowIcon(filePath()->applicationIcon()); QAction* toggleViewAction = m_ui->toolBar->toggleViewAction(); toggleViewAction->setText(tr("Show toolbar")); diff --git a/src/gui/SettingsWidget.cpp b/src/gui/SettingsWidget.cpp index 197cd7472..9a86eac99 100644 --- a/src/gui/SettingsWidget.cpp +++ b/src/gui/SettingsWidget.cpp @@ -22,6 +22,27 @@ #include "autotype/AutoType.h" #include "core/Config.h" +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 settingsPage; + QWidget* widget; +}; + SettingsWidget::SettingsWidget(QWidget* parent) : EditWidget(parent) , m_secWidget(new QWidget()) @@ -50,6 +71,14 @@ SettingsWidget::~SettingsWidget() { } +void SettingsWidget::addSettingsPage(ISettingsPage *page) +{ + QWidget * widget = page->createWidget(); + widget->setParent(this); + m_extraPages.append(ExtraPage(page, widget)); + add(page->name(), widget); +} + void SettingsWidget::loadSettings() { m_generalUi->rememberLastDatabasesCheckBox->setChecked(config()->get("RememberLastDatabases").toBool()); @@ -66,6 +95,9 @@ void SettingsWidget::loadSettings() m_secUi->clearClipboardCheckBox->setChecked(config()->get("security/clearclipboard").toBool()); m_secUi->clearClipboardSpinBox->setValue(config()->get("security/clearclipboardtimeout").toInt()); + Q_FOREACH (const ExtraPage& page, m_extraPages) + page.loadSettings(); + setCurrentRow(0); } @@ -80,6 +112,9 @@ void SettingsWidget::saveSettings() config()->set("security/clearclipboard", m_secUi->clearClipboardCheckBox->isChecked()); config()->set("security/clearclipboardtimeout", m_secUi->clearClipboardSpinBox->value()); + Q_FOREACH (const ExtraPage& page, m_extraPages) + page.saveSettings(); + Q_EMIT editFinished(true); } diff --git a/src/gui/SettingsWidget.h b/src/gui/SettingsWidget.h index cefbf6d49..a53fd30b7 100644 --- a/src/gui/SettingsWidget.h +++ b/src/gui/SettingsWidget.h @@ -25,6 +25,15 @@ namespace Ui { class SettingsWidgetSecurity; } +class ISettingsPage { +public: + virtual ~ISettingsPage() {} + virtual QString name() = 0; + virtual QWidget * createWidget() = 0; + virtual void loadSettings(QWidget * widget) = 0; + virtual void saveSettings(QWidget * widget) = 0; +}; + class SettingsWidget : public EditWidget { Q_OBJECT @@ -32,6 +41,7 @@ class SettingsWidget : public EditWidget public: explicit SettingsWidget(QWidget* parent = Q_NULLPTR); ~SettingsWidget(); + void addSettingsPage(ISettingsPage * page); void loadSettings(); Q_SIGNALS: @@ -49,6 +59,8 @@ private: const QScopedPointer m_generalUi; Qt::Key m_globalAutoTypeKey; Qt::KeyboardModifiers m_globalAutoTypeModifiers; + class ExtraPage; + QList m_extraPages; }; #endif // KEEPASSX_SETTINGSWIDGET_H