Akonadi

agentconfigurationdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
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
23namespace Akonadi
24{
25class AgentConfigurationDialogPrivate
26{
27public:
28 explicit AgentConfigurationDialogPrivate(AgentConfigurationDialog *qq)
29 : q(qq)
30 {
31 }
32 void restoreDialogSize();
33 AgentConfigurationDialog *const q;
34 QPushButton *okButton = nullptr;
36};
37
38void 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
50using namespace Akonadi;
51
52AgentConfigurationDialog::AgentConfigurationDialog(const AgentInstance &instance, QWidget *parent)
53 : QDialog(parent)
54 , d(new AgentConfigurationDialogPrivate(this))
55{
56 setWindowTitle(i18nc("@title:window, %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#if KXMLGUI_VERSION >= QT_VERSION_CHECK(6, 9, 0)
78 auto helpMenu = new KHelpMenu(this, *aboutData);
79 helpMenu->setShowWhatsThis(true);
80#else
81 auto helpMenu = new KHelpMenu(this, *aboutData, true);
82#endif
83 helpMenu->action(KHelpMenu::menuDonate);
84 // Initialize menu
85 QMenu *menu = helpMenu->menu();
86 helpMenu->action(KHelpMenu::menuHelpContents)->setText(i18n("%1 Handbook", aboutData->displayName()));
87 helpMenu->action(KHelpMenu::menuAboutApp)->setText(i18n("About %1", aboutData->displayName()));
88 btnBox->addButton(QDialogButtonBox::Help)->setMenu(menu);
89 }
90 }
91 d->restoreDialogSize();
92}
93
94AgentConfigurationDialog::~AgentConfigurationDialog()
95{
96 if (d->widget) {
97 d->widget->saveDialogSize(size());
98 }
99}
100
101void AgentConfigurationDialog::accept()
102{
103 if (d->widget) {
104 d->widget->save();
105 }
106
108}
109
110#include "moc_agentconfigurationdialog.cpp"
Represents one agent instance and takes care of communication with it.
A widget for displaying agent configuration in applications.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Helper integration between Akonadi and Qt.
void clicked(bool checked)
virtual void accept()
bool isValid() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
void resize(const QSize &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.