Akonadi

agenttypedialog.cpp
1/*
2 SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>
3 SPDX-FileCopyrightText: 2008 Omat Holding B.V. <info@omat.nl>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "agenttypedialog.h"
9#include "agentfilterproxymodel.h"
10
11#include <KConfig>
12#include <QVBoxLayout>
13
14#include <KConfigGroup>
15#include <KLocalizedString>
16#include <KSharedConfig>
17#include <QLineEdit>
18
19#include <QDialogButtonBox>
20#include <QPushButton>
21
22using namespace Akonadi;
23namespace
24{
25static const char myAgentTypeDialogGroupName[] = "AgentTypeDialog";
26}
27class Akonadi::AgentTypeDialogPrivate
28{
29public:
30 explicit AgentTypeDialogPrivate(AgentTypeDialog *qq)
31 : q(qq)
32 {
33 }
34 void readConfig();
35 void writeConfig() const;
36 void slotSearchAgentType(const QString &str);
37 AgentTypeWidget *Widget = nullptr;
38 AgentType agentType;
39 AgentTypeDialog *const q;
40};
41
42void AgentTypeDialogPrivate::writeConfig() const
43{
44 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myAgentTypeDialogGroupName));
45 group.writeEntry("Size", q->size());
46}
47
48void AgentTypeDialogPrivate::readConfig()
49{
50 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myAgentTypeDialogGroupName));
51 const QSize sizeDialog = group.readEntry("Size", QSize(460, 320));
52 if (sizeDialog.isValid()) {
53 q->resize(sizeDialog);
54 }
55}
56
57void AgentTypeDialogPrivate::slotSearchAgentType(const QString &str)
58{
60}
61
63 : QDialog(parent)
64 , d(new AgentTypeDialogPrivate(this))
65{
66 setWindowTitle(i18nc("@title:window", "Configure Account"));
67 auto layout = new QVBoxLayout(this);
68
69 d->Widget = new Akonadi::AgentTypeWidget(this);
71
72 auto searchLine = new QLineEdit(this);
73 layout->addWidget(searchLine);
74 searchLine->setClearButtonEnabled(true);
75 connect(searchLine, &QLineEdit::textChanged, this, [this](const QString &str) {
76 d->slotSearchAgentType(str);
77 });
78
79 layout->addWidget(d->Widget);
80
84 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
85 okButton->setDefault(true);
86 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); // NOLINT(bugprone-suspicious-enum-usage)
87 layout->addWidget(buttonBox);
88 d->readConfig();
89
90 searchLine->setFocus();
91}
92
94{
95 d->writeConfig();
96}
97
98void AgentTypeDialog::done(int result)
99{
100 if (result == Accepted) {
101 d->agentType = d->Widget->currentAgentType();
102 } else {
103 d->agentType = AgentType();
104 }
105
107}
108
110{
111 return d->agentType;
112}
113
115{
116 return d->Widget->agentFilterProxyModel();
117}
118
119#include "moc_agenttypedialog.cpp"
A proxy model for filtering AgentType or AgentInstance.
A dialog to select an available agent type.
~AgentTypeDialog() override
Destroys the agent type dialog.
AgentFilterProxyModel * agentFilterProxyModel() const
Returns the agent filter proxy model that can be used to filter the agent types that shall be shown i...
AgentType agentType() const
Returns the agent type that was selected by the user, or an empty agent type object if no agent type ...
AgentTypeDialog(QWidget *parent=nullptr)
Creates a new agent type dialog.
Provides a widget that lists all available agent types.
AgentFilterProxyModel * agentFilterProxyModel() const
Returns the agent filter proxy model, use this to filter by agent mimetype or capabilities.
void activated()
This signal is emitted whenever the user activates an agent.
A representation of an agent type.
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
Helper integration between Akonadi and Qt.
void setShortcut(const QKeySequence &key)
virtual void accept()
virtual void done(int r)
virtual void reject()
int result() const const
void addWidget(QWidget *w)
void textChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
void setDefault(bool)
bool isValid() const const
void setFilterRegularExpression(const QRegularExpression &regularExpression)
Key_Return
QLayout * layout() const const
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.