Akonadi

agentconfigurationdialog.cpp
1 /*
2  Copyright (c) 2018 Daniel Vrátil <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "agentconfigurationdialog.h"
21 #include "agentconfigurationwidget.h"
22 #include "agentconfigurationwidget_p.h"
23 #include "agentconfigurationbase.h"
24 #include "core/agentmanager.h"
25 
26 #include <QVBoxLayout>
27 #include <QDialogButtonBox>
28 #include <QPushButton>
29 #include <QAction>
30 #include <QDebug>
31 
32 #include <KLocalizedString>
33 #include <KHelpMenu>
34 #include <KAboutData>
35 
36 namespace Akonadi {
37 class Q_DECL_HIDDEN AgentConfigurationDialog::Private
38 {
39 public:
40  Private(AgentConfigurationDialog *qq)
41  : q(qq)
42  {
43 
44  }
45  void restoreDialogSize();
46  AgentConfigurationDialog *q;
47  QPushButton *okButton = nullptr;
49 };
50 
51 void AgentConfigurationDialog::Private::restoreDialogSize()
52 {
53  if (widget) {
54  const QSize size = widget->restoreDialogSize();
55  if (size.isValid()) {
56  q->resize(size);
57  }
58  }
59 }
60 
61 }
62 
63 using namespace Akonadi;
64 
65 AgentConfigurationDialog::AgentConfigurationDialog(const AgentInstance &instance, QWidget *parent)
66  : QDialog(parent)
67  , d(new Private(this))
68 {
69  setWindowTitle(i18nc("%1 = agent name", "%1 Configuration", instance.name()));
70  setWindowIcon(instance.type().icon());
71 
72  auto l = new QVBoxLayout(this);
73 
74  d->widget.reset(new AgentConfigurationWidget(instance, this));
75  l->addWidget(d->widget.data());
76 
77  auto btnBox = new QDialogButtonBox(d->widget->standardButtons(), this);
78  l->addWidget(btnBox);
79  connect(btnBox, &QDialogButtonBox::accepted, this, &AgentConfigurationDialog::accept);
80  connect(btnBox, &QDialogButtonBox::rejected, this, &AgentConfigurationDialog::reject);
81  if (QPushButton *applyButton = btnBox->button(QDialogButtonBox::Apply)) {
82  connect(applyButton, &QPushButton::clicked,
83  d->widget.data(), &AgentConfigurationWidget::save);
84  }
85  if ((d->okButton = btnBox->button(QDialogButtonBox::Ok))) {
86  connect(d->widget.data(), &AgentConfigurationWidget::enableOkButton,
87  d->okButton, &QPushButton::setEnabled);
88  }
89 
90  if (auto plugin = d->widget->d->plugin) {
91  if (auto aboutData = plugin->aboutData()) {
92  KHelpMenu *helpMenu = new KHelpMenu(this, *aboutData, true);
93  helpMenu->action(KHelpMenu::menuDonate);
94  //Initialize menu
95  QMenu *menu = helpMenu->menu();
96  // HACK: the actions are populated from QGuiApplication so they would refer to the
97  // current application not to the agent, so we have to adjust the strings in some
98  // of the actions.
99  helpMenu->action(KHelpMenu::menuAboutApp)->setIcon(QIcon::fromTheme(aboutData->programIconName()));
100  helpMenu->action(KHelpMenu::menuHelpContents)->setText(i18n("%1 Handbook", aboutData->displayName()));
101  helpMenu->action(KHelpMenu::menuAboutApp)->setText(i18n("About %1", aboutData->displayName()));
102  btnBox->addButton(QDialogButtonBox::Help)->setMenu(menu);
103  }
104  }
105  d->restoreDialogSize();
106 }
107 
108 AgentConfigurationDialog::~AgentConfigurationDialog()
109 {
110  if (d->widget) {
111  d->widget->saveDialogSize(size());
112  }
113 }
114 
115 void AgentConfigurationDialog::accept()
116 {
117  if (d->widget) {
118  d->widget->save();
119  }
120 
121  QDialog::accept();
122 }
void setText(const QString &text)
bool isValid() const const
QMenu * menu()
QIcon icon() const
Returns the icon of the agent type.
AgentType type() const
Returns the agent type of this instance.
void setIcon(const QIcon &icon)
void reset(T *other)
void setEnabled(bool)
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.
QAction * action(MenuId id) const
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 Mon May 25 2020 22:46:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.