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 "agentconfigurationbase.h"
9 #include "agentconfigurationwidget.h"
10 #include "agentconfigurationwidget_p.h"
11 #include "core/agentmanager.h"
12 
13 #include <QAction>
14 #include <QDebug>
15 #include <QDialogButtonBox>
16 #include <QPushButton>
17 #include <QVBoxLayout>
18 
19 #include <KAboutData>
20 #include <KHelpMenu>
21 #include <KLocalizedString>
22 
23 namespace Akonadi
24 {
25 class AgentConfigurationDialogPrivate
26 {
27 public:
28  explicit AgentConfigurationDialogPrivate(AgentConfigurationDialog *qq)
29  : q(qq)
30  {
31  }
32  void restoreDialogSize();
33  AgentConfigurationDialog *const q;
34  QPushButton *okButton = nullptr;
36 };
37 
38 void AgentConfigurationDialogPrivate::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 AgentConfigurationDialogPrivate(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, d->widget.data(), &AgentConfigurationWidget::save);
70  }
71  if ((d->okButton = btnBox->button(QDialogButtonBox::Ok))) {
72  connect(d->widget.data(), &AgentConfigurationWidget::enableOkButton, d->okButton, &QPushButton::setEnabled);
73  }
74 
75  if (auto plugin = d->widget->d->plugin) {
76  if (auto aboutData = plugin->aboutData()) {
77  auto helpMenu = new KHelpMenu(this, *aboutData, true);
78  helpMenu->action(KHelpMenu::menuDonate);
79  // Initialize menu
80  QMenu *menu = helpMenu->menu();
81  // HACK: the actions are populated from QGuiApplication so they would refer to the
82  // current application not to the agent, so we have to adjust the strings in some
83  // of the actions.
84  helpMenu->action(KHelpMenu::menuAboutApp)->setIcon(QIcon::fromTheme(aboutData->programIconName()));
85  helpMenu->action(KHelpMenu::menuHelpContents)->setText(i18n("%1 Handbook", aboutData->displayName()));
86  helpMenu->action(KHelpMenu::menuAboutApp)->setText(i18n("About %1", aboutData->displayName()));
87  btnBox->addButton(QDialogButtonBox::Help)->setMenu(menu);
88  }
89  }
90  d->restoreDialogSize();
91 }
92 
93 AgentConfigurationDialog::~AgentConfigurationDialog()
94 {
95  if (d->widget) {
96  d->widget->saveDialogSize(size());
97  }
98 }
99 
100 void AgentConfigurationDialog::accept()
101 {
102  if (d->widget) {
103  d->widget->save();
104  }
105 
106  QDialog::accept();
107 }
bool isValid() const const
AgentType type() const
Returns the agent type of this instance.
void clicked(bool checked)
QIcon fromTheme(const QString &name)
KAboutData * aboutData() const
Returns about data for the currently configured component.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString displayName() const
QString i18n(const char *text, const TYPE &arg...)
virtual void accept()
void setEnabled(bool)
QString name() const
Returns the user visible name of the agent instance.
A widget for displaying agent configuration in applications.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QIcon icon() const
Returns the icon of the agent type.
A representation of an agent instance.
QString programIconName() const
Helper integration between Akonadi and Qt.
void setIcon(const QIcon &icon)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.