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 Akonadi::EmailAddressSelectionDialogPrivate
24 {
25 public:
26  EmailAddressSelectionDialogPrivate(EmailAddressSelectionDialog *qq, QAbstractItemModel *model)
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);
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 EmailAddressSelectionDialogPrivate(this, nullptr))
72 {
73 }
74 
76  : AbstractEmailAddressSelectionDialog(parent)
77  , d(new EmailAddressSelectionDialogPrivate(this, model))
78 {
79 }
80 
82 {
83  d->writeConfig();
84 }
85 
87 {
88  return d->mView->emailAddressSelectionWidget()->selectedAddresses();
89 }
90 
92 {
93  return d->mView->emailAddressSelectionWidget();
94 }
void doubleClicked(const QModelIndex &index)
bool isValid() const const
virtual void reject()
void setShortcut(const QKeySequence &key)
EmailAddressSelectionDialog(QWidget *parent=nullptr)
Creates a new email address selection dialog.
EmailAddressSelection::List selectedAddresses() const override
Returns the list of selected email addresses.
void readConfig()
A widget to select email addresses from Akonadi.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
~EmailAddressSelectionDialog() override
Destroys the email address selection dialog.
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
virtual void accept()
A dialog to select email addresses from Akonadi.
Key_Return
void setDefault(bool)
EmailAddressSelectionWidget * view() const override
Returns the email address selection view that is used.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:57:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.