Akonadi Contacts

emailaddressselectiondialog.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2010 KDAB
5  SPDX-FileContributor: Tobias Koenig <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "emailaddressselectiondialog.h"
11 #include "recipientspicker/recipientspickerwidget.h"
12 
13 #include <KConfigGroup>
14 
15 #include <KSharedConfig>
16 #include <QDialogButtonBox>
17 #include <QPushButton>
18 #include <QTreeView>
19 #include <QVBoxLayout>
20 
21 using namespace Akonadi;
22 
23 class Q_DECL_HIDDEN EmailAddressSelectionDialog::Private
24 {
25 public:
27  : q(qq)
28  {
29  auto mainLayout = new QVBoxLayout(q);
30  if (model) {
31  mView = new RecipientsPickerWidget(true, model, q);
32  } else {
33  mView = new RecipientsPickerWidget(true, nullptr, q);
34  }
35  mainLayout->addWidget(mView);
36  q->connect(mView->emailAddressSelectionWidget()->view(), &QTreeView::doubleClicked, q, &QDialog::accept);
38  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
39  okButton->setDefault(true);
40  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
41  connect(buttonBox, &QDialogButtonBox::accepted, q, &QDialog::accept);
42  connect(buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject);
43 
44  mainLayout->addWidget(buttonBox);
45  readConfig();
46  }
47 
48  void readConfig()
49  {
50  KConfigGroup group(KSharedConfig::openStateConfig(), QStringLiteral("EmailAddressSelectionDialog"));
51  const QSize size = group.readEntry("Size", QSize());
52  if (size.isValid()) {
53  q->resize(size);
54  } else {
55  q->resize(q->sizeHint().width(), q->sizeHint().height());
56  }
57  }
58 
59  void writeConfig()
60  {
61  KConfigGroup group(KSharedConfig::openStateConfig(), QStringLiteral("EmailAddressSelectionDialog"));
62  group.writeEntry("Size", q->size());
63  }
64 
66  RecipientsPickerWidget *mView = nullptr;
67 };
68 
70  : AbstractEmailAddressSelectionDialog(parent)
71  , d(new Private(this, nullptr))
72 {
73 }
74 
76  : AbstractEmailAddressSelectionDialog(parent)
77  , d(new Private(this, model))
78 {
79 }
80 
82 {
83  d->writeConfig();
84  delete d;
85 }
86 
88 {
89  return d->mView->emailAddressSelectionWidget()->selectedAddresses();
90 }
91 
93 {
94  return d->mView->emailAddressSelectionWidget();
95 }
void doubleClicked(const QModelIndex &index)
bool isValid() const const
virtual void reject()
EmailAddressSelectionWidget * view() const override
Returns the email address selection view that is used.
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
A dialog to select email addresses from Akonadi.
A widget to select email addresses from Akonadi.
void setShortcut(const QKeySequence &key)
virtual void accept()
void readConfig()
~EmailAddressSelectionDialog() override
Destroys the email address selection dialog.
EmailAddressSelection::List selectedAddresses() const override
Returns the list of selected email addresses.
QObject * parent() const const
EmailAddressSelectionDialog(QWidget *parent=nullptr)
Creates a new email address selection dialog.
void setDefault(bool)
Key_Return
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jun 17 2021 23:09:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.