Akonadi

agentconfigurationdialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2018 Daniel Vrátil <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "agentconfigurationdialog.h"
8 #include "agentconfigurationwidget.h"
9 #include "agentconfigurationwidget_p.h"
10 #include "agentconfigurationbase.h"
11 #include "core/agentmanager.h"
12 
13 #include <QVBoxLayout>
14 #include <QDialogButtonBox>
15 #include <QPushButton>
16 #include <QAction>
17 #include <QDebug>
18 
19 #include <KLocalizedString>
20 #include <KHelpMenu>
21 #include <KAboutData>
22 
23 namespace Akonadi {
24 class Q_DECL_HIDDEN AgentConfigurationDialog::Private
25 {
26 public:
27  explicit Private(AgentConfigurationDialog *qq)
28  : q(qq)
29  {
30 
31  }
32  void restoreDialogSize();
33  AgentConfigurationDialog *const q;
34  QPushButton *okButton = nullptr;
36 };
37 
38 void AgentConfigurationDialog::Private::restoreDialogSize()
39 {
40  if (widget) {
41  const QSize size = widget->restoreDialogSize();
42  if (size.isValid()) {
43  q->resize(size);
44  }
45  }
46 }
47 
48 } // namespace Akonadi
49 
50 using namespace Akonadi;
51 
52 AgentConfigurationDialog::AgentConfigurationDialog(const AgentInstance &instance, QWidget *parent)
53  : QDialog(parent)
54  , d(new Private(this))
55 {
56  setWindowTitle(i18nc("%1 = agent name", "%1 Configuration", instance.name()));
57  setWindowIcon(instance.type().icon());
58 
59  auto *l = new QVBoxLayout(this);
60 
61  d->widget.reset(new AgentConfigurationWidget(instance, this));
62  l->addWidget(d->widget.data());
63 
64  auto *btnBox = new QDialogButtonBox(d->widget->standardButtons(), this);
65  l->addWidget(btnBox);
66  connect(btnBox, &QDialogButtonBox::accepted, this, &AgentConfigurationDialog::accept);
67  connect(btnBox, &QDialogButtonBox::rejected, this, &AgentConfigurationDialog::reject);
68  if (QPushButton *applyButton = btnBox->button(QDialogButtonBox::Apply)) {
69  connect(applyButton, &QPushButton::clicked,
70  d->widget.data(), &AgentConfigurationWidget::save);
71  }
72  if ((d->okButton = btnBox->button(QDialogButtonBox::Ok))) {
73  connect(d->widget.data(), &AgentConfigurationWidget::enableOkButton,
74  d->okButton, &QPushButton::setEnabled);
75  }
76 
77  if (auto plugin = d->widget->d->plugin) {
78  if (auto *aboutData = plugin->aboutData()) {
79  auto *helpMenu = new KHelpMenu(this, *aboutData, true);
80  helpMenu->action(KHelpMenu::menuDonate);
81  //Initialize menu
82  QMenu *menu = helpMenu->menu();
83  // HACK: the actions are populated from QGuiApplication so they would refer to the
84  // current application not to the agent, so we have to adjust the strings in some
85  // of the actions.
86  helpMenu->action(KHelpMenu::menuAboutApp)->setIcon(QIcon::fromTheme(aboutData->programIconName()));
87  helpMenu->action(KHelpMenu::menuHelpContents)->setText(i18n("%1 Handbook", aboutData->displayName()));
88  helpMenu->action(KHelpMenu::menuAboutApp)->setText(i18n("About %1", aboutData->displayName()));
89  btnBox->addButton(QDialogButtonBox::Help)->setMenu(menu);
90  }
91  }
92  d->restoreDialogSize();
93 }
94 
95 AgentConfigurationDialog::~AgentConfigurationDialog()
96 {
97  if (d->widget) {
98  d->widget->saveDialogSize(size());
99  }
100 }
101 
102 void AgentConfigurationDialog::accept()
103 {
104  if (d->widget) {
105  d->widget->save();
106  }
107 
108  QDialog::accept();
109 }
bool isValid() const const
QIcon icon() const
Returns the icon of the agent type.
AgentType type() const
Returns the agent type of this instance.
void reset(T *other)
void setEnabled(bool)
void setIcon(const QIcon &icon)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void clicked(bool checked)
virtual void accept()
T * data() const const
QString i18n(const char *text, const TYPE &arg...)
QString displayName() const
KAboutData * aboutData() const
Returns about data for the currently configured component.
QString name() const
Returns the user visible name of the agent instance.
A widget for displaying agent configuration in applications.
Helper integration between Akonadi and Qt.
QIcon fromTheme(const QString &name)
A representation of an agent instance.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString programIconName() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Nov 21 2020 23:17:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.