File indexing completed on 2024-11-24 04:39:35
0001 /* 0002 This file is part of Akonadi Contact. 0003 0004 SPDX-FileCopyrightText: 2010 KDAB 0005 SPDX-FileContributor: Tobias Koenig <tokoe@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "emailaddressselectiondialog.h" 0011 #include "recipientspicker/recipientspickerwidget.h" 0012 0013 #include <KConfigGroup> 0014 0015 #include <KSharedConfig> 0016 #include <QDialogButtonBox> 0017 #include <QPushButton> 0018 #include <QTreeView> 0019 #include <QVBoxLayout> 0020 0021 using namespace Akonadi; 0022 0023 class Akonadi::EmailAddressSelectionDialogPrivate 0024 { 0025 public: 0026 EmailAddressSelectionDialogPrivate(EmailAddressSelectionDialog *qq, QAbstractItemModel *model) 0027 : q(qq) 0028 { 0029 auto mainLayout = new QVBoxLayout(q); 0030 if (model) { 0031 mView = new RecipientsPickerWidget(true, model, q); 0032 } else { 0033 mView = new RecipientsPickerWidget(true, nullptr, q); 0034 } 0035 mainLayout->addWidget(mView); 0036 q->connect(mView->emailAddressSelectionWidget()->view(), &QTreeView::doubleClicked, q, &QDialog::accept); 0037 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, q); 0038 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0039 okButton->setDefault(true); 0040 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0041 QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &QDialog::accept); 0042 QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject); 0043 0044 mainLayout->addWidget(buttonBox); 0045 readConfig(); 0046 } 0047 0048 void readConfig() 0049 { 0050 KConfigGroup group(KSharedConfig::openStateConfig(), QStringLiteral("EmailAddressSelectionDialog")); 0051 const QSize size = group.readEntry("Size", QSize()); 0052 if (size.isValid()) { 0053 q->resize(size); 0054 } else { 0055 q->resize(q->sizeHint().width(), q->sizeHint().height()); 0056 } 0057 } 0058 0059 void writeConfig() 0060 { 0061 KConfigGroup group(KSharedConfig::openStateConfig(), QStringLiteral("EmailAddressSelectionDialog")); 0062 group.writeEntry("Size", q->size()); 0063 } 0064 0065 EmailAddressSelectionDialog *const q; 0066 RecipientsPickerWidget *mView = nullptr; 0067 }; 0068 0069 EmailAddressSelectionDialog::EmailAddressSelectionDialog(QWidget *parent) 0070 : AbstractEmailAddressSelectionDialog(parent) 0071 , d(new EmailAddressSelectionDialogPrivate(this, nullptr)) 0072 { 0073 } 0074 0075 EmailAddressSelectionDialog::EmailAddressSelectionDialog(QAbstractItemModel *model, QWidget *parent) 0076 : AbstractEmailAddressSelectionDialog(parent) 0077 , d(new EmailAddressSelectionDialogPrivate(this, model)) 0078 { 0079 } 0080 0081 EmailAddressSelectionDialog::~EmailAddressSelectionDialog() 0082 { 0083 d->writeConfig(); 0084 } 0085 0086 Akonadi::EmailAddressSelection::List EmailAddressSelectionDialog::selectedAddresses() const 0087 { 0088 return d->mView->emailAddressSelectionWidget()->selectedAddresses(); 0089 } 0090 0091 EmailAddressSelectionWidget *EmailAddressSelectionDialog::view() const 0092 { 0093 return d->mView->emailAddressSelectionWidget(); 0094 } 0095 0096 #include "moc_emailaddressselectiondialog.cpp"