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 <KLocalizedString>
16 #include <KSharedConfig>
17 #include <QLineEdit>
18 
19 #include <QDialogButtonBox>
20 #include <QPushButton>
21 
22 using namespace Akonadi;
23 namespace
24 {
25 static const char myAgentTypeDialogGroupName[] = "AgentTypeDialog";
26 }
27 class Akonadi::AgentTypeDialogPrivate
28 {
29 public:
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 
42 void AgentTypeDialogPrivate::writeConfig() const
43 {
44  KConfigGroup group(KSharedConfig::openStateConfig(), myAgentTypeDialogGroupName);
45  group.writeEntry("Size", q->size());
46 }
47 
48 void AgentTypeDialogPrivate::readConfig()
49 {
50  KConfigGroup group(KSharedConfig::openStateConfig(), myAgentTypeDialogGroupName);
51  const QSize sizeDialog = group.readEntry("Size", QSize(460, 320));
52  if (sizeDialog.isValid()) {
53  q->resize(sizeDialog);
54  }
55 }
56 
57 void AgentTypeDialogPrivate::slotSearchAgentType(const QString &str)
58 {
59  Widget->agentFilterProxyModel()->setFilterRegularExpression(str);
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 
98 void 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 }
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)
void setWindowTitle(const QString &)
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)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
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-2023 The KDE developers.
Generated on Mon May 8 2023 03:52:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.