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 <KConfig>
12 #include <QVBoxLayout>
13 
14 #include <KConfigGroup>
15 #include <KFilterProxySearchLine>
16 #include <KSharedConfig>
17 #include <QLineEdit>
18 
19 #include <QDialogButtonBox>
20 #include <QPushButton>
21 
22 using namespace Akonadi;
23 
24 class Akonadi::AgentTypeDialogPrivate
25 {
26 public:
27  explicit AgentTypeDialogPrivate(AgentTypeDialog *qq)
28  : q(qq)
29  {
30  }
31  void readConfig();
32  void writeConfig() const;
33  void slotSearchAgentType(const QString &str);
34  AgentTypeWidget *Widget = nullptr;
35  AgentType agentType;
36  AgentTypeDialog *const q;
37 };
38 
39 void AgentTypeDialogPrivate::writeConfig() const
40 {
41  KConfigGroup group(KSharedConfig::openStateConfig(), "AgentTypeDialog");
42  group.writeEntry("Size", q->size());
43 }
44 
45 void AgentTypeDialogPrivate::readConfig()
46 {
47  KConfigGroup group(KSharedConfig::openStateConfig(), "AgentTypeDialog");
48  const QSize sizeDialog = group.readEntry("Size", QSize(460, 320));
49  if (sizeDialog.isValid()) {
50  q->resize(sizeDialog);
51  }
52 }
53 
54 void AgentTypeDialogPrivate::slotSearchAgentType(const QString &str)
55 {
56  Widget->agentFilterProxyModel()->setFilterRegularExpression(str);
57 }
58 
60  : QDialog(parent)
61  , d(new AgentTypeDialogPrivate(this))
62 {
63  auto layout = new QVBoxLayout(this);
64 
65  d->Widget = new Akonadi::AgentTypeWidget(this);
67 
68  auto searchLine = new QLineEdit(this);
69  layout->addWidget(searchLine);
70  searchLine->setClearButtonEnabled(true);
71  connect(searchLine, &QLineEdit::textChanged, this, [this](const QString &str) {
72  d->slotSearchAgentType(str);
73  });
74 
75  layout->addWidget(d->Widget);
76 
80  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
81  okButton->setDefault(true);
82  okButton->setShortcut(Qt::CTRL | Qt::Key_Return); // NOLINT(bugprone-suspicious-enum-usage)
83  layout->addWidget(buttonBox);
84  d->readConfig();
85 
86  searchLine->setFocus();
87 }
88 
90 {
91  d->writeConfig();
92 }
93 
94 void AgentTypeDialog::done(int result)
95 {
96  if (result == Accepted) {
97  d->agentType = d->Widget->currentAgentType();
98  } else {
99  d->agentType = AgentType();
100  }
101 
103 }
104 
106 {
107  return d->agentType;
108 }
109 
111 {
112  return d->Widget->agentFilterProxyModel();
113 }
bool isValid() const const
virtual void reject()
void setShortcut(const QKeySequence &key)
A representation of an agent type.
QLayout * layout() const const
void readConfig()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
~AgentTypeDialog() override
Destroys the agent type dialog.
AgentTypeDialog(QWidget *parent=nullptr)
Creates a new agent type dialog.
void textChanged(const QString &text)
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
virtual void accept()
virtual void done(int r)
Key_Return
int result() const const
Provides a widget that lists all available agent types.
AgentFilterProxyModel * agentFilterProxyModel() const
Returns the agent filter proxy model that can be used to filter the agent types that shall be shown i...
void activated()
This signal is emitted whenever the user activates an agent.
A proxy model for filtering AgentType or AgentInstance.
void addWidget(QWidget *w)
void setDefault(bool)
A dialog to select an available agent type.
AgentType agentType() const
Returns the agent type that was selected by the user, or an empty agent type object if no agent type ...
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.