diff --git a/src/widgets/agentconfigurationdialog.cpp b/src/widgets/agentconfigurationdialog.cpp index c79eff0c9..2a943397e 100644 --- a/src/widgets/agentconfigurationdialog.cpp +++ b/src/widgets/agentconfigurationdialog.cpp @@ -1,118 +1,122 @@ /* Copyright (c) 2018 Daniel Vrátil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "agentconfigurationdialog.h" #include "agentconfigurationwidget.h" #include "agentconfigurationwidget_p.h" #include "agentconfigurationbase.h" #include "core/agentmanager.h" #include #include #include #include #include #include #include #include namespace Akonadi { class Q_DECL_HIDDEN AgentConfigurationDialog::Private { public: Private(AgentConfigurationDialog *qq) : q(qq) { } void restoreDialogSize(); AgentConfigurationDialog *q; + QPushButton *okButton = nullptr; QScopedPointer widget; }; void AgentConfigurationDialog::Private::restoreDialogSize() { if (widget) { const QSize size = widget->restoreDialogSize(); if (size.isValid()) { q->resize(size); } } } } using namespace Akonadi; AgentConfigurationDialog::AgentConfigurationDialog(const AgentInstance &instance, QWidget *parent) : QDialog(parent) , d(new Private(this)) { setWindowTitle(i18nc("%1 = agent name", "%1 Configuration", instance.name())); setWindowIcon(instance.type().icon()); auto l = new QVBoxLayout(this); d->widget.reset(new AgentConfigurationWidget(instance, this)); l->addWidget(d->widget.data()); auto btnBox = new QDialogButtonBox(d->widget->standardButtons(), this); l->addWidget(btnBox); connect(btnBox, &QDialogButtonBox::accepted, this, &AgentConfigurationDialog::accept); connect(btnBox, &QDialogButtonBox::rejected, this, &AgentConfigurationDialog::reject); if (QPushButton *applyButton = btnBox->button(QDialogButtonBox::Apply)) { connect(applyButton, &QPushButton::clicked, d->widget.data(), &AgentConfigurationWidget::save); } - + if ((d->okButton = btnBox->button(QDialogButtonBox::Ok))) { + connect(d->widget.data(), &AgentConfigurationWidget::enableOkButton, + d->okButton, &QPushButton::setEnabled); + } if (auto plugin = d->widget->d->plugin) { if (auto aboutData = plugin->aboutData()) { KHelpMenu *helpMenu = new KHelpMenu(this, *aboutData, true); helpMenu->action(KHelpMenu::menuDonate); //Initialize menu QMenu *menu = helpMenu->menu(); // HACK: the actions are populated from QGuiApplication so they would refer to the // current application not to the agent, so we have to adjust the strings in some // of the actions. helpMenu->action(KHelpMenu::menuAboutApp)->setIcon(QIcon::fromTheme(aboutData->programIconName())); helpMenu->action(KHelpMenu::menuHelpContents)->setText(i18n("%1 Handbook", aboutData->displayName())); helpMenu->action(KHelpMenu::menuAboutApp)->setText(i18n("About %1", aboutData->displayName())); btnBox->addButton(QDialogButtonBox::Help)->setMenu(menu); } } d->restoreDialogSize(); } AgentConfigurationDialog::~AgentConfigurationDialog() { if (d->widget) { d->widget->saveDialogSize(size()); } } void AgentConfigurationDialog::accept() { if (d->widget) { d->widget->save(); } QDialog::accept(); } diff --git a/src/widgets/agentconfigurationwidget.h b/src/widgets/agentconfigurationwidget.h index 27bdb68d2..1b00bd3fe 100644 --- a/src/widgets/agentconfigurationwidget.h +++ b/src/widgets/agentconfigurationwidget.h @@ -1,62 +1,65 @@ /* Copyright (c) 2018 Daniel Vrátil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_AGENTCONFIGURATIOWIDGET_H #define AKONADI_AGENTCONFIGURATIOWIDGET_H #include #include #include "akonadiwidgets_export.h" namespace Akonadi { class AgentInstance; class AgentConfigurationDialog; /** * @brief A widget for displaying agent configuration in applications. * * To implement an agent configuration widget, see AgentConfigurationBase. */ class AKONADIWIDGETS_EXPORT AgentConfigurationWidget : public QWidget { Q_OBJECT public: explicit AgentConfigurationWidget(const Akonadi::AgentInstance &instance, QWidget *parent = nullptr); ~AgentConfigurationWidget() override; void load(); void save(); QSize restoreDialogSize() const; void saveDialogSize(const QSize &size); QDialogButtonBox::StandardButtons standardButtons() const; +Q_SIGNALS: + void enableOkButton(bool enabled); + protected: void childEvent(QChildEvent *event) override; private: class Private; friend class Private; friend class AgentConfigurationDialog; QScopedPointer d; }; } #endif