Akonadi

agenttypedialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2006 Tobias Koenig <[email protected]>
3  SPDX-FileCopyrightText: 2008 Omat Holding B.V. <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7 
8 #include "agenttypedialog.h"
9 #include "agentfilterproxymodel.h"
10 
11 #include <QVBoxLayout>
12 #include <KConfig>
13 
14 #include <KFilterProxySearchLine>
15 #include <QLineEdit>
16 #include <KSharedConfig>
17 #include <KConfigGroup>
18 
19 #include <QDialogButtonBox>
20 #include <QPushButton>
21 
22 using namespace Akonadi;
23 
24 class Q_DECL_HIDDEN AgentTypeDialog::Private
25 {
26 public:
27  explicit Private(AgentTypeDialog *qq)
28  : q(qq)
29  {
30 
31  }
32  void readConfig();
33  void writeConfig() const;
34  AgentTypeWidget *Widget = nullptr;
35  AgentType agentType;
36  AgentTypeDialog * const q;
37 };
38 
39 void AgentTypeDialog::Private::writeConfig() const
40 {
41  KConfigGroup group(KSharedConfig::openConfig(), "AgentTypeDialog");
42  group.writeEntry("Size", q->size());
43 }
44 
45 void AgentTypeDialog::Private::readConfig()
46 {
47  KConfigGroup group(KSharedConfig::openConfig(), "AgentTypeDialog");
48  const QSize sizeDialog = group.readEntry("Size", QSize(460, 320));
49  if (sizeDialog.isValid()) {
50  q->resize(sizeDialog);
51  }
52 }
53 
55  : QDialog(parent)
56  , d(new Private(this))
57 {
58  QVBoxLayout *layout = new QVBoxLayout(this);
59 
60  d->Widget = new Akonadi::AgentTypeWidget(this);
62 
63  QLineEdit *searchLine = new QLineEdit(this);
64  layout->addWidget(searchLine);
65  searchLine->setClearButtonEnabled(true);
66  connect(searchLine, &QLineEdit::textChanged, d->Widget->agentFilterProxyModel(), &AgentFilterProxyModel::setFilterFixedString);
67 
68  layout->addWidget(d->Widget);
69 
73  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
74  okButton->setDefault(true);
75  okButton->setShortcut(Qt::CTRL | Qt::Key_Return); // NOLINT(bugprone-suspicious-enum-usage)
76  layout->addWidget(buttonBox);
77  d->readConfig();
78 
79  searchLine->setFocus();
80 }
81 
83 {
84  d->writeConfig();
85  delete d;
86 }
87 
88 void AgentTypeDialog::done(int result)
89 {
90  if (result == Accepted) {
91  d->agentType = d->Widget->currentAgentType();
92  } else {
93  d->agentType = AgentType();
94  }
95 
96  QDialog::done(result);
97 }
98 
100 {
101  return d->agentType;
102 }
103 
105 {
106  return d->Widget->agentFilterProxyModel();
107 }
QLayout * layout() const const
void activated()
This signal is emitted whenever the user activates an agent.
bool isValid() const const
virtual void reject()
void textChanged(const QString &text)
virtual void done(int r)
Provides a widget that lists all available agent types.
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
A representation of an agent type.
void setFocus()
AgentType agentType() const
Returns the agent type that was selected by the user, or an empty agent type object if no agent type ...
int result() const const
void setClearButtonEnabled(bool enable)
void setShortcut(const QKeySequence &key)
virtual void accept()
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
void readConfig()
AgentFilterProxyModel * agentFilterProxyModel() const
Returns the agent filter proxy model that can be used to filter the agent types that shall be shown i...
Helper integration between Akonadi and Qt.
A proxy model for filtering AgentType or AgentInstance.
~AgentTypeDialog() override
Destroys the agent type dialog.
A dialog to select an available agent type.
void setFilterFixedString(const QString &pattern)
QPushButton * button(QDialogButtonBox::StandardButton which) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setDefault(bool)
Key_Return
AgentTypeDialog(QWidget *parent=nullptr)
Creates a new agent type dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 14 2020 23:16:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.