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 auto helpMenu = new KHelpMenu(this, *aboutData, true);
78 helpMenu->action(KHelpMenu::menuDonate);
79 // Initialize menu
80 QMenu *menu = helpMenu->menu();
81 helpMenu->action(KHelpMenu::menuHelpContents)->setText(i18n("%1 Handbook", aboutData->displayName()));
82 helpMenu->action(KHelpMenu::menuAboutApp)->setText(i18n("About %1", aboutData->displayName()));
83 btnBox->addButton(QDialogButtonBox::Help)->setMenu(menu);
84 }
85 }
86 d->restoreDialogSize();
87}
88
89AgentConfigurationDialog::~AgentConfigurationDialog()
90{
91 if (d->widget) {
92 d->widget->saveDialogSize(size());
93 }
94}
95
96void AgentConfigurationDialog::accept()
97{
98 if (d->widget) {
99 d->widget->save();
100 }
101
103}
104
105#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 Mon Nov 18 2024 12:08:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.